source: branches/working-0711/ccl/lisp-kernel/x86-constants64.h @ 11089

Last change on this file since 11089 was 11089, checked in by gz, 13 years ago

Merge/bootstrap assorted low level stuff from trunk - kernel, syscall stuff, lowmem-bias, formatting tweaks, a few bug fixes included

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.9 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
17#ifdef DARWIN
18#define REG_RAX 0
19#define REG_RBX 1
20#define REG_RCX 2
21#define REG_RDX 3
22#define REG_RDI 4
23#define REG_RSI 5
24#define REG_RBP 6
25#define REG_RSP 7
26#define REG_R8 8
27#define REG_R9 9
28#define REG_R10 10
29#define REG_R11 11
30#define REG_R12 12
31#define REG_R13 13
32#define REG_R14 14
33#define REG_R15 15
34#define REG_RIP 16
35#define REG_RFL 17
36#endif
37
38#ifdef FREEBSD
39#define REG_RDI 1
40#define REG_RSI 2
41#define REG_RDX 3
42#define REG_RCX 4
43#define REG_R8 5
44#define REG_R9 6
45#define REG_RAX 7
46#define REG_RBX 8
47#define REG_RBP 9
48#define REG_R10 10
49#define REG_R11 11
50#define REG_R12 12
51#define REG_R13 13
52#define REG_R14 14
53#define REG_R15 15
54#define REG_RIP 20
55#define REG_RFL 22
56#define REG_RSP 23
57#endif
58
59#ifdef WIN_64
60/* DWORD64 indices in &(CONTEXT->Rax) */
61#define REG_RAX     0
62#define REG_RCX     1
63#define REG_RDX     2
64#define REG_RBX     3
65#define REG_RSP     4
66#define REG_RBP     5
67#define REG_RSI     6
68#define REG_RDI     7
69#define REG_R8      8
70#define REG_R9      9
71#define REG_R10     10
72#define REG_R11     11
73#define REG_R12     12
74#define REG_R13     13
75#define REG_R14     14
76#define REG_R15     15
77#define REG_RIP     16
78#endif
79/* Define indices of the GPRs in the mcontext component of a ucontext */
80#define Itemp0      REG_RBX
81#define Iarg_y      REG_RDI
82#define Iarg_x      REG_R8
83#define Iarg_z      REG_RSI
84#define Isave3      REG_R11
85#define Isave2      REG_R12
86#define Isave1      REG_R14
87#define Isave0      REG_R15
88#define Itemp2        REG_R10
89#define Ifn         REG_R13
90#define Irbp        REG_RBP
91#define Iimm0       REG_RAX
92#define Iimm1       REG_RDX
93#define Iimm2       REG_RCX
94#define Itemp1      REG_R9
95#define Isp         REG_RSP
96#define Iip         REG_RIP
97#if defined(LINUX) || defined(WINDOWS)
98#define Iflags      REG_EFL
99#endif
100
101#if defined(SOLARIS) || defined(FREEBSD) || defined(DARWIN)
102#define Iflags      REG_RFL
103#endif
104
105
106#define Iallocptr Itemp0
107#define Ira0 Itemp2
108#define Inargs Iimm2
109#define Ixfn Itemp1
110
111
112#define nbits_in_word 64L
113#define log2_nbits_in_word 6L
114#define nbits_in_byte 8L
115#define ntagbits 4L
116#define nlisptagbits 3L
117#define nfixnumtagbits 2L
118#define num_subtag_bits 8L
119#define fixnumshift 3L
120#define fixnum_shift 3L
121#define fulltagmask 15L
122#define tagmask  7L
123#define fixnummask 3
124#define subtagmask ((1L<<num_subtag_bits)-1L)
125#define ncharcodebits 8L
126#define charcode_shift 8L
127#define node_size 8L
128#define node_shift 3L
129
130
131#define tag_fixnum 0L
132#define tag_imm_0 1L            /* subtag_single_float ONLY */
133#define tag_imm_1 2L            /* subtag_character, internal markers */
134#define tag_list 3L             /* subtag_cons or NIL */
135#define tag_tra 4L              /* tagged return_address */
136#define tag_misc 5L             /* random uvector */
137#define tag_symbol 6L           /* non-null symbol */
138#define tag_function 7L /* function entry point */
139
140#define fulltag_even_fixnum 0L
141#define fulltag_imm_0 1L
142#define fulltag_imm_1 2L
143#define fulltag_cons 3L
144#define fulltag_tra_0 4L
145#define fulltag_nodeheader_0 5L
146#define fulltag_nodeheader_1 6L
147#define fulltag_immheader_0 7L
148#define fulltag_odd_fixnum 8L
149#define fulltag_immheader_1 9L
150#define fulltag_immheader_2 10L
151#define fulltag_nil 11L
152#define fulltag_tra_1 12L
153#define fulltag_misc 13L
154#define fulltag_symbol 14L
155#define fulltag_function 15L
156
157#define SUBTAG(tag,subtag) ((tag) | ((subtag) << ntagbits))
158#define subtag_arrayH SUBTAG(fulltag_nodeheader_0,10L)
159#define subtag_vectorH SUBTAG(fulltag_nodeheader_1,10L)
160#define subtag_simple_vector SUBTAG(fulltag_nodeheader_1,11L)
161#define min_vector_subtag subtag_vectorH       
162
163#define ivector_class_64_bit fulltag_immheader_2
164#define ivector_class_32_bit fulltag_immheader_1
165#define ivector_class_other_bit fulltag_immheader_0
166
167
168#define subtag_fixnum_vector SUBTAG(ivector_class_64_bit,12L)
169#define subtag_s64_vector SUBTAG(ivector_class_64_bit,13L)
170#define subtag_u64_vector SUBTAG(ivector_class_64_bit,14L)
171#define subtag_double_float_vector SUBTAG(ivector_class_64_bit,15L)
172
173#define subtag_simple_base_string SUBTAG(ivector_class_32_bit,12L)
174#define subtag_s32_vector SUBTAG(ivector_class_32_bit,13L)
175#define subtag_u32_vector SUBTAG(ivector_class_32_bit,14L)
176#define subtag_single_float_vector SUBTAG(ivector_class_32_bit,15L)
177
178#define subtag_s16_vector SUBTAG(ivector_class_other_bit,10L)
179#define subtag_u16_vector SUBTAG(ivector_class_other_bit,11L)
180#define subtag_s8_vector SUBTAG(ivector_class_other_bit,13L)
181#define subtag_u8_vector SUBTAG(ivector_class_other_bit,14L)
182#define subtag_bit_vector SUBTAG(ivector_class_other_bit,15L)
183/* min_8_bit_ivector_subtag is the old 8-bit simple_base_string */
184#define min_8_bit_ivector_subtag SUBTAG(ivector_class_other_bit,12L)
185
186/* There's some room for expansion in non-array ivector space. */
187#define subtag_macptr SUBTAG(ivector_class_64_bit,1)
188#define subtag_dead_macptr SUBTAG(ivector_class_64_bit,2)
189#define subtag_bignum SUBTAG(ivector_class_32_bit,0)
190#define subtag_double_float SUBTAG(ivector_class_32_bit,1)
191#define subtag_xcode_vector SUBTAG(ivector_class_32_bit,2)
192
193/* Note the difference between (e.g) fulltag_function - which
194   defines what the low 4 bytes of a function pointer look like -
195   and subtag_function - which describes what the subtag byte
196   in a function header looks like.  (Likewise for fulltag_symbol
197   and subtag_symbol)
198*/             
199
200#define subtag_symbol SUBTAG(fulltag_nodeheader_0,1)
201#define subtag_catch_frame SUBTAG(fulltag_nodeheader_0,2)
202#define subtag_hash_vector SUBTAG(fulltag_nodeheader_0,3)
203#define subtag_pool SUBTAG(fulltag_nodeheader_0,4)
204#define subtag_weak SUBTAG(fulltag_nodeheader_0,5)
205#define subtag_package SUBTAG(fulltag_nodeheader_0,6)
206#define subtag_slot_vector SUBTAG(fulltag_nodeheader_0,7)
207#define subtag_basic_stream SUBTAG(fulltag_nodeheader_0,8)
208#define subtag_function SUBTAG(fulltag_nodeheader_0,9)
209
210#define subtag_ratio SUBTAG(fulltag_nodeheader_1,1)
211#define subtag_complex SUBTAG(fulltag_nodeheader_1,2)
212#define subtag_struct SUBTAG(fulltag_nodeheader_1,3)
213#define subtag_istruct SUBTAG(fulltag_nodeheader_1,4)
214#define subtag_value_cell SUBTAG(fulltag_nodeheader_1,5)
215#define subtag_xfunction SUBTAG(fulltag_nodeheader_1,6)
216#define subtag_lock SUBTAG(fulltag_nodeheader_1,7)
217#define subtag_instance SUBTAG(fulltag_nodeheader_1,8)
218
219
220
221#define nil_value ((0x13000+fulltag_nil)+(LOWMEM_BIAS))
222#define t_value ((0x13020+fulltag_symbol)+(LOWMEM_BIAS))
223#define misc_bias fulltag_misc
224#define cons_bias fulltag_cons
225
226       
227#define misc_header_offset -fulltag_misc
228#define misc_subtag_offset misc_header_offset       /* low byte of header */
229#define misc_data_offset misc_header_offset+node_size   /* first word of data */
230#define misc_dfloat_offset misc_header_offset           /* double-floats are doubleword-aligned */
231
232#define subtag_single_float SUBTAG(fulltag_imm_0,0)
233#define subtag_character SUBTAG(fulltag_imm_1,0)
234
235#define subtag_unbound SUBTAG(fulltag_imm_1,1)
236#define unbound_marker subtag_unbound
237#define undefined unbound_marker
238#define unbound unbound_marker
239#define subtag_slot_unbound SUBTAG(fulltag_imm_1,2)
240#define slot_unbound_marker subtag_slot_unbound
241#define slot_unbound slot_unbound_marker
242#define subtag_illegal SUBTAG(fulltag_imm_1,3)
243#define illegal_marker subtag_illegal
244#define subtag_no_thread_local_binding SUBTAG(fulltag_imm_1,4)
245#define no_thread_local_binding_marker subtag_no_thread_local_binding
246#define subtag_reserved_frame  SUBTAG(fulltag_imm_1,5)
247#define reserved_frame_marker subtag_reserved_frame
248#define subtag_forward_marker SUBTAG(fulltag_imm_1,6)
249
250#define function_boundary_marker SUBTAG(fulltag_imm_1,15)       
251
252/* The objects themselves look something like this: */
253
254/*  Order of CAR and CDR doesn't seem to matter much - there aren't */
255/*  too many tricks to be played with predecrement/preincrement addressing. */
256/*  Keep them in the confusing MCL 3.0 order, to avoid confusion. */
257
258typedef struct cons {
259  LispObj cdr;
260  LispObj car;
261} cons;
262
263
264
265typedef struct lispsymbol {
266  LispObj header;
267  LispObj pname;
268  LispObj vcell;
269  LispObj fcell;
270  LispObj package_predicate;
271  LispObj flags;
272  LispObj plist;
273  LispObj binding_index;
274} lispsymbol;
275
276typedef struct ratio {
277  LispObj header;
278  LispObj numer;
279  LispObj denom;
280} ratio;
281
282typedef struct double_float {
283  LispObj header;
284  LispObj value;
285} double_float;
286
287
288typedef struct macptr {
289  LispObj header;
290  LispObj address;
291  LispObj class;
292  LispObj type;
293} macptr;
294
295typedef struct xmacptr {
296  LispObj header;
297  LispObj address;
298  LispObj class;
299  LispObj type;
300  LispObj flags;
301  LispObj link;
302} xmacptr;
303 
304
305
306typedef struct special_binding {
307  struct special_binding *link;
308  struct lispsymbol *sym;
309  LispObj value;
310} special_binding;
311
312typedef struct lisp_frame {
313  struct lisp_frame *backlink;
314  LispObj tra;
315  LispObj xtra;                 /* if tra is nvalretn */
316} lisp_frame;
317
318/* These are created on the lisp stack by the exception callback mechanism,
319   but nothing ever returns to them.  (At the very least, nothing -should-
320   try to return to them ...).
321*/
322typedef struct exception_callback_frame {
323  struct lisp_frame *backlink;
324  LispObj tra;                  /* ALWAYS 0 FOR AN XCF */
325  LispObj nominal_function;     /* the current function at the time of the exception */
326  LispObj relative_pc;          /* Boxed byte offset within actual
327                                   function or absolute address */
328  LispObj containing_uvector;   /* the uvector that contains the relative PC or NIL */
329  LispObj xp;                   /* exception context */
330  LispObj ra0;                  /* value of ra0 from context */
331  LispObj foreign_sp;           /* foreign sp at the time that exception occurred */
332  LispObj prev_xframe;          /* so %apply-in-frame can unwind it */
333} xcf;
334
335
336/* The GC (at least) needs to know what a
337   package looks like, so that it can do GCTWA. */
338typedef struct package {
339  LispObj header;
340  LispObj itab;                 /* itab and etab look like (vector (fixnum . fixnum) */
341  LispObj etab;
342  LispObj used;
343  LispObj used_by;
344  LispObj names;
345  LispObj shadowed;
346} package;
347
348/*
349  The GC also needs to know what a catch_frame looks like.
350*/
351
352typedef struct catch_frame {
353  LispObj header;
354  LispObj catch_tag;
355  LispObj link;
356  LispObj mvflag;
357  LispObj csp;
358  LispObj db_link;
359  LispObj regs[4];
360  LispObj xframe;
361  LispObj tsp_segment;
362} catch_frame;
363
364#define catch_frame_element_count ((sizeof(catch_frame)/sizeof(LispObj))-1)
365#define catch_frame_header make_header(subtag_catch_frame,catch_frame_element_count)
366
367
368/*
369  All exception frames in a thread are linked together
370  */
371typedef struct xframe_list {
372  ExceptionInformation *curr;
373  struct xframe_list *prev;
374} xframe_list;
375
376#define fixnum_bitmask(n)  (1LL<<((n)+fixnumshift))
377
378/*
379  The GC (at least) needs to know about hash-table-vectors and their flag bits.
380*/
381
382typedef struct hash_table_vector_header {
383  LispObj header;
384  LispObj link;                 /* If weak */
385  LispObj flags;                /* a fixnum; see below */
386  LispObj gc_count;             /* gc-count kernel global */
387  LispObj free_alist;           /* preallocated conses for finalization_alist */
388  LispObj finalization_alist;   /* key/value alist for finalization */
389  LispObj weak_deletions_count; /* incremented when GC deletes weak pair */
390  LispObj hash;                 /* backpointer to hash-table */
391  LispObj deleted_count;        /* number of deleted entries [not maintained if lock-free] */
392  LispObj count;                /* number of valid entries [not maintained if lock-free] */
393  LispObj cache_idx;            /* index of last cached pair */
394  LispObj cache_key;            /* value of last cached key */
395  LispObj cache_value;          /* last cached value */
396  LispObj size;                 /* number of entries in table */
397  LispObj size_reciprocal;      /* shifted reciprocal of size */
398} hash_table_vector_header;
399
400/*
401  Bits (masks)  in hash_table_vector.flags:
402*/
403
404/* GC should track keys when addresses change */ 
405#define nhash_track_keys_mask fixnum_bitmask(28)
406
407/* GC should set when nhash_track_keys_bit & addresses change */
408#define nhash_key_moved_mask  fixnum_bitmask(27)
409
410/* weak on key or value (need new "weak both" encoding.) */
411#define nhash_weak_mask       fixnum_bitmask(12)
412
413/* weak on value */
414#define nhash_weak_value_mask fixnum_bitmask(11)
415
416/* finalizable */
417#define nhash_finalizable_mask fixnum_bitmask(10)
418
419/* keys frozen, i.e. don't clobber keys, only values */
420#define nhash_keys_frozen_mask fixnum_bitmask(9)
421
422/* Lfun bits */
423
424#define lfbits_nonnullenv_mask fixnum_bitmask(0)
425#define lfbits_keys_mask fixnum_bitmask(1)
426#define lfbits_restv_mask fixnum_bitmask(7)
427#define lfbits_optinit_mask fixnum_bitmask(14)
428#define lfbits_rest_mask fixnum_bitmask(15)
429#define lfbits_aok_mask fixnum_bitmask(16)
430#define lfbits_lap_mask fixnum_bitmask(23)
431#define lfbits_trampoline_mask fixnum_bitmask(24)
432#define lfbits_evaluated_mask fixnum_bitmask(25)
433#define lfbits_cm_mask fixnum_bitmask(26)         /* combined_method */
434#define lfbits_nextmeth_mask fixnum_bitmask(26)   /* or call_next_method with method_mask */
435#define lfbits_gfn_mask fixnum_bitmask(27)        /* generic_function */
436#define lfbits_nextmeth_with_args_mask fixnum_bitmask(27)   /* or call_next_method_with_args with method_mask */
437#define lfbits_method_mask fixnum_bitmask(28)     /* method function */
438/* PPC only but want it defined for xcompile */
439#define lfbits_noname_mask fixnum_bitmask(29)
440
441/*
442  known values of an "extended" (gcable) macptr's flags word:
443*/
444
445typedef enum {
446  xmacptr_flag_none = 0,        /* Maybe already disposed by Lisp */
447  xmacptr_flag_recursive_lock,  /* recursive-lock */
448  xmacptr_flag_ptr,             /* malloc/free */
449  xmacptr_flag_rwlock,          /* read/write lock */
450  xmacptr_flag_semaphore        /* semaphore */
451} xmacptr_flag;
452
453/* Creole */
454
455#define doh_quantum 400
456#define doh_block_slots ((doh_quantum >> 2) - 3)
457
458typedef struct doh_block {
459  struct doh_block *link;
460  unsigned size;
461  unsigned free;
462  LispObj data[doh_block_slots];
463} doh_block, *doh_block_ptr;
464
465
466#define population_weak_list (0<<fixnum_shift)
467#define population_weak_alist (1<<fixnum_shift)
468#define population_termination_bit (16+fixnum_shift)
469#define population_type_mask ((1<<population_termination_bit)-1)
470
471#define gc_retain_pages_bit fixnum_bitmask(0)
472#define gc_integrity_check_bit fixnum_bitmask(2)
473#define egc_verbose_bit fixnum_bitmask(3)
474#define gc_verbose_bit fixnum_bitmask(4)
475#define gc_allow_stack_overflows_bit fixnum_bitmask(5)
476#define gc_postgc_pending fixnum_bitmask(26)
477
478#include "lisp-errors.h"
479
480
481
482#define TCR_BIAS (0x0)
483
484typedef struct tcr {
485  struct tcr* next;
486  struct tcr* prev;
487  struct {
488    u32_t tag;
489    float f;
490  } single_float_convert;
491  struct tcr* linear;
492  LispObj *save_rbp;            /* RBP when in foreign code */
493  u32_t lisp_mxcsr;
494  u32_t foreign_mxcsr;
495  special_binding* db_link;     /* special binding chain head */
496  LispObj catch_top;            /* top catch frame */
497  LispObj* save_vsp;  /* VSP when in foreign code */
498  LispObj* save_tsp;  /* TSP when in foreign code */
499  LispObj* foreign_sp;
500  struct area* cs_area; /* cstack area pointer */
501  struct area* vs_area; /* vstack area pointer */
502  struct area* ts_area; /* tstack area pointer */
503  LispObj cs_limit;             /* stack overflow limit */
504  natural bytes_allocated;
505  natural log2_allocation_quantum;      /* for per-thread consing */
506  signed_natural interrupt_pending;     /* pending interrupt flag */
507  xframe_list* xframe; /* exception-frame linked list */
508  int* errno_loc;               /* per-thread (?) errno location */
509  LispObj ffi_exception;        /* fpscr bits from ff-call */
510  LispObj osid;                 /* OS thread id */
511  signed_natural valence;                       /* odd when in foreign code */
512  signed_natural foreign_exception_status;      /* non-zero -> call lisp_exit_hook */
513  void* native_thread_info;     /* platform-dependent */
514  void* native_thread_id;       /* mach_thread_t, pid_t, etc. */
515  void* last_allocptr;
516  void* save_allocptr;
517  void* save_allocbase;
518  void* reset_completion;
519  void* activate;
520  signed_natural suspend_count;
521  ExceptionInformation* suspend_context;
522  ExceptionInformation* pending_exception_context;
523  void* suspend;                /* suspension semaphore */
524  void* resume;                 /* resumption semaphore */
525  natural flags;
526  ExceptionInformation* gc_context;
527  void* termination_semaphore;
528  signed_natural unwinding;
529  natural tlb_limit;
530  LispObj* tlb_pointer;
531  natural shutdown_count;
532  LispObj* next_tsp;
533  void *safe_ref_address;
534} TCR;
535
536#define t_offset (t_value-nil_value)
537
538typedef struct {
539  natural Rip;
540  natural Cs;                   /* in low 16 bits */
541  natural Rflags;               /* in low 32 bits */
542  natural Rsp;
543  natural Ss;                   /* in low 16 bits*/
544} x64_iret_frame;
545
546/*
547  These were previously global variables.  There are lots of implicit
548  assumptions about the size of a heap segment, so they might as well
549  be constants.
550*/
551
552#define heap_segment_size 0x00020000L
553#define log2_heap_segment_size 17L
554
Note: See TracBrowser for help on using the repository browser.