diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2009-02-07 00:04:57 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2009-02-07 00:04:57 -0500 |
commit | 95827c4460a6887b61b45ccb3771ebd5a8713c09 (patch) | |
tree | 087b46209aad0b14cd1f49ad55056210e1f29e03 /src | |
parent | 5eac1ddafa2b1efd1f10547e2306540fc995e23d (diff) | |
download | seabios-hppa-95827c4460a6887b61b45ccb3771ebd5a8713c09.zip seabios-hppa-95827c4460a6887b61b45ccb3771ebd5a8713c09.tar.gz seabios-hppa-95827c4460a6887b61b45ccb3771ebd5a8713c09.tar.bz2 |
Introduce MBR struct; simplify cdrom emulation code.
Define and use a struct for the master boot record.
Simplify cdrom emulation chs setting code.
Fix an apparent bug in harddrive chs setting - it wasn't properly
masking the spt/cyl fields.
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.c | 3 | ||||
-rw-r--r-- | src/cdrom.c | 54 | ||||
-rw-r--r-- | src/disk.h | 34 |
3 files changed, 63 insertions, 28 deletions
@@ -130,7 +130,8 @@ try_boot(u16 seq_nr) /* Always check the signature on a HDD boot sector; on FDD, * only do the check if configured for it */ if (type != IPL_TYPE_FLOPPY || IPL.checkfloppysig) { - if (GET_FARVAR(bootseg, *(u16*)0x1fe) != 0xaa55) { + struct mbr_s *mbr = (void*)0; + if (GET_FARVAR(bootseg, mbr->signature) != MBR_SIGNATURE) { print_boot_failure(type, 0); return; } diff --git a/src/cdrom.c b/src/cdrom.c index fdef873..389a42e 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -519,38 +519,38 @@ cdrom_boot() // Floppy emulation SET_EBDA2(ebda_seg, cdemu.emulated_drive, 0x00); SETBITS_BDA(equipment_list_flags, 0x41); + + switch (media) { + case 0x01: // 1.2M floppy + SET_EBDA2(ebda_seg, cdemu.spt, 15); + SET_EBDA2(ebda_seg, cdemu.cylinders, 80); + SET_EBDA2(ebda_seg, cdemu.heads, 2); + break; + case 0x02: // 1.44M floppy + SET_EBDA2(ebda_seg, cdemu.spt, 18); + SET_EBDA2(ebda_seg, cdemu.cylinders, 80); + SET_EBDA2(ebda_seg, cdemu.heads, 2); + break; + case 0x03: // 2.88M floppy + SET_EBDA2(ebda_seg, cdemu.spt, 36); + SET_EBDA2(ebda_seg, cdemu.cylinders, 80); + SET_EBDA2(ebda_seg, cdemu.heads, 2); + break; + } } else { // Harddrive emulation SET_EBDA2(ebda_seg, cdemu.emulated_drive, 0x80); SET_BDA(hdcount, GET_BDA(hdcount) + 1); - } - // Remember the media type - switch (media) { - case 0x01: // 1.2M floppy - SET_EBDA2(ebda_seg, cdemu.spt, 15); - SET_EBDA2(ebda_seg, cdemu.cylinders, 80); - SET_EBDA2(ebda_seg, cdemu.heads, 2); - break; - case 0x02: // 1.44M floppy - SET_EBDA2(ebda_seg, cdemu.spt, 18); - SET_EBDA2(ebda_seg, cdemu.cylinders, 80); - SET_EBDA2(ebda_seg, cdemu.heads, 2); - break; - case 0x03: // 2.88M floppy - SET_EBDA2(ebda_seg, cdemu.spt, 36); - SET_EBDA2(ebda_seg, cdemu.cylinders, 80); - SET_EBDA2(ebda_seg, cdemu.heads, 2); - break; - case 0x04: { // Harddrive - u16 spt = GET_FARVAR(boot_segment,*(u8*)(446+6)); - u16 cyl = (spt << 2) + GET_FARVAR(boot_segment,*(u8*)(446+7)) + 1; - u16 heads = GET_FARVAR(boot_segment,*(u8*)(446+5)) + 1; - SET_EBDA2(ebda_seg, cdemu.spt, spt & 0x3f); - SET_EBDA2(ebda_seg, cdemu.cylinders, cyl); - SET_EBDA2(ebda_seg, cdemu.heads, heads); - break; - } + // Peak at partition table to get chs. + struct mbr_s *mbr = (void*)0; + u8 sptcyl = GET_FARVAR(boot_segment, mbr->partitions[0].last.sptcyl); + u8 cyllow = GET_FARVAR(boot_segment, mbr->partitions[0].last.cyllow); + u8 heads = GET_FARVAR(boot_segment, mbr->partitions[0].last.heads); + + SET_EBDA2(ebda_seg, cdemu.spt, sptcyl & 0x3f); + SET_EBDA2(ebda_seg, cdemu.cylinders, ((sptcyl<<2)&0x300) + cyllow + 1); + SET_EBDA2(ebda_seg, cdemu.heads, heads + 1); } // everything is ok, so from now on, the emulation is active @@ -104,6 +104,40 @@ void __disk_ret(struct bregs *regs, u32 linecode, const char *fname); /**************************************************************** + * 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 ****************************************************************/ |