source: release/1.7/source/lisp-kernel/x86-constants32.h @ 15267

Last change on this file since 15267 was 15099, checked in by rme, 8 years ago

Revert r15026.

File size: 13.3 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
219
220typedef struct double_float {
221    LispObj header;
222    LispObj pad;
223    LispObj value_low;
224    LispObj value_high;
225} double_float;
226
227typedef struct single_float {
228    LispObj header;
229    LispObj value;
230} single_float;
231
232
233typedef struct lisp_frame {
234    struct lisp_frame *backlink;
235    LispObj tra;
236    LispObj xtra;               /* if tra is nvalretn */
237} lisp_frame;
238
239typedef struct exception_callback_frame {
240    struct lisp_frame *backlink;
241    LispObj tra;                /* ALWAYS 0 FOR AN XCF */
242    LispObj nominal_function;   /* the current function at the time of the exception */
243    LispObj relative_pc;        /* Boxed byte offset within actual function or absolute address */
244    LispObj containing_uvector; /* the uvector that contains the relative PC or NIL */
245    LispObj xp;                 /* exception context */
246    LispObj ra0;                /* value of ra0 from context */
247    LispObj foreign_sp;         /* foreign sp at the time that exception occurred */
248    LispObj prev_xframe;        /* so %apply-in-frame can unwind it */
249} xcf;
250
251
252typedef struct catch_frame {
253    LispObj header;
254    LispObj catch_tag;
255    LispObj link;
256    LispObj mvflag;
257    LispObj esp;
258    LispObj ebp;
259    LispObj foreign_sp;
260    LispObj db_link;
261    LispObj xframe;
262    LispObj pc;
263} catch_frame;
264
265#define catch_frame_element_count ((sizeof(catch_frame)/sizeof(LispObj))-1)
266#define catch_frame_header make_header(subtag_catch_frame,catch_frame_element_count)
267
268/*
269   All exception frames in a thread are linked together
270 */
271typedef struct xframe_list {
272  ExceptionInformation *curr;
273  natural node_regs_mask;
274  struct xframe_list *prev;
275} xframe_list;
276
277#define fixnum_bitmask(n)  (1<<((n)+fixnumshift))
278
279
280
281
282
283
284#include "lisp-errors.h"
285
286#ifdef DARWIN
287#include <architecture/i386/sel.h>
288#else
289typedef unsigned short sel_t;   /* for now */
290#endif
291
292/*
293 * bits correspond to reg encoding used in instructions
294 *   7   6   5   4   3   2   1   0
295 *  edi esi ebp esp ebx edx ecx eax
296 */
297
298#define X8632_DEFAULT_NODE_REGS_MASK 0xce
299
300#ifdef WIN_32
301/* TCR is in the last 34 words of NtCurrentTeb()->TlsSlots[] */
302#define TCR_BIAS (0xe10 + 30 * sizeof(natural))
303
304typedef struct tcr {
305  struct tcr *linear;
306  struct tcr_aux *aux;
307  signed_natural valence;       /* odd when in foreign code */
308  natural node_regs_mask;       /* bit set means register contains node */
309  char *save_allocbase;
310  char *save_allocptr;
311  char *last_allocptr;
312  LispObj catch_top;            /* top catch frame */
313  special_binding *db_link;     /* special binding chain head */
314  natural tlb_limit;
315  LispObj *tlb_pointer;
316  LispObj ffi_exception;        /* fpscr bits from ff-call */
317  LispObj *foreign_sp;
318  signed_natural interrupt_pending;     /* pending interrupt flag */
319  LispObj next_method_context;  /* used in lieu of register */
320  LispObj *next_tsp;
321  void *safe_ref_address;
322  LispObj *save_tsp;            /* TSP when in foreign code */
323  LispObj *save_vsp;            /* VSP when in foreign code */
324  LispObj *save_fp;             /* EBP when in foreign code */
325  struct area *ts_area;         /* tstack area pointer */
326  struct area *vs_area;         /* vstack area pointer */
327  xframe_list *xframe;          /* exception-frame linked list */
328  signed_natural unwinding;
329  natural flags;
330  natural foreign_mxcsr;
331  natural lisp_mxcsr;
332  ExceptionInformation *pending_exception_context;
333  natural unboxed0;             /* unboxed scratch locations */
334  natural unboxed1;
335  LispObj save0;                /* spill area for node registers: */
336  LispObj save1;                /*  it must be 16-byte aligned */
337  LispObj save2;
338  LispObj save3;
339} TCR;
340
341struct tcr_aux {
342  unsigned long long bytes_allocated;
343  struct area *cs_area;         /* cstack area pointer */
344  LispObj cs_limit;             /* stack overflow limit */
345  natural log2_allocation_quantum;      /* for per-thread consing */
346  int *errno_loc;               /* per-thread (?) errno location */
347  LispObj osid;                 /* OS thread id */
348  signed_natural foreign_exception_status; /* non-zero -> call lisp_exit_hook */
349  void *native_thread_info;     /* platform-dependent */
350  void *native_thread_id;       /* mach_thread_t, pid_t, etc. */
351  void *reset_completion;
352  void *activate;
353  ExceptionInformation *gc_context;
354  void *termination_semaphore;
355  natural shutdown_count;
356  natural save_eflags;
357  sel_t ldt_selector;
358  signed_natural suspend_count;
359  ExceptionInformation *suspend_context;
360  void *suspend;                /* suspension semaphore */
361  void *resume;                 /* resumption semaphore */
362  void *allocated;
363  void *pending_io_info;
364  void *io_datum;
365  struct tcr *next;
366  struct tcr *prev;
367};
368#else
369#define TCR_BIAS 0
370
371typedef struct tcr {
372  struct tcr *next;
373  struct tcr *prev;
374  natural node_regs_mask; /* bit set means correspnding reg contains node */
375  struct tcr *linear;
376  /* this spill area must be 16-byte aligned */
377  LispObj save0;                /* spill area for node registers */
378  LispObj save1;
379  LispObj save2;
380  LispObj save3;
381  LispObj *save_fp;             /* EBP when in foreign code */
382  u32_t lisp_mxcsr;
383  u32_t foreign_mxcsr;
384  special_binding *db_link;     /* special binding chain head */
385  LispObj catch_top;            /* top catch frame */
386  LispObj *save_vsp;              /* VSP when in foreign code */
387  LispObj *save_tsp;              /* TSP when in foreign code */
388  LispObj *foreign_sp;
389  struct area *cs_area;         /* cstack area pointer */
390  struct area *vs_area;         /* vstack area pointer */
391  struct area *ts_area;         /* tstack area pointer */
392  LispObj cs_limit;                     /* stack overflow limit */
393  natural bytes_allocated;
394  natural bytes_consed_high;
395  natural log2_allocation_quantum;      /* for per-thread consing */
396  signed_natural interrupt_pending;     /* pending interrupt flag */
397  xframe_list *xframe;    /* exception-frame linked list */
398  int *errno_loc;               /* per-thread (?) errno location */
399  LispObj ffi_exception;        /* fpscr bits from ff-call */
400  LispObj osid;                 /* OS thread id */
401  signed_natural valence;         /* odd when in foreign code */
402  signed_natural foreign_exception_status; /* non-zero -> call lisp_exit_hook */
403  void *native_thread_info;                  /* platform-dependent */
404  void *native_thread_id;       /* mach_thread_t, pid_t, etc. */
405  char *last_allocptr;
406  char *save_allocptr;
407  char *save_allocbase;
408  void *reset_completion;
409  void *activate;
410  signed_natural suspend_count;
411  ExceptionInformation *suspend_context;
412  ExceptionInformation *pending_exception_context;
413  void *suspend;                /* suspension semaphore */
414  void *resume;                 /* resumption semaphore */
415  natural flags;
416  ExceptionInformation *gc_context;
417  void *termination_semaphore;
418  signed_natural unwinding;
419  natural tlb_limit;
420  LispObj *tlb_pointer;
421  natural shutdown_count;
422  LispObj *next_tsp;
423  void *safe_ref_address;
424  sel_t ldt_selector;
425  natural scratch_mxcsr;
426  natural unboxed0;
427  natural unboxed1;
428  LispObj next_method_context; /* used in lieu of register */
429  natural save_eflags;
430  void *allocated;
431  void *pending_io_info;
432  void *io_datum;
433} TCR;
434#endif
435
436/* expansion of "TCR_AUX(tcr)": TCR_AUX(tcr) */
437
438#define nil_value ((0x13000 + (fulltag_cons))+(LOWMEM_BIAS))
439#define t_value ((0x13008 + (fulltag_misc))+(LOWMEM_BIAS))
440#define t_offset (t_value-nil_value)
441#define misc_header_offset -fulltag_misc
442#define misc_data_offset misc_header_offset + node_size
443
444typedef struct {
445  natural Eip;
446  natural Cs;                   /* in low 16 bits */
447  natural EFlags;
448} ia32_iret_frame;
449
450#define heap_segment_size 0x00010000
451#define log2_heap_segment_size 16
452
453#ifndef EFL_DF
454#define EFL_DF 1024
455#endif
456
Note: See TracBrowser for help on using the repository browser.