Skip to content

Commit

Permalink
- Add basic forward-only W5500 driver in hypervisor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Oct 25, 2024
1 parent 00491ae commit 1adc920
Show file tree
Hide file tree
Showing 7 changed files with 692 additions and 58 deletions.
78 changes: 54 additions & 24 deletions cube/patches/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,19 @@ sd-v1.eth.bin:
@$(CC) -Os $(OPTS) -c sdgecko/sd.c -DDMA_READ=0 -DISR_READ=1 -DWRITE=0
@$(CC) -Os $(OPTS) -c sdgecko/sd_isr.S
@$(CC) -Os $(OPTS) -c bba/enc28j60.c
@$(CC) -Os $(OPTS) -c bba/w5500.c
@$(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 sd-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 sd.o sd_isr.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o sd-v1-enc28j60.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 sd.o sd_isr.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o sd-v1-w5500.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 sd.o sd_isr.o w5500.o uart.o os.o memcpy.o
@mkdir -p $(DISASM)
@$(OBJDUMP) -D sd-v1.eth.elf > $(DISASM)/sd-v1.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents sd-v1.eth.elf sd-v1.eth.bin
@$(BIN2S) -H $(DEST)/sd_v1_eth_bin.h sd-v1.eth.bin > $(DEST)/sd-v1.eth.bin.s
@$(OBJDUMP) -D sd-v1-enc28j60.eth.elf > $(DISASM)/sd-v1-enc28j60.eth.txt
@$(OBJDUMP) -D sd-v1-w5500.eth.elf > $(DISASM)/sd-v1-w5500.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents sd-v1-enc28j60.eth.elf sd-v1-enc28j60.eth.bin
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents sd-v1-w5500.eth.elf sd-v1-w5500.eth.bin
@$(BIN2S) -H $(DEST)/sd_v1_enc28j60_eth_bin.h sd-v1-enc28j60.eth.bin > $(DEST)/sd-v1-enc28j60.eth.bin.s
@$(BIN2S) -H $(DEST)/sd_v1_w5500_eth_bin.h sd-v1-w5500.eth.bin > $(DEST)/sd-v1-w5500.eth.bin.s
@rm -f *.bin *.elf *.o

sd-v2.bin:
Expand Down Expand Up @@ -246,14 +251,19 @@ sd-v2.eth.bin:
@$(CC) -Os $(OPTS) -c sdgecko/sd.c -DDMA_READ=1 -DISR_READ=1 -DWRITE=0
@$(CC) -Os $(OPTS) -c sdgecko/sd_isr.S -DDMA
@$(CC) -Os $(OPTS) -c bba/enc28j60.c
@$(CC) -Os $(OPTS) -c bba/w5500.c
@$(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 sd-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 sd.o sd_isr.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o sd-v2-enc28j60.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 sd.o sd_isr.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o sd-v2-w5500.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 sd.o sd_isr.o w5500.o uart.o os.o memcpy.o
@mkdir -p $(DISASM)
@$(OBJDUMP) -D sd-v2.eth.elf > $(DISASM)/sd-v2.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents sd-v2.eth.elf sd-v2.eth.bin
@$(BIN2S) -H $(DEST)/sd_v2_eth_bin.h sd-v2.eth.bin > $(DEST)/sd-v2.eth.bin.s
@$(OBJDUMP) -D sd-v2-enc28j60.eth.elf > $(DISASM)/sd-v2-enc28j60.eth.txt
@$(OBJDUMP) -D sd-v2-w5500.eth.elf > $(DISASM)/sd-v2-w5500.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents sd-v2-enc28j60.eth.elf sd-v2-enc28j60.eth.bin
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents sd-v2-w5500.eth.elf sd-v2-w5500.eth.bin
@$(BIN2S) -H $(DEST)/sd_v2_enc28j60_eth_bin.h sd-v2-enc28j60.eth.bin > $(DEST)/sd-v2-enc28j60.eth.bin.s
@$(BIN2S) -H $(DEST)/sd_v2_w5500_eth_bin.h sd-v2-w5500.eth.bin > $(DEST)/sd-v2-w5500.eth.bin.s
@rm -f *.bin *.elf *.o

ideexi-v1.bin:
Expand Down Expand Up @@ -335,14 +345,19 @@ ideexi-v1.eth.bin:
@$(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 bba/enc28j60.c
@$(CC) -Os $(OPTS) -c bba/w5500.c
@$(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 ata.o ata_isr.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o ideexi-v1-enc28j60.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 ata.o ata_isr.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o ideexi-v1-w5500.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 ata.o ata_isr.o w5500.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
@$(OBJDUMP) -D ideexi-v1-enc28j60.eth.elf > $(DISASM)/ideexi-v1-enc28j60.eth.txt
@$(OBJDUMP) -D ideexi-v1-w5500.eth.elf > $(DISASM)/ideexi-v1-w5500.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents ideexi-v1-enc28j60.eth.elf ideexi-v1-enc28j60.eth.bin
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents ideexi-v1-w5500.eth.elf ideexi-v1-w5500.eth.bin
@$(BIN2S) -H $(DEST)/ideexi_v1_enc28j60_eth_bin.h ideexi-v1-enc28j60.eth.bin > $(DEST)/ideexi-v1-enc28j60.eth.bin.s
@$(BIN2S) -H $(DEST)/ideexi_v1_w5500_eth_bin.h ideexi-v1-w5500.eth.bin > $(DEST)/ideexi-v1-w5500.eth.bin.s
@rm -f *.bin *.elf *.o

ideexi-v2.bin:
Expand Down Expand Up @@ -424,14 +439,19 @@ ideexi-v2.eth.bin:
@$(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 bba/enc28j60.c
@$(CC) -Os $(OPTS) -c bba/w5500.c
@$(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 ata.o ata_isr.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o ideexi-v2-enc28j60.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 ata.o ata_isr.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o ideexi-v2-w5500.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 ata.o ata_isr.o w5500.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
@$(OBJDUMP) -D ideexi-v2-enc28j60.eth.elf > $(DISASM)/ideexi-v2-enc28j60.eth.txt
@$(OBJDUMP) -D ideexi-v2-w5500.eth.elf > $(DISASM)/ideexi-v2-w5500.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents ideexi-v2-enc28j60.eth.elf ideexi-v2-enc28j60.eth.bin
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents ideexi-v2-w5500.eth.elf ideexi-v2-w5500.eth.bin
@$(BIN2S) -H $(DEST)/ideexi_v2_enc28j60_eth_bin.h ideexi-v2-enc28j60.eth.bin > $(DEST)/ideexi-v2-enc28j60.eth.bin.s
@$(BIN2S) -H $(DEST)/ideexi_v2_w5500_eth_bin.h ideexi-v2-w5500.eth.bin > $(DEST)/ideexi-v2-w5500.eth.bin.s
@rm -f *.bin *.elf *.o

dvd.bin:
Expand Down Expand Up @@ -736,14 +756,19 @@ gcloader-v2.eth.bin:
@$(CC) -Os $(OPTS) -c base/ipl.c
@$(CC) -Os $(OPTS) -c gcloader/gcloader.c
@$(CC) -Os $(OPTS) -c bba/enc28j60.c
@$(CC) -Os $(OPTS) -c bba/w5500.c
@$(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 gcloader-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 gcloader.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o gcloader-v2-enc28j60.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 gcloader.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o gcloader-v2-w5500.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 gcloader.o w5500.o uart.o os.o memcpy.o
@mkdir -p $(DISASM)
@$(OBJDUMP) -D gcloader-v2.eth.elf > $(DISASM)/gcloader-v2.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents gcloader-v2.eth.elf gcloader-v2.eth.bin
@$(BIN2S) -H $(DEST)/gcloader_v2_eth_bin.h gcloader-v2.eth.bin > $(DEST)/gcloader-v2.eth.bin.s
@$(OBJDUMP) -D gcloader-v2-enc28j60.eth.elf > $(DISASM)/gcloader-v2-enc28j60.eth.txt
@$(OBJDUMP) -D gcloader-v2-w5500.eth.elf > $(DISASM)/gcloader-v2-w5500.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents gcloader-v2-enc28j60.eth.elf gcloader-v2-enc28j60.eth.bin
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents gcloader-v2-w5500.eth.elf gcloader-v2-w5500.eth.bin
@$(BIN2S) -H $(DEST)/gcloader_v2_enc28j60_eth_bin.h gcloader-v2-enc28j60.eth.bin > $(DEST)/gcloader-v2-enc28j60.eth.bin.s
@$(BIN2S) -H $(DEST)/gcloader_v2_w5500_eth_bin.h gcloader-v2-w5500.eth.bin > $(DEST)/gcloader-v2-w5500.eth.bin.s
@rm -f *.bin *.elf *.o

flippy.bin:
Expand Down Expand Up @@ -797,12 +822,17 @@ flippy.eth.bin:
@$(CC) -Os $(OPTS) -c base/ipl.c
@$(CC) -Os $(OPTS) -c flippydrive/flippy.c
@$(CC) -Os $(OPTS) -c bba/enc28j60.c
@$(CC) -Os $(OPTS) -c bba/w5500.c
@$(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 flippy.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 flippy.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o flippy-enc28j60.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 flippy.o enc28j60.o uart.o os.o memcpy.o
@$(CC) -Os $(OPTS) -o flippy-w5500.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 flippy.o w5500.o uart.o os.o memcpy.o
@mkdir -p $(DISASM)
@$(OBJDUMP) -D flippy.eth.elf > $(DISASM)/flippy.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents flippy.eth.elf flippy.eth.bin
@$(BIN2S) -H $(DEST)/flippy_eth_bin.h flippy.eth.bin > $(DEST)/flippy.eth.bin.s
@$(OBJDUMP) -D flippy-enc28j60.eth.elf > $(DISASM)/flippy-enc28j60.eth.txt
@$(OBJDUMP) -D flippy-w5500.eth.elf > $(DISASM)/flippy-w5500.eth.txt
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents flippy-enc28j60.eth.elf flippy-enc28j60.eth.bin
@$(OBJCOPY) -O binary --set-section-flags .bss.*=alloc,load,contents flippy-w5500.eth.elf flippy-w5500.eth.bin
@$(BIN2S) -H $(DEST)/flippy_enc28j60_eth_bin.h flippy-enc28j60.eth.bin > $(DEST)/flippy-enc28j60.eth.bin.s
@$(BIN2S) -H $(DEST)/flippy_w5500_eth_bin.h flippy-w5500.eth.bin > $(DEST)/flippy-w5500.eth.bin.s
@rm -f *.bin *.elf *.o
35 changes: 18 additions & 17 deletions cube/patches/bba/enc28j60.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static struct {
size_t size;
bba_callback callback;
} output;
} _bba;
} enc28j60;

static void exi_clear_interrupts(bool exi, bool tc, bool ext)
{
Expand Down Expand Up @@ -121,11 +121,11 @@ static void enc28j60_select_bank(uint8_t addr)
{
uint8_t bank = addr >> 5;

if (_bba.bank != bank && bank < 4) {
enc28j60_clear_bits(ENC28J60_ECON1, ENC28J60_ECON1_BSEL(_bba.bank));
if (enc28j60.bank != bank && bank < 4) {
enc28j60_clear_bits(ENC28J60_ECON1, ENC28J60_ECON1_BSEL(enc28j60.bank));
enc28j60_set_bits(ENC28J60_ECON1, ENC28J60_ECON1_BSEL(bank));

_bba.bank = bank;
enc28j60.bank = bank;
}
}

Expand Down Expand Up @@ -158,11 +158,11 @@ static void enc28j60_interrupt(void)
uint16_t byte_count = rsv[1];
//uint16_t status = rsv[2];

DCInvalidateRange(__builtin_assume_aligned(_bba.page, 32), byte_count);
exi_dma_read(_bba.page, byte_count, true);
DCInvalidateRange(__builtin_assume_aligned(enc28j60.page, 32), byte_count);
exi_dma_read(enc28j60.page, byte_count, true);
exi_deselect();

eth_mac_receive(_bba.page, byte_count - 4);
eth_mac_receive(enc28j60.page, byte_count - 4);

enc28j60_write_reg16(ENC28J60_ERDPT, next_packet);
enc28j60_write_reg16(ENC28J60_ERXRDPT, next_packet == ENC28J60_INIT_ERXST ? ENC28J60_INIT_ERXND : next_packet - 1);
Expand All @@ -176,13 +176,14 @@ static void enc28j60_interrupt(void)
static void exi_callback()
{
if (EXILock(exi_channel, exi_device, exi_callback)) {
if (_bba.output.callback) {
bba_output(_bba.output.data, _bba.output.size);
_bba.output.callback();
_bba.output.callback = NULL;
enc28j60_interrupt();

if (enc28j60.output.callback) {
bba_output(enc28j60.output.data, enc28j60.output.size);
enc28j60.output.callback();
enc28j60.output.callback = NULL;
}

enc28j60_interrupt();
EXIUnlock(exi_channel);
}
}
Expand Down Expand Up @@ -219,20 +220,20 @@ void bba_output(const void *data, size_t size)

void bba_output_async(const void *data, size_t size, bba_callback callback)
{
_bba.output.data = (void *)data;
_bba.output.size = size;
_bba.output.callback = callback;
enc28j60.output.data = (void *)data;
enc28j60.output.size = size;
enc28j60.output.callback = callback;

exi_callback();
}

void bba_init(void **arenaLo, void **arenaHi)
{
*arenaHi -= sizeof(*_bba.page); _bba.page = *arenaHi;

enc28j60_clear_bits(ENC28J60_EIE, 0xFF);
enc28j60_set_bits(ENC28J60_EIE, ENC28J60_EIE_INTIE | ENC28J60_EIE_PKTIE);

*arenaHi -= sizeof(*enc28j60.page); enc28j60.page = *arenaHi;

if (exi_channel < EXI_CHANNEL_2) {
OSInterrupt interrupt = OS_INTERRUPT_EXI_0_EXI + (3 * exi_channel);
set_interrupt_handler(interrupt, exi_interrupt_handler);
Expand Down
Loading

0 comments on commit 1adc920

Please sign in to comment.