Page 2 of 2

Posted: Thu Feb 21, 2008 10:04 am
by Dex
Here is a simple demo i made for you, to show loading a com file (with no int 21h in it), you should only use bios int's and int 20h for exiting.
I have coded it as a com file, so you can test it in Dos or MiniDos.
But it will be very easy to convert it to work has part of your OS.
It will load any com file that does not use int 21h, the com file also needs to uses int 20h to exit.


Others may also find the code helpfull ?.

Posted: Thu Feb 21, 2008 11:04 am
by Fergo
Oh my god, thanks a lot guys, I'm learning a lot!
Dex, I really appreciate your code, thanks a lot (and I'm sure that other members will find it very useful too). It's very well commented (every line! :D) and pretty easy to follow.

You basically install a new int20 handler, load the .com to a segment, sets the "custom .com stack" and segment registers to 256 bytes below the loaded address and jumps to that address. When .com calls the int20, the stack and segment registers are restored and kernel continues its normal execution. Is this correct?

If so, I have just two more questions about it:

1) In your example, you set ds = es = ss = 2000h, so it is not obligatory to set those registers to 50h?

2) When the .com terminates, it calls the int20, which restores the registers. Then you print 'B', way for keypress, restores the "old" int20 and then you call it again. My question is: what's in the old int20 and why you call it again when the .com is already terminated?

BTW: What a cool .com file!

Again, I really appreciate the help from all of you, thanks a lot!

Have a nice day,
Fergo

Posted: Thu Feb 21, 2008 6:48 pm
by Dex
Your welcome and you are correct in your assessment of whats going on.
As for your first ?, in realmode you have segmention (as you are a where ), this lets you load any com file to a differant segment, So it possible to load the same com file to differant address, this is how you can load many of dos TSR at the same time.
The 60h was just a example of if you load a com file to a segment address of 60h (= to 600h) you would set ds es ss to 50h (= to 500h ).
I have forgotten most of what i new about segment and offset, as 99% of the time we use flat addressing in pmode.

As for ? 2 , when we hook into the int 20h we first store the old address, as you may be running this test program from Dos, if you did not restore the old int 20h address at end of program, it would not exit back to dos right ,if you used int 20h or the next program used int 20h, it would just loop back to the int 20h in the ComLoad.com.
In your own OS you will not need to restore the int 20h, as you will want it to return to your kernel.
Hope this helps, regards Dex.

Posted: Thu Feb 21, 2008 7:39 pm
by Fergo
Oh, I've got it now!
Thanks a lot Dex, really!

Best wishes,
Fergo