source: trunk/source/lisp-kernel/x86-exceptions.h @ 11250

Last change on this file since 11250 was 11250, checked in by gb, 13 years ago

Try to get xpMMXreg right on x862 Solaris. (It seems to be right
enough to find mm0 in the GC trap handler.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/*
2   Copyright (C) 2005 Clozure Associates
3   This file is part of OpenMCL. 
4
5   OpenMCL is licensed under the terms of the Lisp Lesser GNU Public
6   License , known as the LLGPL and distributed with OpenMCL as the
7   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,
8   which is distributed with OpenMCL as the file "LGPL".  Where these
9   conflict, the preamble takes precedence. 
10
11   OpenMCL is referenced in the preamble as the "LIBRARY."
12
13   The LLGPL is also available online at
14   http://opensource.franz.com/preamble.html
15*/
16
17#ifndef X86_EXCEPTIONS_H
18#define X86_EXCEPTIONS_H 1
19
20typedef u8_t opcode, *pc;
21
22#ifdef LINUX
23#define xpGPRvector(x) ((natural *)(&((x)->uc_mcontext.gregs)))
24#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
25#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
26#define xpPC(x) (xpGPR(x,Iip))
27#define xpMMXreg(x,n)  *((natural *)(&((x)->uc_mcontext.fpregs->_st[n])))
28#define eflags_register(xp) xpGPR(xp,Iflags)
29#endif
30
31#ifdef DARWIN
32#define DARWIN_USE_PSEUDO_SIGRETURN 1
33#include <sys/syscall.h>
34#define DarwinSigReturn(context) syscall(0x2000000|SYS_sigreturn,context,0x1e)
35#define xpGPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__ss)))
36#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
37#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
38#define xpPC(x) (xpGPR(x,Iip))
39#define eflags_register(xp) xpGPR(xp,Iflags)
40#define xpFPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__fs.__fpu_xmm0)))
41#define xpMMXvector(x) (&(UC_MCONTEXT(x)->__fs.__fpu_stmm0))
42/* Note that this yields only the lower half of the MMX reg on x8632 */
43#define xpMMXreg(x,n) *(natural *)&(xpMMXvector(x)[n])
44
45#include <mach/mach.h>
46#include <mach/mach_error.h>
47#include <mach/machine/thread_state.h>
48#include <mach/machine/thread_status.h>
49
50pthread_mutex_t *mach_exception_lock;
51
52#endif
53
54#ifdef FREEBSD
55#ifdef X8664
56#include <machine/fpu.h>
57#else
58#include <machine/npx.h>
59#endif
60#define xpGPRvector(x) ((natural *)(&((x)->uc_mcontext)))
61#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
62#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
63#define eflags_register(xp) xpGPR(xp,Iflags)
64#define xpPC(x) xpGPR(x,Iip)
65#ifdef X8664
66#define xpMMXreg(x,n) *((natural *)(&(((struct savefpu *)(&(x)->uc_mcontext.mc_fpstate))->sv_fp[n])))
67#define xpXMMregs(x)(&(((struct savefpu *)(&(x)->uc_mcontext.mc_fpstate))->sv_xmm[0]))
68#else
69#define xpMMXreg(x,n) *((natural *)(&(((struct savexmm *)(&(x)->uc_mcontext.mc_fpstate))->sv_fp[n])))
70#define xpXMMregs(x)(&(((struct savexmm *)(&(x)->uc_mcontext.mc_fpstate))->sv_xmm[0]))
71#endif
72#endif
73
74#ifdef SOLARIS
75#define xpGPRvector(x) ((x)->uc_mcontext.gregs)
76#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
77#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
78#define xpPC(x) xpGPR(x,Iip)
79#define eflags_register(xp) xpGPR(xp,Iflags)
80#define xpXMMregs(x)(&((x)->uc_mcontext.fpregs.fp_reg_set.fpchip_state.xmm[0]))
81#ifdef X8632
82#define xpMMXreg(x,n)*(natural *)(&(((struct fnsave_state *)(&(((x)->uc_mcontext.fpregs))))->f_st[n]))
83#endif
84#endif
85
86#ifdef WINDOWS
87#ifdef X8664
88#define xpGPRvector(x) ((DWORD64 *)(&(x)->Rax))
89#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
90#define xpPC(x) xpGPR(x,Iip)
91#define eflags_register(xp) xp->EFlags
92#else
93#define xpGPRvector(x) ((DWORD *)(&(x)->Edi))
94#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
95#define xpPC(x) xpGPR(x,Iip)
96#define eflags_register(xp) xp->EFlags
97#define xpFPRvector(x) ((natural *)(&(x->ExtendedRegisters[10*16])))
98#define xpMMXreg(x,n)  (*((u64_t *)(&(x->FloatSave.RegisterArea[10*(n)]))))
99#endif
100#endif
101
102#ifdef DARWIN
103#define SIGNAL_FOR_PROCESS_INTERRUPT SIGUSR1
104#endif
105#ifdef LINUX
106#define SIGNAL_FOR_PROCESS_INTERRUPT SIGPWR
107#endif
108#ifdef FREEBSD
109#define SIGNAL_FOR_PROCESS_INTERRUPT SIGEMT
110#endif
111#ifdef SOLARIS
112#define SIGNAL_FOR_PROCESS_INTERRUPT SIGUSR1
113#endif
114#ifdef WINDOWS
115#define SIGNAL_FOR_PROCESS_INTERRUPT SIGINT
116#ifndef SIGBUS
117#define SIGBUS 10
118#endif
119#ifndef CONTEXT_ALL
120#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS)
121#endif
122#endif
123
124
125
126void switch_to_foreign_stack(void*, ...);
127
128#define INTN_OPCODE 0xcd
129
130#define UUO_GC_TRAP    0xc4
131#define UUO_ALLOC_TRAP 0xc5
132#define UUO_DEBUG_TRAP 0xca
133#define UUO_DEBUG_TRAP_WITH_STRING 0xcd
134
135#define XUUO_OPCODE_0 0x0f
136#define XUUO_OPCODE_1 0x0b
137
138#define XUUO_TLB_TOO_SMALL 1
139#define XUUO_INTERRUPT_NOW 2
140#define XUUO_SUSPEND_NOW 3
141#define XUUO_INTERRUPT 4
142#define XUUO_SUSPEND 5
143#define XUUO_SUSPEND_ALL 6
144#define XUUO_RESUME 7
145#define XUUO_RESUME_ALL 8
146#define XUUO_KILL 9
147
148void
149pc_luser_xp(ExceptionInformation*, TCR*, signed_natural*);
150
151
152typedef enum {
153  ID_unrecognized_alloc_instruction,
154  ID_load_allocptr_reg_from_tcr_save_allocptr_instruction,
155  ID_compare_allocptr_reg_to_tcr_save_allocbase_instruction,
156  ID_branch_around_alloc_trap_instruction,
157  ID_alloc_trap_instruction,
158  ID_set_allocptr_header_instruction,
159  ID_clear_tcr_save_allocptr_tag_instruction
160} alloc_instruction_id;
161
162#ifdef LINUX
163#define SIGNUM_FOR_INTN_TRAP SIGSEGV
164#define IS_MAYBE_INT_TRAP(info,xp) (((info->si_code) &0x7f) == 0)
165#define SIGRETURN(context)
166#endif
167
168#ifdef FREEBSD
169extern void freebsd_sigreturn(ExceptionInformation *);
170#define SIGNUM_FOR_INTN_TRAP SIGBUS
171#define IS_MAYBE_INT_TRAP(info,xp) (xp->uc_mcontext.mc_trapno == T_PROTFLT)
172#define SIGRETURN(context) freebsd_sigreturn(context)
173#endif
174
175#ifdef DARWIN
176#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Not really, but our Mach handler fakes that */
177#define IS_MAYBE_INT_TRAP(info,xp) (info->si_code == EXC_I386_GPFLT)
178/* The x86 version of sigreturn just needs the context argument; the
179   hidden, magic "flavor" argument that sigtramp uses is ignored. */
180#define SIGRETURN(context) DarwinSigReturn(context)
181#endif
182
183#ifdef SOLARIS
184#define SIGNUM_FOR_INTN_TRAP SIGSEGV
185#ifdef X8664
186#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,REG_TRAPNO)==0xd)&&((xpGPR(xp,REG_ERR)&7)==2))
187#else
188#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,TRAPNO)==0xd)&&((xpGPR(xp,ERR)&7)==2))
189#endif
190#define SIGRETURN(context) setcontext(context)
191#endif
192
193#ifdef WINDOWS
194#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Also fake */
195#define IS_MAYBE_INT_TRAP(info,xp) \
196  ((info->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) &&       \
197   (info->ExceptionInformation[0]==0) &&                       \
198   (info->ExceptionInformation[1]==(ULONG_PTR)(-1L)))
199#define SIGRETURN(context)      /* for now */
200#endif
201
202/* Please go away. */
203#ifdef DARWIN_GS_HACK
204extern Boolean ensure_gs_pthread(void);
205extern void set_gs_address(void *);
206#endif
207
208
209/* sigaltstack isn't thread-specific on The World's Most Advanced OS */
210#ifdef DARWIN
211#undef USE_SIGALTSTACK
212#else
213#ifdef WINDOWS
214#undef USE_SIGALTSTACK
215#else
216#define USE_SIGALTSTACK 1
217#endif
218#endif
219
220#ifdef USE_SIGALTSTACK
221void setup_sigaltstack(area *);
222#endif
223
224/* recognizing the function associated with a tagged return address */
225/* now involves recognizinig an "(lea (@ disp (% rip)) (% rn))" */
226/* instruction at the tra */
227
228#define RECOVER_FN_FROM_RIP_LENGTH 7 /* the instruction is 7 bytes long */
229#define RECOVER_FN_FROM_RIP_DISP_OFFSET 3 /* displacement word is 3 bytes in */
230#define RECOVER_FN_FROM_RIP_WORD0 0x8d4c /* 0x4c 0x8d, little-endian */
231#define RECOVER_FN_FROM_RIP_BYTE2 0x2d  /* third byte of opcode */
232
233extern natural get_mxcsr();
234extern void set_mxcsr(natural);
235
236#ifdef WINDOWS
237typedef struct {
238  HANDLE h;
239  OVERLAPPED *o;
240} pending_io;
241#endif
242
243#ifdef X8632
244/* The 32-bit immediate value in the instruction
245 * "(mov ($ 0x12345678) (% fn))" at a tagged return address
246 * refers to the associated function.
247 */
248#define RECOVER_FN_OPCODE 0xbf
249#define RECOVER_FN_LENGTH 5
250#endif
251
252#endif /* X86_EXCEPTIONS_H */
253
Note: See TracBrowser for help on using the repository browser.