2 * The x86 Linux incarnation of arch-dependent OS-dependent routines.
3 * 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>
25 #include "genesis/sbcl.h"
29 #include "interrupt.h"
33 #include <sys/types.h>
35 /* #include <sys/sysinfo.h> */
40 #include <sys/syscall.h>
42 #include <linux/version.h>
43 #include "thread.h" /* dynamic_values_bytes */
45 static inline int set_thread_area(struct user_desc
*u_info
)
47 return syscall(SYS_set_thread_area
, u_info
);
52 int arch_os_thread_init(struct thread
*thread
) {
54 #ifdef LISP_FEATURE_SB_THREAD
55 struct user_desc desc
= {
56 0, (unsigned long) thread
,
57 (dynamic_values_bytes
>>12)-1,
61 static int entry_number
= -1;
63 desc
.entry_number
= entry_number
;
65 if (set_thread_area(&desc
) != 0) {
69 entry_number
= desc
.entry_number
;
71 __asm__
__volatile__ ("movw %w0, %%fs" : : "q"
72 ((entry_number
<< 3) + 3));
74 if(entry_number
< 0) return 0;
77 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
78 /* Signal handlers are run on the control stack, so if it is exhausted
79 * we had better use an alternate stack for whatever signal tells us
80 * we've exhausted it */
81 sigstack
.ss_sp
= calc_altstack_base(thread
);
82 sigstack
.ss_flags
= 0;
83 sigstack
.ss_size
= calc_altstack_size(thread
);
84 if(sigaltstack(&sigstack
,0)<0)
85 lose("Cannot sigaltstack: %s",strerror(errno
));
90 struct thread
*debug_get_fs() {
92 __asm__
__volatile__ ("movl %%fs,%0" : "=r" (fs
) : );
93 return (struct thread
*)fs
;
96 /* free any arch/os-specific resources used by thread, which is now
97 * defunct. Not called on live threads
100 int arch_os_thread_cleanup(struct thread
*thread
) {
106 /* KLUDGE: As of kernel 2.2.14 on Red Hat 6.2, there's code in the
107 * <sys/ucontext.h> file to define symbolic names for offsets into
108 * gregs[], but it's conditional on __USE_GNU and not defined, so
109 * we need to do this nasty absolute index magic number thing
111 os_context_register_t
*
112 os_context_register_addr(os_context_t
*context
, int offset
)
115 case reg_EAX
: return &context
->uc_mcontext
.gregs
[11];
116 case reg_ECX
: return &context
->uc_mcontext
.gregs
[10];
117 case reg_EDX
: return &context
->uc_mcontext
.gregs
[9];
118 case reg_EBX
: return &context
->uc_mcontext
.gregs
[8];
119 case reg_ESP
: return &context
->uc_mcontext
.gregs
[7];
120 case reg_EBP
: return &context
->uc_mcontext
.gregs
[6];
121 case reg_ESI
: return &context
->uc_mcontext
.gregs
[5];
122 case reg_EDI
: return &context
->uc_mcontext
.gregs
[4];
125 return &context
->uc_mcontext
.gregs
[offset
];
128 os_context_register_t
*
129 os_context_sp_addr(os_context_t
*context
)
131 return &context
->uc_mcontext
.gregs
[17]; /* REG_UESP */
134 os_context_register_t
*
135 os_context_fp_addr(os_context_t
*context
)
137 return &context
->uc_mcontext
.gregs
[6]; /* REG_EBP */
141 os_context_fp_control(os_context_t
*context
)
143 return ((((context
->uc_mcontext
.fpregs
->cw
) & 0xffff) ^ 0x3f) |
144 (((context
->uc_mcontext
.fpregs
->sw
) & 0xffff) << 16));
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 asm ("fldcw %0" : : "m" (context
->uc_mcontext
.fpregs
->cw
));
160 os_context_register_t
*
161 os_context_float_register_addr(os_context_t
*context
, int offset
)
163 return (os_context_register_t
*)&context
->uc_mcontext
.fpregs
->_st
[offset
];
167 os_flush_icache(os_vm_address_t address
, os_vm_size_t length
)
171 // To avoid "Missing required foreign symbol" errors in os_link_runtime()
172 // the executable must actually depend on libm. It would not require libm,
173 // despite -lm in the link step, if there is no reference to a libm symbol
174 // observable to the linker. Any one symbol suffices to resolve all of them.
176 const long libm_anchor
= (long)acos
;