|
|
— |
blog:pushbx:2025:1017_looking_back_at_2017_s_iniload [2025-10-17 20:13:12 +0200 Oct Fri] (current) ecm created |
| ====== Looking back at 2017's iniload ====== |
| |
| The [[https://hg.pushbx.org/ecm/ldosboot.exp/file/36de8307b26a/iniload.asm|very first revision of iniload]] was checked into the repo on 2017-10-03 (the annual Tag der deutschen Einheit "day of german unity", a public holiday). |
| |
| It only supported MS-DOS v6 / IBM-DOS, MS-DOS v7, and lDOS load (all the ones requiring subsequent loading by the "msload" stage). The latter, lDOS load, still without the "lDXX" signature. (The signature was [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/37ef2ab9e35c|added on 2020-01-22]] and [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/3ff2399ef227|first checked the same day in boot.asm]] and [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/e9da7f87e713|likewise in boot32.asm]] and [[https://hg.pushbx.org/ecm/ldebug/rev/ed9a8c45fb76|by lDebug's loader]]. The signature was first set, to "lDeb" or "lDDb", [[https://hg.pushbx.org/ecm/ldebug/rev/afa0169eb960|for lDebug]] again the same day.) So loading it with ''boot protocol ldos'' in recent lDebug requires specifying ''checkvalue=0''. |
| |
| ===== ===== |
| |
| The structure is mostly the same as in the current revision, except for a few points. Of course, the FreeDOS ([[https://hg.pushbx.org/ecm/ldosboot.exp/rev/733ea517cb58|as of 2018-01-21]]) and Enhanced DR-DOS entrypoints ([[https://hg.pushbx.org/ecm/ldosboot.exp/rev/82071e8903ee|as of 2024-01-02]]) aren't there yet. An MS-DOS v1 (flat-format) application entrypoint ([[https://hg.pushbx.org/ecm/ldosboot.exp/rev/408cd08cb836|as of 2020-04-01]]) is also not yet included. The LBA check still occurs in read_sector for every call, rather than having it moved into query_geometry. (The move was initially ([[https://hg.pushbx.org/ecm/ldosboot.exp/rev/b9223d1925c1|on 2018-01-13]]), I presume, for performance of not calling 13.41 repeatedly, as well as to allow its results be manipulated with the query patch, which also only was added later.) Also, query_geometry is called in two spots, depending on whether the FS is FAT12 (which needs it called before reading the FAT) or not. (That was changed [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/4e8b1d4d7532|in this largely unrelated 2019-12-27 change]].) |
| |
| FAT32 support was there from the very beginning. However, if we try to boot this earliest revision off a FAT16 or FAT32 file system, one particularly critical bug rears its head. The FAT access didn't set es if the current FAT sector is already buffered. [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/8305221bf653|The fix followed on the same day]]. |
| |
| (As an aside, [[https://hg.pushbx.org/ecm/bootimg/rev/966f8a094eca|the first revision of bootimg]] was only created on 2019-07-26 so testing was more complicated back when iniload was first created. Likewise, [[https://hg.pushbx.org/ecm/instsect/rev/5e9d073cb5d0|the initial commit of instsect]] is only from 2018-02-24.) |
| |
| RPL memory size adjustment was supported, albeit [[https://hg.pushbx.org/ecm/ldosboot.exp/file/36de8307b26a/iniload.asm#l834|it expected ds to equal zero on entry]], which [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/ea8d8863bdf0|was fixed the same day too]]. |
| |
| The sector segment buffer was supported already, a good thing as even the early lDOS load protocol was expected to load the file at 00700h (with entry at 70h:400h). So with a file >= 64 KiB the 64 KiB ISA DMA boundary would be crossed by one of the reads. The sector segment buffer was only used upon detecting an error 09h from int 13h (which [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/b7f4779aedb5|was changed on 2025-10-12]]). |
| |
| Many of [[https://retrocomputing.stackexchange.com/questions/31106/what-is-this-freedos-kernel-loader-found-on-the-w3x4ntfs-disk-image|the error messages known from the modern iniload]] were already present, in ASCIZ format. (The [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/ac3cf0a4a638|change to dot-terminated messages]] occurred only very recently, on 2025-10-12, in the experimental lDOS boot repo.) |
| |
| The skip_next_clust + skip_next_sect loop was still mirrored by load_next_clust + load_next_sect, which still lived next to the former within the 1536 bytes loaded by MS-DOS v6 / IBM-DOS load. The loaded_all entry was minimal: It only transfered control to the payload, not even cleaning the stack of the load next loop. (The stack cleaning [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/93b584cd76d9|was added on 2017-10-12]].) |
| |
| A multi-mode (_IMAGE_EXE) or second payload wasn't supported yet, the file was supposed to encode an invalid MZ header so it wouldn't be loaded. This had exePages = exeHeaderSize = exeMinAlloc = -1. Notably, the current iniload has exeHeaderSize = 0 instead ([[https://hg.pushbx.org/ecm/ldosboot.exp/rev/d35ef487d434|since 2018-10-18]]) when building without an application or device driver entry. |
| |
| There are three main incompatibilities with modern payloads: The kernel mode entrypoint is fixed at +0:0 (rather than being configurable to alternatives like +0:32 [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/03db00b0eb42|as of 2017-10-08]]), the query patch value isn't passed to the kernel (like [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/9c885120139d|as of 2022-12-29]]) instead retaining the ldLoadingSeg value, and a kernel command line isn't passed (like it is [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/e1520d53c39a|as of 2020-01-01]]) leading the payload to access memory in unclaimed stack space. Both of the first ones are irrelevant for the current lDOS kernel but will affect the bootloaded lDebug as a kernel mode payload. |
| |
| The original iniload can be used to load a current lDDebug payload by patching ddebug.big to start with ''EB 1E'', disabling the checksum, and fixing the FAT buffer bug manually as in the following log: |
| |
| <code>boot protocol ldos checkvalue=0 oldini.sys |
| -e ss:bp-C as words (-1) (-1) 0 400 |
| -g 2D3 3D6 |
| AX=000A BX=00A2 CX=0000 DX=0000 SP=01FC BP=0220 SI=0000 DI=0008 |
| DS=7255 ES=727C SS=7255 CS=0200 IP=02D3 NV UP DI PL NZ NA PE NC |
| 0200:02D3 31D2 xor dx, dx |
| -r es = word [ss:bp - 8] |
| -g 2D3 3D6 |
| AX=0008 BX=00A4 CX=0000 DX=0000 SP=01FC BP=0220 SI=0000 DI=0008 |
| DS=7255 ES=11E0 SS=7255 CS=0200 IP=02D3 NV UP DI PL ZR NA PE NC |
| 0200:02D3 31D2 xor dx, dx |
| -r es = word [ss:bp - 8] |
| -g 2D3 3D6 |
| AX=0008 BX=00A6 CX=0000 DX=0000 SP=01FC BP=0220 SI=0000 DI=0008 |
| DS=7255 ES=19E0 SS=7255 CS=0200 IP=02D3 NV UP DI PL ZR NA PE NC |
| 0200:02D3 31D2 xor dx, dx |
| -r es = word [ss:bp - 8] |
| -g 2D3 3D6 |
| AX=16CC BX=20A0 CX=000B DX=0002 SP=01FA BP=0220 SI=0000 DI=0008 |
| DS=7255 ES=2080 SS=7255 CS=0200 IP=03D6 NV UP DI PL ZR NA PE NC |
| 0200:03D6 8CC8 mov ax, cs |
| -g |
| |
| ~-q |
| Boot load called |
| -</code> |
| |
| The initial Enter command, ''e ss:bp-C as words (-1) (-1) 0 400'', delays the FAT buffer bug by one clust_next call as it invalidates the buffer passed to the iniload lDOS entrypoint, so the first call will actually read from the FAT and set es in the process, but doesn't ultimately help fix things if clust_next is called multiple times during the load (which it is most likely). The bug doesn't occur on FAT12 file systems. |
| |
| On 2017-10-05 [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/059b6dd89afa|the three size warning messages were added]] (for "ms7_entry", "ldos_entry", and "end"), as well as the final ("end") fill mmacro use to ensure the loader doesn't overflow 1536 bytes. The very first revision weighs in at 1524 bytes, as displayed by the original size warning message ("Loader ends at 1524"). |
| |
| The remaining iniload bugfixes in 2017 October: |
| |
| * 2017-10-03: [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/8b3697d4c4c4|Short read of the boot sector]] (missing the bsBPB adjustment). |
| * 2017-10-05: [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/a887facee835|Improve FAT12/FAT16 distinction cutoff values]]. |
| * 2017-10-05: [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/2f8f94cd5f85|Check that incoming boot sector and FAT buffer]] are below [[https://pushbx.org/ecm/doc/ldosboot.htm#protocol-sector-iniload-memory|the Low Memory Area top reservation]]. |
| * 2017-10-28: [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/b1462105d776|Do not trash di during MS-DOS v7 load entry]], it contains the low word of the starting cluster number. |
| * 2017-10-28: [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/7b57a8dd13b6|Make the relocation work]] by calculating cs minus paragraphs to move down, not the accidental cs plus. |
| * 2017-10-28: [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/72d5031299d6|Check for underflow of relocation destination]]. |
| * 2017-10-28: [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/7ea56a41e2c2|Fix order of initial loader fully loaded check]], bug introduced [[https://hg.pushbx.org/ecm/ldosboot.exp/rev/e7b5d4603bd6|the same day in an optimisation]]. |
| |
| {{tag>ldosboot ldebug}} |
| |
| |
| ~~DISCUSSION~~ |
| |