The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: Shintaro on February 20, 2022, 06:26:02 PM

Title: How do I debug a DOS Driver?
Post by: Shintaro on February 20, 2022, 06:26:02 PM
I copied the code from Expanding DOS for EMSDISK, and obviously made an error somewhere.
Tried it on MS-DOS 5 and 6.0,6.11.

Also I needed to turn MASM 5.1 compatibility on when compiling under MASM 6Something with the way the STRUC is layed out?
In the config.sys after emm386
device=c:\emsdisk.sys 512k

Error:
"Expanded memory allocation failed"

How do I debug a DOS Driver?
The problem is, it doesn't have a stack and starting location.
Do I leave it as an exe?

Code is attached.
Title: Re: How do I debug a DOS Driver?
Post by: _japheth on February 20, 2022, 09:13:02 PM
Quote
How do I debug a DOS Driver?

There exist debuggers that are loaded as device drivers, thus they can debug other drivers. For example, see https://github.com/Baron-von-Riedesel/DOS-debug (https://github.com/Baron-von-Riedesel/DOS-debug). Please read the docs carefully, the device driver version is DebugXG.com

Quote
The problem is, it doesn't have a stack and starting location.
Do I leave it as an exe?

DOS device drivers need not define a stack, they use the stack of the caller.
As it is described in the source, the .EXE is supposed to be converted to a .SYS by tool EXE2BIN.
Title: Re: How do I debug a DOS Driver?
Post by: _japheth on February 20, 2022, 09:57:13 PM
Code is attached.

I tried it. There are problems, though:

1. wrong register used to call EMM

Code: [Select]
;init74: mov     al,43h    ;original line
init74: mov     ah,43h    ;adjusted. register AH must be used to allocate EMS memory!!!!
mov     bx,ownedp
int     emm_int

2. After this modification, the driver loads, but very soon an "overflow" error occurs. Looks like this driver works with MS-DOS v3.3 (only)?
Title: Re: How do I debug a DOS Driver?
Post by: Shintaro on February 20, 2022, 10:18:54 PM
Thanks mate for your help. I do appreciate it.
Strange that it only runs in MS-DOS 3.3 (1987), the book was out in 1992. So I would have thought MS-DOS 5.0 at least.
I'll run up a VM and see what happens.
Title: Re: How do I debug a DOS Driver?
Post by: Shintaro on March 01, 2022, 01:12:29 PM


There exist debuggers that are loaded as device drivers, thus they can debug other drivers. For example, see https://github.com/Baron-von-Riedesel/DOS-debug (https://github.com/Baron-von-Riedesel/DOS-debug). Please read the docs carefully, the device driver version is DebugXG.com

Mate, I have compiled DebugXG.exe and loaded it in the config.sys. But that is as far as I am able to work it out. DebugXG.exe doesn't seem to catch a crashing program, unlike SoftICE.I looked at the instructions for some way to communicate with the loaded DebugXG, but couldn't find anything.
Am I doing something wrong? Missing something? Or maybe this is just beyond my understanding at the moment?

Title: Re: How do I debug a DOS Driver?
Post by: _japheth on March 01, 2022, 05:27:50 PM
Quote
Mate, I have compiled DebugXG.exe and loaded it in the config.sys. But that is as far as I am able to work it out. DebugXG.exe doesn't seem to catch a crashing program, unlike SoftICE.I looked at the instructions for some way to communicate with the loaded DebugXG, but couldn't find anything.
Am I doing something wrong? Missing something? Or maybe this is just beyond my understanding at the moment?

I guess so - better don't use tools that you haven't fully understood yet or that you cannot handle "left-handedly".

Debug is a simple debugger, it has no ( or little ) "post-mortem analysing" capabilities, compared to SoftIce. What do you expect from a 20 kB program? In the case of DebugXG, to debug a device driver, it is supposed that you insert a breakpoint ( "int 3" ) into your driver that has to be debugged, the debugger will then "pop up" when that breakpoint is reached. That's it.

Generally, in real-mode, "post-mortem" capabilities are far less useful than in protected-mode - simple because IT IS NOT protected-mode. Or, in other words, when the crash occurs, it's usually far too late in real-mode to get any idea about what may have caused the crash.
Title: Re: How do I debug a DOS Driver?
Post by: Shintaro on March 01, 2022, 08:05:55 PM


I guess so - better don't use tools that you haven't fully understood yet or that you cannot handle "left-handedly".

Debug is a simple debugger, it has no ( or little ) "post-mortem analysing" capabilities, compared to SoftIce. What do you expect from a 20 kB program? In the case of DebugXG, to debug a device driver, it is supposed that you insert a breakpoint ( "int 3" ) into your driver that has to be debugged, the debugger will then "pop up" when that breakpoint is reached. That's it.
What is "left-handedly"?
Mate, all you needed to say was insert "int 3" in your program and go from there. I must have missed it in the docs.
I may have known that, but the last serious attempt at ASM in MS-DOS was 1990.

I was looking for something that I would set in DebugXG, but it is the other way around, all good.
That obviously saves time as the recommendations that I have read (Advanced MS-DOS Programming Ray Duncan), direct people to debug in parts.

Most likely there will be plenty of "obvious" things that I will miss, that people with a lot more experience will roll their eyes at.
But, I am fine with that. I just want to learn.

I do appreciate your responce and patience.

Title: Re: How do I debug a DOS Driver?
Post by: _japheth on March 01, 2022, 09:35:10 PM
What is "left-handedly"?

It's the German expression "etwas mit links erledigen" translated to English, perhaps a bit too literally - I couldn't remember the appropriate English analogy.
Title: Re: How do I debug a DOS Driver?
Post by: Shintaro on March 01, 2022, 09:40:32 PM
What is "left-handedly"?

It's the German expression "etwas mit links erledigen" translated to English, perhaps a bit too literally - I couldn't remember the appropriate English analogy.

Ah, I understand.
But in order to be able to do it so easily as with the "Left hand", it requires practise first.
Title: Re: How do I debug a DOS Driver?
Post by: Gunther on March 01, 2022, 09:44:31 PM
Andreas,

It's the German expression "etwas mit links erledigen" translated to English, perhaps a bit too literally - I couldn't remember the appropriate English analogy.

that's hard to translate. But what about doing it blindfold?

But no offense intended. Your answer was, of course, absolutely correct.

But in order to be able to do it so easily as with the "Left hand", it requires practise first.
That's as sure as the amen in a church. But you're on a good path. :thumbsup: