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 rlwinm res ptr n-fixnum-tag-bits 1 n-positive-fixnum-bits)))
133 (define-vop (make-other-immediate-type)
134 (:args (val :scs (any-reg descriptor-reg))
135 (type :scs (any-reg descriptor-reg immediate)
137 (:results (res :scs (any-reg descriptor-reg)))
138 (:temporary (:scs (non-descriptor-reg)) temp)
142 (inst slwi temp val n-widetag-bits)
143 (inst ori res temp (tn-value type)))
145 (inst srawi temp type 2)
146 (inst slwi res val (- n-widetag-bits 2))
147 (inst or res res temp)))))
152 (define-vop (dynamic-space-free-pointer)
153 (:results (int :scs (sap-reg)))
154 (:result-types system-area-pointer)
155 (:translate dynamic-space-free-pointer)
158 (move int alloc-tn)))
160 (define-vop (binding-stack-pointer-sap)
161 (:results (int :scs (sap-reg)))
162 (:result-types system-area-pointer)
163 (:translate binding-stack-pointer-sap)
168 (define-vop (control-stack-pointer-sap)
169 (:results (int :scs (sap-reg)))
170 (:result-types system-area-pointer)
171 (:translate control-stack-pointer-sap)
177 ;;;; Code object frobbing.
179 (define-vop (code-instructions)
180 (:translate code-instructions)
182 (:args (code :scs (descriptor-reg)))
183 (:temporary (:scs (non-descriptor-reg)) ndescr)
184 (:results (sap :scs (sap-reg)))
185 (:result-types system-area-pointer)
187 (loadw ndescr code 0 other-pointer-lowtag)
188 (inst srwi ndescr ndescr n-widetag-bits)
189 (inst slwi ndescr ndescr word-shift)
190 (inst subi ndescr ndescr other-pointer-lowtag)
191 (inst add sap code ndescr)))
193 (define-vop (compute-fun)
194 (:args (code :scs (descriptor-reg))
195 (offset :scs (signed-reg unsigned-reg)))
196 (:arg-types * positive-fixnum)
197 (:results (func :scs (descriptor-reg)))
198 (:temporary (:scs (non-descriptor-reg)) ndescr)
200 (loadw ndescr code 0 other-pointer-lowtag)
201 (inst srwi ndescr ndescr n-widetag-bits)
202 (inst slwi ndescr ndescr word-shift)
203 (inst add ndescr ndescr offset)
204 (inst addi ndescr ndescr (- fun-pointer-lowtag other-pointer-lowtag))
205 (inst add func code ndescr)))
209 ;;;; Other random VOPs.
212 (defknown sb!unix::receive-pending-interrupt () (values))
213 (define-vop (sb!unix::receive-pending-interrupt)
215 (:translate sb!unix::receive-pending-interrupt)
217 (inst unimp pending-interrupt-trap)))
221 (inst unimp halt-trap)))
223 ;;;; Dynamic vop count collection support
225 (define-vop (count-me)
226 (:args (count-vector :scs (descriptor-reg)))
228 (:temporary (:scs (non-descriptor-reg)) count)
231 (- (* (+ index vector-data-offset) n-word-bytes) other-pointer-lowtag)))
232 (aver (typep offset '(signed-byte 16)))
233 (inst lwz count count-vector offset)
234 (inst addi count count 1)
235 (inst stw count count-vector offset))))