source: branches/working-0711/ccl/lisp-kernel/ppc-constants32.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.2 KB
Line 
1/*
2   Copyright (C) 1994-2001 Digitool, Inc
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#ifndef __constants32__
18#define __constants32__ 1
19
20#define rcontext 13
21
22#define nbits_in_word 32
23#define log2_nbits_in_word 5
24#define nbits_in_byte 8
25#define ntagbits 3      /* But only 2 are significant to lisp */
26#define nlisptagbits 2
27#define nfixnumtagbits 2
28#define num_subtag_bits 8
29#define fixnumshift 2
30#define fixnum_shift 2
31#define fulltagmask 7
32#define tagmask  3
33#define fixnummask 3
34#define subtagmask ((1<<num_subtag_bits)-1)
35#define ncharcodebits 24        /* Only the low 8 are used currently */
36#define charcode_shift (nbits_in_word-ncharcodebits)
37#define node_size 4
38#define node_shift 2
39
40/*  Tags. */
41/*  There are two-bit tags and three-bit tags. */
42/*  A FULLTAG is the value of the low three bits of a tagged object. */
43/*  A TAG is the value of the low two bits of a tagged object. */
44/*  A TYPECODE is either a TAG or the value of a "tag-misc" object's header-byte. */
45
46/*  There are 4 primary TAG values.  Any object which lisp can "see" can be classified  */
47/*  by its TAG.  (Some headers have FULLTAGS that are congruent modulo 4 with the */
48/*  TAGS of other objects, but lisp can't "see" headers.) */
49
50
51#define tag_fixnum 0    /*  All fixnums, whether odd or even */
52#define tag_list 1      /*  Conses and NIL */
53#define tag_misc 2      /*  Heap-consed objects other than lists: vectors, symbols, functions, floats ... */
54#define tag_imm  3      /*  Immediate-objects: characters, UNBOUND, other markers. */
55
56/*  And there are 8 FULLTAG values.  Note that NIL has its own FULLTAG (congruent mod 4 to tag-list), */
57/*  that FULLTAG-MISC is > 4 (so that code-vector entry-points can be branched to, since the low */
58/*  two bits of the PC are ignored) and that both FULLTAG-MISC and FULLTAG-IMM have header fulltags */
59/*  that share the same TAG. */
60/*  Things that walk memory (and the stack) have to be careful to look at the FULLTAG of each */
61/*  object that they see. */
62
63#define fulltag_even_fixnum 0   /*  I suppose EVENP/ODDP might care; nothing else does. */
64#define fulltag_cons     1      /*  a real (non_null) cons.  Shares TAG with fulltag_nil. */
65#define fulltag_nodeheader 2    /*  Header of heap_allocated object that contains lisp_object pointers */
66#define fulltag_imm      3      /*  a "real" immediate object.  Shares TAG with fulltag_immheader. */
67#define fulltag_odd_fixnum 4    /*   */
68#define fulltag_nil      5      /*  NIL and nothing but.  (Note that there's still a hidden NILSYM.) */
69#define fulltag_misc     6      /*  Pointer "real" tag_misc object.  Shares TAG with fulltag_nodeheader. */
70#define fulltag_immheader 7     /*  Header of heap-allocated object that contains unboxed data. */
71
72
73
74/*  Order of CAR and CDR doesn't seem to matter much - there aren't */
75/*  too many tricks to be played with predecrement/preincrement addressing. */
76/*  Keep them in the confusing MCL 3.0 order, to avoid confusion. */
77
78typedef struct cons {
79  LispObj cdr;
80  LispObj car;
81} cons;
82
83
84#define misc_header_offset -fulltag_misc
85#define misc_subtag_offset misc_header_offset+3         /*  low byte of header */
86#define misc_data_offset misc_header_offset+4           /*  first word of data */
87#define misc_dfloat_offset misc_header_offset+8         /*  double-floats are doubleword-aligned */
88
89#define max_64_bit_constant_index ((0x7fff + misc_dfloat_offset)>>3)
90#define max_32_bit_constant_index ((0x7fff + misc_data_offset)>>2)
91#define max_16_bit_constant_index ((0x7fff + misc_data_offset)>>1)
92#define max_8_bit_constant_index (0x7fff + misc_data_offset)
93#define max_1_bit_constant_index ((0x7fff + misc_data_offset)<<5)
94
95/*  T is almost adjacent to NIL: since NIL is a misaligned CONS, it spans */
96/*  two doublewords.  The arithmetic difference between T and NIL is */
97/*  such that the least-significant bit and exactly one other bit is */
98/*  set in the result. */
99
100#define t_offset (8+(8-fulltag_nil)+fulltag_misc)
101#define t_value (lisp_nil+t_offset)
102
103/*  The order in which various header values are defined is significant in several ways: */
104/*  1) Numeric subtags precede non-numeric ones; there are further orderings among numeric subtags. */
105/*  2) All subtags which denote CL arrays are preceded by those that don't, */
106/*     with a further ordering which requires that (< header-arrayH header-vectorH ,@all-other-CL-vector-types) */
107/*  3) The element-size of ivectors is determined by the ordering of ivector subtags. */
108/*  4) All subtags are >= fulltag-immheader . */
109
110#define SUBTAG(tag,subtag) ((tag) | ((subtag) << ntagbits))
111#define IMM_SUBTAG(subtag) SUBTAG(fulltag_immheader,(subtag))
112#define NODE_SUBTAG(subtag) SUBTAG(fulltag_nodeheader,(subtag))
113
114       
115/* Numeric subtags. */
116
117#define subtag_bignum IMM_SUBTAG(0)
118#define min_numeric_subtag subtag_bignum
119
120#define subtag_ratio NODE_SUBTAG(1)
121#define max_rational_subtag subtag_ratio
122
123#define subtag_single_float IMM_SUBTAG(1)
124#define subtag_double_float IMM_SUBTAG(2)
125#define min_float_subtag subtag_single_float
126#define max_float_subtag subtag_double_float
127#define max_real_subtag subtag_double_float
128
129#define subtag_complex NODE_SUBTAG(3)
130#define max_numeric_subtag subtag_complex
131
132
133/*  CL array types.  There are more immediate types than node types; all CL array subtags must be > than */
134/*  all non-CL-array subtags.  So we start by defining the immediate subtags in decreasing order, starting */
135/*  with that subtag whose element size isn't an integral number of bits and ending with those whose */
136/*  element size - like all non-CL-array fulltag-immheader types - is 32 bits. */
137
138#define subtag_bit_vector IMM_SUBTAG(31)
139#define subtag_double_float_vector IMM_SUBTAG(30)
140#define subtag_s16_vector IMM_SUBTAG(29)
141#define subtag_u16_vector IMM_SUBTAG(28)
142#define min_16_bit_ivector_subtag subtag_u16_vector
143#define max_16_bit_ivector_subtag subtag_s16_vector
144
145#define subtag_s8_vector IMM_SUBTAG(26)
146#define subtag_u8_vector IMM_SUBTAG(25)
147#define min_8_bit_ivector_subtag subtag_u8_vector
148#define max_8_bit_ivector_subtag IMM_SUBTAG(27)
149
150#define subtag_simple_base_string IMM_SUBTAG(24)
151#define subtag_fixnum_vector IMM_SUBTAG(23)
152#define subtag_s32_vector IMM_SUBTAG(22)
153#define subtag_u32_vector IMM_SUBTAG(21)
154#define subtag_single_float_vector IMM_SUBTAG(20)
155#define max_32_bit_ivector_subtag IMM_SUBTAG(24)
156#define min_cl_ivector_subtag subtag_single_float_vector
157
158
159#define subtag_vectorH NODE_SUBTAG(20)
160#define subtag_arrayH NODE_SUBTAG(19)
161#define subtag_simple_vector NODE_SUBTAG(21)    /*  Only one such subtag) */
162#define min_vector_subtag subtag_vectorH
163#define min_array_subtag subtag_arrayH
164
165/*  So, we get the remaining subtags (n: (n > max-numeric-subtag) & (n < min-array-subtag)) */
166/*  for various immediate/node object types. */
167
168#define subtag_macptr IMM_SUBTAG(3)
169#define min_non_numeric_imm_subtag subtag_macptr
170
171#define subtag_dead_macptr IMM_SUBTAG(4)
172#define subtag_code_vector IMM_SUBTAG(5)
173#define subtag_creole IMM_SUBTAG(6)
174
175#define max_non_array_imm_subtag ((19<<ntagbits)|fulltag_immheader)
176
177#define subtag_catch_frame NODE_SUBTAG(4)
178#define subtag_function NODE_SUBTAG(5)
179#define subtag_basic_stream NODE_SUBTAG(6)
180#define subtag_symbol NODE_SUBTAG(7)
181#define subtag_lock NODE_SUBTAG(8)
182#define subtag_hash_vector NODE_SUBTAG(9)
183#define subtag_pool NODE_SUBTAG(10)
184#define subtag_weak NODE_SUBTAG(11)
185#define subtag_package NODE_SUBTAG(12)
186#define subtag_slot_vector NODE_SUBTAG(13)
187#define subtag_instance NODE_SUBTAG(14)
188#define subtag_struct NODE_SUBTAG(15)
189#define subtag_istruct NODE_SUBTAG(16)
190#define max_non_array_node_subtag ((19<<ntagbits)|fulltag_immheader)
191       
192/*  The objects themselves look something like this: */
193
194typedef struct lispsymbol {
195  LispObj header;
196  LispObj pname;
197  LispObj vcell;
198  LispObj fcell;
199  LispObj package_predicate;
200  LispObj flags;
201  LispObj plist;
202  LispObj binding_index;
203} lispsymbol;
204
205typedef struct ratio {
206  LispObj header;
207  LispObj numer;
208  LispObj denom;
209} ratio;
210
211typedef struct double_float {
212  LispObj header;
213  LispObj pad;
214  LispObj value_high;
215  LispObj value_low;
216} double_float;
217
218typedef struct single_float {
219  LispObj header;
220  LispObj value;
221} single_float;
222
223typedef struct macptr {
224  LispObj header;
225  LispObj address;
226  LispObj class;
227  LispObj type;
228} macptr;
229
230typedef struct xmacptr {
231  LispObj header;
232  LispObj address;
233  LispObj class;
234  LispObj type;
235  LispObj flags;
236  LispObj link;
237} xmacptr;
238 
239
240typedef struct eabi_c_frame {
241  struct eabi_c_frame *backlink;
242  unsigned savelr;
243  unsigned params[8];
244} eabi_c_frame;
245
246/* PowerOpen ABI C frame */
247
248typedef struct c_frame {
249  struct c_frame *backlink;
250  unsigned crsave;
251  unsigned savelr;
252  unsigned unused[2];
253  unsigned savetoc;             /* Used with CFM */
254  unsigned params[8];           /* Space for callee to save r3-r10 */
255} c_frame;
256
257typedef struct lisp_frame {
258  struct lisp_frame *backlink;
259  LispObj savefn;
260  LispObj savelr;
261  LispObj savevsp;
262} lisp_frame;
263
264typedef struct special_binding {
265  struct special_binding *link;
266  struct lispsymbol *sym;
267  LispObj value;
268} special_binding;
269
270/* The GC (at least) needs to know what a
271   package looks like, so that it can do GCTWA. */
272typedef struct package {
273  LispObj header;
274  LispObj itab;                 /* itab and etab look like (vector (fixnum . fixnum) */
275  LispObj etab;
276  LispObj used;
277  LispObj used_by;
278  LispObj names;
279  LispObj shadowed;
280} package;
281
282/*
283  The GC also needs to know what a catch_frame looks like.
284*/
285
286typedef struct catch_frame {
287  LispObj header;
288  LispObj catch_tag;
289  LispObj link;
290  LispObj mvflag;
291  LispObj csp;
292  LispObj db_link;
293  LispObj regs[8];
294  LispObj xframe;
295  LispObj tsp_segment;
296} catch_frame;
297
298#define catch_frame_element_count ((sizeof(catch_frame)/sizeof(LispObj))-1)
299#define catch_frame_header make_header(subtag_catch_frame,catch_frame_element_count)
300
301#define unbound SUBTAG(fulltag_imm, 6)
302#define undefined unbound
303#define unbound_marker unbound
304#define subtag_character SUBTAG(fulltag_imm, 9)
305#define slot_unbound SUBTAG(fulltag_imm, 10)
306#define slot_unbound_marker slot_unbound
307#define no_thread_local_binding_marker SUBTAG(fulltag_imm,30)
308
309/*
310  All exception frames in a thread are linked together
311  */
312typedef struct xframe_list {
313  ExceptionInformation *curr;
314  struct xframe_list *prev;
315} xframe_list;
316
317#define fixnum_bitmask(n)  (1<<((n)+fixnumshift))
318
319/*
320  The GC (at least) needs to know about hash-table-vectors and their flag bits.
321*/
322
323typedef struct hash_table_vector_header {
324  LispObj header;
325  LispObj link;                 /* If weak */
326  LispObj flags;                /* a fixnum; see below */
327  LispObj gc_count;             /* gc-count kernel global */
328  LispObj free_alist;           /* preallocated conses for finalization_alist */
329  LispObj finalization_alist;   /* key/value alist for finalization */
330  LispObj weak_deletions_count; /* incremented when GC deletes weak pair */
331  LispObj hash;                 /* backpointer to hash-table */
332  LispObj deleted_count;        /* number of deleted entries [not maintained if lock-free] */
333  LispObj count;                /* number of valid entries [not maintained if lock-free] */
334  LispObj cache_idx;            /* index of last cached pair */
335  LispObj cache_key;            /* value of last cached key */
336  LispObj cache_value;          /* last cached value */
337  LispObj size;                 /* number of entries in table */
338  LispObj size_reciprocal;      /* shifted reciprocal of size */
339} hash_table_vector_header;
340
341/*
342  Bits (masks)  in hash_table_vector.flags:
343*/
344
345/* GC should track keys when addresses change */ 
346#define nhash_track_keys_mask fixnum_bitmask(28)
347
348/* GC should set when nhash_track_keys_bit & addresses change */
349#define nhash_key_moved_mask  fixnum_bitmask(27)
350
351/* weak on key or value (need new "weak both" encoding.) */
352#define nhash_weak_mask       fixnum_bitmask(12)
353
354/* weak on value */
355#define nhash_weak_value_mask fixnum_bitmask(11)
356
357/* finalizable */
358#define nhash_finalizable_mask fixnum_bitmask(10)
359
360/* keys frozen, i.e. don't clobber keys, only values */
361#define nhash_keys_frozen_mask fixnum_bitmask(9)
362
363/* Lfun bits */
364
365#define lfbits_nonnullenv_mask fixnum_bitmask(0)
366#define lfbits_keys_mask fixnum_bitmask(1)
367#define lfbits_restv_mask fixnum_bitmask(7)
368#define lfbits_optinit_mask fixnum_bitmask(14)
369#define lfbits_rest_mask fixnum_bitmask(15)
370#define lfbits_aok_mask fixnum_bitmask(16)
371#define lfbits_lap_mask fixnum_bitmask(23)
372#define lfbits_trampoline_mask fixnum_bitmask(24)
373#define lfbits_evaluated_mask fixnum_bitmask(25)
374#define lfbits_cm_mask fixnum_bitmask(26)         /* combined_method */
375#define lfbits_nextmeth_mask fixnum_bitmask(26)   /* or call_next_method with method_mask */
376#define lfbits_gfn_mask fixnum_bitmask(27)        /* generic_function */
377#define lfbits_nextmeth_with_args_mask fixnum_bitmask(27)   /* or call_next_method_with_args with method_mask */
378#define lfbits_method_mask fixnum_bitmask(28)     /* method function */
379/* PPC only but want it defined for xcompile */
380#define lfbits_noname_mask fixnum_bitmask(29)
381
382/*
383  known values of an "extended" (gcable) macptr's flags word:
384*/
385
386typedef enum {
387  xmacptr_flag_none = 0,        /* Maybe already disposed by Lisp */
388  xmacptr_flag_recursive_lock,  /* recursive-lock */
389  xmacptr_flag_ptr,             /* malloc/free */
390  xmacptr_flag_rwlock,          /* read/write lock */
391  xmacptr_flag_semaphore        /* semaphore */
392} xmacptr_flag;
393
394/* Creole */
395
396#define doh_quantum 400
397#define doh_block_slots ((doh_quantum >> 2) - 3)
398
399typedef struct doh_block {
400  struct doh_block *link;
401  unsigned size;
402  unsigned free;
403  LispObj data[doh_block_slots];
404} doh_block, *doh_block_ptr;
405
406
407#define population_weak_list (0<<fixnum_shift)
408#define population_weak_alist (1<<fixnum_shift)
409#define population_termination_bit (16+fixnum_shift)
410#define population_type_mask ((1<<population_termination_bit)-1)
411
412#define gc_retain_pages_bit fixnum_bitmask(0)
413#define gc_integrity_check_bit fixnum_bitmask(2)
414#define egc_verbose_bit fixnum_bitmask(3)
415#define gc_verbose_bit fixnum_bitmask(4)
416#define gc_allow_stack_overflows_bit fixnum_bitmask(5)
417#define gc_postgc_pending fixnum_bitmask(26)
418
419#include "lisp-errors.h"
420
421
422
423
424#define nil_value (0x00003015+(LOWMEM_BIAS))
425
426#define TCR_BIAS (0)
427
428typedef struct tcr {
429  struct tcr *next;
430  struct tcr *prev;
431  union {
432    double d;
433    struct {unsigned h, l;} words;
434  } lisp_fpscr;                 /* lisp thread's fpscr (in low word) */
435  special_binding *db_link;     /* special binding chain head */
436  LispObj catch_top;            /* top catch frame */
437  LispObj *save_vsp;            /* VSP when in foreign code */
438  LispObj *save_tsp;            /* TSP when in foreign code */
439  struct area *cs_area;         /* cstack area pointer */
440  struct area *vs_area;         /* vstack area pointer */
441  struct area *ts_area;         /* tstack area pointer */
442  LispObj cs_limit;             /* stack overflow limit */
443  unsigned long long bytes_allocated;
444  natural log2_allocation_quantum;  /* for per-thread consing */
445  int interrupt_pending;        /* deferred-interrupt pending */
446  xframe_list *xframe;          /* exception-frame linked list */
447  int *errno_loc;               /* per-thread (?) errno location */
448  LispObj ffi_exception;        /* fpscr bits from ff-call */
449  LispObj osid;                 /* OS thread id */
450  int valence;                  /* odd when in foreign code */
451  int foreign_exception_status; /* non-zero -> call lisp_exit_hook */
452  void *native_thread_info;     /* platform-dependent */
453  void *native_thread_id;       /* mach_thread_t, pid_t, etc. */
454  void *last_allocptr;
455  void *save_allocptr;
456  void *save_allocbase;
457  void *reset_completion;
458  void *activate;
459  int suspend_count;
460  ExceptionInformation *suspend_context;
461  ExceptionInformation *pending_exception_context;
462  void *suspend;                /* suspension semaphore */
463  void *resume;                 /* resumption semaphore */
464  natural flags;
465  ExceptionInformation *gc_context;
466  void *termination_semaphore;
467  int unwinding;
468  unsigned tlb_limit;
469  LispObj *tlb_pointer;
470  unsigned shutdown_count;
471  void *safe_ref_address;
472} TCR;
473
474/*
475  These were previously global variables.  There are lots of implicit
476  assumptions about the size of a heap segment, so they might as well
477  be constants.
478*/
479
480#define heap_segment_size 0x00010000
481#define log2_heap_segment_size 16
482
483
484#endif
485
Note: See TracBrowser for help on using the repository browser.