source: release/1.3/source/lisp-kernel/x86-exceptions.h @ 11927

Last change on this file since 11927 was 11927, checked in by rme, 11 years ago

Merge trunk changes r11863 through r11898.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 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) do {\
35    darwin_sigreturn(context);\
36    Bug(context,"sigreturn returned");\
37  } while (0)
38
39#define xpGPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__ss)))
40#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
41#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
42#define xpPC(x) (xpGPR(x,Iip))
43#define eflags_register(xp) xpGPR(xp,Iflags)
44#define xpFPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__fs.__fpu_xmm0)))
45#define xpMMXvector(x) (&(UC_MCONTEXT(x)->__fs.__fpu_stmm0))
46/* Note that this yields only the lower half of the MMX reg on x8632 */
47#define xpMMXreg(x,n) *(natural *)&(xpMMXvector(x)[n])
48
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#else
62#include "freebsdx8632/fpu.h"
63#endif
64#define xpGPRvector(x) ((natural *)(&((x)->uc_mcontext)))
65#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
66#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
67#define eflags_register(xp) xpGPR(xp,Iflags)
68#define xpPC(x) xpGPR(x,Iip)
69#ifdef X8664
70#define xpMMXreg(x,n) *((natural *)(&(((struct savefpu *)(&(x)->uc_mcontext.mc_fpstate))->sv_fp[n])))
71#define xpXMMregs(x)(&(((struct savefpu *)(&(x)->uc_mcontext.mc_fpstate))->sv_xmm[0]))
72#else
73#define xpMMXreg(x,n) *((natural *)(&(((struct ccl_savexmm *)(&(x)->uc_mcontext.mc_fpstate))->sv_fp[n])))
74#define xpXMMregs(x)(&(((struct ccl_savexmm *)(&(x)->uc_mcontext.mc_fpstate))->sv_xmm[0]))
75#endif
76#endif
77
78#ifdef SOLARIS
79#define xpGPRvector(x) ((x)->uc_mcontext.gregs)
80#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
81#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
82#define xpPC(x) xpGPR(x,Iip)
83#define eflags_register(xp) xpGPR(xp,Iflags)
84#define xpXMMregs(x)(&((x)->uc_mcontext.fpregs.fp_reg_set.fpchip_state.xmm[0]))
85#ifdef X8632
86#define xpMMXreg(x,n)*(natural *)(&(((struct fnsave_state *)(&(((x)->uc_mcontext.fpregs))))->f_st[n]))
87#endif
88#endif
89
90#ifdef WINDOWS
91#ifdef X8664
92#define xpGPRvector(x) ((DWORD64 *)(&(x)->Rax))
93#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
94#define xpPC(x) xpGPR(x,Iip)
95#define eflags_register(xp) xp->EFlags
96#define xpMXCSRptr(x) (DWORD *)(&(x->MxCsr))
97#else
98#define xpGPRvector(x) ((DWORD *)(&(x)->Edi))
99#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
100#define xpPC(x) xpGPR(x,Iip)
101#define eflags_register(xp) xp->EFlags
102#define xpFPRvector(x) ((natural *)(&(x->ExtendedRegisters[10*16])))
103#define xpMMXreg(x,n)  (*((u64_t *)(&(x->FloatSave.RegisterArea[10*(n)]))))
104#define xpMXCSRptr(x) (DWORD *)(&(x->ExtendedRegisters[24]))
105#endif
106#endif
107
108#ifdef DARWIN
109#define SIGNAL_FOR_PROCESS_INTERRUPT SIGUSR1
110#endif
111#ifdef LINUX
112#define SIGNAL_FOR_PROCESS_INTERRUPT SIGPWR
113#endif
114#ifdef FREEBSD
115#define SIGNAL_FOR_PROCESS_INTERRUPT SIGEMT
116#endif
117#ifdef SOLARIS
118#define SIGNAL_FOR_PROCESS_INTERRUPT SIGUSR1
119#endif
120#ifdef WINDOWS
121#define SIGNAL_FOR_PROCESS_INTERRUPT SIGINT
122#ifndef SIGBUS
123#define SIGBUS 10
124#endif
125#ifndef CONTEXT_ALL
126#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS)
127#endif
128#endif
129
130
131
132void switch_to_foreign_stack(void*, ...);
133
134#define INTN_OPCODE 0xcd
135
136#define UUO_GC_TRAP    0xc4
137#define UUO_ALLOC_TRAP 0xc5
138#define UUO_DEBUG_TRAP 0xca
139#define UUO_DEBUG_TRAP_WITH_STRING 0xcd
140
141#define XUUO_OPCODE_0 0x0f
142#define XUUO_OPCODE_1 0x0b
143
144#define XUUO_TLB_TOO_SMALL 1
145#define XUUO_INTERRUPT_NOW 2
146#define XUUO_SUSPEND_NOW 3
147#define XUUO_INTERRUPT 4
148#define XUUO_SUSPEND 5
149#define XUUO_SUSPEND_ALL 6
150#define XUUO_RESUME 7
151#define XUUO_RESUME_ALL 8
152#define XUUO_KILL 9
153#define XUUO_ALLOCATE_LIST 10
154
155void
156pc_luser_xp(ExceptionInformation*, TCR*, signed_natural*);
157
158
159typedef enum {
160  ID_unrecognized_alloc_instruction,
161  ID_load_allocptr_reg_from_tcr_save_allocptr_instruction,
162  ID_compare_allocptr_reg_to_tcr_save_allocbase_instruction,
163  ID_branch_around_alloc_trap_instruction,
164  ID_alloc_trap_instruction,
165  ID_set_allocptr_header_instruction,
166  ID_clear_tcr_save_allocptr_tag_instruction
167} alloc_instruction_id;
168
169#ifdef LINUX
170#define SIGNUM_FOR_INTN_TRAP SIGSEGV
171#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,REG_TRAPNO)==0xd)&&((xpGPR(xp,REG_ERR)&7)==2))
172#define IS_PAGE_FAULT(info,xp) (xpGPR(xp,REG_TRAPNO)==0xe)
173#define SIGRETURN(context)
174#endif
175
176#ifdef FREEBSD
177extern void freebsd_sigreturn(ExceptionInformation *);
178#define SIGNUM_FOR_INTN_TRAP SIGBUS
179#define IS_MAYBE_INT_TRAP(info,xp) ((xp->uc_mcontext.mc_trapno == T_PROTFLT) && ((xp->uc_mcontext.mc_err & 7) == 2))
180#define IS_PAGE_FAULT(info,xp) (xp->uc_mcontext.mc_trapno == T_PAGEFLT)
181#define SIGRETURN(context) freebsd_sigreturn(context)
182#endif
183
184#ifdef DARWIN
185#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Not really, but our Mach handler fakes that */
186#define IS_MAYBE_INT_TRAP(info,xp) ((UC_MCONTEXT(xp)->__es.trapno == 0xd) && (((UC_MCONTEXT(xp)->__es.err)&7)==2))
187#define IS_PAGE_FAULT(info,xp) (UC_MCONTEXT(xp)->__es.trapno == 0xe)
188/* The x86 version of sigreturn just needs the context argument; the
189   hidden, magic "flavor" argument that sigtramp uses is ignored. */
190#define SIGRETURN(context) DarwinSigReturn(context)
191#endif
192
193#ifdef SOLARIS
194#define SIGNUM_FOR_INTN_TRAP SIGSEGV
195#ifdef X8664
196#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,REG_TRAPNO)==0xd)&&((xpGPR(xp,REG_ERR)&7)==2))
197#define IS_PAGE_FAULT(info,xp) (xpGPR(xp,REG_TRAPNO)==0xe)
198#else
199#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,TRAPNO)==0xd)&&((xpGPR(xp,ERR)&7)==2))
200#define IS_PAGE_FAULT(info,xp) (xpGPR(xp,TRAPNO)==0xe)
201#endif
202#define SIGRETURN(context) setcontext(context)
203#endif
204
205#ifdef WINDOWS
206#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Also fake */
207#define IS_MAYBE_INT_TRAP(info,xp) \
208  ((info->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) &&       \
209   (info->ExceptionInformation[0]==0) &&                       \
210   (info->ExceptionInformation[1]==(ULONG_PTR)(-1L)))
211#define IS_PAGE_FAULT(info,xp) (1)
212#define SIGRETURN(context)      /* for now */
213#endif
214
215/* Please go away. */
216#ifdef DARWIN_GS_HACK
217extern Boolean ensure_gs_pthread(void);
218extern void set_gs_address(void *);
219#endif
220
221
222/* sigaltstack isn't thread-specific on The World's Most Advanced OS */
223#ifdef DARWIN
224#undef USE_SIGALTSTACK
225#else
226#ifdef WINDOWS
227#undef USE_SIGALTSTACK
228#else
229#define USE_SIGALTSTACK 1
230#endif
231#endif
232
233#ifdef USE_SIGALTSTACK
234void setup_sigaltstack(area *);
235#endif
236
237/* recognizing the function associated with a tagged return address */
238/* now involves recognizinig an "(lea (@ disp (% rip)) (% rn))" */
239/* instruction at the tra */
240
241#define RECOVER_FN_FROM_RIP_LENGTH 7 /* the instruction is 7 bytes long */
242#define RECOVER_FN_FROM_RIP_DISP_OFFSET 3 /* displacement word is 3 bytes in */
243#define RECOVER_FN_FROM_RIP_WORD0 0x8d4c /* 0x4c 0x8d, little-endian */
244#define RECOVER_FN_FROM_RIP_BYTE2 0x2d  /* third byte of opcode */
245
246extern natural get_mxcsr();
247extern void set_mxcsr(natural);
248
249#ifdef WINDOWS
250typedef struct {
251  HANDLE h;
252  OVERLAPPED *o;
253} pending_io;
254#endif
255
256#ifdef X8632
257/* The 32-bit immediate value in the instruction
258 * "(mov ($ 0x12345678) (% fn))" at a tagged return address
259 * refers to the associated function.
260 */
261#define RECOVER_FN_OPCODE 0xbf
262#define RECOVER_FN_LENGTH 5
263#endif
264
265#endif /* X86_EXCEPTIONS_H */
266
Note: See TracBrowser for help on using the repository browser.