source: release/1.9/source/lisp-kernel/x86-constants64.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.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 KB
Line 
1/*
2   Copyright (C) 2005-2009 Clozure Associates
3   This file is part of Clozure CL. 
4
5   Clozure CL is licensed under the terms of the Lisp Lesser GNU Public
6   License , known as the LLGPL and distributed with Clozure CL as the
7   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,
8   which is distributed with Clozure CL as the file "LGPL".  Where these
9   conflict, the preamble takes precedence. 
10
11   Clozure CL 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
17#include "x86-constants.h"
18
19
20/* Define indices of the GPRs in the mcontext component of a ucontext */
21#define Itemp0      REG_RBX
22#define Iarg_y      REG_RDI
23#define Iarg_x      REG_R8
24#define Iarg_z      REG_RSI
25#define Isave3      REG_R11
26#define Isave2      REG_R12
27#define Isave1      REG_R14
28#define Isave0      REG_R15
29#define Itemp2      REG_R10
30#define Ifn         REG_R13
31#define Irbp        REG_RBP
32#define Iimm0       REG_RAX
33#define Iimm1       REG_RDX
34#define Iimm2       REG_RCX
35#define Itemp1      REG_R9
36#define Isp         REG_RSP
37#define Iip         REG_RIP
38#if defined(LINUX) || defined(WINDOWS)
39#define Iflags      REG_EFL
40#endif
41
42#if defined(SOLARIS) || defined(FREEBSD) || defined(DARWIN)
43#define Iflags      REG_RFL
44#endif
45
46
47#define Iallocptr Itemp0
48#define Ira0 Itemp2
49#define Inargs Iimm2
50#define Ixfn Itemp1
51#define Ifp Irbp
52
53
54#define nbits_in_word 64L
55#define log2_nbits_in_word 6L
56#define nbits_in_byte 8L
57#define ntagbits 4L
58#define nlisptagbits 3L
59#define nfixnumtagbits 2L
60#define num_subtag_bits 8L
61#define fixnumshift 3L
62#define fixnum_shift 3L
63#define fulltagmask 15L
64#define tagmask  7L
65#define fixnummask 3
66#define subtagmask ((1L<<num_subtag_bits)-1L)
67#define ncharcodebits 8L
68#define charcode_shift 8L
69#define node_size 8L
70#define node_shift 3L
71#define nargregs 3L
72
73#define tag_fixnum 0L
74#define tag_imm_0 1L            /* subtag_single_float ONLY */
75#define tag_imm_1 2L            /* subtag_character, internal markers */
76#define tag_list 3L             /* subtag_cons or NIL */
77#define tag_tra 4L              /* tagged return_address */
78#define tag_misc 5L             /* random uvector */
79#define tag_symbol 6L           /* non-null symbol */
80#define tag_function 7L /* function entry point */
81
82#define fulltag_even_fixnum 0L
83#define fulltag_imm_0 1L
84#define fulltag_imm_1 2L
85#define fulltag_cons 3L
86#define fulltag_tra_0 4L
87#define fulltag_nodeheader_0 5L
88#define fulltag_nodeheader_1 6L
89#define fulltag_immheader_0 7L
90#define fulltag_odd_fixnum 8L
91#define fulltag_immheader_1 9L
92#define fulltag_immheader_2 10L
93#define fulltag_nil 11L
94#define fulltag_tra_1 12L
95#define fulltag_misc 13L
96#define fulltag_symbol 14L
97#define fulltag_function 15L
98
99#define SUBTAG(tag,subtag) ((tag) | ((subtag) << ntagbits))
100#define subtag_arrayH SUBTAG(fulltag_nodeheader_0,10L)
101#define subtag_vectorH SUBTAG(fulltag_nodeheader_1,10L)
102#define subtag_simple_vector SUBTAG(fulltag_nodeheader_1,11L)
103#define min_vector_subtag subtag_vectorH       
104
105#define ivector_class_64_bit fulltag_immheader_2
106#define ivector_class_32_bit fulltag_immheader_1
107#define ivector_class_other_bit fulltag_immheader_0
108
109
110#define subtag_fixnum_vector SUBTAG(ivector_class_64_bit,12L)
111#define subtag_s64_vector SUBTAG(ivector_class_64_bit,13L)
112#define subtag_u64_vector SUBTAG(ivector_class_64_bit,14L)
113#define subtag_double_float_vector SUBTAG(ivector_class_64_bit,15L)
114
115#define subtag_simple_base_string SUBTAG(ivector_class_32_bit,12L)
116#define subtag_s32_vector SUBTAG(ivector_class_32_bit,13L)
117#define subtag_u32_vector SUBTAG(ivector_class_32_bit,14L)
118#define subtag_single_float_vector SUBTAG(ivector_class_32_bit,15L)
119
120#define subtag_s16_vector SUBTAG(ivector_class_other_bit,10L)
121#define subtag_u16_vector SUBTAG(ivector_class_other_bit,11L)
122#define subtag_s8_vector SUBTAG(ivector_class_other_bit,13L)
123#define subtag_u8_vector SUBTAG(ivector_class_other_bit,14L)
124#define subtag_bit_vector SUBTAG(ivector_class_other_bit,15L)
125/* min_8_bit_ivector_subtag is the old 8-bit simple_base_string */
126#define min_8_bit_ivector_subtag SUBTAG(ivector_class_other_bit,12L)
127
128/* There's some room for expansion in non-array ivector space. */
129#define subtag_macptr SUBTAG(ivector_class_64_bit,1)
130#define subtag_dead_macptr SUBTAG(ivector_class_64_bit,2)
131#define subtag_bignum SUBTAG(ivector_class_32_bit,0)
132#define subtag_double_float SUBTAG(ivector_class_32_bit,1)
133#define subtag_xcode_vector SUBTAG(ivector_class_32_bit,2)
134
135/* Note the difference between (e.g) fulltag_function - which
136   defines what the low 4 bytes of a function pointer look like -
137   and subtag_function - which describes what the subtag byte
138   in a function header looks like.  (Likewise for fulltag_symbol
139   and subtag_symbol)
140*/             
141
142#define subtag_symbol SUBTAG(fulltag_nodeheader_0,1)
143#define subtag_catch_frame SUBTAG(fulltag_nodeheader_0,2)
144#define subtag_hash_vector SUBTAG(fulltag_nodeheader_0,3)
145#define subtag_pool SUBTAG(fulltag_nodeheader_0,4)
146#define subtag_weak SUBTAG(fulltag_nodeheader_0,5)
147#define subtag_package SUBTAG(fulltag_nodeheader_0,6)
148#define subtag_slot_vector SUBTAG(fulltag_nodeheader_0,7)
149#define subtag_basic_stream SUBTAG(fulltag_nodeheader_0,8)
150#define subtag_function SUBTAG(fulltag_nodeheader_0,9)
151
152#define subtag_ratio SUBTAG(fulltag_nodeheader_1,1)
153#define subtag_complex SUBTAG(fulltag_nodeheader_1,2)
154#define subtag_struct SUBTAG(fulltag_nodeheader_1,3)
155#define subtag_istruct SUBTAG(fulltag_nodeheader_1,4)
156#define subtag_value_cell SUBTAG(fulltag_nodeheader_1,5)
157#define subtag_xfunction SUBTAG(fulltag_nodeheader_1,6)
158#define subtag_lock SUBTAG(fulltag_nodeheader_1,7)
159#define subtag_instance SUBTAG(fulltag_nodeheader_1,8)
160
161
162
163#define nil_value ((0x13000+fulltag_nil)+(LOWMEM_BIAS))
164#define t_value ((0x13020+fulltag_symbol)+(LOWMEM_BIAS))
165#define misc_bias fulltag_misc
166#define cons_bias fulltag_cons
167
168       
169#define misc_header_offset -fulltag_misc
170#define misc_subtag_offset misc_header_offset       /* low byte of header */
171#define misc_data_offset misc_header_offset+node_size   /* first word of data */
172#define misc_dfloat_offset misc_header_offset           /* double-floats are doubleword-aligned */
173
174#define subtag_single_float SUBTAG(fulltag_imm_0,0)
175#define subtag_character SUBTAG(fulltag_imm_1,0)
176
177#define subtag_unbound SUBTAG(fulltag_imm_1,1)
178#define unbound_marker subtag_unbound
179#define undefined unbound_marker
180#define unbound unbound_marker
181#define subtag_slot_unbound SUBTAG(fulltag_imm_1,2)
182#define slot_unbound_marker subtag_slot_unbound
183#define slot_unbound slot_unbound_marker
184#define subtag_illegal SUBTAG(fulltag_imm_1,3)
185#define illegal_marker subtag_illegal
186#define subtag_no_thread_local_binding SUBTAG(fulltag_imm_1,4)
187#define no_thread_local_binding_marker subtag_no_thread_local_binding
188#define subtag_reserved_frame  SUBTAG(fulltag_imm_1,5)
189#define reserved_frame_marker subtag_reserved_frame
190#define subtag_forward_marker SUBTAG(fulltag_imm_1,6)
191
192#define function_boundary_marker SUBTAG(fulltag_imm_1,15)       
193
194/*
195 * To determine the function associated with a tagged return
196 * address, we attempt to recognize an the instruction
197 * (lea (@ disp (% rip)) (% fn)) at the tra.
198 */
199#define RECOVER_FN_FROM_RIP_LENGTH 7 /* the instruction is 7 bytes long */
200#define RECOVER_FN_FROM_RIP_DISP_OFFSET 3 /* displacement word is 3 bytes in */
201#define RECOVER_FN_FROM_RIP_WORD0 0x8d4c /* 0x4c 0x8d, little-endian */
202#define RECOVER_FN_FROM_RIP_BYTE2 0x2d  /* third byte of opcode */
203
204
205/* The objects themselves look something like this: */
206
207
208typedef struct double_float {
209  LispObj header;
210  LispObj value;
211} double_float;
212
213
214
215typedef struct lisp_frame {
216  struct lisp_frame *backlink;
217  LispObj tra;
218  LispObj xtra;                 /* if tra is nvalretn */
219} lisp_frame;
220
221/* These are created on the lisp stack by the exception callback mechanism,
222   but nothing ever returns to them.  (At the very least, nothing -should-
223   try to return to them ...).
224*/
225typedef struct exception_callback_frame {
226  struct lisp_frame *backlink;
227  LispObj tra;                  /* ALWAYS 0 FOR AN XCF */
228  LispObj nominal_function;     /* the current function at the time of the exception */
229  LispObj relative_pc;          /* Boxed byte offset within actual function */
230  LispObj containing_uvector;   /* the uvector that contains the relative PC or NIL */
231  LispObj xp;                   /* exception context */
232  LispObj ra0;                  /* value of ra0 from context */
233  LispObj foreign_sp;           /* foreign sp at the time that exception occurred */
234  LispObj prev_xframe;          /* so %apply-in-frame can unwind it */
235  LispObj pc_low;               /* fixnum low half of absolute pc */
236  LispObj pc_high;              /* and the high half */
237} xcf;
238
239
240
241/*
242  The GC also needs to know what a catch_frame looks like.
243*/
244
245typedef struct catch_frame {
246  LispObj header;
247  LispObj catch_tag;
248  LispObj link;
249  LispObj mvflag;
250  LispObj csp;
251  LispObj db_link;
252  LispObj regs[4];
253  LispObj xframe;
254  LispObj tsp_segment;
255} catch_frame;
256
257#define catch_frame_element_count ((sizeof(catch_frame)/sizeof(LispObj))-1)
258#define catch_frame_header make_header(subtag_catch_frame,catch_frame_element_count)
259
260
261/*
262  All exception frames in a thread are linked together
263  */
264typedef struct xframe_list {
265  ExceptionInformation *curr;
266  struct xframe_list *prev;
267} xframe_list;
268
269#define fixnum_bitmask(n)  (1LL<<((n)+fixnumshift))
270
271
272#include "lisp-errors.h"
273
274
275
276#define TCR_BIAS (0x0)
277
278typedef struct tcr {
279  struct tcr* next;
280  struct tcr* prev;
281  struct {
282    u32_t tag;
283    float f;
284  } single_float_convert;
285  struct tcr* linear;
286  LispObj *save_fp;            /* RBP when in foreign code */
287  u32_t lisp_mxcsr;
288  u32_t foreign_mxcsr;
289  special_binding* db_link;     /* special binding chain head */
290  LispObj catch_top;            /* top catch frame */
291  LispObj* save_vsp;  /* VSP when in foreign code */
292  LispObj* save_tsp;  /* TSP when in foreign code */
293  LispObj* foreign_sp;
294  struct area* cs_area; /* cstack area pointer */
295  struct area* vs_area; /* vstack area pointer */
296  struct area* ts_area; /* tstack area pointer */
297  LispObj cs_limit;             /* stack overflow limit */
298  natural bytes_allocated;
299  natural log2_allocation_quantum;      /* for per-thread consing */
300  signed_natural interrupt_pending;     /* pending interrupt flag */
301  xframe_list* xframe; /* exception-frame linked list */
302  int* errno_loc;               /* per-thread (?) errno location */
303  LispObj ffi_exception;        /* fpscr bits from ff-call */
304  LispObj osid;                 /* OS thread id */
305  signed_natural valence;                       /* odd when in foreign code */
306  signed_natural foreign_exception_status;      /* non-zero -> call lisp_exit_hook */
307  void* native_thread_info;     /* platform-dependent */
308  void* native_thread_id;       /* mach_thread_t, pid_t, etc. */
309  char *last_allocptr;
310  char *save_allocptr;
311  char *save_allocbase;
312  void* reset_completion;
313  void* activate;
314  signed_natural suspend_count;
315  ExceptionInformation* suspend_context;
316  ExceptionInformation* pending_exception_context;
317  void* suspend;                /* suspension semaphore */
318  void* resume;                 /* resumption semaphore */
319  natural flags;
320  ExceptionInformation* gc_context;
321  void* termination_semaphore;
322  signed_natural unwinding;
323  natural tlb_limit;
324  LispObj* tlb_pointer;
325  natural shutdown_count;
326  LispObj* next_tsp;
327  void *safe_ref_address;
328  void *pending_io_info;
329  void *io_datum;
330} TCR;
331
332#define t_offset (t_value-nil_value)
333
334typedef struct {
335  natural Rip;
336  natural Cs;                   /* in low 16 bits */
337  natural Rflags;               /* in low 32 bits */
338  natural Rsp;
339  natural Ss;                   /* in low 16 bits*/
340} x64_iret_frame;
341
342/*
343  These were previously global variables.  There are lots of implicit
344  assumptions about the size of a heap segment, so they might as well
345  be constants.
346*/
347
348#define heap_segment_size 0x00020000L
349#define log2_heap_segment_size 17L
350
351#define ABI_VERSION_MIN 1039
352#define ABI_VERSION_CURRENT 1039
353#define ABI_VERSION_MAX 1039
Note: See TracBrowser for help on using the repository browser.