]>
Commit | Line | Data |
---|---|---|
ada7c492 | 1 | /* |
438624e0 | 2 | * Copyright (c) 1999-2018 Apple Computer, Inc. All rights reserved. |
ada7c492 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /* | |
24 | * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved | |
25 | * | |
26 | * HISTORY | |
27 | * 20-Apr-92 Bruce Martin (bmartin@next.com) | |
28 | * Created from M68K sources. | |
29 | */ | |
30 | ||
31 | /* | |
32 | * C library -- _setjmp, _longjmp | |
33 | * | |
34 | * _longjmp(a,v) | |
35 | * will generate a "return(v)" from | |
36 | * the last call to | |
37 | * _setjmp(a) | |
38 | * by restoring registers from the stack, | |
39 | * The previous signal state is NOT restored. | |
40 | * | |
41 | */ | |
42 | ||
43 | #include <architecture/i386/asm_help.h> | |
438624e0 | 44 | #include <os/tsd.h> |
ada7c492 A |
45 | |
46 | #define JB_RBX 0 | |
47 | #define JB_RBP 8 | |
48 | #define JB_RSP 16 | |
49 | #define JB_R12 24 | |
50 | #define JB_R13 32 | |
51 | #define JB_R14 40 | |
52 | #define JB_R15 48 | |
53 | #define JB_RIP 56 | |
54 | #define JB_RFLAGS 64 | |
55 | #define JB_MXCSR 72 | |
56 | #define JB_FPCONTROL 76 | |
57 | #define JB_MASK 80 | |
58 | ||
59 | LEAF(__setjmp, 0) | |
60 | // %rdi is a jmp_buf (struct sigcontext *) | |
61 | ||
62 | // now build sigcontext | |
63 | movq %rbx, JB_RBX(%rdi) | |
438624e0 A |
64 | movq %rbp, %rax |
65 | _OS_PTR_MUNGE(%rax) | |
66 | movq %rax, JB_RBP(%rdi) | |
ada7c492 A |
67 | movq %r12, JB_R12(%rdi) |
68 | movq %r13, JB_R13(%rdi) | |
69 | movq %r14, JB_R14(%rdi) | |
70 | movq %r15, JB_R15(%rdi) | |
71 | ||
72 | // RIP is set to the frame return address value | |
73 | movq (%rsp), %rax | |
438624e0 | 74 | _OS_PTR_MUNGE(%rax) |
ada7c492 A |
75 | movq %rax, JB_RIP(%rdi) |
76 | // RSP is set to the frame return address plus 8 | |
77 | leaq 8(%rsp), %rax | |
438624e0 | 78 | _OS_PTR_MUNGE(%rax) |
ada7c492 A |
79 | movq %rax, JB_RSP(%rdi) |
80 | ||
81 | // save fp control word | |
82 | fnstcw JB_FPCONTROL(%rdi) | |
83 | ||
84 | // save MXCSR | |
85 | stmxcsr JB_MXCSR(%rdi) | |
86 | ||
87 | // return 0 | |
88 | xorl %eax, %eax | |
89 | ret | |
90 | ||
91 | ||
92 | LEAF(__longjmp, 0) | |
93 | fninit // Clear all FP exceptions | |
94 | // %rdi is a jmp_buf (struct sigcontext *) | |
95 | // %esi is the return value | |
ada7c492 | 96 | testl %esi, %esi |
438624e0 A |
97 | movl $1, %eax |
98 | cmovnel %esi, %eax | |
ada7c492 A |
99 | |
100 | // general registers | |
ada7c492 | 101 | movq JB_RBX(%rdi), %rbx |
438624e0 A |
102 | movq JB_RBP(%rdi), %rsi |
103 | _OS_PTR_UNMUNGE(%rsi) | |
104 | movq %rsi, %rbp | |
105 | movq JB_RSP(%rdi), %rsi | |
106 | _OS_PTR_UNMUNGE(%rsi) | |
442fbc9d | 107 | movsbq (%rsi), %r12 // probe to detect absolutely corrupt stack pointers |
438624e0 | 108 | movq %rsi, %rsp |
ada7c492 A |
109 | movq JB_R12(%rdi), %r12 |
110 | movq JB_R13(%rdi), %r13 | |
111 | movq JB_R14(%rdi), %r14 | |
112 | movq JB_R15(%rdi), %r15 | |
438624e0 A |
113 | movq JB_RIP(%rdi), %rsi |
114 | _OS_PTR_UNMUNGE(%rsi) | |
ada7c492 A |
115 | |
116 | // restore FP control word | |
117 | fldcw JB_FPCONTROL(%rdi) | |
118 | ||
119 | // restore MXCSR | |
120 | ldmxcsr JB_MXCSR(%rdi) | |
121 | ||
ada7c492 A |
122 | // Make sure DF is reset |
123 | cld | |
124 | ||
438624e0 | 125 | jmp *%rsi |