1 ;;;; miscellaneous VM definition noise for the Sparc
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 ;;;; Define the registers
16 (eval-when (:compile-toplevel :load-toplevel :execute)
17 (defvar *register-names* (make-array 32 :initial-element nil)))
19 (macrolet ((defreg (name offset)
20 (let ((offset-sym (symbolicate name "-OFFSET")))
21 `(eval-when (:compile-toplevel :load-toplevel :execute)
22 (def!constant ,offset-sym ,offset)
23 (setf (svref *register-names* ,offset-sym)
24 ,(symbol-name name)))))
26 (defregset (name &rest regs)
27 `(eval-when (:compile-toplevel :load-toplevel :execute)
29 (list ,@(mapcar (lambda (name)
30 (symbolicate name "-OFFSET"))
32 ;; c.f. src/runtime/sparc-lispregs.h
34 ;; Globals. These are difficult to extract from a sigcontext.
36 (defreg alloc 1) ; %g1
41 ;; %g6 and %g7 are supposed to be reserved for the system.
43 ;; Outs. These get clobbered when we call into C.
51 (defreg nargs 15) ; %o7
53 ;; Locals. These are preserved when we call into C.
60 (defreg ocfp 22) ; %l6
63 ;; Ins. These are preserved just like locals.
64 (defreg cname 24) ; %i0
65 (defreg lexenv 25) ; %i1
68 (defreg cfunc 28) ; %i4
69 (defreg code 29) ; %i5
70 ;; we can't touch reg 30 if we ever want to return
73 (defregset non-descriptor-regs
74 nl0 nl1 nl2 nl3 nl4 nl5 cfunc nargs nfp)
76 (defregset descriptor-regs
77 a0 a1 a2 a3 a4 a5 ocfp lra cname lexenv l0)
79 (defregset *register-arg-offsets*
82 ;;;; SB and SC definition
84 (define-storage-base registers :finite :size 32)
85 (define-storage-base float-registers :finite :size 64)
86 (define-storage-base control-stack :unbounded :size 8)
87 (define-storage-base non-descriptor-stack :unbounded :size 0)
88 (define-storage-base constant :non-packed)
89 (define-storage-base immediate-constant :non-packed)
91 ;;; handy macro so we don't have to keep changing all the numbers
92 ;;; whenever we insert a new storage class
93 (defmacro !define-storage-classes (&rest classes)
94 (do ((forms (list 'progn)
95 (let* ((class (car classes))
97 (constant-name (intern (concatenate 'simple-string
100 (list* `(define-storage-class ,sc-name ,index
102 `(def!constant ,constant-name ,index)
103 ;; (The CMU CL version of this macro did
104 ;; `(EXPORT ',CONSTANT-NAME)
105 ;; here, but in SBCL we try to have package
106 ;; structure described statically in one
107 ;; master source file, instead of building it
108 ;; dynamically by letting all the system code
109 ;; modify it as the system boots.)
112 (classes classes (cdr classes)))
116 ;;; see comment in ../x86/vm.lisp. The value of 7 was taken from
117 ;;; vm:catch-block-size in a cmucl that I happened to have around
118 ;;; and seems to be working so far -dan
120 ;;; arbitrarily taken for alpha, too. - Christophe
121 (def!constant kludge-nondeterministic-catch-block-size 7)
123 (!define-storage-classes
125 ;; non-immediate constants in the constant pool
128 ;; ZERO and NULL are in registers.
129 (zero immediate-constant)
130 (null immediate-constant)
132 ;; Anything else that can be an immediate.
133 (immediate immediate-constant)
139 ;; The control stack. (Scanned by GC)
140 (control-stack control-stack)
142 ;; The non-descriptor stacks.
143 (signed-stack non-descriptor-stack) ; (signed-byte 32)
144 (unsigned-stack non-descriptor-stack) ; (unsigned-byte 32)
145 (base-char-stack non-descriptor-stack) ; non-descriptor characters.
146 (sap-stack non-descriptor-stack) ; System area pointers.
147 (single-stack non-descriptor-stack) ; single-floats
148 (double-stack non-descriptor-stack
149 :element-size 2 :alignment 2) ; double floats.
151 (long-stack non-descriptor-stack :element-size 4 :alignment 4) ; long floats.
152 ;; complex-single-floats
153 (complex-single-stack non-descriptor-stack :element-size 2)
154 ;; complex-double-floats.
155 (complex-double-stack non-descriptor-stack :element-size 4 :alignment 2)
157 ;; complex-long-floats.
158 (complex-long-stack non-descriptor-stack :element-size 8 :alignment 4)
161 ;; **** Things that can go in the integer registers.
163 ;; Immediate descriptor objects. Don't have to be seen by GC, but nothing
164 ;; bad will happen if they are. (fixnums, characters, header values, etc).
167 :locations #.(append non-descriptor-regs descriptor-regs)
168 :constant-scs (zero immediate)
170 :alternate-scs (control-stack))
172 ;; Pointer descriptor objects. Must be seen by GC.
173 (descriptor-reg registers
174 :locations #.descriptor-regs
175 :constant-scs (constant null immediate)
177 :alternate-scs (control-stack))
179 ;; Non-Descriptor characters
180 (base-char-reg registers
181 :locations #.non-descriptor-regs
182 :constant-scs (immediate)
184 :alternate-scs (base-char-stack))
186 ;; Non-Descriptor SAP's (arbitrary pointers into address space)
188 :locations #.non-descriptor-regs
189 :constant-scs (immediate)
191 :alternate-scs (sap-stack))
193 ;; Non-Descriptor (signed or unsigned) numbers.
194 (signed-reg registers
195 :locations #.non-descriptor-regs
196 :constant-scs (zero immediate)
198 :alternate-scs (signed-stack))
199 (unsigned-reg registers
200 :locations #.non-descriptor-regs
201 :constant-scs (zero immediate)
203 :alternate-scs (unsigned-stack))
205 ;; Random objects that must not be seen by GC. Used only as temporaries.
206 (non-descriptor-reg registers
207 :locations #.non-descriptor-regs)
209 ;; Pointers to the interior of objects. Used only as an temporary.
210 (interior-reg registers
211 :locations (#.lip-offset))
214 ;; **** Things that can go in the floating point registers.
216 ;; Non-Descriptor single-floats.
217 (single-reg float-registers
218 :locations #.(loop for i from 0 to 31 collect i)
219 :reserve-locations (28 29 30 31)
222 :alternate-scs (single-stack))
224 ;; Non-Descriptor double-floats.
225 (double-reg float-registers
226 :locations #.(loop for i from 0 to #!-sparc-64 31 #!+sparc-64 63
228 :element-size 2 :alignment 2
229 :reserve-locations (28 30)
232 :alternate-scs (double-stack))
234 ;; Non-Descriptor double-floats.
236 (long-reg float-registers
237 :locations #.(loop for i from 0 to #!-sparc-64 31 #!+sparc-64 63
239 :element-size 4 :alignment 4
240 :reserve-locations (28)
243 :alternate-scs (long-stack))
245 (complex-single-reg float-registers
246 :locations #.(loop for i from 0 to 31 by 2 collect i)
247 :element-size 2 :alignment 2
248 :reserve-locations (28 30)
251 :alternate-scs (complex-single-stack))
253 (complex-double-reg float-registers
254 :locations #.(loop for i from 0 to #!-sparc-64 31 #!+sparc-64 63
256 :element-size 4 :alignment 4
257 :reserve-locations (28)
260 :alternate-scs (complex-double-stack))
263 (complex-long-reg float-registers
264 :locations #.(loop for i from 0 to #!-sparc-64 31 #!+sparc-64 63
266 :element-size 8 :alignment 8
269 :alternate-scs (complex-long-stack))
272 ;; A catch or unwind block.
273 (catch-block control-stack :element-size kludge-nondeterministic-catch-block-size))
275 ;;;; Make some miscellaneous TNs for important registers.
276 (macrolet ((defregtn (name sc)
277 (let ((offset-sym (symbolicate name "-OFFSET"))
278 (tn-sym (symbolicate name "-TN")))
279 `(defparameter ,tn-sym
280 (make-random-tn :kind :normal
281 :sc (sc-or-lose ',sc)
282 :offset ,offset-sym)))))
283 (defregtn zero any-reg)
284 (defregtn null descriptor-reg)
285 (defregtn code descriptor-reg)
286 (defregtn alloc any-reg)
288 (defregtn nargs any-reg)
289 (defregtn bsp any-reg)
290 (defregtn csp any-reg)
291 (defregtn cfp any-reg)
292 (defregtn ocfp any-reg)
293 (defregtn nsp any-reg))
295 ;;; If VALUE can be represented as an immediate constant, then return the
296 ;;; appropriate SC number, otherwise return NIL.
297 (!def-vm-support-routine immediate-constant-sc (value)
300 (sc-number-or-lose 'zero))
302 (sc-number-or-lose 'null))
303 ((or fixnum system-area-pointer character)
304 (sc-number-or-lose 'immediate))
306 (if (static-symbol-p value)
307 (sc-number-or-lose 'immediate)
310 ;;;; function call parameters
312 ;;; the SC numbers for register and stack arguments/return values.
313 (def!constant register-arg-scn (meta-sc-number-or-lose 'descriptor-reg))
314 (def!constant immediate-arg-scn (meta-sc-number-or-lose 'any-reg))
315 (def!constant control-stack-arg-scn (meta-sc-number-or-lose 'control-stack))
317 (eval-when (:compile-toplevel :load-toplevel :execute)
319 ;; offsets of special stack frame locations
320 (def!constant ocfp-save-offset 0)
321 (def!constant lra-save-offset 1)
322 (def!constant nfp-save-offset 2)
324 ;; the number of arguments/return values passed in registers.
325 (def!constant register-arg-count 6)
327 ;; names to use for the argument registers.
328 (defparameter register-arg-names '(a0 a1 a2 a3 a4 a5))
332 ;;; a list of TN's describing the register arguments
333 (defparameter *register-arg-tns*
335 (make-random-tn :kind :normal
336 :sc (sc-or-lose 'descriptor-reg)
338 *register-arg-offsets*))
340 ;;; This is used by the debugger.
341 (def!constant single-value-return-byte-offset 8)
343 ;;; This function is called by debug output routines that want a
344 ;;; pretty name for a TN's location. It returns a thing that can be
345 ;;; printed with PRINC.
346 (!def-vm-support-routine location-print-name (tn)
347 (declare (type tn tn)) ; FIXME: commented out on alpha
348 (let ((sb (sb-name (sc-sb (tn-sc tn))))
349 (offset (tn-offset tn)))
351 (registers (or (svref *register-names* offset)
352 (format nil "R~D" offset)))
353 (float-registers (format nil "F~D" offset))
354 (control-stack (format nil "CS~D" offset))
355 (non-descriptor-stack (format nil "NS~D" offset))
356 (constant (format nil "Const~D" offset))
357 (immediate-constant "Immed"))))
360 ;;; The loader uses this to convert alien names to the form they
361 ;;; occure in the symbol table (for example, prepending an
362 ;;; underscore). On the SPARC, we don't prepend an underscore.
363 (defun extern-alien-name (name)
364 (declare (type simple-base-string name))
365 (concatenate 'string #+nil "_" name))