2 * The x86-64 Linux incarnation of arch-dependent OS-dependent
3 * routines. See also "linux-os.c".
7 * This software is part of the SBCL system. See the README file for
10 * This software is derived from the CMU CL system, which was
11 * written at Carnegie Mellon University and released into the
12 * public domain. The software is in the public domain and is
13 * provided with absolutely no warranty. See the COPYING and CREDITS
14 * files for more information.
19 #include <sys/param.h>
21 #include <sys/types.h>
26 #include <sys/ucontext.h>
34 #include "interrupt.h"
38 #include <sys/socket.h>
39 #include <sys/utsname.h>
41 #include <sys/types.h>
43 /* #include <sys/sysinfo.h> */
48 #include <linux/unistd.h>
50 #include <linux/version.h>
51 #include "thread.h" /* dynamic_values_bytes */
54 size_t os_vm_page_size;
56 int arch_os_thread_init(struct thread *thread) {
58 #ifdef LISP_FEATURE_SB_THREAD
59 pthread_setspecific(specials,thread);
61 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
62 /* Signal handlers are run on the control stack, so if it is exhausted
63 * we had better use an alternate stack for whatever signal tells us
64 * we've exhausted it */
65 sigstack.ss_sp=((void *) thread)+dynamic_values_bytes;
67 sigstack.ss_size = 32*SIGSTKSZ;
68 if(sigaltstack(&sigstack,0)<0) {
69 lose("Cannot sigaltstack: %s\n",strerror(errno));
75 /* free any arch/os-specific resources used by thread, which is now
76 * defunct. Not called on live threads
79 int arch_os_thread_cleanup(struct thread *thread) {
84 os_context_register_t *
85 os_context_register_addr(os_context_t *context, int offset)
87 #define RCASE(name) case reg_ ## name: return &context->uc_mcontext.gregs[REG_ ## name];
107 return &context->uc_mcontext.gregs[offset/2+4];
110 return &context->uc_mcontext.gregs[offset];
113 os_context_register_t *
114 os_context_pc_addr(os_context_t *context)
116 return &context->uc_mcontext.gregs[REG_RIP]; /* REG_EIP */
119 os_context_register_t *
120 os_context_sp_addr(os_context_t *context)
122 return &context->uc_mcontext.gregs[REG_RSP];
125 os_context_register_t *
126 os_context_fp_addr(os_context_t *context)
128 return &context->uc_mcontext.gregs[REG_RBP];
132 os_context_fp_control(os_context_t *context)
134 /* return the x87 exception flags ored in with the sse2
135 * control+status flags */
136 unsigned int result = (context->uc_mcontext.fpregs->swd & 0x3F) | context->uc_mcontext.fpregs->mxcsr;
137 /* flip exception mask bits */
138 return result ^ (0x3F << 7);
142 os_context_sigmask_addr(os_context_t *context)
144 return &context->uc_sigmask;
148 os_restore_fp_control(os_context_t *context)
150 /* reset exception flags and restore control flags on SSE2 FPU */
151 unsigned int temp = (context->uc_mcontext.fpregs->mxcsr) & ~0x3F;
152 asm ("ldmxcsr %0" : : "m" (temp));
153 /* same for x87 FPU. */
154 asm ("fldcw %0" : : "m" (context->uc_mcontext.fpregs->cwd));
158 os_flush_icache(os_vm_address_t address, os_vm_size_t length)