Main page I Packages I Help I Forum

SvarDOS community forum

a place to talk about SvarDOS and other DOS-related things

jump to end reply list of threads

Using int 0x13 hook to book svardos over serial port

I have an interest in booting SvarDOS over the serial port through an int 0x13 hook to work around non-functioning floppy drives. My childhood 8088(Zenith ZD-151 or thereabout) a machine monitor roughly equivalent to DOS debug. So I created a small program to grab a bootloader that would hook int 0x13 and start loading disk images over the serial port. It all works beautifully until SvarDOS finishes loading KERNEL.SYS(specifically C=27 H=0 S=4). The 'Enhanced DR-DOS kernel...' banner is displayed, and then execution goes off the rails. There is a DEBUG macro in the source code, but I haven't managed to understand the build system yet. So I am focusing on configuration control that I have without rebuilding SvarDOS. Any suggestions on how to proceed would be appreciated.
914488c23c724b71 831bc56dbfabe5b2 8b75df193fc83a0f 3ce33036bdcce42b d8efa38b45466a88 4a8d6c2fb127932f 66d18f6fe5ce0ce3 e95ecaaac41fb734
Hi Neil, please note that the EDR kernel relocates itself in memory during its initialization phase. When hooking INT13 before the kernel is loaded it is crucial to protect the memory region your handler lives in. A way that comes to my mind is the following: put your handler at the end of conventional memory, then decrease the value of available conventional memory in the BIOS data area (BDA) at address 0040:0013 by the required quantity. The value specifies the available conventional memory IN KILOBYTES! https://stanislavs.org/helppc/bios_data_area.html Bernd
I had got my int 0x13 hook overwritten a couple times until I found a spot where it stayed intact. But your suggestion is far superior, and I followed it. My hook now runs out of 9f00:0000 with base memory being reduced to 638 kiB. Unfortunately the behavior is unchanged. kernel.sys gets loaded to a contiguous buffer at 0000:0600 and starts executing. There is a intermediate step where the code segment register gets redefined to 0070 which has the desirable effect of making the segment offset in memory, where kernel.sys is running, identical to the kernel.sys file offset on disk. I think I see where this is happening in edrdos/drbio/init.asm at least. And somewhere after this things to off the rails.
Can you single step or set breakpoints using that monitor? EDR-DOS definitely supports running under bootloaded lDebug with the debugger reserving memory beyond the top of the Low Memory Area, by lowering the amount of KiB recorded in word [40h:13h]. Where do you store the disk image that you've loaded via serial?
> There is a intermediate step where the code segment register gets redefined to 0070
Yes, the kernel places parts of its drbio module at linear 00700h and addresses them at 70h:0. Originally the kernel file had to be loaded at that address too, but I suggested allowing it to load at 60h:0 like a FreeDOS kernel.sys too.
> which has the desirable effect of making the segment offset in memory, where kernel.sys is running, identical to the kernel.sys file offset on disk. I think I see where this is happening in edrdos/drbio/init.asm at least.
I'm confused about this. The file on disk doesn't have a segment, so how can "the segment offset in memory" be equal to "the file offset on disk"? The offsets within the segment are the same either way, before or after the relocation. I'm not particularly well versed in the segmentation and relocations used by the EDR-DOS kernel, in all my time working on it I never quite understood these too well.
I can single step with the monitor using it's trace command. And that's essentially how I've learned what I know so far. However it is a very slow process especially since I have limited familiarity with the source code and probably would not recognize exactly when things are going wrong. So I was looking for a way to reduce the effort. With regard to my comment about kernel.sys at 0070:0000, I just meant that when the segment is set to 0070, then the segment offset value 0070:xxxx exactly matches the offset displayed when viewing kernel.sys with a hex editor on another computer. So it is easy to compare side-by-side. I assumed this was the design reason for running under segment 0070, but it might just be coincidence. I wrote a small C program running on a different computer that gets the information for the int 0x13 request, loads the correct information from the disk image, and then sends the sectors over the serial port back to the 8088. My int 0x13 hook on the 8088 copies to the correct destination buffer after each byte is received. The file image is never stored on the 8088.
Yeah, that's why I asked whether you can set breakpoints as well. Tracing the entire kernel init would take a long time. Proper debugger commands like Go with temporary breakpoints, and Proceed past a call, help to make this much more manageable, but if your monitor only provides Trace that's too bad. If you load the kernel to 00600h initially then 60h:xxxx will also match the on-disk structure of the kernel file. Changing the segment together with a relocation by 256 bytes doesn't change that. As to the image being sent over the serial port, that should theoretically work.
Your opinion that the image being sent over the serial should work is encouraging. I keep feeling that it's just something small that is preventing the whole process from standing up. The 'go' command allows me to set a single breakpoint on invocation(by replacing a specified byte with 0xCC). It's better than tracing, but I have to pick the next place that I want to stop every single time that I restart execution. In practice, I chose a spot that got jumped over, and then the system hangs without my getting any useful information. The commands available to me are: - MFM-150 Command Summary - CMD: Explanation Syntax ---- ----------- ------ ?: Help ? B: Boot from disk B [{F|W}][{0|1|2|3}][:<partition>] C: Color Bar C D: Display memory D [<range>] E: Examine memory E <addr> F: Fill memory F <range>,{<byte>|",'"<string>"',"}... G: Execute (Go) G [=<addr>][,<breakpoint>]... H: Hex math H <number1>,<number2> I: Input from port I <port> M: Move memory block M <range>,<dest> O: Output to port O <port>,<value> R: Examine Registers R [<register>] S: Search memory S <range>,{<byte>|",'"<string>"',"}... T: Trace program T [<count>] U: Unassemble program U [<range>] V: Set Video/Scroll V [M<mode>][S<scroll>] TEST: Extended diagnostics TEST Where <range> is: <addr>{,<addr>|L<length>} Copyright (C) 1987, by Zenith Data Systems
The "..." in the Go command description seems like it allows multiple temporary breakpoints. Judging by the similarity, your monitor like as not is derived from MS-DOS Debug. That, in MS-DOS v2, provided for up to 10 temporary breakpoints per G command: https://hg.pushbx.org/ecm/msdebug/rev/ebee6ad62616#l6.23 That won't much help with debugging the kernel init though, even if it indeed supports multiple breakpoints. Another thing to recall is that the kernel will overwrite your monitor's int 1 and int 3 handlers by default, so the amount of code you can trace without careful workarounds is limited. I forgot how to do it in the SvarDOS flavour kernel but there should be a flag to set that enables debugger detection. It's here: https://github.com/SvarDOS/edrdos/blob/579ab148df4d6af82752155137e0cad6a31b1a34/drbio/init.asm#L207 This should be very near to the start of the kernel file (if using the SvarDOS flavour) and you need to OR in bit 2 (mask 4) to enable the detection. You can do that on-disk (in your boot image) or using the monitor upon entering the load file entrypoint. I don't know whether there's a tool anywhere to modify this flag, you might have to use a hex editor. If you set the flag and then "Go" with the monitor, it should break into the monitor in the detection: https://github.com/SvarDOS/edrdos/blob/579ab148df4d6af82752155137e0cad6a31b1a34/drbio/init.asm#L984 There, change the Carry Flag to be set, possibly by entering "r f" then "CY", and then the kernel will leave your monitor's int 1 and int 3 vectors unchanged.
If you replaced the kernel with an lDOS flavour kernel - build at https://pushbx.org/ecm/download/old/edrdos/20251221.zip (not 100% synced with SvarDOS flavour) - then you could use the trace listing file that I uploaded at https://hg.pushbx.org/ecm/tlsfiles/file/00e7de020891/edrdos/drbio.tls Also, using patldos you can change the debugger detection setting in the lCFG block without a hex editor: https://pushbx.org/ecm/download/old/patchini/20260805.zip Unfortunately, you won't be able to use lDebug and its companion application TracList - https://pushbx.org/ecm/doc/traclist.htm - directly on your setup, unless you have two serial ports set up and connected to other computers. So the usefulness of the .tls file may be limited. If you do want to use both lDebug and your int 13h handler at the same time, on a single serial port, you'd have to develop some sort of protocol to distinguish data for the disk and data for the debugger. This would require some creativity. Alternatively, load lDebug and (provided it loads fine from the serial int 13h handler) then have it load the kernel, and next configure the debugger to use your single serial port and disable or disuse the disk serial I/O after enabling the debugger serial I/O. However, lDebug may need some 128 KiB of memory for itself. For a 640 KiB setup as you indicated, this should not be a problem though.
TracList link should be https://pushbx.org/ecm/doc/traclist.htm
Another idea is you could provide us the code you're running on the client and the server (with a good license please) and we could review it and possibly try it out ourselves, to see if you made any errors in either.
Thank you for the advice. There's a lot to read and understand, and I've still got some weekend projects to finish before I can sit down at the computer and do some serious reading. I don't mind sharing/donating the code as it was an evening to write but a several days to slowly debug because I've forgotten a whole lot about how dos and x86 assembly work. What license would be appropriate for the source, and where should the code be posted?
I tend to use the Fair License as it is one of the shortest choices, however there's other similarly permissive licenses. The Fair License, the Simplified 2-Clause BSD License, and the MIT License are all listed as options in https://hg.pushbx.org/ecm/ldebug/file/43d91d321975/license.txt (FreeDOS Debug and Debug/X originally use the MIT license, I asked for permission to use the other two choices. Recent NASM since 2.0something at least since 2009 uses the simplified 2-clause BSD license.) Another permissive license is the ISC License. The Apache License v2 is popular too. If you prefer copyleft, there's the GNU GPL (most compatible is if you specify some such "version 2 or any later version" wording) and GNU AGPL (stronger: copyleft kicks in on network interaction as well). Copyleft that allows linking to other code is GNU LGPL or MPL. If you want to be very permissive and don't even care to be credited with attribution, you can choose Creative Commons Zero (CC0) or state that you want to place your code into the Public Domain (not technically a proper license but mostly accepted).
The MIT License is fine. Is https://hg.pushbx.org/ecm the place where you suggest I submit my code?
Oh, I'd forgotten about that. Our hgweb server can only be written using our ssh keys. That means if you want us to host it on there, which we'd happily do, you'll have to send the files (or hg bundles) by email (as attachment) or using some other means. Email address can be read from pages like what I last linked. If you send source text files, make sure to add a username + email combination you want to put as your hg user.
I have gotten SVarDOS to boot. Though I'm now getting a freeze in INSTALL.COM after selecting 'English'. But I can just make a SVarDOS image that works around this problem. So I am going to call this a win. The last disk access when INSTALL.COM hangs is just reading the boot sector. AH=02h: Read Sectors From Drive | Num=1 Drive=0 C=0 H=0 S=1 -> Sector 1/1 (offset 0, lba 0) -> [Boot Sector / BPB] Thanks to everyone for their suggestions. I don't know if I could have succeeded without some orientation. There were a lot of things that I did, undid, redid, then forgot. So here is what I think that I needed to add to what I originally had: 1. Add a handler for int 13h AH = 41h to clearly proclaim that I do not support LBA for my serial port drive. 2. Resetting the serial port to 57600,8,N,1 on every int 13h invocation. I don't know whether SVarDOS or something else was responsible for changing the serial port. I've discovered that my serial port communication is a little non-portable. It works for a particular pair of computers at 57600 baud. If there is still interest, I'll submit my code once my serial port code is portable enough to work on something other than the 8088/486 pairing that I am currently using.
I added the debugger's serial I/O based on an old document I found,
> 2019 by E. C. Masloch
> based on http://www.sci.muni.cz/docs/pc/serport.txt The Serial Port rel. 14
Quoted from https://hg.pushbx.org/ecm/ldebug/file/43d91d321975/source/serialp.asm#l4 I'd like to host and study your source texts whenever you feel like sharing.
078ac416e4811d4f ac7134fc6c34222e e676a6b143232a57 f638c349b414e0e6 b25cc1129ce8293c bc9a49b88c1ea9f5 a8d5c26e0797bc6f 2eba886e5c7e366b
Interesting thread. Booting over serial is a very cool idea. Might have missed something though - where does this int13h-hooking-serial-booting bootloader lives? I assume it has to be on some bootable medium (floppy/hdd) since on a 8088 PC it is unlikely that an option ROM mechanism exists?
I received the email and its attachment, thanks. I will upload your source texts and try it out and maybe work some on the programs in the following days. Mateusz: The serial boot process starts by entering a small (64 ish bytes) binary stub into the memory of the system to boot. Once it is entered, eg at address 1000h:0000h, it must be executed. In the documentation there's examples for that Debug-like monitor and for BASIC. However, the stub could be loaded off an option ROM or a different boot device as well.
I uploaded your two revisions and some subsequent edits to a repo at https://hg.pushbx.org/ecm/serboot I had to add a sequence to enable the on-chip FIFOs to reliably work on a vptty (socat) connected to a dosemu2 process's COM1. I also added usleep calls after every write in the server, though this may be unneeded after all it seems. I also changed the port file open to use O_NONBLOCK and made it so a read call returning <= 0 loops instead of indicating timeout. In your second revision you accidentally didn't return the correct AX from the int 11h handler. Eventually I just deleted the int 11h handler because modifying the equipment word in the BIOS Data Area should suffice. This modification now also sets bit 0 to indicate any diskettes present. The server program now accepts a command line parameter that's used to open the serial device file, if specified. The hardcoded filename is used as a fallback if no parameter specified. The resident and transient used sizes of the main handler binary are reduced, some optimisations and some dead code removal and the loader code is relocated separately (to 200h:0) rather than being included in the resident payload. The loader gets an error message that works properly. Resident block size is determined dynamically, currently allocating 1 KiB rather than 2 KiB. Int 13h requests for HDDs are passed through rather than returning an error. Finally, in several spots you still hardcoded the port numbers rather than using the configured port number as a base. I fixed that. I will probably continue to work on the code some more.
I updated the programs some more. Here's the current readme: https://hg.pushbx.org/ecm/serboot/file/3e07e20d57fa/readme.txt I had to enlarge the stub to 128 bytes (or a few bytes more for unusual port numbers), which has the advantage that the CMD_BOOT is a regular server command and thus restarting the server with a live client actually works. I wasn't able to get this to work previously in my test environment. Also, the next loader stage can be any size up to 32 KiB now. There's a bunch more changes. I'll write about them on next Sunday, to be uploaded to the blog later.
I've looked through all of your commits. You've really cleaned it up quite well. Independently I fixed a few of the same problems, but my lack of a deep understanding of DOS makes it difficult to spot issues. I think that the biggest issue that I had was passing some int 0x13 commands to the BIOS. That seemed to confuse a lot of programs. Once that was fixed then I was able to boot from ms-dos 3.30 which is really close to what was originally used on the computer. Since I don't understand DOS very well, I went the other direction with my changes and added even more error logging. There were lots of bugs in the error handling messaging. I also added an actual CRC check, but I have yet to spot a CRC error in practice. What I have seen is just the occasional desync on the serial port. I'm honestly shocked that the program can maintain 57600 baud on a 4.77 MHz computer with almost no hiccups on a 8250 UART. There are still some programs that do strange things(e.g. getting past level 11 on Dungeons of Kroz) that I will debug in my spare time. Overall I was able to accomplish my goal of getting the floppy drive recognized by the computer. The drive isn't completely working yet, but at least the computer can properly talk to it, move the heads, etc.... Deep cleaning and alignment checks will happen a little later once I find someone else with a working 5 1/4" drive. Thanks again.
I also added CRC checks of all packets now, excepting the response to the CMD_BOOT command. (The server passes the CRC but the stub doesn't check it.) I also added some retrying on corrupted data packets (read or write disk). And size/geometry detection to allow larger disk image files, which also send their 13.08 geometry to the client. Much more detail on the blog, at https://pushbx.org/ecm/dokuwiki/blog/pushbx/2026/1018_early_mid_october_work_on_serboot_ldos_kernel_ldebug I may yet add a check that the write function succeeded in writing the entire data in a 13.03 call. Though this should only fail if the server host file system is full.
Oh, the hgweb server is now restricted to only work if you provide a login. However, you need only enter "anonymous" as user and any nonempty string as a password. Current info on this on the web pages, such as https://pushbx.org/#hgweb

your name or nick

password (optional)


check the FIRST box: