PML4 Confusion

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
User avatar
os.hacker64
Member
Member
Posts: 149
Joined: Mon Feb 11, 2008 4:43 pm
Location: Limbo City,Afterlife

PML4 Confusion

Post by os.hacker64 »

I'm having a little trouble with the PML4. I seem to be unable to RTFM an GTFI on the PML4. Can someone point me to some kind info on setting PML4 up?


PS. I STFW 8)
exkor
Member
Member
Posts: 111
Joined: Wed May 23, 2007 9:38 pm

Post by exkor »

Sounds like you are not familiar with paging at all. Then any Protected Mode tutorial will be good for you.

Anyway, since you are hacker you should understand assembly at least a little

Code: Select all

use32
PMode32:
  mov  eax, data_selector      ;load 4GB data descriptor
  xor  ecx, ecx
  mov  ds, ax             ;to almost all segment registers
  mov  es, ax
  mov  ss, ax
  mov  fs, cx
  mov  gs, cx

  mov  eax, cr4
  or   eax, 1 shl 5
  mov  cr4, eax           ;enable PAE

  ;clear all 4 tables(PML4,PDP,PD,PT)
  xor  eax, eax
  mov  edi, 100000h
  mov  ecx, 512*8         ;512 entries in one table
  rep  stosd              ;write dwords

  ;PML4 located at 100000h
  ;PDP  located at 101000h
  ;Page-Directory at 102000h
  ;Page-table not required since we map 2MB pages

  mov  dword [100000h], 101000h + 111b          ;1st PML4 Entry points to PDP table
  mov  dword [101000h], 102000h + 111b          ;1st PDP Entry points to PD table
  mov  dword [102000h+8*0], 0h + 110000111b      ;1st PD Entry points to 0MB
  mov  dword [102000h+8*1], 200000h + 110000011b ;2nd PD Entry points to 2MB 
  mov  dword [102000h+8*2], 400000h + 110000011b ;3rd PD Entry points to 4MB 

  ;          addr + entry #   memory(page)     permissions
  mov  dword [102000h+8*3],   600000h      +   110000011b


  mov  eax, 100000h
  mov  cr3, eax           ;load PML4 base
  mov  ecx, 0C0000080h    ;EFER MSR
  rdmsr
  or   eax, 1 shl 8       ;enable long mode
  wrmsr
  mov  eax, cr0
  or   eax, 1 shl 31      ;enable paging
  mov  cr0, eax

  jmp  code64_selector:LongMode                                            

use64
LongMode:
User avatar
os.hacker64
Member
Member
Posts: 149
Joined: Mon Feb 11, 2008 4:43 pm
Location: Limbo City,Afterlife

Post by os.hacker64 »

In fact I'm writing my entire kernel in asm. :D

Thanks!
User avatar
os.hacker64
Member
Member
Posts: 149
Joined: Mon Feb 11, 2008 4:43 pm
Location: Limbo City,Afterlife

Post by os.hacker64 »

I'm still a little confused here though as your code uses actual numerical addresses to setup paging. :?
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:

Post by Combuster »

The entire paging method is described in the intel manual. Assuming that you have indeed RTFMed, what do you not understand about it?
"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 ]
exkor
Member
Member
Posts: 111
Joined: Wed May 23, 2007 9:38 pm

Re: PML4 Confusion

Post by exkor »

os.hacker64 wrote: Can someone point me to some kind info on setting PML4 up?
PS. I STFW 8)
I doubt such tutorial exists simply because pml4 follows same rules as other tables.

Like combuster said be specific in your questions.
I mapped physical & virtual spaces as 1 to 1 (virtual mem addr corresponds to same physical addr). Code written using Fasm syntax. Processor(in its mind) will clear permissions(flags) bits when its time to use the page. Each entry in any table is 8 baits.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

I set my 64 bit paging up using a combination of my existing 32 bit paging functions and this page.

Cheers,
Adam
User avatar
os.hacker64
Member
Member
Posts: 149
Joined: Mon Feb 11, 2008 4:43 pm
Location: Limbo City,Afterlife

Post by os.hacker64 »

When I get back from school I'll explain paging here for myself, I hope you can find some errors...
Kanu Operating System
Working on:Paging and Multitasking

BURN /\/\1(40$0|=7
Post Reply