0.9.2.43:
[sbcl/lichteblau.git] / src / code / mips-vm.lisp
blob4da2a8306a9393cdbc7484165747888db686f6bd
1 (in-package "SB!VM")
2 \f
3 (define-alien-type os-context-t (struct os-context-t-struct))
4 \f
5 ;;;; MACHINE-TYPE and MACHINE-VERSION
7 (defun machine-type ()
8 "Returns a string describing the type of the local machine."
9 "MIPS")
11 ;;; support for CL:MACHINE-VERSION defined OAOO elsewhere
12 (defun get-machine-version ()
13 #!+little-endian "little-endian"
14 #!-little-endian "big-endian")
16 ;;;; FIXUP-CODE-OBJECT
18 (defun fixup-code-object (code offset value kind)
19 (unless (zerop (rem offset n-word-bytes))
20 (error "Unaligned instruction? offset=#x~X." offset))
21 (sb!sys:without-gcing
22 (let ((sap (truly-the system-area-pointer
23 (%primitive sb!c::code-instructions code))))
24 (ecase kind
25 (:jump
26 (aver (zerop (ash value -28)))
27 (setf (ldb (byte 26 0) (sap-ref-32 sap offset))
28 (ash value -2)))
29 (:lui
30 (setf (sap-ref-16 sap
31 #!+little-endian offset
32 #!-little-endian (+ offset 2))
33 (+ (ash value -16)
34 (if (logbitp 15 value) 1 0))))
35 (:addi
36 (setf (sap-ref-16 sap
37 #!+little-endian offset
38 #!-little-endian (+ offset 2))
39 (ldb (byte 16 0) value)))))))
42 (define-alien-routine ("os_context_pc_addr" context-pc-addr) (* unsigned-int)
43 (context (* os-context-t)))
45 (defun context-pc (context)
46 (declare (type (alien (* os-context-t)) context))
47 ;; KLUDGE: this sucks, and furthermore will break on either of (a)
48 ;; porting back to IRIX or (b) running on proper 64-bit support.
49 ;; Linux on the MIPS defines its registers in the sigcontext as
50 ;; 64-bit quantities ("unsigned long long"), presumably to be
51 ;; binary-compatible with 64-bit mode. Since there appears not to
52 ;; be ALIEN support for 64-bit return values, we have to do the
53 ;; hacky pointer arithmetic thing. -- CSR, 2002-09-01
54 (int-sap (deref (context-pc-addr context)
55 #!-little-endian 1
56 ;; Untested
57 #!+little-endian 0)))
59 (define-alien-routine ("os_context_register_addr" context-register-addr)
60 (* unsigned-int)
61 (context (* os-context-t))
62 (index int))
64 (define-alien-routine ("os_context_bd_cause" context-bd-cause-int)
65 (unsigned 32)
66 (context (* os-context-t)))
68 ;;; FIXME: Should this and CONTEXT-PC be INLINE to reduce consing?
69 ;;; (Are they used in anything time-critical, or just the debugger?)
70 (defun context-register (context index)
71 (declare (type (alien (* os-context-t)) context))
72 (deref (context-register-addr context index)
73 #!-little-endian 1
74 #!+little-endian 0))
76 (defun %set-context-register (context index new)
77 (declare (type (alien (* os-context-t)) context))
78 (setf (deref (context-register-addr context index)
79 #!-little-endian 1
80 #!+little-endian 0)
81 new))
83 #!+linux
84 ;;; For now.
85 (defun context-floating-point-modes (context)
86 (declare (ignore context))
87 (warn "stub CONTEXT-FLOATING-POINT-MODES")
90 ;;;; Internal-error-arguments.
92 ;;; INTERNAL-ERROR-ARGUMENTS -- interface.
93 ;;;
94 ;;; Given the sigcontext, extract the internal error arguments from the
95 ;;; instruction stream.
96 ;;;
97 (defun internal-error-args (context)
98 (declare (type (alien (* os-context-t)) context))
99 (/show0 "entering INTERNAL-ERROR-ARGS, CONTEXT=..")
100 (/hexstr context)
101 (let ((pc (context-pc context))
102 (cause (context-bd-cause-int context)))
103 (declare (type system-area-pointer pc))
104 (/show0 "got PC=..")
105 (/hexstr (sap-int pc))
106 ;; KLUDGE: This exposure of the branch delay mechanism hurts.
107 (when (logbitp 31 cause)
108 (setf pc (sap+ pc 4)))
109 (when (= (sap-ref-8 pc 4) 255)
110 (setf pc (sap+ pc 1)))
111 (/show0 "now PC=..")
112 (/hexstr (sap-int pc))
113 (let* ((length (sap-ref-8 pc 4))
114 (vector (make-array length :element-type '(unsigned-byte 8))))
115 (declare (type (unsigned-byte 8) length)
116 (type (simple-array (unsigned-byte 8) (*)) vector))
117 (/show0 "LENGTH,VECTOR,ERROR-NUMBER=..")
118 (/hexstr length)
119 (/hexstr vector)
120 (copy-ub8-from-system-area pc 5 vector 0 length)
121 (let* ((index 0)
122 (error-number (sb!c:read-var-integer vector index)))
123 (/hexstr error-number)
124 (collect ((sc-offsets))
125 (loop
126 (/show0 "INDEX=..")
127 (/hexstr index)
128 (when (>= index length)
129 (return))
130 (sc-offsets (sb!c:read-var-integer vector index)))
131 (values error-number (sc-offsets)))))))