simplify context_switch
[EXTERN _current_task_small]
-[EXTERN task_small_offset_to_context]
+[EXTERN _task_context_offset]
+
[GLOBAL context_switch]
context_switch:
- mov ecx, [esp + 0x4] ; save new task argument
+ ; Save arg to function containing task to switch to in ecx
+ mov ecx, [esp + 0x4]
+
;Save the old task's state
; Save registers that are supposed to be callee-saved
push eax
@@ -11,18 +14,22 @@ context_switch:
push edi
push ebp
-; 0x6c is the offset to _current_task_small->context! FIX ME PT
- mov esi,[_current_task_small] ;Get address of old task's "thread control block" from global variable
- mov [esi+0x6c],esp ;Save old task' ESP in its "thread control block"
+ ; Save preempted task's esp as _current_task->machine_state
+ mov eax, [_current_task_small]
+ mov ebx, [_task_context_offset]
+ add eax, ebx
+ mov [eax], esp
;Load the new task's state
+ ; Set the provided argument to _current_task_small
+ mov [_current_task_small], ecx
- mov edi,ecx ;Get address of new task's "thread control block" from arg
- mov [_current_task_small], edi ;Set address of new task's "thread control block" in global variable for later
- mov esp,[edi+0x6c] ;Load new ESP from new task's "thread control block"
+ ; Load esp with _current_task->machine_state
+ mov ebx, [_task_context_offset]
+ add ecx, ebx
+ mov esp,[ecx]
; Restore registers that were callee-saved
-
pop ebp
pop edi
pop esi
@@ -30,6 +37,5 @@ context_switch:
pop eax
; Return to the new task's EIP (that was stored on its stack
-
sti
ret
\ No newline at end of file
