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-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
204 :disp (- other-pointer-lowtag)))))
206 (define-vop (compute-fun)
207 (:args (code :scs (descriptor-reg) :to (:result 0))
208 (offset :scs (signed-reg unsigned-reg) :to (:result 0)))
209 (:arg-types * positive-fixnum)
210 (:results (func :scs (descriptor-reg) :from (:argument 0)))
212 (loadw func code 0 other-pointer-lowtag)
213 (inst shr func n-widetag-bits)
215 (make-ea :byte :base offset :index func
217 :disp (- fun-pointer-lowtag other-pointer-lowtag)))
218 (inst add func code)))
220 (define-vop (%simple-fun-self)
222 (:translate %simple-fun-self)
223 (:args (function :scs (descriptor-reg)))
224 (:results (result :scs (descriptor-reg)))
226 (loadw result function simple-fun-self-slot fun-pointer-lowtag)
228 (make-ea :byte :base result
229 :disp (- fun-pointer-lowtag
230 (* simple-fun-code-offset n-word-bytes))))))
232 ;;; The closure function slot is a pointer to raw code on X86 instead
233 ;;; of a pointer to the code function object itself. This VOP is used
234 ;;; to reference the function object given the closure object.
235 (define-source-transform %closure-fun (closure)
236 `(%simple-fun-self ,closure))
238 (define-source-transform %funcallable-instance-fun (fin)
239 `(%simple-fun-self ,fin))
241 (define-vop (%set-fun-self)
243 (:translate (setf %simple-fun-self))
244 (:args (new-self :scs (descriptor-reg) :target result :to :result)
245 (function :scs (descriptor-reg) :to :result))
246 (:temporary (:sc any-reg :from (:argument 0) :to :result) temp)
247 (:results (result :scs (descriptor-reg)))
250 (make-ea :byte :base new-self
251 :disp (- (ash simple-fun-code-offset word-shift)
252 fun-pointer-lowtag)))
253 (storew temp function simple-fun-self-slot fun-pointer-lowtag)
254 (move result new-self)))
256 ;;; KLUDGE: This seems to be some kind of weird override of the way
257 ;;; that the objdef.lisp code would ordinarily set up the slot
258 ;;; accessor. It's inherited from CMU CL, and it works, and naively
259 ;;; deleting it seemed to cause problems, but it's not obvious why
260 ;;; it's done this way. Any ideas? -- WHN 2001-08-02
261 (defknown ((setf %funcallable-instance-fun)) (function function) function
264 ;;; We would have really liked to use a source-transform for this, but
265 ;;; they don't work with SETF functions.
266 ;;; FIXME: Can't we just use DEFSETF or something?
267 (deftransform (setf %funcallable-instance-fun) ((value fin))
268 '(setf (%simple-fun-self fin) value))
270 ;;;; other miscellaneous VOPs
272 (defknown sb!unix::receive-pending-interrupt () (values))
273 (define-vop (sb!unix::receive-pending-interrupt)
275 (:translate sb!unix::receive-pending-interrupt)
277 (inst break pending-interrupt-trap)))
280 (defknown current-thread-offset-sap ((unsigned-byte 32))
281 system-area-pointer (flushable))
284 (define-vop (current-thread-offset-sap)
285 (:results (sap :scs (sap-reg)))
286 (:result-types system-area-pointer)
287 (:translate current-thread-offset-sap)
288 (:args (n :scs (unsigned-reg) :target sap))
289 (:arg-types unsigned-num)
292 (inst fs-segment-prefix)
293 (inst mov sap (make-ea :dword :disp 0 :index n :scale 4))))
297 (inst break halt-trap)))
299 (defknown float-wait () (values))
300 (define-vop (float-wait)
302 (:translate float-wait)
304 (:save-p :compute-only)
306 (note-next-instruction vop :internal-error)
309 ;;;; dynamic vop count collection support
312 (define-vop (count-me)
313 (:args (count-vector :scs (descriptor-reg)))
316 (inst inc (make-ea :qword :base count-vector
317 :disp (- (* (+ vector-data-offset index) n-word-bytes)
318 other-pointer-lowtag)))))