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))
422 ;;;; Local call with unknown values convention return:
424 ;;; Non-TR local call for a fixed number of values passed according to the
425 ;;; unknown values convention.
427 ;;; Args are the argument passing locations, which are specified only to
428 ;;; terminate their lifetimes in the caller.
430 ;;; Values are the return value locations (wired to the standard passing
433 ;;; Save is the save info, which we can ignore since saving has been done.
434 ;;; Return-PC is the TN that the return PC should be passed in.
435 ;;; Target is a continuation pointing to the start of the called function.
436 ;;; Nvals is the number of values received.
438 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
439 ;;; registers may be tied up by the more operand. Instead, we use
440 ;;; MAYBE-LOAD-STACK-TN.
442 (define-vop (call-local)
446 (:results (values :more t))
448 (:move-args :local-call)
449 (:info arg-locs callee target nvals)
451 (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
452 (:temporary (:scs (non-descriptor-reg)) temp)
453 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
454 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
455 (:ignore arg-locs args ocfp)
457 (let ((label (gen-label))
458 (cur-nfp (current-nfp-tn vop)))
460 (store-stack-tn nfp-save cur-nfp))
461 (let ((callee-nfp (callee-nfp-tn callee)))
463 (maybe-load-stack-tn callee-nfp nfp)))
464 (maybe-load-stack-tn cfp-tn cfp)
465 (trace-table-entry trace-table-call-site)
466 (inst compute-lra-from-code code-tn label temp
467 (callee-return-pc-tn callee))
468 (note-this-location vop :call-site)
469 (inst b target :nullify t)
470 (trace-table-entry trace-table-normal)
471 (emit-return-pc label)
472 (default-unknown-values vop values nvals move-temp temp label)
474 (load-stack-tn cur-nfp nfp-save)))))
476 ;;; Non-TR local call for a variable number of return values passed according
477 ;;; to the unknown values convention. The results are the start of the values
478 ;;; glob and the number of values received.
480 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
481 ;;; registers may be tied up by the more operand. Instead, we use
482 ;;; MAYBE-LOAD-STACK-TN.
484 (define-vop (multiple-call-local unknown-values-receiver)
489 (:move-args :local-call)
490 (:info save callee target)
493 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
494 (:temporary (:scs (non-descriptor-reg)) temp)
496 (let ((label (gen-label))
497 (cur-nfp (current-nfp-tn vop)))
499 (store-stack-tn nfp-save cur-nfp))
500 (let ((callee-nfp (callee-nfp-tn callee)))
502 (maybe-load-stack-tn callee-nfp nfp)))
503 (maybe-load-stack-tn cfp-tn cfp)
504 (trace-table-entry trace-table-call-site)
505 (inst compute-lra-from-code code-tn label temp
506 (callee-return-pc-tn callee))
507 (note-this-location vop :call-site)
508 (inst b target :nullify t)
509 (trace-table-entry trace-table-normal)
510 (emit-return-pc label)
511 (note-this-location vop :unknown-return)
512 (receive-unknown-values values-start nvals start count label temp)
514 (load-stack-tn cur-nfp nfp-save)))))
517 ;;;; Local call with known values return:
519 ;;; Non-TR local call with known return locations. Known-value return works
520 ;;; just like argument passing in local call.
522 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
523 ;;; registers may be tied up by the more operand. Instead, we use
524 ;;; MAYBE-LOAD-STACK-TN.
526 (define-vop (known-call-local)
530 (:results (res :more t))
531 (:move-args :local-call)
533 (:info save callee target)
534 (:ignore args res save)
536 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
537 (:temporary (:scs (non-descriptor-reg)) temp)
539 (let ((label (gen-label))
540 (cur-nfp (current-nfp-tn vop)))
542 (store-stack-tn nfp-save cur-nfp))
543 (let ((callee-nfp (callee-nfp-tn callee)))
545 (maybe-load-stack-tn callee-nfp nfp)))
546 (maybe-load-stack-tn cfp-tn cfp)
547 (trace-table-entry trace-table-call-site)
548 (inst compute-lra-from-code code-tn label temp
549 (callee-return-pc-tn callee))
550 (note-this-location vop :call-site)
551 (inst b target :nullify t)
552 (trace-table-entry trace-table-normal)
553 (emit-return-pc label)
554 (note-this-location vop :known-return)
556 (load-stack-tn cur-nfp nfp-save)))))
558 ;;; Return from known values call. We receive the return locations as
559 ;;; arguments to terminate their lifetimes in the returning function. We
560 ;;; restore FP and CSP and jump to the Return-PC.
562 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
563 ;;; registers may be tied up by the more operand. Instead, we use
564 ;;; MAYBE-LOAD-STACK-TN.
566 (define-vop (known-return)
567 (:args (ocfp :target ocfp-temp)
568 (return-pc :target return-pc-temp)
570 (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
571 (:temporary (:sc descriptor-reg :from (:argument 1)) return-pc-temp)
572 (:temporary (:scs (interior-reg)) lip)
573 (:move-args :known-return)
575 (:ignore val-locs vals)
578 (trace-table-entry trace-table-fun-epilogue)
579 (maybe-load-stack-tn ocfp-temp ocfp)
580 (maybe-load-stack-tn return-pc-temp return-pc)
582 (let ((cur-nfp (current-nfp-tn vop)))
584 (move cur-nfp nsp-tn)))
585 (inst addi (- n-word-bytes other-pointer-lowtag) return-pc-temp lip)
587 (move ocfp-temp cfp-tn t)
588 (trace-table-entry trace-table-normal)))
593 ;;; There is something of a cross-product effect with full calls. Different
594 ;;; versions are used depending on whether we know the number of arguments or
595 ;;; the name of the called function, and whether we want fixed values, unknown
596 ;;; values, or a tail call.
598 ;;; In full call, the arguments are passed creating a partial frame on the
599 ;;; stack top and storing stack arguments into that frame. On entry to the
600 ;;; callee, this partial frame is pointed to by FP. If there are no stack
601 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
602 ;;; to SP just before the call.
604 ;;; This macro helps in the definition of full call VOPs by avoiding code
605 ;;; replication in defining the cross-product VOPs.
607 ;;; Name is the name of the VOP to define.
609 ;;; Named is true if the first argument is a symbol whose global function
610 ;;; definition is to be called.
612 ;;; Return is either :Fixed, :Unknown or :Tail:
613 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
614 ;;; the standard passing locations (passed as result operands).
615 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
616 ;;; result values are specified by the Start and Count as in the
617 ;;; unknown-values continuation representation.
618 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
619 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
621 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
622 ;;; fixed argument. If Variable is false, then the passing locations are
623 ;;; passed as a more arg. Variable is true if there are a variable number of
624 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
625 ;;; return. TR variable argument call is implemented separately.
627 ;;; In tail call with fixed arguments, the passing locations are passed as a
628 ;;; more arg, but there is no new-FP, since the arguments have been set up in
629 ;;; the current frame.
632 (macrolet ((define-full-call (name named return variable)
633 (aver (not (and variable (eq return :tail))))
635 ,@(when (eq return :unknown)
636 '(unknown-values-receiver)))
638 ,@(unless (eq return :tail)
639 '((new-fp :scs (any-reg) :to :eval)))
642 '(name :target name-pass)
643 '(arg-fun :target lexenv))
645 ,@(when (eq return :tail)
646 '((ocfp :target ocfp-pass)
647 (return-pc :target return-pc-pass)))
649 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
651 ,@(when (eq return :fixed)
652 '((:results (values :more t))))
654 (:save-p ,(if (eq return :tail) :compute-only t))
656 ,@(unless (or (eq return :tail) variable)
657 '((:move-args :full-call)))
660 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
661 ,@(unless variable '(nargs))
662 ,@(when (eq return :fixed) '(nvals))
666 ,@(unless (or variable (eq return :tail)) '(arg-locs))
667 ,@(unless variable '(args)))
669 (:temporary (:sc descriptor-reg
672 ,@(unless (eq return :fixed)
676 (:temporary (:sc descriptor-reg
678 :from (:argument ,(if (eq return :tail) 2 1))
683 `((:temporary (:sc descriptor-reg :offset fdefn-offset
684 :from (:argument ,(if (eq return :tail) 0 1))
688 `((:temporary (:sc descriptor-reg :offset lexenv-offset
689 :from (:argument ,(if (eq return :tail) 0 1))
692 (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
695 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
699 (mapcar (lambda (name offset)
700 `(:temporary (:sc descriptor-reg
704 register-arg-names *register-arg-offsets*))
705 ,@(when (eq return :fixed)
706 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
708 (:temporary (:scs (descriptor-reg) :to :eval) stepping)
710 ,@(unless (eq return :tail)
711 '((:temporary (:scs (non-descriptor-reg)) temp)
712 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
714 (:temporary (:sc interior-reg :offset lip-offset) entry-point)
716 (:generator ,(+ (if named 5 0)
718 (if (eq return :tail) 0 10)
720 (if (eq return :unknown) 25 0))
721 (let* ((cur-nfp (current-nfp-tn vop))
722 ,@(unless (eq return :tail)
723 '((lra-label (gen-label))))
724 (step-done-label (gen-label))
728 ,@(if (eq return :tail)
729 '((unless (location= ocfp ocfp-pass)
731 (unless (location= return-pc
741 (flet ((do-next-filler ()
742 (let* ((next (pop filler))
743 (what (if (consp next) (car next) next)))
747 `((inst sub csp-tn new-fp nargs-pass)
749 (mapcar (lambda (name)
750 `(inst ldw ,(ash (incf index)
754 register-arg-names)))
755 '((inst li (fixnumize nargs) nargs-pass))))
756 ,@(if (eq return :tail)
760 (move ocfp ocfp-pass t))
762 (inst ldw (ash (tn-offset ocfp)
768 (move return-pc return-pc-pass t))
770 (inst ldw (ash (tn-offset return-pc)
772 cfp-tn return-pc-pass))))
774 (inst addi (- (bytes-needed-for-non-descriptor-stack-frame))
777 (inst compute-lra-from-code code-tn lra-label
778 temp return-pc-pass))
780 (store-stack-tn nfp-save cur-nfp))
782 (move cfp-tn ocfp-pass t))
785 '(move new-fp cfp-tn)
786 '(if (> nargs register-arg-count)
788 (move csp-tn cfp-tn)))
789 (trace-table-entry trace-table-call-site))))
792 (insert-step-instrumenting (callable-tn)
793 ;; Conditionally insert a conditional trap:
794 (when step-instrumenting
795 (load-symbol-value stepping sb!impl::*stepping*)
796 ;; If it's not NIL, trap.
797 ;(inst comb := stepping null-tn step-done-label)
798 (inst comb := null-tn null-tn step-done-label :nullify t)
799 ;; CONTEXT-PC will be pointing here when the
800 ;; interrupt is handled, not after the BREAK.
801 (note-this-location vop :step-before-vop)
802 ;; Construct a trap code with the low bits from
803 ;; SINGLE-STEP-AROUND-TRAP and the high bits from
804 ;; the register number of CALLABLE-TN.
805 (inst break 0 (logior single-step-around-trap
806 (ash (reg-tn-encoding callable-tn)
808 (emit-label step-done-label))))
811 (descriptor-reg (move name name-pass))
813 (inst ldw (ash (tn-offset name) word-shift)
817 (inst ldw (- (ash (tn-offset name) word-shift)
818 other-pointer-lowtag)
821 ;; The step instrumenting must be done after
822 ;; FUNCTION is loaded, but before ENTRY-POINT is
824 (insert-step-instrumenting name-pass)
825 (inst ldw (- (ash fdefn-raw-addr-slot word-shift)
826 other-pointer-lowtag)
827 name-pass entry-point)
831 (move arg-fun lexenv))
833 (inst ldw (ash (tn-offset arg-fun) word-shift)
838 (- (ash (tn-offset arg-fun) word-shift)
839 other-pointer-lowtag) code-tn lexenv)
841 (inst ldw (- (ash closure-fun-slot word-shift)
845 ;; The step instrumenting must be done before
846 ;; after FUNCTION is loaded, but before ENTRY-POINT
848 (insert-step-instrumenting function)
849 (inst addi (- (ash simple-fun-code-offset word-shift)
851 function entry-point)))
858 (note-this-location vop :call-site)
859 (inst bv entry-point :nullify t))
863 '((trace-table-entry trace-table-normal)
864 (emit-return-pc lra-label)
865 (default-unknown-values vop values nvals
866 move-temp temp lra-label)
868 (load-stack-tn cur-nfp nfp-save))))
870 '((trace-table-entry trace-table-normal)
871 (emit-return-pc lra-label)
872 (note-this-location vop :unknown-return)
873 (receive-unknown-values values-start nvals start count
876 (load-stack-tn cur-nfp nfp-save))))
879 (define-full-call call nil :fixed nil)
880 (define-full-call call-named t :fixed nil)
881 (define-full-call multiple-call nil :unknown nil)
882 (define-full-call multiple-call-named t :unknown nil)
883 (define-full-call tail-call nil :tail nil)
884 (define-full-call tail-call-named t :tail nil)
886 (define-full-call call-variable nil :fixed t)
887 (define-full-call multiple-call-variable nil :unknown t))
890 ;;; Defined separately, since needs special code that blits the arguments
893 (define-vop (tail-call-variable)
894 (:args (args-arg :scs (any-reg) :target args)
895 (function-arg :scs (descriptor-reg) :target lexenv)
896 (ocfp-arg :scs (any-reg) :target ocfp)
897 (lra-arg :scs (descriptor-reg) :target lra))
899 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
900 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
901 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
902 (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
903 (:temporary (:scs (any-reg) :from (:argument 3)) tmp)
906 ;; Move these into the passing locations if they are not already there.
908 (move function-arg lexenv)
911 ;; And jump to the assembly-routine that does the bliting.
912 (let ((fixup (make-fixup 'tail-call-variable :assembly-routine)))
913 (inst ldil fixup tmp)
914 (inst be fixup lisp-heap-space tmp))
915 ;; Pull the number stack if anything is there.
916 (let ((cur-nfp (current-nfp-tn vop)))
918 ;;; NSP is restored by setting it to NSP,
919 ;;; because stack grows towards higher addresses.
920 (move cur-nfp nsp-tn)
924 ;;;; Unknown values return:
926 ;;; Return a single value using the unknown-values convention.
928 ;;; NSP is restored by setting it to NSP, because stack grows
929 ;;; towards higher addresses.
930 (define-vop (return-single)
931 (:args (ocfp :scs (any-reg))
932 (return-pc :scs (descriptor-reg))
937 ;; Clear the number stack.
938 (trace-table-entry trace-table-fun-epilogue)
939 (let ((cur-nfp (current-nfp-tn vop)))
941 (move cur-nfp nsp-tn)))
942 ;; Clear the control stack, and restore the frame pointer.
946 (lisp-return return-pc :offset 2)
947 (trace-table-entry trace-table-normal)))
949 ;;; Do unknown-values return of a fixed number of values. The Values are
950 ;;; required to be set up in the standard passing locations. Nvals is the
951 ;;; number of values returned.
953 ;;; If returning a single value, then deallocate the current frame, restore
954 ;;; FP and jump to the single-value entry at Return-PC + 8.
956 ;;; If returning other than one value, then load the number of values returned,
957 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
958 ;;; When there are stack values, we must initialize the argument pointer to
959 ;;; point to the beginning of the values block (which is the beginning of the
963 (:args (ocfp :scs (any-reg))
964 (return-pc :scs (descriptor-reg) :to (:eval 1))
968 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
969 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
970 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
971 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
972 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
973 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
974 (:temporary (:sc any-reg :offset nargs-offset) nargs)
975 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
979 ;; Clear the number stack.
980 (trace-table-entry trace-table-fun-epilogue)
981 (let ((cur-nfp (current-nfp-tn vop)))
983 (move cur-nfp nsp-tn)))
985 ((= nvals 1) ;; Clear the control stack, and restore the frame pointer
989 (lisp-return return-pc :offset 2))
991 ;; Establish the values pointer and values count.
992 (move cfp-tn val-ptr)
993 (inst li (fixnumize nvals) nargs)
994 ;; restore the frame pointer and clear as much of the control
995 ;; stack as possible.
997 (inst addi (* nvals n-word-bytes) val-ptr csp-tn)
998 (aver (= (* nvals n-word-bytes) (fixnumize nvals)))
999 ;; pre-default any argument register that need it.
1000 (when (< nvals register-arg-count)
1001 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
1002 (move null-tn reg)))
1004 (lisp-return return-pc)))
1005 (trace-table-entry trace-table-normal)))
1007 ;;; Do unknown-values return of an arbitrary number of values (passed on the
1008 ;;; stack.) We check for the common case of a single return value, and do that
1009 ;;; inline using the normal single value return convention. Otherwise, we
1010 ;;; branch off to code that calls an assembly-routine.
1012 (define-vop (return-multiple)
1013 (:args (ocfp-arg :scs (any-reg) :target ocfp)
1014 (lra-arg :scs (descriptor-reg) :target lra)
1015 (vals-arg :scs (any-reg) :target vals)
1016 (nvals-arg :scs (any-reg) :target nvals))
1018 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
1019 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
1020 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
1021 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
1022 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
1023 (:temporary (:scs (any-reg) :from (:eval 0)) tmp)
1026 (trace-table-entry trace-table-fun-epilogue)
1027 (let ((not-single (gen-label)))
1028 ;; Clear the number stack.
1029 (let ((cur-nfp (current-nfp-tn vop)))
1031 (move cur-nfp nsp-tn)))
1032 ;; Check for the single case.
1033 (inst comib :<> (fixnumize 1) nvals-arg not-single)
1035 ;; Return with one value.
1036 (move cfp-tn csp-tn)
1037 (move ocfp-arg cfp-tn)
1038 (lisp-return lra-arg :offset 2)
1039 ;; Nope, not the single case.
1040 (emit-label not-single)
1041 ;; most of these moves will not be emitted and therefor
1042 ;; isn't suitable to put in the delay slot below. But if
1043 ;; you do, dont forget to force-emit as in (move src dst t)
1044 (move ocfp-arg ocfp)
1046 (move vals-arg vals)
1047 (move nvals-arg nvals)
1048 (let ((fixup (make-fixup 'return-multiple :assembly-routine)))
1049 (inst ldil fixup tmp)
1050 (inst be fixup lisp-heap-space tmp :nullify t)))
1051 (trace-table-entry trace-table-normal)))
1056 ;;; We don't need to do anything special for regular functions.
1058 (define-vop (setup-environment)
1062 ;; Don't bother doing anything.
1065 ;;; Get the lexical environment from its passing location.
1067 (define-vop (setup-closure-environment)
1068 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1071 (:results (closure :scs (descriptor-reg)))
1076 (move lexenv closure)))
1078 ;;; Copy a more arg from the argument area to the end of the current frame.
1079 ;;; Fixed is the number of non-more arguments.
1080 ;;; FIXME-lav: old hppa code look smarter.
1081 (define-vop (copy-more-arg)
1082 (:temporary (:sc any-reg :offset nl0-offset) result)
1083 (:temporary (:sc any-reg :offset nl1-offset) count)
1084 (:temporary (:sc any-reg :offset nl2-offset) src)
1085 (:temporary (:sc any-reg :offset nl3-offset) dst)
1086 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1089 (let ((loop (gen-label))
1090 (do-regs (gen-label))
1092 (when (< fixed register-arg-count)
1093 ;; Save a pointer to the results so we can fill in register args.
1094 ;; We don't need this if there are more fixed args than reg args.
1095 (move csp-tn result))
1096 ;; Allocate the space on the stack.
1097 (cond ((zerop fixed)
1098 (inst comb := nargs-tn zero-tn done)
1099 (inst add nargs-tn csp-tn csp-tn))
1101 (inst addi (fixnumize (- fixed)) nargs-tn count)
1102 (inst comb :<= count zero-tn done :nullify t)
1103 (inst add count csp-tn csp-tn)))
1104 (when (< fixed register-arg-count)
1105 ;; We must stop when we run out of stack args, not when we run out of
1107 (inst addi (fixnumize (- register-arg-count)) nargs-tn count))
1108 ;; Everything of interest in registers.
1109 (inst comb :<= count zero-tn do-regs)
1110 ;; Initialize dst to be end of stack.
1112 ;; Initialize src to be end of args.
1113 (inst add nargs-tn cfp-tn src)
1116 ;; decrease src, then load src into temp
1117 (inst ldwm (- n-word-bytes) src temp)
1118 ;; increase, compare if count >= to zero, if true, jump
1119 (inst addib :>= (fixnumize -1) count loop)
1120 ;; decrease dst, then store temp at dst
1121 (inst stwm temp (- n-word-bytes) dst)
1123 (emit-label do-regs)
1124 (when (< fixed register-arg-count)
1125 ;; Now we have to deposit any more args that showed up in registers.
1126 ;; We know there is at least one more arg, otherwise we would have
1127 ;; branched to done up at the top.
1128 (inst addi (- (fixnumize (1+ fixed))) nargs-tn count)
1129 (do ((i fixed (1+ i)))
1130 ((>= i register-arg-count))
1131 ;; Is this the last one?
1132 (inst comb := count zero-tn done)
1133 ;; Store it relative to the pointer saved at the start.
1134 (storew (nth i *register-arg-tns*) result (- i fixed))
1136 (inst addi (- (fixnumize 1)) count count)))
1137 (emit-label done))))
1139 ;;; More args are stored consequtively on the stack, starting immediately at
1140 ;;; the context pointer. The context pointer is not typed, so the lowtag is 0.
1142 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1144 ;;; Turn more arg (context, count) into a list.
1145 (define-vop (listify-rest-args)
1146 (:translate %listify-rest-args)
1147 (:args (context-arg :target context :scs (descriptor-reg))
1148 (count-arg :target count :scs (any-reg)))
1149 (:arg-types * tagged-num)
1150 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1151 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1152 (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1153 (:results (result :scs (descriptor-reg)))
1157 (let* ((enter (gen-label))
1160 (dx-p (node-stack-allocate-p node))
1161 (alloc-area-tn (if dx-p csp-tn alloc-tn)))
1162 (move context-arg context)
1163 (move count-arg count)
1164 ;; Check to see if there are any arguments.
1165 (inst comb := count zero-tn done)
1166 (move null-tn result t)
1168 ;; We need to do this atomically.
1172 ;; Allocate a cons (2 words) for each item.
1173 (set-lowtag list-pointer-lowtag alloc-area-tn result)
1175 (inst sll count 1 temp)
1177 (inst add temp alloc-area-tn alloc-area-tn)
1179 ;; Store the current cons in the cdr of the previous cons.
1181 (inst addi (* 2 n-word-bytes) dst dst)
1182 (storew dst dst -1 list-pointer-lowtag)
1186 (inst ldwm n-word-bytes context temp)
1187 ;; Dec count, and if != zero, go back for more.
1188 (inst addib :<> (fixnumize -1) count loop)
1189 ;; Store the value in the car (in delay slot)
1190 (storew temp dst 0 list-pointer-lowtag)
1192 ;; NIL out the last cons.
1193 (storew null-tn dst 1 list-pointer-lowtag))
1194 (emit-label done))))
1196 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1197 ;;; Supplied is the total number of arguments supplied (originally passed in
1198 ;;; NARGS.) Fixed is the number of non-rest arguments.
1200 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1201 ;;; time the environment is in a pretty brain-damaged state, preventing this
1202 ;;; info from being returned as values. What we do is compute
1203 ;;; supplied - fixed, and return a pointer that many words below the current
1206 (define-vop (more-arg-context)
1207 (:policy :fast-safe)
1208 (:translate sb!c::%more-arg-context)
1209 (:args (supplied :scs (any-reg)))
1210 (:arg-types tagged-num (:constant fixnum))
1212 (:results (context :scs (descriptor-reg))
1213 (count :scs (any-reg)))
1214 (:result-types t tagged-num)
1215 (:note "more-arg-context")
1217 (inst addi (fixnumize (- fixed)) supplied count)
1218 (inst sub csp-tn count context)))
1220 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1222 (define-vop (verify-arg-count)
1223 (:policy :fast-safe)
1224 (:translate sb!c::%verify-arg-count)
1225 (:args (nargs :scs (any-reg)))
1226 (:arg-types positive-fixnum (:constant t))
1229 (:save-p :compute-only)
1232 (generate-error-code vop invalid-arg-count-error nargs)))
1233 (cond ((zerop count)
1234 (inst bc :<> nil nargs zero-tn err-lab))
1236 (inst bci :<> nil (fixnumize count) nargs err-lab))))))
1238 ;;; Signal argument errors.
1240 (macrolet ((frob (name error translate &rest args)
1241 `(define-vop (,name)
1243 `((:policy :fast-safe)
1244 (:translate ,translate)))
1245 (:args ,@(mapcar #'(lambda (arg)
1246 `(,arg :scs (any-reg descriptor-reg)))
1249 (:save-p :compute-only)
1251 (error-call vop ,error ,@args)))))
1252 (frob arg-count-error invalid-arg-count-error
1253 sb!c::%arg-count-error nargs)
1254 (frob type-check-error object-not-type-error sb!c::%type-check-error
1256 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1258 (frob odd-key-args-error odd-key-args-error
1259 sb!c::%odd-key-args-error)
1260 (frob unknown-key-arg-error unknown-key-arg-error
1261 sb!c::%unknown-key-arg-error key)
1262 (frob nil-fun-returned-error nil-fun-returned-error nil fun))
1266 (define-vop (step-instrument-before-vop)
1267 (:temporary (:scs (descriptor-reg)) stepping)
1268 (:policy :fast-safe)
1271 (load-symbol-value stepping sb!impl::*stepping*)
1272 ;; If it's not NIL, trap.
1273 (inst comb := stepping null-tn DONE :nullify t)
1274 ;; CONTEXT-PC will be pointing here when the interrupt is handled,
1275 ;; not after the BREAK.
1276 (note-this-location vop :step-before-vop)
1277 ;; CALLEE-REGISTER-OFFSET isn't needed for before-traps, so we
1278 ;; can just use a bare SINGLE-STEP-BEFORE-TRAP as the code.
1279 (inst break 0 single-step-before-trap)