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

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

Signal number changes, from trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 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 SIGUSR1
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#define XUUO_INTERRUPT 4
108#define XUUO_SUSPEND 5
109#define XUUO_SUSPEND_ALL 6
110#define XUUO_RESUME 7
111#define XUUO_RESUME_ALL 8
112
113void
114pc_luser_xp(ExceptionInformation*, TCR*, signed_natural*);
115
116
117typedef enum {
118  ID_unrecognized_alloc_instruction,
119  ID_load_allocptr_reg_from_tcr_save_allocptr_instruction,
120  ID_compare_allocptr_reg_to_tcr_save_allocbase_instruction,
121  ID_branch_around_alloc_trap_instruction,
122  ID_alloc_trap_instruction,
123  ID_set_allocptr_header_instruction,
124  ID_clear_tcr_save_allocptr_tag_instruction
125} alloc_instruction_id;
126
127#ifdef LINUX
128#define SIGNUM_FOR_INTN_TRAP SIGSEGV
129#define IS_MAYBE_INT_TRAP(info,xp) (((info->si_code) &0x7f) == 0)
130#define SIGRETURN(context)
131#endif
132
133#ifdef FREEBSD
134extern void freebsd_sigreturn(ExceptionInformation *);
135#define SIGNUM_FOR_INTN_TRAP SIGBUS
136#define IS_MAYBE_INT_TRAP(info,xp) (xp->uc_mcontext.mc_trapno == T_PROTFLT)
137#define SIGRETURN(context) freebsd_sigreturn(context)
138#endif
139
140#ifdef DARWIN
141#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Not really, but our Mach handler fakes that */
142#define IS_MAYBE_INT_TRAP(info,xp) (info->si_code == EXC_I386_GPFLT)
143/* The x86 version of sigreturn just needs the context argument; the
144   hidden, magic "flavor" argument that sigtramp uses is ignored. */
145#define SIGRETURN(context) DarwinSigReturn(context)
146#endif
147
148/* Please go away. */
149#ifdef DARWIN_GS_HACK
150extern Boolean ensure_gs_pthread(void);
151extern void set_gs_address(void *);
152#endif
153
154
155/* sigaltstack isn't thread-specific on The World's Most Advanced OS */
156#ifdef DARWIN
157#undef USE_SIGALTSTACK
158#else
159#ifdef WINDOWS
160#undef USE_SIGALTSTACK
161#else
162#define USE_SIGALTSTACK 1
163#endif
164#endif
165
166#ifdef USE_SIGALTSTACK
167void setup_sigaltstack(area *);
168#endif
169
170/* recognizing the function associated with a tagged return address */
171/* now involves recognizinig an "(lea (@ disp (% rip)) (% rn))" */
172/* instruction at the tra */
173
174#define RECOVER_FN_FROM_RIP_LENGTH 7 /* the instruction is 7 bytes long */
175#define RECOVER_FN_FROM_RIP_DISP_OFFSET 3 /* displacement word is 3 bytes in */
176#define RECOVER_FN_FROM_RIP_WORD0 0x8d4c /* 0x4c 0x8d, little-endian */
177#define RECOVER_FN_FROM_RIP_BYTE2 0x2d  /* third byte of opcode */
178
179extern natural get_mxcsr();
180extern void set_mxcsr(natural);
Note: See TracBrowser for help on using the repository browser.