With DPMI into protect mode and back (Developers)
> If I understand the documentation correct, I can switch into protect mode
> by calling address provided in INT2Fh/AX=1687h but there is no transparent
> way how to get back into real (VM86) mode.
> The only way is just to terminate the application. But I don't want to
> terminate it. Maybe is possible to run some child process but I don't want
> to call any external EXE file.
There a 3 methods to switch "back":
1. terminate the DPMI client
2. using Int 31h, ax=0300h/0301h/0302h
3. using raw mode switch (int 31h, ax=0306h)
Here's a sample using the int 31h, ax=0301h method - it's a slightly modified dpmicl16.asm which is supplied with FD DEBUG:
;--- DPMIBACK.ASM: 16bit DPMI application written in MASM syntax.
;--- this sample temporarily switches back to real-mode.
;--- assemble: JWasm -bin -Fo dpmiback.com dpmiback.asm
LF equ 10
CR equ 13
.286
.model tiny
;--- DPMI real-mode call structure
RMCS struct
rEDI dd ?
rESI dd ?
rEBP dd ?
dd ?
rEBX dd ?
rEDX dd ?
rECX dd ?
rEAX dd ?
rFlags dw ?
rES dw ?
rDS dw ?
rFS dw ?
rGS dw ?
rIP dw ?
rCS dw ?
rSP dw ?
rSS dw ?
RMCS ends
.data
szWelcome db "welcome in protected-mode",CR,LF,0
dBack db "back in real-mode",CR,LF,'$'
dErr1 db "no DPMI host installed",CR,LF,'$'
dErr2 db "not enough DOS memory for initialisation",CR,LF,'$'
dErr3 db "DPMI initialisation failed",CR,LF,'$'
.code
org 100h
;--- the 16bit initialization part
start:
pop ax ;get word saved on stack for COM files
mov bx, sp
shr bx, 4
jnz @F
mov bx,1000h ;it was a full 64kB stack
@@:
mov ah, 4Ah ;free unused memory
int 21h
mov ax, 1687h ;DPMI host installed?
int 2Fh
and ax, ax
jnz nohost
push es ;save DPMI entry address
push di
and si, si ;requires host client-specific DOS memory?
jz nomemneeded
mov bx, si
mov ah, 48h ;alloc DOS memory
int 21h
jc nomem
mov es, ax
nomemneeded:
mov bp, sp
mov bx, cs ;save real-mode value of CS in BX
mov ax, 0000 ;start a 16-bit client
call far ptr [bp] ;initial switch to protected-mode
jc initfailed
;--- now in protected-mode
push bx
mov si, offset szWelcome
call printstring
pop bx
;--- switch back to real-mode
sub sp, sizeof RMCS
mov bp,sp
mov [bp].RMCS.rIP, offset backtoreal
mov [bp].RMCS.rCS, bx
mov [bp].RMCS.rFlags, 0
lea ax,[bp-20h]
mov [bp].RMCS.rSP, ax
mov [bp].RMCS.rSS, bx
xor bx,bx
xor cx,cx
mov di,bp
push ss
pop es
mov ax,0301h
int 31h
mov ax, 4C00h ;normal client exit
int 21h
backtoreal:
push cs
pop ds
mov dx,offset dBack
mov ah,9
int 21h
retf ;back to protected-mode for final exit
nohost:
mov dx, offset dErr1
jmp error
nomem:
mov dx, offset dErr2
jmp error
initfailed:
mov dx, offset dErr3
error:
push cs
pop ds
mov ah, 9
int 21h
mov ax, 4C00h
int 21h
;--- print a string in protected-mode with simple
;--- DOS commands not using pointers.
printstring:
lodsb
and al,al
jz stringdone
mov dl,al
mov ah,2
int 21h
jmp printstring
stringdone:
ret
end start
---
MS-DOS forever!
Complete thread:
- With DPMI into protect mode and back - Laaca, 13.08.2010, 10:36 (Developers)
- With DPMI into protect mode and back - EDIT: example - ecm, 13.08.2010, 14:30
- With DPMI into protect mode and back - EDIT: example - DOS386, 26.08.2010, 09:18
- With DPMI into protect mode and back - EDIT: example - ecm, 26.08.2010, 14:35
- With DPMI into protect mode and back - EDIT: example - DOS386, 27.08.2010, 03:33
- With DPMI into protect mode and back - EDIT: example - ecm, 30.08.2010, 21:51
- With DPMI into protect mode and back | physical memory - DOS386, 06.09.2010, 20:08
- With DPMI into protect mode and back | physical memory - ecm, 07.09.2010, 17:04
- With DPMI into protect mode and back | physical memory - DOS386, 08.09.2010, 00:51
- With DPMI into protect mode and back | physical memory - ecm, 08.09.2010, 20:53
- With DPMI into protect mode and back | physical memory - DOS386, 11.09.2010, 01:02
- With DPMI into protect mode and back | physical memory - ecm, 11.09.2010, 01:25
- With DPMI into protect mode and back | physical memory - DOS386, 11.09.2010, 01:02
- With DPMI into protect mode and back | physical memory - ecm, 08.09.2010, 20:53
- With DPMI into protect mode and back | physical memory - DOS386, 08.09.2010, 00:51
- With DPMI into protect mode and back | physical memory - ecm, 07.09.2010, 17:04
- With DPMI into protect mode and back | physical memory - DOS386, 06.09.2010, 20:08
- With DPMI into protect mode and back - EDIT: example - ecm, 30.08.2010, 21:51
- With DPMI into protect mode and back - EDIT: example - DOS386, 27.08.2010, 03:33
- With DPMI into protect mode and back - EDIT: example - ecm, 26.08.2010, 14:35
- With DPMI into protect mode and back - EDIT: example - DOS386, 26.08.2010, 09:18
- With DPMI into protect mode and back - Japheth, 18.08.2010, 08:04
- With DPMI into protect mode and back - Japheth, 18.10.2010, 11:17
- With DPMI into protect mode and back - Rugxulo, 18.10.2010, 23:07
- With DPMI into protect mode and back - Japheth, 19.10.2010, 09:58
- With DPMI into protect mode and back - Rugxulo, 19.10.2010, 10:09
- With DPMI into protect mode and back - Japheth, 19.10.2010, 10:20
- Possible CWSDPMI design flaw - Japheth, 19.10.2010, 17:59
- With DPMI into protect mode and back - Rugxulo, 19.10.2010, 10:09
- With DPMI into protect mode and back - Japheth, 19.10.2010, 09:58
- With DPMI into protect mode and back - Rugxulo, 18.10.2010, 23:07
- With DPMI into protect mode and back - Japheth, 18.10.2010, 11:17
- With DPMI into protect mode and back - EDIT: example - ecm, 13.08.2010, 14:30