Debug scheduler
This commit is contained in:
parent
e59104ffb5
commit
5c3e2d90b3
5 changed files with 86 additions and 47 deletions
|
@ -123,7 +123,7 @@ extern "C" void boucane(u64 mb_info){
|
||||||
mem/=1024;
|
mem/=1024;
|
||||||
printk("RAM:%dMB\n", mem);
|
printk("RAM:%dMB\n", mem);
|
||||||
}
|
}
|
||||||
show_ticks=1;
|
//show_ticks=1;
|
||||||
create_task((void*)task1, 50);
|
create_task((void*)task1, 50);
|
||||||
create_task((void*)task2, 50);
|
create_task((void*)task2, 50);
|
||||||
scheduler_start();
|
scheduler_start();
|
||||||
|
|
|
@ -45,7 +45,7 @@ void idt_enable_interrupt(void){
|
||||||
d2.ign=0;
|
d2.ign=0;
|
||||||
d2.ist=0;
|
d2.ist=0;
|
||||||
d2.selector=0x08;
|
d2.selector=0x08;
|
||||||
d2.options=IDT_OPT_P|IDT_OPT_PRVL_3|IDT_OPT_TYPE_INT;
|
d2.options=IDT_OPT_P|IDT_OPT_PRVL_3|IDT_OPT_TYPE_TRAP;
|
||||||
d2.offset=(u64)&INT_SYSCALL;
|
d2.offset=(u64)&INT_SYSCALL;
|
||||||
idt_write_descriptor(d2, i);
|
idt_write_descriptor(d2, i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,30 +20,35 @@ void schedule(){
|
||||||
// to the clock() %rbp value and then we access to the registers SAVE_REGS in int.S
|
// to the clock() %rbp value and then we access to the registers SAVE_REGS in int.S
|
||||||
u64* stack;
|
u64* stack;
|
||||||
asm("mov %%rbp, %%rax;mov (%%rax), %%rbx; add $16, %%rbx; mov %%rbx,%0": "=m"(stack)::"rax","rbx");
|
asm("mov %%rbp, %%rax;mov (%%rax), %%rbx; add $16, %%rbx; mov %%rbx,%0": "=m"(stack)::"rax","rbx");
|
||||||
|
|
||||||
// Save current task
|
// Save current task
|
||||||
PROC *t=&procs[active_process];
|
PROC *t=&procs[active_process];
|
||||||
t->registers.r8=stack[0];
|
t->registers.rdi=stack[0];
|
||||||
t->registers.r9=stack[1];
|
t->registers.rsi=stack[1];
|
||||||
t->registers.r10=stack[2];
|
t->registers.rbp=stack[2];
|
||||||
t->registers.r11=stack[3];
|
t->registers.rdx=stack[3];
|
||||||
t->registers.r12=stack[4];
|
t->registers.rcx=stack[4];
|
||||||
t->registers.r13=stack[5];
|
t->registers.rbx=stack[5];
|
||||||
t->registers.r14=stack[6];
|
t->registers.rax=stack[6];
|
||||||
t->registers.r15=stack[7];
|
t->registers.r15=stack[7];
|
||||||
t->registers.rdi=stack[8];
|
t->registers.r14=stack[8];
|
||||||
t->registers.rsi=stack[9];
|
t->registers.r13=stack[9];
|
||||||
t->registers.rbp=stack[10];
|
t->registers.r12=stack[10];
|
||||||
t->registers.rdx=stack[11];
|
t->registers.r11=stack[11];
|
||||||
t->registers.rcx=stack[12];
|
t->registers.r10=stack[12];
|
||||||
t->registers.rbx=stack[13];
|
t->registers.r9=stack[13];
|
||||||
t->registers.rax=stack[14];
|
t->registers.r8=stack[14];
|
||||||
t->registers.rip=stack[15];
|
t->registers.rip=stack[15];
|
||||||
t->registers.cs=stack[16];
|
t->registers.cs=stack[16];
|
||||||
t->registers.eflags=stack[17];
|
t->registers.eflags=stack[17];
|
||||||
t->registers.rsp=stack[18];
|
t->registers.rsp=stack[18];
|
||||||
t->registers.ds=stack[19];
|
t->registers.ss=stack[19];
|
||||||
|
if (t->registers.cs!=0x8)
|
||||||
|
t->registers.ds=0x23;
|
||||||
|
else
|
||||||
|
t->registers.ds=0x10;
|
||||||
|
|
||||||
|
//printk("Old task %d cs:%x rsp:%x ds:%x\n ",active_process+1, t->registers.cs,t->registers.rsp,t->registers.ds);
|
||||||
// Goto next task
|
// Goto next task
|
||||||
active_process++;
|
active_process++;
|
||||||
if(active_process>=nproc)
|
if(active_process>=nproc)
|
||||||
|
@ -54,7 +59,7 @@ void schedule(){
|
||||||
|
|
||||||
// Clock acknownledgement
|
// Clock acknownledgement
|
||||||
apic_ack();
|
apic_ack();
|
||||||
|
|
||||||
asm volatile(
|
asm volatile(
|
||||||
"mov %0, %%rdi \n\t"
|
"mov %0, %%rdi \n\t"
|
||||||
"jmp switch \n\t"
|
"jmp switch \n\t"
|
||||||
|
@ -84,6 +89,7 @@ void create_task(void* task, u32 size){
|
||||||
t->registers.rip=TASK_VMA;
|
t->registers.rip=TASK_VMA;
|
||||||
t->registers.cs=0x1B; // 0x18 and 0x3 privilege
|
t->registers.cs=0x1B; // 0x18 and 0x3 privilege
|
||||||
t->registers.ds=0x23; // 0x20 and 0x3 privilege
|
t->registers.ds=0x23; // 0x20 and 0x3 privilege
|
||||||
|
t->registers.ss=0; // Always 0 in long-mode
|
||||||
|
|
||||||
// Load task using
|
// Load task using
|
||||||
lpml4(t->pml4);
|
lpml4(t->pml4);
|
||||||
|
|
|
@ -11,14 +11,14 @@
|
||||||
// DO NOT CHANGE THE FOLLOWING STRUCTURE WITHOUT CONCIDERING UPDATING
|
// DO NOT CHANGE THE FOLLOWING STRUCTURE WITHOUT CONCIDERING UPDATING
|
||||||
// THE SWITCH FUNCTION INTO scheduler_asm.S
|
// THE SWITCH FUNCTION INTO scheduler_asm.S
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u64 rax, rbx, rcx, rdx;
|
u64 rax, rbx, rcx, rdx; // 8 16 24 32
|
||||||
u64 cs, rip;
|
u64 cs, rip; // 40 48
|
||||||
u64 ss, rsp, rbp;
|
u64 ss, rsp, rbp; // 56 64 72
|
||||||
u64 rsi, rdi;
|
u64 rsi, rdi; // 80 88
|
||||||
u64 ds, es, fs, gs;
|
u64 ds, es, fs, gs; // 96 104 112 120
|
||||||
u64 eflags;
|
u64 eflags; // 128
|
||||||
u64 rsp0;
|
u64 rsp0; // 136
|
||||||
u64 r8,r9,r10,r11,r12,r13,r14,r15;
|
u64 r8,r9,r10,r11,r12,r13,r14,r15; // 144 152 160 168 176 184 192 200
|
||||||
} __attribute__((packed)) REGS;
|
} __attribute__((packed)) REGS;
|
||||||
|
|
||||||
// DO NOT CHANGE THE FOLLOWING STRUCTURE WITHOUT CONCIDERING UPDATING
|
// DO NOT CHANGE THE FOLLOWING STRUCTURE WITHOUT CONCIDERING UPDATING
|
||||||
|
|
|
@ -1,34 +1,67 @@
|
||||||
.globl switch
|
.globl switch
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.extern kvar_stack_pma
|
|
||||||
|
|
||||||
switch:
|
switch:
|
||||||
|
|
||||||
# TODO: Check if we come from kernel mode (use kernel stack)
|
# Load task page table
|
||||||
# TODO: restore all registers
|
|
||||||
|
|
||||||
mov 96(%rdi), %ax
|
|
||||||
mov %ax, %ds
|
|
||||||
mov %ax, %es
|
|
||||||
mov %ax, %fs
|
|
||||||
mov %ax, %gs
|
|
||||||
|
|
||||||
mov (%rdi), %rax
|
mov (%rdi), %rax
|
||||||
mov %rax, %cr3
|
mov %rax, %cr3
|
||||||
|
|
||||||
push 96(%rdi)
|
# First load the task stack
|
||||||
push 64(%rdi)
|
mov 64(%rdi), %rsp
|
||||||
pushf
|
|
||||||
|
# Prepare for iret
|
||||||
|
push 96(%rdi) # ds
|
||||||
|
push 64(%rdi) # rsp
|
||||||
|
push 128(%rdi) # Flags
|
||||||
pop %rax
|
pop %rax
|
||||||
or $0x200, %rax # Enable interrupt
|
or $0x200, %rax # Enable interrupt
|
||||||
mov $0xffffffffbfff, %rbx # NT flag
|
mov $0xffffffffbfff, %rbx # NT flag
|
||||||
and %rbx, %rax
|
and %rbx, %rax
|
||||||
push %rax
|
push %rax # Apply flags changes
|
||||||
push 40(%rdi)
|
push 40(%rdi) # cs
|
||||||
push 48(%rdi)
|
push 48(%rdi) # rip
|
||||||
|
|
||||||
|
# Prepare to restore general registers
|
||||||
|
push 8(%rdi) # rax
|
||||||
|
push 16(%rdi) # rbx
|
||||||
|
push 24(%rdi) # rcx
|
||||||
|
push 32(%rdi) # rdx
|
||||||
|
push 72(%rdi) # rbp
|
||||||
|
push 80(%rdi) # rsi
|
||||||
|
push 88(%rdi) # rdi
|
||||||
|
push 144(%rdi) # r8
|
||||||
|
push 152(%rdi) # r9
|
||||||
|
push 160(%rdi) # r10
|
||||||
|
push 160(%rdi) # r11
|
||||||
|
push 176(%rdi) # r12
|
||||||
|
push 184(%rdi) # r13
|
||||||
|
push 192(%rdi) # r14
|
||||||
|
push 200(%rdi) # r15
|
||||||
|
|
||||||
|
# ds
|
||||||
|
mov 96(%rdi), %ax
|
||||||
|
mov %ax, %ds
|
||||||
|
mov %ax, %gs
|
||||||
|
mov %ax, %fs
|
||||||
|
mov %ax, %es
|
||||||
|
|
||||||
|
# Restore general registers
|
||||||
|
pop %r15
|
||||||
|
pop %r14
|
||||||
|
pop %r13
|
||||||
|
pop %r12
|
||||||
|
pop %r11
|
||||||
|
pop %r10
|
||||||
|
pop %r9
|
||||||
|
pop %r8
|
||||||
|
pop %rdi
|
||||||
|
pop %rsi
|
||||||
|
pop %rbp
|
||||||
|
pop %rdx
|
||||||
|
pop %rcx
|
||||||
|
pop %rbx
|
||||||
|
pop %rax
|
||||||
|
|
||||||
|
|
||||||
# Perform task switching
|
# Perform task switching
|
||||||
iretq
|
iretq
|
||||||
|
|
Loading…
Add table
Reference in a new issue