From 5b8fb69c49a8645d9707e83d2f1e14a043d0aaa3 Mon Sep 17 00:00:00 2001 From: Extrems Date: Sat, 9 Mar 2024 22:00:00 -0500 Subject: [PATCH] - Avoid needlessly masking PI debug interrupt. --- cube/patches/Makefile | 22 ++++++++++----------- cube/patches/base/emulator.c | 10 +++++++--- cube/patches/base/interrupt.c | 37 ++++++++++++++++++++++++++++++++++- cube/patches/base/interrupt.h | 3 ++- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/cube/patches/Makefile b/cube/patches/Makefile index 086029d9..b84ebd66 100644 --- a/cube/patches/Makefile +++ b/cube/patches/Makefile @@ -365,7 +365,7 @@ dvd.bin: @$(CC) -Os $(OPTS) -c base/base.S @$(CC) -Os $(OPTS) -c base/emulator.c -DASYNC_READ -DDI_PASSTHROUGH -DDVD @$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1 -DDIRECT_DISC - @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000111100000000 + @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000010000000000 @$(CC) -Os $(OPTS) -c base/ipl.c @$(CC) -Os $(OPTS) -c dvd/dvd.c -DASYNC_READ @$(CC) -Os $(OPTS) -c sdgecko/sd.c -DISR_READ=1 -DWRITE=0 @@ -386,7 +386,7 @@ dvd.card.bin: @$(CC) -Os $(OPTS) -c base/emulator.c -DASYNC_READ -DCARD_EMULATOR -DDI_PASSTHROUGH -DDVD @$(CC) -Os $(OPTS) -c base/emulator_card.c -DASYNC_READ @$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1 -DDIRECT_DISC - @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000111100000000 + @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000010000000000 @$(CC) -Os $(OPTS) -c base/ipl.c @$(CC) -Os $(OPTS) -c dvd/dvd.c -DASYNC_READ @$(CC) -Os $(OPTS) -c sdgecko/sd.c -DISR_READ=1 -DQUEUE_SIZE=4 @@ -426,7 +426,7 @@ wkf.bin: @$(CC) -Os $(OPTS) -c base/base.S @$(CC) -Os $(OPTS) -c base/emulator.c -DASYNC_READ @$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1 - @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000111100000000 + @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000010000000000 @$(CC) -Os $(OPTS) -c base/ipl.c @$(CC) -Os $(OPTS) -c wkf/wkf.c -DASYNC_READ @$(CC) -Os $(OPTS) -c sdgecko/sd.c -DISR_READ=1 -DWRITE=0 @@ -447,7 +447,7 @@ wkf.card.bin: @$(CC) -Os $(OPTS) -c base/emulator.c -DASYNC_READ -DCARD_EMULATOR @$(CC) -Os $(OPTS) -c base/emulator_card.c -DASYNC_READ @$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1 - @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000111100000000 + @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000010000000000 @$(CC) -Os $(OPTS) -c base/ipl.c @$(CC) -Os $(OPTS) -c wkf/wkf.c -DASYNC_READ @$(CC) -Os $(OPTS) -c sdgecko/sd.c -DISR_READ=1 -DQUEUE_SIZE=4 @@ -469,7 +469,7 @@ wkf.dtk.bin: @$(CC) -Os $(OPTS) -c base/audio.c @$(CC) -Os $(OPTS) -c base/fifo.c @$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1 - @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000111100000000 + @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000010000000000 @$(CC) -Os $(OPTS) -c base/ipl.c @$(CC) -Os $(OPTS) -c wkf/wkf.c -DASYNC_READ -DQUEUE_SIZE=3 @$(CC) -Os $(OPTS) -c sdgecko/sd.c -DISR_READ=1 -DWRITE=0 @@ -553,7 +553,7 @@ gcloader-v1.bin: @$(CC) -Os $(OPTS) -c base/emulator_dvd.c -DREAD_SPEED_TIER=1 @$(CC) -Os $(OPTS) -c base/DVDMath.c @$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1 -DDIRECT_DISC - @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000111100000000 + @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000010000000000 @$(CC) -Os $(OPTS) -c base/ipl.c @$(CC) -Os $(OPTS) -c dvd/dvd.c -DASYNC_READ -DDVD_MATH -DGCODE @$(CC) -Os $(OPTS) -c sdgecko/sd.c -DISR_READ=1 -DWRITE=0 @@ -576,7 +576,7 @@ gcloader-v1.card.bin: @$(CC) -Os $(OPTS) -c base/emulator.c -DASYNC_READ -DCARD_EMULATOR -DDI_PASSTHROUGH -DGCODE @$(CC) -Os $(OPTS) -c base/emulator_card.c -DASYNC_READ @$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1 -DDIRECT_DISC - @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000111100000000 + @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000001001001000010000000000 @$(CC) -Os $(OPTS) -c base/ipl.c @$(CC) -Os $(OPTS) -c dvd/dvd.c -DASYNC_READ -DGCODE @$(CC) -Os $(OPTS) -c sdgecko/sd.c -DISR_READ=1 -DQUEUE_SIZE=4 @@ -598,7 +598,7 @@ gcloader-v2.bin: @$(CC) -Os $(OPTS) -c base/emulator_dvd.c -DREAD_SPEED_TIER=1 @$(CC) -Os $(OPTS) -c base/DVDMath.c @$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1 - @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000000000000000111100000000 + @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000000000000000010000000000 @$(CC) -Os $(OPTS) -c base/ipl.c @$(CC) -Os $(OPTS) -c gcloader/gcloader.c -DDVD_MATH @$(CC) -Os $(OPTS) -c usbgecko/uart.c @@ -619,7 +619,7 @@ gcloader-v2.card.bin: @$(CC) -Os $(OPTS) -c base/emulator.c -DASYNC_READ -DCARD_EMULATOR -DGCODE @$(CC) -Os $(OPTS) -c base/emulator_card.c -DASYNC_READ @$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1 - @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000000000000000111100000000 + @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000000000000000010000000000 @$(CC) -Os $(OPTS) -c base/ipl.c @$(CC) -Os $(OPTS) -c gcloader/gcloader.c -DQUEUE_SIZE=4 @$(CC) -Os $(OPTS) -c usbgecko/uart.c @@ -639,7 +639,7 @@ gcloader-v2.dtk.bin: @$(CC) -Os $(OPTS) -c base/audio.c @$(CC) -Os $(OPTS) -c base/fifo.c @$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1 - @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000000000000000111100000000 + @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000000000000000010000000000 @$(CC) -Os $(OPTS) -c base/ipl.c @$(CC) -Os $(OPTS) -c gcloader/gcloader.c -DQUEUE_SIZE=3 @$(CC) -Os $(OPTS) -c usbgecko/uart.c @@ -658,7 +658,7 @@ gcloader-v2.eth.bin: @$(CC) -Os $(OPTS) -c base/emulator.c -DASYNC_READ -DBBA -DETH_EMULATOR -DGCODE -DNO_VIDEO @$(CC) -Os $(OPTS) -c base/emulator_eth.c @$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1 - @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000000000000000111101000000 + @$(CC) -Os $(OPTS) -c base/interrupt.c -DIRQ_MASK=0b00000000000000000000010001000000 @$(CC) -Os $(OPTS) -c base/ipl.c @$(CC) -Os $(OPTS) -c gcloader/gcloader.c @$(CC) -Os $(OPTS) -c bba/enc28j60.c diff --git a/cube/patches/base/emulator.c b/cube/patches/base/emulator.c index 05012785..926f9831 100644 --- a/cube/patches/base/emulator.c +++ b/cube/patches/base/emulator.c @@ -1061,11 +1061,13 @@ static void di_interrupt_handler(OSInterrupt interrupt, OSContext *context) static void pi_read(unsigned index, uint32_t *value) { + uint32_t mask = pi_get_interrupt_mask(); + switch (index) { case 0: if (!(pi.reg.intsr & pi.reg.intmsk)) PI[0] = 1; - *value = pi.reg.intsr | (PI[0] & ~0b01000000000101); + *value = pi.reg.intsr | (PI[0] & ~mask); break; case 1: *value = pi.reg.intmsk; @@ -1077,14 +1079,16 @@ static void pi_read(unsigned index, uint32_t *value) static void pi_write(unsigned index, uint32_t value) { + uint32_t mask = pi_get_interrupt_mask(); + switch (index) { case 0: - PI[0] = value & 0b10111111111010; + PI[0] = value & ~mask; pi.reg.intsr = ((value & 0b11000000000011) ^ pi.reg.intsr) & pi.reg.intsr; pi_update_interrupts(); break; case 1: - PI[1] = (value & 0b10111111111010) | (PI[1] & 0b01000000000101); + PI[1] = (value & ~mask) | (PI[1] & mask); pi.reg.intmsk = value & 0b11111111111111; pi_update_interrupts(); break; diff --git a/cube/patches/base/interrupt.c b/cube/patches/base/interrupt.c index 36e1c408..aa30e0aa 100644 --- a/cube/patches/base/interrupt.c +++ b/cube/patches/base/interrupt.c @@ -148,6 +148,35 @@ uint32_t exi_get_interrupt_mask(unsigned chan) return mask; } +uint32_t pi_get_interrupt_mask(void) +{ + uint32_t mask = (OS_INTERRUPTMASK_PI_DI | OS_INTERRUPTMASK_PI_ERROR) >> (31 - OS_INTERRUPT_PI_ERROR); + uint32_t current = irq.mask; + + if (IRQ_MASK & OS_INTERRUPTMASK_PI_CP) + rlwimi(mask, current, OS_INTERRUPT_PI_CP - 20, 20, 20); + if (IRQ_MASK & OS_INTERRUPTMASK_PI_PE_TOKEN) + rlwimi(mask, current, OS_INTERRUPT_PI_PE_TOKEN - 22, 22, 22); + if (IRQ_MASK & OS_INTERRUPTMASK_PI_PE_FINISH) + rlwimi(mask, current, OS_INTERRUPT_PI_PE_FINISH - 21, 21, 21); + if (IRQ_MASK & OS_INTERRUPTMASK_PI_SI) + rlwimi(mask, current, OS_INTERRUPT_PI_SI - 28, 28, 28); +// if (IRQ_MASK & OS_INTERRUPTMASK_PI_DI) +// rlwimi(mask, current, OS_INTERRUPT_PI_DI - 29, 29, 29); + if (IRQ_MASK & OS_INTERRUPTMASK_PI_RSW) + rlwimi(mask, current, OS_INTERRUPT_PI_RSW - 30, 30, 30); +// if (IRQ_MASK & OS_INTERRUPTMASK_PI_ERROR) +// rlwimi(mask, current, OS_INTERRUPT_PI_ERROR - 31, 31, 31); + if (IRQ_MASK & OS_INTERRUPTMASK_PI_VI) + rlwimi(mask, current, OS_INTERRUPT_PI_VI - 23, 23, 23); + if (IRQ_MASK & OS_INTERRUPTMASK_PI_DEBUG) + rlwimi(mask, current, OS_INTERRUPT_PI_DEBUG - 19, 19, 19); + if (IRQ_MASK & OS_INTERRUPTMASK_PI_HSP) + rlwimi(mask, current, OS_INTERRUPT_PI_HSP - 18, 18, 18); + + return mask; +} + void dispatch_interrupt(OSException exception, OSContext *context) { OSInterruptMask cause = 0; @@ -191,8 +220,14 @@ void dispatch_interrupt(OSException exception, OSContext *context) rlwimi(cause, piintsr, 22 - OS_INTERRUPT_PI_PE_TOKEN, OS_INTERRUPT_PI_PE_TOKEN, OS_INTERRUPT_PI_PE_TOKEN); if (IRQ_MASK & OS_INTERRUPTMASK_PI_PE_FINISH) rlwimi(cause, piintsr, 21 - OS_INTERRUPT_PI_PE_FINISH, OS_INTERRUPT_PI_PE_FINISH, OS_INTERRUPT_PI_PE_FINISH); + if (IRQ_MASK & OS_INTERRUPTMASK_PI_SI) + rlwimi(cause, piintsr, 28 - OS_INTERRUPT_PI_SI, OS_INTERRUPT_PI_SI, OS_INTERRUPT_PI_SI); + if (IRQ_MASK & OS_INTERRUPTMASK_PI_DI) + rlwimi(cause, piintsr, 29 - OS_INTERRUPT_PI_DI, OS_INTERRUPT_PI_DI, OS_INTERRUPT_PI_DI); + if (IRQ_MASK & OS_INTERRUPTMASK_PI_RSW) + rlwimi(cause, piintsr, 30 - OS_INTERRUPT_PI_RSW, OS_INTERRUPT_PI_RSW, OS_INTERRUPT_PI_RSW); if (IRQ_MASK & OS_INTERRUPTMASK_PI_ERROR) - rlwimi(cause, piintsr, 31 - OS_INTERRUPT_PI_ERROR, OS_INTERRUPT_PI_SI, OS_INTERRUPT_PI_ERROR); + rlwimi(cause, piintsr, 31 - OS_INTERRUPT_PI_ERROR, OS_INTERRUPT_PI_ERROR, OS_INTERRUPT_PI_ERROR); if (IRQ_MASK & OS_INTERRUPTMASK_PI_VI) rlwimi(cause, piintsr, 23 - OS_INTERRUPT_PI_VI, OS_INTERRUPT_PI_VI, OS_INTERRUPT_PI_VI); if (IRQ_MASK & OS_INTERRUPTMASK_PI_DEBUG) diff --git a/cube/patches/base/interrupt.h b/cube/patches/base/interrupt.h index 2125df47..5b3a7e31 100644 --- a/cube/patches/base/interrupt.h +++ b/cube/patches/base/interrupt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, Extrems + * Copyright (c) 2021-2024, Extrems * * This file is part of Swiss. * @@ -31,5 +31,6 @@ OSInterruptMask mask_user_interrupts(OSInterruptMask mask); OSInterruptMask unmask_user_interrupts(OSInterruptMask mask); uint32_t exi_get_interrupt_mask(unsigned chan); +uint32_t pi_get_interrupt_mask(void); #endif /* INTERRUPT_H */