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

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

More win64 stuff. Move along, nothing to see here.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 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
17typedef u8_t opcode, *pc;
18
19#ifdef LINUX
20#ifdef X8664
21#define xpGPRvector(x) ((natural *)(&((x)->uc_mcontext.gregs)))
22#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
23#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
24#define xpPC(x) (xpGPR(x,Iip))
25#define xpMMXreg(x,n)  *((natural *)(&((x)->uc_mcontext.fpregs->_st[n])))
26#endif
27#endif
28
29#ifdef DARWIN
30#define DARWIN_USE_PSEUDO_SIGRETURN 1
31#include <sys/syscall.h>
32#define DarwinSigReturn(context) syscall(0x2000000|SYS_sigreturn,context,0x1e)
33#ifdef X8664
34#define xpGPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__ss.__rax)))
35#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
36#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
37#define xpPC(x) (xpGPR(x,Iip))
38#define xpFPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__fs.__fpu_xmm0)))
39#define xpMMXreg(x,n)  (xpFPRvector(x)[n])
40#endif
41#include <mach/mach.h>
42#include <mach/mach_error.h>
43#include <mach/machine/thread_state.h>
44#include <mach/machine/thread_status.h>
45
46pthread_mutex_t *mach_exception_lock;
47
48#endif
49
50#ifdef FREEBSD
51#ifdef X8664
52#include <machine/fpu.h>
53#define xpGPRvector(x) ((natural *)(&((x)->uc_mcontext)))
54#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
55#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
56#define xpPC(x) xpGPR(x,Iip)
57#define xpMMXreg(x,n) *((natural *)(&(((struct savefpu *)(&(x)->uc_mcontext.mc_fpstate))->sv_fp[n])))
58#define xpXMMregs(x)(&(((struct savefpu *)(&(x)->uc_mcontext.mc_fpstate))->sv_xmm[0]))
59#endif
60#endif
61
62#ifdef SOLARIS
63#ifdef X8664
64#define xpGPRvector(x) ((x)->uc_mcontext.gregs)
65#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
66#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
67#define xpPC(x) xpGPR(x,Iip)
68#define xpMMXreg(x,n)  *((natural *)(&(x)->uc_mcontext.fpregs.fp_reg_set.fpchip_state.st[n]))
69#endif
70#endif
71
72#ifdef WIN64
73#define xpGPRvector(x) ((DWORD64 *)((x)->ContextRecord))
74#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
75#define xpPC(x) xpGPR(x,Iip);
76#endif
77
78#ifdef DARWIN
79#define SIGNAL_FOR_PROCESS_INTERRUPT SIGEMT
80#endif
81#ifdef LINUX
82#define SIGNAL_FOR_PROCESS_INTERRUPT SIGPWR
83#endif
84#ifdef FREEBSD
85#define SIGNAL_FOR_PROCESS_INTERRUPT SIGEMT
86#endif
87#ifdef SOLARIS
88#define SIGNAL_FOR_PROCESS_INTERRUPT SIGEMT
89#endif
90
91
92void switch_to_foreign_stack(void*, ...);
93
94#define INTN_OPCODE 0xcd
95
96#define UUO_GC_TRAP    0xc4
97#define UUO_ALLOC_TRAP 0xc5
98#define UUO_DEBUG_TRAP 0xca
99#define UUO_DEBUG_TRAP_WITH_STRING 0xcd
100
101#define XUUO_OPCODE_0 0x0f
102#define XUUO_OPCODE_1 0x0b
103
104#define XUUO_TLB_TOO_SMALL 1
105#define XUUO_INTERRUPT_NOW 2
106#define XUUO_SUSPEND_NOW 3
107
108void
109pc_luser_xp(ExceptionInformation*, TCR*, signed_natural*);
110
111
112typedef enum {
113  ID_unrecognized_alloc_instruction,
114  ID_load_allocptr_reg_from_tcr_save_allocptr_instruction,
115  ID_compare_allocptr_reg_to_tcr_save_allocbase_instruction,
116  ID_branch_around_alloc_trap_instruction,
117  ID_alloc_trap_instruction,
118  ID_set_allocptr_header_instruction,
119  ID_clear_tcr_save_allocptr_tag_instruction
120} alloc_instruction_id;
121
122#ifdef LINUX
123#define SIGNUM_FOR_INTN_TRAP SIGSEGV
124#define IS_MAYBE_INT_TRAP(info,xp) (((info->si_code) &0x7f) == 0)
125#define SIGRETURN(context)
126#endif
127
128#ifdef FREEBSD
129extern void freebsd_sigreturn(ExceptionInformation *);
130#define SIGNUM_FOR_INTN_TRAP SIGBUS
131#define IS_MAYBE_INT_TRAP(info,xp) (xp->uc_mcontext.mc_trapno == T_PROTFLT)
132#define SIGRETURN(context) freebsd_sigreturn(context)
133#endif
134
135#ifdef DARWIN
136#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Not really, but our Mach handler fakes that */
137#define IS_MAYBE_INT_TRAP(info,xp) (info->si_code == EXC_I386_GPFLT)
138/* The x86 version of sigreturn just needs the context argument; the
139   hidden, magic "flavor" argument that sigtramp uses is ignored. */
140#define SIGRETURN(context) DarwinSigReturn(context)
141#endif
142
143/* Please go away. */
144#ifdef DARWIN_GS_HACK
145extern Boolean ensure_gs_pthread(void);
146extern void set_gs_address(void *);
147#endif
148
149
150/* sigaltstack isn't thread-specific on The World's Most Advanced OS */
151#ifdef DARWIN
152#undef USE_SIGALTSTACK
153#else
154#define USE_SIGALTSTACK 1
155/* #undef USE_SIGALTSTACK */
156#endif
157
158#ifdef USE_SIGALTSTACK
159void setup_sigaltstack(area *);
160#endif
161
162/* recognizing the function associated with a tagged return address */
163/* now involves recognizinig an "(lea (@ disp (% rip)) (% rn))" */
164/* instruction at the tra */
165
166#define RECOVER_FN_FROM_RIP_LENGTH 7 /* the instruction is 7 bytes long */
167#define RECOVER_FN_FROM_RIP_DISP_OFFSET 3 /* displacement word is 3 bytes in */
168#define RECOVER_FN_FROM_RIP_WORD0 0x8d4c /* 0x4c 0x8d, little-endian */
169#define RECOVER_FN_FROM_RIP_BYTE2 0x2d  /* third byte of opcode */
Note: See TracBrowser for help on using the repository browser.