File: stack.h

package info (click to toggle)
bochs 3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,244 kB
  • sloc: cpp: 270,331; ansic: 25,334; sh: 8,371; makefile: 5,512; yacc: 1,485; asm: 395; perl: 359; lex: 318; csh: 3
file content (168 lines) | stat: -rw-r--r-- 4,224 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
//   Copyright (c) 2007-2012 Stanislav Shwartsman
//          Written by Stanislav Shwartsman [sshwarts at sourceforge net]
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
//
/////////////////////////////////////////////////////////////////////////

#ifndef BX_PUSHPOP_H
#define BX_PUSHPOP_H

  BX_CPP_INLINE void BX_CPP_AttrRegparmN(1)
BX_CPU_C::push_16(Bit16u value16)
{
#if BX_SUPPORT_X86_64
  if (long64_mode()) { /* StackAddrSize = 64 */
    stack_write_word(RSP-2, value16);
    RSP -= 2;
  }
  else
#endif
  if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) { /* StackAddrSize = 32 */
    stack_write_word((Bit32u) (ESP-2), value16);
    ESP -= 2;
  }
  else /* StackAddrSize = 16 */
  {
    stack_write_word((Bit16u) (SP-2), value16);
    SP -= 2;
  }
}

  BX_CPP_INLINE void BX_CPP_AttrRegparmN(1)
BX_CPU_C::push_32(Bit32u value32)
{
#if BX_SUPPORT_X86_64
  if (long64_mode()) { /* StackAddrSize = 64 */
    stack_write_dword(RSP-4, value32);
    RSP -= 4;
  }
  else
#endif
  if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) { /* StackAddrSize = 32 */
    stack_write_dword((Bit32u) (ESP-4), value32);
    ESP -= 4;
  }
  else /* StackAddrSize = 16 */
  {
    stack_write_dword((Bit16u) (SP-4), value32);
    SP -= 4;
  }
}

/* push 64 bit operand */
#if BX_SUPPORT_X86_64
  BX_CPP_INLINE void BX_CPP_AttrRegparmN(1)
BX_CPU_C::push_64(Bit64u value64)
{
  /* StackAddrSize = 64 */
  stack_write_qword(RSP-8, value64);
  RSP -= 8;
}
#endif

/* pop 16 bit operand from the stack */
BX_CPP_INLINE Bit16u BX_CPU_C::pop_16(void)
{
  Bit16u value16;

#if BX_SUPPORT_X86_64
  if (long64_mode()) { /* StackAddrSize = 64 */
    value16 = stack_read_word(RSP);
    RSP += 2;
  }
  else
#endif
  if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) { /* StackAddrSize = 32 */
    value16 = stack_read_word(ESP);
    ESP += 2;
  }
  else { /* StackAddrSize = 16 */
    value16 = stack_read_word(SP);
    SP += 2;
  }

  return value16;
}

/* pop 32 bit operand from the stack */
BX_CPP_INLINE Bit32u BX_CPU_C::pop_32(void)
{
  Bit32u value32;

#if BX_SUPPORT_X86_64
  if (long64_mode()) { /* StackAddrSize = 64 */
    value32 = stack_read_dword(RSP);
    RSP += 4;
  }
  else
#endif
  if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) { /* StackAddrSize = 32 */
    value32 = stack_read_dword(ESP);
    ESP += 4;
  }
  else { /* StackAddrSize = 16 */
    value32 = stack_read_dword(SP);
    SP += 4;
  }

  return value32;
}

/* pop 64 bit operand from the stack */
#if BX_SUPPORT_X86_64
BX_CPP_INLINE Bit64u BX_CPU_C::pop_64(void)
{
  /* StackAddrSize = 64 */
  Bit64u value64 = stack_read_qword(RSP);
  RSP += 8;
  return value64;
}
#endif // BX_SUPPORT_X86_64

#if BX_SUPPORT_CET
BX_CPP_INLINE void BX_CPP_AttrRegparmN(1) BX_CPU_C::shadow_stack_push_32(Bit32u value32)
{
  shadow_stack_write_dword(SSP-4, CPL, value32);
  SSP -= 4;
}

BX_CPP_INLINE void BX_CPP_AttrRegparmN(1) BX_CPU_C::shadow_stack_push_64(Bit64u value64)
{
  shadow_stack_write_qword(SSP-8, CPL, value64);
  SSP -= 8;
}

BX_CPP_INLINE Bit32u BX_CPU_C::shadow_stack_pop_32(void)
{
  Bit32u value32 = shadow_stack_read_dword(SSP, CPL);
  SSP += 4;
  return value32;
}

BX_CPP_INLINE Bit64u BX_CPU_C::shadow_stack_pop_64(void)
{
  Bit64u value64 = shadow_stack_read_qword(SSP, CPL);
  SSP += 8;
  return value64;
}

#endif // BX_SUPPORT_X86_64

#endif