[5d4902]: src / compiler / x86 / system.lisp Maximize Restore History

Download this file

system.lisp    316 lines (275 with data), 10.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
;;;; x86 VM definitions of various system hacking operations
;;;; This software is part of the SBCL system. See the README file for
;;;; more information.
;;;;
;;;; This software is derived from the CMU CL system, which was
;;;; written at Carnegie Mellon University and released into the
;;;; public domain. The software is in the public domain and is
;;;; provided with absolutely no warranty. See the COPYING and CREDITS
;;;; files for more information.
(in-package "SB!VM")
;;;; type frobbing VOPs
(define-vop (lowtag-of)
(:translate lowtag-of)
(:policy :fast-safe)
(:args (object :scs (any-reg descriptor-reg control-stack)
:target result))
(:results (result :scs (unsigned-reg)))
(:result-types positive-fixnum)
(:generator 1
(move result object)
(inst and result lowtag-mask)))
(define-vop (widetag-of)
(:translate widetag-of)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg)))
(:temporary (:sc unsigned-reg :offset eax-offset :to (:result 0)) eax)
(:results (result :scs (unsigned-reg)))
(:result-types positive-fixnum)
(:generator 6
(inst mov eax object)
(inst and al-tn lowtag-mask)
(inst cmp al-tn other-pointer-lowtag)
(inst jmp :e other-ptr)
(inst cmp al-tn fun-pointer-lowtag)
(inst jmp :e function-ptr)
;; Pick off structures and list pointers.
(inst test al-tn 1)
(inst jmp :ne done)
;; Pick off fixnums.
(inst and al-tn 3)
(inst jmp :e done)
;; must be an other immediate
(inst mov eax object)
(inst jmp done)
FUNCTION-PTR
(load-type al-tn object (- fun-pointer-lowtag))
(inst jmp done)
OTHER-PTR
(load-type al-tn object (- other-pointer-lowtag))
DONE
(inst movzx result al-tn)))
(define-vop (fun-subtype)
(:translate fun-subtype)
(:policy :fast-safe)
(:args (function :scs (descriptor-reg)))
(:temporary (:sc byte-reg :from (:eval 0) :to (:eval 1)) temp)
(:results (result :scs (unsigned-reg)))
(:result-types positive-fixnum)
(:generator 6
(load-type temp function (- fun-pointer-lowtag))
(inst movzx result temp)))
(define-vop (set-fun-subtype)
(:translate (setf fun-subtype))
(:policy :fast-safe)
(:args (type :scs (unsigned-reg) :target eax)
(function :scs (descriptor-reg)))
(:arg-types positive-fixnum *)
(:temporary (:sc unsigned-reg :offset eax-offset :from (:argument 0)
:to (:result 0) :target result)
eax)
(:results (result :scs (unsigned-reg)))
(:result-types positive-fixnum)
(:generator 6
(move eax type)
(inst mov
(make-ea :byte :base function :disp (- fun-pointer-lowtag))
al-tn)
(move result eax)))
(define-vop (get-header-data)
(:translate get-header-data)
(:policy :fast-safe)
(:args (x :scs (descriptor-reg)))
(:results (res :scs (unsigned-reg)))
(:result-types positive-fixnum)
(:generator 6
(loadw res x 0 other-pointer-lowtag)
(inst shr res n-widetag-bits)))
(define-vop (get-closure-length)
(:translate get-closure-length)
(:policy :fast-safe)
(:args (x :scs (descriptor-reg)))
(:results (res :scs (unsigned-reg)))
(:result-types positive-fixnum)
(:generator 6
(loadw res x 0 fun-pointer-lowtag)
(inst shr res n-widetag-bits)))
(define-vop (set-header-data)
(:translate set-header-data)
(:policy :fast-safe)
(:args (x :scs (descriptor-reg) :target res :to (:result 0))
(data :scs (any-reg) :target eax))
(:arg-types * positive-fixnum)
(:results (res :scs (descriptor-reg)))
(:temporary (:sc unsigned-reg :offset eax-offset
:from (:argument 1) :to (:result 0)) eax)
(:generator 6
(move eax data)
(inst shl eax (- n-widetag-bits 2))
(inst mov al-tn (make-ea :byte :base x :disp (- other-pointer-lowtag)))
(storew eax x 0 other-pointer-lowtag)
(move res x)))
(define-vop (make-fixnum)
(:args (ptr :scs (any-reg descriptor-reg) :target res))
(:results (res :scs (any-reg descriptor-reg)))
(:generator 1
;; Some code (the hash table code) depends on this returning a
;; positive number so make sure it does.
(move res ptr)
(inst shl res 3)
(inst shr res 1)))
(define-vop (make-other-immediate-type)
(:args (val :scs (any-reg descriptor-reg) :target res)
(type :scs (unsigned-reg immediate)))
(:results (res :scs (any-reg descriptor-reg) :from (:argument 0)))
(:generator 2
(move res val)
(inst shl res (- n-widetag-bits 2))
(inst or res (sc-case type
(unsigned-reg type)
(immediate (tn-value type))))))
;;;; allocation
(define-vop (dynamic-space-free-pointer)
(:results (int :scs (sap-reg)))
(:result-types system-area-pointer)
(:translate dynamic-space-free-pointer)
(:policy :fast-safe)
(:generator 1
(load-symbol-value int *allocation-pointer*)))
(define-vop (binding-stack-pointer-sap)
(:results (int :scs (sap-reg)))
(:result-types system-area-pointer)
(:translate binding-stack-pointer-sap)
(:policy :fast-safe)
(:generator 1
(load-tl-symbol-value int *binding-stack-pointer*)))
(defknown (setf binding-stack-pointer-sap)
(system-area-pointer) system-area-pointer ())
(define-vop (set-binding-stack-pointer-sap)
(:args (new-value :scs (sap-reg) :target int))
(:arg-types system-area-pointer)
(:results (int :scs (sap-reg)))
(:result-types system-area-pointer)
(:temporary (:sc any-reg) temp)
(:translate (setf binding-stack-pointer-sap))
(:policy :fast-safe)
(:generator 1
(store-tl-symbol-value new-value *binding-stack-pointer* temp)
(move int new-value)))
(define-vop (control-stack-pointer-sap)
(:results (int :scs (sap-reg)))
(:result-types system-area-pointer)
(:translate control-stack-pointer-sap)
(:policy :fast-safe)
(:generator 1
(move int esp-tn)))
;;;; code object frobbing
(define-vop (code-instructions)
(:translate code-instructions)
(:policy :fast-safe)
(:args (code :scs (descriptor-reg) :to (:result 0)))
(:results (sap :scs (sap-reg) :from (:argument 0)))
(:result-types system-area-pointer)
(:generator 10
(loadw sap code 0 other-pointer-lowtag)
(inst shr sap n-widetag-bits)
(inst lea sap (make-ea :byte :base code :index sap :scale 4
:disp (- other-pointer-lowtag)))))
(define-vop (compute-fun)
(:args (code :scs (descriptor-reg) :to (:result 0))
(offset :scs (signed-reg unsigned-reg) :to (:result 0)))
(:arg-types * positive-fixnum)
(:results (func :scs (descriptor-reg) :from (:argument 0)))
(:generator 10
(loadw func code 0 other-pointer-lowtag)
(inst shr func n-widetag-bits)
(inst lea func
(make-ea :byte :base offset :index func :scale 4
:disp (- fun-pointer-lowtag other-pointer-lowtag)))
(inst add func code)))
(define-vop (%simple-fun-self)
(:policy :fast-safe)
(:translate %simple-fun-self)
(:args (function :scs (descriptor-reg)))
(:results (result :scs (descriptor-reg)))
(:generator 3
(loadw result function simple-fun-self-slot fun-pointer-lowtag)
(inst lea result
(make-ea :byte :base result
:disp (- fun-pointer-lowtag
(* simple-fun-code-offset n-word-bytes))))))
;;; The closure function slot is a pointer to raw code on X86 instead
;;; of a pointer to the code function object itself. This VOP is used
;;; to reference the function object given the closure object.
(define-source-transform %closure-fun (closure)
`(%simple-fun-self ,closure))
(define-source-transform %funcallable-instance-fun (fin)
`(%simple-fun-self ,fin))
(define-vop (%set-fun-self)
(:policy :fast-safe)
(:translate (setf %simple-fun-self))
(:args (new-self :scs (descriptor-reg) :target result :to :result)
(function :scs (descriptor-reg) :to :result))
(:temporary (:sc any-reg :from (:argument 0) :to :result) temp)
(:results (result :scs (descriptor-reg)))
(:generator 3
(inst lea temp
(make-ea :byte :base new-self
:disp (- (ash simple-fun-code-offset word-shift)
fun-pointer-lowtag)))
(storew temp function simple-fun-self-slot fun-pointer-lowtag)
(move result new-self)))
;;; KLUDGE: This seems to be some kind of weird override of the way
;;; that the objdef.lisp code would ordinarily set up the slot
;;; accessor. It's inherited from CMU CL, and it works, and naively
;;; deleting it seemed to cause problems, but it's not obvious why
;;; it's done this way. Any ideas? -- WHN 2001-08-02
(defknown ((setf %funcallable-instance-fun)) (function function) function
(unsafe))
;;; CMU CL comment:
;;; We would have really liked to use a source-transform for this, but
;;; they don't work with SETF functions.
;;; FIXME: Can't we just use DEFSETF or something?
(deftransform (setf %funcallable-instance-fun) ((value fin))
'(setf (%simple-fun-self fin) value))
;;;; other miscellaneous VOPs
(defknown sb!unix::receive-pending-interrupt () (values))
(define-vop (sb!unix::receive-pending-interrupt)
(:policy :fast-safe)
(:translate sb!unix::receive-pending-interrupt)
(:generator 1
(inst break pending-interrupt-trap)))
(defknown current-thread-offset-sap ((unsigned-byte 32))
system-area-pointer (flushable))
(define-vop (current-thread-offset-sap)
(:results (sap :scs (sap-reg)))
(:result-types system-area-pointer)
(:translate current-thread-offset-sap)
(:args (n :scs (unsigned-reg) :target sap))
(:arg-types unsigned-num)
(:policy :fast-safe)
(:generator 2
(inst gs-segment-prefix)
(inst mov sap (make-ea :dword :disp 0
:index n :scale 4))))
(define-vop (halt)
(:generator 1
(inst break halt-trap)))
(defknown float-wait () (values))
(define-vop (float-wait)
(:policy :fast-safe)
(:translate float-wait)
(:vop-var vop)
(:save-p :compute-only)
(:generator 1
(note-next-instruction vop :internal-error)
(inst wait)))
;;;; dynamic vop count collection support
#!+sb-dyncount
(define-vop (count-me)
(:args (count-vector :scs (descriptor-reg)))
(:info index)
(:generator 0
(inst inc (make-ea :dword :base count-vector
:disp (- (* (+ vector-data-offset index) n-word-bytes)
other-pointer-lowtag)))))