13#include <aquila/syscall.h>
18MALLOC_DEFINE(M_X86_THREAD,
"x86-thread",
"x86 thread structure");
21#define PUSH(stack, type, value)\
23 (stack) -= sizeof(type);\
24 *((type *) (stack)) = (type) (value);\
80 x86_goto(arch->eip, arch->ebp, arch->esp);
107 stack -=
sizeof(frame);
109 if (copyout((
void *) stack, frame,
sizeof(frame))) {
int arch_thread_create(struct thread *thread, uintptr_t stack, uintptr_t entry, uintptr_t uentry, uintptr_t arg)
Sets up a new user thread's CPU state and kernel stack, for pthread_create().
static void thread_spawn(void)
Runs a thread for the first time: lets go of the kernel lock, and drops to user mode.
void arch_kthread_create(struct thread *thread, uintptr_t entry)
Sets up a kernel thread's CPU state.
void arch_thread_switch(struct thread *thread)
Switches to a thread that has run before: its address space, its kernel stack, then where it stopped.
void arch_thread_kill(struct thread *thread)
Frees a thread's CPU state and kernel stack.
void arch_thread_spawn(struct thread *thread)
Runs a thread for the first time: switches to its address space and kernel stack, and starts it.
void x86_goto(uintptr_t eip, uintptr_t ebp, uintptr_t esp)
void x86_jump_user(uintptr_t eax, uintptr_t eip, uintptr_t cs, uintptr_t eflags, uintptr_t esp, uintptr_t ss)
void x86_thread_saved(uintptr_t ip, uintptr_t sp, uintptr_t bp)
Records where the current thread resumes when it is switched back to (x86_goto()),...
void x86_fpu_disable(void)
Makes the next FPU instruction trap (sets CR0.TS).
void x86_fpu_switch_out(void)
Saves the current thread's FPU state when it is switched out, if the FPU holds it,...
void x86_kernel_stack_set(uintptr_t sp)
Sets the kernel stack that interrupts from user mode switch to, on the running CPU: the thread that i...
struct cpu cpus[CPUS_MAX]
#define MALLOC_DEFINE(type, _name, _desc)
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
void kfree(void *)
Frees an object that kmalloc() gave.
void kernel_unlock(void)
Lets go of the kernel lock, for the next CPU waiting for it.
struct pmap * pmap_switch(struct pmap *pmap)
Switches this CPU to an address space's page tables.
struct thread * fpu_thread
An address space's page tables, on x86.
struct vm_space vm_space
its address space
void * arch
the architecture's own data: its registers, its kernel stack
struct proc * owner
its process
struct pmap * pmap
its page tables (the architecture's)
A thread's x86 state: its kernel stack, and where it resumes.
#define PUSH(stack, type, value)