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 #error Threads are not supported on x86-64 in this SBCL version
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 sigaltstack(&sigstack,0);
73 /* free any arch/os-specific resources used by thread, which is now
74 * defunct. Not called on live threads
77 int arch_os_thread_cleanup(struct thread *thread) {
82 os_context_register_t *
83 os_context_register_addr(os_context_t *context, int offset)
85 #define RCASE(name) case reg_ ## name: return &context->uc_mcontext.gregs[REG_ ## name];
105 return &context->uc_mcontext.gregs[offset/2+4];
108 return &context->uc_mcontext.gregs[offset];
111 os_context_register_t *
112 os_context_pc_addr(os_context_t *context)
114 return &context->uc_mcontext.gregs[REG_RIP]; /* REG_EIP */
117 os_context_register_t *
118 os_context_sp_addr(os_context_t *context)
120 return &context->uc_mcontext.gregs[REG_RSP];
123 os_context_register_t *
124 os_context_fp_addr(os_context_t *context)
126 return &context->uc_mcontext.gregs[REG_RBP];
130 os_context_fp_control(os_context_t *context)
132 int mxcsr = context->uc_mcontext.fpregs->mxcsr;
133 return ((mxcsr & 0x3F) << 16 | ((mxcsr >> 7) & 0x3F)) ^ 0x3F;
137 os_context_sigmask_addr(os_context_t *context)
139 return &context->uc_sigmask;
143 os_restore_fp_control(os_context_t *context)
145 asm ("ldmxcsr %0" : : "m" (context->uc_mcontext.fpregs->mxcsr));
149 os_flush_icache(os_vm_address_t address, os_vm_size_t length)