From: Ed Beroset
Subject: flat real mode
At 08:36 12/16/97, you wrote:
>
>Replying to a message of Ed Beroset to All:
>
> EB> Serguei is correct. In my experience it's more often called
> EB> flat real mode, since it allows one access to the full 4G
> EB> as a flat address space, but it's the same thing.
>
>Have you actually done this?
Yes, of course. More to the point -- have you actually done this?
>If this is at all possible, then why do we need
>DPMI? Why was it invented in teh first place? All you'd have to do in DOS is
>switch to protected mode, make a few selectors in the first meg of memory,
>with memory limits as large as you like, and switch back to "real" mode
sing
>the base values of those selectors as your segment register values.
DPMI allows one to run protected mode code -- flat real mode does not.
They solve different problems.
> EB> isn't any special opcode to switch into this mode, since
> EB> it's nothing more than a switch into, and then back out of
> EB> protected mode.
>
>It's a lot more than that; you didn't quote the real->protected switch, in
>which it clearly states the segment register values are unchanged during a
>mode switch. You have to create new selectors based on the contents of the
>segment registers (which are 20-bit addresses), and forget that any of the
>previous selectors even exist (because you can never find out what they are,
>much less what info they contain).
You're making it overly complicated. If the segment descriptor values are
unaffected by the switch into protected mode, and the descriptor values are
also unaffected by the switch back out of protected mode, why would I need
to reload them at any point? One doesn't have to load ANY descriptors at
all except the new 4G data segment descriptor.
> EB> If you carefully read the note in step 3, you'll see that
> EB> although there isn't a neon sign saying "Flat Real Mode,"
> EB> it's certainly clear what will happen if one were to leave
> EB> some segment descriptors "large."
>
>No, it is not clear, not at all.. again, if this is possible, then why have
>DPMI at all?
I dunno. Why have DOS at all? :-) Maybe this code will clear things up
for you. It's a simple little demonstration that is about 100 bytes long.
Naturally it must be run in true real mode, not in V86 mode, so it won't
work under any extended memory managers, nor in any DOS emulator (e.g. DOS
window in Windows, NT, or OS/2).
-+--- flatmode.asm begins
; flatmode.asm
;
; This program demonstrates flat real mode, which is simply real mode
; with 4G descriptors for some segments. In this code it's done by
; going into protected mode, setting the FS register to a descriptor
; with 4G limits and then returning to real mode. The protected mode
; limit stays in effect, giving "flat real mode."
;
; The demonstration part of this code writes the first 160 bytes from
; the system ROM at F0000h (linear) to the color screen which is assumed
; to be at B8000h (linear) using a flat real mode selector. Since that
; range of the system ROM typically contains a copyright notice, one
; can easily see that the code is truly working as advertised.
;
; This code is intended to be run on a Pentium or better.
;
; To assemble:
;
; using Microsoft's MASM 6.11 or better
; ml /Fl flatmode.asm
;
; or Borland's TASM version 4.0 or better
; tasm /la /m2 flatmode.asm
; tlink /Tdc flatmode
;
; written on Wed 12-17-1997 by Ed Beroset and
; donated to the public domain by the author
;
;----------------------------------------------------------------------
.model tiny
.code
.586P
DESC386 STRUC
limlo dw ?
baselo dw ?
basemid db ?
dpltype db ? ; p(1) dpl(2) s(1) type(4)
limhi db ? ; g(1) d/b(1) 0(1) avl(1) lim(4)
basehi db ?
DESC386 ENDS
;----------------------------------------------------------------------
ORG 100h
start:
call flatmode ; go into flat real mode (fs reg only)
call fillscreen ; fill the screen using 4G descriptor
mov ax,4c00h ; do a standard DOS exit
int 21h ;
;----------------------------------------------------------------------
fillscreen proc
mov esi,0F0000h ; point to ROM
mov edi,0B8000h ; point to screen
mov cx,160 ; just two lines
mov ah,1Eh ; yellow on blue screen attrib
myloop:
mov al,fs:[esi] ; read ROM byte
mov fs:[edi],ax ; store to screen with attribute
inc esi ; increment source ptr
inc edi ; increment dest ptr by two
inc edi ;
loop myloop ; keep going
ret ; and quit
fillscreen endp
;----------------------------------------------------------------------
flatmode proc
; first, calculate the linear address of GDT
xor edx,edx ; clear edx
xor eax,eax ; clear edx
mov dx,ds ; get the data segment
shl edx,4 ; shift it over a bit
add dword ptr [gdt+2],edx ; store as GDT linear base addr
; now load the GDT into the GDTR
lgdt fword ptr gdt ; load GDT base (286-style 24-bit load)
mov bx,1 * size DESC386 ; point to first descriptor
mov eax,cr0 ; prepare to enter protected mode
or al,1 ; flip the PE bit
cli ; turn off interrupts
mov cr0,eax ; we're now in protected mode
mov fs,bx ; load the FS segment register
and al,0FEh ; clear the PE bit again
mov cr0,eax ; back to real mode
sti ; resume handling interrupts
ret ;
flatmode endp
;----------------------------------------------------------------------
GDT DESC386 ; the GDT itself
DESC386 ; 4G data segment
GDT_END:
end start
-+--- flatmode.asm ends
Ed
-!-
---
---------------
* Origin: The Circuit! Board * Spokane * (1:346/100)
|