// Initialize the CPU CPU * CPU_init(int sharedMemCount) { CPU *cpu = malloc(sizeof(CPU)); cpu->isRunning = YES; cpu->modMutex = malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(cpu->modMutex, NULL); cpu->ip = 0; cpu->runningProcess = NULL; cpu->timer = NULL; int i; for (i = 0; i < INTERRUPT_PRIORITY_COUNT; i++) { cpu->interruptQueues[i] = LinkedBlockingQueue_init(); } cpu->scheduler = Scheduler_init(cpu); cpu->dvcDisk = IODevice_init(LOG_TYPE_DISK, cpu); cpu->dvcVid = IODevice_init(LOG_TYPE_VID, cpu); cpu->dvcKbd = KBDDevice_init(cpu); cpu->sharedMemoryCount = sharedMemCount; cpu->sharedMemory = malloc(sizeof(SharedMemory *) * sharedMemCount); for (i = 0; i < sharedMemCount; i++) { cpu->sharedMemory[i] = SharedMemory_init(); } cpu->gui = (struct SchedSimGUI *) SchedSimGUI_init(cpu); return cpu; }
void init_multitasking() { asm volatile("cli"); //memset((void*)(200*1024*1024),0,(40*1024*1024)); kernel_proc = create_process("microkernel", 0, 1, 0); new_process = (uint32_t)kernel_proc; current_task = (uint32_t)create_task("initiating_task",tasking_initiator, 20, 0x202, kernel_proc); //Scheduler initalization task old_task = current_task; Idle_task = create_task("System_idle_task",idle, 20, 0x202, kernel_proc); //default task Activate_task_direct(Idle_task); Activate_task_direct(create_task("idle2",idle2, 10, 0x202, kernel_proc)); Activate_task_direct(create_task("idle3",idle3, 10, 0x202, kernel_proc)); Activate_task_direct(create_task("idle4",idle4, 10, 0x202, kernel_proc)); Activate_task_direct(create_task("idle5",idle5, 10, 0x202, kernel_proc)); Activate_task_direct(create_task("idle6",idle6, 10, 0x202, kernel_proc)); //Activate_task_direct(create_task("Main_Kernel",kernel_main, 10, 0x202, kernel_proc)); Shell_proc = create_process("Shell", 0, 1, kernel_proc); Activate_task_direct(create_task("Shell_Ostream", Console_Writer, 10, 0x202, Shell_proc)); reached_bottom = 0; Scheduler_init(); // Let the FUN Begin :D Lets Switch from the old monotasking world to Multitasking World :D defined in tasking.asm }
void init_multitasking() { asm volatile("cli"); kernel_proc = create_process("microkernel", 0, 1, 0); kernel_proc->pgdir = (uint32_t)system_dir; new_process = (uint32_t)kernel_proc; current_task = (uint32_t)create_task("initiating_task",tasking_initiator, 0, 0x202, kernel_proc); //Scheduler initalization task old_task = current_task; Spurious_task = create_task("Spurious_task", Spurious_task_func, 0, 0x202, kernel_proc); Spurious_task->special = 1; Idle_task = create_task("System_idle_task",idle, 0, 0x202, kernel_proc); //default task, this dosent run Idle_task->special = 1; Shell_proc = create_process("Shell", 0, 1, kernel_proc); Shell_Ostream_task = create_task("Shell_Ostream", Shell_Double_buffer, 10, 0x202, Shell_proc); Activate_task_direct(Shell_Ostream_task); //This is the task which would make printing to console possible! Shell_Istream_task = create_task("Shell_Istream", Shell_Input, 1, 0x202, Shell_proc); Activate_task_direct(Shell_Istream_task); //This would manage keyboard input and delivery to the required process. //Shell_Istream_task->special = 1; Shell_task = create_task("Shell_task", Shell, 5, 0x202, Shell_proc); //Main shell task. //Shell_task->special = 1; Activate_task_direct(Shell_task); SAS_proc = create_process("SAS", 0, 1, kernel_proc); //Scheduler Assistance System process. Activate_task_direct(create_task("SAS_init", SAS_init, 1, 0x202, SAS_proc)); //Initialization of SAS system. reached_bottom = 0; Scheduler_init(); // Let the FUN Begin :D Lets Switch from the old monotasking world to Multitasking World :D defined in tasking.asm while(1); //Never comeback :D }