Finished Aurix Protocol, AxBoot logs to file now
This commit is contained in:
parent
b1d59e02eb
commit
d1a5d7d43d
37 changed files with 744 additions and 221 deletions
17
Makefile
17
Makefile
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
.DEFAULT_GOAL := all
|
.DEFAULT_GOAL := all
|
||||||
|
|
||||||
|
GITREV := $(shell git rev-parse --short HEAD)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Build configuration
|
# Build configuration
|
||||||
#
|
#
|
||||||
|
@ -43,7 +45,7 @@ LIVECD := $(RELEASE_DIR)/aurix-$(GITREV)-livecd_$(ARCH)-$(PLATFORM).iso
|
||||||
LIVEHDD := $(RELEASE_DIR)/aurix-$(GITREV)-livehdd_$(ARCH)-$(PLATFORM).img
|
LIVEHDD := $(RELEASE_DIR)/aurix-$(GITREV)-livehdd_$(ARCH)-$(PLATFORM).img
|
||||||
LIVESD := $(RELEASE_DIR)/aurix-$(GITREV)-livesd_$(ARCH)-$(PLATFORM).img
|
LIVESD := $(RELEASE_DIR)/aurix-$(GITREV)-livesd_$(ARCH)-$(PLATFORM).img
|
||||||
|
|
||||||
QEMU_FLAGS := -m 2G -smp 4 -rtc base=localtime -serial stdio
|
QEMU_FLAGS := -m 512m -smp 4 -rtc base=localtime -serial stdio
|
||||||
|
|
||||||
# QEMU Audio support
|
# QEMU Audio support
|
||||||
#QEMU_FLAGS += -audiodev coreaudio,id=coreaudio0 -device ich9-intel-hda -device hda-output,audiodev=coreaudio0
|
#QEMU_FLAGS += -audiodev coreaudio,id=coreaudio0 -device ich9-intel-hda -device hda-output,audiodev=coreaudio0
|
||||||
|
@ -52,7 +54,10 @@ QEMU_FLAGS := -m 2G -smp 4 -rtc base=localtime -serial stdio
|
||||||
QEMU_FLAGS += -usb -device usb-mouse
|
QEMU_FLAGS += -usb -device usb-mouse
|
||||||
|
|
||||||
# x86_64
|
# x86_64
|
||||||
|
# TODO: Move this elsewhere
|
||||||
|
ifeq ($(ARCH),x86_64)
|
||||||
QEMU_FLAGS += -machine q35
|
QEMU_FLAGS += -machine q35
|
||||||
|
endif
|
||||||
|
|
||||||
##
|
##
|
||||||
# General info
|
# General info
|
||||||
|
@ -130,15 +135,17 @@ livesd: install
|
||||||
@mkdir -p $(RELEASE_DIR)
|
@mkdir -p $(RELEASE_DIR)
|
||||||
@utils/arch/$(ARCH)/generate-sd.sh $(LIVESD)
|
@utils/arch/$(ARCH)/generate-sd.sh $(LIVESD)
|
||||||
|
|
||||||
|
# TODO: Maybe don't run with -hda but -drive?
|
||||||
.PHONY: run
|
.PHONY: run
|
||||||
run: livecd
|
run: livehdd
|
||||||
@printf ">>> Running QEMU...\n"
|
@printf ">>> Running QEMU...\n"
|
||||||
@qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -cdrom $(LIVECD)
|
@qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -hda $(LIVEHDD)
|
||||||
|
|
||||||
|
# TODO: Maybe don't run with -hda but -drive?
|
||||||
.PHONY: run-uefi
|
.PHONY: run-uefi
|
||||||
run-uefi: livecd ovmf
|
run-uefi: livehdd ovmf
|
||||||
@printf ">>> Running QEMU (UEFI)...\n"
|
@printf ">>> Running QEMU (UEFI)...\n"
|
||||||
@qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -bios ovmf/ovmf-$(ARCH).fd -cdrom $(LIVECD)
|
@qemu-system-$(ARCH) $(QEMU_FLAGS) $(QEMU_MACHINE_FLAGS) -bios ovmf/ovmf-$(ARCH).fd -hda $(LIVEHDD)
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|
|
@ -31,6 +31,8 @@ export ASFLAGS := $(foreach d, $(DEFINES), -D$d)
|
||||||
export CFLAGS := $(foreach d, $(DEFINES), -D$d) -Wall -Wextra -Wno-unused-local-typedef -ffreestanding -fno-stack-protector -fno-stack-check -MMD -MP
|
export CFLAGS := $(foreach d, $(DEFINES), -D$d) -Wall -Wextra -Wno-unused-local-typedef -ffreestanding -fno-stack-protector -fno-stack-check -MMD -MP
|
||||||
export LDFLAGS := -nostdlib
|
export LDFLAGS := -nostdlib
|
||||||
|
|
||||||
|
include arch/$(ARCH)/config.mk
|
||||||
|
|
||||||
export BOOT_ROOT := $(ROOT_DIR)/boot
|
export BOOT_ROOT := $(ROOT_DIR)/boot
|
||||||
|
|
||||||
ifeq ($(BUILD_TYPE),debug)
|
ifeq ($(BUILD_TYPE),debug)
|
||||||
|
|
0
boot/arch/aarch64/config.mk
Normal file
0
boot/arch/aarch64/config.mk
Normal file
1
boot/arch/i686/config.mk
Normal file
1
boot/arch/i686/config.mk
Normal file
|
@ -0,0 +1 @@
|
||||||
|
CFLAGS += -DARCH_ACPI_AVAILABLE -DARCH_SMBIOS_AVAILABLE
|
|
@ -58,10 +58,6 @@ static void _map(pagetable *pm, uintptr_t virt, uintptr_t phys, uint64_t flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
pagetable *pml1_table = (pagetable *)(pml2_table->entries[pml2_idx] & 0x000FFFFFFFFFF000);
|
pagetable *pml1_table = (pagetable *)(pml2_table->entries[pml2_idx] & 0x000FFFFFFFFFF000);
|
||||||
if ((pml1_table->entries[pml1_idx] & 1)) {
|
|
||||||
// debug("_map(): Remapping present page\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
pml1_table->entries[pml1_idx] = (phys & 0x000FFFFFFFFFF000) | flags;
|
pml1_table->entries[pml1_idx] = (phys & 0x000FFFFFFFFFF000) | flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
95
boot/arch/x86_64/common/proto/aurix/handoff.c
Normal file
95
boot/arch/x86_64/common/proto/aurix/handoff.c
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/*********************************************************************************/
|
||||||
|
/* Module Name: handoff.c */
|
||||||
|
/* Project: AurixOS */
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2024-2025 Jozef Nagy */
|
||||||
|
/* */
|
||||||
|
/* This source is subject to the MIT License. */
|
||||||
|
/* See License.txt in the root of this repository. */
|
||||||
|
/* All other rights reserved. */
|
||||||
|
/* */
|
||||||
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
|
||||||
|
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
|
||||||
|
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
|
||||||
|
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
|
||||||
|
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
|
||||||
|
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
|
||||||
|
/* SOFTWARE. */
|
||||||
|
/*********************************************************************************/
|
||||||
|
|
||||||
|
#include <arch/cpu/gdt.h>
|
||||||
|
#include <arch/cpu/idt.h>
|
||||||
|
#include <proto/aurix.h>
|
||||||
|
#include <mm/vmm.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct gdt {
|
||||||
|
struct gdt_descriptor null;
|
||||||
|
struct gdt_descriptor kcode;
|
||||||
|
struct gdt_descriptor kdata;
|
||||||
|
struct gdt_descriptor ucode;
|
||||||
|
struct gdt_descriptor udata;
|
||||||
|
struct tss_descriptor tss;
|
||||||
|
};
|
||||||
|
|
||||||
|
void aurix_arch_handoff(void *kernel_entry, pagetable *pm, void *stack, uint32_t stack_size, struct aurix_parameters *parameters)
|
||||||
|
{
|
||||||
|
struct tss tss = {
|
||||||
|
.iomap_base = sizeof(struct tss),
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gdt gdt = {
|
||||||
|
.tss = {
|
||||||
|
.gdt = {
|
||||||
|
.base_low = ((uintptr_t)&tss) & 0xFFFF,
|
||||||
|
.base_mid = (((uintptr_t)&tss) >> 16) & 0xFF,
|
||||||
|
.base_high = (((uintptr_t)&tss) >> 24) & 0xFF,
|
||||||
|
.access = 0b10001001
|
||||||
|
},
|
||||||
|
.base_high = (((uintptr_t)&tss) >> 32) & 0xFFFF
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gdtr gdtr = {
|
||||||
|
.base = (uint64_t)&gdt,
|
||||||
|
.limit = sizeof(gdt) - 1
|
||||||
|
};
|
||||||
|
|
||||||
|
gdt_set_entry(&gdt.null, 0, 0, 0, 0);
|
||||||
|
gdt_set_entry(&gdt.kcode, 0, 0, 0x9a, 0xaf);
|
||||||
|
gdt_set_entry(&gdt.kdata, 0, 0, 0x92, 0xcf);
|
||||||
|
gdt_set_entry(&gdt.ucode, 0, 0, 0xfa, 0xaf);
|
||||||
|
gdt_set_entry(&gdt.udata, 0, 0, 0xf2, 0xcf);
|
||||||
|
|
||||||
|
struct idtr idtr = {
|
||||||
|
.base = (uint64_t)0,
|
||||||
|
.limit = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
__asm__ volatile(
|
||||||
|
"cli\n"
|
||||||
|
"lgdt %[gdtr]\n"
|
||||||
|
"ltr %[tss]\n"
|
||||||
|
"pushq $0x08\n"
|
||||||
|
"lea 1f(%%rip), %%rax\n"
|
||||||
|
"pushq %%rax\n"
|
||||||
|
"lretq\n"
|
||||||
|
"1:\n"
|
||||||
|
"movq $0x10, %%rax\n"
|
||||||
|
"movq %%rax, %%ds\n"
|
||||||
|
"movq %%rax, %%es\n"
|
||||||
|
"movq %%rax, %%ss\n"
|
||||||
|
"movq %%rax, %%fs\n"
|
||||||
|
"movq %%rax, %%gs\n"
|
||||||
|
|
||||||
|
"lidt %[idt]\n"
|
||||||
|
|
||||||
|
"movq %[pml4], %%cr3\n"
|
||||||
|
"movq %[stack], %%rsp\n"
|
||||||
|
"movq %[params], %%rdi\n"
|
||||||
|
"callq *%[entry]\n"
|
||||||
|
:: [gdtr]"g"(gdtr), [tss]"r"((uint16_t)__builtin_offsetof(struct gdt, tss)),
|
||||||
|
[idt]"g"(idtr),
|
||||||
|
[pml4]"r"(pm), [stack]"r"(stack + stack_size),
|
||||||
|
[entry]"r"(kernel_entry), [params]"d"(parameters) : "rax", "memory");
|
||||||
|
}
|
|
@ -1,24 +0,0 @@
|
||||||
.globl _aurix_handoff_start
|
|
||||||
.globl _aurix_handoff_end
|
|
||||||
.globl aurix_handoff
|
|
||||||
|
|
||||||
_aurix_handoff_start:
|
|
||||||
aurix_handoff:
|
|
||||||
cli
|
|
||||||
movq %rsi, %rsp
|
|
||||||
.section _aurix_handoff
|
|
||||||
movq %rdi, %cr3
|
|
||||||
xor %rax, %rax
|
|
||||||
xor %rbx, %rbx
|
|
||||||
xor %rcx, %rcx
|
|
||||||
xor %rdi, %rdi
|
|
||||||
xor %r8, %r8
|
|
||||||
xor %r9, %r9
|
|
||||||
xor %r10, %r10
|
|
||||||
xor %r11, %r11
|
|
||||||
xor %r12, %r12
|
|
||||||
xor %r13, %r13
|
|
||||||
xor %r14, %r14
|
|
||||||
xor %r15, %r15
|
|
||||||
callq *%rdx
|
|
||||||
_aurix_handoff_end:
|
|
1
boot/arch/x86_64/config.mk
Normal file
1
boot/arch/x86_64/config.mk
Normal file
|
@ -0,0 +1 @@
|
||||||
|
CFLAGS += -DARCH_ACPI_AVAILABLE -DARCH_SMBIOS_AVAILABLE
|
|
@ -18,10 +18,10 @@
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
|
|
||||||
#include <config/config.h>
|
#include <config/config.h>
|
||||||
#include <config/ini.h>
|
|
||||||
#include <lib/string.h>
|
#include <lib/string.h>
|
||||||
#include <loader/loader.h>
|
#include <loader/loader.h>
|
||||||
#include <mm/mman.h>
|
#include <mm/mman.h>
|
||||||
|
#include <time/dt.h>
|
||||||
#include <vfs/vfs.h>
|
#include <vfs/vfs.h>
|
||||||
#include <print.h>
|
#include <print.h>
|
||||||
#include <axboot.h>
|
#include <axboot.h>
|
||||||
|
@ -47,8 +47,9 @@ struct axboot_cfg cfg = {
|
||||||
.timeout = DEFAULT_TIMEOUT,
|
.timeout = DEFAULT_TIMEOUT,
|
||||||
.ui_mode = UI_TEXT,
|
.ui_mode = UI_TEXT,
|
||||||
|
|
||||||
//.entry_count = 0
|
//.entry_count = 0,
|
||||||
.entry_count = 2
|
.entry_count = 2,
|
||||||
|
.bootlog_filename = NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
struct axboot_entry entries[2] = {
|
struct axboot_entry entries[2] = {
|
||||||
|
@ -69,6 +70,20 @@ struct axboot_entry entries[2] = {
|
||||||
|
|
||||||
void config_init(void)
|
void config_init(void)
|
||||||
{
|
{
|
||||||
|
// create a filename for boot log
|
||||||
|
// format: \AXBOOT_LOG-YY-MM-DD_HHMMSS.txt
|
||||||
|
char bootlog_fn[33];
|
||||||
|
struct datetime dt;
|
||||||
|
get_datetime(&dt);
|
||||||
|
|
||||||
|
snprintf(bootlog_fn, 33, "\\AXBOOT_LOG-%u-%u-%u_%u%u%u.txt", dt.year, dt.month, dt.day, dt.h, dt.m, dt.s);
|
||||||
|
cfg.bootlog_filename = (char *)mem_alloc(ARRAY_LENGTH(bootlog_fn));
|
||||||
|
if (!cfg.bootlog_filename) {
|
||||||
|
debug("Error!\n");
|
||||||
|
} else {
|
||||||
|
strncpy(cfg.bootlog_filename, (char *)&bootlog_fn, 33);
|
||||||
|
}
|
||||||
|
|
||||||
char *config_buf = NULL;
|
char *config_buf = NULL;
|
||||||
uint8_t open = 0;
|
uint8_t open = 0;
|
||||||
|
|
||||||
|
@ -81,7 +96,7 @@ void config_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (open == 0) {
|
if (open == 0) {
|
||||||
debug("Couldn't open a configuration file! Entering console...\n");
|
debug("config_init(): Couldn't open a configuration file! Entering console...\n");
|
||||||
//console();
|
//console();
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ struct vfs_drive *sfs_init(char *mountpoint)
|
||||||
|
|
||||||
fs->fsdata = fsdata;
|
fs->fsdata = fsdata;
|
||||||
fs->read = sfs_read;
|
fs->read = sfs_read;
|
||||||
fs->write = NULL; // sfs_write()
|
fs->write = sfs_write;
|
||||||
|
|
||||||
struct vfs_drive *drive = (struct vfs_drive *)mem_alloc(sizeof(struct vfs_drive));
|
struct vfs_drive *drive = (struct vfs_drive *)mem_alloc(sizeof(struct vfs_drive));
|
||||||
if (drive == NULL) {
|
if (drive == NULL) {
|
||||||
|
@ -121,7 +121,7 @@ size_t sfs_read(char *filename, char **buffer, struct vfs_drive *dev, void *fsda
|
||||||
wfilename[n] = L'\0';
|
wfilename[n] = L'\0';
|
||||||
|
|
||||||
/* open the file */
|
/* open the file */
|
||||||
status = volume->Open(volume, &file, wfilename, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM);
|
status = volume->Open(volume, &file, wfilename, EFI_FILE_MODE_READ, 0);
|
||||||
if (EFI_ERROR(status)) {
|
if (EFI_ERROR(status)) {
|
||||||
debug("sfs_read(): Failed to open file '%s': %s (%lx)\n", filename, efi_status_to_str(status), status);
|
debug("sfs_read(): Failed to open file '%s': %s (%lx)\n", filename, efi_status_to_str(status), status);
|
||||||
mem_free(wfilename);
|
mem_free(wfilename);
|
||||||
|
@ -159,4 +159,49 @@ size_t sfs_read(char *filename, char **buffer, struct vfs_drive *dev, void *fsda
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t sfs_write(char *filename, char *buffer, size_t size, struct vfs_drive *dev, void *fsdata)
|
||||||
|
{
|
||||||
|
(void)dev;
|
||||||
|
|
||||||
|
struct sfs_fsdata *data = (struct sfs_fsdata *)fsdata;
|
||||||
|
EFI_FILE_PROTOCOL *volume = data->volume;
|
||||||
|
EFI_FILE_PROTOCOL *file;
|
||||||
|
CHAR16 *wfilename;
|
||||||
|
EFI_STATUS status = EFI_SUCCESS;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
wfilename = (CHAR16 *)mem_alloc(strlen(filename) * sizeof(CHAR16));
|
||||||
|
if (!wfilename) {
|
||||||
|
debug("sfs_write(): Failed to allocate memory for wide strings!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t n = mbstowcs(wfilename, (const char **)&filename, strlen(filename));
|
||||||
|
wfilename[n] = L'\0';
|
||||||
|
|
||||||
|
/* open the file */
|
||||||
|
status = volume->Open(volume, &file, wfilename, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, EFI_FILE_SYSTEM);
|
||||||
|
if (EFI_ERROR(status)) {
|
||||||
|
debug("sfs_write(): Failed to open file '%s': %s (%lx)\n", filename, efi_status_to_str(status), status);
|
||||||
|
mem_free(wfilename);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
mem_free(wfilename);
|
||||||
|
|
||||||
|
// set position to the end of the file
|
||||||
|
file->SetPosition(file, 0xffffffffffffffff);
|
||||||
|
|
||||||
|
status = file->Write(file, &size, buffer);
|
||||||
|
if (EFI_ERROR(status)) {
|
||||||
|
debug("sfs_write(): Failed to read file '%s': %s (%lx)\n", filename, efi_status_to_str(status), status);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* close the file */
|
||||||
|
file->Close(file);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -31,18 +31,18 @@ void axboot_init()
|
||||||
uart_init(115200);
|
uart_init(115200);
|
||||||
|
|
||||||
if (!vfs_init("\\")) {
|
if (!vfs_init("\\")) {
|
||||||
debug("axboot_init(): Failed to mount boot drive! Halting...\n");
|
log("axboot_init(): Failed to mount boot drive! Halting...\n");
|
||||||
// TODO: Halt
|
// TODO: Halt
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config_init();
|
||||||
|
|
||||||
#ifdef AXBOOT_UEFI
|
#ifdef AXBOOT_UEFI
|
||||||
#include <driver.h>
|
#include <driver.h>
|
||||||
load_drivers();
|
load_drivers();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//config_init();
|
|
||||||
|
|
||||||
// boot straight away
|
// boot straight away
|
||||||
if (config_get_timeout() < 1) {
|
if (config_get_timeout() < 1) {
|
||||||
struct axboot_entry *entries = config_get_entries();
|
struct axboot_entry *entries = config_get_entries();
|
||||||
|
@ -51,16 +51,6 @@ void axboot_init()
|
||||||
|
|
||||||
ui_init();
|
ui_init();
|
||||||
|
|
||||||
debug("axboot_init(): Returned from main menu, something went wrong. Halting!");
|
log("axboot_init(): Returned from main menu, something went wrong. Halting!");
|
||||||
//UNREACHABLE();
|
|
||||||
|
|
||||||
// just boot aurixos for now
|
|
||||||
struct axboot_entry axos = {
|
|
||||||
.name = "AurixOS",
|
|
||||||
.description = "",
|
|
||||||
.image_path = "\\System\\axkrnl",
|
|
||||||
.protocol = PROTO_AURIX
|
|
||||||
};
|
|
||||||
loader_load(&axos);
|
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
|
@ -28,14 +28,15 @@
|
||||||
/* https://github.com/KevinAlavik/nekonix/blob/main/kernel/src/proc/elf.c */
|
/* https://github.com/KevinAlavik/nekonix/blob/main/kernel/src/proc/elf.c */
|
||||||
/* Thanks, Kevin <3 */
|
/* Thanks, Kevin <3 */
|
||||||
|
|
||||||
uintptr_t elf32_load(char *data, pagetable *pagemap)
|
uintptr_t elf32_load(char *data, uintptr_t *addr, pagetable *pagemap)
|
||||||
{
|
{
|
||||||
(void)data;
|
(void)data;
|
||||||
|
(void)addr;
|
||||||
(void)pagemap;
|
(void)pagemap;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t elf64_load(char *data, pagetable *pagemap)
|
uintptr_t elf64_load(char *data, uintptr_t *addr, pagetable *pagemap)
|
||||||
{
|
{
|
||||||
struct elf_header *header = (struct elf_header *)data;
|
struct elf_header *header = (struct elf_header *)data;
|
||||||
struct elf_program_header *ph = (struct elf_program_header *)((uint8_t *)data + header->e_phoff);
|
struct elf_program_header *ph = (struct elf_program_header *)((uint8_t *)data + header->e_phoff);
|
||||||
|
@ -65,42 +66,46 @@ uintptr_t elf64_load(char *data, pagetable *pagemap)
|
||||||
|
|
||||||
uint64_t phys = ((uint64_t)mem_alloc(ph[i].p_memsz + ph[i].p_vaddr - aligned_vaddr + 4096) + 4096) & ~0xFFF;
|
uint64_t phys = ((uint64_t)mem_alloc(ph[i].p_memsz + ph[i].p_vaddr - aligned_vaddr + 4096) + 4096) & ~0xFFF;
|
||||||
if (!phys) {
|
if (!phys) {
|
||||||
debug("elf64_load(): Out of memory\n");
|
log("elf64_load(): Out of memory\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("elf64_load(): phys=0x%llx, virt=0x%llx, size=%lu\n", phys, ph[i].p_vaddr, ph[i].p_filesz);
|
if (addr != NULL && *addr == 0) {
|
||||||
|
*addr = phys;
|
||||||
|
}
|
||||||
|
|
||||||
|
log("elf64_load(): phys=0x%llx, virt=0x%llx, size=%lu\n", phys, ph[i].p_vaddr, ph[i].p_filesz);
|
||||||
|
|
||||||
map_page(pagemap, aligned_vaddr, phys, flags);
|
map_page(pagemap, aligned_vaddr, phys, flags);
|
||||||
memcpy((void*)(phys + ph[i].p_vaddr - aligned_vaddr), data + ph[i].p_offset, ph[i].p_filesz);
|
memcpy((void*)(phys + ph[i].p_vaddr - aligned_vaddr), data + ph[i].p_offset, ph[i].p_filesz);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("elf64_load(): ELF loaded successfully, entry: 0x%llx\n", header->e_entry);
|
log("elf64_load(): ELF loaded successfully, entry: 0x%llx\n", header->e_entry);
|
||||||
return (uintptr_t)header->e_entry;
|
return (uintptr_t)header->e_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t elf_load(char *data, pagetable *pagemap)
|
uintptr_t elf_load(char *data, uintptr_t *addr, pagetable *pagemap)
|
||||||
{
|
{
|
||||||
struct elf_header *header = (struct elf_header *)data;
|
struct elf_header *header = (struct elf_header *)data;
|
||||||
|
|
||||||
if (header->e_magic != ELF_MAGIC) {
|
if (header->e_magic != ELF_MAGIC) {
|
||||||
debug("Invalid ELF magic: 0x%x", header->e_magic);
|
log("Invalid ELF magic: 0x%x", header->e_magic);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header->e_class != 2) {
|
if (header->e_class != 2) {
|
||||||
debug("Unsupported ELF class: %u", header->e_class);
|
log("Unsupported ELF class: %u", header->e_class);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header->e_machine == 20 ||
|
if (header->e_machine == 20 ||
|
||||||
header->e_machine == 3 ||
|
header->e_machine == 3 ||
|
||||||
header->e_machine == 40) {
|
header->e_machine == 40) {
|
||||||
return elf32_load(data, pagemap);
|
return elf32_load(data, addr, pagemap);
|
||||||
} else if (header->e_machine == 62) {
|
} else if (header->e_machine == 62) {
|
||||||
return elf64_load(data, pagemap);
|
return elf64_load(data, addr, pagemap);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Unsupported ELF machine: %u", header->e_machine);
|
log("Unsupported ELF machine: %u", header->e_machine);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ int proto_str_to_int(char *proto)
|
||||||
|
|
||||||
void loader_load(struct axboot_entry *entry)
|
void loader_load(struct axboot_entry *entry)
|
||||||
{
|
{
|
||||||
debug("loader_load(): Booting \"%s\"...\n", entry->name);
|
log("loader_load(): Booting \"%s\"...\n", entry->name);
|
||||||
|
|
||||||
switch (entry->protocol) {
|
switch (entry->protocol) {
|
||||||
case PROTO_AURIX: {
|
case PROTO_AURIX: {
|
||||||
|
@ -49,7 +49,7 @@ void loader_load(struct axboot_entry *entry)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
debug("Entry doesn't have a supported protocol!\n");
|
log("Entry doesn't have a supported protocol!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ int find_alloc(void *addr)
|
||||||
int add_alloc(void *addr, size_t size)
|
int add_alloc(void *addr, size_t size)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_ALLOCATIONS; i++) {
|
for (int i = 0; i < MAX_ALLOCATIONS; i++) {
|
||||||
if (allocation_list[i].addr == 0) {
|
if (allocation_list[i].addr == NULL) {
|
||||||
allocation_list[i].addr = addr;
|
allocation_list[i].addr = addr;
|
||||||
allocation_list[i].size = size;
|
allocation_list[i].size = size;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -112,8 +112,6 @@ void *mem_alloc(size_t n)
|
||||||
}
|
}
|
||||||
|
|
||||||
add_alloc(alloc, n);
|
add_alloc(alloc, n);
|
||||||
|
|
||||||
debug("mem_alloc(): Allocated %u bytes\n", n);
|
|
||||||
return alloc;
|
return alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +126,6 @@ int mem_allocat(void *addr, size_t npages)
|
||||||
}
|
}
|
||||||
|
|
||||||
add_alloc(addr, npages * PAGE_SIZE);
|
add_alloc(addr, npages * PAGE_SIZE);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +149,6 @@ void *mem_realloc(void *addr, size_t n)
|
||||||
|
|
||||||
memcpy(new, addr, old_size);
|
memcpy(new, addr, old_size);
|
||||||
mem_free(addr);
|
mem_free(addr);
|
||||||
|
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,9 +166,8 @@ void mem_free(void *addr)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("mem_free(): Freed 0x%llx\n", addr);
|
|
||||||
|
|
||||||
remove_alloc(addr);
|
remove_alloc(addr);
|
||||||
|
debug("mem_free(): Freed 0x%llx\n", addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
#define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 0
|
#define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 0
|
||||||
#include <nanoprintf.h>
|
#include <nanoprintf.h>
|
||||||
|
|
||||||
|
#include <config/config.h>
|
||||||
#include <uart/uart.h>
|
#include <uart/uart.h>
|
||||||
|
#include <vfs/vfs.h>
|
||||||
#include <print.h>
|
#include <print.h>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
@ -38,22 +40,29 @@ int32_t _fltused = 0;
|
||||||
int32_t __eqdf2 = 0;
|
int32_t __eqdf2 = 0;
|
||||||
int32_t __ltdf2 = 0;
|
int32_t __ltdf2 = 0;
|
||||||
|
|
||||||
|
extern struct axboot_cfg cfg;
|
||||||
|
|
||||||
void log(const char *fmt, ...)
|
void log(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[4096];
|
char buf[1024];
|
||||||
|
size_t size = 0;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
npf_vsnprintf(buf, sizeof(buf), fmt, args);
|
size = npf_vsnprintf(buf, sizeof(buf), fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
uart_sendstr(buf);
|
uart_sendstr(buf);
|
||||||
|
|
||||||
|
if (cfg.bootlog_filename != NULL) {
|
||||||
|
vfs_write(cfg.bootlog_filename, (char *)&buf, size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug(const char *fmt, ...)
|
void debug(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[4096];
|
char buf[1024];
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
npf_vsnprintf(buf, sizeof(buf), fmt, args);
|
npf_vsnprintf(buf, sizeof(buf), fmt, args);
|
||||||
|
|
|
@ -17,67 +17,190 @@
|
||||||
/* SOFTWARE. */
|
/* SOFTWARE. */
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
|
|
||||||
|
#include <acpi/acpi.h>
|
||||||
#include <proto/aurix.h>
|
#include <proto/aurix.h>
|
||||||
#include <loader/elf.h>
|
#include <loader/elf.h>
|
||||||
#include <mm/mman.h>
|
#include <mm/mman.h>
|
||||||
#include <mm/memmap.h>
|
#include <mm/memmap.h>
|
||||||
#include <mm/vmm.h>
|
#include <mm/vmm.h>
|
||||||
|
#include <lib/string.h>
|
||||||
|
#include <ui/framebuffer.h>
|
||||||
#include <vfs/vfs.h>
|
#include <vfs/vfs.h>
|
||||||
#include <print.h>
|
#include <print.h>
|
||||||
#include <axboot.h>
|
#include <axboot.h>
|
||||||
#include <efi.h>
|
|
||||||
#include <efilib.h>
|
|
||||||
|
|
||||||
extern __attribute__((noreturn)) void aurix_handoff(void *pagemap, void *stack, uint64_t entry, void *params);
|
#include <stdint.h>
|
||||||
extern char _aurix_handoff_start[], _aurix_handoff_end[];
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#define AURIX_STACK_SIZE 16*1024
|
||||||
|
|
||||||
|
bool aurix_get_memmap(struct aurix_parameters *params, axboot_memmap *mmap, uint32_t mmap_entries, pagetable *pm)
|
||||||
|
{
|
||||||
|
if (params == NULL || mmap == NULL || pm == NULL || mmap_entries == 0) {
|
||||||
|
log("aurix_get_memmap(): Invalid parameter!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// UEFI returns an unnecessarily large memory map with regions of the same type
|
||||||
|
// being split into multiple entries (probably due to memory attributes, which we do not care about).
|
||||||
|
for (uint32_t i = 0; i < mmap_entries; i++) {
|
||||||
|
if (i == mmap_entries - 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (mmap[i].base + mmap[i].size >= mmap[i+1].base && mmap[i].type == mmap[i+1].type) {
|
||||||
|
mmap[i].size += mmap[i+1].size;
|
||||||
|
for (uint32_t j = i+1; j < mmap_entries; j++) {
|
||||||
|
mmap[j].base = mmap[j+1].base;
|
||||||
|
mmap[j].size = mmap[j+1].size;
|
||||||
|
mmap[j].type = mmap[j+1].type;
|
||||||
|
}
|
||||||
|
mmap_entries--;
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy the memory map over to kernel parameters
|
||||||
|
params->mmap = (struct aurix_memmap *)mem_alloc(sizeof(struct aurix_memmap) * mmap_entries);
|
||||||
|
if (!(params->mmap)) {
|
||||||
|
log("aurix_get_memmap(): Failed to allocate memory for storing memory map!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
params->mmap_entries = mmap_entries;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < mmap_entries; i++) {
|
||||||
|
params->mmap[i].base = mmap[i].base;
|
||||||
|
params->mmap[i].size = mmap[i].size;
|
||||||
|
switch (mmap[i].type) {
|
||||||
|
case MemMapReserved:
|
||||||
|
case MemMapFaulty:
|
||||||
|
case MemMapFirmware:
|
||||||
|
params->mmap[i].type = AURIX_MMAP_RESERVED;
|
||||||
|
break;
|
||||||
|
case MemMapACPIReclaimable:
|
||||||
|
params->mmap[i].type = AURIX_MMAP_ACPI_RECLAIMABLE;
|
||||||
|
break;
|
||||||
|
case MemMapACPIMappedIO:
|
||||||
|
params->mmap[i].type = AURIX_MMAP_ACPI_MAPPED_IO;
|
||||||
|
break;
|
||||||
|
case MemMapACPIMappedIOPortSpace:
|
||||||
|
params->mmap[i].type = AURIX_MMAP_ACPI_MAPPED_IO_PORTSPACE;
|
||||||
|
break;
|
||||||
|
case MemMapACPINVS:
|
||||||
|
params->mmap[i].type = AURIX_MMAP_ACPI_NVS;
|
||||||
|
break;
|
||||||
|
case MemMapFreeOnLoad:
|
||||||
|
params->mmap[i].type = AURIX_MMAP_BOOTLOADER_RECLAIMABLE;
|
||||||
|
break;
|
||||||
|
case MemMapUsable:
|
||||||
|
params->mmap[i].type = AURIX_MMAP_USABLE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log("aurix_get_memmap(): Unknown memory type in entry %u (%u), setting as reserved.\n", i, mmap[i].type);
|
||||||
|
params->mmap[i].type = AURIX_MMAP_RESERVED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool aurix_get_framebuffer(struct aurix_parameters *params)
|
||||||
|
{
|
||||||
|
struct fb_mode *modes;
|
||||||
|
int current_mode;
|
||||||
|
uint32_t *fb_addr;
|
||||||
|
|
||||||
|
params->framebuffer = (struct aurix_framebuffer *)mem_alloc(sizeof(struct aurix_framebuffer));
|
||||||
|
if (!(params->framebuffer)) {
|
||||||
|
log("aurix_get_framebuffer(): Failed to allocate memory for framebuffer information!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!get_framebuffer(&fb_addr, &modes, NULL, ¤t_mode)) {
|
||||||
|
log("aurix_get_framebuffer(): get_framebuffer() returned false, setting everything to 0.\n");
|
||||||
|
memset(params->framebuffer, 0, sizeof(struct aurix_framebuffer));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
params->framebuffer->addr = (uintptr_t)fb_addr;
|
||||||
|
params->framebuffer->width = modes[current_mode].width;
|
||||||
|
params->framebuffer->height = modes[current_mode].height;
|
||||||
|
params->framebuffer->bpp = modes[current_mode].bpp;
|
||||||
|
params->framebuffer->pitch = modes[current_mode].pitch;
|
||||||
|
params->framebuffer->format = modes[current_mode].format;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void aurix_load(char *kernel_path)
|
void aurix_load(char *kernel_path)
|
||||||
{
|
{
|
||||||
// read kernel -> test read
|
|
||||||
char *kbuf = NULL;
|
char *kbuf = NULL;
|
||||||
vfs_read(kernel_path, &kbuf);
|
vfs_read(kernel_path, &kbuf);
|
||||||
|
|
||||||
// TODO: Do something with the kernel :p
|
|
||||||
pagetable *pm = create_pagemap();
|
pagetable *pm = create_pagemap();
|
||||||
if (!pm) {
|
if (!pm) {
|
||||||
debug("aurix_load(): Failed to create kernel pagemap! Halting...\n");
|
log("aurix_load(): Failed to create kernel pagemap! Halting...\n");
|
||||||
// TODO: Halt
|
// TODO: Halt
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
axboot_memmap *memmap = get_memmap(pm);
|
axboot_memmap *mmap;
|
||||||
(void)memmap;
|
uint32_t mmap_entries = get_memmap(&mmap, pm);
|
||||||
|
|
||||||
map_pages(pm, (uintptr_t)pm, (uintptr_t)pm, PAGE_SIZE, VMM_WRITABLE);
|
map_pages(pm, (uintptr_t)pm, (uintptr_t)pm, PAGE_SIZE, VMM_WRITABLE);
|
||||||
map_pages(pm, (uintptr_t)_aurix_handoff_start, (uintptr_t)_aurix_handoff_start, (uint64_t)_aurix_handoff_end - (uint64_t)_aurix_handoff_start, 0);
|
|
||||||
|
|
||||||
void *stack = mem_alloc(16*1024); // 16 KiB stack should be well more than enough
|
void *stack = mem_alloc(AURIX_STACK_SIZE); // 16 KiB stack should be well more than enough
|
||||||
if (!stack) {
|
if (!stack) {
|
||||||
debug("aurix_load(): Failed to allocate stack! Halting...\n");
|
log("aurix_load(): Failed to allocate stack! Halting...\n");
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
memset(stack, 0, AURIX_STACK_SIZE);
|
||||||
|
|
||||||
map_pages(pm, (uintptr_t)stack, (uintptr_t)stack, 16*1024, VMM_WRITABLE | VMM_NX);
|
map_pages(pm, (uintptr_t)stack, (uintptr_t)stack, AURIX_STACK_SIZE, VMM_WRITABLE | VMM_NX);
|
||||||
|
|
||||||
void *kernel_entry = (void *)elf_load(kbuf, pm);
|
uintptr_t kernel_addr = 0;
|
||||||
|
void *kernel_entry = (void *)elf_load(kbuf, &kernel_addr, pm);
|
||||||
if (!kernel_entry) {
|
if (!kernel_entry) {
|
||||||
debug("aurix_load(): Failed to load '%s'! Halting...\n", kernel_path);
|
log("aurix_load(): Failed to load '%s'! Halting...\n", kernel_path);
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
// mem_free(kbuf);
|
mem_free(kbuf);
|
||||||
|
|
||||||
void *parameters = NULL;
|
struct aurix_parameters parameters = {0};
|
||||||
(void)parameters;
|
|
||||||
|
|
||||||
debug("aurix_load(): Handoff state: pm=0x%llx, stack=0x%llx, kernel_entry=0x%llx\n", pm, stack, kernel_entry);
|
// set current revision
|
||||||
|
parameters.revision = AURIX_PROTOCOL_REVISION;
|
||||||
|
|
||||||
// this triggers a #GP ????
|
// translate memory map
|
||||||
// aurix_handoff(pm, stack, (uint64_t)kernel_entry, (void *)parameters);
|
if (!aurix_get_memmap(¶meters, mmap, mmap_entries, pm)) {
|
||||||
// __builtin_unreachable();
|
log("aurix_load(): Failed to aqcuire memory map!");
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
|
||||||
__asm__ volatile("movq %[pml4], %%cr3\n"
|
parameters.kernel_addr = kernel_addr;
|
||||||
"movq %[stack], %%rsp\n"
|
|
||||||
"callq *%[entry]\n"
|
// get RSDP and SMBIOS
|
||||||
:: [pml4]"r"(pm), [stack]"r"(stack + (16 * 1024)), [entry]"r"(kernel_entry) : "memory");
|
#ifdef ARCH_ACPI_AVAILABLE
|
||||||
|
parameters.rsdp_addr = platform_get_rsdp();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ARCH_SMBIOS_AVAILABLE
|
||||||
|
parameters.smbios_addr = platform_get_smbios();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// get framebuffer information
|
||||||
|
if (!aurix_get_framebuffer(¶meters)) {
|
||||||
|
log("aurix_load(): Failed to aqcuire framebuffer information!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// map framebuffer
|
||||||
|
map_pages(pm, parameters.framebuffer->addr, parameters.framebuffer->addr, parameters.framebuffer->height * parameters.framebuffer->pitch, VMM_WRITABLE);
|
||||||
|
|
||||||
|
log("aurix_load(): Handoff state: pm=0x%llx, stack=0x%llx, kernel_entry=0x%llx\n", pm, stack, kernel_entry);
|
||||||
|
#ifdef AXBOOT_UEFI
|
||||||
|
uefi_exit_bs();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
aurix_arch_handoff(kernel_entry, pm, stack, AURIX_STACK_SIZE, ¶meters);
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,19 +36,19 @@ int vfs_init(char *root_mountpoint)
|
||||||
{
|
{
|
||||||
boot_drive = mount_boot_volume(root_mountpoint);
|
boot_drive = mount_boot_volume(root_mountpoint);
|
||||||
if (boot_drive == NULL) {
|
if (boot_drive == NULL) {
|
||||||
debug("vfs_init(): Failed to allocate memory for VFS!\n");
|
log("vfs_init(): Failed to allocate memory for VFS!\n");
|
||||||
// fuck off and boot out early.
|
// fuck off and boot out early.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("vfs_init(): Mounted boot drive to \"/\"\n");
|
log("vfs_init(): Mounted boot drive to \"\\\"\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t vfs_read(char *filename, char **buf)
|
size_t vfs_read(char *filename, char **buf)
|
||||||
{
|
{
|
||||||
if (boot_drive->fs->read == NULL) {
|
if (boot_drive->fs->read == NULL) {
|
||||||
debug("vfs_read(): Filesystem didn't set up a read function!");
|
log("vfs_read(): Filesystem didn't set up a read function!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +57,10 @@ size_t vfs_read(char *filename, char **buf)
|
||||||
|
|
||||||
int vfs_write(char *filename, char *buf, size_t len)
|
int vfs_write(char *filename, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
(void)filename;
|
if (boot_drive->fs->write == NULL) {
|
||||||
(void)buf;
|
log("vfs_read(): Filesystem didn't setup a write function!\n");
|
||||||
(void)len;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return boot_drive->fs->write(filename, buf, len, boot_drive, boot_drive->fs->fsdata);
|
||||||
}
|
}
|
28
boot/include/acpi/acpi.h
Normal file
28
boot/include/acpi/acpi.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*********************************************************************************/
|
||||||
|
/* Module Name: acpi.h */
|
||||||
|
/* Project: AurixOS */
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2024-2025 Jozef Nagy */
|
||||||
|
/* */
|
||||||
|
/* This source is subject to the MIT License. */
|
||||||
|
/* See License.txt in the root of this repository. */
|
||||||
|
/* All other rights reserved. */
|
||||||
|
/* */
|
||||||
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
|
||||||
|
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
|
||||||
|
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
|
||||||
|
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
|
||||||
|
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
|
||||||
|
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
|
||||||
|
/* SOFTWARE. */
|
||||||
|
/*********************************************************************************/
|
||||||
|
|
||||||
|
#ifndef _ACPI_ACPI_H
|
||||||
|
#define _ACPI_ACPI_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
uintptr_t platform_get_rsdp(void);
|
||||||
|
uintptr_t platform_get_smbios(void);
|
||||||
|
|
||||||
|
#endif /* _ACPI_ACPI_H */
|
|
@ -1,5 +1,5 @@
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
/* Module Name: ini.h */
|
/* Module Name: idt.h */
|
||||||
/* Project: AurixOS */
|
/* Project: AurixOS */
|
||||||
/* */
|
/* */
|
||||||
/* Copyright (c) 2024-2025 Jozef Nagy */
|
/* Copyright (c) 2024-2025 Jozef Nagy */
|
||||||
|
@ -17,70 +17,17 @@
|
||||||
/* SOFTWARE. */
|
/* SOFTWARE. */
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
|
|
||||||
#ifndef _CONFIG_INI_H
|
#ifndef _ARCH_CPU_IDT_H
|
||||||
#define _CONFIG_INI_H
|
#define _ARCH_CPU_IDT_H
|
||||||
|
|
||||||
enum token_type {
|
#include <stdint.h>
|
||||||
SECTION,
|
|
||||||
KEY,
|
|
||||||
VALUE,
|
|
||||||
|
|
||||||
EOF,
|
struct idt_descriptor {
|
||||||
ILLEGAL,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct string_view {
|
struct idtr {
|
||||||
char *data;
|
uint16_t limit;
|
||||||
unsigned int len;
|
uint64_t base;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct token {
|
#endif /* _ARCH_CPU_IDT_H */
|
||||||
enum token_type type;
|
|
||||||
struct string_view lit;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct token_array {
|
|
||||||
struct token *items;
|
|
||||||
unsigned int count;
|
|
||||||
unsigned int capacity;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct lexer {
|
|
||||||
char *input;
|
|
||||||
unsigned int pos;
|
|
||||||
unsigned int read_pos;
|
|
||||||
char ch;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct parser {
|
|
||||||
struct token_array *tokens;
|
|
||||||
unsigned int pos;
|
|
||||||
unsigned int read_pos;
|
|
||||||
struct token *cur_token;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct key_value {
|
|
||||||
struct string_view key;
|
|
||||||
struct string_view value;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct section {
|
|
||||||
struct string_view name;
|
|
||||||
struct key_value *items;
|
|
||||||
unsigned int count;
|
|
||||||
unsigned int capacity;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ini_file {
|
|
||||||
struct section root;
|
|
||||||
struct section *items;
|
|
||||||
unsigned int count;
|
|
||||||
unsigned int capacity;
|
|
||||||
};
|
|
||||||
|
|
||||||
void parse_ini(struct ini_file *ini, char *buf);
|
|
||||||
|
|
||||||
char *ini_get_value(struct ini_file *ini, char *section, char *key);
|
|
||||||
int ini_get_value_int(struct ini_file *ini, char *section, char *key);
|
|
||||||
|
|
||||||
#endif /* _CONFIG_INI_H */
|
|
|
@ -34,4 +34,9 @@
|
||||||
|
|
||||||
void axboot_init(void);
|
void axboot_init(void);
|
||||||
|
|
||||||
|
// I really had no idea where to put this
|
||||||
|
#ifdef AXBOOT_UEFI
|
||||||
|
void uefi_exit_bs(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _AXBOOT_H */
|
#endif /* _AXBOOT_H */
|
|
@ -32,6 +32,7 @@ struct axboot_cfg {
|
||||||
int ui_mode;
|
int ui_mode;
|
||||||
|
|
||||||
int entry_count;
|
int entry_count;
|
||||||
|
char *bootlog_filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct axboot_entry {
|
struct axboot_entry {
|
||||||
|
|
|
@ -32,8 +32,8 @@ struct driver {
|
||||||
EFI_MEMMAP_DEVICE_PATH devpath[2];
|
EFI_MEMMAP_DEVICE_PATH devpath[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void load_drivers();
|
void load_drivers();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _DRIVER_H */
|
#endif /* _DRIVER_H */
|
|
@ -26,5 +26,6 @@
|
||||||
struct vfs_drive *sfs_init(char *mountpoint);
|
struct vfs_drive *sfs_init(char *mountpoint);
|
||||||
|
|
||||||
size_t sfs_read(char *filename, char **buffer, struct vfs_drive *dev, void *fsdata);
|
size_t sfs_read(char *filename, char **buffer, struct vfs_drive *dev, void *fsdata);
|
||||||
|
uint8_t sfs_write(char *filename, char *buffer, size_t size, struct vfs_drive *dev, void *fsdata);
|
||||||
|
|
||||||
#endif /* _FS_UEFI_SFS_H */
|
#endif /* _FS_UEFI_SFS_H */
|
||||||
|
|
|
@ -73,6 +73,6 @@ struct elf_program_header {
|
||||||
#define PF_W 0x2
|
#define PF_W 0x2
|
||||||
#define PF_R 0x4
|
#define PF_R 0x4
|
||||||
|
|
||||||
uintptr_t elf_load(char *kernel, pagetable *pagemap);
|
uintptr_t elf_load(char *kernel, uintptr_t *addr, pagetable *pagemap);
|
||||||
|
|
||||||
#endif /* _LOADER_ELF_H */
|
#endif /* _LOADER_ELF_H */
|
||||||
|
|
|
@ -46,6 +46,6 @@ typedef struct _axboot_memmap {
|
||||||
int type;
|
int type;
|
||||||
} axboot_memmap;
|
} axboot_memmap;
|
||||||
|
|
||||||
axboot_memmap *get_memmap(pagetable *pm);
|
uint32_t get_memmap(axboot_memmap **map, pagetable *pm);
|
||||||
|
|
||||||
#endif /* _MEM_MEMMAP_H */
|
#endif /* _MEM_MEMMAP_H */
|
|
@ -17,9 +17,68 @@
|
||||||
/* SOFTWARE. */
|
/* SOFTWARE. */
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
|
|
||||||
#ifndef _PROTO_AURIX_H
|
#ifndef _AURIX_H
|
||||||
#define _PROTO_AURIX_H
|
#define _AURIX_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define AURIX_PROTOCOL_REVISION 1
|
||||||
|
|
||||||
|
enum aurix_memmap_entry {
|
||||||
|
AURIX_MMAP_RESERVED = 0,
|
||||||
|
|
||||||
|
AURIX_MMAP_ACPI_RECLAIMABLE = 1,
|
||||||
|
AURIX_MMAP_ACPI_MAPPED_IO = 2,
|
||||||
|
AURIX_MMAP_ACPI_MAPPED_IO_PORTSPACE = 3,
|
||||||
|
AURIX_MMAP_ACPI_NVS = 4,
|
||||||
|
|
||||||
|
AURIX_MMAP_BOOTLOADER_RECLAIMABLE = 6,
|
||||||
|
AURIX_MMAP_USABLE = 7
|
||||||
|
};
|
||||||
|
|
||||||
|
enum aurix_framebuffer_format {
|
||||||
|
AURIX_FB_RGBA = 0,
|
||||||
|
AURIX_FB_BGRA = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
struct aurix_memmap {
|
||||||
|
uintptr_t base;
|
||||||
|
uint32_t size;
|
||||||
|
uint8_t type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct aurix_framebuffer {
|
||||||
|
uintptr_t addr;
|
||||||
|
uint32_t width;
|
||||||
|
uint32_t height;
|
||||||
|
uint8_t bpp; // bits!
|
||||||
|
uint32_t pitch;
|
||||||
|
int format;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct aurix_parameters {
|
||||||
|
// PROTOCOL INFO
|
||||||
|
uint8_t revision;
|
||||||
|
|
||||||
|
// MEMORY
|
||||||
|
struct aurix_memmap *mmap;
|
||||||
|
uint32_t mmap_entries;
|
||||||
|
|
||||||
|
uintptr_t kernel_addr; // physical address
|
||||||
|
|
||||||
|
// RSDP and SMBIOS
|
||||||
|
uintptr_t rsdp_addr;
|
||||||
|
uintptr_t smbios_addr;
|
||||||
|
|
||||||
|
// FRAMEBUFFER
|
||||||
|
struct aurix_framebuffer *framebuffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef _AXBOOT
|
||||||
|
#include <mm/vmm.h>
|
||||||
void aurix_load(char *kernel);
|
void aurix_load(char *kernel);
|
||||||
|
|
||||||
|
void aurix_arch_handoff(void *kernel_entry, pagetable *pm, void *stack, uint32_t stack_size, struct aurix_parameters *parameters);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _PROTO_AURIX_H */
|
#endif /* _PROTO_AURIX_H */
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
enum fb_format {
|
enum fb_format {
|
||||||
FB_RGBA,
|
FB_RGBA = 0,
|
||||||
FB_BGRA
|
FB_BGRA = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fb_mode {
|
struct fb_mode {
|
||||||
|
|
77
boot/platform/uefi/acpi.c
Normal file
77
boot/platform/uefi/acpi.c
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/*********************************************************************************/
|
||||||
|
/* Module Name: acpi.c */
|
||||||
|
/* Project: AurixOS */
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2024-2025 Jozef Nagy */
|
||||||
|
/* */
|
||||||
|
/* This source is subject to the MIT License. */
|
||||||
|
/* See License.txt in the root of this repository. */
|
||||||
|
/* All other rights reserved. */
|
||||||
|
/* */
|
||||||
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
|
||||||
|
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
|
||||||
|
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
|
||||||
|
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
|
||||||
|
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
|
||||||
|
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
|
||||||
|
/* SOFTWARE. */
|
||||||
|
/*********************************************************************************/
|
||||||
|
|
||||||
|
#include <lib/string.h>
|
||||||
|
#include <print.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <efi.h>
|
||||||
|
#include <efilib.h>
|
||||||
|
|
||||||
|
uintptr_t platform_get_rsdp()
|
||||||
|
{
|
||||||
|
EFI_GUID acpi10_guid = EFI_ACPI_10_TABLE_GUID;
|
||||||
|
EFI_GUID acpi20_guid = EFI_ACPI_20_TABLE_GUID;
|
||||||
|
uintptr_t rsdp_addr = 0;
|
||||||
|
|
||||||
|
for (EFI_UINTN i = 0; i < gSystemTable->NumberOfTableEntries; i++) {
|
||||||
|
if (memcmp(&(gSystemTable->ConfigurationTable[i].VendorGuid), &acpi10_guid, sizeof(EFI_GUID)) == 0) {
|
||||||
|
log("platform_get_rsdp(): Found RSDP (ACPI 1.0) at 0x%llx\n", gSystemTable->ConfigurationTable[i].VendorTable);
|
||||||
|
rsdp_addr = (uintptr_t)gSystemTable->ConfigurationTable[i].VendorTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ACPI 2.0+ always takes higher priority over older version
|
||||||
|
if (memcmp(&(gSystemTable->ConfigurationTable[i].VendorGuid), &acpi20_guid, sizeof(EFI_GUID)) == 0) {
|
||||||
|
log("platform_get_rsdp(): Found RSDP (ACPI 2.0+) at 0x%llx\n", gSystemTable->ConfigurationTable[i].VendorTable);
|
||||||
|
return (uintptr_t)gSystemTable->ConfigurationTable[i].VendorTable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rsdp_addr == 0) {
|
||||||
|
log("platform_get_rsdp(): RSDP not found!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return rsdp_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
uintptr_t platform_get_smbios()
|
||||||
|
{
|
||||||
|
EFI_GUID smbios_guid = SMBIOS_TABLE_GUID;
|
||||||
|
EFI_GUID smbios3_guid = SMBIOS3_TABLE_GUID;
|
||||||
|
uintptr_t smbios_addr = 0;
|
||||||
|
|
||||||
|
for (EFI_UINTN i = 0; i < gSystemTable->NumberOfTableEntries; i++) {
|
||||||
|
if (memcmp(&(gSystemTable->ConfigurationTable[i].VendorGuid), &smbios_guid, sizeof(EFI_GUID)) == 0) {
|
||||||
|
log("platform_get_rsmbios(): Found SMBIOS at 0x%llx\n", gSystemTable->ConfigurationTable[i].VendorTable);
|
||||||
|
smbios_addr = (uintptr_t)gSystemTable->ConfigurationTable[i].VendorTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
// SMBIOS3 always takes higher priority over older version
|
||||||
|
if (memcmp(&(gSystemTable->ConfigurationTable[i].VendorGuid), &smbios3_guid, sizeof(EFI_GUID)) == 0) {
|
||||||
|
log("platform_get_smbios(): Found SMBIOS3 at 0x%llx\n", gSystemTable->ConfigurationTable[i].VendorTable);
|
||||||
|
return (uintptr_t)gSystemTable->ConfigurationTable[i].VendorTable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (smbios_addr == 0) {
|
||||||
|
log("platform_get_smbios(): SMBIOS not found!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return smbios_addr;
|
||||||
|
}
|
|
@ -36,7 +36,7 @@ bool verify_secure_boot()
|
||||||
bool ret = 0;
|
bool ret = 0;
|
||||||
|
|
||||||
if (!EFI_ERROR(gSystemTable->RuntimeServices->GetVariable(L"SecureBoot", &var_guid, NULL, &size, &val))) {
|
if (!EFI_ERROR(gSystemTable->RuntimeServices->GetVariable(L"SecureBoot", &var_guid, NULL, &size, &val))) {
|
||||||
debug("verify_secure_boot(): Secure Boot Status: %u\n", val);
|
log("verify_secure_boot(): Secure Boot Status: %u\n", val);
|
||||||
ret = (bool)val;
|
ret = (bool)val;
|
||||||
|
|
||||||
if (!EFI_ERROR(gSystemTable->RuntimeServices->GetVariable(L"SetupMode", &var_guid, NULL, &size, &val)) && val != 0) {
|
if (!EFI_ERROR(gSystemTable->RuntimeServices->GetVariable(L"SetupMode", &var_guid, NULL, &size, &val)) && val != 0) {
|
||||||
|
@ -51,14 +51,14 @@ void load_drivers()
|
||||||
{
|
{
|
||||||
// EFI_STATUS status;
|
// EFI_STATUS status;
|
||||||
if (!verify_secure_boot()) {
|
if (!verify_secure_boot()) {
|
||||||
debug("load_drivers(): Secure boot is enabled! Won't load drivers...\n");
|
log("load_drivers(): Secure boot is enabled! Won't load drivers...\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Create a vfs_list() function to get a list of files in a directory
|
// TODO: Create a vfs_list() function to get a list of files in a directory
|
||||||
// char *driver_path = "\\AxBoot\\drivers\\.efi";
|
// char *driver_path = "\\AxBoot\\drivers\\.efi";
|
||||||
// char *driver_binary;
|
// char *driver_binary;
|
||||||
// debug("load_drivers(): Loading '%s'...\n", driver_name);
|
// log("load_drivers(): Loading '%s'...\n", driver_name);
|
||||||
//
|
//
|
||||||
// size_t driver_size = vfs_read(driver_path, &driver_binary);
|
// size_t driver_size = vfs_read(driver_path, &driver_binary);
|
||||||
//
|
//
|
||||||
|
@ -76,13 +76,13 @@ void load_drivers()
|
||||||
//
|
//
|
||||||
// status = gSystemTable->BootServices->LoadImage(EFI_FALSE, gImageHandle, (EFI_DEVICE_PATH_PROTOCOL *)driver_devpath, driver_binary, driver_size, &driver_handle);
|
// status = gSystemTable->BootServices->LoadImage(EFI_FALSE, gImageHandle, (EFI_DEVICE_PATH_PROTOCOL *)driver_devpath, driver_binary, driver_size, &driver_handle);
|
||||||
// if (EFI_ERROR(status)) {
|
// if (EFI_ERROR(status)) {
|
||||||
// debug("load_drivers(): Failed to load driver '%s': %s (%llx)\n", driver_name, efi_status_to_str(status), status);
|
// log("load_drivers(): Failed to load driver '%s': %s (%llx)\n", driver_name, efi_status_to_str(status), status);
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// status = gSystemTable->BootServices->StartImage(driver_handle, NULL, NULL);
|
// status = gSystemTable->BootServices->StartImage(driver_handle, NULL, NULL);
|
||||||
// if (EFI_ERROR(status)) {
|
// if (EFI_ERROR(status)) {
|
||||||
// debug("load_drivers(): Failed to start driver '%s': %s (%llx)\n", driver_name, efi_status_to_str(status), status);
|
// log("load_drivers(): Failed to start driver '%s': %s (%llx)\n", driver_name, efi_status_to_str(status), status);
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
|
@ -23,15 +23,12 @@
|
||||||
#include <axboot.h>
|
#include <axboot.h>
|
||||||
#include <mm/mman.h>
|
#include <mm/mman.h>
|
||||||
#include <lib/string.h>
|
#include <lib/string.h>
|
||||||
|
#include <power.h>
|
||||||
#include <print.h>
|
#include <print.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#define INI_IMPLEMENTATION
|
|
||||||
#include <config/ini.h>
|
|
||||||
|
|
||||||
|
|
||||||
EFI_HANDLE gImageHandle;
|
EFI_HANDLE gImageHandle;
|
||||||
EFI_SYSTEM_TABLE *gSystemTable;
|
EFI_SYSTEM_TABLE *gSystemTable;
|
||||||
EFI_BOOT_SERVICES *gBootServices;
|
EFI_BOOT_SERVICES *gBootServices;
|
||||||
|
@ -96,3 +93,50 @@ EFI_STATUS uefi_entry(EFI_HANDLE ImageHandle,
|
||||||
axboot_init();
|
axboot_init();
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define EXIT_BS_MAX_TRIES 10
|
||||||
|
|
||||||
|
void uefi_exit_bs(void)
|
||||||
|
{
|
||||||
|
EFI_UINTN map_key = 0;
|
||||||
|
EFI_UINTN map_size = 0;
|
||||||
|
EFI_MEMORY_DESCRIPTOR *map = NULL;
|
||||||
|
EFI_UINTN desc_size = 0;
|
||||||
|
EFI_UINT32 desc_ver = 0;
|
||||||
|
EFI_STATUS status;
|
||||||
|
|
||||||
|
int tries = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
map_key = 0;
|
||||||
|
map_size = 0;
|
||||||
|
desc_size = 0;
|
||||||
|
desc_ver = 0;
|
||||||
|
map = NULL;
|
||||||
|
|
||||||
|
tries++;
|
||||||
|
debug("uefi_exit_bs(): Trying to exit Boot Services, try %u/%u...\n", tries, EXIT_BS_MAX_TRIES);
|
||||||
|
|
||||||
|
status = gBootServices->GetMemoryMap(&map_size, map, &map_key, &desc_size, &desc_ver);
|
||||||
|
if (EFI_ERROR(status) && status != EFI_BUFFER_TOO_SMALL) {
|
||||||
|
log("uefi_exit_bs(): Failed to acquire memory map key: %s (%llx)\n", efi_status_to_str(status), status);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = gBootServices->ExitBootServices(gImageHandle, map_key);
|
||||||
|
if (EFI_ERROR(status)) {
|
||||||
|
log("uefi_exit_bs(): Failed to exit boot services: %s (%llx)\n", efi_status_to_str(status), status);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
} while (tries <= EXIT_BS_MAX_TRIES);
|
||||||
|
|
||||||
|
if (EFI_ERROR(status)) {
|
||||||
|
log("uefi_exit_bs(): Failed to exit Boot Services, rebooting!");
|
||||||
|
platform_reboot();
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
debug("uefi_exit_bs(): ExitBootServices() success!\n");
|
||||||
|
}
|
||||||
|
|
|
@ -30,42 +30,46 @@
|
||||||
static int efi_type_to_axboot(uint32_t efi_type)
|
static int efi_type_to_axboot(uint32_t efi_type)
|
||||||
{
|
{
|
||||||
switch (efi_type) {
|
switch (efi_type) {
|
||||||
case EfiReservedMemoryType:
|
|
||||||
return MemMapReserved;
|
|
||||||
case EfiLoaderCode:
|
|
||||||
return MemMapFirmware;
|
|
||||||
case EfiLoaderData:
|
case EfiLoaderData:
|
||||||
return MemMapFirmware;
|
|
||||||
case EfiBootServicesCode:
|
case EfiBootServicesCode:
|
||||||
case EfiBootServicesData:
|
case EfiBootServicesData:
|
||||||
return MemMapFreeOnLoad;
|
return MemMapFreeOnLoad;
|
||||||
|
|
||||||
case EfiRuntimeServicesCode:
|
case EfiRuntimeServicesCode:
|
||||||
case EfiRuntimeServicesData:
|
case EfiRuntimeServicesData:
|
||||||
|
case EfiLoaderCode:
|
||||||
return MemMapFirmware;
|
return MemMapFirmware;
|
||||||
case EfiConventionalMemory:
|
|
||||||
return MemMapUsable;
|
|
||||||
case EfiUnusableMemory:
|
case EfiUnusableMemory:
|
||||||
return MemMapFaulty;
|
return MemMapFaulty;
|
||||||
|
|
||||||
case EfiACPIReclaimMemory:
|
case EfiACPIReclaimMemory:
|
||||||
return MemMapACPIReclaimable;
|
return MemMapACPIReclaimable;
|
||||||
|
|
||||||
case EfiACPIMemoryNVS:
|
case EfiACPIMemoryNVS:
|
||||||
return MemMapACPINVS;
|
return MemMapACPINVS;
|
||||||
|
|
||||||
case EfiMemoryMappedIO:
|
case EfiMemoryMappedIO:
|
||||||
return MemMapACPIMappedIO;
|
return MemMapACPIMappedIO;
|
||||||
|
|
||||||
case EfiMemoryMappedIOPortSpace:
|
case EfiMemoryMappedIOPortSpace:
|
||||||
return MemMapACPIMappedIOPortSpace;
|
return MemMapACPIMappedIOPortSpace;
|
||||||
|
|
||||||
case EfiPalCode:
|
case EfiPalCode:
|
||||||
return MemMapUsable;
|
|
||||||
case EfiPersistentMemory:
|
case EfiPersistentMemory:
|
||||||
|
case EfiConventionalMemory:
|
||||||
return MemMapUsable;
|
return MemMapUsable;
|
||||||
|
return MemMapUsable;
|
||||||
|
|
||||||
case EfiUnacceptedMemoryType:
|
case EfiUnacceptedMemoryType:
|
||||||
|
case EfiReservedMemoryType:
|
||||||
return MemMapReserved;
|
return MemMapReserved;
|
||||||
default:
|
default:
|
||||||
return MemMapReserved;
|
return MemMapReserved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
axboot_memmap *get_memmap(pagetable *pm)
|
uint32_t get_memmap(axboot_memmap **map, pagetable *pm)
|
||||||
{
|
{
|
||||||
EFI_MEMORY_DESCRIPTOR *efi_map = NULL;
|
EFI_MEMORY_DESCRIPTOR *efi_map = NULL;
|
||||||
EFI_UINTN efi_map_key = 0;
|
EFI_UINTN efi_map_key = 0;
|
||||||
|
@ -76,8 +80,8 @@ axboot_memmap *get_memmap(pagetable *pm)
|
||||||
|
|
||||||
status = gBootServices->GetMemoryMap(&size, efi_map, &efi_map_key, &desc_size, &desc_ver);
|
status = gBootServices->GetMemoryMap(&size, efi_map, &efi_map_key, &desc_size, &desc_ver);
|
||||||
if (EFI_ERROR(status) && status != EFI_BUFFER_TOO_SMALL) {
|
if (EFI_ERROR(status) && status != EFI_BUFFER_TOO_SMALL) {
|
||||||
debug("get_memmap(): GetMemoryMap() returned an error: %s (0x%llx)\n", efi_status_to_str(status), status);
|
log("get_memmap(): GetMemoryMap() returned an error: %s (0x%llx)\n", efi_status_to_str(status), status);
|
||||||
return NULL;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
efi_map = (EFI_MEMORY_DESCRIPTOR *)mem_alloc(size);
|
efi_map = (EFI_MEMORY_DESCRIPTOR *)mem_alloc(size);
|
||||||
|
@ -90,8 +94,8 @@ axboot_memmap *get_memmap(pagetable *pm)
|
||||||
size += 2 * desc_size;
|
size += 2 * desc_size;
|
||||||
efi_map = (EFI_MEMORY_DESCRIPTOR *)mem_realloc(efi_map, size);
|
efi_map = (EFI_MEMORY_DESCRIPTOR *)mem_realloc(efi_map, size);
|
||||||
} else {
|
} else {
|
||||||
debug("get_memmap(): GetMemoryMap() returned an error: %s (0x%llx)\n", efi_status_to_str(status), status);
|
log("get_memmap(): GetMemoryMap() returned an error: %s (0x%llx)\n", efi_status_to_str(status), status);
|
||||||
return NULL;
|
return 0;
|
||||||
}
|
}
|
||||||
} while (status != EFI_SUCCESS);
|
} while (status != EFI_SUCCESS);
|
||||||
|
|
||||||
|
@ -133,23 +137,19 @@ axboot_memmap *get_memmap(pagetable *pm)
|
||||||
cur_entry = (EFI_MEMORY_DESCRIPTOR *)((uint8_t *)cur_entry + desc_size);
|
cur_entry = (EFI_MEMORY_DESCRIPTOR *)((uint8_t *)cur_entry + desc_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
axboot_memmap *new_map = (axboot_memmap *)mem_alloc(sizeof(axboot_memmap) * entry_count);
|
*map = mem_alloc(sizeof(axboot_memmap) * entry_count);
|
||||||
memset(new_map, 0, sizeof(axboot_memmap) * entry_count);
|
memset(*map, 0, sizeof(axboot_memmap) * entry_count);
|
||||||
|
|
||||||
cur_entry = efi_map;
|
|
||||||
|
|
||||||
// translate efi memmap to axboot memmap
|
// translate efi memmap to axboot memmap
|
||||||
for (uint32_t i = 0; i < entry_count; i++) {
|
for (uint32_t i = 0; i < entry_count; i++) {
|
||||||
new_map[i].base = cur_entry->PhysicalStart;
|
(*map)[i].base = cur_entry->PhysicalStart;
|
||||||
new_map[i].size = cur_entry->NumberOfPages * PAGE_SIZE;
|
(*map)[i].size = cur_entry->NumberOfPages * PAGE_SIZE;
|
||||||
new_map[i].type = efi_type_to_axboot(efi_map[i].Type);
|
(*map)[i].type = efi_type_to_axboot(efi_map[i].Type);
|
||||||
|
|
||||||
debug("get_memmap(): Entry %d: base=0x%llx, size=%u bytes, type=%x\n", i, new_map[i].base, new_map[i].size, new_map[i].type);
|
|
||||||
|
|
||||||
cur_entry = (EFI_MEMORY_DESCRIPTOR *)((uint8_t *)cur_entry + desc_size);
|
cur_entry = (EFI_MEMORY_DESCRIPTOR *)((uint8_t *)cur_entry + desc_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
mem_free(efi_map);
|
mem_free(efi_map);
|
||||||
|
|
||||||
return new_map;
|
return entry_count;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,11 @@ bool platform_is_reboot_to_fw_possible()
|
||||||
Status = gSystemTable->RuntimeServices->GetVariable(L"OsIndicationsSupported", &GlobalVarGuid, NULL, &OsIndicationsSize, &OsIndications);
|
Status = gSystemTable->RuntimeServices->GetVariable(L"OsIndicationsSupported", &GlobalVarGuid, NULL, &OsIndicationsSize, &OsIndications);
|
||||||
if (!EFI_ERROR(Status)) {
|
if (!EFI_ERROR(Status)) {
|
||||||
if (OsIndications & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) {
|
if (OsIndications & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) {
|
||||||
debug("platform_is_reboot_to_fw_possible(): Boot to firmware UI is possible!\n");
|
log("platform_is_reboot_to_fw_possible(): Boot to firmware UI is possible!\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug("platform_is_reboot_to_fw_possible(): Failed to get OsIndications variable: 0x%llx (%s) \n", Status, efi_status_to_str(Status));
|
log("platform_is_reboot_to_fw_possible(): Failed to get OsIndications variable: 0x%llx (%s) \n", Status, efi_status_to_str(Status));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -58,7 +58,7 @@ void platform_reboot_to_fw()
|
||||||
|
|
||||||
Status = gSystemTable->RuntimeServices->SetVariable(L"OsIndications", &GlobalVarGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, OsIndicationsSize, &OsIndications);
|
Status = gSystemTable->RuntimeServices->SetVariable(L"OsIndications", &GlobalVarGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, OsIndicationsSize, &OsIndications);
|
||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR(Status)) {
|
||||||
debug("platform_reboot_to_fw(): Failed to set OsIndications variable: 0x%llx (%s) \n", Status, efi_status_to_str(Status));
|
log("platform_reboot_to_fw(): Failed to set OsIndications variable: 0x%llx (%s) \n", Status, efi_status_to_str(Status));
|
||||||
}
|
}
|
||||||
|
|
||||||
gSystemTable->RuntimeServices->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
|
gSystemTable->RuntimeServices->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
|
||||||
|
|
|
@ -33,7 +33,7 @@ void get_datetime(struct datetime *dt)
|
||||||
|
|
||||||
status = gSystemTable->RuntimeServices->GetTime(&uefi_dt, NULL);
|
status = gSystemTable->RuntimeServices->GetTime(&uefi_dt, NULL);
|
||||||
if (EFI_ERROR(status)) {
|
if (EFI_ERROR(status)) {
|
||||||
debug("get_datetime(): Failed to acquire current time, setting to 1970/01/01 00:00:00!\n");
|
log("get_datetime(): Failed to acquire current time, setting to 1970/01/01 00:00:00!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ bool get_framebuffer(uint32_t **fb_addr, struct fb_mode **available_modes, int *
|
||||||
|
|
||||||
Status = gBootServices->LocateProtocol(&gop_guid, NULL, (void**)&gop);
|
Status = gBootServices->LocateProtocol(&gop_guid, NULL, (void**)&gop);
|
||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR(Status)) {
|
||||||
debug("get_framebuffer(): Unable to locate GOP: %s (0x%llx)\n", efi_status_to_str(Status), Status);
|
log("get_framebuffer(): Unable to locate GOP: %s (0x%llx)\n", efi_status_to_str(Status), Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = gop->QueryMode(gop, gop->Mode == NULL ? 0 : gop->Mode->Mode, &SizeOfInfo, &mode_info);
|
Status = gop->QueryMode(gop, gop->Mode == NULL ? 0 : gop->Mode->Mode, &SizeOfInfo, &mode_info);
|
||||||
|
@ -48,14 +48,16 @@ bool get_framebuffer(uint32_t **fb_addr, struct fb_mode **available_modes, int *
|
||||||
if (Status == EFI_NOT_STARTED) {
|
if (Status == EFI_NOT_STARTED) {
|
||||||
Status = gop->SetMode(gop, 0);
|
Status = gop->SetMode(gop, 0);
|
||||||
} else if (EFI_ERROR(Status)) {
|
} else if (EFI_ERROR(Status)) {
|
||||||
debug("Unable to get native mode\n");
|
log("Unable to get native mode\n");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
nativeMode = gop->Mode->Mode;
|
nativeMode = gop->Mode->Mode;
|
||||||
numModes = gop->Mode->MaxMode;
|
numModes = gop->Mode->MaxMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (total_modes != NULL) {
|
||||||
*total_modes = numModes;
|
*total_modes = numModes;
|
||||||
|
}
|
||||||
*available_modes = (struct fb_mode *)mem_alloc(sizeof(struct fb_mode) * numModes);
|
*available_modes = (struct fb_mode *)mem_alloc(sizeof(struct fb_mode) * numModes);
|
||||||
|
|
||||||
*fb_addr = (uint32_t *)gop->Mode->FrameBufferBase;
|
*fb_addr = (uint32_t *)gop->Mode->FrameBufferBase;
|
||||||
|
@ -74,7 +76,7 @@ bool get_framebuffer(uint32_t **fb_addr, struct fb_mode **available_modes, int *
|
||||||
} else if (mode_info->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
|
} else if (mode_info->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
|
||||||
(*available_modes)[i].format = FB_BGRA;
|
(*available_modes)[i].format = FB_BGRA;
|
||||||
} else {
|
} else {
|
||||||
debug("get_framebuffer(): Unknown framebuffer format, assuming BGRA...\n");
|
log("get_framebuffer(): Unknown framebuffer format, assuming BGRA...\n");
|
||||||
(*available_modes)[i].format = FB_BGRA;
|
(*available_modes)[i].format = FB_BGRA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
84
kernel/include/boot/aurix.h
Normal file
84
kernel/include/boot/aurix.h
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*********************************************************************************/
|
||||||
|
/* Module Name: aurix.h */
|
||||||
|
/* Project: AurixOS */
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2024-2025 Jozef Nagy */
|
||||||
|
/* */
|
||||||
|
/* This source is subject to the MIT License. */
|
||||||
|
/* See License.txt in the root of this repository. */
|
||||||
|
/* All other rights reserved. */
|
||||||
|
/* */
|
||||||
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
|
||||||
|
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
|
||||||
|
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
|
||||||
|
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
|
||||||
|
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
|
||||||
|
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
|
||||||
|
/* SOFTWARE. */
|
||||||
|
/*********************************************************************************/
|
||||||
|
|
||||||
|
#ifndef _AURIX_H
|
||||||
|
#define _AURIX_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define AURIX_PROTOCOL_REVISION 1
|
||||||
|
|
||||||
|
enum aurix_memmap_entry {
|
||||||
|
AURIX_MMAP_RESERVED = 0,
|
||||||
|
|
||||||
|
AURIX_MMAP_ACPI_RECLAIMABLE = 1,
|
||||||
|
AURIX_MMAP_ACPI_MAPPED_IO = 2,
|
||||||
|
AURIX_MMAP_ACPI_MAPPED_IO_PORTSPACE = 3,
|
||||||
|
AURIX_MMAP_ACPI_NVS = 4,
|
||||||
|
|
||||||
|
AURIX_MMAP_BOOTLOADER_RECLAIMABLE = 6,
|
||||||
|
AURIX_MMAP_USABLE = 7
|
||||||
|
};
|
||||||
|
|
||||||
|
enum aurix_framebuffer_format {
|
||||||
|
AURIX_FB_RGBA = 0,
|
||||||
|
AURIX_FB_BGRA = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
struct aurix_memmap {
|
||||||
|
uintptr_t base;
|
||||||
|
uint32_t size;
|
||||||
|
uint8_t type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct aurix_framebuffer {
|
||||||
|
uintptr_t addr;
|
||||||
|
uint32_t width;
|
||||||
|
uint32_t height;
|
||||||
|
uint8_t bpp; // bits!
|
||||||
|
uint32_t pitch;
|
||||||
|
int format;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct aurix_parameters {
|
||||||
|
// PROTOCOL INFO
|
||||||
|
uint8_t revision;
|
||||||
|
|
||||||
|
// MEMORY
|
||||||
|
struct aurix_memmap *mmap;
|
||||||
|
uint32_t mmap_entries;
|
||||||
|
|
||||||
|
uintptr_t kernel_addr; // physical address
|
||||||
|
|
||||||
|
// RSDP and SMBIOS
|
||||||
|
uintptr_t rsdp_addr;
|
||||||
|
uintptr_t smbios_addr;
|
||||||
|
|
||||||
|
// FRAMEBUFFER
|
||||||
|
struct aurix_framebuffer *framebuffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef _AXBOOT
|
||||||
|
#include <mm/vmm.h>
|
||||||
|
void aurix_load(char *kernel);
|
||||||
|
|
||||||
|
void aurix_arch_handoff(void *kernel_entry, pagetable *pm, void *stack, uint32_t stack_size, struct aurix_parameters *parameters);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _PROTO_AURIX_H */
|
|
@ -17,11 +17,22 @@
|
||||||
/* SOFTWARE. */
|
/* SOFTWARE. */
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
|
|
||||||
|
#include <boot/aurix.h>
|
||||||
#include <debug/uart.h>
|
#include <debug/uart.h>
|
||||||
|
|
||||||
void _start(void)
|
void _start(struct aurix_parameters *params)
|
||||||
{
|
{
|
||||||
serial_init();
|
serial_init();
|
||||||
|
|
||||||
|
if (params->revision != AURIX_PROTOCOL_REVISION) {
|
||||||
|
serial_sendstr("Aurix Protocol revision is not compatible!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
volatile uint32_t *fb_ptr = (uint32_t *)params->framebuffer->addr;
|
||||||
|
fb_ptr[i * (params->framebuffer->pitch / 4) + i] = 0xffffff;
|
||||||
|
}
|
||||||
|
|
||||||
serial_sendstr("Hello from AurixOS!\n");
|
serial_sendstr("Hello from AurixOS!\n");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
@ -75,6 +75,7 @@ if [ "$unamestr" = 'Linux' ]; then
|
||||||
exit 200
|
exit 200
|
||||||
elif [ "$unamestr" = 'Darwin' ]; then
|
elif [ "$unamestr" = 'Darwin' ]; then
|
||||||
diskutil unmount "$tempmountdir" >/dev/null 2>&1
|
diskutil unmount "$tempmountdir" >/dev/null 2>&1
|
||||||
|
diskutil unmountDisk "$loopback" >/dev/null 2>&1
|
||||||
hdiutil detach "$loopback" >/dev/null 2>&1
|
hdiutil detach "$loopback" >/dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -84,4 +85,6 @@ rm -r "$tempmountdir"
|
||||||
dd if="$BUILD_DIR/boot/pc-bios/stage1-hdd.bin" of="$disk_name" conv=notrunc bs=446 count=1 >/dev/null 2>&1
|
dd if="$BUILD_DIR/boot/pc-bios/stage1-hdd.bin" of="$disk_name" conv=notrunc bs=446 count=1 >/dev/null 2>&1
|
||||||
dd if="$BUILD_DIR/boot/pc-bios/stage1-hdd.bin" of="$disk_name" conv=notrunc bs=1 count=2 skip=510 seek=510 >/dev/null 2>&1
|
dd if="$BUILD_DIR/boot/pc-bios/stage1-hdd.bin" of="$disk_name" conv=notrunc bs=1 count=2 skip=510 seek=510 >/dev/null 2>&1
|
||||||
|
|
||||||
|
sync
|
||||||
|
|
||||||
printf " done.\n"
|
printf " done.\n"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue