Skip to content


slightly less trivial boring things
Browse files Browse the repository at this point in the history
Attemting to run the cross-compiler, even on such a minimal source
file, reveals some necessary support routines that aren't needed when
compiling the cross-compiler but are needed pretty much immediately in
running it.

Those routines (and some variables) require at least some of the
machine registers' functions to be defined, so have a stab at defining

- we'll use x5 to hold our lisp return address, since that is defined
  in the platform ABI as an alternate link register (participating in
  return address prediction, for Spectre or for worse)

- x0 is wired to 0, so define that (and its storage class); also use
  the platform ABI to define the number (C) stack and frame pointer

- define args and temporaries in the function argument/return values
  register region (supported by the RISC-V C extension, in case we can
  save on instruction space later)

- use ABI temporaries for the control (Lisp) stack and frame pointers

- put nargs somewhere arbitrary for now
  • Loading branch information
csrhodes committed Aug 5, 2018
1 parent f681d67 commit 506323c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/compiler/rv32/call.lisp
Expand Up @@ -11,6 +11,28 @@

(in-package "SB!VM")

(defun make-return-pc-passing-location (standard)
(if standard
(make-wired-tn *backend-t-primitive-type* descriptor-reg-sc-number lra-offset)
(make-restricted-tn *backend-t-primitive-type* descriptor-reg-sc-number)))

(defun make-old-fp-passing-location ()
(make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset))

(defconstant old-fp-passing-offset
(make-sc+offset descriptor-reg-sc-number ocfp-offset))

(defun make-old-fp-save-location (env)
(physenv-debug-live-tn (make-normal-tn *fixnum-primitive-type*) env)
(make-wired-tn *fixnum-primitive-type* control-stack-arg-scn ocfp-save-offset)))
(defun make-return-pc-save-location (env)
(physenv-debug-live-tn (make-normal-tn *backend-t-primitive-type*) env)
(make-wired-tn *backend-t-primitive-type* control-stack-arg-scn lra-save-offset)))
(defun make-arg-count-location ()
(make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))

(define-vop (current-fp)
(:results (val :scs (any-reg)))
(:generator 1))
Expand Down
56 changes: 55 additions & 1 deletion src/compiler/rv32/vm.lisp
Expand Up @@ -10,7 +10,7 @@
;;;; files for more information.

(in-package "SB!VM")

(define-storage-base registers :finite :size 32)
(define-storage-base control-stack :unbounded :size 8)
Expand All @@ -25,6 +25,7 @@
(constant constant)
(immediate immediate-constant)
(zero immediate-constant)

(control-stack control-stack)
(any-reg registers :alternate-scs (control-stack))
Expand Down Expand Up @@ -53,10 +54,63 @@
(catch-block control-stack :element-size catch-block-size)
(unwind-block control-stack :element-size unwind-block-size)

(defvar *register-names* (make-array 32 :initial-element nil))

(macrolet ((defreg (name offset)
(let ((offset-sym (symbolicate name "-OFFSET")))
(defconstant ,offset-sym ,offset)
(setf (svref *register-names* ,offset-sym) ,(symbol-name name)))))
(defregset (name &rest regs)
(flet ((offset-namify (n) (symbolicate n "-OFFSET")))
`(defparameter ,name
(list ,@(mapcar #'offset-namify regs)))))
(define-argument-register-set (&rest args)
(defregset *register-arg-offsets* ,@args)
(defconstant register-arg-count ,(length args))
(defparameter *register-arg-tns*
(let ((drsc (sc-or-lose 'descriptor-reg)))
(flet ((make (n) (make-random-tn :kind :normal :sc drsc :offset n)))
(mapcar #'make *register-arg-offsets*)))))))
(defreg zero 0)
(defreg lr 1)
(defreg nsp 2)
(defreg lra 5) ; alternate link register
(defreg cfp 6)
(defreg ocfp 7)
(defreg nfp 8)
(defreg csp 9)
(defreg a0 10)
(defreg nl0 11)
(defreg a1 12)
(defreg nl1 13)
(defreg a2 14)
(defreg nl2 15)
(defreg a3 16)
(defreg nl3 17)
(defreg nargs 31)

(defregset non-descriptor-regs nl0 nl1 nl2 nl3 nargs nfp)
(defregset descriptor-regs a0 a1 a2 a3 ocfp lra)

(define-argument-register-set a0 a1 a2 a3))

(defun immediate-constant-sc (value)
(typecase value
((integer!xc:most-negative-fixnum!xc:most-positive-fixnum) immediate-sc-number)))

(defun boxed-immediate-sc-p (sc)
(or (eql sc zero-sc-number)
(eql sc immediate-sc-number)))

(defconstant immediate-arg-scn any-reg-sc-number)
(defconstant control-stack-arg-scn control-stack-sc-number)

(defconstant ocfp-save-offset 0)
(defconstant lra-save-offset 1)
(defconstant nfp-save-offset 2)

(defun combination-implementation-style (node)
(values :default nil))

0 comments on commit 506323c

Please sign in to comment.