Simpify (X - (X & mask)) to (X & ~mask)
[sbcl.git] / src / code / alpha-vm.lisp
blob2bab3665be831b0ca38674bee233850038498ffb
1 ;;;; Alpha-specific implementation stuff
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
12 (in-package "SB!VM")
14 #-sb-xc-host
15 (defun machine-type ()
16 "Return a string describing the type of the local machine."
17 "Alpha")
19 (!with-bigvec-or-sap
20 (defun fixup-code-object (code offset value kind)
21 (unless (zerop (rem offset n-word-bytes))
22 (error "Unaligned instruction? offset=#x~X." offset))
23 (without-gcing
24 (let ((sap (code-instructions code)))
25 (ecase kind
26 (:jmp-hint
27 (aver (zerop (ldb (byte 2 0) value)))
28 #+nil
29 (setf (sap-ref-16 sap offset)
30 (logior (sap-ref-16 sap offset)
31 (ldb (byte 14 0) (ash value -2)))))
32 (:bits-63-48
33 (let* ((value (if (logbitp 15 value) (+ value (ash 1 16)) value))
34 (value (if (logbitp 31 value) (+ value (ash 1 32)) value))
35 (value (if (logbitp 47 value) (+ value (ash 1 48)) value)))
36 (setf (sap-ref-8 sap offset) (ldb (byte 8 48) value))
37 (setf (sap-ref-8 sap (1+ offset)) (ldb (byte 8 56) value))))
38 (:bits-47-32
39 (let* ((value (if (logbitp 15 value) (+ value (ash 1 16)) value))
40 (value (if (logbitp 31 value) (+ value (ash 1 32)) value)))
41 (setf (sap-ref-8 sap offset) (ldb (byte 8 32) value))
42 (setf (sap-ref-8 sap (1+ offset)) (ldb (byte 8 40) value))))
43 (:ldah
44 (let ((value (if (logbitp 15 value) (+ value (ash 1 16)) value)))
45 (setf (sap-ref-8 sap offset) (ldb (byte 8 16) value))
46 (setf (sap-ref-8 sap (1+ offset)) (ldb (byte 8 24) value))))
47 (:lda
48 (setf (sap-ref-8 sap offset) (ldb (byte 8 0) value))
49 (setf (sap-ref-8 sap (1+ offset)) (ldb (byte 8 8) value)))
50 (:absolute32
51 (setf (sap-ref-32 sap offset) value)))))))
53 ;;;; "sigcontext" access functions, cut & pasted from x86-vm.lisp then
54 ;;;; hacked for types.
55 ;;;;
56 ;;;; KLUDGE: The alpha has 64-bit registers, so these potentially
57 ;;;; return 64 bit numbers (which means bignums ... ew) We think that
58 ;;;; 99 times of 100 (i.e. unless something is badly wrong) we'll get
59 ;;;; answers that fit in 32 bits anyway. Which probably won't help us
60 ;;;; stop passing bignums around as the compiler can't prove they fit
61 ;;;; in 32 bits. But maybe the stuff it does on x86 to unbox 32-bit
62 ;;;; constants happens magically for 64-bit constants here. Just
63 ;;;; maybe. -- Dan Barlow, ca. 2001-05-05
64 ;;;;
65 ;;;; See also x86-vm for commentary on signed vs unsigned.
67 #-sb-xc-host (progn
68 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
69 ;;; register. FORMAT is the type of float to return.
71 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
72 ;;; long is another question. This stuff still needs testing.
73 (define-alien-routine ("os_context_float_register_addr"
74 context-float-register-addr)
75 (* long)
76 (context (* os-context-t))
77 (index int))
78 (defun context-float-register (context index format)
79 (declare (type (alien (* os-context-t)) context))
80 (coerce (deref (context-float-register-addr context index)) format))
81 (defun %set-context-float-register (context index format new)
82 (declare (type (alien (* os-context-t)) context))
83 (setf (deref (context-float-register-addr context index))
84 (coerce new format)))
86 ;;; This sets the software fp_control word, which is not the same
87 ;;; thing as the hardware fpcr. We have to do this so that OS FPU
88 ;;; completion works properly
90 ;;; Note that this means we can't set rounding modes; we'd have to do
91 ;;; that separately. That said, almost everybody seems to agree that
92 ;;; changing the rounding mode is rarely a good idea, because it upsets
93 ;;; libm functions. So adding that is not a priority. Sorry.
94 ;;; -dan 2001.02.06
96 (define-alien-routine
97 ("arch_get_fp_control" floating-point-modes) (unsigned 64))
99 (define-alien-routine
100 ("arch_set_fp_control" %floating-point-modes-setter) void (fp (unsigned 64)))
102 (defun (setf floating-point-modes) (val) (%floating-point-modes-setter val))
104 ;;; Given a signal context, return the floating point modes word in
105 ;;; the same format as returned by FLOATING-POINT-MODES.
106 (define-alien-routine ("os_context_fp_control" context-floating-point-modes)
107 (unsigned 64) (context (* os-context-t)))
110 ;;;; INTERNAL-ERROR-ARGS
111 (defun internal-error-args (context)
112 (declare (type (alien (* os-context-t)) context))
113 (let* ((pc (context-pc context))
114 (error-number (sap-ref-8 pc 4)))
115 (declare (type system-area-pointer pc))
116 (values error-number
117 (sb!kernel::decode-internal-error-args (sap+ pc 5) error-number))))
118 ) ; end PROGN