switching from real to protected in assembly

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Ninjarider
Member
Member
Posts: 62
Joined: Fri Jun 29, 2007 8:36 pm

switching from real to protected in assembly

Post by Ninjarider »

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
Last edited by Ninjarider on Sun Jul 15, 2007 3:47 pm, edited 1 time in total.
niteice
Member
Member
Posts: 59
Joined: Tue Oct 03, 2006 3:49 pm

Post by niteice »

You sure it's cr0 and nor cro?
Ninjarider
Member
Member
Posts: 62
Joined: Fri Jun 29, 2007 8:36 pm

Post by Ninjarider »

its suppose to be cr0 that was a mistype.
i know its cr0 because it assembles correct and doesn't give me and invalid operand.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Do you do something like this in you original ?

Code: Select all

lgdt  [source]
And do you disable int ?
Last edited by Dex on Sun Jul 15, 2007 4:51 pm, edited 1 time in total.
exkor
Member
Member
Posts: 111
Joined: Wed May 23, 2007 9:38 pm

Post by exkor »

Why don't you go with some template for PM switching there are plenty out there. And maybe static GDT.

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
1234
Posts: 24
Joined: Sat May 26, 2007 7:58 pm

Post by 1234 »

[post deleted]
Last edited by 1234 on Wed Nov 21, 2007 5:25 pm, edited 1 time in total.
Ninjarider
Member
Member
Posts: 62
Joined: Fri Jun 29, 2007 8:36 pm

Post by Ninjarider »

i do diable interrupts.

i will try a static gdt when i get home
Post Reply