/[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.37 - (show annotations)
Tue Jun 22 15:35:23 2010 UTC (3 years, 9 months ago) by rtoy
Branch: MAIN
CVS Tags: sparc-tramp-assem-base, release-20b-pre1, sparc-tramp-assem-2010-07-19, snapshot-2010-07, snapshot-2010-08
Branch point for: RELEASE-20B-BRANCH, sparc-tramp-assem-branch
Changes since 1.36: +1 -12 lines
Revert the previous change to fix debug:arg/trace issue.  Instead, use
Carl's suggestion and define new SC numbers for the xmm registers
instead of overloading the x87 fpu registers and the xmm register
SC's.

bootfiles/20a/boot-2010-06-cross-x86.lisp:
o New file needed for cross-compiling this change.

code/x86-vm.lisp:
o Revert previous change.

compiler/x86/sse2-c-call.lisp:
o Use xmm0-tn instead of fr0-tn.  No functional change, but makes the
  code more readable.

compiler/x86/vm.lisp:
o Increase the number of float registers from 8 to 16 (8 more for SSE2
  registers).
o Define new xmm<n> registers
o Update the locations with the new sse2 SC locations for single-reg,
  double-reg, double-double-reg, complex-single-reg,
  complex-double-reg, and complex-double-double-reg storage classes.

lisp/Darwin-os.c:
o Revert previous change.
o Update os_sigcontext_fpu_reg to support the xmm registers.

lisp/Linux-os.c:
o Update os_sigcontext_fpu_reg to support the xmm registers.
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.37 2010/06/22 15:35:23 rtoy Exp $")
11 ;;;
12 ;;; **********************************************************************
13 ;;;
14 ;;; This file contains the X86 specific runtime stuff.
15 ;;;
16 ;;; Code movement fixups by Douglas T. Crosher, 1997.
17 ;;; Thread support by Douglas T. Crosher, 1999.
18 ;;;
19
20 (in-package "X86")
21 (use-package "SYSTEM")
22 (use-package "ALIEN")
23 (use-package "C-CALL")
24 (use-package "UNIX")
25 (use-package "KERNEL")
26
27 (intl:textdomain "cmucl-x86-vm")
28
29 (export '(fixup-code-object internal-error-arguments
30 sigcontext-program-counter sigcontext-register
31 sigcontext-float-register sigcontext-floating-point-modes
32 extern-alien-name sanctify-for-execution))
33
34 #+complex-fp-vops
35 (sys:register-lisp-feature :complex-fp-vops)
36
37 #+(or x87 (not :sse2))
38 (sys:register-lisp-feature :x87)
39 #+sse2
40 (progn
41 (setf *features* (delete :x87 *features*))
42 (sys:register-lisp-feature :sse2))
43
44
45 ;;;; The sigcontext structure.
46
47 (def-alien-type sigcontext system-area-pointer)
48
49 ;;;; Add machine specific features to *features*
50
51 (pushnew :x86 *features*)
52
53
54 ;;;; MACHINE-TYPE and MACHINE-VERSION
55
56 #-cross-compiler
57 (defun machine-type ()
58 _N"Returns a string describing the type of the local machine."
59 "X86")
60
61
62 #-cross-compiler
63 (defun machine-version ()
64 _N"Returns a string describing the version of the local machine."
65 "X86")
66
67
68
69 ;;; Fixup-Code-Object -- Interface
70 ;;;
71 ;;; This gets called by LOAD to resolve newly positioned objects
72 ;;; with things (like code instructions) that have to refer to them.
73 ;;;
74 ;;; Add a fixup offset to the vector of fixup offsets for the given
75 ;;; code object.
76 ;;;
77 ;;; Counter to measure the storage overhead.
78 (defvar *num-fixups* 0)
79 ;;; XXX
80 (defun fixup-code-object (code offset fixup kind)
81 (declare (type index offset))
82 (flet ((add-fixup (code offset)
83 ;; Although this could check for and ignore fixups for code
84 ;; objects in the read-only and static spaces, this should
85 ;; only be the case when *enable-dynamic-space-code* is
86 ;; True.
87 (when lisp::*enable-dynamic-space-code*
88 (incf *num-fixups*)
89 (let ((fixups (code-header-ref code code-constants-offset)))
90 (cond ((typep fixups '(simple-array (unsigned-byte 32) (*)))
91 (let ((new-fixups
92 (adjust-array fixups (1+ (length fixups))
93 :element-type '(unsigned-byte 32))))
94 (setf (aref new-fixups (length fixups)) offset)
95 (setf (code-header-ref code code-constants-offset)
96 new-fixups)))
97 (t
98 (unless (or (eq (get-type fixups) vm:unbound-marker-type)
99 (zerop fixups))
100 (format t "** Init. code FU = ~s~%" fixups))
101 (setf (code-header-ref code code-constants-offset)
102 (make-array 1 :element-type '(unsigned-byte 32)
103 :initial-element offset))))))))
104 (system:without-gcing
105 (let* ((sap (truly-the system-area-pointer
106 (kernel:code-instructions code)))
107 (obj-start-addr (logand (kernel:get-lisp-obj-address code)
108 #xfffffff8))
109 #+nil (const-start-addr (+ obj-start-addr (* 5 4)))
110 (code-start-addr (sys:sap-int (kernel:code-instructions code)))
111 (ncode-words (kernel:code-header-ref code 1))
112 (code-end-addr (+ code-start-addr (* ncode-words 4))))
113 (unless (member kind '(:absolute :relative))
114 (error (intl:gettext "Unknown code-object-fixup kind ~s.") kind))
115 (ecase kind
116 (:absolute
117 ;; Word at sap + offset contains a value to be replaced by
118 ;; adding that value to fixup.
119 (setf (sap-ref-32 sap offset) (+ fixup (sap-ref-32 sap offset)))
120 ;; Record absolute fixups that point within the code object.
121 (when (> code-end-addr (sap-ref-32 sap offset) obj-start-addr)
122 (add-fixup code offset)))
123 (:relative
124 ;; Fixup is the actual address wanted.
125 ;;
126 ;; Record relative fixups that point outside the code
127 ;; object.
128 (when (or (< fixup obj-start-addr) (> fixup code-end-addr))
129 (add-fixup code offset))
130 ;; Replace word with value to add to that loc to get there.
131 (let* ((loc-sap (+ (sap-int sap) offset))
132 (rel-val (- fixup loc-sap 4)))
133 (declare (type (unsigned-byte 32) loc-sap)
134 (type (signed-byte 32) rel-val))
135 (setf (signed-sap-ref-32 sap offset) rel-val))))))
136 nil))
137
138 ;;; Do-Load-Time-Code-Fixups
139 ;;;
140 ;;; Add a code fixup to a code object generated by new-genesis. The
141 ;;; fixup has already been applied, it's just a matter of placing the
142 ;;; fixup in the code's fixup vector if necessary.
143 ;;;
144 #+gencgc
145 (defun do-load-time-code-fixup (code offset fixup kind)
146 (flet ((add-load-time-code-fixup (code offset)
147 (let ((fixups (code-header-ref code vm:code-constants-offset)))
148 (cond ((typep fixups '(simple-array (unsigned-byte 32) (*)))
149 (let ((new-fixups
150 (adjust-array fixups (1+ (length fixups))
151 :element-type '(unsigned-byte 32))))
152 (setf (aref new-fixups (length fixups)) offset)
153 (setf (code-header-ref code vm:code-constants-offset)
154 new-fixups)))
155 (t
156 (unless (or (eq (get-type fixups) vm:unbound-marker-type)
157 (zerop fixups))
158 (%primitive print "** Init. code FU"))
159 (setf (code-header-ref code vm:code-constants-offset)
160 (make-array 1 :element-type '(unsigned-byte 32)
161 :initial-element offset)))))))
162 (let* ((sap (truly-the system-area-pointer
163 (kernel:code-instructions code)))
164 (obj-start-addr
165 (logand (kernel:get-lisp-obj-address code) #xfffffff8))
166 (code-start-addr (sys:sap-int (kernel:code-instructions code)))
167 (ncode-words (kernel:code-header-ref code 1))
168 (code-end-addr (+ code-start-addr (* ncode-words 4))))
169 (ecase kind
170 (:absolute
171 ;; Record absolute fixups that point within the
172 ;; code object.
173 (when (> code-end-addr (sap-ref-32 sap offset) obj-start-addr)
174 (add-load-time-code-fixup code offset)))
175 (:relative
176 ;; Record relative fixups that point outside the
177 ;; code object.
178 (when (or (< fixup obj-start-addr) (> fixup code-end-addr))
179 (add-load-time-code-fixup code offset)))))))
180
181
182 ;;;; Internal-error-arguments.
183
184 ;;; INTERNAL-ERROR-ARGUMENTS -- interface.
185 ;;;
186 ;;; Given the sigcontext, extract the internal error arguments from the
187 ;;; instruction stream.
188 ;;;
189 (defun internal-error-arguments (scp)
190 (declare (type (alien (* sigcontext)) scp))
191 (with-alien ((scp (* sigcontext) scp))
192 (let ((pc (sigcontext-program-counter scp)))
193 (declare (type system-area-pointer pc))
194 ;; using INT3 the pc is .. INT3 <here> code length bytes...
195 (let* ((length (sap-ref-8 pc 1))
196 (vector (make-array length :element-type '(unsigned-byte 8))))
197 (declare (type (unsigned-byte 8) length)
198 (type (simple-array (unsigned-byte 8) (*)) vector))
199 (copy-from-system-area pc (* vm:byte-bits 2)
200 vector (* vm:word-bits
201 vm:vector-data-offset)
202 (* length vm:byte-bits))
203 (let* ((index 0)
204 (error-number (c::read-var-integer vector index)))
205 (collect ((sc-offsets))
206 (loop
207 (when (>= index length)
208 (return))
209 (sc-offsets (c::read-var-integer vector index)))
210 (values error-number (sc-offsets))))))))
211
212
213 ;;;; Sigcontext access functions.
214
215 ;;; SIGCONTEXT-PROGRAM-COUNTER -- Interface.
216 ;;;
217 (defun sigcontext-program-counter (scp)
218 (declare (type (alien (* sigcontext)) scp))
219 (let ((fn (extern-alien "os_sigcontext_pc"
220 (function system-area-pointer
221 (* sigcontext)))))
222 (sap-ref-sap (alien-funcall fn scp) 0)))
223
224 ;;; SIGCONTEXT-REGISTER -- Interface.
225 ;;;
226 ;;; An escape register saves the value of a register for a frame that someone
227 ;;; interrupts.
228 ;;;
229 (defun sigcontext-register (scp index)
230 (declare (type (alien (* sigcontext)) scp))
231 (let ((fn (extern-alien "os_sigcontext_reg"
232 (function system-area-pointer
233 (* sigcontext)
234 (integer 32)))))
235 (sap-ref-32 (alien-funcall fn scp index) 0)))
236
237 (defun %set-sigcontext-register (scp index new)
238 (declare (type (alien (* sigcontext)) scp))
239 (let ((fn (extern-alien "os_sigcontext_reg"
240 (function system-area-pointer
241 (* sigcontext)
242 (integer 32)))))
243 (setf (sap-ref-32 (alien-funcall fn scp index) 0) new)))
244
245 (defsetf sigcontext-register %set-sigcontext-register)
246
247
248 ;;; SIGCONTEXT-FLOAT-REGISTER -- Interface
249 ;;;
250 ;;; Like SIGCONTEXT-REGISTER, but returns the value of a float register.
251 ;;; Format is the type of float to return.
252 ;;;
253 (defun sigcontext-float-register (scp index format)
254 (declare (type (alien (* sigcontext)) scp))
255 (let ((fn (extern-alien "os_sigcontext_fpu_reg"
256 (function system-area-pointer
257 (* sigcontext)
258 (integer 32)))))
259 (coerce (sap-ref-long (alien-funcall fn scp index) 0) format)))
260
261 ;;;
262 (defun %set-sigcontext-float-register (scp index format new)
263 (declare (type (alien (* sigcontext)) scp))
264 (let ((fn (extern-alien "os_sigcontext_fpu_reg"
265 (function system-area-pointer
266 (* sigcontext)
267 (integer 32)))))
268 (let* ((sap (alien-funcall fn scp index))
269 (result (setf (sap-ref-long sap 0) (coerce new 'long-float))))
270 (coerce result format))))
271 ;;;
272 (defsetf sigcontext-float-register %set-sigcontext-float-register)
273
274 ;;; SIGCONTEXT-FLOATING-POINT-MODES -- Interface
275 ;;;
276 ;;; Given a sigcontext pointer, return the floating point modes word in the
277 ;;; same format as returned by FLOATING-POINT-MODES.
278 ;;;
279 (defun sigcontext-floating-point-modes (scp)
280 (declare (type (alien (* sigcontext)) scp))
281 (let ((fn (extern-alien "os_sigcontext_fpu_modes"
282 (function (integer 32)
283 (* sigcontext)))))
284 (alien-funcall fn scp)))
285
286 (defun %set-sigcontext-floating-point-modes (scp new-mode)
287 (declare (type (alien (* sigcontext)) scp))
288 (let ((fn (extern-alien "os_set_sigcontext_fpu_modes"
289 (function (integer 32)
290 (* sigcontext)
291 c-call:unsigned-int))))
292 (alien-funcall fn scp new-mode)
293 new-mode))
294
295 (defsetf sigcontext-floating-point-modes %set-sigcontext-floating-point-modes)
296
297
298 ;;; EXTERN-ALIEN-NAME -- interface.
299 ;;;
300 ;;; The loader uses this to convert alien names to the form they occure in
301 ;;; the symbol table (for example, prepending an underscore).
302 ;;;
303 (defun extern-alien-name (name)
304 (declare (type simple-string name))
305 name)
306
307 #+(and (or linux (and freebsd elf)) (not linkage-table))
308 (defun lisp::foreign-symbol-address-aux (name flavor)
309 (declare (ignore flavor))
310 (multiple-value-bind (value found)
311 (gethash name lisp::*foreign-symbols* 0)
312 (if found
313 value
314 (multiple-value-bind (value found)
315 (gethash
316 (concatenate 'string "PVE_stub_" name)
317 lisp::*foreign-symbols* 0)
318 (if found
319 value
320 (let ((value (system:alternate-get-global-address name)))
321 (when (zerop value)
322 (error (intl:gettext "Unknown foreign symbol: ~S") name))
323 value))))))
324
325
326
327 ;;; SANCTIFY-FOR-EXECUTION -- Interface.
328 ;;;
329 ;;; Do whatever is necessary to make the given code component
330 ;;; executable - nothing on the x86.
331 ;;;
332 (defun sanctify-for-execution (component)
333 (declare (ignore component))
334 nil)
335
336 ;;; FLOAT-WAIT
337 ;;;
338 ;;; This is used in error.lisp to insure floating-point exceptions
339 ;;; are properly trapped. The compiler translates this to a VOP.
340 ;;;
341 (defun float-wait()
342 (float-wait))
343
344 ;;; FLOAT CONSTANTS
345 ;;;
346 ;;; These are used by the FP move-from-{single|double} VOPs rather
347 ;;; than the i387 load constant instructions to avoid consing in some
348 ;;; cases. Note these are initialise by genesis as they are needed
349 ;;; early.
350 ;;;
351 (defvar *fp-constant-0s0*)
352 (defvar *fp-constant-1s0*)
353 (defvar *fp-constant-0d0*)
354 (defvar *fp-constant-1d0*)
355 ;;; The long-float constants.
356 (defvar *fp-constant-0l0*)
357 (defvar *fp-constant-1l0*)
358 (defvar *fp-constant-pi*)
359 (defvar *fp-constant-l2t*)
360 (defvar *fp-constant-l2e*)
361 (defvar *fp-constant-lg2*)
362 (defvar *fp-constant-ln2*)
363
364 ;;; Enable/Disable scavenging of the read-only space.
365 (defvar *scavenge-read-only-space* nil)
366
367 ;;; The current alien stack pointer; saved/restored for non-local
368 ;;; exits.
369 (defvar *alien-stack*)
370
371 ;;; Support for the MT19937 random number generator. The update
372 ;;; function is implemented as an assembly routine. This definition is
373 ;;; transformed to a call to this routine allowing its use in byte
374 ;;; compiled code.
375 ;;;
376 (defun random-mt19937 (state)
377 (declare (type (simple-array (unsigned-byte 32) (627)) state))
378 (random-mt19937 state))
379
380
381 ;;;; Useful definitions for writing thread safe code.
382
383 (in-package "KERNEL")
384
385 (export '(atomic-push-symbol-value atomic-pop-symbol-value
386 atomic-pusha atomic-pushd atomic-push-vector))
387
388 (defun %instance-set-conditional (object slot test-value new-value)
389 (declare (type instance object)
390 (type index slot))
391 "Atomically compare object's slot value to test-value and if EQ store
392 new-value in the slot. The original value of the slot is returned."
393 (%instance-set-conditional object slot test-value new-value))
394
395 (defun set-symbol-value-conditional (symbol test-value new-value)
396 (declare (type symbol symbol))
397 "Atomically compare symbol's value to test-value and if EQ store
398 new-value in symbol's value slot and return the original value."
399 (set-symbol-value-conditional symbol test-value new-value))
400
401 (defun rplaca-conditional (cons test-value new-value)
402 (declare (type cons cons))
403 "Atomically compare the car of CONS to test-value and if EQ store
404 new-value its car and return the original value."
405 (rplaca-conditional cons test-value new-value))
406
407 (defun rplacd-conditional (cons test-value new-value)
408 (declare (type cons cons))
409 "Atomically compare the cdr of CONS to test-value and if EQ store
410 new-value its cdr and return the original value."
411 (rplacd-conditional cons test-value new-value))
412
413 (defun data-vector-set-conditional (vector index test-value new-value)
414 (declare (type simple-vector vector))
415 "Atomically compare an element of vector to test-value and if EQ store
416 new-value the element and return the original value."
417 (data-vector-set-conditional vector index test-value new-value))
418
419 (defmacro atomic-push-symbol-value (val symbol)
420 "Thread safe push of val onto the list in the symbol global value."
421 (ext:once-only ((n-val val))
422 (let ((new-list (gensym))
423 (old-list (gensym)))
424 `(let ((,new-list (cons ,n-val nil)))
425 (loop
426 (let ((,old-list ,symbol))
427 (setf (cdr ,new-list) ,old-list)
428 (when (eq (set-symbol-value-conditional
429 ',symbol ,old-list ,new-list)
430 ,old-list)
431 (return ,new-list))))))))
432
433 (defmacro atomic-pop-symbol-value (symbol)
434 "Thread safe pop from the list in the symbol global value."
435 (let ((new-list (gensym))
436 (old-list (gensym)))
437 `(loop
438 (let* ((,old-list ,symbol)
439 (,new-list (cdr ,old-list)))
440 (when (eq (set-symbol-value-conditional
441 ',symbol ,old-list ,new-list)
442 ,old-list)
443 (return (car ,old-list)))))))
444
445 (defmacro atomic-pusha (val cons)
446 "Thread safe push of val onto the list in the car of cons."
447 (once-only ((n-val val)
448 (n-cons cons))
449 (let ((new-list (gensym))
450 (old-list (gensym)))
451 `(let ((,new-list (cons ,n-val nil)))
452 (loop
453 (let ((,old-list (car ,n-cons)))
454 (setf (cdr ,new-list) ,old-list)
455 (when (eq (rplaca-conditional ,n-cons ,old-list ,new-list)
456 ,old-list)
457 (return ,new-list))))))))
458
459 (defmacro atomic-pushd (val cons)
460 "Thread safe push of val onto the list in the cdr of cons."
461 (once-only ((n-val val)
462 (n-cons cons))
463 (let ((new-list (gensym))
464 (old-list (gensym)))
465 `(let ((,new-list (cons ,n-val nil)))
466 (loop
467 (let ((,old-list (cdr ,n-cons)))
468 (setf (cdr ,new-list) ,old-list)
469 (when (eq (rplacd-conditional ,n-cons ,old-list ,new-list)
470 ,old-list)
471 (return ,new-list))))))))
472
473 (defmacro atomic-push-vector (val vect index)
474 "Thread safe push of val onto the list in the vector element."
475 (once-only ((n-val val)
476 (n-vect vect)
477 (n-index index))
478 (let ((new-list (gensym))
479 (old-list (gensym)))
480 `(let ((,new-list (cons ,n-val nil)))
481 (loop
482 (let ((,old-list (svref ,n-vect ,n-index)))
483 (setf (cdr ,new-list) ,old-list)
484 (when (eq (data-vector-set-conditional
485 ,n-vect ,n-index ,old-list ,new-list)
486 ,old-list)
487 (return ,new-list))))))))
488
489 #+linkage-table
490 (progn
491 (defun lisp::foreign-symbol-address-aux (name flavor)
492 (let ((entry-num (lisp::register-foreign-linkage name flavor)))
493 (+ #.vm:target-foreign-linkage-space-start
494 (* entry-num vm:target-foreign-linkage-entry-size))))
495
496 (defun lisp::find-foreign-symbol (addr)
497 (declare (type (unsigned-byte 32) addr))
498 (when (>= addr vm:target-foreign-linkage-space-start)
499 (let ((entry (/ (- addr vm:target-foreign-linkage-space-start)
500 vm:target-foreign-linkage-entry-size)))
501 (when (< entry (lisp::foreign-linkage-symbols))
502 (lisp::foreign-linkage-entry entry)))))
503 )

  ViewVC Help
Powered by ViewVC 1.1.5