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)) eax)
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 eax-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 2))
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 2))
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-tl-symbol-value int *binding-stack-pointer*)))
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 #!+sb-thread (:temporary (:sc any-reg) temp)
177 (:translate (setf binding-stack-pointer-sap))
180 (store-tl-symbol-value new-value *binding-stack-pointer* temp)
181 (move int new-value)))
183 (define-vop (control-stack-pointer-sap)
184 (:results (int :scs (sap-reg)))
185 (:result-types system-area-pointer)
186 (:translate control-stack-pointer-sap)
191 ;;;; code object frobbing
193 (define-vop (code-instructions)
194 (:translate code-instructions)
196 (:args (code :scs (descriptor-reg) :to (:result 0)))
197 (:results (sap :scs (sap-reg) :from (:argument 0)))
198 (:result-types system-area-pointer)
200 (loadw sap code 0 other-pointer-lowtag)
201 (inst shr sap n-widetag-bits)
202 (inst lea sap (make-ea :byte :base code :index sap :scale 4
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 :scale 4
215 :disp (- fun-pointer-lowtag other-pointer-lowtag)))
216 (inst add func code)))
218 (define-vop (%simple-fun-self)
220 (:translate %simple-fun-self)
221 (:args (function :scs (descriptor-reg)))
222 (:results (result :scs (descriptor-reg)))
224 (loadw result function simple-fun-self-slot fun-pointer-lowtag)
226 (make-ea :byte :base result
227 :disp (- fun-pointer-lowtag
228 (* simple-fun-code-offset n-word-bytes))))))
230 ;;; The closure function slot is a pointer to raw code on X86 instead
231 ;;; of a pointer to the code function object itself. This VOP is used
232 ;;; to reference the function object given the closure object.
233 (define-source-transform %closure-fun (closure)
234 `(%simple-fun-self ,closure))
236 (define-source-transform %funcallable-instance-fun (fin)
237 `(%simple-fun-self ,fin))
239 (define-vop (%set-fun-self)
241 (:translate (setf %simple-fun-self))
242 (:args (new-self :scs (descriptor-reg) :target result :to :result)
243 (function :scs (descriptor-reg) :to :result))
244 (:temporary (:sc any-reg :from (:argument 0) :to :result) temp)
245 (:results (result :scs (descriptor-reg)))
248 (make-ea :byte :base new-self
249 :disp (- (ash simple-fun-code-offset word-shift)
250 fun-pointer-lowtag)))
251 (storew temp function simple-fun-self-slot fun-pointer-lowtag)
252 (move result new-self)))
254 ;;; KLUDGE: This seems to be some kind of weird override of the way
255 ;;; that the objdef.lisp code would ordinarily set up the slot
256 ;;; accessor. It's inherited from CMU CL, and it works, and naively
257 ;;; deleting it seemed to cause problems, but it's not obvious why
258 ;;; it's done this way. Any ideas? -- WHN 2001-08-02
259 (defknown ((setf %funcallable-instance-fun)) (function function) function
262 ;;; We would have really liked to use a source-transform for this, but
263 ;;; they don't work with SETF functions.
264 ;;; FIXME: Can't we just use DEFSETF or something?
265 (deftransform (setf %funcallable-instance-fun) ((value fin))
266 '(setf (%simple-fun-self fin) value))
268 ;;;; other miscellaneous VOPs
270 (defknown sb!unix::receive-pending-interrupt () (values))
271 (define-vop (sb!unix::receive-pending-interrupt)
273 (:translate sb!unix::receive-pending-interrupt)
275 (inst break pending-interrupt-trap)))
278 (defknown current-thread-offset-sap ((unsigned-byte 32))
279 system-area-pointer (flushable))
282 (define-vop (current-thread-offset-sap)
283 (:results (sap :scs (sap-reg)))
284 (:result-types system-area-pointer)
285 (:translate current-thread-offset-sap)
286 (:args (n :scs (unsigned-reg) :target sap))
287 (:arg-types unsigned-num)
290 (inst fs-segment-prefix)
291 (inst mov sap (make-ea :dword :disp 0 :index n :scale 4))))
295 (inst break halt-trap)))
297 (defknown float-wait () (values))
298 (define-vop (float-wait)
300 (:translate float-wait)
302 (:save-p :compute-only)
304 (note-next-instruction vop :internal-error)
307 ;;;; dynamic vop count collection support
310 (define-vop (count-me)
311 (:args (count-vector :scs (descriptor-reg)))
314 (inst inc (make-ea :dword :base count-vector
315 :disp (- (* (+ vector-data-offset index) n-word-bytes)
316 other-pointer-lowtag)))))