Skip to content

Commit

Permalink
westeros: Preperations for VMM. Housekeeping.
Browse files Browse the repository at this point in the history
Signed-off-by: TunaCici <[email protected]>
  • Loading branch information
TunaCici committed Apr 4, 2024
1 parent c4fb076 commit 717989b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 58 deletions.
4 changes: 0 additions & 4 deletions Kernel/Arch/ARM64/Entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ _start:
ldr x2, =end_entry
mov x3, #0x00

/* Register vector tables */
adr x0, vector_table
msr vbar_el1, x0

/* Enable access to FPU & Advanced SIMD (NEON) */
mrs x0, CPACR_EL1
orr x0, x0, #(0x3 << 20)
Expand Down
12 changes: 7 additions & 5 deletions Kernel/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
#include "Memory/Physical.h"
#include "Memory/Virtual.h"

/* Kernel physical start & end addresses */
extern uint64_t kstart;
extern uint64_t kend;
extern uint64_t kend; /* in Kernel/kerne.ld */
extern uint64_t vector_table; /* in Kernel/Arch/ARM64/Vector.S */

void kmain(void)
{
volatile const uint8_t *kernel_start = (uint8_t*) &kstart;
volatile const uint8_t *kernel_end = (uint8_t*) &kend;
const void *kernel_end = &kend;

uint64_t mem_start = 0x0;
uint64_t mem_end = 0x0;
Expand All @@ -53,6 +51,10 @@ void kmain(void)
wfi();
}

/* X. Setup vector tables */
MSR("vbar_el1", vector_table);
isb();

/* 1. Init BootMem */
klog("[kmain] Initializing early memory manager...\n");

Expand Down
17 changes: 0 additions & 17 deletions Kernel/Start.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

extern void kmain(void);

extern uint64_t kstart;
extern uint64_t kend;

void _halt(const char *s)
{
klog("Halting due to: %s", s);
Expand All @@ -38,10 +35,6 @@ void start(void)
const char *_cpuModel = "Cortex A-72";
const uint32_t _coreCount = 2u;

/* Symbols. Defined in Kernel/kernel.ld */
const uint64_t *kernelBase = (uint64_t*) &kstart;
const uint64_t *kernelEnd = (uint64_t*) &kend;

klog("WesterOS early boot stage\n");
klog("Running sanity checks...\n");

Expand Down Expand Up @@ -129,9 +122,6 @@ void start(void)
kprintf("Unmasked\n");
}

MRS("VBAR_EL1", val64);
klog("---- Vector Table: 0x%lx\n", val64);

/* -------- Machine Layout -------- */
klog("QEMU ARM Virt Machine memory layout:\n");

Expand Down Expand Up @@ -163,13 +153,6 @@ void start(void)
DTB_START, DTB_END
);

klog ("---- Kernel: 0x%p - 0x%p (system)\n",
kernelBase,
kernelEnd
);

val64 = (kernelEnd - kernelBase);
klog("WesterOS kernel size: %lu bytes\n", val64);

klog("Everything's OK. Calling the Kernel now...\n");
kmain();
Expand Down
73 changes: 41 additions & 32 deletions Kernel/kernel.ld
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,85 @@ OUTPUT_ARCH(aarch64)
ENTRY(_start)

ENTRY_INIT_STACK_SIZE = 0x2000; /* 8 KiB */
KERNEL_VMA_BASE = 0xFFFF000000000000; /* TTBR1_EL1 lower boundary */

SECTIONS
{
/* the entry point, before enabling paging. The code to enable paing
* needs to have the same virtual/physical address. Entry.S and Start.c
* run in this initial setting.
/*
* The entry point, before enabling paging.
* The code to enable paging needs to have the same VA & PA.
* Only Entry.S and Start.c run in this initial setting.
*/

/* QEMU loads DTB at 0x00000000_40000000. So we skip 1MiB */
/* QEMU loads DTB at 0x00000000_40000000. So we skip over it (1MiB) */
. = 0x40100000;
PROVIDE (kstart = .);

.start_sec : {

.start_sec :
{
_start_sec = .;

Build/Entry.o(.text)
Build/Vector.o(.text)
Build/Start.o(.text .text.*)

Build/Entry.o(.rodata .rodata.*)
Build/Vector.o(.rodata .rodata.*)
Build/Start.o(.rodata .rodata.*)

Build/Entry.o(.data .data.*)
Build/Vector.o(.data .data.*)
Build/Start.o(.data .data.*)

PROVIDE(edata_entry = .);

Build/Entry.o(.bss .bss.* COMMON)
Build/Vector.o(.bss .bss.* COMMON)
Build/Start.o(.bss .bss.* COMMON)

/* Reserve space for stack */
/* Reserve stack space for kernel */
. = ALIGN(0x1000);
. += ENTRY_INIT_STACK_SIZE;

PROVIDE (init_stktop = .);

PROVIDE(end_entry = .);
. += 0x1000;
. = ALIGN(0x1000);
}

/* the kernel executes at the higher address space, but loaded
at the lower memory (0x30000) */
/*
* Kernel has two adresses:
* Load Memory Address (LMA): right after '.start_sec'
* Virtual Memory Address (VMA): right after 'KERNEL_VMA_BASE'
*
* https://sourceware.org/binutils/docs/ld/Basic-Script-Concepts.html
*/

/* . = KERNEL_VMA_BASE; */

.text : { /** here to make code also copied into phymem **/
.text : AT(ADDR(.start_sec) + SIZEOF(.start_sec))
{
_code = .;
*(.text .text.* .gnu.linkonce.t.*)
*(.rodata*)
. = ALIGN(0x1000);
}

PROVIDE(etext = .); /* Define the 'etext' symbol to this value */

.rodata : {
*(.rodata .rodata.* .gnu.linkonce.r.*)
}

/* aligned the data to a (4K) page, so it can be assigned
different protection than the code*/
. = ALIGN(0x1000);

PROVIDE (data_start = .);

.data : {
.data : AT(ADDR(.text) + SIZEOF(.text))
{
_data = .;
*(.data .data.*)
. = ALIGN(0x1000);
}

PROVIDE (edata = .);
.eh_frame : AT(ADDR(.data) + SIZEOF(.data))
{
_ehframe = .;
*(.eh_frame)
. = ALIGN(0x1000);
}

.bss : {
.bss : AT(ADDR(.eh_frame) + SIZEOF(.eh_frame))
{
_bss = .;
*(.bss .bss.* COMMON)
. = ALIGN(0x1000);
}

. = ALIGN(0x1000);
PROVIDE (kend = .);
}

0 comments on commit 717989b

Please sign in to comment.