- added instructions how to update the online documentation
[bochs-mirror.git] / cpu / flag_ctrl_pro.cc
blobe1506b9e01ece0787b3059c27b2eb38dc1447570
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: flag_ctrl_pro.cc,v 1.35 2008/08/12 19:25:42 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2001 MandrakeSoft S.A.
6 //
7 // MandrakeSoft S.A.
8 // 43, rue d'Aboukir
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
30 #include "bochs.h"
31 #include "cpu.h"
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
37 #if BX_SUPPORT_X86_64
38 if (long_mode()) {
39 if (BX_CPU_THIS_PTR get_VM()) BX_PANIC(("VM is set in long mode !"));
40 val &= ~EFlagsVMMask;
42 #endif
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();
58 #endif
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;
69 #if BX_CPU_LEVEL >= 4
70 supportMask |= (EFlagsIDMask | EFlagsACMask); // ID/AC
71 #endif
72 #if BX_SUPPORT_VME
73 supportMask |= (EFlagsVIPMask | EFlagsVIFMask); // VIP/VIF
74 #endif
76 // Screen out changing of any unsupported bits.
77 changeMask &= supportMask;
79 Bit32u newEFlags = (BX_CPU_THIS_PTR eflags & ~changeMask) |
80 (flags & changeMask);
81 setEFlags(newEFlags);
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;
92 #if BX_CPU_LEVEL >= 3
93 changeMask |= EFlagsNTMask; // NT is modified as requested.
94 if (change_IOPL)
95 changeMask |= EFlagsIOPLMask; // IOPL is modified as requested.
96 #endif
97 if (change_IF)
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) {
107 Bit32u newflags;
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;