Here some code of multitasking,IRQ and syscalls:
process scheduling:
Code: Select all
if (disableScheduler) return;
struct process *kill = process_findByStatus(PROCESS_KILLING);
if (kill != NULL) {
__process_destroy(kill);
if (runningTask == kill) {
runningTask = NULL;
}
}
if (runningTask != NULL) {
// Simply select new task
arch_saveRegs(stack,runningTask->esp);
runningTask = process_findNextByStatus(PROCESS_RUNNING,runningTask->lAddr);
runningTask->quota = 0;
} else {
// first switch
runningTask = process_findByStatus(PROCESS_RUNNING);
}
if (runningTask == NULL) {
// okay switch to idle
runningTask = idle;
}
// change the TSS and VMM
tss_set_stack(0x10,runningTask->kernelESP);
if (!pmml_isPageAllocated((void *)runningTask->dir)) {
printf("proc: AAA\n");
return;
}
vmm_switch((int *)runningTask->dir);
arch_switchContext(runningTask->esp);
}
Code: Select all
push eax
push ecx
push edx
push ebx
push ebp
push esi
push edi
mov ax,ds
push eax
mov ax, 0x10 ; load the kernel data segment descriptor
mov ds, eax
mov es, eax
mov fs, eax
mov gs, eax
push esp
call irq_handler
mov esp,eax
jmp irq_handler_exit ; Exit from this code using jmp
[GLOBAL irq_handler_exit]
irq_handler_exit:
pop ebx
mov ds, ebx
mov es, ebx
mov fs, ebx
mov gs, ebx
pop edi
pop esi
pop ebp
pop ebx
pop edx
pop ecx
pop eax
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
Code: Select all
registers_t *syscall_handler(registers_t *regs) {
if (regs->eax > 23) {
printf("No such syscall number: %d\n",regs->eax);
process_kill(process_getCurrentPID());
process_yield();
} else {
int (*handler)(int,int,int,int,int) = (int (*)(int,int,int,int,int))syscalls[regs->eax];
regs->eax = handler(regs->edx,regs->ecx,regs->ebx,regs->edi,regs->esi);
}
return regs;
}