Add an apps/ folder and build-system to build userspace apps which can now be loaded from the initrd

This commit is contained in:
apio 2022-10-01 12:17:16 +02:00
parent 9012ccc49e
commit 1c4383dea4
5 changed files with 32 additions and 7 deletions

View File

@ -10,7 +10,7 @@ ASMC := nasm
ASMFLAGS := -felf64
LD := x86_64-elf-ld
APP_LDFLAGS := -T$(APPS_DIR)/apps.ld -nostdlib
APP_LDFLAGS := -T$(APPS_DIR)/apps.ld -nostdlib -z max-page-size=0x1000
$(APPS_OBJ)/%.o: $(APPS_DIR)/%.asm
@mkdir -p $(@D)

View File

@ -1,9 +1,10 @@
ENTRY(_start)
OUTPUT_FORMAT(elf64-x86-64)
. = 0x2f00000000;
SECTIONS
{
. = 0x10000;
.text : ALIGN(16) {
KEEP(*(.text.boot)) *(.text .text.*) /* code */
*(.rodata .rodata.*) /* data */

View File

@ -1,5 +1,24 @@
section .text
global _start
_start:
mov rax, 1
int 42h
mov rdi, HelloLabel
mov rsi, 22
mov rax, 3
int 42h
mov rdi, 400
mov rax, 2
int 42h
mov rdi, ExitLabel
mov rsi, 31
mov rax, 3
int 42h
mov rax, 0
int 42h
int 42h
section .rodata
HelloLabel:
db "Hello from /bin/init!", 0xA
ExitLabel:
db "Well, bye. (/bin/init exiting)", 0xA

View File

@ -40,6 +40,7 @@ extern common_handler
section .text
global asm_common
asm_common:
cli
cld
push rax
push rbx

View File

@ -28,6 +28,7 @@
#include "std/stdio.h"
#include "std/stdlib.h"
#include "std/string.h"
#include "sys/elf/ELFLoader.h"
#include "thread/PIT.h"
#include "thread/Scheduler.h"
@ -125,10 +126,13 @@ extern "C" void _start()
}
});
uint64_t userspace_phys = kernelVMM.getPhysical((uint64_t)_userspace);
if (userspace_phys == UINT64_MAX) panic("_userspace is not mapped");
kernelVMM.map(0x7000, userspace_phys, MAP_USER);
Scheduler::add_user_task((void*)(0x7000 + ((uint64_t)_userspace % 4096)));
void* elf_start_address = ELFLoader::load_elf_from_initrd("bin/init");
if (!elf_start_address) kerrorln("failed to load /bin/init from initrd");
else
{
kinfoln("loaded /bin/init at %lx", (uint64_t)elf_start_address);
Scheduler::add_user_task(elf_start_address);
}
kinfoln("Prepared scheduler tasks");