AquilaOS documentation
How it works, and its code
Toggle main menu visibility
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
*/
20
void
arch_proc_init
(
struct
proc
*
proc
)
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
28
arch->
kstack_base
=
kstack_base
;
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
}
USER_STACK
#define USER_STACK
Definition
arch.h:60
KERN_STACK_SIZE
#define KERN_STACK_SIZE
Definition
arch.h:68
arch_proc_init
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
X86_EFLAGS
#define X86_EFLAGS
Definition
arch.h:12
panic
#define panic(s)
Definition
panic.h:15
arch.h
panic.h
system.h
pmap.h
kmalloc
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
Definition
kvmem.c:123
M_ZERO
#define M_ZERO
Definition
kvmem.h:26
proc.h
queue.h
sched.h
signal.h
uintptr_t
__SIZE_TYPE__ uintptr_t
Definition
stddef.h:12
string.h
proc
A process.
Definition
proc.h:75
proc::threads
struct queue threads
its threads
Definition
proc.h:136
proc::entry
uintptr_t entry
its program's entry point
Definition
proc.h:126
qnode::value
void * value
Definition
queue.h:20
queue::head
struct qnode * head
Definition
queue.h:31
thread
A thread.
Definition
thread.h:23
thread::arch
void * arch
the architecture's own data: its registers, its kernel stack
Definition
thread.h:84
x86_thread
A thread's x86 state: its kernel stack, and where it resumes.
Definition
arch.h:16
x86_thread::kstack_base
uintptr_t kstack_base
Definition
arch.h:18
x86_thread::rip
uintptr_t rip
Definition
arch.h:27
x86_thread::rflags
uintptr_t rflags
Definition
arch.h:30
x86_thread::rsp
uintptr_t rsp
Definition
arch.h:28
x86_thread::kstack
uintptr_t kstack
Definition
arch.h:17
kernel
arch
i386
sys
proc.c
Generated by
1.18.0