Skip to content

Commit

Permalink
More 286 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-jonsson committed Sep 4, 2024
1 parent b926905 commit ae15a7d
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 114 deletions.
4 changes: 2 additions & 2 deletions front/sdl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,8 @@ static bool write_default_config(const char *path, bool clean) {
"bios=0xFE000,GLABIOS.ROM\n"
"uart=0x3F8,4 \t;COM1\n"
"uart=0x2F8,3 \t;COM2\n"
"cga=\n"
";vga=vgabios.bin\n"
";cga=\n"
"vga=vgabios.bin\n"
"disk=\n"
"bios=0xE0000,vxtx.bin \t;DISK\n"
"rtc=0x240\n"
Expand Down
79 changes: 45 additions & 34 deletions lib/vxt/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "common.h"
#include "cpu.h"
#include "include/vxt/vxt.h"
#include "testing.h"

#include "exec.inl"
Expand Down Expand Up @@ -112,43 +111,54 @@ static void prep_exec(CONSTSP(cpu) p) {
}

static void do_exec(CONSTSP(cpu) p) {
const CONSTSP(instruction) inst = &opcode_table[p->opcode];
ENSURE(inst->opcode == p->opcode);

p->ea_cycles = 0;
if (inst->modregrm)
read_modregrm(p);
inst->func(p, inst);

p->cycles += inst->cycles;
p->cycles += p->ea_cycles;

if (UNLIKELY(p->inst_queue_dirty)) {
p->inst_queue_count = 0;
} else {
#ifndef VXT_NO_PREFETCH
prefetch(p, (p->cycles / 2) - p->bus_transfers); // TODO: Round up or down?
#endif
}
const CONSTSP(instruction) inst = &opcode_table[p->opcode];
ENSURE(inst->opcode == p->opcode);

switch (inst->arch) {
case ARCH_8086:
case ARCH_80186:
case ARCH_80286:
case ARCH_FPU:
p->invalid = false;
break;
default:
p->invalid = true;
}

if (inst->modregrm)
read_modregrm(p);
inst->func(p, inst);

if (p->invalid)
call_int(p, 6);

p->cycles += inst->cycles;

if (UNLIKELY(p->inst_queue_dirty)) {
p->inst_queue_count = 0;
} else {
#ifndef VXT_NO_PREFETCH
prefetch(p, (p->cycles / 2) - p->bus_transfers); // TODO: Round up or down?
#endif
}
}

int cpu_step(CONSTSP(cpu) p) {
VALIDATOR_BEGIN(p, &p->regs);

prep_exec(p);
if (LIKELY(!p->halt)) {
read_opcode(p);
do_exec(p);
} else {
p->cycles++;
}
VALIDATOR_BEGIN(p, &p->regs);

prep_exec(p);
if (LIKELY(!p->halt)) {
read_opcode(p);
do_exec(p);
} else {
p->cycles++;
}

const CONSTSP(instruction) inst = &opcode_table[p->opcode];
VALIDATOR_END(p, inst->name, p->opcode, inst->modregrm, p->cycles, &p->regs);
p->invalid = inst->arch != ARCH_8086;
const CONSTSP(instruction) inst = &opcode_table[p->opcode];
VALIDATOR_END(p, inst->name, p->opcode, inst->modregrm, p->cycles, &p->regs);

ENSURE(p->cycles > 0);
return p->cycles;
ENSURE(p->cycles > 0);
return p->cycles;
}

void cpu_reset_cycle_count(CONSTSP(cpu) p) {
Expand All @@ -161,7 +171,8 @@ void cpu_reset(CONSTSP(cpu) p) {
p->trap = false;
vxt_memclear(&p->regs, sizeof(p->regs));

p->regs.flags = 0xF002;
//p->regs.flags = 0xF002;
p->regs.flags = 2; // 286 flag setup
p->regs.cs = 0xFFFF;
p->regs.debug = false;

Expand Down
2 changes: 1 addition & 1 deletion lib/vxt/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct address_mode {
struct cpu {
struct vxt_registers regs;
bool trap, halt, int28, invalid;
int cycles, ea_cycles;
int cycles;
vxt_word inst_start;

vxt_byte opcode, repeat;
Expand Down
19 changes: 0 additions & 19 deletions lib/vxt/exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#define IRQ(p, n) { VALIDATOR_DISCARD((p)); ENSURE((p)->pic); (p)->pic->pic.irq(VXT_GET_DEVICE_PTR((p)->pic), (n)); }
#define INST(n) const struct instruction * const n
#define MOD_TARGET_MEM(mode) ((mode).mod < 3)
#define ADD_CYCLE_MOD_MEM(p, n) { if (MOD_TARGET_MEM((p->mode))) (p)->cycles += (n); }

enum architecture {
ARCH_INVALID,
Expand Down Expand Up @@ -96,42 +95,33 @@ static vxt_word get_ea_offset(CONSTSP(cpu) p) {
CONSTSP(vxt_registers) r = &p->regs;
CONSTSP(address_mode) m = &p->mode;
vxt_word ea = 0;
int cycles = 0;

switch (m->mod) {
case 0:
switch (m->rm) {
case 0:
ea = r->bx + r->si;
cycles = 7;
break;
case 1:
ea = r->bx + r->di;
cycles = 8;
break;
case 2:
ea = r->bp + r->si;
cycles = 8;
break;
case 3:
ea = r->bp + r->di;
cycles = 7;
break;
case 4:
ea = r->si;
cycles = 5;
break;
case 5:
ea = r->di;
cycles = 5;
break;
case 6:
ea = m->disp;
cycles = 6;
break;
case 7:
ea = r->bx;
cycles = 5;
break;
}
break;
Expand All @@ -140,40 +130,31 @@ static vxt_word get_ea_offset(CONSTSP(cpu) p) {
switch (m->rm) {
case 0:
ea = r->bx + r->si + m->disp;
cycles = 11;
break;
case 1:
ea = r->bx + r->di + m->disp;
cycles = 12;
break;
case 2:
ea = r->bp + r->si + m->disp;
cycles = 12;
break;
case 3:
ea = r->bp + r->di + m->disp;
cycles = 11;
break;
case 4:
ea = r->si + m->disp;
cycles = 9;
break;
case 5:
ea = r->di + m->disp;
cycles = 9;
break;
case 6:
ea = r->bp + m->disp;
cycles = 9;
break;
case 7:
ea = r->bx + m->disp;
cycles = 9;
break;
}
break;
}
p->ea_cycles = cycles;
return ea;
}

Expand Down
Loading

0 comments on commit ae15a7d

Please sign in to comment.