1 ;;;; SPARC-specific runtime 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.
13 ;;; See x86-vm.lisp for a description of this.
14 (define-alien-type os-context-t (struct os-context-t-struct))
16 ;;;; MACHINE-TYPE and MACHINE-VERSION
18 (defun machine-type ()
19 "Returns a string describing the type of the local machine."
22 ;;; support for CL:MACHINE-VERSION defined OAOO elsewhere
23 (defun get-machine-version ()
26 (defun fixup-code-object (code offset fixup kind)
27 (declare (type index offset))
28 (unless (zerop (rem offset n-word-bytes))
29 (error "Unaligned instruction? offset=#x~X." offset))
31 (let ((sap (truly-the system-area-pointer
32 (%primitive sb!kernel::code-instructions code))))
35 (error "Can't deal with CALL fixups, yet."))
37 (setf (ldb (byte 22 0) (sap-ref-32 sap offset))
38 (ldb (byte 22 10) fixup)))
40 (setf (ldb (byte 10 0) (sap-ref-32 sap offset))
41 (ldb (byte 10 0) fixup)))))))
44 ;;;; "Sigcontext" access functions, cut & pasted from alpha-vm.lisp.
46 ;;;; See also x86-vm for commentary on signed vs unsigned.
48 (define-alien-routine ("os_context_pc_addr" context-pc-addr) (* unsigned-int)
49 (context (* os-context-t)))
51 (defun context-pc (context)
52 (declare (type (alien (* os-context-t)) context))
53 (int-sap (deref (context-pc-addr context))))
55 (define-alien-routine ("os_context_register_addr" context-register-addr)
57 (context (* os-context-t))
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 (deref (context-register-addr context index)))
66 (defun %set-context-register (context index new)
67 (declare (type (alien (* os-context-t)) context))
68 (setf (deref (context-register-addr context index))
71 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
72 ;;; register. FORMAT is the type of float to return.
74 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
75 ;;; long is another question. This stuff still needs testing.
77 (define-alien-routine ("os_context_float_register_addr" context-float-register-addr)
79 (context (* os-context-t))
82 (defun context-float-register (context index format)
83 (declare (type (alien (* os-context-t)) context))
84 (coerce (deref (context-float-register-addr context index)) format))
86 (defun %set-context-float-register (context index format new)
87 (declare (type (alien (* os-context-t)) context))
88 (setf (deref (context-float-register-addr context index))
91 ;;; Given a signal context, return the floating point modes word in
92 ;;; the same format as returned by FLOATING-POINT-MODES.
94 ;;; Under SunOS, we have a straightforward implementation in C:
96 (define-alien-routine ("os_context_fp_control" context-floating-point-modes)
97 (sb!alien:unsigned 32)
98 (context (* os-context-t)))
100 ;;; Under Linux, we have to contend with utterly broken signal handling.
102 (defun context-floating-point-modes (context)
103 (declare (ignore context))
104 (warn "stub CONTEXT-FLOATING-POINT-MODES")
107 ;;;; INTERNAL-ERROR-ARGS.
109 ;;; Given a (POSIX) signal context, extract the internal error
110 ;;; arguments from the instruction stream. This is e.g.
111 ;;; 4 23 254 240 2 0 0 0
112 ;;; | ~~~~~~~~~~~~~~~~~~~~~~~~~
113 ;;; length data (everything is an octet)
115 (defun internal-error-args (context)
116 (declare (type (alien (* os-context-t)) context))
117 (sb!int::/show0 "entering INTERNAL-ERROR-ARGS")
118 (let* ((pc (context-pc context))
119 (bad-inst (sap-ref-32 pc 0))
120 (op (ldb (byte 2 30) bad-inst))
121 (op2 (ldb (byte 3 22) bad-inst))
122 (op3 (ldb (byte 6 19) bad-inst)))
123 (declare (type system-area-pointer pc))
124 (cond ((and (= op #b00) (= op2 #b000))
125 (args-for-unimp-inst context))
126 ((and (= op #b10) (= (ldb (byte 4 2) op3) #b1000))
127 (args-for-tagged-add-inst context bad-inst))
128 ((and (= op #b10) (= op3 #b111010))
129 (args-for-tcc-inst bad-inst))
131 (values #.(error-number-or-lose 'unknown-error) nil)))))
133 (defun args-for-unimp-inst (context)
134 (declare (type (alien (* os-context-t)) context))
135 (let* ((pc (context-pc context))
136 (length (sap-ref-8 pc 4))
137 (vector (make-array length :element-type '(unsigned-byte 8))))
138 (declare (type system-area-pointer pc)
139 (type (unsigned-byte 8) length)
140 (type (simple-array (unsigned-byte 8) (*)) vector))
141 (copy-ub8-from-system-area pc 5 vector 0 length)
143 (error-number (sb!c:read-var-integer vector index)))
144 (collect ((sc-offsets))
146 (when (>= index length)
148 (sc-offsets (sb!c:read-var-integer vector index)))
149 (values error-number (sc-offsets))))))
151 (defun args-for-tagged-add-inst (context bad-inst)
152 (declare (type (alien (* os-context-t)) context))
153 (let* ((rs1 (ldb (byte 5 14) bad-inst))
154 (op1 (sb!kernel:make-lisp-obj (context-register context rs1))))
156 (if (zerop (ldb (byte 1 13) bad-inst))
157 (let* ((rs2 (ldb (byte 5 0) bad-inst))
158 (op2 (sb!kernel:make-lisp-obj (context-register context rs2))))
160 (values #.(error-number-or-lose 'unknown-error) nil)
161 (values #.(error-number-or-lose 'object-not-fixnum-error)
162 (list (sb!c::make-sc-offset
163 descriptor-reg-sc-number
165 (values #.(error-number-or-lose 'unknown-error) nil))
166 (values #.(error-number-or-lose 'object-not-fixnum-error)
167 (list (sb!c::make-sc-offset descriptor-reg-sc-number
170 (defun args-for-tcc-inst (bad-inst)
171 (let* ((trap-number (ldb (byte 8 0) bad-inst))
172 (reg (ldb (byte 5 8) bad-inst)))
173 (values (case trap-number
174 (#.object-not-list-trap
175 #.(error-number-or-lose 'object-not-list-error))
176 (#.object-not-instance-trap
177 #.(error-number-or-lose 'object-not-instance-error))
179 #.(error-number-or-lose 'unknown-error)))
180 (list (sb!c::make-sc-offset descriptor-reg-sc-number reg)))))