File: flag_ctrl_pro.cc

package info (click to toggle)
bochs 1.4pre2-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 7,656 kB
  • ctags: 10,322
  • sloc: cpp: 66,880; ansic: 19,674; sh: 2,951; makefile: 2,183; asm: 2,110; yacc: 723; lex: 171; csh: 147; perl: 35
file content (213 lines) | stat: -rw-r--r-- 6,266 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/////////////////////////////////////////////////////////////////////////
// $Id: flag_ctrl_pro.cc,v 1.6 2001/10/03 13:10:37 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2001  MandrakeSoft S.A.
//
//    MandrakeSoft S.A.
//    43, rue d'Aboukir
//    75002 Paris - France
//    http://www.linux-mandrake.com/
//    http://www.mandrakesoft.com/
//
//  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA


#define NEED_CPU_REG_SHORTCUTS 1
#include "bochs.h"
#define LOG_THIS BX_CPU_THIS_PTR






  void
BX_CPU_C::write_flags(Bit16u flags, Boolean change_IOPL, Boolean change_IF)
{
  BX_CPU_THIS_PTR set_CF(flags & 0x01);
  BX_CPU_THIS_PTR set_PF((flags >> 2) & 0x01);
  BX_CPU_THIS_PTR set_AF((flags >> 4) & 0x01);
  BX_CPU_THIS_PTR set_ZF((flags >> 6) & 0x01);
  BX_CPU_THIS_PTR set_SF((flags >> 7) & 0x01);

#if 0
// +++
if (BX_CPU_THIS_PTR eflags.tf==0 && (flags&0x0100))
  BX_DEBUG(( "TF 0->1" ));
else if (BX_CPU_THIS_PTR eflags.tf && !(flags&0x0100))
  BX_DEBUG(( "TF 1->0" ));
else if (BX_CPU_THIS_PTR eflags.tf && (flags&0x0100))
  BX_DEBUG(( "TF 1->1" ));
#endif

  BX_CPU_THIS_PTR eflags.tf = (flags >> 8) & 0x01;
  if (BX_CPU_THIS_PTR eflags.tf) {
    BX_CPU_THIS_PTR async_event = 1;
    }

  if (change_IF)
    BX_CPU_THIS_PTR eflags.if_ = (flags >> 9) & 0x01;

  BX_CPU_THIS_PTR eflags.df = (flags >> 10) & 0x01;
  BX_CPU_THIS_PTR set_OF((flags >> 11) & 0x01);


#if BX_CPU_LEVEL == 2
  BX_CPU_THIS_PTR eflags.iopl = 0;
  BX_CPU_THIS_PTR eflags.nt = 0;
#else
  if (change_IOPL)
    BX_CPU_THIS_PTR eflags.iopl = (flags >> 12) & 0x03;
  BX_CPU_THIS_PTR eflags.nt = (flags >> 14) & 0x01;
#endif
}


#if BX_CPU_LEVEL >= 3
  void
BX_CPU_C::write_eflags(Bit32u eflags_raw, Boolean change_IOPL, Boolean change_IF,
                Boolean change_VM, Boolean change_RF)
{
  BX_CPU_THIS_PTR set_CF(eflags_raw & 0x01);
  BX_CPU_THIS_PTR set_PF((eflags_raw >> 2) & 0x01);
  BX_CPU_THIS_PTR set_AF((eflags_raw >> 4) & 0x01);
  BX_CPU_THIS_PTR set_ZF((eflags_raw >> 6) & 0x01);
  BX_CPU_THIS_PTR set_SF((eflags_raw >> 7) & 0x01);

#if 0
// +++
if (BX_CPU_THIS_PTR eflags.tf==0 && (eflags_raw&0x0100))
  BX_DEBUG(( "TF 0->1" ));
else if (BX_CPU_THIS_PTR eflags.tf && !(eflags_raw&0x0100))
  BX_DEBUG(( "TF 1->0" ));
else if (BX_CPU_THIS_PTR eflags.tf && (eflags_raw&0x0100))
  BX_DEBUG(( "TF 1->1" ));
#endif

  BX_CPU_THIS_PTR eflags.tf = (eflags_raw >> 8) & 0x01;
  if (BX_CPU_THIS_PTR eflags.tf) {
    BX_CPU_THIS_PTR async_event = 1;
    }

  if (change_IF)
    BX_CPU_THIS_PTR eflags.if_ = (eflags_raw >> 9) & 0x01;

  BX_CPU_THIS_PTR eflags.df = (eflags_raw >> 10) & 0x01;
  BX_CPU_THIS_PTR set_OF((eflags_raw >> 11) & 0x01);

  if (change_IOPL)
    BX_CPU_THIS_PTR eflags.iopl = (eflags_raw >> 12) & 0x03;
  BX_CPU_THIS_PTR eflags.nt = (eflags_raw >> 14) & 0x01;

  if (change_VM) {
    BX_CPU_THIS_PTR eflags.vm = (eflags_raw >> 17) & 0x01;
#if BX_SUPPORT_V8086_MODE == 0
    if (BX_CPU_THIS_PTR eflags.vm)
      BX_PANIC(("write_eflags: VM bit set: BX_SUPPORT_V8086_MODE==0"));
#endif
    }
  if (change_RF) {
    BX_CPU_THIS_PTR eflags.rf = (eflags_raw >> 16) & 0x01;
    }

#if BX_CPU_LEVEL >= 4
  BX_CPU_THIS_PTR eflags.ac = (eflags_raw >> 18) & 0x01;
  BX_CPU_THIS_PTR eflags.id = (eflags_raw >> 21) & 0x01;
#endif

}
#endif /* BX_CPU_LEVEL >= 3 */


  Bit16u
BX_CPU_C::read_flags(void)
{
  Bit16u flags;

  flags = (get_CF()) |
          (BX_CPU_THIS_PTR eflags.bit1 << 1) |
          ((get_PF()) << 2) |
          (BX_CPU_THIS_PTR eflags.bit3 << 3) |
          ((get_AF()>0) << 4) |
          (BX_CPU_THIS_PTR eflags.bit5 << 5) |
          ((get_ZF()>0) << 6) |
          ((get_SF()>0) << 7) |
          (BX_CPU_THIS_PTR eflags.tf << 8) |
          (BX_CPU_THIS_PTR eflags.if_ << 9) |
          (BX_CPU_THIS_PTR eflags.df << 10) |
          ((get_OF()>0) << 11) |
          (BX_CPU_THIS_PTR eflags.iopl << 12) |
          (BX_CPU_THIS_PTR eflags.nt << 14) |
          (BX_CPU_THIS_PTR eflags.bit15 << 15);

  /* 8086: bits 12-15 always set to 1.
   * 286: in real mode, bits 12-15 always cleared.
   * 386+: real-mode: bit15 cleared, bits 14..12 are last loaded value
   *       protected-mode: bit 15 clear, bit 14 = last loaded, IOPL?
   */
#if BX_CPU_LEVEL < 2
  flags |= 0xF000;  /* 8086 nature */
#elif BX_CPU_LEVEL == 2
  if (real_mode()) {
    flags &= 0x0FFF;  /* 80286 in real mode nature */
    }
#else /* 386+ */
#endif

  return(flags);
}


#if BX_CPU_LEVEL >= 3
  Bit32u
BX_CPU_C::read_eflags(void)
{
  Bit32u eflags_raw;

  eflags_raw =
          (get_CF()) |
          (BX_CPU_THIS_PTR eflags.bit1 << 1) |
          ((get_PF()) << 2) |
          (BX_CPU_THIS_PTR eflags.bit3 << 3) |
          ((get_AF()>0) << 4) |
          (BX_CPU_THIS_PTR eflags.bit5 << 5) |
          ((get_ZF()>0) << 6) |
          ((get_SF()>0) << 7) |
          (BX_CPU_THIS_PTR eflags.tf << 8) |
          (BX_CPU_THIS_PTR eflags.if_ << 9) |
          (BX_CPU_THIS_PTR eflags.df << 10) |
          ((get_OF()>0) << 11) |
          (BX_CPU_THIS_PTR eflags.iopl << 12) |
          (BX_CPU_THIS_PTR eflags.nt << 14) |
          (BX_CPU_THIS_PTR eflags.bit15 << 15) |
          (BX_CPU_THIS_PTR eflags.rf << 16) |
          (BX_CPU_THIS_PTR eflags.vm << 17)
#if BX_CPU_LEVEL >= 4
          | (BX_CPU_THIS_PTR eflags.ac << 18)
          | (BX_CPU_THIS_PTR eflags.id << 21)
#endif
           ;

#if 0
  /*
   * 386+: real-mode: bit15 cleared, bits 14..12 are last loaded value
   *       protected-mode: bit 15 clear, bit 14 = last loaded, IOPL?
   */
#endif

  return(eflags_raw);
}
#endif /* BX_CPU_LEVEL >= 3 */