Skip to content

Commit

Permalink
- Add basic forward-only ENC28J60 driver in hypervisor. (Serial Port …
Browse files Browse the repository at this point in the history
…2 only)

- Enable Broadband Adapter emulation for IDE-EXI and M.2 Loader.
  • Loading branch information
Extrems committed Feb 29, 2024
1 parent 812454e commit b1ac1de
Show file tree
Hide file tree
Showing 12 changed files with 574 additions and 14 deletions.
48 changes: 46 additions & 2 deletions cube/patches/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ all: clean codehandler cpatches stub sdpatch ideexipatch dvdpatch usbgeckopatch

stub: reboot.bin stub.bin
sdpatch: sd.bin sd.card.bin sd.dtk.bin
ideexipatch: ideexi-v1.bin ideexi-v1.card.bin ideexi-v1.dtk.bin ideexi-v2.bin ideexi-v2.card.bin ideexi-v2.dtk.bin
ideexipatch: ideexi-v1.bin ideexi-v1.card.bin ideexi-v1.dtk.bin ideexi-v1.eth.bin ideexi-v2.bin ideexi-v2.card.bin ideexi-v2.dtk.bin ideexi-v2.eth.bin
dvdpatch: dvd.bin dvd.card.bin
usbgeckopatch: usbgecko.bin
wkfpatch: wkf.bin wkf.card.bin wkf.dtk.bin
Expand Down Expand Up @@ -227,6 +227,28 @@ ideexi-v1.dtk.bin:
@$(BIN2S) -H $(DEST)/ideexi_v1_dtk_bin.h ideexi-v1.dtk.bin > $(DEST)/ideexi-v1.dtk.bin.s
@rm -f *.bin *.elf *.o

ideexi-v1.eth.bin:
@echo Building IDE-EXI-v1 Patch + ETH ...
@$(CC) -Os $(OPTS) -c base/base.S
@$(CC) -Os $(OPTS) -c base/emulator.c -DASYNC_READ -DBBA -DETH_EMULATOR -DNO_VIDEO
@$(CC) -Os $(OPTS) -c base/emulator_eth.c
@$(CC) -Os $(OPTS) -c base/frag.c
@$(CC) -Os $(OPTS) -c base/interrupt.c
@$(CC) -Os $(OPTS) -c base/ipl.c
@$(CC) -Os $(OPTS) -c base/blockdevice.c -DASYNC_READ
@$(CC) -Os $(OPTS) -c bba/enc28j60.c
@$(CC) -Os $(OPTS) -c ide-exi/ata.c -DDMA_READ=0 -DISR_READ=1 -DWRITE=0
@$(CC) -Os $(OPTS) -c ide-exi/ata_isr.S
@$(CC) -Os $(OPTS) -c usbgecko/uart.c
@$(CC) -Os $(OPTS) -c base/dolphin/os.c
@$(CC) -Os $(OPTS) -c base/memcpy.S
@$(CC) -Os $(OPTS) -o ideexi-v1.eth.elf -T base/base.ld -T base/common.ld -T base/dolphin/os.ld base.o emulator.o emulator_eth.o frag.o interrupt.o ipl.o blockdevice.o enc28j60.o ata.o ata_isr.o uart.o os.o memcpy.o
@mkdir -p $(DISASM)
@$(OBJDUMP) -D ideexi-v1.eth.elf > $(DISASM)/ideexi-v1.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents ideexi-v1.eth.elf ideexi-v1.eth.bin
@$(BIN2S) -H $(DEST)/ideexi_v1_eth_bin.h ideexi-v1.eth.bin > $(DEST)/ideexi-v1.eth.bin.s
@rm -f *.bin *.elf *.o

ideexi-v2.bin:
@echo Building IDE-EXI-v2 Patch ...
@$(CC) -Os $(OPTS) -c base/base.S
Expand Down Expand Up @@ -294,6 +316,28 @@ ideexi-v2.dtk.bin:
@$(BIN2S) -H $(DEST)/ideexi_v2_dtk_bin.h ideexi-v2.dtk.bin > $(DEST)/ideexi-v2.dtk.bin.s
@rm -f *.bin *.elf *.o

ideexi-v2.eth.bin:
@echo Building IDE-EXI-v2 Patch + ETH ...
@$(CC) -Os $(OPTS) -c base/base.S
@$(CC) -Os $(OPTS) -c base/emulator.c -DASYNC_READ -DBBA -DETH_EMULATOR -DNO_VIDEO
@$(CC) -Os $(OPTS) -c base/emulator_eth.c
@$(CC) -Os $(OPTS) -c base/frag.c
@$(CC) -Os $(OPTS) -c base/interrupt.c
@$(CC) -Os $(OPTS) -c base/ipl.c
@$(CC) -Os $(OPTS) -c base/blockdevice.c -DASYNC_READ
@$(CC) -Os $(OPTS) -c bba/enc28j60.c
@$(CC) -Os $(OPTS) -c ide-exi/ata.c -DDMA_READ=1 -DISR_READ=1 -DWRITE=0
@$(CC) -Os $(OPTS) -c ide-exi/ata_isr.S -DDMA
@$(CC) -Os $(OPTS) -c usbgecko/uart.c
@$(CC) -Os $(OPTS) -c base/dolphin/os.c
@$(CC) -Os $(OPTS) -c base/memcpy.S
@$(CC) -Os $(OPTS) -o ideexi-v2.eth.elf -T base/base.ld -T base/common.ld -T base/dolphin/os.ld base.o emulator.o emulator_eth.o frag.o interrupt.o ipl.o blockdevice.o enc28j60.o ata.o ata_isr.o uart.o os.o memcpy.o
@mkdir -p $(DISASM)
@$(OBJDUMP) -D ideexi-v2.eth.elf > $(DISASM)/ideexi-v2.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents ideexi-v2.eth.elf ideexi-v2.eth.bin
@$(BIN2S) -H $(DEST)/ideexi_v2_eth_bin.h ideexi-v2.eth.bin > $(DEST)/ideexi-v2.eth.bin.s
@rm -f *.bin *.elf *.o

dvd.bin:
@echo Building DVD Patch ...
@$(CC) -Os $(OPTS) -c base/base.S
Expand Down Expand Up @@ -464,7 +508,7 @@ fsp.eth.bin:
@echo Building FSP Patch + ETH ...
@$(CC) -Os $(OPTS) -c base/base.S
@$(CC) -Os $(OPTS) -c base/emulator.c -DASYNC_READ -DBBA -DETH_EMULATOR -DNO_VIDEO
@$(CC) -Os $(OPTS) -c base/emulator_eth.c
@$(CC) -Os $(OPTS) -c base/emulator_eth.c -DBBA
@$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1
@$(CC) -Os $(OPTS) -c base/interrupt.c
@$(CC) -Os $(OPTS) -c base/ipl.c
Expand Down
8 changes: 4 additions & 4 deletions cube/patches/base/emulator.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2023, Extrems <extrems@extremscorner.org>
* Copyright (c) 2019-2024, Extrems <extrems@extremscorner.org>
*
* This file is part of Swiss.
*
Expand Down Expand Up @@ -1049,7 +1049,7 @@ static void pi_read(unsigned index, uint32_t *value)
case 0:
if (!(pi.reg.intsr & pi.reg.intmsk))
PI[0] = 1;
*value = pi.reg.intsr | (PI[0] & ~0b00000000000101);
*value = pi.reg.intsr | (PI[0] & ~0b01000000000101);
break;
case 1:
*value = pi.reg.intmsk;
Expand All @@ -1063,12 +1063,12 @@ static void pi_write(unsigned index, uint32_t value)
{
switch (index) {
case 0:
PI[0] = value & 0b11111111111010;
PI[0] = value & 0b10111111111010;
pi.reg.intsr = ((value & 0b11000000000011) ^ pi.reg.intsr) & pi.reg.intsr;
pi_update_interrupts();
break;
case 1:
PI[1] = (value & 0b11111111111010) | (PI[1] & 0b00000000000101);
PI[1] = (value & 0b10111111111010) | (PI[1] & 0b01000000000101);
pi.reg.intmsk = value & 0b11111111111111;
pi_update_interrupts();
break;
Expand Down
5 changes: 4 additions & 1 deletion cube/patches/base/emulator_eth.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Extrems <extrems@extremscorner.org>
* Copyright (c) 2023-2024, Extrems <extrems@extremscorner.org>
*
* This file is part of Swiss.
*
Expand All @@ -19,6 +19,7 @@

#include <ppu_intrinsics.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "bba/bba.h"
#include "common.h"
Expand Down Expand Up @@ -141,10 +142,12 @@ static void eth_mac_write(uint8_t value)
(*eth.mac.fifo)[eth.mac.txfifocnt++] = value;
break;
}
#ifdef BBA
case BBA_NAFR_MAR0 ... BBA_NAFR_MAR7:
{
bba_out8(address, value);
}
#endif
default:
{
(*eth.mac.data)[(address - 256) % 4096 + 256] = value;
Expand Down
3 changes: 2 additions & 1 deletion cube/patches/base/emulator_eth.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Extrems <extrems@extremscorner.org>
* Copyright (c) 2023-2024, Extrems <extrems@extremscorner.org>
*
* This file is part of Swiss.
*
Expand All @@ -21,6 +21,7 @@
#define EMULATOR_ETH_H

#include <stdint.h>
#include <stddef.h>

void eth_mac_receive(const void *data, size_t size);

Expand Down
10 changes: 5 additions & 5 deletions cube/patches/base/interrupt.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023, Extrems <extrems@extremscorner.org>
* Copyright (c) 2021-2024, Extrems <extrems@extremscorner.org>
*
* This file is part of Swiss.
*
Expand Down Expand Up @@ -134,7 +134,7 @@ uint32_t exi_get_interrupt_mask(unsigned chan)

rlwinm(mask, current, OS_INTERRUPT_EXI_0_EXI - 30, 30, 30);
rlwimi(mask, current, OS_INTERRUPT_EXI_0_TC - 28, 28, 28);
rlwimi(mask, current, OS_INTERRUPT_EXI_0_EXT - 20, 20, 20);
// rlwimi(mask, current, OS_INTERRUPT_EXI_0_EXT - 20, 20, 20);

return mask;
}
Expand All @@ -149,12 +149,12 @@ void dispatch_interrupt(OSException exception, OSContext *context)
uint32_t exi0cpr = EXI[EXI_CHANNEL_0][0];
rlwinm(cause, exi0cpr, 30 - OS_INTERRUPT_EXI_0_EXI, OS_INTERRUPT_EXI_0_EXI, OS_INTERRUPT_EXI_0_EXI);
rlwimi(cause, exi0cpr, 28 - OS_INTERRUPT_EXI_0_TC, OS_INTERRUPT_EXI_0_TC, OS_INTERRUPT_EXI_0_TC);
rlwimi(cause, exi0cpr, 20 - OS_INTERRUPT_EXI_0_EXT, OS_INTERRUPT_EXI_0_EXT, OS_INTERRUPT_EXI_0_EXT);
// rlwimi(cause, exi0cpr, 20 - OS_INTERRUPT_EXI_0_EXT, OS_INTERRUPT_EXI_0_EXT, OS_INTERRUPT_EXI_0_EXT);

uint32_t exi1cpr = EXI[EXI_CHANNEL_1][0];
rlwimi(cause, exi1cpr, 30 - OS_INTERRUPT_EXI_1_EXI, OS_INTERRUPT_EXI_1_EXI, OS_INTERRUPT_EXI_1_EXI);
rlwimi(cause, exi1cpr, 28 - OS_INTERRUPT_EXI_1_TC, OS_INTERRUPT_EXI_1_TC, OS_INTERRUPT_EXI_1_TC);
rlwimi(cause, exi1cpr, 20 - OS_INTERRUPT_EXI_1_EXT, OS_INTERRUPT_EXI_1_EXT, OS_INTERRUPT_EXI_1_EXT);
// rlwimi(cause, exi1cpr, 20 - OS_INTERRUPT_EXI_1_EXT, OS_INTERRUPT_EXI_1_EXT, OS_INTERRUPT_EXI_1_EXT);

uint32_t exi2cpr = EXI[EXI_CHANNEL_2][0];
rlwimi(cause, exi2cpr, 30 - OS_INTERRUPT_EXI_2_EXI, OS_INTERRUPT_EXI_2_EXI, OS_INTERRUPT_EXI_2_EXI);
Expand All @@ -166,7 +166,7 @@ void dispatch_interrupt(OSException exception, OSContext *context)
// rlwimi(cause, piintsr, 21 - OS_INTERRUPT_PI_PE_FINISH, OS_INTERRUPT_PI_PE_FINISH, OS_INTERRUPT_PI_PE_FINISH);
rlwimi(cause, piintsr, 31 - OS_INTERRUPT_PI_ERROR, OS_INTERRUPT_PI_SI, OS_INTERRUPT_PI_ERROR);
// rlwimi(cause, piintsr, 23 - OS_INTERRUPT_PI_VI, OS_INTERRUPT_PI_VI, OS_INTERRUPT_PI_VI);
// rlwimi(cause, piintsr, 19 - OS_INTERRUPT_PI_DEBUG, OS_INTERRUPT_PI_DEBUG, OS_INTERRUPT_PI_DEBUG);
rlwimi(cause, piintsr, 19 - OS_INTERRUPT_PI_DEBUG, OS_INTERRUPT_PI_DEBUG, OS_INTERRUPT_PI_DEBUG);
// rlwimi(cause, piintsr, 18 - OS_INTERRUPT_PI_HSP, OS_INTERRUPT_PI_HSP, OS_INTERRUPT_PI_HSP);

if (cause & irq.mask) {
Expand Down

0 comments on commit b1ac1de

Please sign in to comment.