1.0.4.34: return true from GET-SPINLOCK
[sbcl/lichteblau.git] / src / code / mips-vm.lisp
blob987dc6b02385ae6bec7986afeaf035f2c2d2948c
1 ;;; This file contains the MIPS specific runtime stuff.
2 ;;;
3 (in-package "SB!VM")
5 \f
6 (define-alien-type os-context-t (struct os-context-t-struct))
7 (define-alien-type os-context-register-t unsigned-long-long)
9 \f
10 ;;;; MACHINE-TYPE and MACHINE-VERSION
12 (defun machine-type ()
13 "Returns a string describing the type of the local machine."
14 "MIPS")
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))
28 (sb!sys:without-gcing
29 (let ((sap (truly-the system-area-pointer
30 (%primitive sb!c::code-instructions code))))
31 (ecase kind
32 (:jump
33 (aver (zerop (ash value -28)))
34 (setf (ldb (byte 26 0) (sap-ref-32 sap offset))
35 (ash value -2)))
36 (:lui
37 (setf (ldb (byte 16 0) (sap-ref-32 sap offset))
38 (ash (1+ (ash value -15)) -1)))
39 (:addi
40 (setf (ldb (byte 16 0) (sap-ref-32 sap offset))
41 (ldb (byte 16 0) value)))))))
44 (define-alien-routine ("os_context_pc_addr" context-pc-addr)
45 (* os-context-register-t)
46 (context (* os-context-t) :in))
48 (defun context-pc (context)
49 (declare (type (alien (* os-context-t)) context))
50 (int-sap (deref (context-pc-addr context))))
52 (define-alien-routine ("os_context_register_addr" context-register-addr)
53 (* os-context-register-t)
54 (context (* os-context-t) :in)
55 (index int :in))
57 (define-alien-routine ("os_context_bd_cause" context-bd-cause-int)
58 unsigned-int
59 (context (* os-context-t) :in))
61 ;;; FIXME: Should this and CONTEXT-PC be INLINE to reduce consing?
62 ;;; (Are they used in anything time-critical, or just the debugger?)
63 (defun context-register (context index)
64 (declare (type (alien (* os-context-t)) context))
65 (let ((addr (context-register-addr context index)))
66 (declare (type (alien (* os-context-register-t)) addr))
67 (deref addr)))
69 (defun %set-context-register (context index new)
70 (declare (type (alien (* os-context-t)) context))
71 (let ((addr (context-register-addr context index)))
72 (declare (type (alien (* os-context-register-t)) addr))
73 (setf (deref addr) new)))
75 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
76 ;;; register. FORMAT is the type of float to return.
78 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
79 ;;; long is another question. This stuff still needs testing.
80 (define-alien-routine ("os_context_fpregister_addr" context-float-register-addr)
81 (* os-context-register-t)
82 (context (* os-context-t))
83 (index int))
85 (defun context-float-register (context index format)
86 (declare (type (alien (* os-context-t)) context))
87 (let ((addr (context-float-register-addr context index)))
88 (declare (type (alien (* os-context-register-t)) addr))
89 (coerce (deref addr) format)))
91 (defun %set-context-float-register (context index format new)
92 (declare (type (alien (* os-context-t)) context))
93 (let ((addr (context-float-register-addr context index)))
94 (declare (type (alien (* os-context-register-t)) addr))
95 (setf (deref addr) (coerce new format))))
97 ;;; Given a signal context, return the floating point modes word in
98 ;;; the same format as returned by FLOATING-POINT-MODES.
99 (define-alien-routine ("os_context_fp_control" context-floating-point-modes)
100 unsigned-int
101 (context (* os-context-t)))
103 ;;;; Internal-error-arguments.
105 ;;; INTERNAL-ERROR-ARGUMENTS -- interface.
107 ;;; Given the sigcontext, extract the internal error arguments from the
108 ;;; instruction stream. This is e.g.
109 ;;; 4 23 254 206 1 0 0 0
110 ;;; | ~~~~~~~~~~~~~~~~~~~~~~~~~
111 ;;; length data (everything is an octet)
112 ;;; (pc + 4)
113 (defun internal-error-args (context)
114 (declare (type (alien (* os-context-t)) context))
115 (/show0 "entering INTERNAL-ERROR-ARGS, CONTEXT=..")
116 (/hexstr context)
117 (let ((pc (context-pc context))
118 (cause (context-bd-cause-int context)))
119 (declare (type system-area-pointer pc))
120 (multiple-value-bind (error-number length sc-offsets)
121 ;; KLUDGE: This exposure of the branch delay mechanism hurts.
122 (snarf-error-junk pc (if (logbitp 31 cause) 8 4))
123 (declare (ignore length))
124 (values error-number sc-offsets))))