source: release/1.9/source/lisp-kernel/x86-constants32.h @ 16083

Last change on this file since 16083 was 15609, checked in by gb, 6 years ago

Fix UNSETENV for Windows. Export UNSETENV.

Change min image version for x8632, x8664.

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