-------------------------------------------------------------------------------- -------------------------------------------------------------------------
NCTU-CIS BBS 'programming' board Digest Area
■■■ DOS extender, DPMI ■■■
-------------------------------------------- Compiled by: william@cis_nctu -----
-------------------------------------------------------------------------
Posted By: william (C++/ASM/Win Master) on board 'programming'
Date: Thu Jul 29 12:48:39 1993
Title: What is a DOS Extender?
> What is a DOS Extender?
> Lately I've seen this term in some magazines, but I don't know what it is.
Ordinary MS-DOS runs under the real mode of the Intel 8086 family, so it is subject to the 640KB limit.
UNIX, OS/2, and Windows, on the other hand, run under the protected mode of the Intel i286 family, or even under the Virtual 8086 mode of the i386, and can provide more than 640KB, even virtual memory capability.
But the machine code for protected mode and real mode is not quite the same, especially the addressing mode, so programs formerly built on MS DOS could not run under protected mode.
In order to let old real mode programs be ported to protected mode at the least possible cost, so they could enjoy its advantages, some extremely clever and highly skilled people put a layer of interface between the two (that is, the DOS extender), so that all system calls used by the old applications (real mode) (BIOS, DOS 21h...) are instead taken over by the DOS extender (protected mode real mode). Thus, a program using a DOS extender is equivalent to a dual-mode program: normally it runs in protected mode, and once it encounters a service that requires real mode (for example, the current common BIOS routines for disk I/O and screen I/O are still written in real mode, unless it is PS/2's ABIOS, which is shared by both real mode and protected mode), the DOS extender switches back to real mode by itself.
The details are hard to explain in a few words; please refer to "Extending DOS, 2nd edition", or a series of books published by Flag by Mr. Hou Jun-Jie.
==============================================================================
Sender: Hentai@cis_nctu (), board: programming
Subject: Re: Junior asking a protected mode expert..... experts please help
Posted at: NCTU CIS BBS (Aug 22 20:43:21 1994)
Forwarded from: cis_nctu
==>: pcjames.bbs@bbs.ee.nthu. (Danny) on board 'programming'
> After reading some of your posts, let me ask: do you enter protected mode directly?
Mine switches directly into protected mode, then opens a V86 mode and RUNs in it...
> But it isn't easy to rely completely on your own ability. There is a huge amount of prep work first, and besides I don't understand
> TSS, IDT, so I have even less hope of switching into Protected Mode by myself
> I have a copy of 80386 SYSTEM SOFTWARE WRITER'S GUIDE at hand, but it emphasizes concepts
> and the examples are really too simple
If you don't know that stuff, then it's a bit difficult...
Although that System Software Writer's Guide is indeed a bit too brief, the things in it are all very important. When I first started writing this stuff I often went back and flipped through it!
Also, you can refer to the 80x86 Programmer's Refrence manual. The system-programming material in it isn't as detailed as the System Software book, but for beginners there are quite a few things explained in a bit more detail!
> I really hope seniors can give me some suggestions and programs you've written. Thanks in advance
NCTUCCCA:/PC/demos/programming/source/dos32v24.zip
This is a Protected Mode program. It first checks whether there is a DPMI server; if there is, it uses DPMI to enter PM, and if not, it enters by itself...
> If you can also teach me TSS and IDT, I would be even more grateful
IDT is similar to the interrupt vector table starting at 0:0 in real mode,
in protected mode when there's an interrupt or exception, this is the table that's used!
TSS contains some basic information for Tasks. Basically, if the program doesn't involve multitasking or privilege-level changes,
this can be omitted...
-------------------------------------------------------------------------------- NCTU's Hentai
=============================================================================
Sender: BigLin.bbs@csie.nctu (Daxiong), board: programming
Subject: A small question about protected mode
Posted at: NCTU CS Phoenix City Information Station (Tue Oct 25 03:09:22 1994)
You can use a C function pointer to turn the pointer you got into Func ...
Later when calling XMS, just call Func....
If you want to read books on Protected MODE, I know of two:l:
1. 80386 Technical Manual (Chuan Hwa)
2. 80386 Microprocessor Manual (Tung Hwa) (I saw it in the library
: Hentai@cis_nctu () on board 'programming'
> Do you find dos extender amazing??
> You can get dos32v and play with it!! This is a simple dos extender
> and it even comes with source, which can let you understand the protected mode features of the 386 CPU even better!!
> I learned quite a lot from this thing during winter break!!
Ha! I've also looked at the source code for Dos32V12, as well as pmode386 and protect,
and I even wrote a Dos Extender myself (though it can only enter protected
mode from real mode), but I think none of these Dos Extenders is as godlike as DOS/4GW. Do you know why?
Because entering protected mode requires reprogramming the 8259, freeing INT 0 through INT 31
for use when the CPU raises protection exceptions. Then the original interrupt routines are forced to move to other interrupt vectors.
You can see that ordinary Dos Extenders change IRQ 0-7 from the original INT 8h-fh to INT
32-39; but I tried directly writing "int 10h" in assembly while under DOS/4GW protected mode,
and it still correctly called the graphic card BIOS routine. But isn't this interrupt one of the vectors reserved for CPU
exceptions? How can it still behave just like in real mode? That's
what makes it feel so godlike to me.
===============================================================================
Sender: alexfish.bbs@bbs.nchu (Alex Yu), board: programming
Posted at: NCHU Tianshu Information Network (Sat May 7 14:38:05 1994)
> That's what makes it feel so godlike to me.
It's not that DOS4GW is godlike and can let interrupts overlap; this is what a DPMI server is supposed to do in the first place.
The method isn't very hard. Just set the IDT size a bit smaller,
enough to cover all CPU exceptions.
Then whenever an int occurs, or a program uses the int instruction to call an exception,
it will definitely cause an exception, allowing the RING 0 system to completely control interrupt dispatch.
The DPMI specification explicitly states that the DPMI server/host has the duty to map interrupts in protected mode
back to real mode when there is no protected mode ISR to handle them,
so that the real-mode ISR can handle them. Therefore,
QDPMI is an incomplete DPMI server implementation.
Besides DOS4GW, Borland's RTM also has similar capabilities, and also maps hardware interrupts into protected mode,
letting the protected-mode ISR handle the hardware interrupt first.
Also, under Windows all interrupts must first pass through the virtual programmable interrupt
controller device and the protected mode isr before it is the DOS box real mode ISR's turn.
According to M$ documents, the handling efficiency of real mode isr for hardware interrupts under Windows is only 7% of that outside Windows.
The efficiency ranking is:
1. real mode ISRs outside Windows
2. Windows VxDs
3. Windows bi-modal ISRs (ISRs callable by ring 0)
4. Windows or protected mode ISRs
5. ISRs in DOS box
===============================================================================
Sender: cmp@cis_nctu (), board: programming
Posted at: NCTU CIS BBS (May 9 19:08:10 1994)
==>: alexfish.bbs@bbs.nchu (Alex Yu) on board 'programming'
> It's not that DOS4GW is godlike and can let interrupts overlap; this is what a DPMI server is supposed to do in the first place.
> The method isn't very hard. Just set the IDT size a bit smaller,
> enough to cover all CPU exceptions.
> Then whenever an int occurs, or a program uses the int instruction to call an exception,
> it will definitely cause an exception, allowing the RING 0 system to completely control interrupt dispatch.
After causing the exception, what should be done next? And how does this exception handler know the int number?
I see that other Dos Extenders, when handling calls to original real-mode interrupts, set up
a special interrupt routine for it, such as AH= real-mode int number, then call this interrupt routine, and then this
routine switches into V86 mode to run the original real-mode interrupt.... Also, you say to reduce the IDT size,
but the minimum still can't be smaller than 32*8 Bytes, right! (that is, int 0-31) And I was doing int 16
while in protected mode! I don't think that could be under CPU exception handler control, right! (because int
16 is Math Error exception!)
===============================================================================
Sender: alexfish.bbs@bbs.nchu (Alex Yu), board: programming
Posted at: NCHU Tianshu Information Network (Tue May 10 10:10:40 1994)
> After causing the exception, what should be done next? And how does this exception handler know the int number?
The Exception error code will indicate it.
Under Windows or OS/2, use sidt to look at IDTR, and you'll know how small the IDT is.
> I see that other Dos Extenders, when handling calls to original real-mode interrupts, set up
> a special interrupt routine for it, such as AH= real-mode int number, then call this interrupt routine, and then this
> routine switches into V86 mode to run the original real-mode interrupt.... Also, you say to reduce the IDT size,
> but the minimum still can't be smaller than 32*8 Bytes, right! (that is, int 0-31) And I was doing int 16
> while in protected mode! I don't think that could be under CPU exception handler control, right! (because int
> 16 is Math Error exception! )
Of course it can, because the privilege levels are different. A RING 3 program cannot directly call
RING 0 interrupts and exceptions.
===============================================================================
Sender: alexfish.bbs@bbs.nchu (Alex Yu), board: programming
Posted at: NCHU Tianshu Information Network (Wed May 11 04:49:06 1994)
□ Quoting the post by: cmp.bbs@bbs.cis.nctu () □
>> Of course it can, because the privilege levels are different. A RING 3 program cannot directly call
>> RING 0 interrupts and exceptions.
> Sorry, I wasn't clear. I want to directly implement, in RING 0, a DOS/4GW-like arbitrary feature
> that lets people call original real-mode interrupts. (Don't tell me to use DPMI.)
I still have to say, DPMI has this kind of function, and the method is very simple:
Set every protected mode interrupt vector (the DPMI specification requires a DPMI server
to provide all 256 interrupts for use by DPMI clients; if it doesn't comply then it isn't compatible with the DPMI
specification) to your own handler, and this handler contains only a single int 3.
NCTU-CIS BBS 'programming' board Digest Area
■■■ DOS extender, DPMI ■■■
-------------------------------------------- Compiled by: william@cis_nctu -----
-------------------------------------------------------------------------
Posted By: william (C++/ASM/Win Master) on board 'programming'
Date: Thu Jul 29 12:48:39 1993
Title: What is a DOS Extender?
> What is a DOS Extender?
> Lately I've seen this term in some magazines, but I don't know what it is.
Ordinary MS-DOS runs under the real mode of the Intel 8086 family, so it is subject to the 640KB limit.
UNIX, OS/2, and Windows, on the other hand, run under the protected mode of the Intel i286 family, or even under the Virtual 8086 mode of the i386, and can provide more than 640KB, even virtual memory capability.
But the machine code for protected mode and real mode is not quite the same, especially the addressing mode, so programs formerly built on MS DOS could not run under protected mode.
In order to let old real mode programs be ported to protected mode at the least possible cost, so they could enjoy its advantages, some extremely clever and highly skilled people put a layer of interface between the two (that is, the DOS extender), so that all system calls used by the old applications (real mode) (BIOS, DOS 21h...) are instead taken over by the DOS extender (protected mode real mode). Thus, a program using a DOS extender is equivalent to a dual-mode program: normally it runs in protected mode, and once it encounters a service that requires real mode (for example, the current common BIOS routines for disk I/O and screen I/O are still written in real mode, unless it is PS/2's ABIOS, which is shared by both real mode and protected mode), the DOS extender switches back to real mode by itself.
The details are hard to explain in a few words; please refer to "Extending DOS, 2nd edition", or a series of books published by Flag by Mr. Hou Jun-Jie.
==============================================================================
Sender: Hentai@cis_nctu (), board: programming
Subject: Re: Junior asking a protected mode expert..... experts please help
Posted at: NCTU CIS BBS (Aug 22 20:43:21 1994)
Forwarded from: cis_nctu
==>: pcjames.bbs@bbs.ee.nthu. (Danny) on board 'programming'
> After reading some of your posts, let me ask: do you enter protected mode directly?
Mine switches directly into protected mode, then opens a V86 mode and RUNs in it...
> But it isn't easy to rely completely on your own ability. There is a huge amount of prep work first, and besides I don't understand
> TSS, IDT, so I have even less hope of switching into Protected Mode by myself
> I have a copy of 80386 SYSTEM SOFTWARE WRITER'S GUIDE at hand, but it emphasizes concepts
> and the examples are really too simple
If you don't know that stuff, then it's a bit difficult...
Although that System Software Writer's Guide is indeed a bit too brief, the things in it are all very important. When I first started writing this stuff I often went back and flipped through it!
Also, you can refer to the 80x86 Programmer's Refrence manual. The system-programming material in it isn't as detailed as the System Software book, but for beginners there are quite a few things explained in a bit more detail!
> I really hope seniors can give me some suggestions and programs you've written. Thanks in advance
NCTUCCCA:/PC/demos/programming/source/dos32v24.zip
This is a Protected Mode program. It first checks whether there is a DPMI server; if there is, it uses DPMI to enter PM, and if not, it enters by itself...
> If you can also teach me TSS and IDT, I would be even more grateful
IDT is similar to the interrupt vector table starting at 0:0 in real mode,
in protected mode when there's an interrupt or exception, this is the table that's used!
TSS contains some basic information for Tasks. Basically, if the program doesn't involve multitasking or privilege-level changes,
this can be omitted...
-------------------------------------------------------------------------------- NCTU's Hentai
=============================================================================
Sender: BigLin.bbs@csie.nctu (Daxiong), board: programming
Subject: A small question about protected mode
Posted at: NCTU CS Phoenix City Information Station (Tue Oct 25 03:09:22 1994)
You can use a C function pointer to turn the pointer you got into Func ...
Later when calling XMS, just call Func....
If you want to read books on Protected MODE, I know of two:l:
1. 80386 Technical Manual (Chuan Hwa)
2. 80386 Microprocessor Manual (Tung Hwa) (I saw it in the library
: Hentai@cis_nctu () on board 'programming'
> Do you find dos extender amazing??
> You can get dos32v and play with it!! This is a simple dos extender
> and it even comes with source, which can let you understand the protected mode features of the 386 CPU even better!!
> I learned quite a lot from this thing during winter break!!
Ha! I've also looked at the source code for Dos32V12, as well as pmode386 and protect,
and I even wrote a Dos Extender myself (though it can only enter protected
mode from real mode), but I think none of these Dos Extenders is as godlike as DOS/4GW. Do you know why?
Because entering protected mode requires reprogramming the 8259, freeing INT 0 through INT 31
for use when the CPU raises protection exceptions. Then the original interrupt routines are forced to move to other interrupt vectors.
You can see that ordinary Dos Extenders change IRQ 0-7 from the original INT 8h-fh to INT
32-39; but I tried directly writing "int 10h" in assembly while under DOS/4GW protected mode,
and it still correctly called the graphic card BIOS routine. But isn't this interrupt one of the vectors reserved for CPU
exceptions? How can it still behave just like in real mode? That's
what makes it feel so godlike to me.
===============================================================================
Sender: alexfish.bbs@bbs.nchu (Alex Yu), board: programming
Posted at: NCHU Tianshu Information Network (Sat May 7 14:38:05 1994)
> That's what makes it feel so godlike to me.
It's not that DOS4GW is godlike and can let interrupts overlap; this is what a DPMI server is supposed to do in the first place.
The method isn't very hard. Just set the IDT size a bit smaller,
enough to cover all CPU exceptions.
Then whenever an int occurs, or a program uses the int instruction to call an exception,
it will definitely cause an exception, allowing the RING 0 system to completely control interrupt dispatch.
The DPMI specification explicitly states that the DPMI server/host has the duty to map interrupts in protected mode
back to real mode when there is no protected mode ISR to handle them,
so that the real-mode ISR can handle them. Therefore,
QDPMI is an incomplete DPMI server implementation.
Besides DOS4GW, Borland's RTM also has similar capabilities, and also maps hardware interrupts into protected mode,
letting the protected-mode ISR handle the hardware interrupt first.
Also, under Windows all interrupts must first pass through the virtual programmable interrupt
controller device and the protected mode isr before it is the DOS box real mode ISR's turn.
According to M$ documents, the handling efficiency of real mode isr for hardware interrupts under Windows is only 7% of that outside Windows.
The efficiency ranking is:
1. real mode ISRs outside Windows
2. Windows VxDs
3. Windows bi-modal ISRs (ISRs callable by ring 0)
4. Windows or protected mode ISRs
5. ISRs in DOS box
===============================================================================
Sender: cmp@cis_nctu (), board: programming
Posted at: NCTU CIS BBS (May 9 19:08:10 1994)
==>: alexfish.bbs@bbs.nchu (Alex Yu) on board 'programming'
> It's not that DOS4GW is godlike and can let interrupts overlap; this is what a DPMI server is supposed to do in the first place.
> The method isn't very hard. Just set the IDT size a bit smaller,
> enough to cover all CPU exceptions.
> Then whenever an int occurs, or a program uses the int instruction to call an exception,
> it will definitely cause an exception, allowing the RING 0 system to completely control interrupt dispatch.
After causing the exception, what should be done next? And how does this exception handler know the int number?
I see that other Dos Extenders, when handling calls to original real-mode interrupts, set up
a special interrupt routine for it, such as AH= real-mode int number, then call this interrupt routine, and then this
routine switches into V86 mode to run the original real-mode interrupt.... Also, you say to reduce the IDT size,
but the minimum still can't be smaller than 32*8 Bytes, right! (that is, int 0-31) And I was doing int 16
while in protected mode! I don't think that could be under CPU exception handler control, right! (because int
16 is Math Error exception!)
===============================================================================
Sender: alexfish.bbs@bbs.nchu (Alex Yu), board: programming
Posted at: NCHU Tianshu Information Network (Tue May 10 10:10:40 1994)
> After causing the exception, what should be done next? And how does this exception handler know the int number?
The Exception error code will indicate it.
Under Windows or OS/2, use sidt to look at IDTR, and you'll know how small the IDT is.
> I see that other Dos Extenders, when handling calls to original real-mode interrupts, set up
> a special interrupt routine for it, such as AH= real-mode int number, then call this interrupt routine, and then this
> routine switches into V86 mode to run the original real-mode interrupt.... Also, you say to reduce the IDT size,
> but the minimum still can't be smaller than 32*8 Bytes, right! (that is, int 0-31) And I was doing int 16
> while in protected mode! I don't think that could be under CPU exception handler control, right! (because int
> 16 is Math Error exception! )
Of course it can, because the privilege levels are different. A RING 3 program cannot directly call
RING 0 interrupts and exceptions.
===============================================================================
Sender: alexfish.bbs@bbs.nchu (Alex Yu), board: programming
Posted at: NCHU Tianshu Information Network (Wed May 11 04:49:06 1994)
□ Quoting the post by: cmp.bbs@bbs.cis.nctu () □
>> Of course it can, because the privilege levels are different. A RING 3 program cannot directly call
>> RING 0 interrupts and exceptions.
> Sorry, I wasn't clear. I want to directly implement, in RING 0, a DOS/4GW-like arbitrary feature
> that lets people call original real-mode interrupts. (Don't tell me to use DPMI.)
I still have to say, DPMI has this kind of function, and the method is very simple:
Set every protected mode interrupt vector (the DPMI specification requires a DPMI server
to provide all 256 interrupts for use by DPMI clients; if it doesn't comply then it isn't compatible with the DPMI
specification) to your own handler, and this handler contains only a single int 3.
MSN:tiqit2@hotmail.com


