1. 01/29/15 Protected Mode Assignment 1
Switching from Real to Protected Mode
• Programme Assignments
• Define Global Descriptor Table
• Main Programme Body
0000h
4Gb
x00h
2. 01/29/15 Protected Mode Assignment 2
Programme Assignments
.386p
Code segment use16
Assume cs: code , ss: stack
realadd dd 0
taskadd dd 0
msg0 db ‘ in Real Mode ‘,0
msg1 db ‘ in Protected Model Mode ‘,0
msg2 db ‘ Back in Real Mode ‘,0
msg3 db ‘ < Your own declarations> ‘,0
x00h
3. 01/29/15 Protected Mode Assignment 3
Define Global Descriptor Table
Code Segment cs_32
Data Segment ds_32
Extra Segment es_32
4. 01/29/15 Protected Mode Assignment 4
Define Global Descriptor Table
<Code Segment cs_32>
------------------------------------------------------------------------------------------
cs_32: ; 08h
-----------------------------------------------------------------------------
dw 0ffffh ; segment Limit
c1: dw 00h ; Base Address 15:00
c2: db 00h ; Base Address 23:16
db 09Ah : b ’1001 1010’
db 00h ; b ‘ 0000 0000’
C3 db 00h ; Base Address 24:31
---------------------------------------------------------------------------------------------
5. 01/29/15 Protected Mode Assignment 5
Define Global Descriptor Table
<Extra Segment es_32>
------------------------------------------------------------------------------------------
es_32: ; 10h
------------------------------------------------------------------------------------------
dw 0ffffh ; segment Limit
e1: dw 8000h ; Base Address 15:00
e2: db 0bh ; Base Address 23:16
db 092h : b ’1001 1010’
db 00h ; b ‘ 0000 0000’
e3 db 00h ; Base Address 24:31
---------------------------------------------------------------------------------------------
6. 01/29/15 Protected Mode Assignment 6
Define Global Descriptor Table
<Data Segment ds_32>
------------------------------------------------------------------------------------------
ds_32: ; 18h
------------------------------------------------------------------------------------------
dw 0ffffh ; segment Limit
d1: dw 0000h ; Base Address 15:00
d2: db 00h ; Base Address 23:16
db 092h : b ’1001 1010’
db 00h ; b ‘ 0000 0000’
d3 db 00h ; Base Address 24:31
---------------------------------------------------------------------------------------------
9. 01/29/15 Protected Mode Assignment 9
Main Programme Body
Begin:
Display Some Message (Graphics Mode)
Set up Global Descriptor Table
Load Global Descriptor Table Register
Switch to Protected Mode
Jump to Protected Mode
Display Message
Switch to Real Mode
Exit:
pm:
rmd:
10. 01/29/15 Protected Mode Assignment 10
Display Some Message (Graphics Mode)
Graphics Display B800h
es = B800
ds = cs
clear screen
si = msg0
di = (80 * Lines(hor) ) * 2
cx = length of Msg
Loop es: [di] = al = [si]
inc si ; inc di
loop cx
11. 01/29/15 Protected Mode Assignment 11
Display Some Message (Graphics Mode)
ax = cs
lea si, realadd
mov word ptr [si+2],ax
lea ax,[rmd]
mov word ptr [si],ax
pm:
rmd:
12. 01/29/15 Protected Mode Assignment 12
Set up Global Descriptor Table
ax = cs
eax << ax
ebx << eax
ebx << 4 ; Address is 20 bits
eax = ebx
c1 = d1 = ax
eax >> 16 ; Shift Right by 16
d2 = c2 = al
d3 = c3 = ah
----------------------------------------------------------------------
c1 , d1
c2 d2c3 , d3
14. 01/29/15 Protected Mode Assignment 14
Switch To Protected Mode
cr0<PE> = 1
{
eax = cr0
or al,01
cr0 = eax
}
jump to Protected Mode
pm:
es = 10
ds = 18
display as before using si di
pm:
rmd:
15. 01/29/15 Protected Mode Assignment 15
Switch To Protected Mode
cr0<PE> = 1
{
eax = cr0
or al,01
` cr0 = eax
}
db oeah
dw pm
dw 08h
pm:
es = 10
ds = 18
display as before using si di
pm:
rmd:
16. 01/29/15 Protected Mode Assignment 16
Main Programme Body
CR0<PE> = 0
jmp dword ptr realadd
rmd:
Display Data in Real Mode
Exit using int 21(4ch)
pm:
rmd: