SolraBizna / j6502

Cycle-accurate W65C02 emulator in Java
Other
2 stars 1 forks source link

Use more traditional unmanaged drive booting method for BIOS #1

Closed atirut-w closed 2 years ago

atirut-w commented 2 years ago

I am making an OS and one thing I need is a drive that's bootable and have a filesystem on it. The CAB specifications for unmanaged drives makes it awkward since the OCMOS BIOS does not support offset address. This means there will be a lot of spaces unused(sector 1 exclusively for CAB records and every records needing a separate sector). It also means determining where the filesystem stuff start is complicated.

I think a better and more traditional approach would be how most BIOS boots a drive: load first sector into RAM and jump to it. MBR partitioning scheme does this, and even non-partitioned drives can be booted this way provided the filesystem specs leave some room for bootstrap code(e..g FAT).

To address checking if a drive is bootable. the simplest way would also be something similar to MBR and FAT: checking the last two bytes of the first sector for a signature.

SolraBizna commented 2 years ago

Wasting one or two sectors is really common when dealing with partition schemes and bootloaders. Modern partitioning utilities which align partitions to 2MiB boundaries will waste over 4,000 sectors, which bothers me to no end.

It's been a really long time since I worked on any of this, and I won't be able to do any more. All other issues aside, Microsoft is withholding access to my Minecraft account, so I can't ever play Minecraft again. The only thing I can really do is shake the rot out of the OCMOS BIOS build script so that it works with recent builds of WLA-DX (which I've now done).

It would be pretty easy to modify the OCMOS BIOS to boot an MBR-style boot sector instead of CAB. Specifically, I believe only this function would need to be changed. But, based on scanning the source code, it seems that CAB was designed such that the first CAB sector can either be the first or the second sector on the drive, so you could put a partition table or filesystem superblock in the first sector while still using CAB to boot from the second (and third?) sectors.

SolraBizna commented 2 years ago

Thinking on it a bit more, I remember that one of the use cases for CAB was booting from a specific file on a filesystem. The boot code would be put into the filesystem like any other file, then, in a separate "blessing" step, a CAB header would be written to the disk, indicating the sectors occupied by the boot code file. This CAB header then fits nicely where a normal boot sector would go. A bonus of this approach is that the same filesystem could, in theory, be "blessed" to be bootable from more than one architecture, with different files providing the necessary boot code for each different architecture.

atirut-w commented 2 years ago

A custom BIOS will do ig. Not like that it's super important for me to boot from unmanaged drives anyway and the standard BIOS is pretty good for simple debugging.