4 ;;;; Interfaces to IR2 conversion:
6 ;;; Standard-Argument-Location -- Interface
8 ;;; Return a wired TN describing the N'th full call argument passing
11 (!def-vm-support-routine standard-arg-location (n)
12 (declare (type unsigned-byte n))
13 (if (< n register-arg-count)
14 (make-wired-tn *backend-t-primitive-type*
16 (elt *register-arg-offsets* n))
17 (make-wired-tn *backend-t-primitive-type*
18 control-stack-arg-scn n)))
21 ;;; Make-Return-PC-Passing-Location -- Interface
23 ;;; Make a passing location TN for a local call return PC. If standard is
24 ;;; true, then use the standard (full call) location, otherwise use any legal
25 ;;; location. Even in the non-standard case, this may be restricted by a
26 ;;; desire to use a subroutine call instruction.
28 (!def-vm-support-routine make-return-pc-passing-location (standard)
30 (make-wired-tn *backend-t-primitive-type* register-arg-scn lra-offset)
31 (make-restricted-tn *backend-t-primitive-type* register-arg-scn)))
33 ;;; Make-Old-FP-Passing-Location -- Interface
35 ;;; Similar to Make-Return-PC-Passing-Location, but makes a location to pass
36 ;;; Old-FP in. This is (obviously) wired in the standard convention, but is
37 ;;; totally unrestricted in non-standard conventions, since we can always fetch
38 ;;; it off of the stack using the arg pointer.
40 (!def-vm-support-routine make-old-fp-passing-location (standard)
42 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset)
43 (make-normal-tn *fixnum-primitive-type*)))
45 ;;; Make-Old-FP-Save-Location, Make-Return-PC-Save-Location -- Interface
47 ;;; Make the TNs used to hold Old-FP and Return-PC within the current
48 ;;; function. We treat these specially so that the debugger can find them at a
51 (!def-vm-support-routine make-old-fp-save-location (env)
53 (physenv-debug-live-tn (make-normal-tn *fixnum-primitive-type*) env)
54 (make-wired-tn *fixnum-primitive-type*
58 (!def-vm-support-routine make-return-pc-save-location (env)
59 (let ((ptype *backend-t-primitive-type*))
61 (physenv-debug-live-tn (make-normal-tn ptype) env)
62 (make-wired-tn ptype control-stack-arg-scn lra-save-offset))))
64 ;;; Make-Argument-Count-Location -- Interface
66 ;;; Make a TN for the standard argument count passing location. We only
67 ;;; need to make the standard location, since a count is never passed when we
68 ;;; are using non-standard conventions.
70 (!def-vm-support-routine make-arg-count-location ()
71 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
74 ;;; MAKE-NFP-TN -- Interface
76 ;;; Make a TN to hold the number-stack frame pointer. This is allocated
77 ;;; once per component, and is component-live.
79 (!def-vm-support-routine make-nfp-tn ()
81 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nfp-offset)))
83 ;;; MAKE-STACK-POINTER-TN ()
85 (!def-vm-support-routine make-stack-pointer-tn ()
86 (make-normal-tn *fixnum-primitive-type*))
88 ;;; MAKE-NUMBER-STACK-POINTER-TN ()
90 (!def-vm-support-routine make-number-stack-pointer-tn ()
91 (make-normal-tn *fixnum-primitive-type*))
93 ;;; Make-Unknown-Values-Locations -- Interface
95 ;;; Return a list of TNs that can be used to represent an unknown-values
96 ;;; continuation within a function.
98 (!def-vm-support-routine make-unknown-values-locations ()
99 (list (make-stack-pointer-tn)
100 (make-normal-tn *fixnum-primitive-type*)))
103 ;;; Select-Component-Format -- Interface
105 ;;; This function is called by the Entry-Analyze phase, allowing
106 ;;; VM-dependent initialization of the IR2-Component structure. We push
107 ;;; placeholder entries in the Constants to leave room for additional
108 ;;; noise in the code object header.
110 (!def-vm-support-routine select-component-format (component)
111 (declare (type component component))
112 (dotimes (i code-constants-offset)
113 (vector-push-extend nil
114 (ir2-component-constants (component-info component))))
120 ;;; BYTES-NEEDED-FOR-NON-DESCRIPTOR-STACK-FRAME -- internal
122 ;;; Return the number of bytes needed for the current non-descriptor stack
123 ;;; frame. Non-descriptor stack frames must be multiples of 8 bytes on
126 (defun bytes-needed-for-non-descriptor-stack-frame ()
127 (* (logandc2 (1+ (sb-allocated-size 'non-descriptor-stack)) 1)
130 ;;; Used for setting up the Old-FP in local call.
132 (define-vop (current-fp)
133 (:results (val :scs (any-reg)))
137 ;;; Used for computing the caller's NFP for use in known-values return. Only
138 ;;; works assuming there is no variable size stuff on the nstack.
140 (define-vop (compute-old-nfp)
141 (:results (val :scs (any-reg)))
144 (let ((nfp (current-nfp-tn vop)))
146 (inst addu val nfp (bytes-needed-for-non-descriptor-stack-frame))))))
149 (define-vop (xep-allocate-frame)
150 (:info start-lab copy-more-arg-follows)
151 (:ignore copy-more-arg-follows)
153 (:temporary (:scs (non-descriptor-reg)) temp)
155 ;; Make sure the function is aligned, and drop a label pointing to this
157 (align n-lowtag-bits)
158 (trace-table-entry trace-table-fun-prologue)
159 (emit-label start-lab)
160 ;; Allocate function header.
161 (inst fun-header-word)
162 (dotimes (i (1- simple-fun-code-offset))
164 ;; The start of the actual code.
165 ;; Compute CODE from the address of this entry point.
166 (let ((entry-point (gen-label)))
167 (emit-label entry-point)
168 (inst compute-code-from-fn code-tn lip-tn entry-point temp)
169 ;; ### We should also save it on the stack so that the garbage collector
170 ;; won't forget about us if we call anyone else.
172 ;; Build our stack frames.
173 (inst addu csp-tn cfp-tn
174 (* n-word-bytes (sb-allocated-size 'control-stack)))
175 (let ((nfp (current-nfp-tn vop)))
177 (inst addu nsp-tn nsp-tn
178 (- (bytes-needed-for-non-descriptor-stack-frame)))
180 (trace-table-entry trace-table-normal)))
182 (define-vop (allocate-frame)
183 (:results (res :scs (any-reg))
184 (nfp :scs (any-reg)))
187 (trace-table-entry trace-table-fun-prologue)
189 (inst addu csp-tn csp-tn
190 (* n-word-bytes (sb-allocated-size 'control-stack)))
191 (when (ir2-physenv-number-stack-p callee)
192 (inst addu nsp-tn nsp-tn
193 (- (bytes-needed-for-non-descriptor-stack-frame)))
195 (trace-table-entry trace-table-normal)))
197 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
198 ;;; is the number of arguments passed. If no stack arguments are passed, then
199 ;;; we don't have to do anything.
201 (define-vop (allocate-full-call-frame)
203 (:results (res :scs (any-reg)))
205 (when (> nargs register-arg-count)
207 (inst addu csp-tn csp-tn (* nargs n-word-bytes)))))
212 ;;; Default-Unknown-Values -- Internal
214 ;;; Emit code needed at the return-point from an unknown-values call for a
215 ;;; fixed number of values. Values is the head of the TN-Ref list for the
216 ;;; locations that the values are to be received into. Nvals is the number of
217 ;;; values that are to be received (should equal the length of Values).
219 ;;; Move-Temp is a Descriptor-Reg TN used as a temporary.
221 ;;; This code exploits the fact that in the unknown-values convention, a
222 ;;; single value return returns at the return PC + 8, whereas a return of other
223 ;;; than one value returns directly at the return PC.
225 ;;; If 0 or 1 values are expected, then we just emit an instruction to reset
226 ;;; the SP (which will only be executed when other than 1 value is returned.)
228 ;;; In the general case, we have to do three things:
229 ;;; -- Default unsupplied register values. This need only be done when a
230 ;;; single value is returned, since register values are defaulted by the
231 ;;; called in the non-single case.
232 ;;; -- Default unsupplied stack values. This needs to be done whenever there
233 ;;; are stack values.
234 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
235 ;;; regardless of the number of values desired.
237 ;;; The general-case code looks like this:
239 b regs-defaulted ; Skip if MVs
242 move a1 null-tn ; Default register values
244 loadi nargs 1 ; Force defaulting of stack values
245 move ocfp csp ; Set up args for SP resetting
248 subu temp nargs register-arg-count
250 bltz temp default-value-7 ; jump to default code
252 loadw move-temp ocfp-tn 6 ; Move value to correct location.
253 store-stack-tn val4-tn move-temp
255 bltz temp default-value-8
257 loadw move-temp ocfp-tn 7
258 store-stack-tn val5-tn move-temp
263 move sp ocfp ; Reset SP.
268 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
271 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
279 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
280 (declare (type (or tn-ref null) values)
281 (type unsigned-byte nvals) (type tn move-temp temp))
284 ;; Note that this is a single-value return point. This is actually
285 ;; the multiple-value entry point for a single desired value, but
286 ;; the code location has to be here, or the debugger backtrace
288 (without-scheduling ()
289 (note-this-location vop :single-value-return)
290 (move csp-tn ocfp-tn)
293 (inst compute-code-from-lra code-tn code-tn lra-label temp)))
294 (let ((regs-defaulted (gen-label))
295 (defaulting-done (gen-label))
296 (default-stack-vals (gen-label)))
297 (without-scheduling ()
298 ;; Note that this is an unknown-values return point.
299 (note-this-location vop :unknown-return)
300 ;; Branch off to the MV case.
301 (inst b regs-defaulted)
302 ;; If there are no stack results, clear the stack now.
303 (if (> nvals register-arg-count)
304 (inst addu temp nargs-tn (fixnumize (- register-arg-count)))
305 (move csp-tn ocfp-tn)))
307 ;; Do the single value calse.
309 (val (tn-ref-across values) (tn-ref-across val)))
310 ((= i (min nvals register-arg-count)))
311 (move (tn-ref-tn val) null-tn))
312 (when (> nvals register-arg-count)
313 (inst b default-stack-vals)
314 (move ocfp-tn csp-tn))
316 (emit-label regs-defaulted)
318 (when (> nvals register-arg-count)
319 ;; If there are stack results, we have to default them
320 ;; and clear the stack.
321 (collect ((defaults))
322 (do ((i register-arg-count (1+ i))
323 (val (do ((i 0 (1+ i))
324 (val values (tn-ref-across val)))
325 ((= i register-arg-count) val))
326 (tn-ref-across val)))
329 (let ((default-lab (gen-label))
330 (tn (tn-ref-tn val)))
331 (defaults (cons default-lab tn))
333 (inst blez temp default-lab)
334 (inst lw move-temp ocfp-tn (* i n-word-bytes))
335 (inst addu temp temp (fixnumize -1))
336 (store-stack-tn tn move-temp)))
338 (emit-label defaulting-done)
339 (move csp-tn ocfp-tn)
341 (let ((defaults (defaults)))
343 (assemble (*elsewhere*)
344 (emit-label default-stack-vals)
345 (do ((remaining defaults (cdr remaining)))
347 (let ((def (car remaining)))
348 (emit-label (car def))
349 (when (null (cdr remaining))
350 (inst b defaulting-done))
351 (store-stack-tn (cdr def) null-tn)))))))
354 (inst compute-code-from-lra code-tn code-tn lra-label temp))))
358 ;;;; Unknown values receiving:
360 ;;; Receive-Unknown-Values -- Internal
362 ;;; Emit code needed at the return point for an unknown-values call for an
363 ;;; arbitrary number of values.
365 ;;; We do the single and non-single cases with no shared code: there doesn't
366 ;;; seem to be any potential overlap, and receiving a single value is more
367 ;;; important efficiency-wise.
369 ;;; When there is a single value, we just push it on the stack, returning
370 ;;; the old SP and 1.
372 ;;; When there is a variable number of values, we move all of the argument
373 ;;; registers onto the stack, and return Args and Nargs.
375 ;;; Args and Nargs are TNs wired to the named locations. We must
376 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
377 ;;; results Start and Count (also, it's nice to be able to target them).
379 (defun receive-unknown-values (args nargs start count lra-label temp)
380 (declare (type tn args nargs start count temp))
381 (let ((variable-values (gen-label))
383 (without-scheduling ()
384 (inst b variable-values)
388 (inst compute-code-from-lra code-tn code-tn lra-label temp))
389 (inst addu csp-tn csp-tn 4)
390 (storew (first register-arg-tns) csp-tn -1)
391 (inst addu start csp-tn -4)
392 (inst li count (fixnumize 1))
396 (assemble (*elsewhere*)
397 (emit-label variable-values)
399 (inst compute-code-from-lra code-tn code-tn lra-label temp))
400 (do ((arg register-arg-tns (rest arg))
403 (storew (first arg) args i))
411 ;;; VOP that can be inherited by unknown values receivers. The main thing this
412 ;;; handles is allocation of the result temporaries.
414 (define-vop (unknown-values-receiver)
416 (start :scs (any-reg))
417 (count :scs (any-reg)))
418 (:temporary (:sc descriptor-reg :offset ocfp-offset
419 :from :eval :to (:result 0))
421 (:temporary (:sc any-reg :offset nargs-offset
422 :from :eval :to (:result 1))
424 (:temporary (:scs (non-descriptor-reg)) temp))
428 ;;;; Local call with unknown values convention return:
430 ;;; Non-TR local call for a fixed number of values passed according to the
431 ;;; unknown values convention.
433 ;;; Args are the argument passing locations, which are specified only to
434 ;;; terminate their lifetimes in the caller.
436 ;;; Values are the return value locations (wired to the standard passing
439 ;;; Save is the save info, which we can ignore since saving has been done.
440 ;;; Return-PC is the TN that the return PC should be passed in.
441 ;;; Target is a continuation pointing to the start of the called function.
442 ;;; Nvals is the number of values received.
444 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
445 ;;; registers may be tied up by the more operand. Instead, we use
446 ;;; MAYBE-LOAD-STACK-TN.
448 (define-vop (call-local)
452 (:results (values :more t))
454 (:move-args :local-call)
455 (:info arg-locs callee target nvals)
457 (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
458 (:temporary (:scs (non-descriptor-reg)) temp)
459 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
460 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
461 (:ignore arg-locs args ocfp)
463 (let ((label (gen-label))
464 (cur-nfp (current-nfp-tn vop)))
466 (store-stack-tn nfp-save cur-nfp))
467 (let ((callee-nfp (callee-nfp-tn callee)))
469 (maybe-load-stack-tn callee-nfp nfp)))
470 (maybe-load-stack-tn cfp-tn fp)
471 (trace-table-entry trace-table-call-site)
472 (inst compute-lra-from-code
473 (callee-return-pc-tn callee) code-tn label temp)
474 (note-this-location vop :call-site)
477 (trace-table-entry trace-table-normal)
478 (emit-return-pc label)
479 (default-unknown-values vop values nvals move-temp temp label)
481 (load-stack-tn cur-nfp nfp-save)))))
484 ;;; Non-TR local call for a variable number of return values passed according
485 ;;; to the unknown values convention. The results are the start of the values
486 ;;; glob and the number of values received.
488 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
489 ;;; registers may be tied up by the more operand. Instead, we use
490 ;;; MAYBE-LOAD-STACK-TN.
492 (define-vop (multiple-call-local unknown-values-receiver)
497 (:move-args :local-call)
498 (:info save callee target)
501 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
503 (let ((label (gen-label))
504 (cur-nfp (current-nfp-tn vop)))
506 (store-stack-tn nfp-save cur-nfp))
507 (let ((callee-nfp (callee-nfp-tn callee)))
509 (maybe-load-stack-tn callee-nfp nfp)))
510 (maybe-load-stack-tn cfp-tn fp)
511 (trace-table-entry trace-table-call-site)
512 (inst compute-lra-from-code
513 (callee-return-pc-tn callee) code-tn label temp)
514 (note-this-location vop :call-site)
517 (trace-table-entry trace-table-normal)
518 (emit-return-pc label)
519 (note-this-location vop :unknown-return)
520 (receive-unknown-values values-start nvals start count label temp)
522 (load-stack-tn cur-nfp nfp-save)))))
525 ;;;; Local call with known values return:
527 ;;; Non-TR local call with known return locations. Known-value return works
528 ;;; just like argument passing in local call.
530 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
531 ;;; registers may be tied up by the more operand. Instead, we use
532 ;;; MAYBE-LOAD-STACK-TN.
534 (define-vop (known-call-local)
538 (:results (res :more t))
539 (:move-args :local-call)
541 (:info save callee target)
542 (:ignore args res save)
544 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
545 (:temporary (:scs (non-descriptor-reg)) temp)
547 (let ((label (gen-label))
548 (cur-nfp (current-nfp-tn vop)))
550 (store-stack-tn nfp-save cur-nfp))
551 (let ((callee-nfp (callee-nfp-tn callee)))
553 (maybe-load-stack-tn callee-nfp nfp)))
554 (maybe-load-stack-tn cfp-tn fp)
555 (trace-table-entry trace-table-call-site)
556 (inst compute-lra-from-code
557 (callee-return-pc-tn callee) code-tn label temp)
558 (note-this-location vop :call-site)
561 (trace-table-entry trace-table-normal)
562 (emit-return-pc label)
563 (note-this-location vop :known-return)
565 (load-stack-tn cur-nfp nfp-save)))))
567 ;;; Return from known values call. We receive the return locations as
568 ;;; arguments to terminate their lifetimes in the returning function. We
569 ;;; restore FP and CSP and jump to the Return-PC.
571 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
572 ;;; registers may be tied up by the more operand. Instead, we use
573 ;;; MAYBE-LOAD-STACK-TN.
575 (define-vop (known-return)
576 (:args (ocfp :target ocfp-temp)
577 (return-pc :target return-pc-temp)
579 (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
580 (:temporary (:sc descriptor-reg :from (:argument 1))
582 (:temporary (:scs (interior-reg)) lip)
583 (:move-args :known-return)
585 (:ignore val-locs vals)
588 (trace-table-entry trace-table-fun-epilogue)
589 (maybe-load-stack-tn ocfp-temp ocfp)
590 (maybe-load-stack-tn return-pc-temp return-pc)
592 (let ((cur-nfp (current-nfp-tn vop)))
594 (inst addu nsp-tn cur-nfp
595 (bytes-needed-for-non-descriptor-stack-frame))))
596 (inst addu lip return-pc-temp (- n-word-bytes other-pointer-lowtag))
598 (move cfp-tn ocfp-temp)
599 (trace-table-entry trace-table-normal)))
604 ;;; There is something of a cross-product effect with full calls. Different
605 ;;; versions are used depending on whether we know the number of arguments or
606 ;;; the name of the called function, and whether we want fixed values, unknown
607 ;;; values, or a tail call.
609 ;;; In full call, the arguments are passed creating a partial frame on the
610 ;;; stack top and storing stack arguments into that frame. On entry to the
611 ;;; callee, this partial frame is pointed to by FP. If there are no stack
612 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
613 ;;; to SP just before the call.
615 ;;; Define-Full-Call -- Internal
617 ;;; This macro helps in the definition of full call VOPs by avoiding code
618 ;;; replication in defining the cross-product VOPs.
620 ;;; Name is the name of the VOP to define.
622 ;;; Named is true if the first argument is a symbol whose global function
623 ;;; definition is to be called.
625 ;;; Return is either :Fixed, :Unknown or :Tail:
626 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
627 ;;; the standard passing locations (passed as result operands).
628 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
629 ;;; result values are specified by the Start and Count as in the
630 ;;; unknown-values continuation representation.
631 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
632 ;;; The Ocfp and Return-PC are passed as the second and third arguments.
634 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
635 ;;; fixed argument. If Variable is false, then the passing locations are
636 ;;; passed as a more arg. Variable is true if there are a variable number of
637 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
638 ;;; return. TR variable argument call is implemented separately.
640 ;;; In tail call with fixed arguments, the passing locations are passed as a
641 ;;; more arg, but there is no new-FP, since the arguments have been set up in
642 ;;; the current frame.
644 (defmacro define-full-call (name named return variable)
645 (assert (not (and variable (eq return :tail))))
647 ,@(when (eq return :unknown)
648 '(unknown-values-receiver)))
650 ,@(unless (eq return :tail)
651 '((new-fp :scs (any-reg) :to :eval)))
654 '(name :target name-pass)
655 '(arg-fun :target lexenv))
657 ,@(when (eq return :tail)
658 '((ocfp :target ocfp-pass)
659 (return-pc :target return-pc-pass)))
661 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
663 ,@(when (eq return :fixed)
664 '((:results (values :more t))))
666 (:save-p ,(if (eq return :tail) :compute-only t))
668 ,@(unless (or (eq return :tail) variable)
669 '((:move-args :full-call)))
672 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
673 ,@(unless variable '(nargs))
674 ,@(when (eq return :fixed) '(nvals)))
676 (:ignore ,@(unless (or variable (eq return :tail)) '(arg-locs))
677 ,@(unless variable '(args)))
679 (:temporary (:sc descriptor-reg
682 ,@(unless (eq return :fixed)
686 (:temporary (:sc descriptor-reg
688 :from (:argument ,(if (eq return :tail) 2 1))
693 `((:temporary (:sc descriptor-reg :offset fdefn-offset
694 :from (:argument ,(if (eq return :tail) 0 1))
698 `((:temporary (:sc descriptor-reg :offset lexenv-offset
699 :from (:argument ,(if (eq return :tail) 0 1))
702 (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
705 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
709 (mapcar #'(lambda (name offset)
710 `(:temporary (:sc descriptor-reg
714 register-arg-names *register-arg-offsets*))
715 ,@(when (eq return :fixed)
716 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
718 ,@(unless (eq return :tail)
719 '((:temporary (:scs (non-descriptor-reg)) temp)
720 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
722 (:temporary (:sc interior-reg :offset lip-offset) entry-point)
724 (:generator ,(+ (if named 5 0)
726 (if (eq return :tail) 0 10)
728 (if (eq return :unknown) 25 0))
729 (let* ((cur-nfp (current-nfp-tn vop))
730 ,@(unless (eq return :tail)
731 '((lra-label (gen-label))))
735 ,@(if (eq return :tail)
736 '((unless (location= ocfp ocfp-pass)
738 (unless (location= return-pc
748 (flet ((do-next-filler ()
749 (let* ((next (pop filler))
750 (what (if (consp next) (car next) next)))
754 `((inst subu nargs-pass csp-tn new-fp)
756 (mapcar #'(lambda (name)
757 `(inst lw ,name new-fp
760 register-arg-names)))
761 '((inst li nargs-pass (fixnumize nargs)))))
762 ,@(if (eq return :tail)
766 (inst move ocfp-pass ocfp))
768 (inst lw ocfp-pass cfp-tn
769 (ash (tn-offset ocfp)
774 (inst move return-pc-pass return-pc))
776 (inst lw return-pc-pass cfp-tn
777 (ash (tn-offset return-pc)
780 (inst addu nsp-tn cur-nfp
781 (bytes-needed-for-non-descriptor-stack-frame))))
783 (inst compute-lra-from-code
784 return-pc-pass code-tn lra-label temp))
786 (store-stack-tn nfp-save cur-nfp))
788 (inst move ocfp-pass cfp-tn))
791 '(move cfp-tn new-fp)
792 '(if (> nargs register-arg-count)
794 (move cfp-tn csp-tn)))
795 (trace-table-entry trace-table-call-site))))
801 (descriptor-reg (move name-pass name))
803 (inst lw name-pass cfp-tn
804 (ash (tn-offset name) word-shift))
807 (inst lw name-pass code-tn
808 (- (ash (tn-offset name) word-shift)
809 other-pointer-lowtag))
811 (inst lw entry-point name-pass
812 (- (ash fdefn-raw-addr-slot word-shift)
813 other-pointer-lowtag))
816 (descriptor-reg (move lexenv arg-fun))
818 (inst lw lexenv cfp-tn
819 (ash (tn-offset arg-fun) word-shift))
822 (inst lw lexenv code-tn
823 (- (ash (tn-offset arg-fun) word-shift)
824 other-pointer-lowtag))
826 (inst lw function lexenv
827 (- (ash closure-fun-slot word-shift)
830 (inst addu entry-point function
831 (- (ash simple-fun-code-offset word-shift)
832 fun-pointer-lowtag))))
838 (note-this-location vop :call-site)
844 '((trace-table-entry trace-table-normal)
845 (emit-return-pc lra-label)
846 (default-unknown-values vop values nvals
847 move-temp temp lra-label)
849 (load-stack-tn cur-nfp nfp-save))))
851 '((trace-table-entry trace-table-normal)
852 (emit-return-pc lra-label)
853 (note-this-location vop :unknown-return)
854 (receive-unknown-values values-start nvals start count
857 (load-stack-tn cur-nfp nfp-save))))
861 (define-full-call call nil :fixed nil)
862 (define-full-call call-named t :fixed nil)
863 (define-full-call multiple-call nil :unknown nil)
864 (define-full-call multiple-call-named t :unknown nil)
865 (define-full-call tail-call nil :tail nil)
866 (define-full-call tail-call-named t :tail nil)
868 (define-full-call call-variable nil :fixed t)
869 (define-full-call multiple-call-variable nil :unknown t)
872 ;;; Defined separately, since needs special code that BLT's the arguments
875 (define-vop (tail-call-variable)
877 (args-arg :scs (any-reg) :target args)
878 (function-arg :scs (descriptor-reg) :target lexenv)
879 (ocfp-arg :scs (any-reg) :target ocfp)
880 (lra-arg :scs (descriptor-reg) :target lra))
882 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
883 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
884 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
885 (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
891 ;; Move these into the passing locations if they are not already there.
893 (move lexenv function-arg)
897 ;; Clear the number stack if anything is there.
898 (let ((cur-nfp (current-nfp-tn vop)))
900 (inst addu nsp-tn cur-nfp
901 (bytes-needed-for-non-descriptor-stack-frame))))
903 ;; And jump to the assembly-routine that does the bliting.
904 (inst j (make-fixup 'tail-call-variable :assembly-routine))
908 ;;;; Unknown values return:
910 ;;; Return a single value using the unknown-values convention.
912 (define-vop (return-single)
913 (:args (ocfp :scs (any-reg))
914 (return-pc :scs (descriptor-reg))
917 (:temporary (:scs (interior-reg)) lip)
920 ;; Clear the number stack.
921 (trace-table-entry trace-table-fun-epilogue)
922 (let ((cur-nfp (current-nfp-tn vop)))
924 (inst addu nsp-tn cur-nfp
925 (bytes-needed-for-non-descriptor-stack-frame))))
926 ;; Clear the control stack, and restore the frame pointer.
930 (lisp-return return-pc lip :offset 2)
931 (trace-table-entry trace-table-normal)))
934 ;;; Do unknown-values return of a fixed number of values. The Values are
935 ;;; required to be set up in the standard passing locations. Nvals is the
936 ;;; number of values returned.
938 ;;; If returning a single value, then deallocate the current frame, restore
939 ;;; FP and jump to the single-value entry at Return-PC + 8.
941 ;;; If returning other than one value, then load the number of values returned,
942 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
943 ;;; When there are stack values, we must initialize the argument pointer to
944 ;;; point to the beginning of the values block (which is the beginning of the
948 (:args (ocfp :scs (any-reg))
949 (return-pc :scs (descriptor-reg) :to (:eval 1))
953 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
954 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
955 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
956 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
957 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
958 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
959 (:temporary (:sc any-reg :offset nargs-offset) nargs)
960 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
961 (:temporary (:scs (interior-reg)) lip)
964 ;; Clear the number stack.
965 (trace-table-entry trace-table-fun-epilogue)
966 (let ((cur-nfp (current-nfp-tn vop)))
968 (inst addu nsp-tn cur-nfp
969 (bytes-needed-for-non-descriptor-stack-frame))))
970 ;; Establish the values pointer and values count.
971 (move val-ptr cfp-tn)
972 (inst li nargs (fixnumize nvals))
973 ;; restore the frame pointer and clear as much of the control
974 ;; stack as possible.
976 (inst addu csp-tn val-ptr (* nvals n-word-bytes))
977 ;; pre-default any argument register that need it.
978 (when (< nvals register-arg-count)
979 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
982 (lisp-return return-pc lip)
983 (trace-table-entry trace-table-normal)))
985 ;;; Do unknown-values return of an arbitrary number of values (passed on the
986 ;;; stack.) We check for the common case of a single return value, and do that
987 ;;; inline using the normal single value return convention. Otherwise, we
988 ;;; branch off to code that calls an assembly-routine.
990 (define-vop (return-multiple)
991 (:args (ocfp-arg :scs (any-reg) :target ocfp)
992 (lra-arg :scs (descriptor-reg) :target lra)
993 (vals-arg :scs (any-reg) :target vals)
994 (nvals-arg :scs (any-reg) :target nvals))
996 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
997 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
998 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
999 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
1000 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
1001 (:temporary (:scs (interior-reg)) lip)
1006 (trace-table-entry trace-table-fun-epilogue)
1007 (let ((not-single (gen-label)))
1008 ;; Clear the number stack.
1009 (let ((cur-nfp (current-nfp-tn vop)))
1011 (inst addu nsp-tn cur-nfp
1012 (bytes-needed-for-non-descriptor-stack-frame))))
1014 ;; Check for the single case.
1015 (inst li a0 (fixnumize 1))
1016 (inst bne nvals-arg a0 not-single)
1017 (inst lw a0 vals-arg)
1019 ;; Return with one value.
1020 (move csp-tn cfp-tn)
1021 (move cfp-tn ocfp-arg)
1022 (lisp-return lra-arg lip :offset 2)
1024 ;; Nope, not the single case.
1025 (emit-label not-single)
1026 (move ocfp ocfp-arg)
1028 (move vals vals-arg)
1029 (move nvals nvals-arg)
1030 (inst j (make-fixup 'return-multiple :assembly-routine))
1032 (trace-table-entry trace-table-normal)))
1039 ;;; We don't need to do anything special for regular functions.
1041 (define-vop (setup-environment)
1045 ;; Don't bother doing anything.
1048 ;;; Get the lexical environment from it's passing location.
1050 (define-vop (setup-closure-environment)
1051 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1054 (:results (closure :scs (descriptor-reg)))
1059 (move closure lexenv)))
1061 ;;; Copy a more arg from the argument area to the end of the current frame.
1062 ;;; Fixed is the number of non-more arguments.
1064 (define-vop (copy-more-arg)
1065 (:temporary (:sc any-reg :offset nl0-offset) result)
1066 (:temporary (:sc any-reg :offset nl1-offset) count)
1067 (:temporary (:sc any-reg :offset nl2-offset) src)
1068 (:temporary (:sc any-reg :offset nl4-offset) dst)
1069 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1072 (let ((loop (gen-label))
1073 (do-regs (gen-label))
1075 (when (< fixed register-arg-count)
1076 ;; Save a pointer to the results so we can fill in register args.
1077 ;; We don't need this if there are more fixed args than reg args.
1078 (move result csp-tn))
1079 ;; Allocate the space on the stack.
1080 (cond ((zerop fixed)
1081 (inst beq nargs-tn done)
1082 (inst addu csp-tn csp-tn nargs-tn))
1084 (inst addu count nargs-tn (fixnumize (- fixed)))
1085 (inst blez count done)
1087 (inst addu csp-tn csp-tn count)))
1088 (when (< fixed register-arg-count)
1089 ;; We must stop when we run out of stack args, not when we run out of
1091 (inst addu count nargs-tn (fixnumize (- register-arg-count))))
1092 ;; Everything of interest in registers.
1093 (inst blez count do-regs)
1094 ;; Initialize dst to be end of stack.
1096 ;; Initialize src to be end of args.
1097 (inst addu src cfp-tn nargs-tn)
1100 ;; *--dst = *--src, --count
1101 (inst addu src src (- n-word-bytes))
1102 (inst addu count count (fixnumize -1))
1104 (inst addu dst dst (- n-word-bytes))
1105 (inst bgtz count loop)
1108 (emit-label do-regs)
1109 (when (< fixed register-arg-count)
1110 ;; Now we have to deposit any more args that showed up in registers.
1111 ;; We know there is at least one more arg, otherwise we would have
1112 ;; branched to done up at the top.
1113 (inst subu count nargs-tn (fixnumize (1+ fixed)))
1114 (do ((i fixed (1+ i)))
1115 ((>= i register-arg-count))
1116 ;; Is this the last one?
1117 (inst beq count done)
1118 ;; Store it relative to the pointer saved at the start.
1119 (storew (nth i register-arg-tns) result (- i fixed))
1121 (inst subu count (fixnumize 1))))
1122 (emit-label done))))
1125 ;;; More args are stored consequtively on the stack, starting immediately at
1126 ;;; the context pointer. The context pointer is not typed, so the lowtag is 0.
1128 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1131 ;;; Turn more arg (context, count) into a list.
1133 (define-vop (listify-rest-args)
1134 (:args (context-arg :target context :scs (descriptor-reg))
1135 (count-arg :target count :scs (any-reg)))
1136 (:arg-types * tagged-num)
1137 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1138 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1139 (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1140 (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
1141 (:results (result :scs (descriptor-reg)))
1142 (:translate %listify-rest-args)
1145 (let ((enter (gen-label))
1148 (move context context-arg)
1149 (move count count-arg)
1150 ;; Check to see if there are any arguments.
1151 (inst beq count zero-tn done)
1152 (move result null-tn)
1154 ;; We need to do this atomically.
1155 (pseudo-atomic (pa-flag)
1156 ;; Allocate a cons (2 words) for each item.
1157 (inst or result alloc-tn list-pointer-lowtag)
1159 (inst sll temp count 1)
1161 (inst addu alloc-tn alloc-tn temp)
1163 ;; Store the current cons in the cdr of the previous cons.
1165 (inst addu dst dst (* 2 n-word-bytes))
1166 (storew dst dst -1 list-pointer-lowtag)
1170 (loadw temp context)
1171 (inst addu context context n-word-bytes)
1173 ;; Dec count, and if != zero, go back for more.
1174 (inst addu count count (fixnumize -1))
1175 (inst bne count zero-tn loop)
1177 ;; Store the value in the car (in delay slot)
1178 (storew temp dst 0 list-pointer-lowtag)
1180 ;; NIL out the last cons.
1181 (storew null-tn dst 1 list-pointer-lowtag))
1182 (emit-label done))))
1184 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1185 ;;; Supplied is the total number of arguments supplied (originally passed in
1186 ;;; NARGS.) Fixed is the number of non-rest arguments.
1188 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1189 ;;; time the environment is in a pretty brain-damaged state, preventing this
1190 ;;; info from being returned as values. What we do is compute
1191 ;;; supplied - fixed, and return a pointer that many words below the current
1194 (define-vop (more-arg-context)
1195 (:policy :fast-safe)
1196 (:translate sb!c::%more-arg-context)
1197 (:args (supplied :scs (any-reg)))
1198 (:arg-types tagged-num (:constant fixnum))
1200 (:results (context :scs (descriptor-reg))
1201 (count :scs (any-reg)))
1202 (:result-types t tagged-num)
1203 (:note "more-arg-context")
1205 (inst addu count supplied (fixnumize (- fixed)))
1206 (inst subu context csp-tn count)))
1209 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1211 (define-vop (verify-arg-count)
1212 (:policy :fast-safe)
1213 (:translate sb!c::%verify-arg-count)
1214 (:args (nargs :scs (any-reg)))
1215 (:arg-types positive-fixnum (:constant t))
1216 (:temporary (:scs (any-reg) :type fixnum) temp)
1219 (:save-p :compute-only)
1222 (generate-error-code vop invalid-arg-count-error nargs)))
1223 (cond ((zerop count)
1224 (inst bne nargs zero-tn err-lab)
1227 (inst li temp (fixnumize count))
1228 (inst bne nargs temp err-lab)
1231 ;;; Various other error signalers.
1233 (macrolet ((frob (name error translate &rest args)
1234 `(define-vop (,name)
1236 `((:policy :fast-safe)
1237 (:translate ,translate)))
1238 (:args ,@(mapcar #'(lambda (arg)
1239 `(,arg :scs (any-reg descriptor-reg)))
1242 (:save-p :compute-only)
1244 (error-call vop ,error ,@args)))))
1245 (frob arg-count-error invalid-arg-count-error
1246 sb!c::%arg-count-error nargs)
1247 (frob type-check-error object-not-type-error sb!c::%type-check-error
1249 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1251 (frob odd-key-args-error odd-key-args-error
1252 sb!c::%odd-key-args-error)
1253 (frob unknown-key-arg-error unknown-key-arg-error
1254 sb!c::%unknown-key-arg-error key)
1255 (frob nil-fun-returned-error nil-fun-returned-error nil fun))