5573841a759b6f8ae9aad6b3746829b009d60826
[sbcl.git] / src / code / hppa-vm.lisp
1 (in-package "SB!VM")
2 \f
3 (define-alien-type os-context-t (struct os-context-t-struct))
4 \f
5 ;;;; MACHINE-TYPE and MACHINE-VERSION
6
7 (defun machine-type ()
8   "Returns a string describing the type of the local machine."
9   "HPPA")
10
11 ;;; support for CL:MACHINE-VERSION defined OAOO elsewhere
12 (defun get-machine-version ()
13   nil)
14 \f
15 ;;;; FIXUP-CODE-OBJECT
16 ;FIX-lav: unify code with genesis.lisp fixup
17 (defun fixup-code-object (code offset value kind)
18   (unless (zerop (rem offset n-word-bytes))
19     (error "Unaligned instruction?  offset=#x~X." offset))
20   (sb!sys:without-gcing
21    (let* ((sap (%primitive sb!kernel::code-instructions code))
22           (inst (sap-ref-32 sap offset)))
23      (setf (sap-ref-32 sap offset)
24            (ecase kind
25              (:load
26               (logior (mask-field (byte 18 14) value)
27                       (if (< value 0)
28                         (1+ (ash (ldb (byte 13 0) value) 1))
29                         (ash (ldb (byte 13 0) value) 1))))
30              (:load11u
31               (logior (if (< value 0)
32                           (1+ (ash (ldb (byte 10 0) value) 1))
33                           (ash (ldb (byte 11 0) value) 1))
34                       (mask-field (byte 18 14) inst)))
35              (:load-short
36               (let ((low-bits (ldb (byte 11 0) value)))
37                 (aver (<= 0 low-bits (1- (ash 1 4))))
38                 (logior (ash (dpb (ldb (byte 4 0) value)
39                                   (byte 4 1)
40                                   (ldb (byte 1 4) value)) 17)
41                         (logand inst #xffe0ffff))))
42              (:hi
43               (logior (ash (ldb (byte 5 13) value) 16)
44                       (ash (ldb (byte 2 18) value) 14)
45                       (ash (ldb (byte 2 11) value) 12)
46                       (ash (ldb (byte 11 20) value) 1)
47                       (ldb (byte 1 31) value)
48                       (logand inst #xffe00000)))
49              (:branch
50               (let ((bits (ldb (byte 9 2) value)))
51                 (aver (zerop (ldb (byte 2 0) value)))
52                 (logior (ash bits 3)
53                         (mask-field (byte 1 1) inst)
54                         (mask-field (byte 3 13) inst)
55                         (mask-field (byte 11 21) inst)))))))))
56 \f
57 (define-alien-routine ("os_context_pc_addr" context-pc-addr) (* unsigned-int)
58   (context (* os-context-t)))
59
60 (defun context-pc (context)
61   (declare (type (alien (* os-context-t)) context))
62   (int-sap (logandc2 (deref (context-pc-addr context)) 3)))
63
64 (define-alien-routine ("os_context_register_addr" context-register-addr)
65   (* unsigned-int)
66   (context (* os-context-t))
67   (index int))
68
69 ;;; FIXME: Should this and CONTEXT-PC be INLINE to reduce consing?
70 ;;; (Are they used in anything time-critical, or just the debugger?)
71 (defun context-register (context index)
72   (declare (type (alien (* os-context-t)) context))
73   (deref (context-register-addr context index)))
74
75 (defun %set-context-register (context index new)
76 (declare (type (alien (* os-context-t)) context))
77 (setf (deref (context-register-addr context index))
78       new))
79
80 #!+linux
81 ;;; For now.
82 (defun context-floating-point-modes (context)
83   (warn "stub CONTEXT-FLOATING-POINT-MODES")
84   0)
85
86 ;;;; Internal-error-arguments.
87
88 ;;; INTERNAL-ERROR-ARGUMENTS -- interface.
89 ;;;
90 ;;; Given the sigcontext, extract the internal error arguments from the
91 ;;; instruction stream.
92 ;;;
93 (defun internal-error-args (context)
94   (declare (type (alien (* os-context-t)) context))
95   (let ((pc (context-pc context)))
96     (declare (type system-area-pointer pc))
97     (let* ((length (sap-ref-8 pc 4))
98            (vector (make-array length :element-type '(unsigned-byte 8))))
99       (declare (type (unsigned-byte 8) length)
100                (type (simple-array (unsigned-byte 8) (*)) vector))
101       (copy-ub8-from-system-area pc 5 vector 0 length)
102       (let* ((index 0)
103              (error-number (sb!c:read-var-integer vector index)))
104         (collect ((sc-offsets))
105          (loop
106           (when (>= index length)
107             (return))
108           (sc-offsets (sb!c:read-var-integer vector index)))
109          (values error-number (sc-offsets)))))))