1 ;;; This file contains the PPC specific runtime stuff.
5 (define-alien-type os-context-t
(struct os-context-t-struct
))
10 (defun machine-type ()
11 "Returns a string describing the type of the local machine."
14 ;;;; FIXUP-CODE-OBJECT
16 (defun fixup-code-object (code offset fixup kind
)
17 (declare (type index offset
))
18 (unless (zerop (rem offset n-word-bytes
))
19 (error "Unaligned instruction? offset=#x~X." offset
))
21 (let ((sap (%primitive code-instructions code
)))
24 (error "Can't deal with CALL fixups, yet."))
26 (setf (ldb (byte 24 2) (sap-ref-32 sap offset
))
29 (let* ((h (ldb (byte 16 16) fixup
))
30 (l (ldb (byte 16 0) fixup
)))
31 ; Compensate for possible sign-extension when the low half
32 ; is added to the high. We could avoid this by ORI-ing
33 ; the low half in 32-bit absolute loads, but it'd be
34 ; nice to be able to do:
37 ; and lwz/stw and friends all use a signed 16-bit offset.
38 (setf (ldb (byte 16 0) (sap-ref-32 sap offset
))
39 (if (logbitp 15 l
) (ldb (byte 16 0) (1+ h
)) h
))))
41 (setf (ldb (byte 16 0) (sap-ref-32 sap offset
))
42 (ldb (byte 16 0) fixup
)))))))
45 ;;;; "Sigcontext" access functions, cut & pasted from x86-vm.lisp then
46 ;;;; hacked for types.
48 (define-alien-routine ("os_context_pc_addr" context-pc-addr
) (* unsigned-long
)
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 (defun context-register (context index
)
61 (declare (type (alien (* os-context-t
)) context
))
62 (deref (context-register-addr context index
)))
64 (define-alien-routine ("os_context_lr_addr" context-lr-addr
) (* unsigned-long
)
65 (context (* os-context-t
)))
67 (defun context-lr (context)
68 (declare (type (alien (* os-context-t
)) context
))
69 (int-sap (deref (context-lr-addr context
))))
71 (defun %set-context-register
(context index new
)
72 (declare (type (alien (* os-context-t
)) context
))
73 (setf (deref (context-register-addr context index
))
75 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
76 ;;; register. FORMAT is the type of float to return.
78 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
79 ;;; long is another question. This stuff still needs testing.
81 (define-alien-routine ("os_context_fpregister_addr" context-float-register-addr
)
83 (context (* os-context-t
))
86 (defun context-float-register (context index format
)
87 (declare (type (alien (* os-context-t
)) context
))
88 (coerce (deref (context-float-register-addr context index
)) format
))
90 (defun %set-context-float-register
(context index format new
)
91 (declare (type (alien (* os-context-t
)) context
))
92 (setf (deref (context-float-register-addr context index
))
95 ;;; Given a signal context, return the floating point modes word in
96 ;;; the same format as returned by FLOATING-POINT-MODES.
98 ;;; FIXME: surely this must be accessible somewhere under Darwin? Or
101 (define-alien-routine ("os_context_fp_control" context-floating-point-modes
)
103 (context (* os-context-t
)))
106 ;;;; INTERNAL-ERROR-ARGS.
108 ;;; GIVEN a (POSIX) signal context, extract the internal error
109 ;;; arguments from the instruction stream. This is e.g.
111 ;;; INTERNAL-ERROR-ARGS -- interface.
113 ;;; Given the sigcontext, extract the internal error arguments from the
114 ;;; instruction stream.
116 (defun internal-error-args (context)
117 (declare (type (alien (* os-context-t
)) context
))
118 (let* ((pc (context-pc context
))
119 (bad-inst (sap-ref-32 pc
0))
120 (op (ldb (byte 16 16) bad-inst
)))
121 (declare (type system-area-pointer pc
))
122 (cond ((= op
(logior (ash 3 10) (ash 6 5)))
123 (args-for-unimp-inst context
))
124 ((and (= (ldb (byte 6 10) op
) 3)
125 (= (ldb (byte 5 5) op
) 24))
126 (let* ((regnum (ldb (byte 5 0) op
))
127 (prev (sap-ref-32 (int-sap (- (sap-int pc
) 4)) 0)))
128 (if (and (= (ldb (byte 6 26) prev
) 3)
129 (= (ldb (byte 5 21) prev
) 0))
130 (values (ldb (byte 16 0) prev
)
131 (list (make-sc-offset any-reg-sc-number
132 (ldb (byte 5 16) prev
))))
133 (values #.
(error-number-or-lose
134 'invalid-arg-count-error
)
135 (list (make-sc-offset any-reg-sc-number regnum
))))))
138 (values #.
(error-number-or-lose 'unknown-error
) nil
)))))
140 (defun args-for-unimp-inst (context)
141 (declare (type (alien (* os-context-t
)) context
))
142 (let* ((pc (context-pc context
))
143 (length (sap-ref-8 pc
4))
144 (vector (make-array length
:element-type
'(unsigned-byte 8))))
145 (declare (type system-area-pointer pc
)
146 (type (unsigned-byte 8) length
)
147 (type (simple-array (unsigned-byte 8) (*)) vector
))
148 (copy-ub8-from-system-area pc
5 vector
0 length
)
150 (error-number (read-var-integer vector index
)))
151 (collect ((sc-offsets))
153 (when (>= index length
)
155 (sc-offsets (read-var-integer vector index
)))
156 (values error-number
(sc-offsets))))))