2017-09-30 16:56:38 -04:00
|
|
|
/*
|
2023-01-06 15:36:05 -05:00
|
|
|
* 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.
|
2017-09-30 16:56:38 -04:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* This file is part of the 86Box distribution.
|
2017-09-30 16:56:38 -04:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Definitions for the hard disk image handler.
|
2017-09-30 16:56:38 -04:00
|
|
|
*
|
2020-03-25 00:46:02 +02:00
|
|
|
*
|
2017-09-30 16:56:38 -04:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Authors: Miran Grca, <mgrca8@gmail.com>
|
|
|
|
|
* Fred N. van Kempen, <decwiz@yahoo.com>
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2016-2018 Miran Grca.
|
2023-01-06 15:36:29 -05:00
|
|
|
* Copyright 2017-2018 Fred N. van Kempen.
|
2017-09-30 16:56:38 -04:00
|
|
|
*/
|
2017-08-24 01:14:39 -04:00
|
|
|
#ifndef EMU_HDD_H
|
2022-09-18 17:15:38 -04:00
|
|
|
#define EMU_HDD_H
|
2017-10-01 16:29:15 -04:00
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
#define IMG_FMT_RAW 0
|
|
|
|
|
#define IMG_FMT_HDI 1
|
|
|
|
|
#define IMG_FMT_HDX 2
|
|
|
|
|
#define IMG_FMT_VHD_FIXED 3
|
2022-11-11 17:19:47 -05:00
|
|
|
#define IMG_FMT_VHD_DYNAMIC 4
|
2022-11-19 08:49:04 -05:00
|
|
|
#define IMG_FMT_VHD_DIFF 5
|
2022-11-11 17:19:47 -05:00
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
#define HDD_NUM 88 /* total of 88 images supported */
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2017-09-30 16:56:38 -04:00
|
|
|
/* Hard Disk bus types. */
|
2018-04-25 23:51:13 +02:00
|
|
|
#if 0
|
|
|
|
|
/* Bit 4 = DMA supported (0 = no, 1 yes) - used for IDE and ATAPI only;
|
|
|
|
|
Bit 5 = Removable (0 = no, 1 yes). */
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
BUS_DISABLED = 0x00,
|
|
|
|
|
|
|
|
|
|
BUS_MFM = 0x01, /* These four are for hard disk only. */
|
|
|
|
|
BUS_XIDE = 0x02,
|
|
|
|
|
BUS_XTA = 0x03,
|
|
|
|
|
BUS_ESDI = 0x04,
|
|
|
|
|
|
|
|
|
|
BUS_PANASONIC = 0x21, / These four are for CD-ROM only. */
|
|
|
|
|
BUS_PHILIPS = 0x22,
|
|
|
|
|
BUS_SONY = 0x23,
|
|
|
|
|
BUS_MITSUMI = 0x24,
|
|
|
|
|
|
|
|
|
|
BUS_IDE_PIO_ONLY = 0x05,
|
|
|
|
|
BUS_IDE_PIO_AND_DMA = 0x15,
|
|
|
|
|
BUS_IDE_R_PIO_ONLY = 0x25,
|
|
|
|
|
BUS_IDE_R_PIO_AND_DMA = 0x35,
|
|
|
|
|
|
|
|
|
|
BUS_ATAPI_PIO_ONLY = 0x06,
|
|
|
|
|
BUS_ATAPI_PIO_AND_DMA = 0x16,
|
|
|
|
|
BUS_ATAPI_R_PIO_ONLY = 0x26,
|
|
|
|
|
BUS_ATAPI_R_PIO_AND_DMA = 0x36,
|
|
|
|
|
|
|
|
|
|
BUS_SASI = 0x07,
|
|
|
|
|
BUS_SASI_R = 0x27,
|
|
|
|
|
|
|
|
|
|
BUS_SCSI = 0x08,
|
|
|
|
|
BUS_SCSI_R = 0x28,
|
|
|
|
|
|
|
|
|
|
BUS_USB = 0x09,
|
|
|
|
|
BUS_USB_R = 0x29
|
|
|
|
|
};
|
|
|
|
|
#else
|
2017-09-30 16:56:38 -04:00
|
|
|
enum {
|
|
|
|
|
HDD_BUS_DISABLED = 0,
|
|
|
|
|
HDD_BUS_MFM,
|
2018-04-25 23:51:13 +02:00
|
|
|
HDD_BUS_XTA,
|
2017-09-30 16:56:38 -04:00
|
|
|
HDD_BUS_ESDI,
|
2018-04-25 23:51:13 +02:00
|
|
|
HDD_BUS_IDE,
|
PIC rewrite, proper SMRAM API, complete SiS 471 rewrite and addition of 40x, 460, and 461, changes to mem.c/h, disabled Voodoo memory dumping on exit, bumped SDL Hardware scale quality to 2, bumped IDE/ATAPI drives to ATA-6, finally bumped emulator version to 3.0, redid the bus type ID's to allow for planned ATAPI hard disks, made SST flash set its high mappings to the correct address if the CPU is 16-bit, and added the SiS 401 AMI 486 Clone, AOpen Vi15G, and the Soyo 4SA2 (486 with SiS 496/497 that can boot from CD-ROM), assorted 286+ protected mode fixes (for slightly more accuracy), and fixes to 808x emulation (MS Word 1.0 and 1.10 for DOS now work correctly from floppy).
2020-10-14 23:15:01 +02:00
|
|
|
HDD_BUS_ATAPI,
|
2017-09-30 16:56:38 -04:00
|
|
|
HDD_BUS_SCSI,
|
|
|
|
|
HDD_BUS_USB
|
|
|
|
|
};
|
2018-04-25 23:51:13 +02:00
|
|
|
#endif
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2022-07-07 23:35:34 +02:00
|
|
|
enum {
|
|
|
|
|
HDD_OP_SEEK = 0,
|
|
|
|
|
HDD_OP_READ,
|
|
|
|
|
HDD_OP_WRITE
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-18 17:15:38 -04:00
|
|
|
#define HDD_MAX_ZONES 16
|
2022-07-07 23:35:34 +02:00
|
|
|
#define HDD_MAX_CACHE_SEG 16
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2022-07-19 11:31:06 +02:00
|
|
|
const char *name;
|
|
|
|
|
const char *internal_name;
|
2022-09-18 17:15:38 -04:00
|
|
|
uint32_t zones;
|
|
|
|
|
uint32_t avg_spt;
|
|
|
|
|
uint32_t heads;
|
|
|
|
|
uint32_t rpm;
|
|
|
|
|
uint32_t rcache_num_seg;
|
|
|
|
|
uint32_t rcache_seg_size;
|
|
|
|
|
uint32_t max_multiple;
|
|
|
|
|
double full_stroke_ms;
|
|
|
|
|
double track_seek_ms;
|
2022-07-07 23:35:34 +02:00
|
|
|
} hdd_preset_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint32_t id;
|
|
|
|
|
uint32_t lba_addr;
|
|
|
|
|
uint32_t ra_addr;
|
|
|
|
|
uint32_t host_addr;
|
2022-09-18 17:15:38 -04:00
|
|
|
uint8_t lru;
|
|
|
|
|
uint8_t valid;
|
2022-07-07 23:35:34 +02:00
|
|
|
} hdd_cache_seg_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
// Read cache
|
|
|
|
|
hdd_cache_seg_t segments[HDD_MAX_CACHE_SEG];
|
2022-09-18 17:15:38 -04:00
|
|
|
uint32_t num_segments;
|
|
|
|
|
uint32_t segment_size;
|
|
|
|
|
uint32_t ra_segment;
|
|
|
|
|
uint8_t ra_ongoing;
|
|
|
|
|
uint64_t ra_start_time;
|
2022-07-07 23:35:34 +02:00
|
|
|
|
|
|
|
|
// Write cache
|
|
|
|
|
uint32_t write_addr;
|
|
|
|
|
uint32_t write_pending;
|
|
|
|
|
uint32_t write_size;
|
|
|
|
|
uint64_t write_start_time;
|
|
|
|
|
} hdd_cache_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint32_t cylinders;
|
|
|
|
|
uint32_t sectors_per_track;
|
2022-09-18 17:15:38 -04:00
|
|
|
double sector_time_usec;
|
2022-07-07 23:35:34 +02:00
|
|
|
uint32_t start_sector;
|
|
|
|
|
uint32_t end_sector;
|
|
|
|
|
uint32_t start_track;
|
|
|
|
|
} hdd_zone_t;
|
2017-09-30 16:56:38 -04:00
|
|
|
|
|
|
|
|
/* Define the virtual Hard Disk. */
|
|
|
|
|
typedef struct {
|
2022-09-18 17:15:38 -04:00
|
|
|
uint8_t id;
|
2020-11-16 00:01:21 +01:00
|
|
|
union {
|
2022-09-18 17:15:38 -04:00
|
|
|
uint8_t channel; /* Needed for Settings to reduce the number of if's */
|
2020-11-16 00:01:21 +01:00
|
|
|
|
2022-09-18 17:15:38 -04:00
|
|
|
uint8_t mfm_channel; /* Should rename and/or unionize */
|
|
|
|
|
uint8_t esdi_channel;
|
|
|
|
|
uint8_t xta_channel;
|
|
|
|
|
uint8_t ide_channel;
|
|
|
|
|
uint8_t scsi_id;
|
2020-11-16 00:01:21 +01:00
|
|
|
};
|
2022-09-18 17:15:38 -04:00
|
|
|
uint8_t bus,
|
|
|
|
|
res; /* Reserved for bus mode */
|
|
|
|
|
uint8_t wp; /* Disk has been mounted READ-ONLY */
|
|
|
|
|
uint8_t pad, pad0;
|
2017-09-30 16:56:38 -04:00
|
|
|
|
2022-09-18 17:15:38 -04:00
|
|
|
void *priv;
|
2018-10-26 04:47:21 +02:00
|
|
|
|
2023-05-30 17:39:42 -04:00
|
|
|
char fn[1024]; /* Name of current image file */
|
|
|
|
|
char vhd_parent[1041]; /* Differential VHD parent file */
|
2017-09-30 16:56:38 -04:00
|
|
|
|
2022-09-18 17:15:38 -04:00
|
|
|
uint32_t res0, pad1,
|
|
|
|
|
base,
|
|
|
|
|
spt,
|
|
|
|
|
hpc, /* Physical geometry parameters */
|
|
|
|
|
tracks;
|
2022-07-07 23:35:34 +02:00
|
|
|
|
2022-09-18 17:15:38 -04:00
|
|
|
hdd_zone_t zones[HDD_MAX_ZONES];
|
|
|
|
|
uint32_t num_zones;
|
2022-07-07 23:35:34 +02:00
|
|
|
hdd_cache_t cache;
|
2022-09-18 17:15:38 -04:00
|
|
|
uint32_t phy_cyl;
|
|
|
|
|
uint32_t phy_heads;
|
|
|
|
|
uint32_t rpm;
|
|
|
|
|
uint8_t max_multiple_block;
|
2022-07-07 23:35:34 +02:00
|
|
|
|
|
|
|
|
uint32_t cur_cylinder;
|
|
|
|
|
uint32_t cur_track;
|
|
|
|
|
uint32_t cur_addr;
|
|
|
|
|
|
2022-07-19 11:31:06 +02:00
|
|
|
uint32_t speed_preset;
|
2023-05-30 17:39:42 -04:00
|
|
|
uint32_t vhd_blocksize;
|
2022-07-19 11:31:06 +02:00
|
|
|
|
2022-07-07 23:35:34 +02:00
|
|
|
double avg_rotation_lat_usec;
|
|
|
|
|
double full_stroke_usec;
|
|
|
|
|
double head_switch_usec;
|
|
|
|
|
double cyl_switch_usec;
|
2017-09-30 16:56:38 -04:00
|
|
|
} hard_disk_t;
|
|
|
|
|
|
2022-09-18 17:15:38 -04:00
|
|
|
extern hard_disk_t hdd[HDD_NUM];
|
|
|
|
|
extern unsigned int hdd_table[128][3];
|
|
|
|
|
|
|
|
|
|
extern int hdd_init(void);
|
|
|
|
|
extern int hdd_string_to_bus(char *str, int cdrom);
|
|
|
|
|
extern char *hdd_bus_to_string(int bus, int cdrom);
|
|
|
|
|
extern int hdd_is_valid(int c);
|
|
|
|
|
|
|
|
|
|
extern void hdd_image_init(void);
|
|
|
|
|
extern int hdd_image_load(int id);
|
|
|
|
|
extern void hdd_image_seek(uint8_t id, uint32_t sector);
|
|
|
|
|
extern void hdd_image_read(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer);
|
|
|
|
|
extern int hdd_image_read_ex(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer);
|
|
|
|
|
extern void hdd_image_write(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer);
|
|
|
|
|
extern int hdd_image_write_ex(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer);
|
|
|
|
|
extern void hdd_image_zero(uint8_t id, uint32_t sector, uint32_t count);
|
|
|
|
|
extern int hdd_image_zero_ex(uint8_t id, uint32_t sector, uint32_t count);
|
|
|
|
|
extern uint32_t hdd_image_get_last_sector(uint8_t id);
|
|
|
|
|
extern uint32_t hdd_image_get_pos(uint8_t id);
|
|
|
|
|
extern uint8_t hdd_image_get_type(uint8_t id);
|
|
|
|
|
extern void hdd_image_unload(uint8_t id, int fn_preserve);
|
|
|
|
|
extern void hdd_image_close(uint8_t id);
|
|
|
|
|
extern void hdd_image_calc_chs(uint32_t *c, uint32_t *h, uint32_t *s, uint32_t size);
|
|
|
|
|
|
|
|
|
|
extern int image_is_hdi(const char *s);
|
|
|
|
|
extern int image_is_hdx(const char *s, int check_signature);
|
|
|
|
|
extern int image_is_vhd(const char *s, int check_signature);
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2022-10-14 14:44:36 +03:00
|
|
|
extern double hdd_timing_write(hard_disk_t *hdd, uint32_t addr, uint32_t len);
|
|
|
|
|
extern double hdd_timing_read(hard_disk_t *hdd, uint32_t addr, uint32_t len);
|
|
|
|
|
extern double hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_t operation, uint8_t continuous, double max_seek_time);
|
2022-11-17 22:44:06 +01:00
|
|
|
int hdd_preset_get_num(void);
|
2022-10-14 14:44:36 +03:00
|
|
|
const char *hdd_preset_getname(int preset);
|
|
|
|
|
extern const char *hdd_preset_get_internal_name(int preset);
|
|
|
|
|
extern int hdd_preset_get_from_internal_name(char *s);
|
|
|
|
|
extern void hdd_preset_apply(int hdd_id);
|
2017-08-24 01:14:39 -04:00
|
|
|
|
2022-09-18 17:15:38 -04:00
|
|
|
#endif /*EMU_HDD_H*/
|