OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [bochs486/] [cpu/] [stack32.cc] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/////////////////////////////////////////////////////////////////////////
2
// $Id: stack32.cc 11313 2012-08-05 13:52:40Z sshwarts $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//  Copyright (C) 2001-2012  The Bochs Project
6
//
7
//  This library is free software; you can redistribute it and/or
8
//  modify it under the terms of the GNU Lesser General Public
9
//  License as published by the Free Software Foundation; either
10
//  version 2 of the License, or (at your option) any later version.
11
//
12
//  This library is distributed in the hope that it will be useful,
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
//  Lesser General Public License for more details.
16
//
17
//  You should have received a copy of the GNU Lesser General Public
18
//  License along with this library; if not, write to the Free Software
19
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
20
/////////////////////////////////////////////////////////////////////////
21
 
22
#define NEED_CPU_REG_SHORTCUTS 1
23
#include "bochs.h"
24
#include "cpu.h"
25
#define LOG_THIS BX_CPU_THIS_PTR
26
 
27
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POP_EdM(bxInstruction_c *i)
28
{
29
  RSP_SPECULATIVE;
30
 
31
  Bit32u val32 = pop_32();
32
 
33
  // Note: there is one little weirdism here.  It is possible to use
34
  // ESP in the modrm addressing. If used, the value of ESP after the
35
  // pop is used to calculate the address.
36
  Bit32u eaddr = (Bit32u) BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
37
 
38
  write_virtual_dword_32(i->seg(), eaddr, val32);
39
 
40
  RSP_COMMIT;
41
 
42
  BX_NEXT_INSTR(i);
43
}
44
 
45
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH_ERX(bxInstruction_c *i)
46
{
47
  push_32(BX_READ_32BIT_REG(i->dst()));
48
 
49
  BX_NEXT_INSTR(i);
50
}
51
 
52
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POP_ERX(bxInstruction_c *i)
53
{
54
  BX_WRITE_32BIT_REGZ(i->dst(), pop_32());
55
 
56
  BX_NEXT_INSTR(i);
57
}
58
 
59
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH32_Sw(bxInstruction_c *i)
60
{
61
  Bit16u val_16 = BX_CPU_THIS_PTR sregs[i->src()].selector.value;
62
 
63
  if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
64
    stack_write_word((Bit32u) (ESP-4), val_16);
65
    ESP -= 4;
66
  }
67
  else
68
  {
69
    stack_write_word((Bit16u) (SP-4), val_16);
70
    SP -= 4;
71
  }
72
 
73
  BX_NEXT_INSTR(i);
74
}
75
 
76
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POP32_Sw(bxInstruction_c *i)
77
{
78
  Bit16u selector;
79
 
80
  if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
81
    selector = stack_read_word(ESP);
82
    load_seg_reg(&BX_CPU_THIS_PTR sregs[i->dst()], selector);
83
    ESP += 4;
84
  }
85
  else {
86
    selector = stack_read_word(SP);
87
    load_seg_reg(&BX_CPU_THIS_PTR sregs[i->dst()], selector);
88
    SP += 4;
89
  }
90
 
91
  if (i->dst() == BX_SEG_REG_SS) {
92
    // POP SS inhibits interrupts, debug exceptions and single-step
93
    // trap exceptions until the execution boundary following the
94
    // next instruction is reached.
95
    // Same code as MOV_SwEw()
96
    inhibit_interrupts(BX_INHIBIT_INTERRUPTS_BY_MOVSS);
97
  }
98
 
99
  BX_NEXT_INSTR(i);
100
}
101
 
102
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH_Id(bxInstruction_c *i)
103
{
104
  push_32(i->Id());
105
 
106
  BX_NEXT_INSTR(i);
107
}
108
 
109
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSH_EdM(bxInstruction_c *i)
110
{
111
  Bit32u eaddr = (Bit32u) BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
112
 
113
  Bit32u op1_32 = read_virtual_dword_32(i->seg(), eaddr);
114
 
115
  push_32(op1_32);
116
 
117
  BX_NEXT_INSTR(i);
118
}
119
 
120
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSHAD32(bxInstruction_c *i)
121
{
122
  Bit32u temp_ESP = ESP;
123
  Bit16u temp_SP  = SP;
124
 
125
  if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b)
126
  {
127
    stack_write_dword((Bit32u) (temp_ESP -  4), EAX);
128
    stack_write_dword((Bit32u) (temp_ESP -  8), ECX);
129
    stack_write_dword((Bit32u) (temp_ESP - 12), EDX);
130
    stack_write_dword((Bit32u) (temp_ESP - 16), EBX);
131
    stack_write_dword((Bit32u) (temp_ESP - 20), temp_ESP);
132
    stack_write_dword((Bit32u) (temp_ESP - 24), EBP);
133
    stack_write_dword((Bit32u) (temp_ESP - 28), ESI);
134
    stack_write_dword((Bit32u) (temp_ESP - 32), EDI);
135
    ESP -= 32;
136
  }
137
  else
138
  {
139
    stack_write_dword((Bit16u) (temp_SP -  4), EAX);
140
    stack_write_dword((Bit16u) (temp_SP -  8), ECX);
141
    stack_write_dword((Bit16u) (temp_SP - 12), EDX);
142
    stack_write_dword((Bit16u) (temp_SP - 16), EBX);
143
    stack_write_dword((Bit16u) (temp_SP - 20), temp_ESP);
144
    stack_write_dword((Bit16u) (temp_SP - 24), EBP);
145
    stack_write_dword((Bit16u) (temp_SP - 28), ESI);
146
    stack_write_dword((Bit16u) (temp_SP - 32), EDI);
147
    SP -= 32;
148
  }
149
 
150
  BX_NEXT_INSTR(i);
151
}
152
 
153
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::POPAD32(bxInstruction_c *i)
154
{
155
  Bit32u edi, esi, ebp, ebx, edx, ecx, eax;
156
 
157
  if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b)
158
  {
159
    Bit32u temp_ESP = ESP;
160
    edi = stack_read_dword((Bit32u) (temp_ESP +  0));
161
    esi = stack_read_dword((Bit32u) (temp_ESP +  4));
162
    ebp = stack_read_dword((Bit32u) (temp_ESP +  8));
163
          stack_read_dword((Bit32u) (temp_ESP + 12));
164
    ebx = stack_read_dword((Bit32u) (temp_ESP + 16));
165
    edx = stack_read_dword((Bit32u) (temp_ESP + 20));
166
    ecx = stack_read_dword((Bit32u) (temp_ESP + 24));
167
    eax = stack_read_dword((Bit32u) (temp_ESP + 28));
168
    ESP += 32;
169
  }
170
  else
171
  {
172
    Bit16u temp_SP = SP;
173
    edi = stack_read_dword((Bit16u) (temp_SP +  0));
174
    esi = stack_read_dword((Bit16u) (temp_SP +  4));
175
    ebp = stack_read_dword((Bit16u) (temp_SP +  8));
176
          stack_read_dword((Bit16u) (temp_SP + 12));
177
    ebx = stack_read_dword((Bit16u) (temp_SP + 16));
178
    edx = stack_read_dword((Bit16u) (temp_SP + 20));
179
    ecx = stack_read_dword((Bit16u) (temp_SP + 24));
180
    eax = stack_read_dword((Bit16u) (temp_SP + 28));
181
    SP += 32;
182
  }
183
 
184
  EDI = edi;
185
  ESI = esi;
186
  EBP = ebp;
187
  EBX = ebx;
188
  EDX = edx;
189
  ECX = ecx;
190
  EAX = eax;
191
 
192
  BX_NEXT_INSTR(i);
193
}
194
 
195
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::ENTER32_IwIb(bxInstruction_c *i)
196
{
197
  Bit16u imm16 = i->Iw();
198
  Bit8u level = i->Ib2();
199
  level &= 0x1F;
200
 
201
  RSP_SPECULATIVE;
202
 
203
  push_32(EBP);
204
  Bit32u frame_ptr32 = ESP;
205
 
206
  if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
207
    Bit32u ebp = EBP;  // Use temp copy for case of exception.
208
 
209
    if (level > 0) {
210
      /* do level-1 times */
211
      while (--level) {
212
        ebp -= 4;
213
        Bit32u temp32 = stack_read_dword(ebp);
214
        push_32(temp32);
215
      }
216
 
217
      /* push(frame pointer) */
218
      push_32(frame_ptr32);
219
    }
220
 
221
    ESP -= imm16;
222
 
223
    // ENTER finishes with memory write check on the final stack pointer
224
    // the memory is touched but no write actually occurs
225
    // emulate it by doing RMW read access from SS:ESP
226
    read_RMW_virtual_dword_32(BX_SEG_REG_SS, ESP);
227
  }
228
  else {
229
    Bit16u bp = BP;
230
 
231
    if (level > 0) {
232
      /* do level-1 times */
233
      while (--level) {
234
        bp -= 4;
235
        Bit32u temp32 = stack_read_dword(bp);
236
        push_32(temp32);
237
      }
238
 
239
      /* push(frame pointer) */
240
      push_32(frame_ptr32);
241
    }
242
 
243
    SP -= imm16;
244
 
245
    // ENTER finishes with memory write check on the final stack pointer
246
    // the memory is touched but no write actually occurs
247
    // emulate it by doing RMW read access from SS:SP
248
    read_RMW_virtual_dword_32(BX_SEG_REG_SS, SP);
249
  }
250
 
251
  EBP = frame_ptr32;
252
 
253
  RSP_COMMIT;
254
 
255
  BX_NEXT_INSTR(i);
256
}
257
 
258
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::LEAVE32(bxInstruction_c *i)
259
{
260
  BX_ASSERT(BX_CPU_THIS_PTR cpu_mode != BX_MODE_LONG_64);
261
 
262
  Bit32u value32;
263
 
264
  if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) {
265
    value32 = stack_read_dword(EBP);
266
    ESP = EBP + 4;
267
  }
268
  else {
269
    value32 = stack_read_dword(BP);
270
    SP = BP + 4;
271
  }
272
 
273
  EBP = value32;
274
 
275
  BX_NEXT_INSTR(i);
276
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.