Skip to content

Commit

Permalink
Implement TSS debug trap bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cacodemon345 committed Jan 13, 2024
1 parent b1c292a commit a13a8ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cpu/386.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ exec386_2386(int32_t cycs)
}
} else if (trap) {
flags_rebuild();
dr[6] |= (trap == 2) ? 0x8000 : 0x4000;
trap = 0;
#ifndef USE_NEW_DYNAREC
oldcs = CS;
#endif
cpu_state.oldpc = cpu_state.pc;
dr[6] |= 0x4000;
x86_int(1);
}

Expand Down
11 changes: 9 additions & 2 deletions src/cpu/386_dynarec.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ exec386_dynarec_int(void)
cpu_block_end = 0;
x86_was_reset = 0;

if (trap == 2) {
/* Handle the T bit in the new TSS first. */
CPU_BLOCK_END();
goto block_ended;
}

while (!cpu_block_end) {
# ifndef USE_NEW_DYNAREC
oldcs = CS;
Expand Down Expand Up @@ -321,13 +327,14 @@ exec386_dynarec_int(void)
CPU_BLOCK_END();
}

block_ended:
if (!cpu_state.abrt && trap) {
dr[6] |= (trap == 2) ? 0x8000 : 0x4000;
trap = 0;
# ifndef USE_NEW_DYNAREC
oldcs = CS;
# endif
cpu_state.oldpc = cpu_state.pc;
dr[6] |= 0x4000;
x86_int(1);
}

Expand Down Expand Up @@ -542,7 +549,7 @@ exec386_dynarec_dyn(void)
# endif
CPU_BLOCK_END();

if (cpu_state.flags & T_FLAG)
if ((cpu_state.flags & T_FLAG) || (trap == 2))
CPU_BLOCK_END();
if (smi_line)
CPU_BLOCK_END();
Expand Down
13 changes: 13 additions & 0 deletions src/cpu/x86seg.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ x86seg_log(const char *fmt, ...)
# define x86seg_log(fmt, ...)
#endif

#ifdef USE_DYNAREC
extern int cpu_block_end;
#endif

void
#ifdef OPS_286_386
x86_doabrt_2386(int x86_abrt)
Expand Down Expand Up @@ -2088,6 +2092,7 @@ taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
uint32_t new_edi;
uint32_t new_pc;
uint32_t new_flags;
uint32_t t_bit;
uint32_t addr;
uint32_t *segdat232 = (uint32_t *) segdat2;
const x86seg *dt;
Expand Down Expand Up @@ -2189,6 +2194,7 @@ taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
new_fs = readmemw(base, 0x58);
new_gs = readmemw(base, 0x5C);
new_ldt = readmemw(base, 0x60);
t_bit = readmemb(base, 0x64) & 1;

cr0 |= 8;

Expand Down Expand Up @@ -2279,6 +2285,13 @@ taskswitch286(uint16_t seg, uint16_t *segdat, int is32)
op_loadseg(new_ds, &cpu_state.seg_ds);
op_loadseg(new_fs, &cpu_state.seg_fs);
op_loadseg(new_gs, &cpu_state.seg_gs);

if (t_bit) {
trap = 2;
#ifdef USE_DYNAREC
cpu_block_end = 1;
#endif
}
} else {
if (limit < 43) {
x86ts(NULL, seg);
Expand Down

0 comments on commit a13a8ef

Please sign in to comment.