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