Skip to content

Commit

Permalink
MAIN: fix interrupt not chained properly due to f5c6321
Browse files Browse the repository at this point in the history
  • Loading branch information
crazii committed Jan 24, 2024
1 parent 84135ae commit 3e4cd68
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
28 changes: 17 additions & 11 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ static uint32_t MAIN_DMA_MappedAddr = 0;
static uint8_t MAIN_QEMM_Present = 0;
static uint8_t MAIN_HDPMI_Present = 0;
static uint8_t MAIN_InINT;
#define MAIN_ININT_PM 0x01
#define MAIN_ININT_RM 0x02

SBEMU_EXTFUNS MAIN_SbemuExtFun;

Expand Down Expand Up @@ -917,30 +919,34 @@ int main(int argc, char* argv[])

static void MAIN_InterruptPM()
{
if(MAIN_InINT) return;
if(MAIN_InINT&MAIN_ININT_PM) return;
//DBG_Log("INTPM %d\n", MAIN_InINT);

HDPMIPT_GetInterrupContext(&MAIN_IntContext);
if(aui.card_handler->irq_routine && aui.card_handler->irq_routine(&aui)) //check if the irq belong the sound card
if(!MAIN_InINT && aui.card_handler->irq_routine && aui.card_handler->irq_routine(&aui)) //check if the irq belong the sound card
{
MAIN_Interrupt();
PIC_SendEOIWithIRQ(aui.card_irq);
}
else
{
BOOL InInt = MAIN_InINT;
MAIN_InINT = TRUE;
if(MAIN_IntContext.EFLAGS&CPU_VMFLAG)
MAIN_InINT |= MAIN_ININT_PM;
if((MAIN_InINT&MAIN_ININT_RM) || (MAIN_IntContext.EFLAGS&CPU_VMFLAG))
DPMI_CallOldISR(&MAIN_IntHandlePM);
else
DPMI_CallOldISRWithContext(&MAIN_IntHandlePM, &MAIN_IntContext.regs);
PIC_UnmaskIRQ(aui.card_irq);
MAIN_InINT = InInt;
MAIN_InINT &= ~MAIN_ININT_PM;
//DBG_Log("INTPME %d\n", MAIN_InINT);
}
}

static void MAIN_InterruptRM()
{
if(MAIN_InINT) return;
if(aui.card_handler->irq_routine && aui.card_handler->irq_routine(&aui)) //check if the irq belong the sound card
if(MAIN_InINT&MAIN_ININT_RM) return;
//DBG_Log("INTRM %d\n", MAIN_InINT);

if(!MAIN_InINT && aui.card_handler->irq_routine && aui.card_handler->irq_routine(&aui)) //check if the irq belong the sound card
{
MAIN_IntContext.regs = MAIN_RMIntREG;
MAIN_IntContext.EFLAGS = MAIN_RMIntREG.w.flags | CPU_VMFLAG;
Expand All @@ -949,12 +955,12 @@ static void MAIN_InterruptRM()
}
else
{
BOOL InInt = MAIN_InINT;
MAIN_InINT = TRUE;
MAIN_InINT |= MAIN_ININT_RM;
DPMI_REG r = MAIN_RMIntREG; //don't modify MAIN_RMIntREG on hardware interrupt
DPMI_CallRealModeOldISR(&MAIN_IntHandleRM, &r);
PIC_UnmaskIRQ(aui.card_irq);
MAIN_InINT = InInt;
MAIN_InINT &= ~MAIN_ININT_RM;
//DBG_Log("INTRME %d\n", MAIN_InINT);
}
}

Expand Down
2 changes: 1 addition & 1 deletion sbemu/dpmi/dbgutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#ifndef DEBUG
#define DEBUG 0
#elif DEBUG != 0
#else
#undef DEBUG
#define DEBUG 1
#endif
Expand Down
10 changes: 7 additions & 3 deletions sbemu/dpmi/dpmi_dj2.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,19 @@ uint32_t DPMI_CallOldISRWithContext(DPMI_ISR_HANDLE* inputp handle, const DPMI_R
"mov %0, %%eax \n\t mov %1, %%ecx \n\t mov %2, %%edx \n\t mov %3, %%ebx \n\t mov %4, %%esi \n\t mov %5, %%edi \n\t"
"push %6 \n\t pop %%ds \n\t push %7 \n\t pop %%es \n\t push %8 \n\t pop %%fs \n\t push %9 \n\t pop %%gs \n\t"

//"pushl %10 \n\t andw $0xFCFF, (%%esp) \n\t" //don't restore ebp, lcall uses it.
"push %12 \n\t"
"push %11 \n\t"
//"pushl %10 \n\t andw $0xFCFF, (%%esp) \n\t"
"pushfl \n\t"
"lcall *%11 \n\t"
"mov %13, %%ebp \n\t"
"lcall *4(%%esp) \n\t"
"add $8, %%esp \n\t"

"pop %%gs \n\t pop %%fs \n\t pop %%es \n\t pop %%ds \n\t"
"popfl \n\t popal \n\t"
::"m"(r.d.eax),"m"(r.d.ecx),"m"(r.d.edx),"m"(r.d.ebx),"m"(r.d.esi),"m"(r.d.edi),
"m"(r.w.ds),"m"(r.w.es),"m"(r.w.fs),"m"(r.w.gs),
"m"(r.w.flags), "m"(h.old_offset)
"m"(r.w.flags), "m"(h.old_offset), "m"(h.old_cs), "m"(r.d.ebp)
);
return 0;
}
Expand Down

0 comments on commit 3e4cd68

Please sign in to comment.