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 (setf (sap-ref-32 sap offset
) fixup
))
26 (error "Can't deal with CALL fixups, yet."))
28 (setf (ldb (byte 24 2) (sap-ref-32 sap offset
))
31 (let* ((h (ldb (byte 16 16) fixup
))
32 (l (ldb (byte 16 0) fixup
)))
33 ; Compensate for possible sign-extension when the low half
34 ; is added to the high. We could avoid this by ORI-ing
35 ; the low half in 32-bit absolute loads, but it'd be
36 ; nice to be able to do:
39 ; and lwz/stw and friends all use a signed 16-bit offset.
40 (setf (ldb (byte 16 0) (sap-ref-32 sap offset
))
41 (if (logbitp 15 l
) (ldb (byte 16 0) (1+ h
)) h
))))
43 (setf (ldb (byte 16 0) (sap-ref-32 sap offset
))
44 (ldb (byte 16 0) fixup
)))))))
47 ;;;; "Sigcontext" access functions, cut & pasted from x86-vm.lisp then
48 ;;;; hacked for types.
50 (define-alien-routine ("os_context_pc_addr" context-pc-addr
) (* unsigned-long
)
51 (context (* os-context-t
)))
53 (defun context-pc (context)
54 (declare (type (alien (* os-context-t
)) context
))
55 (int-sap (deref (context-pc-addr context
))))
57 (define-alien-routine ("os_context_register_addr" context-register-addr
)
59 (context (* os-context-t
))
62 (defun context-register (context index
)
63 (declare (type (alien (* os-context-t
)) context
))
64 (deref (context-register-addr context index
)))
66 (define-alien-routine ("os_context_lr_addr" context-lr-addr
) (* unsigned-long
)
67 (context (* os-context-t
)))
69 (defun context-lr (context)
70 (declare (type (alien (* os-context-t
)) context
))
71 (int-sap (deref (context-lr-addr context
))))
73 (defun %set-context-register
(context index new
)
74 (declare (type (alien (* os-context-t
)) context
))
75 (setf (deref (context-register-addr context index
))
77 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
78 ;;; register. FORMAT is the type of float to return.
80 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
81 ;;; long is another question. This stuff still needs testing.
83 (define-alien-routine ("os_context_fpregister_addr" context-float-register-addr
)
85 (context (* os-context-t
))
88 (defun context-float-register (context index format
)
89 (declare (type (alien (* os-context-t
)) context
))
90 (coerce (deref (context-float-register-addr context index
)) format
))
92 (defun %set-context-float-register
(context index format new
)
93 (declare (type (alien (* os-context-t
)) context
))
94 (setf (deref (context-float-register-addr context index
))
97 ;;; Given a signal context, return the floating point modes word in
98 ;;; the same format as returned by FLOATING-POINT-MODES.
100 ;;; FIXME: surely this must be accessible somewhere under Darwin? Or
103 (define-alien-routine ("os_context_fp_control" context-floating-point-modes
)
105 (context (* os-context-t
)))
108 ;;;; INTERNAL-ERROR-ARGS.
110 ;;; GIVEN a (POSIX) signal context, extract the internal error
111 ;;; arguments from the instruction stream. This is e.g.
113 ;;; INTERNAL-ERROR-ARGS -- interface.
115 ;;; Given the sigcontext, extract the internal error arguments from the
116 ;;; instruction stream.
118 (defun internal-error-args (context)
119 (declare (type (alien (* os-context-t
)) context
))
120 (let* ((pc (context-pc context
))
121 (bad-inst (sap-ref-32 pc
0))
122 (op (ldb (byte 16 16) bad-inst
))
123 (regnum (ldb (byte 5 0) op
)))
124 (declare (type system-area-pointer pc
))
125 (cond ((= op
(logior (ash 3 10) (ash 6 5)))
126 (let ((error-number (sap-ref-8 pc
4)))
128 (sb!kernel
::decode-internal-error-args
(sap+ pc
5) error-number
))))
129 #!-precise-arg-count-error
130 ((and (= (ldb (byte 6 10) op
) 3)
131 (= (ldb (byte 5 5) op
) 24))
132 (let ((prev (sap-ref-32 (int-sap (- (sap-int pc
) 4)) 0)))
133 (if (and (= (ldb (byte 6 26) prev
) 3)
134 (= (ldb (byte 5 21) prev
) 0))
135 (values (ldb (byte 16 0) prev
)
136 (list (make-sc-offset any-reg-sc-number
137 (ldb (byte 5 16) prev
))))
138 (values #.
(error-number-or-lose
139 'invalid-arg-count-error
)
140 (list (make-sc-offset any-reg-sc-number regnum
))))))
141 #!+precise-arg-count-error
142 ((and (= (ldb (byte 6 10) op
) 3) ;; twi
143 (or (= regnum
#.
(sc-offset-offset arg-count-sc
))
144 (= (ldb (byte 5 5) op
) 24))) ;; :ne
145 ;; Type errors are encoded as
146 ;; twi 0 value-register error-code
147 ;; twi :ne temp-register x
148 (let ((prev (sap-ref-32 (int-sap (- (sap-int pc
) 4)) 0)))
149 (if (and (= (ldb (byte 5 5) op
) 24) ;; is the condition :ne?
150 (= (ldb (byte 6 26) prev
) 3) ;; is it twi?
151 (= (ldb (byte 5 21) prev
) 0)) ;; is it non-trapping?
152 (values (ldb (byte 16 0) prev
)
153 (list (make-sc-offset any-reg-sc-number
154 (ldb (byte 5 16) prev
))))
155 ;; arg-count errors are encoded as
156 ;; twi {:ne :llt :lgt} nargs arg-count
157 (values #.
(error-number-or-lose 'invalid-arg-count-error
)
158 '(#.arg-count-sc
)))))
160 (values #.
(error-number-or-lose 'unknown-error
) nil
)))))