Commit ffa16ab2 by malcolm

horrible hacks and other stuff

parent b77e65dd
#include "PCB.h" #include "PCB.h"
#include "serial.h"
#include "term.h"
#define NUM_SYSCALLS 256
process* curproc;
process* otherproc;
void setproc(process* proc)
{
curproc=proc;
}
void schedule()
{
context_switch(&curproc->ctxt, otherproc->ctxt);
process* t = curproc;
curproc = otherproc;
otherproc = t;
}
int yield()
{
//lock mutex
curproc->state = RUNNABLE;
schedule();
//unlock mutex
return 1;
}
int print1()
{
terminal_writestring("1");
return 1;
}
int print2()
{
terminal_writestring("2");
return 2;
}
int(*syscalls[NUM_SYSCALLS])()={0,0,0, yield, print1, print2};
/*NOPE, exit, fork, yield, test, test*/
void syscall()
{
int num = curproc->tf->eax;
if(num>0 && num<NUM_SYSCALLS && syscalls[num])
{
curproc->tf->eax = syscalls[num]();
}
else
{
serial_writestring("UNKNOWN SYSCALL CALLED\n");
curproc->tf->eax = -1;
}
}
...@@ -49,16 +49,22 @@ typedef struct//regs needed for context ...@@ -49,16 +49,22 @@ typedef struct//regs needed for context
uint32_t eip; uint32_t eip;
}__attribute__((packed)) context; }__attribute__((packed)) context;
enum procstate {KILLED, RUNNABLE, RUNNING};
typedef struct typedef struct
{ {
page_directory_entry* mem; page_directory_entry* mem;
volatile int pid; volatile int pid;
struct process* parent; struct process* parent;
char* kstack;//apparently we need this. idk why
trapframe* tf; trapframe* tf;
context* ctxt; context* ctxt;
char name[32]; char name[32];
enum procstate state;
}__attribute__((packed)) process; }__attribute__((packed)) process;
extern void context_switch(context** old, context* new); extern void context_switch(context** old, context* new);
void syscall();
void setproc(process* proc);
#endif #endif
...@@ -105,6 +105,7 @@ int idt_init(uint16_t code_sel) ...@@ -105,6 +105,7 @@ int idt_init(uint16_t code_sel)
idtsetup(); idtsetup();
idt_install(); idt_install();
load_error_handlers(); load_error_handlers();
handlers[0x100] = syscall;
return 0; return 0;
} }
#pragma GCC pop_options #pragma GCC pop_options
global context_switch global context_switch
switch: context_switch:
mov eax, [esp+4] mov eax, [esp+4]
mov edx, [esp+8] mov edx, [esp+8]
......
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