unreal mode

Programming, for all ages and all languages.
dileep
Posts: 13
Joined: Tue Feb 28, 2012 11:31 pm

unreal mode

Post by dileep »

Hi guys , below the code , that i am using to switch in to the unreal mode.

Code: Select all

DESCRIPTOR struct
    segment_limit_0_15   dw  ?
    base_addr_0_15       dw  ?
    base_addr_16_23      db  ?
    segment_properties   db  ?
    seg_limit_16_19_gran db  ?
    base_addr_24_31      db  ?
DESCRIPTOR ends

gstart  label  qword

nullDescriptor          DESCRIPTOR    <0,0,0,0,0,0>
code16Descriptor        DESCRIPTOR    <0ffffh,0000,00,9Fh,00h,00>
code32Descriptor        DESCRIPTOR    <0ffffh,0000,00,9Fh,08Fh,00>
data16Descriptor        DESCRIPTOR    <0ffffh,0000,00,93h,00h,00>
Stack16Descriptor       DESCRIPTOR    <0ffffh,0000,00,93h,00h,00>
bigData16Descriptor     DESCRIPTOR    <0ffffh,0000,00,92h,0CFh,00>

gend label qword

gbase label     fword
limit dw   gend-gstart-1     ;limit
addr  dd    ?

 
org_gdt label fword
orig_gdt_limit      dw  0000h     
orig_gdt_addr       dd  00000000h 

unrealmode proc
    push eax
    push ebx
    push ds
    push es
    push fs
    push gs
	
    db  66h
    sgdt fword ptr cs:org_gdt
   
    xor eax,  eax
    mov ax, cs
    shl eax, 4
    add eax, offset gstart
    mov dword ptr cs:[addr], eax

    pushf
    cli

    mov bx, bigData16Descriptor - gstart	
    lgdt    fword ptr cs:[gbase]
	
     
    mov eax, cr0
    or  al, 1    
    mov cr0,eax
 
    mov ds, bx
    mov es, bx
   
    mov eax, cr0
    and al,  0FEh
    mov cr0, eax

     nop
    db 66h
    lgdt cs:orig_gdt

     popf 
      pop gs
    pop fs
    pop es
    pop ds
    pop ebx
    pop eax
    ret
unrealmode endp		
While setting PE bit in CR0 the system reboots.
Can anyone help me in this.?
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: unreal mode

Post by JAAman »

i fixed your post for now, but in the future, please use code tags
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: unreal mode

Post by bluemoon »

This is going to be an FAQ...

1. Check your ORG, make sure you have correct address for LGDT
2. You don't need to restore descriptors in real mode, you can simply mov values to the segment registers.
3. If your CS is nonzero, your ip will be relative to that segment, once you enter protected mode you need to make sure CS:EIP points to same place. You either use zero CS with flat descriptor at the beginning; or for non-zero CS you need to tweak the code descriptor's base.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: unreal mode

Post by Combuster »

There's not even a start to that code in general. Where's the rest? How do you build and run it? Most errors at this stage are caused by a wrong environment, as bluemoon detailed.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
dileep
Posts: 13
Joined: Tue Feb 28, 2012 11:31 pm

Re: unreal mode

Post by dileep »

actually this code is part of pxe option ROM driver. i burnt this driver image into network card , while the system is coming up it will load this driver and will call this procedure to switch into unreal mode.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: unreal mode

Post by Combuster »

Still not even close to being able to reproduce the problem.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
dileep
Posts: 13
Joined: Tue Feb 28, 2012 11:31 pm

Re: unreal mode

Post by dileep »

Do i need to handle IDT while switching to unreal mode?
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: unreal mode

Post by Love4Boobies »

Not if you have IRQs disabled during the short trip to protected mode.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
dileep
Posts: 13
Joined: Tue Feb 28, 2012 11:31 pm

Re: unreal mode

Post by dileep »

Still i am facing the same issue. Can anyone help me in this?
I am calling this proc from int18h handler context.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: unreal mode

Post by Solar »

Combuster wrote:Still not even close to being able to reproduce the problem.
Every good solution is obvious once you've found it.
dileep
Posts: 13
Joined: Tue Feb 28, 2012 11:31 pm

Re: unreal mode

Post by dileep »

Is there any way to register a handler for the triple fault exception?
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: unreal mode

Post by Love4Boobies »

Nope; just for double faults. Then again, you don't even need that.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
dileep
Posts: 13
Joined: Tue Feb 28, 2012 11:31 pm

Re: unreal mode

Post by dileep »

Hi,

On some systems i am able to access 32bit offset without changing to unreal mode and not in other systems.
This is because some systems are left in unreal mode always.

So i registered #GPF handler and switching to unreal mode only when the handler invoked. Things worked fine.

Is it okay to use our own #GPF handler?

why does this work on some machines and not others? Are they already in unreal mode, left that way by the BIOS?
Is there any way to check whether processor is in unreal mode or not?

Thanks in adv
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: unreal mode

Post by Solar »

dileep wrote:Is it okay to use our own #GPF handler?
Uh... which one have you been using so far?
Every good solution is obvious once you've found it.
dileep
Posts: 13
Joined: Tue Feb 28, 2012 11:31 pm

Re: unreal mode

Post by dileep »

I hadn't used GPF handler previously. i was trying to switch in to unreal mode before accessing 32 bit offset.
Post Reply