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