wip: better way of handling thread switch (iret in the switch)

This commit is contained in:
0x35c
2025-11-11 11:13:35 +01:00
parent bf993baa59
commit 9059901f70
7 changed files with 64 additions and 66 deletions

View File

@ -19,15 +19,27 @@ struct tcb *create_thread(struct pcb *process, void (*entry)(void))
vfree(new_tcb);
return NULL;
}
// set esp to "skip" the 4 GPRs and eip later to be used as the context
// of the thread
uint32_t *stack =
(uint32_t *)((uint8_t *)new_tcb->esp0 + STACK_SIZE - 5 * 4);
uint32_t *stack = (uint32_t *)((uint8_t *)new_tcb->esp0 + STACK_SIZE);
uint32_t *esp = stack;
// testing out some stuff
*(--stack) = 0x202; // EFLAGS
*(--stack) = 0x08; // CS = kernel code segment
*(--stack) = (uint32_t)entry;
// Error code and interrupt number (skipped by add $8, %esp)
*(--stack) = 0; // err_code
*(--stack) = 0; // int_no
// General purpose registers (for popa)
*(--stack) = 0; // EAX
*(--stack) = 0; // ECX
*(--stack) = 0; // EDX
*(--stack) = 0; // EBX
*(--stack) = (uint32_t)esp; // ESP (original - points to exit_process)
*(--stack) = 0; // EBP
*(--stack) = 0; // ESI
*(--stack) = 0; // EDI
*(--stack) = 0x10; // kernel DS
new_tcb->esp = stack;
new_tcb->process = process;
new_tcb->next = NULL;