ok. using a .386p
theres a struct for Desc and a struct for table reg
temp_gdt_null_desc is a Desc
temp_gdt_scratch is a table_reg
the following code has a 66h proceding it
mov ebx, offset temp_gdt
mov dword ptr [ebx], 0
mov dword ptr [ebx] + 4, 0
mov dword ptr [ebx] + 8, Linear_Proto_hi //0000ffffh
mov dword ptr [ebx] + 12, linear_proto_lo //000cf9200h
mov temp_gdt_scratch.table_linear, ebx
mov temp_gdt_scratch.table_lim, 15
lgdt temp_gdt_scratch
mov ebx, cr0 // is not lead by a 66h
or ebx, 1
mov cr0, ebx ///////////// for some reason when it executes this line the computer reboots
switching from real to protected in assembly
-
- Member
- Posts: 62
- Joined: Fri Jun 29, 2007 8:36 pm
switching from real to protected in assembly
Last edited by Ninjarider on Sun Jul 15, 2007 3:47 pm, edited 1 time in total.
-
- Member
- Posts: 62
- Joined: Fri Jun 29, 2007 8:36 pm
Do you do something like this in you original ?
And do you disable int ?
Code: Select all
lgdt [source]
Last edited by Dex on Sun Jul 15, 2007 4:51 pm, edited 1 time in total.
Why don't you go with some template for PM switching there are plenty out there. And maybe static GDT.
Example, Fasm:
and you'll need to disable interupts
Example, Fasm:
Code: Select all
macro descr name, lim1, limit, pDPLs, type, gDBavl, base{
.#name#.sel = (($-GDT)/8) shl 3
.#name: dw limit
.#name#.base3 dw (base) and 0ffffh
.#name#.base2 db ((base) shr 16) and 0ffh
.#name#.flags2: db pDPLs#type#b
.#name#.flags1: db gDBavl#lim1#b
.#name#.base1 db (base) shr 24
}
align 8
GDT:
dq 0 ; L
; [ LIMIT ][PDLS TYPE] GD0A BASE
descr data, 1111,0ffffh, 1001, 0010, 1100, 0
descr code, 1111,0ffffh, 1001, 1010, 1100, 0
descr code64, 1111,0ffffh, 1001, 1010, 1010, 0
.reg:
.limit dw $-GDT-1
.addr dq GDT
use16
lgdt [cs:GDT.reg] ; load GDT
mov eax, cr0
or al, 1 ; set PE flag
mov cr0, eax ; enable protected mode
jmp GDT.code.sel:PMode32 ; jump to protected mode segment
use32
PMode32:
mov eax, GDT.data.sel ; load 4 GB data descriptor
mov ds,ax ; to all data segment registers
and you'll need to disable interupts
-
- Member
- Posts: 62
- Joined: Fri Jun 29, 2007 8:36 pm