Comment by fuzzfactor
1 day ago
Final thoughts, I would try this:
Start with a zeroed SSD, open it in DMDE, hit Editor > Partition Table and there is nothing but zeros as expected. Type in this, analogously to the above:
80 0E 0 32 33 4 52 48 2048 65536
Also manually put the required AA55 signature at the final 2 bytes. Apply Changes. You have just partitioned it a very mainstream way.
The Relative Sector value shown is supposed to be incorporated into the bootsector at that position as the Hidden Sector offset, which it uses to find its way into the filesystem.
Therefore ideally after you copy the IMG to the SSD starting at sector 2048 (rather than starting at the now-proven, wonderful sector 0), it would be like any other OS on any other partition, with your functional bootsector right there on 2048 where the partition table expects it to be, the only thing to change is your original "Hidden Sectors" of 0 so that is what to edit.
In DMDE Partition Table view, double click on the 80 0E...2048... line and it will take you to sector 2048 as expected, plus autointerpret it as a bootsector, displaying the correct template for FAT bootsectors.
Edit > Edit Mode and where it says Hidden Sectors 0, carefully change that to 2048. Drive Number is supposed to be 80 most of the time too. Apply Changes. The partition should be self-contained now. All you should need to do is boot to it.
You will still need a Master Boot Record (MBR) within the first 440 bytes of sector 0 as usual, which can interpret the partition table and jump to the designated Active partition whose bootsector at 2048 will take over from there. Regardless of whether the OS was originally "installed" to a volume starting at 2048, it needs to be able to work after recovery to a different sized volume which starts at something different like sector 512000 for instance some other time too.
I copy a current MBR from a working bootable MBR-layout USB, bytes 0-439 to the SSD.
And we're off to the races on a real partition.
The success was however, limited. After choosing a resolution, no more display :(
There is mostly no code yet in the 65535-sector 32mb volume, only sectors 0 - 3097 in this IMG are nonzero so far. This is normal at this scale.
Getting it going does seem to depend on specific code always existing somewhere in sectors 1 - 3097 rather than the OS relying on the Hidden Sectors offset within its own bootsector to find that same code located further beyond 2048. This is easy to have happen since hidden sectors has always been zero. VMs tend to abstract this since they are not on real partitions, and they don't always want to make it easy to move to bare metal anyway.
However there is really nothing wrong if the specific bootloader for this OS is permanently stored outside the filesystem at this time and/or at a hard-coded address for the time being, Grub did that sometimes so it would be outside the filesystem and not touched by DOS or Windows normally. I wanted to see if the OS itself can be easily relocated as an IMG to any partition within reach of FAT16. Formatted or not the IMG will overwrite what was there so you get your familiar format parameters and the only thing you're supposed to need to edit is the hidden sectors to match where the partition actually starts when it is different than original. But that didn't quite do it.
So next, additionally copied IMG sectors 1 - 2000 to the SSD starting at sector 1 of the SSD. (Didn't want to overwrite sector 0 with its new partiton table & MBR, nor the other good code now starting at 2048, which didn't leave enough room for all 3097 sectors of data in the IMG to fit in that space any more.) Incidentally, 3097 sectors is only about 1.5+ mb in the whole OS at this point, if it could be trimmed to 2880 sectors it would fit on a regular 1.44mb floppy. Partitons-R-not-us at all for that. Well, you've pretty much accomlished that and more on USB so it really is something to be proud of.
Sectors 1-2000 are completely outside the filesystem as I have it partitioned now.
Now it works, regular Windows MBR on sector 0 finds the Active partition like normal, jumps to 2048 as indicated by the partition table as expected, where it first encounters your bootsector/loader? code and proceeds nominally from there. No more failure of display. Any dependency on code being located in the original dev sectors 1-2000 is fulfilled now because a copy of it is there too, regardless of it being outside the current filesystem which now starts at 2048.
Appears to work with only sectors 1-1000 in place too. I would maybe leave the bootloader in that position and make sure the OS can do its thing starting at 2048 (everything relative to the hidden sectors value within your bootsector, at the time) without relying on any sectors below 2048 after the kernel has loaded.
At this point I should be able to reformat my FAT16 SSD partition using MS-DOS, which will not only clear off the RetrOS, but also rejigger the parameters seen on the template to be completely conventional, I would expect quite a bit different since yours are not very mainstream values. No problem if that's what your OS likes right now. Then I could easily copy io.sys, msdos.sys, and command.com (in that order can be best) to the freshly formatted partition and DOS would boot fine in its familiar landscape, never touching your code in sectors 1-1000 since that's not in the filesystem and not routinely accessed by DOS. When I was done with DOS, then I could copy your IMG back starting at 2048 again, and it would boot right up, without any experimentation, since the code it occasionally depends on is still there somewhere between 1-1000.
So you're ready to switch over to bare metal like this and tie up the loose ends in the real world!
In the long run you want your own simple bootloader to be a file on your filesystem that your bootsector simply seeks after the standard generic stuff jumps to your bootsector, and never depend on anything in earlier sectors than your bootsector after that.
Whatever OS you put on a partition, fundamentally it should be able to exist as just a bunch of stored files unless you boot to it.
Another milestone will be when you can just copy the files of your OS to a regular FAT16 volume that was formatted using MS-DOS itself. Do not skip this step. Even 20-year old Windows XP FAT16 is no substitute, and Linux is also non-ideal. Plus different sized partitions than 32mb will need to be taken in stride. The only thing that needs to be special is the bootsector itself, mainly the part that seeks your OS bootloader file specifically.
Use the mainstream old generic stuff to lead to your bootsector, use DMDE to craft a custom bootsector easily for any partition when needed without having to write your own Format routine, and concentrate on the OS functioning well within its own volume anywhere like the best of them!
I’m overwhelmed with the effort you put into making my OS run! I really appreciate it! Will take some time to through it all in detail. But a lot of the partitions and filesystem parts of the OS was simply to be able to mount the image in Linux and copy over files. Initially my OS and bootloader didn’t need partitions. As you noticed currently the kernel is not part of the filesystem, but is prepended. The entire partition / boot system is very shaky, so a lot more work will have to go into making it stable. Thanks again for all your comments and efforts. Will try to implement and research as much as possible of the parts you touched on! Thanks!