run-program: support I/O redirection to binary streams on win32.
[sbcl.git] / src / code / sparc-vm.lisp
blobf2342bdc795f0d4d6fafcb669cb67f5bc040f32d
1 ;;;; SPARC-specific runtime stuff
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
11 (in-package "SB!VM")
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
18 (defun machine-type ()
19 "Returns a string describing the type of the local machine."
20 "SPARC")
22 (defun fixup-code-object (code offset fixup kind)
23 (declare (type index offset))
24 (unless (zerop (rem offset n-word-bytes))
25 (error "Unaligned instruction? offset=#x~X." offset))
26 (without-gcing
27 (let ((sap (%primitive code-instructions code)))
28 (ecase kind
29 (:call
30 (error "Can't deal with CALL fixups, yet."))
31 (:sethi
32 (setf (ldb (byte 22 0) (sap-ref-32 sap offset))
33 (ldb (byte 22 10) fixup)))
34 (:add
35 (setf (ldb (byte 10 0) (sap-ref-32 sap offset))
36 (ldb (byte 10 0) fixup)))))))
39 ;;;; "Sigcontext" access functions, cut & pasted from alpha-vm.lisp.
40 ;;;;
41 ;;;; See also x86-vm for commentary on signed vs unsigned.
43 (define-alien-routine ("os_context_pc_addr" context-pc-addr) (* unsigned-int)
44 (context (* os-context-t)))
46 (defun context-pc (context)
47 (declare (type (alien (* os-context-t)) context))
48 (int-sap (deref (context-pc-addr context))))
50 (define-alien-routine ("os_context_register_addr" context-register-addr)
51 (* unsigned-int)
52 (context (* os-context-t))
53 (index int))
55 ;;; FIXME: Should this and CONTEXT-PC be INLINE to reduce consing?
56 ;;; (Are they used in anything time-critical, or just the debugger?)
57 (defun context-register (context index)
58 (declare (type (alien (* os-context-t)) context))
59 (deref (context-register-addr context index)))
61 (defun %set-context-register (context index new)
62 (declare (type (alien (* os-context-t)) context))
63 (setf (deref (context-register-addr context index))
64 new))
66 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
67 ;;; register. FORMAT is the type of float to return.
69 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
70 ;;; long is another question. This stuff still needs testing.
71 #+nil
72 (define-alien-routine ("os_context_float_register_addr" context-float-register-addr)
73 (* long)
74 (context (* os-context-t))
75 (index int))
76 #+nil
77 (defun context-float-register (context index format)
78 (declare (type (alien (* os-context-t)) context))
79 (coerce (deref (context-float-register-addr context index)) format))
80 #+nil
81 (defun %set-context-float-register (context index format new)
82 (declare (type (alien (* os-context-t)) context))
83 (setf (deref (context-float-register-addr context index))
84 (coerce new format)))
86 ;;; Given a signal context, return the floating point modes word in
87 ;;; the same format as returned by FLOATING-POINT-MODES.
89 ;;; Under SunOS, we have a straightforward implementation in C:
90 #!+sunos
91 (define-alien-routine ("os_context_fp_control" context-floating-point-modes)
92 (unsigned 32)
93 (context (* os-context-t)))
95 ;;; Under Linux, we have to contend with utterly broken signal handling.
96 #!+linux
97 (defun context-floating-point-modes (context)
98 (declare (ignore context))
99 (warn "stub CONTEXT-FLOATING-POINT-MODES")
102 ;;;; INTERNAL-ERROR-ARGS.
104 ;;; Given a (POSIX) signal context, extract the internal error
105 ;;; arguments from the instruction stream. This is e.g.
106 ;;; 4 23 254 240 2 0 0 0
107 ;;; | ~~~~~~~~~~~~~~~~~~~~~~~~~
108 ;;; length data (everything is an octet)
109 ;;; (pc)
110 (defun internal-error-args (context)
111 (declare (type (alien (* os-context-t)) context))
112 (sb!int::/show0 "entering INTERNAL-ERROR-ARGS")
113 (let* ((pc (context-pc context))
114 (bad-inst (sap-ref-32 pc 0))
115 (op (ldb (byte 2 30) bad-inst))
116 (op2 (ldb (byte 3 22) bad-inst))
117 (op3 (ldb (byte 6 19) bad-inst)))
118 (declare (type system-area-pointer pc))
119 (cond ((and (= op #b00) (= op2 #b000))
120 (args-for-unimp-inst context))
121 ((and (= op #b10) (= (ldb (byte 4 2) op3) #b1000))
122 (args-for-tagged-add-inst context bad-inst))
123 ((and (= op #b10) (= op3 #b111010))
124 (args-for-tcc-inst bad-inst))
126 (values #.(error-number-or-lose 'unknown-error) nil)))))
128 (defun args-for-unimp-inst (context)
129 (declare (type (alien (* os-context-t)) context))
130 (let* ((pc (context-pc context))
131 (length (sap-ref-8 pc 4))
132 (vector (make-array length :element-type '(unsigned-byte 8))))
133 (declare (type system-area-pointer pc)
134 (type (unsigned-byte 8) length)
135 (type (simple-array (unsigned-byte 8) (*)) vector))
136 (copy-ub8-from-system-area pc 5 vector 0 length)
137 (let* ((index 0)
138 (error-number (sb!c:read-var-integer vector index)))
139 (collect ((sc-offsets))
140 (loop
141 (when (>= index length)
142 (return))
143 (sc-offsets (sb!c:read-var-integer vector index)))
144 (values error-number (sc-offsets))))))
146 (defun args-for-tagged-add-inst (context bad-inst)
147 (declare (type (alien (* os-context-t)) context))
148 (let* ((rs1 (ldb (byte 5 14) bad-inst))
149 (op1 (make-lisp-obj (context-register context rs1))))
150 (if (fixnump op1)
151 (if (zerop (ldb (byte 1 13) bad-inst))
152 (let* ((rs2 (ldb (byte 5 0) bad-inst))
153 (op2 (make-lisp-obj (context-register context rs2))))
154 (if (fixnump op2)
155 (values #.(error-number-or-lose 'unknown-error) nil)
156 (values #.(error-number-or-lose 'object-not-fixnum-error)
157 (list (sb!c::make-sc-offset
158 descriptor-reg-sc-number
159 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 descriptor-reg-sc-number
163 rs1))))))
165 (defun args-for-tcc-inst (bad-inst)
166 (let* ((trap-number (ldb (byte 8 0) bad-inst))
167 (reg (ldb (byte 5 8) bad-inst)))
168 (values (case trap-number
169 (#.object-not-list-trap
170 #.(error-number-or-lose 'object-not-list-error))
171 (#.object-not-instance-trap
172 #.(error-number-or-lose 'object-not-instance-error))
174 #.(error-number-or-lose 'unknown-error)))
175 (list (sb!c::make-sc-offset descriptor-reg-sc-number reg)))))