source: trunk/source/lisp-kernel/x86-constants32.h @ 14991

Last change on this file since 14991 was 14991, checked in by rme, 9 years ago

New functions in x86-utils.[ch], moved, more-or-less,
from xlbt.c.

Use them in x86-exceptions.c, in particular in
create_exception_callback_frame().

Move the definitions of the RECOVER_FN_xxx constants
from x86-exceptions.h to the appropriate x86-constants{32,64}.h
files.

File size: 13.6 KB
Line 
1/*
2   Copyright (C) 2009 Clozure Associates
3   Copyright (C) 1994-2001 Digitool, Inc
4   This file is part of Clozure CL. 
5
6   Clozure CL is licensed under the terms of the Lisp Lesser GNU Public
7   License , known as the LLGPL and distributed with Clozure CL as the
8   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,
9   which is distributed with Clozure CL as the file "LGPL".  Where these
10   conflict, the preamble takes precedence. 
11
12   Clozure CL is referenced in the preamble as the "LIBRARY."
13
14   The LLGPL is also available online at
15   http://opensource.franz.com/preamble.html
16*/
17
18#include "x86-constants.h"
19
20/* offsets into uc_mcontext.ss */
21#ifdef DARWIN
22#define REG_EAX 0
23#define REG_EBX 1
24#define REG_ECX 2
25#define REG_EDX 3
26#define REG_EDI 4
27#define REG_ESI 5
28#define REG_EBP 6
29#define REG_ESP 7
30#define REG_EFL 9
31#define REG_EIP 10
32#endif
33
34#ifdef WINDOWS
35/* Offsets relative to _CONTEXT.Edi */
36#define REG_EDI 0
37#define REG_ESI 1
38#define REG_EBX 2
39#define REG_EDX 3
40#define REG_ECX 4
41#define REG_EAX 5
42#define REG_EBP 6
43#define REG_EIP 7
44#define REG_EFL 9
45#define REG_ESP 10
46#endif
47
48#ifdef FREEBSD
49#define REG_EDI 5
50#define REG_ESI 6
51#define REG_EBP 7
52#define REG_ISP 8
53#define REG_EBX 9
54#define REG_EDX 10
55#define REG_ECX 11
56#define REG_EAX 12
57#define REG_EIP 15
58#define REG_EFL 17
59#define REG_ESP 18
60#endif
61
62#ifdef SOLARIS
63#include <sys/regset.h>
64#include <limits.h>
65#define REG_EAX EAX
66#define REG_EBX EBX
67#define REG_ECX ECX
68#define REG_EDX EDX
69#define REG_ESI ESI
70#define REG_EDI EDI
71#define REG_EBP EBP
72#define REG_ESP UESP    /* Maybe ... ESP is often 0, but who knows why ? */
73#define REG_EFL EFL
74#define REG_EIP EIP
75#endif
76
77/* Indicies of GPRs in the mcontext component of a ucontext */
78#define Iimm0  REG_EAX
79#define Iarg_z REG_EBX
80#define Itemp0 REG_ECX
81#define Itemp1 REG_EDX
82#define Ifn    REG_EDI
83#define Iarg_y REG_ESI
84#define Iesp   REG_ESP
85#define Iebp   REG_EBP
86#define Ieip   REG_EIP
87#define Iflags REG_EFL
88
89#define Isp Iesp
90#define Iip Ieip
91#define Iallocptr Itemp0
92#define Ira0 Itemp0
93#define Inargs Itemp1
94#define Ixfn Itemp1
95#define Ifp Iebp
96
97/* MMX register offsets from where mm0 is found in uc_mcontext.fs */
98#define Imm0 0
99#define Imm1 1
100
101#define nbits_in_word 32
102#define log2_nbits_in_word 5
103#define nbits_in_byte 8
104#define ntagbits 3
105#define nlisptagbits 2
106#define nfixnumtagbits 2
107#define num_subtag_bits 8
108#define fixnumshift 2
109#define fixnum_shift 2
110#define fulltagmask 7
111#define tagmask  3
112#define fixnummask 3
113#define subtagmask ((1<<num_subtag_bits)-1)
114#define ncharcodebits 8
115#define charcode_shift 8
116#define node_size 4
117#define node_shift 2
118#define nargregs 2
119
120#define tag_fixnum 0
121#define tag_list 1
122#define tag_misc 2
123#define tag_imm 3
124
125#define fulltag_even_fixnum 0
126#define fulltag_cons 1
127#define fulltag_nodeheader 2
128#define fulltag_imm 3
129#define fulltag_odd_fixnum 4
130#define fulltag_tra 5
131#define fulltag_misc 6
132#define fulltag_immheader 7
133
134#define SUBTAG(tag,subtag) ((tag) | ((subtag) << ntagbits))
135#define IMM_SUBTAG(subtag) SUBTAG(fulltag_immheader,(subtag))
136#define NODE_SUBTAG(subtag) SUBTAG(fulltag_nodeheader,(subtag))
137
138#define subtag_bignum IMM_SUBTAG(0)
139#define min_numeric_subtag subtag_bignum
140#define subtag_ratio NODE_SUBTAG(1)
141#define max_rational_subtag subtag_ratio
142#define subtag_single_float IMM_SUBTAG(1)
143#define subtag_double_float IMM_SUBTAG(2)
144#define min_float_subtag subtag_single_float
145#define max_float_subtag subtag_double_float
146#define max_real_subtag subtag_double_float
147#define subtag_complex NODE_SUBTAG(3)
148#define max_numeric_subtag subtag_complex
149
150#define subtag_bit_vector IMM_SUBTAG(31)
151#define subtag_double_float_vector IMM_SUBTAG(30)
152#define subtag_s16_vector IMM_SUBTAG(29)
153#define subtag_u16_vector IMM_SUBTAG(28)
154#define min_16_bit_ivector_subtag subtag_u16_vector
155#define max_16_bit_ivector_subtag subtag_s16_vector
156
157/* subtag 27 unused*/
158#define subtag_s8_vector IMM_SUBTAG(26)
159#define subtag_u8_vector IMM_SUBTAG(25)
160#define min_8_bit_ivector_subtag subtag_u8_vector
161#define max_8_bit_ivector_subtag IMM_SUBTAG(27)
162
163#define subtag_simple_base_string IMM_SUBTAG(24)
164#define subtag_fixnum_vector IMM_SUBTAG(23)
165#define subtag_s32_vector IMM_SUBTAG(22)
166#define subtag_u32_vector IMM_SUBTAG(21)
167#define subtag_single_float_vector IMM_SUBTAG(20)
168#define max_32_bit_ivector_subtag IMM_SUBTAG(24)
169#define min_cl_ivector_subtag subtag_single_float_vector
170
171#define subtag_vectorH NODE_SUBTAG(20)
172#define subtag_arrayH NODE_SUBTAG(19)
173#define subtag_simple_vector NODE_SUBTAG(21)    /*  Only one such subtag */
174#define min_vector_subtag subtag_vectorH
175#define min_array_subtag subtag_arrayH
176
177#define subtag_macptr IMM_SUBTAG(3)
178#define min_non_numeric_imm_subtag subtag_macptr
179
180#define subtag_dead_macptr IMM_SUBTAG(4)
181#define subtag_code_vector IMM_SUBTAG(5)
182#define subtag_creole IMM_SUBTAG(6)
183
184#define max_non_array_imm_subtag ((19<<ntagbits)|fulltag_immheader)
185
186#define subtag_catch_frame NODE_SUBTAG(4)
187#define subtag_function NODE_SUBTAG(5)
188#define subtag_basic_stream NODE_SUBTAG(6)
189#define subtag_symbol NODE_SUBTAG(7)
190#define subtag_lock NODE_SUBTAG(8)
191#define subtag_hash_vector NODE_SUBTAG(9)
192#define subtag_pool NODE_SUBTAG(10)
193#define subtag_weak NODE_SUBTAG(11)
194#define subtag_package NODE_SUBTAG(12)
195#define subtag_slot_vector NODE_SUBTAG(13)
196#define subtag_instance NODE_SUBTAG(14)
197#define subtag_struct NODE_SUBTAG(15)
198#define subtag_istruct NODE_SUBTAG(16)
199#define max_non_array_node_subtag ((19<<ntagbits)|fulltag_immheader)
200
201#define subtag_unbound SUBTAG(fulltag_imm, 6)
202#define unbound_marker subtag_unbound
203#define undefined subtag_unbound
204#define unbound subtag_unbound
205#define subtag_character SUBTAG(fulltag_imm, 9)
206#define slot_unbound SUBTAG(fulltag_imm, 10)
207#define slot_unbound_marker slot_unbound
208#define subtag_illegal SUBTAG(fulltag_imm,11)
209#define illegal_marker subtag_illegal
210#define subtag_forward_marker SUBTAG(fulltag_imm,28)
211#define subtag_reserved_frame  SUBTAG(fulltag_imm,29)
212#define reserved_frame_marker subtag_reserved_frame
213#define subtag_no_thread_local_binding SUBTAG(fulltag_imm,30)
214#define no_thread_local_binding_marker subtag_no_thread_local_binding
215#define subtag_function_boundary_marker SUBTAG(fulltag_imm,31)
216#define function_boundary_marker subtag_function_boundary_marker
217
218/* The 32-bit immediate value in the instruction
219 * "(mov ($ 0x12345678) (% fn))" at a tagged return address
220 * refers to the associated function.
221 */
222#define RECOVER_FN_OPCODE 0xbf
223#define RECOVER_FN_LENGTH 5
224
225
226typedef struct double_float {
227    LispObj header;
228    LispObj pad;
229    LispObj value_low;
230    LispObj value_high;
231} double_float;
232
233typedef struct single_float {
234    LispObj header;
235    LispObj value;
236} single_float;
237
238
239typedef struct lisp_frame {
240    struct lisp_frame *backlink;
241    LispObj tra;
242    LispObj xtra;               /* if tra is nvalretn */
243} lisp_frame;
244
245typedef struct exception_callback_frame {
246    struct lisp_frame *backlink;
247    LispObj tra;                /* ALWAYS 0 FOR AN XCF */
248    LispObj nominal_function;   /* the current function at the time of the exception */
249    LispObj relative_pc;        /* Boxed byte offset within actual function or absolute address */
250    LispObj containing_uvector; /* the uvector that contains the relative PC or NIL */
251    LispObj xp;                 /* exception context */
252    LispObj ra0;                /* value of ra0 from context */
253    LispObj foreign_sp;         /* foreign sp at the time that exception occurred */
254    LispObj prev_xframe;        /* so %apply-in-frame can unwind it */
255} xcf;
256
257
258typedef struct catch_frame {
259    LispObj header;
260    LispObj catch_tag;
261    LispObj link;
262    LispObj mvflag;
263    LispObj esp;
264    LispObj ebp;
265    LispObj foreign_sp;
266    LispObj db_link;
267    LispObj xframe;
268    LispObj pc;
269} catch_frame;
270
271#define catch_frame_element_count ((sizeof(catch_frame)/sizeof(LispObj))-1)
272#define catch_frame_header make_header(subtag_catch_frame,catch_frame_element_count)
273
274/*
275   All exception frames in a thread are linked together
276 */
277typedef struct xframe_list {
278  ExceptionInformation *curr;
279  natural node_regs_mask;
280  struct xframe_list *prev;
281} xframe_list;
282
283#define fixnum_bitmask(n)  (1<<((n)+fixnumshift))
284
285
286
287
288
289
290#include "lisp-errors.h"
291
292#ifdef DARWIN
293#include <architecture/i386/sel.h>
294#else
295typedef unsigned short sel_t;   /* for now */
296#endif
297
298/*
299 * bits correspond to reg encoding used in instructions
300 *   7   6   5   4   3   2   1   0
301 *  edi esi ebp esp ebx edx ecx eax
302 */
303
304#define X8632_DEFAULT_NODE_REGS_MASK 0xce
305
306#ifdef WIN_32
307/* TCR is in the last 34 words of NtCurrentTeb()->TlsSlots[] */
308#define TCR_BIAS (0xe10 + 30 * sizeof(natural))
309
310typedef struct tcr {
311  struct tcr *linear;
312  struct tcr_aux *aux;
313  signed_natural valence;       /* odd when in foreign code */
314  natural node_regs_mask;       /* bit set means register contains node */
315  char *save_allocbase;
316  char *save_allocptr;
317  char *last_allocptr;
318  LispObj catch_top;            /* top catch frame */
319  special_binding *db_link;     /* special binding chain head */
320  natural tlb_limit;
321  LispObj *tlb_pointer;
322  LispObj ffi_exception;        /* fpscr bits from ff-call */
323  LispObj *foreign_sp;
324  signed_natural interrupt_pending;     /* pending interrupt flag */
325  LispObj next_method_context;  /* used in lieu of register */
326  LispObj *next_tsp;
327  void *safe_ref_address;
328  LispObj *save_tsp;            /* TSP when in foreign code */
329  LispObj *save_vsp;            /* VSP when in foreign code */
330  LispObj *save_fp;             /* EBP when in foreign code */
331  struct area *ts_area;         /* tstack area pointer */
332  struct area *vs_area;         /* vstack area pointer */
333  xframe_list *xframe;          /* exception-frame linked list */
334  signed_natural unwinding;
335  natural flags;
336  natural foreign_mxcsr;
337  natural lisp_mxcsr;
338  ExceptionInformation *pending_exception_context;
339  natural unboxed0;             /* unboxed scratch locations */
340  natural unboxed1;
341  LispObj save0;                /* spill area for node registers: */
342  LispObj save1;                /*  it must be 16-byte aligned */
343  LispObj save2;
344  LispObj save3;
345} TCR;
346
347struct tcr_aux {
348  unsigned long long bytes_allocated;
349  struct area *cs_area;         /* cstack area pointer */
350  LispObj cs_limit;             /* stack overflow limit */
351  natural log2_allocation_quantum;      /* for per-thread consing */
352  int *errno_loc;               /* per-thread (?) errno location */
353  LispObj osid;                 /* OS thread id */
354  signed_natural foreign_exception_status; /* non-zero -> call lisp_exit_hook */
355  void *native_thread_info;     /* platform-dependent */
356  void *native_thread_id;       /* mach_thread_t, pid_t, etc. */
357  void *reset_completion;
358  void *activate;
359  ExceptionInformation *gc_context;
360  void *termination_semaphore;
361  natural shutdown_count;
362  natural save_eflags;
363  sel_t ldt_selector;
364  signed_natural suspend_count;
365  ExceptionInformation *suspend_context;
366  void *suspend;                /* suspension semaphore */
367  void *resume;                 /* resumption semaphore */
368  void *allocated;
369  void *pending_io_info;
370  void *io_datum;
371  struct tcr *next;
372  struct tcr *prev;
373};
374#else
375#define TCR_BIAS 0
376
377typedef struct tcr {
378  struct tcr *next;
379  struct tcr *prev;
380  natural node_regs_mask; /* bit set means correspnding reg contains node */
381  struct tcr *linear;
382  /* this spill area must be 16-byte aligned */
383  LispObj save0;                /* spill area for node registers */
384  LispObj save1;
385  LispObj save2;
386  LispObj save3;
387  LispObj *save_fp;             /* EBP when in foreign code */
388  u32_t lisp_mxcsr;
389  u32_t foreign_mxcsr;
390  special_binding *db_link;     /* special binding chain head */
391  LispObj catch_top;            /* top catch frame */
392  LispObj *save_vsp;              /* VSP when in foreign code */
393  LispObj *save_tsp;              /* TSP when in foreign code */
394  LispObj *foreign_sp;
395  struct area *cs_area;         /* cstack area pointer */
396  struct area *vs_area;         /* vstack area pointer */
397  struct area *ts_area;         /* tstack area pointer */
398  LispObj cs_limit;                     /* stack overflow limit */
399  natural bytes_allocated;
400  natural bytes_consed_high;
401  natural log2_allocation_quantum;      /* for per-thread consing */
402  signed_natural interrupt_pending;     /* pending interrupt flag */
403  xframe_list *xframe;    /* exception-frame linked list */
404  int *errno_loc;               /* per-thread (?) errno location */
405  LispObj ffi_exception;        /* fpscr bits from ff-call */
406  LispObj osid;                 /* OS thread id */
407  signed_natural valence;         /* odd when in foreign code */
408  signed_natural foreign_exception_status; /* non-zero -> call lisp_exit_hook */
409  void *native_thread_info;                  /* platform-dependent */
410  void *native_thread_id;       /* mach_thread_t, pid_t, etc. */
411  char *last_allocptr;
412  char *save_allocptr;
413  char *save_allocbase;
414  void *reset_completion;
415  void *activate;
416  signed_natural suspend_count;
417  ExceptionInformation *suspend_context;
418  ExceptionInformation *pending_exception_context;
419  void *suspend;                /* suspension semaphore */
420  void *resume;                 /* resumption semaphore */
421  natural flags;
422  ExceptionInformation *gc_context;
423  void *termination_semaphore;
424  signed_natural unwinding;
425  natural tlb_limit;
426  LispObj *tlb_pointer;
427  natural shutdown_count;
428  LispObj *next_tsp;
429  void *safe_ref_address;
430  sel_t ldt_selector;
431  natural scratch_mxcsr;
432  natural unboxed0;
433  natural unboxed1;
434  LispObj next_method_context; /* used in lieu of register */
435  natural save_eflags;
436  void *allocated;
437  void *pending_io_info;
438  void *io_datum;
439} TCR;
440#endif
441
442/* expansion of "TCR_AUX(tcr)": TCR_AUX(tcr) */
443
444#define nil_value ((0x13000 + (fulltag_cons))+(LOWMEM_BIAS))
445#define t_value ((0x13008 + (fulltag_misc))+(LOWMEM_BIAS))
446#define t_offset (t_value-nil_value)
447#define misc_header_offset -fulltag_misc
448#define misc_data_offset misc_header_offset + node_size
449
450typedef struct {
451  natural Eip;
452  natural Cs;                   /* in low 16 bits */
453  natural EFlags;
454} ia32_iret_frame;
455
456#define heap_segment_size 0x00010000
457#define log2_heap_segment_size 16
458
459#ifndef EFL_DF
460#define EFL_DF 1024
461#endif
462
Note: See TracBrowser for help on using the repository browser.