1 ;;; This file contains the PPC specific runtime stuff.
7 "Returns a string describing the type of the local machine."
10 ;;;; FIXUP-CODE-OBJECT
13 (defun fixup-code-object (code offset fixup kind
)
14 (declare (type index offset
))
15 (unless (zerop (rem offset n-word-bytes
))
16 (error "Unaligned instruction? offset=#x~X." offset
))
18 (let ((sap (code-instructions code
)))
21 (setf (sap-ref-32 sap offset
) fixup
))
23 (error "Can't deal with CALL fixups, yet."))
25 (setf (ldb (byte 24 2) (sap-ref-32 sap offset
))
28 (let* ((h (ldb (byte 16 16) fixup
))
29 (l (ldb (byte 16 0) fixup
)))
30 ; Compensate for possible sign-extension when the low half
31 ; is added to the high. We could avoid this by ORI-ing
32 ; the low half in 32-bit absolute loads, but it'd be
33 ; nice to be able to do:
36 ; and lwz/stw and friends all use a signed 16-bit offset.
37 (setf (ldb (byte 16 0) (sap-ref-32 sap offset
))
38 (if (logbitp 15 l
) (ldb (byte 16 0) (1+ h
)) h
))))
40 (setf (ldb (byte 16 0) (sap-ref-32 sap offset
))
41 (ldb (byte 16 0) fixup
))))))))
44 ;;;; "Sigcontext" access functions, cut & pasted from x86-vm.lisp then
45 ;;;; hacked for types.
48 (define-alien-routine ("os_context_lr_addr" context-lr-addr
) (* unsigned-long
)
49 (context (* os-context-t
)))
51 (defun context-lr (context)
52 (declare (type (alien (* os-context-t
)) context
))
53 (int-sap (deref (context-lr-addr context
))))
54 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
55 ;;; register. FORMAT is the type of float to return.
57 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
58 ;;; long is another question. This stuff still needs testing.
60 (define-alien-routine ("os_context_fpregister_addr" context-float-register-addr
)
62 (context (* os-context-t
))
65 (defun context-float-register (context index format
)
66 (declare (type (alien (* os-context-t
)) context
))
67 (coerce (deref (context-float-register-addr context index
)) format
))
69 (defun %set-context-float-register
(context index format new
)
70 (declare (type (alien (* os-context-t
)) context
))
71 (setf (deref (context-float-register-addr context index
))
74 ;;; Given a signal context, return the floating point modes word in
75 ;;; the same format as returned by FLOATING-POINT-MODES.
77 ;;; FIXME: surely this must be accessible somewhere under Darwin? Or
80 (define-alien-routine ("os_context_fp_control" context-floating-point-modes
)
82 (context (* os-context-t
)))
85 ;;;; INTERNAL-ERROR-ARGS.
87 ;;; GIVEN a (POSIX) signal context, extract the internal error
88 ;;; arguments from the instruction stream. This is e.g.
90 ;;; INTERNAL-ERROR-ARGS -- interface.
92 ;;; Given the sigcontext, extract the internal error arguments from the
93 ;;; instruction stream.
95 (defun internal-error-args (context)
96 (declare (type (alien (* os-context-t
)) context
))
97 (let* ((pc (context-pc context
))
98 (bad-inst (sap-ref-32 pc
0))
99 (op (ldb (byte 16 16) bad-inst
))
100 (regnum (ldb (byte 5 0) op
)))
101 (declare (type system-area-pointer pc
))
102 (cond ((= op
(logior (ash 3 10) (ash 6 5)))
103 (let ((error-number (sap-ref-8 pc
4)))
105 (sb!kernel
::decode-internal-error-args
(sap+ pc
5) error-number
))))
106 #!-precise-arg-count-error
107 ((and (= (ldb (byte 6 10) op
) 3)
108 (= (ldb (byte 5 5) op
) 24))
109 (let ((prev (sap-ref-32 (int-sap (- (sap-int pc
) 4)) 0)))
110 (if (and (= (ldb (byte 6 26) prev
) 3)
111 (= (ldb (byte 5 21) prev
) 0))
112 (values (ldb (byte 16 0) prev
)
113 (list (make-sc-offset any-reg-sc-number
114 (ldb (byte 5 16) prev
))))
115 (values #.
(error-number-or-lose
116 'invalid-arg-count-error
)
117 (list (make-sc-offset any-reg-sc-number regnum
))))))
118 #!+precise-arg-count-error
119 ((and (= (ldb (byte 6 10) op
) 3) ;; twi
120 (or (= regnum
#.
(sc-offset-offset arg-count-sc
))
121 (= (ldb (byte 5 5) op
) 24))) ;; :ne
122 ;; Type errors are encoded as
123 ;; twi 0 value-register error-code
124 ;; twi :ne temp-register x
125 (let ((prev (sap-ref-32 (int-sap (- (sap-int pc
) 4)) 0)))
126 (if (and (= (ldb (byte 5 5) op
) 24) ;; is the condition :ne?
127 (= (ldb (byte 6 26) prev
) 3) ;; is it twi?
128 (= (ldb (byte 5 21) prev
) 0)) ;; is it non-trapping?
129 (values (ldb (byte 16 0) prev
)
130 (list (make-sc-offset any-reg-sc-number
131 (ldb (byte 5 16) prev
))))
132 ;; arg-count errors are encoded as
133 ;; twi {:ne :llt :lgt} nargs arg-count
134 (values #.
(error-number-or-lose 'invalid-arg-count-error
)
135 '(#.arg-count-sc
)))))
137 (values #.
(error-number-or-lose 'unknown-error
) nil
)))))