1 ;;;; miscellaneous VM definition noise for MIPS
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.
17 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
18 (defvar *register-names
* (make-array 32 :initial-element nil
)))
20 (macrolet ((defreg (name offset
)
21 (let ((offset-sym (symbolicate name
"-OFFSET")))
22 `(eval-when (:compile-toplevel
:load-toplevel
:execute
)
23 (def!constant
,offset-sym
,offset
)
24 (setf (svref *register-names
* ,offset-sym
) ,(symbol-name name
)))))
26 (defregset (name &rest regs
)
27 `(eval-when (:compile-toplevel
:load-toplevel
:execute
)
29 (list ,@(mapcar #'(lambda (name) (symbolicate name
"-OFFSET")) regs
))))))
30 ;; Wired zero register.
31 (defreg zero
0) ; NULL
32 ;; Reserved for assembler use.
33 (defreg nl3
1) ; untagged temporary 3
34 ;; C return registers.
35 (defreg cfunc
2) ; FF function address, wastes a register
36 (defreg nl4
3) ; PA flag
37 ;; C argument registers.
38 (defreg nl0
4) ; untagged temporary 0
39 (defreg nl1
5) ; untagged temporary 1
40 (defreg nl2
6) ; untagged temporary 2
41 (defreg nargs
7) ; number of function arguments
42 ;; C unsaved temporaries.
43 (defreg a0
8) ; function arg 0
44 (defreg a1
9) ; function arg 1
45 (defreg a2
10) ; function arg 2
46 (defreg a3
11) ; function arg 3
47 (defreg a4
12) ; function arg 4
48 (defreg a5
13) ; function arg 5
50 (defreg lexenv
15) ; wastes a register
52 (defreg nfp
16) ; non-lisp frame pointer
53 (defreg ocfp
17) ; caller's control frame pointer
54 (defreg lra
18) ; tagged Lisp return address
55 (defreg l0
19) ; tagged temporary 0
56 (defreg null
20) ; NIL
57 (defreg bsp
21) ; binding stack pointer
58 (defreg cfp
22) ; control frame pointer
59 (defreg csp
23) ; control stack pointer
60 ;; More C unsaved temporaries.
61 (defreg l1
24) ; tagged temporary 1
62 (defreg alloc
25) ; ALLOC pointer
63 ;; 26 and 27 are used by the system kernel.
64 ;; 28 is the global pointer of our C runtime, and used for
65 ;; jump/branch relaxation in Lisp.
66 (defreg nsp
29) ; number (native) stack pointer
67 ;; C frame pointer, or additional saved register.
68 (defreg code
30) ; current function object
69 ;; Return link register.
70 (defreg lip
31) ; Lisp interior pointer
72 (defregset non-descriptor-regs
73 nl0 nl1 nl2 nl3 nl4 cfunc nargs nfp
)
75 (defregset descriptor-regs
76 a0 a1 a2 a3 a4 a5 fdefn lexenv ocfp lra l0 l1
)
78 (defregset *register-arg-offsets
*
81 (defregset reserve-descriptor-regs
84 (defregset reserve-non-descriptor-regs
88 ;;;; SB and SC definition:
90 (define-storage-base registers
:finite
:size
32)
91 (define-storage-base float-registers
:finite
:size
32)
92 (define-storage-base control-stack
:unbounded
:size
8)
93 (define-storage-base non-descriptor-stack
:unbounded
:size
0)
94 (define-storage-base constant
:non-packed
)
95 (define-storage-base immediate-constant
:non-packed
)
98 ;;; Handy macro so we don't have to keep changing all the numbers whenever
99 ;;; we insert a new storage class.
101 (defmacro !define-storage-classes
(&rest classes
)
102 (do ((forms (list 'progn
)
103 (let* ((class (car classes
))
104 (sc-name (car class
))
105 (constant-name (intern (concatenate 'simple-string
108 (list* `(define-storage-class ,sc-name
,index
110 `(def!constant
,constant-name
,index
)
113 (classes classes
(cdr classes
)))
117 (def!constant kludge-nondeterministic-catch-block-size
6)
119 (!define-storage-classes
121 ;; Non-immediate constants in the constant pool
124 ;; Immediate constant.
125 (null immediate-constant
)
126 (zero immediate-constant
)
127 (immediate immediate-constant
)
131 ;; The control stack. (Scanned by GC)
132 (control-stack control-stack
)
134 ;; We put ANY-REG and DESCRIPTOR-REG early so that their SC-NUMBER
135 ;; is small and therefore the error trap information is smaller.
136 ;; Moving them up here from their previous place down below saves
137 ;; ~250K in core file size. --njf, 2006-01-27
139 ;; Immediate descriptor objects. Don't have to be seen by GC, but nothing
140 ;; bad will happen if they are. (fixnums, characters, header values, etc).
143 :locations
#.
(append non-descriptor-regs descriptor-regs
)
144 :reserve-locations
#.
(append reserve-non-descriptor-regs
145 reserve-descriptor-regs
)
146 :constant-scs
(constant zero immediate
)
148 :alternate-scs
(control-stack))
150 ;; Pointer descriptor objects. Must be seen by GC.
151 (descriptor-reg registers
152 :locations
#.descriptor-regs
153 :reserve-locations
#.reserve-descriptor-regs
154 :constant-scs
(constant null immediate
)
156 :alternate-scs
(control-stack))
158 ;; The non-descriptor stacks.
159 (signed-stack non-descriptor-stack
) ; (signed-byte 32)
160 (unsigned-stack non-descriptor-stack
) ; (unsigned-byte 32)
161 (character-stack non-descriptor-stack
) ; non-descriptor characters.
162 (sap-stack non-descriptor-stack
) ; System area pointers.
163 (single-stack non-descriptor-stack
) ; single-floats
164 (double-stack non-descriptor-stack
165 :element-size
2 :alignment
2) ; double floats.
166 ;; complex-single-floats
167 (complex-single-stack non-descriptor-stack
:element-size
2)
168 ;; complex-double-floats.
169 (complex-double-stack non-descriptor-stack
:element-size
4 :alignment
2)
172 ;; **** Things that can go in the integer registers.
174 ;; Non-Descriptor characters
175 (character-reg registers
176 :locations
#.non-descriptor-regs
177 :reserve-locations
#.reserve-non-descriptor-regs
178 :constant-scs
(immediate)
180 :alternate-scs
(character-stack))
182 ;; Non-Descriptor SAP's (arbitrary pointers into address space)
184 :locations
#.non-descriptor-regs
185 :reserve-locations
#.reserve-non-descriptor-regs
186 :constant-scs
(immediate)
188 :alternate-scs
(sap-stack))
190 ;; Non-Descriptor (signed or unsigned) numbers.
191 (signed-reg registers
192 :locations
#.non-descriptor-regs
193 :reserve-locations
#.reserve-non-descriptor-regs
194 :constant-scs
(zero immediate
)
196 :alternate-scs
(signed-stack))
197 (unsigned-reg registers
198 :locations
#.non-descriptor-regs
199 :reserve-locations
#.reserve-non-descriptor-regs
200 :constant-scs
(zero immediate
)
202 :alternate-scs
(unsigned-stack))
204 ;; Random objects that must not be seen by GC. Used only as temporaries.
205 (non-descriptor-reg registers
206 :locations
#.non-descriptor-regs
)
208 ;; Pointers to the interior of objects. Used only as an temporary.
209 (interior-reg registers
210 :locations
(#.lip-offset
))
213 ;; **** Things that can go in the floating point registers.
215 ;; Non-Descriptor single-floats.
216 (single-reg float-registers
217 :locations
(0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30)
218 :reserve-locations
(26 28 30)
221 :alternate-scs
(single-stack))
223 ;; Non-Descriptor double-floats.
224 (double-reg float-registers
225 :locations
(0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30)
226 :reserve-locations
(26 28 30)
227 ;; Note: we don't bother with the element size, 'cause nothing can be
228 ;; allocated in the odd fp regs anyway.
231 :alternate-scs
(double-stack))
233 (complex-single-reg float-registers
234 :locations
(0 4 8 12 16 20 24 28)
236 :reserve-locations
(24 28)
239 :alternate-scs
(complex-single-stack))
241 (complex-double-reg float-registers
242 :locations
(0 4 8 12 16 20 24 28)
244 :reserve-locations
(24 28)
247 :alternate-scs
(complex-double-stack))
249 ;; A catch or unwind block.
250 (catch-block control-stack
:element-size kludge-nondeterministic-catch-block-size
)
252 ;; floating point numbers temporarily stuck in integer registers for c-call
253 (single-int-carg-reg registers
257 (double-int-carg-reg registers
261 :alignment
2 ;is this needed?
267 ;;;; Random TNs for interesting registers
269 (macrolet ((defregtn (name sc
)
270 (let ((offset-sym (symbolicate name
"-OFFSET"))
271 (tn-sym (symbolicate name
"-TN")))
272 `(defparameter ,tn-sym
273 (make-random-tn :kind
:normal
274 :sc
(sc-or-lose ',sc
)
275 :offset
,offset-sym
)))))
276 (defregtn zero any-reg
)
277 (defregtn nargs any-reg
)
279 (defregtn fdefn descriptor-reg
)
280 (defregtn lexenv descriptor-reg
)
282 (defregtn nfp any-reg
)
283 (defregtn ocfp any-reg
)
285 (defregtn null descriptor-reg
)
287 (defregtn bsp any-reg
)
288 (defregtn cfp any-reg
)
289 (defregtn csp any-reg
)
290 (defregtn alloc any-reg
)
291 (defregtn nsp any-reg
)
293 (defregtn code descriptor-reg
)
294 (defregtn lip interior-reg
))
296 ;;; If VALUE can be represented as an immediate constant, then return the
297 ;;; appropriate SC number, otherwise return NIL.
298 (!def-vm-support-routine immediate-constant-sc
(value)
301 (sc-number-or-lose 'zero
))
303 (sc-number-or-lose 'null
))
305 (if (static-symbol-p value
)
306 (sc-number-or-lose 'immediate
)
308 ((or (integer #.sb
!xc
:most-negative-fixnum
#.sb
!xc
:most-positive-fixnum
)
310 (sc-number-or-lose 'immediate
))
312 (sc-number-or-lose 'immediate
))
314 (sc-number-or-lose 'immediate
))))
317 ;;;; Function Call Parameters
319 ;;; The SC numbers for register and stack arguments/return values.
321 (def!constant register-arg-scn
(meta-sc-number-or-lose 'descriptor-reg
))
322 (def!constant immediate-arg-scn
(meta-sc-number-or-lose 'any-reg
))
323 (def!constant control-stack-arg-scn
(meta-sc-number-or-lose 'control-stack
))
325 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
327 ;;; Offsets of special stack frame locations
328 (def!constant ocfp-save-offset
0)
329 (def!constant lra-save-offset
1)
330 (def!constant nfp-save-offset
2)
332 ;;; The number of arguments/return values passed in registers.
334 (def!constant register-arg-count
6)
336 ;;; The offsets within the register-arg SC that we pass values in, first
340 ;;; Names to use for the argument registers.
342 (defconstant-eqx register-arg-names
'(a0 a1 a2 a3 a4 a5
) #'equal
)
347 ;;; A list of TN's describing the register arguments.
349 (defparameter *register-arg-tns
*
350 (mapcar #'(lambda (n)
351 (make-random-tn :kind
:normal
352 :sc
(sc-or-lose 'descriptor-reg
)
354 *register-arg-offsets
*))
356 ;;; This is used by the debugger.
357 (def!constant single-value-return-byte-offset
8)
359 ;;; This function is called by debug output routines that want a pretty name
360 ;;; for a TN's location. It returns a thing that can be printed with PRINC.
361 (!def-vm-support-routine location-print-name
(tn)
362 (declare (type tn tn
))
363 (let ((sb (sb-name (sc-sb (tn-sc tn
))))
364 (offset (tn-offset tn
)))
366 (registers (or (svref *register-names
* offset
)
367 (format nil
"R~D" offset
)))
368 (float-registers (format nil
"F~D" offset
))
369 (control-stack (format nil
"CS~D" offset
))
370 (non-descriptor-stack (format nil
"NS~D" offset
))
371 (constant (format nil
"Const~D" offset
))
372 (immediate-constant "Immed"))))
374 (!def-vm-support-routine combination-implementation-style
(node)
375 (declare (type sb
!c
::combination node
) (ignore node
))
376 (values :default nil
))