assem-rtns.lisp 6.83 KB
Newer Older
hallgren's avatar
hallgren committed
1 2 3 4 5 6 7
;;; -*- Package: ALPHA -*-
;;;
;;; **********************************************************************
;;; This code was written as part of the CMU Common Lisp project at
;;; Carnegie Mellon University, and has been placed in the public domain.
;;;
(ext:file-comment
8
  "$Header: src/assembly/alpha/assem-rtns.lisp $")
hallgren's avatar
hallgren committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
;;;
;;; **********************************************************************
;;;
(in-package "ALPHA")


;;;; Return-multiple with other than one value

#+assembler ;; we don't want a vop for this one.
(define-assembly-routine
    (return-multiple
     (:return-style :none))

     ;; These four are really arguments.
    ((:temp nvals any-reg nargs-offset)
     (:temp vals any-reg nl0-offset)
     (:temp ocfp any-reg nl1-offset)
     (:temp lra descriptor-reg lra-offset)

     ;; These are just needed to facilitate the transfer
     (:temp lip interior-reg lip-offset)
     (:temp count any-reg nl2-offset)
     (:temp dst any-reg nl4-offset)
     (:temp temp descriptor-reg l0-offset)

     ;; These are needed so we can get at the register args.
     (:temp a0 descriptor-reg a0-offset)
     (:temp a1 descriptor-reg a1-offset)
     (:temp a2 descriptor-reg a2-offset)
     (:temp a3 descriptor-reg a3-offset)
     (:temp a4 descriptor-reg a4-offset)
     (:temp a5 descriptor-reg a5-offset))

  ;; Note, because of the way the return-multiple vop is written, we can
  ;; assume that we are never called with nvals == 1 and that a0 has already
  ;; been loaded.
  (inst ble nvals default-a0-and-on)
  (inst ldl a1 (* 1 vm:word-bytes) vals)
47
  (inst subq nvals (fixnumize 2) count)
hallgren's avatar
hallgren committed
48 49
  (inst ble count default-a2-and-on)
  (inst ldl a2 (* 2 vm:word-bytes) vals)
50
  (inst subq nvals (fixnumize 3) count)
hallgren's avatar
hallgren committed
51 52
  (inst ble count default-a3-and-on)
  (inst ldl a3 (* 3 vm:word-bytes) vals)
53
  (inst subq nvals (fixnumize 4) count)
hallgren's avatar
hallgren committed
54 55
  (inst ble count default-a4-and-on)
  (inst ldl a4 (* 4 vm:word-bytes) vals)
56
  (inst subq nvals (fixnumize 5) count)
hallgren's avatar
hallgren committed
57 58
  (inst ble count default-a5-and-on)
  (inst ldl a5 (* 5 vm:word-bytes) vals)
59
  (inst subq nvals (fixnumize 6) count)
hallgren's avatar
hallgren committed
60 61 62 63 64 65 66 67 68 69
  (inst ble count done)

  ;; Copy the remaining args to the top of the stack.
  (inst addq vals (* 6 vm:word-bytes) vals)
  (inst addq cfp-tn (* 6 vm:word-bytes) dst)

  LOOP
  (inst ldl temp 0 vals)
  (inst addq vals vm:word-bytes vals)
  (inst stl temp 0 dst)
70
  (inst subq count (fixnumize 1) count)
hallgren's avatar
hallgren committed
71
  (inst addq dst vm:word-bytes dst)
72
  (inst bne count loop)
hallgren's avatar
hallgren committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
		
  (inst br zero-tn done)

  DEFAULT-A0-AND-ON
  (inst move null-tn a0)
  (inst move null-tn a1)
  DEFAULT-A2-AND-ON
  (inst move null-tn a2)
  DEFAULT-A3-AND-ON
  (inst move null-tn a3)
  DEFAULT-A4-AND-ON
  (inst move null-tn a4)
  DEFAULT-A5-AND-ON
  (inst move null-tn a5)
  DONE
  
  ;; Clear the stack.
  (move cfp-tn ocfp-tn)
  (move ocfp cfp-tn)
  (inst addq ocfp-tn nvals csp-tn)
  
  ;; Return.
  (lisp-return lra lip))


;;;; tail-call-variable.

#+assembler ;; no vop for this one either.
(define-assembly-routine
    (tail-call-variable
     (:return-style :none))

    ;; These are really args.
    ((:temp args any-reg nl0-offset)
     (:temp lexenv descriptor-reg lexenv-offset)

     ;; We need to compute this
     (:temp nargs any-reg nargs-offset)

     ;; These are needed by the blitting code.
     (:temp src any-reg nl1-offset)
     (:temp dst any-reg nl2-offset)
     (:temp count any-reg cfunc-offset)
     (:temp temp descriptor-reg l0-offset)

     ;; Needed for the jump
     (:temp lip interior-reg lip-offset)

     ;; These are needed so we can get at the register args.
     (:temp a0 descriptor-reg a0-offset)
     (:temp a1 descriptor-reg a1-offset)
     (:temp a2 descriptor-reg a2-offset)
     (:temp a3 descriptor-reg a3-offset)
     (:temp a4 descriptor-reg a4-offset)
     (:temp a5 descriptor-reg a5-offset))


  ;; Calculate NARGS (as a fixnum)
  (inst subq csp-tn args nargs)
     
  ;; Load the argument regs (must do this now, 'cause the blt might
  ;; trash these locations)
  (inst ldl a0 (* 0 vm:word-bytes) args)
  (inst ldl a1 (* 1 vm:word-bytes) args)
  (inst ldl a2 (* 2 vm:word-bytes) args)
  (inst ldl a3 (* 3 vm:word-bytes) args)
  (inst ldl a4 (* 4 vm:word-bytes) args)
  (inst ldl a5 (* 5 vm:word-bytes) args)

  ;; Calc SRC, DST, and COUNT
143
  (inst subq nargs (fixnumize register-arg-count) count)
hallgren's avatar
hallgren committed
144 145 146 147 148 149 150 151 152
  (inst addq args (* vm:word-bytes register-arg-count) src)
  (inst ble count done)
  (inst addq cfp-tn (* vm:word-bytes register-arg-count) dst)
	
  LOOP
  ;; Copy one arg.
  (inst ldl temp 0 src)
  (inst addq src vm:word-bytes src)
  (inst stl temp 0 dst)
153
  (inst subq count (fixnumize 1) count)
hallgren's avatar
hallgren committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
  (inst addq dst vm:word-bytes dst)
  (inst bgt count loop)
	
  DONE
  ;; We are done.  Do the jump.
  (progn
    (loadw temp lexenv vm:closure-function-slot vm:function-pointer-type)
    (lisp-jump temp lip)))


;;;; Non-local exit noise.

(define-assembly-routine
    (unwind
     (:translate %continue-unwind)
     (:policy :fast-safe))
    ((:arg block (any-reg descriptor-reg) a0-offset)
     (:arg start (any-reg descriptor-reg) ocfp-offset)
     (:arg count (any-reg descriptor-reg) nargs-offset)
     (:temp lip interior-reg lip-offset)
     (:temp lra descriptor-reg lra-offset)
     (:temp cur-uwp any-reg nl0-offset)
     (:temp next-uwp any-reg nl1-offset)
     (:temp target-uwp any-reg nl2-offset)
     (:temp temp1 non-descriptor-reg nl3-offset))
  (declare (ignore start count))

  (load-symbol-value cur-uwp lisp::*current-unwind-protect-block*)
  (let ((error (generate-error-code nil invalid-unwind-error)))
    (inst beq block error))
  
  (loadw target-uwp block vm:unwind-block-current-uwp-slot)
  (inst cmpeq cur-uwp target-uwp temp1)
  (inst beq temp1 do-uwp)
      
  (move block cur-uwp)

  do-exit
      
  (loadw cfp-tn cur-uwp vm:unwind-block-current-cont-slot)
  (loadw code-tn cur-uwp vm:unwind-block-current-code-slot)
  (progn
    (loadw lra cur-uwp vm:unwind-block-entry-pc-slot)
    (lisp-return lra lip :frob-code nil))

  do-uwp

  (loadw next-uwp cur-uwp vm:unwind-block-current-uwp-slot)
  (store-symbol-value next-uwp lisp::*current-unwind-protect-block*)
  (inst br zero-tn do-exit))


(define-assembly-routine
    throw
    ((:arg target descriptor-reg a0-offset)
     (:arg start any-reg ocfp-offset)
     (:arg count any-reg nargs-offset)
     (:temp catch any-reg a1-offset)
     (:temp tag descriptor-reg a2-offset)
     (:temp temp1 non-descriptor-reg nl0-offset))
  
  (progn start count) ; We just need them in the registers.

  (load-symbol-value catch lisp::*current-catch-block*)
  
  loop
  
  (let ((error (generate-error-code nil unseen-throw-tag-error target)))
    (inst beq catch error))
  
  (loadw tag catch vm:catch-block-tag-slot)
  (inst cmpeq tag target temp1)
  (inst bne temp1 exit)
  (loadw catch catch vm:catch-block-previous-catch-slot)
  (inst br zero-tn loop)
  
  exit
  
  (move catch target)
  (inst li (make-fixup 'unwind :assembly-routine) temp1)
  (inst jmp zero-tn temp1 (make-fixup 'unwind :assembly-routine)))