1 ;;; This file contains the MIPS specific runtime stuff.
6 (define-alien-type os-context-t (struct os-context-t-struct))
9 ;;;; MACHINE-TYPE and MACHINE-VERSION
11 (defun machine-type ()
12 "Returns a string describing the type of the local machine."
15 ;;; support for CL:MACHINE-VERSION defined OAOO elsewhere
16 (defun get-machine-version ()
17 #!+little-endian "little-endian"
18 #!-little-endian "big-endian")
21 ;;;; FIXUP-CODE-OBJECT
23 (defun fixup-code-object (code offset value kind)
24 (declare (type index offset))
25 (unless (zerop (rem offset n-word-bytes))
26 (error "Unaligned instruction? offset=#x~X." offset))
28 (let ((sap (truly-the system-area-pointer
29 (%primitive sb!c::code-instructions code))))
32 (aver (zerop (ash value -28)))
33 (setf (ldb (byte 26 0) (sap-ref-32 sap offset))
37 #!+little-endian offset
38 #!-little-endian (+ offset 2))
40 (if (logbitp 15 value) 1 0))))
43 #!+little-endian offset
44 #!-little-endian (+ offset 2))
45 (ldb (byte 16 0) value)))))))
48 (define-alien-routine ("os_context_pc_addr" context-pc-addr)
49 (* unsigned-long-long)
50 (context (* os-context-t)))
52 (defun context-pc (context)
53 (declare (type (alien (* os-context-t)) context))
54 (int-sap (deref (context-pc-addr context))))
56 (define-alien-routine ("os_context_register_addr" context-register-addr)
57 (* unsigned-long-long)
58 (context (* os-context-t))
61 (define-alien-routine ("os_context_bd_cause" context-bd-cause-int)
63 (context (* os-context-t)))
65 ;;; FIXME: Should this and CONTEXT-PC be INLINE to reduce consing?
66 ;;; (Are they used in anything time-critical, or just the debugger?)
67 (defun context-register (context index)
68 (declare (type (alien (* os-context-t)) context))
69 (let ((addr (context-register-addr context index)))
70 (declare (type (alien (* unsigned-long-long)) addr))
73 (defun %set-context-register (context index new)
74 (declare (type (alien (* os-context-t)) context))
75 (let ((addr (context-register-addr context index)))
76 (declare (type (alien (* unsigned-long-long)) addr))
77 (setf (deref addr) new)))
79 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
80 ;;; register. FORMAT is the type of float to return.
82 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
83 ;;; long is another question. This stuff still needs testing.
84 (define-alien-routine ("os_context_fpregister_addr" context-float-register-addr)
85 (* unsigned-long-long)
86 (context (* os-context-t))
89 (defun context-float-register (context index format)
90 (declare (type (alien (* os-context-t)) context))
91 (let ((addr (context-float-register-addr context index)))
92 (declare (type (alien (* unsigned-long-long)) addr))
93 (coerce (deref addr) format)))
95 (defun %set-context-float-register (context index format new)
96 (declare (type (alien (* os-context-t)) context))
97 (let ((addr (context-float-register-addr context index)))
98 (declare (type (alien (* unsigned-long-long)) addr))
99 (setf (deref addr) (coerce new format))))
101 ;;; Given a signal context, return the floating point modes word in
102 ;;; the same format as returned by FLOATING-POINT-MODES.
103 (define-alien-routine ("os_context_fp_control" context-floating-point-modes)
105 (context (* os-context-t)))
107 ;;;; Internal-error-arguments.
109 ;;; INTERNAL-ERROR-ARGUMENTS -- interface.
111 ;;; Given the sigcontext, extract the internal error arguments from the
112 ;;; instruction stream.
114 (defun internal-error-args (context)
115 (declare (type (alien (* os-context-t)) context))
116 (/show0 "entering INTERNAL-ERROR-ARGS, CONTEXT=..")
118 (let ((pc (context-pc context))
119 (cause (context-bd-cause-int context)))
120 (declare (type system-area-pointer pc))
121 ;; KLUDGE: This exposure of the branch delay mechanism hurts.
122 (when (logbitp 31 cause)
123 (setf pc (sap+ pc 4)))
124 (args-for-unimp-inst pc)))
126 (defun args-for-unimp-inst (pc)
127 (declare (type system-area-pointer pc))
128 (let* ((length (sap-ref-8 pc 4))
129 (vector (make-array length :element-type '(unsigned-byte 8))))
130 (declare (type (unsigned-byte 8) length)
131 (type (simple-array (unsigned-byte 8) (*)) vector))
132 (copy-ub8-from-system-area pc 5 vector 0 length)
134 (error-number (sb!c:read-var-integer vector index)))
135 (collect ((sc-offsets))
137 (when (>= index length)
139 (sc-offsets (sb!c:read-var-integer vector index)))
140 (values error-number (sc-offsets))))))