|
AquilaOS documentation
How it works, and its code
|
x86: a thread's CPU state, its kernel stack, and switching to it. More...
#include <core/system.h>#include <core/string.h>#include <core/arch.h>#include <sys/proc.h>#include <sys/sched.h>#include <sys/signal.h>#include <sys/lock.h>#include <sys/uaccess.h>#include <aquila/syscall.h>#include <ds/queue.h>#include <mm/pmap.h>Go to the source code of this file.
Macros | |
| #define | PUSH(stack, type, value) |
Functions | |
| static void | thread_spawn (void) |
| Starts the current thread in user mode, for the first time, from its own 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 | arch_thread_switch (struct thread *thread) |
| Switches to a thread that has run before: its address space, its kernel stack, then where it stopped. | |
| 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(). | |
| void | arch_kthread_create (struct thread *thread, uintptr_t entry) |
| Sets up a kernel thread's CPU state. | |
| void | arch_thread_kill (struct thread *thread) |
| Frees a thread's CPU state and kernel stack. | |
| 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()), with its registers saved on its kernel stack. | |
x86: a thread's CPU state, its kernel stack, and switching to it.
Definition in file thread.c.
| #define PUSH | ( | stack, | |
| type, | |||
| value ) |
Sets up a kernel thread's CPU state.
The thread starts at entry, a function without arguments that never returns, on its own kernel stack, once it is switched to.
| thread | the new thread; its arch stays NULL if there was no memory for its state |
| entry | the function it runs |
Definition at line 146 of file thread.c.
References thread::arch, arch_kthread_create(), KERN_STACK_SIZE, kfree(), kmalloc(), x86_thread::kstack, x86_thread::kstack_base, M_ZERO, NULL, PUSH, x86_thread::rbp, x86_thread::rflags, x86_thread::rip, x86_thread::rsp, and X86_EFLAGS.
| 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().
The thread will start at entry in user mode, on its user stack, and that code calls uentry with arg.
| thread | the new thread |
| stack | the top of its user stack |
| entry | where it starts in user mode (the C library's thread start routine) |
| uentry | the function that routine calls (the user's function) |
| arg | that function's argument |
Definition at line 91 of file thread.c.
References thread::arch, arch_thread_create(), KERN_STACK_SIZE, kfree(), kmalloc(), x86_thread::kstack, x86_thread::kstack_base, M_ZERO, NULL, PUSH, x86_thread::rflags, x86_thread::rip, x86_thread::rsp, and X86_EFLAGS.
| void arch_thread_kill | ( | struct thread * | thread | ) |
Frees a thread's CPU state and kernel stack.
The thread must not be running on them.
| thread | the thread |
Definition at line 186 of file thread.c.
References cpu::arch, thread::arch, arch_thread_kill(), cpus, cpus_count, curthread, x86_thread::fpu_context, arch_cpu::fpu_thread, kfree(), x86_thread::kstack_base, NULL, VMA, and x86_kernel_stack_set().
| 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.
It doesn't return.
| thread | the thread, which has never run |
Definition at line 47 of file thread.c.
References thread::arch, arch_thread_spawn(), x86_thread::kstack, thread::owner, vm_space::pmap, pmap_switch(), thread_spawn(), proc::vm_space, x86_fpu_disable(), x86_goto(), and x86_kernel_stack_set().
| 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.
It doesn't return.
| thread | the thread |
Definition at line 67 of file thread.c.
References thread::arch, arch_thread_switch(), x86_thread::kstack, thread::owner, vm_space::pmap, pmap_switch(), x86_thread::rbp, x86_thread::rip, x86_thread::rsp, proc::vm_space, x86_fpu_disable(), x86_goto(), and x86_kernel_stack_set().
|
static |
Starts the current thread in user mode, for the first time, from its own kernel stack.
It lets go of the kernel lock first; once it does, another CPU may run the thread that was running here.
Definition at line 30 of file thread.c.
References curthread, kernel_unlock(), x86_thread::rax, x86_thread::rflags, x86_thread::rip, x86_thread::rsp, thread_spawn(), X86_CS, x86_jump_user(), and X86_SS.
Records where the current thread resumes when it is switched back to (x86_goto()), with its registers saved on its kernel stack.
x86_sleep and x86_preempt call it, and it saves the thread's FPU state too.
| ip | where it resumes |
| sp | its stack pointer there |
| bp | its frame pointer there |
Definition at line 227 of file thread.c.
References curthread, x86_thread::rbp, x86_thread::rip, x86_thread::rsp, x86_fpu_switch_out(), and x86_thread_saved().
Referenced by x86_thread_saved().