Commit af2a722f by malcolm

updated stuff to use an array for now

parent ffa16ab2
Showing with 40 additions and 13 deletions
......@@ -2,27 +2,43 @@
#include "serial.h"
#include "term.h"
#define NUM_SYSCALLS 256
#define NUM_PROCS 16
process* curproc;
process* otherproc;
process* procs[NUM_PROCS];
int curproc=-1;
int firstfree=0;
void setproc(process* proc)
//process* curproc;
//process* otherproc;
void addproc(process* proc)
{
curproc=proc;
procs[firstfree]=proc;
firstfree++;
//curproc=proc;
}
void schedule()
{
context_switch(&curproc->ctxt, otherproc->ctxt);
process* t = curproc;
curproc = otherproc;
otherproc = t;
int old = curproc;
curproc++;
while(procs[curproc]==0 || procs[curproc]->state!=RUNNABLE)
{
curproc=(curproc<NUM_PROCS-1)?curproc+1:0;
}
context_switch(&procs[old]->ctxt, procs[curproc]->ctxt);
//procs[old]->state=RUNNABLE;
procs[curproc]->state=RUNNING;
//process* t = curproc;
//curproc = otherproc;
//otherproc = t;
}
int yield()
{
//lock mutex
curproc->state = RUNNABLE;
procs[curproc]->state = RUNNABLE;
schedule();
//unlock mutex
return 1;
......@@ -45,15 +61,23 @@ int(*syscalls[NUM_SYSCALLS])()={0,0,0, yield, print1, print2};
void syscall()
{
int num = curproc->tf->eax;
int num = procs[curproc]->tf->eax;
if(num>0 && num<NUM_SYSCALLS && syscalls[num])
{
curproc->tf->eax = syscalls[num]();
procs[curproc]->tf->eax = syscalls[num]();
}
else
{
serial_writestring("UNKNOWN SYSCALL CALLED\n");
curproc->tf->eax = -1;
procs[curproc]->tf->eax = -1;
}
}
void proc_setup()
{
for(int i=0;i<NUM_PROCS;i++)
{
procs[i]=NULL;
}
}
......@@ -65,6 +65,7 @@ typedef struct
extern void context_switch(context** old, context* new);
void syscall();
void setproc(process* proc);
void addproc(process* proc);
void proc_setup();
#endif
......@@ -20,6 +20,7 @@
#include "pit.h"
#include "io.h"
#include "elf.h"
#include "PCB.h"
// The parameters passed here ultimately come through the bootloader
void kernel_main(multiboot_info* mbt, uint32_t magic)
......@@ -39,6 +40,7 @@ void kernel_main(multiboot_info* mbt, uint32_t magic)
pic_init(0x20,0x28);
pit_init();
io_init();
proc_setup();
pit_start_counter(100, PIT_OCW_CONT_0, PIT_OCW_MODE_SQWVGEN);
enable_int();
......
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