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 (%primitive sb!kernel::code-instructions code)))
34 (error "Can't deal with CALL fixups, yet."))
36 (setf (ldb (byte 22 0) (sap-ref-32 sap offset))
37 (ldb (byte 22 10) fixup)))
39 (setf (ldb (byte 10 0) (sap-ref-32 sap offset))
40 (ldb (byte 10 0) fixup)))))))
43 ;;;; "Sigcontext" access functions, cut & pasted from alpha-vm.lisp.
45 ;;;; See also x86-vm for commentary on signed vs unsigned.
47 (define-alien-routine ("os_context_pc_addr" context-pc-addr) (* unsigned-int)
48 (context (* os-context-t)))
50 (defun context-pc (context)
51 (declare (type (alien (* os-context-t)) context))
52 (int-sap (deref (context-pc-addr context))))
54 (define-alien-routine ("os_context_register_addr" context-register-addr)
56 (context (* os-context-t))
59 ;;; FIXME: Should this and CONTEXT-PC be INLINE to reduce consing?
60 ;;; (Are they used in anything time-critical, or just the debugger?)
61 (defun context-register (context index)
62 (declare (type (alien (* os-context-t)) context))
63 (deref (context-register-addr context index)))
65 (defun %set-context-register (context index new)
66 (declare (type (alien (* os-context-t)) context))
67 (setf (deref (context-register-addr context index))
70 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
71 ;;; register. FORMAT is the type of float to return.
73 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
74 ;;; long is another question. This stuff still needs testing.
76 (define-alien-routine ("os_context_float_register_addr" context-float-register-addr)
78 (context (* os-context-t))
81 (defun context-float-register (context index format)
82 (declare (type (alien (* os-context-t)) context))
83 (coerce (deref (context-float-register-addr context index)) format))
85 (defun %set-context-float-register (context index format new)
86 (declare (type (alien (* os-context-t)) context))
87 (setf (deref (context-float-register-addr context index))
90 ;;; Given a signal context, return the floating point modes word in
91 ;;; the same format as returned by FLOATING-POINT-MODES.
93 ;;; Under SunOS, we have a straightforward implementation in C:
95 (define-alien-routine ("os_context_fp_control" context-floating-point-modes)
96 (sb!alien:unsigned 32)
97 (context (* os-context-t)))
99 ;;; Under Linux, we have to contend with utterly broken signal handling.
101 (defun context-floating-point-modes (context)
102 (declare (ignore context))
103 (warn "stub CONTEXT-FLOATING-POINT-MODES")
106 ;;;; INTERNAL-ERROR-ARGS.
108 ;;; Given a (POSIX) signal context, extract the internal error
109 ;;; arguments from the instruction stream. This is e.g.
110 ;;; 4 23 254 240 2 0 0 0
111 ;;; | ~~~~~~~~~~~~~~~~~~~~~~~~~
112 ;;; length data (everything is an octet)
114 (defun internal-error-args (context)
115 (declare (type (alien (* os-context-t)) context))
116 (sb!int::/show0 "entering INTERNAL-ERROR-ARGS")
117 (let* ((pc (context-pc context))
118 (bad-inst (sap-ref-32 pc 0))
119 (op (ldb (byte 2 30) bad-inst))
120 (op2 (ldb (byte 3 22) bad-inst))
121 (op3 (ldb (byte 6 19) bad-inst)))
122 (declare (type system-area-pointer pc))
123 (cond ((and (= op #b00) (= op2 #b000))
124 (args-for-unimp-inst context))
125 ((and (= op #b10) (= (ldb (byte 4 2) op3) #b1000))
126 (args-for-tagged-add-inst context bad-inst))
127 ((and (= op #b10) (= op3 #b111010))
128 (args-for-tcc-inst bad-inst))
130 (values #.(error-number-or-lose 'unknown-error) nil)))))
132 (defun args-for-unimp-inst (context)
133 (declare (type (alien (* os-context-t)) context))
134 (let* ((pc (context-pc context))
135 (length (sap-ref-8 pc 4))
136 (vector (make-array length :element-type '(unsigned-byte 8))))
137 (declare (type system-area-pointer pc)
138 (type (unsigned-byte 8) length)
139 (type (simple-array (unsigned-byte 8) (*)) vector))
140 (copy-ub8-from-system-area pc 5 vector 0 length)
142 (error-number (sb!c:read-var-integer vector index)))
143 (collect ((sc-offsets))
145 (when (>= index length)
147 (sc-offsets (sb!c:read-var-integer vector index)))
148 (values error-number (sc-offsets))))))
150 (defun args-for-tagged-add-inst (context bad-inst)
151 (declare (type (alien (* os-context-t)) context))
152 (let* ((rs1 (ldb (byte 5 14) bad-inst))
153 (op1 (sb!kernel:make-lisp-obj (context-register context rs1))))
155 (if (zerop (ldb (byte 1 13) bad-inst))
156 (let* ((rs2 (ldb (byte 5 0) bad-inst))
157 (op2 (sb!kernel:make-lisp-obj (context-register context rs2))))
159 (values #.(error-number-or-lose 'unknown-error) nil)
160 (values #.(error-number-or-lose 'object-not-fixnum-error)
161 (list (sb!c::make-sc-offset
162 descriptor-reg-sc-number
164 (values #.(error-number-or-lose 'unknown-error) nil))
165 (values #.(error-number-or-lose 'object-not-fixnum-error)
166 (list (sb!c::make-sc-offset descriptor-reg-sc-number
169 (defun args-for-tcc-inst (bad-inst)
170 (let* ((trap-number (ldb (byte 8 0) bad-inst))
171 (reg (ldb (byte 5 8) bad-inst)))
172 (values (case trap-number
173 (#.object-not-list-trap
174 #.(error-number-or-lose 'object-not-list-error))
175 (#.object-not-instance-trap
176 #.(error-number-or-lose 'object-not-instance-error))
178 #.(error-number-or-lose 'unknown-error)))
179 (list (sb!c::make-sc-offset descriptor-reg-sc-number reg)))))