X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcode%2Fmips-vm.lisp;h=987dc6b02385ae6bec7986afeaf035f2c2d2948c;hb=bfb19d306581ac86feb4371846c4b9953d692dd8;hp=541bb35ee86edf52238873ee7ff4756588dd3667;hpb=6365d636fa30ff3e2c2ebc9668f978fa0ebc7a0e;p=sbcl.git diff --git a/src/code/mips-vm.lisp b/src/code/mips-vm.lisp index 541bb35..987dc6b 100644 --- a/src/code/mips-vm.lisp +++ b/src/code/mips-vm.lisp @@ -1,6 +1,11 @@ +;;; This file contains the MIPS specific runtime stuff. +;;; (in-package "SB!VM") + (define-alien-type os-context-t (struct os-context-t-struct)) +(define-alien-type os-context-register-t unsigned-long-long) + ;;;; MACHINE-TYPE and MACHINE-VERSION @@ -12,125 +17,108 @@ (defun get-machine-version () #!+little-endian "little-endian" #!-little-endian "big-endian") + ;;;; FIXUP-CODE-OBJECT (defun fixup-code-object (code offset value kind) + (declare (type index offset)) (unless (zerop (rem offset n-word-bytes)) (error "Unaligned instruction? offset=#x~X." offset)) (sb!sys:without-gcing (let ((sap (truly-the system-area-pointer - (%primitive sb!c::code-instructions code)))) + (%primitive sb!c::code-instructions code)))) (ecase kind (:jump - (aver (zerop (ash value -28))) - (setf (ldb (byte 26 0) (sap-ref-32 sap offset)) - (ash value -2))) + (aver (zerop (ash value -28))) + (setf (ldb (byte 26 0) (sap-ref-32 sap offset)) + (ash value -2))) (:lui - (setf (sap-ref-16 sap - #!+little-endian offset - #!-little-endian (+ offset 2)) - (+ (ash value -16) - (if (logbitp 15 value) 1 0)))) + (setf (ldb (byte 16 0) (sap-ref-32 sap offset)) + (ash (1+ (ash value -15)) -1))) (:addi - (setf (sap-ref-16 sap - #!+little-endian offset - #!-little-endian (+ offset 2)) - (ldb (byte 16 0) value))))))) + (setf (ldb (byte 16 0) (sap-ref-32 sap offset)) + (ldb (byte 16 0) value))))))) -(define-alien-routine ("os_context_pc_addr" context-pc-addr) (* unsigned-int) - (context (* os-context-t))) +(define-alien-routine ("os_context_pc_addr" context-pc-addr) + (* os-context-register-t) + (context (* os-context-t) :in)) (defun context-pc (context) (declare (type (alien (* os-context-t)) context)) - ;; KLUDGE: this sucks, and furthermore will break on either of (a) - ;; porting back to IRIX or (b) running on proper 64-bit support. - ;; Linux on the MIPS defines its registers in the sigcontext as - ;; 64-bit quantities ("unsigned long long"), presumably to be - ;; binary-compatible with 64-bit mode. Since there appears not to - ;; be ALIEN support for 64-bit return values, we have to do the - ;; hacky pointer arithmetic thing. -- CSR, 2002-09-01 - (int-sap (deref (context-pc-addr context) - #!-little-endian 1 - ;; Untested - #!+little-endian 0))) + (int-sap (deref (context-pc-addr context)))) (define-alien-routine ("os_context_register_addr" context-register-addr) - (* unsigned-int) - (context (* os-context-t)) - (index int)) + (* os-context-register-t) + (context (* os-context-t) :in) + (index int :in)) (define-alien-routine ("os_context_bd_cause" context-bd-cause-int) - (unsigned 32) - (context (* os-context-t))) + unsigned-int + (context (* os-context-t) :in)) ;;; FIXME: Should this and CONTEXT-PC be INLINE to reduce consing? ;;; (Are they used in anything time-critical, or just the debugger?) (defun context-register (context index) (declare (type (alien (* os-context-t)) context)) - (deref (context-register-addr context index) - #!-little-endian 1 - #!+little-endian 0)) + (let ((addr (context-register-addr context index))) + (declare (type (alien (* os-context-register-t)) addr)) + (deref addr))) (defun %set-context-register (context index new) (declare (type (alien (* os-context-t)) context)) - (setf (deref (context-register-addr context index) - #!-little-endian 1 - #!+little-endian 0) - new)) - -#!+linux -;;; For now. -(defun context-floating-point-modes (context) - (declare (ignore context)) - (warn "stub CONTEXT-FLOATING-POINT-MODES") - 0) + (let ((addr (context-register-addr context index))) + (declare (type (alien (* os-context-register-t)) addr)) + (setf (deref addr) new))) + +;;; This is like CONTEXT-REGISTER, but returns the value of a float +;;; register. FORMAT is the type of float to return. + +;;; FIXME: Whether COERCE actually knows how to make a float out of a +;;; long is another question. This stuff still needs testing. +(define-alien-routine ("os_context_fpregister_addr" context-float-register-addr) + (* os-context-register-t) + (context (* os-context-t)) + (index int)) + +(defun context-float-register (context index format) + (declare (type (alien (* os-context-t)) context)) + (let ((addr (context-float-register-addr context index))) + (declare (type (alien (* os-context-register-t)) addr)) + (coerce (deref addr) format))) + +(defun %set-context-float-register (context index format new) + (declare (type (alien (* os-context-t)) context)) + (let ((addr (context-float-register-addr context index))) + (declare (type (alien (* os-context-register-t)) addr)) + (setf (deref addr) (coerce new format)))) + +;;; Given a signal context, return the floating point modes word in +;;; the same format as returned by FLOATING-POINT-MODES. +(define-alien-routine ("os_context_fp_control" context-floating-point-modes) + unsigned-int + (context (* os-context-t))) ;;;; Internal-error-arguments. ;;; INTERNAL-ERROR-ARGUMENTS -- interface. ;;; ;;; Given the sigcontext, extract the internal error arguments from the -;;; instruction stream. -;;; +;;; instruction stream. This is e.g. +;;; 4 23 254 206 1 0 0 0 +;;; | ~~~~~~~~~~~~~~~~~~~~~~~~~ +;;; length data (everything is an octet) +;;; (pc + 4) (defun internal-error-args (context) (declare (type (alien (* os-context-t)) context)) (/show0 "entering INTERNAL-ERROR-ARGS, CONTEXT=..") (/hexstr context) (let ((pc (context-pc context)) - (cause (context-bd-cause-int context))) + (cause (context-bd-cause-int context))) (declare (type system-area-pointer pc)) - (/show0 "got PC=..") - (/hexstr (sap-int pc)) - ;; KLUDGE: This exposure of the branch delay mechanism hurts. - (when (logbitp 31 cause) - (setf pc (sap+ pc 4))) - (when (= (sap-ref-8 pc 4) 255) - (setf pc (sap+ pc 1))) - (/show0 "now PC=..") - (/hexstr (sap-int pc)) - (let* ((length (sap-ref-8 pc 4)) - (vector (make-array length :element-type '(unsigned-byte 8)))) - (declare (type (unsigned-byte 8) length) - (type (simple-array (unsigned-byte 8) (*)) vector)) - (/show0 "LENGTH,VECTOR,ERROR-NUMBER=..") - (/hexstr length) - (/hexstr vector) - (copy-ub8-from-system-area pc 5 vector 0 length) - (let* ((index 0) - (error-number (sb!c:read-var-integer vector index))) - (/hexstr error-number) - (collect ((sc-offsets)) - (loop - (/show0 "INDEX=..") - (/hexstr index) - (when (>= index length) - (return)) - (sc-offsets (sb!c:read-var-integer vector index))) - (values error-number (sc-offsets))))))) - - - - - + (multiple-value-bind (error-number length sc-offsets) + ;; KLUDGE: This exposure of the branch delay mechanism hurts. + (snarf-error-junk pc (if (logbitp 31 cause) 8 4)) + (declare (ignore length)) + (values error-number sc-offsets))))