AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
proc.c
Go to the documentation of this file.
1
4
5#include <core/system.h>
6#include <core/string.h>
7#include <core/panic.h>
8#include <core/arch.h>
9#include <sys/proc.h>
10#include <sys/sched.h>
11#include <sys/signal.h>
12#include <ds/queue.h>
13#include <mm/pmap.h>
14
15/*
16 * Sets up the x86 state of init's thread, at boot: a kernel stack, and a
17 * start at the program's entry point in user mode. Panics if there's no
18 * memory: the kernel can't go on without init.
19 */
21{
22 struct x86_thread *arch = kmalloc(sizeof(struct x86_thread), &M_X86_THREAD, M_ZERO);
23 uintptr_t kstack_base = arch ? (uintptr_t) kmalloc(KERN_STACK_SIZE, &M_KERN_STACK, 0) : 0;
24
25 if (!kstack_base)
26 panic("no memory for init's thread");
27
29 arch->kstack = kstack_base + KERN_STACK_SIZE; /* its top */
30#if ARCH_BITS==32
31 arch->eip = proc->entry;
32 arch->esp = USER_STACK;
33 arch->eflags = X86_EFLAGS;
34#else
35 arch->rip = proc->entry;
36 arch->rsp = USER_STACK;
37 arch->rflags = X86_EFLAGS;
38#endif
39
40 struct thread *thread = (struct thread *) proc->threads.head->value;
41 thread->arch = arch;
42}
#define USER_STACK
Definition arch.h:60
#define KERN_STACK_SIZE
Definition arch.h:68
void arch_proc_init(struct proc *proc)
Sets up the architecture's part of a new process's thread (init's, at boot): its kernel stack,...
Definition proc.c:19
#define X86_EFLAGS
Definition arch.h:12
#define panic(s)
Definition panic.h:15
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
Definition kvmem.c:123
#define M_ZERO
Definition kvmem.h:26
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
A process.
Definition proc.h:75
struct queue threads
its threads
Definition proc.h:136
uintptr_t entry
its program's entry point
Definition proc.h:126
void * value
Definition queue.h:20
struct qnode * head
Definition queue.h:31
A thread.
Definition thread.h:23
void * arch
the architecture's own data: its registers, its kernel stack
Definition thread.h:84
A thread's x86 state: its kernel stack, and where it resumes.
Definition arch.h:16
uintptr_t kstack_base
Definition arch.h:18
uintptr_t rip
Definition arch.h:27
uintptr_t rflags
Definition arch.h:30
uintptr_t rsp
Definition arch.h:28
uintptr_t kstack
Definition arch.h:17