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

Last change on this file since 12198 was 12198, checked in by gz, 10 years ago

Merge with trunk kernel (and a few compiler changes to match): a few bug fixes, a lot of changes for other platforms.

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