esp: add Tekram DC-390 emulation (PC SCSI adapter)
PATCH 1/1 esp: add Tekram DC-390 emulation (PC SCSI adapter)
Difference with AMD PCscsi is that DC-390 contains a EEPROM, and that a romfile is available to add INT13 support.
This has been successfully tested on:
- MS DOS 6.22 (using DC390 ASPI driver)
- MS Windows 98 SE (using DC390 driver)
- MS Windows NT 3.1 (using DC390 driver)
- MS Windows NT 4.0 (using DC390 driver)
- hard disk and cdrom boot
---
You're now able to install MS Windows NT 3.1 (which does not support IDE cdroms) directly on an empty VM, without installing MS-DOS first!
hw/esp.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+)
hw/esp.c +116 -0
@@ -26,6 +26,7 @@#include "sysbus.h" #include "pci.h" #include "scsi.h" +#include "eeprom93xx.h" #include "esp.h" #include "trace.h" #include "qemu-log.h"
@@ -1185,10 +1186,125 @@ static TypeInfo esp_pci_info = { .class_init = esp_pci_class_init, }; +typedef struct { +PCIESPState pci; +eeprom_t *eeprom; +}DC390State ; + +static uint32_t dc390_read_config (PCIDevice *dev,uint32_t addr,int l) +{ +DC390State *pci =DO_UPCAST (DC390State, pci.dev, dev); +uint32_t val; + + val =pci_default_read_config (dev, addr, l); + +if (addr ==0x00 && l ==1 ) { +/* First byte of address space is AND-ed with EEPROM DO line */ +if (!eeprom93xx_read (pci->eeprom)) { + val &= ~0xff ; + } + } + +return val; +} + +static void dc390_write_config (PCIDevice *dev, +uint32_t addr,uint32_t val,int l) +{ +DC390State *pci =DO_UPCAST (DC390State, pci.dev, dev); +if (addr ==0x80 ) { +/* EEPROM write */ +int eesk = val &0x80 ?1 :0 ; +int eedi = val &0x40 ?1 :0 ; +eeprom93xx_write (pci->eeprom,1 , eesk, eedi); + }else if (addr ==0xc0 ) { +/* EEPROM CS low */ +eeprom93xx_write (pci->eeprom,0 ,0 ,0 ); + }else { +pci_default_write_config (dev, addr, val, l); + } +} + +static int dc390_scsi_init (PCIDevice *dev) +{ +DC390State *pci =DO_UPCAST (DC390State, pci.dev, dev); +uint8_t *contents; +uint16_t chksum =0 ; +int i, ret; + +/* init base class */ + ret =esp_pci_scsi_init (dev); +if (ret <0 ) { +return ret; + } + +/* EEPROM */ + pci->eeprom =eeprom93xx_new (&dev->qdev,64 ); + +/* set default eeprom values */ + contents = (uint8_t *)eeprom93xx_data (pci->eeprom); + +#define EE_ADAPT_SCSI_ID 64 +#define EE_MODE2 65 +#define EE_DELAY 66 +#define EE_TAG_CMD_NUM 67 +#define EE_ADAPT_OPTIONS 68 +#define EE_BOOT_SCSI_ID 69 +#define EE_BOOT_SCSI_LUN 70 +#define EE_CHKSUM1 126 +#define EE_CHKSUM2 127 + +#define OPTION_F6_F8_AT_BOOT 0x01 +#define OPTION_BOOT_FROM_CDROM 0x02 +#define OPTION_INT13 0x04 +#define OPTION_SCAM_SUPPORT 0x08 + +for (i =0 ; i <16 ; i++) { + contents[i *2 ] =0x57 ; + contents[i *2 +1 ] =0x00 ; + } + contents[EE_ADAPT_SCSI_ID ] =7 ; + contents[EE_MODE2 ] =0x0f ; + contents[EE_TAG_CMD_NUM ] =0x04 ; + contents[EE_ADAPT_OPTIONS ] =OPTION_F6_F8_AT_BOOT + |OPTION_BOOT_FROM_CDROM + |OPTION_INT13 ; + +/* update eeprom checksum */ +for (i =0 ; i <EE_CHKSUM1 ; i +=2 ) { + chksum += contents[i] + (((uint16_t )contents[i +1 ]) <<8 ); + } + chksum =0x1234 - chksum; + contents[EE_CHKSUM1 ] = chksum &0xff ; + contents[EE_CHKSUM2 ] = chksum >>8 ; + +return 0 ; +} + +static void dc390_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); + + k->init = dc390_scsi_init; + k->romfile ="INT13.BIN" ; + k->config_read = dc390_read_config; + k->config_write = dc390_write_config; + dc->desc ="Tekram DC-390 SCSI adapter" ; +} + +static TypeInfo dc390_info = { + .name ="dc390" , + .parent ="am53c974" , + .instance_size =sizeof (DC390State), + .class_init = dc390_class_init, +}; +static void esp_register_types (void ) {type_register_static (&sysbus_esp_info);type_register_static (&esp_pci_info); +type_register_static (&dc390_info); }type_init (esp_register_types)
Signature · 1 line
1.7.10.4
Am 01.08.2012 18:59, schrieb Hervé Poussineau:
Quoted 34 lines
Difference with AMD PCscsi is that DC-390 contains a EEPROM, and that a romfile is available to add INT13 support.
This has been successfully tested on:
- MS DOS 6.22 (using DC390 ASPI driver)
- MS Windows 98 SE (using DC390 driver)
- MS Windows NT 3.1 (using DC390 driver)
- MS Windows NT 4.0 (using DC390 driver)
- hard disk and cdrom bootSigned-off-by Hervé Poussineau <[email protected]>---
You're now able to install MS Windows NT 3.1 (which does not support IDE cdroms) directly on an empty VM, without installing MS-DOS first!
hw/esp.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+)hw/esp.c +1
-0@@ -26,6 +26,7 @@#include "sysbus.h" #include "pci.h" #include "scsi.h" +#include "eeprom93xx.h" #include "esp.h" #include "trace.h" #include "qemu-log.h" @@ -1185,10 +1186,125 @@ static TypeInfo esp_pci_info = { .class_init = esp_pci_class_init,
hw/esp.c static TypeInfo esp_pci_info = { · line 1196
Quoted 10 lines
hw/esp.c +8
-0}; +typedef struct { +PCIESPState pci; +eeprom_t *eeprom; +}DC390State ; + +static uint32_t dc390_read_config (PCIDevice *dev,uint32_t addr,int l) +{ +DC390State *pci =DO_UPCAST (DC390State, pci.dev, dev);
Using QOM cast macros in place of DO_UPCAST() would be preferred.
Quoted 36 lines
hw/esp.c +36
-0+uint32_t val; + + val =pci_default_read_config (dev, addr, l); + +if (addr ==0x00 && l ==1 ) { +/* First byte of address space is AND-ed with EEPROM DO line */ +if (!eeprom93xx_read (pci->eeprom)) { + val &= ~0xff ; + } + } + +return val; +} + +static void dc390_write_config (PCIDevice *dev, +uint32_t addr,uint32_t val,int l) +{ +DC390State *pci =DO_UPCAST (DC390State, pci.dev, dev); +if (addr ==0x80 ) { +/* EEPROM write */ +int eesk = val &0x80 ?1 :0 ; +int eedi = val &0x40 ?1 :0 ; +eeprom93xx_write (pci->eeprom,1 , eesk, eedi); + }else if (addr ==0xc0 ) { +/* EEPROM CS low */ +eeprom93xx_write (pci->eeprom,0 ,0 ,0 ); + }else { +pci_default_write_config (dev, addr, val, l); + } +} + +static int dc390_scsi_init (PCIDevice *dev) +{ +DC390State *pci =DO_UPCAST (DC390State, pci.dev, dev); +uint8_t *contents; +uint16_t chksum =0 ;
hw/esp.c static TypeInfo esp_pci_info = { · line 1242
Quoted 10 lines
hw/esp.c +10
-0+int i, ret; + +/* init base class */ + ret =esp_pci_scsi_init (dev); +if (ret <0 ) { +return ret; + } + +/* EEPROM */ + pci->eeprom =eeprom93xx_new (&dev->qdev,64 );
DEVICE(dev)
Quoted 8 lines
hw/esp.c +8
-0+ +/* set default eeprom values */ + contents = (uint8_t *)eeprom93xx_data (pci->eeprom); + +#define EE_ADAPT_SCSI_ID 64 +#define EE_MODE2 65 +#define EE_DELAY 66 +#define EE_TAG_CMD_NUM 67
hw/esp.c static TypeInfo esp_pci_info = { · line 1260
Quoted 10 lines
hw/esp.c +10
-0+#define EE_ADAPT_OPTIONS 68 +#define EE_BOOT_SCSI_ID 69 +#define EE_BOOT_SCSI_LUN 70 +#define EE_CHKSUM1 126 +#define EE_CHKSUM2 127 + +#define OPTION_F6_F8_AT_BOOT 0x01 +#define OPTION_BOOT_FROM_CDROM 0x02 +#define OPTION_INT13 0x04 +#define OPTION_SCAM_SUPPORT 0x08
Usually such constants are requested not to be in the middle of a function.
Quoted 26 lines
hw/esp.c +26
-0+ +for (i =0 ; i <16 ; i++) { + contents[i *2 ] =0x57 ; + contents[i *2 +1 ] =0x00 ; + } + contents[EE_ADAPT_SCSI_ID ] =7 ; + contents[EE_MODE2 ] =0x0f ; + contents[EE_TAG_CMD_NUM ] =0x04 ; + contents[EE_ADAPT_OPTIONS ] =OPTION_F6_F8_AT_BOOT + |OPTION_BOOT_FROM_CDROM + |OPTION_INT13 ; + +/* update eeprom checksum */ +for (i =0 ; i <EE_CHKSUM1 ; i +=2 ) { + chksum += contents[i] + (((uint16_t )contents[i +1 ]) <<8 ); + } + chksum =0x1234 - chksum; + contents[EE_CHKSUM1 ] = chksum &0xff ; + contents[EE_CHKSUM2 ] = chksum >>8 ; + +return 0 ; +} + +static void dc390_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass);
hw/esp.c static TypeInfo esp_pci_info = { · line 1296
Quoted 10 lines
hw/esp.c +10
-0+PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); + + k->init = dc390_scsi_init; + k->romfile ="INT13.BIN" ; + k->config_read = dc390_read_config; + k->config_write = dc390_write_config; + dc->desc ="Tekram DC-390 SCSI adapter" ; +} + +static TypeInfo dc390_info = {
static const please.
hw/esp.c static TypeInfo esp_pci_info = { · line 1298
Quoted 2 lines
hw/esp.c +2
-0+ .name = "dc390", + .parent = "am53c974",
Introduce a TYPE_... constant for the parent to avoid runtime breakage if renamed?
Andreas
Quoted 13 lines
hw/esp.c +5
-0+ .instance_size = sizeof(DC390State), + .class_init = dc390_class_init, +}; +static void esp_register_types (void ) {type_register_static (&sysbus_esp_info);type_register_static (&esp_pci_info); +type_register_static (&dc390_info); }type_init (esp_register_types)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Il 01/08/2012 18:59, Hervé Poussineau ha scritto:
hw/esp.c static TypeInfo esp_pci_info = { · line 1290
Quoted 8 lines
hw/esp.c +8
-0+ +static void dc390_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); + + k->init = dc390_scsi_init; + k->romfile ="INT13.BIN" ;
Is this available under a free license? Otherwise, it's probably easier to just add support to SeaBIOS.
Paolo
Quoted 4 lines
hw/esp.c +4
-0+ k->config_read = dc390_read_config; + k->config_write = dc390_write_config; + dc->desc ="Tekram DC-390 SCSI adapter" ; +}
Quoted 13 lines · Paolo Bonzini
Il 01/08/2012 18:59, Hervé Poussineau ha scritto:
hw/esp.c static TypeInfo esp_pci_info = { · line 1290
Quoted 8 lines
hw/esp.c +8
-0+ +static void dc390_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); + + k->init = dc390_scsi_init; + k->romfile ="INT13.BIN" ;Is this available under a free license? Otherwise, it's probably easier to just add support to SeaBIOS.
Licence for the rom doesn't seem to be available, so I can drop that line if you want.
Hervé
Il 02/08/2012 09:25, Hervé Poussineau ha scritto:
Quoted 12 lines
Quoted 11 lines
hw/esp.c static TypeInfo esp_pci_info = { · line 1290
Quoted 8 lines
hw/esp.c +7
-0+static void dc390_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); + + k->init = dc390_scsi_init; + k->romfile ="INT13.BIN" ;Is this available under a free license? Otherwise, it's probably easier to just add support to SeaBIOS.
Quoted 2 lines
Licence for the rom doesn't seem to be available, so I can drop that line if you want.
Yes, please.
Paolo