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 ;;;; Additional constants
16 ;;; NUMBER-STACK-DISPLACEMENT
18 ;;; The number of bytes reserved above the number stack pointer. These
19 ;;; slots are required by architecture for a place to spill register windows.
21 ;;; FIXME: Where is this used?
22 (def!constant number-stack-displacement
25 ;;;; Define the registers
27 (eval-when (:compile-toplevel :load-toplevel :execute)
28 (defvar *register-names* (make-array 32 :initial-element nil)))
30 (macrolet ((defreg (name offset)
31 (let ((offset-sym (symbolicate name "-OFFSET")))
32 `(eval-when (:compile-toplevel :load-toplevel :execute)
33 (def!constant ,offset-sym ,offset)
34 (setf (svref *register-names* ,offset-sym)
35 ,(symbol-name name)))))
37 (defregset (name &rest regs)
38 `(eval-when (:compile-toplevel :load-toplevel :execute)
40 (list ,@(mapcar (lambda (name)
41 (symbolicate name "-OFFSET"))
43 ;; c.f. src/runtime/sparc-lispregs.h
45 ;; Globals. These are difficult to extract from a sigcontext.
47 (defreg alloc 1) ; %g1
52 ;; %g6 and %g7 are supposed to be reserved for the system.
54 ;; Outs. These get clobbered when we call into C.
62 (defreg nargs 15) ; %o7
64 ;; Locals. These are preserved when we call into C.
71 (defreg ocfp 22) ; %l6
74 ;; Ins. These are preserved just like locals.
75 (defreg cname 24) ; %i0
76 (defreg lexenv 25) ; %i1
79 (defreg cfunc 28) ; %i4
80 (defreg code 29) ; %i5
81 ;; we can't touch reg 30 if we ever want to return
84 (defregset non-descriptor-regs
85 nl0 nl1 nl2 nl3 nl4 nl5 cfunc nargs nfp)
87 (defregset descriptor-regs
88 a0 a1 a2 a3 a4 a5 ocfp lra cname lexenv l0)
90 (defregset *register-arg-offsets*
93 ;;;; SB and SC definition
95 (define-storage-base registers :finite :size 32)
96 (define-storage-base float-registers :finite :size 64)
97 (define-storage-base control-stack :unbounded :size 8)
98 (define-storage-base non-descriptor-stack :unbounded :size 0)
99 (define-storage-base constant :non-packed)
100 (define-storage-base immediate-constant :non-packed)
102 ;;; handy macro so we don't have to keep changing all the numbers
103 ;;; whenever we insert a new storage class
104 (defmacro !define-storage-classes (&rest classes)
105 (do ((forms (list 'progn)
106 (let* ((class (car classes))
107 (sc-name (car class))
108 (constant-name (intern (concatenate 'simple-string
111 (list* `(define-storage-class ,sc-name ,index
113 `(def!constant ,constant-name ,index)
114 ;; (The CMU CL version of this macro did
115 ;; `(EXPORT ',CONSTANT-NAME)
116 ;; here, but in SBCL we try to have package
117 ;; structure described statically in one
118 ;; master source file, instead of building it
119 ;; dynamically by letting all the system code
120 ;; modify it as the system boots.)
123 (classes classes (cdr classes)))
127 ;;; see comment in ../x86/vm.lisp. The value of 7 was taken from
128 ;;; vm:catch-block-size in a cmucl that I happened to have around
129 ;;; and seems to be working so far -dan
131 ;;; arbitrarily taken for alpha, too. - Christophe
132 (def!constant kludge-nondeterministic-catch-block-size 7)
134 (!define-storage-classes
136 ;; non-immediate constants in the constant pool
139 ;; ZERO and NULL are in registers.
140 (zero immediate-constant)
141 (null immediate-constant)
143 ;; Anything else that can be an immediate.
144 (immediate immediate-constant)
150 ;; The control stack. (Scanned by GC)
151 (control-stack control-stack)
153 ;; We put ANY-REG and DESCRIPTOR-REG early so that their SC-NUMBER
154 ;; is small and therefore the error trap information is smaller.
155 ;; Moving them up here from their previous place down below saves
156 ;; ~250K in core file size. --njf, 2006-01-27
158 ;; Immediate descriptor objects. Don't have to be seen by GC, but nothing
159 ;; bad will happen if they are. (fixnums, characters, header values, etc).
162 :locations #.(append non-descriptor-regs descriptor-regs)
163 :constant-scs (zero immediate)
165 :alternate-scs (control-stack))
167 ;; Pointer descriptor objects. Must be seen by GC.
168 (descriptor-reg registers
169 :locations #.descriptor-regs
170 :constant-scs (constant null immediate)
172 :alternate-scs (control-stack))
174 ;; The non-descriptor stacks.
175 (signed-stack non-descriptor-stack) ; (signed-byte 32)
176 (unsigned-stack non-descriptor-stack) ; (unsigned-byte 32)
177 (character-stack non-descriptor-stack) ; non-descriptor characters.
178 (sap-stack non-descriptor-stack) ; System area pointers.
179 (single-stack non-descriptor-stack) ; single-floats
180 (double-stack non-descriptor-stack
181 :element-size 2 :alignment 2) ; double floats.
183 (long-stack non-descriptor-stack :element-size 4 :alignment 4) ; long floats.
184 ;; complex-single-floats
185 (complex-single-stack non-descriptor-stack :element-size 2)
186 ;; complex-double-floats.
187 (complex-double-stack non-descriptor-stack :element-size 4 :alignment 2)
189 ;; complex-long-floats.
190 (complex-long-stack non-descriptor-stack :element-size 8 :alignment 4)
193 ;; **** Things that can go in the integer registers.
195 ;; Non-Descriptor characters
196 (character-reg registers
197 :locations #.non-descriptor-regs
198 :constant-scs (immediate)
200 :alternate-scs (character-stack))
202 ;; Non-Descriptor SAP's (arbitrary pointers into address space)
204 :locations #.non-descriptor-regs
205 :constant-scs (immediate)
207 :alternate-scs (sap-stack))
209 ;; Non-Descriptor (signed or unsigned) numbers.
210 (signed-reg registers
211 :locations #.non-descriptor-regs
212 :constant-scs (zero immediate)
214 :alternate-scs (signed-stack))
215 (unsigned-reg registers
216 :locations #.non-descriptor-regs
217 :constant-scs (zero immediate)
219 :alternate-scs (unsigned-stack))
221 ;; Random objects that must not be seen by GC. Used only as temporaries.
222 (non-descriptor-reg registers
223 :locations #.non-descriptor-regs)
225 ;; Pointers to the interior of objects. Used only as an temporary.
226 (interior-reg registers
227 :locations (#.lip-offset))
230 ;; **** Things that can go in the floating point registers.
232 ;; Non-Descriptor single-floats.
233 (single-reg float-registers
234 :locations #.(loop for i from 0 to 31 collect i)
235 :reserve-locations (28 29 30 31)
238 :alternate-scs (single-stack))
240 ;; Non-Descriptor double-floats.
241 (double-reg float-registers
242 :locations #.(loop for i from 0 to #!-sparc-64 31 #!+sparc-64 63
244 :element-size 2 :alignment 2
245 :reserve-locations (28 30)
248 :alternate-scs (double-stack))
250 ;; Non-Descriptor double-floats.
252 (long-reg float-registers
253 :locations #.(loop for i from 0 to #!-sparc-64 31 #!+sparc-64 63
255 :element-size 4 :alignment 4
256 :reserve-locations (28)
259 :alternate-scs (long-stack))
261 (complex-single-reg float-registers
262 :locations #.(loop for i from 0 to 31 by 2 collect i)
263 :element-size 2 :alignment 2
264 :reserve-locations (28 30)
267 :alternate-scs (complex-single-stack))
269 (complex-double-reg float-registers
270 :locations #.(loop for i from 0 to #!-sparc-64 31 #!+sparc-64 63
272 :element-size 4 :alignment 4
273 :reserve-locations (28)
276 :alternate-scs (complex-double-stack))
279 (complex-long-reg float-registers
280 :locations #.(loop for i from 0 to #!-sparc-64 31 #!+sparc-64 63
282 :element-size 8 :alignment 8
285 :alternate-scs (complex-long-stack))
288 ;; A catch or unwind block.
289 (catch-block control-stack :element-size kludge-nondeterministic-catch-block-size))
291 ;;;; Make some miscellaneous TNs for important registers.
292 (macrolet ((defregtn (name sc)
293 (let ((offset-sym (symbolicate name "-OFFSET"))
294 (tn-sym (symbolicate name "-TN")))
295 `(defparameter ,tn-sym
296 (make-random-tn :kind :normal
297 :sc (sc-or-lose ',sc)
298 :offset ,offset-sym)))))
299 (defregtn zero any-reg)
300 (defregtn null descriptor-reg)
301 (defregtn code descriptor-reg)
302 (defregtn alloc any-reg)
304 (defregtn nargs any-reg)
305 (defregtn bsp any-reg)
306 (defregtn csp any-reg)
307 (defregtn cfp any-reg)
308 (defregtn ocfp any-reg)
309 (defregtn nsp any-reg))
311 ;;; If VALUE can be represented as an immediate constant, then return the
312 ;;; appropriate SC number, otherwise return NIL.
313 (!def-vm-support-routine immediate-constant-sc (value)
316 (sc-number-or-lose 'zero))
318 (sc-number-or-lose 'null))
319 ((or (integer #.sb!xc:most-negative-fixnum #.sb!xc:most-positive-fixnum)
320 system-area-pointer character)
321 (sc-number-or-lose 'immediate))
323 (if (static-symbol-p value)
324 (sc-number-or-lose 'immediate)
327 ;;;; function call parameters
329 ;;; the SC numbers for register and stack arguments/return values.
330 (def!constant register-arg-scn (meta-sc-number-or-lose 'descriptor-reg))
331 (def!constant immediate-arg-scn (meta-sc-number-or-lose 'any-reg))
332 (def!constant control-stack-arg-scn (meta-sc-number-or-lose 'control-stack))
334 (eval-when (:compile-toplevel :load-toplevel :execute)
336 ;; offsets of special stack frame locations
337 (def!constant ocfp-save-offset 0)
338 (def!constant lra-save-offset 1)
339 (def!constant nfp-save-offset 2)
341 ;; the number of arguments/return values passed in registers.
342 (def!constant register-arg-count 6)
344 ;; names to use for the argument registers.
345 (defparameter register-arg-names '(a0 a1 a2 a3 a4 a5))
349 ;;; a list of TN's describing the register arguments
350 (defparameter *register-arg-tns*
352 (make-random-tn :kind :normal
353 :sc (sc-or-lose 'descriptor-reg)
355 *register-arg-offsets*))
357 ;;; This is used by the debugger.
358 (def!constant single-value-return-byte-offset 8)
360 ;;; This function is called by debug output routines that want a
361 ;;; pretty name for a TN's location. It returns a thing that can be
362 ;;; printed with PRINC.
363 (!def-vm-support-routine location-print-name (tn)
364 (declare (type tn tn)) ; FIXME: commented out on alpha
365 (let ((sb (sb-name (sc-sb (tn-sc tn))))
366 (offset (tn-offset tn)))
368 (registers (or (svref *register-names* offset)
369 (format nil "R~D" offset)))
370 (float-registers (format nil "F~D" offset))
371 (control-stack (format nil "CS~D" offset))
372 (non-descriptor-stack (format nil "NS~D" offset))
373 (constant (format nil "Const~D" offset))
374 (immediate-constant "Immed"))))
376 (!def-vm-support-routine combination-implementation-style (node)
377 (declare (type sb!c::combination node) (ignore node))
378 (values :default nil))