- update sector count before calling write completion function (SF patch #2144692)
[bochs-mirror.git] / cpu / stack.h
blob59d4248bc82ab1c4df38a059bc47b8cb7f5eec4d
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: stack.h,v 1.3 2008/06/12 19:14:39 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2007 Stanislav Shwartsman
6 // Written by Stanislav Shwartsman [sshwarts at sourceforge net]
7 //
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 /////////////////////////////////////////////////////////////////////////
24 #ifndef BX_PUSHPOP_H
25 #define BX_PUSHPOP_H
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 */
31 #if BX_SUPPORT_X86_64
32 if (StackAddrSize64()) {
33 write_virtual_word_64(BX_SEG_REG_SS, RSP-2, value16);
34 RSP -= 2;
36 else
37 #endif
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);
40 ESP -= 2;
42 else
44 write_virtual_word_32(BX_SEG_REG_SS, (Bit16u) (SP-2), value16);
45 SP -= 2;
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 */
53 #if BX_SUPPORT_X86_64
54 if (StackAddrSize64()) {
55 write_virtual_dword_64(BX_SEG_REG_SS, RSP-4, value32);
56 RSP -= 4;
58 else
59 #endif
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);
62 ESP -= 4;
64 else
66 write_virtual_dword_32(BX_SEG_REG_SS, (Bit16u) (SP-4), value32);
67 SP -= 4;
71 /* push 64 bit operand */
72 #if BX_SUPPORT_X86_64
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);
77 RSP -= 8;
79 #endif
81 /* pop 16 bit operand from the stack */
82 BX_CPP_INLINE Bit16u BX_CPU_C::pop_16(void)
84 Bit16u value16;
86 #if BX_SUPPORT_X86_64
87 if (StackAddrSize64()) {
88 value16 = read_virtual_word_64(BX_SEG_REG_SS, RSP);
89 RSP += 2;
91 else
92 #endif
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);
95 ESP += 2;
97 else {
98 value16 = read_virtual_word_32(BX_SEG_REG_SS, SP);
99 SP += 2;
102 return value16;
105 /* pop 32 bit operand from the stack */
106 BX_CPP_INLINE Bit32u BX_CPU_C::pop_32(void)
108 Bit32u value32;
110 #if BX_SUPPORT_X86_64
111 if (StackAddrSize64()) {
112 value32 = read_virtual_dword_64(BX_SEG_REG_SS, RSP);
113 RSP += 4;
115 else
116 #endif
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);
119 ESP += 4;
121 else {
122 value32 = read_virtual_dword_32(BX_SEG_REG_SS, SP);
123 SP += 4;
126 return value32;
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);
134 RSP += 8;
136 return value64;
138 #endif // BX_SUPPORT_X86_64
140 #endif