1 /////////////////////////////////////////////////////////////////////////
2 // $Id: stack.h,v 1.3 2008/06/12 19:14:39 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (c) 2007 Stanislav Shwartsman
6 // Written by Stanislav Shwartsman [sshwarts at sourceforge net]
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /////////////////////////////////////////////////////////////////////////
27 BX_CPP_INLINE
void BX_CPP_AttrRegparmN(1)
28 BX_CPU_C::push_16(Bit16u value16
)
30 /* must use StackAddrSize, and either RSP, ESP or SP accordingly */
32 if (StackAddrSize64()) {
33 write_virtual_word_64(BX_SEG_REG_SS
, RSP
-2, value16
);
38 if (BX_CPU_THIS_PTR sregs
[BX_SEG_REG_SS
].cache
.u
.segment
.d_b
) { /* StackAddrSize = 32 */
39 write_virtual_word_32(BX_SEG_REG_SS
, (Bit32u
) (ESP
-2), value16
);
44 write_virtual_word_32(BX_SEG_REG_SS
, (Bit16u
) (SP
-2), value16
);
49 BX_CPP_INLINE
void BX_CPP_AttrRegparmN(1)
50 BX_CPU_C::push_32(Bit32u value32
)
52 /* must use StackAddrSize, and either RSP, ESP or SP accordingly */
54 if (StackAddrSize64()) {
55 write_virtual_dword_64(BX_SEG_REG_SS
, RSP
-4, value32
);
60 if (BX_CPU_THIS_PTR sregs
[BX_SEG_REG_SS
].cache
.u
.segment
.d_b
) { /* StackAddrSize = 32 */
61 write_virtual_dword_32(BX_SEG_REG_SS
, (Bit32u
) (ESP
-4), value32
);
66 write_virtual_dword_32(BX_SEG_REG_SS
, (Bit16u
) (SP
-4), value32
);
71 /* push 64 bit operand */
73 BX_CPP_INLINE
void BX_CPP_AttrRegparmN(1)
74 BX_CPU_C::push_64(Bit64u value64
)
76 write_virtual_qword_64(BX_SEG_REG_SS
, RSP
-8, value64
);
81 /* pop 16 bit operand from the stack */
82 BX_CPP_INLINE Bit16u
BX_CPU_C::pop_16(void)
87 if (StackAddrSize64()) {
88 value16
= read_virtual_word_64(BX_SEG_REG_SS
, RSP
);
93 if (BX_CPU_THIS_PTR sregs
[BX_SEG_REG_SS
].cache
.u
.segment
.d_b
) {
94 value16
= read_virtual_word_32(BX_SEG_REG_SS
, ESP
);
98 value16
= read_virtual_word_32(BX_SEG_REG_SS
, SP
);
105 /* pop 32 bit operand from the stack */
106 BX_CPP_INLINE Bit32u
BX_CPU_C::pop_32(void)
110 #if BX_SUPPORT_X86_64
111 if (StackAddrSize64()) {
112 value32
= read_virtual_dword_64(BX_SEG_REG_SS
, RSP
);
117 if (BX_CPU_THIS_PTR sregs
[BX_SEG_REG_SS
].cache
.u
.segment
.d_b
) {
118 value32
= read_virtual_dword_32(BX_SEG_REG_SS
, ESP
);
122 value32
= read_virtual_dword_32(BX_SEG_REG_SS
, SP
);
129 /* pop 64 bit operand from the stack */
130 #if BX_SUPPORT_X86_64
131 BX_CPP_INLINE Bit64u
BX_CPU_C::pop_64(void)
133 Bit64u value64
= read_virtual_qword_64(BX_SEG_REG_SS
, RSP
);
138 #endif // BX_SUPPORT_X86_64