1 ;;;; This software is part of the SBCL system. See the README file for
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.
12 (eval-when (:compile-toplevel :load-toplevel :execute)
14 (def!constant n-word-bits 32
16 "Number of bits per word where a word holds one lisp descriptor.")
18 ;;; the natural width of a machine word (as seen in e.g. register width,
20 (def!constant n-machine-word-bits 64)
22 (def!constant n-byte-bits 8
24 "Number of bits per byte where a byte is the smallest addressable object.")
26 (def!constant word-shift (1- (integer-length (/ n-word-bits n-byte-bits)))
28 "Number of bits to shift between word addresses and byte addresses.")
30 (def!constant n-word-bytes (/ n-word-bits n-byte-bits)
32 "Number of bytes in a word.")
34 (def!constant float-sign-shift 31)
36 (def!constant single-float-bias 126)
37 (defconstant-eqx single-float-exponent-byte (byte 8 23) #'equalp)
38 (defconstant-eqx single-float-significand-byte (byte 23 0) #'equalp)
39 (def!constant single-float-normal-exponent-min 1)
40 (def!constant single-float-normal-exponent-max 254)
41 (def!constant single-float-hidden-bit (ash 1 23))
42 (def!constant single-float-trapping-nan-bit (ash 1 22))
44 (def!constant double-float-bias 1022)
45 (defconstant-eqx double-float-exponent-byte (byte 11 20) #'equalp)
46 (defconstant-eqx double-float-significand-byte (byte 20 0) #'equalp)
47 (def!constant double-float-normal-exponent-min 1)
48 (def!constant double-float-normal-exponent-max #x7FE)
49 (def!constant double-float-hidden-bit (ash 1 20))
50 (def!constant double-float-trapping-nan-bit (ash 1 19))
52 (def!constant single-float-digits
53 (+ (byte-size single-float-significand-byte) 1))
55 (def!constant double-float-digits
56 (+ (byte-size double-float-significand-byte) n-word-bits 1))
58 ;;; These values are originally from the DEC Assembly Language
59 ;;; Programmers guide. Where possible we read/write the software
60 ;;; fp_control word, which apparently is necessary for the OS FPU
61 ;;; completion (OS handler which fixes up non-IEEE answers that the
62 ;;; hardware occasionally gives us) to work properly. The rounding
63 ;;; mode, however, can't be set that way, so we have to deal with that
64 ;;; directly. (FIXME: we actually don't suport setting the rounding mode
65 ;;; at the moment anyway)
67 ;;; Short guide to floating point trap terminology: an "exception" is
68 ;;; cheap and can happen at almost any time. An exception will only
69 ;;; generate a trap if that trap is enabled, otherwise a default value
70 ;;; will be substituted. A "trap" will end up somewhere in the
71 ;;; kernel, which may play by its own rules, (on Alpha it allegedly
72 ;;; actually fixes up some non-IEEE compliant results to get the
73 ;;; _right_ answer) but if something is really wrong will eventually
74 ;;; signal SIGFPE and let us sort it out.
76 ;;; Old comment follows: The active bits are actually in (byte 12 52)
77 ;;; of the fpcr. (byte 6 52) contain the exception flags. Bit 63 is the
78 ;;; bitwise logor of all exceptions. The enable and exception bytes
79 ;;; are in a software control word manipulated via OS functions and the
80 ;;; bits in the SCP match those defs. This mapping follows
83 ;;; trap enables are set in software (fp_control)
84 (def!constant float-inexact-trap-bit (ash 1 4)) ; rw
85 (def!constant float-underflow-trap-bit (ash 1 3)) ; rw
86 (def!constant float-overflow-trap-bit (ash 1 2)) ; ro
87 (def!constant float-divide-by-zero-trap-bit (ash 1 1)) ; ro
88 (def!constant float-invalid-trap-bit (ash 1 0)) ; ro
89 (defconstant-eqx float-traps-byte (byte 6 1) #'equalp)
91 ;;; exceptions are also read/written in software (by syscalls, no less).
92 ;;; This is kind of dumb, but has to be done
93 (defconstant-eqx float-sticky-bits (byte 6 17) #'equalp) ; fp_control
95 ;;; (We don't actually _have_ "current exceptions" on Alpha; the
96 ;;; hardware only ever sets bits. So, set this the same as accrued
98 (defconstant-eqx float-exceptions-byte (byte 6 17) #'equalp)
100 ;;; Rounding modes can only be set by frobbing the hardware fpcr directly
101 (def!constant float-round-to-zero 0)
102 (def!constant float-round-to-negative 1)
103 (def!constant float-round-to-nearest 2)
104 (def!constant float-round-to-positive 3)
105 (defconstant-eqx float-rounding-mode (byte 2 58) #'equalp)
107 ;;; Miscellaneous stuff - I think it's far to say that you deserve
108 ;;; what you get if you ask for fast mode.
109 (def!constant float-fast-bit 0)
115 ;;;; Description of the target address space.
117 ;;; Where to put the different spaces.
122 (def!constant read-only-space-start #x20000000)
123 (def!constant read-only-space-end #x24000000))
127 (defconstant read-only-space-start #x10000000)
128 (defconstant read-only-space-end #x25000000))
131 (def!constant static-space-start #x28000000)
132 (def!constant static-space-end #x2c000000)
134 ;; this is used in PURIFY as part of a sloppy check to see if a pointer
135 ;; is in dynamic space. Chocolate brownie for the first person to fix it
137 (def!constant dynamic-space-start #x30000000)
138 (def!constant dynamic-space-end #x3fff0000)
140 (def!constant dynamic-0-space-start #x30000000)
141 (def!constant dynamic-0-space-end #x3fff0000)
143 (def!constant dynamic-1-space-start #x40000000)
144 (def!constant dynamic-1-space-end #x4fff0000)
146 ;;; FIXME nothing refers to either of these in alpha or x86 cmucl
147 ;;; backend, so they could probably be removed.
149 ;; The space-register holding the lisp heap.
150 (def!constant lisp-heap-space 4)
152 ;; The space-register holding the C text segment.
153 (def!constant c-text-space 4)
155 ;;; the X86 port defines *nil-value* as (+ *target-static-space-start* #xB)
156 ;;; here, but it seems to be the only port that needs to know the
157 ;;; location of NIL from lisp.
159 ;;;; other miscellaneous constants
161 (defenum (:suffix -trap :start 8)
168 single-step-breakpoint)
170 (defenum (:prefix trace-table-)
178 ;;; These symbols are loaded into static space directly after NIL so
179 ;;; that the system can compute their address by adding a constant
182 ;;; The fdefn objects for the static functions are loaded into static
183 ;;; space directly after the static symbols. That way, the raw-addr
184 ;;; can be loaded directly out of them by indirecting relative to NIL.
186 (defparameter *static-symbols*
189 ;; The C startup code must fill these in.
192 ;; functions that the C code needs to call
194 sb!kernel::internal-error
195 sb!kernel::control-stack-exhausted-error
196 sb!di::handle-breakpoint
197 sb!di::handle-fun-end-breakpoint
200 *read-only-space-free-pointer*
201 *static-space-free-pointer*
202 *initial-dynamic-space-free-pointer*
204 ;; things needed for non-local exit
205 *current-catch-block*
206 *current-unwind-protect-block*
208 *binding-stack-start*
209 *control-stack-start*
212 ;; interrupt handling
213 *free-interrupt-context-index*
214 sb!unix::*interrupts-enabled*
215 sb!unix::*interrupt-pending*))
217 (defparameter *static-funs*
227 ;; probably need the following as they are defined in
228 ;; arith.lisp: two-arg-<= two-arg->= two-arg-/=
229 ;; a comment from old CMU CL or old old CMU CL or
230 ;; the SBCL alpha port or what? Do we need to worry about it,
231 ;; or can we delete it?
234 sb!kernel:two-arg-and
235 sb!kernel:two-arg-ior
236 sb!kernel:two-arg-xor
237 sb!kernel:two-arg-eqv
238 sb!kernel:two-arg-gcd
239 sb!kernel:two-arg-lcm))