Fixed the intendation mess in cpu/x86seg.c, removed port 61h handling from keyboard/keyboard_at.c, and fixed a function with undeclared type in win/win.c.

This commit is contained in:
OBattler
2021-11-13 23:15:28 +01:00
parent 758d8acb63
commit bfb3c0c324
3 changed files with 148 additions and 237 deletions

View File

@@ -942,173 +942,173 @@ void loadcscall(uint16_t seg)
segdat[2] = (segdat[2] & ~(3 << (5+8))) | (CPL << (5+8)); segdat[2] = (segdat[2] & ~(3 << (5+8))) | (CPL << (5+8));
} else /* On non-conforming segments, set RPL = CPL */ } else /* On non-conforming segments, set RPL = CPL */
seg = (seg & 0xfffc) | CPL; seg = (seg & 0xfffc) | CPL;
CS = seg; CS = seg;
do_seg_load(&cpu_state.seg_cs, segdat); do_seg_load(&cpu_state.seg_cs, segdat);
if ((CPL == 3) && (oldcpl != 3)) if ((CPL == 3) && (oldcpl != 3))
flushmmucache_cr3(); flushmmucache_cr3();
#ifdef USE_NEW_DYNAREC #ifdef USE_NEW_DYNAREC
oldcpl = CPL; oldcpl = CPL;
#endif #endif
#ifdef ENABLE_X86SEG_LOG #ifdef ENABLE_X86SEG_LOG
x86seg_log("Complete\n"); x86seg_log("Complete\n");
#endif #endif
cycles -= timing_call_pm; cycles -= timing_call_pm;
} else { } else {
type = segdat[2] & 0x0f00; type = segdat[2] & 0x0f00;
x86seg_log("Type %03X\n", type); x86seg_log("Type %03X\n", type);
switch (type) { switch (type) {
case 0x0400: /* Call gate */ case 0x0400: /* Call gate */
case 0x0c00: /* 386 Call gate */ case 0x0c00: /* 386 Call gate */
x86seg_log("Callgate %08X\n", cpu_state.pc); x86seg_log("Callgate %08X\n", cpu_state.pc);
cgate32 = (type & 0x0800); cgate32 = (type & 0x0800);
cgate16 = !cgate32; cgate16 = !cgate32;
#ifndef USE_NEW_DYNAREC #ifndef USE_NEW_DYNAREC
oldcs = CS; oldcs = CS;
#endif #endif
count = segdat[2] & 0x001f; count = segdat[2] & 0x001f;
if (DPL < CPL) { if (DPL < CPL) {
x86gpf("loadcscall(): ex DPL < CPL",seg & 0xfffc); x86gpf("loadcscall(): ex DPL < CPL",seg & 0xfffc);
return; return;
} }
if (DPL < (seg & 0x0003)) { if (DPL < (seg & 0x0003)) {
x86gpf("loadcscall(): ex DPL < RPL", seg & 0xfffc); x86gpf("loadcscall(): ex DPL < RPL", seg & 0xfffc);
return; return;
} }
if (!(segdat[2] & 0x8000)) { if (!(segdat[2] & 0x8000)) {
x86np("Call gate not present", seg & 0xfffc); x86np("Call gate not present", seg & 0xfffc);
return; return;
} }
seg2 = segdat[1]; seg2 = segdat[1];
x86seg_log("New address : %04X:%08X\n", seg2, newpc); x86seg_log("New address : %04X:%08X\n", seg2, newpc);
if (!(seg2 & 0xfffc)) { if (!(seg2 & 0xfffc)) {
x86gpf("loadcscall(): ex selector is NULL", 0); x86gpf("loadcscall(): ex selector is NULL", 0);
return; return;
} }
addr = seg2 & 0xfff8; addr = seg2 & 0xfff8;
dt = (seg2 & 0x0004) ? &ldt : &gdt; dt = (seg2 & 0x0004) ? &ldt : &gdt;
if ((addr + 7) > dt->limit) { if ((addr + 7) > dt->limit) {
x86gpf("loadcscall(): ex Selector > DT limit", seg2 & 0xfff8); x86gpf("loadcscall(): ex Selector > DT limit", seg2 & 0xfff8);
return; return;
} }
addr += dt->base; addr += dt->base;
read_descriptor(addr, segdat, segdat32, 1); read_descriptor(addr, segdat, segdat32, 1);
if (cpu_state.abrt) if (cpu_state.abrt)
return; return;
x86seg_log("Code seg2 call - %04X - %04X %04X %04X\n", seg2, segdat[0], segdat[1], segdat[2]); x86seg_log("Code seg2 call - %04X - %04X %04X %04X\n", seg2, segdat[0], segdat[1], segdat[2]);
if (DPL > CPL) { if (DPL > CPL) {
x86gpf("loadcscall(): ex DPL > CPL", seg2 & 0xfffc); x86gpf("loadcscall(): ex DPL > CPL", seg2 & 0xfffc);
return; return;
} }
if (!(segdat[2] & 0x8000)) { if (!(segdat[2] & 0x8000)) {
x86seg_log("Call gate CS not present %04X\n", seg2); x86seg_log("Call gate CS not present %04X\n", seg2);
x86np("Call gate CS not present", seg2 & 0xfffc); x86np("Call gate CS not present", seg2 & 0xfffc);
return; return;
} }
switch (segdat[2] & 0x1f00) { switch (segdat[2] & 0x1f00) {
case 0x1800: case 0x1900: case 0x1a00: case 0x1b00: /* Non-conforming code */ case 0x1800: case 0x1900: case 0x1a00: case 0x1b00: /* Non-conforming code */
if (DPL < CPL) { if (DPL < CPL) {
#ifdef USE_NEW_DYNAREC #ifdef USE_NEW_DYNAREC
uint16_t oldcs = CS; uint16_t oldcs = CS;
#endif #endif
oaddr = addr; oaddr = addr;
/* Load new stack */ /* Load new stack */
oldss = SS; oldss = SS;
oldsp = oldsp2 = ESP; oldsp = oldsp2 = ESP;
cpl_override = 1; cpl_override = 1;
if (tr.access & 8) { if (tr.access & 8) {
addr = 4 + tr.base + (DPL << 3); addr = 4 + tr.base + (DPL << 3);
newss = readmemw(0, addr + 4); newss = readmemw(0, addr + 4);
if (cpu_16bitbus) { if (cpu_16bitbus) {
newsp = readmemw(0, addr);
newsp |= (readmemw(0, addr + 2) << 16);
} else
newsp = readmeml(0, addr);
} else {
addr = 2 + tr.base + (DPL * 4);
newss = readmemw(0, addr + 2);
newsp = readmemw(0, addr); newsp = readmemw(0, addr);
} newsp |= (readmemw(0, addr + 2) << 16);
cpl_override = 0; } else
if (cpu_state.abrt) newsp = readmeml(0, addr);
return; } else {
x86seg_log("New stack %04X:%08X\n", newss, newsp); addr = 2 + tr.base + (DPL * 4);
if (!(newss & 0xfffc)) { newss = readmemw(0, addr + 2);
x86ts(NULL, newss & 0xfffc); newsp = readmemw(0, addr);
return; }
} cpl_override = 0;
addr = newss & 0xfff8; if (cpu_state.abrt)
dt = (newss & 0x0004) ? &ldt : &gdt; return;
if ((addr + 7) > dt->limit) { x86seg_log("New stack %04X:%08X\n", newss, newsp);
fatal("Bigger than DT limit %04X %08X %04X CSC SS\n", newss, addr, dt->limit); if (!(newss & 0xfffc)) {
x86ts(NULL, newss & ~3); x86ts(NULL, newss & 0xfffc);
return; return;
} }
addr += dt->base; addr = newss & 0xfff8;
x86seg_log("Read stack seg\n"); dt = (newss & 0x0004) ? &ldt : &gdt;
read_descriptor(addr, segdat2, segdat232, 1); if ((addr + 7) > dt->limit) {
if (cpu_state.abrt) fatal("Bigger than DT limit %04X %08X %04X CSC SS\n", newss, addr, dt->limit);
return; x86ts(NULL, newss & ~3);
x86seg_log("Read stack seg done!\n"); return;
if (((newss & 0x0003) != DPL) || (DPL2 != DPL)) { }
x86ts(NULL, newss & 0xfffc); addr += dt->base;
return; x86seg_log("Read stack seg\n");
} read_descriptor(addr, segdat2, segdat232, 1);
if ((segdat2[2] & 0x1a00) != 0x1200) { if (cpu_state.abrt)
x86ts("Call gate loading SS unknown type", newss & 0xfffc); return;
return; x86seg_log("Read stack seg done!\n");
} if (((newss & 0x0003) != DPL) || (DPL2 != DPL)) {
if (!(segdat2[2] & 0x8000)) { x86ts(NULL, newss & 0xfffc);
x86ss("Call gate loading SS not present", newss & 0xfffc); return;
return; }
} if ((segdat2[2] & 0x1a00) != 0x1200) {
if (!stack32) x86ts("Call gate loading SS unknown type", newss & 0xfffc);
oldsp &= 0xffff; return;
SS = newss; }
set_stack32((segdat2[3] & 0x0040) ? 1 : 0); if (!(segdat2[2] & 0x8000)) {
if (stack32) x86ss("Call gate loading SS not present", newss & 0xfffc);
ESP = newsp; return;
else }
SP = newsp; if (!stack32)
oldsp &= 0xffff;
SS = newss;
set_stack32((segdat2[3] & 0x0040) ? 1 : 0);
if (stack32)
ESP = newsp;
else
SP = newsp;
do_seg_load(&cpu_state.seg_ss, segdat2); do_seg_load(&cpu_state.seg_ss, segdat2);
x86seg_log("Set access 1\n"); x86seg_log("Set access 1\n");
cpl_override = 1; cpl_override = 1;
writememw(0, addr + 4, segdat2[2] | 0x100); /* Set accessed bit */ writememw(0, addr + 4, segdat2[2] | 0x100); /* Set accessed bit */
cpl_override = 0; cpl_override = 0;
CS = seg2; CS = seg2;
do_seg_load(&cpu_state.seg_cs, segdat); do_seg_load(&cpu_state.seg_cs, segdat);
if ((CPL == 3) && (oldcpl != 3)) if ((CPL == 3) && (oldcpl != 3))
flushmmucache_cr3(); flushmmucache_cr3();
#ifdef USE_NEW_DYNAREC #ifdef USE_NEW_DYNAREC
oldcpl = CPL; oldcpl = CPL;
#endif #endif
set_use32(segdat[3] & 0x0040); set_use32(segdat[3] & 0x0040);
cpu_state.pc = newpc; cpu_state.pc = newpc;
x86seg_log("Set access 2\n"); x86seg_log("Set access 2\n");
cpl_override = 1; cpl_override = 1;
writememw(0, oaddr + 4, segdat[2] | 0x100); /* Set accessed bit */ writememw(0, oaddr + 4, segdat[2] | 0x100); /* Set accessed bit */
cpl_override = 0; cpl_override = 0;
x86seg_log("Type %04X\n", type); x86seg_log("Type %04X\n", type);
if (type == 0x0c00) { if (type == 0x0c00) {
PUSHL(oldss); PUSHL(oldss);
PUSHL(oldsp2); PUSHL(oldsp2);
if (cpu_state.abrt) { if (cpu_state.abrt) {
SS = oldss; SS = oldss;
ESP = oldsp2; ESP = oldsp2;
#ifdef USE_NEW_DYNAREC #ifdef USE_NEW_DYNAREC
CS = oldcs; CS = oldcs;
#endif #endif
return; return;
} }
if (count) { if (count) {
while (count--) { while (count--) {

View File

@@ -57,8 +57,6 @@
#define STAT_IFULL 0x02 #define STAT_IFULL 0x02
#define STAT_OFULL 0x01 #define STAT_OFULL 0x01
#define PS2_REFRESH_TIME (16 * TIMER_USEC)
#define RESET_DELAY_TIME (100 * 10) /* 600ms */ #define RESET_DELAY_TIME (100 * 10) /* 600ms */
#define CCB_UNUSED 0x80 #define CCB_UNUSED 0x80
@@ -98,8 +96,7 @@ typedef struct {
uint8_t command, status, old_status, out, old_out, secr_phase, uint8_t command, status, old_status, out, old_out, secr_phase,
mem_addr, input_port, output_port, old_output_port, mem_addr, input_port, output_port, old_output_port,
key_command, output_locked, ami_stat, want60, key_command, output_locked, ami_stat, want60,
wantirq, key_wantdata, refresh, first_write, wantirq, key_wantdata, ami_flags, first_write;
ami_flags, pad[7];
uint8_t mem[0x100]; uint8_t mem[0x100];
@@ -109,7 +106,7 @@ typedef struct {
uint32_t flags; uint32_t flags;
pc_timer_t refresh_time, pulse_cb; pc_timer_t pulse_cb;
uint8_t (*write60_ven)(void *p, uint8_t val); uint8_t (*write60_ven)(void *p, uint8_t val);
uint8_t (*write64_ven)(void *p, uint8_t val); uint8_t (*write64_ven)(void *p, uint8_t val);
@@ -1706,11 +1703,6 @@ kbd_write(uint16_t port, uint8_t val, void *priv)
uint8_t mask, kbc_ven = 0x0; uint8_t mask, kbc_ven = 0x0;
kbc_ven = dev->flags & KBC_VEN_MASK; kbc_ven = dev->flags & KBC_VEN_MASK;
if ((kbc_ven == KBC_VEN_XI8088) && (port == 0x63))
port = 0x61;
kbd_log((port == 0x61) ? "" : "ATkbc: write(%04X, %02X)\n", port, val);
switch (port) { switch (port) {
case 0x60: case 0x60:
dev->status &= ~STAT_CD; dev->status &= ~STAT_CD;
@@ -1972,20 +1964,6 @@ kbd_write(uint16_t port, uint8_t val, void *priv)
} }
break; break;
case 0x61:
ppi.pb = (ppi.pb & 0x10) | (val & 0x0f);
speaker_update();
speaker_gated = val & 1;
speaker_enable = val & 2;
if (speaker_enable)
was_speaker_enable = 1;
pit_ctr_set_gate(&pit->counters[2], val & 1);
if (kbc_ven == KBC_VEN_XI8088)
xi8088_turbo_set(!!(val & 0x04));
break;
case 0x64: case 0x64:
/* Controller command. */ /* Controller command. */
dev->want60 = 0; dev->want60 = 0;
@@ -2135,9 +2113,6 @@ kbd_read(uint16_t port, void *priv)
if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF)
cycles -= ISA_CYCLES(8); cycles -= ISA_CYCLES(8);
if ((kbc_ven == KBC_VEN_XI8088) && (port == 0x63))
port = 0x61;
switch (port) { switch (port) {
case 0x60: case 0x60:
ret = dev->out; ret = dev->out;
@@ -2146,56 +2121,6 @@ kbd_read(uint16_t port, void *priv)
dev->last_irq = 0; dev->last_irq = 0;
break; break;
case 0x61:
ret = ppi.pb & ~0xe0;
if (ppispeakon)
ret |= 0x20;
if ((dev->flags & KBC_TYPE_MASK) > KBC_TYPE_PS2_NOREF) {
if (dev->refresh)
ret |= 0x10;
else
ret &= ~0x10;
}
if (kbc_ven == KBC_VEN_XI8088) {
if (xi8088_turbo_get())
ret |= 0x04;
else
ret &= ~0x04;
}
break;
case 0x62:
ret = 0xff;
if (kbc_ven == KBC_VEN_OLIVETTI) {
/* SWA on Olivetti M240 mainboard (off=1) */
ret = 0x00;
if (ppi.pb & 0x8) {
/* Switches 4, 5 - floppy drives (number) */
int i, fdd_count = 0;
for (i = 0; i < FDD_NUM; i++) {
if (fdd_get_flags(i))
fdd_count++;
}
if (!fdd_count)
ret |= 0x00;
else
ret |= ((fdd_count - 1) << 2);
/* Switches 6, 7 - monitor type */
if (video_is_mda())
ret |= 0x3;
else if (video_is_cga())
ret |= 0x2; /* 0x10 would be 40x25 */
else
ret |= 0x0;
} else {
/* bit 2 always on */
ret |= 0x4;
/* Switch 8 - 8087 FPU. */
if (hasfpu)
ret |= 0x02;
}
}
break;
case 0x64: case 0x64:
ret = (dev->status & 0xfb); ret = (dev->status & 0xfb);
if (dev->mem[0] & STAT_SYSFLAG) if (dev->mem[0] & STAT_SYSFLAG)
@@ -2219,16 +2144,6 @@ kbd_read(uint16_t port, void *priv)
} }
static void
kbd_refresh(void *priv)
{
atkbd_t *dev = (atkbd_t *)priv;
dev->refresh = !dev->refresh;
timer_advance_u64(&dev->refresh_time, PS2_REFRESH_TIME);
}
static void static void
kbd_reset(void *priv) kbd_reset(void *priv)
{ {
@@ -2273,7 +2188,7 @@ kbd_reset(void *priv)
set_scancode_map(dev); set_scancode_map(dev);
dev->ami_flags = ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) ? 0x01 : 0x00); dev->ami_flags = ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) ? 0x01 : 0x00;
} }
@@ -2295,7 +2210,6 @@ kbd_close(void *priv)
/* Stop timers. */ /* Stop timers. */
timer_disable(&dev->send_delay_timer); timer_disable(&dev->send_delay_timer);
timer_disable(&dev->refresh_time);
keyboard_scan = 0; keyboard_scan = 0;
keyboard_send = NULL; keyboard_send = NULL;
@@ -2321,15 +2235,11 @@ kbd_init(const device_t *info)
video_reset(gfxcard); video_reset(gfxcard);
kbd_reset(dev); kbd_reset(dev);
io_sethandler(0x0060, 5, io_sethandler(0x0060, 1, kbd_read, NULL, NULL, kbd_write, NULL, NULL, dev);
kbd_read, NULL, NULL, kbd_write, NULL, NULL, dev); io_sethandler(0x0064, 1, kbd_read, NULL, NULL, kbd_write, NULL, NULL, dev);
keyboard_send = add_data_kbd; keyboard_send = add_data_kbd;
timer_add(&dev->send_delay_timer, kbd_poll, dev, 1); timer_add(&dev->send_delay_timer, kbd_poll, dev, 1);
if ((dev->flags & KBC_TYPE_MASK) > KBC_TYPE_PS2_NOREF)
timer_add(&dev->refresh_time, kbd_refresh, dev, 1);
timer_add(&dev->pulse_cb, pulse_poll, dev, 0); timer_add(&dev->pulse_cb, pulse_poll, dev, 0);
dev->write60_ven = NULL; dev->write60_ven = NULL;

View File

@@ -139,6 +139,7 @@ win_log(const char *fmt, ...)
#endif #endif
void
free_string(rc_str_t **str) free_string(rc_str_t **str)
{ {
if (*str != NULL) { if (*str != NULL) {