1 ;;;; the VM definition of function call for MIPS
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
18 (!def-vm-support-routine standard-arg-location (n)
19 (declare (type unsigned-byte n))
20 (if (< n register-arg-count)
21 (make-wired-tn *backend-t-primitive-type*
23 (elt *register-arg-offsets* n))
24 (make-wired-tn *backend-t-primitive-type*
25 control-stack-arg-scn n)))
28 ;;; Make a passing location TN for a local call return PC. If standard is
29 ;;; true, then use the standard (full call) location, otherwise use any legal
30 ;;; location. Even in the non-standard case, this may be restricted by a
31 ;;; desire to use a subroutine call instruction.
32 (!def-vm-support-routine make-return-pc-passing-location (standard)
34 (make-wired-tn *backend-t-primitive-type* register-arg-scn lra-offset)
35 (make-restricted-tn *backend-t-primitive-type* register-arg-scn)))
37 ;;; This is similar to MAKE-RETURN-PC-PASSING-LOCATION, but makes a
38 ;;; location to pass OLD-FP in. This is (obviously) wired in the
39 ;;; standard convention, but is totally unrestricted in non-standard
40 ;;; conventions, since we can always fetch it off of the stack using
42 (!def-vm-support-routine make-old-fp-passing-location (standard)
44 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset)
45 (make-normal-tn *fixnum-primitive-type*)))
47 ;;; Make the TNs used to hold OLD-FP and RETURN-PC within the current
48 ;;; function. We treat these specially so that the debugger can find
49 ;;; them at a known location.
50 (!def-vm-support-routine make-old-fp-save-location (env)
52 (physenv-debug-live-tn (make-normal-tn *fixnum-primitive-type*) env)
53 (make-wired-tn *fixnum-primitive-type*
57 (!def-vm-support-routine make-return-pc-save-location (env)
58 (let ((ptype *backend-t-primitive-type*))
60 (physenv-debug-live-tn (make-normal-tn ptype) env)
61 (make-wired-tn ptype control-stack-arg-scn lra-save-offset))))
63 ;;; Make a TN for the standard argument count passing location. We only
64 ;;; need to make the standard location, since a count is never passed when we
65 ;;; are using non-standard conventions.
66 (!def-vm-support-routine make-arg-count-location ()
67 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
70 ;;; Make a TN to hold the number-stack frame pointer. This is allocated
71 ;;; once per component, and is component-live.
72 (!def-vm-support-routine make-nfp-tn ()
74 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nfp-offset)))
76 (!def-vm-support-routine make-stack-pointer-tn ()
77 (make-normal-tn *fixnum-primitive-type*))
79 (!def-vm-support-routine make-number-stack-pointer-tn ()
80 (make-normal-tn *fixnum-primitive-type*))
82 ;;; Return a list of TNs that can be used to represent an unknown-values
83 ;;; continuation within a function.
84 (!def-vm-support-routine make-unknown-values-locations ()
85 (list (make-stack-pointer-tn)
86 (make-normal-tn *fixnum-primitive-type*)))
89 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
90 ;;; VM-dependent initialization of the IR2-COMPONENT structure. We push
91 ;;; placeholder entries in the Constants to leave room for additional
92 ;;; noise in the code object header.
93 (!def-vm-support-routine select-component-format (component)
94 (declare (type component component))
95 (dotimes (i code-constants-offset)
96 (vector-push-extend nil
97 (ir2-component-constants (component-info component))))
103 ;;; BYTES-NEEDED-FOR-NON-DESCRIPTOR-STACK-FRAME -- internal
105 ;;; Return the number of bytes needed for the current non-descriptor stack
106 ;;; frame. Non-descriptor stack frames must be multiples of 8 bytes on
109 (defun bytes-needed-for-non-descriptor-stack-frame ()
110 (* (logandc2 (1+ (sb-allocated-size 'non-descriptor-stack)) 1)
113 ;;; Used for setting up the Old-FP in local call.
115 (define-vop (current-fp)
116 (:results (val :scs (any-reg)))
120 ;;; Used for computing the caller's NFP for use in known-values return. Only
121 ;;; works assuming there is no variable size stuff on the nstack.
123 (define-vop (compute-old-nfp)
124 (:results (val :scs (any-reg)))
127 (let ((nfp (current-nfp-tn vop)))
129 (inst addu val nfp (bytes-needed-for-non-descriptor-stack-frame))))))
131 ;;; Accessing a slot from an earlier stack frame is definite hackery.
132 (define-vop (ancestor-frame-ref)
133 (:args (frame-pointer :scs (descriptor-reg))
134 (variable-home-tn :load-if nil))
135 (:results (value :scs (descriptor-reg any-reg)))
138 (aver (sc-is variable-home-tn control-stack))
139 (loadw value frame-pointer (tn-offset variable-home-tn))))
140 (define-vop (ancestor-frame-set)
141 (:args (frame-pointer :scs (descriptor-reg))
142 (value :scs (descriptor-reg any-reg)))
143 (:results (variable-home-tn :load-if nil))
146 (aver (sc-is variable-home-tn control-stack))
147 (storew value frame-pointer (tn-offset variable-home-tn))))
149 (define-vop (xep-allocate-frame)
150 (:info start-lab copy-more-arg-follows)
151 (:ignore copy-more-arg-follows)
153 (:temporary (:scs (non-descriptor-reg)) temp)
155 ;; Make sure the function is aligned, and drop a label pointing to this
157 (emit-alignment n-lowtag-bits)
158 (trace-table-entry trace-table-fun-prologue)
159 (emit-label start-lab)
160 ;; Allocate function header.
161 (inst simple-fun-header-word)
162 (dotimes (i (1- simple-fun-code-offset))
164 ;; The start of the actual code.
165 ;; Compute CODE from the address of this entry point.
166 (let ((entry-point (gen-label)))
167 (emit-label entry-point)
168 (inst compute-code-from-lip code-tn lip-tn entry-point temp)
169 ;; ### We should also save it on the stack so that the garbage collector
170 ;; won't forget about us if we call anyone else.
172 ;; Build our stack frames.
173 (inst addu csp-tn cfp-tn
174 (* n-word-bytes (sb-allocated-size 'control-stack)))
175 (let ((nfp (current-nfp-tn vop)))
177 (inst addu nsp-tn nsp-tn
178 (- (bytes-needed-for-non-descriptor-stack-frame)))
180 (trace-table-entry trace-table-normal)))
182 (define-vop (allocate-frame)
183 (:results (res :scs (any-reg))
184 (nfp :scs (any-reg)))
187 (trace-table-entry trace-table-fun-prologue)
189 (inst addu csp-tn csp-tn
190 (* n-word-bytes (sb-allocated-size 'control-stack)))
191 (when (ir2-physenv-number-stack-p callee)
192 (inst addu nsp-tn nsp-tn
193 (- (bytes-needed-for-non-descriptor-stack-frame)))
195 (trace-table-entry trace-table-normal)))
197 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
198 ;;; is the number of arguments passed. If no stack arguments are passed, then
199 ;;; we don't have to do anything.
201 (define-vop (allocate-full-call-frame)
203 (:results (res :scs (any-reg)))
205 (when (> nargs register-arg-count)
207 (inst addu csp-tn csp-tn (* nargs n-word-bytes)))))
212 ;;; Emit code needed at the return-point from an unknown-values call for a
213 ;;; fixed number of values. Values is the head of the TN-Ref list for the
214 ;;; locations that the values are to be received into. Nvals is the number of
215 ;;; values that are to be received (should equal the length of Values).
217 ;;; MOVE-TEMP is a DESCRIPTOR-REG TN used as a temporary.
219 ;;; This code exploits the fact that in the unknown-values convention, a
220 ;;; single value return returns at the return PC + 8, whereas a return of other
221 ;;; than one value returns directly at the return PC.
223 ;;; If 0 or 1 values are expected, then we just emit an instruction to reset
224 ;;; the SP (which will only be executed when other than 1 value is returned.)
226 ;;; In the general case, we have to do three things:
227 ;;; -- Default unsupplied register values. This need only be done when a
228 ;;; single value is returned, since register values are defaulted by the
229 ;;; callee in the non-single case.
230 ;;; -- Default unsupplied stack values. This needs to be done whenever there
231 ;;; are stack values.
232 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
233 ;;; regardless of the number of values desired.
235 ;;; The general-case code looks like this:
237 b regs-defaulted ; Skip if MVs
240 move a1 null-tn ; Default register values
242 loadi nargs 1 ; Force defaulting of stack values
243 move ocfp csp ; Set up args for SP resetting
246 subu temp nargs register-arg-count
248 bltz temp default-value-7 ; jump to default code
250 loadw move-temp ocfp-tn 6 ; Move value to correct location.
251 store-stack-tn val4-tn move-temp
253 bltz temp default-value-8
255 loadw move-temp ocfp-tn 7
256 store-stack-tn val5-tn move-temp
261 move csp ocfp ; Reset SP.
266 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
269 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
277 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
278 (declare (type (or tn-ref null) values)
279 (type unsigned-byte nvals) (type tn move-temp temp))
282 ;; Note that this is a single-value return point. This is actually
283 ;; the multiple-value entry point for a single desired value, but
284 ;; the code location has to be here, or the debugger backtrace
286 (without-scheduling ()
287 (note-this-location vop :single-value-return)
288 (move csp-tn ocfp-tn t)
291 (inst compute-code-from-lra code-tn code-tn lra-label temp)))
292 (let ((regs-defaulted (gen-label))
293 (defaulting-done (gen-label))
294 (default-stack-vals (gen-label)))
295 (without-scheduling ()
296 ;; Note that this is an unknown-values return point.
297 (note-this-location vop :unknown-return)
298 ;; Branch off to the MV case.
299 (inst b regs-defaulted)
300 ;; If there are no stack results, clear the stack now.
301 (if (> nvals register-arg-count)
302 (inst addu temp nargs-tn (fixnumize (- register-arg-count)))
303 (move csp-tn ocfp-tn t)))
305 ;; Do the single value case.
307 (val (tn-ref-across values) (tn-ref-across val)))
308 ((= i (min nvals register-arg-count)))
309 (move (tn-ref-tn val) null-tn))
310 (when (> nvals register-arg-count)
311 (inst b default-stack-vals)
312 (move ocfp-tn csp-tn t))
314 (emit-label regs-defaulted)
316 (when (> nvals register-arg-count)
317 ;; If there are stack results, we have to default them
318 ;; and clear the stack.
319 (collect ((defaults))
320 (do ((i register-arg-count (1+ i))
321 (val (do ((i 0 (1+ i))
322 (val values (tn-ref-across val)))
323 ((= i register-arg-count) val))
324 (tn-ref-across val)))
327 (let ((default-lab (gen-label))
328 (tn (tn-ref-tn val)))
329 (defaults (cons default-lab tn))
331 (inst blez temp default-lab)
332 (inst lw move-temp ocfp-tn (* i n-word-bytes))
333 (inst addu temp temp (fixnumize -1))
334 (store-stack-tn tn move-temp)))
336 (emit-label defaulting-done)
337 (move csp-tn ocfp-tn)
339 (let ((defaults (defaults)))
341 (assemble (*elsewhere*)
342 (emit-label default-stack-vals)
343 (trace-table-entry trace-table-fun-prologue)
344 (do ((remaining defaults (cdr remaining)))
346 (let ((def (car remaining)))
347 (emit-label (car def))
348 (when (null (cdr remaining))
349 (inst b defaulting-done))
350 (store-stack-tn (cdr def) null-tn)))
351 (trace-table-entry trace-table-normal)))))
354 (inst compute-code-from-lra code-tn code-tn lra-label temp))))
358 ;;;; Unknown values receiving:
360 ;;; Emit code needed at the return point for an unknown-values call for an
361 ;;; arbitrary number of values.
363 ;;; We do the single and non-single cases with no shared code: there doesn't
364 ;;; seem to be any potential overlap, and receiving a single value is more
365 ;;; important efficiency-wise.
367 ;;; When there is a single value, we just push it on the stack, returning
368 ;;; the old SP and 1.
370 ;;; When there is a variable number of values, we move all of the argument
371 ;;; registers onto the stack, and return Args and Nargs.
373 ;;; Args and Nargs are TNs wired to the named locations. We must
374 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
375 ;;; results Start and Count (also, it's nice to be able to target them).
377 (defun receive-unknown-values (args nargs start count lra-label temp)
378 (declare (type tn args nargs start count temp))
379 (let ((variable-values (gen-label))
381 (without-scheduling ()
382 (inst b variable-values)
386 (inst compute-code-from-lra code-tn code-tn lra-label temp))
387 (inst addu csp-tn csp-tn n-word-bytes)
388 (storew (first *register-arg-tns*) csp-tn -1)
389 (inst addu start csp-tn (- n-word-bytes))
390 (inst li count (fixnumize 1))
394 (assemble (*elsewhere*)
395 (trace-table-entry trace-table-fun-prologue)
396 (emit-label variable-values)
398 (inst compute-code-from-lra code-tn code-tn lra-label temp))
399 (do ((arg *register-arg-tns* (rest arg))
402 (storew (first arg) args i))
406 (trace-table-entry trace-table-normal)))
410 ;;; VOP that can be inherited by unknown values receivers. The main thing this
411 ;;; handles is allocation of the result temporaries.
413 (define-vop (unknown-values-receiver)
415 (start :scs (any-reg))
416 (count :scs (any-reg)))
417 (:temporary (:sc descriptor-reg :offset ocfp-offset
418 :from :eval :to (:result 0))
420 (:temporary (:sc any-reg :offset nargs-offset
421 :from :eval :to (:result 1))
423 (:temporary (:scs (non-descriptor-reg)) temp))
426 ;;; This hook in the codegen pass lets us insert code before fall-thru entry
427 ;;; points, local-call entry points, and tail-call entry points. The default
429 (defun emit-block-header (start-label trampoline-label fall-thru-p alignp)
430 (declare (ignore fall-thru-p alignp))
431 (when trampoline-label
432 (emit-label trampoline-label))
433 (emit-label start-label))
436 ;;;; Local call with unknown values convention return:
438 ;;; Non-TR local call for a fixed number of values passed according to the
439 ;;; unknown values convention.
441 ;;; Args are the argument passing locations, which are specified only to
442 ;;; terminate their lifetimes in the caller.
444 ;;; Values are the return value locations (wired to the standard passing
447 ;;; Save is the save info, which we can ignore since saving has been done.
448 ;;; Return-PC is the TN that the return PC should be passed in.
449 ;;; Target is a continuation pointing to the start of the called function.
450 ;;; Nvals is the number of values received.
452 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
453 ;;; registers may be tied up by the more operand. Instead, we use
454 ;;; MAYBE-LOAD-STACK-TN.
456 (define-vop (call-local)
460 (:results (values :more t))
462 (:move-args :local-call)
463 (:info arg-locs callee target nvals)
465 (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
466 (:temporary (:scs (non-descriptor-reg)) temp)
467 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
468 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
469 (:ignore arg-locs args ocfp)
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 (default-unknown-values vop values nvals move-temp temp label)
489 (load-stack-tn cur-nfp nfp-save)))))
492 ;;; Non-TR local call for a variable number of return values passed according
493 ;;; to the unknown values convention. The results are the start of the values
494 ;;; glob and the number of values received.
496 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
497 ;;; registers may be tied up by the more operand. Instead, we use
498 ;;; MAYBE-LOAD-STACK-TN.
500 (define-vop (multiple-call-local unknown-values-receiver)
505 (:move-args :local-call)
506 (:info save callee target)
509 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
510 (:temporary (:scs (non-descriptor-reg)) temp)
512 (let ((label (gen-label))
513 (cur-nfp (current-nfp-tn vop)))
515 (store-stack-tn nfp-save cur-nfp))
516 (let ((callee-nfp (callee-nfp-tn callee)))
518 (maybe-load-stack-tn callee-nfp nfp)))
519 (maybe-load-stack-tn cfp-tn fp)
520 (trace-table-entry trace-table-call-site)
521 (inst compute-lra-from-code
522 (callee-return-pc-tn callee) code-tn label temp)
523 (note-this-location vop :call-site)
526 (trace-table-entry trace-table-normal)
527 (emit-return-pc label)
528 (note-this-location vop :unknown-return)
529 (receive-unknown-values values-start nvals start count label temp)
531 (load-stack-tn cur-nfp nfp-save)))))
534 ;;;; Local call with known values return:
536 ;;; Non-TR local call with known return locations. Known-value return works
537 ;;; just like argument passing in local call.
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-call-local)
547 (:results (res :more t))
548 (:move-args :local-call)
550 (:info save callee target)
551 (:ignore args res save)
553 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
554 (:temporary (:scs (non-descriptor-reg)) temp)
556 (let ((label (gen-label))
557 (cur-nfp (current-nfp-tn vop)))
559 (store-stack-tn nfp-save cur-nfp))
560 (let ((callee-nfp (callee-nfp-tn callee)))
562 (maybe-load-stack-tn callee-nfp nfp)))
563 (maybe-load-stack-tn cfp-tn fp)
564 (trace-table-entry trace-table-call-site)
565 (inst compute-lra-from-code
566 (callee-return-pc-tn callee) code-tn label temp)
567 (note-this-location vop :call-site)
570 (trace-table-entry trace-table-normal)
571 (emit-return-pc label)
572 (note-this-location vop :known-return)
574 (load-stack-tn cur-nfp nfp-save)))))
576 ;;; Return from known values call. We receive the return locations as
577 ;;; arguments to terminate their lifetimes in the returning function. We
578 ;;; restore FP and CSP and jump to the Return-PC.
580 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
581 ;;; registers may be tied up by the more operand. Instead, we use
582 ;;; MAYBE-LOAD-STACK-TN.
584 (define-vop (known-return)
585 (:args (ocfp :target ocfp-temp)
586 (return-pc :target return-pc-temp)
588 (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
589 (:temporary (:sc descriptor-reg :from (:argument 1))
591 (:temporary (:scs (interior-reg)) lip)
592 (:move-args :known-return)
594 (:ignore val-locs vals)
597 (trace-table-entry trace-table-fun-epilogue)
598 (maybe-load-stack-tn ocfp-temp ocfp)
599 (maybe-load-stack-tn return-pc-temp return-pc)
601 (let ((cur-nfp (current-nfp-tn vop)))
603 (inst addu nsp-tn cur-nfp
604 (bytes-needed-for-non-descriptor-stack-frame))))
605 (inst addu lip return-pc-temp (- n-word-bytes other-pointer-lowtag))
607 (move cfp-tn ocfp-temp t)
608 (trace-table-entry trace-table-normal)))
613 ;;; There is something of a cross-product effect with full calls. Different
614 ;;; versions are used depending on whether we know the number of arguments or
615 ;;; the name of the called function, and whether we want fixed values, unknown
616 ;;; values, or a tail call.
618 ;;; In full call, the arguments are passed creating a partial frame on the
619 ;;; stack top and storing stack arguments into that frame. On entry to the
620 ;;; callee, this partial frame is pointed to by FP. If there are no stack
621 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
622 ;;; to SP just before the call.
624 ;;; This macro helps in the definition of full call VOPs by avoiding code
625 ;;; replication in defining the cross-product VOPs.
627 ;;; Name is the name of the VOP to define.
629 ;;; Named is true if the first argument is a symbol whose global function
630 ;;; definition is to be called.
632 ;;; Return is either :Fixed, :Unknown or :Tail:
633 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
634 ;;; the standard passing locations (passed as result operands).
635 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
636 ;;; result values are specified by the Start and Count as in the
637 ;;; unknown-values continuation representation.
638 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
639 ;;; The Ocfp and Return-PC are passed as the second and third arguments.
641 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
642 ;;; fixed argument. If Variable is false, then the passing locations are
643 ;;; passed as a more arg. Variable is true if there are a variable number of
644 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
645 ;;; return. TR variable argument call is implemented separately.
647 ;;; In tail call with fixed arguments, the passing locations are passed as a
648 ;;; more arg, but there is no new-FP, since the arguments have been set up in
649 ;;; the current frame.
651 (defmacro define-full-call (name named return variable)
652 (aver (not (and variable (eq return :tail))))
654 ,@(when (eq return :unknown)
655 '(unknown-values-receiver)))
657 ,@(unless (eq return :tail)
658 '((new-fp :scs (any-reg) :to :eval)))
661 '(name :target name-pass)
662 '(arg-fun :target lexenv))
664 ,@(when (eq return :tail)
665 '((ocfp :target ocfp-pass)
666 (return-pc :target return-pc-pass)))
668 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
670 ,@(when (eq return :fixed)
671 '((:results (values :more t))))
673 (:save-p ,(if (eq return :tail) :compute-only t))
675 ,@(unless (or (eq return :tail) variable)
676 '((:move-args :full-call)))
679 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
680 ,@(unless variable '(nargs))
681 ,@(when (eq return :fixed) '(nvals))
684 (:ignore ,@(unless (or variable (eq return :tail)) '(arg-locs))
685 ,@(unless variable '(args)))
687 (:temporary (:sc descriptor-reg
690 ,@(unless (eq return :fixed)
694 (:temporary (:sc descriptor-reg
696 :from (:argument ,(if (eq return :tail) 2 1))
701 `((:temporary (:sc descriptor-reg :offset fdefn-offset
702 :from (:argument ,(if (eq return :tail) 0 1))
706 `((:temporary (:sc descriptor-reg :offset lexenv-offset
707 :from (:argument ,(if (eq return :tail) 0 1))
710 (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
713 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
717 (mapcar #'(lambda (name offset)
718 `(:temporary (:sc descriptor-reg
722 register-arg-names *register-arg-offsets*))
723 ,@(when (eq return :fixed)
724 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
726 (:temporary (:scs (descriptor-reg) :to :eval) stepping)
728 ,@(unless (eq return :tail)
729 '((:temporary (:scs (non-descriptor-reg)) temp)
730 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
732 (:temporary (:sc interior-reg) entry-point)
734 (:generator ,(+ (if named 5 0)
736 (if (eq return :tail) 0 10)
738 (if (eq return :unknown) 25 0))
739 (let* ((cur-nfp (current-nfp-tn vop))
740 ,@(unless (eq return :tail)
741 '((lra-label (gen-label))))
742 (step-done-label (gen-label))
746 ,@(if (eq return :tail)
747 '((unless (location= ocfp ocfp-pass)
749 (unless (location= return-pc
759 (flet ((do-next-filler ()
760 (let* ((next (pop filler))
761 (what (if (consp next) (car next) next)))
765 `((inst subu nargs-pass csp-tn new-fp)
767 (mapcar #'(lambda (name)
768 `(inst lw ,name new-fp
771 register-arg-names)))
772 '((inst li nargs-pass (fixnumize nargs)))))
773 ,@(if (eq return :tail)
777 (move ocfp-pass ocfp t))
779 (inst lw ocfp-pass cfp-tn
780 (ash (tn-offset ocfp)
785 (move return-pc-pass return-pc t))
787 (inst lw return-pc-pass cfp-tn
788 (ash (tn-offset return-pc)
791 (inst addu nsp-tn cur-nfp
792 (bytes-needed-for-non-descriptor-stack-frame))))
794 (inst compute-lra-from-code
795 return-pc-pass code-tn lra-label temp))
797 (store-stack-tn nfp-save cur-nfp))
799 (move ocfp-pass cfp-tn t))
802 '(move cfp-tn new-fp)
803 '(if (> nargs register-arg-count)
805 (move cfp-tn csp-tn)))
806 (trace-table-entry trace-table-call-site))))
809 (insert-step-instrumenting (callable-tn)
810 ;; Conditionally insert a conditional trap:
811 (when step-instrumenting
812 (load-symbol-value stepping sb!impl::*stepping*)
813 ;; If it's not NIL, trap.
814 (inst beq stepping null-tn step-done-label)
816 ;; CONTEXT-PC will be pointing here when the
817 ;; interrupt is handled, not after the BREAK.
818 (note-this-location vop :step-before-vop)
819 ;; Construct a trap code with the low bits from
820 ;; SINGLE-STEP-AROUND-TRAP and the high bits from
821 ;; the register number of CALLABLE-TN.
822 (inst break 0 (logior single-step-around-trap
823 (ash (reg-tn-encoding callable-tn)
825 (emit-label step-done-label))))
829 (descriptor-reg (move name-pass name))
831 (inst lw name-pass cfp-tn
832 (ash (tn-offset name) word-shift))
835 (inst lw name-pass code-tn
836 (- (ash (tn-offset name) word-shift)
837 other-pointer-lowtag))
839 ;; The step instrumenting must be done after
840 ;; FUNCTION is loaded, but before ENTRY-POINT is
842 (insert-step-instrumenting name-pass)
843 (inst lw entry-point name-pass
844 (- (ash fdefn-raw-addr-slot word-shift)
845 other-pointer-lowtag))
848 (descriptor-reg (move lexenv arg-fun))
850 (inst lw lexenv cfp-tn
851 (ash (tn-offset arg-fun) word-shift))
854 (inst lw lexenv code-tn
855 (- (ash (tn-offset arg-fun) word-shift)
856 other-pointer-lowtag))
858 (inst lw function lexenv
859 (- (ash closure-fun-slot word-shift)
862 ;; The step instrumenting must be done before
863 ;; after FUNCTION is loaded, but before ENTRY-POINT
865 (insert-step-instrumenting function)
866 (inst addu entry-point function
867 (- (ash simple-fun-code-offset word-shift)
868 fun-pointer-lowtag))))
875 (note-this-location vop :call-site)
881 '((trace-table-entry trace-table-normal)
882 (emit-return-pc lra-label)
883 (default-unknown-values vop values nvals
884 move-temp temp lra-label)
886 (load-stack-tn cur-nfp nfp-save))))
888 '((trace-table-entry trace-table-normal)
889 (emit-return-pc lra-label)
890 (note-this-location vop :unknown-return)
891 (receive-unknown-values values-start nvals start count
894 (load-stack-tn cur-nfp nfp-save))))
898 (define-full-call call nil :fixed nil)
899 (define-full-call call-named t :fixed nil)
900 (define-full-call multiple-call nil :unknown nil)
901 (define-full-call multiple-call-named t :unknown nil)
902 (define-full-call tail-call nil :tail nil)
903 (define-full-call tail-call-named t :tail nil)
905 (define-full-call call-variable nil :fixed t)
906 (define-full-call multiple-call-variable nil :unknown t)
909 ;;; Defined separately, since needs special code that BLT's the arguments
912 (define-vop (tail-call-variable)
914 (args-arg :scs (any-reg) :target args)
915 (function-arg :scs (descriptor-reg) :target lexenv)
916 (ocfp-arg :scs (any-reg) :target ocfp)
917 (lra-arg :scs (descriptor-reg) :target lra))
919 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
920 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
921 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
922 (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
928 ;; Move these into the passing locations if they are not already there.
930 (move lexenv function-arg)
934 ;; Clear the number stack if anything is there and jump to the
935 ;; assembly-routine that does the bliting.
936 (inst j (make-fixup 'tail-call-variable :assembly-routine))
937 (let ((cur-nfp (current-nfp-tn vop)))
939 (inst addu nsp-tn cur-nfp
940 (bytes-needed-for-non-descriptor-stack-frame))
944 ;;;; Unknown values return:
946 ;;; Return a single value using the unknown-values convention.
948 (define-vop (return-single)
949 (:args (ocfp :scs (any-reg))
950 (return-pc :scs (descriptor-reg))
953 (:temporary (:scs (interior-reg)) lip)
956 ;; Clear the number stack.
957 (trace-table-entry trace-table-fun-epilogue)
958 (let ((cur-nfp (current-nfp-tn vop)))
960 (inst addu nsp-tn cur-nfp
961 (bytes-needed-for-non-descriptor-stack-frame))))
962 ;; Clear the control stack, and restore the frame pointer.
966 (lisp-return return-pc lip :offset 2)
967 (trace-table-entry trace-table-normal)))
970 ;;; Do unknown-values return of a fixed number of values. The Values are
971 ;;; required to be set up in the standard passing locations. Nvals is the
972 ;;; number of values returned.
974 ;;; If returning a single value, then deallocate the current frame, restore
975 ;;; FP and jump to the single-value entry at Return-PC + 8.
977 ;;; If returning other than one value, then load the number of values returned,
978 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
979 ;;; When there are stack values, we must initialize the argument pointer to
980 ;;; point to the beginning of the values block (which is the beginning of the
984 (:args (ocfp :scs (any-reg))
985 (return-pc :scs (descriptor-reg) :to (:eval 1))
989 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
990 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
991 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
992 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
993 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
994 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
995 (:temporary (:sc any-reg :offset nargs-offset) nargs)
996 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
997 (:temporary (:scs (interior-reg)) lip)
1000 ;; Clear the number stack.
1001 (trace-table-entry trace-table-fun-epilogue)
1002 (let ((cur-nfp (current-nfp-tn vop)))
1004 (inst addu nsp-tn cur-nfp
1005 (bytes-needed-for-non-descriptor-stack-frame))))
1007 ;; Clear the control stack, and restore the frame pointer.
1008 (move csp-tn cfp-tn)
1011 (lisp-return return-pc lip :offset 2))
1013 ;; Establish the values pointer and values count.
1014 (move val-ptr cfp-tn)
1015 (inst li nargs (fixnumize nvals))
1016 ;; restore the frame pointer and clear as much of the control
1017 ;; stack as possible.
1019 (inst addu csp-tn val-ptr (* nvals n-word-bytes))
1020 ;; pre-default any argument register that need it.
1021 (when (< nvals register-arg-count)
1022 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
1023 (move reg null-tn)))
1025 (lisp-return return-pc lip)))
1026 (trace-table-entry trace-table-normal)))
1028 ;;; Do unknown-values return of an arbitrary number of values (passed on the
1029 ;;; stack.) We check for the common case of a single return value, and do that
1030 ;;; inline using the normal single value return convention. Otherwise, we
1031 ;;; branch off to code that calls an assembly-routine.
1033 (define-vop (return-multiple)
1034 (:args (ocfp-arg :scs (any-reg) :target ocfp)
1035 (lra-arg :scs (descriptor-reg) :target lra)
1036 (vals-arg :scs (any-reg) :target vals)
1037 (nvals-arg :scs (any-reg) :target nvals))
1039 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
1040 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
1041 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
1042 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
1043 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
1044 (:temporary (:scs (interior-reg)) lip)
1049 (trace-table-entry trace-table-fun-epilogue)
1050 (let ((not-single (gen-label)))
1051 ;; Clear the number stack.
1052 (let ((cur-nfp (current-nfp-tn vop)))
1054 (inst addu nsp-tn cur-nfp
1055 (bytes-needed-for-non-descriptor-stack-frame))))
1057 ;; Check for the single case.
1058 (inst li a0 (fixnumize 1))
1059 (inst bne nvals-arg a0 not-single)
1060 (inst lw a0 vals-arg)
1062 ;; Return with one value.
1063 (move csp-tn cfp-tn)
1064 (move cfp-tn ocfp-arg)
1065 (lisp-return lra-arg lip :offset 2)
1067 ;; Nope, not the single case.
1068 (emit-label not-single)
1069 (move ocfp ocfp-arg)
1071 (move vals vals-arg)
1073 (inst j (make-fixup 'return-multiple :assembly-routine))
1074 (move nvals nvals-arg t))
1075 (trace-table-entry trace-table-normal)))
1082 ;;; We don't need to do anything special for regular functions.
1084 (define-vop (setup-environment)
1088 ;; Don't bother doing anything.
1091 ;;; Get the lexical environment from its passing location.
1093 (define-vop (setup-closure-environment)
1094 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1097 (:results (closure :scs (descriptor-reg)))
1102 (move closure lexenv)))
1104 ;;; Copy a more arg from the argument area to the end of the current frame.
1105 ;;; Fixed is the number of non-more arguments.
1107 (define-vop (copy-more-arg)
1108 (:temporary (:sc any-reg :offset nl0-offset) result)
1109 (:temporary (:sc any-reg :offset nl1-offset) count)
1110 (:temporary (:sc any-reg :offset nl2-offset) src)
1111 (:temporary (:sc any-reg :offset nl3-offset) dst)
1112 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1115 (let ((loop (gen-label))
1116 (do-regs (gen-label))
1118 (when (< fixed register-arg-count)
1119 ;; Save a pointer to the results so we can fill in register args.
1120 ;; We don't need this if there are more fixed args than reg args.
1121 (move result csp-tn))
1122 ;; Allocate the space on the stack.
1123 (cond ((zerop fixed)
1124 (inst beq nargs-tn done)
1125 (inst addu csp-tn csp-tn nargs-tn))
1127 (inst addu count nargs-tn (fixnumize (- fixed)))
1128 (inst blez count done)
1130 (inst addu csp-tn csp-tn count)))
1131 (when (< fixed register-arg-count)
1132 ;; We must stop when we run out of stack args, not when we run out of
1134 (inst addu count nargs-tn (fixnumize (- register-arg-count))))
1135 ;; Everything of interest in registers.
1136 (inst blez count do-regs)
1137 ;; Initialize dst to be end of stack.
1139 ;; Initialize src to be end of args.
1140 (inst addu src cfp-tn nargs-tn)
1143 ;; *--dst = *--src, --count
1144 (inst addu src src (- n-word-bytes))
1145 (inst addu count count (fixnumize -1))
1147 (inst addu dst dst (- n-word-bytes))
1148 (inst bgtz count loop)
1151 (emit-label do-regs)
1152 (when (< fixed register-arg-count)
1153 ;; Now we have to deposit any more args that showed up in registers.
1154 ;; We know there is at least one more arg, otherwise we would have
1155 ;; branched to done up at the top.
1156 (inst subu count nargs-tn (fixnumize (1+ fixed)))
1157 (do ((i fixed (1+ i)))
1158 ((>= i register-arg-count))
1159 ;; Is this the last one?
1160 (inst beq count done)
1161 ;; Store it relative to the pointer saved at the start.
1162 (storew (nth i *register-arg-tns*) result (- i fixed))
1164 (inst subu count (fixnumize 1))))
1165 (emit-label done))))
1168 ;;; More args are stored consecutively on the stack, starting
1169 ;;; immediately at the context pointer. The context pointer is not
1170 ;;; typed, so the lowtag is 0.
1171 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1173 ;;; Turn more arg (context, count) into a list.
1174 (define-vop (listify-rest-args)
1175 (:args (context-arg :target context :scs (descriptor-reg))
1176 (count-arg :target count :scs (any-reg)))
1177 (:arg-types * tagged-num)
1178 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1179 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1180 (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1181 (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
1182 (:results (result :scs (descriptor-reg)))
1183 (:translate %listify-rest-args)
1187 (let* ((enter (gen-label))
1190 (dx-p (node-stack-allocate-p node))
1191 (alloc-area-tn (if dx-p csp-tn alloc-tn)))
1192 (move context context-arg)
1193 (move count count-arg)
1194 ;; Check to see if there are any arguments.
1195 (inst beq count done)
1196 (move result null-tn t)
1198 ;; We need to do this atomically.
1199 (pseudo-atomic (pa-flag)
1202 ;; Allocate a cons (2 words) for each item.
1203 (inst srl result alloc-area-tn n-lowtag-bits)
1204 (inst sll result n-lowtag-bits)
1205 (inst or result list-pointer-lowtag)
1207 (inst sll temp count 1)
1209 (inst addu alloc-area-tn temp)
1211 ;; Store the current cons in the cdr of the previous cons.
1213 (inst addu dst dst (* 2 n-word-bytes))
1214 (storew dst dst -1 list-pointer-lowtag)
1218 (loadw temp context)
1219 (inst addu context n-word-bytes)
1221 ;; Dec count, and if != zero, go back for more.
1222 (inst addu count count (fixnumize -1))
1223 (inst bne count loop)
1225 ;; Store the value in the car (in delay slot)
1226 (storew temp dst 0 list-pointer-lowtag)
1228 ;; NIL out the last cons.
1229 (storew null-tn dst 1 list-pointer-lowtag))
1230 (emit-label done))))
1232 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1233 ;;; Supplied is the total number of arguments supplied (originally passed in
1234 ;;; NARGS.) Fixed is the number of non-rest arguments.
1236 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1237 ;;; time the environment is in a pretty brain-damaged state, preventing this
1238 ;;; info from being returned as values. What we do is compute
1239 ;;; supplied - fixed, and return a pointer that many words below the current
1242 (define-vop (more-arg-context)
1243 (:policy :fast-safe)
1244 (:translate sb!c::%more-arg-context)
1245 (:args (supplied :scs (any-reg)))
1246 (:arg-types tagged-num (:constant fixnum))
1248 (:results (context :scs (descriptor-reg))
1249 (count :scs (any-reg)))
1250 (:result-types t tagged-num)
1251 (:note "more-arg-context")
1253 (inst addu count supplied (fixnumize (- fixed)))
1254 (inst subu context csp-tn count)))
1257 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1259 (define-vop (verify-arg-count)
1260 (:policy :fast-safe)
1261 (:translate sb!c::%verify-arg-count)
1262 (:args (nargs :scs (any-reg)))
1263 (:arg-types positive-fixnum (:constant t))
1264 (:temporary (:scs (any-reg) :type fixnum) temp)
1267 (:save-p :compute-only)
1270 (generate-error-code vop invalid-arg-count-error nargs)))
1271 (cond ((zerop count)
1272 (inst bne nargs err-lab)
1275 (inst li temp (fixnumize count))
1276 (inst bne nargs temp err-lab)
1279 ;;; Various other error signalers.
1281 (macrolet ((frob (name error translate &rest args)
1282 `(define-vop (,name)
1284 `((:policy :fast-safe)
1285 (:translate ,translate)))
1286 (:args ,@(mapcar #'(lambda (arg)
1287 `(,arg :scs (any-reg descriptor-reg)))
1290 (:save-p :compute-only)
1292 (error-call vop ,error ,@args)))))
1293 (frob arg-count-error invalid-arg-count-error
1294 sb!c::%arg-count-error nargs)
1295 (frob type-check-error object-not-type-error sb!c::%type-check-error
1297 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1299 (frob odd-key-args-error odd-key-args-error
1300 sb!c::%odd-key-args-error)
1301 (frob unknown-key-arg-error unknown-key-arg-error
1302 sb!c::%unknown-key-arg-error key)
1303 (frob nil-fun-returned-error nil-fun-returned-error nil fun))
1307 (define-vop (step-instrument-before-vop)
1308 (:temporary (:scs (descriptor-reg)) stepping)
1309 (:policy :fast-safe)
1312 (load-symbol-value stepping sb!impl::*stepping*)
1313 ;; If it's not NIL, trap.
1314 (inst beq stepping null-tn DONE)
1316 ;; CONTEXT-PC will be pointing here when the interrupt is handled,
1317 ;; not after the BREAK.
1318 (note-this-location vop :step-before-vop)
1319 ;; CALLEE-REGISTER-OFFSET isn't needed for before-traps, so we
1320 ;; can just use a bare SINGLE-STEP-BEFORE-TRAP as the code.
1321 (inst break 0 single-step-before-trap)