1 ;;;; miscellaneous VM definition noise for the PPC
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 ;;; NUMBER-STACK-DISPLACEMENT
16 ;;; The number of bytes reserved above the number stack pointer. These
17 ;;; slots are required by architecture, mostly (?) to make C backtrace
18 ;;; work. This must be a power of 2 - see BYTES-REQUIRED-FOR-NUMBER-STACK.
20 (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
) ,(symbol-name name
)))))
36 (defregset (name &rest regs
)
37 `(eval-when (:compile-toplevel
:load-toplevel
:execute
)
39 (list ,@(mapcar #'(lambda (name)
40 (symbolicate name
"-OFFSET")) regs
))))))
44 (defreg rtoc
2) ; May be "NULL" someday.
54 ;; FIXME: some kind of comment here would be nice.
56 ;; FIXME II: this also reveals the need to autogenerate lispregs.h
57 #!+darwin
(defreg cfunc
12)
58 #!-darwin
(defreg nfp
12)
59 #!+darwin
(defreg nfp
13)
60 #!-darwin
(defreg cfunc
13)
77 (defreg #!-sb-thread l2
#!+sb-thread thread
30)
80 (defregset non-descriptor-regs
81 nl0 nl1 nl2 nl3 nl4 nl5 nl6 cfunc nargs nfp
)
83 (defregset descriptor-regs
84 fdefn a0 a1 a2 a3 ocfp lra cname lexenv l0 l1
#!-sb-thread l2
)
87 (defregset *register-arg-offsets
* a0 a1 a2 a3
)
88 (defparameter register-arg-names
'(a0 a1 a2 a3
)))
92 ;;;; SB and SC definition:
94 (define-storage-base registers
:finite
:size
32)
95 (define-storage-base float-registers
:finite
:size
32)
96 (define-storage-base control-stack
:unbounded
:size
8)
97 (define-storage-base non-descriptor-stack
:unbounded
:size
0)
98 (define-storage-base constant
:non-packed
)
99 (define-storage-base immediate-constant
:non-packed
)
102 ;;; Handy macro so we don't have to keep changing all the numbers whenever
103 ;;; we insert a new storage class.
105 (defmacro define-storage-classes
(&rest classes
)
106 (do ((forms (list 'progn
)
107 (let* ((class (car classes
))
108 (sc-name (car class
))
109 (constant-name (intern (concatenate 'simple-string
112 (list* `(define-storage-class ,sc-name
,index
114 `(def!constant
,constant-name
,index
)
117 (classes classes
(cdr classes
)))
121 (define-storage-classes
123 ;; Non-immediate contstants in the constant pool
126 ;; ZERO and NULL are in registers.
127 (zero immediate-constant
)
128 (null immediate-constant
)
130 ;; Anything else that can be an immediate.
131 (immediate immediate-constant
)
136 ;; The control stack. (Scanned by GC)
137 (control-stack control-stack
)
139 ;; We put ANY-REG and DESCRIPTOR-REG early so that their SC-NUMBER
140 ;; is small and therefore the error trap information is smaller.
141 ;; Moving them up here from their previous place down below saves
142 ;; ~250K in core file size. --njf, 2006-01-27
144 ;; Immediate descriptor objects. Don't have to be seen by GC, but nothing
145 ;; bad will happen if they are. (fixnums, characters, header values, etc).
148 :locations
#.
(append non-descriptor-regs descriptor-regs
)
149 :constant-scs
(zero immediate
)
151 :alternate-scs
(control-stack))
153 ;; Pointer descriptor objects. Must be seen by GC.
154 (descriptor-reg registers
155 :locations
#.descriptor-regs
156 :constant-scs
(constant null immediate
)
158 :alternate-scs
(control-stack))
160 ;; The non-descriptor stacks.
161 (signed-stack non-descriptor-stack
) ; (signed-byte 32)
162 (unsigned-stack non-descriptor-stack
) ; (unsigned-byte 32)
163 (character-stack non-descriptor-stack
) ; non-descriptor characters.
164 (sap-stack non-descriptor-stack
) ; System area pointers.
165 (single-stack non-descriptor-stack
) ; single-floats
166 (double-stack non-descriptor-stack
167 :element-size
2 :alignment
2) ; double floats.
168 (complex-single-stack non-descriptor-stack
:element-size
2)
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 :constant-scs
(immediate)
179 :alternate-scs
(character-stack))
181 ;; Non-Descriptor SAP's (arbitrary pointers into address space)
183 :locations
#.non-descriptor-regs
184 :constant-scs
(immediate)
186 :alternate-scs
(sap-stack))
188 ;; Non-Descriptor (signed or unsigned) numbers.
189 (signed-reg registers
190 :locations
#.non-descriptor-regs
191 :constant-scs
(zero immediate
)
193 :alternate-scs
(signed-stack))
194 (unsigned-reg registers
195 :locations
#.non-descriptor-regs
196 :constant-scs
(zero immediate
)
198 :alternate-scs
(unsigned-stack))
200 ;; Random objects that must not be seen by GC. Used only as temporaries.
201 (non-descriptor-reg registers
202 :locations
#.non-descriptor-regs
)
204 ;; Pointers to the interior of objects. Used only as a temporary.
205 (interior-reg registers
206 :locations
(#.lip-offset
))
209 ;; **** Things that can go in the floating point registers.
211 ;; Non-Descriptor single-floats.
212 (single-reg float-registers
213 :locations
#.
(loop for i from
0 to
31 collect i
)
214 ;; ### Note: We really should have every location listed, but then we
215 ;; would have to make load-tns work with element-sizes other than 1.
218 :alternate-scs
(single-stack))
220 ;; Non-Descriptor double-floats.
221 (double-reg float-registers
222 :locations
#.
(loop for i from
0 to
31 collect i
)
223 ;; ### Note: load-tns don't work with an element-size other than 1.
224 ;; :element-size 2 :alignment 2
227 :alternate-scs
(double-stack))
229 (complex-single-reg float-registers
230 :locations
#.
(loop for i from
0 to
30 by
2 collect i
)
234 :alternate-scs
(complex-single-stack))
236 (complex-double-reg float-registers
237 :locations
#.
(loop for i from
0 to
30 by
2 collect i
)
241 :alternate-scs
(complex-double-stack))
243 (catch-block control-stack
:element-size catch-block-size
)
244 (unwind-block control-stack
:element-size unwind-block-size
))
246 ;;;; Make some random tns for important registers.
248 (macrolet ((defregtn (name sc
)
249 (let ((offset-sym (symbolicate name
"-OFFSET"))
250 (tn-sym (symbolicate name
"-TN")))
251 `(defparameter ,tn-sym
252 (make-random-tn :kind
:normal
253 :sc
(sc-or-lose ',sc
)
254 :offset
,offset-sym
)))))
256 (defregtn zero any-reg
)
257 (defregtn lip interior-reg
)
258 (defregtn null descriptor-reg
)
259 (defregtn code descriptor-reg
)
260 (defregtn alloc any-reg
)
261 (defregtn lra descriptor-reg
)
262 (defregtn lexenv descriptor-reg
)
264 (defregtn nargs any-reg
)
265 (defregtn bsp any-reg
)
266 (defregtn csp any-reg
)
267 (defregtn cfp any-reg
)
268 (defregtn ocfp any-reg
)
269 (defregtn nsp any-reg
))
271 ;;; If VALUE can be represented as an immediate constant, then return the
272 ;;; appropriate SC number, otherwise return NIL.
273 (defun immediate-constant-sc (value)
276 (sc-number-or-lose 'zero
))
278 (sc-number-or-lose 'null
))
279 ((or (integer #.sb
!xc
:most-negative-fixnum
#.sb
!xc
:most-positive-fixnum
)
281 (sc-number-or-lose 'immediate
))
283 (if (static-symbol-p value
)
284 (sc-number-or-lose 'immediate
)
287 (defun boxed-immediate-sc-p (sc)
288 (or (eql sc
(sc-number-or-lose 'zero
))
289 (eql sc
(sc-number-or-lose 'null
))
290 (eql sc
(sc-number-or-lose 'immediate
))))
292 ;;; A predicate to see if a character can be used as an inline
293 ;;; constant (the immediate field in the instruction used is sixteen
294 ;;; bits wide, which is not the same as any defined subtype of
296 (defun inlinable-character-constant-p (char)
297 (and (characterp char
)
298 (< (char-code char
) #x10000
)))
300 ;;;; function call parameters
302 ;;; the SC numbers for register and stack arguments/return values
303 (def!constant immediate-arg-scn
(sc-number-or-lose 'any-reg
))
304 (def!constant control-stack-arg-scn
(sc-number-or-lose 'control-stack
))
306 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
308 ;;; offsets of special stack frame locations
309 (def!constant ocfp-save-offset
0)
310 (def!constant lra-save-offset
1)
311 (def!constant nfp-save-offset
2)
313 ;;; the number of arguments/return values passed in registers
314 (def!constant register-arg-count
4)
316 ;;; names to use for the argument registers
322 ;;; A list of TN's describing the register arguments.
324 (defparameter *register-arg-tns
*
325 (mapcar #'(lambda (n)
326 (make-random-tn :kind
:normal
327 :sc
(sc-or-lose 'descriptor-reg
)
329 *register-arg-offsets
*))
332 (defparameter thread-base-tn
333 (make-random-tn :kind
:normal
:sc
(sc-or-lose 'unsigned-reg
)
334 :offset thread-offset
))
336 (export 'single-value-return-byte-offset
)
338 ;;; This is used by the debugger.
339 (def!constant single-value-return-byte-offset
8)
341 ;;; This function is called by debug output routines that want a pretty name
342 ;;; for a TN's location. It returns a thing that can be printed with PRINC.
343 (defun location-print-name (tn)
344 (declare (type tn tn
))
345 (let ((sb (sb-name (sc-sb (tn-sc tn
))))
346 (offset (tn-offset tn
)))
348 (registers (or (svref *register-names
* offset
)
349 (format nil
"R~D" offset
)))
350 (float-registers (format nil
"F~D" offset
))
351 (control-stack (format nil
"CS~D" offset
))
352 (non-descriptor-stack (format nil
"NS~D" offset
))
353 (constant (format nil
"Const~D" offset
))
354 (immediate-constant "Immed"))))
356 (defun combination-implementation-style (node)
357 (declare (type sb
!c
::combination node
))
358 (flet ((valid-funtype (args result
)
359 (sb!c
::valid-fun-use node
360 (sb!c
::specifier-type
361 `(function ,args
,result
)))))
362 (case (sb!c
::combination-fun-source-name node
)
365 ((or (valid-funtype '(fixnum fixnum
) '*)
366 (valid-funtype '((signed-byte 32) (signed-byte 32)) '*)
367 (valid-funtype '((unsigned-byte 32) (unsigned-byte 32)) '*))
369 (t (values :default nil
))))
372 ((or (valid-funtype '((constant-arg (integer 0 29)) fixnum
) '*)
373 (valid-funtype '((constant-arg (integer 0 31)) (signed-byte 32)) '*)
374 (valid-funtype '((constant-arg (integer 0 31)) (unsigned-byte 32)) '*))
375 (values :transform
'(lambda (index integer
)
376 (%logbitp integer index
))))
377 (t (values :default nil
))))
378 ;; FIXME: can handle MIN and MAX here
380 (flet ((validp (type width
)
381 (and (valid-funtype `((constant-arg (integer 1 29))
382 (constant-arg (mod ,width
))
385 (destructuring-bind (size posn integer
)
386 (sb!c
::basic-combination-args node
)
387 (declare (ignore integer
))
388 (<= (+ (sb!c
::lvar-value size
)
389 (sb!c
::lvar-value posn
))
391 (if (or (validp 'fixnum
29)
392 (validp '(signed-byte 32) 32)
393 (validp '(unsigned-byte 32) 32))
394 (values :transform
'(lambda (size posn integer
)
395 (%%ldb integer size posn
)))
396 (values :default nil
))))
397 (t (values :default nil
)))))
399 (defun primitive-type-indirect-cell-type (ptype)
400 (declare (ignore ptype
))