hi
can anyone plz give me example code and information on how to go back to real mode from protected mode and also how to get into unreal mode.
if you could also give me links to online documentation dat explain it well would be a help 2.
thnx
back to real and unreal mode
-
Guest
Re:back to real and unreal mode
so far ivae got the follwong code to switch bak to real mode, but i think it has erros init it, and my assembly is not 2 god so can nebody plz help?
[BITS 32]
segment .text
[global _RealMode]
; Begin Real Mode Switch
_RealMode:
cli ; Disable Interupts
jmp word 0x8765:0x4321 ; 32 to 16 bit
dec ax ; Switch back to real mode
mov cr0, eax
sti ; Enable Interupts
ret
; End Real Mode Switch
[BITS 32]
segment .text
[global _RealMode]
; Begin Real Mode Switch
_RealMode:
cli ; Disable Interupts
jmp word 0x8765:0x4321 ; 32 to 16 bit
dec ax ; Switch back to real mode
mov cr0, eax
sti ; Enable Interupts
ret
; End Real Mode Switch
-
jrfritz
Re:back to real and unreal mode
Here:
mov al, <Your GDT Code Sel Here> ;Selector for 4Gb data seg
mov ds, ax ;{2} Extend limit for ds
mov es, ax ;Extend limit for es
dec cx ;Switch back to real mode
mov CR0, ecx ;{5}
Actually...this is real mode with 4GB data...but it lets you have interrupts...and when you want to go back to PMode...I have code for that too...since you can't reenter just the same way...
I THINK this is unreal mode....
mov al, <Your GDT Code Sel Here> ;Selector for 4Gb data seg
mov ds, ax ;{2} Extend limit for ds
mov es, ax ;Extend limit for es
dec cx ;Switch back to real mode
mov CR0, ecx ;{5}
Actually...this is real mode with 4GB data...but it lets you have interrupts...and when you want to go back to PMode...I have code for that too...since you can't reenter just the same way...
I THINK this is unreal mode....
-
Turdus
Re:back to real and unreal mode
Well, unreal is simple real mode with 4GB segments. None of recent processors have real real mode; they emulate them by special 64k GDT entries. If you change that entries, you'll have unreal mode.
For real mode, it's a bit difficult: you have to fill up PIC registers correct real mode values, and GDT with correct entries.
Protmode code segment:
db 66h, 0eah, Back, RealCS
Real Mode segment (RealCS):
Back:
cli
mov ax, RealDS ; switch back to real mode
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov eax, CR0
and al, not 9
mov CR0, eax
jmp far RealSeg, realcs ; load real mode segment into cs
realcs: xor ax, ax
mov ss, ax
mov sp, 1000h
call RestoreIDT
call RestorePIC
RestoreIDT uses lidt to load previously saved state into idt register.
RestoreIDT Proc
lidt Real_IDT_Value
ret
RestoreIDT Endp
RestorePIC does the same:
RestorePIC Proc
push ax dx
mov dx, 0870h ; IRQ -> int 08h, 70h
call SetPIC
mov al, Old_Mask0 ; restore old values
out 21h, al
mov al, Old_Mask1
out 0a1h, al
in al, 60h ; read from keyboard to desire PIC
pop dx ax
ret
RestorePIC Endp
The SetPIC procedure:
SetPIC Proc
; reallocation of IRQ 0-7. hardware interrupts
mov al, 10001b ; ICW1 Bit 0: in PC ICW4 required too
out 20h, al
mov al, dh ; ICW2: new base address of master IRQs
out 21h, al
mov al, 100b ; ICW3: master+slave: irq 2
out 21h, al
mov al, 1 ; ICW4: Bit 0: indicates 8086 mode
out 21h, al ; Bit 1: EOI (0=non automatic)
; IRQ 8-15. hardware interrupts
mov al, 10001b ; ICW1
out 0a0h, al
mov al, dl ; ICW2: new address of slave IRQs
out 0a1h, al
mov al, 10b ; ICW3: master+slave: irq 9
out 0a1h, al
mov al, 1 ; ICW4
out 0a1h, al
ret
SetPIC Endp
That's all
Turdus, developer os OS/42
For real mode, it's a bit difficult: you have to fill up PIC registers correct real mode values, and GDT with correct entries.
Protmode code segment:
db 66h, 0eah, Back, RealCS
Real Mode segment (RealCS):
Back:
cli
mov ax, RealDS ; switch back to real mode
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov eax, CR0
and al, not 9
mov CR0, eax
jmp far RealSeg, realcs ; load real mode segment into cs
realcs: xor ax, ax
mov ss, ax
mov sp, 1000h
call RestoreIDT
call RestorePIC
RestoreIDT uses lidt to load previously saved state into idt register.
RestoreIDT Proc
lidt Real_IDT_Value
ret
RestoreIDT Endp
RestorePIC does the same:
RestorePIC Proc
push ax dx
mov dx, 0870h ; IRQ -> int 08h, 70h
call SetPIC
mov al, Old_Mask0 ; restore old values
out 21h, al
mov al, Old_Mask1
out 0a1h, al
in al, 60h ; read from keyboard to desire PIC
pop dx ax
ret
RestorePIC Endp
The SetPIC procedure:
SetPIC Proc
; reallocation of IRQ 0-7. hardware interrupts
mov al, 10001b ; ICW1 Bit 0: in PC ICW4 required too
out 20h, al
mov al, dh ; ICW2: new base address of master IRQs
out 21h, al
mov al, 100b ; ICW3: master+slave: irq 2
out 21h, al
mov al, 1 ; ICW4: Bit 0: indicates 8086 mode
out 21h, al ; Bit 1: EOI (0=non automatic)
; IRQ 8-15. hardware interrupts
mov al, 10001b ; ICW1
out 0a0h, al
mov al, dl ; ICW2: new address of slave IRQs
out 0a1h, al
mov al, 10b ; ICW3: master+slave: irq 9
out 0a1h, al
mov al, 1 ; ICW4
out 0a1h, al
ret
SetPIC Endp
That's all
Turdus, developer os OS/42
Re:back to real and unreal mode
..
Last edited by Perica on Sun Dec 03, 2006 8:44 pm, edited 1 time in total.
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:back to real and unreal mode
hmm, it will work, but why bothering yourself with something that complicated while a simple
would also work ?
and, for the efficience, i would not worry too much because mov CRx,<reg> is not pairable and is a serializing (flushes pipe-line) instruction, iirc.
Code: Select all
mov eax,cr0
and al,0xFE
mov cr0,eax
and, for the efficience, i would not worry too much because mov CRx,<reg> is not pairable and is a serializing (flushes pipe-line) instruction, iirc.
-
distantvoices
- Member

- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:back to real and unreal mode
one question:
Why bothering about going back to (un)real mode? Except for bios ints?
It would simplify the things a little bit, if one didn't bother about THAT in first time.
Just my opinion
ad Perica: I wonder how you ENTER protected mode *dg*
Why bothering about going back to (un)real mode? Except for bios ints?
It would simplify the things a little bit, if one didn't bother about THAT in first time.
Just my opinion
ad Perica: I wonder how you ENTER protected mode *dg*
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
