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> */
46 #include <linux/unistd.h>
48 #include <linux/version.h>
49 #include "thread.h" /* dynamic_values_bytes */
52 size_t os_vm_page_size
;
54 int arch_os_thread_init(struct thread
*thread
) {
56 #ifdef LISP_FEATURE_SB_THREAD
57 #ifdef LISP_FEATURE_GCC_TLS
58 current_thread
= thread
;
60 pthread_setspecific(specials
,thread
);
63 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
64 /* Signal handlers are run on the control stack, so if it is exhausted
65 * we had better use an alternate stack for whatever signal tells us
66 * we've exhausted it */
67 sigstack
.ss_sp
=((char *) thread
)+dynamic_values_bytes
;
69 sigstack
.ss_size
= 32*SIGSTKSZ
;
70 if(sigaltstack(&sigstack
,0)<0) {
71 lose("Cannot sigaltstack: %s\n",strerror(errno
));
77 /* free any arch/os-specific resources used by thread, which is now
78 * defunct. Not called on live threads
81 int arch_os_thread_cleanup(struct thread
*thread
) {
86 os_context_register_t
*
87 os_context_register_addr(os_context_t
*context
, int offset
)
89 #define RCASE(name) case reg_ ## name: return \
90 (os_context_register_t*)&context->uc_mcontext.gregs[REG_ ## name];
110 return (os_context_register_t
*)&context
->uc_mcontext
.gregs
[offset
/2+4];
113 return (os_context_register_t
*)&context
->uc_mcontext
.gregs
[offset
];
116 os_context_register_t
*
117 os_context_pc_addr(os_context_t
*context
)
119 return (os_context_register_t
*)&context
->uc_mcontext
.gregs
[REG_RIP
]; /* REG_EIP */
122 os_context_register_t
*
123 os_context_sp_addr(os_context_t
*context
)
125 return (os_context_register_t
*)&context
->uc_mcontext
.gregs
[REG_RSP
];
128 os_context_register_t
*
129 os_context_fp_addr(os_context_t
*context
)
131 return (os_context_register_t
*)&context
->uc_mcontext
.gregs
[REG_RBP
];
135 os_context_fp_control(os_context_t
*context
)
137 return (uintptr_t)&context
->uc_mcontext
.gregs
[REG_RSP
];
141 os_context_register_t
*
142 os_context_float_register_addr(os_context_t
*context
, int offset
)
144 return (os_context_register_t
*)&context
->uc_mcontext
.fpregs
->_xmm
[offset
];
148 os_context_sigmask_addr(os_context_t
*context
)
150 return &context
->uc_sigmask
;
154 os_restore_fp_control(os_context_t
*context
)
156 if (context
->uc_mcontext
.fpregs
) {
157 /* reset exception flags and restore control flags on SSE2 FPU */
158 unsigned int temp
= (context
->uc_mcontext
.fpregs
->mxcsr
) & ~0x3F;
159 asm ("ldmxcsr %0" : : "m" (temp
));
160 /* same for x87 FPU. */
161 asm ("fldcw %0" : : "m" (context
->uc_mcontext
.fpregs
->cwd
));
166 os_flush_icache(os_vm_address_t address
, os_vm_size_t length
)