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.
15 ;;; See x86-vm.lisp for a description of this.
16 (define-alien-type os-context-t
(struct os-context-t-struct
))
20 (defun machine-type ()
21 "Return a string describing the type of the local machine."
26 (defun fixup-code-object (code offset value kind
)
27 (unless (zerop (rem offset n-word-bytes
))
28 (error "Unaligned instruction? offset=#x~X." offset
))
30 (let ((sap (code-instructions code
)))
33 (aver (zerop (ldb (byte 2 0) value
)))
35 (setf (sap-ref-16 sap offset
)
36 (logior (sap-ref-16 sap offset
)
37 (ldb (byte 14 0) (ash value -
2)))))
39 (let* ((value (if (logbitp 15 value
) (+ value
(ash 1 16)) value
))
40 (value (if (logbitp 31 value
) (+ value
(ash 1 32)) value
))
41 (value (if (logbitp 47 value
) (+ value
(ash 1 48)) value
)))
42 (setf (sap-ref-8 sap offset
) (ldb (byte 8 48) value
))
43 (setf (sap-ref-8 sap
(1+ offset
)) (ldb (byte 8 56) value
))))
45 (let* ((value (if (logbitp 15 value
) (+ value
(ash 1 16)) value
))
46 (value (if (logbitp 31 value
) (+ value
(ash 1 32)) value
)))
47 (setf (sap-ref-8 sap offset
) (ldb (byte 8 32) value
))
48 (setf (sap-ref-8 sap
(1+ offset
)) (ldb (byte 8 40) value
))))
50 (let ((value (if (logbitp 15 value
) (+ value
(ash 1 16)) value
)))
51 (setf (sap-ref-8 sap offset
) (ldb (byte 8 16) value
))
52 (setf (sap-ref-8 sap
(1+ offset
)) (ldb (byte 8 24) value
))))
54 (setf (sap-ref-8 sap offset
) (ldb (byte 8 0) value
))
55 (setf (sap-ref-8 sap
(1+ offset
)) (ldb (byte 8 8) value
)))
57 (setf (sap-ref-32 sap offset
) value
)))))))
59 ;;;; "sigcontext" access functions, cut & pasted from x86-vm.lisp then
60 ;;;; hacked for types.
62 ;;;; KLUDGE: The alpha has 64-bit registers, so these potentially
63 ;;;; return 64 bit numbers (which means bignums ... ew) We think that
64 ;;;; 99 times of 100 (i.e. unless something is badly wrong) we'll get
65 ;;;; answers that fit in 32 bits anyway. Which probably won't help us
66 ;;;; stop passing bignums around as the compiler can't prove they fit
67 ;;;; in 32 bits. But maybe the stuff it does on x86 to unbox 32-bit
68 ;;;; constants happens magically for 64-bit constants here. Just
69 ;;;; maybe. -- Dan Barlow, ca. 2001-05-05
71 ;;;; See also x86-vm for commentary on signed vs unsigned.
74 (define-alien-routine ("os_context_pc_addr" context-pc-addr
) (* unsigned-long
)
75 (context (* os-context-t
)))
77 (defun context-pc (context)
78 (declare (type (alien (* os-context-t
)) context
))
79 (int-sap (deref (context-pc-addr context
))))
81 (define-alien-routine ("os_context_register_addr" context-register-addr
)
83 (context (* os-context-t
))
86 ;;; FIXME: Should this and CONTEXT-PC be INLINE to reduce consing?
87 ;;; (Are they used in anything time-critical, or just the debugger?)
88 (defun context-register (context index
)
89 (declare (type (alien (* os-context-t
)) context
))
90 (deref (the (alien (* unsigned-long
))
91 (context-register-addr context index
))))
93 (defun %set-context-register
(context index new
)
94 (declare (type (alien (* os-context-t
)) context
))
95 (setf (deref (the (alien (* unsigned-long
))
96 (context-register-addr context index
)))
99 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
100 ;;; register. FORMAT is the type of float to return.
102 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
103 ;;; long is another question. This stuff still needs testing.
104 (define-alien-routine ("os_context_float_register_addr"
105 context-float-register-addr
)
107 (context (* os-context-t
))
109 (defun context-float-register (context index format
)
110 (declare (type (alien (* os-context-t
)) context
))
111 (coerce (deref (context-float-register-addr context index
)) format
))
112 (defun %set-context-float-register
(context index format new
)
113 (declare (type (alien (* os-context-t
)) context
))
114 (setf (deref (context-float-register-addr context index
))
115 (coerce new format
)))
117 ;;; This sets the software fp_control word, which is not the same
118 ;;; thing as the hardware fpcr. We have to do this so that OS FPU
119 ;;; completion works properly
121 ;;; Note that this means we can't set rounding modes; we'd have to do
122 ;;; that separately. That said, almost everybody seems to agree that
123 ;;; changing the rounding mode is rarely a good idea, because it upsets
124 ;;; libm functions. So adding that is not a priority. Sorry.
127 (define-alien-routine
128 ("arch_get_fp_control" floating-point-modes
) (unsigned 64))
130 (define-alien-routine
131 ("arch_set_fp_control" %floating-point-modes-setter
) void
(fp (unsigned 64)))
133 (defun (setf floating-point-modes
) (val) (%floating-point-modes-setter val
))
135 ;;; Given a signal context, return the floating point modes word in
136 ;;; the same format as returned by FLOATING-POINT-MODES.
137 (define-alien-routine ("os_context_fp_control" context-floating-point-modes
)
138 (unsigned 64) (context (* os-context-t
)))
141 ;;;; INTERNAL-ERROR-ARGS
142 (defun internal-error-args (context)
143 (declare (type (alien (* os-context-t
)) context
))
144 (let* ((pc (context-pc context
))
145 (error-number (sap-ref-8 pc
4)))
146 (declare (type system-area-pointer pc
))
148 (sb!kernel
::decode-internal-error-args
(sap+ pc
5) error-number
))))