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.
17 #define _GNU_SOURCE /* for REG_RAX etc. from sys/ucontext */
21 #include <sys/param.h>
23 #include <sys/types.h>
27 #include <sys/ucontext.h>
33 #include "interrupt.h"
37 #include <sys/socket.h>
38 #include <sys/utsname.h>
40 #include <sys/types.h>
42 /* #include <sys/sysinfo.h> */
47 #include <linux/unistd.h>
49 #include <linux/version.h>
50 #include "thread.h" /* dynamic_values_bytes */
53 size_t os_vm_page_size;
55 int arch_os_thread_init(struct thread *thread) {
57 #ifdef LISP_FEATURE_SB_THREAD
58 #ifdef LISP_FEATURE_GCC_TLS
59 current_thread = thread;
61 pthread_setspecific(specials,thread);
64 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
65 /* Signal handlers are run on the control stack, so if it is exhausted
66 * we had better use an alternate stack for whatever signal tells us
67 * we've exhausted it */
68 sigstack.ss_sp=((void *) thread)+dynamic_values_bytes;
70 sigstack.ss_size = 32*SIGSTKSZ;
71 if(sigaltstack(&sigstack,0)<0) {
72 lose("Cannot sigaltstack: %s\n",strerror(errno));
78 /* free any arch/os-specific resources used by thread, which is now
79 * defunct. Not called on live threads
82 int arch_os_thread_cleanup(struct thread *thread) {
87 os_context_register_t *
88 os_context_register_addr(os_context_t *context, int offset)
90 #define RCASE(name) case reg_ ## name: return &context->uc_mcontext.gregs[REG_ ## name];
110 return &context->uc_mcontext.gregs[offset/2+4];
113 return &context->uc_mcontext.gregs[offset];
116 os_context_register_t *
117 os_context_pc_addr(os_context_t *context)
119 return &context->uc_mcontext.gregs[REG_RIP]; /* REG_EIP */
122 os_context_register_t *
123 os_context_sp_addr(os_context_t *context)
125 return &context->uc_mcontext.gregs[REG_RSP];
128 os_context_register_t *
129 os_context_fp_addr(os_context_t *context)
131 return &context->uc_mcontext.gregs[REG_RBP];
135 os_context_fp_control(os_context_t *context)
137 /* return the x87 exception flags ored in with the sse2
138 * control+status flags */
139 unsigned int result = (context->uc_mcontext.fpregs->swd & 0x3F) | context->uc_mcontext.fpregs->mxcsr;
140 /* flip exception mask bits */
141 return result ^ (0x3F << 7);
145 os_context_sigmask_addr(os_context_t *context)
147 return &context->uc_sigmask;
151 os_restore_fp_control(os_context_t *context)
153 if (context->uc_mcontext.fpregs) {
154 /* reset exception flags and restore control flags on SSE2 FPU */
155 unsigned int temp = (context->uc_mcontext.fpregs->mxcsr) & ~0x3F;
156 asm ("ldmxcsr %0" : : "m" (temp));
157 /* same for x87 FPU. */
158 asm ("fldcw %0" : : "m" (context->uc_mcontext.fpregs->cwd));
163 os_flush_icache(os_vm_address_t address, os_vm_size_t length)