timer isr:
Code: Select all
timer_isr: cli
pusha
push %ds
push %es
push %fs
push %gs
movl (task_curr), %eax // move the stack pointer in the process's structure
movl %esp, (%eax)
movl (task_head), %eax // get the kernel stack
movl (%eax), %esp
call schedule
movl (tss), %eax // put kernel stack pointer in the tss
addl $0x4, %eax
mov %esp, (%eax)
movl (task_head), %eax // put kernel stack pointer in the kernel process's task
movl %esp, (%eax)
movl (task_curr), %eax // get the stack pointer from the process
movl (%eax), %esp
pop %gs
pop %fs
pop %es
pop %ds
popa
sti
ret_here:
add $0x8, %esp
iret
Code: Select all
void schedule(void) {
if(task_count > 0) {
if (task_curr->time < 1) {
if (task_curr->next != 0) {
task_curr = task_curr->next;
} else
task_curr = task_head;
task_curr->time = 10;
task_curr->time_ran++;
write_cr3(task_curr->cr3);
} else
task_curr->time--;
}
p_outb(0x20, 0x20);
}
Code: Select all
// create tss descriptor
GDT[3].limit = sizeof(tss_t) - 1;
GDT[3].base_lo = (int) tss;
GDT[3].base_hi = (int) tss >> 16;
GDT[3].type = TSS_PRESENT + TSS_READY;
GDT[3].type2 = 0x0;
GDT[3].base_vhi = (int) tss >> 24;
// create tss
tss->esp0 = read_esp();
tss->cr3 = read_cr3();
set_tr(24);
thanks