More robust undefined restarts.
[sbcl.git] / src / code / arm64-vm.lisp
blob83826e9eabf79d47122ea1212d9d3898adc40861
1 ;;; This file contains the ARM specific runtime stuff.
2 ;;;
3 (in-package "SB!VM")
5 #-sb-xc-host (progn
6 ;;; See x86-vm.lisp for a description of this.
7 ;;; FIXME: Why is this present in every ARCH-vm.lisp with the the same definition. Is there something like common-vm?
8 (define-alien-type os-context-t (struct os-context-t-struct))
9 \f
10 (defun machine-type ()
11 "Return a string describing the type of the local machine."
12 "ARM64")
13 ) ; end PROGN
15 ;;;; FIXUP-CODE-OBJECT
17 (!with-bigvec-or-sap
18 (defun fixup-code-object (code offset fixup kind)
19 (declare (type index offset))
20 (unless (zerop (rem offset 4))
21 (error "Unaligned instruction? offset=#x~X." offset))
22 (without-gcing
23 (let ((sap (code-instructions code)))
24 (ecase kind
25 (:absolute
26 (setf (sap-ref-word sap offset) fixup))
27 (:cond-branch
28 (setf (ldb (byte 19 5) (sap-ref-32 sap offset))
29 (ash (- fixup (+ (sap-int sap) offset)) -2)))
30 (:uncond-branch
31 (setf (ldb (byte 26 0) (sap-ref-32 sap offset))
32 (ash (- fixup (+ (sap-int sap) offset)) -2))))))))
34 ;;;; "Sigcontext" access functions, cut & pasted from sparc-vm.lisp,
35 ;;;; then modified for ARM.
36 ;;;;
37 ;;;; See also x86-vm for commentary on signed vs unsigned.
39 #-sb-xc-host (progn
40 (define-alien-routine ("os_context_register_addr" context-register-addr)
41 (* unsigned-long)
42 (context (* os-context-t))
43 (index int))
45 (define-alien-routine ("os_context_pc_addr" context-register-pc-addr)
46 (* unsigned-long)
47 (context (* os-context-t)))
48 (define-alien-routine ("os_context_float_register_addr" context-float-register-addr)
49 (* unsigned) (context (* os-context-t)) (index int))
51 ;;; FIXME: Should this and CONTEXT-PC be INLINE to reduce consing?
52 ;;; (Are they used in anything time-critical, or just the debugger?)
53 (defun context-register (context index)
54 (declare (type (alien (* os-context-t)) context))
55 (deref (context-register-addr context index)))
57 (defun %set-context-register (context index new)
58 (declare (type (alien (* os-context-t)) context))
59 (setf (deref (context-register-addr context index))
60 new))
62 (defun context-float-register (context index format)
63 (let ((sap (alien-sap (context-float-register-addr context index))))
64 (ecase format
65 (single-float
66 (sap-ref-single sap 0))
67 (double-float
68 (sap-ref-double sap 0))
69 (complex-single-float
70 (complex (sap-ref-single sap 0)
71 (sap-ref-single sap 4)))
72 (complex-double-float
73 (complex (sap-ref-double sap 0)
74 (sap-ref-double sap 8))))))
76 (defun %set-context-float-register (context index format value)
77 (let ((sap (alien-sap (context-float-register-addr context index))))
78 (ecase format
79 (single-float
80 (setf (sap-ref-single sap 0) value))
81 (double-float
82 (setf (sap-ref-double sap 0) value))
83 (complex-single-float
84 (locally
85 (declare (type (complex single-float) value))
86 (setf (sap-ref-single sap 0) (realpart value)
87 (sap-ref-single sap 4) (imagpart value))))
88 (complex-double-float
89 (locally
90 (declare (type (complex double-float) value))
91 (setf (sap-ref-double sap 0) (realpart value)
92 (sap-ref-double sap 8) (imagpart value)))))))
94 (defun context-pc (context)
95 (declare (type (alien (* os-context-t)) context))
96 (int-sap (deref (context-register-pc-addr context))))
98 ;;;; INTERNAL-ERROR-ARGS.
100 ;;; Given a (POSIX) signal context, extract the internal error
101 ;;; arguments from the instruction stream.
102 (defun internal-error-args (context)
103 (declare (type (alien (* os-context-t)) context))
104 (let* ((pc (context-pc context))
105 (instruction (sap-ref-32 pc 0))
106 (error-number (ldb (byte 8 13) instruction)))
107 (declare (type system-area-pointer pc))
108 (values error-number
109 (if (= (ldb (byte 8 5) instruction) invalid-arg-count-trap)
110 '(#.arg-count-sc)
111 (sb!kernel::decode-internal-error-args (sap+ pc 4) error-number)))))
112 ) ; end PROGN