0.8.21.21: fix & share EXTERN-ALIEN-NAME logic (fixes bug #373)
[sbcl.git] / src / compiler / hppa / vm.lisp
1 ;;;; miscellaneous VM definition noise for HPPA
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
11
12 (in-package "SB!VM")
13
14 \f
15 ;;;; Define the registers
16
17 (eval-when (:compile-toplevel :load-toplevel :execute)
18   (defvar *register-names* (make-array 32 :initial-element nil)))
19
20 ;;; FIXME: These want to turn into macrolets.
21 (macrolet ((defreg (name offset)
22                (let ((offset-sym (symbolicate name "-OFFSET")))
23                  `(eval-when (:compile-toplevel :load-toplevel :execute)
24                    (def!constant ,offset-sym ,offset)
25                    (setf (svref *register-names* ,offset-sym) ,(symbol-name name)))))
26            (defregset (name &rest regs)
27                `(eval-when (:compile-toplevel :load-toplevel :execute)
28                  (defparameter ,name
29                    (list ,@(mapcar #'(lambda (name) (symbolicate name "-OFFSET")) regs))))))
30
31   ;; Wired-zero
32   (defreg zero 0)
33   ;; This gets trashed by the C call convention.
34   (defreg nfp 1)
35   (defreg cfunc 2)
36   ;; These are the callee saves, so these registers are stay live over
37   ;; call-out.
38   (defreg csp 3)
39   (defreg cfp 4)
40   (defreg bsp 5)
41   (defreg null 6)
42   (defreg alloc 7)
43   (defreg code 8)
44   (defreg fdefn 9)
45   (defreg lexenv 10)
46   (defreg nargs 11)
47   (defreg ocfp 12)
48   (defreg lra 13)
49   (defreg a0 14)
50   (defreg a1 15)
51   (defreg a2 16)
52   (defreg a3 17)
53   (defreg a4 18)
54   ;; This is where the caller-saves registers start, but we don't
55   ;; really care because we need to clear the above after call-out to
56   ;; make sure no pointers into oldspace are kept around.
57   (defreg a5 19)
58   (defreg l0 20)
59   (defreg l1 21)
60   (defreg l2 22)
61   ;; These are the 4 C argument registers.
62   (defreg nl3 23)
63   (defreg nl2 24)
64   (defreg nl1 25)
65   (defreg nl0 26)
66   ;; The global Data Pointer.  We just leave it alone, because we
67   ;; don't need it.
68   (defreg dp 27)
69   ;; These two are use for C return values.
70   (defreg nl4 28)
71   (defreg nl5 29)
72   (defreg nsp 30)
73   (defreg lip 31)
74
75   (defregset non-descriptor-regs
76       nl0 nl1 nl2 nl3 nl4 nl5 nfp cfunc)
77
78   (defregset descriptor-regs
79       fdefn lexenv nargs ocfp lra a0 a1 a2 a3 a4 a5 l0 l1 l2)
80
81   (defregset *register-arg-offsets*
82       a0 a1 a2 a3 a4 a5))
83
84
85 (define-storage-base registers :finite :size 32)
86 (define-storage-base float-registers :finite :size 64)
87 (define-storage-base control-stack :unbounded :size 8)
88 (define-storage-base non-descriptor-stack :unbounded :size 0)
89 (define-storage-base constant :non-packed)
90 (define-storage-base immediate-constant :non-packed)
91
92 ;;;
93 ;;; Handy macro so we don't have to keep changing all the numbers whenever
94 ;;; we insert a new storage class.
95 ;;; 
96 (defmacro !define-storage-classes (&rest classes)
97   (do ((forms (list 'progn)
98               (let* ((class (car classes))
99                      (sc-name (car class))
100                      (constant-name (intern (concatenate 'simple-string
101                                                          (string sc-name)
102                                                          "-SC-NUMBER"))))
103                 (list* `(define-storage-class ,sc-name ,index
104                           ,@(cdr class))
105                        `(defconstant ,constant-name ,index)
106                        `(export ',constant-name)
107                        forms)))
108        (index 0 (1+ index))
109        (classes classes (cdr classes)))
110       ((null classes)
111        (nreverse forms))))
112
113 (def!constant kludge-nondeterministic-catch-block-size 7)
114
115 (!define-storage-classes
116
117   ;; Non-immediate contstants in the constant pool
118   (constant constant)
119
120   ;; ZERO and NULL are in registers.
121   (zero immediate-constant)
122   (null immediate-constant)
123   (fp-single-zero immediate-constant)
124   (fp-double-zero immediate-constant)
125
126   ;; Anything else that can be an immediate.
127   (immediate immediate-constant)
128
129
130   ;; **** The stacks.
131
132   ;; The control stack.  (Scanned by GC)
133   (control-stack control-stack)
134
135   ;; The non-descriptor stacks.
136   (signed-stack non-descriptor-stack) ; (signed-byte 32)
137   (unsigned-stack non-descriptor-stack) ; (unsigned-byte 32)
138   (character-stack non-descriptor-stack) ; non-descriptor characters.
139   (sap-stack non-descriptor-stack) ; System area pointers.
140   (single-stack non-descriptor-stack) ; single-floats
141   (double-stack non-descriptor-stack
142                 :element-size 2 :alignment 2) ; double floats.
143   (complex-single-stack non-descriptor-stack :element-size 2)
144   (complex-double-stack non-descriptor-stack :element-size 4 :alignment 2)
145
146
147   ;; **** Things that can go in the integer registers.
148
149   ;; Immediate descriptor objects.  Don't have to be seen by GC, but nothing
150   ;; bad will happen if they are.  (fixnums, characters, header values, etc).
151   (any-reg
152    registers
153    :locations #.(append non-descriptor-regs descriptor-regs)
154    :constant-scs (zero immediate)
155    :save-p t
156    :alternate-scs (control-stack))
157
158   ;; Pointer descriptor objects.  Must be seen by GC.
159   (descriptor-reg registers
160    :locations #.descriptor-regs
161    :constant-scs (constant null immediate)
162    :save-p t
163    :alternate-scs (control-stack))
164
165   ;; Non-Descriptor characters
166   (character-reg registers
167    :locations #.non-descriptor-regs
168    :constant-scs (immediate)
169    :save-p t
170    :alternate-scs (character-stack))
171
172   ;; Non-Descriptor SAP's (arbitrary pointers into address space)
173   (sap-reg registers
174    :locations #.non-descriptor-regs
175    :constant-scs (immediate)
176    :save-p t
177    :alternate-scs (sap-stack))
178
179   ;; Non-Descriptor (signed or unsigned) numbers.
180   (signed-reg registers
181    :locations #.non-descriptor-regs
182    :constant-scs (zero immediate)
183    :save-p t
184    :alternate-scs (signed-stack))
185   (unsigned-reg registers
186    :locations #.non-descriptor-regs
187    :constant-scs (zero immediate)
188    :save-p t
189    :alternate-scs (unsigned-stack))
190
191   ;; Random objects that must not be seen by GC.  Used only as temporaries.
192   (non-descriptor-reg registers
193    :locations #.non-descriptor-regs)
194
195   ;; Pointers to the interior of objects.  Used only as an temporary.
196   (interior-reg registers
197    :locations (#.lip-offset))
198
199
200   ;; **** Things that can go in the floating point registers.
201
202   ;; Non-Descriptor single-floats.
203   (single-reg float-registers
204    :locations #.(loop for i from 4 to 31 collect i)
205    :constant-scs (fp-single-zero)
206    :save-p t
207    :alternate-scs (single-stack))
208
209   ;; Non-Descriptor double-floats.
210   (double-reg float-registers
211    :locations #.(loop for i from 4 to 31 collect i)
212    :constant-scs (fp-double-zero)
213    :save-p t
214    :alternate-scs (double-stack))
215
216   (complex-single-reg float-registers
217    :locations #.(loop for i from 4 to 30 by 2 collect i)
218    :element-size 2
219    :constant-scs ()
220    :save-p t
221    :alternate-scs (complex-single-stack))
222
223   (complex-double-reg float-registers
224    :locations #.(loop for i from 4 to 30 by 2 collect i)
225    :element-size 2
226    :constant-scs ()
227    :save-p t
228    :alternate-scs (complex-double-stack))
229
230   ;; A catch or unwind block.
231   (catch-block control-stack :element-size kludge-nondeterministic-catch-block-size))
232
233 \f
234 ;;;; Make some random tns for important registers.
235
236 (macrolet ((defregtn (name sc)
237                (let ((offset-sym (symbolicate name "-OFFSET"))
238                      (tn-sym (symbolicate name "-TN")))
239                  `(defparameter ,tn-sym
240                    (make-random-tn :kind :normal
241                     :sc (sc-or-lose ',sc)
242                     :offset ,offset-sym)))))
243
244   ;; These, we access by foo-TN only
245   
246   (defregtn zero any-reg)
247   (defregtn null descriptor-reg)
248   (defregtn code descriptor-reg)
249   (defregtn alloc any-reg)
250   (defregtn bsp any-reg)
251   (defregtn csp any-reg)
252   (defregtn cfp any-reg)
253   (defregtn nsp any-reg)
254   
255   ;; These alias regular locations, so we have to make sure we don't bypass
256   ;; the register allocator when using them.
257   (defregtn nargs any-reg)
258   (defregtn ocfp any-reg)
259   (defregtn lip interior-reg))
260
261 ;; And some floating point values.
262 (defparameter fp-single-zero-tn
263   (make-random-tn :kind :normal
264                   :sc (sc-or-lose 'single-reg)
265                   :offset 0))
266 (defparameter fp-double-zero-tn
267   (make-random-tn :kind :normal
268                   :sc (sc-or-lose 'double-reg)
269                   :offset 0))
270
271 \f
272 ;;; If VALUE can be represented as an immediate constant, then return
273 ;;; the appropriate SC number, otherwise return NIL.
274 (!def-vm-support-routine immediate-constant-sc (value)
275   (typecase value
276     ((integer 0 0)
277      (sc-number-or-lose 'zero))
278     (null
279      (sc-number-or-lose 'null))
280     ((or (integer #.sb!xc:most-negative-fixnum #.sb!xc:most-positive-fixnum)
281          system-area-pointer character)
282      (sc-number-or-lose 'immediate))
283     (symbol
284      (if (static-symbol-p value)
285          (sc-number-or-lose 'immediate)
286          nil))
287     (single-float
288      (if (zerop value)
289          (sc-number-or-lose 'fp-single-zero)
290          nil))
291     (double-float
292      (if (zerop value)
293          (sc-number-or-lose 'fp-double-zero)
294          nil))))
295
296 \f
297 ;;;; Function Call Parameters
298
299 ;;; The SC numbers for register and stack arguments/return values.
300 ;;;
301 (defconstant register-arg-scn (meta-sc-number-or-lose 'descriptor-reg))
302 (defconstant immediate-arg-scn (meta-sc-number-or-lose 'any-reg))
303 (defconstant control-stack-arg-scn (meta-sc-number-or-lose 'control-stack))
304
305 (eval-when (:compile-toplevel :load-toplevel :execute)
306
307 ;;; Offsets of special stack frame locations
308 (defconstant ocfp-save-offset 0)
309 (defconstant lra-save-offset 1)
310 (defconstant nfp-save-offset 2)
311
312 ;;; The number of arguments/return values passed in registers.
313 ;;;
314 (defconstant register-arg-count 6)
315
316 ;;; Names to use for the argument registers.
317 ;;; 
318 (defconstant-eqx register-arg-names '(a0 a1 a2 a3 a4 a5) #'equal)
319
320 ) ; EVAL-WHEN
321
322
323 ;;; A list of TN's describing the register arguments.
324 ;;;
325 (defparameter register-arg-tns
326   (mapcar #'(lambda (n)
327               (make-random-tn :kind :normal
328                               :sc (sc-or-lose 'descriptor-reg)
329                               :offset n))
330           *register-arg-offsets*))
331
332 ;;; This is used by the debugger.
333 (defconstant single-value-return-byte-offset 4)
334 \f
335 ;;; This function is called by debug output routines that want a pretty name
336 ;;; for a TN's location.  It returns a thing that can be printed with PRINC.
337 (!def-vm-support-routine location-print-name (tn)
338   (declare (type tn tn))
339   (let ((sb (sb-name (sc-sb (tn-sc tn))))
340         (offset (tn-offset tn)))
341     (ecase sb
342       (registers (or (svref *register-names* offset)
343                      (format nil "R~D" offset)))
344       (float-registers (format nil "F~D" offset))
345       (control-stack (format nil "CS~D" offset))
346       (non-descriptor-stack (format nil "NS~D" offset))
347       (constant (format nil "Const~D" offset))
348       (immediate-constant "Immed"))))
349
350