1 ;;;; PPC 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.
14 ;;;; Type frobbing VOPs
16 (define-vop (lowtag-of)
17 (:translate lowtag-of)
19 (:args (object :scs (any-reg descriptor-reg)))
20 (:results (result :scs (unsigned-reg)))
21 (:result-types positive-fixnum)
23 (inst andi. result object lowtag-mask)))
25 (define-vop (widetag-of)
26 (:translate widetag-of)
28 (:args (object :scs (descriptor-reg) :to (:eval 1)))
29 (:results (result :scs (unsigned-reg) :from (:eval 0)))
30 (:result-types positive-fixnum)
33 (inst andi. result object lowtag-mask)
34 ;; Check for various pointer types.
35 (inst cmpwi result list-pointer-lowtag)
37 (inst cmpwi result other-pointer-lowtag)
38 (inst beq other-pointer)
39 (inst cmpwi result fun-pointer-lowtag)
40 (inst beq function-pointer)
41 (inst cmpwi result instance-pointer-lowtag)
43 ;; Okay, it is an immediate. If fixnum, we want zero. Otherwise,
44 ;; we want the low 8 bits.
45 (inst andi. result object #b11)
47 ;; It wasn't a fixnum, so get the low 8 bits.
48 (inst andi. result object widetag-mask)
52 (load-type result object (- fun-pointer-lowtag))
56 (load-type result object (- other-pointer-lowtag))
61 (define-vop (fun-subtype)
62 (:translate fun-subtype)
64 (:args (function :scs (descriptor-reg)))
65 (:results (result :scs (unsigned-reg)))
66 (:result-types positive-fixnum)
68 (load-type result function (- fun-pointer-lowtag))))
70 (define-vop (set-fun-subtype)
71 (:translate (setf fun-subtype))
73 (:args (type :scs (unsigned-reg) :target result)
74 (function :scs (descriptor-reg)))
75 (:arg-types positive-fixnum *)
76 (:results (result :scs (unsigned-reg)))
77 (:result-types positive-fixnum)
79 (inst stb type function (- 3 fun-pointer-lowtag))
82 (define-vop (get-header-data)
83 (:translate get-header-data)
85 (:args (x :scs (descriptor-reg)))
86 (:results (res :scs (unsigned-reg)))
87 (:result-types positive-fixnum)
89 (loadw res x 0 other-pointer-lowtag)
90 (inst srwi res res n-widetag-bits)))
92 (define-vop (get-closure-length)
93 (:translate get-closure-length)
95 (:args (x :scs (descriptor-reg)))
96 (:results (res :scs (unsigned-reg)))
97 (:result-types positive-fixnum)
99 (loadw res x 0 fun-pointer-lowtag)
100 (inst srwi res res n-widetag-bits)))
102 (define-vop (set-header-data)
103 (:translate set-header-data)
105 (:args (x :scs (descriptor-reg) :target res)
106 (data :scs (any-reg immediate zero)))
107 (:arg-types * positive-fixnum)
108 (:results (res :scs (descriptor-reg)))
109 (:temporary (:scs (non-descriptor-reg)) t1 t2)
111 (loadw t1 x 0 other-pointer-lowtag)
112 (inst andi. t1 t1 widetag-mask)
115 (inst slwi t2 data (- n-widetag-bits 2))
118 (inst ori t1 t1 (ash (tn-value data) n-widetag-bits)))
120 (storew t1 x 0 other-pointer-lowtag)
124 (define-vop (make-fixnum)
125 (:args (ptr :scs (any-reg descriptor-reg)))
126 (:results (res :scs (any-reg descriptor-reg)))
129 ;; Some code (the hash table code) depends on this returning a
130 ;; positive number so make sure it does.
131 (inst slwi res ptr 3)
132 (inst srwi res res 1)))
134 (define-vop (make-other-immediate-type)
135 (:args (val :scs (any-reg descriptor-reg))
136 (type :scs (any-reg descriptor-reg immediate)
138 (:results (res :scs (any-reg descriptor-reg)))
139 (:temporary (:scs (non-descriptor-reg)) temp)
143 (inst slwi temp val n-widetag-bits)
144 (inst ori res temp (tn-value type)))
146 (inst srawi temp type 2)
147 (inst slwi res val (- n-widetag-bits 2))
148 (inst or res res temp)))))
153 (define-vop (dynamic-space-free-pointer)
154 (:results (int :scs (sap-reg)))
155 (:result-types system-area-pointer)
156 (:translate dynamic-space-free-pointer)
159 (move int alloc-tn)))
161 (define-vop (binding-stack-pointer-sap)
162 (:results (int :scs (sap-reg)))
163 (:result-types system-area-pointer)
164 (:translate binding-stack-pointer-sap)
169 (define-vop (control-stack-pointer-sap)
170 (:results (int :scs (sap-reg)))
171 (:result-types system-area-pointer)
172 (:translate control-stack-pointer-sap)
178 ;;;; Code object frobbing.
180 (define-vop (code-instructions)
181 (:translate code-instructions)
183 (:args (code :scs (descriptor-reg)))
184 (:temporary (:scs (non-descriptor-reg)) ndescr)
185 (:results (sap :scs (sap-reg)))
186 (:result-types system-area-pointer)
188 (loadw ndescr code 0 other-pointer-lowtag)
189 (inst srwi ndescr ndescr n-widetag-bits)
190 (inst slwi ndescr ndescr word-shift)
191 (inst subi ndescr ndescr other-pointer-lowtag)
192 (inst add sap code ndescr)))
194 (define-vop (compute-fun)
195 (:args (code :scs (descriptor-reg))
196 (offset :scs (signed-reg unsigned-reg)))
197 (:arg-types * positive-fixnum)
198 (:results (func :scs (descriptor-reg)))
199 (:temporary (:scs (non-descriptor-reg)) ndescr)
201 (loadw ndescr code 0 other-pointer-lowtag)
202 (inst srwi ndescr ndescr n-widetag-bits)
203 (inst slwi ndescr ndescr word-shift)
204 (inst add ndescr ndescr offset)
205 (inst addi ndescr ndescr (- fun-pointer-lowtag other-pointer-lowtag))
206 (inst add func code ndescr)))
210 ;;;; Other random VOPs.
213 (defknown sb!unix::receive-pending-interrupt () (values))
214 (define-vop (sb!unix::receive-pending-interrupt)
216 (:translate sb!unix::receive-pending-interrupt)
218 (inst unimp pending-interrupt-trap)))
222 (inst unimp halt-trap)))
224 ;;;; Dynamic vop count collection support
226 (define-vop (count-me)
227 (:args (count-vector :scs (descriptor-reg)))
229 (:temporary (:scs (non-descriptor-reg)) count)
232 (- (* (+ index vector-data-offset) n-word-bytes) other-pointer-lowtag)))
233 (aver (typep offset '(signed-byte 16)))
234 (inst lwz count count-vector offset)
235 (inst addi count count 1)
236 (inst stw count count-vector offset))))