FDOS / kernel

FreeDOS kernel - implements the core MS-DOS/PC-DOS (R) compatible operating system. It is derived from Pat Villani's DOS-C kernel and released under the GPL v2 or later. Please see http://www.freedos.org/ for more details about the FreeDOS (TM) Project.
http://kernel.fdos.org/
GNU General Public License v2.0
786 stars 142 forks source link

sys and boot sector improvements [TODO] #139

Open PerditionC opened 7 months ago

PerditionC commented 7 months ago
          Not yet included:

Originally posted by @ecm-pushbx in https://github.com/FDOS/kernel/issues/135#issuecomment-1931021708

PerditionC commented 7 months ago
PerditionC commented 7 months ago

merge all changes from kernel sys and boot sectors into sys repo and then make it a submodule of the kernel like share, etc.

ecm-pushbx commented 7 months ago
  • update sys and boot code so sys can extract all necessary offsets without hard coding, possibly by scanning for magic bytes or having the boot sectors have an additional trailer chunk

The current 512-Bytes files per boot sector loader are more compatible and easier to use for other programs, eg my instsect or with dd to write to an image. Albeit, it would be a nice(r) approach to append some trailer. I also did this in https://github.com/FDOS/kernel/pull/78 for the new exeflat stubs, the stubs have trailing data to point exeflat to where to patch them. But in that case there was no compatibility with other programs to consider.

The unit selection code (/FORCE:BSDRV or /FORCE:BIOSDRV) can be scanned very easily, I do that in instsect already. The FAT12/FAT16 LBA detection (/FORCE:LBA or /FORCE:CHS or /FORCE:AUTO) is also easily scanned.

The loadsegoff is fairly simple to scan for too, just check for a dword matching 60_0000h or 70_0000h and also you can check that there is a jmp far indirect that references the same dword. The check for segment 70h is for boot sector loaders that are modified with the EDR-DOS SYS/boot patches, which changed the default segment too. Eg in https://pushbx.org/ecm/download/edrdos/freedos/drsys35s.zip boot.asm and boot32.asm have the default segment as 70h, but not boot32lb.asm. (It doesn't really matter to SYS because it writes opts->kernel.loadaddr to the variable unconditionally.)

In the OEM boot sector loaders, just scanning for jmp 70h:0 or jmp 70h:200h should be sufficient to find the far branch to the next stage.

The kernel name is okay to leave as a magic offset I think. In instsect I chose to scan for potentially multiple filenames (up to 4 are supported by default) just using a heuristic for valid filenames, which works nicely, but isn't really needed for SYS.

  • see if possible to update FAT32 boot code to support both LBA and CHS with same boot sector, may require using more than one sector

lDOS boot32 does this, it is a combined LBA and CHS, 8086-clean loader. It uses its "FSIBOOT4" stage in the FSINFO sector's large reserved area, which I believe has never been used by anyone else. The current revision has a _COMPAT_FREEDOS mode which allows to load kernel.sys. The addressing and relocation differs from the kernel's current loaders, but the protocol matches what I consider essential to FreeDOS load. The exact same FSIBOOT4 stage can be used by different loader first stages, to load RxDOS.3, lDOS/lDebug, MS-DOS v7.10, or PC-DOS v7.10, all changes for these protocols are confined to the first stage. That includes the addresses to load at and transfer control to, as well as the filenames to search for.

ecm-pushbx commented 7 months ago

Ah, I think in the PR I forgot that not all of the boot loader sources use the appropriate cpu 8086 or cpu 386 NASM directives. So add that to the pile.

ecm-pushbx commented 7 months ago

Also relevant: https://github.com/FDOS/kernel/issues/94