Remove some test noise. A drop in the ocean unfortunately.
[sbcl.git] / src / code / x86-64-vm.lisp
blobe794e4bdcdf2536ce4fd6c456a4a57c520deefee
1 ;;;; X86-64-specific runtime stuff
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!VM")
14 ;;;; OS-CONTEXT-T
16 ;;; a POSIX signal context, i.e. the type passed as the third
17 ;;; argument to an SA_SIGACTION-style signal handler
18 ;;;
19 ;;; The real type does have slots, but at Lisp level, we never
20 ;;; access them, or care about the size of the object. Instead, we
21 ;;; always refer to these objects by pointers handed to us by the C
22 ;;; runtime library, and ask the runtime library any time we need
23 ;;; information about the contents of one of these objects. Thus, it
24 ;;; works to represent this as an object with no slots.
25 ;;;
26 ;;; KLUDGE: It would be nice to have a type definition analogous to
27 ;;; C's "struct os_context_t;", for an incompletely specified object
28 ;;; which can only be referred to by reference, but I don't know how
29 ;;; to do that in the FFI, so instead we just this bogus no-slots
30 ;;; representation. -- WHN 20000730
31 ;;;
32 ;;; FIXME: Since SBCL, unlike CMU CL, uses this as an opaque type,
33 ;;; it's no longer architecture-dependent, and probably belongs in
34 ;;; some other package, perhaps SB-KERNEL.
35 (define-alien-type os-context-t (struct os-context-t-struct))
37 ;;;; MACHINE-TYPE
39 (defun machine-type ()
40 #!+sb-doc
41 "Return a string describing the type of the local machine."
42 "X86-64")
44 ;;;; :CODE-OBJECT fixups
46 ;;; This gets called by LOAD to resolve newly positioned objects
47 ;;; with things (like code instructions) that have to refer to them.
48 (defun fixup-code-object (code offset fixup kind)
49 (declare (type index offset))
50 (without-gcing
51 (let ((sap (truly-the system-area-pointer
52 (code-instructions code))))
53 (unless (member kind '(:absolute :absolute64 :relative))
54 (error "Unknown code-object-fixup kind ~S." kind))
55 (ecase kind
56 (:absolute64
57 ;; Word at sap + offset contains a value to be replaced by
58 ;; adding that value to fixup.
59 (setf (sap-ref-64 sap offset) (+ fixup (sap-ref-64 sap offset))))
60 (:absolute
61 ;; Word at sap + offset contains a value to be replaced by
62 ;; adding that value to fixup.
63 (setf (sap-ref-32 sap offset) (+ fixup (sap-ref-32 sap offset))))
64 (:relative
65 ;; Fixup is the actual address wanted.
66 ;; Replace word with value to add to that loc to get there.
67 (let* ((loc-sap (+ (sap-int sap) offset))
68 (rel-val (- fixup loc-sap (/ n-word-bytes 2))))
69 (declare (type (unsigned-byte 64) loc-sap)
70 (type (signed-byte 32) rel-val))
71 (setf (signed-sap-ref-32 sap offset) rel-val))))))
72 nil)
74 ;;;; low-level signal context access functions
75 ;;;;
76 ;;;; Note: In CMU CL, similar functions were hardwired to access
77 ;;;; BSD-style sigcontext structures defined as alien objects. Our
78 ;;;; approach is different in two ways:
79 ;;;; 1. We use POSIX SA_SIGACTION-style signals, so our context is
80 ;;;; whatever the void pointer in the sigaction handler dereferences
81 ;;;; to, not necessarily a sigcontext.
82 ;;;; 2. We don't try to maintain alien definitions of the context
83 ;;;; structure at Lisp level, but instead call alien C functions
84 ;;;; which take care of access for us. (Since the C functions can
85 ;;;; be defined in terms of system standard header files, they
86 ;;;; should be easier to maintain; and since Lisp code uses signal
87 ;;;; contexts only in interactive or exception code (like the debugger
88 ;;;; and internal error handling) the extra runtime cost should be
89 ;;;; negligible.
91 (declaim (inline context-pc-addr))
92 (define-alien-routine ("os_context_pc_addr" context-pc-addr) (* unsigned)
93 ;; (Note: Just as in CONTEXT-REGISTER-ADDR, we intentionally use an
94 ;; 'unsigned *' interpretation for the 32-bit word passed to us by
95 ;; the C code, even though the C code may think it's an 'int *'.)
96 (context (* os-context-t)))
98 (declaim (inline context-pc))
99 (defun context-pc (context)
100 (declare (type (alien (* os-context-t)) context))
101 (let ((addr (context-pc-addr context)))
102 (declare (type (alien (* unsigned)) addr))
103 (int-sap (deref addr))))
105 (declaim (inline context-register-addr))
106 (define-alien-routine ("os_context_register_addr" context-register-addr)
107 (* unsigned)
108 ;; (Note the mismatch here between the 'int *' value that the C code
109 ;; may think it's giving us and the 'unsigned *' value that we
110 ;; receive. It's intentional: the C header files may think of
111 ;; register values as signed, but the CMU CL code tends to think of
112 ;; register values as unsigned, and might get bewildered if we ask
113 ;; it to work with signed values.)
114 (context (* os-context-t))
115 (index int))
117 (declaim (inline context-register))
118 (defun context-register (context index)
119 (declare (type (alien (* os-context-t)) context))
120 (let ((addr (context-register-addr context index)))
121 (declare (type (alien (* unsigned)) addr))
122 (deref addr)))
124 (defun %set-context-register (context index new)
125 (declare (type (alien (* os-context-t)) context))
126 (let ((addr (context-register-addr context index)))
127 (declare (type (alien (* unsigned)) addr))
128 (setf (deref addr) new)))
130 ;;; This is like CONTEXT-REGISTER, but returns the value of a float
131 ;;; register. FORMAT is the type of float to return.
133 ;;; As of sbcl-0.6.7, there is no working code which calls this code,
134 ;;; so it's stubbed out. Someday, in order to make the debugger work
135 ;;; better, it may be necessary to unstubify it.
136 (defun context-float-register (context index format)
137 (declare (ignore context index))
138 (warn "stub CONTEXT-FLOAT-REGISTER")
139 (coerce 0.0 format))
140 (defun %set-context-float-register (context index format new-value)
141 (declare (ignore context index))
142 (warn "stub %SET-CONTEXT-FLOAT-REGISTER")
143 (coerce new-value format))
145 ;;; Given a signal context, return the floating point modes word in
146 ;;; the same format as returned by FLOATING-POINT-MODES.
147 #!-linux
148 (defun context-floating-point-modes (context)
149 (declare (ignore context)) ; stub!
150 (warn "stub CONTEXT-FLOATING-POINT-MODES")
152 #!+linux
153 (define-alien-routine ("os_context_fp_control" context-floating-point-modes)
154 (unsigned 32)
155 (context (* os-context-t)))
157 (define-alien-routine
158 ("arch_get_fp_modes" floating-point-modes) (unsigned 32))
160 (define-alien-routine
161 ("arch_set_fp_modes" %floating-point-modes-setter) void (fp (unsigned 32)))
163 (defun (setf floating-point-modes) (val) (%floating-point-modes-setter val))
166 ;;;; INTERNAL-ERROR-ARGS
168 ;;; Given a (POSIX) signal context, extract the internal error
169 ;;; arguments from the instruction stream.
170 (defun internal-error-args (context)
171 (declare (type (alien (* os-context-t)) context))
172 (/show0 "entering INTERNAL-ERROR-ARGS, CONTEXT=..")
173 (/hexstr context)
174 (let* ((pc (context-pc context))
175 (trap-number (sap-ref-8 pc 0) ))
176 (declare (type system-area-pointer pc))
177 (/show0 "got PC")
178 ;; using INT3 the pc is .. INT3 <here> code length bytes...
179 (if (= trap-number invalid-arg-count-trap)
180 (values #.(error-number-or-lose 'invalid-arg-count-error)
181 '(#.arg-count-sc))
182 (let* ((length (sap-ref-8 pc 1))
183 (vector (make-array length :element-type '(unsigned-byte 8))))
184 (declare (type (unsigned-byte 8) length)
185 (type (simple-array (unsigned-byte 8) (*)) vector))
186 (/show0 "LENGTH,VECTOR,ERROR-NUMBER=..")
187 (/hexstr length)
188 (/hexstr vector)
189 (copy-ub8-from-system-area pc 2 vector 0 length)
190 (let* ((index 0)
191 (error-number (sb!c:read-var-integer vector index)))
192 (/hexstr error-number)
193 (collect ((sc-offsets))
194 (loop
195 (/show0 "INDEX=..")
196 (/hexstr index)
197 (when (>= index length)
198 (return))
199 (let ((sc-offset (sb!c:read-var-integer vector index)))
200 (/show0 "SC-OFFSET=..")
201 (/hexstr sc-offset)
202 (sc-offsets sc-offset)))
203 (values error-number (sc-offsets))))))))
206 ;;; the current alien stack pointer; saved/restored for non-local exits
207 (defvar *alien-stack-pointer*)