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 #ifdef LISP_FEATURE_GCC_TLS
60 current_thread
= thread
;
62 pthread_setspecific(specials
,thread
);
65 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
66 /* Signal handlers are run on the control stack, so if it is exhausted
67 * we had better use an alternate stack for whatever signal tells us
68 * we've exhausted it */
69 sigstack
.ss_sp
=((void *) thread
)+dynamic_values_bytes
;
71 sigstack
.ss_size
= 32*SIGSTKSZ
;
72 if(sigaltstack(&sigstack
,0)<0) {
73 lose("Cannot sigaltstack: %s\n",strerror(errno
));
79 /* free any arch/os-specific resources used by thread, which is now
80 * defunct. Not called on live threads
83 int arch_os_thread_cleanup(struct thread
*thread
) {
88 os_context_register_t
*
89 os_context_register_addr(os_context_t
*context
, int offset
)
91 #define RCASE(name) case reg_ ## name: return &context->uc_mcontext.gregs[REG_ ## name];
111 return &context
->uc_mcontext
.gregs
[offset
/2+4];
114 return &context
->uc_mcontext
.gregs
[offset
];
117 os_context_register_t
*
118 os_context_pc_addr(os_context_t
*context
)
120 return &context
->uc_mcontext
.gregs
[REG_RIP
]; /* REG_EIP */
123 os_context_register_t
*
124 os_context_sp_addr(os_context_t
*context
)
126 return &context
->uc_mcontext
.gregs
[REG_RSP
];
129 os_context_register_t
*
130 os_context_fp_addr(os_context_t
*context
)
132 return &context
->uc_mcontext
.gregs
[REG_RBP
];
136 os_context_fp_control(os_context_t
*context
)
138 /* return the x87 exception flags ored in with the sse2
139 * control+status flags */
140 unsigned int result
= (context
->uc_mcontext
.fpregs
->swd
& 0x3F) | context
->uc_mcontext
.fpregs
->mxcsr
;
141 /* flip exception mask bits */
142 return result
^ (0x3F << 7);
146 os_context_sigmask_addr(os_context_t
*context
)
148 return &context
->uc_sigmask
;
152 os_restore_fp_control(os_context_t
*context
)
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
));
162 os_flush_icache(os_vm_address_t address
, os_vm_size_t length
)