Fixed scheduler for reals now :3
This commit is contained in:
parent
144f951b9d
commit
a6883dd536
|
|
@ -7,21 +7,6 @@
|
|||
#include "drivers/cpuio.h"
|
||||
#include "system/scheduler.h"
|
||||
|
||||
void testf(){
|
||||
printf("Hello from thread!\n");
|
||||
// thread_exit(1);
|
||||
// enable_interrupts();
|
||||
// asm volatile ("jmp .");
|
||||
for(;;);
|
||||
}
|
||||
void test1(){
|
||||
// printf("Hello from thread1!\n");
|
||||
uint16_t *test = (void *)0xb8000;
|
||||
*test = 0x0f41;
|
||||
thread_start(testf);
|
||||
for(;;);
|
||||
// asm
|
||||
}
|
||||
void dead_proc(){
|
||||
for(;;);
|
||||
}
|
||||
|
|
@ -34,11 +19,8 @@ extern void kmain(kernel_info_t *kernel_info){
|
|||
pic_setmask(0xfe, PIC1_DATA);
|
||||
//TODO: Map and load filesystem and disk modules
|
||||
//TODO: Start Initial Process
|
||||
uint32_t exit_code = -1;
|
||||
init_scheduler();
|
||||
thread_start(dead_proc);
|
||||
thread_start(testf);
|
||||
thread_start(test1);
|
||||
enable_interrupts();
|
||||
for(;;);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -35,25 +35,16 @@ cpu_registers_t *schedule(cpu_registers_t *regs){
|
|||
// if(queue_length == 0){
|
||||
// return regs;
|
||||
// }
|
||||
uint32_t i = 0;
|
||||
// uint32_t i = 0;
|
||||
processes[current_pid].cpuregs = *regs;
|
||||
processes[process_queue[current_queue_index]].flags.ran = 1;
|
||||
uint32_t run_count = 0;
|
||||
for(uint32_t i = 0; i < queue_length; i++){
|
||||
run_count += processes[process_queue[i]].flags.ran;
|
||||
}
|
||||
if(run_count == queue_length){
|
||||
for(uint32_t i = 0; i < queue_length; i++){
|
||||
processes[process_queue[i]].flags.ran = 0;
|
||||
}
|
||||
current_queue_index++;
|
||||
if(current_queue_index >= queue_length){
|
||||
current_queue_index = 0;
|
||||
}
|
||||
else{
|
||||
current_queue_index++;
|
||||
}
|
||||
// current_pid = [current_queue_index]
|
||||
current_pid = process_queue[current_queue_index];
|
||||
asm volatile("mov %0, %%cr3" : : "r"(processes[current_pid].page_dir));
|
||||
|
||||
// printf("pid: %d, %d\n", run_count, queue_length);
|
||||
cpu_registers_t *newregs = (cpu_registers_t*)processes[current_pid].cpuregs.esp;
|
||||
// printf("EAX: %x EBX: %x ECX: %x EDX: %x\n", newregs->eax, newregs->ebx, newregs->ecx, newregs->edx);
|
||||
// printf("ESI: %x EDI: %x ESP: %x EBP: %x\n", newregs->esi, newregs->edi, newregs->esp, newregs->ebp);
|
||||
|
|
@ -81,6 +72,7 @@ void remove_process_queue(uint32_t pid){
|
|||
if(old_index == last_queue_index) return;
|
||||
process_queue[old_index] = process_queue[last_queue_index];
|
||||
process_queue[last_queue_index] = 0;
|
||||
queue_length--;
|
||||
}
|
||||
|
||||
uint32_t spawn_new_process(cpu_registers_t defaultregs, char **argv, uint32_t argc, void *cr3){
|
||||
|
|
@ -154,11 +146,17 @@ uint32_t thread_start(void (*function)()){
|
|||
return retpid;
|
||||
}
|
||||
void thread_join(uint32_t thread_id, uint32_t *exit_code){
|
||||
while(processes[thread_id].flags.present);
|
||||
asm volatile ("" : : :"memory");
|
||||
while(processes[thread_id].flags.present){
|
||||
// printf("%d", processes[thread_id].flags.present);
|
||||
};
|
||||
// printf("Done");
|
||||
*exit_code = processes[thread_id].exit_value;
|
||||
}
|
||||
void thread_exit(uint32_t exit_code){
|
||||
processes[current_pid].flags.present = 0;
|
||||
processes[current_pid].exit_value = exit_code;
|
||||
remove_process_queue(current_pid);
|
||||
}
|
||||
// printf("Exiting pid %d, %d\n", current_pid);
|
||||
asm volatile ("int $32");//call scheduler via interrupt
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue