1 ;;;; function call for the x86 VM
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 ;;;; interfaces to IR2 conversion
16 ;;; Return a wired TN describing the N'th full call argument passing
18 (defun standard-arg-location (n)
19 (declare (type unsigned-byte n))
20 (if (< n register-arg-count)
21 (make-wired-tn *backend-t-primitive-type* descriptor-reg-sc-number
22 (nth n *register-arg-offsets*))
23 (make-wired-tn *backend-t-primitive-type* control-stack-sc-number n)))
25 ;;; Make a passing location TN for a local call return PC.
27 ;;; Always wire the return PC location to the stack in its standard
29 (defun make-return-pc-passing-location (standard)
30 (declare (ignore standard))
31 (make-wired-tn (primitive-type-or-lose 'system-area-pointer)
32 sap-stack-sc-number return-pc-save-offset))
34 ;;; This is similar to MAKE-RETURN-PC-PASSING-LOCATION, but makes a
35 ;;; location to pass OLD-FP in.
37 ;;; This is wired in both the standard and the local-call conventions,
38 ;;; because we want to be able to assume it's always there. Besides,
39 ;;; the x86 doesn't have enough registers to really make it profitable
40 ;;; to pass it in a register.
41 (defun make-old-fp-passing-location (standard)
42 (declare (ignore standard))
43 (make-wired-tn *fixnum-primitive-type* control-stack-sc-number
46 ;;; Make the TNs used to hold OLD-FP and RETURN-PC within the current
47 ;;; function. We treat these specially so that the debugger can find
48 ;;; them at a known location.
50 ;;; Without using a save-tn - which does not make much sense if it is
51 ;;; wired to the stack?
52 (defun make-old-fp-save-location (physenv)
53 (physenv-debug-live-tn (make-wired-tn *fixnum-primitive-type*
54 control-stack-sc-number
57 (defun make-return-pc-save-location (physenv)
58 (physenv-debug-live-tn
59 (make-wired-tn (primitive-type-or-lose 'system-area-pointer)
60 sap-stack-sc-number return-pc-save-offset)
63 ;;; Make a TN for the standard argument count passing location. We only
64 ;;; need to make the standard location, since a count is never passed when we
65 ;;; are using non-standard conventions.
66 (defun make-arg-count-location ()
67 (make-wired-tn *fixnum-primitive-type* any-reg-sc-number ecx-offset))
69 ;;; Make a TN to hold the number-stack frame pointer. This is allocated
70 ;;; once per component, and is component-live.
72 (make-restricted-tn *fixnum-primitive-type* ignore-me-sc-number))
74 (defun make-stack-pointer-tn ()
75 (make-normal-tn *fixnum-primitive-type*))
77 (defun make-number-stack-pointer-tn ()
78 (make-restricted-tn *fixnum-primitive-type* ignore-me-sc-number))
80 ;;; Return a list of TNs that can be used to represent an unknown-values
81 ;;; continuation within a function.
82 (defun make-unknown-values-locations ()
83 (list (make-stack-pointer-tn)
84 (make-normal-tn *fixnum-primitive-type*)))
86 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
87 ;;; VM-dependent initialization of the IR2-COMPONENT structure. We
88 ;;; push placeholder entries in the CONSTANTS to leave room for
89 ;;; additional noise in the code object header.
90 (defun select-component-format (component)
91 (declare (type component component))
92 ;; The 1+ here is because for the x86 the first constant is a
93 ;; pointer to a list of fixups, or NIL if the code object has none.
94 ;; (If I understand correctly, the fixups are needed at GC copy
95 ;; time because the X86 code isn't relocatable.)
97 ;; KLUDGE: It'd be cleaner to have the fixups entry be a named
98 ;; element of the CODE (aka component) primitive object. However,
99 ;; it's currently a large, tricky, error-prone chore to change
100 ;; the layout of any primitive object, so for the foreseeable future
101 ;; we'll just live with this ugliness. -- WHN 2002-01-02
102 (dotimes (i (1+ code-constants-offset))
103 (vector-push-extend nil
104 (ir2-component-constants (component-info component))))
109 ;;; This is used for setting up the Old-FP in local call.
110 (define-vop (current-fp)
111 (:results (val :scs (any-reg control-stack)))
115 ;;; We don't have a separate NFP, so we don't need to do anything here.
116 (define-vop (compute-old-nfp)
122 ;;; Accessing a slot from an earlier stack frame is definite hackery.
123 (define-vop (ancestor-frame-ref)
124 (:args (frame-pointer :scs (descriptor-reg))
125 (variable-home-tn :load-if nil))
126 (:results (value :scs (descriptor-reg any-reg)))
129 (aver (sc-is variable-home-tn control-stack))
130 (loadw value frame-pointer
131 (frame-word-offset (tn-offset variable-home-tn)))))
132 (define-vop (ancestor-frame-set)
133 (:args (frame-pointer :scs (descriptor-reg))
134 (value :scs (descriptor-reg any-reg)))
135 (:results (variable-home-tn :load-if nil))
138 (aver (sc-is variable-home-tn control-stack))
139 (storew value frame-pointer
140 (frame-word-offset (tn-offset variable-home-tn)))))
142 (macrolet ((define-frame-op
143 (suffix sc stack-sc instruction
147 :disp (frame-byte-offset
148 (tn-offset variable-home-tn)))))
149 (let ((reffer (symbolicate 'ancestor-frame-ref '/ suffix))
150 (setter (symbolicate 'ancestor-frame-set '/ suffix)))
152 (define-vop (,reffer ancestor-frame-ref)
153 (:results (value :scs (,sc)))
155 (aver (sc-is variable-home-tn ,stack-sc))
156 (inst ,instruction value
158 (define-vop (,setter ancestor-frame-set)
159 (:args (frame-pointer :scs (descriptor-reg))
162 (aver (sc-is variable-home-tn ,stack-sc))
163 (inst ,instruction ,ea value))))))
165 (suffix sc stack-sc (load set)
169 :disp (frame-byte-offset
170 (tn-offset variable-home-tn)))))
171 (let ((reffer (symbolicate 'ancestor-frame-ref '/ suffix))
172 (setter (symbolicate 'ancestor-frame-set '/ suffix)))
174 (define-vop (,reffer ancestor-frame-ref)
175 (:results (value :scs (,sc)))
177 (aver (sc-is variable-home-tn ,stack-sc))
179 `(with-empty-tn@fp-top (value)
182 (define-vop (,setter ancestor-frame-set)
183 (:args (frame-pointer :scs (descriptor-reg))
186 (aver (sc-is variable-home-tn ,stack-sc))
188 `(with-tn@fp-top (value)
191 (define-frame-op signed-byte-32 signed-reg signed-stack mov)
192 (define-frame-op unsigned-byte-32 unsigned-reg unsigned-stack mov)
193 (define-frame-op system-area-pointer sap-reg sap-stack mov)
195 (define-x87-frame-op double-float double-reg double-stack
196 (fldd fstd) (make-ea :dword
198 :disp (frame-byte-offset
199 (1+ (tn-offset variable-home-tn)))))
200 (define-x87-frame-op single-float single-reg single-stack
203 (define-x87-frame-op complex-double-float complex-double-reg
205 ((let ((real (complex-double-reg-real-tn value))
206 (imag (complex-double-reg-imag-tn value)))
207 (with-empty-tn@fp-top (real)
208 (inst fldd (ea-for-cdf-real-stack variable-home-tn frame-pointer)))
209 (with-empty-tn@fp-top (imag)
210 (inst fldd (ea-for-cdf-imag-stack variable-home-tn frame-pointer))))
211 (let ((real (complex-double-reg-real-tn value))
212 (imag (complex-double-reg-imag-tn value)))
213 (with-tn@fp-top (real)
214 (inst fstd (ea-for-cdf-real-stack variable-home-tn frame-pointer)))
215 (with-tn@fp-top (imag)
216 (inst fstd (ea-for-cdf-imag-stack variable-home-tn frame-pointer))))))
217 (define-x87-frame-op complex-single-float complex-single-reg
219 ((let ((real (complex-single-reg-real-tn value))
220 (imag (complex-single-reg-imag-tn value)))
221 (with-empty-tn@fp-top (real)
222 (inst fld (ea-for-csf-real-stack variable-home-tn frame-pointer)))
223 (with-empty-tn@fp-top (imag)
224 (inst fld (ea-for-csf-imag-stack variable-home-tn frame-pointer))))
225 (let ((real (complex-single-reg-real-tn value))
226 (imag (complex-single-reg-imag-tn value)))
227 (with-tn@fp-top (real)
228 (inst fst (ea-for-csf-real-stack variable-home-tn frame-pointer)))
229 (with-tn@fp-top (imag)
230 (inst fst (ea-for-csf-imag-stack variable-home-tn frame-pointer)))))))
232 (defun primitive-type-indirect-cell-type (ptype)
233 (declare (type primitive-type ptype))
234 (macrolet ((foo (&body data)
235 `(case (primitive-type-name ptype)
236 ,@(loop for (name stack-sc ref set) in data
240 (list (primitive-type-or-lose ',name)
241 (sc-or-lose ',stack-sc)
242 (lambda (node block fp value res)
243 (sb!c::vop ,ref node block
245 (lambda (node block fp new-val value)
246 (sb!c::vop ,set node block
247 fp new-val value)))))))))
248 (foo (double-float double-stack
249 ancestor-frame-ref/double-float
250 ancestor-frame-set/double-float)
251 (single-float single-stack
252 ancestor-frame-ref/single-float
253 ancestor-frame-set/single-float)
254 (complex-double-float complex-double-stack
255 ancestor-frame-ref/complex-double-float
256 ancestor-frame-set/complex-double-float)
257 (complex-single-float complex-single-stack
258 ancestor-frame-ref/complex-single-float
259 ancestor-frame-set/complex-single-float)
260 (signed-byte-32 signed-stack
261 ancestor-frame-ref/signed-byte-32
262 ancestor-frame-set/signed-byte-32)
263 (unsigned-byte-32 unsigned-stack
264 ancestor-frame-ref/unsigned-byte-32
265 ancestor-frame-set/unsigned-byte-32)
266 (unsigned-byte-31 unsigned-stack
267 ancestor-frame-ref/unsigned-byte-32
268 ancestor-frame-set/unsigned-byte-32)
269 (system-area-pointer sap-stack
270 ancestor-frame-ref/system-area-pointer
271 ancestor-frame-set/system-area-pointer))))
273 (define-vop (xep-allocate-frame)
274 (:info start-lab copy-more-arg-follows)
277 (emit-alignment n-lowtag-bits)
278 (trace-table-entry trace-table-fun-prologue)
279 (emit-label start-lab)
280 ;; Skip space for the function header.
281 (inst simple-fun-header-word)
282 (dotimes (i (1- simple-fun-code-offset))
285 ;; The start of the actual code.
286 ;; Save the return-pc.
287 (popw ebp-tn (frame-word-offset return-pc-save-offset))
289 ;; If copy-more-arg follows it will allocate the correct stack
290 ;; size. The stack is not allocated first here as this may expose
291 ;; args on the stack if they take up more space than the frame!
292 (unless copy-more-arg-follows
293 ;; The args fit within the frame so just allocate the frame.
295 (make-ea :dword :base ebp-tn
296 :disp (- (* n-word-bytes
297 (- (max 3 (sb-allocated-size 'stack))
300 (trace-table-entry trace-table-normal)))
302 ;;; This is emitted directly before either a known-call-local, call-local,
303 ;;; or a multiple-call-local. All it does is allocate stack space for the
304 ;;; callee (who has the same size stack as us).
305 (define-vop (allocate-frame)
306 (:results (res :scs (any-reg))
311 (inst lea res (make-ea :dword :base esp-tn
312 :disp (- (* sp->fp-offset n-word-bytes))))
313 (inst sub esp-tn (* n-word-bytes (sb-allocated-size 'stack)))))
315 ;;; Allocate a partial frame for passing stack arguments in a full
316 ;;; call. NARGS is the number of arguments passed. We allocate at
317 ;;; least 3 slots, because the XEP noise is going to want to use them
318 ;;; before it can extend the stack.
319 (define-vop (allocate-full-call-frame)
321 (:results (res :scs (any-reg)))
323 (inst lea res (make-ea :dword :base esp-tn
324 :disp (- (* sp->fp-offset n-word-bytes))))
325 (inst sub esp-tn (* (max nargs 3) n-word-bytes))))
327 ;;; Emit code needed at the return-point from an unknown-values call
328 ;;; for a fixed number of values. Values is the head of the TN-REF
329 ;;; list for the locations that the values are to be received into.
330 ;;; Nvals is the number of values that are to be received (should
331 ;;; equal the length of Values).
333 ;;; If 0 or 1 values are expected, then we just emit an instruction to
334 ;;; reset the SP (which will only be executed when other than 1 value
337 ;;; In the general case we have to do three things:
338 ;;; -- Default unsupplied register values. This need only be done
339 ;;; when a single value is returned, since register values are
340 ;;; defaulted by the called in the non-single case.
341 ;;; -- Default unsupplied stack values. This needs to be done whenever
342 ;;; there are stack values.
343 ;;; -- Reset SP. This must be done whenever other than 1 value is
344 ;;; returned, regardless of the number of values desired.
345 (defun default-unknown-values (vop values nvals node)
346 (declare (type (or tn-ref null) values)
347 (type unsigned-byte nvals))
348 (let ((type (sb!c::basic-combination-derived-type node)))
351 (note-this-location vop :single-value-return)
353 ((<= (sb!kernel:values-type-max-value-count type)
355 (when (and (named-type-p type)
356 (eq nil (named-type-name type)))
357 ;; The function never returns, it may happen that the code
358 ;; ends right here leavig the :SINGLE-VALUE-RETURN note
359 ;; dangling. Let's emit a NOP.
361 ((not (sb!kernel:values-type-may-be-single-value-p type))
362 (inst mov esp-tn ebx-tn))
363 ((member :cmov *backend-subfeatures*)
364 (inst cmov :c esp-tn ebx-tn))
366 (let ((single-value (gen-label)))
367 (inst jmp :nc single-value)
368 (inst mov esp-tn ebx-tn)
369 (emit-label single-value)))))
370 ((<= nvals register-arg-count)
371 (note-this-location vop :unknown-return)
372 (when (sb!kernel:values-type-may-be-single-value-p type)
373 (let ((regs-defaulted (gen-label)))
374 (inst jmp :c regs-defaulted)
375 ;; Default the unsupplied registers.
376 (let* ((2nd-tn-ref (tn-ref-across values))
377 (2nd-tn (tn-ref-tn 2nd-tn-ref)))
378 (inst mov 2nd-tn nil-value)
381 for tn-ref = (tn-ref-across 2nd-tn-ref)
382 then (tn-ref-across tn-ref)
383 for count from 2 below register-arg-count
384 do (inst mov (tn-ref-tn tn-ref) 2nd-tn))))
385 (inst mov ebx-tn esp-tn)
386 (emit-label regs-defaulted)))
387 (when (< register-arg-count
388 (sb!kernel:values-type-max-value-count type))
389 (inst mov esp-tn ebx-tn)))
391 ;; The number of bytes depends on the relative jump instructions.
392 ;; Best case is 31+(n-3)*14, worst case is 35+(n-3)*18. For
393 ;; NVALS=6 that is 73/89 bytes, and for NVALS=7 that is 87/107
394 ;; bytes which is likely better than using the blt below.
395 (let ((regs-defaulted (gen-label))
396 (defaulting-done (gen-label))
397 (default-stack-slots (gen-label)))
398 (note-this-location vop :unknown-return)
399 ;; Branch off to the MV case.
400 (inst jmp :c regs-defaulted)
401 ;; Do the single value case.
402 ;; Default the register args
403 (inst mov eax-tn nil-value)
405 (val (tn-ref-across values) (tn-ref-across val)))
406 ((= i (min nvals register-arg-count)))
407 (inst mov (tn-ref-tn val) eax-tn))
408 ;; Fake other registers so it looks like we returned with all the
409 ;; registers filled in.
411 (inst jmp default-stack-slots)
412 (emit-label regs-defaulted)
413 (inst mov eax-tn nil-value)
414 (collect ((defaults))
415 (do ((i register-arg-count (1+ i))
416 (val (do ((i 0 (1+ i))
417 (val values (tn-ref-across val)))
418 ((= i register-arg-count) val))
419 (tn-ref-across val)))
421 (let ((default-lab (gen-label))
423 (first-stack-arg-p (= i register-arg-count)))
424 (defaults (cons default-lab
425 (cons tn first-stack-arg-p)))
426 (inst cmp ecx-tn (fixnumize i))
427 (inst jmp :be default-lab)
428 (when first-stack-arg-p
429 ;; There are stack args so the frame of the callee is
430 ;; still there, save EDX in its first slot temporalily.
431 (storew edx-tn ebx-tn (frame-word-offset sp->fp-offset)))
432 (loadw edx-tn ebx-tn (frame-word-offset (+ sp->fp-offset i)))
433 (inst mov tn edx-tn)))
434 (emit-label defaulting-done)
435 (loadw edx-tn ebx-tn (frame-word-offset sp->fp-offset))
437 (let ((defaults (defaults)))
439 (assemble (*elsewhere*)
440 (trace-table-entry trace-table-fun-prologue)
441 (emit-label default-stack-slots)
442 (dolist (default defaults)
443 (emit-label (car default))
445 ;; We are setting the first stack argument to NIL.
446 ;; The callee's stack frame is dead, save EDX by
447 ;; pushing it to the stack, it will end up at same
448 ;; place as in the (STOREW EDX-TN EBX-TN -1) case
451 (inst mov (second default) eax-tn))
452 (inst jmp defaulting-done)
453 (trace-table-entry trace-table-normal)))))))
455 ;; 91 bytes for this branch.
456 (let ((regs-defaulted (gen-label))
457 (restore-edi (gen-label))
458 (no-stack-args (gen-label))
459 (default-stack-vals (gen-label))
460 (count-okay (gen-label)))
461 (note-this-location vop :unknown-return)
462 ;; Branch off to the MV case.
463 (inst jmp :c regs-defaulted)
464 ;; Default the register args, and set up the stack as if we
465 ;; entered the MV return point.
466 (inst mov ebx-tn esp-tn)
467 (inst mov edi-tn nil-value)
468 (inst mov esi-tn edi-tn)
469 ;; Compute a pointer to where to put the [defaulted] stack values.
470 (emit-label no-stack-args)
474 (make-ea :dword :base ebp-tn
475 :disp (frame-byte-offset register-arg-count)))
476 ;; Load EAX with NIL so we can quickly store it, and set up
477 ;; stuff for the loop.
478 (inst mov eax-tn nil-value)
480 (inst mov ecx-tn (- nvals register-arg-count))
481 ;; Jump into the default loop.
482 (inst jmp default-stack-vals)
483 ;; The regs are defaulted. We need to copy any stack arguments,
484 ;; and then default the remaining stack arguments.
485 (emit-label regs-defaulted)
486 ;; Compute the number of stack arguments, and if it's zero or
487 ;; less, don't copy any stack arguments.
488 (inst sub ecx-tn (fixnumize register-arg-count))
489 (inst jmp :le no-stack-args)
491 (storew edi-tn ebx-tn (frame-word-offset (+ sp->fp-offset 1)))
492 ;; Throw away any unwanted args.
493 (inst cmp ecx-tn (fixnumize (- nvals register-arg-count)))
494 (inst jmp :be count-okay)
495 (inst mov ecx-tn (fixnumize (- nvals register-arg-count)))
496 (emit-label count-okay)
497 ;; Save the number of stack values.
498 (inst mov eax-tn ecx-tn)
499 ;; Compute a pointer to where the stack args go.
501 (make-ea :dword :base ebp-tn
502 :disp (frame-byte-offset register-arg-count)))
503 ;; Save ESI, and compute a pointer to where the args come from.
504 (storew esi-tn ebx-tn (frame-word-offset (+ sp->fp-offset 2)))
506 (make-ea :dword :base ebx-tn
507 :disp (frame-byte-offset
508 (+ sp->fp-offset register-arg-count))))
510 (inst shr ecx-tn word-shift) ; make word count
515 (loadw esi-tn ebx-tn (frame-word-offset (+ sp->fp-offset 2)))
516 ;; Now we have to default the remaining args. Find out how many.
517 (inst sub eax-tn (fixnumize (- nvals register-arg-count)))
519 ;; If none, then just blow out of here.
520 (inst jmp :le restore-edi)
521 (inst mov ecx-tn eax-tn)
522 (inst shr ecx-tn word-shift) ; word count
523 ;; Load EAX with NIL for fast storing.
524 (inst mov eax-tn nil-value)
526 (emit-label default-stack-vals)
529 ;; Restore EDI, and reset the stack.
530 (emit-label restore-edi)
531 (loadw edi-tn ebx-tn (frame-word-offset (+ sp->fp-offset 1)))
532 (inst mov esp-tn ebx-tn)
536 ;;;; unknown values receiving
538 ;;; Emit code needed at the return point for an unknown-values call
539 ;;; for an arbitrary number of values.
541 ;;; We do the single and non-single cases with no shared code: there
542 ;;; doesn't seem to be any potential overlap, and receiving a single
543 ;;; value is more important efficiency-wise.
545 ;;; When there is a single value, we just push it on the stack,
546 ;;; returning the old SP and 1.
548 ;;; When there is a variable number of values, we move all of the
549 ;;; argument registers onto the stack, and return ARGS and NARGS.
551 ;;; ARGS and NARGS are TNs wired to the named locations. We must
552 ;;; explicitly allocate these TNs, since their lifetimes overlap with
553 ;;; the results start and count. (Also, it's nice to be able to target
555 (defun receive-unknown-values (args nargs start count node)
556 (declare (type tn args nargs start count))
557 (let ((type (sb!c::basic-combination-derived-type node))
558 (variable-values (gen-label))
559 (stack-values (gen-label))
561 (when (sb!kernel:values-type-may-be-single-value-p type)
562 (inst jmp :c variable-values)
563 (cond ((location= start (first *register-arg-tns*))
564 (inst push (first *register-arg-tns*))
565 (inst lea start (make-ea :dword :base esp-tn :disp n-word-bytes)))
566 (t (inst mov start esp-tn)
567 (inst push (first *register-arg-tns*))))
568 (inst mov count (fixnumize 1))
570 (emit-label variable-values))
571 ;; The stack frame is burnt and RETurned from if there are no
572 ;; stack values. In this case quickly reallocate sufficient space.
573 (when (<= (sb!kernel:values-type-min-value-count type)
575 (inst cmp nargs (fixnumize register-arg-count))
576 (inst jmp :g stack-values)
577 (inst sub esp-tn nargs)
578 (emit-label stack-values))
579 ;; dtc: this writes the registers onto the stack even if they are
580 ;; not needed, only the number specified in ecx are used and have
581 ;; stack allocated to them. No harm is done.
583 for arg in *register-arg-tns*
585 for j below (sb!kernel:values-type-max-value-count type)
586 do (storew arg args i))
593 ;;; VOP that can be inherited by unknown values receivers. The main thing this
594 ;;; handles is allocation of the result temporaries.
595 (define-vop (unknown-values-receiver)
596 (:temporary (:sc descriptor-reg :offset ebx-offset
597 :from :eval :to (:result 0))
599 (:temporary (:sc any-reg :offset ecx-offset
600 :from :eval :to (:result 1))
602 (:results (start :scs (any-reg control-stack))
603 (count :scs (any-reg control-stack))))
605 ;;;; local call with unknown values convention return
607 (defun check-ocfp-and-return-pc (old-fp return-pc)
609 (format t "*known-return: old-fp ~S, tn-kind ~S; ~S ~S~%"
610 old-fp (sb!c::tn-kind old-fp) (sb!c::tn-save-tn old-fp)
611 (sb!c::tn-kind (sb!c::tn-save-tn old-fp)))
613 (format t "*known-return: return-pc ~S, tn-kind ~S; ~S ~S~%"
614 return-pc (sb!c::tn-kind return-pc)
615 (sb!c::tn-save-tn return-pc)
616 (sb!c::tn-kind (sb!c::tn-save-tn return-pc)))
617 (unless (and (sc-is old-fp control-stack)
618 (= (tn-offset old-fp) ocfp-save-offset))
619 (error "ocfp not on stack in standard save location?"))
620 (unless (and (sc-is return-pc sap-stack)
621 (= (tn-offset return-pc) return-pc-save-offset))
622 (error "return-pc not on stack in standard save location?")))
624 ;;; The local call convention doesn't fit that well with x86-style
625 ;;; calls. Emit a header for local calls to pop the return address
626 ;;; in the right place.
627 (defun emit-block-header (start-label trampoline-label fall-thru-p alignp)
628 (declare (ignore alignp))
629 (when trampoline-label
631 (inst jmp start-label))
632 (emit-label trampoline-label)
633 (popw ebp-tn (frame-word-offset return-pc-save-offset)))
634 (emit-label start-label))
636 ;;; Non-TR local call for a fixed number of values passed according to
637 ;;; the unknown values convention.
639 ;;; FP is the frame pointer in install before doing the call.
641 ;;; NFP would be the number-stack frame pointer if we had a separate
644 ;;; Args are the argument passing locations, which are specified only
645 ;;; to terminate their lifetimes in the caller.
647 ;;; VALUES are the return value locations (wired to the standard
648 ;;; passing locations). NVALS is the number of values received.
650 ;;; Save is the save info, which we can ignore since saving has been
653 ;;; TARGET is a continuation pointing to the start of the called
655 (define-vop (call-local)
659 (:results (values :more t))
661 (:move-args :local-call)
662 (:info arg-locs callee target nvals)
664 (:ignore nfp arg-locs args callee)
667 (trace-table-entry trace-table-call-site)
669 (note-this-location vop :call-site)
671 (default-unknown-values vop values nvals node)
672 (trace-table-entry trace-table-normal)))
674 ;;; Non-TR local call for a variable number of return values passed according
675 ;;; to the unknown values convention. The results are the start of the values
676 ;;; glob and the number of values received.
677 (define-vop (multiple-call-local unknown-values-receiver)
682 (:move-args :local-call)
683 (:info save callee target)
684 (:ignore args save nfp callee)
688 (trace-table-entry trace-table-call-site)
690 (note-this-location vop :call-site)
692 (note-this-location vop :unknown-return)
693 (receive-unknown-values values-start nvals start count node)
694 (trace-table-entry trace-table-normal)))
696 ;;;; local call with known values return
698 ;;; Non-TR local call with known return locations. Known-value return
699 ;;; works just like argument passing in local call.
701 ;;; Note: we can't use normal load-tn allocation for the fixed args,
702 ;;; since all registers may be tied up by the more operand. Instead,
703 ;;; we use MAYBE-LOAD-STACK-TN.
704 (define-vop (known-call-local)
708 (:results (res :more t))
709 (:move-args :local-call)
711 (:info save callee target)
712 (:ignore args res save nfp callee)
715 (trace-table-entry trace-table-call-site)
717 (note-this-location vop :call-site)
719 (note-this-location vop :known-return)
720 (trace-table-entry trace-table-normal)))
722 ;;; From Douglas Crosher
723 ;;; Return from known values call. We receive the return locations as
724 ;;; arguments to terminate their lifetimes in the returning function. We
725 ;;; restore FP and CSP and jump to the Return-PC.
726 (define-vop (known-return)
730 (:move-args :known-return)
732 (:ignore val-locs vals)
735 (check-ocfp-and-return-pc old-fp return-pc)
736 (trace-table-entry trace-table-fun-epilogue)
737 ;; Zot all of the stack except for the old-fp and return-pc.
738 (inst mov esp-tn ebp-tn)
741 (trace-table-entry trace-table-normal)))
745 ;;; There is something of a cross-product effect with full calls.
746 ;;; Different versions are used depending on whether we know the
747 ;;; number of arguments or the name of the called function, and
748 ;;; whether we want fixed values, unknown values, or a tail call.
750 ;;; In full call, the arguments are passed creating a partial frame on
751 ;;; the stack top and storing stack arguments into that frame. On
752 ;;; entry to the callee, this partial frame is pointed to by FP.
754 ;;; This macro helps in the definition of full call VOPs by avoiding
755 ;;; code replication in defining the cross-product VOPs.
757 ;;; NAME is the name of the VOP to define.
759 ;;; NAMED is true if the first argument is an fdefinition object whose
760 ;;; definition is to be called.
762 ;;; RETURN is either :FIXED, :UNKNOWN or :TAIL:
763 ;;; -- If :FIXED, then the call is for a fixed number of values, returned in
764 ;;; the standard passing locations (passed as result operands).
765 ;;; -- If :UNKNOWN, then the result values are pushed on the stack, and the
766 ;;; result values are specified by the Start and Count as in the
767 ;;; unknown-values continuation representation.
768 ;;; -- If :TAIL, then do a tail-recursive call. No values are returned.
769 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
771 ;;; In non-tail calls, the pointer to the stack arguments is passed as
772 ;;; the last fixed argument. If Variable is false, then the passing
773 ;;; locations are passed as a more arg. Variable is true if there are
774 ;;; a variable number of arguments passed on the stack. Variable
775 ;;; cannot be specified with :TAIL return. TR variable argument call
776 ;;; is implemented separately.
778 ;;; In tail call with fixed arguments, the passing locations are
779 ;;; passed as a more arg, but there is no new-FP, since the arguments
780 ;;; have been set up in the current frame.
781 (macrolet ((define-full-call (name named return variable)
782 (aver (not (and variable (eq return :tail))))
784 ,@(when (eq return :unknown)
785 '(unknown-values-receiver)))
787 ,@(unless (eq return :tail)
788 '((new-fp :scs (any-reg) :to (:argument 1))))
790 (fun :scs (descriptor-reg control-stack)
791 :target eax :to (:argument 0))
793 ,@(when (eq return :tail)
797 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
799 ,@(when (eq return :fixed)
800 '((:results (values :more t))))
802 (:save-p ,(if (eq return :tail) :compute-only t))
804 ,@(unless (or (eq return :tail) variable)
805 '((:move-args :full-call)))
809 ,@(unless (or variable (eq return :tail)) '(arg-locs))
810 ,@(unless variable '(nargs))
811 ,@(when (eq return :fixed) '(nvals))
815 ,@(unless (or variable (eq return :tail)) '(arg-locs))
816 ,@(unless variable '(args)))
818 ;; We pass either the fdefn object (for named call) or
819 ;; the actual function object (for unnamed call) in
820 ;; EAX. With named call, closure-tramp will replace it
821 ;; with the real function and invoke the real function
822 ;; for closures. Non-closures do not need this value,
823 ;; so don't care what shows up in it.
831 ;; We pass the number of arguments in ECX.
832 (:temporary (:sc unsigned-reg :offset ecx-offset :to :eval) ecx)
834 ;; With variable call, we have to load the
835 ;; register-args out of the (new) stack frame before
836 ;; doing the call. Therefore, we have to tell the
837 ;; lifetime stuff that we need to use them.
839 (mapcar (lambda (name offset)
840 `(:temporary (:sc descriptor-reg
845 *register-arg-names* *register-arg-offsets*))
847 ,@(when (eq return :tail)
848 '((:temporary (:sc unsigned-reg
852 ,@(unless (eq return :tail)
855 (:generator ,(+ (if named 5 0)
857 (if (eq return :tail) 0 10)
859 (if (eq return :unknown) 25 0))
860 (trace-table-entry trace-table-call-site)
862 ;; This has to be done before the frame pointer is
863 ;; changed! EAX stores the 'lexical environment' needed
869 ;; For variable call, compute the number of
870 ;; arguments and move some of the arguments to
873 ;; Compute the number of arguments.
874 (noise '(inst mov ecx new-fp))
875 (noise '(inst sub ecx esp-tn))
876 ;; Move the necessary args to registers,
877 ;; this moves them all even if they are
880 for name in *register-arg-names*
881 for index downfrom -1
882 do (noise `(loadw ,name new-fp ,index)))
886 (inst mov ecx (fixnumize nargs)))))
887 ,@(cond ((eq return :tail)
888 '(;; Python has figured out what frame we should
889 ;; return to so might as well use that clue.
890 ;; This seems really important to the
891 ;; implementation of things like
892 ;; (without-interrupts ...)
894 ;; dtc; Could be doing a tail call from a
895 ;; known-local-call etc in which the old-fp
896 ;; or ret-pc are in regs or in non-standard
897 ;; places. If the passing location were
898 ;; wired to the stack in standard locations
899 ;; then these moves will be un-necessary;
900 ;; this is probably best for the x86.
903 (unless (= ocfp-save-offset
905 ;; FIXME: FORMAT T for stale
906 ;; diagnostic output (several of
907 ;; them around here), ick
908 (error "** tail-call old-fp not S0~%")
909 (move old-fp-tmp old-fp)
912 (frame-word-offset ocfp-save-offset))))
913 ((any-reg descriptor-reg)
914 (error "** tail-call old-fp in reg not S0~%")
917 (frame-word-offset ocfp-save-offset))))
919 ;; For tail call, we have to push the
920 ;; return-pc so that it looks like we CALLed
921 ;; despite the fact that we are going to JMP.
922 (inst push return-pc)
925 ;; For non-tail call, we have to save our
926 ;; frame pointer and install the new frame
927 ;; pointer. We can't load stack tns after this
929 `(;; Python doesn't seem to allocate a frame
930 ;; here which doesn't leave room for the
933 ;; The variable args are on the stack and
934 ;; become the frame, but there may be <3
935 ;; args and 3 stack slots are assumed
936 ;; allocate on the call. So need to ensure
937 ;; there are at least 3 slots. This hack
940 '(inst sub esp-tn (fixnumize 3)))
942 ;; Bias the new-fp for use as an fp
944 '(inst sub new-fp (fixnumize sp->fp-offset)))
947 (storew ebp-tn new-fp
948 (frame-word-offset ocfp-save-offset))
950 (move ebp-tn new-fp) ; NB - now on new stack frame.
953 (when step-instrumenting
954 (emit-single-step-test)
956 (inst break single-step-around-trap))
959 (note-this-location vop :call-site)
961 (inst ,(if (eq return :tail) 'jmp 'call)
963 '(make-ea-for-object-slot eax fdefn-raw-addr-slot
964 other-pointer-lowtag)
965 '(make-ea-for-object-slot eax closure-fun-slot
966 fun-pointer-lowtag)))
969 '((default-unknown-values vop values nvals node)))
971 '((note-this-location vop :unknown-return)
972 (receive-unknown-values values-start nvals start count
975 (trace-table-entry trace-table-normal)))))
977 (define-full-call call nil :fixed nil)
978 (define-full-call call-named t :fixed nil)
979 (define-full-call multiple-call nil :unknown nil)
980 (define-full-call multiple-call-named t :unknown nil)
981 (define-full-call tail-call nil :tail nil)
982 (define-full-call tail-call-named t :tail nil)
984 (define-full-call call-variable nil :fixed t)
985 (define-full-call multiple-call-variable nil :unknown t))
987 ;;; This is defined separately, since it needs special code that BLT's
988 ;;; the arguments down. All the real work is done in the assembly
989 ;;; routine. We just set things up so that it can find what it needs.
990 (define-vop (tail-call-variable)
991 (:args (args :scs (any-reg control-stack) :target esi)
992 (function :scs (descriptor-reg control-stack) :target eax)
995 (:temporary (:sc unsigned-reg :offset esi-offset :from (:argument 0)) esi)
996 (:temporary (:sc unsigned-reg :offset eax-offset :from (:argument 1)) eax)
998 (check-ocfp-and-return-pc old-fp return-pc)
999 ;; Move these into the passing locations if they are not already there.
1002 ;; And jump to the assembly routine.
1003 (inst jmp (make-fixup 'tail-call-variable :assembly-routine))))
1005 ;;;; unknown values return
1007 ;;; Return a single-value using the Unknown-Values convention.
1009 ;;; pfw--get wired-tn conflicts sometimes if register sc specd for args
1010 ;;; having problems targeting args to regs -- using temps instead.
1012 ;;; First off, modifying the return-pc defeats the branch-prediction
1013 ;;; optimizations on modern CPUs quite handily. Second, we can do all
1014 ;;; this without needing a temp register. Fixed the latter, at least.
1015 ;;; -- AB 2006/Feb/04
1016 (define-vop (return-single)
1022 (check-ocfp-and-return-pc old-fp return-pc)
1023 (trace-table-entry trace-table-fun-epilogue)
1024 ;; Drop stack above old-fp
1025 (inst mov esp-tn ebp-tn)
1026 ;; Clear the multiple-value return flag
1028 ;; Restore the old frame pointer
1033 ;;; Do unknown-values return of a fixed (other than 1) number of
1034 ;;; values. The VALUES are required to be set up in the standard
1035 ;;; passing locations. NVALS is the number of values returned.
1037 ;;; Basically, we just load ECX with the number of values returned and
1038 ;;; EBX with a pointer to the values, set ESP to point to the end of
1039 ;;; the values, and jump directly to return-pc.
1040 (define-vop (return)
1042 (return-pc :to (:eval 1))
1046 ;; In the case of other than one value, we need these registers to
1047 ;; tell the caller where they are and how many there are.
1048 (:temporary (:sc unsigned-reg :offset ebx-offset) ebx)
1049 (:temporary (:sc unsigned-reg :offset ecx-offset) ecx)
1050 ;; We need to stretch the lifetime of return-pc past the argument
1051 ;; registers so that we can default the argument registers without
1052 ;; trashing return-pc.
1053 (:temporary (:sc unsigned-reg :offset (first *register-arg-offsets*)
1055 (:temporary (:sc unsigned-reg :offset (second *register-arg-offsets*)
1057 (:temporary (:sc unsigned-reg :offset (third *register-arg-offsets*)
1061 (check-ocfp-and-return-pc old-fp return-pc)
1063 ;; This is handled in RETURN-SINGLE.
1064 (error "nvalues is 1"))
1065 (trace-table-entry trace-table-fun-epilogue)
1066 ;; Establish the values pointer and values count.
1067 (inst lea ebx (make-ea :dword :base ebp-tn
1068 :disp (* sp->fp-offset n-word-bytes)))
1070 (inst xor ecx ecx) ; smaller
1071 (inst mov ecx (fixnumize nvals)))
1072 ;; Pre-default any argument register that need it.
1073 (when (< nvals register-arg-count)
1074 (let* ((arg-tns (nthcdr nvals (list a0 a1 a2)))
1075 (first (first arg-tns)))
1076 (inst mov first nil-value)
1077 (dolist (tn (cdr arg-tns))
1078 (inst mov tn first))))
1079 ;; Set the multiple value return flag.
1081 ;; And away we go. Except that return-pc is still on the
1082 ;; stack and we've changed the stack pointer. So we have to
1083 ;; tell it to index off of EBX instead of EBP.
1084 (cond ((<= nvals register-arg-count)
1085 (inst mov esp-tn ebp-tn)
1089 ;; Some values are on the stack after RETURN-PC and OLD-FP,
1090 ;; can't return normally and some slots of the frame will
1091 ;; be used as temporaries by the receiver.
1093 ;; Clear as much of the stack as possible, but not past the
1094 ;; old frame address.
1096 (make-ea :dword :base ebp-tn
1097 :disp (frame-byte-offset (1- nvals))))
1098 (move ebp-tn old-fp)
1099 (inst push (make-ea :dword :base ebx
1100 :disp (frame-byte-offset
1102 (tn-offset return-pc)))))
1105 (trace-table-entry trace-table-normal)))
1107 ;;; Do unknown-values return of an arbitrary number of values (passed
1108 ;;; on the stack.) We check for the common case of a single return
1109 ;;; value, and do that inline using the normal single value return
1110 ;;; convention. Otherwise, we branch off to code that calls an
1111 ;;; assembly-routine.
1113 ;;; The assembly routine takes the following args:
1114 ;;; ECX -- number of values to find there.
1115 ;;; ESI -- pointer to where to find the values.
1116 (define-vop (return-multiple)
1119 (vals :scs (any-reg) :target esi)
1120 (nvals :scs (any-reg) :target ecx))
1121 (:temporary (:sc unsigned-reg :offset esi-offset :from (:argument 2)) esi)
1122 (:temporary (:sc unsigned-reg :offset ecx-offset :from (:argument 3)) ecx)
1123 (:temporary (:sc descriptor-reg :offset (first *register-arg-offsets*)
1124 :from (:eval 0)) a0)
1127 (check-ocfp-and-return-pc old-fp return-pc)
1128 (trace-table-entry trace-table-fun-epilogue)
1129 (unless (policy node (> space speed))
1130 ;; Check for the single case.
1131 (let ((not-single (gen-label)))
1132 (inst cmp nvals (fixnumize 1))
1133 (inst jmp :ne not-single)
1134 ;; Return with one value.
1136 ;; Clear the stack until ocfp.
1137 (inst mov esp-tn ebp-tn)
1138 ;; clear the multiple-value return flag
1143 ;; Nope, not the single case. Jump to the assembly routine.
1144 (emit-label not-single)))
1147 (inst jmp (make-fixup 'return-multiple :assembly-routine))
1148 (trace-table-entry trace-table-normal)))
1152 ;;; We don't need to do anything special for regular functions.
1153 (define-vop (setup-environment)
1157 ;; Don't bother doing anything.
1160 ;;; Get the lexical environment from its passing location.
1161 (define-vop (setup-closure-environment)
1162 (:results (closure :scs (descriptor-reg)))
1167 (move closure eax-tn)))
1169 ;;; Copy a &MORE arg from the argument area to the end of the current
1170 ;;; frame. FIXED is the number of non-&MORE arguments.
1172 ;;; The tricky part is doing this without trashing any of the calling
1173 ;;; convention registers that are still needed. This vop is emitted
1174 ;;; directly after the xep-allocate frame. That means the registers
1175 ;;; are in use as follows:
1177 ;;; EAX -- The lexenv.
1178 ;;; EBX -- Available.
1179 ;;; ECX -- The total number of arguments * N-WORD-BYTES.
1180 ;;; EDX -- The first arg.
1181 ;;; EDI -- The second arg.
1182 ;;; ESI -- The third arg.
1184 ;;; So basically, we have one register available for our use: EBX.
1186 ;;; What we can do is push the other regs onto the stack, and then
1187 ;;; restore their values by looking directly below where we put the
1189 (define-vop (copy-more-arg)
1192 ;; Avoid the copy if there are no more args.
1193 (cond ((zerop fixed)
1194 (inst jecxz JUST-ALLOC-FRAME))
1196 (inst cmp ecx-tn (fixnumize fixed))
1197 (inst jmp :be JUST-ALLOC-FRAME)))
1199 ;; Allocate the space on the stack.
1200 ;; stack = ebp + sp->fp-offset - (max 3 frame-size) - (nargs - fixed)
1202 (make-ea :dword :base ebp-tn
1203 :disp (* n-word-bytes
1204 (- (+ sp->fp-offset fixed)
1205 (max 3 (sb-allocated-size 'stack))))))
1206 (inst sub ebx-tn ecx-tn) ; Got the new stack in ebx
1207 (inst mov esp-tn ebx-tn)
1209 ;; Now: nargs>=1 && nargs>fixed
1211 ;; Save the original count of args.
1212 (inst mov ebx-tn ecx-tn)
1214 (cond ((< fixed register-arg-count)
1215 ;; We must stop when we run out of stack args, not when we
1216 ;; run out of more args.
1217 ;; Number to copy = nargs-3
1218 (inst sub ecx-tn (fixnumize register-arg-count))
1219 ;; Everything of interest in registers.
1220 (inst jmp :be DO-REGS))
1222 ;; Number to copy = nargs-fixed
1223 (inst sub ecx-tn (fixnumize fixed))))
1225 ;; Save edi and esi register args.
1229 ;; Okay, we have pushed the register args. We can trash them
1232 ;; Initialize src to be end of args.
1233 (inst lea esi-tn (make-ea :dword :base ebp-tn
1234 :disp (* sp->fp-offset n-word-bytes)))
1235 (inst sub esi-tn ebx-tn)
1237 ;; We need to copy from downwards up to avoid overwriting some of
1238 ;; the yet uncopied args. So we need to use EBX as the copy index
1239 ;; and ECX as the loop counter, rather than using ECX for both.
1240 (inst xor ebx-tn ebx-tn)
1242 ;; We used to use REP MOVS here, but on modern x86 it performs
1243 ;; much worse than an explicit loop for small blocks.
1245 (inst mov edi-tn (make-ea :dword :base esi-tn :index ebx-tn))
1246 ;; The :DISP is to account for the registers saved on the stack
1247 (inst mov (make-ea :dword :base esp-tn :disp (* 3 n-word-bytes)
1250 (inst add ebx-tn n-word-bytes)
1251 (inst sub ecx-tn n-word-bytes)
1252 (inst jmp :nz COPY-LOOP)
1254 ;; So now we need to restore EDI and ESI.
1262 (inst mov ecx-tn ebx-tn)
1264 ;; Here: nargs>=1 && nargs>fixed
1265 (when (< fixed register-arg-count)
1266 ;; Now we have to deposit any more args that showed up in
1270 ;; Store it relative to ebp
1271 (inst mov (make-ea :dword :base ebp-tn
1272 :disp (* n-word-bytes
1276 (max 3 (sb-allocated-size
1278 (nth i *register-arg-tns*))
1281 (when (>= i register-arg-count)
1284 ;; Don't deposit any more than there are.
1286 (inst test ecx-tn ecx-tn)
1287 (inst cmp ecx-tn (fixnumize i)))
1288 (inst jmp :eq DONE)))
1294 (make-ea :dword :base ebp-tn
1295 :disp (* n-word-bytes
1297 (max 3 (sb-allocated-size 'stack))))))
1301 (define-vop (more-kw-arg)
1302 (:translate sb!c::%more-kw-arg)
1303 (:policy :fast-safe)
1304 (:args (object :scs (descriptor-reg) :to (:result 1))
1305 (index :scs (any-reg immediate) :to (:result 1) :target keyword))
1306 (:arg-types * tagged-num)
1307 (:results (value :scs (descriptor-reg any-reg))
1308 (keyword :scs (descriptor-reg any-reg)))
1313 (inst mov value (make-ea :dword :base object :disp (tn-value index)))
1314 (inst mov keyword (make-ea :dword :base object
1315 :disp (+ (tn-value index) n-word-bytes))))
1317 (inst mov value (make-ea :dword :base object :index index))
1318 (inst mov keyword (make-ea :dword :base object :index index
1319 :disp n-word-bytes))))))
1321 (define-vop (more-arg)
1322 (:translate sb!c::%more-arg)
1323 (:policy :fast-safe)
1324 (:args (object :scs (descriptor-reg) :to (:result 1))
1325 (index :scs (any-reg) :to (:result 1) :target value))
1326 (:arg-types * tagged-num)
1327 (:results (value :scs (descriptor-reg any-reg)))
1332 (inst mov value (make-ea :dword :base object :index value))))
1334 ;;; Turn more arg (context, count) into a list.
1335 (define-vop (listify-rest-args)
1336 (:translate %listify-rest-args)
1338 (:args (context :scs (descriptor-reg) :target src)
1339 (count :scs (any-reg) :target ecx))
1340 (:arg-types * tagged-num)
1341 (:temporary (:sc unsigned-reg :offset esi-offset :from (:argument 0)) src)
1342 (:temporary (:sc unsigned-reg :offset ecx-offset :from (:argument 1)) ecx)
1343 (:temporary (:sc unsigned-reg :offset eax-offset) eax)
1344 (:temporary (:sc unsigned-reg) dst)
1345 (:results (result :scs (descriptor-reg)))
1348 (let ((enter (gen-label))
1351 (stack-allocate-p (node-stack-allocate-p node)))
1354 ;; Check to see whether there are no args, and just return NIL if so.
1355 (inst mov result nil-value)
1357 (inst lea dst (make-ea :dword :base ecx :index ecx))
1358 (maybe-pseudo-atomic stack-allocate-p
1359 (allocation dst dst node stack-allocate-p list-pointer-lowtag)
1360 ;; Set decrement mode (successive args at lower addresses)
1362 ;; Set up the result.
1364 ;; Jump into the middle of the loop, 'cause that's where we want
1368 ;; Compute a pointer to the next cons.
1369 (inst add dst (* cons-size n-word-bytes))
1370 ;; Store a pointer to this cons in the CDR of the previous cons.
1371 (storew dst dst -1 list-pointer-lowtag)
1373 ;; Grab one value and stash it in the car of this cons.
1375 (storew eax dst 0 list-pointer-lowtag)
1376 ;; Go back for more.
1377 (inst sub ecx n-word-bytes)
1379 ;; NIL out the last cons.
1380 (storew nil-value dst 1 list-pointer-lowtag)
1382 (emit-label done))))
1384 ;;; Return the location and size of the &MORE arg glob created by
1385 ;;; COPY-MORE-ARG. SUPPLIED is the total number of arguments supplied
1386 ;;; (originally passed in ECX). FIXED is the number of non-rest
1389 ;;; We must duplicate some of the work done by COPY-MORE-ARG, since at
1390 ;;; that time the environment is in a pretty brain-damaged state,
1391 ;;; preventing this info from being returned as values. What we do is
1392 ;;; compute supplied - fixed, and return a pointer that many words
1393 ;;; below the current stack top.
1394 (define-vop (more-arg-context)
1395 (:policy :fast-safe)
1396 (:translate sb!c::%more-arg-context)
1397 (:args (supplied :scs (any-reg) :target count))
1398 (:arg-types positive-fixnum (:constant fixnum))
1400 (:results (context :scs (descriptor-reg))
1401 (count :scs (any-reg)))
1402 (:result-types t tagged-num)
1403 (:note "more-arg-context")
1405 (move count supplied)
1406 ;; SP at this point points at the last arg pushed.
1407 ;; Point to the first more-arg, not above it.
1408 (inst lea context (make-ea :dword :base esp-tn
1409 :index count :scale 1
1410 :disp (- (+ (fixnumize fixed) n-word-bytes))))
1411 (unless (zerop fixed)
1412 (inst sub count (fixnumize fixed)))))
1414 ;;; Signal wrong argument count error if NARGS isn't equal to COUNT.
1415 (define-vop (verify-arg-count)
1416 (:policy :fast-safe)
1417 (:translate sb!c::%verify-arg-count)
1418 (:args (nargs :scs (any-reg)))
1419 (:arg-types positive-fixnum (:constant t))
1422 (:save-p :compute-only)
1425 (generate-error-code vop 'invalid-arg-count-error nargs)))
1427 (inst test nargs nargs) ; smaller instruction
1428 (inst cmp nargs (fixnumize count)))
1429 (inst jmp :ne err-lab))))
1431 ;;; Various other error signallers.
1432 (macrolet ((def (name error translate &rest args)
1433 `(define-vop (,name)
1435 `((:policy :fast-safe)
1436 (:translate ,translate)))
1437 (:args ,@(mapcar (lambda (arg)
1438 `(,arg :scs (any-reg descriptor-reg)))
1441 (:save-p :compute-only)
1443 (error-call vop ',error ,@args)))))
1444 (def arg-count-error invalid-arg-count-error
1445 sb!c::%arg-count-error nargs)
1446 (def type-check-error object-not-type-error sb!c::%type-check-error
1448 (def layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1450 (def odd-key-args-error odd-key-args-error
1451 sb!c::%odd-key-args-error)
1452 (def unknown-key-arg-error unknown-key-arg-error
1453 sb!c::%unknown-key-arg-error key)
1454 (def nil-fun-returned-error nil-fun-returned-error nil fun))
1458 (defun emit-single-step-test ()
1459 ;; We use different ways of representing whether stepping is on on
1460 ;; +SB-THREAD / -SB-THREAD: on +SB-THREAD, we use a slot in the
1461 ;; thread structure. On -SB-THREAD we use the value of a static
1462 ;; symbol. Things are done this way, since reading a thread-local
1463 ;; slot from a symbol would require an extra register on +SB-THREAD,
1464 ;; and reading a slot from a thread structure would require an extra
1465 ;; register on -SB-THREAD.
1468 #!+win32 (inst push eax-tn)
1469 (with-tls-ea (EA :base #!+win32 eax-tn #!-win32 :unused
1470 :disp-type :constant
1471 :disp (* thread-stepping-slot n-word-bytes))
1472 (inst cmp EA nil-value :maybe-fs))
1473 #!+win32 (inst pop eax-tn))
1475 (inst cmp (make-ea-for-symbol-value sb!impl::*stepping*)
1478 (define-vop (step-instrument-before-vop)
1479 (:policy :fast-safe)
1482 (emit-single-step-test)
1484 (inst break single-step-before-trap)
1486 (note-this-location vop :step-before-vop)))