Commit 70c0f742 by malcolm

debug serial output and fixed syscalls

parent af2a722f
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#define NUM_PROCS 16 #define NUM_PROCS 16
process* procs[NUM_PROCS]; process* procs[NUM_PROCS];
int curproc=-1; int curproc=0;
int firstfree=0; int firstfree=0;
//process* curproc; //process* curproc;
...@@ -18,6 +18,11 @@ void addproc(process* proc) ...@@ -18,6 +18,11 @@ void addproc(process* proc)
//curproc=proc; //curproc=proc;
} }
void settf(trapframe* tf)
{
procs[curproc]->tf = tf;
}
void schedule() void schedule()
{ {
int old = curproc; int old = curproc;
...@@ -46,13 +51,13 @@ int yield() ...@@ -46,13 +51,13 @@ int yield()
int print1() int print1()
{ {
terminal_writestring("1"); terminal_writestring("1\n");
return 1; return 1;
} }
int print2() int print2()
{ {
terminal_writestring("2"); terminal_writestring("2\n");
return 2; return 2;
} }
...@@ -63,13 +68,18 @@ void syscall() ...@@ -63,13 +68,18 @@ void syscall()
{ {
int num = procs[curproc]->tf->eax; int num = procs[curproc]->tf->eax;
serial_hexword(num);
serial_writestring(" SYSCALLED\n");
if(num>0 && num<NUM_SYSCALLS && syscalls[num]) if(num>0 && num<NUM_SYSCALLS && syscalls[num])
{ {
procs[curproc]->tf->eax = syscalls[num](); procs[curproc]->tf->eax = syscalls[num]();
} }
else else
{ {
serial_writestring("UNKNOWN SYSCALL CALLED\n"); serial_writestring("UNKNOWN SYSCALL CALLED ");
serial_hexword(num);
serial_writestring("\n");
procs[curproc]->tf->eax = -1; procs[curproc]->tf->eax = -1;
} }
} }
......
...@@ -66,6 +66,7 @@ typedef struct ...@@ -66,6 +66,7 @@ typedef struct
extern void context_switch(context** old, context* new); extern void context_switch(context** old, context* new);
void syscall(); void syscall();
void addproc(process* proc); void addproc(process* proc);
void settf(trapframe* tf);
void proc_setup(); void proc_setup();
#endif #endif
...@@ -59,7 +59,14 @@ void int_general_protection_fault(uint32_t __attribute__((unused))error) ...@@ -59,7 +59,14 @@ void int_general_protection_fault(uint32_t __attribute__((unused))error)
} }
void int_page_fault(uint32_t __attribute__((unused))error) void int_page_fault(uint32_t __attribute__((unused))error)
{ {
serial_writestring("PAGE FAULT ERROR\n"); serial_writestring("PAGE FAULT ERROR ");
serial_hexword(error);
uint32_t cr2;
asm volatile("movl %%cr2, %0" : "=r" (cr2) : );
//register uint32_t cr2 asm("%%cr2");
serial_writestring(" ");
serial_hexword(cr2);
serial_writestring("\n");
} }
void int_reserved(uint32_t __attribute__((unused))error) void int_reserved(uint32_t __attribute__((unused))error)
{ {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "string.h" #include "string.h"
#include "serial.h" #include "serial.h"
#include "exceptions.h" #include "exceptions.h"
#include "PCB.h"
#pragma GCC push_options #pragma GCC push_options
#pragma GCC optimize ("0") #pragma GCC optimize ("0")
...@@ -45,6 +46,7 @@ void load_error_handlers() ...@@ -45,6 +46,7 @@ void load_error_handlers()
void default_handler(trapframe reg) void default_handler(trapframe reg)
{ {
settf(&reg);
if(reg.trap<32) if(reg.trap<32)
reg.eip+=2; reg.eip+=2;
if(handlers[reg.trap]!=NULL) if(handlers[reg.trap]!=NULL)
...@@ -105,7 +107,7 @@ int idt_init(uint16_t code_sel) ...@@ -105,7 +107,7 @@ int idt_init(uint16_t code_sel)
idtsetup(); idtsetup();
idt_install(); idt_install();
load_error_handlers(); load_error_handlers();
handlers[0x100] = syscall; handlers[0x80] = syscall;
return 0; return 0;
} }
#pragma GCC pop_options #pragma GCC pop_options
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
void test_idt() void test_idt()
{ {
asm ("int $0x80"); asm volatile("mov $4, %eax; int $0x80");
asm ("int $0x90"); asm volatile("int $0x90");
} }
void test_mem() void test_mem()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment