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 (defconstant ,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 `(defconstant ,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 (defconstant sb!vm::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 sb!vm::kludge-nondeterministic-catch-block-size))
277 ;;;; Make some random tns for important registers.
279 (macrolet ((defregtn (name sc)
280 (let ((offset-sym (symbolicate name "-OFFSET"))
281 (tn-sym (symbolicate name "-TN")))
282 `(defparameter ,tn-sym
283 (make-random-tn :kind :normal
284 :sc (sc-or-lose ',sc)
285 :offset ,offset-sym)))))
286 (defregtn zero any-reg)
287 (defregtn null descriptor-reg)
288 (defregtn code descriptor-reg)
289 (defregtn alloc any-reg)
291 (defregtn nargs any-reg)
292 (defregtn bsp any-reg)
293 (defregtn csp any-reg)
294 (defregtn cfp any-reg)
295 (defregtn ocfp any-reg)
296 (defregtn nsp any-reg))
300 ;;; If value can be represented as an immediate constant, then return the
301 ;;; appropriate SC number, otherwise return NIL.
302 (!def-vm-support-routine immediate-constant-sc (value)
305 (sc-number-or-lose 'zero))
307 (sc-number-or-lose 'null))
308 ((or fixnum system-area-pointer character)
309 (sc-number-or-lose 'immediate))
311 (if (static-symbol-p value)
312 (sc-number-or-lose 'immediate)
316 ;;;; function call parameters
318 ;;; the SC numbers for register and stack arguments/return values.
319 (defconstant register-arg-scn (meta-sc-number-or-lose 'descriptor-reg))
320 (defconstant immediate-arg-scn (meta-sc-number-or-lose 'any-reg))
321 (defconstant control-stack-arg-scn (meta-sc-number-or-lose 'control-stack))
323 (eval-when (:compile-toplevel :load-toplevel :execute)
325 ;; offsets of special stack frame locations
326 (defconstant ocfp-save-offset 0)
327 (defconstant lra-save-offset 1)
328 (defconstant nfp-save-offset 2)
330 ;; the number of arguments/return values passed in registers.
332 (defconstant register-arg-count 6)
334 ;; names to use for the argument registers.
336 (defparameter register-arg-names '(a0 a1 a2 a3 a4 a5))
337 ); eval-when (:compile-toplevel :load-toplevel :execute)
340 ;;; a list of TN's describing the register arguments.
341 (defparameter *register-arg-tns*
343 (make-random-tn :kind :normal
344 :sc (sc-or-lose 'descriptor-reg)
346 *register-arg-offsets*))
348 ;;; This is used by the debugger.
349 (defconstant single-value-return-byte-offset 8)
352 ;;; This function is called by debug output routines that want a
353 ;;; pretty name for a TN's location. It returns a thing that can be
354 ;;; printed with PRINC.
355 (!def-vm-support-routine location-print-name (tn)
356 (declare (type tn tn)) ; FIXME: commented out on alpha
357 (let ((sb (sb-name (sc-sb (tn-sc tn))))
358 (offset (tn-offset tn)))
360 (registers (or (svref *register-names* offset)
361 (format nil "R~D" offset)))
362 (float-registers (format nil "F~D" offset))
363 (control-stack (format nil "CS~D" offset))
364 (non-descriptor-stack (format nil "NS~D" offset))
365 (constant (format nil "Const~D" offset))
366 (immediate-constant "Immed"))))
369 ;;; The loader uses this to convert alien names to the form they
370 ;;; occure in the symbol table (for example, prepending an
371 ;;; underscore). On the SPARC, we don't prepend an underscore.
372 (defun extern-alien-name (name)
373 (declare (type simple-base-string name))
374 (concatenate 'string #+nil "_" name))