AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
init.c
Go to the documentation of this file.
1
6
7#include <boot/boot.h>
8#include <console/earlycon.h>
9#include <core/arch.h>
10#include <core/kargs.h>
11#include <core/printk.h>
12#include <cpu/cpu.h>
13#include <mm/mm.h>
14#include <mm/vm.h>
15#include <sys/cpu.h>
16#include <sys/lock.h>
17#include <platform/virt.h>
18
19struct boot *__kboot;
20
21/* The boot CPU's idle loop's stack. */
22static char bsp_idle_stack[8192] __aligned(16);
23
24/* User mode's use of the FP/SIMD registers traps (CPACR_EL1.FPEN = 0b01)
25 * until cpu/fpsimd.c gives them to its thread; the kernel uses none. */
26#define CPACR_FPEN_TRAP (1UL << 20)
27
35{
36 /* the boot CPU's struct cpu first: curcpu() and curthread need it */
37 struct cpu *bsp = &cpus[0];
38 bsp->self = bsp;
39 bsp->id = 0;
41 cpus_count = 1;
42 write_sysreg(tpidr_el1, bsp);
43
44 /* the kernel lock is the kernel's until the first process runs */
46
48 printk("aarch64: Welcome to AquilaOS!\n");
49 printk("aarch64: running at EL%d, the devicetree at %p\n",
50 (int) (read_sysreg(CurrentEL) >> 2), (void *) dtb);
51
52 /* the exception vectors, so that an exception is reported rather than
53 * hanging the CPU */
54 extern char aarch64_vectors[];
55 write_sysreg(vbar_el1, aarch64_vectors);
56 write_sysreg(cpacr_el1, CPACR_FPEN_TRAP);
57 isb();
58
59 struct boot *boot = fdt_boot(dtb);
60 __kboot = boot;
61
64
67
69
70 extern void kmain(struct boot *);
71 kmain(boot);
72}
static char bsp_idle_stack[8192]
Definition init.c:22
#define CPACR_FPEN_TRAP
Definition init.c:26
void aarch64_init(uintptr_t dtb)
Sets up the CPU, memory and the platform, then calls kmain().
Definition init.c:34
struct boot * __kboot
Definition init.c:19
void earlycon_reinit(void)
Sets up the early console again, once the kernel's command line has been read, since it may choose an...
Definition earlycon.c:65
void earlycon_init(void)
Sets up the early console at boot, before anything else.
Definition earlycon.c:59
struct boot * fdt_boot(uintptr_t dtb)
Reads the boot loader's devicetree into a struct boot.
Definition fdt.c:78
#define read_sysreg(r)
Definition cpu.h:33
#define isb()
Definition cpu.h:45
#define write_sysreg(r, v)
Definition cpu.h:39
#define __aligned(n)
Definition system.h:31
void mm_setup(struct boot *boot)
Sets up physical memory at boot, from the boot loader's memory map: the page structures,...
Definition mm.c:365
struct cpu cpus[CPUS_MAX]
Definition sched.c:28
int cpus_count
Definition sched.c:29
int kargs_parse(const char *_cmdline)
Splits the kernel's command line into arguments, at boot.
Definition kargs.c:31
void kernel_lock(void)
Takes the kernel lock, waiting for its turn if another CPU holds it.
Definition lock.c:32
void kmain(struct boot *boot)
Starts the kernel's generic part, once the architecture has set up the CPU, memory and the platform.
Definition main.c:38
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
Definition printk.c:249
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
uintptr_t idle_stack
Definition cpu.h:55
Definition boot.h:35
char * cmdline
Definition boot.h:36
A processor, and what runs on it.
Definition cpu.h:11
int id
Definition cpu.h:13
struct cpu * self
Definition cpu.h:12
struct arch_cpu arch
Definition cpu.h:17
int platform_init(void)
Definition init.c:31
void kvmem_setup(void)
Sets up the kernel's allocator at boot, once physical memory and the page tables are ready.
Definition kvmem.c:55