1 ;;;; Alpha-specific implementation stuff
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 (defvar *number-of-signals* 64)
15 (defvar *bits-per-word* 64)
17 ;;; See x86-vm.lisp for a description of this.
18 (define-alien-type os-context-t (struct os-context-t-struct))
20 ;;;; MACHINE-TYPE and MACHINE-VERSION
22 (defun machine-type ()
23 "Return a string describing the type of the local machine."
25 (defun machine-version ()
26 "Return a string describing the version of the local machine."
29 (defun fixup-code-object (code offset value kind)
30 (unless (zerop (rem offset n-word-bytes))
31 (error "Unaligned instruction? offset=#x~X." offset))
33 (let ((sap (truly-the system-area-pointer
34 (%primitive code-instructions code))))
37 (assert (zerop (ldb (byte 2 0) value)))
39 (setf (sap-ref-16 sap offset)
40 (logior (sap-ref-16 sap offset)
41 (ldb (byte 14 0) (ash value -2)))))
43 (let* ((value (if (logbitp 15 value) (+ value (ash 1 16)) value))
44 (value (if (logbitp 31 value) (+ value (ash 1 32)) value))
45 (value (if (logbitp 47 value) (+ value (ash 1 48)) value)))
46 (setf (sap-ref-8 sap offset) (ldb (byte 8 48) value))
47 (setf (sap-ref-8 sap (1+ offset)) (ldb (byte 8 56) value))))
49 (let* ((value (if (logbitp 15 value) (+ value (ash 1 16)) value))
50 (value (if (logbitp 31 value) (+ value (ash 1 32)) value)))
51 (setf (sap-ref-8 sap offset) (ldb (byte 8 32) value))
52 (setf (sap-ref-8 sap (1+ offset)) (ldb (byte 8 40) value))))
54 (let ((value (if (logbitp 15 value) (+ value (ash 1 16)) value)))
55 (setf (sap-ref-8 sap offset) (ldb (byte 8 16) value))
56 (setf (sap-ref-8 sap (1+ offset)) (ldb (byte 8 24) value))))
58 (setf (sap-ref-8 sap offset) (ldb (byte 8 0) value))
59 (setf (sap-ref-8 sap (1+ offset)) (ldb (byte 8 8) value)))))))
61 ;;;; "sigcontext" access functions, cut & pasted from x86-vm.lisp then
62 ;;;; hacked for types.
64 ;;;; KLUDGE: The alpha has 64-bit registers, so these potentially
65 ;;;; return 64 bit numbers (which means bignums ... ew) We think that
66 ;;;; 99 times of 100 (i.e. unless something is badly wrong) we'll get
67 ;;;; answers that fit in 32 bits anyway. Which probably won't help us
68 ;;;; stop passing bignums around as the compiler can't prove they fit
69 ;;;; in 32 bits. But maybe the stuff it does on x86 to unbox 32-bit
70 ;;;; constants happens magically for 64-bit constants here. Just
71 ;;;; maybe. -- Dan Barlow, ca. 2001-05-05
73 ;;;; See also x86-vm for commentary on signed vs unsigned.
75 (define-alien-routine ("os_context_pc_addr" context-pc-addr) (* unsigned-long)
76 (context (* os-context-t)))
78 (defun context-pc (context)
79 (declare (type (alien (* os-context-t)) context))
80 (int-sap (deref (context-pc-addr context))))
82 (define-alien-routine ("os_context_register_addr" context-register-addr)
84 (context (* os-context-t))
87 ;;; FIXME: Should this and CONTEXT-PC be INLINE to reduce consing?
88 ;;; (Are they used in anything time-critical, or just the debugger?)
89 (defun context-register (context index)
90 (declare (type (alien (* os-context-t)) context))
91 (deref (the (alien (* unsigned-long))
92 (context-register-addr context index))))
94 (defun %set-context-register (context index new)
95 (declare (type (alien (* os-context-t)) context))
96 (setf (deref (the (alien (* unsigned-long))
97 (context-register-addr context index)))
100 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
101 ;;; register. FORMAT is the type of float to return.
103 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
104 ;;; long is another question. This stuff still needs testing.
105 (define-alien-routine ("os_context_float_register_addr"
106 context-float-register-addr)
108 (context (* os-context-t))
110 (defun context-float-register (context index format)
111 (declare (type (alien (* os-context-t)) context))
112 (coerce (deref (context-float-register-addr context index)) format))
113 (defun %set-context-float-register (context index format new)
114 (declare (type (alien (* os-context-t)) context))
115 (setf (deref (context-float-register-addr context index))
116 (coerce new format)))
118 ;;; This sets the software fp_control word, which is not the same
119 ;;; thing as the hardware fpcr. We have to do this so that OS FPU
120 ;;; completion works properly
122 ;;; Note that this means we can't set rounding modes; we'd have to do
123 ;;; that separately. That said, almost everybody seems to agree that
124 ;;; changing the rounding mode is rarely a good idea, because it upsets
125 ;;; libm functions. So adding that is not a priority. Sorry.
128 (define-alien-routine
129 ("arch_get_fp_control" floating-point-modes) (sb!alien:unsigned 64))
131 (define-alien-routine
132 ("arch_set_fp_control" %floating-point-modes-setter) void (fp (sb!alien:unsigned 64)))
134 (defun (setf floating-point-modes) (val) (%floating-point-modes-setter val))
136 ;;; Given a signal context, return the floating point modes word in
137 ;;; the same format as returned by FLOATING-POINT-MODES.
138 (define-alien-routine ("os_context_fp_control" context-floating-point-modes)
139 (sb!alien:unsigned 64) (context (* os-context-t)))
142 ;;;; INTERNAL-ERROR-ARGS
144 ;;; Given a (POSIX) signal context, extract the internal error
145 ;;; arguments from the instruction stream. This is e.g.
146 ;;; 4 23 254 240 2 0 0 0
147 ;;; | ~~~~~~~~~~~~~~~~~~~~~~~~~
148 ;;; length data (everything is an octet)
150 ;;; (example from undefined_tramp: "(gdb) x/40ub 0x10148" for yourself
152 (defun internal-error-args (context)
153 (declare (type (alien (* os-context-t)) context))
154 (let ((pc (context-pc context)))
155 (declare (type system-area-pointer pc))
156 ;; pc is a SAP pointing at - or actually, shortly after -
157 ;; the instruction that got us into this mess in the first place
158 (let* ((length (sap-ref-8 pc 4))
159 (vector (make-array length :element-type '(unsigned-byte 8))))
160 (declare (type (unsigned-byte 8) length)
161 (type (simple-array (unsigned-byte 8) (*)) vector))
162 (copy-from-system-area pc (* n-byte-bits 5)
163 vector (* n-word-bits vector-data-offset)
164 (* length n-byte-bits))
166 (error-number (sb!c:read-var-integer vector index)))
167 (collect ((sc-offsets))
169 (when (>= index length)
171 (sc-offsets (sb!c:read-var-integer vector index)))
172 (values error-number (sc-offsets)))))))