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.
49 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
50 ;;; register. FORMAT is the type of float to return.
52 ;;; FIXME: Whether COERCE actually knows how to make a float out of a
53 ;;; long is another question. This stuff still needs testing.
55 (define-alien-routine ("os_context_fpregister_addr" context-float-register-addr
)
57 (context (* os-context-t
))
60 (defun context-float-register (context index format
)
61 (declare (type (alien (* os-context-t
)) context
))
62 (coerce (deref (context-float-register-addr context index
)) format
))
64 (defun %set-context-float-register
(context index format new
)
65 (declare (type (alien (* os-context-t
)) context
))
66 (setf (deref (context-float-register-addr context index
))
69 ;;; Given a signal context, return the floating point modes word in
70 ;;; the same format as returned by FLOATING-POINT-MODES.
72 ;;; FIXME: surely this must be accessible somewhere under Darwin? Or
75 (define-alien-routine ("os_context_fp_control" context-floating-point-modes
)
77 (context (* os-context-t
)))
80 ;;;; INTERNAL-ERROR-ARGS.
82 ;;; GIVEN a (POSIX) signal context, extract the internal error
83 ;;; arguments from the instruction stream. This is e.g.
85 ;;; INTERNAL-ERROR-ARGS -- interface.
87 ;;; Given the sigcontext, extract the internal error arguments from the
88 ;;; instruction stream.
90 (defun internal-error-args (context)
91 (declare (type (alien (* os-context-t
)) context
))
92 (let* ((pc (context-pc context
))
93 (bad-inst (sap-ref-32 pc
0))
94 (op (ldb (byte 16 16) bad-inst
))
95 (regnum (ldb (byte 5 0) op
)))
96 (declare (type system-area-pointer pc
))
97 (cond ((= op
(logior (ash 3 10) (ash 6 5)))
98 (let ((error-number (sap-ref-8 pc
4)))
100 (sb!kernel
::decode-internal-error-args
(sap+ pc
5) error-number
))))
101 #!-precise-arg-count-error
102 ((and (= (ldb (byte 6 10) op
) 3)
103 (= (ldb (byte 5 5) op
) 24))
104 (let ((prev (sap-ref-32 (int-sap (- (sap-int pc
) 4)) 0)))
105 (if (and (= (ldb (byte 6 26) prev
) 3)
106 (= (ldb (byte 5 21) prev
) 0))
107 (values (ldb (byte 16 0) prev
)
108 (list (make-sc-offset any-reg-sc-number
109 (ldb (byte 5 16) prev
))))
110 (values #.
(error-number-or-lose
111 'invalid-arg-count-error
)
112 (list (make-sc-offset any-reg-sc-number regnum
))))))
113 #!+precise-arg-count-error
114 ((and (= (ldb (byte 6 10) op
) 3) ;; twi
115 (or (= regnum
#.
(sc-offset-offset arg-count-sc
))
116 (= (ldb (byte 5 5) op
) 24))) ;; :ne
117 ;; Type errors are encoded as
118 ;; twi 0 value-register error-code
119 ;; twi :ne temp-register x
120 (let ((prev (sap-ref-32 (int-sap (- (sap-int pc
) 4)) 0)))
121 (if (and (= (ldb (byte 5 5) op
) 24) ;; is the condition :ne?
122 (= (ldb (byte 6 26) prev
) 3) ;; is it twi?
123 (= (ldb (byte 5 21) prev
) 0)) ;; is it non-trapping?
124 (values (ldb (byte 16 0) prev
)
125 (list (make-sc-offset any-reg-sc-number
126 (ldb (byte 5 16) prev
))))
127 ;; arg-count errors are encoded as
128 ;; twi {:ne :llt :lgt} nargs arg-count
129 (values #.
(error-number-or-lose 'invalid-arg-count-error
)
130 '(#.arg-count-sc
)))))
132 (values #.
(error-number-or-lose 'unknown-error
) nil
)))))