diff --git a/asmfuncs.asm b/asmfuncs.asm index c3cad80..6aacc23 100644 --- a/asmfuncs.asm +++ b/asmfuncs.asm @@ -45,6 +45,16 @@ _write_cr3: pop ebp ret + +;returns the value in the CR2 register +;extern dword read_cr2(); +[global _read_cr2] +_read_cr2: + mov eax, cr2; + ret + + + ;returns the value in the CR3 register ;extern dword read_cr3(); [global _read_cr3] diff --git a/idt.inc b/idt.inc index fd7a8f9..b3b6d1f 100644 --- a/idt.inc +++ b/idt.inc @@ -5,7 +5,7 @@ idtr: dw 50*8-1 ;size of idt - dd IDT_P ;address of idt + dd IDT_V ;address of idt %macro isr_label 1 @@ -96,6 +96,7 @@ isr_syscall: push ebx call _putc + add esp, 4 pop es pop ds diff --git a/kernel.asm b/kernel.asm index 2b15735..c5d18f6 100644 --- a/kernel.asm +++ b/kernel.asm @@ -16,6 +16,7 @@ [global start] [extern _isr] [extern _k_init] +[extern _putc] bits 32 diff --git a/kernel.c b/kernel.c index a5237f0..2d3d90c 100644 --- a/kernel.c +++ b/kernel.c @@ -27,6 +27,7 @@ void k_init(); extern dword write_cr0(dword cr0); extern dword read_cr0(); extern dword write_cr3(dword cr3); +extern dword read_cr2(); extern dword read_cr3(); extern void writeCursorPosition(dword pos); extern dword getCursorPosition(); @@ -82,21 +83,20 @@ void k_init() printf("Memory available to OS: %u MB (%u bytes)\n", mm_megabytes, mm_totalmem); printf("Free memory: %u bytes (%u pages)\n", mm_freemem(), mm_freemem()>>12); printf("Root Directory: %s/\n", rootDevice->id); - -// int a; -// byte *addr = 0; -// for (a = 0; a < 2; a++) -// { -// byte *app = mm_palloc(); -// vmm_map1((dword)addr, (dword)app); -// addr += 4096; -// } - -// addr = vfs_readFile("/bin/hash.hos"); -// memcpy(0, addr, 8192); -// asm("call 0"); + int a; + byte *addr = 0; + for (a = 0; a < 5; a++) + { + byte *app = mm_palloc(); + vmm_map1((dword)addr, (dword)app); + addr += 4096; + } + addr = vfs_readFile("/bin/hash.hos"); + memcpy(0, addr, 4192); + asm("call 0"); + free(addr); dword key = 0; for (;;) @@ -112,6 +112,10 @@ void isr(dword num) { switch(num) { + case 14: + printf("Page fault, CR2 = 0x%x\n", read_cr2()); + halt(); + break; case 0x20: // IRQ0 - timer interrupt timer++; (*(byte *)(0xc00b8000))++; @@ -126,6 +130,7 @@ void isr(dword num) break; default: printf("Interrupt %d (0x%x) Unhandled!!\n", num, num); + halt(); break; } } diff --git a/video.c b/video.c index 9d318d5..514410e 100644 --- a/video.c +++ b/video.c @@ -9,10 +9,7 @@ void video_init() videoMode = *(word *)0xC0090002; if (!videoMode) //we are in console mode - { - video_psetp = &video_psetpnull; return; - } video_mode = *(ModeInfoBlock *) 0xC0090306; diff --git a/video.h b/video.h index 03bca9c..9109dbc 100644 --- a/video.h +++ b/video.h @@ -63,7 +63,7 @@ word *vid_ptr16 = (word *)0xF0000000; byte *vid_ptr24 = (byte *)0xF0000000; dword *vid_ptr32 = (dword *)0xF0000000; word console_memory[2000]; //holds a copy of the console's memory -void (*video_psetp)(int, dword); //function pointer to set a pixel +void (*video_psetp)(int, dword) = video_psetpnull; //function pointer to set a pixel