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))))
192 ;;; Emit code needed at the return-point from an unknown-values call
193 ;;; for a fixed number of values. Values is the head of the TN-Ref
194 ;;; list for the locations that the values are to be received into.
195 ;;; Nvals is the number of values that are to be received (should
196 ;;; equal the length of Values).
198 ;;; Move-Temp is a Descriptor-Reg TN used as a temporary.
200 ;;; This code exploits the fact that in the unknown-values convention,
201 ;;; a single value return returns at the return PC + 8, whereas a
202 ;;; return of other than one value returns directly at the return PC.
204 ;;; If 0 or 1 values are expected, then we just emit an instruction to
205 ;;; reset the SP (which will only be executed when other than 1 value
208 ;;; In the general case, we have to do three things:
209 ;;; -- Default unsupplied register values. This need only be done when a
210 ;;; single value is returned, since register values are defaulted by the
211 ;;; called in the non-single case.
212 ;;; -- Default unsupplied stack values. This needs to be done whenever there
213 ;;; are stack values.
214 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
215 ;;; regardless of the number of values desired.
217 ;;; The general-case code looks like this:
219 b regs-defaulted ; Skip if MVs
222 move a1 null-tn ; Default register values
224 loadi nargs 1 ; Force defaulting of stack values
225 move ocfp csp ; Set up args for SP resetting
228 subu temp nargs register-arg-count
230 bltz temp default-value-7 ; jump to default code
232 loadw move-temp ocfp-tn 6 ; Move value to correct location.
233 store-stack-tn val4-tn move-temp
235 bltz temp default-value-8
237 loadw move-temp ocfp-tn 7
238 store-stack-tn val5-tn move-temp
243 move sp ocfp ; Reset SP.
248 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
251 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
258 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
259 (declare (type (or tn-ref null) values)
260 (type unsigned-byte nvals) (type tn move-temp temp))
263 ;; Note that this is a single-value return point. This is
264 ;; actually the multiple-value entry point for a single
265 ;; desired value, but the code location has to be here, or the
266 ;; debugger backtrace gets confused.
267 (without-scheduling ()
268 (note-this-location vop :single-value-return)
269 (move ocfp-tn csp-tn)
272 #!-gengc (inst compute-code-from-lra code-tn code-tn lra-label temp)
273 #!+gengc (inst compute-code-from-ra code-tn ra-tn lra-label temp)))
274 (let ((regs-defaulted (gen-label))
275 (defaulting-done (gen-label))
276 (default-stack-vals (gen-label)))
277 (without-scheduling ()
278 ;; Note that this is an unknown-values return point.
279 (note-this-location vop :unknown-return)
280 ;; If there are no stack results, clear the stack now.
281 (if (> nvals register-arg-count)
282 (inst subq nargs-tn (fixnumize register-arg-count) temp)
283 (move ocfp-tn csp-tn))
284 ;; Branch off to the MV case.
285 (inst br zero-tn regs-defaulted))
287 ;; Do the single value case.
289 (val (tn-ref-across values) (tn-ref-across val)))
290 ((= i (min nvals register-arg-count)))
291 (move null-tn (tn-ref-tn val)))
292 (when (> nvals register-arg-count)
293 (move csp-tn ocfp-tn)
294 (inst br zero-tn default-stack-vals))
296 (emit-label regs-defaulted)
298 (when (> nvals register-arg-count)
299 ;; If there are stack results, we have to default them
300 ;; and clear the stack.
301 (collect ((defaults))
302 (do ((i register-arg-count (1+ i))
303 (val (do ((i 0 (1+ i))
304 (val values (tn-ref-across val)))
305 ((= i register-arg-count) val))
306 (tn-ref-across val)))
309 (let ((default-lab (gen-label))
310 (tn (tn-ref-tn val)))
311 (defaults (cons default-lab tn))
313 (inst blt temp default-lab)
314 (inst ldl move-temp (* i word-bytes) ocfp-tn)
315 (inst subq temp (fixnumize 1) temp)
316 (store-stack-tn tn move-temp)))
318 (emit-label defaulting-done)
319 (move ocfp-tn csp-tn)
321 (let ((defaults (defaults)))
323 (assemble (*elsewhere*)
324 (emit-label default-stack-vals)
325 (do ((remaining defaults (cdr remaining)))
327 (let ((def (car remaining)))
328 (emit-label (car def))
329 (when (null (cdr remaining))
330 (inst br zero-tn defaulting-done))
331 (store-stack-tn (cdr def) null-tn)))))))
334 #!-gengc (inst compute-code-from-lra code-tn code-tn lra-label temp)
335 #!+gengc (inst compute-code-from-ra code-tn ra-tn lra-label temp))))
338 ;;;; unknown values receiving
340 ;;; Emit code needed at the return point for an unknown-values call
341 ;;; for an arbitrary number of values.
343 ;;; We do the single and non-single cases with no shared code: there
344 ;;; doesn't seem to be any potential overlap, and receiving a single
345 ;;; value is more important efficiency-wise.
347 ;;; When there is a single value, we just push it on the stack,
348 ;;; returning the old SP and 1.
350 ;;; When there is a variable number of values, we move all of the
351 ;;; argument registers onto the stack, and return Args and Nargs.
353 ;;; Args and Nargs are TNs wired to the named locations. We must
354 ;;; explicitly allocate these TNs, since their lifetimes overlap with
355 ;;; the results Start and Count (also, it's nice to be able to target
357 (defun receive-unknown-values (args nargs start count lra-label temp)
358 (declare (type tn args nargs start count temp))
359 (let ((variable-values (gen-label))
361 (without-scheduling ()
362 (inst br zero-tn variable-values)
366 #!-gengc (inst compute-code-from-lra code-tn code-tn lra-label temp)
367 #!+gengc (inst compute-code-from-ra code-tn ra-tn lra-label temp))
368 (inst addq csp-tn 4 csp-tn)
369 (storew (first *register-arg-tns*) csp-tn -1)
370 (inst subq csp-tn 4 start)
371 (inst li (fixnumize 1) count)
375 (assemble (*elsewhere*)
376 (emit-label variable-values)
378 #!-gengc (inst compute-code-from-lra code-tn code-tn lra-label temp)
379 #!+gengc (inst compute-code-from-ra code-tn ra-tn lra-label temp))
380 (do ((arg *register-arg-tns* (rest arg))
383 (storew (first arg) args i))
386 (inst br zero-tn done)))
389 ;;; a VOP that can be inherited by unknown values receivers. The main
390 ;;; thing this handles is allocation of the result temporaries.
391 (define-vop (unknown-values-receiver)
393 (start :scs (any-reg))
394 (count :scs (any-reg)))
395 (:temporary (:sc descriptor-reg :offset ocfp-offset
396 :from :eval :to (:result 0))
398 (:temporary (:sc any-reg :offset nargs-offset
399 :from :eval :to (:result 1))
401 (:temporary (:scs (non-descriptor-reg)) temp))
403 ;;;; local call with unknown values convention return
405 ;;; Non-TR local call for a fixed number of values passed according to the
406 ;;; unknown values convention.
408 ;;; Args are the argument passing locations, which are specified only to
409 ;;; terminate their lifetimes in the caller.
411 ;;; Values are the return value locations (wired to the standard passing
414 ;;; Save is the save info, which we can ignore since saving has been
415 ;;; done. Return-PC is the TN that the return PC should be passed in.
416 ;;; Target is a continuation pointing to the start of the called
417 ;;; function. Nvals is the number of values received.
419 ;;; Note: we can't use normal load-tn allocation for the fixed args,
420 ;;; since all registers may be tied up by the more operand. Instead,
421 ;;; we use MAYBE-LOAD-STACK-TN.
422 (define-vop (call-local)
426 (:results (values :more t))
428 (:move-args :local-call)
429 (:info arg-locs callee target nvals)
431 (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
432 (:temporary (:scs (non-descriptor-reg)) temp)
433 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
434 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
435 (:ignore arg-locs args ocfp)
437 (let ((label (gen-label))
438 (cur-nfp (current-nfp-tn vop)))
440 (store-stack-tn nfp-save cur-nfp))
441 (let ((callee-nfp (callee-nfp-tn callee)))
442 (maybe-load-stack-nfp-tn callee-nfp nfp temp))
443 (maybe-load-stack-tn cfp-tn fp)
444 (trace-table-entry trace-table-call-site)
445 (inst compute-lra-from-code
446 (callee-return-pc-tn callee) code-tn label temp)
447 (note-this-location vop :call-site)
448 (inst br zero-tn target)
449 (trace-table-entry trace-table-normal)
450 (emit-return-pc label)
451 (default-unknown-values vop values nvals move-temp temp label)
452 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp))))
455 ;;; Non-TR local call for a variable number of return values passed
456 ;;; according to the unknown values convention. The results are the
457 ;;; start of the values glob and the number of values received.
459 ;;; Note: we can't use normal load-tn allocation for the fixed args,
460 ;;; since all registers may be tied up by the more operand. Instead,
461 ;;; we use MAYBE-LOAD-STACK-TN.
462 (define-vop (multiple-call-local unknown-values-receiver)
467 (:move-args :local-call)
468 (:info save callee target)
471 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
472 (:temporary (:scs (non-descriptor-reg)) temp)
474 (let ((label (gen-label))
475 (cur-nfp (current-nfp-tn vop)))
477 (store-stack-tn nfp-save cur-nfp))
478 (let ((callee-nfp (callee-nfp-tn callee)))
479 (maybe-load-stack-nfp-tn callee-nfp nfp temp))
480 (maybe-load-stack-tn cfp-tn fp)
481 (trace-table-entry trace-table-call-site)
482 (inst compute-lra-from-code
483 (callee-return-pc-tn callee) code-tn label temp)
484 (note-this-location vop :call-site)
485 (inst bsr zero-tn target)
486 (trace-table-entry trace-table-normal)
487 (emit-return-pc label)
488 (note-this-location vop :unknown-return)
489 (receive-unknown-values values-start nvals start count label temp)
490 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp))))
493 ;;;; local call with known values return
495 ;;; Non-TR local call with known return locations. Known-value return
496 ;;; works just like argument passing in local call.
498 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
499 ;;; registers may be tied up by the more operand. Instead, we use
500 ;;; MAYBE-LOAD-STACK-TN.
501 (define-vop (known-call-local)
505 (:results (res :more t))
506 (:move-args :local-call)
508 (:info save callee target)
509 (:ignore args res save)
511 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
512 (:temporary (:scs (non-descriptor-reg)) temp)
514 (let (#!-gengc (label (gen-label))
515 (cur-nfp (current-nfp-tn vop)))
517 (store-stack-tn nfp-save cur-nfp))
518 (let ((callee-nfp (callee-nfp-tn callee)))
519 (maybe-load-stack-nfp-tn callee-nfp nfp temp))
520 (maybe-load-stack-tn cfp-tn fp)
521 (trace-table-entry trace-table-call-site)
522 (inst compute-lra-from-code
523 (callee-return-pc-tn callee) code-tn label temp)
524 (note-this-location vop :call-site)
525 (inst bsr zero-tn target)
526 (trace-table-entry trace-table-normal)
527 (emit-return-pc label)
528 (note-this-location vop :known-return)
529 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp))))
531 ;;; Return from known values call. We receive the return locations as
532 ;;; arguments to terminate their lifetimes in the returning function.
533 ;;; We restore FP and CSP and jump to the Return-PC.
535 ;;; Note: we can't use normal load-tn allocation for the fixed args,
536 ;;; since all registers may be tied up by the more operand. Instead,
537 ;;; we use MAYBE-LOAD-STACK-TN.
538 (define-vop (known-return)
539 (:args (ocfp :target ocfp-temp)
540 (return-pc :target return-pc-temp)
542 (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
543 (:temporary (:sc #!-gengc descriptor-reg #!+gengc any-reg
546 #!-gengc (:temporary (:scs (interior-reg)) lip)
547 (:move-args :known-return)
549 (:ignore val-locs vals)
552 (trace-table-entry trace-table-function-epilogue)
553 (maybe-load-stack-tn ocfp-temp ocfp)
554 (maybe-load-stack-tn return-pc-temp return-pc)
556 (let ((cur-nfp (current-nfp-tn vop)))
558 (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
560 (inst subq return-pc-temp (- other-pointer-type word-bytes) lip)
561 (move ocfp-temp cfp-tn)
562 (inst ret zero-tn lip 1)
563 (trace-table-entry trace-table-normal)))
568 ;;;; There is something of a cross-product effect with full calls.
569 ;;;; Different versions are used depending on whether we know the
570 ;;;; number of arguments or the name of the called function, and
571 ;;;; whether we want fixed values, unknown values, or a tail call.
573 ;;;; In full call, the arguments are passed creating a partial frame on
574 ;;;; the stack top and storing stack arguments into that frame. On
575 ;;;; entry to the callee, this partial frame is pointed to by FP. If
576 ;;;; there are no stack arguments, we don't bother allocating a partial
577 ;;;; frame, and instead set FP to SP just before the call.
579 ;;; This macro helps in the definition of full call VOPs by avoiding
580 ;;; code replication in defining the cross-product VOPs.
582 ;;; Name is the name of the VOP to define.
584 ;;; Named is true if the first argument is a symbol whose global
585 ;;; function definition is to be called.
587 ;;; Return is either :Fixed, :Unknown or :Tail:
588 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
589 ;;; the standard passing locations (passed as result operands).
590 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
591 ;;; result values are specified by the Start and Count as in the
592 ;;; unknown-values continuation representation.
593 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
594 ;;; The Ocfp and Return-PC are passed as the second and third arguments.
596 ;;; In non-tail calls, the pointer to the stack arguments is passed as
597 ;;; the last fixed argument. If Variable is false, then the passing
598 ;;; locations are passed as a more arg. Variable is true if there are
599 ;;; a variable number of arguments passed on the stack. Variable
600 ;;; cannot be specified with :Tail return. TR variable argument call
601 ;;; is implemented separately.
603 ;;; In tail call with fixed arguments, the passing locations are
604 ;;; passed as a more arg, but there is no new-FP, since the arguments
605 ;;; have been set up in the current frame.
606 (defmacro define-full-call (name named return variable)
607 (assert (not (and variable (eq return :tail))))
609 ,@(when (eq return :unknown)
610 '(unknown-values-receiver)))
612 ,@(unless (eq return :tail)
613 '((new-fp :scs (any-reg) :to :eval)))
616 '(name :target name-pass)
617 '(arg-fun :target lexenv))
619 ,@(when (eq return :tail)
620 '((ocfp :target ocfp-pass)
621 (return-pc :target return-pc-pass)))
623 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
625 ,@(when (eq return :fixed)
626 '((:results (values :more t))))
628 (:save-p ,(if (eq return :tail) :compute-only t))
630 ,@(unless (or (eq return :tail) variable)
631 '((:move-args :full-call)))
634 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
635 ,@(unless variable '(nargs))
636 ,@(when (eq return :fixed) '(nvals)))
638 (:ignore #!+gengc ,@(unless (eq return :tail) '(return-pc-pass))
639 ,@(unless (or variable (eq return :tail)) '(arg-locs))
640 ,@(unless variable '(args)))
642 (:temporary (:sc descriptor-reg
645 ,@(unless (eq return :fixed)
649 (:temporary (:sc descriptor-reg
650 :offset #!-gengc lra-offset #!+gengc ra-offset
651 :from (:argument ,(if (eq return :tail) 2 1))
656 `((:temporary (:sc descriptor-reg :offset fdefn-offset
657 :from (:argument ,(if (eq return :tail) 0 1))
661 `((:temporary (:sc descriptor-reg :offset lexenv-offset
662 :from (:argument ,(if (eq return :tail) 0 1))
666 (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
669 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
673 (mapcar #'(lambda (name offset)
674 `(:temporary (:sc descriptor-reg
678 register-arg-names *register-arg-offsets*))
679 ,@(when (eq return :fixed)
680 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
682 ,@(unless (eq return :tail)
683 '((:temporary (:scs (non-descriptor-reg)) temp)
684 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
686 (:temporary (:sc interior-reg :offset lip-offset) entry-point)
688 (:generator ,(+ (if named 5 0)
690 (if (eq return :tail) 0 10)
692 (if (eq return :unknown) 25 0))
693 (let* ((cur-nfp (current-nfp-tn vop))
694 ,@(unless (eq return :tail)
695 '((lra-label (gen-label))))
699 ,@(if (eq return :tail)
700 '((unless (location= ocfp ocfp-pass)
702 (unless (location= return-pc
713 (flet ((do-next-filler ()
714 (let* ((next (pop filler))
715 (what (if (consp next) (car next) next)))
719 `((inst subq csp-tn new-fp nargs-pass)
721 (mapcar #'(lambda (name)
726 register-arg-names)))
727 '((inst li (fixnumize nargs) nargs-pass))))
728 ,@(if (eq return :tail)
732 (inst move ocfp ocfp-pass))
735 (ash (tn-offset ocfp)
740 (#!-gengc descriptor-reg #!+gengc any-reg
741 (inst move return-pc return-pc-pass))
743 (inst ldl return-pc-pass
744 (ash (tn-offset return-pc)
749 (bytes-needed-for-non-descriptor-stack-frame)
753 (inst compute-lra-from-code
754 return-pc-pass code-tn lra-label temp))
756 (store-stack-tn nfp-save cur-nfp))
758 (inst move cfp-tn ocfp-pass))
761 '(move new-fp cfp-tn)
762 '(if (> nargs register-arg-count)
764 (move csp-tn cfp-tn)))
765 (trace-table-entry trace-table-call-site))))
770 (descriptor-reg (move name name-pass))
773 (ash (tn-offset name) word-shift) cfp-tn)
777 (- (ash (tn-offset name) word-shift)
778 other-pointer-type) code-tn)
780 (inst ldl entry-point
781 (- (ash fdefn-raw-addr-slot word-shift)
782 other-pointer-type) name-pass)
785 (descriptor-reg (move arg-fun lexenv))
788 (ash (tn-offset arg-fun) word-shift) cfp-tn)
792 (- (ash (tn-offset arg-fun) word-shift)
793 other-pointer-type) code-tn)
797 (- (ash closure-function-slot word-shift)
798 function-pointer-type) lexenv)
803 (- (ash function-code-offset word-shift)
804 function-pointer-type) entry-point)
806 (inst ldl entry-point
807 (- (ash closure-entry-point-slot word-shift)
808 function-pointer-type) lexenv)
816 (note-this-location vop :call-site)
818 (inst jsr zero-tn entry-point))
822 '((trace-table-entry trace-table-normal)
823 (emit-return-pc lra-label)
824 (default-unknown-values vop values nvals
825 move-temp temp lra-label)
826 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp)))
828 '((trace-table-entry trace-table-normal)
829 (emit-return-pc lra-label)
830 (note-this-location vop :unknown-return)
831 (receive-unknown-values values-start nvals start count
833 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp)))
836 (define-full-call call nil :fixed nil)
837 (define-full-call call-named t :fixed nil)
838 (define-full-call multiple-call nil :unknown nil)
839 (define-full-call multiple-call-named t :unknown nil)
840 (define-full-call tail-call nil :tail nil)
841 (define-full-call tail-call-named t :tail nil)
843 (define-full-call call-variable nil :fixed t)
844 (define-full-call multiple-call-variable nil :unknown t)
846 ;;; This is defined separately, since it needs special code that blits
847 ;;; the arguments down.
848 (define-vop (tail-call-variable)
850 (args-arg :scs (any-reg) :target args)
851 (function-arg :scs (descriptor-reg) :target lexenv)
852 (ocfp-arg :scs (any-reg) :target ocfp)
853 (lra-arg :scs (#!-gengc descriptor-reg #!+gengc any-reg) :target lra))
855 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
856 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
857 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
858 (:temporary (:sc any-reg :offset #!-gengc lra-offset #!+gengc ra-offset
859 :from (:argument 3)) lra)
860 (:temporary (:scs (non-descriptor-reg)) temp)
866 ;; Move these into the passing locations if they are not already there.
868 (move function-arg lexenv)
872 ;; Clear the number stack if anything is there.
873 (let ((cur-nfp (current-nfp-tn vop)))
875 (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
878 ;; And jump to the assembly-routine that does the bliting.
879 (inst li (make-fixup 'tail-call-variable :assembly-routine) temp)
880 (inst jmp zero-tn temp)))
882 ;;;; unknown values return
884 ;;; Return a single value using the unknown-values convention.
885 (define-vop (return-single)
886 (:args (ocfp :scs (any-reg))
887 #!-gengc (return-pc :scs (descriptor-reg))
888 #!+gengc (return-pc :scs (any-reg) :target ra)
891 #!-gengc (:temporary (:scs (interior-reg)) lip)
892 #!+gengc (:temporary (:sc any-reg :offset ra-offset :from (:argument 1)) ra)
893 #!+gengc (:temporary (:scs (any-reg) :from (:argument 1)) temp)
896 ;; Clear the number stack.
897 (trace-table-entry trace-table-function-epilogue)
898 (let ((cur-nfp (current-nfp-tn vop)))
900 (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
902 ;; Clear the control stack, and restore the frame pointer.
906 #!-gengc (lisp-return return-pc lip :offset 2)
909 (inst addq return-pc (* 2 word-bytes) temp)
910 (unless (location= ra return-pc)
911 (inst move ra return-pc))
912 (inst ret zero-tn temp 1))
913 (trace-table-entry trace-table-normal)))
915 ;;; Do unknown-values return of a fixed number of values. The Values
916 ;;; are required to be set up in the standard passing locations. Nvals
917 ;;; is the number of values returned.
919 ;;; If returning a single value, then deallocate the current frame,
920 ;;; restore FP and jump to the single-value entry at Return-PC + 8.
922 ;;; If returning other than one value, then load the number of values
923 ;;; returned, NIL out unsupplied values registers, restore FP and
924 ;;; return at Return-PC. When there are stack values, we must
925 ;;; initialize the argument pointer to point to the beginning of the
926 ;;; values block (which is the beginning of the current frame.)
928 (:args (ocfp :scs (any-reg))
929 (return-pc :scs (#!-gengc descriptor-reg #!+gengc any-reg)
931 #!+gengc :target #!+gengc ra)
935 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
936 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
937 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
938 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
939 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
940 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
941 (:temporary (:sc any-reg :offset nargs-offset) nargs)
942 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
943 #!-gengc (:temporary (:scs (interior-reg)) lip)
944 #!+gengc (:temporary (:sc any-reg :offset ra-offset :from (:eval 1)) ra)
947 ;; Clear the number stack.
948 (trace-table-entry trace-table-function-epilogue)
949 (let ((cur-nfp (current-nfp-tn vop)))
951 (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
953 ;; Establish the values pointer and values count.
954 (move cfp-tn val-ptr)
955 (inst li (fixnumize nvals) nargs)
956 ;; restore the frame pointer and clear as much of the control
957 ;; stack as possible.
959 (inst addq val-ptr (* nvals word-bytes) csp-tn)
960 ;; pre-default any argument register that need it.
961 (when (< nvals register-arg-count)
962 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
965 (lisp-return return-pc lip)
966 (trace-table-entry trace-table-normal)))
968 ;;; Do unknown-values return of an arbitrary number of values (passed
969 ;;; on the stack.) We check for the common case of a single return
970 ;;; value, and do that inline using the normal single value return
971 ;;; convention. Otherwise, we branch off to code that calls an
972 ;;; assembly-routine.
973 (define-vop (return-multiple)
974 (:args (ocfp-arg :scs (any-reg) :target ocfp)
975 #!-gengc (lra-arg :scs (descriptor-reg) :target lra)
976 #!+gengc (return-pc :scs (any-reg) :target ra)
977 (vals-arg :scs (any-reg) :target vals)
978 (nvals-arg :scs (any-reg) :target nvals))
980 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
982 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
984 (:temporary (:sc any-reg :offset ra-offset :from (:argument 1)) ra)
985 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
986 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
987 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
988 (:temporary (:scs (non-descriptor-reg)) temp)
989 #!-gengc (:temporary (:scs (interior-reg)) lip)
990 #!+gengc (:temporary (:scs (any-reg) :from (:argument 0)) temp)
995 (trace-table-entry trace-table-function-epilogue)
996 (let ((not-single (gen-label)))
997 ;; Clear the number stack.
998 (let ((cur-nfp (current-nfp-tn vop)))
1000 (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
1003 ;; Check for the single case.
1004 (inst li (fixnumize 1) a0)
1005 (inst cmpeq nvals-arg a0 temp)
1006 (inst ldl a0 0 vals-arg)
1007 (inst beq temp not-single)
1009 ;; Return with one value.
1010 (move cfp-tn csp-tn)
1011 (move ocfp-arg cfp-tn)
1012 (lisp-return lra-arg lip :offset 2)
1014 ;; Nope, not the single case.
1015 (emit-label not-single)
1016 (move ocfp-arg ocfp)
1018 (move vals-arg vals)
1019 (move nvals-arg nvals)
1020 (inst li (make-fixup 'return-multiple :assembly-routine) temp)
1021 (inst jmp zero-tn temp))
1022 (trace-table-entry trace-table-normal)))
1026 ;;; We don't need to do anything special for regular functions.
1027 (define-vop (setup-environment)
1031 ;; Don't bother doing anything.
1034 ;;; Get the lexical environment from its passing location.
1035 (define-vop (setup-closure-environment)
1036 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1039 (:results (closure :scs (descriptor-reg)))
1044 (move lexenv closure)))
1046 ;;; Copy a &MORE arg from the argument area to the end of the current
1047 ;;; frame. FIXED is the number of non-&MORE arguments.
1048 (define-vop (copy-more-arg)
1049 (:temporary (:sc any-reg :offset nl0-offset) result)
1050 (:temporary (:sc any-reg :offset nl1-offset) count)
1051 (:temporary (:sc any-reg :offset nl2-offset) src)
1052 (:temporary (:sc any-reg :offset nl4-offset) dst)
1053 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1056 (let ((loop (gen-label))
1057 (do-regs (gen-label))
1059 (when (< fixed register-arg-count)
1060 ;; Save a pointer to the results so we can fill in register
1061 ;; args. We don't need this if there are more fixed args than
1063 (move csp-tn result))
1064 ;; Allocate the space on the stack.
1065 (cond ((zerop fixed)
1066 (inst addq csp-tn nargs-tn csp-tn)
1067 (inst beq nargs-tn done))
1069 (inst subq nargs-tn (fixnumize fixed) count)
1070 (inst ble count done)
1071 (inst addq csp-tn count csp-tn)))
1072 (when (< fixed register-arg-count)
1073 ;; We must stop when we run out of stack args, not when we run
1074 ;; out of &MORE args.
1075 (inst subq nargs-tn (fixnumize register-arg-count) count))
1076 ;; Initialize dst to be end of stack.
1078 ;; Everything of interest in registers.
1079 (inst ble count do-regs)
1080 ;; Initialize SRC to be end of args.
1081 (inst addq cfp-tn nargs-tn src)
1084 ;; *--dst = *--src, --count
1085 (inst subq src word-bytes src)
1086 (inst subq count (fixnumize 1) count)
1088 (inst subq dst word-bytes dst)
1090 (inst bgt count loop)
1092 (emit-label do-regs)
1093 (when (< fixed register-arg-count)
1094 ;; Now we have to deposit any more args that showed up in
1095 ;; registers. We know there is at least one &MORE arg,
1096 ;; otherwise we would have branched to DONE up at the top.
1097 (inst subq nargs-tn (fixnumize (1+ fixed)) count)
1098 (do ((i fixed (1+ i)))
1099 ((>= i register-arg-count))
1100 ;; Store it relative to the pointer saved at the start.
1101 (storew (nth i *register-arg-tns*) result (- i fixed))
1102 ;; Is this the last one?
1103 (inst beq count done)
1105 (inst subq count (fixnumize 1) count)))
1106 (emit-label done))))
1108 ;;; &MORE args are stored consecutively on the stack, starting
1109 ;;; immediately at the context pointer. The context pointer is not
1110 ;;; typed, so the lowtag is 0.
1111 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1113 ;;; Turn &MORE arg (context, count) into a list.
1114 (define-vop (listify-rest-args)
1115 (:args (context-arg :target context :scs (descriptor-reg))
1116 (count-arg :target count :scs (any-reg)))
1117 (:arg-types * tagged-num)
1118 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1119 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1120 (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1121 (:results (result :scs (descriptor-reg)))
1122 (:translate %listify-rest-args)
1125 (let ((enter (gen-label))
1128 (move context-arg context)
1129 (move count-arg count)
1130 ;; Check to see if there are any arguments.
1131 (move null-tn result)
1132 (inst beq count done)
1134 ;; We need to do this atomically.
1136 ;; Allocate a cons (2 words) for each item.
1137 (inst bis alloc-tn list-pointer-type result)
1139 (inst sll count 1 temp)
1140 (inst addq alloc-tn temp alloc-tn)
1141 (inst br zero-tn enter)
1143 ;; Store the current cons in the cdr of the previous cons.
1145 (inst addq dst (* 2 word-bytes) dst)
1146 (storew dst dst -1 list-pointer-type)
1150 (loadw temp context)
1151 (inst addq context word-bytes context)
1153 ;; Store the value in the car (in delay slot)
1154 (storew temp dst 0 list-pointer-type)
1156 ;; Decrement count, and if != zero, go back for more.
1157 (inst subq count (fixnumize 1) count)
1158 (inst bne count loop)
1160 ;; NIL out the last cons.
1161 (storew null-tn dst 1 list-pointer-type))
1162 (emit-label done))))
1164 ;;; Return the location and size of the &MORE arg glob created by
1165 ;;; COPY-MORE-ARG. Supplied is the total number of arguments supplied
1166 ;;; (originally passed in NARGS.) Fixed is the number of non-&rest
1169 ;;; We must duplicate some of the work done by COPY-MORE-ARG, since at
1170 ;;; that time the environment is in a pretty brain-damaged state,
1171 ;;; preventing this info from being returned as values. What we do is
1172 ;;; compute supplied - fixed, and return a pointer that many words
1173 ;;; below the current stack top.
1174 (define-vop (more-arg-context)
1175 (:policy :fast-safe)
1176 (:translate sb!c::%more-arg-context)
1177 (:args (supplied :scs (any-reg)))
1178 (:arg-types tagged-num (:constant fixnum))
1180 (:results (context :scs (descriptor-reg))
1181 (count :scs (any-reg)))
1182 (:result-types t tagged-num)
1183 (:note "more-arg-context")
1185 (inst subq supplied (fixnumize fixed) count)
1186 (inst subq csp-tn count context)))
1188 ;;; Signal wrong argument count error if NARGS isn't equal to COUNT.
1189 (define-vop (verify-argument-count)
1190 (:policy :fast-safe)
1191 (:translate sb!c::%verify-argument-count)
1192 (:args (nargs :scs (any-reg)))
1193 (:arg-types positive-fixnum (:constant t))
1194 (:temporary (:scs (any-reg) :type fixnum) temp)
1197 (:save-p :compute-only)
1200 (generate-error-code vop invalid-argument-count-error nargs)))
1201 (cond ((zerop count)
1202 (inst bne nargs err-lab))
1204 (inst subq nargs (fixnumize count) temp)
1205 (inst bne temp err-lab))))))
1207 ;;; various other error signalers
1208 (macrolet ((frob (name error translate &rest args)
1209 `(define-vop (,name)
1211 `((:policy :fast-safe)
1212 (:translate ,translate)))
1213 (:args ,@(mapcar #'(lambda (arg)
1214 `(,arg :scs (any-reg descriptor-reg)))
1217 (:save-p :compute-only)
1219 (error-call vop ,error ,@args)))))
1220 (frob argument-count-error invalid-argument-count-error
1221 sb!c::%argument-count-error nargs)
1222 (frob type-check-error object-not-type-error sb!c::%type-check-error
1224 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1226 (frob odd-key-arguments-error odd-key-arguments-error
1227 sb!c::%odd-key-arguments-error)
1228 (frob unknown-key-argument-error unknown-key-argument-error
1229 sb!c::%unknown-key-argument-error key)
1230 (frob nil-function-returned-error nil-function-returned-error nil fun))