1 /////////////////////////////////////////////////////////////////////////
2 // $Id: flag_ctrl_pro.cc,v 1.35 2008/08/12 19:25:42 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2001 MandrakeSoft S.A.
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 /////////////////////////////////////////////////////////////////////////
29 #define NEED_CPU_REG_SHORTCUTS 1
32 #define LOG_THIS BX_CPU_THIS_PTR
34 void BX_CPP_AttrRegparmN(1) BX_CPU_C::setEFlags(Bit32u val
)
36 // VM flag could not be set from long mode
39 if (BX_CPU_THIS_PTR
get_VM()) BX_PANIC(("VM is set in long mode !"));
44 if (val
& EFlagsTFMask
) {
45 BX_CPU_THIS_PTR async_event
= 1; // TF = 1
48 if (val
& EFlagsIFMask
) {
49 if (! BX_CPU_THIS_PTR
get_IF())
50 BX_CPU_THIS_PTR async_event
= 1; // IF bit was set
53 BX_CPU_THIS_PTR eflags
= val
;
54 BX_CPU_THIS_PTR lf_flags_status
= 0; // OSZAPC flags are known.
56 #if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
57 handleAlignmentCheck();
60 handleCpuModeChange(); // VM flag might be changed
63 void BX_CPP_AttrRegparmN(2)
64 BX_CPU_C::writeEFlags(Bit32u flags
, Bit32u changeMask
)
66 // Build a mask of the non-reserved bits:
67 // ID,VIP,VIF,AC,VM,RF,x,NT,IOPL,OF,DF,IF,TF,SF,ZF,x,AF,x,PF,x,CF
68 Bit32u supportMask
= 0x00037fd5;
70 supportMask
|= (EFlagsIDMask
| EFlagsACMask
); // ID/AC
73 supportMask
|= (EFlagsVIPMask
| EFlagsVIFMask
); // VIP/VIF
76 // Screen out changing of any unsupported bits.
77 changeMask
&= supportMask
;
79 Bit32u newEFlags
= (BX_CPU_THIS_PTR eflags
& ~changeMask
) |
82 // OSZAPC flags are known - done in setEFlags(newEFlags)
85 void BX_CPP_AttrRegparmN(3)
86 BX_CPU_C::write_flags(Bit16u flags
, bx_bool change_IOPL
, bx_bool change_IF
)
88 // Build a mask of the following bits:
89 // x,NT,IOPL,OF,DF,IF,TF,SF,ZF,x,AF,x,PF,x,CF
90 Bit32u changeMask
= 0x0dd5;
93 changeMask
|= EFlagsNTMask
; // NT is modified as requested.
95 changeMask
|= EFlagsIOPLMask
; // IOPL is modified as requested.
98 changeMask
|= EFlagsIFMask
;
100 writeEFlags(Bit32u(flags
), changeMask
);
103 // Cause arithmetic flags to be in known state and cached in val32.
104 Bit32u
BX_CPU_C::force_flags(void)
106 if (BX_CPU_THIS_PTR lf_flags_status
) {
109 newflags
= get_CF() ? EFlagsCFMask
: 0;
110 newflags
|= get_PF() ? EFlagsPFMask
: 0;
111 newflags
|= get_AF() ? EFlagsAFMask
: 0;
112 newflags
|= get_ZF() ? EFlagsZFMask
: 0;
113 newflags
|= get_SF() ? EFlagsSFMask
: 0;
114 newflags
|= get_OF() ? EFlagsOFMask
: 0;
116 setEFlagsOSZAPC(newflags
);
119 return BX_CPU_THIS_PTR eflags
;