/[cmucl]/src/code/x86-vm.lisp
ViewVC logotype

Contents of /src/code/x86-vm.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations)
Sun Nov 16 13:59:57 1997 UTC (16 years, 5 months ago) by dtc
Branch: MAIN
Changes since 1.9: +1 -20 lines
No longer source transform realpart and imagpart with the
complex-float support.
The realpart and imagpart functions now need to do some type dispatch.
The VOPs are now direct translations of realpart and imagpart;
remove the hack accessor functions.
1 ;;; -*- Mode: LISP; Syntax: Common-Lisp; Base: 10; Package: X86 -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; This code was written as part of the CMU Common Lisp project at
5 ;;; Carnegie Mellon University, and has been placed in the public domain.
6 ;;; If you want to use this code or any part of CMU Common Lisp, please contact
7 ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
8 ;;;
9 (ext:file-comment
10 "$Header: /tiger/var/lib/cvsroots/cmucl/src/code/x86-vm.lisp,v 1.10 1997/11/16 13:59:57 dtc Exp $")
11 ;;;
12 ;;; **********************************************************************
13 ;;;
14 ;;; This file contains the X86 specific runtime stuff.
15 ;;;
16
17 (in-package "X86")
18 (use-package "SYSTEM")
19 (use-package "ALIEN")
20 (use-package "C-CALL")
21 (use-package "UNIX")
22 (use-package "KERNEL")
23
24 (export '(fixup-code-object internal-error-arguments
25 sigcontext-program-counter sigcontext-register
26 sigcontext-float-register sigcontext-floating-point-modes
27 extern-alien-name sanctify-for-execution))
28
29
30 ;;;; The sigcontext structure.
31 ;;;; Add machine specific features to *features*
32
33 (pushnew :x86 *features*)
34
35
36
37 #+linux
38 (def-alien-type nil
39 (struct fpreg
40 (significand (array unsigned-short 4))
41 (exponent unsigned-short)))
42 #+linux
43 (def-alien-type nil
44 (struct fpstate
45 (cw unsigned-long)
46 (sw unsigned-long)
47 (tag unsigned-long)
48 (ipoff unsigned-long)
49 (cssel unsigned-long)
50 (dataoff unsigned-long)
51 (datasel unsigned-long)
52 (fpreg (array (struct fpreg) 8))
53 (status unsigned-long)))
54
55 ;;; for FreeBSD
56 #+freebsd
57 (def-alien-type sigcontext
58 (struct nil
59 (sc-onstack unsigned-int)
60 (sc-mask unsigned-int)
61 (sc-sp unsigned-int)
62 (sc-fp unsigned-int)
63 (sc-isp unsigned-int)
64 (sc-pc unsigned-int)
65 (sc-efl unsigned-int) ; sc_ps
66 (sc-es unsigned-int)
67 (sc-ds unsigned-int)
68 (sc-cs unsigned-int)
69 (sc-ss unsigned-int)
70 (sc-edi unsigned-int)
71 (sc-esi unsigned-int)
72 (sc-ebx unsigned-int)
73 (sc-edx unsigned-int)
74 (sc-ecx unsigned-int)
75 (sc-eax unsigned-int)))
76
77 ;; For Linux...
78 #+linux
79 (def-alien-type sigcontext
80 (struct nil
81 (gs unsigned-short)
82 (__gsh unsigned-short)
83 (fs unsigned-short)
84 (__fsh unsigned-short)
85 (sc-es unsigned-short)
86 (__esh unsigned-short)
87 (sc-ds unsigned-short)
88 (__dsh unsigned-short)
89 (sc-edi unsigned-long)
90 (sc-esi unsigned-long)
91 (ebp unsigned-long)
92 (sc-sp unsigned-long)
93 (sc-ebx unsigned-long)
94 (sc-edx unsigned-long)
95 (sc-ecx unsigned-long)
96 (sc-eax unsigned-long)
97 (trapno unsigned-long)
98 (err unsigned-long)
99 (sc-pc unsigned-long)
100 (sc-cs unsigned-short)
101 (__csh unsigned-short)
102 (sc-efl unsigned-long)
103 (esp_at_signal unsigned-long)
104 (sc-ss unsigned-short)
105 (__ssh unsigned-short)
106 ; (fpstate unsigned-long) ;; fpstate struct pointer
107 (fpstate (* (struct fpstate)))
108 (sc-mask unsigned-long)
109 (cr2 unsigned-long)))
110
111
112
113 ;;;; MACHINE-TYPE and MACHINE-VERSION
114
115 #-cross-compiler
116 (defun machine-type ()
117 "Returns a string describing the type of the local machine."
118 "X86")
119
120
121 #-cross-compiler
122 (defun machine-version ()
123 "Returns a string describing the version of the local machine."
124 "X86")
125
126
127
128 ;;; FIXUP-CODE-OBJECT -- Interface
129 ;;; This gets called by LOAD to resolve newly positioned objects
130 ;;; with things (like code instructions) that have to refer to them.
131
132 ;;; Add a fixup offset to the vector of fixup offsets for the given
133 ;;; code object.
134 ;;;
135 ;;; Counter to measure the storage overhead.
136 (defvar *num-fixups* 0)
137 ;;;
138 (defun add-fixup (code offset)
139 ;; Although this could check for and ignore fixups for code objects
140 ;; in the read-only and static spaces, this should only be the case
141 ;; when *enable-dynamic-space-code* is True.
142 (when lisp::*enable-dynamic-space-code*
143 (incf *num-fixups*)
144 (let ((fixups (code-header-ref code code-constants-offset)))
145 (cond ((typep fixups '(simple-array (unsigned-byte 32) (*)))
146 (let ((new-fixups
147 (adjust-array fixups (1+ (length fixups))
148 :element-type '(unsigned-byte 32))))
149 (setf (aref new-fixups (length fixups)) offset)
150 (setf (code-header-ref code code-constants-offset)
151 new-fixups)))
152 (t
153 (unless (or (eq (get-type fixups) x86:unbound-marker-type)
154 (zerop fixups))
155 (format t "** Init. code FU = ~s~%" fixups))
156 (setf (code-header-ref code code-constants-offset)
157 (make-array 1 :element-type '(unsigned-byte 32)
158 :initial-element offset)))))))
159
160
161 (defun fixup-code-object (code offset fixup kind)
162 (declare (type index offset))
163 (system:without-gcing
164 (let* ((sap (truly-the system-area-pointer (c::code-instructions code)))
165 (obj-start-addr (logand (kernel::get-lisp-obj-address code)
166 #xfffffff8))
167 #+nil (const-start-addr (+ obj-start-addr (* 5 4)))
168 (code-start-addr (c::sap-int (kernel::code-instructions code)))
169 (ncode-words (kernel::code-header-ref code 1))
170 (code-end-addr (+ code-start-addr (* ncode-words 4))))
171 (unless (member kind '(:absolute :relative))
172 (error "Unknown code-object-fixup kind ~s." kind))
173 (ecase kind
174 (:absolute
175 ;; word at sap + offset contains a value to be replaced by
176 ;; adding that value to fixup.
177 (setf (sap-ref-32 sap offset) (+ fixup (sap-ref-32 sap offset)))
178 ;; Record absolute fixups that point within the code object.
179 (when (> code-end-addr (sap-ref-32 sap offset) obj-start-addr)
180 (add-fixup code offset)))
181 (:relative
182 ;; Fixup is the actual address wanted.
183 ;;
184 ;; Record relative fixups that point outside the code object.
185 (when (or (< fixup obj-start-addr) (> fixup code-end-addr))
186 (add-fixup code offset))
187 ;; Replace word with value to add to that loc to get there.
188 (let* ((loc-sap (+ (sap-int sap) offset))
189 (rel-val (- fixup loc-sap 4)))
190 (declare (type (unsigned-byte 32) loc-sap)
191 (type (signed-byte 32) rel-val))
192 (setf (sap-ref-32 sap offset) rel-val)) ))))
193 nil)
194
195
196
197 ;;;; Internal-error-arguments.
198
199 ;;; INTERNAL-ERROR-ARGUMENTS -- interface.
200 ;;;
201 ;;; Given the sigcontext, extract the internal error arguments from the
202 ;;; instruction stream.
203 ;;;
204 (defun internal-error-arguments (scp)
205 (declare (type (alien (* sigcontext)) scp))
206 (with-alien ((scp (* sigcontext) scp))
207 (let ((pc (int-sap (slot scp 'sc-pc))))
208 (declare (type system-area-pointer pc))
209 ;; using INT3 the pc is .. INT3 <here> code length bytes...
210 (let* ((length (sap-ref-8 pc 1))
211 (vector (make-array length :element-type '(unsigned-byte 8))))
212 (declare (type (unsigned-byte 8) length)
213 (type (simple-array (unsigned-byte 8) (*)) vector))
214 (copy-from-system-area pc (* vm:byte-bits 2)
215 vector (* vm:word-bits
216 vm:vector-data-offset)
217 (* length vm:byte-bits))
218 (let* ((index 0)
219 (error-number (c::read-var-integer vector index)))
220 (collect ((sc-offsets))
221 (loop
222 (when (>= index length)
223 (return))
224 (sc-offsets (c::read-var-integer vector index)))
225 (values error-number (sc-offsets))))))))
226
227
228 ;;;; Sigcontext access functions.
229
230 ;;; SIGCONTEXT-PROGRAM-COUNTER -- Interface.
231 ;;;
232 (defun sigcontext-program-counter (scp)
233 (declare (type (alien (* sigcontext)) scp))
234 (with-alien ((scp (* sigcontext) scp))
235 (int-sap (slot scp 'sc-pc))))
236
237 ;;; SIGCONTEXT-REGISTER -- Interface.
238 ;;;
239 ;;; An escape register saves the value of a register for a frame that someone
240 ;;; interrupts.
241 ;;;
242
243 (defun sigcontext-register (scp index)
244 (declare (type (alien (* sigcontext)) scp))
245 (with-alien ((scp (* sigcontext) scp))
246 (case index ; ugly -- I know.
247 (#.eax-offset (slot scp 'sc-eax))
248 (#.ecx-offset (slot scp 'sc-ecx))
249 (#.edx-offset (slot scp 'sc-edx))
250 (#.ebx-offset (slot scp 'sc-ebx))
251 (#.esp-offset (slot scp 'sc-sp))
252 #-linux (#.ebp-offset (slot scp 'sc-fp))
253 #+linux (#.ebp-offset (slot scp 'ebp))
254 (#.esi-offset (slot scp 'sc-esi))
255 (#.edi-offset (slot scp 'sc-edi)))))
256
257
258 (defun %set-sigcontext-register (scp index new)
259 (declare (type (alien (* sigcontext)) scp))
260 (with-alien ((scp (* sigcontext) scp))
261 (case index
262 (#.eax-offset (setf (slot scp 'sc-eax) new))
263 (#.ecx-offset (setf (slot scp 'sc-ecx) new))
264 (#.edx-offset (setf (slot scp 'sc-edx) new))
265 (#.ebx-offset (setf (slot scp 'sc-ebx) new))
266 (#.esp-offset (setf (slot scp 'sc-sp) new))
267 #-linux (#.ebp-offset (setf (slot scp 'sc-fp) new))
268 #+linux (#.ebp-offset (setf (slot scp 'ebp) new))
269 (#.esi-offset (setf (slot scp 'sc-esi) new))
270 (#.edi-offset (setf (slot scp 'sc-edi) new))))
271 new)
272
273 (defsetf sigcontext-register %set-sigcontext-register)
274
275
276 ;;; SIGCONTEXT-FLOAT-REGISTER -- Interface
277 ;;;
278 ;;; Like SIGCONTEXT-REGISTER, but returns the value of a float register.
279 ;;; Format is the type of float to return.
280 ;;; XXX
281 #-linux
282 (defun sigcontext-float-register (scp index format)
283 (declare (type (alien (* sigcontext)) scp))
284 (with-alien ((scp (* sigcontext) scp))
285 ;; fp regs not in sigcontext -- need new vop or c support
286 (let ((sap #+nil (alien-sap (slot scp 'sc-fpregs))))
287 (declare (ignore sap))
288 index
289 (ecase format
290 (single-float 0s0
291 #+nil (system:sap-ref-single sap (* index vm:word-bytes)))
292 (double-float 0d0
293 #+nil(system:sap-ref-double sap (* index vm:word-bytes)))))))
294
295 #+linux
296 (defun sigcontext-float-register (scp index format)
297 (declare (type (alien (* sigcontext)) scp))
298 (with-alien ((scp (* sigcontext) scp))
299 ;; fp regs in sigcontext !!!
300 (let ((reg-sap (alien-sap (deref (slot (deref (slot scp 'fpstate) 0)
301 'fpreg)
302 index))))
303 (ecase format
304 (single-float
305 (system:sap-ref-single reg-sap 0))
306 (double-float
307 (system:sap-ref-double reg-sap 0))))))
308
309 ;;;
310 #-linux
311 (defun %set-sigcontext-float-register (scp index format new-value)
312 (declare (type (alien (* sigcontext)) scp))
313 scp index format new-value
314 #+nil
315 (with-alien ((scp (* sigcontext) scp))
316 (let ((sap (alien-sap (slot scp 'fpregs))))
317 (ecase format
318 (single-float
319 (setf (sap-ref-single sap (* index vm:word-bytes)) new-value))
320 (double-float
321 (setf (sap-ref-double sap (* index vm:word-bytes)) new-value))))))
322 #+linux
323 (defun %set-sigcontext-float-register (scp index format new-value)
324 (declare (type (alien (* sigcontext)) scp))
325 (with-alien ((scp (* sigcontext) scp))
326 (let ((reg-sap (alien-sap (deref (slot (deref (slot scp 'fpstate) 0)
327 'fpreg)
328 index))))
329 (ecase format
330 (single-float
331 (setf (system:sap-ref-single reg-sap 0) new-value))
332 (double-float
333 (setf (system:sap-ref-double reg-sap 0)new-value))))))
334
335 ;;;
336
337 (defsetf sigcontext-float-register %set-sigcontext-float-register)
338
339 ;;; SIGCONTEXT-FLOATING-POINT-MODES -- Interface
340 ;;;
341 ;;; Given a sigcontext pointer, return the floating point modes word in the
342 ;;; same format as returned by FLOATING-POINT-MODES.
343 ;;;
344
345 #+FreeBSD
346 (defun sigcontext-floating-point-modes (scp)
347 (declare (type (alien (* sigcontext)) scp)
348 (ignore scp))
349 ;; This is broken until some future release of FreeBSD!!!
350 (floating-point-modes))
351
352 #+linux
353 (defun sigcontext-floating-point-modes (scp)
354 (declare (type (alien (* sigcontext)) scp))
355 (let ((cw (slot (deref (slot scp 'fpstate) 0) 'cw))
356 (sw (slot (deref (slot scp 'fpstate) 0) 'sw)))
357 ;;(format t "cw = ~4x~%sw = ~4x~%" cw sw)
358 ;; NOT TESTED -- clear sticky bits to clear interrupt condition
359 (setf (slot (deref (slot scp 'fpstate) 0) 'sw) (logandc2 sw #x3f))
360 ;;(format t "new sw = ~x~%" (slot (deref (slot scp 'fpstate) 0) 'sw))
361 ;; simulate floating-point-modes VOP
362 (logior (ash (logand sw #xffff) 16) (logxor (logand cw #xffff) #x3f))))
363
364
365 ;;; EXTERN-ALIEN-NAME -- interface.
366 ;;;
367 ;;; The loader uses this to convert alien names to the form they occure in
368 ;;; the symbol table (for example, prepending an underscore).
369 ;;;
370 (defun extern-alien-name (name)
371 (declare (type simple-string name))
372 name)
373
374 (defun lisp::foreign-symbol-address-aux (name)
375 (multiple-value-bind (value found)
376 (gethash name lisp::*foreign-symbols* 0)
377 (if found
378 value
379 (multiple-value-bind (value found)
380 (gethash
381 (concatenate 'string #+linux "PVE_stub_" #+freebsd "_" name)
382 lisp::*foreign-symbols* 0)
383 (if found
384 value
385 (let ((value (system:alternate-get-global-address name)))
386 (when (zerop value)
387 (error "Unknown foreign symbol: ~S" name))
388 value))))))
389
390
391 ;;; SANCTIFY-FOR-EXECUTION -- Interface.
392 ;;;
393 ;;; Do whatever is necessary to make the given code component executable.
394 ;;; On the sparc, we don't need to do anything, because the i and d caches
395 ;;; are unified.
396 ;;;
397 (defun sanctify-for-execution (component)
398 (declare (ignore component))
399 nil)
400
401 ;;; FLOAT-WAIT
402 ;;;
403 ;;; This is used in error.lisp to insure floating-point exceptions
404 ;;; are properly trapped. The compiler translates this to a VOP.
405 ;;; Note: if you are compiling this from an old version you may need
406 ;;; to disable this until the float-wait VOP is entrenched.
407 (defun float-wait()
408 (float-wait))
409
410 ;;; FLOAT CONSTANTS
411 ;;;
412 ;;; These are used by the FP move-from-{single|double} VOPs
413 ;;; rather than the i387 load constant instructions to avoid
414 ;;; consing in some cases.
415
416 (defvar *fp-constant-0s0* 0s0)
417 (defvar *fp-constant-0d0* 0d0)
418 (defvar *fp-constant-1s0* 1s0)
419 (defvar *fp-constant-1d0* 1d0)
420
421 ;;; Enable/Disable scavenging of the read-only space.
422 (defvar *scavenge-read-only-space*)
423
424 ;;; The current alien stack pointer; saved/restored for non-local
425 ;;; exits.
426 (defvar *alien-stack*)
427
428 ;;;
429 (defun kernel::%instance-set-conditional (object slot test-value new-value)
430 (declare (type instance object)
431 (type index slot))
432 "Atomically compare object's slot value to test-value and if EQ store
433 new-value in the slot. The original value of the slot is returned."
434 (kernel::%instance-set-conditional object slot test-value new-value))

  ViewVC Help
Powered by ViewVC 1.1.5