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

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

Merge changes from branches/win64.

As well as the expected low-level exception/suspend/interrupt stuff,
these changes also include changes to [f]printf format strings. Note
that on win64, a 'long' is 32-bits wide, which complicates matters:

  • an address (viewed as an integer) or a natural-sized integer isn't

(portably) a long, and so can't be printed with %l.

  • an address (viewed as an integer) or a natural-sized integer isn't

(portably) a long long, and so can't be printed with %ll.

  • an address (viewed as an integer) or a natural-sized integer can be

portably printed with '%p', but implementations differ as to whether
or not '%p' prepends a gratuitous '0x' to the hex address. (Linux
does, other current platforms seem not to.)

The approach that seems to work is to cast arguments to natural, then
to u64_t, then use %ll. That approach probably isn't taken consistently
(yet), so some debugging information printed by the kernel may be
incorrect.

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