summaryrefslogtreecommitdiff
path: root/roms/seabios/src/cdrom.c
diff options
context:
space:
mode:
Diffstat (limited to 'roms/seabios/src/cdrom.c')
-rw-r--r--roms/seabios/src/cdrom.c98
1 files changed, 43 insertions, 55 deletions
diff --git a/roms/seabios/src/cdrom.c b/roms/seabios/src/cdrom.c
index 42d8e0818..811bef5b5 100644
--- a/roms/seabios/src/cdrom.c
+++ b/roms/seabios/src/cdrom.c
@@ -5,15 +5,19 @@
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "disk.h" // cdrom_13
-#include "util.h" // memset
-#include "bregs.h" // struct bregs
#include "biosvar.h" // GET_GLOBAL
-#include "ata.h" // ATA_CMD_REQUEST_SENSE
-#include "blockcmd.h" // CDB_CMD_REQUEST_SENSE
+#include "block.h" // struct drive_s
+#include "bregs.h" // struct bregs
+#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[CONFIG_MAX_EXTDRIVE] VARLOW;
+u8 CDRom_locks[BUILD_MAX_EXTDRIVE] VARLOW;
/****************************************************************
@@ -21,15 +25,14 @@ u8 CDRom_locks[CONFIG_MAX_EXTDRIVE] VARLOW;
****************************************************************/
struct cdemu_s CDEmu VARLOW;
-struct drive_s *cdemu_drive_gf VAR16VISIBLE;
+struct drive_s *cdemu_drive_gf VARFSEG;
static int
cdemu_read(struct disk_op_s *op)
{
- struct drive_s *drive_g;
- drive_g = GLOBALFLAT2GLOBAL(GET_LOW(CDEmu.emulated_drive_gf));
+ struct drive_s *drive_gf = GET_LOW(CDEmu.emulated_drive_gf);
struct disk_op_s dop;
- dop.drive_g = drive_g;
+ dop.drive_gf = drive_gf;
dop.command = op->command;
dop.lba = GET_LOW(CDEmu.ilba) + op->lba / 4;
@@ -107,43 +110,28 @@ process_cdemu_op(struct disk_op_s *op)
}
void
-cdemu_setup(void)
+cdrom_prepboot(void)
{
if (!CONFIG_CDROM_EMU)
return;
if (!CDCount)
return;
- if (bounce_buf_init() < 0)
+ if (create_bounce_buf() < 0)
return;
- struct drive_s *drive_g = malloc_fseg(sizeof(*drive_g));
- if (!drive_g) {
+ struct drive_s *drive = malloc_fseg(sizeof(*drive));
+ if (!drive) {
warn_noalloc();
- free(drive_g);
+ free(drive);
return;
}
- cdemu_drive_gf = drive_g;
- memset(drive_g, 0, sizeof(*drive_g));
- drive_g->type = DTYPE_CDEMU;
- drive_g->blksize = DISK_SECTOR_SIZE;
- drive_g->sectors = (u64)-1;
+ cdemu_drive_gf = drive;
+ memset(drive, 0, sizeof(*drive));
+ drive->type = DTYPE_CDEMU;
+ drive->blksize = DISK_SECTOR_SIZE;
+ drive->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))
@@ -165,9 +153,9 @@ cdemu_134b(struct bregs *regs)
SET_INT13ET(regs, buffer_segment, GET_LOW(CDEmu.buffer_segment));
SET_INT13ET(regs, load_segment, GET_LOW(CDEmu.load_segment));
SET_INT13ET(regs, sector_count, GET_LOW(CDEmu.sector_count));
- SET_INT13ET(regs, cylinders, GET_LOW(CDEmu.lchs.cylinders));
- SET_INT13ET(regs, sectors, GET_LOW(CDEmu.lchs.spt));
- SET_INT13ET(regs, heads, GET_LOW(CDEmu.lchs.heads));
+ SET_INT13ET(regs, cylinders, GET_LOW(CDEmu.lchs.cylinder));
+ SET_INT13ET(regs, sectors, GET_LOW(CDEmu.lchs.sector));
+ SET_INT13ET(regs, heads, GET_LOW(CDEmu.lchs.head));
// If we have to terminate emulation
if (regs->al == 0x00) {
@@ -186,14 +174,14 @@ cdemu_134b(struct bregs *regs)
****************************************************************/
int
-cdrom_boot(struct drive_s *drive_g)
+cdrom_boot(struct drive_s *drive)
{
ASSERT32FLAT();
struct disk_op_s dop;
- int cdid = getDriveId(EXTTYPE_CD, drive_g);
+ int cdid = getDriveId(EXTTYPE_CD, drive);
memset(&dop, 0, sizeof(dop));
- dop.drive_g = drive_g;
- if (!dop.drive_g || cdid < 0)
+ dop.drive_gf = drive;
+ if (!dop.drive_gf || cdid < 0)
return 1;
int ret = scsi_is_ready(&dop);
@@ -242,7 +230,7 @@ cdrom_boot(struct drive_s *drive_g)
u8 media = buffer[0x21];
CDEmu.media = media;
- CDEmu.emulated_drive_gf = dop.drive_g;
+ CDEmu.emulated_drive_gf = dop.drive_gf;
u16 boot_segment = *(u16*)&buffer[0x22];
if (!boot_segment)
@@ -284,19 +272,19 @@ cdrom_boot(struct drive_s *drive_g)
switch (media) {
case 0x01: // 1.2M floppy
- CDEmu.lchs.spt = 15;
- CDEmu.lchs.cylinders = 80;
- CDEmu.lchs.heads = 2;
+ CDEmu.lchs.sector = 15;
+ CDEmu.lchs.cylinder = 80;
+ CDEmu.lchs.head = 2;
break;
case 0x02: // 1.44M floppy
- CDEmu.lchs.spt = 18;
- CDEmu.lchs.cylinders = 80;
- CDEmu.lchs.heads = 2;
+ CDEmu.lchs.sector = 18;
+ CDEmu.lchs.cylinder = 80;
+ CDEmu.lchs.head = 2;
break;
case 0x03: // 2.88M floppy
- CDEmu.lchs.spt = 36;
- CDEmu.lchs.cylinders = 80;
- CDEmu.lchs.heads = 2;
+ CDEmu.lchs.sector = 36;
+ CDEmu.lchs.cylinder = 80;
+ CDEmu.lchs.head = 2;
break;
}
} else {
@@ -310,9 +298,9 @@ cdrom_boot(struct drive_s *drive_g)
u8 cyllow = GET_FARVAR(boot_segment, mbr->partitions[0].last.cyllow);
u8 heads = GET_FARVAR(boot_segment, mbr->partitions[0].last.heads);
- CDEmu.lchs.spt = sptcyl & 0x3f;
- CDEmu.lchs.cylinders = ((sptcyl<<2)&0x300) + cyllow + 1;
- CDEmu.lchs.heads = heads + 1;
+ CDEmu.lchs.sector = sptcyl & 0x3f;
+ CDEmu.lchs.cylinder = ((sptcyl<<2)&0x300) + cyllow + 1;
+ CDEmu.lchs.head = heads + 1;
}
// everything is ok, so from now on, the emulation is active