wip: uncrampt the stack thing in the irq

This commit is contained in:
0x35c
2025-11-07 16:58:11 +01:00
parent a3a226ad95
commit bf993baa59
3 changed files with 11 additions and 5 deletions

View File

@ -22,6 +22,6 @@ struct tcb {
struct tcb *next;
};
struct tcb *create_thread(struct pcb *process, void (*routine)(void));
struct tcb *create_thread(struct pcb *process, void (*entry)(void));
void delete_thread(struct tcb *thread);
void switch_thread(struct tcb *thread_to_switch);

View File

@ -15,7 +15,7 @@ switch_thread:
// stack pointer + the 4 regs pushed
// and + 1 to get the argument (next thread)
.LABEL1:
mov esi, [esp+(4+1)*4]
mov esi, [esp+4]
mov [current_tcb], esi
mov eax, [current_tcb]

View File

@ -6,7 +6,7 @@
#include "string.h"
#include "thread.h"
struct tcb *create_thread(struct pcb *process, void (*routine)(void))
struct tcb *create_thread(struct pcb *process, void (*entry)(void))
{
static uint32_t tid = 1;
struct tcb *new_tcb = vmalloc(sizeof(struct tcb));
@ -21,8 +21,14 @@ struct tcb *create_thread(struct pcb *process, void (*routine)(void))
}
// set esp to "skip" the 4 GPRs and eip later to be used as the context
// of the thread
new_tcb->esp = new_tcb->esp0 + STACK_SIZE - 5 * 4;
new_tcb->esp[4] = (uint32_t)routine;
uint32_t *stack =
(uint32_t *)((uint8_t *)new_tcb->esp0 + STACK_SIZE - 5 * 4);
// testing out some stuff
*(--stack) = 0x202; // EFLAGS
*(--stack) = 0x08; // CS = kernel code segment
*(--stack) = (uint32_t)entry;
new_tcb->esp = stack;
new_tcb->process = process;
new_tcb->next = NULL;
new_tcb->state = NEW;