1 ;;;; unknown-values VOPs 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 (define-vop (reset-stack-pointer)
15 (:args (ptr :scs (any-reg)))
19 (define-vop (%%nip-values)
20 (:args (last-nipped-ptr :scs (any-reg) :target edi)
21 (last-preserved-ptr :scs (any-reg) :target esi)
22 (moved-ptrs :scs (any-reg) :more t))
23 (:results (r-moved-ptrs :scs (any-reg) :more t)
26 (:temporary (:sc any-reg :offset esi-offset) esi)
27 (:temporary (:sc any-reg :offset edi-offset) edi)
28 (:ignore r-moved-ptrs)
30 (move edi last-nipped-ptr)
31 (move esi last-preserved-ptr)
32 (inst sub esi n-word-bytes)
33 (inst sub edi n-word-bytes)
42 ;; solaris requires DF being zero.
44 (inst lea esp-tn (make-ea :dword :base edi :disp n-word-bytes))
46 (loop for moved = moved-ptrs then (tn-ref-across moved)
48 do (inst add (tn-ref-tn moved) edi))))
50 ;;; Push some values onto the stack, returning the start and number of values
51 ;;; pushed as results. It is assumed that the Vals are wired to the standard
52 ;;; argument locations. Nvals is the number of values to push.
54 ;;; The generator cost is pseudo-random. We could get it right by defining a
55 ;;; bogus SC that reflects the costs of the memory-to-memory moves for each
56 ;;; operand, but this seems unworthwhile.
57 (define-vop (push-values)
58 (:args (vals :more t))
59 (:temporary (:sc unsigned-reg :to (:result 0) :target start) temp)
60 (:results (start) (count))
63 (move temp esp-tn) ; WARN pointing 1 below
64 (do ((val vals (tn-ref-across val)))
66 (inst push (tn-ref-tn val)))
68 (inst mov count (fixnumize nvals))))
70 ;;; Push a list of values on the stack, returning Start and Count as used in
71 ;;; unknown values continuations.
72 (define-vop (values-list)
73 (:args (arg :scs (descriptor-reg) :target list))
76 (:results (start :scs (any-reg))
77 (count :scs (any-reg)))
78 (:temporary (:sc descriptor-reg :from (:argument 0) :to (:result 1)) list)
79 (:temporary (:sc descriptor-reg :to (:result 1)) nil-temp)
80 (:temporary (:sc unsigned-reg :offset eax-offset :to (:result 1)) eax)
82 (:save-p :compute-only)
85 (move start esp-tn) ; WARN pointing 1 below
86 (inst mov nil-temp nil-value)
89 (inst cmp list nil-temp)
91 (pushw list cons-car-slot list-pointer-lowtag)
92 (loadw list list cons-cdr-slot list-pointer-lowtag)
94 (inst and al-tn lowtag-mask)
95 (inst cmp al-tn list-pointer-lowtag)
97 (error-call vop bogus-arg-to-values-list-error list)
100 (inst mov count start) ; start is high address
101 (inst sub count esp-tn))) ; stackp is low address
103 ;;; Copy the more arg block to the top of the stack so we can use them
104 ;;; as function arguments.
106 ;;; Accepts a context as produced by more-arg-context; points to the first
107 ;;; value on the stack, not 4 bytes above as in other contexts.
109 ;;; Return a context that is 4 bytes above the first value, suitable for
110 ;;; defining a new stack frame.
111 (define-vop (%more-arg-values)
112 (:args (context :scs (descriptor-reg any-reg) :target src)
113 (skip :scs (any-reg immediate))
114 (num :scs (any-reg) :target count))
115 (:arg-types * positive-fixnum positive-fixnum)
116 (:temporary (:sc any-reg :offset esi-offset :from (:argument 0)) src)
117 (:temporary (:sc descriptor-reg :offset eax-offset) temp)
118 (:temporary (:sc unsigned-reg :offset ecx-offset) temp1)
119 (:results (start :scs (any-reg))
120 (count :scs (any-reg)))
124 (cond ((zerop (tn-value skip))
128 (inst lea src (make-ea :dword :base context
129 :disp (- (* (tn-value skip)
132 (inst sub count (* (tn-value skip) n-word-bytes)))))
138 (inst sub count skip)))
141 (inst mov start esp-tn)
142 (inst jecxz done) ; check for 0 count?
144 (inst shr temp1 word-shift) ; convert the fixnum to a count.
146 (inst std) ; move down the stack as more value are copied to the bottom.
153 ;; solaris requires DF being zero.
154 #!+sunos (inst cld)))