How to exit to DOS in protected mode?

Started by leetow2003, November 24, 2010, 01:28:10 AM

Previous topic - Next topic

leetow2003

I find under pure DOS codes enter in
protected mode,and do something,finally
codes must switch back to real-mode and
then:
mov ax,4c00h
int 21h
I want to know how to exit to DOS in
protected mode,not switching back to
real-modelike unix or linux?

clive

Isn't the problem that DOS isn't designed to do that? And you'd basically have to dig through DOS, and everything it loaded and "fix" the code/data to understand selectors instead of segments. This strikes me as a hugely impractical task, even for a novice.
It could be a random act of randomness. Those happen a lot as well.

MichaelW

QuoteI want to know how to exit to DOS in protected mode, not switching back to real-mode

You cannot, or at least not literally as stated. DOS consists of real-mode code, and the processor cannot (generally) execute real-mode code when it's in protected mode. Are you perhaps asking about DOS extenders and protected-mode DOS programs?
eschew obfuscation

leetow2003

Quote from: MichaelW on November 24, 2010, 02:38:33 AM
QuoteI want to know how to exit to DOS in protected mode, not switching back to real-mode

You cannot, or at least not literally as stated. DOS consists of real-mode code, and the processor cannot (generally) execute real-mode code when it's in protected mode. Are you perhaps asking about DOS extenders and protected-mode DOS programs?

I mean how to exit,not using:
mov ax,4c00h
int 21h

dedndave

well...
INT 20h was the original way of exiting DOS programs
for EXE programs, if you push the PSP segment, then a 0 word it will exit with a RETF
for COM programs, if you push a 0 word, it will exit with a RETN
these methods execute an INT 20h, which, in later version of DOS, eventually execute AH=4Ch, INT 21h

but, that is still not going to fly in protected mode
it returns you to the DOS kernel, which is real mode

if you want to get to protected mode, or perhaps have a protected mode driver, there are a couple ways
one way is to write it as a device driver and install it in config.sys
another way is to write it as a TSR, using INT 27h to exit (i think there is also an INT 21h function for that - don't remember)
this is how programs like EMM.EXE work
in these cases, you enter protected mode to access the features (extended memory, for example), then
return to real mode before returning control to the caller

Gunther

Quote from: leetow2003, November 24, 2010, at 05:12:12 AMI mean how to exit,not using:
mov ax,4c00h
int 21h

Another way is that: Assuming your program runs under a 32 bit DPMI host. You can call function 306h to determine the addresses of the raw switch procedures. For example:

mov     ax,306h                         ;FUNCTION: get addresses of raw switch procedures
int        31h                                 ;transfer to DPMI host
jc          err                                  ;error: jump
mov     word ptr rmtopm,cx ;offset Real Mode switch
mov     word ptr rmtopm+2,bx ;segment Real Mode switch
mov     dword ptr pmtorm,edi ;offset Protected Mode switch
mov     word ptr pmtorm+4,si ;selector Protected Mode switch
err:


Please check also the DPMI specification.

Gunther
Forgive your enemies, but never forget their names.

FORTRANS

Quote from: dedndave on November 24, 2010, 06:06:52 AM
another way is to write it as a TSR, using INT 27h to exit (i think there is also an INT 21h function for that - don't remember)

Hi,

   DOS function 31H is "Keep Program".  And Int 27H is marked
as "Superceded" and "Programs should use Keep Program...".

   Gunther may have mentioned what you need.  DMPI allows
you to switch between real and protected modes.

Regards,

Steve N.

Gunther

Quote from: FORTRANS, November 24, 2010, at 04:45:34 PMDPMI allows you to switch between real and protected modes.

Yes, but that technique will fail if the program is running under a VCPI server, XMS manager or in raw Protected Mode via INT 15h. In most cases, it isn't necessary to swtch back from PM to RM, because the normal termination via INT 21h will do the job.

Years ago, I've used the mode switching procedures with PowerBASIC for DOS to avoid a GPF by the compiler's cleanup code. But that's one of the rare cases.

Gunther
Forgive your enemies, but never forget their names.