OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 17, 2024 6:59 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Triple fault after enabling paging
PostPosted: Sun Apr 29, 2018 12:12 am 
Offline
Member
Member

Joined: Fri Apr 13, 2018 10:18 am
Posts: 32
Location: Melbourne, VIC, Australia
Hi,
After enabling paging my kernel will cause a page fault, then a double fault and a triple fault. This is my paging library:
Code:
#include <kernel/paging.h>

uint32_t pageDirectory[1024] __attribute__((aligned(4096)));
uint32_t* pageTable_ID[1024] __attribute__ ((aligned(4096)));
uint32_t* pageTable_Kernel[1024] __attribute__ ((aligned(4096)));

extern void pagingLoadDir(uint32_t* directory);
extern void pagingEnable();

void pagingCalculateAddress(uint32_t vaddr, uint16_t* dirEntry, uint16_t* tableEntry) {
   *dirEntry = vaddr / 4194304;
   *tableEntry = vaddr % 4194304;
}

void pagingFillTable(void* table, uint32_t* address, uint16_t attributes) {
   uint32_t* tablePtr = (uint32_t*) table;
   for(uint16_t i = 0; i < 1024; i++) {
      tablePtr[i] = address;
      tablePtr[i] |= attributes;
      address += 4096;
   }
}

void pagingAddTable(uint16_t entry, void* table, uint16_t attributes) {
   pageDirectory[entry] = table;
   pageDirectory[entry] |= attributes;
}

void pagingInit(void) {
   for(uint16_t i = 0; i < 1024; i++) pageDirectory[i] = 0;
   
   pagingFillTable(pageTable_ID, 0x00000000, 3);
   pagingAddTable(0, pageTable_ID, 3);
   pagingFillTable(pageTable_Kernel, 0x00100000, 3);
   pagingAddTable(768, pageTable_Kernel, 3);
   
   pagingLoadDir((uint32_t) pageDirectory);
   pagingEnable();
}

The full source code is at https://github.com/weedboi6969/puckos. Can someone help me with that?
These are the guides that I used:
http://www.osdever.net/tutorials/view/implementing-basic-paging
https://wiki.osdev.org/Setting_Up_Paging

_________________
Just a procrastinating uni student doing stupid things (or not doing them at all)...

SysX: https://github.com/itsmevjnk/sysx.git


Top
 Profile  
 
 Post subject: Re: Triple fault after enabling paging
PostPosted: Sun Apr 29, 2018 2:55 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
Code:
void pagingFillTable(..., uint32_t* address, ...) {
   ...
   for(...) {
      ...
      address += 4096;
   }
}


Can you spot any problem here?


Top
 Profile  
 
 Post subject: Re: Triple fault after enabling paging
PostPosted: Sun Apr 29, 2018 5:36 am 
Offline
Member
Member

Joined: Fri Apr 13, 2018 10:18 am
Posts: 32
Location: Melbourne, VIC, Australia
alexfru wrote:
Code:
void pagingFillTable(..., uint32_t* address, ...) {
   ...
   for(...) {
      ...
      address += 4096;
   }
}


Can you spot any problem here?

No. What's wrong with it?

_________________
Just a procrastinating uni student doing stupid things (or not doing them at all)...

SysX: https://github.com/itsmevjnk/sysx.git


Top
 Profile  
 
 Post subject: Re: Triple fault after enabling paging
PostPosted: Sun Apr 29, 2018 5:54 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
If you were to single-step through that code in a debugger you would spot the error immediately.


Top
 Profile  
 
 Post subject: Re: Triple fault after enabling paging
PostPosted: Sun Apr 29, 2018 8:27 am 
Offline
Member
Member

Joined: Fri Apr 13, 2018 10:18 am
Posts: 32
Location: Melbourne, VIC, Australia
iansjack wrote:
If you were to single-step through that code in a debugger you would spot the error immediately.

I can see in Bochs that it's causing a page fault and that's it.

_________________
Just a procrastinating uni student doing stupid things (or not doing them at all)...

SysX: https://github.com/itsmevjnk/sysx.git


Top
 Profile  
 
 Post subject: Re: Triple fault after enabling paging
PostPosted: Sun Apr 29, 2018 8:36 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Brush up on pointer arithmetic in C.


Top
 Profile  
 
 Post subject: Re: Triple fault after enabling paging
PostPosted: Sun Apr 29, 2018 9:54 am 
Offline
Member
Member

Joined: Fri Apr 13, 2018 10:18 am
Posts: 32
Location: Melbourne, VIC, Australia
After changing uint32_t* to uint32_t, it works.

_________________
Just a procrastinating uni student doing stupid things (or not doing them at all)...

SysX: https://github.com/itsmevjnk/sysx.git


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 186 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group