From d2dbf49e3c50f48808af82a0d7e512096e7ae4fa Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 21 Jun 2020 03:58:32 +0200 Subject: [PATCH] Added the Catalyst 28F010 Flash chip needed by the ASUS P5MP3, fixed a memory leak in the Intel Flash close code (it was not free'ing dev->array), and unified all the flash chip header files into one single flash.h. --- src/include/86box/{sst_flash.h => flash.h} | 46 ++-- src/include/86box/intel_flash.h | 21 -- src/machine/m_at_386dx_486.c | 3 +- src/machine/m_at_slot1.c | 3 +- src/machine/m_at_slot2.c | 3 +- src/machine/m_at_socket370.c | 3 +- src/machine/m_at_socket4_5.c | 10 +- src/machine/m_at_socket7_s7.c | 3 +- src/machine/m_at_socket8.c | 4 +- src/machine/m_at_sockets7.c | 3 +- src/mem/catalyst_flash.c | 269 +++++++++++++++++++++ src/mem/intel_flash.c | 3 + src/win/Makefile.mingw | 2 +- 13 files changed, 313 insertions(+), 60 deletions(-) rename src/include/86box/{sst_flash.h => flash.h} (62%) delete mode 100644 src/include/86box/intel_flash.h create mode 100644 src/mem/catalyst_flash.c diff --git a/src/include/86box/sst_flash.h b/src/include/86box/flash.h similarity index 62% rename from src/include/86box/sst_flash.h rename to src/include/86box/flash.h index f473d4d33..d1efee32b 100644 --- a/src/include/86box/sst_flash.h +++ b/src/include/86box/flash.h @@ -1,20 +1,26 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Implementation of an SST flash chip. - * - * - * - * Author: Melissa Goad, - * Copyright 2020 Melissa Goad. - */ - -extern const device_t sst_flash_29ee010_device; -extern const device_t sst_flash_29ee020_device; -extern const device_t sst_flash_39sf010_device; -extern const device_t sst_flash_39sf020_device; +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Handling of the emulated flash devices. + * + * + * + * Author: Miran Grca, + * Copyright 2020 Miran Grca. + */ + +extern const device_t catalyst_flash_device; + +extern const device_t intel_flash_bxt_ami_device; +extern const device_t intel_flash_bxt_device; +extern const device_t intel_flash_bxb_device; + +extern const device_t sst_flash_29ee010_device; +extern const device_t sst_flash_29ee020_device; +extern const device_t sst_flash_39sf010_device; +extern const device_t sst_flash_39sf020_device; diff --git a/src/include/86box/intel_flash.h b/src/include/86box/intel_flash.h deleted file mode 100644 index fd14f03f5..000000000 --- a/src/include/86box/intel_flash.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Implementation of the Intel 1 Mbit 8-bit flash devices. - * - * - * - * Author: Sarah Walker, - * Miran Grca, - * Copyright 2008-2019 Sarah Walker. - * Copyright 2016-2019 Miran Grca. - */ - -extern const device_t intel_flash_bxt_ami_device; -extern const device_t intel_flash_bxt_device; -extern const device_t intel_flash_bxb_device; diff --git a/src/machine/m_at_386dx_486.c b/src/machine/m_at_386dx_486.c index efa3b34e3..cdf86fee8 100644 --- a/src/machine/m_at_386dx_486.c +++ b/src/machine/m_at_386dx_486.c @@ -38,8 +38,7 @@ #include <86box/sio.h> #include <86box/hdc.h> #include <86box/video.h> -#include <86box/intel_flash.h> -#include <86box/sst_flash.h> +#include <86box/flash.h> #include <86box/scsi_ncr53c8xx.h> #include <86box/machine.h> diff --git a/src/machine/m_at_slot1.c b/src/machine/m_at_slot1.c index cb90b06ce..3ddc77186 100644 --- a/src/machine/m_at_slot1.c +++ b/src/machine/m_at_slot1.c @@ -29,9 +29,8 @@ #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/keyboard.h> -#include <86box/intel_flash.h> +#include <86box/flash.h> #include <86box/sio.h> -#include <86box/sst_flash.h> #include <86box/hwm.h> #include <86box/spd.h> #include <86box/video.h> diff --git a/src/machine/m_at_slot2.c b/src/machine/m_at_slot2.c index 8ed78a000..fc9538f53 100644 --- a/src/machine/m_at_slot2.c +++ b/src/machine/m_at_slot2.c @@ -30,8 +30,7 @@ #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/keyboard.h> -#include <86box/intel_flash.h> -#include <86box/sst_flash.h> +#include <86box/flash.h> #include <86box/sio.h> #include <86box/hwm.h> #include <86box/spd.h> diff --git a/src/machine/m_at_socket370.c b/src/machine/m_at_socket370.c index 5642cc74f..9c19cc221 100644 --- a/src/machine/m_at_socket370.c +++ b/src/machine/m_at_socket370.c @@ -29,9 +29,8 @@ #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/keyboard.h> -#include <86box/intel_flash.h> +#include <86box/flash.h> #include <86box/sio.h> -#include <86box/sst_flash.h> #include <86box/hwm.h> #include <86box/spd.h> #include <86box/video.h> diff --git a/src/machine/m_at_socket4_5.c b/src/machine/m_at_socket4_5.c index f96be1bea..2bf904938 100644 --- a/src/machine/m_at_socket4_5.c +++ b/src/machine/m_at_socket4_5.c @@ -34,8 +34,7 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/keyboard.h> -#include <86box/intel_flash.h> -#include <86box/sst_flash.h> +#include <86box/flash.h> #include <86box/nvr.h> #include <86box/sio.h> #include <86box/video.h> @@ -100,7 +99,6 @@ machine_at_award_common_init(const machine_t *model) device_add(&fdc_at_device); device_add(&keyboard_ps2_pci_device); device_add(&sio_device); - device_add(&intel_flash_bxt_device); } @@ -162,6 +160,7 @@ machine_at_valuepointp60_init(const machine_t *model) } #endif + int machine_at_p5mp3_init(const machine_t *model) { @@ -175,11 +174,13 @@ machine_at_p5mp3_init(const machine_t *model) machine_at_award_common_init(model); + device_add(&catalyst_flash_device); device_add(&i430lx_device); return ret; } + int machine_at_586mc1_init(const machine_t *model) { @@ -193,6 +194,7 @@ machine_at_586mc1_init(const machine_t *model) machine_at_award_common_init(model); + device_add(&intel_flash_bxt_device); device_add(&i430lx_device); return ret; @@ -250,6 +252,7 @@ machine_at_430nx_init(const machine_t *model) machine_at_award_common_init(model); + device_add(&intel_flash_bxt_device); device_add(&i430nx_device); return ret; @@ -416,6 +419,7 @@ machine_at_mb500n_init(const machine_t *model) return ret; } + #if defined(DEV_BRANCH) && defined(USE_VECTRA54) int machine_at_vectra54_init(const machine_t *model) diff --git a/src/machine/m_at_socket7_s7.c b/src/machine/m_at_socket7_s7.c index 76a843a25..a2fa0cceb 100644 --- a/src/machine/m_at_socket7_s7.c +++ b/src/machine/m_at_socket7_s7.c @@ -33,9 +33,8 @@ #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/keyboard.h> -#include <86box/intel_flash.h> +#include <86box/flash.h> #include <86box/sio.h> -#include <86box/sst_flash.h> #include <86box/hwm.h> #include <86box/video.h> #include <86box/spd.h> diff --git a/src/machine/m_at_socket8.c b/src/machine/m_at_socket8.c index 95dfa2e14..04fcffd1f 100644 --- a/src/machine/m_at_socket8.c +++ b/src/machine/m_at_socket8.c @@ -29,10 +29,8 @@ #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/keyboard.h> -#include <86box/intel_flash.h> -#include <86box/sst_flash.h> +#include <86box/flash.h> #include <86box/sio.h> -#include <86box/sst_flash.h> #include <86box/hwm.h> #include <86box/spd.h> #include <86box/video.h> diff --git a/src/machine/m_at_sockets7.c b/src/machine/m_at_sockets7.c index ebaaa49ee..f66a29353 100644 --- a/src/machine/m_at_sockets7.c +++ b/src/machine/m_at_sockets7.c @@ -33,9 +33,8 @@ #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/keyboard.h> -#include <86box/intel_flash.h> +#include <86box/flash.h> #include <86box/sio.h> -#include <86box/sst_flash.h> #include <86box/spd.h> #include <86box/hwm.h> #include <86box/video.h> diff --git a/src/mem/catalyst_flash.c b/src/mem/catalyst_flash.c new file mode 100644 index 000000000..7e672e5a8 --- /dev/null +++ b/src/mem/catalyst_flash.c @@ -0,0 +1,269 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Implementation of the Intel 1 Mbit and 2 Mbit, 8-bit and + * 16-bit flash devices. + * + * + * + * Authors: Sarah Walker, + * Miran Grca, + * + * Copyright 2008-2019 Sarah Walker. + * Copyright 2016-2019 Miran Grca. + */ +#include +#include +#include +#include +#include +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/mem.h> +#include <86box/machine.h> +#include <86box/timer.h> +#include <86box/nvr.h> +#include <86box/plat.h> + + +#define FLAG_WORD 4 +#define FLAG_BXB 2 +#define FLAG_INV_A16 1 + + +enum +{ + BLOCK_MAIN1, + BLOCK_MAIN2, + BLOCK_DATA1, + BLOCK_DATA2, + BLOCK_BOOT, + BLOCKS_NUM +}; + +enum +{ + CMD_SET_READ = 0x00, + CMD_READ_SIGNATURE = 0x90, + CMD_ERASE = 0x20, + CMD_ERASE_CONFIRM = 0x20, + CMD_ERASE_VERIFY = 0xA0, + CMD_PROGRAM = 0x40, + CMD_PROGRAM_VERIFY = 0xC0, + CMD_RESET = 0xFF +}; + + +typedef struct flash_t +{ + uint8_t command, pad, + pad0, pad1, + *array; + + mem_mapping_t mapping, mapping_h[2]; +} flash_t; + + +static wchar_t flash_path[1024]; + + +static uint8_t +flash_read(uint32_t addr, void *p) +{ + flash_t *dev = (flash_t *) p; + uint8_t ret = 0xff; + + addr &= biosmask; + + switch (dev->command) { + case CMD_ERASE_VERIFY: + case CMD_PROGRAM_VERIFY: + case CMD_RESET: + case CMD_SET_READ: + ret = dev->array[addr]; + break; + + case CMD_READ_SIGNATURE: + if (addr == 0x00000) + ret = 0x31; /* CATALYST */ + else if (addr == 0x00001) + ret = 0xB4; /* 28F010 */ + break; + } + + return ret; +} + + +static uint16_t +flash_readw(uint32_t addr, void *p) +{ + flash_t *dev = (flash_t *)p; + uint16_t *q; + + addr &= biosmask; + + q = (uint16_t *)&(dev->array[addr]); + + return *q; +} + + +static uint32_t +flash_readl(uint32_t addr, void *p) +{ + flash_t *dev = (flash_t *)p; + uint32_t *q; + + addr &= biosmask; + + q = (uint32_t *)&(dev->array[addr]); + + return *q; +} + + +static void +flash_write(uint32_t addr, uint8_t val, void *p) +{ + flash_t *dev = (flash_t *) p; + + addr &= biosmask; + + switch (dev->command) { + case CMD_ERASE: + if (val == CMD_ERASE_CONFIRM) + memset(dev->array, 0xff, biosmask + 1); + break; + + case CMD_PROGRAM: + dev->array[addr] = val; + break; + + default: + dev->command = val; + break; + } +} + + +static void +flash_writew(uint32_t addr, uint16_t val, void *p) +{ +} + + +static void +flash_writel(uint32_t addr, uint32_t val, void *p) +{ +} + + +static void +catalyst_flash_add_mappings(flash_t *dev) +{ + memcpy(dev->array, rom, biosmask + 1); + + mem_mapping_add(&dev->mapping, 0xe0000, 0x20000, + flash_read, flash_readw, flash_readl, + flash_write, flash_writew, flash_writel, + dev->array, MEM_MAPPING_EXTERNAL|MEM_MAPPING_ROMCS, (void *) dev); + + mem_mapping_add(&(dev->mapping_h[0]), 0xfffc0000, 0x20000, + flash_read, flash_readw, flash_readl, + flash_write, flash_writew, flash_writel, + dev->array, MEM_MAPPING_EXTERNAL|MEM_MAPPING_ROMCS, (void *) dev); + mem_mapping_add(&(dev->mapping_h[1]), 0xfffe0000, 0x20000, + flash_read, flash_readw, flash_readl, + flash_write, flash_writew, flash_writel, + dev->array, MEM_MAPPING_EXTERNAL|MEM_MAPPING_ROMCS, (void *) dev); +} + + +static void +catalyst_flash_reset(void *priv) +{ + flash_t *dev = (flash_t *) priv; + + dev->command = CMD_RESET; +} + + +static void * +catalyst_flash_init(const device_t *info) +{ + FILE *f; + int l; + flash_t *dev; + wchar_t *machine_name, *flash_name; + + dev = malloc(sizeof(flash_t)); + memset(dev, 0, sizeof(flash_t)); + + l = strlen(machine_get_internal_name_ex(machine))+1; + machine_name = (wchar_t *) malloc(l * sizeof(wchar_t)); + mbstowcs(machine_name, machine_get_internal_name_ex(machine), l); + l = wcslen(machine_name)+5; + flash_name = (wchar_t *)malloc(l*sizeof(wchar_t)); + swprintf(flash_name, l, L"%ls.bin", machine_name); + + if (wcslen(flash_name) <= 1024) + wcscpy(flash_path, flash_name); + else + wcsncpy(flash_path, flash_name, 1024); + + mem_mapping_disable(&bios_mapping); + mem_mapping_disable(&bios_high_mapping); + + dev->array = (uint8_t *) malloc(0x20000); + memset(dev->array, 0xff, 0x20000); + + catalyst_flash_add_mappings(dev); + + dev->command = CMD_RESET; + + f = nvr_fopen(flash_path, L"rb"); + if (f) { + fread(dev->array, 0x20000, 1, f); + fclose(f); + } + + free(flash_name); + free(machine_name); + + return dev; +} + + +static void +catalyst_flash_close(void *p) +{ + FILE *f; + flash_t *dev = (flash_t *)p; + + f = nvr_fopen(flash_path, L"wb"); + fwrite(dev->array, 0x20000, 1, f); + fclose(f); + + free(dev->array); + dev->array = NULL; + + free(dev); +} + + +const device_t catalyst_flash_device = +{ + "Catalyst 28F010-D Flash BIOS", + DEVICE_PCI, + 0, + catalyst_flash_init, + catalyst_flash_close, + catalyst_flash_reset, + NULL, NULL, NULL, NULL +}; diff --git a/src/mem/intel_flash.c b/src/mem/intel_flash.c index 28ea1e8d4..d6a625ab7 100644 --- a/src/mem/intel_flash.c +++ b/src/mem/intel_flash.c @@ -463,6 +463,9 @@ intel_flash_close(void *p) fwrite(&(dev->array[dev->block_start[BLOCK_DATA2]]), dev->block_len[BLOCK_DATA2], 1, f); fclose(f); + free(dev->array); + dev->array = NULL; + free(dev); } diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 3d48ac37a..ca93dd521 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -552,7 +552,7 @@ MAINOBJ := pc.o config.o random.o timer.o io.o acpi.o apm.o dma.o ddma.o \ usb.o device.o nvr.o nvr_at.o nvr_ps2.o \ $(VNCOBJ) -MEMOBJ := intel_flash.o mem.o rom.o spd.o sst_flash.o +MEMOBJ := catalyst_flash.o intel_flash.o mem.o rom.o spd.o sst_flash.o CPUOBJ := cpu.o cpu_table.o \ 808x.o 386.o 386_common.o 386_dynarec.o 386_dynarec_ops.o $(CGTOBJ) \