kernel/scheduler.c (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#include "cedos/scheduler.h"
#include "cedos/process.h"
#include "cedos/mm/paging.h"
#include "cedos/drivers/console.h"
#include "cedos/core.h"
#include "cedos/interrupts.h"
#include "cedos/pit.h"
#include "cedos/pic.h"
#include "assembly.h"
#include "cedos/drivers/speaker.h"
PROCESS* get_slot(void) {
static PROCESS free_slots[4];
static uint32_t index = 0;
return &(free_slots[index++]);
}
/*!
* Executes a task.
*/
PROCESS_ID sched_exec(PHYS_ADDR page_dir, VIRT_ADDR eip, VIRT_ADDR esp) {
PROCESS* p = get_slot();
p->page_dir = page_dir;
p->eip = eip;
p->esp = esp;
// TODO: add file descriptors for stdin, stdout and stderr
p->state = PSTATE_READY;
return add_process(p);
}
INTERRUPT(sched_interrupt, frame) {
printk("--#");
// reset the timer
pit_setup_channel(PIT_CHANNEL_0, PIT_MODE_0, 0xFFFF);
uint32_t big_ben[] = { 415, 330, 370, 247, 247, 370, 415, 330 };
static int i = 0;
bios_sp.make_sound(big_ben[(i / 8) % (sizeof(big_ben)/sizeof(big_ben[0]))], 1);
i++;
pic1_eoi();
}
int sched_init(void) {
// TODO: create and start idle process
//sched_exec(create_empty_page_dir(), (void*)0, (void*)0);
// install timer interrupt
install_interrupt(0x20, sched_interrupt, 0x08, INT_GATE);
return 1;
}
int sched_start(void) {
// perform the first timer interrupt manually
INT(0x20);
}
int sched_dispatcher(void) {
}