Change immobile space free pointers to alien vars
[sbcl.git] / src / compiler / generic / early-vm.lisp
blobecd064730f8be07acc8777582a36f0d0a33f5815
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
10 (in-package "SB!VM")
12 ;;; the number of bits per byte, where a byte is the smallest
13 ;;; addressable object
14 (defconstant n-byte-bits 8)
16 ;;; the number of bits at the low end of a pointer used for type
17 ;;; information
18 (defconstant n-lowtag-bits
19 (integer-length (1- (/ (* 2 n-word-bits) n-byte-bits))))
20 ;;; a mask to extract the low tag bits from a pointer
21 (defconstant lowtag-mask (1- (ash 1 n-lowtag-bits)))
22 ;;; the exclusive upper bound on the value of the low tag bits from a
23 ;;; pointer
24 (defconstant lowtag-limit (ash 1 n-lowtag-bits))
25 ;;; the number of tag bits used for a fixnum
26 (defconstant n-fixnum-tag-bits
27 ;; On 64-bit targets, this may be as low as 1 (for 63-bit
28 ;; fixnums) and as high as 3 (for 61-bit fixnums). The
29 ;; constraint on the low end is that we need at least one bit
30 ;; to determine if a value is a fixnum or not, and the
31 ;; constraint on the high end is that it must not exceed
32 ;; WORD-SHIFT (defined below) due to the use of unboxed
33 ;; word-aligned byte pointers as boxed values in various
34 ;; places. FIXME: This should possibly be exposed for
35 ;; configuration via customize-target-features.
36 #!+64-bit 1
37 ;; On 32-bit targets, this may be as low as 2 (for 30-bit
38 ;; fixnums) and as high as 2 (for 30-bit fixnums). The
39 ;; constraint on the low end is simple overcrowding of the
40 ;; lowtag space, and the constraint on the high end is that it
41 ;; must not exceed WORD-SHIFT.
42 #!-64-bit (1- n-lowtag-bits))
43 ;;; the fixnum tag mask
44 (defconstant fixnum-tag-mask (1- (ash 1 n-fixnum-tag-bits)))
45 ;;; the bit width of fixnums
46 (defconstant n-fixnum-bits (- n-word-bits n-fixnum-tag-bits))
47 ;;; the bit width of positive fixnums
48 (defconstant n-positive-fixnum-bits (1- n-fixnum-bits))
50 ;;; the number of bits to shift between word addresses and byte addresses
51 (defconstant word-shift (1- (integer-length (/ n-word-bits n-byte-bits))))
53 ;;; the number of bytes in a word
54 (defconstant n-word-bytes (/ n-word-bits n-byte-bits))
56 ;;; the number of bytes in a machine word
57 (defconstant n-machine-word-bytes (/ n-machine-word-bits n-byte-bits))
59 ;;; the number of bits used in the header word of a data block to store
60 ;;; the type
61 (defconstant n-widetag-bits 8)
62 ;;; a mask to extract the type from a data block header word
63 (defconstant widetag-mask (1- (ash 1 n-widetag-bits)))
65 (defconstant sb!xc:most-positive-fixnum
66 (1- (ash 1 n-positive-fixnum-bits))
67 "the fixnum closest in value to positive infinity")
68 (defconstant sb!xc:most-negative-fixnum
69 (ash -1 n-positive-fixnum-bits)
70 "the fixnum closest in value to negative infinity")
72 (defconstant most-positive-word (1- (expt 2 n-word-bits))
73 "The most positive integer that is of type SB-EXT:WORD.")
75 (defconstant most-positive-exactly-single-float-fixnum
76 (min (expt 2 single-float-digits) sb!xc:most-positive-fixnum))
77 (defconstant most-negative-exactly-single-float-fixnum
78 (max (- (expt 2 single-float-digits)) sb!xc:most-negative-fixnum))
79 (defconstant most-positive-exactly-double-float-fixnum
80 (min (expt 2 double-float-digits) sb!xc:most-positive-fixnum))
81 (defconstant most-negative-exactly-double-float-fixnum
82 (max (- (expt 2 double-float-digits)) sb!xc:most-negative-fixnum))
84 ;;;; Point where continuous area starting at dynamic-space-start bumps into
85 ;;;; next space.
86 #!+gencgc
87 (defconstant max-dynamic-space-end
88 (let ((stop (1- (ash 1 n-word-bits)))
89 (start default-dynamic-space-start))
90 (dolist (other-start (list read-only-space-start static-space-start
91 #!+linkage-table
92 linkage-table-space-start))
93 (declare (notinline <)) ; avoid dead code note
94 (when (< start other-start)
95 (setf stop (min stop other-start))))
96 stop))
98 ;; The lowest index that you can pass to %INSTANCE-REF accessing
99 ;; a slot of data that is not the instance-layout.
100 ;; To get a layout, you must call %INSTANCE-LAYOUT - don't assume index 0.
101 (defconstant instance-data-start (+ #!-compact-instance-header 1))
103 ;; The largest number that may appear in the header-data for an instance,
104 ;; and some other mostly-boxed objects, such as FDEFNs.
105 ;; This constraint exists because for objects managed by the immobile GC,
106 ;; their generation number is stored in the header, so we have to know
107 ;; how much to mask off to obtain the payload size.
108 ;; Objects whose payload gets capped to this limit are considered
109 ;; "short_boxed" objects in the sizetab[] array in 'gc-common'.
110 ;; Additionally there are "tiny_boxed" objects, the payload length of
111 ;; which can be expressed in 8 bits.
112 (defconstant short-header-max-words #x7fff)
114 ;;; Is X a fixnum in the target Lisp?
115 #+sb-xc-host
116 (defun fixnump (x)
117 (and (integerp x)
118 (<= sb!xc:most-negative-fixnum x sb!xc:most-positive-fixnum)))
120 ;;; Helper macro for defining FIXUP-CODE-OBJECT so that its body
121 ;;; can be the same between the host and target.
122 ;;; In the target, the byte offset supplied is relative to CODE-INSTRUCTIONS.
123 ;;; Genesis works differently - it adjusts the offset so that it is relative
124 ;;; to the containing gspace since that's what bvref requires.
125 (defmacro !with-bigvec-or-sap (&body body)
126 `(macrolet #-sb-xc-host ()
127 #+sb-xc-host
128 ((code-instructions (code) `(sb!fasl::descriptor-mem ,code))
129 (sap-int (sap)
130 ;; KLUDGE: SAP is a bigvec; it doesn't know its address.
131 ;; Note that this shadows the uncallable stub function for SAP-INT
132 ;; that placates the host when compiling 'compiler/*/move.lisp'.
133 (declare (ignore sap))
134 `(locally
135 (declare (notinline sb!fasl::descriptor-gspace)) ; fwd ref
136 (sb!fasl::gspace-byte-address
137 (sb!fasl::descriptor-gspace code)))) ; use CODE, not SAP
138 (sap-ref-8 (sap offset) `(sb!fasl::bvref-8 ,sap ,offset))
139 (sap-ref-32 (sap offset) `(sb!fasl::bvref-32 ,sap ,offset))
140 (sap-ref-word (sap offset) `(sb!fasl::bvref-word ,sap ,offset)))
141 ,@body))