d9ccfeef4198bd533ee22eee91114af38b458c8e
[sbcl.git] / src / compiler / alpha / call.lisp
1 ;;;; the VM definition of function call for the Alpha
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
11
12 (in-package "SB!VM")
13 \f
14 ;;;; interfaces to IR2 conversion
15
16 ;;; Return a wired TN describing the N'th full call argument passing
17 ;;; location.
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*
22                      register-arg-scn
23                      (elt *register-arg-offsets* n))
24       (make-wired-tn *backend-t-primitive-type*
25                      control-stack-arg-scn n)))
26
27
28 ;;; Make a passing location TN for a local call return PC. If standard
29 ;;; is true, then use the standard (full call) location, otherwise use
30 ;;; any legal location. Even in the non-standard case, this may be
31 ;;; restricted by a desire to use a subroutine call instruction.
32 (!def-vm-support-routine make-return-pc-passing-location (standard)
33   (if 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)))
36
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
41 ;;; the arg pointer.
42 (!def-vm-support-routine make-old-fp-passing-location (standard)
43   (if standard
44       (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset)
45       (make-normal-tn *fixnum-primitive-type*)))
46
47 ;;; These functions make the TNs used to hold Old-FP and Return-PC
48 ;;; within the current function. We treat these specially so that the
49 ;;; debugger can find them at a known location.
50 (!def-vm-support-routine make-old-fp-save-location (env)
51   (specify-save-tn
52    (physenv-debug-live-tn (make-normal-tn *fixnum-primitive-type*) env)
53    (make-wired-tn *fixnum-primitive-type*
54                   control-stack-arg-scn
55                   ocfp-save-offset)))
56 (!def-vm-support-routine make-return-pc-save-location (env)
57   (let ((ptype *backend-t-primitive-type*))
58     (specify-save-tn
59      (physenv-debug-live-tn (make-normal-tn ptype) env)
60      (make-wired-tn ptype control-stack-arg-scn lra-save-offset))))
61
62 ;;; Make a TN for the standard argument count passing location. We
63 ;;; only need to make the standard location, since a count is never
64 ;;; passed when we are using non-standard conventions.
65 (!def-vm-support-routine make-arg-count-location ()
66   (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
67
68
69 ;;; Make a TN to hold the number-stack frame pointer. This is
70 ;;; allocated once per component, and is component-live.
71 (!def-vm-support-routine make-nfp-tn ()
72   (component-live-tn
73    (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nfp-offset)))
74
75 (!def-vm-support-routine make-stack-pointer-tn ()
76   (make-normal-tn *fixnum-primitive-type*))
77
78 (!def-vm-support-routine make-number-stack-pointer-tn ()
79   (make-normal-tn *fixnum-primitive-type*))
80
81 ;;; Return a list of TNs that can be used to represent an
82 ;;; unknown-values continuation within a function.
83 (!def-vm-support-routine make-unknown-values-locations ()
84   (list (make-stack-pointer-tn)
85         (make-normal-tn *fixnum-primitive-type*)))
86
87
88 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
89 ;;; VM-dependent initialization of the IR2-COMPONENT structure. We
90 ;;; push placeholder entries in the CONSTANTS to leave room for
91 ;;; additional noise in the code object header.
92 (!def-vm-support-routine select-component-format (component)
93   (declare (type component component))
94   (dotimes (i code-constants-offset)
95     (vector-push-extend nil
96                         (ir2-component-constants (component-info component))))
97   (values))
98
99 \f
100 ;;;; frame hackery
101
102 ;;; Return the number of bytes needed for the current non-descriptor
103 ;;; stack frame. Non-descriptor stack frames must be multiples of 8
104 ;;; bytes on the PMAX.
105 (defun bytes-needed-for-non-descriptor-stack-frame ()
106   (* (logandc2 (1+ (sb-allocated-size 'non-descriptor-stack)) 1)
107      n-word-bytes))
108
109 ;;; This is used for setting up the Old-FP in local call.
110 (define-vop (current-fp)
111   (:results (val :scs (any-reg)))
112   (:generator 1
113     (move cfp-tn val)))
114
115 ;;; This is used for computing the caller's NFP for use in
116 ;;; known-values return. It only works assuming there is no variable
117 ;;; size stuff on the nstack.
118 (define-vop (compute-old-nfp)
119   (:results (val :scs (any-reg)))
120   (:vop-var vop)
121   (:generator 1
122     (let ((nfp (current-nfp-tn vop)))
123       (when nfp
124         (inst addq nfp (bytes-needed-for-non-descriptor-stack-frame) val)))))
125
126 (define-vop (xep-allocate-frame)
127   (:info start-lab copy-more-arg-follows)
128   (:ignore copy-more-arg-follows)
129   (:vop-var vop)
130   (:temporary (:scs (non-descriptor-reg)) temp)
131   (:generator 1
132     ;; Make sure the function is aligned, and drop a label pointing to
133     ;; this function header.
134     (align n-lowtag-bits)
135     (trace-table-entry trace-table-fun-prologue)
136     (emit-label start-lab)
137     ;; Allocate function header.
138     (inst simple-fun-header-word)
139     (dotimes (i (1- simple-fun-code-offset))
140       (inst lword 0))
141     ;; The start of the actual code.
142     ;; Compute CODE from the address of this entry point.
143     (let ((entry-point (gen-label)))
144       (emit-label entry-point)
145       (inst compute-code-from-lip code-tn lip-tn entry-point temp)
146       ;; ### We should also save it on the stack so that the garbage
147       ;; collector won't forget about us if we call anyone else.
148       )
149     ;; Build our stack frames.
150     (inst lda
151           csp-tn
152           (* n-word-bytes (sb-allocated-size 'control-stack))
153           cfp-tn)
154     (let ((nfp (current-nfp-tn vop)))
155       (when nfp
156         (inst subq nsp-tn (bytes-needed-for-non-descriptor-stack-frame)
157               nsp-tn)
158         (move nsp-tn nfp)))
159     (trace-table-entry trace-table-normal)))
160
161 (define-vop (allocate-frame)
162   (:results (res :scs (any-reg))
163             (nfp :scs (any-reg)))
164   (:info callee)
165   (:generator 2
166     (trace-table-entry trace-table-fun-prologue)
167     (move csp-tn res)
168     (inst lda
169           csp-tn
170           (* n-word-bytes (sb-allocated-size 'control-stack))
171           csp-tn)
172     (when (ir2-physenv-number-stack-p callee)
173       (inst subq nsp-tn (bytes-needed-for-non-descriptor-stack-frame)
174             nsp-tn)
175       (move nsp-tn nfp))
176     (trace-table-entry trace-table-normal)))
177
178 ;;; Allocate a partial frame for passing stack arguments in a full
179 ;;; call. NARGS is the number of arguments passed. If no stack
180 ;;; arguments are passed, then we don't have to do anything.
181 (define-vop (allocate-full-call-frame)
182   (:info nargs)
183   (:results (res :scs (any-reg)))
184   (:generator 2
185     (when (> nargs register-arg-count)
186       (move csp-tn res)
187       (inst lda csp-tn (* nargs n-word-bytes) csp-tn))))
188
189 ;;; Emit code needed at the return-point from an unknown-values call
190 ;;; for a fixed number of values. Values is the head of the TN-REF
191 ;;; list for the locations that the values are to be received into.
192 ;;; Nvals is the number of values that are to be received (should
193 ;;; equal the length of Values).
194 ;;;
195 ;;; Move-Temp is a Descriptor-Reg TN used as a temporary.
196 ;;;
197 ;;; This code exploits the fact that in the unknown-values convention,
198 ;;; a single value return returns at the return PC + 8, whereas a
199 ;;; return of other than one value returns directly at the return PC.
200 ;;;
201 ;;; If 0 or 1 values are expected, then we just emit an instruction to
202 ;;; reset the SP (which will only be executed when other than 1 value
203 ;;; is returned.)
204 ;;;
205 ;;; In the general case, we have to do three things:
206 ;;;  -- Default unsupplied register values.  This need only be done when a
207 ;;;     single value is returned, since register values are defaulted by the
208 ;;;     called in the non-single case.
209 ;;;  -- Default unsupplied stack values.  This needs to be done whenever there
210 ;;;     are stack values.
211 ;;;  -- Reset SP.  This must be done whenever other than 1 value is returned,
212 ;;;     regardless of the number of values desired.
213 ;;;
214 ;;; The general-case code looks like this:
215 #|
216         b regs-defaulted                ; Skip if MVs
217         nop
218
219         move a1 null-tn                 ; Default register values
220         ...
221         loadi nargs 1                   ; Force defaulting of stack values
222         move ocfp csp                   ; Set up args for SP resetting
223
224 regs-defaulted
225         subu temp nargs register-arg-count
226
227         bltz temp default-value-7       ; jump to default code
228         addu temp temp -1
229         loadw move-temp ocfp-tn 6       ; Move value to correct location.
230         store-stack-tn val4-tn move-temp
231
232         bltz temp default-value-8
233         addu temp temp -1
234         loadw move-temp ocfp-tn 7
235         store-stack-tn val5-tn move-temp
236
237         ...
238
239 defaulting-done
240         move sp ocfp                    ; Reset SP.
241 <end of code>
242
243 <elsewhere>
244 default-value-7
245         store-stack-tn val4-tn null-tn  ; Nil out 7'th value. (first on stack)
246
247 default-value-8
248         store-stack-tn val5-tn null-tn  ; Nil out 8'th value.
249
250         ...
251
252         br defaulting-done
253         nop
254 |#
255 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
256   (declare (type (or tn-ref null) values)
257            (type unsigned-byte nvals) (type tn move-temp temp))
258   (if (<= nvals 1)
259       (progn
260         ;; Note that this is a single-value return point. This is
261         ;; actually the multiple-value entry point for a single
262         ;; desired value, but the code location has to be here, or the
263         ;; debugger backtrace gets confused.
264         (without-scheduling ()
265           (note-this-location vop :single-value-return)
266           (move ocfp-tn csp-tn)
267           (inst nop))
268         (when lra-label
269           (inst compute-code-from-lra code-tn code-tn lra-label temp)))
270       (let ((regs-defaulted (gen-label))
271             (defaulting-done (gen-label))
272             (default-stack-vals (gen-label)))
273         (without-scheduling ()
274           ;; Note that this is an unknown-values return point.
275           (note-this-location vop :unknown-return)
276           ;; If there are no stack results, clear the stack now.
277           (if (> nvals register-arg-count)
278               (inst subq nargs-tn (fixnumize register-arg-count) temp)
279               (move ocfp-tn csp-tn))
280           ;; Branch off to the MV case.
281           (inst br zero-tn regs-defaulted))
282
283         ;; Do the single value case.
284         (do ((i 1 (1+ i))
285              (val (tn-ref-across values) (tn-ref-across val)))
286             ((= i (min nvals register-arg-count)))
287           (move null-tn (tn-ref-tn val)))
288         (when (> nvals register-arg-count)
289           (move csp-tn ocfp-tn)
290           (inst br zero-tn default-stack-vals))
291
292         (emit-label regs-defaulted)
293
294         (when (> nvals register-arg-count)
295           ;; If there are stack results, we have to default them
296           ;; and clear the stack.
297           (collect ((defaults))
298             (do ((i register-arg-count (1+ i))
299                  (val (do ((i 0 (1+ i))
300                            (val values (tn-ref-across val)))
301                           ((= i register-arg-count) val))
302                       (tn-ref-across val)))
303                 ((null val))
304
305               (let ((default-lab (gen-label))
306                     (tn (tn-ref-tn val)))
307                 (defaults (cons default-lab tn))
308
309                 (inst ble temp default-lab)
310                 (inst ldl move-temp (* i n-word-bytes) ocfp-tn)
311                 (inst subq temp (fixnumize 1) temp)
312                 (store-stack-tn tn move-temp)))
313
314             (emit-label defaulting-done)
315             (move ocfp-tn csp-tn)
316
317             (let ((defaults (defaults)))
318               (aver defaults)
319               (assemble (*elsewhere*)
320                 (emit-label default-stack-vals)
321                 (do ((remaining defaults (cdr remaining)))
322                     ((null remaining))
323                   (let ((def (car remaining)))
324                     (emit-label (car def))
325                     (store-stack-tn (cdr def) null-tn)))
326                 (inst br zero-tn defaulting-done)))))
327
328         (when lra-label
329           (inst compute-code-from-lra code-tn code-tn lra-label temp))))
330   (values))
331 \f
332 ;;;; unknown values receiving
333
334 ;;; Emit code needed at the return point for an unknown-values call
335 ;;; for an arbitrary number of values.
336 ;;;
337 ;;; We do the single and non-single cases with no shared code: there
338 ;;; doesn't seem to be any potential overlap, and receiving a single
339 ;;; value is more important efficiency-wise.
340 ;;;
341 ;;; When there is a single value, we just push it on the stack,
342 ;;; returning the old SP and 1.
343 ;;;
344 ;;; When there is a variable number of values, we move all of the
345 ;;; argument registers onto the stack, and return Args and Nargs.
346 ;;;
347 ;;; Args and Nargs are TNs wired to the named locations. We must
348 ;;; explicitly allocate these TNs, since their lifetimes overlap with
349 ;;; the results Start and Count (also, it's nice to be able to target
350 ;;; them).
351 (defun receive-unknown-values (args nargs start count lra-label temp)
352   (declare (type tn args nargs start count temp))
353   (let ((variable-values (gen-label))
354         (done (gen-label)))
355     (without-scheduling ()
356       (inst br zero-tn variable-values)
357       (inst nop))
358
359     (when lra-label
360       (inst compute-code-from-lra code-tn code-tn lra-label temp))
361     (inst addq csp-tn 4 csp-tn)
362     (storew (first *register-arg-tns*) csp-tn -1)
363     (inst subq csp-tn 4 start)
364     (inst li (fixnumize 1) count)
365
366     (emit-label done)
367
368     (assemble (*elsewhere*)
369       (emit-label variable-values)
370       (when lra-label
371         (inst compute-code-from-lra code-tn code-tn lra-label temp))
372       (do ((arg *register-arg-tns* (rest arg))
373            (i 0 (1+ i)))
374           ((null arg))
375         (storew (first arg) args i))
376       (move args start)
377       (move nargs count)
378       (inst br zero-tn done)))
379   (values))
380
381 ;;; a VOP that can be inherited by unknown values receivers. The main
382 ;;; thing this handles is allocation of the result temporaries.
383 (define-vop (unknown-values-receiver)
384   (:results
385    (start :scs (any-reg))
386    (count :scs (any-reg)))
387   (:temporary (:sc descriptor-reg :offset ocfp-offset
388                    :from :eval :to (:result 0))
389               values-start)
390   (:temporary (:sc any-reg :offset nargs-offset
391                :from :eval :to (:result 1))
392               nvals)
393   (:temporary (:scs (non-descriptor-reg)) temp))
394 \f
395 ;;;; local call with unknown values convention return
396
397 ;;; Non-TR local call for a fixed number of values passed according to the
398 ;;; unknown values convention.
399 ;;;
400 ;;; Args are the argument passing locations, which are specified only to
401 ;;; terminate their lifetimes in the caller.
402 ;;;
403 ;;; Values are the return value locations (wired to the standard passing
404 ;;; locations).
405 ;;;
406 ;;; Save is the save info, which we can ignore since saving has been
407 ;;; done. Return-PC is the TN that the return PC should be passed in.
408 ;;; Target is a continuation pointing to the start of the called
409 ;;; function. Nvals is the number of values received.
410 ;;;
411 ;;; Note: we can't use normal load-tn allocation for the fixed args,
412 ;;; since all registers may be tied up by the more operand. Instead,
413 ;;; we use MAYBE-LOAD-STACK-TN.
414 (define-vop (call-local)
415   (:args (fp)
416          (nfp)
417          (args :more t))
418   (:results (values :more t))
419   (:save-p t)
420   (:move-args :local-call)
421   (:info arg-locs callee target nvals)
422   (:vop-var vop)
423   (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
424   (:temporary (:scs (non-descriptor-reg)) temp)
425   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
426   (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
427   (:ignore arg-locs args ocfp)
428   (:generator 5
429     (let ((label (gen-label))
430           (cur-nfp (current-nfp-tn vop)))
431       (when cur-nfp
432         (store-stack-tn nfp-save cur-nfp))
433       (let ((callee-nfp (callee-nfp-tn callee)))
434         (maybe-load-stack-nfp-tn callee-nfp nfp temp))
435       (maybe-load-stack-tn cfp-tn fp)
436       (trace-table-entry trace-table-call-site)
437       (inst compute-lra-from-code
438             (callee-return-pc-tn callee) code-tn label temp)
439       (note-this-location vop :call-site)
440       (inst br zero-tn target)
441       (trace-table-entry trace-table-normal)
442       (emit-return-pc label)
443       (default-unknown-values vop values nvals move-temp temp label)
444       (maybe-load-stack-nfp-tn cur-nfp nfp-save temp))))
445
446
447 ;;; Non-TR local call for a variable number of return values passed
448 ;;; according to the unknown values convention. The results are the
449 ;;; start of the values glob and the number of values received.
450 ;;;
451 ;;; Note: we can't use normal load-tn allocation for the fixed args,
452 ;;; since all registers may be tied up by the more operand. Instead,
453 ;;; we use MAYBE-LOAD-STACK-TN.
454 (define-vop (multiple-call-local unknown-values-receiver)
455   (:args (fp)
456          (nfp)
457          (args :more t))
458   (:save-p t)
459   (:move-args :local-call)
460   (:info save callee target)
461   (:ignore args save)
462   (:vop-var vop)
463   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
464   (:temporary (:scs (non-descriptor-reg)) temp)
465   (:generator 20
466     (let ((label (gen-label))
467           (cur-nfp (current-nfp-tn vop)))
468       (when cur-nfp
469         (store-stack-tn nfp-save cur-nfp))
470       (let ((callee-nfp (callee-nfp-tn callee)))
471         (maybe-load-stack-nfp-tn callee-nfp nfp temp))
472       (maybe-load-stack-tn cfp-tn fp)
473       (trace-table-entry trace-table-call-site)
474       (inst compute-lra-from-code
475             (callee-return-pc-tn callee) code-tn label temp)
476       (note-this-location vop :call-site)
477       (inst bsr zero-tn target)
478       (trace-table-entry trace-table-normal)
479       (emit-return-pc label)
480       (note-this-location vop :unknown-return)
481       (receive-unknown-values values-start nvals start count label temp)
482       (maybe-load-stack-nfp-tn cur-nfp nfp-save temp))))
483
484 \f
485 ;;;; local call with known values return
486
487 ;;; Non-TR local call with known return locations. Known-value return
488 ;;; works just like argument passing in local call.
489 ;;;
490 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
491 ;;; registers may be tied up by the more operand.  Instead, we use
492 ;;; MAYBE-LOAD-STACK-TN.
493 (define-vop (known-call-local)
494   (:args (fp)
495          (nfp)
496          (args :more t))
497   (:results (res :more t))
498   (:move-args :local-call)
499   (:save-p t)
500   (:info save callee target)
501   (:ignore args res save)
502   (:vop-var vop)
503   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
504   (:temporary (:scs (non-descriptor-reg)) temp)
505   (:generator 5
506     (let ((label (gen-label))
507           (cur-nfp (current-nfp-tn vop)))
508       (when cur-nfp
509         (store-stack-tn nfp-save cur-nfp))
510       (let ((callee-nfp (callee-nfp-tn callee)))
511         (maybe-load-stack-nfp-tn callee-nfp nfp temp))
512       (maybe-load-stack-tn cfp-tn fp)
513       (trace-table-entry trace-table-call-site)
514       (inst compute-lra-from-code
515             (callee-return-pc-tn callee) code-tn label temp)
516       (note-this-location vop :call-site)
517       (inst bsr zero-tn target)
518       (trace-table-entry trace-table-normal)
519       (emit-return-pc label)
520       (note-this-location vop :known-return)
521       (maybe-load-stack-nfp-tn cur-nfp nfp-save temp))))
522
523 ;;; Return from known values call. We receive the return locations as
524 ;;; arguments to terminate their lifetimes in the returning function.
525 ;;; We restore FP and CSP and jump to the Return-PC.
526 ;;;
527 ;;; Note: we can't use normal load-tn allocation for the fixed args,
528 ;;; since all registers may be tied up by the more operand. Instead,
529 ;;; we use MAYBE-LOAD-STACK-TN.
530 (define-vop (known-return)
531   (:args (ocfp :target ocfp-temp)
532          (return-pc :target return-pc-temp)
533          (vals :more t))
534   (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
535   (:temporary (:sc any-reg :from (:argument 1))
536               return-pc-temp)
537   (:temporary (:scs (interior-reg)) lip)
538   (:move-args :known-return)
539   (:info val-locs)
540   (:ignore val-locs vals)
541   (:vop-var vop)
542   (:generator 6
543     (trace-table-entry trace-table-fun-epilogue)
544     (maybe-load-stack-tn ocfp-temp ocfp)
545     (maybe-load-stack-tn return-pc-temp return-pc)
546     (move cfp-tn csp-tn)
547     (let ((cur-nfp (current-nfp-tn vop)))
548       (when cur-nfp
549         (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
550               nsp-tn)))
551     (inst subq return-pc-temp (- other-pointer-lowtag n-word-bytes) lip)
552     (move ocfp-temp cfp-tn)
553     (inst ret zero-tn lip 1)
554     (trace-table-entry trace-table-normal)))
555 \f
556 ;;;; full call:
557 ;;;;
558 ;;;; There is something of a cross-product effect with full calls.
559 ;;;; Different versions are used depending on whether we know the
560 ;;;; number of arguments or the name of the called function, and
561 ;;;; whether we want fixed values, unknown values, or a tail call.
562 ;;;;
563 ;;;; In full call, the arguments are passed creating a partial frame on
564 ;;;; the stack top and storing stack arguments into that frame. On
565 ;;;; entry to the callee, this partial frame is pointed to by FP. If
566 ;;;; there are no stack arguments, we don't bother allocating a partial
567 ;;;; frame, and instead set FP to SP just before the call.
568
569 ;;; This macro helps in the definition of full call VOPs by avoiding
570 ;;; code replication in defining the cross-product VOPs.
571 ;;;
572 ;;; Name is the name of the VOP to define.
573 ;;;
574 ;;; Named is true if the first argument is a symbol whose global
575 ;;; function definition is to be called.
576 ;;;
577 ;;; Return is either :FIXED, :UNKNOWN or :TAIL:
578 ;;; -- If :FIXED, then the call is for a fixed number of values, returned
579 ;;;    in the standard passing locations (passed as result operands).
580 ;;; -- If :UNKNOWN, then the result values are pushed on the stack, and
581 ;;;    the result values are specified by the Start and Count as in the
582 ;;;    unknown-values continuation representation.
583 ;;; -- If :TAIL, then do a tail-recursive call.  No values are returned.
584 ;;;    The Ocfp and Return-PC are passed as the second and third arguments.
585 ;;;
586 ;;; In non-tail calls, the pointer to the stack arguments is passed as
587 ;;; the last fixed argument. If Variable is false, then the passing
588 ;;; locations are passed as a more arg. Variable is true if there are
589 ;;; a variable number of arguments passed on the stack. Variable
590 ;;; cannot be specified with :TAIL return. TR variable argument call
591 ;;; is implemented separately.
592 ;;;
593 ;;; In tail call with fixed arguments, the passing locations are
594 ;;; passed as a more arg, but there is no new-FP, since the arguments
595 ;;; have been set up in the current frame.
596 (defmacro define-full-call (name named return variable)
597   (aver (not (and variable (eq return :tail))))
598   `(define-vop (,name
599                 ,@(when (eq return :unknown)
600                     '(unknown-values-receiver)))
601      (:args
602       ,@(unless (eq return :tail)
603           '((new-fp :scs (any-reg) :to :eval)))
604
605       ,(if named
606            '(name :target name-pass)
607            '(arg-fun :target lexenv))
608
609       ,@(when (eq return :tail)
610           '((ocfp :target ocfp-pass)
611             (return-pc :target return-pc-pass)))
612
613       ,@(unless variable '((args :more t :scs (descriptor-reg)))))
614
615      ,@(when (eq return :fixed)
616          '((:results (values :more t))))
617
618      (:save-p ,(if (eq return :tail) :compute-only t))
619
620      ,@(unless (or (eq return :tail) variable)
621          '((:move-args :full-call)))
622
623      (:vop-var vop)
624      (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
625             ,@(unless variable '(nargs))
626             ,@(when (eq return :fixed) '(nvals))
627             step-instrumenting)
628
629      (:ignore #!+gengc ,@(unless (eq return :tail) '(return-pc-pass))
630               ,@(unless (or variable (eq return :tail)) '(arg-locs))
631               ,@(unless variable '(args))
632               ;; Step instrumentation for full calls not implemented yet.
633               ;; See the PPC backend for an example.
634               step-instrumenting)
635
636      (:temporary (:sc descriptor-reg
637                   :offset ocfp-offset
638                   :from (:argument 1)
639                   ,@(unless (eq return :fixed)
640                       '(:to :eval)))
641                  ocfp-pass)
642
643      (:temporary (:sc descriptor-reg
644                   :offset #!-gengc lra-offset #!+gengc ra-offset
645                   :from (:argument ,(if (eq return :tail) 2 1))
646                   :to :eval)
647                  return-pc-pass)
648
649      ,@(if named
650          `((:temporary (:sc descriptor-reg :offset fdefn-offset
651                         :from (:argument ,(if (eq return :tail) 0 1))
652                         :to :eval)
653                        name-pass))
654
655          `((:temporary (:sc descriptor-reg :offset lexenv-offset
656                         :from (:argument ,(if (eq return :tail) 0 1))
657                         :to :eval)
658                        lexenv)
659            #!-gengc
660            (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
661                        function)))
662
663      (:temporary (:sc any-reg :offset nargs-offset :to :eval)
664                  nargs-pass)
665
666      ,@(when variable
667          (mapcar (lambda (name offset)
668                    `(:temporary (:sc descriptor-reg
669                                      :offset ,offset
670                                      :to :eval)
671                                 ,name))
672                  register-arg-names *register-arg-offsets*))
673      ,@(when (eq return :fixed)
674          '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
675
676      ,@(unless (eq return :tail)
677          '((:temporary (:scs (non-descriptor-reg)) temp)
678            (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
679
680      (:temporary (:sc interior-reg :offset lip-offset) entry-point)
681
682      (:generator ,(+ (if named 5 0)
683                      (if variable 19 1)
684                      (if (eq return :tail) 0 10)
685                      15
686                      (if (eq return :unknown) 25 0))
687        (let* ((cur-nfp (current-nfp-tn vop))
688               ,@(unless (eq return :tail)
689                   '((lra-label (gen-label))))
690               (filler
691                (remove nil
692                        (list :load-nargs
693                              ,@(if (eq return :tail)
694                                    '((unless (location= ocfp ocfp-pass)
695                                        :load-ocfp)
696                                      (unless (location= return-pc
697                                                         return-pc-pass)
698                                        :load-return-pc)
699                                      (when cur-nfp
700                                        :frob-nfp))
701                                    '(#!-gengc
702                                      :comp-lra
703                                      (when cur-nfp
704                                        :frob-nfp)
705                                      :save-fp
706                                      :load-fp))))))
707          (flet ((do-next-filler ()
708                   (let* ((next (pop filler))
709                          (what (if (consp next) (car next) next)))
710                     (ecase what
711                       (:load-nargs
712                        ,@(if variable
713                              `((inst subq csp-tn new-fp nargs-pass)
714                                ,@(let ((index -1))
715                                    (mapcar (lambda (name)
716                                              `(inst ldl ,name
717                                                     ,(ash (incf index)
718                                                           word-shift)
719                                                     new-fp))
720                                            register-arg-names)))
721                              '((inst li (fixnumize nargs) nargs-pass))))
722                       ,@(if (eq return :tail)
723                             '((:load-ocfp
724                                (sc-case ocfp
725                                  (any-reg
726                                   (inst move ocfp ocfp-pass))
727                                  (control-stack
728                                   (inst ldl ocfp-pass
729                                         (ash (tn-offset ocfp)
730                                              word-shift)
731                                         cfp-tn))))
732                               (:load-return-pc
733                                (sc-case return-pc
734                                  (#!-gengc descriptor-reg #!+gengc any-reg
735                                   (inst move return-pc return-pc-pass))
736                                  (control-stack
737                                   (inst ldl return-pc-pass
738                                         (ash (tn-offset return-pc)
739                                              word-shift)
740                                          cfp-tn))))
741                               (:frob-nfp
742                                (inst addq cur-nfp
743                                      (bytes-needed-for-non-descriptor-stack-frame)
744                                      nsp-tn)))
745                             `(#!-gengc
746                               (:comp-lra
747                                (inst compute-lra-from-code
748                                      return-pc-pass code-tn lra-label temp))
749                               (:frob-nfp
750                                (store-stack-tn nfp-save cur-nfp))
751                               (:save-fp
752                                (inst move cfp-tn ocfp-pass))
753                               (:load-fp
754                                ,(if variable
755                                     '(move new-fp cfp-tn)
756                                     '(if (> nargs register-arg-count)
757                                          (move new-fp cfp-tn)
758                                          (move csp-tn cfp-tn)))
759                                (trace-table-entry trace-table-call-site))))
760                       ((nil))))))
761
762            ,@(if named
763                  `((sc-case name
764                      (descriptor-reg (move name name-pass))
765                      (control-stack
766                       (inst ldl name-pass
767                             (ash (tn-offset name) word-shift) cfp-tn)
768                       (do-next-filler))
769                      (constant
770                       (inst ldl name-pass
771                             (- (ash (tn-offset name) word-shift)
772                                other-pointer-lowtag) code-tn)
773                       (do-next-filler)))
774                    (inst ldl entry-point
775                          (- (ash fdefn-raw-addr-slot word-shift)
776                             other-pointer-lowtag) name-pass)
777                    (do-next-filler))
778                  `((sc-case arg-fun
779                      (descriptor-reg (move arg-fun lexenv))
780                      (control-stack
781                       (inst ldl lexenv
782                             (ash (tn-offset arg-fun) word-shift) cfp-tn)
783                       (do-next-filler))
784                      (constant
785                       (inst ldl lexenv
786                             (- (ash (tn-offset arg-fun) word-shift)
787                                other-pointer-lowtag) code-tn)
788                       (do-next-filler)))
789                    #!-gengc
790                    (inst ldl function
791                          (- (ash closure-fun-slot word-shift)
792                             fun-pointer-lowtag) lexenv)
793                    #!-gengc
794                    (do-next-filler)
795                    #!-gengc
796                    (inst addq function
797                          (- (ash simple-fun-code-offset word-shift)
798                             fun-pointer-lowtag) entry-point)
799                    #!+gengc
800                    (inst ldl entry-point
801                          (- (ash closure-entry-point-slot word-shift)
802                             fun-pointer-lowtag) lexenv)
803                    #!+gengc
804                    (do-next-filler)))
805            (loop
806              (if (cdr filler)
807                  (do-next-filler)
808                  (return)))
809
810            (note-this-location vop :call-site)
811            (do-next-filler)
812            (inst jsr zero-tn entry-point))
813
814          ,@(ecase return
815              (:fixed
816               '((trace-table-entry trace-table-normal)
817                 (emit-return-pc lra-label)
818                 (default-unknown-values vop values nvals
819                                         move-temp temp lra-label)
820                 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp)))
821              (:unknown
822               '((trace-table-entry trace-table-normal)
823                 (emit-return-pc lra-label)
824                 (note-this-location vop :unknown-return)
825                 (receive-unknown-values values-start nvals start count
826                                         lra-label temp)
827                 (maybe-load-stack-nfp-tn cur-nfp nfp-save temp)))
828              (:tail))))))
829
830 (define-full-call call nil :fixed nil)
831 (define-full-call call-named t :fixed nil)
832 (define-full-call multiple-call nil :unknown nil)
833 (define-full-call multiple-call-named t :unknown nil)
834 (define-full-call tail-call nil :tail nil)
835 (define-full-call tail-call-named t :tail nil)
836
837 (define-full-call call-variable nil :fixed t)
838 (define-full-call multiple-call-variable nil :unknown t)
839
840 ;;; This is defined separately, since it needs special code that blits
841 ;;; the arguments down.
842 (define-vop (tail-call-variable)
843   (:args
844    (args-arg :scs (any-reg) :target args)
845    (function-arg :scs (descriptor-reg) :target lexenv)
846    (ocfp-arg :scs (any-reg) :target ocfp)
847    (lra-arg :scs (#!-gengc descriptor-reg #!+gengc any-reg) :target lra))
848
849   (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
850   (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
851   (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
852   (:temporary (:sc any-reg :offset #!-gengc lra-offset #!+gengc ra-offset
853                    :from (:argument 3)) lra)
854   (:temporary (:scs (non-descriptor-reg)) temp)
855
856   (:vop-var vop)
857
858   (:generator 75
859
860     ;; Move these into the passing locations if they are not already there.
861     (move args-arg args)
862     (move function-arg lexenv)
863     (move ocfp-arg ocfp)
864     (move lra-arg lra)
865
866     ;; Clear the number stack if anything is there.
867     (let ((cur-nfp (current-nfp-tn vop)))
868       (when cur-nfp
869         (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
870               nsp-tn)))
871
872     ;; And jump to the assembly-routine that does the bliting.
873     (inst li (make-fixup 'tail-call-variable :assembly-routine) temp)
874     (inst jmp zero-tn temp)))
875 \f
876 ;;;; unknown values return
877
878 ;;; Return a single value using the unknown-values convention.
879 (define-vop (return-single)
880   (:args (ocfp :scs (any-reg))
881          #!-gengc (return-pc :scs (descriptor-reg))
882          #!+gengc (return-pc :scs (any-reg) :target ra)
883          (value))
884   (:ignore value)
885   #!-gengc (:temporary (:scs (interior-reg)) lip)
886   #!+gengc (:temporary (:sc any-reg :offset ra-offset :from (:argument 1)) ra)
887   #!+gengc (:temporary (:scs (any-reg) :from (:argument 1)) temp)
888   (:vop-var vop)
889   (:generator 6
890     ;; Clear the number stack.
891     (trace-table-entry trace-table-fun-epilogue)
892     (let ((cur-nfp (current-nfp-tn vop)))
893       (when cur-nfp
894         (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
895               nsp-tn)))
896     ;; Clear the control stack, and restore the frame pointer.
897     (move cfp-tn csp-tn)
898     (move ocfp cfp-tn)
899     ;; Out of here.
900     #!-gengc (lisp-return return-pc lip :offset 2)
901     #!+gengc
902     (progn
903       (inst addq return-pc (* 2 n-word-bytes) temp)
904       (unless (location= ra return-pc)
905         (inst move ra return-pc))
906       (inst ret zero-tn temp 1))
907     (trace-table-entry trace-table-normal)))
908
909 ;;; Do unknown-values return of a fixed number of values. The Values
910 ;;; are required to be set up in the standard passing locations. Nvals
911 ;;; is the number of values returned.
912 ;;;
913 ;;; If returning a single value, then deallocate the current frame,
914 ;;; restore FP and jump to the single-value entry at Return-PC + 8.
915 ;;;
916 ;;; If returning other than one value, then load the number of values
917 ;;; returned, NIL out unsupplied values registers, restore FP and
918 ;;; return at Return-PC. When there are stack values, we must
919 ;;; initialize the argument pointer to point to the beginning of the
920 ;;; values block (which is the beginning of the current frame.)
921 (define-vop (return)
922   (:args (ocfp :scs (any-reg))
923          (return-pc :scs (#!-gengc descriptor-reg #!+gengc any-reg)
924                     :to (:eval 1)
925                     #!+gengc :target #!+gengc ra)
926          (values :more t))
927   (:ignore values)
928   (:info nvals)
929   (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
930   (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
931   (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
932   (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
933   (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
934   (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
935   (:temporary (:sc any-reg :offset nargs-offset) nargs)
936   (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
937   #!-gengc (:temporary (:scs (interior-reg)) lip)
938   #!+gengc (:temporary (:sc any-reg :offset ra-offset :from (:eval 1)) ra)
939   (:vop-var vop)
940   (:generator 6
941     ;; Clear the number stack.
942     (trace-table-entry trace-table-fun-epilogue)
943     (let ((cur-nfp (current-nfp-tn vop)))
944       (when cur-nfp
945         (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
946               nsp-tn)))
947     ;; Establish the values pointer and values count.
948     (move cfp-tn val-ptr)
949     (inst li (fixnumize nvals) nargs)
950     ;; restore the frame pointer and clear as much of the control
951     ;; stack as possible.
952     (move ocfp cfp-tn)
953     ;; ADDQ only accepts immediates of type (UNSIGNED-BYTE 8).  Here,
954     ;; instead of adding (* NVALS N-WORD-BYTES), we use NARGS that
955     ;; we've carefully set up, but protect ourselves by averring that
956     ;; FIXNUMIZEation and multiplication by N-WORD-BYTES is the same.
957     (aver (= (* nvals n-word-bytes) (fixnumize nvals)))
958     (inst addq val-ptr nargs csp-tn)
959     ;; pre-default any argument register that need it.
960     (when (< nvals register-arg-count)
961       (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
962         (move null-tn reg)))
963     ;; And away we go.
964     (lisp-return return-pc lip)
965     (trace-table-entry trace-table-normal)))
966
967 ;;; Do unknown-values return of an arbitrary number of values (passed
968 ;;; on the stack.) We check for the common case of a single return
969 ;;; value, and do that inline using the normal single value return
970 ;;; convention. Otherwise, we branch off to code that calls an
971 ;;; assembly-routine.
972 (define-vop (return-multiple)
973   (:args (ocfp-arg :scs (any-reg) :target ocfp)
974          #!-gengc (lra-arg :scs (descriptor-reg) :target lra)
975          #!+gengc (return-pc :scs (any-reg) :target ra)
976          (vals-arg :scs (any-reg) :target vals)
977          (nvals-arg :scs (any-reg) :target nvals))
978
979   (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
980   #!-gengc
981   (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
982   #!+gengc
983   (:temporary (:sc any-reg :offset ra-offset :from (:argument 1)) ra)
984   (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
985   (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
986   (:temporary (:sc descriptor-reg :offset a0-offset) a0)
987   (:temporary (:scs (non-descriptor-reg)) temp)
988   #!-gengc (:temporary (:scs (interior-reg)) lip)
989   #!+gengc (:temporary (:scs (any-reg) :from (:argument 0)) temp)
990
991   (:vop-var vop)
992
993   (:generator 13
994     (trace-table-entry trace-table-fun-epilogue)
995     (let ((not-single (gen-label)))
996       ;; Clear the number stack.
997       (let ((cur-nfp (current-nfp-tn vop)))
998         (when cur-nfp
999           (inst addq cur-nfp (bytes-needed-for-non-descriptor-stack-frame)
1000                 nsp-tn)))
1001
1002       ;; Check for the single case.
1003       (inst li (fixnumize 1) a0)
1004       (inst cmpeq nvals-arg a0 temp)
1005       (inst ldl a0 0 vals-arg)
1006       (inst beq temp not-single)
1007
1008       ;; Return with one value.
1009       (move cfp-tn csp-tn)
1010       (move ocfp-arg cfp-tn)
1011       (lisp-return lra-arg lip :offset 2)
1012
1013       ;; Nope, not the single case.
1014       (emit-label not-single)
1015       (move ocfp-arg ocfp)
1016       (move lra-arg lra)
1017       (move vals-arg vals)
1018       (move nvals-arg nvals)
1019       (inst li (make-fixup 'return-multiple :assembly-routine) temp)
1020       (inst jmp zero-tn temp))
1021     (trace-table-entry trace-table-normal)))
1022 \f
1023 ;;;; XEP hackery
1024
1025 ;;; We don't need to do anything special for regular functions.
1026 (define-vop (setup-environment)
1027   (:info label)
1028   (:ignore label)
1029   (:generator 0
1030     ;; Don't bother doing anything.
1031     ))
1032
1033 ;;; Get the lexical environment from its passing location.
1034 (define-vop (setup-closure-environment)
1035   (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1036                :to (:result 0))
1037               lexenv)
1038   (:results (closure :scs (descriptor-reg)))
1039   (:info label)
1040   (:ignore label)
1041   (:generator 6
1042     ;; Get result.
1043     (move lexenv closure)))
1044
1045 ;;; Copy a &MORE arg from the argument area to the end of the current
1046 ;;; frame. FIXED is the number of non-&MORE arguments.
1047 (define-vop (copy-more-arg)
1048   (:temporary (:sc any-reg :offset nl0-offset) result)
1049   (:temporary (:sc any-reg :offset nl1-offset) count)
1050   (:temporary (:sc any-reg :offset nl2-offset) src)
1051   (:temporary (:sc any-reg :offset nl4-offset) dst)
1052   (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1053   (:info fixed)
1054   (:generator 20
1055     (let ((loop (gen-label))
1056           (do-regs (gen-label))
1057           (done (gen-label)))
1058       (when (< fixed register-arg-count)
1059         ;; Save a pointer to the results so we can fill in register
1060         ;; args. We don't need this if there are more fixed args than
1061         ;; reg args.
1062         (move csp-tn result))
1063       ;; Allocate the space on the stack.
1064       (cond ((zerop fixed)
1065              (inst addq csp-tn nargs-tn csp-tn)
1066              (inst beq nargs-tn done))
1067             (t
1068              (inst subq nargs-tn (fixnumize fixed) count)
1069              (inst ble count done)
1070              (inst addq csp-tn count csp-tn)))
1071       (when (< fixed register-arg-count)
1072         ;; We must stop when we run out of stack args, not when we run
1073         ;; out of &MORE args.
1074         (inst subq nargs-tn (fixnumize register-arg-count) count))
1075       ;; Initialize dst to be end of stack.
1076       (move csp-tn dst)
1077       ;; Everything of interest in registers.
1078       (inst ble count do-regs)
1079       ;; Initialize SRC to be end of args.
1080       (inst addq cfp-tn nargs-tn src)
1081
1082       (emit-label loop)
1083       ;; *--dst = *--src, --count
1084       (inst subq src n-word-bytes src)
1085       (inst subq count (fixnumize 1) count)
1086       (loadw temp src)
1087       (inst subq dst n-word-bytes dst)
1088       (storew temp dst)
1089       (inst bgt count loop)
1090
1091       (emit-label do-regs)
1092       (when (< fixed register-arg-count)
1093         ;; Now we have to deposit any more args that showed up in
1094         ;; registers. We know there is at least one &MORE arg,
1095         ;; otherwise we would have branched to DONE up at the top.
1096         (inst subq nargs-tn (fixnumize (1+ fixed)) count)
1097         (do ((i fixed (1+ i)))
1098             ((>= i register-arg-count))
1099           ;; Store it relative to the pointer saved at the start.
1100           (storew (nth i *register-arg-tns*) result (- i fixed))
1101           ;; Is this the last one?
1102           (inst beq count done)
1103           ;; Decrement count.
1104           (inst subq count (fixnumize 1) count)))
1105       (emit-label done))))
1106
1107 ;;; &MORE args are stored consecutively on the stack, starting
1108 ;;; immediately at the context pointer. The context pointer is not
1109 ;;; typed, so the lowtag is 0.
1110 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1111
1112 ;;; Turn &MORE arg (context, count) into a list.
1113 (defoptimizer (%listify-rest-args stack-allocate-result) ((&rest args))
1114   t)
1115
1116 (define-vop (listify-rest-args)
1117   (:args (context-arg :target context :scs (descriptor-reg))
1118          (count-arg :target count :scs (any-reg)))
1119   (:arg-types * tagged-num)
1120   (:temporary (:scs (any-reg) :from (:argument 0)) context)
1121   (:temporary (:scs (any-reg) :from (:argument 1)) count)
1122   (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1123   (:results (result :scs (descriptor-reg)))
1124   (:translate %listify-rest-args)
1125   (:policy :safe)
1126   (:node-var node)
1127   (:generator 20
1128     (let* ((enter (gen-label))
1129            (loop (gen-label))
1130            (done (gen-label))
1131            (dx-p (node-stack-allocate-p node))
1132            (alloc-area-tn (if dx-p csp-tn alloc-tn)))
1133       (move context-arg context)
1134       (move count-arg count)
1135       ;; Check to see if there are any arguments.
1136       (move null-tn result)
1137       (inst beq count done)
1138
1139       ;; We need to do this atomically.
1140       (pseudo-atomic ()
1141         ;; align CSP
1142         (when dx-p (align-csp temp))
1143         ;; Allocate a cons (2 words) for each item.
1144         (inst bis alloc-area-tn list-pointer-lowtag result)
1145         (move result dst)
1146         (inst sll count 1 temp)
1147         (inst addq alloc-area-tn temp alloc-area-tn)
1148         (inst br zero-tn enter)
1149
1150         ;; Store the current cons in the cdr of the previous cons.
1151         (emit-label loop)
1152         (inst addq dst (* 2 n-word-bytes) dst)
1153         (storew dst dst -1 list-pointer-lowtag)
1154
1155         (emit-label enter)
1156         ;; Grab one value.
1157         (loadw temp context)
1158         (inst addq context n-word-bytes context)
1159
1160         ;; Store the value in the car (in delay slot)
1161         (storew temp dst 0 list-pointer-lowtag)
1162
1163         ;; Decrement count, and if != zero, go back for more.
1164         (inst subq count (fixnumize 1) count)
1165         (inst bne count loop)
1166
1167         ;; NIL out the last cons.
1168         (storew null-tn dst 1 list-pointer-lowtag))
1169       (emit-label done))))
1170
1171 ;;; Return the location and size of the &MORE arg glob created by
1172 ;;; COPY-MORE-ARG. Supplied is the total number of arguments supplied
1173 ;;; (originally passed in NARGS.) Fixed is the number of non-&rest
1174 ;;; arguments.
1175 ;;;
1176 ;;; We must duplicate some of the work done by COPY-MORE-ARG, since at
1177 ;;; that time the environment is in a pretty brain-damaged state,
1178 ;;; preventing this info from being returned as values. What we do is
1179 ;;; compute supplied - fixed, and return a pointer that many words
1180 ;;; below the current stack top.
1181 (define-vop (more-arg-context)
1182   (:policy :fast-safe)
1183   (:translate sb!c::%more-arg-context)
1184   (:args (supplied :scs (any-reg)))
1185   (:arg-types tagged-num (:constant fixnum))
1186   (:info fixed)
1187   (:results (context :scs (descriptor-reg))
1188             (count :scs (any-reg)))
1189   (:result-types t tagged-num)
1190   (:note "more-arg-context")
1191   (:generator 5
1192     (inst subq supplied (fixnumize fixed) count)
1193     (inst subq csp-tn count context)))
1194
1195 ;;; Signal wrong argument count error if NARGS isn't equal to COUNT.
1196 (define-vop (verify-arg-count)
1197   (:policy :fast-safe)
1198   (:translate sb!c::%verify-arg-count)
1199   (:args (nargs :scs (any-reg)))
1200   (:arg-types positive-fixnum (:constant t))
1201   (:temporary (:scs (any-reg) :type fixnum) temp)
1202   (:info count)
1203   (:vop-var vop)
1204   (:save-p :compute-only)
1205   (:generator 3
1206     (let ((err-lab
1207            (generate-error-code vop invalid-arg-count-error nargs)))
1208       (cond ((zerop count)
1209              (inst bne nargs err-lab))
1210             (t
1211              (inst subq nargs (fixnumize count) temp)
1212              (inst bne temp err-lab))))))
1213
1214 ;;; various other error signalers
1215 (macrolet ((frob (name error translate &rest args)
1216              `(define-vop (,name)
1217                 ,@(when translate
1218                     `((:policy :fast-safe)
1219                       (:translate ,translate)))
1220                 (:args ,@(mapcar (lambda (arg)
1221                                    `(,arg :scs (any-reg descriptor-reg)))
1222                                  args))
1223                 (:vop-var vop)
1224                 (:save-p :compute-only)
1225                 (:generator 1000
1226                   (error-call vop ,error ,@args)))))
1227   (frob arg-count-error invalid-arg-count-error
1228     sb!c::%arg-count-error nargs)
1229   (frob type-check-error object-not-type-error sb!c::%type-check-error
1230     object type)
1231   (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1232     object layout)
1233   (frob odd-key-args-error odd-key-args-error
1234     sb!c::%odd-key-args-error)
1235   (frob unknown-key-arg-error unknown-key-arg-error
1236     sb!c::%unknown-key-arg-error key)
1237   (frob nil-fun-returned-error nil-fun-returned-error nil fun))
1238
1239 ;;; Single-stepping
1240
1241 (define-vop (step-instrument-before-vop)
1242   (:policy :fast-safe)
1243   (:vop-var vop)
1244   (:generator 3
1245     ;; Stub! See the PPC backend for an example.
1246     (note-this-location vop :step-before-vop)))