source: branches/x8664-call/ccl/lisp-kernel/x86-constants64.h @ 6384

Last change on this file since 6384 was 6384, checked in by gb, 15 years ago

Reassign registers: %rcx = %imm2, %r10 = %temp2.
This basically means that we get an additional immediate register.

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