1 ;;;; the VM definition of function call for HPPA
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))))
101 ;;; bytes-needed-for-non-descriptor-stack-frame is the amount
102 ;;; we grow or shrink the NSP/NFP stack. This stack is used
103 ;;; by C-code so the convention (grow direction, grow size)
104 ;;; is governed by the hpux+hppa ABI or linux+hppa ABI.
105 ;;; Return the number of bytes needed for the current non-descriptor stack.
106 ;;; We have to allocate multiples of 64 bytes
107 (defun bytes-needed-for-non-descriptor-stack-frame ()
108 (logandc2 (+ (* (sb-allocated-size 'non-descriptor-stack) n-word-bytes) 63)
111 ;;; Used for setting up the Old-FP in local call.
113 (define-vop (current-fp)
114 (:results (val :scs (any-reg)))
118 ;;; Used for computing the caller's NFP for use in known-values return. Only
119 ;;; works assuming there is no variable size stuff on the nstack.
121 (define-vop (compute-old-nfp)
122 (:results (val :scs (any-reg)))
125 (let ((nfp (current-nfp-tn vop)))
127 (inst addi (- (bytes-needed-for-non-descriptor-stack-frame))
130 ;;; Accessing a slot from an earlier stack frame is definite hackery.
131 (define-vop (ancestor-frame-ref)
132 (:args (frame-pointer :scs (descriptor-reg))
133 (variable-home-tn :load-if nil))
134 (:results (value :scs (descriptor-reg any-reg)))
137 (aver (sc-is variable-home-tn control-stack))
138 (loadw value frame-pointer (tn-offset variable-home-tn))))
139 (define-vop (ancestor-frame-set)
140 (:args (frame-pointer :scs (descriptor-reg))
141 (value :scs (descriptor-reg any-reg)))
142 (:results (variable-home-tn :load-if nil))
145 (aver (sc-is variable-home-tn control-stack))
146 (storew value frame-pointer (tn-offset variable-home-tn))))
148 (define-vop (xep-allocate-frame)
149 (:info start-lab copy-more-arg-follows)
150 (:ignore copy-more-arg-follows)
152 (:temporary (:scs (non-descriptor-reg)) temp)
154 ;; Make sure the function is aligned, and drop a label pointing to this
156 (emit-alignment n-lowtag-bits)
157 (trace-table-entry trace-table-fun-prologue)
158 (emit-label start-lab)
159 ;; Allocate function header.
160 (inst simple-fun-header-word)
161 (dotimes (i (1- simple-fun-code-offset))
163 ;; The start of the actual code.
164 ;; Fix CODE, cause the function object was passed in.
165 (let ((entry-point (gen-label)))
166 (emit-label entry-point)
167 (inst compute-code-from-lip lip-tn entry-point temp code-tn)
168 ;; ### We should also save it on the stack so that the garbage
169 ;; collector won't forget about us if we call anyone else.
171 ;; Build our stack frames.
172 (inst addi (* n-word-bytes (sb-allocated-size 'control-stack))
174 (let ((nfp (current-nfp-tn vop)))
177 (inst addi (bytes-needed-for-non-descriptor-stack-frame)
179 (trace-table-entry trace-table-normal)))
181 (define-vop (allocate-frame)
182 (:results (res :scs (any-reg))
183 (nfp :scs (any-reg)))
186 (trace-table-entry trace-table-fun-prologue)
188 (inst addi (* n-word-bytes (sb-allocated-size 'control-stack))
190 (when (ir2-physenv-number-stack-p callee)
192 (inst addi (bytes-needed-for-non-descriptor-stack-frame)
194 (trace-table-entry trace-table-normal)))
196 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
197 ;;; is the number of arguments passed. If no stack arguments are passed, then
198 ;;; we don't have to do anything.
200 (define-vop (allocate-full-call-frame)
202 (:results (res :scs (any-reg)))
204 (when (> nargs register-arg-count)
206 (inst addi (* nargs n-word-bytes) csp-tn csp-tn))))
209 ;;; Fix: boil down below notes into something nicer
210 ;;; Emit code needed at the return-point from an unknown-values call for a
211 ;;; fixed number of values. VALUES is the head of the TN-REF list for the
212 ;;; locations that the values are to be received into. NVALS is the number of
213 ;;; values that are to be received (should equal the length of VALUES).
215 ;;; MOVE-TEMP is a DESCRIPTOR-REG TN used as a temporary.
217 ;;; This code exploits the fact that in the unknown-values convention, a
218 ;;; single value return returns at the return PC + 8, whereas a return of other
219 ;;; than one value returns directly at the return PC.
221 ;;; If 0 or 1 values are expected, then we just emit an instruction to reset
222 ;;; the SP (which will only be executed when other than 1 value is returned.)
224 ;;; In the general case, we have to do three things:
225 ;;; -- Default unsupplied register values. This need only be done when a
226 ;;; single value is returned, since register values are defaulted by the
227 ;;; called in the non-single case.
228 ;;; -- Default unsupplied stack values. This needs to be done whenever there
229 ;;; are stack values.
230 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
231 ;;; regardless of the number of values desired.
233 ;;; The general-case code looks like this:
235 b regs-defaulted ; Skip if MVs
238 move a1 null-tn ; Default register values
240 loadi nargs 1 ; Force defaulting of stack values
241 move old-fp csp ; Set up args for SP resetting
244 subu temp nargs register-arg-count
246 bltz temp default-value-7 ; jump to default code
248 loadw move-temp old-fp-tn 6 ; Move value to correct location.
249 store-stack-tn val4-tn move-temp
251 bltz temp default-value-8
253 loadw move-temp old-fp-tn 7
254 store-stack-tn val5-tn move-temp
259 move sp old-fp ; Reset SP.
264 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
267 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
275 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
276 (declare (type (or tn-ref null) values)
277 (type unsigned-byte nvals)
278 (type tn move-temp temp))
281 ;; Note that this is a single-value return point. This is actually
282 ;; the multiple-value entry point for a single desired value, but
283 ;; the code location has to be here, or the debugger backtrace
285 (without-scheduling ()
286 (note-this-location vop :single-value-return)
287 (move ocfp-tn csp-tn t)
290 (inst compute-code-from-lra code-tn lra-label temp code-tn)))
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) ; dont nullify
300 ;; If there are no stack results, clear the stack before branch.
301 (if (> nvals register-arg-count) ; what inst to late-branch-exec
302 (inst addi (fixnumize (- register-arg-count)) nargs-tn temp)
303 (move ocfp-tn csp-tn t)))
304 ;; Do the single value case.
306 (val (tn-ref-across values) (tn-ref-across val)))
307 ((= i (min nvals register-arg-count)))
308 (move null-tn (tn-ref-tn val)))
309 (when (> nvals register-arg-count)
310 (inst b default-stack-vals)
311 (move csp-tn ocfp-tn t))
313 (emit-label regs-defaulted)
315 (when (> nvals register-arg-count)
316 ;; If there are stack results, we have to default them
317 ;; and clear the stack.
318 (collect ((defaults))
319 (do ((i register-arg-count (1+ i))
320 (val (do ((i 0 (1+ i))
321 (val values (tn-ref-across val)))
322 ((= i register-arg-count) val))
323 (tn-ref-across val)))
326 (let ((default-lab (gen-label))
327 (tn (tn-ref-tn val)))
328 (defaults (cons default-lab tn))
330 (inst ldw (* i n-word-bytes) ocfp-tn move-temp)
331 (inst bc :<= nil temp zero-tn default-lab)
332 (inst addi (fixnumize -1) temp temp)
333 (store-stack-tn tn move-temp)))
335 (emit-label defaulting-done)
336 (move ocfp-tn csp-tn)
338 (let ((defaults (defaults)))
340 (assemble (*elsewhere*)
341 (emit-label default-stack-vals)
342 (trace-table-entry trace-table-fun-prologue)
343 (do ((remaining defaults (cdr remaining)))
345 (let ((def (car remaining)))
346 (emit-label (car def))
347 (when (null (cdr remaining))
348 (inst b defaulting-done))
349 (store-stack-tn (cdr def) null-tn)))
350 (trace-table-entry trace-table-normal)))))
352 (inst compute-code-from-lra code-tn lra-label temp code-tn)))))
356 ;;;; Unknown values receiving:
358 ;;; Emit code needed at the return point for an unknown-values call for an
359 ;;; arbitrary number of values.
361 ;;; We do the single and non-single cases with no shared code: there doesn't
362 ;;; seem to be any potential overlap, and receiving a single value is more
363 ;;; important efficiency-wise.
365 ;;; When there is a single value, we just push it on the stack, returning
366 ;;; the old SP and 1.
368 ;;; When there is a variable number of values, we move all of the argument
369 ;;; registers onto the stack, and return Args and Nargs.
371 ;;; Args and Nargs are TNs wired to the named locations. We must
372 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
373 ;;; results Start and Count (also, it's nice to be able to target them).
374 (defun receive-unknown-values (args nargs start count lra-label temp)
375 (declare (type tn args nargs start count temp))
376 (let ((variable-values (gen-label))
378 (without-scheduling ()
379 (inst b variable-values :nullify t)
380 (inst nop)) ; nop because of emit-return-pc alignment
383 (inst compute-code-from-lra code-tn lra-label temp code-tn))
384 (inst addi n-word-bytes csp-tn csp-tn)
385 (storew (first *register-arg-tns*) csp-tn -1)
386 (inst addi (- n-word-bytes) csp-tn start)
387 (inst li (fixnumize 1) count)
391 (assemble (*elsewhere*)
392 (trace-table-entry trace-table-fun-prologue)
393 (emit-label variable-values)
395 (inst compute-code-from-lra code-tn lra-label temp code-tn))
396 (do ((arg *register-arg-tns* (rest arg))
399 (storew (first arg) args i))
403 (trace-table-entry trace-table-normal)))
406 ;;; VOP that can be inherited by unknown values receivers. The main thing this
407 ;;; handles is allocation of the result temporaries.
409 (define-vop (unknown-values-receiver)
410 (:results (start :scs (any-reg))
411 (count :scs (any-reg)))
412 (:temporary (:sc descriptor-reg :offset ocfp-offset
413 :from :eval :to (:result 0))
415 (:temporary (:sc any-reg :offset nargs-offset
416 :from :eval :to (:result 1))
418 (:temporary (:scs (non-descriptor-reg)) temp))
421 ;;; This hook in the codegen pass lets us insert code before fall-thru entry
422 ;;; points, local-call entry points, and tail-call entry points. The default
424 (defun emit-block-header (start-label trampoline-label fall-thru-p alignp)
425 (declare (ignore fall-thru-p alignp))
426 (when trampoline-label
427 (emit-label trampoline-label))
428 (emit-label start-label))
431 ;;;; Local call with unknown values convention return:
433 ;;; Non-TR local call for a fixed number of values passed according to the
434 ;;; unknown values convention.
436 ;;; Args are the argument passing locations, which are specified only to
437 ;;; terminate their lifetimes in the caller.
439 ;;; Values are the return value locations (wired to the standard passing
442 ;;; Save is the save info, which we can ignore since saving has been done.
443 ;;; Return-PC is the TN that the return PC should be passed in.
444 ;;; Target is a continuation pointing to the start of the called function.
445 ;;; Nvals is the number of values received.
447 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
448 ;;; registers may be tied up by the more operand. Instead, we use
449 ;;; MAYBE-LOAD-STACK-TN.
451 (define-vop (call-local)
455 (:results (values :more t))
457 (:move-args :local-call)
458 (:info arg-locs callee target nvals)
460 (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
461 (:temporary (:scs (non-descriptor-reg)) temp)
462 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
463 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
464 (:ignore arg-locs args ocfp)
466 (let ((label (gen-label))
467 (cur-nfp (current-nfp-tn vop)))
469 (store-stack-tn nfp-save cur-nfp))
470 (let ((callee-nfp (callee-nfp-tn callee)))
472 (maybe-load-stack-tn callee-nfp nfp)))
473 (maybe-load-stack-tn cfp-tn cfp)
474 (trace-table-entry trace-table-call-site)
475 (inst compute-lra-from-code code-tn label temp
476 (callee-return-pc-tn callee))
477 (note-this-location vop :call-site)
478 (inst b target :nullify t)
479 (trace-table-entry trace-table-normal)
480 (emit-return-pc label)
481 (default-unknown-values vop values nvals move-temp temp label)
483 (load-stack-tn cur-nfp nfp-save)))))
485 ;;; Non-TR local call for a variable number of return values passed according
486 ;;; to the unknown values convention. The results are the start of the values
487 ;;; glob and the number of values received.
489 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
490 ;;; registers may be tied up by the more operand. Instead, we use
491 ;;; MAYBE-LOAD-STACK-TN.
493 (define-vop (multiple-call-local unknown-values-receiver)
498 (:move-args :local-call)
499 (:info save callee target)
502 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
503 (:temporary (:scs (non-descriptor-reg)) temp)
505 (let ((label (gen-label))
506 (cur-nfp (current-nfp-tn vop)))
508 (store-stack-tn nfp-save cur-nfp))
509 (let ((callee-nfp (callee-nfp-tn callee)))
511 (maybe-load-stack-tn callee-nfp nfp)))
512 (maybe-load-stack-tn cfp-tn cfp)
513 (trace-table-entry trace-table-call-site)
514 (inst compute-lra-from-code code-tn label temp
515 (callee-return-pc-tn callee))
516 (note-this-location vop :call-site)
517 (inst b target :nullify t)
518 (trace-table-entry trace-table-normal)
519 (emit-return-pc label)
520 (note-this-location vop :unknown-return)
521 (receive-unknown-values values-start nvals start count label temp)
523 (load-stack-tn cur-nfp nfp-save)))))
526 ;;;; Local call with known values return:
528 ;;; Non-TR local call with known return locations. Known-value return works
529 ;;; just like argument passing in local call.
531 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
532 ;;; registers may be tied up by the more operand. Instead, we use
533 ;;; MAYBE-LOAD-STACK-TN.
535 (define-vop (known-call-local)
539 (:results (res :more t))
540 (:move-args :local-call)
542 (:info save callee target)
543 (:ignore args res save)
545 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
546 (:temporary (:scs (non-descriptor-reg)) temp)
548 (let ((label (gen-label))
549 (cur-nfp (current-nfp-tn vop)))
551 (store-stack-tn nfp-save cur-nfp))
552 (let ((callee-nfp (callee-nfp-tn callee)))
554 (maybe-load-stack-tn callee-nfp nfp)))
555 (maybe-load-stack-tn cfp-tn cfp)
556 (trace-table-entry trace-table-call-site)
557 (inst compute-lra-from-code code-tn label temp
558 (callee-return-pc-tn callee))
559 (note-this-location vop :call-site)
560 (inst b target :nullify t)
561 (trace-table-entry trace-table-normal)
562 (emit-return-pc label)
563 (note-this-location vop :known-return)
565 (load-stack-tn cur-nfp nfp-save)))))
567 ;;; Return from known values call. We receive the return locations as
568 ;;; arguments to terminate their lifetimes in the returning function. We
569 ;;; restore FP and CSP and jump to the Return-PC.
571 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
572 ;;; registers may be tied up by the more operand. Instead, we use
573 ;;; MAYBE-LOAD-STACK-TN.
575 (define-vop (known-return)
576 (:args (ocfp :target ocfp-temp)
577 (return-pc :target return-pc-temp)
579 (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
580 (:temporary (:sc descriptor-reg :from (:argument 1)) return-pc-temp)
581 (:temporary (:scs (interior-reg)) lip)
582 (:move-args :known-return)
584 (:ignore val-locs vals)
587 (trace-table-entry trace-table-fun-epilogue)
588 (maybe-load-stack-tn ocfp-temp ocfp)
589 (maybe-load-stack-tn return-pc-temp return-pc)
591 (let ((cur-nfp (current-nfp-tn vop)))
593 (move cur-nfp nsp-tn)))
594 (inst addi (- n-word-bytes other-pointer-lowtag) return-pc-temp lip)
596 (move ocfp-temp cfp-tn t)
597 (trace-table-entry trace-table-normal)))
602 ;;; There is something of a cross-product effect with full calls. Different
603 ;;; versions are used depending on whether we know the number of arguments or
604 ;;; the name of the called function, and whether we want fixed values, unknown
605 ;;; values, or a tail call.
607 ;;; In full call, the arguments are passed creating a partial frame on the
608 ;;; stack top and storing stack arguments into that frame. On entry to the
609 ;;; callee, this partial frame is pointed to by FP. If there are no stack
610 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
611 ;;; to SP just before the call.
613 ;;; This macro helps in the definition of full call VOPs by avoiding code
614 ;;; replication in defining the cross-product VOPs.
616 ;;; Name is the name of the VOP to define.
618 ;;; Named is true if the first argument is a symbol whose global function
619 ;;; definition is to be called.
621 ;;; Return is either :Fixed, :Unknown or :Tail:
622 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
623 ;;; the standard passing locations (passed as result operands).
624 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
625 ;;; result values are specified by the Start and Count as in the
626 ;;; unknown-values continuation representation.
627 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
628 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
630 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
631 ;;; fixed argument. If Variable is false, then the passing locations are
632 ;;; passed as a more arg. Variable is true if there are a variable number of
633 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
634 ;;; return. TR variable argument call is implemented separately.
636 ;;; In tail call with fixed arguments, the passing locations are passed as a
637 ;;; more arg, but there is no new-FP, since the arguments have been set up in
638 ;;; the current frame.
641 (macrolet ((define-full-call (name named return variable)
642 (aver (not (and variable (eq return :tail))))
644 ,@(when (eq return :unknown)
645 '(unknown-values-receiver)))
647 ,@(unless (eq return :tail)
648 '((new-fp :scs (any-reg) :to :eval)))
651 '(name :target name-pass)
652 '(arg-fun :target lexenv))
654 ,@(when (eq return :tail)
655 '((ocfp :target ocfp-pass)
656 (return-pc :target return-pc-pass)))
658 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
660 ,@(when (eq return :fixed)
661 '((:results (values :more t))))
663 (:save-p ,(if (eq return :tail) :compute-only t))
665 ,@(unless (or (eq return :tail) variable)
666 '((:move-args :full-call)))
669 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
670 ,@(unless variable '(nargs))
671 ,@(when (eq return :fixed) '(nvals))
675 ,@(unless (or variable (eq return :tail)) '(arg-locs))
676 ,@(unless variable '(args)))
678 (:temporary (:sc descriptor-reg
681 ,@(unless (eq return :fixed)
685 (:temporary (:sc descriptor-reg
687 :from (:argument ,(if (eq return :tail) 2 1))
692 `((:temporary (:sc descriptor-reg :offset fdefn-offset
693 :from (:argument ,(if (eq return :tail) 0 1))
697 `((:temporary (:sc descriptor-reg :offset lexenv-offset
698 :from (:argument ,(if (eq return :tail) 0 1))
701 (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
704 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
708 (mapcar (lambda (name offset)
709 `(:temporary (:sc descriptor-reg
713 register-arg-names *register-arg-offsets*))
714 ,@(when (eq return :fixed)
715 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
717 (:temporary (:scs (descriptor-reg) :to :eval) stepping)
719 ,@(unless (eq return :tail)
720 '((:temporary (:scs (non-descriptor-reg)) temp)
721 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
723 (:temporary (:sc interior-reg :offset lip-offset) entry-point)
725 (:generator ,(+ (if named 5 0)
727 (if (eq return :tail) 0 10)
729 (if (eq return :unknown) 25 0))
730 (let* ((cur-nfp (current-nfp-tn vop))
731 ,@(unless (eq return :tail)
732 '((lra-label (gen-label))))
733 (step-done-label (gen-label))
737 ,@(if (eq return :tail)
738 '((unless (location= ocfp ocfp-pass)
740 (unless (location= return-pc
750 (flet ((do-next-filler ()
751 (let* ((next (pop filler))
752 (what (if (consp next) (car next) next)))
756 `((inst sub csp-tn new-fp nargs-pass)
758 (mapcar (lambda (name)
759 `(inst ldw ,(ash (incf index)
763 register-arg-names)))
764 '((inst li (fixnumize nargs) nargs-pass))))
765 ,@(if (eq return :tail)
769 (move ocfp ocfp-pass t))
771 (inst ldw (ash (tn-offset ocfp)
777 (move return-pc return-pc-pass t))
779 (inst ldw (ash (tn-offset return-pc)
781 cfp-tn return-pc-pass))))
783 (inst addi (- (bytes-needed-for-non-descriptor-stack-frame))
786 (inst compute-lra-from-code code-tn lra-label
787 temp return-pc-pass))
789 (store-stack-tn nfp-save cur-nfp))
791 (move cfp-tn ocfp-pass t))
794 '(move new-fp cfp-tn)
795 '(if (> nargs register-arg-count)
797 (move csp-tn cfp-tn)))
798 (trace-table-entry trace-table-call-site))))
801 (insert-step-instrumenting (callable-tn)
802 ;; Conditionally insert a conditional trap:
803 (when step-instrumenting
804 (load-symbol-value stepping sb!impl::*stepping*)
805 ;; If it's not NIL, trap.
806 ;(inst comb := stepping null-tn step-done-label)
807 (inst comb := null-tn null-tn step-done-label :nullify t)
808 ;; CONTEXT-PC will be pointing here when the
809 ;; interrupt is handled, not after the BREAK.
810 (note-this-location vop :step-before-vop)
811 ;; Construct a trap code with the low bits from
812 ;; SINGLE-STEP-AROUND-TRAP and the high bits from
813 ;; the register number of CALLABLE-TN.
814 (inst break 0 (logior single-step-around-trap
815 (ash (reg-tn-encoding callable-tn)
817 (emit-label step-done-label))))
820 (descriptor-reg (move name name-pass))
822 (inst ldw (ash (tn-offset name) word-shift)
826 (inst ldw (- (ash (tn-offset name) word-shift)
827 other-pointer-lowtag)
830 ;; The step instrumenting must be done after
831 ;; FUNCTION is loaded, but before ENTRY-POINT is
833 (insert-step-instrumenting name-pass)
834 (inst ldw (- (ash fdefn-raw-addr-slot word-shift)
835 other-pointer-lowtag)
836 name-pass entry-point)
840 (move arg-fun lexenv))
842 (inst ldw (ash (tn-offset arg-fun) word-shift)
847 (- (ash (tn-offset arg-fun) word-shift)
848 other-pointer-lowtag) code-tn lexenv)
850 (inst ldw (- (ash closure-fun-slot word-shift)
854 ;; The step instrumenting must be done before
855 ;; after FUNCTION is loaded, but before ENTRY-POINT
857 (insert-step-instrumenting function)
858 (inst addi (- (ash simple-fun-code-offset word-shift)
860 function entry-point)))
867 (note-this-location vop :call-site)
868 (inst bv entry-point :nullify t))
872 '((trace-table-entry trace-table-normal)
873 (emit-return-pc lra-label)
874 (default-unknown-values vop values nvals
875 move-temp temp lra-label)
877 (load-stack-tn cur-nfp nfp-save))))
879 '((trace-table-entry trace-table-normal)
880 (emit-return-pc lra-label)
881 (note-this-location vop :unknown-return)
882 (receive-unknown-values values-start nvals start count
885 (load-stack-tn cur-nfp nfp-save))))
888 (define-full-call call nil :fixed nil)
889 (define-full-call call-named t :fixed nil)
890 (define-full-call multiple-call nil :unknown nil)
891 (define-full-call multiple-call-named t :unknown nil)
892 (define-full-call tail-call nil :tail nil)
893 (define-full-call tail-call-named t :tail nil)
895 (define-full-call call-variable nil :fixed t)
896 (define-full-call multiple-call-variable nil :unknown t))
899 ;;; Defined separately, since needs special code that blits the arguments
902 (define-vop (tail-call-variable)
903 (:args (args-arg :scs (any-reg) :target args)
904 (function-arg :scs (descriptor-reg) :target lexenv)
905 (ocfp-arg :scs (any-reg) :target ocfp)
906 (lra-arg :scs (descriptor-reg) :target lra))
908 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
909 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
910 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
911 (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
912 (:temporary (:scs (any-reg) :from (:argument 3)) tmp)
915 ;; Move these into the passing locations if they are not already there.
917 (move function-arg lexenv)
920 ;; And jump to the assembly-routine that does the bliting.
921 (let ((fixup (make-fixup 'tail-call-variable :assembly-routine)))
922 (inst ldil fixup tmp)
923 (inst be fixup lisp-heap-space tmp))
924 ;; Pull the number stack if anything is there.
925 (let ((cur-nfp (current-nfp-tn vop)))
927 ;;; NSP is restored by setting it to NSP,
928 ;;; because stack grows towards higher addresses.
929 (move cur-nfp nsp-tn)
933 ;;;; Unknown values return:
935 ;;; Return a single value using the unknown-values convention.
937 ;;; NSP is restored by setting it to NSP, because stack grows
938 ;;; towards higher addresses.
939 (define-vop (return-single)
940 (:args (ocfp :scs (any-reg))
941 (return-pc :scs (descriptor-reg))
946 ;; Clear the number stack.
947 (trace-table-entry trace-table-fun-epilogue)
948 (let ((cur-nfp (current-nfp-tn vop)))
950 (move cur-nfp nsp-tn)))
951 ;; Clear the control stack, and restore the frame pointer.
955 (lisp-return return-pc :offset 2)
956 (trace-table-entry trace-table-normal)))
958 ;;; Do unknown-values return of a fixed number of values. The Values are
959 ;;; required to be set up in the standard passing locations. Nvals is the
960 ;;; number of values returned.
962 ;;; If returning a single value, then deallocate the current frame, restore
963 ;;; FP and jump to the single-value entry at Return-PC + 8.
965 ;;; If returning other than one value, then load the number of values returned,
966 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
967 ;;; When there are stack values, we must initialize the argument pointer to
968 ;;; point to the beginning of the values block (which is the beginning of the
972 (:args (ocfp :scs (any-reg))
973 (return-pc :scs (descriptor-reg) :to (:eval 1))
977 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
978 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
979 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
980 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
981 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
982 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
983 (:temporary (:sc any-reg :offset nargs-offset) nargs)
984 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
988 ;; Clear the number stack.
989 (trace-table-entry trace-table-fun-epilogue)
990 (let ((cur-nfp (current-nfp-tn vop)))
992 (move cur-nfp nsp-tn)))
994 ((= nvals 1) ;; Clear the control stack, and restore the frame pointer
998 (lisp-return return-pc :offset 2))
1000 ;; Establish the values pointer and values count.
1001 (move cfp-tn val-ptr)
1002 (inst li (fixnumize nvals) nargs)
1003 ;; restore the frame pointer and clear as much of the control
1004 ;; stack as possible.
1006 (inst addi (* nvals n-word-bytes) val-ptr csp-tn)
1007 (aver (= (* nvals n-word-bytes) (fixnumize nvals)))
1008 ;; pre-default any argument register that need it.
1009 (when (< nvals register-arg-count)
1010 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
1011 (move null-tn reg)))
1013 (lisp-return return-pc)))
1014 (trace-table-entry trace-table-normal)))
1016 ;;; Do unknown-values return of an arbitrary number of values (passed on the
1017 ;;; stack.) We check for the common case of a single return value, and do that
1018 ;;; inline using the normal single value return convention. Otherwise, we
1019 ;;; branch off to code that calls an assembly-routine.
1021 (define-vop (return-multiple)
1022 (:args (ocfp-arg :scs (any-reg) :target ocfp)
1023 (lra-arg :scs (descriptor-reg) :target lra)
1024 (vals-arg :scs (any-reg) :target vals)
1025 (nvals-arg :scs (any-reg) :target nvals))
1027 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
1028 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
1029 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
1030 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
1031 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
1032 (:temporary (:scs (any-reg) :from (:eval 0)) tmp)
1035 (trace-table-entry trace-table-fun-epilogue)
1036 (let ((not-single (gen-label)))
1037 ;; Clear the number stack.
1038 (let ((cur-nfp (current-nfp-tn vop)))
1040 (move cur-nfp nsp-tn)))
1041 ;; Check for the single case.
1042 (inst comib :<> (fixnumize 1) nvals-arg not-single)
1044 ;; Return with one value.
1045 (move cfp-tn csp-tn)
1046 (move ocfp-arg cfp-tn)
1047 (lisp-return lra-arg :offset 2)
1048 ;; Nope, not the single case.
1049 (emit-label not-single)
1050 ;; most of these moves will not be emitted and therefor
1051 ;; isn't suitable to put in the delay slot below. But if
1052 ;; you do, dont forget to force-emit as in (move src dst t)
1053 (move ocfp-arg ocfp)
1055 (move vals-arg vals)
1056 (move nvals-arg nvals)
1057 (let ((fixup (make-fixup 'return-multiple :assembly-routine)))
1058 (inst ldil fixup tmp)
1059 (inst be fixup lisp-heap-space tmp :nullify t)))
1060 (trace-table-entry trace-table-normal)))
1065 ;;; We don't need to do anything special for regular functions.
1067 (define-vop (setup-environment)
1071 ;; Don't bother doing anything.
1074 ;;; Get the lexical environment from its passing location.
1076 (define-vop (setup-closure-environment)
1077 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1080 (:results (closure :scs (descriptor-reg)))
1085 (move lexenv closure)))
1087 ;;; Copy a more arg from the argument area to the end of the current frame.
1088 ;;; Fixed is the number of non-more arguments.
1089 ;;; FIXME-lav: old hppa code look smarter.
1090 (define-vop (copy-more-arg)
1091 (:temporary (:sc any-reg :offset nl0-offset) result)
1092 (:temporary (:sc any-reg :offset nl1-offset) count)
1093 (:temporary (:sc any-reg :offset nl2-offset) src)
1094 (:temporary (:sc any-reg :offset nl3-offset) dst)
1095 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1098 (let ((loop (gen-label))
1099 (do-regs (gen-label))
1101 (when (< fixed register-arg-count)
1102 ;; Save a pointer to the results so we can fill in register args.
1103 ;; We don't need this if there are more fixed args than reg args.
1104 (move csp-tn result))
1105 ;; Allocate the space on the stack.
1106 (cond ((zerop fixed)
1107 (inst comb := nargs-tn zero-tn done)
1108 (inst add nargs-tn csp-tn csp-tn))
1110 (inst addi (fixnumize (- fixed)) nargs-tn count)
1111 (inst comb :<= count zero-tn done :nullify t)
1112 (inst add count csp-tn csp-tn)))
1113 (when (< fixed register-arg-count)
1114 ;; We must stop when we run out of stack args, not when we run out of
1116 (inst addi (fixnumize (- register-arg-count)) nargs-tn count))
1117 ;; Everything of interest in registers.
1118 (inst comb :<= count zero-tn do-regs)
1119 ;; Initialize dst to be end of stack.
1121 ;; Initialize src to be end of args.
1122 (inst add nargs-tn cfp-tn src)
1125 ;; decrease src, then load src into temp
1126 (inst ldwm (- n-word-bytes) src temp)
1127 ;; increase, compare if count >= to zero, if true, jump
1128 (inst addib :>= (fixnumize -1) count loop)
1129 ;; decrease dst, then store temp at dst
1130 (inst stwm temp (- n-word-bytes) dst)
1132 (emit-label do-regs)
1133 (when (< fixed register-arg-count)
1134 ;; Now we have to deposit any more args that showed up in registers.
1135 ;; We know there is at least one more arg, otherwise we would have
1136 ;; branched to done up at the top.
1137 (inst addi (- (fixnumize (1+ fixed))) nargs-tn count)
1138 (do ((i fixed (1+ i)))
1139 ((>= i register-arg-count))
1140 ;; Is this the last one?
1141 (inst comb := count zero-tn done)
1142 ;; Store it relative to the pointer saved at the start.
1143 (storew (nth i *register-arg-tns*) result (- i fixed))
1145 (inst addi (- (fixnumize 1)) count count)))
1146 (emit-label done))))
1148 ;;; More args are stored consequtively on the stack, starting immediately at
1149 ;;; the context pointer. The context pointer is not typed, so the lowtag is 0.
1151 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1153 ;;; Turn more arg (context, count) into a list.
1154 (define-vop (listify-rest-args)
1155 (:translate %listify-rest-args)
1156 (:args (context-arg :target context :scs (descriptor-reg))
1157 (count-arg :target count :scs (any-reg)))
1158 (:arg-types * tagged-num)
1159 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1160 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1161 (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1162 (:results (result :scs (descriptor-reg)))
1166 (let* ((enter (gen-label))
1169 (dx-p (node-stack-allocate-p node))
1170 (alloc-area-tn (if dx-p csp-tn alloc-tn)))
1171 (move context-arg context)
1172 (move count-arg count)
1173 ;; Check to see if there are any arguments.
1174 (inst comb := count zero-tn done)
1175 (move null-tn result t)
1177 ;; We need to do this atomically.
1181 ;; Allocate a cons (2 words) for each item.
1182 (set-lowtag list-pointer-lowtag alloc-area-tn result)
1184 (inst sll count 1 temp)
1186 (inst add temp alloc-area-tn alloc-area-tn)
1188 ;; Store the current cons in the cdr of the previous cons.
1190 (inst addi (* 2 n-word-bytes) dst dst)
1191 (storew dst dst -1 list-pointer-lowtag)
1195 (inst ldwm n-word-bytes context temp)
1196 ;; Dec count, and if != zero, go back for more.
1197 (inst addib :<> (fixnumize -1) count loop)
1198 ;; Store the value in the car (in delay slot)
1199 (storew temp dst 0 list-pointer-lowtag)
1201 ;; NIL out the last cons.
1202 (storew null-tn dst 1 list-pointer-lowtag))
1203 (emit-label done))))
1205 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1206 ;;; Supplied is the total number of arguments supplied (originally passed in
1207 ;;; NARGS.) Fixed is the number of non-rest arguments.
1209 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1210 ;;; time the environment is in a pretty brain-damaged state, preventing this
1211 ;;; info from being returned as values. What we do is compute
1212 ;;; supplied - fixed, and return a pointer that many words below the current
1215 (define-vop (more-arg-context)
1216 (:policy :fast-safe)
1217 (:translate sb!c::%more-arg-context)
1218 (:args (supplied :scs (any-reg)))
1219 (:arg-types tagged-num (:constant fixnum))
1221 (:results (context :scs (descriptor-reg))
1222 (count :scs (any-reg)))
1223 (:result-types t tagged-num)
1224 (:note "more-arg-context")
1226 (inst addi (fixnumize (- fixed)) supplied count)
1227 (inst sub csp-tn count context)))
1229 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1231 (define-vop (verify-arg-count)
1232 (:policy :fast-safe)
1233 (:translate sb!c::%verify-arg-count)
1234 (:args (nargs :scs (any-reg)))
1235 (:arg-types positive-fixnum (:constant t))
1238 (:save-p :compute-only)
1241 (generate-error-code vop invalid-arg-count-error nargs)))
1242 (cond ((zerop count)
1243 (inst bc :<> nil nargs zero-tn err-lab))
1245 (inst bci :<> nil (fixnumize count) nargs err-lab))))))
1247 ;;; Signal argument errors.
1249 (macrolet ((frob (name error translate &rest args)
1250 `(define-vop (,name)
1252 `((:policy :fast-safe)
1253 (:translate ,translate)))
1254 (:args ,@(mapcar #'(lambda (arg)
1255 `(,arg :scs (any-reg descriptor-reg)))
1258 (:save-p :compute-only)
1260 (error-call vop ,error ,@args)))))
1261 (frob arg-count-error invalid-arg-count-error
1262 sb!c::%arg-count-error nargs)
1263 (frob type-check-error object-not-type-error sb!c::%type-check-error
1265 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1267 (frob odd-key-args-error odd-key-args-error
1268 sb!c::%odd-key-args-error)
1269 (frob unknown-key-arg-error unknown-key-arg-error
1270 sb!c::%unknown-key-arg-error key)
1271 (frob nil-fun-returned-error nil-fun-returned-error nil fun))
1275 (define-vop (step-instrument-before-vop)
1276 (:temporary (:scs (descriptor-reg)) stepping)
1277 (:policy :fast-safe)
1280 (load-symbol-value stepping sb!impl::*stepping*)
1281 ;; If it's not NIL, trap.
1282 (inst comb := stepping null-tn DONE :nullify t)
1283 ;; CONTEXT-PC will be pointing here when the interrupt is handled,
1284 ;; not after the BREAK.
1285 (note-this-location vop :step-before-vop)
1286 ;; CALLEE-REGISTER-OFFSET isn't needed for before-traps, so we
1287 ;; can just use a bare SINGLE-STEP-BEFORE-TRAP as the code.
1288 (inst break 0 single-step-before-trap)