/* main.c */ #include "asm.h" #include "main.h" #include "process.h" #include "mips4kc.h" #include "program.h" #include "registers.h" #include "scheduler.h" #include "string.h" #include "tty3.h" #include "user.h" int latest_p = 0; void call(void (*func)()) { func(); } registers_t regs; void kinit() { kset_registers(®s); init_programs(); init_PCB(); char args_other_name[2][MAX_STR_LEN]; string_memcpy(args_other_name[0], "welcome"); /* what to run in init */ // new_p("lcd", args_other_name); new_p("console", args_other_name); PCB_list[0].status = RUNNING; init_UART(); kset_sr(0x0, 0x8401); kload_timer(100*timer_msec); call((void *) PCB_list[get_running()].address); } void handle_timer_interrupt() { int pid = latest_p + 1; if (is_supervisor(pid)) { check_crashes(); revive(pid); } do_delay(); increase_wait(); select_process(); latest_p = get_running(); if (PCB_list[latest_p].toggle) { PCB_list[latest_p].toggle = 0; } else { PCB_list[latest_p].toggle = 1; } } void kexception() { cause_reg_t cause; cause.reg = get_cause(); registers_t *tmp; tmp = kget_registers(); if (cause.field.exc == 8) { syscall_handler(tmp); tmp->epc_reg += 4; } else if (cause.field.ip & 0x80) { registers_memcpy(&PCB_list[latest_p].regs, tmp); handle_timer_interrupt(); registers_memcpy(tmp, &PCB_list[latest_p].regs); kset_registers(tmp); kload_timer(100*timer_msec); } else if (cause.field.ip & 4) { handle_tty_input(); } }