[c06b8c]: src / runtime / x86-64-bsd-os.c Maximize Restore History

Download this file

x86-64-bsd-os.c    213 lines (193 with data), 5.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include <signal.h>
#include "sbcl.h"
#include "runtime.h"
#include "thread.h"
#include "lispregs.h"
#if defined(LISP_FEATURE_FREEBSD)
#include <machine/fpu.h>
#endif
#if defined(LISP_FEATURE_OPENBSD)
#include <machine/fpu.h>
#endif
#if defined(LISP_FEATURE_DRAGONFLY)
#include <machine/npx.h>
#endif
/* KLUDGE: There is strong family resemblance in the signal context
* stuff in FreeBSD and OpenBSD, but in detail they're different in
* almost every line of code. It would be nice to find some way to
* factor out the commonality better; failing that, it might be best
* just to split this generic-BSD code into one variant for each BSD.
*
* KLUDGE II: this split has begun with the addition of the Darwin BSD
* flavour, with the cross-architecture complications that this
* entails; unfortunately, currently the situation is worse, not
* better, than in the above paragraph. */
#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DARWIN) || defined(LISP_FEATURE_OPENBSD) || defined(LISP_FEATURE_DRAGONFLY)
os_context_register_t *
os_context_register_addr(os_context_t *context, int offset)
{
switch(offset) {
case reg_RAX:
return CONTEXT_ADDR_FROM_STEM(rax);
case reg_RCX:
return CONTEXT_ADDR_FROM_STEM(rcx);
case reg_RDX:
return CONTEXT_ADDR_FROM_STEM(rdx);
case reg_RBX:
return CONTEXT_ADDR_FROM_STEM(rbx);
case reg_RSP:
return CONTEXT_ADDR_FROM_STEM(rsp);
case reg_RBP:
return CONTEXT_ADDR_FROM_STEM(rbp);
case reg_RSI:
return CONTEXT_ADDR_FROM_STEM(rsi);
case reg_RDI:
return CONTEXT_ADDR_FROM_STEM(rdi);
case reg_R8:
return CONTEXT_ADDR_FROM_STEM(r8);
case reg_R9:
return CONTEXT_ADDR_FROM_STEM(r9);
case reg_R10:
return CONTEXT_ADDR_FROM_STEM(r10);
case reg_R11:
return CONTEXT_ADDR_FROM_STEM(r11);
case reg_R12:
return CONTEXT_ADDR_FROM_STEM(r12);
case reg_R13:
return CONTEXT_ADDR_FROM_STEM(r13);
case reg_R14:
return CONTEXT_ADDR_FROM_STEM(r14);
case reg_R15:
return CONTEXT_ADDR_FROM_STEM(r15);
default:
return 0;
}
}
os_context_register_t *
os_context_sp_addr(os_context_t *context)
{
return CONTEXT_ADDR_FROM_STEM(rsp);
}
os_context_register_t *
os_context_pc_addr(os_context_t *context)
{
return CONTEXT_ADDR_FROM_STEM(rip);
}
#elif defined(LISP_FEATURE_NETBSD)
os_context_register_t *
os_context_register_addr(os_context_t *context, int offset)
{
switch(offset) {
case reg_RAX:
return CONTEXT_ADDR_FROM_STEM(RAX);
case reg_RCX:
return CONTEXT_ADDR_FROM_STEM(RCX);
case reg_RDX:
return CONTEXT_ADDR_FROM_STEM(RDX);
case reg_RBX:
return CONTEXT_ADDR_FROM_STEM(RBX);
case reg_RSP:
return CONTEXT_ADDR_FROM_STEM(RSP);
case reg_RBP:
return CONTEXT_ADDR_FROM_STEM(RBP);
case reg_RSI:
return CONTEXT_ADDR_FROM_STEM(RSI);
case reg_RDI:
return CONTEXT_ADDR_FROM_STEM(RDI);
case reg_R8:
return CONTEXT_ADDR_FROM_STEM(R8);
case reg_R9:
return CONTEXT_ADDR_FROM_STEM(R9);
case reg_R10:
return CONTEXT_ADDR_FROM_STEM(R10);
case reg_R11:
return CONTEXT_ADDR_FROM_STEM(R11);
case reg_R12:
return CONTEXT_ADDR_FROM_STEM(R12);
case reg_R13:
return CONTEXT_ADDR_FROM_STEM(R13);
case reg_R14:
return CONTEXT_ADDR_FROM_STEM(R14);
case reg_R15:
return CONTEXT_ADDR_FROM_STEM(R15);
default:
return 0;
}
}
os_context_register_t *
os_context_sp_addr(os_context_t *context)
{
return CONTEXT_ADDR_FROM_STEM(RSP);
}
os_context_register_t *
os_context_pc_addr(os_context_t *context)
{
return CONTEXT_ADDR_FROM_STEM(RIP);
}
#endif
void
os_flush_icache(os_vm_address_t address, os_vm_size_t length)
{
}
int arch_os_thread_init(struct thread *thread) {
stack_t sigstack;
#ifdef LISP_FEATURE_SB_THREAD
#ifdef LISP_FEATURE_GCC_TLS
current_thread = thread;
#else
pthread_setspecific(specials,thread);
#endif
#endif
#ifdef LISP_FEATURE_MACH_EXCEPTION_HANDLER
mach_lisp_thread_init(thread);
#endif
#ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
/* Signal handlers are run on the control stack, so if it is exhausted
* we had better use an alternate stack for whatever signal tells us
* we've exhausted it */
sigstack.ss_sp=((void *) thread)+dynamic_values_bytes;
sigstack.ss_flags=0;
sigstack.ss_size = 32*SIGSTKSZ;
sigaltstack(&sigstack,0);
#endif
return 1; /* success */
}
int arch_os_thread_cleanup(struct thread *thread) {
return 1; /* success */
}
#if defined(LISP_FEATURE_DRAGONFLY)
void
os_restore_fp_control(os_context_t *context)
{
struct envxmm *ex = (struct envxmm*)(&context->uc_mcontext.mc_fpregs);
/* reset exception flags and restore control flags on SSE2 FPU */
unsigned int temp = (ex->en_mxcsr) & ~0x3F;
asm ("ldmxcsr %0" : : "m" (temp));
/* same for x87 FPU. */
asm ("fldcw %0" : : "m" (ex->en_cw));
}
#endif
#if defined(LISP_FEATURE_FREEBSD)
void
os_restore_fp_control(os_context_t *context)
{
struct envxmm *ex = (struct envxmm*)(&context->uc_mcontext.mc_fpstate);
/* reset exception flags and restore control flags on SSE2 FPU */
unsigned int temp = (ex->en_mxcsr) & ~0x3F;
asm ("ldmxcsr %0" : : "m" (temp));
/* same for x87 FPU. */
asm ("fldcw %0" : : "m" (ex->en_cw));
}
#endif
#if defined(LISP_FEATURE_OPENBSD)
void
os_restore_fp_control(os_context_t *context)
{
if (context->sc_fpstate != NULL) {
u_int32_t mxcsr = context->sc_fpstate->fx_mxcsr & ~0x3F;
u_int16_t cw = context->sc_fpstate->fx_fcw;
asm ("ldmxcsr %0" : : "m" (mxcsr));
asm ("fldcw %0" : : "m" (cw));
}
}
#endif