Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 35 ++++++- src/block.h | 129 +++++++++++++++++++++++ src/boot.c | 3 +- src/cdrom.c | 19 +--- src/clock.c | 1 - src/disk.c | 28 +---- src/disk.h | 290 --------------------------------------------------- src/fw/coreboot.c | 2 +- src/hw/ahci.c | 2 +- src/hw/ahci.h | 2 +- src/hw/ata.c | 3 +- src/hw/ata.h | 4 +- src/hw/blockcmd.c | 3 +- src/hw/esp-scsi.c | 3 +- src/hw/floppy.c | 3 +- src/hw/lsi-scsi.c | 3 +- src/hw/megasas.c | 3 +- src/hw/ramdisk.c | 4 +- src/hw/usb-msc.c | 3 +- src/hw/usb-uas.c | 3 +- src/hw/virtio-blk.c | 3 +- src/hw/virtio-scsi.c | 3 +- src/post.c | 1 - src/std/disk.h | 161 ++++++++++++++++++++++++++++ src/util.h | 22 ++++ 25 files changed, 381 insertions(+), 352 deletions(-) create mode 100644 src/block.h delete mode 100644 src/disk.h create mode 100644 src/std/disk.h
diff --git a/src/block.c b/src/block.c index 73d6068..4560b24 100644 --- a/src/block.c +++ b/src/block.c @@ -6,7 +6,8 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL -#include "disk.h" // struct ata_s +#include "block.h" // process_op +#include "bregs.h" // struct bregs #include "hw/ata.h" // process_ata_op #include "hw/ahci.h" // process_ahci_op #include "hw/cmos.h" // inb_cmos @@ -15,7 +16,9 @@ #include "malloc.h" // malloc_low #include "output.h" // dprintf #include "stacks.h" // stack_hop +#include "std/disk.h" // struct dpte_s #include "string.h" // checksum +#include "util.h" // process_floppy_op
u8 FloppyCount VARFSEG; u8 CDCount; @@ -277,6 +280,36 @@ map_floppy_drive(struct drive_s *drive_g)
/**************************************************************** + * Return status functions + ****************************************************************/ + +void +__disk_ret(struct bregs *regs, u32 linecode, const char *fname) +{ + u8 code = linecode; + if (regs->dl < EXTSTART_HD) + SET_BDA(floppy_last_status, code); + else + SET_BDA(disk_last_status, code); + if (code) + __set_code_invalid(regs, linecode, fname); + else + set_code_success(regs); +} + +void +__disk_ret_unimplemented(struct bregs *regs, u32 linecode, const char *fname) +{ + u8 code = linecode; + if (regs->dl < EXTSTART_HD) + SET_BDA(floppy_last_status, code); + else + SET_BDA(disk_last_status, code); + __set_code_unimplemented(regs, linecode, fname); +} + + +/**************************************************************** * 16bit calling interface ****************************************************************/
diff --git a/src/block.h b/src/block.h new file mode 100644 index 0000000..3492806 --- /dev/null +++ b/src/block.h @@ -0,0 +1,129 @@ +#ifndef __BLOCK_H +#define __BLOCK_H + +#include "types.h" // u32 + + +/**************************************************************** + * Disk command request + ****************************************************************/ + +struct disk_op_s { + u64 lba; + void *buf_fl; + struct drive_s *drive_g; + u16 count; + u8 command; +}; + +#define CMD_RESET 0x00 +#define CMD_READ 0x02 +#define CMD_WRITE 0x03 +#define CMD_VERIFY 0x04 +#define CMD_FORMAT 0x05 +#define CMD_SEEK 0x07 +#define CMD_ISREADY 0x10 + + +/**************************************************************** + * Global storage + ****************************************************************/ + +struct chs_s { + u16 heads; // # heads + u16 cylinders; // # cylinders + u16 spt; // # sectors / track + u16 pad; +}; + +// ElTorito Device Emulation data +struct cdemu_s { + struct drive_s *emulated_drive_gf; + u32 ilba; + u16 buffer_segment; + u16 load_segment; + u16 sector_count; + u8 active; + u8 media; + u8 emulated_extdrive; + + // Virtual device + struct chs_s lchs; +}; + +struct drive_s { + u8 type; // Driver type (DTYPE_*) + u8 floppy_type; // Type of floppy (only for floppy drives). + struct chs_s lchs; // Logical CHS + u64 sectors; // Total sectors count + u32 cntl_id; // Unique id for a given driver type. + u8 removable; // Is media removable (currently unused) + + // Info for EDD calls + u8 translation; // type of translation + u16 blksize; // block size + struct chs_s pchs; // Physical CHS +}; + +#define DISK_SECTOR_SIZE 512 +#define CDROM_SECTOR_SIZE 2048 + +#define DTYPE_NONE 0x00 +#define DTYPE_FLOPPY 0x01 +#define DTYPE_ATA 0x02 +#define DTYPE_ATA_ATAPI 0x03 +#define DTYPE_RAMDISK 0x04 +#define DTYPE_CDEMU 0x05 +#define DTYPE_AHCI 0x06 +#define DTYPE_AHCI_ATAPI 0x07 +#define DTYPE_VIRTIO_SCSI 0x08 +#define DTYPE_VIRTIO_BLK 0x09 +#define DTYPE_USB 0x0a +#define DTYPE_UAS 0x0b +#define DTYPE_LSI_SCSI 0x0c +#define DTYPE_ESP_SCSI 0x0d +#define DTYPE_MEGASAS 0x0e + +#define MAXDESCSIZE 80 + +#define TRANSLATION_NONE 0 +#define TRANSLATION_LBA 1 +#define TRANSLATION_LARGE 2 +#define TRANSLATION_RECHS 3 + +#define EXTTYPE_FLOPPY 0 +#define EXTTYPE_HD 1 +#define EXTTYPE_CD 2 + +#define EXTSTART_HD 0x80 +#define EXTSTART_CD 0xE0 + + +/**************************************************************** + * Function defs + ****************************************************************/ + +// block.c +extern struct dpte_s DefaultDPTE; +extern u8 FloppyCount, CDCount; +extern u8 *bounce_buf_fl; +struct drive_s *getDrive(u8 exttype, u8 extdriveoffset); +int getDriveId(u8 exttype, struct drive_s *drive_g); +void map_floppy_drive(struct drive_s *drive_g); +void map_hd_drive(struct drive_s *drive_g); +void map_cd_drive(struct drive_s *drive_g); +struct bregs; +void __disk_ret(struct bregs *regs, u32 linecode, const char *fname); +void __disk_ret_unimplemented(struct bregs *regs, u32 linecode + , const char *fname); +int process_op(struct disk_op_s *op); +int send_disk_op(struct disk_op_s *op); +int create_bounce_buf(void); + +// Helper function for setting up a return code. +#define disk_ret(regs, code) \ + __disk_ret((regs), (code) | (__LINE__ << 8), __func__) +#define disk_ret_unimplemented(regs, code) \ + __disk_ret_unimplemented((regs), (code) | (__LINE__ << 8), __func__) + +#endif // block.h diff --git a/src/boot.c b/src/boot.c index fbfbf34..70888e2 100644 --- a/src/boot.c +++ b/src/boot.c @@ -6,9 +6,9 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "boot.h" // boot_init +#include "block.h" // struct drive_s #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* -#include "disk.h" // cdrom_boot #include "fw/paravirt.h" // qemu_cfg_show_boot_menu #include "hw/cmos.h" // inb_cmos #include "hw/pci.h" // pci_bdf_to_* @@ -17,6 +17,7 @@ #include "malloc.h" // free #include "output.h" // dprintf #include "romfile.h" // romfile_loadint +#include "std/disk.h" // struct mbr_s #include "string.h" // memset #include "util.h" // irqtimer_calc
diff --git a/src/cdrom.c b/src/cdrom.c index c499cf9..827ffdb 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -6,13 +6,15 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "bregs.h" // struct bregs -#include "disk.h" // cdrom_13 #include "hw/ata.h" // ATA_CMD_REQUEST_SENSE #include "hw/blockcmd.h" // CDB_CMD_REQUEST_SENSE #include "malloc.h" // free #include "output.h" // dprintf +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset +#include "util.h" // cdrom_prepboot
// Locks for removable devices u8 CDRom_locks[BUILD_MAX_EXTDRIVE] VARLOW; @@ -131,21 +133,6 @@ cdrom_prepboot(void) drive_g->sectors = (u64)-1; }
-struct eltorito_s { - u8 size; - u8 media; - u8 emulated_drive; - u8 controller_index; - u32 ilba; - u16 device_spec; - u16 buffer_segment; - u16 load_segment; - u16 sector_count; - u8 cylinders; - u8 sectors; - u8 heads; -}; - #define SET_INT13ET(regs,var,val) \ SET_FARVAR((regs)->ds, ((struct eltorito_s*)((regs)->si+0))->var, (val))
diff --git a/src/clock.c b/src/clock.c index d7de59e..7e24626 100644 --- a/src/clock.c +++ b/src/clock.c @@ -7,7 +7,6 @@
#include "biosvar.h" // SET_BDA #include "bregs.h" // struct bregs -#include "disk.h" // floppy_tick #include "hw/cmos.h" // inb_cmos #include "hw/pic.h" // pic_eoi1 #include "hw/pit.h" // PM_SEL_TIMER0 diff --git a/src/disk.c b/src/disk.c index b149b6d..8a5ce0c 100644 --- a/src/disk.c +++ b/src/disk.c @@ -8,44 +8,20 @@ #include "biosvar.h" // SET_BDA #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* -#include "disk.h" // floppy_13 #include "hw/ata.h" // ATA_CB_DC #include "hw/pci.h" // pci_bdf_to_bus #include "hw/pic.h" // pic_eoi2 #include "output.h" // debug_enter #include "stacks.h" // call16_int +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset +#include "util.h" // CDRom_locks
/**************************************************************** * Helper functions ****************************************************************/
-void -__disk_ret(struct bregs *regs, u32 linecode, const char *fname) -{ - u8 code = linecode; - if (regs->dl < EXTSTART_HD) - SET_BDA(floppy_last_status, code); - else - SET_BDA(disk_last_status, code); - if (code) - __set_code_invalid(regs, linecode, fname); - else - set_code_success(regs); -} - -void -__disk_ret_unimplemented(struct bregs *regs, u32 linecode, const char *fname) -{ - u8 code = linecode; - if (regs->dl < EXTSTART_HD) - SET_BDA(floppy_last_status, code); - else - SET_BDA(disk_last_status, code); - __set_code_unimplemented(regs, linecode, fname); -} - static void __disk_stub(struct bregs *regs, int lineno, const char *fname) { diff --git a/src/disk.h b/src/disk.h deleted file mode 100644 index 48496da..0000000 --- a/src/disk.h +++ /dev/null @@ -1,290 +0,0 @@ -// Definitions for X86 bios disks. -// -// Copyright (C) 2008 Kevin O'Connor kevin@koconnor.net -// -// This file may be distributed under the terms of the GNU LGPLv3 license. -#ifndef __DISK_H -#define __DISK_H - -#include "types.h" // u8 - -#define DISK_RET_SUCCESS 0x00 -#define DISK_RET_EPARAM 0x01 -#define DISK_RET_EADDRNOTFOUND 0x02 -#define DISK_RET_EWRITEPROTECT 0x03 -#define DISK_RET_ECHANGED 0x06 -#define DISK_RET_EBOUNDARY 0x09 -#define DISK_RET_EBADTRACK 0x0c -#define DISK_RET_ECONTROLLER 0x20 -#define DISK_RET_ETIMEOUT 0x80 -#define DISK_RET_ENOTLOCKED 0xb0 -#define DISK_RET_ELOCKED 0xb1 -#define DISK_RET_ENOTREMOVABLE 0xb2 -#define DISK_RET_ETOOMANYLOCKS 0xb4 -#define DISK_RET_EMEDIA 0xC0 -#define DISK_RET_ENOTREADY 0xAA - - -/**************************************************************** - * Interface structs - ****************************************************************/ - -// Bios disk structures. -struct int13ext_s { - u8 size; - u8 reserved; - u16 count; - struct segoff_s data; - u64 lba; -} PACKED; - -// DPTE definition -struct dpte_s { - u16 iobase1; - u16 iobase2; - u8 prefix; - u8 unused; - u8 irq; - u8 blkcount; - u8 dma; - u8 pio; - u16 options; - u16 reserved; - u8 revision; - u8 checksum; -}; - -extern struct dpte_s DefaultDPTE; - -// Disk Physical Table definition -struct int13dpt_s { - u16 size; - u16 infos; - u32 cylinders; - u32 heads; - u32 spt; - u64 sector_count; - u16 blksize; - struct segoff_s dpte; - u16 key; - u8 dpi_length; - u8 reserved1; - u16 reserved2; - u8 host_bus[4]; - u8 iface_type[8]; - u64 iface_path; - union { - struct { - u64 device_path; - u8 reserved3; - u8 checksum; - } phoenix; - struct { - u64 device_path[2]; - u8 reserved3; - u8 checksum; - } t13; - }; -} PACKED; - -// Floppy "Disk Base Table" -struct floppy_dbt_s { - u8 specify1; - u8 specify2; - u8 shutoff_ticks; - u8 bps_code; - u8 sectors; - u8 interblock_len; - u8 data_len; - u8 gap_len; - u8 fill_byte; - u8 settle_time; - u8 startup_time; -} PACKED; - -struct floppy_ext_dbt_s { - struct floppy_dbt_s dbt; - // Extra fields - u8 max_track; - u8 data_rate; - u8 drive_type; -} PACKED; - -// Helper function for setting up a return code. -struct bregs; -void __disk_ret(struct bregs *regs, u32 linecode, const char *fname); -#define disk_ret(regs, code) \ - __disk_ret((regs), (code) | (__LINE__ << 8), __func__) -void __disk_ret_unimplemented(struct bregs *regs, u32 linecode - , const char *fname); -#define disk_ret_unimplemented(regs, code) \ - __disk_ret_unimplemented((regs), (code) | (__LINE__ << 8), __func__) - - -/**************************************************************** - * Master boot record - ****************************************************************/ - -struct packed_chs_s { - u8 heads; - u8 sptcyl; - u8 cyllow; -}; - -struct partition_s { - u8 status; - struct packed_chs_s first; - u8 type; - struct packed_chs_s last; - u32 lba; - u32 count; -} PACKED; - -struct mbr_s { - u8 code[440]; - // 0x01b8 - u32 diskseg; - // 0x01bc - u16 null; - // 0x01be - struct partition_s partitions[4]; - // 0x01fe - u16 signature; -} PACKED; - -#define MBR_SIGNATURE 0xaa55 - - -/**************************************************************** - * Disk command request - ****************************************************************/ - -struct disk_op_s { - u64 lba; - void *buf_fl; - struct drive_s *drive_g; - u16 count; - u8 command; -}; - -#define CMD_RESET 0x00 -#define CMD_READ 0x02 -#define CMD_WRITE 0x03 -#define CMD_VERIFY 0x04 -#define CMD_FORMAT 0x05 -#define CMD_SEEK 0x07 -#define CMD_ISREADY 0x10 - - -/**************************************************************** - * Global storage - ****************************************************************/ - -struct chs_s { - u16 heads; // # heads - u16 cylinders; // # cylinders - u16 spt; // # sectors / track - u16 pad; -}; - -// ElTorito Device Emulation data -struct cdemu_s { - struct drive_s *emulated_drive_gf; - u32 ilba; - u16 buffer_segment; - u16 load_segment; - u16 sector_count; - u8 active; - u8 media; - u8 emulated_extdrive; - - // Virtual device - struct chs_s lchs; -}; - -struct drive_s { - u8 type; // Driver type (DTYPE_*) - u8 floppy_type; // Type of floppy (only for floppy drives). - struct chs_s lchs; // Logical CHS - u64 sectors; // Total sectors count - u32 cntl_id; // Unique id for a given driver type. - u8 removable; // Is media removable (currently unused) - - // Info for EDD calls - u8 translation; // type of translation - u16 blksize; // block size - struct chs_s pchs; // Physical CHS -}; - -#define DISK_SECTOR_SIZE 512 -#define CDROM_SECTOR_SIZE 2048 - -#define DTYPE_NONE 0x00 -#define DTYPE_FLOPPY 0x01 -#define DTYPE_ATA 0x02 -#define DTYPE_ATA_ATAPI 0x03 -#define DTYPE_RAMDISK 0x04 -#define DTYPE_CDEMU 0x05 -#define DTYPE_AHCI 0x06 -#define DTYPE_AHCI_ATAPI 0x07 -#define DTYPE_VIRTIO_SCSI 0x08 -#define DTYPE_VIRTIO_BLK 0x09 -#define DTYPE_USB 0x0a -#define DTYPE_UAS 0x0b -#define DTYPE_LSI_SCSI 0x0c -#define DTYPE_ESP_SCSI 0x0d -#define DTYPE_MEGASAS 0x0e - -#define MAXDESCSIZE 80 - -#define TRANSLATION_NONE 0 -#define TRANSLATION_LBA 1 -#define TRANSLATION_LARGE 2 -#define TRANSLATION_RECHS 3 - -#define EXTTYPE_FLOPPY 0 -#define EXTTYPE_HD 1 -#define EXTTYPE_CD 2 - -#define EXTSTART_HD 0x80 -#define EXTSTART_CD 0xE0 - - -/**************************************************************** - * Function defs - ****************************************************************/ - -// block.c -extern u8 FloppyCount, CDCount; -extern u8 *bounce_buf_fl; -struct drive_s *getDrive(u8 exttype, u8 extdriveoffset); -int getDriveId(u8 exttype, struct drive_s *drive_g); -void map_floppy_drive(struct drive_s *drive_g); -void map_hd_drive(struct drive_s *drive_g); -void map_cd_drive(struct drive_s *drive_g); -int process_op(struct disk_op_s *op); -int send_disk_op(struct disk_op_s *op); -int create_bounce_buf(void); - -// floppy.c -extern struct floppy_ext_dbt_s diskette_param_table2; -void floppy_setup(void); -struct drive_s *init_floppy(int floppyid, int ftype); -int find_floppy_type(u32 size); -int process_floppy_op(struct disk_op_s *op); -void floppy_tick(void); - -// cdrom.c -extern u8 CDRom_locks[]; -extern struct cdemu_s CDEmu; -extern struct drive_s *cdemu_drive_gf; -int process_cdemu_op(struct disk_op_s *op); -void cdrom_prepboot(void); -void cdemu_134b(struct bregs *regs); -int cdrom_boot(struct drive_s *drive_g); - -// ramdisk.c -void ramdisk_setup(void); -int process_ramdisk_op(struct disk_op_s *op); - -#endif // disk.h diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index e9874e2..7d877eb 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -4,10 +4,10 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
+#include "block.h" // MAXDESCSIZE #include "boot.h" // boot_add_cbfs #include "byteorder.h" // be32_to_cpu #include "config.h" // CONFIG_* -#include "disk.h" // MAXDESCSIZE #include "hw/pci.h" // pci_probe_devices #include "lzmadecode.h" // LzmaDecode #include "malloc.h" // free diff --git a/src/hw/ahci.c b/src/hw/ahci.c index bf70e23..6bf0bf0 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -9,7 +9,6 @@ #include "biosvar.h" // GET_GLOBAL #include "blockcmd.h" // CDB_CMD_READ_10 #include "boot.h" // add_bcv_hd -#include "disk.h" // struct drive_s #include "ioport.h" // inb #include "malloc.h" // free #include "output.h" // dprintf @@ -17,6 +16,7 @@ #include "pci_ids.h" // PCI_CLASS_STORAGE_OTHER #include "pci_regs.h" // PCI_INTERRUPT_LINE #include "stacks.h" // yield +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // timer_calc
diff --git a/src/hw/ahci.h b/src/hw/ahci.h index c3d2402..c8c755a 100644 --- a/src/hw/ahci.h +++ b/src/hw/ahci.h @@ -1,8 +1,8 @@ #ifndef __AHCI_H #define __AHCI_H
+#include "block.h" // struct drive_s #include "types.h" // u32 -#include "disk.h" // struct drive_s
struct sata_cmd_fis { u8 reg; diff --git a/src/hw/ata.c b/src/hw/ata.c index 7338ebf..4ea6cd1 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -7,11 +7,11 @@
#include "ata.h" // ATA_CB_STAT #include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "blockcmd.h" // CDB_CMD_READ_10 #include "boot.h" // boot_add_hd #include "byteorder.h" // be16_to_cpu #include "cmos.h" // inb_cmos -#include "disk.h" // struct ata_s #include "ioport.h" // inb #include "malloc.h" // malloc_fseg #include "output.h" // dprintf @@ -20,6 +20,7 @@ #include "pci_regs.h" // PCI_INTERRUPT_LINE #include "pic.h" // enable_hwirq #include "stacks.h" // yield +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // timer_calc
diff --git a/src/hw/ata.h b/src/hw/ata.h index 1f41233..a9f865e 100644 --- a/src/hw/ata.h +++ b/src/hw/ata.h @@ -1,9 +1,9 @@ #ifndef __ATA_H #define __ATA_H
-#include "types.h" // u8 +#include "block.h" // struct drive_s #include "config.h" // CONFIG_MAX_ATA_INTERFACES -#include "disk.h" // struct drive_s +#include "types.h" // u8
struct ata_channel_s { u16 iobase1; diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 59f5763..b9e61cd 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -8,14 +8,15 @@ #include "ahci.h" // atapi_cmd_data #include "ata.h" // atapi_cmd_data #include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct disk_op_s #include "blockcmd.h" // struct cdb_request_sense #include "boot.h" // boot_add_hd #include "byteorder.h" // be32_to_cpu -#include "disk.h" // struct disk_op_s #include "esp-scsi.h" // esp_scsi_cmd_data #include "lsi-scsi.h" // lsi_scsi_cmd_data #include "megasas.h" // megasas_cmd_data #include "output.h" // dprintf +#include "std/disk.h" // DISK_RET_EPARAM #include "string.h" // memset #include "usb-msc.h" // usb_cmd_data #include "usb-uas.h" // usb_cmd_data diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index 65a67cd..e6533af 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -11,16 +11,17 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup #include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* -#include "disk.h" #include "fw/paravirt.h" // runningOnQEMU #include "malloc.h" // free #include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID #include "pci_regs.h" // PCI_VENDOR_ID +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // usleep
diff --git a/src/hw/floppy.c b/src/hw/floppy.c index e2db2f8..05c518f 100644 --- a/src/hw/floppy.c +++ b/src/hw/floppy.c @@ -6,11 +6,11 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // SET_BDA +#include "block.h" // struct drive_s #include "boot.h" // boot_add_floppy #include "bregs.h" // struct bregs #include "cmos.h" // inb_cmos #include "config.h" // CONFIG_FLOPPY -#include "disk.h" // DISK_RET_SUCCESS #include "malloc.h" // malloc_fseg #include "output.h" // dprintf #include "pci.h" // pci_to_bdf @@ -18,6 +18,7 @@ #include "pic.h" // pic_eoi1 #include "romfile.h" // romfile_loadint #include "stacks.h" // yield +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // timer_calc
diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index 87751aa..b7eb1f1 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -11,16 +11,17 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup #include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* -#include "disk.h" #include "fw/paravirt.h" // runningOnQEMU #include "malloc.h" // free #include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // usleep
diff --git a/src/hw/megasas.c b/src/hw/megasas.c index 4bba0e1..772fc75 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -11,16 +11,17 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup #include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* -#include "disk.h" #include "malloc.h" // free #include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_XXX #include "pci_regs.h" // PCI_VENDOR_ID #include "stacks.h" // yield +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // timer_calc
diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index 2599f9a..f57affd 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -5,15 +5,17 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "boot.h" // boot_add_floppy #include "bregs.h" // struct bregs -#include "disk.h" // process_ramdisk_op #include "malloc.h" // malloc_fseg #include "memmap.h" // add_e820 #include "output.h" // dprintf #include "romfile.h" // romfile_findprefix #include "stacks.h" // call16_int +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset +#include "util.h" // process_ramdisk_op
void ramdisk_setup(void) diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index ee1fe20..975ec7a 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -5,12 +5,13 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // DTYPE_USB #include "blockcmd.h" // cdb_read #include "boot.h" // bootprio_find_usb #include "config.h" // CONFIG_USB_MSC -#include "disk.h" // DTYPE_USB #include "malloc.h" // free #include "output.h" // dprintf +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "usb.h" // struct usb_s #include "usb-msc.h" // usb_msc_setup diff --git a/src/hw/usb-uas.c b/src/hw/usb-uas.c index 6925f33..9f4b558 100644 --- a/src/hw/usb-uas.c +++ b/src/hw/usb-uas.c @@ -15,12 +15,13 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // DTYPE_USB #include "blockcmd.h" // cdb_read #include "boot.h" // bootprio_find_usb #include "config.h" // CONFIG_USB_UAS -#include "disk.h" // DTYPE_UAS #include "malloc.h" // free #include "output.h" // dprintf +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "usb.h" // struct usb_s #include "usb-uas.h" // usb_uas_init diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 07f6e57..c48ea45 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -10,12 +10,13 @@ #include "biosvar.h" // GET_GLOBAL #include "boot.h" // boot_add_hd #include "config.h" // CONFIG_* -#include "disk.h" +#include "block.h" // struct drive_s #include "malloc.h" // free #include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // usleep #include "virtio-pci.h" diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index 1c3500c..f50e335 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -8,15 +8,16 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup #include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* -#include "disk.h" #include "malloc.h" // free #include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // usleep #include "virtio-pci.h" diff --git a/src/post.c b/src/post.c index e84dcae..5514120 100644 --- a/src/post.c +++ b/src/post.c @@ -9,7 +9,6 @@ #include "boot.h" // boot_init #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* -#include "disk.h" // floppy_setup #include "fw/paravirt.h" // qemu_cfg_preinit #include "fw/xen.h" // xen_preinit #include "hw/ahci.h" // ahci_setup diff --git a/src/std/disk.h b/src/std/disk.h new file mode 100644 index 0000000..c111e07 --- /dev/null +++ b/src/std/disk.h @@ -0,0 +1,161 @@ +// Standard disk BIOS definitions. +#ifndef __DISK_H +#define __DISK_H + +#include "types.h" // u8 + +#define DISK_RET_SUCCESS 0x00 +#define DISK_RET_EPARAM 0x01 +#define DISK_RET_EADDRNOTFOUND 0x02 +#define DISK_RET_EWRITEPROTECT 0x03 +#define DISK_RET_ECHANGED 0x06 +#define DISK_RET_EBOUNDARY 0x09 +#define DISK_RET_EBADTRACK 0x0c +#define DISK_RET_ECONTROLLER 0x20 +#define DISK_RET_ETIMEOUT 0x80 +#define DISK_RET_ENOTLOCKED 0xb0 +#define DISK_RET_ELOCKED 0xb1 +#define DISK_RET_ENOTREMOVABLE 0xb2 +#define DISK_RET_ETOOMANYLOCKS 0xb4 +#define DISK_RET_EMEDIA 0xC0 +#define DISK_RET_ENOTREADY 0xAA + + +/**************************************************************** + * Interface structs + ****************************************************************/ + +// Bios disk structures. +struct int13ext_s { + u8 size; + u8 reserved; + u16 count; + struct segoff_s data; + u64 lba; +} PACKED; + +// DPTE definition +struct dpte_s { + u16 iobase1; + u16 iobase2; + u8 prefix; + u8 unused; + u8 irq; + u8 blkcount; + u8 dma; + u8 pio; + u16 options; + u16 reserved; + u8 revision; + u8 checksum; +}; + +// Disk Physical Table definition +struct int13dpt_s { + u16 size; + u16 infos; + u32 cylinders; + u32 heads; + u32 spt; + u64 sector_count; + u16 blksize; + struct segoff_s dpte; + u16 key; + u8 dpi_length; + u8 reserved1; + u16 reserved2; + u8 host_bus[4]; + u8 iface_type[8]; + u64 iface_path; + union { + struct { + u64 device_path; + u8 reserved3; + u8 checksum; + } phoenix; + struct { + u64 device_path[2]; + u8 reserved3; + u8 checksum; + } t13; + }; +} PACKED; + +// Floppy "Disk Base Table" +struct floppy_dbt_s { + u8 specify1; + u8 specify2; + u8 shutoff_ticks; + u8 bps_code; + u8 sectors; + u8 interblock_len; + u8 data_len; + u8 gap_len; + u8 fill_byte; + u8 settle_time; + u8 startup_time; +} PACKED; + +struct floppy_ext_dbt_s { + struct floppy_dbt_s dbt; + // Extra fields + u8 max_track; + u8 data_rate; + u8 drive_type; +} PACKED; + + +/**************************************************************** + * Master boot record + ****************************************************************/ + +struct packed_chs_s { + u8 heads; + u8 sptcyl; + u8 cyllow; +}; + +struct partition_s { + u8 status; + struct packed_chs_s first; + u8 type; + struct packed_chs_s last; + u32 lba; + u32 count; +} PACKED; + +struct mbr_s { + u8 code[440]; + // 0x01b8 + u32 diskseg; + // 0x01bc + u16 null; + // 0x01be + struct partition_s partitions[4]; + // 0x01fe + u16 signature; +} PACKED; + +#define MBR_SIGNATURE 0xaa55 + + +/**************************************************************** + * ElTorito CDROM interface + ****************************************************************/ + +struct eltorito_s { + u8 size; + u8 media; + u8 emulated_drive; + u8 controller_index; + u32 ilba; + u16 device_spec; + u16 buffer_segment; + u16 load_segment; + u16 sector_count; + u8 cylinders; + u8 sectors; + u8 heads; +}; + +#endif // disk.h diff --git a/src/util.h b/src/util.h index 333d116..6d8c0d2 100644 --- a/src/util.h +++ b/src/util.h @@ -18,6 +18,16 @@ void process_mouse(u8 data); void serial_setup(void); void lpt_setup(void);
+// cdrom.c +extern u8 CDRom_locks[]; +extern struct cdemu_s CDEmu; +extern struct drive_s *cdemu_drive_gf; +struct disk_op_s; +int process_cdemu_op(struct disk_op_s *op); +void cdrom_prepboot(void); +void cdemu_134b(struct bregs *regs); +int cdrom_boot(struct drive_s *drive_g); + // clock.c void clock_setup(void); void handle_1583(struct bregs *regs); @@ -25,6 +35,18 @@ void handle_1586(struct bregs *regs); void useRTC(void); void releaseRTC(void);
+// hw/floppy.c +extern struct floppy_ext_dbt_s diskette_param_table2; +void floppy_setup(void); +struct drive_s *init_floppy(int floppyid, int ftype); +int find_floppy_type(u32 size); +int process_floppy_op(struct disk_op_s *op); +void floppy_tick(void); + +// hw/ramdisk.c +void ramdisk_setup(void); +int process_ramdisk_op(struct disk_op_s *op); + // hw/timer.c void timer_setup(void); void pmtimer_setup(u16 ioport);