source: release/1.2/source/lisp-kernel/x86-exceptions.h @ 11582

Last change on this file since 11582 was 11582, checked in by gb, 11 years ago

Hold TCR_AREA_LOCK when calling pthread_create(), to avoid Darwin lossage.

Propagate recent x86 Darwin sigreturn changes to 1.2.

  • 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) do {\
33    darwin_sigreturn(context);\
34    Bug(context,"sigreturn returned");\
35  } while (0)
36
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 xpFPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__fs.__fpu_xmm0)))
43#define xpMMXreg(x,n)  (xpFPRvector(x)[n])
44#endif
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#define xpGPRvector(x) ((natural *)(&((x)->uc_mcontext)))
58#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
59#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
60#define xpPC(x) xpGPR(x,Iip)
61#define xpMMXreg(x,n) *((natural *)(&(((struct savefpu *)(&(x)->uc_mcontext.mc_fpstate))->sv_fp[n])))
62#define xpXMMregs(x)(&(((struct savefpu *)(&(x)->uc_mcontext.mc_fpstate))->sv_xmm[0]))
63#endif
64#endif
65
66#ifdef SOLARIS
67#ifdef X8664
68#define xpGPRvector(x) ((x)->uc_mcontext.gregs)
69#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
70#define set_xpGPR(x,gpr,new) xpGPR((x),(gpr)) = (natural)(new)
71#define xpPC(x) xpGPR(x,Iip)
72#define xpMMXreg(x,n)  *((natural *)(&(x)->uc_mcontext.fpregs.fp_reg_set.fpchip_state.st[n]))
73#endif
74#endif
75
76#ifdef WIN64
77#define xpGPRvector(x) ((DWORD64 *)((x)->ContextRecord))
78#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
79#define xpPC(x) xpGPR(x,Iip)
80#endif
81
82#ifdef DARWIN
83#define SIGNAL_FOR_PROCESS_INTERRUPT SIGUSR1
84#endif
85#ifdef LINUX
86#define SIGNAL_FOR_PROCESS_INTERRUPT SIGPWR
87#endif
88#ifdef FREEBSD
89#define SIGNAL_FOR_PROCESS_INTERRUPT SIGEMT
90#endif
91#ifdef SOLARIS
92#define SIGNAL_FOR_PROCESS_INTERRUPT SIGEMT
93#endif
94
95
96void switch_to_foreign_stack(void*, ...);
97
98#define INTN_OPCODE 0xcd
99
100#define UUO_GC_TRAP    0xc4
101#define UUO_ALLOC_TRAP 0xc5
102#define UUO_DEBUG_TRAP 0xca
103#define UUO_DEBUG_TRAP_WITH_STRING 0xcd
104
105#define XUUO_OPCODE_0 0x0f
106#define XUUO_OPCODE_1 0x0b
107
108#define XUUO_TLB_TOO_SMALL 1
109#define XUUO_INTERRUPT_NOW 2
110#define XUUO_SUSPEND_NOW 3
111#define XUUO_INTERRUPT 4
112#define XUUO_SUSPEND 5
113#define XUUO_SUSPEND_ALL 6
114#define XUUO_RESUME 7
115#define XUUO_RESUME_ALL 8
116
117void
118pc_luser_xp(ExceptionInformation*, TCR*, signed_natural*);
119
120
121typedef enum {
122  ID_unrecognized_alloc_instruction,
123  ID_load_allocptr_reg_from_tcr_save_allocptr_instruction,
124  ID_compare_allocptr_reg_to_tcr_save_allocbase_instruction,
125  ID_branch_around_alloc_trap_instruction,
126  ID_alloc_trap_instruction,
127  ID_set_allocptr_header_instruction,
128  ID_clear_tcr_save_allocptr_tag_instruction
129} alloc_instruction_id;
130
131#ifdef LINUX
132#define SIGNUM_FOR_INTN_TRAP SIGSEGV
133#define IS_MAYBE_INT_TRAP(info,xp) (((info->si_code) &0x7f) == 0)
134#define SIGRETURN(context)
135#endif
136
137#ifdef FREEBSD
138extern void freebsd_sigreturn(ExceptionInformation *);
139#define SIGNUM_FOR_INTN_TRAP SIGBUS
140#define IS_MAYBE_INT_TRAP(info,xp) (xp->uc_mcontext.mc_trapno == T_PROTFLT)
141#define SIGRETURN(context) freebsd_sigreturn(context)
142#endif
143
144#ifdef DARWIN
145#define SIGNUM_FOR_INTN_TRAP SIGSEGV /* Not really, but our Mach handler fakes that */
146#define IS_MAYBE_INT_TRAP(info,xp) (info->si_code == EXC_I386_GPFLT)
147/* The x86 version of sigreturn just needs the context argument; the
148   hidden, magic "flavor" argument that sigtramp uses is ignored. */
149#define SIGRETURN(context) DarwinSigReturn(context)
150#endif
151
152/* Please go away. */
153#ifdef DARWIN_GS_HACK
154extern Boolean ensure_gs_pthread(void);
155extern void set_gs_address(void *);
156#endif
157
158
159/* sigaltstack isn't thread-specific on The World's Most Advanced OS */
160#ifdef DARWIN
161#undef USE_SIGALTSTACK
162#else
163#ifdef WINDOWS
164#undef USE_SIGALTSTACK
165#else
166#define USE_SIGALTSTACK 1
167#endif
168#endif
169
170#ifdef USE_SIGALTSTACK
171void setup_sigaltstack(area *);
172#endif
173
174/* recognizing the function associated with a tagged return address */
175/* now involves recognizinig an "(lea (@ disp (% rip)) (% rn))" */
176/* instruction at the tra */
177
178#define RECOVER_FN_FROM_RIP_LENGTH 7 /* the instruction is 7 bytes long */
179#define RECOVER_FN_FROM_RIP_DISP_OFFSET 3 /* displacement word is 3 bytes in */
180#define RECOVER_FN_FROM_RIP_WORD0 0x8d4c /* 0x4c 0x8d, little-endian */
181#define RECOVER_FN_FROM_RIP_BYTE2 0x2d  /* third byte of opcode */
182
183extern natural get_mxcsr();
184extern void set_mxcsr(natural);
Note: See TracBrowser for help on using the repository browser.