aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ata.c163
-rw-r--r--src/ata.h6
-rw-r--r--src/biosvar.h21
-rw-r--r--src/block.c112
-rw-r--r--src/boot.c16
-rw-r--r--src/boot.h3
-rw-r--r--src/cdrom.c57
-rw-r--r--src/disk.c274
-rw-r--r--src/disk.h22
-rw-r--r--src/floppy.c69
-rw-r--r--src/ramdisk.c13
11 files changed, 391 insertions, 365 deletions
diff --git a/src/ata.c b/src/ata.c
index f5a1c98c..2312f7d0 100644
--- a/src/ata.c
+++ b/src/ata.c
@@ -77,15 +77,15 @@ ndelay_await_not_bsy(u16 iobase1)
// Reset a drive
static void
-ata_reset(int driveid)
+ata_reset(struct drive_s *drive_g)
{
- u8 ataid = GET_GLOBAL(Drives.drives[driveid].cntl_id);
+ u8 ataid = GET_GLOBAL(drive_g->cntl_id);
u8 channel = ataid / 2;
u8 slave = ataid % 2;
u16 iobase1 = GET_GLOBAL(ATA_channels[channel].iobase1);
u16 iobase2 = GET_GLOBAL(ATA_channels[channel].iobase2);
- dprintf(6, "ata_reset driveid=%d\n", driveid);
+ dprintf(6, "ata_reset drive=%p\n", drive_g);
// Pulse SRST
outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN | ATA_CB_DC_SRST, iobase2+ATA_CB_DC);
udelay(5);
@@ -118,7 +118,7 @@ ata_reset(int driveid)
}
// On a user-reset request, wait for RDY if it is an ATA device.
- u8 type=GET_GLOBAL(Drives.drives[driveid].type);
+ u8 type=GET_GLOBAL(drive_g->type);
if (type == DTYPE_ATA)
status = await_rdy(iobase1);
@@ -130,10 +130,10 @@ done:
}
static int
-isready(int driveid)
+isready(struct drive_s *drive_g)
{
// Read the status from controller
- u8 ataid = GET_GLOBAL(Drives.drives[driveid].cntl_id);
+ u8 ataid = GET_GLOBAL(drive_g->cntl_id);
u8 channel = ataid / 2;
u16 iobase1 = GET_GLOBAL(ATA_channels[channel].iobase1);
u8 status = inb(iobase1 + ATA_CB_STAT);
@@ -150,10 +150,10 @@ process_ata_misc_op(struct disk_op_s *op)
switch (op->command) {
case CMD_RESET:
- ata_reset(op->driveid);
+ ata_reset(op->drive_g);
return DISK_RET_SUCCESS;
case CMD_ISREADY:
- return isready(op->driveid);
+ return isready(op->drive_g);
case CMD_FORMAT:
case CMD_VERIFY:
case CMD_SEEK:
@@ -186,9 +186,9 @@ struct ata_pio_command {
// Send an ata command to the drive.
static int
-send_cmd(int driveid, struct ata_pio_command *cmd)
+send_cmd(struct drive_s *drive_g, struct ata_pio_command *cmd)
{
- u8 ataid = GET_GLOBAL(Drives.drives[driveid].cntl_id);
+ u8 ataid = GET_GLOBAL(drive_g->cntl_id);
u8 channel = ataid / 2;
u8 slave = ataid % 2;
u16 iobase1 = GET_GLOBAL(ATA_channels[channel].iobase1);
@@ -249,14 +249,14 @@ send_cmd(int driveid, struct ata_pio_command *cmd)
****************************************************************/
// Transfer 'op->count' blocks (of 'blocksize' bytes) to/from drive
-// 'op->driveid'.
+// 'op->drive_g'.
static int
ata_transfer(struct disk_op_s *op, int iswrite, int blocksize)
{
- dprintf(16, "ata_transfer id=%d write=%d count=%d bs=%d buf=%p\n"
- , op->driveid, iswrite, op->count, blocksize, op->buf_fl);
+ dprintf(16, "ata_transfer id=%p write=%d count=%d bs=%d buf=%p\n"
+ , op->drive_g, iswrite, op->count, blocksize, op->buf_fl);
- u8 ataid = GET_GLOBAL(Drives.drives[op->driveid].cntl_id);
+ u8 ataid = GET_GLOBAL(op->drive_g->cntl_id);
u8 channel = ataid / 2;
u16 iobase1 = GET_GLOBAL(ATA_channels[channel].iobase1);
u16 iobase2 = GET_GLOBAL(ATA_channels[channel].iobase2);
@@ -266,14 +266,14 @@ ata_transfer(struct disk_op_s *op, int iswrite, int blocksize)
for (;;) {
if (iswrite) {
// Write data to controller
- dprintf(16, "Write sector id=%d dest=%p\n", op->driveid, buf_fl);
+ dprintf(16, "Write sector id=%p dest=%p\n", op->drive_g, buf_fl);
if (CONFIG_ATA_PIO32)
outsl_fl(iobase1, buf_fl, blocksize / 4);
else
outsw_fl(iobase1, buf_fl, blocksize / 2);
} else {
// Read data from controller
- dprintf(16, "Read sector id=%d dest=%p\n", op->driveid, buf_fl);
+ dprintf(16, "Read sector id=%p dest=%p\n", op->drive_g, buf_fl);
if (CONFIG_ATA_PIO32)
insl_fl(iobase1, buf_fl, blocksize / 4);
else
@@ -346,7 +346,7 @@ ata_cmd_data(struct disk_op_s *op, int iswrite, int command)
cmd.lba_high = lba >> 16;
cmd.device = ((lba >> 24) & 0xf) | ATA_CB_DH_LBA;
- int ret = send_cmd(op->driveid, &cmd);
+ int ret = send_cmd(op->drive_g, &cmd);
if (ret)
return ret;
return ata_transfer(op, iswrite, DISK_SECTOR_SIZE);
@@ -381,9 +381,9 @@ process_ata_op(struct disk_op_s *op)
// Low-level atapi command transmit function.
static int
-send_atapi_cmd(int driveid, u8 *cmdbuf, u8 cmdlen, u16 blocksize)
+send_atapi_cmd(struct drive_s *drive_g, u8 *cmdbuf, u8 cmdlen, u16 blocksize)
{
- u8 ataid = GET_GLOBAL(Drives.drives[driveid].cntl_id);
+ u8 ataid = GET_GLOBAL(drive_g->cntl_id);
u8 channel = ataid / 2;
u16 iobase1 = GET_GLOBAL(ATA_channels[channel].iobase1);
u16 iobase2 = GET_GLOBAL(ATA_channels[channel].iobase2);
@@ -397,7 +397,7 @@ send_atapi_cmd(int driveid, u8 *cmdbuf, u8 cmdlen, u16 blocksize)
cmd.device = 0;
cmd.command = ATA_CMD_PACKET;
- int ret = send_cmd(driveid, &cmd);
+ int ret = send_cmd(drive_g, &cmd);
if (ret)
return ret;
@@ -438,7 +438,7 @@ cdrom_read(struct disk_op_s *op)
atacmd[4]=(op->lba & 0x0000ff00) >> 8;
atacmd[5]=(op->lba & 0x000000ff);
- int ret = send_atapi_cmd(op->driveid, atacmd, sizeof(atacmd)
+ int ret = send_atapi_cmd(op->drive_g, atacmd, sizeof(atacmd)
, CDROM_SECTOR_SIZE);
if (ret)
return ret;
@@ -467,16 +467,16 @@ process_atapi_op(struct disk_op_s *op)
// Send a simple atapi command to a drive.
int
-ata_cmd_packet(int driveid, u8 *cmdbuf, u8 cmdlen
+ata_cmd_packet(struct drive_s *drive_g, u8 *cmdbuf, u8 cmdlen
, u32 length, void *buf_fl)
{
- int ret = send_atapi_cmd(driveid, cmdbuf, cmdlen, length);
+ int ret = send_atapi_cmd(drive_g, cmdbuf, cmdlen, length);
if (ret)
return ret;
struct disk_op_s dop;
memset(&dop, 0, sizeof(dop));
- dop.driveid = driveid;
+ dop.drive_g = drive_g;
dop.count = 1;
dop.buf_fl = buf_fl;
@@ -503,13 +503,13 @@ extract_version(u16 *buffer)
// Extract common information from IDENTIFY commands.
static void
-extract_identify(int driveid, u16 *buffer)
+extract_identify(struct drive_s *drive_g, u16 *buffer)
{
dprintf(3, "Identify w0=%x w2=%x\n", buffer[0], buffer[2]);
// Read model name
- char *model = Drives.drives[driveid].model;
- int maxsize = ARRAY_SIZE(Drives.drives[driveid].model);
+ char *model = drive_g->model;
+ int maxsize = ARRAY_SIZE(drive_g->model);
int i;
for (i=0; i<maxsize/2; i++) {
u16 v = buffer[27+i];
@@ -523,62 +523,66 @@ extract_identify(int driveid, u16 *buffer)
model[i] = 0x00;
// Common flags.
- SET_GLOBAL(Drives.drives[driveid].removable, (buffer[0] & 0x80) ? 1 : 0);
- SET_GLOBAL(Drives.drives[driveid].cntl_info, extract_version(buffer));
+ SET_GLOBAL(drive_g->removable, (buffer[0] & 0x80) ? 1 : 0);
+ SET_GLOBAL(drive_g->cntl_info, extract_version(buffer));
}
void
-describe_atapi(int driveid)
+describe_atapi(struct drive_s *drive_g)
{
- u8 ataid = Drives.drives[driveid].cntl_id;
+ u8 ataid = drive_g->cntl_id;
u8 channel = ataid / 2;
u8 slave = ataid % 2;
- u8 version = Drives.drives[driveid].cntl_info;
- int iscd = Drives.drives[driveid].floppy_type;
+ u8 version = drive_g->cntl_info;
+ int iscd = drive_g->floppy_type;
printf("ata%d-%d: %s ATAPI-%d %s", channel, slave
- , Drives.drives[driveid].model, version
+ , drive_g->model, version
, (iscd ? "CD-Rom/DVD-Rom" : "Device"));
}
-static int
-init_drive_atapi(int driveid, u16 *buffer)
+static struct drive_s *
+init_drive_atapi(struct drive_s *dummy, u16 *buffer)
{
// Send an IDENTIFY_DEVICE_PACKET command to device
memset(buffer, 0, DISK_SECTOR_SIZE);
struct disk_op_s dop;
memset(&dop, 0, sizeof(dop));
- dop.driveid = driveid;
+ dop.drive_g = dummy;
dop.count = 1;
dop.lba = 1;
dop.buf_fl = MAKE_FLATPTR(GET_SEG(SS), buffer);
int ret = ata_cmd_data(&dop, 0, ATA_CMD_IDENTIFY_DEVICE_PACKET);
if (ret)
- return ret;
+ return NULL;
// Success - setup as ATAPI.
- extract_identify(driveid, buffer);
- SET_GLOBAL(Drives.drives[driveid].type, DTYPE_ATAPI);
- SET_GLOBAL(Drives.drives[driveid].blksize, CDROM_SECTOR_SIZE);
- SET_GLOBAL(Drives.drives[driveid].sectors, (u64)-1);
+ struct drive_s *drive_g = allocDrive();
+ if (! drive_g)
+ return NULL;
+ SET_GLOBAL(drive_g->cntl_id, dummy->cntl_id);
+ extract_identify(drive_g, buffer);
+ SET_GLOBAL(drive_g->type, DTYPE_ATAPI);
+ SET_GLOBAL(drive_g->blksize, CDROM_SECTOR_SIZE);
+ SET_GLOBAL(drive_g->sectors, (u64)-1);
u8 iscd = ((buffer[0] >> 8) & 0x1f) == 0x05;
- SET_GLOBAL(Drives.drives[driveid].floppy_type, iscd);
+ SET_GLOBAL(drive_g->floppy_type, iscd);
// fill cdidmap
if (iscd)
- map_cd_drive(driveid);
+ map_cd_drive(drive_g);
- return 0;
+ return drive_g;
}
void
-describe_ata(int driveid)
+describe_ata(struct drive_s *drive_g)
{
- u8 ataid = Drives.drives[driveid].cntl_id;
+ u8 ataid = drive_g->cntl_id;
u8 channel = ataid / 2;
u8 slave = ataid % 2;
- u64 sectors = Drives.drives[driveid].sectors;
- u8 version = Drives.drives[driveid].cntl_info;
- char *model = Drives.drives[driveid].model;
+ u64 sectors = drive_g->sectors;
+ u8 version = drive_g->cntl_info;
+ char *model = drive_g->model;
printf("ata%d-%d: %s ATA-%d Hard-Disk", channel, slave, model, version);
u64 sizeinmb = sectors >> 11;
if (sizeinmb < (1 << 16))
@@ -587,44 +591,48 @@ describe_ata(int driveid)
printf(" (%u GiBytes)", (u32)(sizeinmb >> 10));
}
-static int
-init_drive_ata(int driveid, u16 *buffer)
+static struct drive_s *
+init_drive_ata(struct drive_s *dummy, u16 *buffer)
{
// Send an IDENTIFY_DEVICE command to device
memset(buffer, 0, DISK_SECTOR_SIZE);
struct disk_op_s dop;
memset(&dop, 0, sizeof(dop));
- dop.driveid = driveid;
+ dop.drive_g = dummy;
dop.count = 1;
dop.lba = 1;
dop.buf_fl = MAKE_FLATPTR(GET_SEG(SS), buffer);
int ret = ata_cmd_data(&dop, 0, ATA_CMD_IDENTIFY_DEVICE);
if (ret)
- return ret;
+ return NULL;
// Success - setup as ATA.
- extract_identify(driveid, buffer);
- SET_GLOBAL(Drives.drives[driveid].type, DTYPE_ATA);
- SET_GLOBAL(Drives.drives[driveid].blksize, DISK_SECTOR_SIZE);
-
- SET_GLOBAL(Drives.drives[driveid].pchs.cylinders, buffer[1]);
- SET_GLOBAL(Drives.drives[driveid].pchs.heads, buffer[3]);
- SET_GLOBAL(Drives.drives[driveid].pchs.spt, buffer[6]);
+ struct drive_s *drive_g = allocDrive();
+ if (! drive_g)
+ return NULL;
+ SET_GLOBAL(drive_g->cntl_id, dummy->cntl_id);
+ extract_identify(drive_g, buffer);
+ SET_GLOBAL(drive_g->type, DTYPE_ATA);
+ SET_GLOBAL(drive_g->blksize, DISK_SECTOR_SIZE);
+
+ SET_GLOBAL(drive_g->pchs.cylinders, buffer[1]);
+ SET_GLOBAL(drive_g->pchs.heads, buffer[3]);
+ SET_GLOBAL(drive_g->pchs.spt, buffer[6]);
u64 sectors;
if (buffer[83] & (1 << 10)) // word 83 - lba48 support
sectors = *(u64*)&buffer[100]; // word 100-103
else
sectors = *(u32*)&buffer[60]; // word 60 and word 61
- SET_GLOBAL(Drives.drives[driveid].sectors, sectors);
+ SET_GLOBAL(drive_g->sectors, sectors);
// Setup disk geometry translation.
- setup_translation(driveid);
+ setup_translation(drive_g);
// Register with bcv system.
- add_bcv_internal(driveid);
+ add_bcv_internal(drive_g);
- return 0;
+ return drive_g;
}
static int
@@ -653,6 +661,8 @@ powerup_await_non_bsy(u16 base, u64 end)
static void
ata_detect()
{
+ struct drive_s dummy;
+ memset(&dummy, 0, sizeof(dummy));
// Device detection
u64 end = calc_future_tsc(IDE_TIMEOUT);
int ataid, last_reset_ataid=-1;
@@ -687,25 +697,21 @@ ata_detect()
if (sc != 0x55 || sn != 0xaa || dh != newdh)
continue;
- // Prepare new driveid.
- u8 driveid = GET_GLOBAL(Drives.drivecount);
- if (driveid >= ARRAY_SIZE(Drives.drives))
- break;
- memset(&Drives.drives[driveid], 0, sizeof(Drives.drives[0]));
- Drives.drives[driveid].cntl_id = ataid;
+ // Prepare new drive.
+ dummy.cntl_id = ataid;
// reset the channel
if (slave && ataid == last_reset_ataid + 1) {
// The drive was just reset - no need to reset it again.
} else {
- ata_reset(driveid);
+ ata_reset(&dummy);
last_reset_ataid = ataid;
}
// check for ATAPI
u16 buffer[256];
- int ret = init_drive_atapi(driveid, buffer);
- if (ret) {
+ struct drive_s *drive_g = init_drive_atapi(&dummy, buffer);
+ if (!drive_g) {
// Didn't find an ATAPI drive - look for ATA drive.
u8 st = inb(iobase1+ATA_CB_STAT);
if (!st)
@@ -713,20 +719,19 @@ ata_detect()
continue;
// Wait for RDY.
- ret = await_rdy(iobase1);
+ int ret = await_rdy(iobase1);
if (ret < 0)
continue;
// check for ATA.
- ret = init_drive_ata(driveid, buffer);
- if (ret)
+ drive_g = init_drive_ata(&dummy, buffer);
+ if (!drive_g)
// No ATA drive found
continue;
}
- SET_GLOBAL(Drives.drivecount, driveid+1);
// Report drive info to user.
- describe_drive(driveid);
+ describe_drive(drive_g);
printf("\n");
u16 resetresult = buffer[93];
diff --git a/src/ata.h b/src/ata.h
index f04db921..65d67b0b 100644
--- a/src/ata.h
+++ b/src/ata.h
@@ -14,13 +14,13 @@ struct ata_channel_s {
// ata.c
extern struct ata_channel_s ATA_channels[CONFIG_MAX_ATA_INTERFACES];
int cdrom_read(struct disk_op_s *op);
-int ata_cmd_packet(int driveid, u8 *cmdbuf, u8 cmdlen
+int ata_cmd_packet(struct drive_s *drive_g, u8 *cmdbuf, u8 cmdlen
, u32 length, void *buf_fl);
void ata_setup();
int process_ata_op(struct disk_op_s *op);
int process_atapi_op(struct disk_op_s *op);
-void describe_ata(int driveid);
-void describe_atapi(int driveid);
+void describe_ata(struct drive_s *drive_g);
+void describe_atapi(struct drive_s *drive_g);
// Global defines -- ATA register and register bits.
// command block & control block regs
diff --git a/src/biosvar.h b/src/biosvar.h
index 983d28fb..7a8e33b9 100644
--- a/src/biosvar.h
+++ b/src/biosvar.h
@@ -160,14 +160,14 @@ struct dpte_s {
// ElTorito Device Emulation data
struct cdemu_s {
- u8 active;
- u8 media;
- u8 emulated_extdrive;
- u8 emulated_driveid;
+ struct drive_s *emulated_drive;
u32 ilba;
u16 buffer_segment;
u16 load_segment;
u16 sector_count;
+ u8 active;
+ u8 media;
+ u8 emulated_extdrive;
// Virtual device
struct chs_s lchs;
@@ -214,7 +214,7 @@ struct extended_bios_data_area_s {
struct dpte_s dpte;
// Locks for removable devices
- u8 cdrom_locks[CONFIG_MAX_DRIVES];
+ u8 cdrom_locks[CONFIG_MAX_EXTDRIVE];
u16 boot_sequence;
@@ -265,10 +265,15 @@ static inline u16 get_global_seg() {
}
#define GET_GLOBAL(var) \
GET_VAR(GLOBAL_SEGREG, (var))
-#define SET_GLOBAL(var, val) do { \
- ASSERT32(); \
- (var) = (val); \
+#define SET_GLOBAL(var, val) do { \
+ ASSERT32(); \
+ (var) = (val); \
} while (0)
+#if MODE16
+#define ADJUST_GLOBAL_PTR(var) (var)
+#else
+#define ADJUST_GLOBAL_PTR(var) ((typeof(var))((void*)var - BUILD_BIOS_ADDR))
+#endif
/****************************************************************
diff --git a/src/block.c b/src/block.c
index d581b79c..ce6c807c 100644
--- a/src/block.c
+++ b/src/block.c
@@ -13,18 +13,47 @@
struct drives_s Drives VAR16VISIBLE;
+struct drive_s *
+getDrive(u8 exttype, u8 extdriveoffset)
+{
+ // basic check : device has to be defined
+ if (extdriveoffset >= ARRAY_SIZE(Drives.idmap[0]))
+ return NULL;
+
+ // Get the ata channel
+ u8 driveid = GET_GLOBAL(Drives.idmap[exttype][extdriveoffset]);
+
+ // basic check : device has to be valid
+ if (driveid >= ARRAY_SIZE(Drives.drives))
+ return NULL;
+
+ return &Drives.drives[driveid];
+}
+
+struct drive_s *
+allocDrive()
+{
+ int driveid = Drives.drivecount;
+ if (driveid >= ARRAY_SIZE(Drives.drives))
+ return NULL;
+ Drives.drivecount++;
+ struct drive_s *drive_g = &Drives.drives[driveid];
+ memset(drive_g, 0, sizeof(*drive_g));
+ return drive_g;
+}
+
/****************************************************************
* Disk geometry translation
****************************************************************/
static u8
-get_translation(int driveid)
+get_translation(struct drive_s *drive_g)
{
- u8 type = GET_GLOBAL(Drives.drives[driveid].type);
+ u8 type = GET_GLOBAL(drive_g->type);
if (! CONFIG_COREBOOT && type == DTYPE_ATA) {
// Emulators pass in the translation info via nvram.
- u8 ataid = GET_GLOBAL(Drives.drives[driveid].cntl_id);
+ u8 ataid = GET_GLOBAL(drive_g->cntl_id);
u8 channel = ataid / 2;
u8 translation = inb_cmos(CMOS_BIOS_DISKTRANSFLAG + channel/2);
translation >>= 2 * (ataid % 4);
@@ -33,9 +62,9 @@ get_translation(int driveid)
}
// On COREBOOT, use a heuristic to determine translation type.
- u16 heads = GET_GLOBAL(Drives.drives[driveid].pchs.heads);
- u16 cylinders = GET_GLOBAL(Drives.drives[driveid].pchs.cylinders);
- u16 spt = GET_GLOBAL(Drives.drives[driveid].pchs.spt);
+ u16 heads = GET_GLOBAL(drive_g->pchs.heads);
+ u16 cylinders = GET_GLOBAL(drive_g->pchs.cylinders);
+ u16 spt = GET_GLOBAL(drive_g->pchs.spt);
if (cylinders <= 1024 && heads <= 16 && spt <= 63)
return TRANSLATION_NONE;
@@ -45,18 +74,18 @@ get_translation(int driveid)
}
void
-setup_translation(int driveid)
+setup_translation(struct drive_s *drive_g)
{
- u8 translation = get_translation(driveid);
- SET_GLOBAL(Drives.drives[driveid].translation, translation);
+ u8 translation = get_translation(drive_g);
+ SET_GLOBAL(drive_g->translation, translation);
- u8 ataid = GET_GLOBAL(Drives.drives[driveid].cntl_id);
+ u8 ataid = GET_GLOBAL(drive_g->cntl_id);
u8 channel = ataid / 2;
u8 slave = ataid % 2;
- u16 heads = GET_GLOBAL(Drives.drives[driveid].pchs.heads);
- u16 cylinders = GET_GLOBAL(Drives.drives[driveid].pchs.cylinders);
- u16 spt = GET_GLOBAL(Drives.drives[driveid].pchs.spt);
- u64 sectors = GET_GLOBAL(Drives.drives[driveid].sectors);
+ u16 heads = GET_GLOBAL(drive_g->pchs.heads);
+ u16 cylinders = GET_GLOBAL(drive_g->pchs.cylinders);
+ u16 spt = GET_GLOBAL(drive_g->pchs.spt);
+ u64 sectors = GET_GLOBAL(drive_g->sectors);
dprintf(1, "ata%d-%d: PCHS=%u/%d/%d translation="
, channel, slave, cylinders, heads, spt);
@@ -114,9 +143,9 @@ setup_translation(int driveid)
cylinders = 1024;
dprintf(1, " LCHS=%d/%d/%d\n", cylinders, heads, spt);
- SET_GLOBAL(Drives.drives[driveid].lchs.heads, heads);
- SET_GLOBAL(Drives.drives[driveid].lchs.cylinders, cylinders);
- SET_GLOBAL(Drives.drives[driveid].lchs.spt, spt);
+ SET_GLOBAL(drive_g->lchs.heads, heads);
+ SET_GLOBAL(drive_g->lchs.cylinders, cylinders);
+ SET_GLOBAL(drive_g->lchs.spt, spt);
}
@@ -126,18 +155,18 @@ setup_translation(int driveid)
// Fill in Fixed Disk Parameter Table (located in ebda).
static void
-fill_fdpt(int driveid, int hdid)
+fill_fdpt(struct drive_s *drive_g, int hdid)
{
if (hdid > 1)
return;
- u16 nlc = GET_GLOBAL(Drives.drives[driveid].lchs.cylinders);
- u16 nlh = GET_GLOBAL(Drives.drives[driveid].lchs.heads);
- u16 nlspt = GET_GLOBAL(Drives.drives[driveid].lchs.spt);
+ u16 nlc = GET_GLOBAL(drive_g->lchs.cylinders);
+ u16 nlh = GET_GLOBAL(drive_g->lchs.heads);
+ u16 nlspt = GET_GLOBAL(drive_g->lchs.spt);
- u16 npc = GET_GLOBAL(Drives.drives[driveid].pchs.cylinders);
- u16 nph = GET_GLOBAL(Drives.drives[driveid].pchs.heads);
- u16 npspt = GET_GLOBAL(Drives.drives[driveid].pchs.spt);
+ u16 npc = GET_GLOBAL(drive_g->pchs.cylinders);
+ u16 nph = GET_GLOBAL(drive_g->pchs.heads);
+ u16 npspt = GET_GLOBAL(drive_g->pchs.spt);
struct fdpt_s *fdpt = &get_ebda_ptr()->fdpt[hdid];
fdpt->precompensation = 0xffff;
@@ -172,42 +201,45 @@ fill_fdpt(int driveid, int hdid)
// Map a drive (that was registered via add_bcv_hd)
void
-map_hd_drive(int driveid)
+map_hd_drive(struct drive_s *drive_g)
{
// fill hdidmap
u8 hdcount = GET_BDA(hdcount);
if (hdcount >= ARRAY_SIZE(Drives.idmap[0]))
return;
- dprintf(3, "Mapping hd driveid %d to %d\n", driveid, hdcount);
+ dprintf(3, "Mapping hd drive %p to %d\n", drive_g, hdcount);
+ int driveid = drive_g - Drives.drives;
SET_GLOBAL(Drives.idmap[EXTTYPE_HD][hdcount], driveid);
SET_BDA(hdcount, hdcount + 1);
// Fill "fdpt" structure.
- fill_fdpt(driveid, hdcount);
+ fill_fdpt(drive_g, hdcount);
}
// Map a cd
void
-map_cd_drive(int driveid)
+map_cd_drive(struct drive_s *drive_g)
{
// fill cdidmap
u8 cdcount = GET_GLOBAL(Drives.cdcount);
if (cdcount >= ARRAY_SIZE(Drives.idmap[0]))
return;
- dprintf(3, "Mapping cd driveid %d to %d\n", driveid, cdcount);
+ dprintf(3, "Mapping cd drive %p to %d\n", drive_g, cdcount);
+ int driveid = drive_g - Drives.drives;
SET_GLOBAL(Drives.idmap[EXTTYPE_CD][cdcount], driveid);
SET_GLOBAL(Drives.cdcount, cdcount+1);
}
// Map a floppy
void
-map_floppy_drive(int driveid)
+map_floppy_drive(struct drive_s *drive_g)
{
// fill idmap
u8 floppycount = GET_GLOBAL(Drives.floppycount);
if (floppycount >= ARRAY_SIZE(Drives.idmap[0]))
return;
- dprintf(3, "Mapping floppy driveid %d to %d\n", driveid, floppycount);
+ dprintf(3, "Mapping floppy drive %p to %d\n", drive_g, floppycount);
+ int driveid = drive_g - Drives.drives;
SET_GLOBAL(Drives.idmap[EXTTYPE_FLOPPY][floppycount], driveid);
floppycount++;
SET_GLOBAL(Drives.floppycount, floppycount);
@@ -226,22 +258,22 @@ map_floppy_drive(int driveid)
// Show a one line description (without trailing newline) of a drive.
void
-describe_drive(int driveid)
+describe_drive(struct drive_s *drive_g)
{
ASSERT32();
- u8 type = GET_GLOBAL(Drives.drives[driveid].type);
+ u8 type = GET_GLOBAL(drive_g->type);
switch (type) {
case DTYPE_FLOPPY:
- describe_floppy(driveid);
+ describe_floppy(drive_g);
break;
case DTYPE_ATA:
- describe_ata(driveid);
+ describe_ata(drive_g);
break;
case DTYPE_ATAPI:
- describe_atapi(driveid);
+ describe_atapi(drive_g);
break;
case DTYPE_RAMDISK:
- describe_ramdisk(driveid);
+ describe_ramdisk(drive_g);
break;
default:
printf("Unknown");
@@ -258,7 +290,7 @@ describe_drive(int driveid)
int
process_op(struct disk_op_s *op)
{
- u8 type = GET_GLOBAL(Drives.drives[op->driveid].type);
+ u8 type = GET_GLOBAL(op->drive_g->type);
switch (type) {
case DTYPE_FLOPPY:
return process_floppy_op(op);
@@ -285,8 +317,8 @@ __send_disk_op(struct disk_op_s *op_far, u16 op_seg)
, op_seg, op_far
, sizeof(dop));
- dprintf(DEBUG_HDL_13, "disk_op d=%d lba=%d buf=%p count=%d cmd=%d\n"
- , dop.driveid, (u32)dop.lba, dop.buf_fl
+ dprintf(DEBUG_HDL_13, "disk_op d=%p lba=%d buf=%p count=%d cmd=%d\n"
+ , dop.drive_g, (u32)dop.lba, dop.buf_fl
, dop.count, dop.command);
irq_enable();
diff --git a/src/boot.c b/src/boot.c
index 2de28dd6..e4cdbbcf 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -107,7 +107,7 @@ add_bcv(u16 seg, u16 ip, u16 desc)
// Add a bcv entry for an internal harddrive
void
-add_bcv_internal(int driveid)
+add_bcv_internal(struct drive_s *drive_g)
{
if (! CONFIG_BOOT)
return;
@@ -116,7 +116,7 @@ add_bcv_internal(int driveid)
struct ipl_entry_s *ie = &IPL.bcv[IPL.bcvcount++];
ie->type = BCV_TYPE_INTERNAL;
- ie->vector = driveid;
+ ie->vector = (u32)drive_g;
ie->description = "";
}
@@ -141,9 +141,9 @@ menu_show_floppy(struct ipl_entry_s *ie, int menupos)
{
int i;
for (i = 0; i < Drives.floppycount; i++) {
- int driveid = Drives.idmap[EXTTYPE_FLOPPY][i];
+ struct drive_s *drive_g = getDrive(EXTTYPE_FLOPPY, i);
printf("%d. Floppy [", menupos + i);
- describe_drive(driveid);
+ describe_drive(drive_g);
printf("]\n");
}
return Drives.floppycount;
@@ -159,7 +159,7 @@ menu_show_harddisk(struct ipl_entry_s *ie, int menupos)
switch (ie->type) {
case BCV_TYPE_INTERNAL:
printf("%d. ", menupos + i);
- describe_drive(ie->vector);
+ describe_drive((void*)ie->vector);
printf("\n");
break;
default:
@@ -176,9 +176,9 @@ menu_show_cdrom(struct ipl_entry_s *ie, int menupos)
{
int i;
for (i = 0; i < Drives.cdcount; i++) {
- int driveid = Drives.idmap[EXTTYPE_CD][i];
+ struct drive_s *drive_g = getDrive(EXTTYPE_CD, i);
printf("%d. CD-Rom [", menupos + i);
- describe_drive(driveid);
+ describe_drive(drive_g);
printf("]\n");
}
return Drives.cdcount;
@@ -282,7 +282,7 @@ run_bcv(struct ipl_entry_s *ie)
{
switch (ie->type) {
case BCV_TYPE_INTERNAL:
- map_hd_drive(ie->vector);
+ map_hd_drive((void*)ie->vector);
break;
case BCV_TYPE_EXTERNAL:
call_bcv(ie->vector >> 16, ie->vector & 0xffff);
diff --git a/src/boot.h b/src/boot.h
index 89a25932..1aa1bdc0 100644
--- a/src/boot.h
+++ b/src/boot.h
@@ -41,7 +41,8 @@ extern struct ipl_s IPL;
void boot_setup();
void add_bev(u16 seg, u16 bev, u16 desc);
void add_bcv(u16 seg, u16 ip, u16 desc);
-void add_bcv_internal(int driveid);
+struct drive_s;
+void add_bcv_internal(struct drive_s *drive_g);
void boot_prep();
#endif // __BOOT_H
diff --git a/src/cdrom.c b/src/cdrom.c
index 67d7016b..ba533d0f 100644
--- a/src/cdrom.c
+++ b/src/cdrom.c
@@ -20,9 +20,9 @@ static int
cdemu_read(struct disk_op_s *op)
{
u16 ebda_seg = get_ebda_seg();
- u8 driveid = GET_EBDA2(ebda_seg, cdemu.emulated_driveid);
+ struct drive_s *drive_g = GET_EBDA2(ebda_seg, cdemu.emulated_drive);
struct disk_op_s dop;
- dop.driveid = driveid;
+ dop.drive_g = drive_g;
dop.command = op->command;
dop.lba = GET_EBDA2(ebda_seg, cdemu.ilba) + op->lba / 4;
@@ -104,7 +104,7 @@ process_cdemu_op(struct disk_op_s *op)
}
}
-int cdemu_driveid VAR16VISIBLE;
+struct drive_s *cdemu_drive VAR16VISIBLE;
void
cdemu_setup()
@@ -112,17 +112,15 @@ cdemu_setup()
if (!CONFIG_CDROM_EMU)
return;
- int driveid = Drives.drivecount;
- if (driveid >= ARRAY_SIZE(Drives.drives)) {
- cdemu_driveid = -1;
+ struct drive_s *drive_g = allocDrive();
+ if (!drive_g) {
+ cdemu_drive = NULL;
return;
}
- Drives.drivecount++;
- cdemu_driveid = driveid;
- memset(&Drives.drives[driveid], 0, sizeof(Drives.drives[0]));
- Drives.drives[driveid].type = DTYPE_CDEMU;
- Drives.drives[driveid].blksize = DISK_SECTOR_SIZE;
- Drives.drives[driveid].sectors = (u64)-1;
+ cdemu_drive = ADJUST_GLOBAL_PTR(drive_g);
+ drive_g->type = DTYPE_CDEMU;
+ drive_g->blksize = DISK_SECTOR_SIZE;
+ drive_g->sectors = (u64)-1;
}
struct eltorito_s {
@@ -153,8 +151,8 @@ cdemu_134b(struct bregs *regs)
SET_INT13ET(regs, media, GET_EBDA2(ebda_seg, cdemu.media));
SET_INT13ET(regs, emulated_drive
, GET_EBDA2(ebda_seg, cdemu.emulated_extdrive));
- u8 driveid = GET_EBDA2(ebda_seg, cdemu.emulated_driveid);
- u8 cntl_id = GET_GLOBAL(Drives.drives[driveid].cntl_id);
+ struct drive_s *drive_g = GET_EBDA2(ebda_seg, cdemu.emulated_drive);
+ u8 cntl_id = GET_GLOBAL(drive_g->cntl_id);
SET_INT13ET(regs, controller_index, cntl_id / 2);
SET_INT13ET(regs, device_spec, cntl_id % 2);
SET_INT13ET(regs, ilba, GET_EBDA2(ebda_seg, cdemu.ilba));
@@ -181,13 +179,13 @@ cdemu_134b(struct bregs *regs)
// Request SENSE
static int
-atapi_get_sense(int driveid, u8 *asc, u8 *ascq)
+atapi_get_sense(struct drive_s *drive_g, u8 *asc, u8 *ascq)
{
u8 atacmd[12], buffer[18];
memset(atacmd, 0, sizeof(atacmd));
atacmd[0] = ATA_CMD_REQUEST_SENSE;
atacmd[4] = sizeof(buffer);
- int ret = ata_cmd_packet(driveid, atacmd, sizeof(atacmd), sizeof(buffer)
+ int ret = ata_cmd_packet(drive_g, atacmd, sizeof(atacmd), sizeof(buffer)
, MAKE_FLATPTR(GET_SEG(SS), buffer));
if (ret)
return ret;
@@ -200,12 +198,12 @@ atapi_get_sense(int driveid, u8 *asc, u8 *ascq)
// Request capacity
static int
-atapi_read_capacity(int driveid, u32 *blksize, u32 *sectors)
+atapi_read_capacity(struct drive_s *drive_g, u32 *blksize, u32 *sectors)
{
u8 packet[12], buf[8];
memset(packet, 0, sizeof(packet));
packet[0] = 0x25; /* READ CAPACITY */
- int ret = ata_cmd_packet(driveid, packet, sizeof(packet), sizeof(buf)
+ int ret = ata_cmd_packet(drive_g, packet, sizeof(packet), sizeof(buf)
, MAKE_FLATPTR(GET_SEG(SS), buf));
if (ret)
return ret;
@@ -219,9 +217,9 @@ atapi_read_capacity(int driveid, u32 *blksize, u32 *sectors)
}
static int
-atapi_is_ready(u16 driveid)
+atapi_is_ready(struct drive_s *drive_g)
{
- dprintf(6, "atapi_is_ready (driveid=%d)\n", driveid);
+ dprintf(6, "atapi_is_ready (drive=%p)\n", drive_g);
/* Retry READ CAPACITY for 5 seconds unless MEDIUM NOT PRESENT is
* reported by the device. If the device reports "IN PROGRESS",
@@ -235,13 +233,13 @@ atapi_is_ready(u16 driveid)
return -1;
}
- int ret = atapi_read_capacity(driveid, &blksize, &sectors);
+ int ret = atapi_read_capacity(drive_g, &blksize, &sectors);
if (!ret)
// Success
break;
u8 asc, ascq;
- ret = atapi_get_sense(driveid, &asc, &ascq);
+ ret = atapi_get_sense(drive_g, &asc, &ascq);
if (ret)
// Error - retry.
continue;
@@ -261,7 +259,7 @@ atapi_is_ready(u16 driveid)
}
}
- if (blksize != GET_GLOBAL(Drives.drives[driveid].blksize)) {
+ if (blksize != GET_GLOBAL(drive_g->blksize)) {
printf("Unsupported sector size %u\n", blksize);
return -1;
}
@@ -274,12 +272,11 @@ atapi_is_ready(u16 driveid)
int
cdrom_boot(int cdid)
{
- // Verify device is a cdrom.
- if (cdid >= Drives.cdcount)
+ struct drive_s *drive_g = getDrive(EXTTYPE_CD, cdid);
+ if (!drive_g)
return 1;
- int driveid = GET_GLOBAL(Drives.idmap[EXTTYPE_CD][cdid]);
- int ret = atapi_is_ready(driveid);
+ int ret = atapi_is_ready(drive_g);
if (ret)
dprintf(1, "atapi_is_ready returned %d\n", ret);
@@ -287,7 +284,7 @@ cdrom_boot(int cdid)
u8 buffer[2048];
struct disk_op_s dop;
memset(&dop, 0, sizeof(dop));
- dop.driveid = driveid;
+ dop.drive_g = drive_g;
dop.lba = 0x11;
dop.count = 1;
dop.buf_fl = MAKE_FLATPTR(GET_SEG(SS), buffer);
@@ -328,7 +325,7 @@ cdrom_boot(int cdid)
u8 media = buffer[0x21];
SET_EBDA2(ebda_seg, cdemu.media, media);
- SET_EBDA2(ebda_seg, cdemu.emulated_driveid, driveid);
+ SET_EBDA2(ebda_seg, cdemu.emulated_drive, ADJUST_GLOBAL_PTR(drive_g));
u16 boot_segment = *(u16*)&buffer[0x22];
if (!boot_segment)
@@ -357,7 +354,7 @@ cdrom_boot(int cdid)
}
// Emulation of a floppy/harddisk requested
- if (! CONFIG_CDROM_EMU || cdemu_driveid < 0)
+ if (! CONFIG_CDROM_EMU || !cdemu_drive)
return 13;
// Set emulated drive id and increase bios installed hardware
diff --git a/src/disk.c b/src/disk.c
index 4ebccee7..617cdf02 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -44,9 +44,9 @@ __disk_stub(struct bregs *regs, int lineno, const char *fname)
__disk_stub((regs), __LINE__, __func__)
static void
-fillLCHS(u8 driveid, u16 *nlc, u16 *nlh, u16 *nlspt)
+fillLCHS(struct drive_s *drive_g, u16 *nlc, u16 *nlh, u16 *nlspt)
{
- if (CONFIG_CDROM_EMU && driveid == GET_GLOBAL(cdemu_driveid)) {
+ if (CONFIG_CDROM_EMU && drive_g == GET_GLOBAL(cdemu_drive)) {
// Emulated drive - get info from ebda. (It's not possible to
// populate the geometry directly in the driveid because the
// geometry is only known after the bios segment is made
@@ -57,17 +57,17 @@ fillLCHS(u8 driveid, u16 *nlc, u16 *nlh, u16 *nlspt)
*nlspt = GET_EBDA2(ebda_seg, cdemu.lchs.spt);
return;
}
- *nlc = GET_GLOBAL(Drives.drives[driveid].lchs.cylinders);
- *nlh = GET_GLOBAL(Drives.drives[driveid].lchs.heads);
- *nlspt = GET_GLOBAL(Drives.drives[driveid].lchs.spt);
+ *nlc = GET_GLOBAL(drive_g->lchs.cylinders);
+ *nlh = GET_GLOBAL(drive_g->lchs.heads);
+ *nlspt = GET_GLOBAL(drive_g->lchs.spt);
}
// Perform read/write/verify using old-style chs accesses
static void
-basic_access(struct bregs *regs, u8 driveid, u16 command)
+basic_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
{
struct disk_op_s dop;
- dop.driveid = driveid;
+ dop.drive_g = drive_g;
dop.command = command;
u8 count = regs->al;
@@ -84,7 +84,7 @@ basic_access(struct bregs *regs, u8 driveid, u16 command)
dop.count = count;
u16 nlc, nlh, nlspt;
- fillLCHS(driveid, &nlc, &nlh, &nlspt);
+ fillLCHS(drive_g, &nlc, &nlh, &nlspt);
// sanity check on cyl heads, sec
if (cylinder >= nlc || head >= nlh || sector > nlspt) {
@@ -110,14 +110,14 @@ basic_access(struct bregs *regs, u8 driveid, u16 command)
// Perform read/write/verify using new-style "int13ext" accesses.
static void
-extended_access(struct bregs *regs, u8 driveid, u16 command)
+extended_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
{
struct disk_op_s dop;
// Get lba and check.
dop.lba = GET_INT13EXT(regs, lba);
dop.command = command;
- dop.driveid = driveid;
- if (dop.lba >= GET_GLOBAL(Drives.drives[driveid].sectors)) {
+ dop.drive_g = drive_g;
+ if (dop.lba >= GET_GLOBAL(drive_g->sectors)) {
dprintf(1, "int13_harddisk: function %02x. LBA out of range\n"
, regs->ah);
disk_ret(regs, DISK_RET_EPARAM);
@@ -141,10 +141,10 @@ extended_access(struct bregs *regs, u8 driveid, u16 command)
// disk controller reset
static void
-disk_1300(struct bregs *regs, u8 driveid)
+disk_1300(struct bregs *regs, struct drive_s *drive_g)
{
struct disk_op_s dop;
- dop.driveid = driveid;
+ dop.drive_g = drive_g;
dop.command = CMD_RESET;
int status = send_disk_op(&dop);
disk_ret(regs, status);
@@ -152,7 +152,7 @@ disk_1300(struct bregs *regs, u8 driveid)
// read disk status
static void
-disk_1301(struct bregs *regs, u8 driveid)
+disk_1301(struct bregs *regs, struct drive_s *drive_g)
{
u8 v;
if (regs->dl < EXTSTART_HD)
@@ -167,34 +167,33 @@ disk_1301(struct bregs *regs, u8 driveid)
// read disk sectors
static void
-disk_1302(struct bregs *regs, u8 driveid)
+disk_1302(struct bregs *regs, struct drive_s *drive_g)
{
- basic_access(regs, driveid, CMD_READ);
+ basic_access(regs, drive_g, CMD_READ);
}
// write disk sectors
static void
-disk_1303(struct bregs *regs, u8 driveid)
+disk_1303(struct bregs *regs, struct drive_s *drive_g)
{
- basic_access(regs, driveid, CMD_WRITE);
+ basic_access(regs, drive_g, CMD_WRITE);
}
// verify disk sectors
static void
-disk_1304(struct bregs *regs, u8 driveid)
+disk_1304(struct bregs *regs, struct drive_s *drive_g)
{
- basic_access(regs, driveid, CMD_VERIFY);
- // FIXME verify
+ basic_access(regs, drive_g, CMD_VERIFY);
}
// format disk track
static void
-disk_1305(struct bregs *regs, u8 driveid)
+disk_1305(struct bregs *regs, struct drive_s *drive_g)
{
DISK_STUB(regs);
u16 nlc, nlh, nlspt;
- fillLCHS(driveid, &nlc, &nlh, &nlspt);
+ fillLCHS(drive_g, &nlc, &nlh, &nlspt);
u8 num_sectors = regs->al;
u8 head = regs->dh;
@@ -205,7 +204,7 @@ disk_1305(struct bregs *regs, u8 driveid)
}
struct disk_op_s dop;
- dop.driveid = driveid;
+ dop.drive_g = drive_g;
dop.command = CMD_FORMAT;
dop.lba = head;
dop.count = num_sectors;
@@ -216,12 +215,12 @@ disk_1305(struct bregs *regs, u8 driveid)
// read disk drive parameters
static void
-disk_1308(struct bregs *regs, u8 driveid)
+disk_1308(struct bregs *regs, struct drive_s *drive_g)
{
u16 ebda_seg = get_ebda_seg();
// Get logical geometry from table
u16 nlc, nlh, nlspt;
- fillLCHS(driveid, &nlc, &nlh, &nlspt);
+ fillLCHS(drive_g, &nlc, &nlh, &nlspt);
nlc--;
nlh--;
u8 count;
@@ -229,10 +228,10 @@ disk_1308(struct bregs *regs, u8 driveid)
// Floppy
count = GET_GLOBAL(Drives.floppycount);
- if (CONFIG_CDROM_EMU && driveid == GET_GLOBAL(cdemu_driveid))
+ if (CONFIG_CDROM_EMU && drive_g == GET_GLOBAL(cdemu_drive))
regs->bx = GET_EBDA2(ebda_seg, cdemu.media) * 2;
else
- regs->bx = GET_GLOBAL(Drives.drives[driveid].floppy_type);
+ regs->bx = GET_GLOBAL(drive_g->floppy_type);
// set es & di to point to 11 byte diskette param table in ROM
regs->es = SEG_BIOS;
@@ -268,33 +267,33 @@ disk_1308(struct bregs *regs, u8 driveid)
// initialize drive parameters
static void
-disk_1309(struct bregs *regs, u8 driveid)
+disk_1309(struct bregs *regs, struct drive_s *drive_g)
{
DISK_STUB(regs);
}
// seek to specified cylinder
static void
-disk_130c(struct bregs *regs, u8 driveid)
+disk_130c(struct bregs *regs, struct drive_s *drive_g)
{
DISK_STUB(regs);
}
// alternate disk reset
static void
-disk_130d(struct bregs *regs, u8 driveid)
+disk_130d(struct bregs *regs, struct drive_s *drive_g)
{
DISK_STUB(regs);
}
// check drive ready
static void
-disk_1310(struct bregs *regs, u8 driveid)
+disk_1310(struct bregs *regs, struct drive_s *drive_g)
{
// should look at 40:8E also???
struct disk_op_s dop;
- dop.driveid = driveid;
+ dop.drive_g = drive_g;
dop.command = CMD_ISREADY;
int status = send_disk_op(&dop);
disk_ret(regs, status);
@@ -302,21 +301,21 @@ disk_1310(struct bregs *regs, u8 driveid)
// recalibrate
static void
-disk_1311(struct bregs *regs, u8 driveid)
+disk_1311(struct bregs *regs, struct drive_s *drive_g)
{
DISK_STUB(regs);
}
// controller internal diagnostic
static void
-disk_1314(struct bregs *regs, u8 driveid)
+disk_1314(struct bregs *regs, struct drive_s *drive_g)
{
DISK_STUB(regs);
}
// read disk drive size
static void
-disk_1315(struct bregs *regs, u8 driveid)
+disk_1315(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_SUCCESS);
if (regs->dl < EXTSTART_HD || regs->dl >= EXTSTART_CD) {
@@ -328,7 +327,7 @@ disk_1315(struct bregs *regs, u8 driveid)
// Get logical geometry from table
u16 nlc, nlh, nlspt;
- fillLCHS(driveid, &nlc, &nlh, &nlspt);
+ fillLCHS(drive_g, &nlc, &nlh, &nlspt);
// Compute sector count seen by int13
u32 lba = (u32)(nlc - 1) * (u32)nlh * (u32)nlspt;
@@ -338,7 +337,7 @@ disk_1315(struct bregs *regs, u8 driveid)
}
static void
-disk_1316(struct bregs *regs, u8 driveid)
+disk_1316(struct bregs *regs, struct drive_s *drive_g)
{
if (regs->dl >= EXTSTART_HD) {
// Hard drive
@@ -350,7 +349,7 @@ disk_1316(struct bregs *regs, u8 driveid)
// IBM/MS installation check
static void
-disk_1341(struct bregs *regs, u8 driveid)
+disk_1341(struct bregs *regs, struct drive_s *drive_g)
{
regs->bx = 0xaa55; // install check
regs->cx = 0x0007; // ext disk access and edd, removable supported
@@ -360,76 +359,79 @@ disk_1341(struct bregs *regs, u8 driveid)
// IBM/MS extended read
static void
-disk_1342(struct bregs *regs, u8 driveid)
+disk_1342(struct bregs *regs, struct drive_s *drive_g)
{
- extended_access(regs, driveid, CMD_READ);
+ extended_access(regs, drive_g, CMD_READ);
}
// IBM/MS extended write
static void
-disk_1343(struct bregs *regs, u8 driveid)
+disk_1343(struct bregs *regs, struct drive_s *drive_g)
{
- extended_access(regs, driveid, CMD_WRITE);
+ extended_access(regs, drive_g, CMD_WRITE);
}
// IBM/MS verify
static void
-disk_1344(struct bregs *regs, u8 driveid)
+disk_1344(struct bregs *regs, struct drive_s *drive_g)
{
- extended_access(regs, driveid, CMD_VERIFY);
+ extended_access(regs, drive_g, CMD_VERIFY);
}
// lock
static void
-disk_134500(struct bregs *regs, u8 driveid)
+disk_134500(struct bregs *regs, struct drive_s *drive_g)
{
u16 ebda_seg = get_ebda_seg();
- u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[driveid]);
+ int cdid = regs->dl - EXTSTART_CD;
+ u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[cdid]);
if (locks == 0xff) {
regs->al = 1;
disk_ret(regs, DISK_RET_ETOOMANYLOCKS);
return;
}
- SET_EBDA2(ebda_seg, cdrom_locks[driveid], locks + 1);
+ SET_EBDA2(ebda_seg, cdrom_locks[cdid], locks + 1);
regs->al = 1;
disk_ret(regs, DISK_RET_SUCCESS);
}
// unlock
static void
-disk_134501(struct bregs *regs, u8 driveid)
+disk_134501(struct bregs *regs, struct drive_s *drive_g)
{
u16 ebda_seg = get_ebda_seg();
- u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[driveid]);
+ int cdid = regs->dl - EXTSTART_CD;
+ u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[cdid]);
if (locks == 0x00) {
regs->al = 0;
disk_ret(regs, DISK_RET_ENOTLOCKED);
return;
}
locks--;
- SET_EBDA2(ebda_seg, cdrom_locks[driveid], locks);
+ SET_EBDA2(ebda_seg, cdrom_locks[cdid], locks);
regs->al = (locks ? 1 : 0);
disk_ret(regs, DISK_RET_SUCCESS);
}
// status
static void
-disk_134502(struct bregs *regs, u8 driveid)
+disk_134502(struct bregs *regs, struct drive_s *drive_g)
{
- u8 locks = GET_EBDA(cdrom_locks[driveid]);
+ int cdid = regs->dl - EXTSTART_CD;
+ u8 locks = GET_EBDA(cdrom_locks[cdid]);
regs->al = (locks ? 1 : 0);
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_1345XX(struct bregs *regs, u8 driveid)
+disk_1345XX(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_EPARAM);
}
// IBM/MS lock/unlock drive
static void
-disk_1345(struct bregs *regs, u8 driveid)
+disk_1345(struct bregs *regs, struct drive_s *drive_g)
{
if (regs->dl < EXTSTART_CD) {
// Always success for HD
@@ -438,16 +440,16 @@ disk_1345(struct bregs *regs, u8 driveid)
}
switch (regs->al) {
- case 0x00: disk_134500(regs, driveid); break;
- case 0x01: disk_134501(regs, driveid); break;
- case 0x02: disk_134502(regs, driveid); break;
- default: disk_1345XX(regs, driveid); break;
+ case 0x00: disk_134500(regs, drive_g); break;
+ case 0x01: disk_134501(regs, drive_g); break;
+ case 0x02: disk_134502(regs, drive_g); break;
+ default: disk_1345XX(regs, drive_g); break;
}
}
// IBM/MS eject media
static void
-disk_1346(struct bregs *regs, u8 driveid)
+disk_1346(struct bregs *regs, struct drive_s *drive_g)
{
if (regs->dl < EXTSTART_CD) {
// Volume Not Removable
@@ -455,7 +457,8 @@ disk_1346(struct bregs *regs, u8 driveid)
return;
}
- u8 locks = GET_EBDA(cdrom_locks[driveid]);
+ int cdid = regs->dl - EXTSTART_CD;
+ u8 locks = GET_EBDA(cdrom_locks[cdid]);
if (locks != 0) {
disk_ret(regs, DISK_RET_ELOCKED);
return;
@@ -479,14 +482,14 @@ disk_1346(struct bregs *regs, u8 driveid)
// IBM/MS extended seek
static void
-disk_1347(struct bregs *regs, u8 driveid)
+disk_1347(struct bregs *regs, struct drive_s *drive_g)
{
- extended_access(regs, driveid, CMD_SEEK);
+ extended_access(regs, drive_g, CMD_SEEK);
}
// IBM/MS get drive parameters
static void
-disk_1348(struct bregs *regs, u8 driveid)
+disk_1348(struct bregs *regs, struct drive_s *drive_g)
{
u16 size = GET_INT13DPT(regs, size);
@@ -498,12 +501,12 @@ disk_1348(struct bregs *regs, u8 driveid)
// EDD 1.x
- u8 type = GET_GLOBAL(Drives.drives[driveid].type);
- u16 npc = GET_GLOBAL(Drives.drives[driveid].pchs.cylinders);
- u16 nph = GET_GLOBAL(Drives.drives[driveid].pchs.heads);
- u16 npspt = GET_GLOBAL(Drives.drives[driveid].pchs.spt);
- u64 lba = GET_GLOBAL(Drives.drives[driveid].sectors);
- u16 blksize = GET_GLOBAL(Drives.drives[driveid].blksize);
+ u8 type = GET_GLOBAL(drive_g->type);
+ u16 npc = GET_GLOBAL(drive_g->pchs.cylinders);
+ u16 nph = GET_GLOBAL(drive_g->pchs.heads);
+ u16 npspt = GET_GLOBAL(drive_g->pchs.spt);
+ u64 lba = GET_GLOBAL(drive_g->sectors);
+ u16 blksize = GET_GLOBAL(drive_g->blksize);
dprintf(DEBUG_HDL_13, "disk_1348 size=%d t=%d chs=%d,%d,%d lba=%d bs=%d\n"
, size, type, npc, nph, npspt, (u32)lba, blksize);
@@ -545,7 +548,7 @@ disk_1348(struct bregs *regs, u8 driveid)
, offsetof(struct extended_bios_data_area_s, dpte));
// Fill in dpte
- u8 ataid = GET_GLOBAL(Drives.drives[driveid].cntl_id);
+ u8 ataid = GET_GLOBAL(drive_g->cntl_id);
u8 channel = ataid / 2;
u8 slave = ataid % 2;
u16 iobase1 = GET_GLOBAL(ATA_channels[channel].iobase1);
@@ -554,7 +557,7 @@ disk_1348(struct bregs *regs, u8 driveid)
u16 options = 0;
if (type == DTYPE_ATA) {
- u8 translation = GET_GLOBAL(Drives.drives[driveid].translation);
+ u8 translation = GET_GLOBAL(drive_g->translation);
if (translation != TRANSLATION_NONE) {
options |= 1<<3; // CHS translation
if (translation == TRANSLATION_LBA)
@@ -628,7 +631,7 @@ disk_1348(struct bregs *regs, u8 driveid)
// IBM/MS extended media change
static void
-disk_1349(struct bregs *regs, u8 driveid)
+disk_1349(struct bregs *regs, struct drive_s *drive_g)
{
if (regs->dl < EXTSTART_CD) {
// Always success for HD
@@ -641,56 +644,56 @@ disk_1349(struct bregs *regs, u8 driveid)
}
static void
-disk_134e01(struct bregs *regs, u8 driveid)
+disk_134e01(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134e03(struct bregs *regs, u8 driveid)
+disk_134e03(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134e04(struct bregs *regs, u8 driveid)
+disk_134e04(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134e06(struct bregs *regs, u8 driveid)
+disk_134e06(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134eXX(struct bregs *regs, u8 driveid)
+disk_134eXX(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_EPARAM);
}
// IBM/MS set hardware configuration
static void
-disk_134e(struct bregs *regs, u8 driveid)
+disk_134e(struct bregs *regs, struct drive_s *drive_g)
{
switch (regs->al) {
- case 0x01: disk_134e01(regs, driveid); break;
- case 0x03: disk_134e03(regs, driveid); break;
- case 0x04: disk_134e04(regs, driveid); break;
- case 0x06: disk_134e06(regs, driveid); break;
- default: disk_134eXX(regs, driveid); break;
+ case 0x01: disk_134e01(regs, drive_g); break;
+ case 0x03: disk_134e03(regs, drive_g); break;
+ case 0x04: disk_134e04(regs, drive_g); break;
+ case 0x06: disk_134e06(regs, drive_g); break;
+ default: disk_134eXX(regs, drive_g); break;
}
}
static void
-disk_13XX(struct bregs *regs, u8 driveid)
+disk_13XX(struct bregs *regs, struct drive_s *drive_g)
{
disk_ret(regs, DISK_RET_EPARAM);
}
static void
-disk_13(struct bregs *regs, u8 driveid)
+disk_13(struct bregs *regs, struct drive_s *drive_g)
{
//debug_stub(regs);
@@ -698,37 +701,37 @@ disk_13(struct bregs *regs, u8 driveid)
SET_BDA(disk_interrupt_flag, 0);
switch (regs->ah) {
- case 0x00: disk_1300(regs, driveid); break;
- case 0x01: disk_1301(regs, driveid); break;
- case 0x02: disk_1302(regs, driveid); break;
- case 0x03: disk_1303(regs, driveid); break;
- case 0x04: disk_1304(regs, driveid); break;
- case 0x05: disk_1305(regs, driveid); break;
- case 0x08: disk_1308(regs, driveid); break;
- case 0x09: disk_1309(regs, driveid); break;
- case 0x0c: disk_130c(regs, driveid); break;
- case 0x0d: disk_130d(regs, driveid); break;
- case 0x10: disk_1310(regs, driveid); break;
- case 0x11: disk_1311(regs, driveid); break;
- case 0x14: disk_1314(regs, driveid); break;
- case 0x15: disk_1315(regs, driveid); break;
- case 0x16: disk_1316(regs, driveid); break;
- case 0x41: disk_1341(regs, driveid); break;
- case 0x42: disk_1342(regs, driveid); break;
- case 0x43: disk_1343(regs, driveid); break;
- case 0x44: disk_1344(regs, driveid); break;
- case 0x45: disk_1345(regs, driveid); break;
- case 0x46: disk_1346(regs, driveid); break;
- case 0x47: disk_1347(regs, driveid); break;
- case 0x48: disk_1348(regs, driveid); break;
- case 0x49: disk_1349(regs, driveid); break;
- case 0x4e: disk_134e(regs, driveid); break;
- default: disk_13XX(regs, driveid); break;
+ case 0x00: disk_1300(regs, drive_g); break;
+ case 0x01: disk_1301(regs, drive_g); break;
+ case 0x02: disk_1302(regs, drive_g); break;
+ case 0x03: disk_1303(regs, drive_g); break;
+ case 0x04: disk_1304(regs, drive_g); break;
+ case 0x05: disk_1305(regs, drive_g); break;
+ case 0x08: disk_1308(regs, drive_g); break;
+ case 0x09: disk_1309(regs, drive_g); break;
+ case 0x0c: disk_130c(regs, drive_g); break;
+ case 0x0d: disk_130d(regs, drive_g); break;
+ case 0x10: disk_1310(regs, drive_g); break;
+ case 0x11: disk_1311(regs, drive_g); break;
+ case 0x14: disk_1314(regs, drive_g); break;
+ case 0x15: disk_1315(regs, drive_g); break;
+ case 0x16: disk_1316(regs, drive_g); break;
+ case 0x41: disk_1341(regs, drive_g); break;
+ case 0x42: disk_1342(regs, drive_g); break;
+ case 0x43: disk_1343(regs, drive_g); break;
+ case 0x44: disk_1344(regs, drive_g); break;
+ case 0x45: disk_1345(regs, drive_g); break;
+ case 0x46: disk_1346(regs, drive_g); break;
+ case 0x47: disk_1347(regs, drive_g); break;
+ case 0x48: disk_1348(regs, drive_g); break;
+ case 0x49: disk_1349(regs, drive_g); break;
+ case 0x4e: disk_134e(regs, drive_g); break;
+ default: disk_13XX(regs, drive_g); break;
}
}
static void
-floppy_13(struct bregs *regs, u8 driveid)
+floppy_13(struct bregs *regs, struct drive_s *drive_g)
{
// Only limited commands are supported on floppies.
switch (regs->ah) {
@@ -741,9 +744,9 @@ floppy_13(struct bregs *regs, u8 driveid)
case 0x08:
case 0x15:
case 0x16:
- disk_13(regs, driveid);
+ disk_13(regs, drive_g);
break;
- default: disk_13XX(regs, driveid); break;
+ default: disk_13XX(regs, drive_g); break;
}
}
@@ -752,23 +755,6 @@ floppy_13(struct bregs *regs, u8 driveid)
* Entry points
****************************************************************/
-static int
-get_driveid(struct bregs *regs, u8 exttype, u8 extdriveoffset)
-{
- // basic check : device has to be defined
- if (extdriveoffset >= ARRAY_SIZE(Drives.idmap[0]))
- return -1;
-
- // Get the ata channel
- u8 driveid = GET_GLOBAL(Drives.idmap[exttype][extdriveoffset]);
-
- // basic check : device has to be valid
- if (driveid >= ARRAY_SIZE(Drives.drives))
- return -1;
-
- return driveid;
-}
-
static void
handle_legacy_disk(struct bregs *regs, u8 extdrive)
{
@@ -779,21 +765,21 @@ handle_legacy_disk(struct bregs *regs, u8 extdrive)
}
if (extdrive < EXTSTART_HD) {
- int driveid = get_driveid(regs, EXTTYPE_FLOPPY, extdrive);
- if (driveid < 0)
+ struct drive_s *drive_g = getDrive(EXTTYPE_FLOPPY, extdrive);
+ if (!drive_g)
goto fail;
- floppy_13(regs, driveid);
+ floppy_13(regs, drive_g);
return;
}
- int driveid;
+ struct drive_s *drive_g;
if (extdrive >= EXTSTART_CD)
- driveid = get_driveid(regs, EXTTYPE_CD, extdrive - EXTSTART_CD);
+ drive_g = getDrive(EXTTYPE_CD, extdrive - EXTSTART_CD);
else
- driveid = get_driveid(regs, EXTTYPE_HD, extdrive - EXTSTART_HD);
- if (driveid < 0)
+ drive_g = getDrive(EXTTYPE_HD, extdrive - EXTSTART_HD);
+ if (!drive_g)
goto fail;
- disk_13(regs, driveid);
+ disk_13(regs, drive_g);
return;
fail:
@@ -824,16 +810,18 @@ handle_13(struct bregs *regs)
if (GET_EBDA2(ebda_seg, cdemu.active)) {
u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive);
if (extdrive == emudrive) {
- int cdemuid = GET_GLOBAL(cdemu_driveid);
+ // Access to an emulated drive.
+ struct drive_s *cdemu = GET_GLOBAL(cdemu_drive);
if (regs->ah > 0x16) {
// Only old-style commands supported.
- disk_13XX(regs, cdemuid);
+ disk_13XX(regs, cdemu);
return;
}
- disk_13(regs, cdemuid);
+ disk_13(regs, cdemu);
return;
}
if (extdrive < EXTSTART_CD && ((emudrive ^ extdrive) & 0x80) == 0)
+ // Adjust id to make room for emulated drive.
extdrive--;
}
}
diff --git a/src/disk.h b/src/disk.h
index 28aeda31..832bf9b4 100644
--- a/src/disk.h
+++ b/src/disk.h
@@ -144,8 +144,8 @@ struct mbr_s {
struct disk_op_s {
u64 lba;
void *buf_fl;
+ struct drive_s *drive_g;
u16 count;
- u8 driveid;
u8 command;
};
@@ -225,11 +225,13 @@ struct drives_s {
// block.c
extern struct drives_s Drives;
-void setup_translation(int driveid);
-void map_floppy_drive(int driveid);
-void map_hd_drive(int driveid);
-void map_cd_drive(int driveid);
-void describe_drive(int driveid);
+struct drive_s *getDrive(u8 exttype, u8 extdriveoffset);
+struct drive_s *allocDrive();
+void setup_translation(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);
+void describe_drive(struct drive_s *drive_g);
int process_op(struct disk_op_s *op);
int send_disk_op(struct disk_op_s *op);
void drive_setup();
@@ -237,21 +239,21 @@ void drive_setup();
// floppy.c
extern struct floppy_ext_dbt_s diskette_param_table2;
void floppy_setup();
-int addFloppy(int floppyid, int ftype, int driver);
-void describe_floppy(int driveid);
+struct drive_s *addFloppy(int floppyid, int ftype, int driver);
+void describe_floppy(struct drive_s *drive_g);
int find_floppy_type(u32 size);
int process_floppy_op(struct disk_op_s *op);
void floppy_tick();
// cdrom.c
-extern int cdemu_driveid;
+extern struct drive_s *cdemu_drive;
int process_cdemu_op(struct disk_op_s *op);
void cdemu_setup();
void cdemu_134b(struct bregs *regs);
int cdrom_boot(int cdid);
// ramdisk.c
-void describe_ramdisk(int driveid);
+void describe_ramdisk(struct drive_s *drive_g);
void ramdisk_setup();
int process_ramdisk_op(struct disk_op_s *op);
diff --git a/src/floppy.c b/src/floppy.c
index ad7aa7f1..311fc4b3 100644
--- a/src/floppy.c
+++ b/src/floppy.c
@@ -88,36 +88,34 @@ struct floppyinfo_s FloppyInfo[] VAR16VISIBLE = {
{ {2, 40, 8}, 0x00, 0x27},
};
-int
+struct drive_s *
addFloppy(int floppyid, int ftype, int driver)
{
if (ftype <= 0 || ftype >= ARRAY_SIZE(FloppyInfo)) {
dprintf(1, "Bad floppy type %d\n", ftype);
- return -1;
+ return NULL;
}
- int driveid = Drives.drivecount;
- if (driveid >= ARRAY_SIZE(Drives.drives))
- return -1;
- Drives.drivecount++;
- memset(&Drives.drives[driveid], 0, sizeof(Drives.drives[0]));
- Drives.drives[driveid].cntl_id = floppyid;
- Drives.drives[driveid].type = driver;
- Drives.drives[driveid].blksize = DISK_SECTOR_SIZE;
- Drives.drives[driveid].floppy_type = ftype;
- Drives.drives[driveid].sectors = (u64)-1;
-
- memcpy(&Drives.drives[driveid].lchs, &FloppyInfo[ftype].chs
+ struct drive_s *drive_g = allocDrive();
+ if (!drive_g)
+ return NULL;
+ drive_g->cntl_id = floppyid;
+ drive_g->type = driver;
+ drive_g->blksize = DISK_SECTOR_SIZE;
+ drive_g->floppy_type = ftype;
+ drive_g->sectors = (u64)-1;
+
+ memcpy(&drive_g->lchs, &FloppyInfo[ftype].chs
, sizeof(FloppyInfo[ftype].chs));
- map_floppy_drive(driveid);
- return driveid;
+ map_floppy_drive(drive_g);
+ return drive_g;
}
void
-describe_floppy(int driveid)
+describe_floppy(struct drive_s *drive_g)
{
- printf("drive %c", 'A' + Drives.drives[driveid].cntl_id);
+ printf("drive %c", 'A' + drive_g->cntl_id);
}
void
@@ -316,7 +314,7 @@ floppy_drive_recal(u8 floppyid)
}
static int
-floppy_media_sense(u8 driveid)
+floppy_media_sense(struct drive_s *drive_g)
{
// for now cheat and get drive type from CMOS,
// assume media is same as drive type
@@ -349,18 +347,18 @@ floppy_media_sense(u8 driveid)
// 110 reserved
// 111 all other formats/drives
- u8 ftype = GET_GLOBAL(Drives.drives[driveid].floppy_type);
+ u8 ftype = GET_GLOBAL(drive_g->floppy_type);
SET_BDA(floppy_last_data_rate, GET_GLOBAL(FloppyInfo[ftype].config_data));
- u8 floppyid = GET_GLOBAL(Drives.drives[driveid].cntl_id);
+ u8 floppyid = GET_GLOBAL(drive_g->cntl_id);
SET_BDA(floppy_media_state[floppyid]
, GET_GLOBAL(FloppyInfo[ftype].media_state));
return DISK_RET_SUCCESS;
}
static int
-check_recal_drive(u8 driveid)
+check_recal_drive(struct drive_s *drive_g)
{
- u8 floppyid = GET_GLOBAL(Drives.drives[driveid].cntl_id);
+ u8 floppyid = GET_GLOBAL(drive_g->cntl_id);
if ((GET_BDA(floppy_recalibration_status) & (1<<floppyid))
&& (GET_BDA(floppy_media_state[floppyid]) & FMS_MEDIA_DRIVE_ESTABLISHED))
// Media is known.
@@ -370,7 +368,7 @@ check_recal_drive(u8 driveid)
floppy_drive_recal(floppyid);
// Sense media.
- return floppy_media_sense(driveid);
+ return floppy_media_sense(drive_g);
}
@@ -382,14 +380,13 @@ static void
lba2chs(struct disk_op_s *op, u8 *track, u8 *sector, u8 *head)
{
u32 lba = op->lba;
- u8 driveid = op->driveid;
u32 tmp = lba + 1;
- u16 nlspt = GET_GLOBAL(Drives.drives[driveid].lchs.spt);
+ u16 nlspt = GET_GLOBAL(op->drive_g->lchs.spt);
*sector = tmp % nlspt;
tmp /= nlspt;
- u16 nlh = GET_GLOBAL(Drives.drives[driveid].lchs.heads);
+ u16 nlh = GET_GLOBAL(op->drive_g->lchs.heads);
*head = tmp % nlh;
tmp /= nlh;
@@ -400,7 +397,7 @@ lba2chs(struct disk_op_s *op, u8 *track, u8 *sector, u8 *head)
static int
floppy_reset(struct disk_op_s *op)
{
- u8 floppyid = GET_GLOBAL(Drives.drives[op->driveid].cntl_id);
+ u8 floppyid = GET_GLOBAL(op->drive_g->cntl_id);
set_diskette_current_cyl(floppyid, 0); // current cylinder
return DISK_RET_SUCCESS;
}
@@ -409,7 +406,7 @@ floppy_reset(struct disk_op_s *op)
static int
floppy_read(struct disk_op_s *op)
{
- int res = check_recal_drive(op->driveid);
+ int res = check_recal_drive(op->drive_g);
if (res)
goto fail;
@@ -417,7 +414,7 @@ floppy_read(struct disk_op_s *op)
lba2chs(op, &track, &sector, &head);
// send read-normal-data command (9 bytes) to controller
- u8 floppyid = GET_GLOBAL(Drives.drives[op->driveid].cntl_id);
+ u8 floppyid = GET_GLOBAL(op->drive_g->cntl_id);
u8 data[12];
data[0] = 0xe6; // e6: read normal data
data[1] = (head << 2) | floppyid; // HD DR1 DR2
@@ -450,7 +447,7 @@ fail:
static int
floppy_write(struct disk_op_s *op)
{
- int res = check_recal_drive(op->driveid);
+ int res = check_recal_drive(op->drive_g);
if (res)
goto fail;
@@ -458,7 +455,7 @@ floppy_write(struct disk_op_s *op)
lba2chs(op, &track, &sector, &head);
// send write-normal-data command (9 bytes) to controller
- u8 floppyid = GET_GLOBAL(Drives.drives[op->driveid].cntl_id);
+ u8 floppyid = GET_GLOBAL(op->drive_g->cntl_id);
u8 data[12];
data[0] = 0xc5; // c5: write normal data
data[1] = (head << 2) | floppyid; // HD DR1 DR2
@@ -494,7 +491,7 @@ fail:
static int
floppy_verify(struct disk_op_s *op)
{
- int res = check_recal_drive(op->driveid);
+ int res = check_recal_drive(op->drive_g);
if (res)
goto fail;
@@ -502,7 +499,7 @@ floppy_verify(struct disk_op_s *op)
lba2chs(op, &track, &sector, &head);
// ??? should track be new val from return_status[3] ?
- u8 floppyid = GET_GLOBAL(Drives.drives[op->driveid].cntl_id);
+ u8 floppyid = GET_GLOBAL(op->drive_g->cntl_id);
set_diskette_current_cyl(floppyid, track);
return DISK_RET_SUCCESS;
fail:
@@ -514,14 +511,14 @@ fail:
static int
floppy_format(struct disk_op_s *op)
{
- int ret = check_recal_drive(op->driveid);
+ int ret = check_recal_drive(op->drive_g);
if (ret)
return ret;
u8 head = op->lba;
// send format-track command (6 bytes) to controller
- u8 floppyid = GET_GLOBAL(Drives.drives[op->driveid].cntl_id);
+ u8 floppyid = GET_GLOBAL(op->drive_g->cntl_id);
u8 data[12];
data[0] = 0x4d; // 4d: format track
data[1] = (head << 2) | floppyid; // HD DR1 DR2
diff --git a/src/ramdisk.c b/src/ramdisk.c
index 36b9f226..c1e0b8af 100644
--- a/src/ramdisk.c
+++ b/src/ramdisk.c
@@ -11,9 +11,9 @@
#include "bregs.h" // struct bregs
void
-describe_ramdisk(int driveid)
+describe_ramdisk(struct drive_s *drive_g)
{
- printf("%s", Drives.drives[driveid].model);
+ printf("%s", drive_g->model);
}
void
@@ -47,16 +47,15 @@ ramdisk_setup()
// Setup driver.
dprintf(1, "Mapping CBFS floppy %s to addr %p\n", cbfs_filename(file), pos);
- int driveid = addFloppy((u32)pos, ftype, DTYPE_RAMDISK);
- if (driveid >= 0)
- strtcpy(Drives.drives[driveid].model, cbfs_filename(file)
- , ARRAY_SIZE(Drives.drives[driveid].model));
+ struct drive_s *drive_g = addFloppy((u32)pos, ftype, DTYPE_RAMDISK);
+ if (drive_g)
+ strtcpy(drive_g->model, cbfs_filename(file), ARRAY_SIZE(drive_g->model));
}
static int
ramdisk_copy(struct disk_op_s *op, int iswrite)
{
- u32 offset = GET_GLOBAL(Drives.drives[op->driveid].cntl_id);
+ u32 offset = GET_GLOBAL(op->drive_g->cntl_id);
offset += (u32)op->lba * DISK_SECTOR_SIZE;
u64 opd = GDT_DATA | GDT_LIMIT(0xfffff) | GDT_BASE((u32)op->buf_fl);
u64 ramd = GDT_DATA | GDT_LIMIT(0xfffff) | GDT_BASE(offset);