1 ;;; This file contains the MIPS specific runtime stuff.
6 (define-alien-type os-context-t (struct os-context-t-struct))
7 (define-alien-type os-context-register-t unsigned-long-long)
10 ;;;; MACHINE-TYPE and MACHINE-VERSION
12 (defun machine-type ()
13 "Returns a string describing the type of the local machine."
16 ;;; support for CL:MACHINE-VERSION defined OAOO elsewhere
17 (defun get-machine-version ()
18 #!+little-endian "little-endian"
19 #!-little-endian "big-endian")
22 ;;;; FIXUP-CODE-OBJECT
24 (defun fixup-code-object (code offset value kind)
25 (declare (type index offset))
26 (unless (zerop (rem offset n-word-bytes))
27 (error "Unaligned instruction? offset=#x~X." offset))
29 (let ((sap (%primitive sb!c::code-instructions code)))
32 (aver (zerop (ash value -28)))
33 (setf (ldb (byte 26 0) (sap-ref-32 sap offset))
36 (setf (ldb (byte 16 0) (sap-ref-32 sap offset))
37 (ash (1+ (ash value -15)) -1)))
39 (setf (ldb (byte 16 0) (sap-ref-32 sap offset))
40 (ldb (byte 16 0) value)))))))
43 (define-alien-routine ("os_context_pc_addr" context-pc-addr)
44 (* os-context-register-t)
45 (context (* os-context-t) :in))
47 (defun context-pc (context)
48 (declare (type (alien (* os-context-t)) context))
49 (int-sap (deref (context-pc-addr context))))
51 (define-alien-routine ("os_context_register_addr" context-register-addr)
52 (* os-context-register-t)
53 (context (* os-context-t) :in)
56 (define-alien-routine ("os_context_bd_cause" context-bd-cause-int)
58 (context (* os-context-t) :in))
60 ;;; FIXME: Should this and CONTEXT-PC be INLINE to reduce consing?
61 ;;; (Are they used in anything time-critical, or just the debugger?)
62 (defun context-register (context index)
63 (declare (type (alien (* os-context-t)) context))
64 (let ((addr (context-register-addr context index)))
65 (declare (type (alien (* os-context-register-t)) addr))
68 (defun %set-context-register (context index new)
69 (declare (type (alien (* os-context-t)) context))
70 (let ((addr (context-register-addr context index)))
71 (declare (type (alien (* os-context-register-t)) addr))
72 (setf (deref addr) new)))
74 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
75 ;;; register. FORMAT is the type of float to return.
77 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
78 ;;; long is another question. This stuff still needs testing.
79 (define-alien-routine ("os_context_fpregister_addr" context-float-register-addr)
80 (* os-context-register-t)
81 (context (* os-context-t) :in)
84 (defun context-float-register (context index format)
85 (declare (type (alien (* os-context-t)) context))
86 (let ((addr (context-float-register-addr context index)))
87 (declare (type (alien (* os-context-register-t)) addr))
88 (coerce (deref addr) format)))
90 (defun %set-context-float-register (context index format new)
91 (declare (type (alien (* os-context-t)) context))
92 (let ((addr (context-float-register-addr context index)))
93 (declare (type (alien (* os-context-register-t)) addr))
94 (setf (deref addr) (coerce new format))))
97 ("arch_get_fp_control" floating-point-modes) unsigned-int)
100 ("arch_set_fp_control" %floating-point-modes-setter) void (fp unsigned-int :in))
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)
108 (context (* os-context-t) :in))
110 ;;;; Internal-error-arguments.
112 ;;; INTERNAL-ERROR-ARGUMENTS -- interface.
114 ;;; Given the sigcontext, extract the internal error arguments from the
115 ;;; instruction stream. This is e.g.
116 ;;; 4 23 254 206 1 0 0 0
117 ;;; | ~~~~~~~~~~~~~~~~~~~~~~~~~
118 ;;; length data (everything is an octet)
120 (defun internal-error-args (context)
121 (declare (type (alien (* os-context-t)) context))
122 (/show0 "entering INTERNAL-ERROR-ARGS, CONTEXT=..")
124 (let ((pc (context-pc context))
125 (cause (context-bd-cause-int context)))
126 (declare (type system-area-pointer pc))
127 (multiple-value-bind (error-number length sc-offsets)
128 ;; KLUDGE: This exposure of the branch delay mechanism hurts.
129 (snarf-error-junk pc (if (logbitp 31 cause) 8 4))
130 (declare (ignore length))
131 (values error-number sc-offsets))))