source: branches/working-0711/ccl/lisp-kernel/x86-exceptions.h @ 11089

Last change on this file since 11089 was 11089, checked in by gz, 13 years ago

Merge/bootstrap assorted low level stuff from trunk - kernel, syscall stuff, lowmem-bias, formatting tweaks, a few bug fixes included

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