Paging Triple Fault
I had a similar problem come up when using James' tutorials. It turns out that the problem is solved in the download-able version of the code.
Change this:
To this:
The extra 0x1000 is needed, probably because the kernel "leaks" slightly over the last page boundary. (the 0x1000 simply "rounds up" the number of pages so that you are guaranteed to have enough pages.)
Change this:
Code: Select all
int idx = 0;
while (idx < placement_address) {
/* Kernel code is readable but not writeable from userspace */
allocate_frame(get_page(idx, 1, kernel_directory), 0, 0);
idx += 0x1000;
}
Code: Select all
int idx = 0;
while (idx < placement_address + 0x1000) {
/* Kernel code is readable but not writeable from userspace */
allocate_frame(get_page(idx, 1, kernel_directory), 0, 0);
idx += 0x1000;
}
- zaleschiemilgabriel
- Member
- Posts: 232
- Joined: Mon Feb 04, 2008 3:58 am
- gzaloprgm
- Member
- Posts: 141
- Joined: Sun Sep 23, 2007 4:53 pm
- Location: Buenos Aires, Argentina
- Contact:
Jeremiah, this must work with your kernel.
That function (from osdever) works in my kernel and maps 0-4MB virtual to 0-4MB physical.
Hope it helps to you.
Gonzalo
Code: Select all
unsigned long *page_directory;
unsigned long *page_table;
void map(unsigned int frame, unsigned int vframe){
page_table[frame] = vframe*4096 | 3;
}
int init_paging(){
page_directory = (unsigned long *) kmalloc_a(4096);
page_table = (unsigned long *) kmalloc_a(4096);
unsigned int i;
for(i=0; i<1024; i++){
map(i,i);
};
page_directory[0] = (unsigned long)page_table;
page_directory[0] = page_directory[0] | 3;
for(i=1; i<1024; i++){
page_directory[i] = 0 | 2;
};
write_cr3(page_directory);
write_cr0(read_cr0() | 0x80000000);
return 0;
}
Code: Select all
[global read_cr0]
read_cr0:
mov eax, cr0
retn
[global write_cr0]
write_cr0:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov cr0, eax
pop ebp
retn
[global write_cr3]
write_cr3:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov cr3, eax
pop ebp
retn
Hope it helps to you.
Gonzalo