1 ;;;; This file contains some parameterizations of various VM
2 ;;;; attributes for the x86. This file is separate from other stuff so
3 ;;;; that it can be compiled and loaded earlier.
5 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
16 ;;; ### Note: we simultaneously use ``word'' to mean a 32 bit quantity
17 ;;; and a 16 bit quantity depending on context. This is because Intel
18 ;;; insists on calling 16 bit things words and 32 bit things
19 ;;; double-words (or dwords). Therefore, in the instruction definition
20 ;;; and register specs, we use the Intel convention. But whenever we
21 ;;; are talking about stuff the rest of the lisp system might be
22 ;;; interested in, we use ``word'' to mean the size of a descriptor
23 ;;; object, which is 32 bits.
25 ;;;; machine architecture parameters
27 (defconstant word-bits 32
29 "Number of bits per word where a word holds one lisp descriptor.")
31 (defconstant byte-bits 8
33 "Number of bits per byte where a byte is the smallest addressable object.")
35 (defconstant word-shift (1- (integer-length (/ word-bits byte-bits)))
37 "Number of bits to shift between word addresses and byte addresses.")
39 (defconstant word-bytes (/ word-bits byte-bits)
41 "Number of bytes in a word.")
43 (defconstant float-sign-shift 31)
45 ;;; comment from CMU CL:
46 ;;; These values were taken from the alpha code. The values for
47 ;;; bias and exponent min/max are not the same as shown in the 486 book.
48 ;;; They may be correct for how Python uses them.
49 (defconstant single-float-bias 126) ; Intel says 127.
50 (defconstant-eqx single-float-exponent-byte (byte 8 23) #'equalp)
51 (defconstant-eqx single-float-significand-byte (byte 23 0) #'equalp)
52 ;;; comment from CMU CL:
53 ;;; The 486 book shows the exponent range -126 to +127. The Lisp
54 ;;; code that uses these values seems to want already biased numbers.
55 (defconstant single-float-normal-exponent-min 1)
56 (defconstant single-float-normal-exponent-max 254)
57 (defconstant single-float-hidden-bit (ash 1 23))
58 (defconstant single-float-trapping-nan-bit (ash 1 22))
60 (defconstant double-float-bias 1022)
61 (defconstant-eqx double-float-exponent-byte (byte 11 20) #'equalp)
62 (defconstant-eqx double-float-significand-byte (byte 20 0) #'equalp)
63 (defconstant double-float-normal-exponent-min 1)
64 (defconstant double-float-normal-exponent-max #x7FE)
65 (defconstant double-float-hidden-bit (ash 1 20))
66 (defconstant double-float-trapping-nan-bit (ash 1 19))
68 (defconstant long-float-bias 16382)
69 (defconstant-eqx long-float-exponent-byte (byte 15 0) #'equalp)
70 (defconstant-eqx long-float-significand-byte (byte 31 0) #'equalp)
71 (defconstant long-float-normal-exponent-min 1)
72 (defconstant long-float-normal-exponent-max #x7FFE)
73 (defconstant long-float-hidden-bit (ash 1 31)) ; actually not hidden
74 (defconstant long-float-trapping-nan-bit (ash 1 30))
76 (defconstant single-float-digits
77 (+ (byte-size single-float-significand-byte) 1))
79 (defconstant double-float-digits
80 (+ (byte-size double-float-significand-byte) word-bits 1))
82 (defconstant long-float-digits
83 (+ (byte-size long-float-significand-byte) word-bits 1))
85 ;;; pfw -- from i486 microprocessor programmer's reference manual
86 (defconstant float-invalid-trap-bit (ash 1 0))
87 (defconstant float-denormal-trap-bit (ash 1 1))
88 (defconstant float-divide-by-zero-trap-bit (ash 1 2))
89 (defconstant float-overflow-trap-bit (ash 1 3))
90 (defconstant float-underflow-trap-bit (ash 1 4))
91 (defconstant float-inexact-trap-bit (ash 1 5))
93 (defconstant float-round-to-nearest 0)
94 (defconstant float-round-to-negative 1)
95 (defconstant float-round-to-positive 2)
96 (defconstant float-round-to-zero 3)
98 (defconstant-eqx float-rounding-mode (byte 2 10) #'equalp)
99 (defconstant-eqx float-sticky-bits (byte 6 16) #'equalp)
100 (defconstant-eqx float-traps-byte (byte 6 0) #'equalp)
101 (defconstant-eqx float-exceptions-byte (byte 6 16) #'equalp)
102 (defconstant-eqx float-precision-control (byte 2 8) #'equalp)
103 (defconstant float-fast-bit 0) ; no fast mode on x86
105 ;;;; description of the target address space
107 ;;; where to put the different spaces
109 ;;; Note: Mostly these values are black magic, inherited from CMU CL
110 ;;; without any documentation. However, there were a few explanatory
111 ;;; comments in the CMU CL sources:
113 ;;; ** The space 0x08000000-0x10000000 is "C program and memory allocation".
114 ;;; ** The space 0x40000000-0x48000000 is reserved for shared libs.
115 ;;; ** The space >0xE0000000 is "C stack - Alien stack".
117 ;;; ** The space 0x0E000000-0x10000000 is "Foreign segment".
118 ;;; ** The space 0x20000000-0x30000000 is reserved for shared libs.
119 ;;; And there have been some changes since the fork from CMU CL:
120 ;;; * The OpenBSD port is new since the fork. We started with
121 ;;; the FreeBSD address map, which actually worked until the
122 ;;; Alpha port patches, for reasons which in retrospect are rather
123 ;;; mysterious. After the Alpha port patches were added, the
124 ;;; OpenBSD port suffered memory corruption problems. While
125 ;;; debugging those, it was discovered that src/runtime/trymap
126 ;;; failed for the control stack region #x40000000-#x47fff000.
127 ;;; After the control stack was moved upward out of this region
128 ;;; (stealing some bytes from dynamic space) the problems went
130 ;;; * The FreeBSD STATIC-SPACE-START value was bumped up from
131 ;;; #x28000000 to #x30000000 when FreeBSD ld.so dynamic linking
132 ;;; support was added for FreeBSD ca. 20000910. This was to keep from
133 ;;; stomping on an address range that the dynamic libraries want to
134 ;;; use. (They want to use this address range even if we try to
135 ;;; reserve it with a call to validate() as the first operation in
141 (defconstant read-only-space-start #x01000000)
142 (defconstant read-only-space-end #x037ff000)
144 (defconstant static-space-start #x05000000)
145 (defconstant static-space-end #x07fff000)
147 (defconstant dynamic-space-start #x09000000)
148 (defconstant dynamic-space-end #x29000000)
150 (defconstant control-stack-start #x50000000)
151 (defconstant control-stack-end #x57fff000)
153 (defconstant binding-stack-start #x60000000)
154 (defconstant binding-stack-end #x67fff000))
159 (defconstant read-only-space-start #x10000000)
160 (defconstant read-only-space-end #x1ffff000)
162 (defconstant static-space-start
163 #!+freebsd #x30000000
164 #!+openbsd #x28000000)
165 (defconstant static-space-end #x37fff000)
167 (defconstant binding-stack-start #x38000000)
168 (defconstant binding-stack-end #x3ffff000)
170 (defconstant control-stack-start
172 #+openbsd #x48000000)
173 (defconstant control-stack-end
175 #+openbsd #x4ffff000)
176 (defconstant dynamic-space-start
178 #+openbsd #x50000000)
179 (defconstant dynamic-space-end #x88000000))
181 ;;; Given that NIL is the first thing allocated in static space, we
182 ;;; know its value at compile time:
183 (defconstant nil-value (+ static-space-start #xb))
185 ;;;; other miscellaneous constants
187 (defenum (:suffix -trap :start 8)
193 function-end-breakpoint
194 single-step-breakpoint)
195 ;;; FIXME: It'd be nice to replace all the DEFENUMs with something like
196 ;;; (WITH-DEF-ENUM (:START 8)
197 ;;; (DEF-ENUM HALT-TRAP)
198 ;;; (DEF-ENUM PENDING-INTERRUPT-TRAP)
200 ;;; for the benefit of anyone doing a lexical search for definitions
201 ;;; of these symbols.
203 (defenum (:prefix object-not- :suffix -trap :start 16)
207 (defenum (:prefix trace-table-)
215 ;;; These symbols are loaded into static space directly after NIL so
216 ;;; that the system can compute their address by adding a constant
219 ;;; The fdefn objects for the static functions are loaded into static
220 ;;; space directly after the static symbols. That way, the raw-addr
221 ;;; can be loaded directly out of them by indirecting relative to NIL.
223 ;;; pfw X86 doesn't have enough registers to keep these things there.
224 ;;; Note these spaces grow from low to high addresses.
225 (defvar *allocation-pointer*)
226 (defvar *binding-stack-pointer*)
228 ;;; FIXME: *!INITIAL-FDEFN-OBJECTS* and !COLD-INIT probably don't need
229 ;;; to be in the static symbols table any more. Also, if
230 ;;; *INTERNAL-GC-TRIGGER* really is not used, we can punt it.
231 (defparameter *static-symbols*
234 ;; The C startup code must fill these in.
236 sb!impl::*!initial-fdefn-objects*
238 ;; functions that the C code needs to call
240 sb!kernel::internal-error
241 sb!di::handle-breakpoint
246 ;; Note that these are FIXNUM word counts, not (as one might
247 ;; expect) byte counts or SAPs. The reason seems to be that by
248 ;; representing them this way, we can avoid consing bignums.
250 *read-only-space-free-pointer*
251 *static-space-free-pointer*
252 *initial-dynamic-space-free-pointer*
254 ;; things needed for non-local exit
255 *current-catch-block*
256 *current-unwind-protect-block*
260 ;; interrupt handling
261 *pseudo-atomic-atomic*
262 *pseudo-atomic-interrupted*
263 sb!unix::*interrupts-enabled*
264 sb!unix::*interrupt-pending*
265 *free-interrupt-context-index*
267 sb!vm::*allocation-pointer*
268 sb!vm::*binding-stack-pointer*
269 sb!vm::*internal-gc-trigger* ; Not used.
271 ;; the floating point constants
272 sb!vm::*fp-constant-0d0*
273 sb!vm::*fp-constant-1d0*
274 sb!vm::*fp-constant-0s0*
275 sb!vm::*fp-constant-1s0*
276 ;; The following are all long-floats.
277 sb!vm::*fp-constant-0l0*
278 sb!vm::*fp-constant-1l0*
279 sb!vm::*fp-constant-pi*
280 sb!vm::*fp-constant-l2t*
281 sb!vm::*fp-constant-l2e*
282 sb!vm::*fp-constant-lg2*
283 sb!vm::*fp-constant-ln2*
285 ;; The ..SLOT-UNBOUND.. symbol is static in order to optimise the
286 ;; common slot unbound check.
288 ;; FIXME: In SBCL, the CLOS code has become sufficiently tightly
289 ;; integrated into the system that it'd probably make sense to use
290 ;; the ordinary unbound marker for this.
291 sb!pcl::..slot-unbound..))
293 (defparameter *static-functions*
304 sb!kernel:two-arg-and
305 sb!kernel:two-arg-ior
306 sb!kernel:two-arg-xor
307 sb!kernel:two-arg-gcd
308 sb!kernel:two-arg-lcm))
310 ;;;; stuff added by jrd
312 ;;; FIXME: Is this used? Delete it or document it.
313 ;;; cf the sparc PARMS.LISP
314 (defparameter *assembly-unit-length* 8)