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