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)
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);
85 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
89 int arch_os_thread_init(struct thread *thread) {
91 #ifdef LISP_FEATURE_SB_THREAD
92 pthread_setspecific(specials,thread);
95 #ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER
96 mach_thread_init(THREAD_STRUCT_TO_EXCEPTION_PORT(thread));
99 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
100 /* Signal handlers are run on the control stack, so if it is exhausted
101 * we had better use an alternate stack for whatever signal tells us
102 * we've exhausted it */
103 sigstack.ss_sp=((void *) thread)+dynamic_values_bytes;
105 sigstack.ss_size = 32*SIGSTKSZ;
106 sigaltstack(&sigstack,0);
108 return 1; /* success */
111 int arch_os_thread_cleanup(struct thread *thread) {
112 return 1; /* success */
115 #if defined(LISP_FEATURE_FREEBSD)
117 os_restore_fp_control(os_context_t *context)
119 struct envxmm *ex = (struct envxmm*)(&context->uc_mcontext.mc_fpstate);
120 /* reset exception flags and restore control flags on SSE2 FPU */
121 unsigned int temp = (ex->en_mxcsr) & ~0x3F;
122 asm ("ldmxcsr %0" : : "m" (temp));
123 /* same for x87 FPU. */
124 asm ("fldcw %0" : : "m" (ex->en_cw));