7 #if defined(LISP_FEATURE_FREEBSD)
8 #include <machine/fpu.h>
11 /* KLUDGE: There is strong family resemblance in the signal context
12 * stuff in FreeBSD and OpenBSD, but in detail they're different in
13 * almost every line of code. It would be nice to find some way to
14 * factor out the commonality better; failing that, it might be best
15 * just to split this generic-BSD code into one variant for each BSD.
17 * KLUDGE II: this split has begun with the addition of the Darwin BSD
18 * flavour, with the cross-architecture complications that this
19 * entails; unfortunately, currently the situation is worse, not
20 * better, than in the above paragraph. */
22 #if defined(LISP_FEATURE_FREEBSD)
23 os_context_register_t *
24 os_context_register_addr(os_context_t *context, int offset)
28 return CONTEXT_ADDR_FROM_STEM(rax);
30 return CONTEXT_ADDR_FROM_STEM(rcx);
32 return CONTEXT_ADDR_FROM_STEM(rdx);
34 return CONTEXT_ADDR_FROM_STEM(rbx);
36 return CONTEXT_ADDR_FROM_STEM(rsp);
38 return CONTEXT_ADDR_FROM_STEM(rbp);
40 return CONTEXT_ADDR_FROM_STEM(rsi);
42 return CONTEXT_ADDR_FROM_STEM(rdi);
44 return CONTEXT_ADDR_FROM_STEM(r8);
46 return CONTEXT_ADDR_FROM_STEM(r9);
48 return CONTEXT_ADDR_FROM_STEM(r10);
50 return CONTEXT_ADDR_FROM_STEM(r11);
52 return CONTEXT_ADDR_FROM_STEM(r12);
54 return CONTEXT_ADDR_FROM_STEM(r13);
56 return CONTEXT_ADDR_FROM_STEM(r14);
58 return CONTEXT_ADDR_FROM_STEM(r15);
64 os_context_register_t *
65 os_context_sp_addr(os_context_t *context)
67 return CONTEXT_ADDR_FROM_STEM(rsp);
70 os_context_register_t *
71 os_context_pc_addr(os_context_t *context)
73 return CONTEXT_ADDR_FROM_STEM(rip);
79 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
83 int arch_os_thread_init(struct thread *thread) {
85 #ifdef LISP_FEATURE_SB_THREAD
86 pthread_setspecific(specials,thread);
88 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
89 /* Signal handlers are run on the control stack, so if it is exhausted
90 * we had better use an alternate stack for whatever signal tells us
91 * we've exhausted it */
92 sigstack.ss_sp=((void *) thread)+dynamic_values_bytes;
94 sigstack.ss_size = 32*SIGSTKSZ;
95 sigaltstack(&sigstack,0);
97 return 1; /* success */
100 int arch_os_thread_cleanup(struct thread *thread) {
101 return 1; /* success */
104 #if defined(LISP_FEATURE_FREEBSD)
106 os_restore_fp_control(os_context_t *context)
108 struct envxmm *ex = (struct envxmm*)(&context->uc_mcontext.mc_fpstate);
109 /* reset exception flags and restore control flags on SSE2 FPU */
110 unsigned int temp = (ex->en_mxcsr) & ~0x3F;
111 asm ("ldmxcsr %0" : : "m" (temp));
112 /* same for x87 FPU. */
113 asm ("fldcw %0" : : "m" (ex->en_cw));