1 ;;;; MIPS VM definitions of various system hacking operations
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.
15 ;;;; Type frobbing VOPs
17 (define-vop (lowtag-of)
18 (:translate lowtag-of)
20 (:args (object :scs (any-reg descriptor-reg)))
21 (:results (result :scs (unsigned-reg)))
22 (:result-types positive-fixnum)
24 (inst and result object lowtag-mask)))
26 (define-vop (widetag-of)
27 (:translate widetag-of)
29 (:args (object :scs (descriptor-reg)))
30 (:temporary (:scs (non-descriptor-reg)) ndescr)
31 (:results (result :scs (unsigned-reg)))
32 (:result-types positive-fixnum)
34 ;; Pick off objects with headers.
35 (inst and ndescr object lowtag-mask)
36 (inst xor ndescr other-pointer-lowtag)
37 (inst beq ndescr other-ptr)
38 (inst xor ndescr (logxor other-pointer-lowtag fun-pointer-lowtag))
39 (inst beq ndescr function-ptr)
42 (inst and result object 3)
43 (inst beq result done)
45 ;; Pick off structure and list pointers.
46 (inst and result object 1)
47 (inst bne result lowtag-only)
50 ;; Must be an other immediate.
52 (inst and result object widetag-mask)
55 (load-type result object (- fun-pointer-lowtag))
61 (inst and result object lowtag-mask)
64 (load-type result object (- other-pointer-lowtag))
69 (define-vop (fun-subtype)
70 (:translate fun-subtype)
72 (:args (function :scs (descriptor-reg)))
73 (:results (result :scs (unsigned-reg)))
74 (:result-types positive-fixnum)
76 (load-type result function (- fun-pointer-lowtag))
79 (define-vop (set-fun-subtype)
80 (:translate (setf fun-subtype))
82 (:args (type :scs (unsigned-reg) :target result)
83 (function :scs (descriptor-reg)))
84 (:arg-types positive-fixnum *)
85 (:results (result :scs (unsigned-reg)))
86 (:result-types positive-fixnum)
88 (inst sb type function (- fun-pointer-lowtag))
92 (define-vop (get-header-data)
93 (:translate get-header-data)
95 (:args (x :scs (descriptor-reg)))
96 (:results (res :scs (unsigned-reg)))
97 (:result-types positive-fixnum)
99 (loadw res x 0 other-pointer-lowtag)
100 (inst srl res res n-widetag-bits)))
102 (define-vop (get-closure-length)
103 (:translate get-closure-length)
105 (:args (x :scs (descriptor-reg)))
106 (:results (res :scs (unsigned-reg)))
107 (:result-types positive-fixnum)
109 (loadw res x 0 fun-pointer-lowtag)
110 (inst srl res res n-widetag-bits)))
112 (define-vop (set-header-data)
113 (:translate set-header-data)
115 (:args (x :scs (descriptor-reg) :target res)
116 (data :scs (any-reg immediate zero)))
117 (:arg-types * positive-fixnum)
118 (:results (res :scs (descriptor-reg)))
119 (:temporary (:scs (non-descriptor-reg)) t1 t2)
121 (loadw t1 x 0 other-pointer-lowtag)
122 (inst and t1 widetag-mask)
125 (inst sll t2 data (- n-widetag-bits 2))
128 (inst or t1 (ash (tn-value data) n-widetag-bits)))
130 (storew t1 x 0 other-pointer-lowtag)
133 (define-vop (pointer-hash)
134 (:translate pointer-hash)
135 (:args (ptr :scs (any-reg descriptor-reg)))
136 (:results (res :scs (any-reg descriptor-reg)))
139 ;; FIXME: It would be better if this would mask the lowtag,
140 ;; and shift the result into a positive fixnum like on x86.
142 (inst srl res res 1)))
144 (define-vop (make-other-immediate-type)
145 (:args (val :scs (any-reg descriptor-reg))
146 (type :scs (any-reg descriptor-reg immediate)
148 (:results (res :scs (any-reg descriptor-reg)))
149 (:temporary (:scs (non-descriptor-reg)) temp)
153 (inst sll temp val n-widetag-bits)
154 (inst or res temp (tn-value type)))
156 (inst sra temp type 2)
157 (inst sll res val (- n-widetag-bits 2))
158 (inst or res res temp)))))
163 (define-vop (dynamic-space-free-pointer)
164 (:results (int :scs (sap-reg)))
165 (:result-types system-area-pointer)
166 (:translate dynamic-space-free-pointer)
169 (move int alloc-tn)))
171 (define-vop (binding-stack-pointer-sap)
172 (:results (int :scs (sap-reg)))
173 (:result-types system-area-pointer)
174 (:translate binding-stack-pointer-sap)
179 (define-vop (control-stack-pointer-sap)
180 (:results (int :scs (sap-reg)))
181 (:result-types system-area-pointer)
182 (:translate control-stack-pointer-sap)
188 ;;;; Code object frobbing.
190 (define-vop (code-instructions)
191 (:translate code-instructions)
193 (:args (code :scs (descriptor-reg)))
194 (:temporary (:scs (non-descriptor-reg)) ndescr)
195 (:results (sap :scs (sap-reg)))
196 (:result-types system-area-pointer)
198 (loadw ndescr code 0 other-pointer-lowtag)
199 (inst srl ndescr n-widetag-bits)
200 (inst sll ndescr word-shift)
201 (inst subu ndescr other-pointer-lowtag)
202 (inst addu sap code ndescr)))
204 (define-vop (compute-fun)
205 (:args (code :scs (descriptor-reg))
206 (offset :scs (signed-reg unsigned-reg)))
207 (:arg-types * positive-fixnum)
208 (:results (func :scs (descriptor-reg)))
209 (:temporary (:scs (non-descriptor-reg)) ndescr)
211 (loadw ndescr code 0 other-pointer-lowtag)
212 (inst srl ndescr n-widetag-bits)
213 (inst sll ndescr word-shift)
214 (inst addu ndescr offset)
215 (inst addu ndescr (- fun-pointer-lowtag other-pointer-lowtag))
216 (inst addu func code ndescr)))
219 ;;;; Other random VOPs.
222 (defknown sb!unix::receive-pending-interrupt () (values))
223 (define-vop (sb!unix::receive-pending-interrupt)
225 (:translate sb!unix::receive-pending-interrupt)
227 (inst break 0 pending-interrupt-trap)))
232 (inst break 0 halt-trap)))
235 ;;;; Dynamic vop count collection support
237 (define-vop (count-me)
238 (:args (count-vector :scs (descriptor-reg)))
240 (:temporary (:scs (non-descriptor-reg)) count)
243 (- (* (+ index vector-data-offset) n-word-bytes) other-pointer-lowtag)))
244 (inst lw count count-vector offset)
247 (inst sw count count-vector offset))))