1 ;;;; the VM definition of function call for the Alpha
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 ;;;; interfaces to IR2 conversion
16 ;;; Return a wired TN describing the N'th full call argument passing
19 (!def-vm-support-routine standard-argument-location (n)
20 (declare (type unsigned-byte n))
21 (if (< n register-arg-count)
22 (make-wired-tn *backend-t-primitive-type*
24 (elt *register-arg-offsets* n))
25 (make-wired-tn *backend-t-primitive-type*
26 control-stack-arg-scn n)))
29 ;;; Make a passing location TN for a local call return PC. If standard
30 ;;; is true, then use the standard (full call) location, otherwise use
31 ;;; any legal location. Even in the non-standard case, this may be
32 ;;; restricted by a desire to use a subroutine call instruction.
34 (!def-vm-support-routine make-return-pc-passing-location (standard)
35 #!+gengc (declare (ignore standard))
38 (make-wired-tn *backend-t-primitive-type* register-arg-scn lra-offset)
39 (make-restricted-tn *backend-t-primitive-type* register-arg-scn))
41 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ra-offset))
43 ;;; This is similar to Make-Return-PC-Passing-Location, but makes a
44 ;;; location to pass Old-FP in. This is (obviously) wired in the
45 ;;; standard convention, but is totally unrestricted in non-standard
46 ;;; conventions, since we can always fetch it off of the stack using
49 (!def-vm-support-routine make-old-fp-passing-location (standard)
51 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset)
52 (make-normal-tn *fixnum-primitive-type*)))
54 ;;; These functions make the TNs used to hold Old-FP and Return-PC
55 ;;; within the current function. We treat these specially so that the
56 ;;; debugger can find them at a known location.
57 (!def-vm-support-routine make-old-fp-save-location (env)
59 (environment-debug-live-tn (make-normal-tn *fixnum-primitive-type*) env)
60 (make-wired-tn *fixnum-primitive-type*
63 (!def-vm-support-routine make-return-pc-save-location (env)
64 (let ((ptype #!-gengc *backend-t-primitive-type*
65 #!+gengc *fixnum-primitive-type*))
67 (environment-debug-live-tn (make-normal-tn ptype) env)
68 (make-wired-tn ptype control-stack-arg-scn
69 #!-gengc lra-save-offset #!+gengc ra-save-offset))))
71 ;;; Make a TN for the standard argument count passing location. We
72 ;;; only need to make the standard location, since a count is never
73 ;;; passed when we are using non-standard conventions.
74 (!def-vm-support-routine make-argument-count-location ()
75 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
78 ;;; Make a TN to hold the number-stack frame pointer. This is
79 ;;; allocated once per component, and is component-live.
80 (!def-vm-support-routine make-nfp-tn ()
82 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nfp-offset)))
84 (!def-vm-support-routine make-stack-pointer-tn ()
85 (make-normal-tn *fixnum-primitive-type*))
87 (!def-vm-support-routine make-number-stack-pointer-tn ()
88 (make-normal-tn *fixnum-primitive-type*))
90 ;;; Return a list of TNs that can be used to represent an
91 ;;; unknown-values continuation within a function.
92 (!def-vm-support-routine make-unknown-values-locations ()
93 (list (make-stack-pointer-tn)
94 (make-normal-tn *fixnum-primitive-type*)))
97 ;;; This function is called by the Entry-Analyze phase, allowing
98 ;;; VM-dependent initialization of the IR2-Component structure. We
99 ;;; push placeholder entries in the Constants to leave room for
100 ;;; additional noise in the code object header.
101 (!def-vm-support-routine select-component-format (component)
102 (declare (type component component))
103 (dotimes (i code-constants-offset)
104 (vector-push-extend nil
105 (ir2-component-constants (component-info component))))
111 ;;; Return the number of bytes needed for the current non-descriptor
112 ;;; stack frame. Non-descriptor stack frames must be multiples of 8
113 ;;; bytes on the PMAX.
114 (defun bytes-needed-for-non-descriptor-stack-frame ()
115 (* (logandc2 (1+ (sb-allocated-size 'non-descriptor-stack)) 1)
118 ;;; This is used for setting up the Old-FP in local call.
119 (define-vop (current-fp)
120 (:results (val :scs (any-reg)))
124 ;;; This is used for computing the caller's NFP for use in
125 ;;; known-values return. It only works assuming there is no variable
126 ;;; size stuff on the nstack.
127 (define-vop (compute-old-nfp)
128 (:results (val :scs (any-reg)))
131 (let ((nfp (current-nfp-tn vop)))
133 (inst addq nfp (bytes-needed-for-non-descriptor-stack-frame) val)))))
135 (define-vop (xep-allocate-frame)
136 (:info start-lab copy-more-arg-follows)
137 (:ignore copy-more-arg-follows)
139 (:temporary (:scs (non-descriptor-reg)) temp)
141 ;; Make sure the function is aligned, and drop a label pointing to
142 ;; this function header.
144 (trace-table-entry trace-table-function-prologue)
145 (emit-label start-lab)
146 ;; Allocate function header.
147 (inst function-header-word)
148 (dotimes (i (1- function-code-offset))
150 ;; The start of the actual code.
151 ;; Compute CODE from the address of this entry point.
152 (let ((entry-point (gen-label)))
153 (emit-label entry-point)
154 (inst compute-code-from-fn code-tn lip-tn entry-point temp)
155 ;; ### We should also save it on the stack so that the garbage
156 ;; collector won't forget about us if we call anyone else.
158 ;; Build our stack frames.
159 (inst lda csp-tn (* word-bytes (sb-allocated-size 'control-stack)) cfp-tn)
160 (let ((nfp (current-nfp-tn vop)))
162 (inst subq nsp-tn (bytes-needed-for-non-descriptor-stack-frame)
165 (trace-table-entry trace-table-normal)))
167 (define-vop (allocate-frame)
168 (:results (res :scs (any-reg))
169 (nfp :scs (any-reg)))
172 (trace-table-entry trace-table-function-prologue)
174 (inst lda csp-tn (* word-bytes (sb-allocated-size 'control-stack)) csp-tn)
175 (when (ir2-environment-number-stack-p callee)
176 (inst subq nsp-tn (bytes-needed-for-non-descriptor-stack-frame)
179 (trace-table-entry trace-table-normal)))
181 ;;; Allocate a partial frame for passing stack arguments in a full
182 ;;; call. Nargs is the number of arguments passed. If no stack
183 ;;; arguments are passed, then we don't have to do anything.
184 (define-vop (allocate-full-call-frame)
186 (:results (res :scs (any-reg)))
188 (when (> nargs register-arg-count)
190 (inst lda csp-tn (* nargs word-bytes) csp-tn))))
194 ;;; Emit code needed at the return-point from an unknown-values call
195 ;;; for a fixed number of values. Values is the head of the TN-Ref
196 ;;; list for the locations that the values are to be received into.
197 ;;; Nvals is the number of values that are to be received (should
198 ;;; equal the length of Values).
200 ;;; Move-Temp is a Descriptor-Reg TN used as a temporary.
202 ;;; This code exploits the fact that in the unknown-values convention,
203 ;;; a single value return returns at the return PC + 8, whereas a
204 ;;; return of other than one value returns directly at the return PC.
206 ;;; If 0 or 1 values are expected, then we just emit an instruction to
207 ;;; reset the SP (which will only be executed when other than 1 value
210 ;;; In the general case, we have to do three things:
211 ;;; -- Default unsupplied register values. This need only be done when a
212 ;;; single value is returned, since register values are defaulted by the
213 ;;; called in the non-single case.
214 ;;; -- Default unsupplied stack values. This needs to be done whenever there
215 ;;; are stack values.
216 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
217 ;;; regardless of the number of values desired.
219 ;;; The general-case code looks like this:
221 b regs-defaulted ; Skip if MVs
224 move a1 null-tn ; Default register values
226 loadi nargs 1 ; Force defaulting of stack values
227 move ocfp csp ; Set up args for SP resetting
230 subu temp nargs register-arg-count
232 bltz temp default-value-7 ; jump to default code
234 loadw move-temp ocfp-tn 6 ; Move value to correct location.
235 store-stack-tn val4-tn move-temp
237 bltz temp default-value-8
239 loadw move-temp ocfp-tn 7
240 store-stack-tn val5-tn move-temp
245 move sp ocfp ; Reset SP.
250 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
253 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
260 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
261 (declare (type (or tn-ref null) values)
262 (type unsigned-byte nvals) (type tn move-temp temp))
265 ;; Note that this is a single-value return point. This is
266 ;; actually the multiple-value entry point for a single
267 ;; desired value, but the code location has to be here, or the
268 ;; debugger backtrace gets confused.
269 (without-scheduling ()
270 (note-this-location vop :single-value-return)
271 (move ocfp-tn csp-tn)
274 #!-gengc (inst compute-code-from-lra code-tn code-tn lra-label temp)
275 #!+gengc (inst compute-code-from-ra code-tn ra-tn lra-label temp)))
276 (let ((regs-defaulted (gen-label))
277 (defaulting-done (gen-label))
278 (default-stack-vals (gen-label)))
279 (without-scheduling ()
280 ;; Note that this is an unknown-values return point.
281 (note-this-location vop :unknown-return)
282 ;; If there are no stack results, clear the stack now.
283 (if (> nvals register-arg-count)
284 (inst subq nargs-tn (fixnumize register-arg-count) temp)
285 (move ocfp-tn csp-tn))
286 ;; Branch off to the MV case.
287 (inst br zero-tn regs-defaulted))
289 ;; Do the single value case.
291 (val (tn-ref-across values) (tn-ref-across val)))
292 ((= i (min nvals register-arg-count)))
293 (move null-tn (tn-ref-tn val)))
294 (when (> nvals register-arg-count)
295 (move csp-tn ocfp-tn)
296 (inst br zero-tn default-stack-vals))
298 (emit-label regs-defaulted)
300 (when (> nvals register-arg-count)
301 ;; If there are stack results, we have to default them
302 ;; and clear the stack.
303 (collect ((defaults))
304 (do ((i register-arg-count (1+ i))
305 (val (do ((i 0 (1+ i))
306 (val values (tn-ref-across val)))
307 ((= i register-arg-count) val))
308 (tn-ref-across val)))
311 (let ((default-lab (gen-label))
312 (tn (tn-ref-tn val)))
313 (defaults (cons default-lab tn))
315 (inst blt temp default-lab)
316 (inst ldl move-temp (* i word-bytes) ocfp-tn)
317 (inst subq temp (fixnumize 1) temp)
318 (store-stack-tn tn move-temp)))
320 (emit-label defaulting-done)
321 (move ocfp-tn csp-tn)
323 (let ((defaults (defaults)))
325 (assemble (*elsewhere*)
326 (emit-label default-stack-vals)
327 (do ((remaining defaults (cdr remaining)))
329 (let ((def (car remaining)))
330 (emit-label (car def))
331 (when (null (cdr remaining))
332 (inst br zero-tn defaulting-done))
333 (store-stack-tn (cdr def) null-tn)))))))
336 #!-gengc (inst compute-code-from-lra code-tn code-tn lra-label temp)
337 #!+gengc (inst compute-code-from-ra code-tn ra-tn lra-label temp))))
340 ;;;; unknown values receiving
342 ;;; Emit code needed at the return point for an unknown-values call
343 ;;; for an arbitrary number of values.
345 ;;; We do the single and non-single cases with no shared code: there
346 ;;; doesn't seem to be any potential overlap, and receiving a single
347 ;;; value is more important efficiency-wise.
349 ;;; When there is a single value, we just push it on the stack,
350 ;;; returning the old SP and 1.
352 ;;; When there is a variable number of values, we move all of the
353 ;;; argument registers onto the stack, and return Args and Nargs.
355 ;;; Args and Nargs are TNs wired to the named locations. We must
356 ;;; explicitly allocate these TNs, since their lifetimes overlap with
357 ;;; the results Start and Count (also, it's nice to be able to target
359 (defun receive-unknown-values (args nargs start count lra-label temp)
360 (declare (type tn args nargs start count temp))
361 (let ((variable-values (gen-label))
363 (without-scheduling ()
364 (inst br zero-tn variable-values)
368 #!-gengc (inst compute-code-from-lra code-tn code-tn lra-label temp)
369 #!+gengc (inst compute-code-from-ra code-tn ra-tn lra-label temp))
370 (inst addq csp-tn 4 csp-tn)
371 (storew (first *register-arg-tns*) csp-tn -1)
372 (inst subq csp-tn 4 start)
373 (inst li (fixnumize 1) count)
377 (assemble (*elsewhere*)
378 (emit-label variable-values)
380 #!-gengc (inst compute-code-from-lra code-tn code-tn lra-label temp)
381 #!+gengc (inst compute-code-from-ra code-tn ra-tn lra-label temp))
382 (do ((arg *register-arg-tns* (rest arg))
385 (storew (first arg) args i))
388 (inst br zero-tn done)))
391 ;;; a VOP that can be inherited by unknown values receivers. The main
392 ;;; thing this handles is allocation of the result temporaries.
393 (define-vop (unknown-values-receiver)
395 (start :scs (any-reg))
396 (count :scs (any-reg)))
397 (:temporary (:sc descriptor-reg :offset ocfp-offset
398 :from :eval :to (:result 0))
400 (:temporary (:sc any-reg :offset nargs-offset
401 :from :eval :to (:result 1))
403 (:temporary (:scs (non-descriptor-reg)) temp))
405 ;;;; local call with unknown values convention return
407 ;;; Non-TR local call for a fixed number of values passed according to the
408 ;;; unknown values convention.
410 ;;; Args are the argument passing locations, which are specified only to
411 ;;; terminate their lifetimes in the caller.
413 ;;; Values are the return value locations (wired to the standard passing
416 ;;; Save is the save info, which we can ignore since saving has been
417 ;;; done. Return-PC is the TN that the return PC should be passed in.
418 ;;; Target is a continuation pointing to the start of the called
419 ;;; function. Nvals is the number of values received.
421 ;;; Note: we can't use normal load-tn allocation for the fixed args,
422 ;;; since all registers may be tied up by the more operand. Instead,
423 ;;; we use MAYBE-LOAD-STACK-TN.
424 (define-vop (call-local)
428 (:results (values :more t))
430 (:move-args :local-call)
431 (:info arg-locs callee target nvals)
433 (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
434 (:temporary (:scs (non-descriptor-reg)) temp)
435 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
436 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
437 (:ignore arg-locs args ocfp)
439 (let ((label (gen-label))
440 (cur-nfp (current-nfp-tn vop)))
442 (store-stack-tn nfp-save cur-nfp))
443 (let ((callee-nfp (callee-nfp-tn callee)))
444 (maybe-load-stack-nfp-tn callee-nfp nfp temp))
445 (maybe-load-stack-tn cfp-tn fp)
446 (trace-table-entry trace-table-call-site)
447 (inst compute-lra-from-code
448 (callee-return-pc-tn callee) code-tn label temp)
449 (note-this-location vop :call-site)
450 (inst br zero-tn target)
451 (trace-table-entry trace-table-normal)
452 (emit-return-pc label)
453 (default-unknown-values vop values nvals move-temp temp label)
454 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp))))
457 ;;; Non-TR local call for a variable number of return values passed
458 ;;; according to the unknown values convention. The results are the
459 ;;; start of the values glob and the number of values received.
461 ;;; Note: we can't use normal load-tn allocation for the fixed args,
462 ;;; since all registers may be tied up by the more operand. Instead,
463 ;;; we use MAYBE-LOAD-STACK-TN.
464 (define-vop (multiple-call-local unknown-values-receiver)
469 (:move-args :local-call)
470 (:info save callee target)
473 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
474 (:temporary (:scs (non-descriptor-reg)) temp)
476 (let ((label (gen-label))
477 (cur-nfp (current-nfp-tn vop)))
479 (store-stack-tn nfp-save cur-nfp))
480 (let ((callee-nfp (callee-nfp-tn callee)))
481 (maybe-load-stack-nfp-tn callee-nfp nfp temp))
482 (maybe-load-stack-tn cfp-tn fp)
483 (trace-table-entry trace-table-call-site)
484 (inst compute-lra-from-code
485 (callee-return-pc-tn callee) code-tn label temp)
486 (note-this-location vop :call-site)
487 (inst bsr zero-tn target)
488 (trace-table-entry trace-table-normal)
489 (emit-return-pc label)
490 (note-this-location vop :unknown-return)
491 (receive-unknown-values values-start nvals start count label temp)
492 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp))))
495 ;;;; local call with known values return
497 ;;; Non-TR local call with known return locations. Known-value return
498 ;;; works just like argument passing in local call.
500 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
501 ;;; registers may be tied up by the more operand. Instead, we use
502 ;;; MAYBE-LOAD-STACK-TN.
503 (define-vop (known-call-local)
507 (:results (res :more t))
508 (:move-args :local-call)
510 (:info save callee target)
511 (:ignore args res save)
513 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
514 (:temporary (:scs (non-descriptor-reg)) temp)
516 (let (#!-gengc (label (gen-label))
517 (cur-nfp (current-nfp-tn vop)))
519 (store-stack-tn nfp-save cur-nfp))
520 (let ((callee-nfp (callee-nfp-tn callee)))
521 (maybe-load-stack-nfp-tn callee-nfp nfp temp))
522 (maybe-load-stack-tn cfp-tn fp)
523 (trace-table-entry trace-table-call-site)
524 (inst compute-lra-from-code
525 (callee-return-pc-tn callee) code-tn label temp)
526 (note-this-location vop :call-site)
527 (inst bsr zero-tn target)
528 (trace-table-entry trace-table-normal)
529 (emit-return-pc label)
530 (note-this-location vop :known-return)
531 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp))))
533 ;;; Return from known values call. We receive the return locations as
534 ;;; arguments to terminate their lifetimes in the returning function.
535 ;;; We restore FP and CSP and jump to the Return-PC.
537 ;;; Note: we can't use normal load-tn allocation for the fixed args,
538 ;;; since all registers may be tied up by the more operand. Instead,
539 ;;; we use MAYBE-LOAD-STACK-TN.
540 (define-vop (known-return)
541 (:args (ocfp :target ocfp-temp)
542 (return-pc :target return-pc-temp)
544 (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
545 (:temporary (:sc #!-gengc descriptor-reg #!+gengc any-reg
548 #!-gengc (:temporary (:scs (interior-reg)) lip)
549 (:move-args :known-return)
551 (:ignore val-locs vals)
554 (trace-table-entry trace-table-function-epilogue)
555 (maybe-load-stack-tn ocfp-temp ocfp)
556 (maybe-load-stack-tn return-pc-temp return-pc)
558 (let ((cur-nfp (current-nfp-tn vop)))
560 (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
562 (inst subq return-pc-temp (- other-pointer-type word-bytes) lip)
563 (move ocfp-temp cfp-tn)
564 (inst ret zero-tn lip 1)
565 (trace-table-entry trace-table-normal)))
570 ;;;; There is something of a cross-product effect with full calls.
571 ;;;; Different versions are used depending on whether we know the
572 ;;;; number of arguments or the name of the called function, and
573 ;;;; whether we want fixed values, unknown values, or a tail call.
575 ;;;; In full call, the arguments are passed creating a partial frame on
576 ;;;; the stack top and storing stack arguments into that frame. On
577 ;;;; entry to the callee, this partial frame is pointed to by FP. If
578 ;;;; there are no stack arguments, we don't bother allocating a partial
579 ;;;; frame, and instead set FP to SP just before the call.
581 ;;; This macro helps in the definition of full call VOPs by avoiding
582 ;;; code replication in defining the cross-product VOPs.
584 ;;; Name is the name of the VOP to define.
586 ;;; Named is true if the first argument is a symbol whose global
587 ;;; function definition is to be called.
589 ;;; Return is either :Fixed, :Unknown or :Tail:
590 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
591 ;;; the standard passing locations (passed as result operands).
592 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
593 ;;; result values are specified by the Start and Count as in the
594 ;;; unknown-values continuation representation.
595 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
596 ;;; The Ocfp and Return-PC are passed as the second and third arguments.
598 ;;; In non-tail calls, the pointer to the stack arguments is passed as
599 ;;; the last fixed argument. If Variable is false, then the passing
600 ;;; locations are passed as a more arg. Variable is true if there are
601 ;;; a variable number of arguments passed on the stack. Variable
602 ;;; cannot be specified with :Tail return. TR variable argument call
603 ;;; is implemented separately.
605 ;;; In tail call with fixed arguments, the passing locations are
606 ;;; passed as a more arg, but there is no new-FP, since the arguments
607 ;;; have been set up in the current frame.
608 (defmacro define-full-call (name named return variable)
609 (assert (not (and variable (eq return :tail))))
611 ,@(when (eq return :unknown)
612 '(unknown-values-receiver)))
614 ,@(unless (eq return :tail)
615 '((new-fp :scs (any-reg) :to :eval)))
618 '(name :target name-pass)
619 '(arg-fun :target lexenv))
621 ,@(when (eq return :tail)
622 '((ocfp :target ocfp-pass)
623 (return-pc :target return-pc-pass)))
625 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
627 ,@(when (eq return :fixed)
628 '((:results (values :more t))))
630 (:save-p ,(if (eq return :tail) :compute-only t))
632 ,@(unless (or (eq return :tail) variable)
633 '((:move-args :full-call)))
636 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
637 ,@(unless variable '(nargs))
638 ,@(when (eq return :fixed) '(nvals)))
640 (:ignore #!+gengc ,@(unless (eq return :tail) '(return-pc-pass))
641 ,@(unless (or variable (eq return :tail)) '(arg-locs))
642 ,@(unless variable '(args)))
644 (:temporary (:sc descriptor-reg
647 ,@(unless (eq return :fixed)
651 (:temporary (:sc descriptor-reg
652 :offset #!-gengc lra-offset #!+gengc ra-offset
653 :from (:argument ,(if (eq return :tail) 2 1))
658 `((:temporary (:sc descriptor-reg :offset fdefn-offset
659 :from (:argument ,(if (eq return :tail) 0 1))
663 `((:temporary (:sc descriptor-reg :offset lexenv-offset
664 :from (:argument ,(if (eq return :tail) 0 1))
668 (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
671 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
675 (mapcar #'(lambda (name offset)
676 `(:temporary (:sc descriptor-reg
680 register-arg-names *register-arg-offsets*))
681 ,@(when (eq return :fixed)
682 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
684 ,@(unless (eq return :tail)
685 '((:temporary (:scs (non-descriptor-reg)) temp)
686 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
688 (:temporary (:sc interior-reg :offset lip-offset) entry-point)
690 (:generator ,(+ (if named 5 0)
692 (if (eq return :tail) 0 10)
694 (if (eq return :unknown) 25 0))
695 (let* ((cur-nfp (current-nfp-tn vop))
696 ,@(unless (eq return :tail)
697 '((lra-label (gen-label))))
701 ,@(if (eq return :tail)
702 '((unless (location= ocfp ocfp-pass)
704 (unless (location= return-pc
715 (flet ((do-next-filler ()
716 (let* ((next (pop filler))
717 (what (if (consp next) (car next) next)))
721 `((inst subq csp-tn new-fp nargs-pass)
723 (mapcar #'(lambda (name)
728 register-arg-names)))
729 '((inst li (fixnumize nargs) nargs-pass))))
730 ,@(if (eq return :tail)
734 (inst move ocfp ocfp-pass))
737 (ash (tn-offset ocfp)
742 (#!-gengc descriptor-reg #!+gengc any-reg
743 (inst move return-pc return-pc-pass))
745 (inst ldl return-pc-pass
746 (ash (tn-offset return-pc)
751 (bytes-needed-for-non-descriptor-stack-frame)
755 (inst compute-lra-from-code
756 return-pc-pass code-tn lra-label temp))
758 (store-stack-tn nfp-save cur-nfp))
760 (inst move cfp-tn ocfp-pass))
763 '(move new-fp cfp-tn)
764 '(if (> nargs register-arg-count)
766 (move csp-tn cfp-tn)))
767 (trace-table-entry trace-table-call-site))))
772 (descriptor-reg (move name name-pass))
775 (ash (tn-offset name) word-shift) cfp-tn)
779 (- (ash (tn-offset name) word-shift)
780 other-pointer-type) code-tn)
782 (inst ldl entry-point
783 (- (ash fdefn-raw-addr-slot word-shift)
784 other-pointer-type) name-pass)
787 (descriptor-reg (move arg-fun lexenv))
790 (ash (tn-offset arg-fun) word-shift) cfp-tn)
794 (- (ash (tn-offset arg-fun) word-shift)
795 other-pointer-type) code-tn)
799 (- (ash closure-function-slot word-shift)
800 function-pointer-type) lexenv)
805 (- (ash function-code-offset word-shift)
806 function-pointer-type) entry-point)
808 (inst ldl entry-point
809 (- (ash closure-entry-point-slot word-shift)
810 function-pointer-type) lexenv)
818 (note-this-location vop :call-site)
820 (inst jsr zero-tn entry-point))
824 '((trace-table-entry trace-table-normal)
825 (emit-return-pc lra-label)
826 (default-unknown-values vop values nvals
827 move-temp temp lra-label)
828 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp)))
830 '((trace-table-entry trace-table-normal)
831 (emit-return-pc lra-label)
832 (note-this-location vop :unknown-return)
833 (receive-unknown-values values-start nvals start count
835 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp)))
838 (define-full-call call nil :fixed nil)
839 (define-full-call call-named t :fixed nil)
840 (define-full-call multiple-call nil :unknown nil)
841 (define-full-call multiple-call-named t :unknown nil)
842 (define-full-call tail-call nil :tail nil)
843 (define-full-call tail-call-named t :tail nil)
845 (define-full-call call-variable nil :fixed t)
846 (define-full-call multiple-call-variable nil :unknown t)
848 ;;; This is defined separately, since it needs special code that blits
849 ;;; the arguments down.
850 (define-vop (tail-call-variable)
852 (args-arg :scs (any-reg) :target args)
853 (function-arg :scs (descriptor-reg) :target lexenv)
854 (ocfp-arg :scs (any-reg) :target ocfp)
855 (lra-arg :scs (#!-gengc descriptor-reg #!+gengc any-reg) :target lra))
857 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
858 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
859 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
860 (:temporary (:sc any-reg :offset #!-gengc lra-offset #!+gengc ra-offset
861 :from (:argument 3)) lra)
862 (:temporary (:scs (non-descriptor-reg)) temp)
868 ;; Move these into the passing locations if they are not already there.
870 (move function-arg lexenv)
874 ;; Clear the number stack if anything is there.
875 (let ((cur-nfp (current-nfp-tn vop)))
877 (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
880 ;; And jump to the assembly-routine that does the bliting.
881 (inst li (make-fixup 'tail-call-variable :assembly-routine) temp)
882 (inst jmp zero-tn temp)))
884 ;;;; unknown values return
886 ;;; Return a single value using the unknown-values convention.
887 (define-vop (return-single)
888 (:args (ocfp :scs (any-reg))
889 #!-gengc (return-pc :scs (descriptor-reg))
890 #!+gengc (return-pc :scs (any-reg) :target ra)
893 #!-gengc (:temporary (:scs (interior-reg)) lip)
894 #!+gengc (:temporary (:sc any-reg :offset ra-offset :from (:argument 1)) ra)
895 #!+gengc (:temporary (:scs (any-reg) :from (:argument 1)) temp)
898 ;; Clear the number stack.
899 (trace-table-entry trace-table-function-epilogue)
900 (let ((cur-nfp (current-nfp-tn vop)))
902 (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
904 ;; Clear the control stack, and restore the frame pointer.
908 #!-gengc (lisp-return return-pc lip :offset 2)
911 (inst addq return-pc (* 2 word-bytes) temp)
912 (unless (location= ra return-pc)
913 (inst move ra return-pc))
914 (inst ret zero-tn temp 1))
915 (trace-table-entry trace-table-normal)))
917 ;;; Do unknown-values return of a fixed number of values. The Values
918 ;;; are required to be set up in the standard passing locations. Nvals
919 ;;; is the number of values returned.
921 ;;; If returning a single value, then deallocate the current frame,
922 ;;; restore FP and jump to the single-value entry at Return-PC + 8.
924 ;;; If returning other than one value, then load the number of values
925 ;;; returned, NIL out unsupplied values registers, restore FP and
926 ;;; return at Return-PC. When there are stack values, we must
927 ;;; initialize the argument pointer to point to the beginning of the
928 ;;; values block (which is the beginning of the current frame.)
930 (:args (ocfp :scs (any-reg))
931 (return-pc :scs (#!-gengc descriptor-reg #!+gengc any-reg)
933 #!+gengc :target #!+gengc ra)
937 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
938 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
939 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
940 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
941 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
942 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
943 (:temporary (:sc any-reg :offset nargs-offset) nargs)
944 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
945 #!-gengc (:temporary (:scs (interior-reg)) lip)
946 #!+gengc (:temporary (:sc any-reg :offset ra-offset :from (:eval 1)) ra)
949 ;; Clear the number stack.
950 (trace-table-entry trace-table-function-epilogue)
951 (let ((cur-nfp (current-nfp-tn vop)))
953 (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
955 ;; Establish the values pointer and values count.
956 (move cfp-tn val-ptr)
957 (inst li (fixnumize nvals) nargs)
958 ;; restore the frame pointer and clear as much of the control
959 ;; stack as possible.
961 (inst addq val-ptr (* nvals word-bytes) csp-tn)
962 ;; pre-default any argument register that need it.
963 (when (< nvals register-arg-count)
964 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
967 (lisp-return return-pc lip)
968 (trace-table-entry trace-table-normal)))
970 ;;; Do unknown-values return of an arbitrary number of values (passed
971 ;;; on the stack.) We check for the common case of a single return
972 ;;; value, and do that inline using the normal single value return
973 ;;; convention. Otherwise, we branch off to code that calls an
974 ;;; assembly-routine.
975 (define-vop (return-multiple)
976 (:args (ocfp-arg :scs (any-reg) :target ocfp)
977 #!-gengc (lra-arg :scs (descriptor-reg) :target lra)
978 #!+gengc (return-pc :scs (any-reg) :target ra)
979 (vals-arg :scs (any-reg) :target vals)
980 (nvals-arg :scs (any-reg) :target nvals))
982 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
984 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
986 (:temporary (:sc any-reg :offset ra-offset :from (:argument 1)) ra)
987 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
988 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
989 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
990 (:temporary (:scs (non-descriptor-reg)) temp)
991 #!-gengc (:temporary (:scs (interior-reg)) lip)
992 #!+gengc (:temporary (:scs (any-reg) :from (:argument 0)) temp)
997 (trace-table-entry trace-table-function-epilogue)
998 (let ((not-single (gen-label)))
999 ;; Clear the number stack.
1000 (let ((cur-nfp (current-nfp-tn vop)))
1002 (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
1005 ;; Check for the single case.
1006 (inst li (fixnumize 1) a0)
1007 (inst cmpeq nvals-arg a0 temp)
1008 (inst ldl a0 0 vals-arg)
1009 (inst beq temp not-single)
1011 ;; Return with one value.
1012 (move cfp-tn csp-tn)
1013 (move ocfp-arg cfp-tn)
1014 (lisp-return lra-arg lip :offset 2)
1016 ;; Nope, not the single case.
1017 (emit-label not-single)
1018 (move ocfp-arg ocfp)
1020 (move vals-arg vals)
1021 (move nvals-arg nvals)
1022 (inst li (make-fixup 'return-multiple :assembly-routine) temp)
1023 (inst jmp zero-tn temp))
1024 (trace-table-entry trace-table-normal)))
1028 ;;; We don't need to do anything special for regular functions.
1029 (define-vop (setup-environment)
1033 ;; Don't bother doing anything.
1036 ;;; Get the lexical environment from its passing location.
1037 (define-vop (setup-closure-environment)
1038 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1041 (:results (closure :scs (descriptor-reg)))
1046 (move lexenv closure)))
1048 ;;; Copy a &MORE arg from the argument area to the end of the current
1049 ;;; frame. FIXED is the number of non-more arguments.
1050 (define-vop (copy-more-arg)
1051 (:temporary (:sc any-reg :offset nl0-offset) result)
1052 (:temporary (:sc any-reg :offset nl1-offset) count)
1053 (:temporary (:sc any-reg :offset nl2-offset) src)
1054 (:temporary (:sc any-reg :offset nl4-offset) dst)
1055 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1058 (let ((loop (gen-label))
1059 (do-regs (gen-label))
1061 (when (< fixed register-arg-count)
1062 ;; Save a pointer to the results so we can fill in register args.
1063 ;; We don't need this if there are more fixed args than reg args.
1064 (move csp-tn result))
1065 ;; Allocate the space on the stack.
1066 (cond ((zerop fixed)
1067 (inst addq csp-tn nargs-tn csp-tn)
1068 (inst beq nargs-tn done))
1070 (inst subq nargs-tn (fixnumize fixed) count)
1071 (inst ble count done)
1072 (inst addq csp-tn count csp-tn)))
1073 (when (< fixed register-arg-count)
1074 ;; We must stop when we run out of stack args, not when we run out of
1076 (inst subq nargs-tn (fixnumize register-arg-count) count))
1077 ;; Initialize dst to be end of stack.
1079 ;; Everything of interest in registers.
1080 (inst ble count do-regs)
1081 ;; Initialize src to be end of args.
1082 (inst addq cfp-tn nargs-tn src)
1085 ;; *--dst = *--src, --count
1086 (inst subq src word-bytes src)
1087 (inst subq count (fixnumize 1) count)
1089 (inst subq dst word-bytes dst)
1091 (inst bgt count loop)
1093 (emit-label do-regs)
1094 (when (< fixed register-arg-count)
1095 ;; Now we have to deposit any more args that showed up in registers.
1096 ;; We know there is at least one more arg, otherwise we would have
1097 ;; branched to done up at the top.
1098 (inst subq nargs-tn (fixnumize (1+ fixed)) count)
1099 (do ((i fixed (1+ i)))
1100 ((>= i register-arg-count))
1101 ;; Store it relative to the pointer saved at the start.
1102 (storew (nth i *register-arg-tns*) result (- i fixed))
1103 ;; Is this the last one?
1104 (inst beq count done)
1106 (inst subq count (fixnumize 1) count)))
1107 (emit-label done))))
1109 ;;; &More args are stored consecutively on the stack, starting
1110 ;;; immediately at the context pointer. The context pointer is not
1111 ;;; typed, so the lowtag is 0.
1112 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1114 ;;; Turn &MORE arg (context, count) into a list.
1115 (define-vop (listify-rest-args)
1116 (:args (context-arg :target context :scs (descriptor-reg))
1117 (count-arg :target count :scs (any-reg)))
1118 (:arg-types * tagged-num)
1119 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1120 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1121 (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1122 (:results (result :scs (descriptor-reg)))
1123 (:translate %listify-rest-args)
1126 (let ((enter (gen-label))
1129 (move context-arg context)
1130 (move count-arg count)
1131 ;; Check to see if there are any arguments.
1132 (move null-tn result)
1133 (inst beq count done)
1135 ;; We need to do this atomically.
1137 ;; Allocate a cons (2 words) for each item.
1138 (inst bis alloc-tn list-pointer-type result)
1140 (inst sll count 1 temp)
1141 (inst addq alloc-tn temp alloc-tn)
1142 (inst br zero-tn enter)
1144 ;; Store the current cons in the cdr of the previous cons.
1146 (inst addq dst (* 2 word-bytes) dst)
1147 (storew dst dst -1 list-pointer-type)
1151 (loadw temp context)
1152 (inst addq context word-bytes context)
1154 ;; Store the value in the car (in delay slot)
1155 (storew temp dst 0 list-pointer-type)
1157 ;; Dec count, and if != zero, go back for more.
1158 (inst subq count (fixnumize 1) count)
1159 (inst bne count loop)
1161 ;; NIL out the last cons.
1162 (storew null-tn dst 1 list-pointer-type))
1163 (emit-label done))))
1165 ;;; Return the location and size of the &MORE arg glob created by
1166 ;;; Copy-More-Arg. Supplied is the total number of arguments supplied
1167 ;;; (originally passed in NARGS.) Fixed is the number of non-&rest
1170 ;;; We must duplicate some of the work done by Copy-More-Arg, since at
1171 ;;; that time the environment is in a pretty brain-damaged state,
1172 ;;; preventing this info from being returned as values. What we do is
1173 ;;; compute supplied - fixed, and return a pointer that many words
1174 ;;; below the current stack top.
1175 (define-vop (more-arg-context)
1176 (:policy :fast-safe)
1177 (:translate sb!c::%more-arg-context)
1178 (:args (supplied :scs (any-reg)))
1179 (:arg-types tagged-num (:constant fixnum))
1181 (:results (context :scs (descriptor-reg))
1182 (count :scs (any-reg)))
1183 (:result-types t tagged-num)
1184 (:note "more-arg-context")
1186 (inst subq supplied (fixnumize fixed) count)
1187 (inst subq csp-tn count context)))
1190 ;;; Signal wrong argument count error if Nargs isn't equal to Count.
1191 (define-vop (verify-argument-count)
1192 (:policy :fast-safe)
1193 (:translate sb!c::%verify-argument-count)
1194 (:args (nargs :scs (any-reg)))
1195 (:arg-types positive-fixnum (:constant t))
1196 (:temporary (:scs (any-reg) :type fixnum) temp)
1199 (:save-p :compute-only)
1202 (generate-error-code vop invalid-argument-count-error nargs)))
1203 (cond ((zerop count)
1204 (inst bne nargs err-lab))
1206 (inst subq nargs (fixnumize count) temp)
1207 (inst bne temp err-lab))))))
1209 ;;; various other error signalers
1210 (macrolet ((frob (name error translate &rest args)
1211 `(define-vop (,name)
1213 `((:policy :fast-safe)
1214 (:translate ,translate)))
1215 (:args ,@(mapcar #'(lambda (arg)
1216 `(,arg :scs (any-reg descriptor-reg)))
1219 (:save-p :compute-only)
1221 (error-call vop ,error ,@args)))))
1222 (frob argument-count-error invalid-argument-count-error
1223 sb!c::%argument-count-error nargs)
1224 (frob type-check-error object-not-type-error sb!c::%type-check-error
1226 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1228 (frob odd-key-arguments-error odd-key-arguments-error
1229 sb!c::%odd-key-arguments-error)
1230 (frob unknown-key-argument-error unknown-key-argument-error
1231 sb!c::%unknown-key-argument-error key)
1232 (frob nil-function-returned-error nil-function-returned-error nil fun))