Hi guys,
I've been following a tutorial ( see below for link ) about making my own os. I got to the Multitasking section and compiling and linking goes fine throughout it all.
But when it comes to firing up bochs, it spits out a page fault error. I've never had to deal with these before and I haven't got a clue how to fix it :L
here's what I get from my compiler after I add the -Wall flag to my makefile:
Code:
nasm -felf asem/boot.s -o obj/boot.o
nasm -felf asem/interrupt.s -o obj/interrupt.o
nasm -felf asem/gdt.s -o obj/gdt.o
nasm -felf asem/process.s -o obj/process.o
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/main.c -o obj/main.o
source/main.c:19:5: warning: first argument of ‘main’ should be ‘int’
source/main.c:19:5: warning: second argument of ‘main’ should be ‘char **’
source/main.c: In function ‘main’:
source/main.c:81:4: warning: pointer targets in passing argument 4 of ‘read_fs’ differ in signedness
headers/fs.h:58:8: note: expected ‘u8int *’ but argument is of type ‘char *’
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/monitor.c -o obj/monitor.o
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/common.c -o obj/common.o
source/common.c: In function ‘strcat’:
source/common.c:80:22: warning: operation on ‘dest’ may be undefined
source/common.c: In function ‘panic’:
source/common.c:104:5: warning: implicit declaration of function ‘monitor_write’
source/common.c:109:5: warning: implicit declaration of function ‘monitor_write_dec’
source/common.c: In function ‘strcpy’:
source/common.c:72:1: warning: control reaches end of non-void function
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/descriptor_tables.c -o obj/descriptor_tables.o
source/descriptor_tables.c: In function ‘init_descriptor_tables’:
source/descriptor_tables.c:43:5: warning: implicit declaration of function ‘memset’
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/isr.c -o obj/isr.o
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/timer.c -o obj/timer.o
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/kheap.c -o obj/kheap.o
source/kheap.c: In function ‘expand’:
source/kheap.c:76:5: warning: suggest parentheses around comparison in operand of ‘&’
source/kheap.c:91:9: warning: implicit declaration of function ‘alloc_frame’
source/kheap.c: In function ‘contract’:
source/kheap.c:118:9: warning: implicit declaration of function ‘free_frame’
source/kheap.c: In function ‘find_smallest_hole’:
source/kheap.c:139:13: warning: suggest parentheses around comparison in operand of ‘&’
source/kheap.c: In function ‘create_heap’:
source/kheap.c:177:5: warning: suggest parentheses around comparison in operand of ‘&’
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/paging.c -o obj/paging.o
source/paging.c: In function ‘initialise_paging’:
source/paging.c:118:5: warning: implicit declaration of function ‘memset’
source/paging.c:121:12: warning: unused variable ‘phys’
source/paging.c: In function ‘page_fault’:
source/paging.c:220:5: warning: implicit declaration of function ‘monitor_write’
source/paging.c:226:5: warning: implicit declaration of function ‘monitor_write_hex’
source/paging.c:217:9: warning: unused variable ‘id’
source/paging.c: In function ‘clone_table’:
source/paging.c:257:2: warning: implicit declaration of function ‘copy_page_physical’
source/paging.c: At top level:
source/paging.c:44:15: warning: ‘test_frame’ defined but not used
source/paging.c: In function ‘first_frame’:
source/paging.c:71:1: warning: control reaches end of non-void function
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/ordered_array.c -o obj/ordered_array.o
source/ordered_array.c: In function ‘create_ordered_array’:
source/ordered_array.c:15:5: warning: implicit declaration of function ‘kmalloc’
source/ordered_array.c:16:5: warning: implicit declaration of function ‘memset’
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/fs.c -o obj/fs.o
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/initrd.c -o obj/initrd.o
source/initrd.c: In function ‘initrd_read’:
source/initrd.c:22:5: warning: implicit declaration of function ‘memcpy’
source/initrd.c: In function ‘initrd_readdir’:
source/initrd.c:30:7: warning: implicit declaration of function ‘strcpy’
source/initrd.c:39:5: warning: implicit declaration of function ‘strlen’
source/initrd.c: In function ‘initrd_finddir’:
source/initrd.c:47:9: warning: implicit declaration of function ‘strcmp’
source/initrd.c: In function ‘initialise_initrd’:
source/initrd.c:64:5: warning: implicit declaration of function ‘kmalloc’
gcc -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -Iheaders -Wall source/task.c -o obj/task.o
source/task.c: In function ‘initialise_tasking’:
source/task.c:34:5: warning: implicit declaration of function ‘kmalloc’
source/task.c:40:5: warning: implicit declaration of function ‘kmalloc_a’
source/task.c: In function ‘move_stack’:
source/task.c:75:3: warning: implicit declaration of function ‘memcpy’
source/task.c: In function ‘switch_task’:
source/task.c:142:5: warning: implicit declaration of function ‘set_kernel_stack’
ld -Tlink.ld -melf_i386 --oformat=elf32-i386 -o kern/kernel obj/boot.o obj/interrupt.o obj/gdt.o obj/process.o obj/main.o obj/monitor.o obj/common.o obj/descriptor_tables.o obj/isr.o obj/timer.o obj/kheap.o obj/paging.o obj/ordered_array.o obj/fs.o obj/initrd.o obj/task.o
NOTE: I did find out that the first two arguments in the function main ( int and char** ) are meant to be like that.
here's my main.c file:
Code:
// main.c -- Defines the C-code kernel entry point, calls initialisation routines.
// Made for JamesM's tutorials <www.jamesmolloy.co.uk>
char kern_ver[] = "0.01";
#include "monitor.h"
#include "descriptor_tables.h"
#include "timer.h"
#include "paging.h"
#include "multiboot.h"
#include "fs.h"
#include "initrd.h"
#include "task.h"
extern u32int placement_address;
u32int initial_esp;
int main ( struct multiboot *mboot_ptr, u32int initial_stack )
{
initial_esp = initial_stack;
// Initialise all the ISRs and segmentation
init_descriptor_tables();
// Initialise the screen ( by clearing it )
monitor_clear();
// Initialise the PIT to 100Hz
asm volatile ( "sti" );
init_timer ( 50 );
// Find the location of our initial ramdisk.
ASSERT ( mboot_ptr -> mods_count > 0 );
u32int initrd_location = * ( ( u32int * ) mboot_ptr -> mods_addr );
u32int initrd_end = * ( u32int * ) ( mboot_ptr -> mods_addr + 4 );
// Don't trample our module with placement accesses, please!
placement_address = initrd_end;
// Initialise paging
initialise_paging();
// Initialise the initial ramdisk, and set it as the filesystem root.
fs_root = initialise_initrd ( initrd_location );
// Write to screen.
monitor_write ( "urOS Version " );
monitor_write ( kern_ver );
monitor_write ( "\n" );
// Create a new process in a new address space which is a clone of this.
int ret = fork();
monitor_write ( "\n" );
monitor_write ( "fork() returned " );
monitor_write_hex ( ret );
monitor_write ( ", and getpid() returned " );
monitor_write_hex ( getpid() );
monitor_write ( "\n============================================================================\n" );
// The next section of code is not reentrant so make sure we aren't interrupted during.
asm volatile ( "cli" );
// List contents of /
int i = 0;
struct dirent *node = 0;
while ( ( node = readdir_fs ( fs_root, i ) ) != 0 )
{
monitor_write ( "Found file " );
monitor_write ( node -> name );
fs_node_t *fsnode = finddir_fs ( fs_root, node -> name );
if ( ( fsnode -> flags & 0x7 ) == FS_DIRECTORY )
{
monitor_write ( "\n\t( directory )\n" );
}
else
{
monitor_write ( "\n\t contents: \"" );
char buf[256];
u32int sz = read_fs ( fsnode, 0, 256, buf );
int j;
for ( j = 0; j < sz; j++ )
monitor_put ( buf[j] );
monitor_write ( "\"\n" );
}
i++;
}
monitor_write ( "\n" );
asm volatile ( "sti" );
return 0;
}
Any idea's in what could be going wrong and making a page fault?
If you need any other file then just say and I will update the OP.