Triple fault after enabling paging

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
itsmevjnk
Member
Member
Posts: 32
Joined: Fri Apr 13, 2018 10:18 am
Location: Melbourne, VIC, Australia

Triple fault after enabling paging

Post by itsmevjnk »

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: Select all

#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/i ... sic-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
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: Triple fault after enabling paging

Post by alexfru »

Code: Select all

void pagingFillTable(..., uint32_t* address, ...) {
   ...
   for(...) {
      ...
      address += 4096;
   }
}
Can you spot any problem here?
itsmevjnk
Member
Member
Posts: 32
Joined: Fri Apr 13, 2018 10:18 am
Location: Melbourne, VIC, Australia

Re: Triple fault after enabling paging

Post by itsmevjnk »

alexfru wrote:

Code: Select all

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
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Triple fault after enabling paging

Post by iansjack »

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

Re: Triple fault after enabling paging

Post by itsmevjnk »

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
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Triple fault after enabling paging

Post by iansjack »

Brush up on pointer arithmetic in C.
itsmevjnk
Member
Member
Posts: 32
Joined: Fri Apr 13, 2018 10:18 am
Location: Melbourne, VIC, Australia

Re: Triple fault after enabling paging

Post by itsmevjnk »

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
Post Reply