1 |
39 |
zeus |
/////////////////////////////////////////////////////////////////////////
|
2 |
52 |
zeus |
// $Id: crregs.h,v 1.10 2008/04/16 16:44:04 sshwarts Exp $
|
3 |
39 |
zeus |
/////////////////////////////////////////////////////////////////////////
|
4 |
|
|
//
|
5 |
|
|
// Copyright (c) 2007 Stanislav Shwartsman
|
6 |
|
|
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
7 |
|
|
//
|
8 |
|
|
// This library is free software; you can redistribute it and/or
|
9 |
|
|
// modify it under the terms of the GNU Lesser General Public
|
10 |
|
|
// License as published by the Free Software Foundation; either
|
11 |
|
|
// version 2 of the License, or (at your option) any later version.
|
12 |
|
|
//
|
13 |
|
|
// This library is distributed in the hope that it will be useful,
|
14 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16 |
|
|
// Lesser General Public License for more details.
|
17 |
|
|
//
|
18 |
|
|
// You should have received a copy of the GNU Lesser General Public
|
19 |
|
|
// License along with this library; if not, write to the Free Software
|
20 |
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21 |
|
|
//
|
22 |
|
|
/////////////////////////////////////////////////////////////////////////
|
23 |
|
|
|
24 |
|
|
#ifndef BX_CRREGS
|
25 |
|
|
#define BX_CRREGS
|
26 |
|
|
|
27 |
|
|
struct bx_cr0_t {
|
28 |
|
|
Bit32u val32; // 32bit value of register
|
29 |
|
|
|
30 |
|
|
// Accessors for all cr0 bitfields.
|
31 |
|
|
#define IMPLEMENT_CRREG_ACCESSORS(name,bitnum) \
|
32 |
|
|
BX_CPP_INLINE bx_bool get_##name () { \
|
33 |
|
|
return 1 & (val32 >> bitnum); \
|
34 |
|
|
} \
|
35 |
|
|
BX_CPP_INLINE void set_##name (Bit8u val) { \
|
36 |
|
|
val32 = (val32&~(1<<bitnum)) | (val ? (1<<bitnum) : 0); \
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
// CR0 notes:
|
40 |
|
|
// Each x86 level has its own quirks regarding how it handles
|
41 |
|
|
// reserved bits. I used DOS DEBUG.EXE in real mode on the
|
42 |
|
|
// following processors, tried to clear bits 1..30, then tried
|
43 |
|
|
// to set bits 1..30, to see how these bits are handled.
|
44 |
|
|
// I found the following:
|
45 |
|
|
//
|
46 |
|
|
// Processor try to clear bits 1..30 try to set bits 1..30
|
47 |
|
|
// 386 7FFFFFF0 7FFFFFFE
|
48 |
|
|
// 486DX2 00000010 6005003E
|
49 |
|
|
// Pentium 00000010 7FFFFFFE
|
50 |
|
|
// Pentium-II 00000010 6005003E
|
51 |
|
|
//
|
52 |
|
|
// My assumptions:
|
53 |
|
|
// All processors: bit 4 is hardwired to 1 (not true on all clones)
|
54 |
|
|
// 386: bits 5..30 of CR0 are also hardwired to 1
|
55 |
|
|
// Pentium: reserved bits retain value set using mov cr0, reg32
|
56 |
|
|
// 486DX2/Pentium-II: reserved bits are hardwired to 0
|
57 |
|
|
|
58 |
|
|
//IMPLEMENT_CRREG_ACCESSORS(PE, 0);
|
59 |
|
|
BX_CPP_INLINE bx_bool get_PE () {
|
60 |
|
|
return 1 & (val32 >> 0);
|
61 |
|
|
}
|
62 |
|
|
BX_CPP_INLINE void set_PE (Bit8u val) {
|
63 |
|
|
printf("set_PE()\n");
|
64 |
|
|
val32 = (val32&~(1<<0)) | (val ? (1<<0) : 0);
|
65 |
|
|
}
|
66 |
|
|
IMPLEMENT_CRREG_ACCESSORS(MP, 1);
|
67 |
|
|
IMPLEMENT_CRREG_ACCESSORS(EM, 2);
|
68 |
|
|
IMPLEMENT_CRREG_ACCESSORS(TS, 3);
|
69 |
|
|
#if BX_CPU_LEVEL >= 4
|
70 |
|
|
IMPLEMENT_CRREG_ACCESSORS(ET, 4);
|
71 |
|
|
IMPLEMENT_CRREG_ACCESSORS(NE, 5);
|
72 |
|
|
IMPLEMENT_CRREG_ACCESSORS(AM, 18);
|
73 |
|
|
IMPLEMENT_CRREG_ACCESSORS(WP, 16);
|
74 |
|
|
IMPLEMENT_CRREG_ACCESSORS(CD, 29);
|
75 |
|
|
IMPLEMENT_CRREG_ACCESSORS(NW, 30);
|
76 |
|
|
#endif
|
77 |
|
|
IMPLEMENT_CRREG_ACCESSORS(PG, 31);
|
78 |
|
|
|
79 |
|
|
BX_CPP_INLINE Bit32u getRegister() { return val32; }
|
80 |
|
|
BX_CPP_INLINE void setRegister(Bit32u val) { if (val & 1) printf("setCR0 (PE)\n"); val32 = val; }
|
81 |
|
|
};
|
82 |
|
|
|
83 |
|
|
#if BX_CPU_LEVEL >= 4
|
84 |
|
|
struct bx_cr4_t {
|
85 |
|
|
Bit32u val32; // 32bit value of register
|
86 |
|
|
|
87 |
|
|
#if BX_SUPPORT_VME
|
88 |
|
|
IMPLEMENT_CRREG_ACCESSORS(VME, 0);
|
89 |
|
|
IMPLEMENT_CRREG_ACCESSORS(PVI, 1);
|
90 |
|
|
#endif
|
91 |
|
|
IMPLEMENT_CRREG_ACCESSORS(TSD, 2);
|
92 |
|
|
IMPLEMENT_CRREG_ACCESSORS(DE, 3);
|
93 |
|
|
IMPLEMENT_CRREG_ACCESSORS(PSE, 4);
|
94 |
|
|
IMPLEMENT_CRREG_ACCESSORS(PAE, 5);
|
95 |
|
|
IMPLEMENT_CRREG_ACCESSORS(MCE, 6);
|
96 |
|
|
IMPLEMENT_CRREG_ACCESSORS(PGE, 7);
|
97 |
|
|
IMPLEMENT_CRREG_ACCESSORS(PCE, 8);
|
98 |
|
|
IMPLEMENT_CRREG_ACCESSORS(OSFXSR, 9);
|
99 |
|
|
IMPLEMENT_CRREG_ACCESSORS(OSXMMEXCPT, 10);
|
100 |
|
|
#if BX_SUPPORT_XSAVE
|
101 |
|
|
IMPLEMENT_CRREG_ACCESSORS(OSXSAVE, 18);
|
102 |
|
|
#endif
|
103 |
|
|
|
104 |
|
|
BX_CPP_INLINE Bit32u getRegister() { return val32; }
|
105 |
|
|
BX_CPP_INLINE void setRegister(Bit32u val) { val32 = val; }
|
106 |
|
|
};
|
107 |
|
|
#endif // #if BX_CPU_LEVEL >= 4
|
108 |
|
|
|
109 |
|
|
#if BX_SUPPORT_VME
|
110 |
|
|
#define CR4_VME_ENABLED (BX_CPU_THIS_PTR cr4.get_VME())
|
111 |
|
|
#else
|
112 |
|
|
#define CR4_VME_ENABLED (0)
|
113 |
|
|
#endif
|
114 |
|
|
|
115 |
|
|
#if BX_SUPPORT_X86_64
|
116 |
|
|
|
117 |
|
|
struct bx_efer_t {
|
118 |
|
|
Bit32u val32; // 32bit value of register
|
119 |
|
|
|
120 |
|
|
IMPLEMENT_CRREG_ACCESSORS(SCE, 0);
|
121 |
|
|
IMPLEMENT_CRREG_ACCESSORS(LME, 8);
|
122 |
|
|
IMPLEMENT_CRREG_ACCESSORS(LMA, 10);
|
123 |
|
|
IMPLEMENT_CRREG_ACCESSORS(NXE, 11);
|
124 |
|
|
IMPLEMENT_CRREG_ACCESSORS(FFXSR, 14);
|
125 |
|
|
|
126 |
|
|
BX_CPP_INLINE Bit32u getRegister() { return val32; }
|
127 |
|
|
BX_CPP_INLINE void setRegister(Bit32u val) { val32 = val; }
|
128 |
|
|
};
|
129 |
|
|
|
130 |
|
|
#define BX_EFER_LMA_MASK (1<<10)
|
131 |
|
|
#define BX_EFER_SUPPORTED_BITS BX_CONST64(0x00004d01)
|
132 |
|
|
|
133 |
|
|
#endif
|
134 |
|
|
|
135 |
|
|
#if BX_SUPPORT_XSAVE
|
136 |
|
|
struct xcr0_t {
|
137 |
|
|
Bit32u val32; // 32bit value of register
|
138 |
|
|
|
139 |
|
|
#define BX_XCR0_SUPPORTED_BITS 0x3
|
140 |
|
|
|
141 |
|
|
#define BX_XCR0_FPU_BIT 0
|
142 |
|
|
#define BX_XCR0_FPU_MASK (1<<BX_XCR0_FPU_BIT)
|
143 |
|
|
#define BX_XCR0_SSE_BIT 1
|
144 |
|
|
#define BX_XCR0_SSE_MASK (1<<BX_XCR0_SSE_BIT)
|
145 |
|
|
|
146 |
|
|
IMPLEMENT_CRREG_ACCESSORS(FPU, BX_XCR0_FPU_BIT);
|
147 |
|
|
#if BX_SUPPORT_SSE
|
148 |
|
|
IMPLEMENT_CRREG_ACCESSORS(SSE, BX_XCR0_SSE_BIT);
|
149 |
|
|
#endif
|
150 |
|
|
|
151 |
|
|
BX_CPP_INLINE Bit32u getRegister() { return val32; }
|
152 |
|
|
BX_CPP_INLINE void setRegister(Bit32u val) { val32 = val; }
|
153 |
|
|
};
|
154 |
|
|
#endif
|
155 |
|
|
|
156 |
|
|
#undef IMPLEMENT_CRREG_ACCESSORS
|
157 |
|
|
|
158 |
|
|
#endif
|