1 |
2 |
alfik |
#include <cstdio>
|
2 |
|
|
#include <cstdlib>
|
3 |
|
|
|
4 |
|
|
#include "bochs.h"
|
5 |
|
|
#include "cpu.h"
|
6 |
|
|
#include "iodev/iodev.h"
|
7 |
|
|
|
8 |
|
|
//------------------------------------------------------------------------------
|
9 |
|
|
//------------------------------------------------------------------------------
|
10 |
|
|
//------------------------------------------------------------------------------
|
11 |
|
|
|
12 |
|
|
int test_type;
|
13 |
|
|
|
14 |
|
|
bool load_segment(bx_segment_reg_t *seg, const char *prefix, char *name, unsigned long long value) {
|
15 |
|
|
|
16 |
|
|
if(strncmp(name, prefix, strlen(prefix)) == 0 && strcmp(name+strlen(prefix), "cache_valid:") == 0) { seg->cache.valid = value & 1; }
|
17 |
|
|
|
18 |
|
|
else if( (strncmp(name, "cs:", 3) == 0 && strcmp(prefix, "cs_") == 0) ||
|
19 |
|
|
(strncmp(name, "ds:", 3) == 0 && strcmp(prefix, "ds_") == 0) ||
|
20 |
|
|
(strncmp(name, "es:", 3) == 0 && strcmp(prefix, "es_") == 0) ||
|
21 |
|
|
(strncmp(name, "fs:", 3) == 0 && strcmp(prefix, "fs_") == 0) ||
|
22 |
|
|
(strncmp(name, "gs:", 3) == 0 && strcmp(prefix, "gs_") == 0) ||
|
23 |
|
|
(strncmp(name, "ss:", 3) == 0 && strcmp(prefix, "ss_") == 0) ||
|
24 |
|
|
(strncmp(name, "ldtr:", 5) == 0 && strcmp(prefix, "ldtr_") == 0) ||
|
25 |
|
|
(strncmp(name, "tr:", 3) == 0 && strcmp(prefix, "tr_") == 0) )
|
26 |
|
|
{
|
27 |
|
|
seg->selector.value = value & 0xFFFF;
|
28 |
|
|
seg->selector.index = value >> 3;
|
29 |
|
|
seg->selector.ti = (value >> 2) & 1;
|
30 |
|
|
seg->selector.rpl = value & 3;
|
31 |
|
|
}
|
32 |
|
|
else if(strncmp(name, prefix, strlen(prefix)) == 0 && strcmp(name+strlen(prefix), "rpl:") == 0) { seg->selector.rpl = value & 3; }
|
33 |
|
|
else if(strncmp(name, prefix, strlen(prefix)) == 0 && strcmp(name+strlen(prefix), "base:") == 0) { seg->cache.u.segment.base = value & 0xFFFFFFFF; }
|
34 |
|
|
else if(strncmp(name, prefix, strlen(prefix)) == 0 && strcmp(name+strlen(prefix), "limit:") == 0) {
|
35 |
|
|
seg->cache.u.segment.limit_scaled = value & 0xFFFFF;
|
36 |
|
|
if(seg->cache.u.segment.g) seg->cache.u.segment.limit_scaled = (seg->cache.u.segment.limit_scaled << 12) | 0xFFF;
|
37 |
|
|
}
|
38 |
|
|
else if(strncmp(name, prefix, strlen(prefix)) == 0 && strcmp(name+strlen(prefix), "g:") == 0) {
|
39 |
|
|
seg->cache.u.segment.g = value & 1;
|
40 |
|
|
if(seg->cache.u.segment.g) seg->cache.u.segment.limit_scaled = (seg->cache.u.segment.limit_scaled << 12) | 0xFFF;
|
41 |
|
|
}
|
42 |
|
|
else if(strncmp(name, prefix, strlen(prefix)) == 0 && strcmp(name+strlen(prefix), "d_b:") == 0) { seg->cache.u.segment.d_b = value & 1; }
|
43 |
|
|
else if(strncmp(name, prefix, strlen(prefix)) == 0 && strcmp(name+strlen(prefix), "avl:") == 0) { seg->cache.u.segment.avl = value & 1; }
|
44 |
|
|
else if(strncmp(name, prefix, strlen(prefix)) == 0 && strcmp(name+strlen(prefix), "p:") == 0) { seg->cache.p = value & 1; }
|
45 |
|
|
else if(strncmp(name, prefix, strlen(prefix)) == 0 && strcmp(name+strlen(prefix), "dpl:") == 0) { seg->cache.dpl = value & 3; }
|
46 |
|
|
else if(strncmp(name, prefix, strlen(prefix)) == 0 && strcmp(name+strlen(prefix), "s:") == 0) { seg->cache.segment = value & 1; }
|
47 |
|
|
else if(strncmp(name, prefix, strlen(prefix)) == 0 && strcmp(name+strlen(prefix), "type:") == 0) { seg->cache.type = value & 15; }
|
48 |
|
|
else return false;
|
49 |
|
|
|
50 |
|
|
return true;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
void initialize() {
|
54 |
|
|
printf("start_input: 0\n");
|
55 |
|
|
printf("\n");
|
56 |
|
|
fflush(stdout);
|
57 |
|
|
|
58 |
|
|
bool do_loop = true;
|
59 |
|
|
|
60 |
|
|
char name[256];
|
61 |
|
|
unsigned long long value;
|
62 |
|
|
|
63 |
|
|
while(do_loop) {
|
64 |
|
|
|
65 |
|
|
fscanf(stdin, "%s", name);
|
66 |
|
|
fscanf(stdin, "%x", &value);
|
67 |
|
|
|
68 |
|
|
if (strcmp(name, "quit:") == 0) { exit(0); }
|
69 |
|
|
else if(strcmp(name, "continue:") == 0) { do_loop = false; }
|
70 |
|
|
|
71 |
|
|
else if(strcmp(name, "test_type:") == 0) { test_type = value; }
|
72 |
|
|
|
73 |
|
|
else if(strcmp(name, "eax:") == 0) { bx_cpu.set_reg32(BX_32BIT_REG_EAX, value); }
|
74 |
|
|
else if(strcmp(name, "ebx:") == 0) { bx_cpu.set_reg32(BX_32BIT_REG_EBX, value); }
|
75 |
|
|
else if(strcmp(name, "ecx:") == 0) { bx_cpu.set_reg32(BX_32BIT_REG_ECX, value); }
|
76 |
|
|
else if(strcmp(name, "edx:") == 0) { bx_cpu.set_reg32(BX_32BIT_REG_EDX, value); }
|
77 |
|
|
else if(strcmp(name, "esi:") == 0) { bx_cpu.set_reg32(BX_32BIT_REG_ESI, value); }
|
78 |
|
|
else if(strcmp(name, "edi:") == 0) { bx_cpu.set_reg32(BX_32BIT_REG_EDI, value); }
|
79 |
|
|
else if(strcmp(name, "ebp:") == 0) { bx_cpu.set_reg32(BX_32BIT_REG_EBP, value); }
|
80 |
|
|
else if(strcmp(name, "esp:") == 0) { bx_cpu.set_reg32(BX_32BIT_REG_ESP, value); }
|
81 |
|
|
|
82 |
|
|
else if(strcmp(name, "eip:") == 0) { bx_cpu.gen_reg[BX_32BIT_REG_EIP].dword.erx = value; }
|
83 |
|
|
|
84 |
|
|
else if(strcmp(name, "cflag:") == 0) { bx_cpu.set_CF(value); }
|
85 |
|
|
else if(strcmp(name, "pflag:") == 0) { bx_cpu.set_PF(value); }
|
86 |
|
|
else if(strcmp(name, "aflag:") == 0) { bx_cpu.set_AF(value); }
|
87 |
|
|
else if(strcmp(name, "zflag:") == 0) { bx_cpu.set_ZF(value); }
|
88 |
|
|
else if(strcmp(name, "sflag:") == 0) { bx_cpu.set_SF(value); }
|
89 |
|
|
else if(strcmp(name, "tflag:") == 0) { bx_cpu.set_TF(value); }
|
90 |
|
|
else if(strcmp(name, "iflag:") == 0) { bx_cpu.set_IF(value); }
|
91 |
|
|
else if(strcmp(name, "dflag:") == 0) { bx_cpu.set_DF(value); }
|
92 |
|
|
else if(strcmp(name, "oflag:") == 0) { bx_cpu.set_OF(value); }
|
93 |
|
|
else if(strcmp(name, "iopl:") == 0) { bx_cpu.set_IOPL(value); }
|
94 |
|
|
else if(strcmp(name, "ntflag:") == 0) { bx_cpu.set_NT(value); }
|
95 |
|
|
else if(strcmp(name, "rflag:") == 0) { bx_cpu.set_RF(value); }
|
96 |
|
|
else if(strcmp(name, "vmflag:") == 0) { bx_cpu.set_VM(value); }
|
97 |
|
|
else if(strcmp(name, "acflag:") == 0) { bx_cpu.set_AC(value); }
|
98 |
|
|
else if(strcmp(name, "idflag:") == 0) { bx_cpu.set_ID(value); }
|
99 |
|
|
|
100 |
|
|
else if(load_segment(&(bx_cpu.sregs[BX_SEG_REG_CS]), "cs_", name, value)) { }
|
101 |
|
|
else if(load_segment(&(bx_cpu.sregs[BX_SEG_REG_DS]), "ds_", name, value)) { }
|
102 |
|
|
else if(load_segment(&(bx_cpu.sregs[BX_SEG_REG_ES]), "es_", name, value)) { }
|
103 |
|
|
else if(load_segment(&(bx_cpu.sregs[BX_SEG_REG_FS]), "fs_", name, value)) { }
|
104 |
|
|
else if(load_segment(&(bx_cpu.sregs[BX_SEG_REG_GS]), "gs_", name, value)) { }
|
105 |
|
|
else if(load_segment(&(bx_cpu.sregs[BX_SEG_REG_SS]), "ss_", name, value)) { }
|
106 |
|
|
else if(load_segment(&(bx_cpu.ldtr), "ldtr_", name, value)) { }
|
107 |
|
|
else if(load_segment(&(bx_cpu.tr), "tr_", name, value)) { }
|
108 |
|
|
|
109 |
|
|
else if(strcmp(name, "gdtr_base:") == 0) { bx_cpu.gdtr.base = value & 0xFFFFFFFF; }
|
110 |
|
|
else if(strcmp(name, "gdtr_limit:") == 0){ bx_cpu.gdtr.limit = value & 0xFFFF; }
|
111 |
|
|
|
112 |
|
|
else if(strcmp(name, "idtr_base:") == 0) { bx_cpu.idtr.base = value & 0xFFFFFFFF; }
|
113 |
|
|
else if(strcmp(name, "idtr_limit:") == 0){ bx_cpu.idtr.limit = value & 0xFFFF; }
|
114 |
|
|
|
115 |
|
|
else if(strcmp(name, "cr0_pe:") == 0) { bx_cpu.cr0.set_PE(value & 1); }
|
116 |
|
|
else if(strcmp(name, "cr0_mp:") == 0) { bx_cpu.cr0.set_MP(value & 1); }
|
117 |
|
|
else if(strcmp(name, "cr0_em:") == 0) { bx_cpu.cr0.set_EM(value & 1); }
|
118 |
|
|
else if(strcmp(name, "cr0_ts:") == 0) { bx_cpu.cr0.set_TS(value & 1); }
|
119 |
|
|
else if(strcmp(name, "cr0_ne:") == 0) { bx_cpu.cr0.set_NE(value & 1); }
|
120 |
|
|
else if(strcmp(name, "cr0_wp:") == 0) { bx_cpu.cr0.set_WP(value & 1); }
|
121 |
|
|
else if(strcmp(name, "cr0_am:") == 0) { bx_cpu.cr0.set_AM(value & 1); }
|
122 |
|
|
else if(strcmp(name, "cr0_nw:") == 0) { bx_cpu.cr0.set_NW(value & 1); }
|
123 |
|
|
else if(strcmp(name, "cr0_cd:") == 0) { bx_cpu.cr0.set_CD(value & 1); }
|
124 |
|
|
else if(strcmp(name, "cr0_pg:") == 0) { bx_cpu.cr0.set_PG(value & 1); }
|
125 |
|
|
|
126 |
|
|
else if(strcmp(name, "cr2:") == 0) { bx_cpu.cr2 = value & 0xFFFFFFFF; }
|
127 |
|
|
else if(strcmp(name, "cr3:") == 0) { bx_cpu.cr3 = value & 0xFFFFFFFF; }
|
128 |
|
|
|
129 |
|
|
else if(strcmp(name, "dr0:") == 0) { bx_cpu.dr[0] = value & 0xFFFFFFFF; }
|
130 |
|
|
else if(strcmp(name, "dr1:") == 0) { bx_cpu.dr[1] = value & 0xFFFFFFFF; }
|
131 |
|
|
else if(strcmp(name, "dr2:") == 0) { bx_cpu.dr[2] = value & 0xFFFFFFFF; }
|
132 |
|
|
else if(strcmp(name, "dr3:") == 0) { bx_cpu.dr[3] = value & 0xFFFFFFFF; }
|
133 |
|
|
|
134 |
|
|
else if(strcmp(name, "dr6:") == 0) { bx_cpu.dr6.val32 = (bx_cpu.dr6.val32 & 0xffff0ff0) | (value & 0x0000f00f); }
|
135 |
|
|
else if(strcmp(name, "dr7:") == 0) { bx_cpu.dr7.val32 = value | 0x00000400; }
|
136 |
|
|
|
137 |
|
|
else {
|
138 |
|
|
printf("#bochs486: unknown input: %s %x\n", name, value);
|
139 |
|
|
exit(-1);
|
140 |
|
|
}
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
void print_segment(bx_segment_reg_t *seg, const char *prefix) {
|
145 |
|
|
|
146 |
|
|
printf("%s_cache_valid: %01x\n", prefix, seg->cache.valid & 1);
|
147 |
|
|
printf("%s: %04x\n", prefix, seg->selector.value);
|
148 |
|
|
printf("%s_rpl: %01hhx\n", prefix, seg->selector.rpl);
|
149 |
|
|
|
150 |
|
|
printf("%s_base: %08x\n", prefix, seg->cache.u.segment.base);
|
151 |
|
|
printf("%s_limit: %08x\n", prefix, (seg->cache.u.segment.g)? seg->cache.u.segment.limit_scaled >> 12 : seg->cache.u.segment.limit_scaled);
|
152 |
|
|
printf("%s_g: %01x\n", prefix, seg->cache.u.segment.g);
|
153 |
|
|
printf("%s_d_b: %01x\n", prefix, seg->cache.u.segment.d_b);
|
154 |
|
|
printf("%s_avl: %01x\n", prefix, seg->cache.u.segment.avl);
|
155 |
|
|
printf("%s_p: %01x\n", prefix, seg->cache.p);
|
156 |
|
|
printf("%s_dpl: %01x\n", prefix, seg->cache.dpl);
|
157 |
|
|
printf("%s_s: %01x\n", prefix, seg->cache.segment);
|
158 |
|
|
printf("%s_type: %01x\n", prefix, seg->cache.type);
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
void output_cpu_state() {
|
162 |
|
|
printf("start_output: 0\n");
|
163 |
|
|
|
164 |
|
|
//used only in verilog testbench
|
165 |
|
|
printf("tb_wr_cmd_last: 0\n");
|
166 |
|
|
printf("tb_can_ignore: 0\n");
|
167 |
|
|
|
168 |
|
|
printf("eax: %08x\n", bx_cpu.get_reg32(BX_32BIT_REG_EAX));
|
169 |
|
|
printf("ebx: %08x\n", bx_cpu.get_reg32(BX_32BIT_REG_EBX));
|
170 |
|
|
printf("ecx: %08x\n", bx_cpu.get_reg32(BX_32BIT_REG_ECX));
|
171 |
|
|
printf("edx: %08x\n", bx_cpu.get_reg32(BX_32BIT_REG_EDX));
|
172 |
|
|
printf("esi: %08x\n", bx_cpu.get_reg32(BX_32BIT_REG_ESI));
|
173 |
|
|
printf("edi: %08x\n", bx_cpu.get_reg32(BX_32BIT_REG_EDI));
|
174 |
|
|
printf("ebp: %08x\n", bx_cpu.get_reg32(BX_32BIT_REG_EBP));
|
175 |
|
|
printf("esp: %08x\n", bx_cpu.get_reg32(BX_32BIT_REG_ESP));
|
176 |
|
|
|
177 |
|
|
printf("eip: %08x\n", bx_cpu.gen_reg[BX_32BIT_REG_EIP].dword.erx);
|
178 |
|
|
|
179 |
|
|
printf("cflag: %01x\n", bx_cpu.getB_CF());
|
180 |
|
|
printf("pflag: %01x\n", bx_cpu.getB_PF());
|
181 |
|
|
printf("aflag: %01x\n", bx_cpu.getB_AF());
|
182 |
|
|
printf("zflag: %01x\n", bx_cpu.getB_ZF());
|
183 |
|
|
printf("sflag: %01x\n", bx_cpu.getB_SF());
|
184 |
|
|
printf("tflag: %01x\n", bx_cpu.getB_TF()&1);
|
185 |
|
|
printf("iflag: %01x\n", bx_cpu.getB_IF()&1);
|
186 |
|
|
printf("dflag: %01x\n", bx_cpu.getB_DF()&1);
|
187 |
|
|
printf("oflag: %01x\n", bx_cpu.getB_OF()&1);
|
188 |
|
|
printf("iopl: %01x\n", bx_cpu.get_IOPL()&3);
|
189 |
|
|
printf("ntflag: %01x\n", bx_cpu.getB_NT()&1);
|
190 |
|
|
printf("rflag: %01x\n", bx_cpu.getB_RF()&1);
|
191 |
|
|
printf("vmflag: %01x\n", bx_cpu.getB_VM()&1);
|
192 |
|
|
printf("acflag: %01x\n", bx_cpu.getB_AC()&1);
|
193 |
|
|
printf("idflag: %01x\n", bx_cpu.getB_ID()&1);
|
194 |
|
|
|
195 |
|
|
print_segment(&(bx_cpu.sregs[BX_SEG_REG_CS]), "cs");
|
196 |
|
|
print_segment(&(bx_cpu.sregs[BX_SEG_REG_DS]), "ds");
|
197 |
|
|
print_segment(&(bx_cpu.sregs[BX_SEG_REG_ES]), "es");
|
198 |
|
|
print_segment(&(bx_cpu.sregs[BX_SEG_REG_FS]), "fs");
|
199 |
|
|
print_segment(&(bx_cpu.sregs[BX_SEG_REG_GS]), "gs");
|
200 |
|
|
print_segment(&(bx_cpu.sregs[BX_SEG_REG_SS]), "ss");
|
201 |
|
|
print_segment(&(bx_cpu.ldtr), "ldtr");
|
202 |
|
|
print_segment(&(bx_cpu.tr), "tr");
|
203 |
|
|
|
204 |
|
|
printf("gdtr_base: %08x\n", bx_cpu.gdtr.base);
|
205 |
|
|
printf("gdtr_limit: %02x\n", bx_cpu.gdtr.limit & 0xFFFF);
|
206 |
|
|
|
207 |
|
|
printf("idtr_base: %08x\n", bx_cpu.idtr.base);
|
208 |
|
|
printf("idtr_limit: %02x\n", bx_cpu.idtr.limit & 0xFFFF);
|
209 |
|
|
|
210 |
|
|
printf("cr0_pe: %01x\n", bx_cpu.cr0.get_PE() & 1);
|
211 |
|
|
printf("cr0_mp: %01x\n", bx_cpu.cr0.get_MP() & 1);
|
212 |
|
|
printf("cr0_em: %01x\n", bx_cpu.cr0.get_EM() & 1);
|
213 |
|
|
printf("cr0_ts: %01x\n", bx_cpu.cr0.get_TS() & 1);
|
214 |
|
|
printf("cr0_ne: %01x\n", bx_cpu.cr0.get_NE() & 1);
|
215 |
|
|
printf("cr0_wp: %01x\n", bx_cpu.cr0.get_WP() & 1);
|
216 |
|
|
printf("cr0_am: %01x\n", bx_cpu.cr0.get_AM() & 1);
|
217 |
|
|
printf("cr0_nw: %01x\n", bx_cpu.cr0.get_NW() & 1);
|
218 |
|
|
printf("cr0_cd: %01x\n", bx_cpu.cr0.get_CD() & 1);
|
219 |
|
|
printf("cr0_pg: %01x\n", bx_cpu.cr0.get_PG() & 1);
|
220 |
|
|
|
221 |
|
|
printf("cr2: %08x\n", bx_cpu.cr2);
|
222 |
|
|
printf("cr3: %08x\n", bx_cpu.cr3);
|
223 |
|
|
|
224 |
|
|
printf("dr0: %08x\n", bx_cpu.dr[0]);
|
225 |
|
|
printf("dr1: %08x\n", bx_cpu.dr[1]);
|
226 |
|
|
printf("dr2: %08x\n", bx_cpu.dr[2]);
|
227 |
|
|
printf("dr3: %08x\n", bx_cpu.dr[3]);
|
228 |
|
|
|
229 |
|
|
printf("dr6: %08x\n", bx_cpu.dr6.val32);
|
230 |
|
|
printf("dr7: %08x\n", bx_cpu.dr7.val32);
|
231 |
|
|
|
232 |
|
|
printf("\n");
|
233 |
|
|
fflush(stdout);
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
|
237 |
|
|
//------------------------------------------------------------------------------
|
238 |
|
|
//------------------------------------------------------------------------------
|
239 |
|
|
//------------------------------------------------------------------------------ logfunctions
|
240 |
|
|
|
241 |
|
|
void logfunctions::panic(const char *fmt, ...) {
|
242 |
|
|
printf("#bochs486::logfunctions::panic(): ");
|
243 |
|
|
|
244 |
|
|
va_list ap;
|
245 |
|
|
va_start(ap, fmt);
|
246 |
|
|
vprintf(fmt, ap);
|
247 |
|
|
va_end(ap);
|
248 |
|
|
|
249 |
|
|
printf("\n");
|
250 |
|
|
fflush(stdout);
|
251 |
|
|
|
252 |
|
|
if(strstr(fmt, "exception with no resolution") != NULL) {
|
253 |
|
|
printf("start_shutdown: 0\n");
|
254 |
|
|
printf("\n");
|
255 |
|
|
fflush(stdout);
|
256 |
|
|
exit(0);
|
257 |
|
|
}
|
258 |
|
|
else {
|
259 |
|
|
exit(-1);
|
260 |
|
|
}
|
261 |
|
|
}
|
262 |
|
|
void logfunctions::error(const char *fmt, ...) {
|
263 |
|
|
printf("#bochs486::logfunctions::error(): ");
|
264 |
|
|
|
265 |
|
|
va_list ap;
|
266 |
|
|
va_start(ap, fmt);
|
267 |
|
|
vprintf(fmt, ap);
|
268 |
|
|
va_end(ap);
|
269 |
|
|
|
270 |
|
|
printf("\n");
|
271 |
|
|
fflush(stdout);
|
272 |
|
|
}
|
273 |
|
|
void logfunctions::ldebug(const char *fmt, ...) {
|
274 |
|
|
printf("#bochs486::logfunctions::debug(): ");
|
275 |
|
|
|
276 |
|
|
va_list ap;
|
277 |
|
|
va_start(ap, fmt);
|
278 |
|
|
vprintf(fmt, ap);
|
279 |
|
|
va_end(ap);
|
280 |
|
|
|
281 |
|
|
printf("\n");
|
282 |
|
|
fflush(stdout);
|
283 |
|
|
}
|
284 |
|
|
void logfunctions::info(const char *fmt, ...) {
|
285 |
|
|
printf("#bochs486::logfunctions::info(): ");
|
286 |
|
|
|
287 |
|
|
va_list ap;
|
288 |
|
|
va_start(ap, fmt);
|
289 |
|
|
vprintf(fmt, ap);
|
290 |
|
|
va_end(ap);
|
291 |
|
|
|
292 |
|
|
printf("\n");
|
293 |
|
|
fflush(stdout);
|
294 |
|
|
}
|
295 |
|
|
void logfunctions::put(const char *n, const char *p) {
|
296 |
|
|
}
|
297 |
|
|
logfunctions::logfunctions() {
|
298 |
|
|
}
|
299 |
|
|
logfunctions::~logfunctions() {
|
300 |
|
|
}
|
301 |
|
|
|
302 |
|
|
static logfunctions theLog;
|
303 |
|
|
logfunctions *pluginlog = &theLog;
|
304 |
|
|
logfunctions *siminterface_log = &theLog;
|
305 |
|
|
|
306 |
|
|
//------------------------------------------------------------------------------
|
307 |
|
|
//------------------------------------------------------------------------------
|
308 |
|
|
//------------------------------------------------------------------------------ menu
|
309 |
|
|
|
310 |
|
|
void bx_param_string_c::text_print(FILE *fp) {
|
311 |
|
|
printf("#bochs486::bx_param_string_c::text_print()\n");
|
312 |
|
|
}
|
313 |
|
|
void bx_param_enum_c::text_print(FILE *fp) {
|
314 |
|
|
printf("#bochs486::bx_param_enum_c::text_print()\n");
|
315 |
|
|
}
|
316 |
|
|
void bx_param_bool_c::text_print(FILE *fp) {
|
317 |
|
|
printf("#bochs486::bx_param_bool_c::text_print()\n");
|
318 |
|
|
}
|
319 |
|
|
void bx_param_num_c::text_print(FILE *fp) {
|
320 |
|
|
printf("#bochs486::bx_param_num_c::text_print()\n");
|
321 |
|
|
}
|
322 |
|
|
void bx_list_c::text_print(FILE *fp) {
|
323 |
|
|
printf("#bochs486::bx_list_c::text_print()\n");
|
324 |
|
|
}
|
325 |
|
|
int bx_param_enum_c::text_ask(FILE *fpin, FILE *fpout) {
|
326 |
|
|
printf("#bochs486::bx_param_enum_c::text_ask()\n");
|
327 |
|
|
return 0;
|
328 |
|
|
}
|
329 |
|
|
int bx_param_bool_c::text_ask(FILE *fpin, FILE *fpout) {
|
330 |
|
|
printf("#bochs486::bx_param_bool_c::text_ask()\n");
|
331 |
|
|
return 0;
|
332 |
|
|
}
|
333 |
|
|
int bx_param_num_c::text_ask(FILE *fpin, FILE *fpout) {
|
334 |
|
|
printf("#bochs486::bx_param_num_c::text_ask()\n");
|
335 |
|
|
return 0;
|
336 |
|
|
}
|
337 |
|
|
int bx_param_string_c::text_ask(FILE *fpin, FILE *fpout) {
|
338 |
|
|
printf("#bochs486::bx_param_string_c::text_ask()\n");
|
339 |
|
|
return 0;
|
340 |
|
|
}
|
341 |
|
|
int bx_list_c::text_ask(FILE *fpin, FILE *fpout) {
|
342 |
|
|
printf("#bochs486::bx_list_c::text_ask()\n");
|
343 |
|
|
return 0;
|
344 |
|
|
}
|
345 |
|
|
|
346 |
|
|
bx_list_c *root_param = NULL;
|
347 |
|
|
|
348 |
|
|
bx_gui_c *bx_gui = NULL;
|
349 |
|
|
|
350 |
|
|
//------------------------------------------------------------------------------
|
351 |
|
|
//------------------------------------------------------------------------------
|
352 |
|
|
//------------------------------------------------------------------------------ cpu
|
353 |
|
|
|
354 |
|
|
void BX_CPU_C::enter_system_management_mode(void) {
|
355 |
|
|
printf("#bochs486: enter_system_management_mod()\n");
|
356 |
|
|
}
|
357 |
|
|
void BX_CPU_C::init_SMRAM(void) {
|
358 |
|
|
printf("#bochs486: init_SMRAM()\n");
|
359 |
|
|
}
|
360 |
|
|
void BX_CPU_C::debug(bx_address offset) {
|
361 |
|
|
printf("#bochs486: debug(offset=%08x)\n", offset);
|
362 |
|
|
}
|
363 |
|
|
void BX_CPU_C::debug_disasm_instruction(bx_address offset) {
|
364 |
|
|
printf("#bochs486: debug_disasm_instruction(offset=%08x)\n", offset);
|
365 |
|
|
}
|
366 |
|
|
|
367 |
|
|
//------------------------------------------------------------------------------
|
368 |
|
|
//------------------------------------------------------------------------------
|
369 |
|
|
//------------------------------------------------------------------------------ pc_system
|
370 |
|
|
|
371 |
|
|
void bx_pc_system_c::countdownEvent(void) {
|
372 |
|
|
}
|
373 |
|
|
bx_pc_system_c::bx_pc_system_c() {
|
374 |
|
|
}
|
375 |
|
|
int bx_pc_system_c::Reset(unsigned type) {
|
376 |
|
|
printf("#bochs486: bx_pc_system_c::Reset(%d) unimplemented.\n", type);
|
377 |
|
|
std::exit(-1);
|
378 |
|
|
}
|
379 |
|
|
|
380 |
|
|
bx_pc_system_c bx_pc_system;
|
381 |
|
|
|
382 |
|
|
const char* cpu_mode_string(unsigned cpu_mode) {
|
383 |
|
|
static const char *cpu_mode_name[] = {
|
384 |
|
|
"real mode",
|
385 |
|
|
"v8086 mode",
|
386 |
|
|
"protected mode",
|
387 |
|
|
"compatibility mode",
|
388 |
|
|
"long mode",
|
389 |
|
|
"unknown mode"
|
390 |
|
|
};
|
391 |
|
|
|
392 |
|
|
if(cpu_mode >= 5) cpu_mode = 5;
|
393 |
|
|
return cpu_mode_name[cpu_mode];
|
394 |
|
|
}
|
395 |
|
|
|
396 |
|
|
bx_param_string_c *param_vendor_string;
|
397 |
|
|
bx_param_string_c *param_brand_string;
|
398 |
|
|
bx_param_bool_c *param_bool_false;
|
399 |
|
|
bx_param_enum_c *param_enum_zero;
|
400 |
|
|
bx_param_num_c *param_stepping, *param_model, *param_family;
|
401 |
|
|
bx_param_num_c *param_cpulevel_for_cpuid;
|
402 |
|
|
|
403 |
|
|
class bochs486_sim : public bx_simulator_interface_c {
|
404 |
|
|
|
405 |
|
|
bx_param_bool_c *get_param_bool(const char *pname, bx_param_c *base) {
|
406 |
|
|
if(strcmp(pname, BXPN_CPUID_LIMIT_WINNT) == 0) return param_bool_false;
|
407 |
|
|
if(strcmp(pname, BXPN_CPUID_SSE4A) == 0) return param_bool_false;
|
408 |
|
|
if(strcmp(pname, BXPN_CPUID_SEP) == 0) return param_bool_false;
|
409 |
|
|
if(strcmp(pname, BXPN_CPUID_XSAVE) == 0) return param_bool_false;
|
410 |
|
|
if(strcmp(pname, BXPN_CPUID_XSAVEOPT) == 0) return param_bool_false;
|
411 |
|
|
if(strcmp(pname, BXPN_CPUID_AES) == 0) return param_bool_false;
|
412 |
|
|
if(strcmp(pname, BXPN_CPUID_MOVBE) == 0) return param_bool_false;
|
413 |
|
|
if(strcmp(pname, BXPN_CPUID_SMEP) == 0) return param_bool_false;
|
414 |
|
|
if(strcmp(pname, BXPN_RESET_ON_TRIPLE_FAULT) == 0) return param_bool_false;
|
415 |
|
|
return NULL;
|
416 |
|
|
}
|
417 |
|
|
bx_param_string_c *get_param_string(const char *pname, bx_param_c *base) {
|
418 |
|
|
if(strcmp(pname, BXPN_VENDOR_STRING) == 0) return param_vendor_string;
|
419 |
|
|
if(strcmp(pname, BXPN_BRAND_STRING) == 0) return param_brand_string;
|
420 |
|
|
return NULL;
|
421 |
|
|
}
|
422 |
|
|
bx_param_enum_c *get_param_enum(const char *pname, bx_param_c *base) {
|
423 |
|
|
if(strcmp(pname, BXPN_CPU_MODEL) == 0) return param_enum_zero;
|
424 |
|
|
if(strcmp(pname, BXPN_CPUID_SSE) == 0) return param_enum_zero;
|
425 |
|
|
return NULL;
|
426 |
|
|
}
|
427 |
|
|
bx_param_num_c *get_param_num(const char *pname, bx_param_c *base) {
|
428 |
|
|
if(strcmp(pname, BXPN_CPUID_STEPPING) == 0) return param_stepping;
|
429 |
|
|
if(strcmp(pname, BXPN_CPUID_MODEL) == 0) return param_model;
|
430 |
|
|
if(strcmp(pname, BXPN_CPUID_FAMILY) == 0) return param_family;
|
431 |
|
|
if(strcmp(pname, BXPN_CPUID_LEVEL) == 0) return param_cpulevel_for_cpuid;
|
432 |
|
|
return NULL;
|
433 |
|
|
}
|
434 |
|
|
};
|
435 |
|
|
|
436 |
|
|
bx_simulator_interface_c *SIM;
|
437 |
|
|
|
438 |
|
|
BOCHSAPI BX_CPU_C bx_cpu;
|
439 |
|
|
int interrupt_vector;
|
440 |
|
|
|
441 |
|
|
//------------------------------------------------------------------------------
|
442 |
|
|
//------------------------------------------------------------------------------
|
443 |
|
|
//------------------------------------------------------------------------------ devices
|
444 |
|
|
|
445 |
|
|
class bochs486_pic : public bx_pic_stub_c {
|
446 |
|
|
Bit8u IAC(void) { bx_cpu.clear_INTR(); return interrupt_vector & 0xFF; }
|
447 |
|
|
|
448 |
|
|
};
|
449 |
|
|
|
450 |
|
|
Bit32u BX_CPP_AttrRegparmN(2)
|
451 |
|
|
bx_devices_c::inp(Bit16u addr, unsigned io_len) {
|
452 |
|
|
// read aligned to 4 bytes, with byteena
|
453 |
|
|
|
454 |
|
|
bool two_reads = (addr & 0x3) + io_len > 4;
|
455 |
|
|
|
456 |
|
|
Bit16u addr1 = addr & 0xFFFC;
|
457 |
|
|
unsigned byteena1 = (io_len == 1)? 0x1 : (io_len == 2)? 0x3 : (io_len == 3)? 0x7 : 0xF;
|
458 |
|
|
byteena1 = ((addr & 0x3) == 0)? byteena1 : ((addr & 0x3) == 1)? byteena1 << 1 : ((addr & 0x3) == 2)? byteena1 << 2 : byteena1 << 3;
|
459 |
|
|
|
460 |
|
|
Bit16u addr2 = (addr + 4) & 0xFFFC;
|
461 |
|
|
unsigned byteena2 = (byteena1 >> 4) & 0xF;
|
462 |
|
|
|
463 |
|
|
printf("start_io_read: 0\n");
|
464 |
|
|
printf("address: %04hx\n", addr1);
|
465 |
|
|
printf("byteena: %02x\n", byteena1 & 0xF);
|
466 |
|
|
printf("can_ignore: 0\n");
|
467 |
|
|
printf("\n");
|
468 |
|
|
fflush(stdout);
|
469 |
|
|
|
470 |
|
|
unsigned int data1 = 0;
|
471 |
|
|
fscanf(stdin, "%x", &data1);
|
472 |
|
|
|
473 |
|
|
unsigned long long data = data1;
|
474 |
|
|
|
475 |
|
|
if(two_reads) {
|
476 |
|
|
printf("start_io_read: 0\n");
|
477 |
|
|
printf("address: %04hx\n", addr2);
|
478 |
|
|
printf("byteena: %02x\n", byteena2);
|
479 |
|
|
printf("can_ignore: 0\n");
|
480 |
|
|
printf("\n");
|
481 |
|
|
fflush(stdout);
|
482 |
|
|
|
483 |
|
|
unsigned int data2 = 0;
|
484 |
|
|
fscanf(stdin, "%x", &data2);
|
485 |
|
|
|
486 |
|
|
data = ((unsigned long long)data2 << 32) | data1;
|
487 |
|
|
}
|
488 |
|
|
|
489 |
|
|
while((byteena1 & 1) == 0) {
|
490 |
|
|
byteena1 >>= 1;
|
491 |
|
|
data >>= 8;
|
492 |
|
|
}
|
493 |
|
|
|
494 |
|
|
return (io_len == 1)? (data & 0xFF) : (io_len == 2)? (data & 0xFFFF) : (io_len == 3)? (data & 0xFFFFFF) : (data & 0xFFFFFFFF);
|
495 |
|
|
|
496 |
|
|
}
|
497 |
|
|
|
498 |
|
|
void BX_CPP_AttrRegparmN(3)
|
499 |
|
|
bx_devices_c::outp(Bit16u addr, Bit32u value, unsigned io_len) {
|
500 |
|
|
// write aligned to 4 bytes, with byteena
|
501 |
|
|
|
502 |
|
|
bool two_writes = (addr & 0x3) + io_len > 4;
|
503 |
|
|
|
504 |
|
|
Bit16u addr1 = addr & 0xFFFC;
|
505 |
|
|
unsigned byteena1 = (io_len == 1)? 0x1 : (io_len == 2)? 0x3 : (io_len == 3)? 0x7 : 0xF;
|
506 |
|
|
byteena1 = ((addr & 0x3) == 0)? byteena1 : ((addr & 0x3) == 1)? byteena1 << 1 : ((addr & 0x3) == 2)? byteena1 << 2 : byteena1 << 3;
|
507 |
|
|
|
508 |
|
|
Bit16u addr2 = (addr + 4) & 0xFFFC;
|
509 |
|
|
unsigned byteena2 = (byteena1 >> 4) & 0xF;
|
510 |
|
|
|
511 |
|
|
Bit64u value_full = ((addr & 0x3) == 0)? (Bit64u)value : ((addr & 0x3) == 1)? ((Bit64u)value << 8) : ((addr & 0x3) == 2)? ((Bit64u)value << 16) : ((Bit64u)value << 24);
|
512 |
|
|
Bit32u value1 = value_full;
|
513 |
|
|
Bit32u value2 = (value_full >> 32);
|
514 |
|
|
|
515 |
|
|
printf("start_io_write: 0\n");
|
516 |
|
|
printf("address: %04hx\n", addr1);
|
517 |
|
|
printf("data: %08x\n", value1);
|
518 |
|
|
printf("byteena: %02x\n", byteena1 & 0xF);
|
519 |
|
|
printf("can_ignore: 0\n");
|
520 |
|
|
|
521 |
|
|
printf("\n");
|
522 |
|
|
fflush(stdout);
|
523 |
|
|
|
524 |
|
|
if(two_writes) {
|
525 |
|
|
printf("start_io_write: 0\n");
|
526 |
|
|
printf("address: %04hx\n", addr2);
|
527 |
|
|
printf("data: %08x\n", value2);
|
528 |
|
|
printf("byteena: %02x\n", byteena2);
|
529 |
|
|
printf("can_ignore: 0\n");
|
530 |
|
|
|
531 |
|
|
printf("\n");
|
532 |
|
|
fflush(stdout);
|
533 |
|
|
}
|
534 |
|
|
}
|
535 |
|
|
bx_devices_c::bx_devices_c() {
|
536 |
|
|
pluginPicDevice = new bochs486_pic();
|
537 |
|
|
}
|
538 |
|
|
bx_devices_c::~bx_devices_c() {
|
539 |
|
|
}
|
540 |
|
|
|
541 |
|
|
bx_devices_c bx_devices;
|
542 |
|
|
|
543 |
|
|
//------------------------------------------------------------------------------
|
544 |
|
|
//------------------------------------------------------------------------------
|
545 |
|
|
//------------------------------------------------------------------------------ memory
|
546 |
|
|
|
547 |
|
|
struct bochs486_page_t {
|
548 |
|
|
Bit8u page_buf[4096*2];
|
549 |
|
|
Bit8u *page;
|
550 |
|
|
bx_phy_address paddr;
|
551 |
|
|
struct bochs486_page_t *next;
|
552 |
|
|
};
|
553 |
|
|
struct bochs486_page_t *bochs486_pages = NULL;
|
554 |
|
|
|
555 |
|
|
void BX_MEM_C::writePhysicalPage(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, void *data) {
|
556 |
|
|
printf("#bochs486: writePhysicalPage: addr=%08x, len=%d\n", addr, len);
|
557 |
|
|
|
558 |
|
|
if(len > 4) {
|
559 |
|
|
printf("#bochs486: writePhysicalPage() with len = %d\n", len);
|
560 |
|
|
exit(-1);
|
561 |
|
|
}
|
562 |
|
|
|
563 |
|
|
bool two_writes = (addr & 0x3) + len > 4;
|
564 |
|
|
|
565 |
|
|
Bit32u addr1 = addr & 0xFFFFFFFC;
|
566 |
|
|
unsigned byteena1 = (len == 1)? 0x1 : (len == 2)? 0x3 : (len == 3)? 0x7 : 0xF;
|
567 |
|
|
byteena1 = ((addr & 0x3) == 0)? byteena1 : ((addr & 0x3) == 1)? byteena1 << 1 : ((addr & 0x3) == 2)? byteena1 << 2 : byteena1 << 3;
|
568 |
|
|
|
569 |
|
|
Bit32u addr2 = (addr + 4) & 0xFFFFFFFC;
|
570 |
|
|
unsigned byteena2 = (byteena1 >> 4) & 0xF;
|
571 |
|
|
|
572 |
|
|
Bit32u value = ((unsigned int *)data)[0];
|
573 |
|
|
|
574 |
|
|
Bit64u value_full = ((addr & 0x3) == 0)? (Bit64u)value : ((addr & 0x3) == 1)? ((Bit64u)value << 8) : ((addr & 0x3) == 2)? ((Bit64u)value << 16) : ((Bit64u)value << 24);
|
575 |
|
|
Bit32u value1 = value_full;
|
576 |
|
|
Bit32u value2 = (value_full >> 32);
|
577 |
|
|
|
578 |
|
|
printf("start_write: 0\n");
|
579 |
|
|
printf("address: %08x\n", addr1);
|
580 |
|
|
printf("data: %08x\n", value1);
|
581 |
|
|
printf("byteena: %02x\n", byteena1 & 0xF);
|
582 |
|
|
printf("can_ignore: 0\n");
|
583 |
|
|
|
584 |
|
|
printf("\n");
|
585 |
|
|
fflush(stdout);
|
586 |
|
|
|
587 |
|
|
if(two_writes) {
|
588 |
|
|
printf("start_write: 0\n");
|
589 |
|
|
printf("address: %08x\n", addr2);
|
590 |
|
|
printf("data: %08x\n", value2);
|
591 |
|
|
printf("byteena: %02x\n", byteena2);
|
592 |
|
|
printf("can_ignore: 0\n");
|
593 |
|
|
|
594 |
|
|
printf("\n");
|
595 |
|
|
fflush(stdout);
|
596 |
|
|
}
|
597 |
|
|
|
598 |
|
|
//update host memory pages
|
599 |
|
|
unsigned char *ptr = (unsigned char *)data;
|
600 |
|
|
|
601 |
|
|
struct bochs486_page_t *page_ptr = bochs486_pages;
|
602 |
|
|
while(page_ptr != NULL) {
|
603 |
|
|
if(page_ptr->paddr == (addr & 0xFFFFF000) && page_ptr->page != NULL) {
|
604 |
|
|
for(int i=0; i<len; i++) page_ptr->page[(addr & 0xFFF) + i] = ptr[i];
|
605 |
|
|
}
|
606 |
|
|
page_ptr = page_ptr->next;
|
607 |
|
|
}
|
608 |
|
|
}
|
609 |
|
|
|
610 |
|
|
void BX_MEM_C::readPhysicalPage(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, void *data) {
|
611 |
|
|
printf("#bochs486: readPhysicalPage: addr=%08x, len=%d\n", addr, len);
|
612 |
|
|
|
613 |
|
|
if(len == 4096) {
|
614 |
|
|
if((addr & 3) != 0) {
|
615 |
|
|
printf("#bochs486: readPhysicalPage() with len = 4096 and addr not aligned to 4.");
|
616 |
|
|
exit(-1);
|
617 |
|
|
}
|
618 |
|
|
|
619 |
|
|
unsigned int *ptr = (unsigned int*)data;
|
620 |
|
|
|
621 |
|
|
for(unsigned i=0; i<len; i+=4) {
|
622 |
|
|
printf("start_read_code: 0\n");
|
623 |
|
|
printf("address: %08x\n", addr);
|
624 |
|
|
printf("byteena: F\n");
|
625 |
|
|
printf("\n");
|
626 |
|
|
fflush(stdout);
|
627 |
|
|
|
628 |
|
|
fscanf(stdin, "%x", &(ptr[i/4]));
|
629 |
|
|
|
630 |
|
|
addr += 4;
|
631 |
|
|
}
|
632 |
|
|
return;
|
633 |
|
|
}
|
634 |
|
|
|
635 |
|
|
//check if read crosses line boundry (16 bytes)
|
636 |
|
|
if( ((addr) & 0xFFFFFFF0) != ((addr + len - 1) & 0xFFFFFFF0) ) {
|
637 |
|
|
unsigned char *ptr = (unsigned char*)data;
|
638 |
|
|
readPhysicalPage(cpu, addr, (addr | 0xF) - addr + 1, ptr);
|
639 |
|
|
readPhysicalPage(cpu, (addr | 0xF) + 1, len - (addr | 0xF) + addr - 1, ptr + ((addr | 0xF) - addr + 1));
|
640 |
|
|
return;
|
641 |
|
|
}
|
642 |
|
|
|
643 |
|
|
bool two_reads = ((addr & 0x3) + len > 4) && ((addr & 0x3) + len <= 8);
|
644 |
|
|
bool three_reads = ((addr & 0x3) + len > 8);
|
645 |
|
|
|
646 |
|
|
Bit32u addr1 = addr & 0xFFFFFFFC;
|
647 |
|
|
unsigned byteena1 = (len == 1)? 0x1 : (len == 2)? 0x3 : (len == 3)? 0x7 : 0xF;
|
648 |
|
|
byteena1 = ((addr & 0x3) == 0)? byteena1 : ((addr & 0x3) == 1)? byteena1 << 1 : ((addr & 0x3) == 2)? byteena1 << 2 : byteena1 << 3;
|
649 |
|
|
|
650 |
|
|
Bit32u addr2 = (addr + 4) & 0xFFFFFFFC;
|
651 |
|
|
Bit32u addr3 = (addr + 8) & 0xFFFFFFFC;
|
652 |
|
|
|
653 |
|
|
if(two_reads || three_reads) byteena1 = 0xF;
|
654 |
|
|
byteena1 &= 0xF;
|
655 |
|
|
printf("start_read: 0\n");
|
656 |
|
|
printf("address: %08x\n", addr1);
|
657 |
|
|
printf("byteena: %02x\n", byteena1);
|
658 |
|
|
printf("can_ignore: 0\n");
|
659 |
|
|
|
660 |
|
|
printf("\n");
|
661 |
|
|
fflush(stdout);
|
662 |
|
|
|
663 |
|
|
unsigned int data_read[3] = { 0,0,0 };
|
664 |
|
|
fscanf(stdin, "%x", &data_read[0]);
|
665 |
|
|
|
666 |
|
|
if(two_reads || three_reads) {
|
667 |
|
|
printf("start_read: 0\n");
|
668 |
|
|
printf("address: %08x\n", addr2);
|
669 |
|
|
printf("byteena: F\n");
|
670 |
|
|
printf("can_ignore: 0\n");
|
671 |
|
|
|
672 |
|
|
printf("\n");
|
673 |
|
|
fflush(stdout);
|
674 |
|
|
|
675 |
|
|
unsigned int data2 = 0;
|
676 |
|
|
fscanf(stdin, "%x", &data_read[1]);
|
677 |
|
|
|
678 |
|
|
if(three_reads) {
|
679 |
|
|
printf("start_read: 0\n");
|
680 |
|
|
printf("address: %08x\n", addr3);
|
681 |
|
|
printf("byteena: F\n");
|
682 |
|
|
printf("can_ignore: 0\n");
|
683 |
|
|
|
684 |
|
|
printf("\n");
|
685 |
|
|
fflush(stdout);
|
686 |
|
|
|
687 |
|
|
unsigned int data3 = 0;
|
688 |
|
|
fscanf(stdin, "%x", &data_read[2]);
|
689 |
|
|
}
|
690 |
|
|
}
|
691 |
|
|
|
692 |
|
|
unsigned char *ptr = (unsigned char *)data_read;
|
693 |
|
|
|
694 |
|
|
for(int i=0; i<(addr & 0x3); i++) ptr++;
|
695 |
|
|
|
696 |
|
|
memcpy((unsigned char *)data, ptr, len);
|
697 |
|
|
|
698 |
|
|
//ptr = (unsigned char *)data;
|
699 |
|
|
//for(int i=0; i<len; i++) printf("#R[%d]: %hhx\n", i, ptr[i]);
|
700 |
|
|
}
|
701 |
|
|
|
702 |
|
|
Bit8u *BX_MEM_C::getHostMemAddr(BX_CPU_C *cpu, bx_phy_address addr, unsigned rw) {
|
703 |
|
|
printf("#bochs486: getHostMemAddr: addr=%08x, rw=%d\n", addr, rw);
|
704 |
|
|
|
705 |
|
|
// find page
|
706 |
|
|
struct bochs486_page_t *ptr = bochs486_pages;
|
707 |
|
|
|
708 |
|
|
while(ptr != NULL) {
|
709 |
|
|
if(ptr->paddr == addr) {
|
710 |
|
|
printf("#bochs486: getHostMemAddr: hostPtr[old]: %p\n", ptr->page);
|
711 |
|
|
return ptr->page;
|
712 |
|
|
}
|
713 |
|
|
|
714 |
|
|
if(ptr->next != NULL) ptr = ptr->next;
|
715 |
|
|
else break;
|
716 |
|
|
}
|
717 |
|
|
|
718 |
|
|
// create new page
|
719 |
|
|
struct bochs486_page_t *new_page = new struct bochs486_page_t();
|
720 |
|
|
new_page->paddr = addr;
|
721 |
|
|
new_page->next = NULL;
|
722 |
|
|
|
723 |
|
|
// find address at 4096 boundry
|
724 |
|
|
new_page->page = new_page->page_buf;
|
725 |
|
|
while( ( ((unsigned long long)new_page->page) % 4096) != 0 ) new_page->page++;
|
726 |
|
|
|
727 |
|
|
readPhysicalPage(cpu, addr, 4096, new_page->page);
|
728 |
|
|
|
729 |
|
|
// link new page
|
730 |
|
|
if(bochs486_pages == NULL) {
|
731 |
|
|
bochs486_pages = new_page;
|
732 |
|
|
}
|
733 |
|
|
else {
|
734 |
|
|
ptr->next = new_page;
|
735 |
|
|
}
|
736 |
|
|
|
737 |
|
|
printf("#bochs486: getHostMemAddr: hostPtr[new]: %p\n", new_page->page);
|
738 |
|
|
return new_page->page;
|
739 |
|
|
}
|
740 |
|
|
BX_MEM_C::BX_MEM_C() {
|
741 |
|
|
}
|
742 |
|
|
BX_MEM_C::~BX_MEM_C() {
|
743 |
|
|
}
|
744 |
|
|
|
745 |
|
|
BOCHSAPI BX_MEM_C bx_mem;
|
746 |
|
|
|
747 |
|
|
//------------------------------------------------------------------------------
|
748 |
|
|
//------------------------------------------------------------------------------
|
749 |
|
|
//------------------------------------------------------------------------------ interrupt
|
750 |
|
|
|
751 |
|
|
bool bochs486_skip_rep_finish = false;
|
752 |
|
|
|
753 |
|
|
//------------------------------------------------------------------------------
|
754 |
|
|
//------------------------------------------------------------------------------
|
755 |
|
|
//------------------------------------------------------------------------------ instrument
|
756 |
|
|
|
757 |
|
|
int instruction_count = 0;
|
758 |
|
|
|
759 |
|
|
int bochs486_rep;
|
760 |
|
|
int bochs486_seg;
|
761 |
|
|
int bochs486_lock;
|
762 |
|
|
int bochs486_as32;
|
763 |
|
|
int bochs486_os32;
|
764 |
|
|
int bochs486_cmd_len;
|
765 |
|
|
|
766 |
|
|
void bx_instr_init_env(void) { }
|
767 |
|
|
void bx_instr_exit_env(void) { }
|
768 |
|
|
|
769 |
|
|
void bx_instr_debug_promt() { }
|
770 |
|
|
void bx_instr_debug_cmd(const char *cmd) { }
|
771 |
|
|
|
772 |
|
|
void bx_instr_cnear_branch_taken(unsigned cpu, bx_address branch_eip, bx_address new_eip) { }
|
773 |
|
|
void bx_instr_cnear_branch_not_taken(unsigned cpu, bx_address branch_eip) { }
|
774 |
|
|
void bx_instr_ucnear_branch(unsigned cpu, unsigned what, bx_address branch_eip, bx_address new_eip) { }
|
775 |
|
|
void bx_instr_far_branch(unsigned cpu, unsigned what, Bit16u new_cs, bx_address new_eip) { }
|
776 |
|
|
|
777 |
|
|
void bx_instr_opcode(unsigned cpu, bxInstruction_c *i, const Bit8u *opcode, unsigned len, bx_bool is32, bx_bool is64) { }
|
778 |
|
|
|
779 |
|
|
void bx_instr_exception(unsigned cpu, unsigned vector, unsigned error_code) { }
|
780 |
|
|
void bx_instr_hwinterrupt(unsigned cpu, unsigned vector, Bit16u cs, bx_address eip) { }
|
781 |
|
|
|
782 |
|
|
void bx_instr_tlb_cntrl(unsigned cpu, unsigned what, bx_phy_address new_cr3) { }
|
783 |
|
|
void bx_instr_cache_cntrl(unsigned cpu, unsigned what) { }
|
784 |
|
|
void bx_instr_prefetch_hint(unsigned cpu, unsigned what, unsigned seg, bx_address offset) { }
|
785 |
|
|
void bx_instr_clflush(unsigned cpu, bx_address laddr, bx_phy_address paddr) { }
|
786 |
|
|
|
787 |
|
|
void bx_instr_initialize(unsigned cpu) { }
|
788 |
|
|
void bx_instr_exit(unsigned cpu) { }
|
789 |
|
|
void bx_instr_reset(unsigned cpu, unsigned type) { }
|
790 |
|
|
|
791 |
|
|
void bx_instr_inp(Bit16u addr, unsigned len) { }
|
792 |
|
|
void bx_instr_inp2(Bit16u addr, unsigned len, unsigned val) { }
|
793 |
|
|
void bx_instr_outp(Bit16u addr, unsigned len, unsigned val) { }
|
794 |
|
|
|
795 |
|
|
void bx_instr_lin_access(unsigned cpu, bx_address lin, bx_address phy, unsigned len, unsigned rw) { }
|
796 |
|
|
void bx_instr_phy_access(unsigned cpu, bx_address phy, unsigned len, unsigned rw) { }
|
797 |
|
|
|
798 |
|
|
void bx_instr_wrmsr(unsigned cpu, unsigned addr, Bit64u value) { }
|
799 |
|
|
|
800 |
|
|
|
801 |
|
|
|
802 |
|
|
void bx_instr_interrupt(unsigned cpu, unsigned vector, unsigned type, bx_bool push_error, Bit16u error_code) {
|
803 |
|
|
|
804 |
|
|
bochs486_skip_rep_finish = false;
|
805 |
|
|
|
806 |
|
|
if(type != 4 && type != 5 && type != 6) { //BX_SOFTWARE_INTERRUPT; BX_PRIVILEGED_SOFTWARE_INTERRUPT; BX_SOFTWARE_EXCEPTION
|
807 |
|
|
|
808 |
|
|
printf("#bochs486: bx_instr_interrupt(), test_type: %d, type: %d, vector: %02x\n", test_type, type, vector); fflush(stdout);
|
809 |
|
|
|
810 |
|
|
int is_interrupt = 0;
|
811 |
|
|
if(type == 0) is_interrupt = 1; // BX_EXTERNAL_INTERRUPT
|
812 |
|
|
|
813 |
|
|
if(is_interrupt) {
|
814 |
|
|
printf("start_interrupt: 0\n");
|
815 |
|
|
}
|
816 |
|
|
else {
|
817 |
|
|
printf("start_exception: 0\n");
|
818 |
|
|
printf("push_error: %01x\n", push_error);
|
819 |
|
|
printf("error_code: %04x\n", error_code);
|
820 |
|
|
}
|
821 |
|
|
printf("vector: %02x\n", vector);
|
822 |
|
|
printf("\n");
|
823 |
|
|
fflush(stdout);
|
824 |
|
|
|
825 |
|
|
output_cpu_state();
|
826 |
|
|
|
827 |
|
|
if(test_type == 0) exit(0);
|
828 |
|
|
|
829 |
|
|
instruction_count++;
|
830 |
|
|
if(test_type > 0 && instruction_count == test_type) exit(0);
|
831 |
|
|
}
|
832 |
|
|
}
|
833 |
|
|
|
834 |
|
|
void instr_after_execution() {
|
835 |
|
|
printf("#bochs486: instr_after_execution()\n"); fflush(stdout);
|
836 |
|
|
|
837 |
|
|
printf("start_completed: 0\n");
|
838 |
|
|
printf("rep: %x\n", bochs486_rep);
|
839 |
|
|
printf("seg: %x\n", bochs486_seg);
|
840 |
|
|
printf("lock: %x\n", bochs486_lock);
|
841 |
|
|
printf("os32: %x\n", bochs486_os32);
|
842 |
|
|
printf("as32: %x\n", bochs486_as32);
|
843 |
|
|
printf("consumed: %x\n", bochs486_cmd_len);
|
844 |
|
|
printf("\n");
|
845 |
|
|
fflush(stdout);
|
846 |
|
|
|
847 |
|
|
output_cpu_state();
|
848 |
|
|
|
849 |
|
|
instruction_count++;
|
850 |
|
|
if(test_type > 0 && instruction_count == test_type) exit(0);
|
851 |
|
|
|
852 |
|
|
//interrupt
|
853 |
|
|
printf("start_check_interrupt: 0\n");
|
854 |
|
|
printf("\n");
|
855 |
|
|
fflush(stdout);
|
856 |
|
|
|
857 |
|
|
fscanf(stdin, "%x", &interrupt_vector);
|
858 |
|
|
|
859 |
|
|
printf("#bochs486_check_interrupt: %x\n", interrupt_vector);
|
860 |
|
|
if(interrupt_vector != 0x100) {
|
861 |
|
|
bx_cpu.raise_INTR();
|
862 |
|
|
}
|
863 |
|
|
else bx_cpu.clear_INTR();
|
864 |
|
|
}
|
865 |
|
|
|
866 |
|
|
void bx_instr_before_execution(unsigned cpu, bxInstruction_c *i) {
|
867 |
|
|
bochs486_rep = i->bochs486_rep; // 0-none, 2-0xF2, 3-0xF3
|
868 |
|
|
bochs486_seg = i->seg() & 0x7; // 0-5
|
869 |
|
|
bochs486_lock = (i->bochs486_lock)? 1 : 0;
|
870 |
|
|
bochs486_as32 = (i->as32L())? 1 : 0;
|
871 |
|
|
bochs486_os32 = (i->os32L())? 1 : 0;
|
872 |
|
|
bochs486_cmd_len = i->ilen();
|
873 |
|
|
|
874 |
|
|
printf("#instr: %02x, async_event: %x\n", i->bochs486_opcode, bx_cpu.async_event);
|
875 |
|
|
|
876 |
|
|
printf("#start_decoded:\n");
|
877 |
|
|
printf("#decoded_rep: %x\n", bochs486_rep);
|
878 |
|
|
printf("#decoded_seg: %x\n", bochs486_seg);
|
879 |
|
|
printf("#decoded_lock: %x\n", bochs486_lock);
|
880 |
|
|
printf("#decoded_os32: %x\n", bochs486_os32);
|
881 |
|
|
printf("#decoded_as32: %x\n", bochs486_as32);
|
882 |
|
|
printf("#decoded_consumed: %x\n", bochs486_cmd_len);
|
883 |
|
|
printf("\n");
|
884 |
|
|
fflush(stdout);
|
885 |
|
|
}
|
886 |
|
|
void bx_instr_after_execution(unsigned cpu, bxInstruction_c *i) {
|
887 |
|
|
if(bochs486_skip_rep_finish) {
|
888 |
|
|
printf("#bx_instr_after_execution: bochs486_skip_rep_finished\n");
|
889 |
|
|
bochs486_skip_rep_finish = false;
|
890 |
|
|
return;
|
891 |
|
|
}
|
892 |
|
|
|
893 |
|
|
//patch XCHG
|
894 |
|
|
if((i->bochs486_modregrm >> 6) != 3 && (i->bochs486_opcode == 0x86 || i->bochs486_opcode == 0x87)) bochs486_lock = 1;
|
895 |
|
|
|
896 |
|
|
instr_after_execution();
|
897 |
|
|
}
|
898 |
|
|
void bx_instr_repeat_iteration(unsigned cpu, bxInstruction_c *i) {
|
899 |
|
|
bochs486_skip_rep_finish = true;
|
900 |
|
|
|
901 |
|
|
instr_after_execution();
|
902 |
|
|
}
|
903 |
|
|
|
904 |
|
|
void bx_instr_hlt(unsigned cpu) {
|
905 |
|
|
instr_after_execution();
|
906 |
|
|
|
907 |
|
|
//if(test_type == 0) exit(0);
|
908 |
|
|
}
|
909 |
|
|
void bx_instr_mwait(unsigned cpu, bx_phy_address addr, unsigned len, Bit32u flags) { }
|
910 |
|
|
|
911 |
|
|
// memory trace callbacks from CPU, len=1,2,4 or 8
|
912 |
|
|
void bx_dbg_lin_memory_access(unsigned cpu, bx_address lin, bx_phy_address phy, unsigned len, unsigned pl, unsigned rw, Bit8u *data) {
|
913 |
|
|
if(rw == BX_READ) {
|
914 |
|
|
printf("#bochs486: bx_dbg_lin_memory_access() read redirect.\n");
|
915 |
|
|
Bit8u buf[8];
|
916 |
|
|
bx_mem.readPhysicalPage(NULL, phy, len, buf);
|
917 |
|
|
|
918 |
|
|
bool read_ok = true;
|
919 |
|
|
for(int i=0; i<len; i++) if(data[i] != buf[i]) read_ok = false;
|
920 |
|
|
|
921 |
|
|
if(read_ok == false) {
|
922 |
|
|
printf("#bochs486: bx_dbg_lin_memory_access() read mismatch: lin=%08x, phy=%08x, len=%d, pl=%d, rw=%d\n", lin, phy, len, pl, rw);
|
923 |
|
|
for(int i=0; i<len; i++) {
|
924 |
|
|
printf("#%d: %02hhx --- %02hhx\n", i, data[i], buf[i]);
|
925 |
|
|
}
|
926 |
|
|
exit(-1);
|
927 |
|
|
}
|
928 |
|
|
}
|
929 |
|
|
if(rw == BX_WRITE) {
|
930 |
|
|
printf("#bochs486: bx_dbg_lin_memory_access() write redirect: phy=%08x, len=%d\n", phy, len);
|
931 |
|
|
bx_mem.writePhysicalPage(NULL, phy, len, data);
|
932 |
|
|
}
|
933 |
|
|
}
|
934 |
|
|
void bx_dbg_phy_memory_access(unsigned cpu, bx_phy_address phy, unsigned len, unsigned rw, unsigned attr, Bit8u *data) {
|
935 |
|
|
}
|
936 |
|
|
|
937 |
|
|
//------------------------------------------------------------------------------
|
938 |
|
|
//------------------------------------------------------------------------------
|
939 |
|
|
//------------------------------------------------------------------------------ main
|
940 |
|
|
|
941 |
|
|
int main(int argc, char **argv) {
|
942 |
|
|
|
943 |
|
|
bx_pc_system.a20_mask = 0xFFFFFFFF;
|
944 |
|
|
|
945 |
|
|
SIM = new bochs486_sim();
|
946 |
|
|
|
947 |
|
|
const char *choices[] = { "0_choice", NULL };
|
948 |
|
|
|
949 |
|
|
param_vendor_string = new bx_param_string_c(NULL, "1_name", "1_label", "1_descr", "GeniuneAO486");
|
950 |
|
|
param_brand_string = new bx_param_string_c(NULL, "2_name", "2_label", "2_descr", "ao486 ");
|
951 |
|
|
param_bool_false = new bx_param_bool_c( NULL, "3_name", "3_label", "3_descr", 0);
|
952 |
|
|
param_enum_zero = new bx_param_enum_c( NULL, "4_name", "4_label", "4_descr", choices, 0);
|
953 |
|
|
param_stepping = new bx_param_num_c( NULL, "5_name", "5_label", "5_descr", 0xB,0xB,0xB);
|
954 |
|
|
param_model = new bx_param_num_c( NULL, "6_name", "6_label", "6_descr", 0x5,0x5,0x5);
|
955 |
|
|
param_family = new bx_param_num_c( NULL, "7_name", "7_label", "7_descr", 0x4,0x4,0x4);
|
956 |
|
|
param_cpulevel_for_cpuid = new bx_param_num_c( NULL, "8_name", "8_label", "8_descr", 0x4,0x4,0x4);
|
957 |
|
|
|
958 |
|
|
bx_cpu.initialize();
|
959 |
|
|
bx_cpu.reset(BX_RESET_HARDWARE);
|
960 |
|
|
|
961 |
|
|
printf("START\n");
|
962 |
|
|
|
963 |
|
|
initialize();
|
964 |
|
|
|
965 |
|
|
bx_cpu.async_event = 0;
|
966 |
|
|
bx_cpu.handleCpuModeChange();
|
967 |
|
|
|
968 |
|
|
output_cpu_state();
|
969 |
|
|
bx_cpu.cpu_loop();
|
970 |
|
|
|
971 |
|
|
printf("#bochs486: finishing.\n");
|
972 |
|
|
return 0;
|
973 |
|
|
}
|