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

Last change on this file since 10195 was 10195, checked in by gb, 12 years ago

Better IS_MAYBE_INT_TRAP for Solaris.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 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
17typedef u8_t opcode, *pc;
18
19#ifdef LINUX
20#ifdef X8664
21#define xpGPRvector(x) ((natural *)(&((x)->uc_mcontext.gregs)))
22#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
23#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
24#define xpPC(x) (xpGPR(x,Iip))
25#define xpMMXreg(x,n)  *((natural *)(&((x)->uc_mcontext.fpregs->_st[n])))
26#endif
27#endif
28
29#ifdef DARWIN
30#define DARWIN_USE_PSEUDO_SIGRETURN 1
31#include <sys/syscall.h>
32#define DarwinSigReturn(context) syscall(0x2000000|SYS_sigreturn,context,0x1e)
33#ifdef X8664
34#define xpGPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__ss.__rax)))
35#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
36#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
37#define xpPC(x) (xpGPR(x,Iip))
38#define xpFPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__fs.__fpu_xmm0)))
39#define xpMMXreg(x,n)  (xpFPRvector(x)[n])
40#else /* X8632 */
41#define xpGPRvector(x) ((natural *)(&((x)->uc_mcontext->__ss.__eax)))
42#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
43#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
44#define xpPC(x) (xpGPR(x,Iip))
45#define xpFPRvector(x) ((natural *)(&((x)->uc_mcontext->__fs.__fpu_xmm0)))
46/* are you ready for this? */
47#define xpMMXreg(x,n) *((natural *)&((&((x)->uc_mcontext->__fs.__fpu_stmm0))[n]))
48#endif
49#include <mach/mach.h>
50#include <mach/mach_error.h>
51#include <mach/machine/thread_state.h>
52#include <mach/machine/thread_status.h>
53
54pthread_mutex_t *mach_exception_lock;
55
56#endif
57
58#ifdef FREEBSD
59#ifdef X8664
60#include <machine/fpu.h>
61#define xpGPRvector(x) ((natural *)(&((x)->uc_mcontext)))
62#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
63#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
64#define xpPC(x) xpGPR(x,Iip)
65#define xpMMXreg(x,n) *((natural *)(&(((struct savefpu *)(&(x)->uc_mcontext.mc_fpstate))->sv_fp[n])))
66#define xpXMMregs(x)(&(((struct savefpu *)(&(x)->uc_mcontext.mc_fpstate))->sv_xmm[0]))
67#endif
68#endif
69
70#ifdef SOLARIS
71#ifdef X8664
72#define xpGPRvector(x) ((x)->uc_mcontext.gregs)
73#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
74#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
75#define xpPC(x) xpGPR(x,Iip)
76#define xpXMMregs(x)(&((x)->uc_mcontext.fpregs.fp_reg_set.fpchip_state.xmm[0]))
77#endif
78#endif
79
80#ifdef WIN64
81#define xpGPRvector(x) ((DWORD64 *)((x)->ContextRecord))
82#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
83#define xpPC(x) xpGPR(x,Iip)
84#endif
85
86#ifdef DARWIN
87#define SIGNAL_FOR_PROCESS_INTERRUPT SIGUSR1
88#endif
89#ifdef LINUX
90#define SIGNAL_FOR_PROCESS_INTERRUPT SIGPWR
91#endif
92#ifdef FREEBSD
93#define SIGNAL_FOR_PROCESS_INTERRUPT SIGEMT
94#endif
95#ifdef SOLARIS
96#define SIGNAL_FOR_PROCESS_INTERRUPT SIGUSR1
97#endif
98
99
100void switch_to_foreign_stack(void*, ...);
101
102#define INTN_OPCODE 0xcd
103
104#define UUO_GC_TRAP    0xc4
105#define UUO_ALLOC_TRAP 0xc5
106#define UUO_DEBUG_TRAP 0xca
107#define UUO_DEBUG_TRAP_WITH_STRING 0xcd
108
109#define XUUO_OPCODE_0 0x0f
110#define XUUO_OPCODE_1 0x0b
111
112#define XUUO_TLB_TOO_SMALL 1
113#define XUUO_INTERRUPT_NOW 2
114#define XUUO_SUSPEND_NOW 3
115#define XUUO_INTERRUPT 4
116#define XUUO_SUSPEND 5
117#define XUUO_SUSPEND_ALL 6
118#define XUUO_RESUME 7
119#define XUUO_RESUME_ALL 8
120
121void
122pc_luser_xp(ExceptionInformation*, TCR*, signed_natural*);
123
124
125typedef enum {
126  ID_unrecognized_alloc_instruction,
127  ID_load_allocptr_reg_from_tcr_save_allocptr_instruction,
128  ID_compare_allocptr_reg_to_tcr_save_allocbase_instruction,
129  ID_branch_around_alloc_trap_instruction,
130  ID_alloc_trap_instruction,
131  ID_set_allocptr_header_instruction,
132  ID_clear_tcr_save_allocptr_tag_instruction
133} alloc_instruction_id;
134
135#ifdef LINUX
136#define SIGNUM_FOR_INTN_TRAP SIGSEGV
137#define IS_MAYBE_INT_TRAP(info,xp) (((info->si_code) &0x7f) == 0)
138#define SIGRETURN(context)
139#endif
140
141#ifdef FREEBSD
142extern void freebsd_sigreturn(ExceptionInformation *);
143#define SIGNUM_FOR_INTN_TRAP SIGBUS
144#define IS_MAYBE_INT_TRAP(info,xp) (xp->uc_mcontext.mc_trapno == T_PROTFLT)
145#define SIGRETURN(context) freebsd_sigreturn(context)
146#endif
147
148#ifdef DARWIN
149#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Not really, but our Mach handler fakes that */
150#define IS_MAYBE_INT_TRAP(info,xp) (info->si_code == EXC_I386_GPFLT)
151/* The x86 version of sigreturn just needs the context argument; the
152   hidden, magic "flavor" argument that sigtramp uses is ignored. */
153#define SIGRETURN(context) DarwinSigReturn(context)
154#endif
155
156#ifdef SOLARIS
157#define SIGNUM_FOR_INTN_TRAP SIGSEGV
158#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,REG_TRAPNO)==0xd)&&((xpGPR(xp,REG_ERR)&7)==2))
159#define SIGRETURN(context) setcontext(context)
160#endif
161
162/* Please go away. */
163#ifdef DARWIN_GS_HACK
164extern Boolean ensure_gs_pthread(void);
165extern void set_gs_address(void *);
166#endif
167
168
169/* sigaltstack isn't thread-specific on The World's Most Advanced OS */
170#ifdef DARWIN
171#undef USE_SIGALTSTACK
172#else
173#ifdef WINDOWS
174#undef USE_SIGALTSTACK
175#else
176#define USE_SIGALTSTACK 1
177#endif
178#endif
179
180#ifdef USE_SIGALTSTACK
181void setup_sigaltstack(area *);
182#endif
183
184/* recognizing the function associated with a tagged return address */
185/* now involves recognizinig an "(lea (@ disp (% rip)) (% rn))" */
186/* instruction at the tra */
187
188#define RECOVER_FN_FROM_RIP_LENGTH 7 /* the instruction is 7 bytes long */
189#define RECOVER_FN_FROM_RIP_DISP_OFFSET 3 /* displacement word is 3 bytes in */
190#define RECOVER_FN_FROM_RIP_WORD0 0x8d4c /* 0x4c 0x8d, little-endian */
191#define RECOVER_FN_FROM_RIP_BYTE2 0x2d  /* third byte of opcode */
192
193extern natural get_mxcsr();
194extern void set_mxcsr(natural);
195
196#ifdef X8632
197/* The 32-bit immediate value in the instruction
198 * "(mov ($ 0x12345678) (% fn))" at a tagged return address
199 * refers to the associated function.
200 */
201#define RECOVER_FN_OPCODE 0xbf
202#define RECOVER_FN_LENGTH 5
203#endif
Note: See TracBrowser for help on using the repository browser.