4 ;;;; Interfaces to IR2 conversion:
6 ;;; Return a wired TN describing the N'th full call argument passing
8 (!def-vm-support-routine standard-arg-location (n)
9 (declare (type unsigned-byte n))
10 (if (< n register-arg-count)
11 (make-wired-tn *backend-t-primitive-type*
13 (elt *register-arg-offsets* n))
14 (make-wired-tn *backend-t-primitive-type*
15 control-stack-arg-scn n)))
18 ;;; Make a passing location TN for a local call return PC. If standard is
19 ;;; true, then use the standard (full call) location, otherwise use any legal
20 ;;; location. Even in the non-standard case, this may be restricted by a
21 ;;; desire to use a subroutine call instruction.
22 (!def-vm-support-routine make-return-pc-passing-location (standard)
24 (make-wired-tn *backend-t-primitive-type* register-arg-scn lra-offset)
25 (make-restricted-tn *backend-t-primitive-type* register-arg-scn)))
27 ;;; This is similar to MAKE-RETURN-PC-PASSING-LOCATION, but makes a
28 ;;; location to pass Old-FP in. This is (obviously) wired in the
29 ;;; standard convention, but is totally unrestricted in non-standard
30 ;;; conventions, since we can always fetch it off of the stack using
32 (!def-vm-support-routine make-old-fp-passing-location (standard)
34 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset)
35 (make-normal-tn *fixnum-primitive-type*)))
37 ;;; Make the TNs used to hold OLD-FP and RETURN-PC within the current
38 ;;; function. We treat these specially so that the debugger can find
39 ;;; them at a known location.
40 (!def-vm-support-routine make-old-fp-save-location (env)
42 (physenv-debug-live-tn (make-normal-tn *fixnum-primitive-type*) env)
43 (make-wired-tn *fixnum-primitive-type*
46 (!def-vm-support-routine make-return-pc-save-location (env)
47 (let ((ptype *backend-t-primitive-type*))
49 (physenv-debug-live-tn (make-normal-tn ptype) env)
50 (make-wired-tn ptype control-stack-arg-scn lra-save-offset))))
52 ;;; Make a TN for the standard argument count passing location. We only
53 ;;; need to make the standard location, since a count is never passed when we
54 ;;; are using non-standard conventions.
55 (!def-vm-support-routine make-arg-count-location ()
56 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
59 ;;; Make a TN to hold the number-stack frame pointer. This is allocated
60 ;;; once per component, and is component-live.
61 (!def-vm-support-routine make-nfp-tn ()
63 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nfp-offset)))
65 (!def-vm-support-routine make-stack-pointer-tn ()
66 (make-normal-tn *fixnum-primitive-type*))
68 (!def-vm-support-routine make-number-stack-pointer-tn ()
69 (make-normal-tn *fixnum-primitive-type*))
71 ;;; Return a list of TNs that can be used to represent an unknown-values
72 ;;; continuation within a function.
73 (!def-vm-support-routine make-unknown-values-locations ()
74 (list (make-stack-pointer-tn)
75 (make-normal-tn *fixnum-primitive-type*)))
78 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
79 ;;; VM-dependent initialization of the IR2-COMPONENT structure. We push
80 ;;; placeholder entries in the Constants to leave room for additional
81 ;;; noise in the code object header.
82 (!def-vm-support-routine select-component-format (component)
83 (declare (type component component))
84 (dotimes (i code-constants-offset)
85 (vector-push-extend nil
86 (ir2-component-constants (component-info component))))
92 ;;; BYTES-NEEDED-FOR-NON-DESCRIPTOR-STACK-FRAME -- internal
94 ;;; Return the number of bytes needed for the current non-descriptor stack
95 ;;; frame. Non-descriptor stack frames must be multiples of 8 bytes on
98 (defun bytes-needed-for-non-descriptor-stack-frame ()
99 (* (logandc2 (1+ (sb-allocated-size 'non-descriptor-stack)) 1)
102 ;;; Used for setting up the Old-FP in local call.
104 (define-vop (current-fp)
105 (:results (val :scs (any-reg)))
109 ;;; Used for computing the caller's NFP for use in known-values return. Only
110 ;;; works assuming there is no variable size stuff on the nstack.
112 (define-vop (compute-old-nfp)
113 (:results (val :scs (any-reg)))
116 (let ((nfp (current-nfp-tn vop)))
118 (inst addu val nfp (bytes-needed-for-non-descriptor-stack-frame))))))
121 (define-vop (xep-allocate-frame)
122 (:info start-lab copy-more-arg-follows)
123 (:ignore copy-more-arg-follows)
125 (:temporary (:scs (non-descriptor-reg)) temp)
127 ;; Make sure the function is aligned, and drop a label pointing to this
129 (align n-lowtag-bits)
130 (trace-table-entry trace-table-fun-prologue)
131 (emit-label start-lab)
132 ;; Allocate function header.
133 (inst fun-header-word)
134 (dotimes (i (1- simple-fun-code-offset))
136 ;; The start of the actual code.
137 ;; Compute CODE from the address of this entry point.
138 (let ((entry-point (gen-label)))
139 (emit-label entry-point)
140 (inst compute-code-from-fn code-tn lip-tn entry-point temp)
141 ;; ### We should also save it on the stack so that the garbage collector
142 ;; won't forget about us if we call anyone else.
144 ;; Build our stack frames.
145 (inst addu csp-tn cfp-tn
146 (* n-word-bytes (sb-allocated-size 'control-stack)))
147 (let ((nfp (current-nfp-tn vop)))
149 (inst addu nsp-tn nsp-tn
150 (- (bytes-needed-for-non-descriptor-stack-frame)))
152 (trace-table-entry trace-table-normal)))
154 (define-vop (allocate-frame)
155 (:results (res :scs (any-reg))
156 (nfp :scs (any-reg)))
159 (trace-table-entry trace-table-fun-prologue)
161 (inst addu csp-tn csp-tn
162 (* n-word-bytes (sb-allocated-size 'control-stack)))
163 (when (ir2-physenv-number-stack-p callee)
164 (inst addu nsp-tn nsp-tn
165 (- (bytes-needed-for-non-descriptor-stack-frame)))
167 (trace-table-entry trace-table-normal)))
169 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
170 ;;; is the number of arguments passed. If no stack arguments are passed, then
171 ;;; we don't have to do anything.
173 (define-vop (allocate-full-call-frame)
175 (:results (res :scs (any-reg)))
177 (when (> nargs register-arg-count)
179 (inst addu csp-tn csp-tn (* nargs n-word-bytes)))))
184 ;;; Emit code needed at the return-point from an unknown-values call for a
185 ;;; fixed number of values. Values is the head of the TN-Ref list for the
186 ;;; locations that the values are to be received into. Nvals is the number of
187 ;;; values that are to be received (should equal the length of Values).
189 ;;; MOVE-TEMP is a DESCRIPTOR-REG TN used as a temporary.
191 ;;; This code exploits the fact that in the unknown-values convention, a
192 ;;; single value return returns at the return PC + 8, whereas a return of other
193 ;;; than one value returns directly at the return PC.
195 ;;; If 0 or 1 values are expected, then we just emit an instruction to reset
196 ;;; the SP (which will only be executed when other than 1 value is returned.)
198 ;;; In the general case, we have to do three things:
199 ;;; -- Default unsupplied register values. This need only be done when a
200 ;;; single value is returned, since register values are defaulted by the
201 ;;; called in the non-single case.
202 ;;; -- Default unsupplied stack values. This needs to be done whenever there
203 ;;; are stack values.
204 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
205 ;;; regardless of the number of values desired.
207 ;;; The general-case code looks like this:
209 b regs-defaulted ; Skip if MVs
212 move a1 null-tn ; Default register values
214 loadi nargs 1 ; Force defaulting of stack values
215 move ocfp csp ; Set up args for SP resetting
218 subu temp nargs register-arg-count
220 bltz temp default-value-7 ; jump to default code
222 loadw move-temp ocfp-tn 6 ; Move value to correct location.
223 store-stack-tn val4-tn move-temp
225 bltz temp default-value-8
227 loadw move-temp ocfp-tn 7
228 store-stack-tn val5-tn move-temp
233 move sp ocfp ; Reset SP.
238 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
241 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
249 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
250 (declare (type (or tn-ref null) values)
251 (type unsigned-byte nvals) (type tn move-temp temp))
254 ;; Note that this is a single-value return point. This is actually
255 ;; the multiple-value entry point for a single desired value, but
256 ;; the code location has to be here, or the debugger backtrace
258 (without-scheduling ()
259 (note-this-location vop :single-value-return)
260 (move csp-tn ocfp-tn)
263 (inst compute-code-from-lra code-tn code-tn lra-label temp)))
264 (let ((regs-defaulted (gen-label))
265 (defaulting-done (gen-label))
266 (default-stack-vals (gen-label)))
267 (without-scheduling ()
268 ;; Note that this is an unknown-values return point.
269 (note-this-location vop :unknown-return)
270 ;; Branch off to the MV case.
271 (inst b regs-defaulted)
272 ;; If there are no stack results, clear the stack now.
273 (if (> nvals register-arg-count)
274 (inst addu temp nargs-tn (fixnumize (- register-arg-count)))
275 (move csp-tn ocfp-tn)))
277 ;; Do the single value calse.
279 (val (tn-ref-across values) (tn-ref-across val)))
280 ((= i (min nvals register-arg-count)))
281 (move (tn-ref-tn val) null-tn))
282 (when (> nvals register-arg-count)
283 (inst b default-stack-vals)
284 (move ocfp-tn csp-tn))
286 (emit-label regs-defaulted)
288 (when (> nvals register-arg-count)
289 ;; If there are stack results, we have to default them
290 ;; and clear the stack.
291 (collect ((defaults))
292 (do ((i register-arg-count (1+ i))
293 (val (do ((i 0 (1+ i))
294 (val values (tn-ref-across val)))
295 ((= i register-arg-count) val))
296 (tn-ref-across val)))
299 (let ((default-lab (gen-label))
300 (tn (tn-ref-tn val)))
301 (defaults (cons default-lab tn))
303 (inst blez temp default-lab)
304 (inst lw move-temp ocfp-tn (* i n-word-bytes))
305 (inst addu temp temp (fixnumize -1))
306 (store-stack-tn tn move-temp)))
308 (emit-label defaulting-done)
309 (move csp-tn ocfp-tn)
311 (let ((defaults (defaults)))
313 (assemble (*elsewhere*)
314 (emit-label default-stack-vals)
315 (do ((remaining defaults (cdr remaining)))
317 (let ((def (car remaining)))
318 (emit-label (car def))
319 (when (null (cdr remaining))
320 (inst b defaulting-done))
321 (store-stack-tn (cdr def) null-tn)))))))
324 (inst compute-code-from-lra code-tn code-tn lra-label temp))))
328 ;;;; Unknown values receiving:
330 ;;; Emit code needed at the return point for an unknown-values call for an
331 ;;; arbitrary number of values.
333 ;;; We do the single and non-single cases with no shared code: there doesn't
334 ;;; seem to be any potential overlap, and receiving a single value is more
335 ;;; important efficiency-wise.
337 ;;; When there is a single value, we just push it on the stack, returning
338 ;;; the old SP and 1.
340 ;;; When there is a variable number of values, we move all of the argument
341 ;;; registers onto the stack, and return Args and Nargs.
343 ;;; Args and Nargs are TNs wired to the named locations. We must
344 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
345 ;;; results Start and Count (also, it's nice to be able to target them).
347 (defun receive-unknown-values (args nargs start count lra-label temp)
348 (declare (type tn args nargs start count temp))
349 (let ((variable-values (gen-label))
351 (without-scheduling ()
352 (inst b variable-values)
356 (inst compute-code-from-lra code-tn code-tn lra-label temp))
357 (inst addu csp-tn csp-tn 4)
358 (storew (first register-arg-tns) csp-tn -1)
359 (inst addu start csp-tn -4)
360 (inst li count (fixnumize 1))
364 (assemble (*elsewhere*)
365 (emit-label variable-values)
367 (inst compute-code-from-lra code-tn code-tn lra-label temp))
368 (do ((arg register-arg-tns (rest arg))
371 (storew (first arg) args i))
379 ;;; VOP that can be inherited by unknown values receivers. The main thing this
380 ;;; handles is allocation of the result temporaries.
382 (define-vop (unknown-values-receiver)
384 (start :scs (any-reg))
385 (count :scs (any-reg)))
386 (:temporary (:sc descriptor-reg :offset ocfp-offset
387 :from :eval :to (:result 0))
389 (:temporary (:sc any-reg :offset nargs-offset
390 :from :eval :to (:result 1))
392 (:temporary (:scs (non-descriptor-reg)) temp))
396 ;;;; Local call with unknown values convention return:
398 ;;; Non-TR local call for a fixed number of values passed according to the
399 ;;; unknown values convention.
401 ;;; Args are the argument passing locations, which are specified only to
402 ;;; terminate their lifetimes in the caller.
404 ;;; Values are the return value locations (wired to the standard passing
407 ;;; Save is the save info, which we can ignore since saving has been done.
408 ;;; Return-PC is the TN that the return PC should be passed in.
409 ;;; Target is a continuation pointing to the start of the called function.
410 ;;; Nvals is the number of values received.
412 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
413 ;;; registers may be tied up by the more operand. Instead, we use
414 ;;; MAYBE-LOAD-STACK-TN.
416 (define-vop (call-local)
420 (:results (values :more t))
422 (:move-args :local-call)
423 (:info arg-locs callee target nvals)
425 (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
426 (:temporary (:scs (non-descriptor-reg)) temp)
427 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
428 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
429 (:ignore arg-locs args ocfp)
431 (let ((label (gen-label))
432 (cur-nfp (current-nfp-tn vop)))
434 (store-stack-tn nfp-save cur-nfp))
435 (let ((callee-nfp (callee-nfp-tn callee)))
437 (maybe-load-stack-tn callee-nfp nfp)))
438 (maybe-load-stack-tn cfp-tn fp)
439 (trace-table-entry trace-table-call-site)
440 (inst compute-lra-from-code
441 (callee-return-pc-tn callee) code-tn label temp)
442 (note-this-location vop :call-site)
445 (trace-table-entry trace-table-normal)
446 (emit-return-pc label)
447 (default-unknown-values vop values nvals move-temp temp label)
449 (load-stack-tn cur-nfp nfp-save)))))
452 ;;; Non-TR local call for a variable number of return values passed according
453 ;;; to the unknown values convention. The results are the start of the values
454 ;;; glob and the number of values received.
456 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
457 ;;; registers may be tied up by the more operand. Instead, we use
458 ;;; MAYBE-LOAD-STACK-TN.
460 (define-vop (multiple-call-local unknown-values-receiver)
465 (:move-args :local-call)
466 (:info save callee target)
469 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
471 (let ((label (gen-label))
472 (cur-nfp (current-nfp-tn vop)))
474 (store-stack-tn nfp-save cur-nfp))
475 (let ((callee-nfp (callee-nfp-tn callee)))
477 (maybe-load-stack-tn callee-nfp nfp)))
478 (maybe-load-stack-tn cfp-tn fp)
479 (trace-table-entry trace-table-call-site)
480 (inst compute-lra-from-code
481 (callee-return-pc-tn callee) code-tn label temp)
482 (note-this-location vop :call-site)
485 (trace-table-entry trace-table-normal)
486 (emit-return-pc label)
487 (note-this-location vop :unknown-return)
488 (receive-unknown-values values-start nvals start count label temp)
490 (load-stack-tn cur-nfp nfp-save)))))
493 ;;;; Local call with known values return:
495 ;;; Non-TR local call with known return locations. Known-value return works
496 ;;; 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.
502 (define-vop (known-call-local)
506 (:results (res :more t))
507 (:move-args :local-call)
509 (:info save callee target)
510 (:ignore args res save)
512 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
513 (:temporary (:scs (non-descriptor-reg)) temp)
515 (let ((label (gen-label))
516 (cur-nfp (current-nfp-tn vop)))
518 (store-stack-tn nfp-save cur-nfp))
519 (let ((callee-nfp (callee-nfp-tn callee)))
521 (maybe-load-stack-tn callee-nfp nfp)))
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)
529 (trace-table-entry trace-table-normal)
530 (emit-return-pc label)
531 (note-this-location vop :known-return)
533 (load-stack-tn cur-nfp nfp-save)))))
535 ;;; Return from known values call. We receive the return locations as
536 ;;; arguments to terminate their lifetimes in the returning function. We
537 ;;; restore FP and CSP and jump to the Return-PC.
539 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
540 ;;; registers may be tied up by the more operand. Instead, we use
541 ;;; MAYBE-LOAD-STACK-TN.
543 (define-vop (known-return)
544 (:args (ocfp :target ocfp-temp)
545 (return-pc :target return-pc-temp)
547 (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
548 (:temporary (:sc descriptor-reg :from (:argument 1))
550 (:temporary (:scs (interior-reg)) lip)
551 (:move-args :known-return)
553 (:ignore val-locs vals)
556 (trace-table-entry trace-table-fun-epilogue)
557 (maybe-load-stack-tn ocfp-temp ocfp)
558 (maybe-load-stack-tn return-pc-temp return-pc)
560 (let ((cur-nfp (current-nfp-tn vop)))
562 (inst addu nsp-tn cur-nfp
563 (bytes-needed-for-non-descriptor-stack-frame))))
564 (inst addu lip return-pc-temp (- n-word-bytes other-pointer-lowtag))
566 (move cfp-tn ocfp-temp)
567 (trace-table-entry trace-table-normal)))
572 ;;; There is something of a cross-product effect with full calls. Different
573 ;;; versions are used depending on whether we know the number of arguments or
574 ;;; the name of the called function, and whether we want fixed values, unknown
575 ;;; values, or a tail call.
577 ;;; In full call, the arguments are passed creating a partial frame on the
578 ;;; stack top and storing stack arguments into that frame. On entry to the
579 ;;; callee, this partial frame is pointed to by FP. If there are no stack
580 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
581 ;;; to SP just before the call.
583 ;;; This macro helps in the definition of full call VOPs by avoiding code
584 ;;; replication in defining the cross-product VOPs.
586 ;;; Name is the name of the VOP to define.
588 ;;; Named is true if the first argument is a symbol whose global function
589 ;;; definition is to be called.
591 ;;; Return is either :Fixed, :Unknown or :Tail:
592 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
593 ;;; the standard passing locations (passed as result operands).
594 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
595 ;;; result values are specified by the Start and Count as in the
596 ;;; unknown-values continuation representation.
597 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
598 ;;; The Ocfp and Return-PC are passed as the second and third arguments.
600 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
601 ;;; fixed argument. If Variable is false, then the passing locations are
602 ;;; passed as a more arg. Variable is true if there are a variable number of
603 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
604 ;;; return. TR variable argument call is implemented separately.
606 ;;; In tail call with fixed arguments, the passing locations are passed as a
607 ;;; more arg, but there is no new-FP, since the arguments have been set up in
608 ;;; the current frame.
610 (defmacro define-full-call (name named return variable)
611 (assert (not (and variable (eq return :tail))))
613 ,@(when (eq return :unknown)
614 '(unknown-values-receiver)))
616 ,@(unless (eq return :tail)
617 '((new-fp :scs (any-reg) :to :eval)))
620 '(name :target name-pass)
621 '(arg-fun :target lexenv))
623 ,@(when (eq return :tail)
624 '((ocfp :target ocfp-pass)
625 (return-pc :target return-pc-pass)))
627 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
629 ,@(when (eq return :fixed)
630 '((:results (values :more t))))
632 (:save-p ,(if (eq return :tail) :compute-only t))
634 ,@(unless (or (eq return :tail) variable)
635 '((:move-args :full-call)))
638 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
639 ,@(unless variable '(nargs))
640 ,@(when (eq return :fixed) '(nvals)))
642 (:ignore ,@(unless (or variable (eq return :tail)) '(arg-locs))
643 ,@(unless variable '(args)))
645 (:temporary (:sc descriptor-reg
648 ,@(unless (eq return :fixed)
652 (:temporary (:sc descriptor-reg
654 :from (:argument ,(if (eq return :tail) 2 1))
659 `((:temporary (:sc descriptor-reg :offset fdefn-offset
660 :from (:argument ,(if (eq return :tail) 0 1))
664 `((:temporary (:sc descriptor-reg :offset lexenv-offset
665 :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
714 (flet ((do-next-filler ()
715 (let* ((next (pop filler))
716 (what (if (consp next) (car next) next)))
720 `((inst subu nargs-pass csp-tn new-fp)
722 (mapcar #'(lambda (name)
723 `(inst lw ,name new-fp
726 register-arg-names)))
727 '((inst li nargs-pass (fixnumize nargs)))))
728 ,@(if (eq return :tail)
732 (inst move ocfp-pass ocfp))
734 (inst lw ocfp-pass cfp-tn
735 (ash (tn-offset ocfp)
740 (inst move return-pc-pass return-pc))
742 (inst lw return-pc-pass cfp-tn
743 (ash (tn-offset return-pc)
746 (inst addu nsp-tn cur-nfp
747 (bytes-needed-for-non-descriptor-stack-frame))))
749 (inst compute-lra-from-code
750 return-pc-pass code-tn lra-label temp))
752 (store-stack-tn nfp-save cur-nfp))
754 (inst move ocfp-pass cfp-tn))
757 '(move cfp-tn new-fp)
758 '(if (> nargs register-arg-count)
760 (move cfp-tn csp-tn)))
761 (trace-table-entry trace-table-call-site))))
767 (descriptor-reg (move name-pass name))
769 (inst lw name-pass cfp-tn
770 (ash (tn-offset name) word-shift))
773 (inst lw name-pass code-tn
774 (- (ash (tn-offset name) word-shift)
775 other-pointer-lowtag))
777 (inst lw entry-point name-pass
778 (- (ash fdefn-raw-addr-slot word-shift)
779 other-pointer-lowtag))
782 (descriptor-reg (move lexenv arg-fun))
784 (inst lw lexenv cfp-tn
785 (ash (tn-offset arg-fun) word-shift))
788 (inst lw lexenv code-tn
789 (- (ash (tn-offset arg-fun) word-shift)
790 other-pointer-lowtag))
792 (inst lw function lexenv
793 (- (ash closure-fun-slot word-shift)
796 (inst addu entry-point function
797 (- (ash simple-fun-code-offset word-shift)
798 fun-pointer-lowtag))))
804 (note-this-location vop :call-site)
810 '((trace-table-entry trace-table-normal)
811 (emit-return-pc lra-label)
812 (default-unknown-values vop values nvals
813 move-temp temp lra-label)
815 (load-stack-tn cur-nfp nfp-save))))
817 '((trace-table-entry trace-table-normal)
818 (emit-return-pc lra-label)
819 (note-this-location vop :unknown-return)
820 (receive-unknown-values values-start nvals start count
823 (load-stack-tn cur-nfp nfp-save))))
827 (define-full-call call nil :fixed nil)
828 (define-full-call call-named t :fixed nil)
829 (define-full-call multiple-call nil :unknown nil)
830 (define-full-call multiple-call-named t :unknown nil)
831 (define-full-call tail-call nil :tail nil)
832 (define-full-call tail-call-named t :tail nil)
834 (define-full-call call-variable nil :fixed t)
835 (define-full-call multiple-call-variable nil :unknown t)
838 ;;; Defined separately, since needs special code that BLT's the arguments
841 (define-vop (tail-call-variable)
843 (args-arg :scs (any-reg) :target args)
844 (function-arg :scs (descriptor-reg) :target lexenv)
845 (ocfp-arg :scs (any-reg) :target ocfp)
846 (lra-arg :scs (descriptor-reg) :target lra))
848 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
849 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
850 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
851 (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
857 ;; Move these into the passing locations if they are not already there.
859 (move lexenv function-arg)
863 ;; Clear the number stack if anything is there.
864 (let ((cur-nfp (current-nfp-tn vop)))
866 (inst addu nsp-tn cur-nfp
867 (bytes-needed-for-non-descriptor-stack-frame))))
869 ;; And jump to the assembly-routine that does the bliting.
870 (inst j (make-fixup 'tail-call-variable :assembly-routine))
874 ;;;; Unknown values return:
876 ;;; Return a single value using the unknown-values convention.
878 (define-vop (return-single)
879 (:args (ocfp :scs (any-reg))
880 (return-pc :scs (descriptor-reg))
883 (:temporary (:scs (interior-reg)) lip)
886 ;; Clear the number stack.
887 (trace-table-entry trace-table-fun-epilogue)
888 (let ((cur-nfp (current-nfp-tn vop)))
890 (inst addu nsp-tn cur-nfp
891 (bytes-needed-for-non-descriptor-stack-frame))))
892 ;; Clear the control stack, and restore the frame pointer.
896 (lisp-return return-pc lip :offset 2)
897 (trace-table-entry trace-table-normal)))
900 ;;; Do unknown-values return of a fixed number of values. The Values are
901 ;;; required to be set up in the standard passing locations. Nvals is the
902 ;;; number of values returned.
904 ;;; If returning a single value, then deallocate the current frame, restore
905 ;;; FP and jump to the single-value entry at Return-PC + 8.
907 ;;; If returning other than one value, then load the number of values returned,
908 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
909 ;;; When there are stack values, we must initialize the argument pointer to
910 ;;; point to the beginning of the values block (which is the beginning of the
914 (:args (ocfp :scs (any-reg))
915 (return-pc :scs (descriptor-reg) :to (:eval 1))
919 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
920 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
921 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
922 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
923 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
924 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
925 (:temporary (:sc any-reg :offset nargs-offset) nargs)
926 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
927 (:temporary (:scs (interior-reg)) lip)
930 ;; Clear the number stack.
931 (trace-table-entry trace-table-fun-epilogue)
932 (let ((cur-nfp (current-nfp-tn vop)))
934 (inst addu nsp-tn cur-nfp
935 (bytes-needed-for-non-descriptor-stack-frame))))
936 ;; Establish the values pointer and values count.
937 (move val-ptr cfp-tn)
938 (inst li nargs (fixnumize nvals))
939 ;; restore the frame pointer and clear as much of the control
940 ;; stack as possible.
942 (inst addu csp-tn val-ptr (* nvals n-word-bytes))
943 ;; pre-default any argument register that need it.
944 (when (< nvals register-arg-count)
945 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
948 (lisp-return return-pc lip)
949 (trace-table-entry trace-table-normal)))
951 ;;; Do unknown-values return of an arbitrary number of values (passed on the
952 ;;; stack.) We check for the common case of a single return value, and do that
953 ;;; inline using the normal single value return convention. Otherwise, we
954 ;;; branch off to code that calls an assembly-routine.
956 (define-vop (return-multiple)
957 (:args (ocfp-arg :scs (any-reg) :target ocfp)
958 (lra-arg :scs (descriptor-reg) :target lra)
959 (vals-arg :scs (any-reg) :target vals)
960 (nvals-arg :scs (any-reg) :target nvals))
962 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
963 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
964 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
965 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
966 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
967 (:temporary (:scs (interior-reg)) lip)
972 (trace-table-entry trace-table-fun-epilogue)
973 (let ((not-single (gen-label)))
974 ;; Clear the number stack.
975 (let ((cur-nfp (current-nfp-tn vop)))
977 (inst addu nsp-tn cur-nfp
978 (bytes-needed-for-non-descriptor-stack-frame))))
980 ;; Check for the single case.
981 (inst li a0 (fixnumize 1))
982 (inst bne nvals-arg a0 not-single)
983 (inst lw a0 vals-arg)
985 ;; Return with one value.
987 (move cfp-tn ocfp-arg)
988 (lisp-return lra-arg lip :offset 2)
990 ;; Nope, not the single case.
991 (emit-label not-single)
995 (move nvals nvals-arg)
996 (inst j (make-fixup 'return-multiple :assembly-routine))
998 (trace-table-entry trace-table-normal)))
1005 ;;; We don't need to do anything special for regular functions.
1007 (define-vop (setup-environment)
1011 ;; Don't bother doing anything.
1014 ;;; Get the lexical environment from it's passing location.
1016 (define-vop (setup-closure-environment)
1017 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1020 (:results (closure :scs (descriptor-reg)))
1025 (move closure lexenv)))
1027 ;;; Copy a more arg from the argument area to the end of the current frame.
1028 ;;; Fixed is the number of non-more arguments.
1030 (define-vop (copy-more-arg)
1031 (:temporary (:sc any-reg :offset nl0-offset) result)
1032 (:temporary (:sc any-reg :offset nl1-offset) count)
1033 (:temporary (:sc any-reg :offset nl2-offset) src)
1034 (:temporary (:sc any-reg :offset nl4-offset) dst)
1035 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1038 (let ((loop (gen-label))
1039 (do-regs (gen-label))
1041 (when (< fixed register-arg-count)
1042 ;; Save a pointer to the results so we can fill in register args.
1043 ;; We don't need this if there are more fixed args than reg args.
1044 (move result csp-tn))
1045 ;; Allocate the space on the stack.
1046 (cond ((zerop fixed)
1047 (inst beq nargs-tn done)
1048 (inst addu csp-tn csp-tn nargs-tn))
1050 (inst addu count nargs-tn (fixnumize (- fixed)))
1051 (inst blez count done)
1053 (inst addu csp-tn csp-tn count)))
1054 (when (< fixed register-arg-count)
1055 ;; We must stop when we run out of stack args, not when we run out of
1057 (inst addu count nargs-tn (fixnumize (- register-arg-count))))
1058 ;; Everything of interest in registers.
1059 (inst blez count do-regs)
1060 ;; Initialize dst to be end of stack.
1062 ;; Initialize src to be end of args.
1063 (inst addu src cfp-tn nargs-tn)
1066 ;; *--dst = *--src, --count
1067 (inst addu src src (- n-word-bytes))
1068 (inst addu count count (fixnumize -1))
1070 (inst addu dst dst (- n-word-bytes))
1071 (inst bgtz count loop)
1074 (emit-label do-regs)
1075 (when (< fixed register-arg-count)
1076 ;; Now we have to deposit any more args that showed up in registers.
1077 ;; We know there is at least one more arg, otherwise we would have
1078 ;; branched to done up at the top.
1079 (inst subu count nargs-tn (fixnumize (1+ fixed)))
1080 (do ((i fixed (1+ i)))
1081 ((>= i register-arg-count))
1082 ;; Is this the last one?
1083 (inst beq count done)
1084 ;; Store it relative to the pointer saved at the start.
1085 (storew (nth i register-arg-tns) result (- i fixed))
1087 (inst subu count (fixnumize 1))))
1088 (emit-label done))))
1091 ;;; More args are stored consequtively on the stack, starting immediately at
1092 ;;; the context pointer. The context pointer is not typed, so the lowtag is 0.
1094 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1097 ;;; Turn more arg (context, count) into a list.
1099 (define-vop (listify-rest-args)
1100 (:args (context-arg :target context :scs (descriptor-reg))
1101 (count-arg :target count :scs (any-reg)))
1102 (:arg-types * tagged-num)
1103 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1104 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1105 (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1106 (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
1107 (:results (result :scs (descriptor-reg)))
1108 (:translate %listify-rest-args)
1111 (let ((enter (gen-label))
1114 (move context context-arg)
1115 (move count count-arg)
1116 ;; Check to see if there are any arguments.
1117 (inst beq count zero-tn done)
1118 (move result null-tn)
1120 ;; We need to do this atomically.
1121 (pseudo-atomic (pa-flag)
1122 ;; Allocate a cons (2 words) for each item.
1123 (inst or result alloc-tn list-pointer-lowtag)
1125 (inst sll temp count 1)
1127 (inst addu alloc-tn alloc-tn temp)
1129 ;; Store the current cons in the cdr of the previous cons.
1131 (inst addu dst dst (* 2 n-word-bytes))
1132 (storew dst dst -1 list-pointer-lowtag)
1136 (loadw temp context)
1137 (inst addu context context n-word-bytes)
1139 ;; Dec count, and if != zero, go back for more.
1140 (inst addu count count (fixnumize -1))
1141 (inst bne count zero-tn loop)
1143 ;; Store the value in the car (in delay slot)
1144 (storew temp dst 0 list-pointer-lowtag)
1146 ;; NIL out the last cons.
1147 (storew null-tn dst 1 list-pointer-lowtag))
1148 (emit-label done))))
1150 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1151 ;;; Supplied is the total number of arguments supplied (originally passed in
1152 ;;; NARGS.) Fixed is the number of non-rest arguments.
1154 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1155 ;;; time the environment is in a pretty brain-damaged state, preventing this
1156 ;;; info from being returned as values. What we do is compute
1157 ;;; supplied - fixed, and return a pointer that many words below the current
1160 (define-vop (more-arg-context)
1161 (:policy :fast-safe)
1162 (:translate sb!c::%more-arg-context)
1163 (:args (supplied :scs (any-reg)))
1164 (:arg-types tagged-num (:constant fixnum))
1166 (:results (context :scs (descriptor-reg))
1167 (count :scs (any-reg)))
1168 (:result-types t tagged-num)
1169 (:note "more-arg-context")
1171 (inst addu count supplied (fixnumize (- fixed)))
1172 (inst subu context csp-tn count)))
1175 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1177 (define-vop (verify-arg-count)
1178 (:policy :fast-safe)
1179 (:translate sb!c::%verify-arg-count)
1180 (:args (nargs :scs (any-reg)))
1181 (:arg-types positive-fixnum (:constant t))
1182 (:temporary (:scs (any-reg) :type fixnum) temp)
1185 (:save-p :compute-only)
1188 (generate-error-code vop invalid-arg-count-error nargs)))
1189 (cond ((zerop count)
1190 (inst bne nargs zero-tn err-lab)
1193 (inst li temp (fixnumize count))
1194 (inst bne nargs temp err-lab)
1197 ;;; Various other error signalers.
1199 (macrolet ((frob (name error translate &rest args)
1200 `(define-vop (,name)
1202 `((:policy :fast-safe)
1203 (:translate ,translate)))
1204 (:args ,@(mapcar #'(lambda (arg)
1205 `(,arg :scs (any-reg descriptor-reg)))
1208 (:save-p :compute-only)
1210 (error-call vop ,error ,@args)))))
1211 (frob arg-count-error invalid-arg-count-error
1212 sb!c::%arg-count-error nargs)
1213 (frob type-check-error object-not-type-error sb!c::%type-check-error
1215 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1217 (frob odd-key-args-error odd-key-args-error
1218 sb!c::%odd-key-args-error)
1219 (frob unknown-key-arg-error unknown-key-arg-error
1220 sb!c::%unknown-key-arg-error key)
1221 (frob nil-fun-returned-error nil-fun-returned-error nil fun))