1 ;;;; x86 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 control-stack)
21 (:results (result :scs (unsigned-reg)))
22 (:result-types positive-fixnum)
25 (inst and result lowtag-mask)))
27 (define-vop (widetag-of)
28 (:translate widetag-of)
30 (:args (object :scs (descriptor-reg)))
31 (:temporary (:sc unsigned-reg :offset eax-offset :to (:result 0)) rax)
32 (:results (result :scs (unsigned-reg)))
33 (:result-types positive-fixnum)
36 (inst and al-tn lowtag-mask)
37 (inst cmp al-tn other-pointer-lowtag)
38 (inst jmp :e OTHER-PTR)
39 (inst cmp al-tn fun-pointer-lowtag)
40 (inst jmp :e FUNCTION-PTR)
42 ;; Pick off structures and list pointers.
50 ;; must be an other immediate
55 (load-type al-tn object (- fun-pointer-lowtag))
59 (load-type al-tn object (- other-pointer-lowtag))
62 (inst movzx result al-tn)))
64 (define-vop (fun-subtype)
65 (:translate fun-subtype)
67 (:args (function :scs (descriptor-reg)))
68 (:temporary (:sc byte-reg :from (:eval 0) :to (:eval 1)) temp)
69 (:results (result :scs (unsigned-reg)))
70 (:result-types positive-fixnum)
72 (load-type temp function (- fun-pointer-lowtag))
73 (inst movzx result temp)))
75 (define-vop (set-fun-subtype)
76 (:translate (setf fun-subtype))
78 (:args (type :scs (unsigned-reg) :target eax)
79 (function :scs (descriptor-reg)))
80 (:arg-types positive-fixnum *)
81 (:temporary (:sc unsigned-reg :offset rax-offset :from (:argument 0)
82 :to (:result 0) :target result)
84 (:results (result :scs (unsigned-reg)))
85 (:result-types positive-fixnum)
89 (make-ea :byte :base function :disp (- fun-pointer-lowtag))
93 (define-vop (get-header-data)
94 (:translate get-header-data)
96 (:args (x :scs (descriptor-reg)))
97 (:results (res :scs (unsigned-reg)))
98 (:result-types positive-fixnum)
100 (loadw res x 0 other-pointer-lowtag)
101 (inst shr res n-widetag-bits)))
103 (define-vop (get-closure-length)
104 (:translate get-closure-length)
106 (:args (x :scs (descriptor-reg)))
107 (:results (res :scs (unsigned-reg)))
108 (:result-types positive-fixnum)
110 (loadw res x 0 fun-pointer-lowtag)
111 (inst shr res n-widetag-bits)))
113 (define-vop (set-header-data)
114 (:translate set-header-data)
116 (:args (x :scs (descriptor-reg) :target res :to (:result 0))
117 (data :scs (any-reg) :target eax))
118 (:arg-types * positive-fixnum)
119 (:results (res :scs (descriptor-reg)))
120 (:temporary (:sc unsigned-reg :offset eax-offset
121 :from (:argument 1) :to (:result 0)) eax)
124 (inst shl eax (- n-widetag-bits n-fixnum-tag-bits))
125 (inst mov al-tn (make-ea :byte :base x :disp (- other-pointer-lowtag)))
126 (storew eax x 0 other-pointer-lowtag)
129 (define-vop (make-fixnum)
130 (:args (ptr :scs (any-reg descriptor-reg) :target res))
131 (:results (res :scs (any-reg descriptor-reg)))
133 ;; Some code (the hash table code) depends on this returning a
134 ;; positive number so make sure it does.
139 (define-vop (make-other-immediate-type)
140 (:args (val :scs (any-reg descriptor-reg) :target res)
141 (type :scs (unsigned-reg immediate)))
142 (:results (res :scs (any-reg descriptor-reg) :from (:argument 0)))
145 (inst shl res (- n-widetag-bits n-fixnum-tag-bits))
146 (inst or res (sc-case type
148 (immediate (tn-value type))))))
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 (load-symbol-value int *allocation-pointer*)))
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)
166 (load-binding-stack-pointer int)))
168 (defknown (setf binding-stack-pointer-sap)
169 (system-area-pointer) system-area-pointer ())
171 (define-vop (set-binding-stack-pointer-sap)
172 (:args (new-value :scs (sap-reg) :target int))
173 (:arg-types system-area-pointer)
174 (:results (int :scs (sap-reg)))
175 (:result-types system-area-pointer)
176 (:translate (setf binding-stack-pointer-sap))
179 (store-binding-stack-pointer new-value)
180 (move int new-value)))
182 (define-vop (control-stack-pointer-sap)
183 (:results (int :scs (sap-reg)))
184 (:result-types system-area-pointer)
185 (:translate control-stack-pointer-sap)
190 ;;;; code object frobbing
192 (define-vop (code-instructions)
193 (:translate code-instructions)
195 (:args (code :scs (descriptor-reg) :to (:result 0)))
196 (:results (sap :scs (sap-reg) :from (:argument 0)))
197 (:result-types system-area-pointer)
199 (loadw sap code 0 other-pointer-lowtag)
200 (inst shr sap n-widetag-bits)
201 (inst lea sap (make-ea :byte :base code :index sap
203 :disp (- other-pointer-lowtag)))))
205 (define-vop (compute-fun)
206 (:args (code :scs (descriptor-reg) :to (:result 0))
207 (offset :scs (signed-reg unsigned-reg) :to (:result 0)))
208 (:arg-types * positive-fixnum)
209 (:results (func :scs (descriptor-reg) :from (:argument 0)))
211 (loadw func code 0 other-pointer-lowtag)
212 (inst shr func n-widetag-bits)
214 (make-ea :byte :base offset :index func
216 :disp (- fun-pointer-lowtag other-pointer-lowtag)))
217 (inst add func code)))
219 (define-vop (%simple-fun-self)
221 (:translate %simple-fun-self)
222 (:args (function :scs (descriptor-reg)))
223 (:results (result :scs (descriptor-reg)))
225 (loadw result function simple-fun-self-slot fun-pointer-lowtag)
227 (make-ea :byte :base result
228 :disp (- fun-pointer-lowtag
229 (* simple-fun-code-offset n-word-bytes))))))
231 ;;; The closure function slot is a pointer to raw code on X86 instead
232 ;;; of a pointer to the code function object itself. This VOP is used
233 ;;; to reference the function object given the closure object.
234 (define-source-transform %closure-fun (closure)
235 `(%simple-fun-self ,closure))
237 (define-vop (%set-fun-self)
239 (:translate (setf %simple-fun-self))
240 (:args (new-self :scs (descriptor-reg) :target result :to :result)
241 (function :scs (descriptor-reg) :to :result))
242 (:temporary (:sc any-reg :from (:argument 0) :to :result) temp)
243 (:results (result :scs (descriptor-reg)))
246 (make-ea :byte :base new-self
247 :disp (- (ash simple-fun-code-offset word-shift)
248 fun-pointer-lowtag)))
249 (storew temp function simple-fun-self-slot fun-pointer-lowtag)
250 (move result new-self)))
252 ;;;; other miscellaneous VOPs
254 (defknown sb!unix::receive-pending-interrupt () (values))
255 (define-vop (sb!unix::receive-pending-interrupt)
257 (:translate sb!unix::receive-pending-interrupt)
259 (inst break pending-interrupt-trap)))
262 (defknown current-thread-offset-sap ((unsigned-byte 64))
263 system-area-pointer (flushable))
266 (define-vop (current-thread-offset-sap)
267 (:results (sap :scs (sap-reg)))
268 (:result-types system-area-pointer)
269 (:translate current-thread-offset-sap)
270 (:args (n :scs (unsigned-reg) :target sap))
271 (:arg-types unsigned-num)
275 (make-ea :qword :base thread-base-tn :disp 0 :index n :scale 8))))
279 (inst break halt-trap)))
281 (defknown float-wait () (values))
282 (define-vop (float-wait)
284 (:translate float-wait)
286 (:save-p :compute-only)
288 (note-next-instruction vop :internal-error)
291 ;;;; dynamic vop count collection support
294 (define-vop (count-me)
295 (:args (count-vector :scs (descriptor-reg)))
298 (inst inc (make-ea :qword :base count-vector
299 :disp (- (* (+ vector-data-offset index) n-word-bytes)
300 other-pointer-lowtag)))))