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

Last change on this file since 13206 was 13206, checked in by rme, 10 years ago

Changes to allow the Dawrin/x86 lisp kernels to build with the 10.5 SDK.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/*
2   Copyright (C) 2005-2009 Clozure Associates
3   This file is part of Clozure CL. 
4
5   Clozure CL is licensed under the terms of the Lisp Lesser GNU Public
6   License , known as the LLGPL and distributed with Clozure CL as the
7   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,
8   which is distributed with Clozure CL as the file "LGPL".  Where these
9   conflict, the preamble takes precedence. 
10
11   Clozure CL 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#define UUO_WATCH_TRAP 0xce
141  #define WATCH_TRAP_FUNCTION_WATCH 0
142  #define WATCH_TRAP_FUNCTION_UNWATCH 1
143
144#define XUUO_OPCODE_0 0x0f
145#define XUUO_OPCODE_1 0x0b
146
147#define XUUO_TLB_TOO_SMALL 1
148#define XUUO_INTERRUPT_NOW 2
149#define XUUO_SUSPEND_NOW 3
150#define XUUO_INTERRUPT 4
151#define XUUO_SUSPEND 5
152#define XUUO_SUSPEND_ALL 6
153#define XUUO_RESUME 7
154#define XUUO_RESUME_ALL 8
155#define XUUO_KILL 9
156#define XUUO_ALLOCATE_LIST 10
157
158void
159pc_luser_xp(ExceptionInformation*, TCR*, signed_natural*);
160
161
162typedef enum {
163  ID_unrecognized_alloc_instruction,
164  ID_load_allocptr_reg_from_tcr_save_allocptr_instruction,
165  ID_compare_allocptr_reg_to_tcr_save_allocbase_instruction,
166  ID_branch_around_alloc_trap_instruction,
167  ID_alloc_trap_instruction,
168  ID_set_allocptr_header_instruction,
169  ID_clear_tcr_save_allocptr_tag_instruction
170} alloc_instruction_id;
171
172#ifdef LINUX
173#define SIGNUM_FOR_INTN_TRAP SIGSEGV
174#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,REG_TRAPNO)==0xd)&&((xpGPR(xp,REG_ERR)&7)==2))
175#define IS_PAGE_FAULT(info,xp) (xpGPR(xp,REG_TRAPNO)==0xe)
176#define SIGRETURN(context)
177#endif
178
179#ifdef FREEBSD
180extern void freebsd_sigreturn(ExceptionInformation *);
181#define SIGNUM_FOR_INTN_TRAP SIGBUS
182#define IS_MAYBE_INT_TRAP(info,xp) ((xp->uc_mcontext.mc_trapno == T_PROTFLT) && ((xp->uc_mcontext.mc_err & 7) == 2))
183#define IS_PAGE_FAULT(info,xp) (xp->uc_mcontext.mc_trapno == T_PAGEFLT)
184#define SIGRETURN(context) freebsd_sigreturn(context)
185#endif
186
187#ifdef DARWIN
188#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Not really, but our Mach handler fakes that */
189#define IS_MAYBE_INT_TRAP(info,xp) ((UC_MCONTEXT(xp)->__es.__trapno == 0xd) && (((UC_MCONTEXT(xp)->__es.__err)&7)==2))
190#define IS_PAGE_FAULT(info,xp) (UC_MCONTEXT(xp)->__es.__trapno == 0xe)
191/* The x86 version of sigreturn just needs the context argument; the
192   hidden, magic "flavor" argument that sigtramp uses is ignored. */
193#define SIGRETURN(context) DarwinSigReturn(context)
194#endif
195
196#ifdef SOLARIS
197#define SIGNUM_FOR_INTN_TRAP SIGSEGV
198#ifdef X8664
199#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,REG_TRAPNO)==0xd)&&((xpGPR(xp,REG_ERR)&7)==2))
200#define IS_PAGE_FAULT(info,xp) (xpGPR(xp,REG_TRAPNO)==0xe)
201#else
202#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,TRAPNO)==0xd)&&((xpGPR(xp,ERR)&7)==2))
203#define IS_PAGE_FAULT(info,xp) (xpGPR(xp,TRAPNO)==0xe)
204#endif
205#define SIGRETURN(context) setcontext(context)
206#endif
207
208#ifdef WINDOWS
209#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Also fake */
210#define IS_MAYBE_INT_TRAP(info,xp) \
211  ((info->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) &&       \
212   (info->ExceptionInformation[0]==0) &&                       \
213   (info->ExceptionInformation[1]==(ULONG_PTR)(-1L)))
214#define IS_PAGE_FAULT(info,xp) (1)
215#define SIGRETURN(context)      /* for now */
216#endif
217
218/* Please go away. */
219#ifdef DARWIN_GS_HACK
220extern Boolean ensure_gs_pthread(void);
221extern void set_gs_address(void *);
222#endif
223
224
225/* sigaltstack isn't thread-specific on The World's Most Advanced OS */
226#ifdef DARWIN
227#undef USE_SIGALTSTACK
228#else
229#ifdef WINDOWS
230#undef USE_SIGALTSTACK
231#else
232#define USE_SIGALTSTACK 1
233#endif
234#endif
235
236#ifdef USE_SIGALTSTACK
237void setup_sigaltstack(area *);
238#endif
239
240/* recognizing the function associated with a tagged return address */
241/* now involves recognizinig an "(lea (@ disp (% rip)) (% rn))" */
242/* instruction at the tra */
243
244#define RECOVER_FN_FROM_RIP_LENGTH 7 /* the instruction is 7 bytes long */
245#define RECOVER_FN_FROM_RIP_DISP_OFFSET 3 /* displacement word is 3 bytes in */
246#define RECOVER_FN_FROM_RIP_WORD0 0x8d4c /* 0x4c 0x8d, little-endian */
247#define RECOVER_FN_FROM_RIP_BYTE2 0x2d  /* third byte of opcode */
248
249extern natural get_mxcsr();
250extern void set_mxcsr(natural);
251
252#ifdef WINDOWS
253typedef struct {
254  HANDLE h;
255  OVERLAPPED *o;
256} pending_io;
257#endif
258
259#ifdef X8632
260/* The 32-bit immediate value in the instruction
261 * "(mov ($ 0x12345678) (% fn))" at a tagged return address
262 * refers to the associated function.
263 */
264#define RECOVER_FN_OPCODE 0xbf
265#define RECOVER_FN_LENGTH 5
266#endif
267
268#endif /* X86_EXCEPTIONS_H */
269
Note: See TracBrowser for help on using the repository browser.