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 (regnum (ldb (byte 5 0) op
)))
122 (declare (type system-area-pointer pc
))
123 (cond ((= op
(logior (ash 3 10) (ash 6 5)))
124 (args-for-unimp-inst context
))
125 #!-precise-arg-count-error
126 ((and (= (ldb (byte 6 10) op
) 3)
127 (= (ldb (byte 5 5) op
) 24))
128 (let ((prev (sap-ref-32 (int-sap (- (sap-int pc
) 4)) 0)))
129 (if (and (= (ldb (byte 6 26) prev
) 3)
130 (= (ldb (byte 5 21) prev
) 0))
131 (values (ldb (byte 16 0) prev
)
132 (list (make-sc-offset any-reg-sc-number
133 (ldb (byte 5 16) prev
))))
134 (values #.
(error-number-or-lose
135 'invalid-arg-count-error
)
136 (list (make-sc-offset any-reg-sc-number regnum
))))))
137 #!+precise-arg-count-error
138 ((and (= (ldb (byte 6 10) op
) 3) ;; twi
139 (or (= regnum
#.
(sc-offset-offset arg-count-sc
))
140 (= (ldb (byte 5 5) op
) 24))) ;; :ne
141 ;; Type errors are encoded as
142 ;; twi 0 value-register error-code
143 ;; twi :ne temp-register x
144 (let ((prev (sap-ref-32 (int-sap (- (sap-int pc
) 4)) 0)))
145 (if (and (= (ldb (byte 5 5) op
) 24) ;; is the condition :ne?
146 (= (ldb (byte 6 26) prev
) 3) ;; is it twi?
147 (= (ldb (byte 5 21) prev
) 0)) ;; is it non-trapping?
148 (values (ldb (byte 16 0) prev
)
149 (list (make-sc-offset any-reg-sc-number
150 (ldb (byte 5 16) prev
))))
151 ;; arg-count errors are encoded as
152 ;; twi {:ne :llt :lgt} nargs arg-count
153 (values #.
(error-number-or-lose 'invalid-arg-count-error
)
154 '(#.arg-count-sc
)))))
156 (values #.
(error-number-or-lose 'unknown-error
) nil
)))))
158 (defun args-for-unimp-inst (context)
159 (declare (type (alien (* os-context-t
)) context
))
160 (let* ((pc (context-pc context
))
161 (length (sap-ref-8 pc
4))
162 (vector (make-array length
:element-type
'(unsigned-byte 8))))
163 (declare (type system-area-pointer pc
)
164 (type (unsigned-byte 8) length
)
165 (type (simple-array (unsigned-byte 8) (*)) vector
))
166 (copy-ub8-from-system-area pc
5 vector
0 length
)
168 (error-number (read-var-integer vector index
)))
169 (collect ((sc-offsets))
171 (when (>= index length
)
173 (sc-offsets (read-var-integer vector index
)))
174 (values error-number
(sc-offsets))))))