Page Setup

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
PlayOS

Page Setup

Post by PlayOS »

Hi,

I am using this code below to setup a basic paging environment just to get it started, the code I have works without this stuff in it so I know that somewhere in here is the error, hopefully someone will see the problem.


; Page Directory Address = 0x400000
; Page Table 0 = 0x401000
; Page Table 1 = 0x402000

; Setup Page Directory
   mov      ebx, 0x400000               ; The PageDir Address
   mov      dword [ebx], 0x401003         ; Table 0 Address and Attributes
   add      ebx, 4
   mov      dword [ebx], 0x402003         ; Table 1 Address and Attributes

; Clear other page tables
   mov      cx, 0
   mov      ebx, 0x400008               ; Base Not Used
   mov      eax, 0x02                  ; Attributes Only
ClearDirLoop:
   cmp      cx, 1022
   je      ClearDirDone
   inc      cx
   mov      dword [ebx], eax            ; Setup Next Page
   add      ebx, 4                     ; Next Page Table Entry
   jmp      ClearDirLoop
ClearDirDone:

; Map First 4MB
   mov      cx, 0
   mov      ebx, 0x401000               ; Page Table 0 Base
   mov      eax, 0x00000003               ; Page Address and Attributes
Page4MBLoop:
   cmp      cx, 1024
   je      Page4MBDone
   inc      cx
   mov      dword [ebx], eax            ; Setup Next Page
   add      ebx, 4                     ; Next Page Table Entry
   add      eax, 0x1000                  ; Next Page Address
   jmp      Page4MBLoop
Page4MBDone:

; Map Second 4MB
   mov      cx, 0
   mov      ebx, 0x402000               ; Page Table 1 Base
   mov      eax, 0x00400003               ; Page Address and Attributes
Page8MBLoop:
   cmp      cx, 1024
   je      Page8MBDone
   inc      cx
   mov      dword [ebx], eax            ; Setup Next Page
   add      ebx, 4                     ; Next Page Table Entry
   add      eax, 0x1000                  ; Next Page Address
   jmp      Page8MBLoop
Page8MBDone:   
   
; Install the Pages
   mov      eax, 0x400000
   mov      cr3, eax

; Set PG Bit
   mov      eax, cr0
   or      eax, 0x80000000
   mov      cr0, eax

; Jump into Page World! Tried both of these
   ; jmp      0x08:PageWorld
   jmp      PageWorld

PageWorld:


The error that I get from bochs is with

jmp 0x08:PageWorld is

jump_protected: S=1: descriptor not executable

jmp PageWorld is

3rd exception without resolution

I have interrupts disabled until after this code and the IDT setup code.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Page Setup

Post by Pype.Clicker »

is your data segment 0-based ? if not, remember to align your 0x40.0000 before anything else...

normally, no jump is required after enabling paging ...
PlayOS

Re:Page Setup

Post by PlayOS »

My data segment is definately 0 base.

However I do have ORG = 0x20000 because this is the position I have the code at, would this make a difference?
PlayOS

Re:Page Setup

Post by PlayOS »

I have worked out that as soon as I set the PG bit in cr0 I get an error from bochs that says '3rd exception without resolution' I am still using the code above so if anyone can see the problem, I would appreciate your help.

Thanks.
Post Reply