forked from b-dmitry1/e86r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
x86.cpp
178 lines (159 loc) · 3.19 KB
/
x86.cpp
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
#include "stdafx.h"
#include "cpu.h"
#include "interrupts.h"
#include "memdescr.h"
#include "modrm.h"
#include "ioports.h"
void verr(unsigned short sel)
{
r.eflags &= ~F_Z;
if (sel < 4)
return;
descr_t d;
if (!get_descr(&d, sel, 1))
return;
switch (d.type)
{
case DESCR_CODE_C_R:
case DESCR_CODE_C_R_A:
r.eflags |= F_Z;
break;
case DESCR_DATA_DN:
case DESCR_DATA_DN_A:
case DESCR_DATA_DN_W:
case DESCR_DATA_DN_W_A:
case DESCR_DATA_UP:
case DESCR_DATA_UP_A:
case DESCR_DATA_UP_W:
case DESCR_DATA_UP_W_A:
case DESCR_CODE_R:
case DESCR_CODE_R_A:
if (!((d.dpl < cpl) || (d.dpl < (sel & 3u))))
r.eflags |= F_Z;
break;
}
}
void verw(unsigned short sel)
{
r.eflags &= ~F_Z;
if (sel < 4)
return;
descr_t d;
if (!get_descr(&d, sel, 1))
return;
switch (d.type)
{
case DESCR_DATA_DN_W:
case DESCR_DATA_DN_W_A:
case DESCR_DATA_UP_W:
case DESCR_DATA_UP_W_A:
if (!((d.dpl < cpl) || (d.dpl < (sel & 3u))))
r.eflags |= F_Z;
break;
}
}
unsigned int lar(unsigned short sel)
{
r.eflags &= ~F_Z;
if (sel < 4)
return 0;
descr_t d;
unsigned int *p = (unsigned int *)&d;
if (!get_descr(&d, sel, 1))
return 0;
switch (d.type)
{
case DESCR_CODE_C:
case DESCR_CODE_C_A:
case DESCR_CODE_C_R:
case DESCR_CODE_C_R_A:
break;
case DESCR_DATA_DN:
case DESCR_DATA_DN_A:
case DESCR_DATA_DN_W:
case DESCR_DATA_DN_W_A:
case DESCR_DATA_UP:
case DESCR_DATA_UP_A:
case DESCR_DATA_UP_W:
case DESCR_DATA_UP_W_A:
case DESCR_CODE:
case DESCR_CODE_A:
case DESCR_CODE_R:
case DESCR_CODE_R_A:
case DESCR_LDT:
case DESCR_TASK_GATE:
case DESCR_286_TSS_AVAIL:
case DESCR_286_TSS_BUSY:
case DESCR_386_TSS_AVAIL:
case DESCR_386_TSS_BUSY:
case DESCR_286_CALL_GATE:
case DESCR_386_CALL_GATE:
if ((d.dpl < cpl) || (d.dpl < (sel & 3u)))
return 0;
break;
default:
return 0;
}
r.eflags |= F_Z;
return p[1] & 0x00FFFF00u;
}
unsigned int lsl(unsigned short sel)
{
r.eflags &= ~F_Z;
if (sel < 4)
return 0;
descr_t d;
if (!get_descr(&d, sel, 1))
return 0;
switch (d.type)
{
case DESCR_CODE_C:
case DESCR_CODE_C_A:
case DESCR_CODE_C_R:
case DESCR_CODE_C_R_A:
break;
case DESCR_DATA_DN:
case DESCR_DATA_DN_A:
case DESCR_DATA_DN_W:
case DESCR_DATA_DN_W_A:
case DESCR_DATA_UP:
case DESCR_DATA_UP_A:
case DESCR_DATA_UP_W:
case DESCR_DATA_UP_W_A:
case DESCR_CODE:
case DESCR_CODE_A:
case DESCR_CODE_R:
case DESCR_CODE_R_A:
case DESCR_LDT:
case DESCR_286_TSS_AVAIL:
case DESCR_286_TSS_BUSY:
case DESCR_386_TSS_AVAIL:
case DESCR_386_TSS_BUSY:
if ((d.dpl < cpl) || (d.dpl < (sel & 3u)))
return 0;
break;
default:
return 0;
}
r.eflags |= F_Z;
return get_limit(&d);
}
void lmsw(unsigned int v)
{
if ((cr[0] & 1) && (cpl > 0))
{
ex(EX_GP, 0);
return;
}
v &= 0x0F;
v |= cr[0] & 0xFFFFFFF1;
cr[0] = v;
#if (ENABLE_FPU == 1)
cr[0] |= CR0_MP | CR0_ET;
#else
cr[0] &= ~(CR0_MP | CR0_ET);
#endif
pmode = cr[0] & 1;
paging = (cr[0] & 0x80000000u) != 0;
dir = (unsigned int *)&ram[cr[3] & 0xFFFFF000u];
}