7 #if defined(LISP_FEATURE_FREEBSD)
8 #include <machine/fpu.h>
11 #if defined(LISP_FEATURE_OPENBSD)
12 #include <machine/fpu.h>
15 /* KLUDGE: There is strong family resemblance in the signal context
16 * stuff in FreeBSD and OpenBSD, but in detail they're different in
17 * almost every line of code. It would be nice to find some way to
18 * factor out the commonality better; failing that, it might be best
19 * just to split this generic-BSD code into one variant for each BSD.
21 * KLUDGE II: this split has begun with the addition of the Darwin BSD
22 * flavour, with the cross-architecture complications that this
23 * entails; unfortunately, currently the situation is worse, not
24 * better, than in the above paragraph. */
26 #if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DARWIN) || defined(LISP_FEATURE_OPENBSD)
27 os_context_register_t *
28 os_context_register_addr(os_context_t *context, int offset)
32 return CONTEXT_ADDR_FROM_STEM(rax);
34 return CONTEXT_ADDR_FROM_STEM(rcx);
36 return CONTEXT_ADDR_FROM_STEM(rdx);
38 return CONTEXT_ADDR_FROM_STEM(rbx);
40 return CONTEXT_ADDR_FROM_STEM(rsp);
42 return CONTEXT_ADDR_FROM_STEM(rbp);
44 return CONTEXT_ADDR_FROM_STEM(rsi);
46 return CONTEXT_ADDR_FROM_STEM(rdi);
48 return CONTEXT_ADDR_FROM_STEM(r8);
50 return CONTEXT_ADDR_FROM_STEM(r9);
52 return CONTEXT_ADDR_FROM_STEM(r10);
54 return CONTEXT_ADDR_FROM_STEM(r11);
56 return CONTEXT_ADDR_FROM_STEM(r12);
58 return CONTEXT_ADDR_FROM_STEM(r13);
60 return CONTEXT_ADDR_FROM_STEM(r14);
62 return CONTEXT_ADDR_FROM_STEM(r15);
68 os_context_register_t *
69 os_context_sp_addr(os_context_t *context)
71 return CONTEXT_ADDR_FROM_STEM(rsp);
74 os_context_register_t *
75 os_context_pc_addr(os_context_t *context)
77 return CONTEXT_ADDR_FROM_STEM(rip);
80 #elif defined(LISP_FEATURE_NETBSD)
81 os_context_register_t *
82 os_context_register_addr(os_context_t *context, int offset)
86 return CONTEXT_ADDR_FROM_STEM(RAX);
88 return CONTEXT_ADDR_FROM_STEM(RCX);
90 return CONTEXT_ADDR_FROM_STEM(RDX);
92 return CONTEXT_ADDR_FROM_STEM(RBX);
94 return CONTEXT_ADDR_FROM_STEM(RSP);
96 return CONTEXT_ADDR_FROM_STEM(RBP);
98 return CONTEXT_ADDR_FROM_STEM(RSI);
100 return CONTEXT_ADDR_FROM_STEM(RDI);
102 return CONTEXT_ADDR_FROM_STEM(R8);
104 return CONTEXT_ADDR_FROM_STEM(R9);
106 return CONTEXT_ADDR_FROM_STEM(R10);
108 return CONTEXT_ADDR_FROM_STEM(R11);
110 return CONTEXT_ADDR_FROM_STEM(R12);
112 return CONTEXT_ADDR_FROM_STEM(R13);
114 return CONTEXT_ADDR_FROM_STEM(R14);
116 return CONTEXT_ADDR_FROM_STEM(R15);
122 os_context_register_t *
123 os_context_sp_addr(os_context_t *context)
125 return CONTEXT_ADDR_FROM_STEM(RSP);
128 os_context_register_t *
129 os_context_pc_addr(os_context_t *context)
131 return CONTEXT_ADDR_FROM_STEM(RIP);
137 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
141 int arch_os_thread_init(struct thread *thread) {
143 #ifdef LISP_FEATURE_SB_THREAD
144 #ifdef LISP_FEATURE_GCC_TLS
145 current_thread = thread;
147 pthread_setspecific(specials,thread);
151 #ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER
152 mach_lisp_thread_init(thread);
155 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
156 /* Signal handlers are run on the control stack, so if it is exhausted
157 * we had better use an alternate stack for whatever signal tells us
158 * we've exhausted it */
159 sigstack.ss_sp=((void *) thread)+dynamic_values_bytes;
161 sigstack.ss_size = 32*SIGSTKSZ;
162 sigaltstack(&sigstack,0);
164 return 1; /* success */
167 int arch_os_thread_cleanup(struct thread *thread) {
168 return 1; /* success */
171 #if defined(LISP_FEATURE_FREEBSD)
173 os_restore_fp_control(os_context_t *context)
175 struct envxmm *ex = (struct envxmm*)(&context->uc_mcontext.mc_fpstate);
176 /* reset exception flags and restore control flags on SSE2 FPU */
177 unsigned int temp = (ex->en_mxcsr) & ~0x3F;
178 asm ("ldmxcsr %0" : : "m" (temp));
179 /* same for x87 FPU. */
180 asm ("fldcw %0" : : "m" (ex->en_cw));
184 #if defined(LISP_FEATURE_OPENBSD)
186 os_restore_fp_control(os_context_t *context)
188 if (context->sc_fpstate != NULL) {
189 u_int32_t mxcsr = context->sc_fpstate->fx_mxcsr & ~0x3F;
190 u_int16_t cw = context->sc_fpstate->fx_fcw;
191 asm ("ldmxcsr %0" : : "m" (mxcsr));
192 asm ("fldcw %0" : : "m" (cw));