AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
init.c File Reference

i386: the kernel's first steps in C, moving itself to the higher half. More...

#include <core/system.h>
#include <core/string.h>
#include <cpu/cpu.h>
#include <mm/mm.h>
#include <boot/multiboot.h>
#include <boot/boot.h>

Go to the source code of this file.

Macros

#define P   _BV(0)
#define RW   _BV(1)
#define PCD   _BV(4)

Functions

static void enable_paging (uintptr_t page_directory)
 Loads the page directory into CR3, and turns paging on.
static void switch_to_higher_half (void)
 Builds the boot page tables, which map the first ARCH_BOOT_MAPPED bytes of physical memory both at 0 and at the kernel's virtual base, and switches to them.
void x86_bootstrap ()
 Moves the kernel to the higher half and goes on to x86_cpu_init().

Variables

volatile uint32_t _BSP_PD [1024]
char kernel_end
char scratch [1024 *1024]

Detailed Description

i386: the kernel's first steps in C, moving itself to the higher half.

The boot code (multiboot.S) calls x86_bootstrap() with paging off. It builds boot page tables that map the start of physical memory twice, at 0 and at the kernel's virtual base (3 GiB), turns paging on, moves the stack to the higher half, and goes on to x86_cpu_init().

Only i386 builds this file: x86_64 does the same in assembly (x86_64_bootstrap.S).

Definition in file init.c.

Macro Definition Documentation

◆ P

#define P   _BV(0)

Definition at line 23 of file init.c.

Referenced by switch_to_higher_half().

◆ PCD

#define PCD   _BV(4)

Definition at line 25 of file init.c.

◆ RW

#define RW   _BV(1)

Definition at line 24 of file init.c.

Referenced by switch_to_higher_half().

Function Documentation

◆ enable_paging()

void enable_paging ( uintptr_t page_directory)
inlinestatic

Loads the page directory into CR3, and turns paging on.

Definition at line 31 of file init.c.

References CR0_PG, CR0_WP, and enable_paging().

Referenced by enable_paging(), and switch_to_higher_half().

◆ switch_to_higher_half()

void switch_to_higher_half ( void )
static

Builds the boot page tables, which map the first ARCH_BOOT_MAPPED bytes of physical memory both at 0 and at the kernel's virtual base, and switches to them.

Definition at line 44 of file init.c.

References _BSP_PD, ARCH_BOOT_MAPPED, enable_paging(), memset(), P, PAGE_SIZE, RW, scratch, switch_to_higher_half(), and TABLE_SIZE.

Referenced by switch_to_higher_half(), and x86_bootstrap().

◆ x86_bootstrap()

void x86_bootstrap ( )

Moves the kernel to the higher half and goes on to x86_cpu_init().

The boot code calls it; it doesn't return.

Definition at line 77 of file init.c.

References switch_to_higher_half(), VMA, x86_bootstrap(), and x86_cpu_init().

Referenced by x86_bootstrap().

Variable Documentation

◆ _BSP_PD

volatile uint32_t _BSP_PD[1024]

Definition at line 21 of file init.c.

Referenced by switch_to_higher_half().

◆ kernel_end

char kernel_end
extern

Referenced by boot_mem_place(), and buddy_setup().

◆ scratch

char scratch[1024 *1024]

Definition at line 28 of file init.c.

Referenced by switch_to_higher_half().