real to protected_mode
DESCRIPTION
TRANSCRIPT
04/10/23 Protected Mode Assignment 1
Switching from Real to Protected Mode
• Programme Assignments
• Define Global Descriptor Table
• Main Programme Body
0000h
4Gb
x00h
04/10/23 Protected Mode Assignment 2
Programme Assignments
.386p
Code segment use16
Assume cs: code , ss: stackrealadd dd 0taskadd dd 0
msg0 db ‘ in Real Mode ‘,0msg1 db ‘ in Protected Model Mode ‘,0msg2 db ‘ Back in Real Mode ‘,0msg3 db ‘ < Your own declarations> ‘,0
x00h
04/10/23 Protected Mode Assignment 3
Define Global Descriptor Table
Code Segment cs_32
Data Segment ds_32
Extra Segment es_32
04/10/23 Protected Mode Assignment 4
Define Global Descriptor Table
<Code Segment cs_32>------------------------------------------------------------------------------------------cs_32: ; 08h -----------------------------------------------------------------------------
dw 0ffffh ; segment Limitc1: dw 00h ; Base Address 15:00c2: db 00h ; Base Address 23:16
db 09Ah : b ’1001 1010’db 00h ; b ‘ 0000 0000’
C3 db 00h ; Base Address 24:31---------------------------------------------------------------------------------------------
04/10/23 Protected Mode Assignment 5
Define Global Descriptor Table
<Extra Segment es_32>------------------------------------------------------------------------------------------es_32: ; 10h------------------------------------------------------------------------------------------
dw 0ffffh ; segment Limite1: dw 8000h ; Base Address 15:00e2: db 0bh ; Base Address 23:16
db 092h : b ’1001 1010’db 00h ; b ‘ 0000 0000’
e3 db 00h ; Base Address 24:31---------------------------------------------------------------------------------------------
04/10/23 Protected Mode Assignment 6
Define Global Descriptor Table
<Data Segment ds_32>------------------------------------------------------------------------------------------ds_32: ; 18h------------------------------------------------------------------------------------------
dw 0ffffh ; segment Limitd1: dw 0000h ; Base Address 15:00d2: db 00h ; Base Address 23:16
db 092h : b ’1001 1010’db 00h ; b ‘ 0000 0000’
d3 db 00h ; Base Address 24:31---------------------------------------------------------------------------------------------
04/10/23 Protected Mode Assignment 7
Global Descriptor Table
x00h
cs_32
es_32
ds_32
gdt_Start
cs_32(08h)
es_32(10h)
ds_32(18h)
gdt_End
Null Desc(0h)
04/10/23 Protected Mode Assignment 8
Global Descriptor Table
x00h
gdt_start:cs_32:es_32:ds_32:
gdt_end:
gdt_reg label fwordgdt_limit dw gdt_end - gdt_startgdt_base dd 0
cs_32(08h)
es_32(10h)
ds_32(18h)
gdt_End
Null Desc(0h)
gdt_Start
04/10/23 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:
04/10/23 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
04/10/23 Protected Mode Assignment 11
Display Some Message (Graphics Mode)
ax = cslea si, realaddmov word ptr [si+2],axlea ax,[rmd]mov word ptr [si],ax
pm:
rmd:
04/10/23 Protected Mode Assignment 12
Set up Global Descriptor Tableax = cseax << axebx << eaxebx << 4 ; Address is 20 bitseax = ebx
c1 = d1 = axeax >> 16 ; Shift Right by 16
d2 = c2 = ald3 = c3 = ah----------------------------------------------------------------------
c1 , d1
c2 d2c3 , d3
04/10/23 Protected Mode Assignment 13
Load Global Descriptor Table Register
----------------------------------------------------------------------------------eax = ax = cseax << 4ebx << bx = gdt_Startebx = eax + ebxcs:gdt_Base = ebxlgdt cs:gdtreg
04/10/23 Protected Mode Assignment 14
Switch To Protected Mode
cr0<PE> = 1{
eax = cr0or al,01cr0 = eax
}
jump to Protected Mode
pm:es = 10ds = 18
display as before using si di
pm:
rmd:
04/10/23 Protected Mode Assignment 15
Switch To Protected Mode
cr0<PE> = 1{
eax = cr0or al,01
` cr0 = eax}
db oeahdw pmdw 08h
pm:es = 10ds = 18
display as before using si di
pm:
rmd:
04/10/23 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: