From b2ce5b32e826f2048c3f4516e0bad7ff0ad281c9 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 20 Oct 2018 17:13:01 +0200 Subject: [PATCH] Fixed some WD80x3 NIC bugs and redid how the DP8390 is told how much memory to allocate and what internal memory space address to map it to. --- src/network/net_3c503.c | 1 + src/network/net_dp8390.c | 51 +++++++++++++++++++++------------------- src/network/net_dp8390.h | 10 ++++---- src/network/net_ne2000.c | 16 ++++++++----- src/network/net_wd8003.c | 17 +++++++------- 5 files changed, 51 insertions(+), 44 deletions(-) diff --git a/src/network/net_3c503.c b/src/network/net_3c503.c index aca87f0cf..04a471712 100644 --- a/src/network/net_3c503.c +++ b/src/network/net_3c503.c @@ -596,6 +596,7 @@ threec503_nic_init(const device_t *info) dev->dp8390->priv = dev; dev->dp8390->interrupt = threec503_interrupt; dp8390_set_defaults(dev->dp8390, DP8390_FLAG_CHECK_CR | DP8390_FLAG_CLEAR_IRQ); + dp8390_mem_alloc(dev->dp8390, 0x2000, 0x2000); memcpy(dev->dp8390->physaddr, dev->maclocal, sizeof(dev->maclocal)); diff --git a/src/network/net_dp8390.c b/src/network/net_dp8390.c index e645d5b3d..95d190712 100644 --- a/src/network/net_dp8390.c +++ b/src/network/net_dp8390.c @@ -7,7 +7,7 @@ * Emulation of the DP8390 Network Interface Controller used by * the WD family, NE1000/NE2000 family, and 3Com 3C503 NIC's. * - * Version: @(#)net_dp8390.c 1.0.0 2018/10/17 + * Version: @(#)net_dp8390.c 1.0.1 2018/10/20 * * Authors: Miran Grca, * Bochs project, @@ -104,10 +104,10 @@ dp8390_chipmem_read(dp8390_t *dev, uint32_t addr, unsigned int len) /* ROM'd MAC address */ for (i = 0; i < len; i++) { - if (addr < dev->macaddr_size) - retval |= ((uint32_t) dev->macaddr[addr & (dev->macaddr_size - 1)]) << (i << 3); - else if ((addr >= dev->mem_start) && (addr < dev->mem_end) && !(dev->flags & DP8390_FLAG_NO_CHIPMEM)) + if ((addr >= dev->mem_start) && (addr < dev->mem_end)) retval |= (uint32_t) (dev->mem[addr - dev->mem_start]) << (i << 3); + else if (addr < dev->macaddr_size) + retval |= ((uint32_t) dev->macaddr[addr & (dev->macaddr_size - 1)]) << (i << 3); else { dp8390_log("DP8390: out-of-bounds chipmem read, %04X\n", addr); retval |= 0xff << (i << 3); @@ -124,9 +124,6 @@ dp8390_chipmem_write(dp8390_t *dev, uint32_t addr, uint32_t val, unsigned len) { int i; - if (dev->flags & DP8390_FLAG_NO_CHIPMEM) - return; - #ifdef ENABLE_DP8390_LOG if ((len > 1) && (addr & (len - 1)) dp8390_log("DP8390: unaligned chipmem word write\n"); @@ -534,10 +531,12 @@ dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) switch(off) { case 0x01: /* PSTART */ dev->page_start = val; + dp8390_log("DP8390: Starting RAM address: %04X\n", val << 8); break; case 0x02: /* PSTOP */ dev->page_stop = val; + dp8390_log("DP8390: Stopping RAM address: %04X\n", val << 8); break; case 0x03: /* BNRY */ @@ -962,25 +961,25 @@ dp8390_page2_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) void dp8390_set_defaults(dp8390_t *dev, uint8_t flags) { - if (flags & DP8390_FLAG_DWORD_MEM) { - dev->mem_size = DP8390_DWORD_MEMSIZ; - dev->mem_start = DP8390_DWORD_MEMSTART; - dev->mem_end = DP8390_DWORD_MEMEND; - dev->macaddr_size = 32; - } else { - dev->mem_size = DP8390_WORD_MEMSIZ; - dev->mem_start = DP8390_WORD_MEMSTART; - dev->mem_end = DP8390_WORD_MEMEND; - dev->macaddr_size = 16; - } - - if (flags & DP8390_FLAG_NO_CHIPMEM) - dev->mem_start = 0; + dev->macaddr_size = (flags & DP8390_FLAG_EVEN_MAC) ? 32 : 16; dev->flags = flags; } +void +dp8390_mem_alloc(dp8390_t *dev, uint32_t start, uint32_t size) +{ + dev->mem = (uint8_t *) malloc(size * sizeof(uint8_t)); + memset(dev->mem, 0, size * sizeof(uint8_t)); + dev->mem_start = start; + dev->mem_end = start + size; + dev->mem_size = size; + dp8390_log("DP8390: Mapped %i bytes of memory at address %04X in the address space\n", size, start); + pclog("DP8390: Mapped %i bytes of memory at address %04X in the address space\n", size, start); +} + + void dp8390_set_id(dp8390_t *dev, uint8_t id0, uint8_t id1) { @@ -994,7 +993,7 @@ dp8390_reset(dp8390_t *dev) { int i, max, shift = 0; - if (dev->flags & DP8390_FLAG_DWORD_MEM) + if (dev->flags & DP8390_FLAG_EVEN_MAC) shift = 1; max = 16 << shift; @@ -1039,7 +1038,7 @@ dp8390_reset(dp8390_t *dev) dev->localpkt_ptr = 0; dev->address_cnt = 0; - memset(&dev->mem, 0x00, sizeof(dev->mem)); + memset(dev->mem, 0x00, dev->mem_size); /* Set power-up conditions */ dev->CR.stop = 1; @@ -1087,8 +1086,12 @@ dp8390_close(void *priv) /* Make sure the platform layer is shut down. */ network_close(); - if (dp8390) + if (dp8390) { + if (dp8390->mem) + free(dp8390->mem); + free(dp8390); + } } diff --git a/src/network/net_dp8390.h b/src/network/net_dp8390.h index 75dd9ed10..313538b5a 100644 --- a/src/network/net_dp8390.h +++ b/src/network/net_dp8390.h @@ -8,7 +8,7 @@ * Controller used by the WD family, NE1000/NE2000 family, and * 3Com 3C503 NIC's. * - * Version: @(#)net_dp8390.h 1.0.0 2018/10/17 + * Version: @(#)net_dp8390.h 1.0.1 2018/10/20 * * Authors: Miran Grca, * Bochs project, @@ -31,10 +31,9 @@ #define DP8390_WORD_MEMSTART (8*1024) #define DP8390_WORD_MEMEND (DP8390_WORD_MEMSTART+DP8390_WORD_MEMSIZ) -#define DP8390_FLAG_DWORD_MEM 0x01 +#define DP8390_FLAG_EVEN_MAC 0x01 #define DP8390_FLAG_CHECK_CR 0x02 #define DP8390_FLAG_CLEAR_IRQ 0x04 -#define DP8390_FLAG_NO_CHIPMEM 0x08 typedef struct { /* Page 0 */ @@ -168,8 +167,8 @@ typedef struct { /* Page 3 - should never be modified. */ - /* Novell ASIC state */ - uint8_t mem[DP8390_DWORD_MEMSIZ]; /* on-chip packet memory */ + /* DP8390 memory */ + uint8_t *mem; /* on-chip packet memory */ uint8_t macaddr[32]; /* ASIC ROM'd MAC address, even bytes */ uint8_t macaddr_size, /* Defaults to 16 but can be 32 */ @@ -207,6 +206,7 @@ extern uint32_t dp8390_page2_read(dp8390_t *dev, uint32_t off, unsigned int len) extern void dp8390_page2_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len); extern void dp8390_set_defaults(dp8390_t *dev, uint8_t flags); +extern void dp8390_mem_alloc(dp8390_t *dev, uint32_t start, uint32_t size); extern void dp8390_set_id(dp8390_t *dev, uint8_t id0, uint8_t id1); extern void dp8390_reset(dp8390_t *dev); extern void dp8390_soft_reset(dp8390_t *dev); diff --git a/src/network/net_ne2000.c b/src/network/net_ne2000.c index a21587112..853c39f04 100644 --- a/src/network/net_ne2000.c +++ b/src/network/net_ne2000.c @@ -13,7 +13,7 @@ * - Realtek RTL8019AS (ISA 16-bit, PnP); * - Realtek RTL8029AS (PCI). * - * Version: @(#)net_ne2000.c 1.0.10 2018/10/17 + * Version: @(#)net_ne2000.c 1.0.11 2018/10/20 * * Based on @(#)ne2k.cc v1.56.2.1 2004/02/02 22:37:22 cbothamy * @@ -304,7 +304,7 @@ asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) else dev->dp8390->remote_bytes -= (dev->dp8390->DCR.wdsize + 1); - if (dev->dp8390->remote_bytes > DP8390_DWORD_MEMSIZ) + if (dev->dp8390->remote_bytes > dev->dp8390->mem_size) dev->dp8390->remote_bytes = 0; /* If all bytes have been written, signal remote-DMA complete */ @@ -1266,6 +1266,7 @@ nic_init(const device_t *info) case NE2K_NE1000: dev->is_8bit = 1; dp8390_set_defaults(dev->dp8390, DP8390_FLAG_CHECK_CR | DP8390_FLAG_CLEAR_IRQ); + dp8390_mem_alloc(dev->dp8390, 0x2000, 0x2000); /*FALLTHROUGH*/ case NE2K_NE2000: @@ -1273,8 +1274,9 @@ nic_init(const device_t *info) dev->maclocal[1] = 0x00; dev->maclocal[2] = 0xD8; rom = (dev->board == NE2K_NE1000) ? NULL : ROM_PATH_NE2000; - dp8390_set_defaults(dev->dp8390, DP8390_FLAG_DWORD_MEM | DP8390_FLAG_CHECK_CR | + dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC | DP8390_FLAG_CHECK_CR | DP8390_FLAG_CLEAR_IRQ); + dp8390_mem_alloc(dev->dp8390, 0x4000, 0x4000); break; case NE2K_ETHERNEXT_MC: @@ -1284,8 +1286,9 @@ nic_init(const device_t *info) dev->pos_regs[0] = 0x1F; dev->pos_regs[1] = 0x61; rom = NULL; - dp8390_set_defaults(dev->dp8390, DP8390_FLAG_DWORD_MEM | DP8390_FLAG_CHECK_CR | + dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC | DP8390_FLAG_CHECK_CR | DP8390_FLAG_CLEAR_IRQ); + dp8390_mem_alloc(dev->dp8390, 0x4000, 0x4000); break; case NE2K_RTL8019AS: @@ -1296,10 +1299,11 @@ nic_init(const device_t *info) dev->maclocal[2] = 0x4C; rom = (dev->board == NE2K_RTL8019AS) ? ROM_PATH_RTL8019 : ROM_PATH_RTL8029; if (dev->is_pci) - dp8390_set_defaults(dev->dp8390, DP8390_FLAG_DWORD_MEM); + dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC); else - dp8390_set_defaults(dev->dp8390, DP8390_FLAG_DWORD_MEM | DP8390_FLAG_CLEAR_IRQ); + dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC | DP8390_FLAG_CLEAR_IRQ); dp8390_set_id(dev->dp8390, 0x50, (dev->board == NE2K_RTL8019AS) ? 0x70 : 0x43); + dp8390_mem_alloc(dev->dp8390, 0x4000, 0x8000); break; } diff --git a/src/network/net_wd8003.c b/src/network/net_wd8003.c index 0be6ced48..f36ab0b06 100644 --- a/src/network/net_wd8003.c +++ b/src/network/net_wd8003.c @@ -11,7 +11,7 @@ * - SMC/WD 8013EBT (ISA 16-bit); * - SMC/WD 8013EP/A (MCA). * - * Version: @(#)net_wd8003.c 1.0.3 2018/10/20 + * Version: @(#)net_wd8003.c 1.0.4 2018/10/20 * * Authors: Fred N. van Kempen, * TheCollector1995, @@ -151,9 +151,6 @@ wd_reset(void *priv) wdlog("%s: reset\n", dev->name); dp8390_reset(dev->dp8390); - - dev->msr &= 0x3f; - mem_mapping_disable(&dev->ram_mapping); } @@ -676,14 +673,14 @@ wd_init(const device_t *info) case WD8003E: dev->board_chip = WE_TYPE_WD8003E; dev->ram_size = 0x2000; - dp8390_set_defaults(dev->dp8390, DP8390_FLAG_CLEAR_IRQ | DP8390_FLAG_NO_CHIPMEM); + dp8390_set_defaults(dev->dp8390, DP8390_FLAG_CLEAR_IRQ); dev->msr |= 0x40; break; case WD8013EBT: dev->board_chip = WE_TYPE_WD8013EBT; dev->ram_size = device_get_config_int("ram_size"); - dp8390_set_defaults(dev->dp8390, DP8390_FLAG_CLEAR_IRQ | DP8390_FLAG_NO_CHIPMEM); + dp8390_set_defaults(dev->dp8390, DP8390_FLAG_CLEAR_IRQ); irq = 255; for (i = 0; i < 8; i++) { if (we_int_table[i] == dev->base_irq) @@ -714,7 +711,7 @@ wd_init(const device_t *info) dev->ram_size = 0x4000; dev->pos_regs[0] = 0xC8; dev->pos_regs[1] = 0x61; - dp8390_set_defaults(dev->dp8390, DP8390_FLAG_CLEAR_IRQ | DP8390_FLAG_NO_CHIPMEM); + dp8390_set_defaults(dev->dp8390, DP8390_FLAG_CLEAR_IRQ); dev->bit16 = 1; break; } @@ -722,6 +719,8 @@ wd_init(const device_t *info) dev->irr |= 0x80; dev->icr |= dev->bit16; + dp8390_mem_alloc(dev->dp8390, 0x0000, dev->ram_size); + if (dev->base_address) wd_io_set(dev, dev->base_address); @@ -736,7 +735,7 @@ wd_init(const device_t *info) wd_reset(dev); /* Map this system into the memory map. */ - if (!dev->bit16) { + if (dev->bit16) { mem_mapping_add(&dev->ram_mapping, dev->ram_addr, dev->ram_size, wd_ram_readb, wd_ram_readw, NULL, wd_ram_writeb, wd_ram_writew, NULL, @@ -1015,4 +1014,4 @@ const device_t wd8013epa_device = { wd_init, wd_close, NULL, NULL, NULL, NULL, mca_mac_config -}; \ No newline at end of file +};