1 ;;; This file contains the PPC specific runtime stuff.
5 (defvar *number-of-signals* 64)
6 (defvar *bits-per-word* 32)
8 (define-alien-type os-context-t (struct os-context-t-struct))
11 ;;;; MACHINE-TYPE and MACHINE-VERSION
13 (defun machine-type ()
14 "Returns a string describing the type of the local machine."
17 (defun machine-version ()
18 "Returns a string describing the version of the local machine."
23 ;;; FIXUP-CODE-OBJECT -- Interface
25 (defun fixup-code-object (code offset fixup kind)
26 (declare (type index offset))
27 (unless (zerop (rem offset n-word-bytes))
28 (error "Unaligned instruction? offset=#x~X." offset))
30 (let ((sap (truly-the system-area-pointer
31 (%primitive sb!kernel::code-instructions code))))
34 (error "Can't deal with CALL fixups, yet."))
36 (setf (ldb (byte 24 2) (sap-ref-32 sap offset))
39 (let* ((h (ldb (byte 16 16) fixup))
40 (l (ldb (byte 16 0) fixup)))
41 ; Compensate for possible sign-extension when the low half
42 ; is added to the high. We could avoid this by ORI-ing
43 ; the low half in 32-bit absolute loads, but it'd be
44 ; nice to be able to do:
47 ; and lwz/stw and friends all use a signed 16-bit offset.
48 (setf (ldb (byte 16 0) (sap-ref-32 sap offset))
49 (if (logbitp 15 l) (ldb (byte 16 0) (1+ h)) h))))
51 (setf (ldb (byte 16 0) (sap-ref-32 sap offset))
52 (ldb (byte 16 0) fixup)))))))
55 ;;;; "Sigcontext" access functions, cut & pasted from x86-vm.lisp then
56 ;;;; hacked for types.
58 (define-alien-routine ("os_context_pc_addr" context-pc-addr) (* unsigned-long)
59 (context (* os-context-t)))
61 (defun context-pc (context)
62 (declare (type (alien (* os-context-t)) context))
63 (int-sap (deref (context-pc-addr context))))
65 (define-alien-routine ("os_context_register_addr" context-register-addr)
67 (context (* os-context-t))
70 (defun context-register (context index)
71 (declare (type (alien (* os-context-t)) context))
72 (deref (context-register-addr context index)))
74 (defun %set-context-register (context index new)
75 (declare (type (alien (* os-context-t)) context))
76 (setf (deref (context-register-addr context index))
78 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
79 ;;; register. FORMAT is the type of float to return.
81 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
82 ;;; long is another question. This stuff still needs testing.
84 (define-alien-routine ("os_context_fpregister_addr" context-float-register-addr)
86 (context (* os-context-t))
89 (defun context-float-register (context index format)
90 (declare (type (alien (* os-context-t)) context))
91 (coerce (deref (context-float-register-addr context index)) format))
93 (defun %set-context-float-register (context index format new)
94 (declare (type (alien (* os-context-t)) context))
95 (setf (deref (context-float-register-addr context index))
98 ;;; Given a signal context, return the floating point modes word in
99 ;;; the same format as returned by FLOATING-POINT-MODES.
100 (defun context-floating-point-modes (context)
101 ;; FIXME: As of sbcl-0.6.7 and the big rewrite of signal handling
102 ;; for POSIXness and (at the Lisp level) opaque signal contexts,
103 ;; this is needs to be rewritten as an alien function.
104 (warn "stub CONTEXT-FLOATING-POINT-MODES")
109 ;;;; INTERNAL-ERROR-ARGS.
111 ;;; GIVEN a (POSIX) signal context, extract the internal error
112 ;;; arguments from the instruction stream. This is e.g.
114 ;;; INTERNAL-ERROR-ARGS -- interface.
116 ;;; Given the sigcontext, extract the internal error arguments from the
117 ;;; instruction stream.
119 (defun internal-error-args (context)
120 (declare (type (alien (* os-context-t)) context))
121 (let* ((pc (context-pc context))
122 (bad-inst (sap-ref-32 pc 0))
123 (op (ldb (byte 16 16) bad-inst)))
124 (declare (type system-area-pointer pc))
125 (cond ((= op (logior (ash 3 10) (ash 6 5)))
126 (args-for-unimp-inst context))
127 ((and (= (ldb (byte 6 10) op) 3)
128 (= (ldb (byte 5 5) op) 24))
129 (let* ((regnum (ldb (byte 5 0) op))
130 (prev (sap-ref-32 (int-sap (- (sap-int pc) 4)) 0)))
131 (if (and (= (ldb (byte 6 26) prev) 3)
132 (= (ldb (byte 5 21) prev) 0))
133 (values (ldb (byte 16 0) prev)
134 (list (sb!c::make-sc-offset sb!vm:any-reg-sc-number
135 (ldb (byte 5 16) prev))))
136 (values #.(sb!kernel:error-number-or-lose
137 'sb!kernel:invalid-arg-count-error)
138 (list (sb!c::make-sc-offset sb!vm:any-reg-sc-number regnum))))))
141 (values #.(error-number-or-lose 'unknown-error) nil)))))
143 (defun args-for-unimp-inst (context)
144 (declare (type (alien (* os-context-t)) context))
145 (let* ((pc (context-pc context))
146 (length (sap-ref-8 pc 4))
147 (vector (make-array length :element-type '(unsigned-byte 8))))
148 (declare (type system-area-pointer pc)
149 (type (unsigned-byte 8) length)
150 (type (simple-array (unsigned-byte 8) (*)) vector))
151 (copy-from-system-area pc (* sb!vm:n-byte-bits 5)
152 vector (* sb!vm:n-word-bits
153 sb!vm:vector-data-offset)
154 (* length sb!vm:n-byte-bits))
156 (error-number (sb!c::read-var-integer vector index)))
157 (collect ((sc-offsets))
159 (when (>= index length)
161 (sc-offsets (sb!c::read-var-integer vector index)))
162 (values error-number (sc-offsets))))))
166 ;;; The loader uses this to convert alien names to the form they
167 ;;; occur in the symbol table. This is ELF, so do nothing
169 (defun extern-alien-name (name)
170 (declare (type simple-base-string name))
175 ;;; SANCTIFY-FOR-EXECUTION -- Interface.
177 ;;; Do whatever is necessary to make the given code component executable.
178 ;;; On the 601, we have less to do than on some other PowerPC chips.
179 ;;; This should what needs to be done in the general case.
181 (defun sanctify-for-execution (component)
183 (alien-funcall (extern-alien "ppc_flush_icache"
187 (code-instructions component)
188 (* (code-header-ref component code-code-size-slot)