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

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

32-bit Solaris x86 changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 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)(((x)->uc_mcontext.fpregs.fp_reg_set.fpchip_state.state[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#define IS_MAYBE_INT_TRAP(info,xp) ((xpGPR(xp,REG_TRAPNO)==0xd)&&((xpGPR(xp,REG_ERR)&7)==2))
186#define SIGRETURN(context) setcontext(context)
187#endif
188
189#ifdef WINDOWS
190#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Also fake */
191#define IS_MAYBE_INT_TRAP(info,xp) \
192  ((info->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) &&       \
193   (info->ExceptionInformation[0]==0) &&                       \
194   (info->ExceptionInformation[1]==(ULONG_PTR)(-1L)))
195#define SIGRETURN(context)      /* for now */
196#endif
197
198/* Please go away. */
199#ifdef DARWIN_GS_HACK
200extern Boolean ensure_gs_pthread(void);
201extern void set_gs_address(void *);
202#endif
203
204
205/* sigaltstack isn't thread-specific on The World's Most Advanced OS */
206#ifdef DARWIN
207#undef USE_SIGALTSTACK
208#else
209#ifdef WINDOWS
210#undef USE_SIGALTSTACK
211#else
212#define USE_SIGALTSTACK 1
213#endif
214#endif
215
216#ifdef USE_SIGALTSTACK
217void setup_sigaltstack(area *);
218#endif
219
220/* recognizing the function associated with a tagged return address */
221/* now involves recognizinig an "(lea (@ disp (% rip)) (% rn))" */
222/* instruction at the tra */
223
224#define RECOVER_FN_FROM_RIP_LENGTH 7 /* the instruction is 7 bytes long */
225#define RECOVER_FN_FROM_RIP_DISP_OFFSET 3 /* displacement word is 3 bytes in */
226#define RECOVER_FN_FROM_RIP_WORD0 0x8d4c /* 0x4c 0x8d, little-endian */
227#define RECOVER_FN_FROM_RIP_BYTE2 0x2d  /* third byte of opcode */
228
229extern natural get_mxcsr();
230extern void set_mxcsr(natural);
231
232#ifdef WINDOWS
233typedef struct {
234  HANDLE h;
235  OVERLAPPED *o;
236} pending_io;
237#endif
238
239#ifdef X8632
240/* The 32-bit immediate value in the instruction
241 * "(mov ($ 0x12345678) (% fn))" at a tagged return address
242 * refers to the associated function.
243 */
244#define RECOVER_FN_OPCODE 0xbf
245#define RECOVER_FN_LENGTH 5
246#endif
247
248#endif /* X86_EXCEPTIONS_H */
249
Note: See TracBrowser for help on using the repository browser.