Commented everything
This commit is contained in:
parent
43fc6c94e5
commit
0984eb593f
4 changed files with 45 additions and 15 deletions
|
@ -333,8 +333,8 @@ int test_init(void)
|
|||
mailbox_int32_init(&mbox);
|
||||
|
||||
create_kernel_task(NULL, measure_ctx_switch, NULL, NORMAL_PRIO);
|
||||
create_kernel_task(NULL, foo, "Hello from foo1", NORMAL_PRIO);
|
||||
create_kernel_task(NULL, foo, "Hello from foo2", NORMAL_PRIO);
|
||||
//create_kernel_task(NULL, foo, "Hello from foo1", NORMAL_PRIO);
|
||||
//create_kernel_task(NULL, foo, "Hello from foo2", NORMAL_PRIO);
|
||||
//create_kernel_task(NULL, join_test, NULL, NORMAL_PRIO);
|
||||
//create_kernel_task(NULL, producer, , NORMAL_PRIO);
|
||||
//create_kernel_task(NULL, consumer, NULL, NORMAL_PRIO);
|
||||
|
|
|
@ -507,22 +507,32 @@ hack:
|
|||
jmp 0x00 : 0xDEADBEAF
|
||||
ret
|
||||
|
||||
; This procedure is used by scheduler() to switch tasks.
|
||||
; It is the software-equivalent to the hw-procedure switch_task from above.
|
||||
; Call it in C with the following arguments:
|
||||
; sw_switch_context(&old_tasks_stack_pointer, &new_tasks_stack_pointer)
|
||||
global sw_switch_context
|
||||
sw_switch_context:
|
||||
;pushf
|
||||
push DWORD 0x8
|
||||
push DWORD [esp+4]
|
||||
push DWORD 0
|
||||
push DWORD 0xc0edbabe
|
||||
pusha
|
||||
; The stack layout looks like this:
|
||||
; [new stack pointer]
|
||||
; [old stack pointer]
|
||||
;pushf ; [this procedure's return address] overwritten by: EFLAGS (*1)
|
||||
push DWORD 0x8 ; CS
|
||||
push DWORD [esp+4] ; EIP
|
||||
push DWORD 0 ; Interrupt number
|
||||
push DWORD 0xc0edbabe ; Error code
|
||||
pusha ; Registers...
|
||||
; ---- This will be popped off by iret later.
|
||||
|
||||
pushf
|
||||
pop eax
|
||||
mov [esp+48], eax
|
||||
mov [esp+48], eax ; Move EFLAGS to position (*1) by overwriting
|
||||
; the return address of sw_switch_context()
|
||||
|
||||
mov ecx, [esp+52]
|
||||
mov [ecx], esp
|
||||
mov [ecx], esp ; Save stack position in old task structure
|
||||
mov ecx, [esp+56]
|
||||
mov esp, [ecx]
|
||||
mov esp, [ecx] ; Load new stack
|
||||
|
||||
sw_rollback:
|
||||
popa
|
||||
|
|
|
@ -149,10 +149,29 @@ int create_default_frame(task_t* task, internal_entry_point_t ep, void* arg)
|
|||
#ifdef SW_TASK_SWITCH
|
||||
memset(kstacks[id], 0xCD, KERNEL_STACK_SIZE);
|
||||
|
||||
/* The difference between setting up a task for SW-task-switching
|
||||
* and not for HW-task-switching is setting up a stack and not a TSS.
|
||||
* This is the stack which will be activated and popped off for iret later.
|
||||
*/
|
||||
stack = kstacks[id] +KERNEL_STACK_SIZE -sizeof(uint32_t);
|
||||
|
||||
/* The next three things on the stack are a marker for debugging purposes, ... */
|
||||
*stack-- = 0xDEADBEEF;
|
||||
/* the first-function-to-be-called's arguments, ... */
|
||||
*stack-- = arg;
|
||||
/* and the "caller" we shall return to.
|
||||
* This procedure cleans the task after exit. */
|
||||
*stack = leave_kernel_task;
|
||||
|
||||
/* Next bunch on the stack is the initial register state.
|
||||
* The stack must look like the stack of a task which was
|
||||
* scheduled away previously. */
|
||||
|
||||
/* short_state_size was introduced because the convenient "struct state"
|
||||
* is used for filling the stack with initial values. But the problem is that
|
||||
* "iret" will not remove the last two entries from the stack, since we're
|
||||
* "returning" from kernel space to kernel space. Therefore it is shortened
|
||||
* by its last two entries. */
|
||||
stack -= short_state_size;
|
||||
|
||||
stptr = stack;
|
||||
|
@ -161,12 +180,14 @@ int create_default_frame(task_t* task, internal_entry_point_t ep, void* arg)
|
|||
stptr->int_no = 0xB16B00B5;
|
||||
stptr->error = 0xC03DB4B3;
|
||||
|
||||
/* The instruction pointer shall be set on the first function to be called
|
||||
* after IRETing */
|
||||
stptr->eip = ep;
|
||||
stptr->cs = cs;
|
||||
stptr->eflags = 0x1002;
|
||||
//stptr->ss = ds;
|
||||
//stptr->useresp = kstacks[id] +KERNEL_STACK_SIZE - 3*sizeof(uint32_t);
|
||||
|
||||
/* Set the task's stack pointer entry to the stack we have crafted right now.
|
||||
* This is the pointer which will be used by sw_switch_task(old_task, new_task) later.*/
|
||||
task->stack = stack;
|
||||
#else
|
||||
/* reset buffers */
|
||||
|
|
|
@ -1382,11 +1382,10 @@ get_task_out:
|
|||
// orig_task->id, curr_task->id, (uint32_t)curr_task->prio, CORE_ID);
|
||||
#ifndef SW_TASK_SWITCH
|
||||
switch_task(curr_task->id);
|
||||
#else
|
||||
write_cr3(virt_to_phys((size_t)curr_task->pgd));
|
||||
#endif
|
||||
finish_task_switch(0);
|
||||
#ifdef SW_TASK_SWITCH
|
||||
write_cr3(virt_to_phys((size_t)curr_task->pgd));
|
||||
sw_switch_context(&orig_task->stack, &curr_task->stack);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue