]>
Commit | Line | Data |
---|---|---|
8e029c65 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
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> | |
44 | ||
45 | #define JB_RBX 0 | |
46 | #define JB_RBP 8 | |
47 | #define JB_RSP 16 | |
48 | #define JB_R12 24 | |
49 | #define JB_R13 32 | |
50 | #define JB_R14 40 | |
51 | #define JB_R15 48 | |
52 | #define JB_RIP 56 | |
53 | #define JB_RFLAGS 64 | |
54 | #define JB_MXCSR 72 | |
55 | #define JB_FPCONTROL 76 | |
56 | #define JB_MASK 80 | |
57 | ||
58 | LEAF(__setjmp, 0) | |
59 | // %rdi is a jmp_buf (struct sigcontext *) | |
60 | ||
61 | // now build sigcontext | |
62 | movq %rbx, JB_RBX(%rdi) | |
63 | movq %rbp, JB_RBP(%rdi) | |
64 | movq %r12, JB_R12(%rdi) | |
65 | movq %r13, JB_R13(%rdi) | |
66 | movq %r14, JB_R14(%rdi) | |
67 | movq %r15, JB_R15(%rdi) | |
68 | ||
69 | // RIP is set to the frame return address value | |
70 | movq (%rsp), %rax | |
71 | movq %rax, JB_RIP(%rdi) | |
72 | // RSP is set to the frame return address plus 8 | |
73 | movq %rsp, %rax | |
74 | addq $8, %rax | |
75 | movq %rax, JB_RSP(%rdi) | |
76 | ||
77 | // save rflags - you can't use movq | |
78 | pushfq | |
79 | popq %rax | |
80 | movq %rax, JB_RFLAGS(%rdi) | |
81 | ||
82 | // save fp control word | |
83 | fnstcw JB_FPCONTROL(%rdi) | |
84 | ||
85 | // save MXCSR | |
86 | stmxcsr JB_MXCSR(%rdi) | |
87 | ||
88 | // return 0 | |
89 | xorq %rax, %rax | |
90 | ret | |
91 | ||
92 | ||
93 | LEAF(__longjmp, 0) | |
94 | fninit // reset FP coprocessor | |
95 | ||
96 | // %rdi is a jmp_buf (struct sigcontext *) | |
97 | // %rsi is the return value | |
98 | movq %rsi, %rax | |
99 | testq %rax, %rax | |
100 | jnz 1f | |
101 | addq $1, %rax | |
102 | ||
103 | // general registers | |
104 | 1: | |
105 | movq JB_RBX(%rdi), %rbx | |
106 | movq JB_RBP(%rdi), %rbp | |
107 | movq JB_RSP(%rdi), %rsp | |
108 | movq JB_R12(%rdi), %r12 | |
109 | movq JB_R13(%rdi), %r13 | |
110 | movq JB_R14(%rdi), %r14 | |
111 | movq JB_R15(%rdi), %r15 | |
112 | ||
113 | // restore FP control word | |
114 | fldcw JB_FPCONTROL(%rdi) | |
115 | ||
116 | // restore MXCSR | |
117 | ldmxcsr JB_MXCSR(%rdi) | |
118 | ||
119 | // rflags | |
120 | pushq JB_RFLAGS(%rdi) | |
121 | popfq | |
122 | ||
123 | jmp *JB_RIP(%rdi) |