source: trunk/ccl/lisp-kernel/constants32.h @ 557

Last change on this file since 557 was 557, checked in by gb, 16 years ago

PPC64 changes (some of them rather suspect ...). 32-bit kernel may be a
little funky ...

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