Page 1 of 1

Page Setup

Posted: Mon Sep 09, 2002 7:26 am
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.

Re:Page Setup

Posted: Mon Sep 09, 2002 7:55 am
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 ...

Re:Page Setup

Posted: Mon Sep 09, 2002 7:57 am
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?

Re:Page Setup

Posted: Tue Sep 10, 2002 6:48 am
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.