|
|
— |
blog:pushbx:2024:0602_barely_any_work_in_the_may_june_week [2024-06-02 19:18:26 +0200 Jun Sun] (current) ecm created |
| ====== Barely any work in the May June week ====== |
| |
| |
| **2024-06-02** |
| |
| ===== lDebug ===== |
| |
| The chstool Extension for lDebug [[https://hg.pushbx.org/ecm/ldebug/rev/a4927b1a25cc|gained a new mode]], ''CHSTOOL GEOMETRY unit'', which just initialises a unit and displays the detected amount of Heads and Sectors (in hexadecimal and decimal). |
| |
| [[https://hg.pushbx.org/ecm/ldebug/rev/91729104bdbc|The manual was updated]] with some comments on boot load protocol compatibility. |
| |
| **ETA**: [[https://hg.pushbx.org/ecm/ldebug/rev/490d2c31005b|The chstool.eld will now use BOOTUNITFLxx variables]] to force diskette geometry or LBA versus CHS. |
| |
| |
| ===== lDOS FAT32 boot sector loader for FreeDOS ===== |
| |
| [[https://sourceforge.net/p/freedos/mailman/message/58778839/|It was mentioned on the FreeDOS mailing lists]] that FreeDOS SYS may install the wrong FAT32 loader, one of which only supports LBA operation and the other one only CHS operation. The lDOS loader was suggested as an alternative. |
| |
| |
| ==== How to build ==== |
| |
| The lDOS boot loader for FAT32 is [[https://hg.pushbx.org/ecm/ldosboot/file/b54b87601845/boot32.asm|contained in the boot32.asm file]]. Assembling this (with an include path [[https://hg.pushbx.org/ecm/lmacros/|for lmacros]]) results in a 1024-byte file. The first 512 bytes contain the first stage. The second half contains the second stage, called FSIBOOT. The second stage must be installed into the FSINFO sector of the file system. Therefore, the FS must have an FSINFO sector. |
| |
| When the loader is built [[https://hg.pushbx.org/ecm/ldosboot/file/b54b87601845/boot32.asm#l124|with the _COMPAT_FREEDOS define enabled]], the default kernel filename is set to KERNEL.SYS and the first stage will include relocation so as to allow loading a kernel file to linear 00600h even if it exceeds 29 KiB in size. |
| |
| |
| ==== The stages ==== |
| |
| The first stage always includes a read sector function and error handling. The lDOS boot sector loader error handling, however, is limited to displaying a single letter on errors. This is R for sector read errors, M for out of memory, E for not enough file data, V for check value mismatch (not used by FreeDOS load), F for file not found, B for bad chain or file system, or I for FSIBOOT not found or mismatch. |
| |
| The FSIBOOT stage, in its current protocol revision of FSIBOOT4, contains code to access the FAT one sector at a time, the root directory likewise, and to load the first kernel file into available memory. FSIBOOT4 is unchanged regardless of the compatibility set selected at build time, so an RxDOS.3, lDebug, or lDOS loader can use the same FSIBOOT4 stage as a FreeDOS loader. Only the first stage changes depending on options. |
| |
| |
| ==== LBA detection ==== |
| |
| The _COMPAT_FREEDOS build of the first stage is actually small enough to also use _LBA_SKIP_CHECK=0. If the LBA skip check option is enabled (default) then the loader will try interrupt 13h function 42h (LBA read) unconditionally, and if an error is returned fall back to function 02h (CHS read). If LBA skip check is disabled, the proper LBA check using function 41h is used (ah=41h, bx=55AAh, dl=drive, cx=0010h (low bit clear), CY, al and dh unknown). |
| |
| Note that the boot sector loader's LBA check does not include the Xi8088 BIOS bug workaround of setting ds=40h. This is due to the space constraints. To disable the LBA use (including the function 41h check if _LBA_SKIP_CHECK=0) use the instsect switch ''/L NONE''. |
| |
| |
| ==== instsect ==== |
| |
| The instsect program is used to install a boot sector loader. [[https://pushbx.org/ecm/download/ldebug.zip|The daily lDebug builds]] include a pre-built instsect.com executable. Although this executable contains an lDOS/lDebug loader, a file may be specified to it using the /S= or /S32= switches. |
| |
| If the file is 1024 bytes in size, it is assumed that the second half contains an lDOS style FSIBOOT stage to install into the FSINFO sector. The first stage is installed as usual. There are some switches to allow modifying some extended features of the lDOS style loaders: |
| |
| * ''/P NONE'' to disable partition start sector (hidden sectors) detection. |
| |
| With this disabled, the loader acts like most loaders, requiring the correct hidden sectors be hardcoded into the sector. With the detection enabled (''/P AUTO'') the loader tries to detect the hidden sectors passed by an MBR loader that ran before it. This detection is imperfect however, so disabling it with ''/P NONE'' may be needed. |
| |
| |
| * ''/Q NONE'' to disable CHS geometry detection |
| |
| With this disabled, the loader acts like most loaders, requiring the CHS heads and CHS sectors fields in the boot sector to be set correctly (if CHS access is used). With the detection enabled, the loader tries to query the geometry using interrupt 13h function 08h, with some safeguards to insure valid values are returned by this function. Using ''/Q NONE'' should not be needed usually, except if the ROM-BIOS returns a wrong geometry that cannot be used successfully to read off the unit. |
| |
| |
| * ''/U 80'' to hardcode the boot load unit (eg as 80h, first hard disk) rather than using the value passed by the prior loader in DL |
| |
| May be needed if the prior loader is defective. This option can be used to patch the original FreeDOS loaders as well. |
| |
| |
| * ''/L NONE'' to disable LBA access and always fall back to CHS access |
| |
| This is only available if both access modes are supported by a loader. Can be used to patch the original FreeDOS loaders for FAT12 and FAT16 as well. |
| |
| |
| * ''/G AUTO'' to query the DOS for hidden sectors and CHS geometry during installation. This may or may not be useful. |
| |
| * ''/G HEADS='' to hardcode a certain CHS Heads geometry |
| |
| * ''/G SECTORS='' to hardcode a certain CHS Sectors geometry |
| |
| * ''/G HIDDEN='' to hardcode a certain hidden sectors value |
| |
| Note that the /G values are only used when partition info detection fails or is disabled (''/P NONE'') respectively when query geometry detection fails or is disabled (''/Q NONE''). |
| |
| |
| * ''/F=name'' to patch the first detected filename in the sector |
| |
| This can be used to load different files if they are compatible to the same protocol as the loader being used. For instance, ''/F=metakern.sys'' can be used to modify a FreeDOS-compatible loader (either original FreeDOS or lDOS-style in FreeDOS compatibility) to load a MetaKern kernel file rather than the default of KERNEL.SYS. When patching filenames instsect will display the detected and patched filenames during its run. |
| |
| |
| ==== Why two stages? ==== |
| |
| The lDOS dual-stage FAT32 + FSIBOOT loader was designed to support all desired features of a loader. It enables LBA or CHS access, can detect hidden sectors and query CHS geometry, will work on any 8086-compatible CPU, and has enough space that no option needs to be disabled to enable the FreeDOS compatibility of the loader. |
| |
| However, this design does have its drawbacks. It requires an FSINFO sector be used. And the installation of the loader is more complicated. Also, different versions of FSIBOOT cannot be used at the same time. (For instance, the latest RxDOS builds still use an older FSIBOOT version, FSIBOOT2. By updating the loader, RXDOS.COM can also be loaded using FSIBOOT4 however.) |
| |
| |
| ==== Patch to not use FSINFO sector's FSIBOOT ==== |
| |
| [[https://github.com/FDOS/kernel/issues/50#issuecomment-1950221747|In a discussion on booting kernels using lDebug]] and in turn booting lDebug itself, I suggested a Script for lDebug that allows to chainload a 1024-byte file that includes an FSIBOOT stage without depending on the FSINFO sector of the actual file system: |
| |
| <blockquote>You do need FSIBOOT to run the boot32 loader. However, the loader's first stage expects to find its FSIBOOT in the actual file system FSINFO, not chainloaded behind it. The defaults for /I (''/IS /IR /IV'') will install to the FSINFO sector, even if you use /B=. |
| |
| Albeit, if GRUB4DOS chainloads the entire 1024 Bytes file as created with ''/IB'' then you can patch the first stage in a small way. This will make it so the first stage finds FSIBOOT **only** when the entire file is chainloaded and never tries to load it from the FS. Save this [[https://pushbx.org/ecm/test/20240217/patchfsi.sld|in the file patchfsi.sld]]: |
| |
| <code>@r ysf |= 4000 |
| a ss:sp - 10 |
| cmp ax, 20 |
| jae (sp) |
| . |
| s cs:ip l 200 range ss:sp - 10 aao - 2 |
| if (src == 1) then goto :found |
| if (src == 0) then goto :notfound |
| r ysf clr= 4000 |
| ; Error: Multiple patch sites found |
| @goto :eof |
| |
| :notfound |
| a ss:sp - 10 |
| cmp ax, 20 |
| jmp short (sp) |
| . |
| s cs:ip l 200 range ss:sp - 10 aao - 2 |
| if (src == 1) then goto :alreadypatched |
| if (src == 0) then goto :notfound2 |
| r ysf clr= 4000 |
| ; Error: Multiple already patched patch sites found |
| @goto :eof |
| |
| :notfound2 |
| r ysf clr= 4000 |
| ; Patch site not found |
| @goto :eof |
| |
| :alreadypatched |
| r ysf clr= 4000 |
| ; Patch site found, but is already patched |
| @goto :eof |
| |
| :found |
| a srs:sro |
| cmp ax, 20 |
| db EB |
| . |
| r ysf clr= 4000 |
| ; File patched, don't forget to run W command</code> |
| |
| Then run: |
| |
| <code>ldebug bootinfo.bin |
| y patchfsi.sld |
| w |
| q</code> |
| |
| </blockquote> |
| |
| |
| ==== Another ad for the FAT32 + FSIBOOT loader ==== |
| |
| [[https://github.com/FDOS/kernel/issues/139#issuecomment-1951436341|In another FreeDOS kernel issue]] I also explained some of the lDOS loaders' design: |
| |
| <blockquote> |
| |
| <blockquote>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</blockquote> |
| |
| [[https://hg.pushbx.org/ecm/ldosboot/file/1794893b35e6/boot32.asm|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 [[https://pushbx.org/ecm/doc/ldosboot.htm#protocol-sector-freedos|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.</blockquote> |
| |
| |
| {{tag>ldebug eld ldosboot boot32 freedos sys}} |
| |
| |
| ~~DISCUSSION~~ |
| |