assem-rtns.lisp 8.92 KB
Newer Older
wlott's avatar
wlott committed
1 2 3
;;; -*- Package: SPARC -*-
;;;
;;; **********************************************************************
ram's avatar
ram committed
4 5 6 7
;;; 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/sparc/assem-rtns.lisp $")
ram's avatar
ram committed
9
;;;
wlott's avatar
wlott committed
10 11
;;; **********************************************************************
;;;
12
;;; $Header: src/assembly/sparc/assem-rtns.lisp $
wlott's avatar
wlott committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
;;;
;;;
(in-package "SPARC")


;;;; 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 count any-reg nl2-offset)
     (:temp src any-reg nl3-offset)
     (:temp dst any-reg nl4-offset)
35
     (:temp temp descriptor-reg cname-offset)
wlott's avatar
wlott committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49

     ;; 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 cmp nvals)
  (inst b :le default-a0-and-on)
50
  (inst cmp nvals (fixnumize 2))
wlott's avatar
wlott committed
51 52
  (inst b :le default-a2-and-on)
  (inst ld a1 vals (* 1 vm:word-bytes))
53
  (inst cmp nvals (fixnumize 3))
wlott's avatar
wlott committed
54 55
  (inst b :le default-a3-and-on)
  (inst ld a2 vals (* 2 vm:word-bytes))
56
  (inst cmp nvals (fixnumize 4))
wlott's avatar
wlott committed
57 58
  (inst b :le default-a4-and-on)
  (inst ld a3 vals (* 3 vm:word-bytes))
59
  (inst cmp nvals (fixnumize 5))
wlott's avatar
wlott committed
60 61
  (inst b :le default-a5-and-on)
  (inst ld a4 vals (* 4 vm:word-bytes))
62
  (inst cmp nvals (fixnumize 6))
wlott's avatar
wlott committed
63 64 65 66 67 68
  (inst b :le done)
  (inst ld a5 vals (* 5 vm:word-bytes))

  ;; Copy the remaining args to the top of the stack.
  (inst add src vals (* 6 vm:word-bytes))
  (inst add dst cfp-tn (* 6 vm:word-bytes))
69
  (inst subcc count nvals (fixnumize 6))
wlott's avatar
wlott committed
70 71 72 73 74 75 76

  LOOP
  (inst ld temp src)
  (inst add src vm:word-bytes)
  (inst st temp dst)
  (inst add dst vm:word-bytes)
  (inst b :gt loop)
77
  (inst subcc count (fixnumize 1))
wlott's avatar
wlott committed
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
		
  (inst b done)
  (inst nop)

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



;;;; 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 nl3-offset)
123
     (:temp temp descriptor-reg cname-offset)
wlott's avatar
wlott committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

     ;; 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 sub nargs csp-tn args)
     
  ;; Load the argument regs (must do this now, 'cause the blt might
  ;; trash these locations)
  (inst ld a0 args (* 0 vm:word-bytes))
  (inst ld a1 args (* 1 vm:word-bytes))
  (inst ld a2 args (* 2 vm:word-bytes))
  (inst ld a3 args (* 3 vm:word-bytes))
  (inst ld a4 args (* 4 vm:word-bytes))
  (inst ld a5 args (* 5 vm:word-bytes))

  ;; Calc SRC, DST, and COUNT
147
  (inst addcc count nargs (fixnumize (- register-arg-count)))
wlott's avatar
wlott committed
148 149 150 151 152 153 154 155 156
  (inst b :le done)
  (inst add src args (* vm:word-bytes register-arg-count))
  (inst add dst cfp-tn (* vm:word-bytes register-arg-count))
	
  LOOP
  ;; Copy one arg.
  (inst ld temp src)
  (inst add src src vm:word-bytes)
  (inst st temp dst)
157
  (inst addcc count (fixnumize -1))
wlott's avatar
wlott committed
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 235 236 237 238 239 240 241 242 243 244
  (inst b :gt loop)
  (inst add dst dst vm:word-bytes)
	
  DONE
  ;; We are done.  Do the jump.
  (loadw temp lexenv vm:closure-function-slot vm:function-pointer-type)
  (lisp-jump temp))



;;;; Non-local exit noise.

(define-assembly-routine (unwind
			  (:return-style :none)
			  (: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 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))
  (declare (ignore start count))

  (let ((error (generate-error-code nil invalid-unwind-error)))
    (inst cmp block)
    (inst b :eq error))
  
  (load-symbol-value cur-uwp lisp::*current-unwind-protect-block*)
  (loadw target-uwp block vm:unwind-block-current-uwp-slot)
  (inst cmp cur-uwp target-uwp)
  (inst b :ne do-uwp)
  (inst nop)
      
  (move cur-uwp block)

  DO-EXIT
      
  (loadw cfp-tn cur-uwp vm:unwind-block-current-cont-slot)
  (loadw code-tn cur-uwp vm:unwind-block-current-code-slot)
  (loadw lra cur-uwp vm:unwind-block-entry-pc-slot)
  (lisp-return lra :frob-code nil)

  DO-UWP

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


(define-assembly-routine (throw
			  (:return-style :none))
			 ((: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 temp non-descriptor-reg nl0-offset))
  
  (declare (ignore start count))

  (load-symbol-value catch lisp::*current-catch-block*)
  
  loop
  
  (let ((error (generate-error-code nil unseen-throw-tag-error target)))
    (inst cmp catch)
    (inst b :eq error)
    (inst nop))
  
  (loadw tag catch vm:catch-block-tag-slot)
  (inst cmp tag target)
  (inst b :eq exit)
  (inst nop)
  (loadw catch catch vm:catch-block-previous-catch-slot)
  (inst b loop)
  (inst nop)
  
  exit
  
  (move target catch)
  (inst li temp (make-fixup 'unwind :assembly-routine))
  (inst j temp)
  (inst nop))


245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311


;; Assembly routines for undefined_tramp and closure_tramp

#+assembler
(define-assembly-routine (closure-tramp-function-alignment
			  (:return-style :none))
                         ()
  ;; Align to a dualword and put in the magic function header stuff so
  ;; that closure-tramp looks like a normal function with a function
  ;; tag.
  (align vm:lowtag-bits)
  (inst byte 0))

#+assembler
(define-assembly-routine (closure-tramp
			  (:return-style :none))
                         ()
  (inst byte 0)
  (inst byte 0)
  (inst byte vm:function-header-type)
  ;; This is supposed to be closure-tramp, not 0.
  (inst word 0)
  (inst word (kernel:get-lisp-obj-address nil))
  (inst word (kernel:get-lisp-obj-address nil))
  (inst word (kernel:get-lisp-obj-address nil))
  (inst word (kernel:get-lisp-obj-address nil))

  (loadw lexenv-tn cname-tn fdefn-function-slot other-pointer-type)
  (loadw code-tn lexenv-tn closure-function-slot function-pointer-type)
  (inst j code-tn (- (* function-code-offset word-bytes) function-pointer-type))
  (inst nop)
  ;; Make sure following routine is dual-word aligned
  (align vm:lowtag-bits))

#+assembler
(define-assembly-routine (undefined-tramp-function-alignment
			  (:return-style :none))
                         ()
  ;; Align to a dualword and put in the magic function header stuff so
  ;; that closure-tramp looks like a normal function with a function
  ;; tag.
  (align vm:lowtag-bits)
  (inst byte 0))

#+assembler
(define-assembly-routine (undefined-tramp
			  (:return-style :none))
                         ()
  (inst byte 0)
  (inst byte 0)
  (inst byte vm:function-header-type)
  ;; This is supposed to be undefined-tramp, not 0.
  (inst word 0)
  (inst word (kernel:get-lisp-obj-address nil))
  (inst word (kernel:get-lisp-obj-address nil))
  (inst word (kernel:get-lisp-obj-address nil))
  (inst word (kernel:get-lisp-obj-address nil))

  (let ((error (generate-cerror-code nil undefined-symbol-error cname-tn)))
    (inst b error)
    (inst nop)
    ;; I don't think we ever return from the undefined-symbol-error
    ;; handler, but the assembly code did this so we'll do it too.
    (loadw code-tn cname-tn fdefn-raw-addr-slot other-pointer-type)
    (inst j code-tn (- (* function-code-offset word-bytes) function-pointer-type))
    (inst nop)))