7 #if defined(LISP_FEATURE_FREEBSD)
8 #include <machine/fpu.h>
11 #ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER
12 #include <mach/mach.h>
14 kern_return_t mach_thread_init(mach_port_t thread_exception_port);
17 /* KLUDGE: There is strong family resemblance in the signal context
18 * stuff in FreeBSD and OpenBSD, but in detail they're different in
19 * almost every line of code. It would be nice to find some way to
20 * factor out the commonality better; failing that, it might be best
21 * just to split this generic-BSD code into one variant for each BSD.
23 * KLUDGE II: this split has begun with the addition of the Darwin BSD
24 * flavour, with the cross-architecture complications that this
25 * entails; unfortunately, currently the situation is worse, not
26 * better, than in the above paragraph. */
28 #if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DARWIN) || defined(LISP_FEATURE_OPENBSD)
29 os_context_register_t *
30 os_context_register_addr(os_context_t *context, int offset)
34 return CONTEXT_ADDR_FROM_STEM(rax);
36 return CONTEXT_ADDR_FROM_STEM(rcx);
38 return CONTEXT_ADDR_FROM_STEM(rdx);
40 return CONTEXT_ADDR_FROM_STEM(rbx);
42 return CONTEXT_ADDR_FROM_STEM(rsp);
44 return CONTEXT_ADDR_FROM_STEM(rbp);
46 return CONTEXT_ADDR_FROM_STEM(rsi);
48 return CONTEXT_ADDR_FROM_STEM(rdi);
50 return CONTEXT_ADDR_FROM_STEM(r8);
52 return CONTEXT_ADDR_FROM_STEM(r9);
54 return CONTEXT_ADDR_FROM_STEM(r10);
56 return CONTEXT_ADDR_FROM_STEM(r11);
58 return CONTEXT_ADDR_FROM_STEM(r12);
60 return CONTEXT_ADDR_FROM_STEM(r13);
62 return CONTEXT_ADDR_FROM_STEM(r14);
64 return CONTEXT_ADDR_FROM_STEM(r15);
70 os_context_register_t *
71 os_context_sp_addr(os_context_t *context)
73 return CONTEXT_ADDR_FROM_STEM(rsp);
76 os_context_register_t *
77 os_context_pc_addr(os_context_t *context)
79 return CONTEXT_ADDR_FROM_STEM(rip);
82 #elif defined(LISP_FEATURE_NETBSD)
83 os_context_register_t *
84 os_context_register_addr(os_context_t *context, int offset)
88 return CONTEXT_ADDR_FROM_STEM(RAX);
90 return CONTEXT_ADDR_FROM_STEM(RCX);
92 return CONTEXT_ADDR_FROM_STEM(RDX);
94 return CONTEXT_ADDR_FROM_STEM(RBX);
96 return CONTEXT_ADDR_FROM_STEM(RSP);
98 return CONTEXT_ADDR_FROM_STEM(RBP);
100 return CONTEXT_ADDR_FROM_STEM(RSI);
102 return CONTEXT_ADDR_FROM_STEM(RDI);
104 return CONTEXT_ADDR_FROM_STEM(R8);
106 return CONTEXT_ADDR_FROM_STEM(R9);
108 return CONTEXT_ADDR_FROM_STEM(R10);
110 return CONTEXT_ADDR_FROM_STEM(R11);
112 return CONTEXT_ADDR_FROM_STEM(R12);
114 return CONTEXT_ADDR_FROM_STEM(R13);
116 return CONTEXT_ADDR_FROM_STEM(R14);
118 return CONTEXT_ADDR_FROM_STEM(R15);
124 os_context_register_t *
125 os_context_sp_addr(os_context_t *context)
127 return CONTEXT_ADDR_FROM_STEM(RSP);
130 os_context_register_t *
131 os_context_pc_addr(os_context_t *context)
133 return CONTEXT_ADDR_FROM_STEM(RIP);
139 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
143 int arch_os_thread_init(struct thread *thread) {
145 #ifdef LISP_FEATURE_SB_THREAD
146 #ifdef LISP_FEATURE_GCC_TLS
147 current_thread = thread;
149 pthread_setspecific(specials,thread);
153 #ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER
154 mach_thread_init(THREAD_STRUCT_TO_EXCEPTION_PORT(thread));
157 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
158 /* Signal handlers are run on the control stack, so if it is exhausted
159 * we had better use an alternate stack for whatever signal tells us
160 * we've exhausted it */
161 sigstack.ss_sp=((void *) thread)+dynamic_values_bytes;
163 sigstack.ss_size = 32*SIGSTKSZ;
164 sigaltstack(&sigstack,0);
166 return 1; /* success */
169 int arch_os_thread_cleanup(struct thread *thread) {
170 return 1; /* success */
173 #if defined(LISP_FEATURE_FREEBSD)
175 os_restore_fp_control(os_context_t *context)
177 struct envxmm *ex = (struct envxmm*)(&context->uc_mcontext.mc_fpstate);
178 /* reset exception flags and restore control flags on SSE2 FPU */
179 unsigned int temp = (ex->en_mxcsr) & ~0x3F;
180 asm ("ldmxcsr %0" : : "m" (temp));
181 /* same for x87 FPU. */
182 asm ("fldcw %0" : : "m" (ex->en_cw));