forked from Piraterna/aurix
Compare commits
19 commits
Author | SHA1 | Date | |
---|---|---|---|
|
860c9ea53c | ||
|
02e846f1ab | ||
|
6eb04c8c40 | ||
|
d1a5d7d43d | ||
|
b1d59e02eb | ||
|
4f39a7564e | ||
|
35c922d5ed | ||
|
ad1b840637 | ||
|
d9bcce9008 | ||
5b1a271d45 | |||
|
fb99d8d36f | ||
|
dae7b9c869 | ||
|
06fb67beca | ||
|
a3bc0fc76c | ||
|
dd4fda27bb | ||
|
bc4ec556e2 | ||
|
10ee4fcbd9 | ||
|
5c682c4209 | ||
|
42cc0d9f40 |
84 changed files with 4623 additions and 263 deletions
2
.gitmodules
vendored
2
.gitmodules
vendored
|
@ -1,3 +1,3 @@
|
|||
[submodule "boot/platform/uefi/libefi"]
|
||||
path = boot/platform/uefi/libefi
|
||||
url = https://github.com/aurixos/efi
|
||||
url = https://git.piraterna.org/Piraterna/libsefi
|
||||
|
|
1
Brewfile
1
Brewfile
|
@ -10,6 +10,7 @@ brew "make"
|
|||
brew "gptfdisk"
|
||||
brew "xorriso"
|
||||
brew "qemu"
|
||||
brew "ffmpeg"
|
||||
brew "llvm"
|
||||
brew "lld"
|
||||
brew "util-linux" if OS.mac?
|
||||
|
|
40
Makefile
40
Makefile
|
@ -19,6 +19,8 @@
|
|||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
GITREV := $(shell git rev-parse --short HEAD)
|
||||
|
||||
##
|
||||
# Build configuration
|
||||
#
|
||||
|
@ -33,7 +35,7 @@ export BUILD_DIR ?= $(ROOT_DIR)/build
|
|||
export SYSROOT_DIR ?= $(ROOT_DIR)/sysroot
|
||||
export RELEASE_DIR ?= $(ROOT_DIR)/release
|
||||
|
||||
NOUEFI ?= n
|
||||
export NOUEFI ?= n
|
||||
|
||||
##
|
||||
# Image generation and running
|
||||
|
@ -43,7 +45,19 @@ LIVECD := $(RELEASE_DIR)/aurix-$(GITREV)-livecd_$(ARCH)-$(PLATFORM).iso
|
|||
LIVEHDD := $(RELEASE_DIR)/aurix-$(GITREV)-livehdd_$(ARCH)-$(PLATFORM).img
|
||||
LIVESD := $(RELEASE_DIR)/aurix-$(GITREV)-livesd_$(ARCH)-$(PLATFORM).img
|
||||
|
||||
QEMU_FLAGS := -m 2G -smp 4 -serial stdio
|
||||
QEMU_FLAGS := -m 2G -smp 4 -rtc base=localtime -serial stdio
|
||||
|
||||
# QEMU Audio support
|
||||
#QEMU_FLAGS += -audiodev coreaudio,id=coreaudio0 -device ich9-intel-hda -device hda-output,audiodev=coreaudio0
|
||||
|
||||
# QEMU Mouse support
|
||||
QEMU_FLAGS += -usb -device usb-mouse
|
||||
|
||||
# x86_64
|
||||
# TODO: Move this elsewhere
|
||||
ifeq ($(ARCH),x86_64)
|
||||
QEMU_FLAGS += -machine q35
|
||||
endif
|
||||
|
||||
##
|
||||
# General info
|
||||
|
@ -75,16 +89,7 @@ all: boot kernel
|
|||
.PHONY: boot
|
||||
boot:
|
||||
@printf ">>> Building bootloader...\n"
|
||||
ifneq (,$(filter $(ARCH),i686 x86_64))
|
||||
@$(MAKE) -C boot PLATFORM=pc-bios
|
||||
else
|
||||
@$(MAKE) -C boot
|
||||
endif
|
||||
ifneq (,$(filter $(ARCH),i686 x86_64 arm32 aarch64))
|
||||
ifeq ($(NOUEFI),n)
|
||||
@$(MAKE) -C boot PLATFORM=uefi
|
||||
endif
|
||||
endif
|
||||
@$(MAKE) -C boot all
|
||||
|
||||
.PHONY: kernel
|
||||
kernel:
|
||||
|
@ -130,18 +135,21 @@ livesd: install
|
|||
@mkdir -p $(RELEASE_DIR)
|
||||
@utils/arch/$(ARCH)/generate-sd.sh $(LIVESD)
|
||||
|
||||
# TODO: Maybe don't run with -hda but -drive?
|
||||
.PHONY: run
|
||||
run: livecd
|
||||
run: livehdd
|
||||
@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
|
||||
run-uefi: livecd ovmf
|
||||
run-uefi: livehdd ovmf
|
||||
@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
|
||||
clean:
|
||||
@$(MAKE) -C boot clean
|
||||
@rm -rf $(BUILD_DIR) $(SYSROOT_DIR)
|
||||
|
||||
.PHONY: distclean
|
||||
|
|
1
boot/.gitignore
vendored
Normal file
1
boot/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
include/sounds
|
|
@ -28,9 +28,11 @@ export BUILD_DIR ?= build
|
|||
export SYSROOT_DIR ?= sysroot
|
||||
|
||||
export ASFLAGS := $(foreach d, $(DEFINES), -D$d)
|
||||
export CFLAGS := $(foreach d, $(DEFINES), -D$d) -Wall -Wextra -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
|
||||
|
||||
include arch/$(ARCH)/config.mk
|
||||
|
||||
export BOOT_ROOT := $(ROOT_DIR)/boot
|
||||
|
||||
ifeq ($(BUILD_TYPE),debug)
|
||||
|
@ -40,13 +42,37 @@ CFLAGS += -O2
|
|||
endif
|
||||
|
||||
.PHONY: all
|
||||
all:
|
||||
all: sounds
|
||||
ifneq (,$(filter $(ARCH),i686 x86_64))
|
||||
@$(MAKE) -C platform/pc-bios all
|
||||
else
|
||||
@$(MAKE) -C platform/$(PLATFORM) all
|
||||
endif
|
||||
ifneq (,$(filter $(ARCH),i686 x86_64 arm32 aarch64))
|
||||
ifeq ($(NOUEFI),n)
|
||||
@$(MAKE) -C platform/uefi all
|
||||
# @$(MAKE) -C drivers all
|
||||
endif
|
||||
endif
|
||||
|
||||
.PHONY: sounds
|
||||
sounds:
|
||||
@mkdir -p $(BUILD_DIR)/boot/sounds
|
||||
@mkdir -p $(BOOT_ROOT)/include/sounds
|
||||
@for f in $(BOOT_ROOT)/sound/*.mp3; do \
|
||||
file=$$(basename $$f ".$${f##*.}") ; \
|
||||
printf " GEN\t$$file.h\n" ; \
|
||||
ffmpeg -i "$$f" -acodec pcm_s16le -f s16le -ac 2 "$(BUILD_DIR)/boot/sounds/$$file.raw" -y 2>/dev/null ; \
|
||||
python3 $(ROOT_DIR)/utils/bin_to_header.py "$(BUILD_DIR)/boot/sounds/$$file.raw" "$(BOOT_ROOT)/include/sounds/$$file.h" $$file ; \
|
||||
done
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
@$(MAKE) -C platform/$(PLATFORM) install
|
||||
# @$(MAKE) -C drivers install
|
||||
@mkdir -p $(SYSROOT_DIR)/AxBoot
|
||||
@cp -r base/* $(SYSROOT_DIR)/AxBoot
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@$(MAKE) -C platform/$(PLATFORM) clean
|
||||
@rm -rf $(BOOT_ROOT)/include/sounds
|
||||
|
|
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);
|
||||
if ((pml1_table->entries[pml1_idx] & 1)) {
|
||||
// debug("_map(): Remapping present page\n");
|
||||
}
|
||||
|
||||
pml1_table->entries[pml1_idx] = (phys & 0x000FFFFFFFFFF000) | flags;
|
||||
}
|
||||
|
||||
|
|
115
boot/arch/x86_64/common/proto/aurix/handoff.c
Normal file
115
boot/arch/x86_64/common/proto/aurix/handoff.c
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*********************************************************************************/
|
||||
/* 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 <print.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"
|
||||
"movq %[entry], %%rsi\n"
|
||||
|
||||
// rsi = kernel entry point addr
|
||||
// rdi = kernel parameters
|
||||
"xor %%rax, %%rax\n"
|
||||
"xor %%rbx, %%rbx\n"
|
||||
"xor %%rcx, %%rcx\n"
|
||||
"xor %%rdx, %%rdx\n"
|
||||
//"xor %%rdi, %%rdi\n"
|
||||
//"xor %%rsi, %%rsi\n"
|
||||
"xor %%r8, %%r8\n"
|
||||
"xor %%r9, %%r9\n"
|
||||
"xor %%r10, %%r10\n"
|
||||
"xor %%r11, %%r11\n"
|
||||
"xor %%r12, %%r12\n"
|
||||
"xor %%r13, %%r13\n"
|
||||
"xor %%r14, %%r14\n"
|
||||
"xor %%r15, %%r15\n"
|
||||
|
||||
"callq *%%rsi\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:
|
56
boot/arch/x86_64/common/uart/uart.c
Normal file
56
boot/arch/x86_64/common/uart/uart.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: uart.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 <stdint.h>
|
||||
|
||||
#include <arch/cpu/cpu.h>
|
||||
#include <uart/uart.h>
|
||||
|
||||
#define COM1 0x3f8
|
||||
|
||||
void uart_init(uint32_t baud_rate)
|
||||
{
|
||||
uint8_t divisor = 115200 / baud_rate;
|
||||
|
||||
outb(COM1 + 1, 0x00);
|
||||
outb(COM1 + 3, 0x80);
|
||||
outb(COM1 + 0, divisor & 0xFF);
|
||||
outb(COM1 + 1, (divisor >> 8) & 0xFF);
|
||||
outb(COM1 + 3, 0x03);
|
||||
outb(COM1 + 2, 0xC7);
|
||||
outb(COM1 + 4, 0x0B);
|
||||
outb(COM1 + 4, 0x0F);
|
||||
}
|
||||
|
||||
void uart_send(char c)
|
||||
{
|
||||
while ((inb(COM1 + 5) & 0x20) == 0);
|
||||
outb(COM1, c);
|
||||
}
|
||||
|
||||
void uart_sendstr(char *str)
|
||||
{
|
||||
while (*str != '\0') {
|
||||
if (*str == '\n') {
|
||||
uart_send('\r');
|
||||
}
|
||||
uart_send(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
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
|
|
@ -1,12 +1,13 @@
|
|||
; This is a comment
|
||||
;; please leave this here, the parser breaks without it
|
||||
|
||||
entry "AurixOS" {
|
||||
PROTOCOL="aurix"
|
||||
IMAGE_PATH="boot:///System/axkrnl.sys"
|
||||
}
|
||||
default = 0
|
||||
timeout = 30
|
||||
ui = text
|
||||
|
||||
;; UEFI only
|
||||
entry "Windows" {
|
||||
PROTOCOL="chainload"
|
||||
IMAGE_PATH="boot:///EFI/Microsoft/bootmgfw.efi"
|
||||
}
|
||||
[AurixOS]
|
||||
protocol = aurix
|
||||
image = boot:///System/axkrnl.sys
|
||||
|
||||
[Windows 10]
|
||||
protocol = efi-chainload
|
||||
image = boot:///EFI/Microsoft/bootmgfw.efi
|
BIN
boot/base/fonts/u_vga16/u_vga16.sfn
Normal file
BIN
boot/base/fonts/u_vga16/u_vga16.sfn
Normal file
Binary file not shown.
BIN
boot/base/fonts/vera/Vera.sfn
Normal file
BIN
boot/base/fonts/vera/Vera.sfn
Normal file
Binary file not shown.
|
@ -17,8 +17,11 @@
|
|||
/* SOFTWARE. */
|
||||
/*********************************************************************************/
|
||||
|
||||
#include <config/config.h>
|
||||
#include <lib/string.h>
|
||||
#include <loader/loader.h>
|
||||
#include <mm/mman.h>
|
||||
#include <time/dt.h>
|
||||
#include <vfs/vfs.h>
|
||||
#include <print.h>
|
||||
#include <axboot.h>
|
||||
|
@ -26,20 +29,66 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define DEFAULT_ENTRY 0
|
||||
// default timeout of 0 disables the UI entirely, which is essentialy what *should* happen now since the UI
|
||||
// is... in a catastrophic state. Just remember to set this back to 30 once the UI is ready
|
||||
#define DEFAULT_TIMEOUT 0
|
||||
// #define DEFAULT_TIMEOUT 30
|
||||
|
||||
char *config_paths[] = {
|
||||
"\\AxBoot\\axboot.cfg",
|
||||
"\\axboot.cfg",
|
||||
"\\System\\axboot.cfg",
|
||||
"\\EFI\\axboot.cfg",
|
||||
"\\EFI\\BOOT\\axboot.cfg",
|
||||
};
|
||||
|
||||
struct axboot_cfg cfg = {
|
||||
.default_entry = DEFAULT_ENTRY,
|
||||
.timeout = DEFAULT_TIMEOUT,
|
||||
.ui_mode = UI_TEXT,
|
||||
|
||||
//.entry_count = 0,
|
||||
.entry_count = 2,
|
||||
.bootlog_filename = NULL
|
||||
};
|
||||
|
||||
struct axboot_entry entries[2] = {
|
||||
{
|
||||
.name = "AurixOS",
|
||||
.description = "Boot the Aurix Operating System",
|
||||
.image_path = "\\System\\axkrnl",
|
||||
.protocol = PROTO_AURIX
|
||||
},
|
||||
{
|
||||
.name = "Windows 10",
|
||||
.description = "",
|
||||
.image_path = "\\EFI\\Microsoft\\bootmgfw.efi",
|
||||
.protocol = PROTO_CHAINLOAD
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void config_init(void)
|
||||
{
|
||||
char *config_buf;
|
||||
// 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;
|
||||
uint8_t open = 0;
|
||||
|
||||
for (size_t i = 0; i < ARRAY_LENGTH(config_paths); i++) {
|
||||
vfs_read("\\System\\axkrnl", &config_buf);
|
||||
vfs_read(config_paths[i], &config_buf);
|
||||
if (config_buf != NULL) {
|
||||
open = 1;
|
||||
break;
|
||||
|
@ -47,12 +96,35 @@ void config_init(void)
|
|||
}
|
||||
|
||||
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();
|
||||
while (1);
|
||||
}
|
||||
|
||||
// TODO: parse configuration file
|
||||
|
||||
mem_free(config_buf);
|
||||
}
|
||||
|
||||
int config_get_timeout()
|
||||
{
|
||||
return cfg.timeout;
|
||||
}
|
||||
|
||||
int config_get_default()
|
||||
{
|
||||
return cfg.default_entry;
|
||||
}
|
||||
|
||||
int config_get_entry_count()
|
||||
{
|
||||
return cfg.entry_count;
|
||||
}
|
||||
|
||||
struct axboot_entry *config_get_entries()
|
||||
{
|
||||
return entries;
|
||||
}
|
||||
|
||||
int config_get_ui_mode()
|
||||
{
|
||||
return cfg.ui_mode;
|
||||
}
|
130
boot/common/data/list.c
Normal file
130
boot/common/data/list.c
Normal file
|
@ -0,0 +1,130 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: list.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 <data/list.h>
|
||||
#include <mm/mman.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
List *list_new()
|
||||
{
|
||||
List *list = (List *)mem_alloc(sizeof(List));
|
||||
if (!list) {
|
||||
debug("list_new(): Failed to allocate memory for new list!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list->count = 0;
|
||||
list->root = (ListNode *)0;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
ListNode *listnode_new(void *data)
|
||||
{
|
||||
ListNode *ln = (ListNode *)mem_alloc(sizeof(ListNode));
|
||||
if (!ln) {
|
||||
debug("listnode_new(): Failed to allocate memory for new list node!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ln->prev = (ListNode *)0;
|
||||
ln->next = (ListNode *)0;
|
||||
ln->data = data;
|
||||
|
||||
return ln;
|
||||
}
|
||||
|
||||
int list_add(List *list, void *data)
|
||||
{
|
||||
ListNode *node = listnode_new(data);
|
||||
if (!node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!list->root) {
|
||||
list->root = node;
|
||||
} else {
|
||||
ListNode *cur = list->root;
|
||||
|
||||
while (cur->next) {
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
cur->next = node;
|
||||
node->prev = cur;
|
||||
}
|
||||
|
||||
list->count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void *list_remove_at(List *list, uint32_t idx)
|
||||
{
|
||||
void *data;
|
||||
|
||||
if (!list || list->count == 0 || idx >= list->count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ListNode *cur = list->root;
|
||||
|
||||
for (uint32_t i = 0; (i < idx) && cur; i++) {
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
if (!cur) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = cur->data;
|
||||
|
||||
if (cur->prev) {
|
||||
cur->prev->next = cur->next;
|
||||
}
|
||||
|
||||
if (cur->next) {
|
||||
cur->next->prev = cur->prev;
|
||||
}
|
||||
|
||||
if (idx == 0) {
|
||||
list->root = cur->next;
|
||||
}
|
||||
|
||||
mem_free(cur);
|
||||
|
||||
list->count--;
|
||||
return data;
|
||||
}
|
||||
|
||||
void *list_get_at(List *list, uint32_t idx)
|
||||
{
|
||||
if (!list || list->count == 0 | idx >= list->count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ListNode *cur = list->root;
|
||||
|
||||
for (uint32_t i = 0; (i < idx) && cur; i++) {
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
return cur ? cur->data : NULL;
|
||||
}
|
|
@ -80,7 +80,7 @@ struct vfs_drive *sfs_init(char *mountpoint)
|
|||
|
||||
fs->fsdata = fsdata;
|
||||
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));
|
||||
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';
|
||||
|
||||
/* 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)) {
|
||||
debug("sfs_read(): Failed to open file '%s': %s (%lx)\n", filename, efi_status_to_str(status), status);
|
||||
mem_free(wfilename);
|
||||
|
@ -159,4 +159,49 @@ size_t sfs_read(char *filename, char **buffer, struct vfs_drive *dev, void *fsda
|
|||
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
|
29
boot/common/i18n/cs_CZ.c
Normal file
29
boot/common/i18n/cs_CZ.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: cs_CZ.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 <i18n.h>
|
||||
|
||||
struct language i18n_csCZ = {
|
||||
.shutdown = "Vypnout",
|
||||
.reboot = "Restartovat",
|
||||
.reboot_to_firmware = "Přejít do nastavení firmwaru",
|
||||
.resolution = "Rozlišení",
|
||||
|
||||
.language = "Jazyk"
|
||||
};
|
29
boot/common/i18n/en_US.c
Normal file
29
boot/common/i18n/en_US.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: en_US.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 <i18n.h>
|
||||
|
||||
struct language i18n_enUS = {
|
||||
.shutdown = "Shutdown",
|
||||
.reboot = "Reboot",
|
||||
.reboot_to_firmware = "Reboot to Firmware",
|
||||
.resolution = "Resolution",
|
||||
|
||||
.language = "Language"
|
||||
};
|
38
boot/common/i18n/i18n.c
Normal file
38
boot/common/i18n/i18n.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: i18n.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 <i18n.h>
|
||||
|
||||
extern struct language i18n_csCZ;
|
||||
extern struct language i18n_enUS;
|
||||
|
||||
struct language_selection i18n_languages[] = {
|
||||
{
|
||||
"Čeština",
|
||||
"cs_CZ",
|
||||
&i18n_csCZ
|
||||
},
|
||||
{
|
||||
"English",
|
||||
"en_US",
|
||||
&i18n_enUS
|
||||
}
|
||||
};
|
||||
|
||||
struct language_selection *i18n_curlang = &i18n_languages[1]; // english
|
|
@ -17,21 +17,50 @@
|
|||
/* SOFTWARE. */
|
||||
/*********************************************************************************/
|
||||
|
||||
#include <vfs/vfs.h>
|
||||
#include <mm/mman.h>
|
||||
#include <mm/vmm.h>
|
||||
#include <config/config.h>
|
||||
#include <loader/loader.h>
|
||||
#include <proto/aurix.h>
|
||||
#include <uart/uart.h>
|
||||
#include <vfs/vfs.h>
|
||||
#include <ui/ui.h>
|
||||
#include <axboot.h>
|
||||
#include <print.h>
|
||||
|
||||
void axboot_init()
|
||||
{
|
||||
uart_init(115200);
|
||||
|
||||
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
|
||||
while (1);
|
||||
}
|
||||
|
||||
aurix_load("\\System\\axkrnl");
|
||||
config_init();
|
||||
|
||||
while (1);
|
||||
#if defined(__aarch64__) && !defined(AXBOOT_UEFI)
|
||||
struct axboot_entry rpi_kernel = {
|
||||
.name = "AurixOS for Raspberry Pi",
|
||||
.image_path = "\\System\\axkrnl",
|
||||
.protocol = PROTO_AURIX
|
||||
};
|
||||
loader_load(&rpi_kernel);
|
||||
UNREACHABLE();
|
||||
#endif
|
||||
|
||||
#ifdef AXBOOT_UEFI
|
||||
#include <driver.h>
|
||||
load_drivers();
|
||||
#endif
|
||||
|
||||
// boot straight away
|
||||
if (config_get_timeout() < 1) {
|
||||
struct axboot_entry *entries = config_get_entries();
|
||||
loader_load(&(entries[config_get_default()]));
|
||||
}
|
||||
|
||||
ui_init();
|
||||
|
||||
log("axboot_init(): Returned from main menu, something went wrong. Halting!");
|
||||
UNREACHABLE();
|
||||
}
|
|
@ -143,6 +143,38 @@ char *strcpy(char *dest, const char *src)
|
|||
return pdest;
|
||||
}
|
||||
|
||||
char *strncpy(char *dest, const char *src, size_t n)
|
||||
{
|
||||
if (dest == NULL || src == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *pdest = dest;
|
||||
|
||||
while (*src != '\0' || n--) {
|
||||
*pdest++ = *src++;
|
||||
}
|
||||
|
||||
*pdest = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *strncat(char *dest, const char *src, size_t n)
|
||||
{
|
||||
if (dest == 0 || src == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t i = strlen(dest);
|
||||
size_t a = 0;
|
||||
|
||||
while (a < n && src[a] != '\0') {
|
||||
dest[i++] = src[a++];
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
// TODO: Get rid of this function
|
||||
char *strdup(const char *s)
|
||||
{
|
||||
|
|
|
@ -28,14 +28,15 @@
|
|||
/* https://github.com/KevinAlavik/nekonix/blob/main/kernel/src/proc/elf.c */
|
||||
/* 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)addr;
|
||||
(void)pagemap;
|
||||
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_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;
|
||||
if (!phys) {
|
||||
debug("elf64_load(): Out of memory\n");
|
||||
log("elf64_load(): Out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (addr != NULL && *addr == 0) {
|
||||
*addr = phys;
|
||||
}
|
||||
|
||||
debug("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);
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (header->e_magic != ELF_MAGIC) {
|
||||
debug("Invalid ELF magic: 0x%x", header->e_magic);
|
||||
log("elf_load(): Invalid ELF magic: 0x%x", header->e_magic);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (header->e_class != 2) {
|
||||
debug("Unsupported ELF class: %u", header->e_class);
|
||||
log("elf_load(): Unsupported ELF class: %u", header->e_class);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (header->e_machine == 20 ||
|
||||
header->e_machine == 3 ||
|
||||
header->e_machine == 40) {
|
||||
return elf32_load(data, pagemap);
|
||||
return elf32_load(data, addr, pagemap);
|
||||
} 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("elf_load(): Unsupported ELF machine: %u", header->e_machine);
|
||||
return 0;
|
||||
}
|
||||
|
|
58
boot/common/loader/loader.c
Normal file
58
boot/common/loader/loader.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: loader.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 <config/config.h>
|
||||
#include <loader/loader.h>
|
||||
#include <lib/string.h>
|
||||
#include <proto/aurix.h>
|
||||
#include <print.h>
|
||||
#include <axboot.h>
|
||||
|
||||
int proto_str_to_int(char *proto)
|
||||
{
|
||||
if (strcmp(proto, "aurix") == 0) {
|
||||
return PROTO_AURIX;
|
||||
}
|
||||
|
||||
#ifdef AXBOOT_UEFI
|
||||
if (strcmp(proto, "efi-chainload") == 0) {
|
||||
return PROTO_CHAINLOAD;
|
||||
}
|
||||
#endif
|
||||
|
||||
return PROTO_UNSUPPORTED;
|
||||
}
|
||||
|
||||
void loader_load(struct axboot_entry *entry)
|
||||
{
|
||||
log("loader_load(): Booting \"%s\"...\n", entry->name);
|
||||
|
||||
switch (entry->protocol) {
|
||||
case PROTO_AURIX: {
|
||||
aurix_load(entry->image_path);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
log("loader_load(): Entry doesn't have a supported protocol!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UNREACHABLE();
|
||||
}
|
|
@ -42,7 +42,7 @@ int find_alloc(void *addr)
|
|||
int add_alloc(void *addr, size_t size)
|
||||
{
|
||||
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].size = size;
|
||||
return 1;
|
||||
|
@ -112,7 +112,6 @@ void *mem_alloc(size_t n)
|
|||
}
|
||||
|
||||
add_alloc(alloc, n);
|
||||
|
||||
return alloc;
|
||||
}
|
||||
|
||||
|
@ -122,12 +121,11 @@ int mem_allocat(void *addr, size_t npages)
|
|||
|
||||
status = gBootServices->AllocatePages(AllocateAddress, EfiLoaderData, (EFI_UINTN)npages, addr);
|
||||
if (EFI_ERROR(status)) {
|
||||
debug("mem_allocat(): Couldn't allocate %u bytes at 0x%lx: %s (%lx)\n", npages, addr, efi_status_to_str(status), status);
|
||||
debug("mem_allocat(): Couldn't allocate %u pages at 0x%lx: %s (%lx)\n", npages, addr, efi_status_to_str(status), status);
|
||||
return 0;
|
||||
}
|
||||
|
||||
add_alloc(addr, npages * PAGE_SIZE);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -137,9 +135,9 @@ void *mem_realloc(void *addr, size_t n)
|
|||
void *new = NULL;
|
||||
|
||||
int i = find_alloc(addr);
|
||||
if (i == -1) {
|
||||
debug("mem_realloc(): Couldn't find allocation for 0x%lx.\n");
|
||||
return NULL;
|
||||
if (i == -1 || addr == NULL) {
|
||||
debug("mem_realloc(): Couldn't find allocation for 0x%lx, allocating new memory.\n");
|
||||
return mem_alloc(n);
|
||||
}
|
||||
|
||||
old_size = allocation_list[i].size;
|
||||
|
@ -151,7 +149,6 @@ void *mem_realloc(void *addr, size_t n)
|
|||
|
||||
memcpy(new, addr, old_size);
|
||||
mem_free(addr);
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
|
@ -170,6 +167,7 @@ void mem_free(void *addr)
|
|||
}
|
||||
|
||||
remove_alloc(addr);
|
||||
debug("mem_free(): Freed 0x%llx\n", addr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,13 +19,16 @@
|
|||
|
||||
#define NANOPRINTF_IMPLEMENTATION
|
||||
#define NANOPRINTF_USE_FIELD_WIDTH_FORMAT_SPECIFIERS 1
|
||||
#define NANOPRINTF_USE_PRECISION_FORMAT_SPECIFIERS 0
|
||||
#define NANOPRINTF_USE_PRECISION_FORMAT_SPECIFIERS 1
|
||||
#define NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS 0
|
||||
#define NANOPRINTF_USE_LARGE_FORMAT_SPECIFIERS 1
|
||||
#define NANOPRINTF_USE_BINARY_FORMAT_SPECIFIERS 0
|
||||
#define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 0
|
||||
#include <nanoprintf.h>
|
||||
|
||||
#include <config/config.h>
|
||||
#include <uart/uart.h>
|
||||
#include <vfs/vfs.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
@ -33,43 +36,75 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
#include <mm/mman.h>
|
||||
#include <lib/string.h>
|
||||
|
||||
int32_t _fltused = 0;
|
||||
int32_t __eqdf2 = 0;
|
||||
int32_t __ltdf2 = 0;
|
||||
|
||||
extern struct axboot_cfg cfg;
|
||||
|
||||
CHAR16 wstr[1024];
|
||||
|
||||
void log(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char buf[4096];
|
||||
char buf[1024];
|
||||
size_t size = 0;
|
||||
|
||||
va_start(args, fmt);
|
||||
npf_vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
size = npf_vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
// TODO: Get rid of this
|
||||
uart_sendstr(buf);
|
||||
|
||||
if (cfg.bootlog_filename != NULL) {
|
||||
vfs_write(cfg.bootlog_filename, (char *)&buf, size);
|
||||
}
|
||||
|
||||
#ifdef AXBOOT_UEFI
|
||||
printstr(buf);
|
||||
char *bufp = &buf;
|
||||
size_t n = mbstowcs((wchar_t *)&wstr, (const char **)&bufp, 1024);
|
||||
wstr[n] = L'\r';
|
||||
wstr[n+1] = L'\0';
|
||||
gSystemTable->ConOut->OutputString(gSystemTable->ConOut, wstr);
|
||||
gBootServices->Stall(100000);
|
||||
#endif
|
||||
}
|
||||
|
||||
void debug(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char buf[4096];
|
||||
char buf[1024];
|
||||
|
||||
va_start(args, fmt);
|
||||
npf_vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
#ifdef AXBOOT_UEFI
|
||||
printstr(buf);
|
||||
char *bufp = &buf;
|
||||
size_t n = mbstowcs((wchar_t *)&wstr, (const char **)&bufp, 1024);
|
||||
wstr[n] = L'\r';
|
||||
wstr[n+1] = L'\0';
|
||||
gSystemTable->ConOut->OutputString(gSystemTable->ConOut, wstr);
|
||||
gBootServices->Stall(100000);
|
||||
#endif
|
||||
uart_sendstr(buf);
|
||||
}
|
||||
|
||||
void snprintf(char *buf, size_t size, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
npf_vsnprintf(buf, size, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
|
||||
{
|
||||
npf_vsnprintf(buf, size, fmt, args);
|
||||
}
|
||||
|
|
|
@ -17,65 +17,190 @@
|
|||
/* SOFTWARE. */
|
||||
/*********************************************************************************/
|
||||
|
||||
#include <acpi/acpi.h>
|
||||
#include <proto/aurix.h>
|
||||
#include <loader/elf.h>
|
||||
#include <mm/mman.h>
|
||||
#include <mm/memmap.h>
|
||||
#include <mm/vmm.h>
|
||||
#include <lib/string.h>
|
||||
#include <ui/framebuffer.h>
|
||||
#include <vfs/vfs.h>
|
||||
#include <print.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);
|
||||
extern char _aurix_handoff_start[], _aurix_handoff_end[];
|
||||
#include <stdint.h>
|
||||
#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)
|
||||
{
|
||||
// read kernel -> test read
|
||||
char *kbuf = NULL;
|
||||
vfs_read(kernel_path, &kbuf);
|
||||
|
||||
// TODO: Do something with the kernel :p
|
||||
pagetable *pm = create_pagemap();
|
||||
if (!pm) {
|
||||
debug("aurix_load(): Failed to create kernel pagemap! Halting...\n");
|
||||
log("aurix_load(): Failed to create kernel pagemap! Halting...\n");
|
||||
// TODO: Halt
|
||||
while (1);
|
||||
}
|
||||
|
||||
axboot_memmap *memmap = get_memmap(pm);
|
||||
axboot_memmap *mmap;
|
||||
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)_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) {
|
||||
debug("aurix_load(): Failed to allocate stack! Halting...\n");
|
||||
log("aurix_load(): Failed to allocate stack! Halting...\n");
|
||||
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) {
|
||||
debug("aurix_load(): Failed to load '%s'! Halting...\n", kernel_path);
|
||||
mem_free(kbuf);
|
||||
log("aurix_load(): Failed to load '%s'! Halting...\n", kernel_path);
|
||||
while (1);
|
||||
}
|
||||
mem_free(kbuf);
|
||||
|
||||
struct aurix_parameters parameters = {0};
|
||||
|
||||
// set current revision
|
||||
parameters.revision = AURIX_PROTOCOL_REVISION;
|
||||
|
||||
// translate memory map
|
||||
if (!aurix_get_memmap(¶meters, mmap, mmap_entries, pm)) {
|
||||
log("aurix_load(): Failed to aqcuire memory map!");
|
||||
while (1);
|
||||
}
|
||||
|
||||
void *parameters = NULL;
|
||||
parameters.kernel_addr = kernel_addr;
|
||||
|
||||
debug("aurix_load(): Handoff state: pm=0x%llx, stack=0x%llx, kernel_entry=0x%llx\n", pm, stack, kernel_entry);
|
||||
// get RSDP and SMBIOS
|
||||
#ifdef ARCH_ACPI_AVAILABLE
|
||||
parameters.rsdp_addr = platform_get_rsdp();
|
||||
#endif
|
||||
|
||||
// this triggers a #GP ????
|
||||
// aurix_handoff(pm, stack, (uint64_t)kernel_entry, (void *)parameters);
|
||||
// __builtin_unreachable();
|
||||
#ifdef ARCH_SMBIOS_AVAILABLE
|
||||
parameters.smbios_addr = platform_get_smbios();
|
||||
#endif
|
||||
|
||||
__asm__ volatile("movq %[pml4], %%cr3\n"
|
||||
"movq %[stack], %%rsp\n"
|
||||
"callq *%[entry]\n"
|
||||
:: [pml4]"r"(pm), [stack]"r"(stack), [entry]"r"(kernel_entry) : "memory");
|
||||
// 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();
|
||||
}
|
||||
|
|
91
boot/common/ui/font.c
Normal file
91
boot/common/ui/font.c
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: font.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 <mm/mman.h>
|
||||
#include <lib/string.h>
|
||||
#include <lib/assert.h>
|
||||
#include <vfs/vfs.h>
|
||||
#define FONT_IMPLEMENTATION
|
||||
#include <ui/ui.h>
|
||||
#include <ui/font.h>
|
||||
#include <print.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
bool font_init(struct ui_context *ctx, char *font_path, int size)
|
||||
{
|
||||
vfs_read(font_path, &(ctx->font_file));
|
||||
if (!ctx->font_file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int ssfn_status;
|
||||
|
||||
ssfn_status = ssfn_load(&(ctx->font), (void *)(ctx->font_file));
|
||||
if (ssfn_status != SSFN_OK) {
|
||||
debug("font_init(): SSFN failed to load font: %s!\n", ssfn_error(ssfn_status));
|
||||
goto error;
|
||||
}
|
||||
|
||||
ssfn_status = ssfn_select(&(ctx->font), SSFN_FAMILY_ANY, NULL, SSFN_STYLE_REGULAR, size);
|
||||
if (ssfn_status != SSFN_OK) {
|
||||
debug("font_init(): SSFN failed to select font: %s!\n", ssfn_error(ssfn_status));
|
||||
goto error;
|
||||
}
|
||||
|
||||
// initialize terminal
|
||||
ctx->terminal.font_size = size;
|
||||
ctx->terminal.cx = 0;
|
||||
ctx->terminal.cy = size;
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
mem_free(ctx->font_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
void font_write(struct ui_context *ctx, char *s, uint32_t cx, uint32_t cy)
|
||||
{
|
||||
ctx->font_buf.x = cx;
|
||||
ctx->font_buf.y = cy;
|
||||
ssfn_render(&(ctx->font), &(ctx->font_buf), s);
|
||||
}
|
||||
|
||||
void font_free(struct ui_context *ctx)
|
||||
{
|
||||
ssfn_free(&(ctx->font));
|
||||
mem_free(ctx->font_file);
|
||||
}
|
||||
|
||||
/*
|
||||
void font_ttf_init(char *font_path, int initial_size)
|
||||
{
|
||||
vfs_read(font_path, (char **)&font_buf);
|
||||
if (!font_buf) {
|
||||
debug("Font not loaded, returning...\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void font_psf2_init()
|
||||
{
|
||||
}
|
||||
*/
|
86
boot/common/ui/terminal.c
Normal file
86
boot/common/ui/terminal.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: terminal.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 <ui/ui.h>
|
||||
#include <ui/terminal.h>
|
||||
#include <axboot.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define HORIZONTAL_TAB_WIDTH 8
|
||||
|
||||
void terminal_print(struct ui_context *ctx, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char buf[4096] = {0};
|
||||
char *s = (char *)&buf;
|
||||
|
||||
va_start(args, fmt);
|
||||
vsnprintf((char *)&buf, sizeof(buf), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
while (*s) {
|
||||
switch (*s) {
|
||||
case '\t': {
|
||||
// horizontal tab - 4 spaces
|
||||
int w, h;
|
||||
ssfn_bbox(&(ctx->font), " ", &w, &h, NULL, NULL);
|
||||
if (ctx->terminal.cx >= ctx->fb_modes[ctx->current_mode].width - (w * HORIZONTAL_TAB_WIDTH)) {
|
||||
for (int i = 1; i <= HORIZONTAL_TAB_WIDTH; i++) {
|
||||
if (ctx->terminal.cx >= ctx->fb_modes[ctx->current_mode].width - (w * i)) {
|
||||
ctx->terminal.cx = ((HORIZONTAL_TAB_WIDTH * (w + 1)) - (w * i));
|
||||
ctx->terminal.cy += h;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ctx->terminal.cx += w * HORIZONTAL_TAB_WIDTH;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '\n': {
|
||||
// newline
|
||||
ctx->terminal.cx = 0;
|
||||
ctx->terminal.cy += ctx->terminal.font_size;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// printable character
|
||||
const char str[2] = {*s, 0};
|
||||
int w, h;
|
||||
ssfn_bbox(&(ctx->font), (char *)&str, &w, &h, NULL, NULL);
|
||||
if (ctx->terminal.cx + w >= ctx->fb_modes[ctx->current_mode].width) {
|
||||
ctx->terminal.cx = 0;
|
||||
ctx->terminal.cy += h;
|
||||
}
|
||||
font_write(ctx, (char *)&str, ctx->terminal.cx, ctx->terminal.cy);
|
||||
ctx->terminal.cx += w;
|
||||
break;
|
||||
}
|
||||
}
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
void terminal_setcur(struct ui_context *ui, uint32_t x, uint32_t y)
|
||||
{
|
||||
ui->terminal.cx = x;
|
||||
ui->terminal.cy = y;
|
||||
}
|
290
boot/common/ui/ui.c
Normal file
290
boot/common/ui/ui.c
Normal file
|
@ -0,0 +1,290 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: ui.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 <config/config.h>
|
||||
#include <lib/string.h>
|
||||
#include <ui/framebuffer.h>
|
||||
#include <ui/keyboard.h>
|
||||
#include <ui/mouse.h>
|
||||
#include <ui/font.h>
|
||||
#include <ui/ui.h>
|
||||
#include <loader/loader.h>
|
||||
#include <time/dt.h>
|
||||
#include <i18n.h>
|
||||
#include <axboot.h>
|
||||
|
||||
#include <print.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
EVENT_TIME = (1 << 0),
|
||||
EVENT_TIMEOUT = (1 << 1),
|
||||
EVENT_MOUSE = (1 << 2),
|
||||
|
||||
EVENT_NEXT_ENTRY = (1 << 3),
|
||||
EVENT_PREV_ENTRY = (1 << 4),
|
||||
EVENT_NEXT_TAB = (1 << 5),
|
||||
|
||||
EVENT_LANG_CHANGE = (1 << 6),
|
||||
};
|
||||
|
||||
struct datetime last_dt;
|
||||
|
||||
bool gui_init(struct ui_context *ctx)
|
||||
{
|
||||
if (!font_init(ctx, "\\AxBoot\\fonts\\vera\\Vera.sfn", 16)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool tui_init(struct ui_context *ctx)
|
||||
{
|
||||
if (!font_init(ctx, "\\AxBoot\\fonts\\u_vga16\\u_vga16.sfn", 16)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int width = ctx->fb_modes[ctx->current_mode].width;
|
||||
int height = ctx->fb_modes[ctx->current_mode].height;
|
||||
int width_center = width / 2;
|
||||
int height_center = height / 2;
|
||||
|
||||
int w, h;
|
||||
|
||||
// display string at the top center of the screen
|
||||
char *top_string = BOOTLOADER_NAME_STR " v" BOOTLOADER_VERSION_STR;
|
||||
ssfn_bbox(&(ctx->font), top_string, &w, NULL, NULL, NULL);
|
||||
|
||||
terminal_setcur(ctx, width_center - (w / 2), height / 32);
|
||||
terminal_print(ctx, top_string);
|
||||
|
||||
// display current language
|
||||
char lang_str[64];
|
||||
snprintf((char *)&lang_str, 64, "%s: %s", i18n_curlang->lang->language, i18n_curlang->name);
|
||||
ssfn_bbox(&(ctx->font), (char *)lang_str, &w, &h, NULL, NULL);
|
||||
terminal_setcur(ctx, width - w - ctx->font.size, height - h);
|
||||
terminal_print(ctx, (char *)lang_str);
|
||||
|
||||
// display all entries
|
||||
int entry_count = config_get_entry_count();
|
||||
int entry_height_offset = height_center - ((h * entry_count) / 2);
|
||||
struct axboot_entry *entries = config_get_entries();
|
||||
|
||||
for (int i = 0; i < entry_count; i++) {
|
||||
debug("tui_init(): Drawing entries... (%u/%u)\n", i, entry_count);
|
||||
ssfn_bbox(&(ctx->font), entries[i].name, &w, &h, NULL, NULL);
|
||||
terminal_setcur(ctx, width_center - (w/2), entry_height_offset + (i * h));
|
||||
terminal_print(ctx, entries[i].name);
|
||||
}
|
||||
|
||||
// highlight default entry
|
||||
int default_entry = ctx->current_selection;
|
||||
char final_selent[128];
|
||||
int f_w, f_h;
|
||||
ssfn_bbox(&(ctx->font), " ", &f_w, &f_h, NULL, NULL);
|
||||
snprintf((char *)&final_selent, 128, "> %s <", entries[default_entry].name);
|
||||
ssfn_bbox(&(ctx->font), entries[default_entry].name, &w, &h, NULL, NULL);
|
||||
terminal_setcur(ctx, width_center - (w/2) - (f_w*2), entry_height_offset + (default_entry * h));
|
||||
terminal_print(ctx, "> ");
|
||||
terminal_setcur(ctx, width_center + (w/2), entry_height_offset + (default_entry * h));
|
||||
terminal_print(ctx, " <");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void gui_draw(struct ui_context *ctx, struct datetime *dt, struct language_selection *newlang, struct mouse_event *mouse_status, uint8_t event)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)dt;
|
||||
(void)newlang;
|
||||
(void)mouse_status;
|
||||
(void)event;
|
||||
}
|
||||
|
||||
void tui_draw(struct ui_context *ctx, struct datetime *dt, struct language_selection *newlang, struct mouse_event *mouse_status, uint8_t event)
|
||||
{
|
||||
(void)mouse_status;
|
||||
|
||||
// display the current date and time at the bottom left corner of the screen
|
||||
if (event & EVENT_TIME) {
|
||||
int w, h;
|
||||
char dt_str[20] = {0}; // YYYY/mm/dd HH:MM:SS
|
||||
snprintf((char *)&dt_str, 20, "%.4u/%.2u/%.2u %.2u:%.2u:%.2u", dt->year, dt->month, dt->day, dt->h, dt->m, dt->s);
|
||||
|
||||
ssfn_bbox(&(ctx->font), (char *)dt_str, &w, &h, NULL, NULL);
|
||||
|
||||
for (uint32_t y = ctx->fb_modes[ctx->current_mode].height - (2*h); y < ctx->fb_modes[ctx->current_mode].height - h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
*((uint32_t *)ctx->fb_addr + (ctx->fb_modes[ctx->current_mode].pitch / ctx->fb_modes[ctx->current_mode].bpp) * y + x) = 0xFF000000;
|
||||
}
|
||||
}
|
||||
terminal_setcur(ctx, 0, ctx->fb_modes[ctx->current_mode].height - h);
|
||||
terminal_print(ctx, (char *)dt_str);
|
||||
|
||||
// update last datetime
|
||||
last_dt = *dt;
|
||||
}
|
||||
|
||||
// timeout update
|
||||
if (event & EVENT_TIMEOUT) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// select next entry
|
||||
if (event & EVENT_NEXT_ENTRY) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// select previous entry
|
||||
if (event & EVENT_PREV_ENTRY) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// update language
|
||||
if (event & EVENT_LANG_CHANGE) {
|
||||
int w, h;
|
||||
char curlang_str[64];
|
||||
snprintf((char *)&curlang_str, 64, "%s: %s", i18n_curlang->lang->language);
|
||||
ssfn_bbox(&(ctx->font), (char *)curlang_str, &w, &h, NULL, NULL);
|
||||
for (uint32_t y = ctx->fb_modes[ctx->current_mode].height - (2*h); y < ctx->fb_modes[ctx->current_mode].height - h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
*((uint32_t *)ctx->fb_addr + (ctx->fb_modes[ctx->current_mode].pitch / ctx->fb_modes[ctx->current_mode].bpp) * y + x) = 0xFF000000;
|
||||
}
|
||||
}
|
||||
|
||||
i18n_curlang = newlang;
|
||||
|
||||
char newlang_str[64];
|
||||
snprintf((char *)&curlang_str, 64, "%s: %s", i18n_curlang->lang->language);
|
||||
ssfn_bbox(&(ctx->font), (char *)curlang_str, &w, &h, NULL, NULL);
|
||||
terminal_setcur(ctx, ctx->fb_modes[ctx->current_mode].width - w, ctx->fb_modes[ctx->current_mode].height - h);
|
||||
terminal_print(ctx, (char *)newlang_str);
|
||||
}
|
||||
}
|
||||
|
||||
void ui_init()
|
||||
{
|
||||
struct ui_context ctx = {0};
|
||||
|
||||
if (!get_framebuffer(&ctx.fb_addr, &ctx.fb_modes, &ctx.total_modes, &ctx.current_mode)) {
|
||||
debug("ui_init(): Failed to acquire a framebuffer!\n");
|
||||
while (1);
|
||||
}
|
||||
|
||||
ctx.ui = config_get_ui_mode();
|
||||
|
||||
debug("Dumping framebuffer information\n");
|
||||
debug("--------------------------------\n");
|
||||
debug("Address: 0x%llx\n", ctx.fb_addr);
|
||||
|
||||
for (int i = 0; i < ctx.total_modes; i++) {
|
||||
debug("Mode %u:%s | ", i, (i == ctx.current_mode) ? " (current)" : "");
|
||||
debug("Resolution: %ux%u | ", ctx.fb_modes[i].width, ctx.fb_modes[i].height);
|
||||
debug("Bytes Per Pixel: %u | ", ctx.fb_modes[i].bpp);
|
||||
debug("Pitch: %u | ", ctx.fb_modes[i].pitch);
|
||||
debug("Format: %s\n", ctx.fb_modes[i].format == FB_RGBA ? "RGBA" : "BGRA");
|
||||
}
|
||||
|
||||
ctx.font_buf.ptr = (uint8_t *)ctx.fb_addr;
|
||||
ctx.font_buf.w = ctx.fb_modes[ctx.current_mode].width;
|
||||
ctx.font_buf.h = ctx.fb_modes[ctx.current_mode].height;
|
||||
ctx.font_buf.p = ctx.fb_modes[ctx.current_mode].pitch;
|
||||
ctx.font_buf.x = 0;
|
||||
ctx.font_buf.y = 0;
|
||||
ctx.font_buf.fg = 0xFFFFFFFF;
|
||||
|
||||
ctx.current_selection = config_get_default();
|
||||
|
||||
void (*ui_callback)(struct ui_context*,struct datetime*,struct language_selection*,struct mouse_event*,uint8_t) = NULL;
|
||||
|
||||
switch (ctx.ui) {
|
||||
case UI_MODERN: {
|
||||
if (!gui_init(&ctx)) {
|
||||
debug("ui_init(): Failed to initialize modern UI, booting default selection...\n");
|
||||
break;
|
||||
}
|
||||
ui_callback = gui_draw;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case UI_TEXT: {
|
||||
if (!tui_init(&ctx)) {
|
||||
debug("ui_init(): Failed to initialize text UI, booting default selection...\n");
|
||||
break;
|
||||
}
|
||||
ui_callback = tui_draw;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct datetime dt;
|
||||
struct mouse_event me;
|
||||
|
||||
while (1) {
|
||||
uint8_t event = 0;
|
||||
|
||||
// datetime?
|
||||
get_datetime(&dt);
|
||||
if (memcmp(&dt, &last_dt, sizeof(struct datetime)) != 0) {
|
||||
event |= EVENT_TIME;
|
||||
}
|
||||
|
||||
// mouse movement?
|
||||
get_mouse(&(me.x), &(me.y), &(me.but));
|
||||
if (memcmp(&me, &(ctx.last_mouse), sizeof(struct mouse_event)) != 0) {
|
||||
event |= EVENT_MOUSE;
|
||||
}
|
||||
|
||||
// keypress?
|
||||
uint16_t scancode;
|
||||
get_keypress(&scancode);
|
||||
if (scancode != 0) {
|
||||
switch (scancode) {
|
||||
case SCANCODE_ARROW_DOWN:
|
||||
event |= EVENT_NEXT_ENTRY;
|
||||
break;
|
||||
case SCANCODE_ARROW_UP:
|
||||
event |= EVENT_PREV_ENTRY;
|
||||
break;
|
||||
case SCANCODE_ENTER:
|
||||
// clear the screen
|
||||
for (uint32_t y = 0; y < ctx.fb_modes[ctx.current_mode].height; y++) {
|
||||
for (uint32_t x = 0; x < ctx.fb_modes[ctx.current_mode].width; x++) {
|
||||
*((uint32_t *)ctx.fb_addr + (ctx.fb_modes[ctx.current_mode].pitch / ctx.fb_modes[ctx.current_mode].bpp) * y + x) = 0xFF000000;
|
||||
}
|
||||
}
|
||||
struct axboot_entry *entries = config_get_entries();
|
||||
loader_load(&entries[ctx.current_selection]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (event != 0) {
|
||||
ui_callback(&ctx, &dt, NULL, &me, event);
|
||||
} else {
|
||||
#ifdef __x86_64
|
||||
__asm__ volatile("hlt");
|
||||
#endif
|
||||
//arch_wait();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,19 +36,19 @@ int vfs_init(char *root_mountpoint)
|
|||
{
|
||||
boot_drive = mount_boot_volume(root_mountpoint);
|
||||
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.
|
||||
return 0;
|
||||
}
|
||||
|
||||
debug("vfs_init(): Mounted boot drive to \"/\"\n");
|
||||
log("vfs_init(): Mounted boot drive to \"\\\"\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t vfs_read(char *filename, char **buf)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -57,9 +57,10 @@ size_t vfs_read(char *filename, char **buf)
|
|||
|
||||
int vfs_write(char *filename, char *buf, size_t len)
|
||||
{
|
||||
(void)filename;
|
||||
(void)buf;
|
||||
(void)len;
|
||||
if (boot_drive->fs->write == NULL) {
|
||||
log("vfs_read(): Filesystem didn't setup a write function!\n");
|
||||
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 */
|
33
boot/include/arch/x86_64/arch/cpu/idt.h
Normal file
33
boot/include/arch/x86_64/arch/cpu/idt.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: idt.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 _ARCH_CPU_IDT_H
|
||||
#define _ARCH_CPU_IDT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct idt_descriptor {
|
||||
};
|
||||
|
||||
struct idtr {
|
||||
uint16_t limit;
|
||||
uint64_t base;
|
||||
};
|
||||
|
||||
#endif /* _ARCH_CPU_IDT_H */
|
94
boot/include/arch/x86_64/arch/lib/math.h
Normal file
94
boot/include/arch/x86_64/arch/lib/math.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: math.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 _ARCH_LIB_MATH_H
|
||||
#define _ARCH_LIB_MATH_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
static double _sqrt(double n)
|
||||
{
|
||||
double out;
|
||||
__asm__ volatile("fldl %[input];"
|
||||
"fsqrt;"
|
||||
"fstpl %[output];"
|
||||
: [ output ] "=g"(out)
|
||||
: [ input ] "g"(n)
|
||||
:);
|
||||
return out;
|
||||
}
|
||||
|
||||
static double _cos(double n)
|
||||
{
|
||||
double out;
|
||||
__asm__ volatile("fldl %[input];"
|
||||
"fcos;"
|
||||
"fstpl %[output];"
|
||||
: [ output ] "=g"(out)
|
||||
: [ input ] "g"(n)
|
||||
:);
|
||||
return out;
|
||||
}
|
||||
|
||||
static double _acos(double n)
|
||||
{
|
||||
double imd = _sqrt(1 - (n * n));
|
||||
double out;
|
||||
__asm__ volatile("fldl %[imd];"
|
||||
"fldl %[input];"
|
||||
"fpatan;"
|
||||
"fstpl %[output];"
|
||||
: [ output ] "=g"(out)
|
||||
: [ input ] "g"(n), [ imd ] "g"(imd)
|
||||
:);
|
||||
return out;
|
||||
}
|
||||
|
||||
static int _ifloor(double d)
|
||||
{
|
||||
if ((((double)((int)d)) == d) || (d >= 0))
|
||||
return (int)d;
|
||||
return (int)(d - 1);
|
||||
}
|
||||
|
||||
static int _iceil(double d)
|
||||
{
|
||||
if ((((double)((int)d)) == d) || (d < 0))
|
||||
return (int)d;
|
||||
return (int)(d + 1);
|
||||
}
|
||||
|
||||
static double _pow(double a, int n)
|
||||
{
|
||||
double prod = 1;
|
||||
bool neg = (n < 0);
|
||||
n = neg ? -n : n;
|
||||
for (int i = 0; i < n; i++)
|
||||
prod = prod * a;
|
||||
if (neg)
|
||||
prod = 1 / prod;
|
||||
return prod;
|
||||
}
|
||||
|
||||
static double _fmod(double x, double y)
|
||||
{
|
||||
return x - ((int)(x / y)) * y;
|
||||
}
|
||||
|
||||
#endif /* _ARCH_LIB_MATH_H */
|
|
@ -29,6 +29,14 @@
|
|||
#define UNREACHABLE() __builtin_unreachable()
|
||||
#endif
|
||||
|
||||
// TODO: This is hacky
|
||||
#define axboot_halt() while (1);
|
||||
|
||||
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 */
|
53
boot/include/config/config.h
Normal file
53
boot/include/config/config.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: config.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 _CONFIG_CONFIG_H
|
||||
#define _CONFIG_CONFIG_H
|
||||
|
||||
enum {
|
||||
UI_TEXT = 0,
|
||||
UI_MODERN = 1
|
||||
};
|
||||
|
||||
struct axboot_cfg {
|
||||
// overridable stuff
|
||||
int default_entry;
|
||||
int timeout;
|
||||
int ui_mode;
|
||||
|
||||
int entry_count;
|
||||
char *bootlog_filename;
|
||||
};
|
||||
|
||||
struct axboot_entry {
|
||||
char *name;
|
||||
char *description;
|
||||
char *image_path;
|
||||
int protocol;
|
||||
};
|
||||
|
||||
void config_init(void);
|
||||
|
||||
int config_get_timeout();
|
||||
int config_get_default();
|
||||
int config_get_entry_count();
|
||||
struct axboot_entry *config_get_entries();
|
||||
int config_get_ui_mode();
|
||||
|
||||
#endif /* _CONFIG_CONFIG_H */
|
41
boot/include/data/da.h
Normal file
41
boot/include/data/da.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: da.b */
|
||||
/* 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 _DATA_DA_H
|
||||
#define _DATA_DA_H
|
||||
|
||||
#include <mm/mman.h>
|
||||
#include <print.h>
|
||||
#include <stddef.h>
|
||||
#include <efilib.h>
|
||||
|
||||
#define DA_INIT_CAPACITY 8192
|
||||
#define DA_REALLOC(oldptr, newsz) mem_realloc(oldptr, newsz)
|
||||
|
||||
#define da_append(da, item) \
|
||||
do {\
|
||||
if ((da)->count >= (da)->capacity) { \
|
||||
size_t new_capacity = (da)->capacity + DA_INIT_CAPACITY; \
|
||||
(da)->items = DA_REALLOC((da)->items, new_capacity * sizeof((da)->items[0])); \
|
||||
(da)->capacity = new_capacity; \
|
||||
} \
|
||||
(da)->items[(da)->count++] = (item); \
|
||||
} while (0)
|
||||
|
||||
#endif /* _DATA_DA_H */
|
45
boot/include/data/list.h
Normal file
45
boot/include/data/list.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: list.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 _DATA_LIST_H
|
||||
#define _DATA_LIST_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct _ListNode {
|
||||
void *data;
|
||||
struct _ListNode *prev;
|
||||
struct _ListNode *next;
|
||||
} ListNode;
|
||||
|
||||
typedef struct _List {
|
||||
uint32_t count;
|
||||
ListNode *root;
|
||||
} List;
|
||||
|
||||
List *list_new();
|
||||
|
||||
int list_add(List *list, void *data);
|
||||
void *list_remove_at(List *list, uint32_t idx);
|
||||
|
||||
ListNode *listnode_new(void *data);
|
||||
|
||||
void *list_get_at(List *list, uint32_t idx);
|
||||
|
||||
#endif /* _DATA_LIST_H */
|
|
@ -1,5 +1,5 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: print.c */
|
||||
/* Module Name: driver.h */
|
||||
/* Project: AurixOS */
|
||||
/* */
|
||||
/* Copyright (c) 2024-2025 Jozef Nagy */
|
||||
|
@ -17,14 +17,23 @@
|
|||
/* SOFTWARE. */
|
||||
/*********************************************************************************/
|
||||
|
||||
#include <lib/string.h>
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
#ifndef _DRIVER_H
|
||||
#define _DRIVER_H
|
||||
|
||||
void printstr(const char *str)
|
||||
{
|
||||
CHAR16 wstr[4096];
|
||||
mbstowcs(wstr, &str, strlen(str));
|
||||
wstr[strlen(str)] = '\0';
|
||||
gSystemTable->ConOut->OutputString(gSystemTable->ConOut, wstr);
|
||||
}
|
||||
#ifdef AXBOOT_UEFI
|
||||
|
||||
#include <stddef.h>
|
||||
#include <efi.h>
|
||||
|
||||
struct driver {
|
||||
EFI_HANDLE handle;
|
||||
char *binary;
|
||||
size_t binsize;
|
||||
EFI_MEMMAP_DEVICE_PATH devpath[2];
|
||||
};
|
||||
|
||||
void load_drivers();
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _DRIVER_H */
|
|
@ -26,5 +26,6 @@
|
|||
struct vfs_drive *sfs_init(char *mountpoint);
|
||||
|
||||
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 */
|
||||
|
|
40
boot/include/i18n.h
Normal file
40
boot/include/i18n.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: i18n.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 _I18N_H
|
||||
#define _I18N_H
|
||||
|
||||
struct language {
|
||||
char *shutdown;
|
||||
char *reboot;
|
||||
char *reboot_to_firmware;
|
||||
char *resolution;
|
||||
|
||||
char *language;
|
||||
};
|
||||
|
||||
struct language_selection {
|
||||
char *name;
|
||||
char *code;
|
||||
struct language *lang;
|
||||
};
|
||||
|
||||
extern struct language_selection *i18n_curlang;
|
||||
|
||||
#endif /* _I18N_H */
|
34
boot/include/lib/assert.h
Normal file
34
boot/include/lib/assert.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: assert.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 _LIB_ASSERT_H
|
||||
#define _LIB_ASSERT_H
|
||||
|
||||
#include <print.h>
|
||||
#include <axboot.h>
|
||||
|
||||
#define assert(expr, msg) \
|
||||
do { \
|
||||
if (!!(expr)) { \
|
||||
log("Assertion failed in file %s, line %u: %s\n", __FILE__, __LINE__, msg); \
|
||||
axboot_halt(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif /* _LIB_ASSERT_H */
|
|
@ -30,6 +30,8 @@ size_t strlen(const char *str);
|
|||
int strcmp(const char *s1, const char *s2);
|
||||
int strncmp(const char *s1, const char *s2, size_t n);
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strncpy(char *dest, const char *src, size_t n);
|
||||
char *strncat(char *dest, const char *src, size_t n);
|
||||
char *strdup(const char *s);
|
||||
char *strtok(char *str, const char *delim);
|
||||
char *strchr(char *s, int c);
|
||||
|
|
|
@ -73,6 +73,6 @@ struct elf_program_header {
|
|||
#define PF_W 0x2
|
||||
#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 */
|
||||
|
|
36
boot/include/loader/loader.h
Normal file
36
boot/include/loader/loader.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: loader.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 _LOADER_LOADER_H
|
||||
#define _LOADER_LOADER_H
|
||||
|
||||
enum loader_protocol {
|
||||
PROTO_AURIX,
|
||||
#ifdef AXBOOT_UEFI
|
||||
PROTO_CHAINLOAD,
|
||||
#endif
|
||||
|
||||
PROTO_UNSUPPORTED
|
||||
};
|
||||
|
||||
void loader_load(struct axboot_entry *entry);
|
||||
|
||||
int proto_str_to_int(char *proto);
|
||||
|
||||
#endif /* _LOADER_LOADER_H */
|
|
@ -20,6 +20,7 @@
|
|||
#ifndef _MEM_MEMMAP_H
|
||||
#define _MEM_MEMMAP_H
|
||||
|
||||
#include <mm/vmm.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum AxBootMemMapType {
|
||||
|
@ -45,6 +46,6 @@ typedef struct _axboot_memmap {
|
|||
int type;
|
||||
} axboot_memmap;
|
||||
|
||||
axboot_memmap *get_memmap();
|
||||
uint32_t get_memmap(axboot_memmap **map, pagetable *pm);
|
||||
|
||||
#endif /* _MEM_MEMMAP_H */
|
30
boot/include/power.h
Normal file
30
boot/include/power.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: power.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 _POWER_H
|
||||
#define _POWER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool platform_is_reboot_to_fw_possible();
|
||||
void platform_reboot_to_fw();
|
||||
void platform_reboot();
|
||||
void platform_shutdown();
|
||||
|
||||
#endif /* _POWER_H */
|
|
@ -31,5 +31,6 @@ void debug(const char *fmt, ...);
|
|||
void printstr(const char *str);
|
||||
|
||||
void snprintf(char *buf, size_t size, const char *fmt, ...);
|
||||
void vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
|
||||
|
||||
#endif /* _PRINT_H */
|
|
@ -17,9 +17,68 @@
|
|||
/* SOFTWARE. */
|
||||
/*********************************************************************************/
|
||||
|
||||
#ifndef _PROTO_AURIX_H
|
||||
#define _PROTO_AURIX_H
|
||||
#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 */
|
||||
|
|
35
boot/include/time/dt.h
Normal file
35
boot/include/time/dt.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: dt.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 _TIME_DT_H
|
||||
#define _TIME_DT_H
|
||||
|
||||
struct datetime {
|
||||
int year;
|
||||
int month;
|
||||
int day;
|
||||
|
||||
int h;
|
||||
int m;
|
||||
int s;
|
||||
};
|
||||
|
||||
void get_datetime(struct datetime *dt);
|
||||
|
||||
#endif /* _TIME_DT_H */
|
30
boot/include/uart/uart.h
Normal file
30
boot/include/uart/uart.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: uart.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 _UART_UART_H
|
||||
#define _UART_UART_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void uart_init(uint32_t baud_rate);
|
||||
|
||||
void uart_send(char c);
|
||||
void uart_sendstr(char *str);
|
||||
|
||||
#endif /* _UART_UART_H */
|
33
boot/include/ui/font.h
Normal file
33
boot/include/ui/font.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: font.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 _UI_FONT_H
|
||||
#define _UI_FONT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct ui_context;
|
||||
|
||||
bool font_init(struct ui_context *ctx, char *font_path, int size);
|
||||
void font_free(struct ui_context *ctx);
|
||||
|
||||
void font_write(struct ui_context *ctx, char *s, uint32_t cx, uint32_t cy);
|
||||
|
||||
#endif /* _UI_FONT_H */
|
41
boot/include/ui/framebuffer.h
Normal file
41
boot/include/ui/framebuffer.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: framebuffer.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 _UI_FRAMEBUFFER_H
|
||||
#define _UI_FRAMEBUFFER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
enum fb_format {
|
||||
FB_RGBA = 0,
|
||||
FB_BGRA = 1
|
||||
};
|
||||
|
||||
struct fb_mode {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint8_t bpp;
|
||||
uint32_t pitch;
|
||||
int format;
|
||||
};
|
||||
|
||||
bool get_framebuffer(uint32_t **fb_addr, struct fb_mode **available_modes, int *total_modes, int *current_mode_index);
|
||||
|
||||
#endif /* _UI_FRAMEBUFFER_H */
|
31
boot/include/ui/keyboard.h
Normal file
31
boot/include/ui/keyboard.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: keyboard.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. */
|
||||
/*********************************************************************************/
|
||||
|
||||
#ifndef _UI_KEYBOARD_H
|
||||
#define _UI_KEYBOARD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SCANCODE_ARROW_UP 0x1
|
||||
#define SCANCODE_ARROW_DOWN 0x2
|
||||
#define SCANCODE_ENTER 43
|
||||
|
||||
void get_keypress(uint16_t *scancode);
|
||||
|
||||
#endif /* _UI_KEYBOARD_H */
|
31
boot/include/ui/mouse.h
Normal file
31
boot/include/ui/mouse.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: mouse.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 _UI_MOUSE_H
|
||||
#define _UI_MOUSE_H
|
||||
|
||||
enum {
|
||||
LEFT_MOUSE_BUTTON = 0x1,
|
||||
MIDDLE_MOUSE_BUTTON = 0x2,
|
||||
RIGHT_MOUSE_BUTTON = 0x4
|
||||
};
|
||||
|
||||
void get_mouse(uint16_t *mouse_x, uint16_t *mouse_y, uint8_t *mouse_buttons);
|
||||
|
||||
#endif /* _UI_MOUSE_H */
|
1604
boot/include/ui/ssfn.h
Normal file
1604
boot/include/ui/ssfn.h
Normal file
File diff suppressed because it is too large
Load diff
37
boot/include/ui/terminal.h
Normal file
37
boot/include/ui/terminal.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: terminal.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 _UI_TERMINAL_H
|
||||
#define _UI_TERMINAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct terminal {
|
||||
uint32_t cx;
|
||||
uint32_t cy;
|
||||
|
||||
int font_size;
|
||||
};
|
||||
|
||||
struct ui_context;
|
||||
|
||||
void terminal_print(struct ui_context *ctx, char *fmt, ...);
|
||||
void terminal_setcur(struct ui_context *ui, uint32_t x, uint32_t y);
|
||||
|
||||
#endif /* _UI_TERMINAL_H */
|
69
boot/include/ui/ui.h
Normal file
69
boot/include/ui/ui.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: ui.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 _UI_UI_H
|
||||
#define _UI_UI_H
|
||||
|
||||
#include <ui/framebuffer.h>
|
||||
#include <ui/terminal.h>
|
||||
#include <ui/font.h>
|
||||
|
||||
// this is so hacky... but it works
|
||||
#ifdef FONT_IMPLEMENTATION
|
||||
#include <lib/string.h>
|
||||
#include <mm/mman.h>
|
||||
|
||||
#define SSFN_memcmp memcmp
|
||||
#define SSFN_memset memset
|
||||
#define SSFN_realloc mem_realloc
|
||||
#define SSFN_free mem_free
|
||||
#define SSFN_IMPLEMENTATION
|
||||
#endif
|
||||
#include <ui/ssfn.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct mouse_event {
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
uint8_t but;
|
||||
};
|
||||
|
||||
struct ui_context {
|
||||
uint32_t *fb_addr;
|
||||
struct fb_mode *fb_modes;
|
||||
int total_modes;
|
||||
int current_mode;
|
||||
int ui;
|
||||
|
||||
struct mouse_event last_mouse;
|
||||
|
||||
int current_selection;
|
||||
int last_selection;
|
||||
|
||||
struct terminal terminal;
|
||||
|
||||
ssfn_t font;
|
||||
ssfn_buf_t font_buf;
|
||||
char *font_file;
|
||||
};
|
||||
|
||||
void ui_init();
|
||||
|
||||
#endif /* _UI_UI_H */
|
|
@ -37,7 +37,8 @@ INCLUDE_DIRS += $(BOOT_ROOT)/include \
|
|||
$(BOOT_ROOT)/include/arch/$(ARCH) \
|
||||
$(BOOT_ROOT)/include/arch/$(ARCH)/uefi \
|
||||
$(BOOT_ROOT)/include/platform/$(PLATFORM) \
|
||||
$(BOOT_ROOT)/platform/uefi/libefi
|
||||
$(BOOT_ROOT)/platform/uefi/libefi \
|
||||
$(BOOT_ROOT)/platform/uefi/drivers/intel-hda
|
||||
|
||||
UEFI_AS := $(ARCH)-w64-mingw32-as
|
||||
UEFI_CC := clang
|
||||
|
@ -51,7 +52,10 @@ UEFI_CFLAGS := $(CFLAGS) \
|
|||
-DAXBOOT_UEFI=1 \
|
||||
$(foreach d, $(INCLUDE_DIRS), -I$d) \
|
||||
-target $(ARCH)-unknown-windows \
|
||||
-std=c11 \
|
||||
-flto \
|
||||
-fshort-wchar \
|
||||
-msoft-float \
|
||||
-mno-red-zone \
|
||||
-mno-stack-arg-probe
|
||||
|
||||
|
@ -67,6 +71,7 @@ UEFI_LDFLAGS := $(LDFLAGS) \
|
|||
-fuse-ld=lld-link \
|
||||
-Wl,-subsystem:efi_application \
|
||||
-Wl,-entry:uefi_entry
|
||||
|
||||
COMMON_CFILES := $(shell find $(BOOT_ROOT)/common -name '*.c')
|
||||
COMMON_ARCH_CFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH)/common -name '*.c')
|
||||
COMMON_ARCH_ASFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH)/common -name '*.S')
|
||||
|
|
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;
|
||||
}
|
88
boot/platform/uefi/driver.c
Normal file
88
boot/platform/uefi/driver.c
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: entry.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 <driver.h>
|
||||
#include <config/config.h>
|
||||
#include <mm/mman.h>
|
||||
#include <lib/string.h>
|
||||
#include <vfs/vfs.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
bool verify_secure_boot()
|
||||
{
|
||||
EFI_GUID var_guid = EFI_GLOBAL_VARIABLE;
|
||||
EFI_UINT8 val = 0;
|
||||
EFI_UINTN size = sizeof(val);
|
||||
bool ret = 0;
|
||||
|
||||
if (!EFI_ERROR(gSystemTable->RuntimeServices->GetVariable(L"SecureBoot", &var_guid, NULL, &size, &val))) {
|
||||
log("verify_secure_boot(): Secure Boot Status: %u\n", val);
|
||||
ret = (bool)val;
|
||||
|
||||
if (!EFI_ERROR(gSystemTable->RuntimeServices->GetVariable(L"SetupMode", &var_guid, NULL, &size, &val)) && val != 0) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
return !ret;
|
||||
}
|
||||
|
||||
void load_drivers()
|
||||
{
|
||||
// EFI_STATUS status;
|
||||
if (!verify_secure_boot()) {
|
||||
log("load_drivers(): Secure boot is enabled! Won't load drivers...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Create a vfs_list() function to get a list of files in a directory
|
||||
// char *driver_path = "\\AxBoot\\drivers\\.efi";
|
||||
// char *driver_binary;
|
||||
// log("load_drivers(): Loading '%s'...\n", driver_name);
|
||||
//
|
||||
// size_t driver_size = vfs_read(driver_path, &driver_binary);
|
||||
//
|
||||
// driver_devpath[0].Header.Length[0] = sizeof(EFI_MEMMAP_DEVICE_PATH);
|
||||
// driver_devpath[0].Header.Length[1] = sizeof(EFI_MEMMAP_DEVICE_PATH) >> 8;
|
||||
// driver_devpath[0].Header.Type = 1;
|
||||
// driver_devpath[0].Header.SubType = 3;
|
||||
// driver_devpath[0].MemoryType = EfiLoaderData;
|
||||
// driver_devpath[0].StartingAddress = (EFI_UINTPTR)driver_binary;
|
||||
// driver_devpath[0].EndingAddress = (EFI_UINTPTR)driver_binary + driver_size;
|
||||
// driver_devpath[1].Header.Length[0] = sizeof(EFI_DEVICE_PATH_PROTOCOL);
|
||||
// driver_devpath[1].Header.Length[1] = sizeof(EFI_DEVICE_PATH_PROTOCOL) >> 8;
|
||||
// driver_devpath[1].Header.Type = 0x7F;
|
||||
// driver_devpath[1].Header.SubType = 0xFF;
|
||||
//
|
||||
// status = gSystemTable->BootServices->LoadImage(EFI_FALSE, gImageHandle, (EFI_DEVICE_PATH_PROTOCOL *)driver_devpath, driver_binary, driver_size, &driver_handle);
|
||||
// if (EFI_ERROR(status)) {
|
||||
// log("load_drivers(): Failed to load driver '%s': %s (%llx)\n", driver_name, efi_status_to_str(status), status);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// status = gSystemTable->BootServices->StartImage(driver_handle, NULL, NULL);
|
||||
// if (EFI_ERROR(status)) {
|
||||
// log("load_drivers(): Failed to start driver '%s': %s (%llx)\n", driver_name, efi_status_to_str(status), status);
|
||||
// return;
|
||||
// }
|
||||
}
|
|
@ -23,32 +23,120 @@
|
|||
#include <axboot.h>
|
||||
#include <mm/mman.h>
|
||||
#include <lib/string.h>
|
||||
#include <power.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
EFI_HANDLE gImageHandle;
|
||||
EFI_SYSTEM_TABLE *gSystemTable;
|
||||
EFI_BOOT_SERVICES *gBootServices;
|
||||
|
||||
EFI_SIMPLE_POINTER_PROTOCOL *gPointerProtocol;
|
||||
uint16_t mouse_resx;
|
||||
uint16_t mouse_resy;
|
||||
|
||||
EFI_STATUS uefi_entry(EFI_HANDLE ImageHandle,
|
||||
EFI_SYSTEM_TABLE *SystemTable)
|
||||
EFI_SYSTEM_TABLE *SystemTable)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_STATUS Status;
|
||||
EFI_GUID spp_guid = EFI_SIMPLE_POINTER_PROTOCOL_GUID;
|
||||
EFI_SIMPLE_POINTER_PROTOCOL *spp[5];
|
||||
|
||||
gImageHandle = ImageHandle;
|
||||
gSystemTable = SystemTable;
|
||||
gBootServices = SystemTable->BootServices;
|
||||
gImageHandle = ImageHandle;
|
||||
gSystemTable = SystemTable;
|
||||
gBootServices = SystemTable->BootServices;
|
||||
|
||||
// clear the screen
|
||||
gSystemTable->ConOut->ClearScreen(gSystemTable->ConOut);
|
||||
// reset input
|
||||
gSystemTable->ConIn->Reset(gSystemTable->ConIn, EFI_FALSE);
|
||||
|
||||
// disable UEFI watchdog
|
||||
Status = gSystemTable->BootServices->SetWatchdogTimer(0, 0, 0, NULL);
|
||||
if (EFI_ERROR(Status)) {
|
||||
debug("Couldn't disable UEFI watchdog: %s (%x)\n", efi_status_to_str(Status), Status);
|
||||
}
|
||||
// clear the screen
|
||||
gSystemTable->ConOut->ClearScreen(gSystemTable->ConOut);
|
||||
|
||||
axboot_init();
|
||||
UNREACHABLE();
|
||||
// disable UEFI watchdog
|
||||
Status = gSystemTable->BootServices->SetWatchdogTimer(0, 0, 0, NULL);
|
||||
if (EFI_ERROR(Status)) {
|
||||
debug("uefi_entry(): Couldn't disable UEFI watchdog: %s (%x)\n", efi_status_to_str(Status), Status);
|
||||
}
|
||||
|
||||
// load that mouse up
|
||||
EFI_UINTN spp_handles = 0;
|
||||
EFI_HANDLE *spp_handle_buf = NULL;
|
||||
Status = gBootServices->LocateHandleBuffer(ByProtocol, &spp_guid, NULL, &spp_handles, &spp_handle_buf);
|
||||
if (EFI_ERROR(Status)) {
|
||||
debug("uefi_entry(): Failed to locate Simple Pointer Protocol handle buffer: %s (%x).", efi_status_to_str(Status), Status);
|
||||
} else {
|
||||
debug("uefi_entry(): Found %u handle%s\n", spp_handles, spp_handles == 1 ? "" : "s");
|
||||
for (EFI_UINTN i = 0; i < spp_handles; i++) {
|
||||
Status = gBootServices->OpenProtocol(spp_handle_buf[i], &spp_guid, (void **)&spp[i], gImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
|
||||
if (EFI_ERROR(Status)) {
|
||||
debug("uefi_entry(): Failed to open Simple Pointer Protocol on handle: %s (%x)\n", efi_status_to_str(Status), Status);
|
||||
continue;
|
||||
}
|
||||
|
||||
debug("uefi_entry(): Found SPP with ResX=%u, ResY=%u\n", spp[i]->Mode->ResolutionX, spp[i]->Mode->ResolutionY);
|
||||
if (spp[i]->Reset(spp[i], EFI_TRUE) == EFI_DEVICE_ERROR) {
|
||||
debug("uefi_entry(): Failed to reset device\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (spp[i]->Mode->ResolutionX < 65536) {
|
||||
gPointerProtocol = spp[i];
|
||||
mouse_resx = spp[i]->Mode->ResolutionX;
|
||||
mouse_resy = spp[i]->Mode->ResolutionY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
axboot_init();
|
||||
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;
|
||||
|
||||
log("uefi_exit_bs(): Calling ExitBootServices(), this will be the last log you'll see before handoff!\n");
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
Subproject commit c6a93ef5d4f6129cc579b3376d1f2990515210f9
|
||||
Subproject commit 37d4b5459f6473324b4a30b067cc013dcab7821f
|
|
@ -30,54 +30,58 @@
|
|||
static int efi_type_to_axboot(uint32_t efi_type)
|
||||
{
|
||||
switch (efi_type) {
|
||||
case EfiReservedMemoryType:
|
||||
return MemMapReserved;
|
||||
case EfiLoaderCode:
|
||||
return MemMapFirmware;
|
||||
case EfiLoaderData:
|
||||
return MemMapFirmware;
|
||||
case EfiBootServicesCode:
|
||||
case EfiBootServicesData:
|
||||
return MemMapFreeOnLoad;
|
||||
|
||||
case EfiRuntimeServicesCode:
|
||||
case EfiRuntimeServicesData:
|
||||
case EfiLoaderCode:
|
||||
return MemMapFirmware;
|
||||
case EfiConventionalMemory:
|
||||
return MemMapUsable;
|
||||
|
||||
case EfiUnusableMemory:
|
||||
return MemMapFaulty;
|
||||
|
||||
case EfiACPIReclaimMemory:
|
||||
return MemMapACPIReclaimable;
|
||||
|
||||
case EfiACPIMemoryNVS:
|
||||
return MemMapACPINVS;
|
||||
|
||||
case EfiMemoryMappedIO:
|
||||
return MemMapACPIMappedIO;
|
||||
|
||||
case EfiMemoryMappedIOPortSpace:
|
||||
return MemMapACPIMappedIOPortSpace;
|
||||
|
||||
case EfiPalCode:
|
||||
return MemMapUsable;
|
||||
case EfiPersistentMemory:
|
||||
case EfiConventionalMemory:
|
||||
return MemMapUsable;
|
||||
return MemMapUsable;
|
||||
|
||||
case EfiUnacceptedMemoryType:
|
||||
case EfiReservedMemoryType:
|
||||
return MemMapReserved;
|
||||
default:
|
||||
return MemMapReserved;
|
||||
}
|
||||
}
|
||||
|
||||
axboot_memmap *get_memmap(pagetable *pm)
|
||||
uint32_t get_memmap(axboot_memmap **map, pagetable *pm)
|
||||
{
|
||||
EFI_MEMORY_DESCRIPTOR *efi_map;
|
||||
EFI_UINTN efi_map_key;
|
||||
EFI_MEMORY_DESCRIPTOR *efi_map = NULL;
|
||||
EFI_UINTN efi_map_key = 0;
|
||||
EFI_UINTN size = 0;
|
||||
EFI_UINTN desc_size;
|
||||
EFI_UINT32 desc_ver;
|
||||
EFI_STATUS status;
|
||||
EFI_UINTN desc_size = 0;
|
||||
EFI_UINT32 desc_ver = 0;
|
||||
EFI_STATUS status = 0;
|
||||
|
||||
status = gBootServices->GetMemoryMap(&size, efi_map, &efi_map_key, &desc_size, &desc_ver);
|
||||
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);
|
||||
return NULL;
|
||||
log("get_memmap(): GetMemoryMap() returned an error: %s (0x%llx)\n", efi_status_to_str(status), status);
|
||||
return 0;
|
||||
}
|
||||
|
||||
efi_map = (EFI_MEMORY_DESCRIPTOR *)mem_alloc(size);
|
||||
|
@ -90,8 +94,8 @@ axboot_memmap *get_memmap(pagetable *pm)
|
|||
size += 2 * desc_size;
|
||||
efi_map = (EFI_MEMORY_DESCRIPTOR *)mem_realloc(efi_map, size);
|
||||
} else {
|
||||
debug("get_memmap(): GetMemoryMap() returned an error: %s (0x%llx)\n", efi_status_to_str(status), status);
|
||||
return NULL;
|
||||
log("get_memmap(): GetMemoryMap() returned an error: %s (0x%llx)\n", efi_status_to_str(status), status);
|
||||
return 0;
|
||||
}
|
||||
} while (status != EFI_SUCCESS);
|
||||
|
||||
|
@ -99,7 +103,7 @@ axboot_memmap *get_memmap(pagetable *pm)
|
|||
uint32_t entry_count = size / desc_size;
|
||||
|
||||
// map all the memory
|
||||
for (int i = 0; i < entry_count; i++) {
|
||||
for (uint32_t i = 0; i < entry_count; i++) {
|
||||
uint64_t flags;
|
||||
switch (cur_entry->Type) {
|
||||
case EfiConventionalMemory:
|
||||
|
@ -133,21 +137,19 @@ axboot_memmap *get_memmap(pagetable *pm)
|
|||
cur_entry = (EFI_MEMORY_DESCRIPTOR *)((uint8_t *)cur_entry + desc_size);
|
||||
}
|
||||
|
||||
axboot_memmap *new_map = (axboot_memmap *)mem_alloc(sizeof(axboot_memmap) * entry_count);
|
||||
memset(new_map, 0, sizeof(axboot_memmap) * entry_count);
|
||||
|
||||
cur_entry = efi_map;
|
||||
*map = mem_alloc(sizeof(axboot_memmap) * entry_count);
|
||||
memset(*map, 0, sizeof(axboot_memmap) * entry_count);
|
||||
|
||||
// translate efi memmap to axboot memmap
|
||||
for (int i = 0; i < entry_count; i++) {
|
||||
new_map[i].base = cur_entry->PhysicalStart;
|
||||
new_map[i].size = cur_entry->NumberOfPages * PAGE_SIZE;
|
||||
new_map[i].type = efi_type_to_axboot(efi_map[i].Type);
|
||||
for (uint32_t i = 0; i < entry_count; i++) {
|
||||
(*map)[i].base = cur_entry->PhysicalStart;
|
||||
(*map)[i].size = cur_entry->NumberOfPages * PAGE_SIZE;
|
||||
(*map)[i].type = efi_type_to_axboot(efi_map[i].Type);
|
||||
|
||||
cur_entry = (EFI_MEMORY_DESCRIPTOR *)((uint8_t *)cur_entry + desc_size);
|
||||
}
|
||||
|
||||
mem_free(efi_map);
|
||||
|
||||
return new_map;
|
||||
return entry_count;
|
||||
}
|
||||
|
|
75
boot/platform/uefi/power.c
Normal file
75
boot/platform/uefi/power.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: power.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 <power.h>
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
#include <axboot.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool platform_is_reboot_to_fw_possible()
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_UINT64 OsIndications;
|
||||
EFI_UINTN OsIndicationsSize = sizeof(EFI_UINT64);
|
||||
EFI_GUID GlobalVarGuid = EFI_GLOBAL_VARIABLE;
|
||||
|
||||
Status = gSystemTable->RuntimeServices->GetVariable(L"OsIndicationsSupported", &GlobalVarGuid, NULL, &OsIndicationsSize, &OsIndications);
|
||||
if (!EFI_ERROR(Status)) {
|
||||
if (OsIndications & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) {
|
||||
log("platform_is_reboot_to_fw_possible(): Boot to firmware UI is possible!\n");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
log("platform_is_reboot_to_fw_possible(): Failed to get OsIndications variable: 0x%llx (%s) \n", Status, efi_status_to_str(Status));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void platform_reboot_to_fw()
|
||||
{
|
||||
if (!platform_is_reboot_to_fw_possible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EFI_STATUS Status;
|
||||
EFI_UINT64 OsIndications = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
|
||||
EFI_UINTN OsIndicationsSize = sizeof(EFI_UINT64);
|
||||
EFI_GUID GlobalVarGuid = EFI_GLOBAL_VARIABLE;
|
||||
|
||||
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)) {
|
||||
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);
|
||||
}
|
||||
|
||||
void platform_reboot()
|
||||
{
|
||||
gSystemTable->RuntimeServices->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
|
||||
}
|
||||
|
||||
void platform_shutdown()
|
||||
{
|
||||
gSystemTable->RuntimeServices->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
|
||||
}
|
46
boot/platform/uefi/time/datetime.c
Normal file
46
boot/platform/uefi/time/datetime.c
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: datetime.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 <time/dt.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <axboot.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
void get_datetime(struct datetime *dt)
|
||||
{
|
||||
EFI_STATUS status;
|
||||
EFI_TIME uefi_dt;
|
||||
|
||||
status = gSystemTable->RuntimeServices->GetTime(&uefi_dt, NULL);
|
||||
if (EFI_ERROR(status)) {
|
||||
log("get_datetime(): Failed to acquire current time, setting to 1970/01/01 00:00:00!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
dt->year = uefi_dt.Year;
|
||||
dt->month = uefi_dt.Month;
|
||||
dt->day = uefi_dt.Day;
|
||||
dt->h = uefi_dt.Hour;
|
||||
dt->m = uefi_dt.Minute;
|
||||
dt->s = uefi_dt.Second;
|
||||
}
|
91
boot/platform/uefi/ui/framebuffer.c
Normal file
91
boot/platform/uefi/ui/framebuffer.c
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: framebuffer.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 <mm/mman.h>
|
||||
#include <ui/framebuffer.h>
|
||||
#include <print.h>
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
bool get_framebuffer(uint32_t **fb_addr, struct fb_mode **available_modes, int *total_modes, int *current_mode_index)
|
||||
{
|
||||
EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
|
||||
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info = NULL;
|
||||
EFI_UINTN mode_info_size = sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
|
||||
EFI_UINTN SizeOfInfo;
|
||||
EFI_UINTN numModes = 0;
|
||||
EFI_UINTN nativeMode = 0;
|
||||
EFI_UINTN mode_index = 0;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Status = gBootServices->LocateProtocol(&gop_guid, NULL, (void**)&gop);
|
||||
if (EFI_ERROR(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);
|
||||
// this is needed to get the current video mode
|
||||
if (Status == EFI_NOT_STARTED) {
|
||||
Status = gop->SetMode(gop, 0);
|
||||
} else if (EFI_ERROR(Status)) {
|
||||
log("Unable to get native mode\n");
|
||||
return false;
|
||||
} else {
|
||||
nativeMode = gop->Mode->Mode;
|
||||
numModes = gop->Mode->MaxMode;
|
||||
}
|
||||
|
||||
if (total_modes != NULL) {
|
||||
*total_modes = numModes;
|
||||
}
|
||||
*available_modes = (struct fb_mode *)mem_alloc(sizeof(struct fb_mode) * numModes);
|
||||
|
||||
*fb_addr = (uint32_t *)gop->Mode->FrameBufferBase;
|
||||
|
||||
// get all available modes
|
||||
for (int i = 0; i < (int)numModes; i++) {
|
||||
Status = gop->QueryMode(gop, i, &SizeOfInfo, &mode_info);
|
||||
|
||||
(*available_modes)[i].width = mode_info->HorizontalResolution;
|
||||
(*available_modes)[i].height = mode_info->VerticalResolution;
|
||||
(*available_modes)[i].bpp = 4;
|
||||
(*available_modes)[i].pitch = mode_info->PixelsPerScanLine * 4;
|
||||
|
||||
if (mode_info->PixelFormat == PixelRedGreenBlueReserved8BitPerColor) {
|
||||
(*available_modes)[i].format = FB_RGBA;
|
||||
} else if (mode_info->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
|
||||
(*available_modes)[i].format = FB_BGRA;
|
||||
} else {
|
||||
log("get_framebuffer(): Unknown framebuffer format, assuming BGRA...\n");
|
||||
(*available_modes)[i].format = FB_BGRA;
|
||||
}
|
||||
|
||||
if (i == (int)nativeMode) {
|
||||
*current_mode_index = i;
|
||||
}
|
||||
}
|
||||
|
||||
gop->QueryMode(gop, mode_index, &mode_info_size, &mode_info);
|
||||
|
||||
return true;
|
||||
}
|
39
boot/platform/uefi/ui/keyboard.c
Normal file
39
boot/platform/uefi/ui/keyboard.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: keyboard.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 <ui/keyboard.h>
|
||||
#include <stdint.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
void get_keypress(uint16_t *scancode)
|
||||
{
|
||||
EFI_INPUT_KEY key;
|
||||
if (gSystemTable->ConIn->ReadKeyStroke(gSystemTable->ConIn, &key) == EFI_SUCCESS) {
|
||||
if (key.UnicodeChar == L'\r') {
|
||||
*scancode = SCANCODE_ENTER;
|
||||
return;
|
||||
}
|
||||
*scancode = key.ScanCode;
|
||||
} else {
|
||||
*scancode = 0;
|
||||
}
|
||||
}
|
45
boot/platform/uefi/ui/mouse.c
Normal file
45
boot/platform/uefi/ui/mouse.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: mouse.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 <ui/ui.h>
|
||||
#include <ui/mouse.h>
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern EFI_SIMPLE_POINTER_PROTOCOL *gPointerProtocol;
|
||||
extern uint16_t mouse_resx;
|
||||
extern uint16_t mouse_resy;
|
||||
|
||||
void get_mouse(uint16_t *mouse_x, uint16_t *mouse_y, uint8_t *mouse_buttons)
|
||||
{
|
||||
if (!gPointerProtocol) {
|
||||
return;
|
||||
}
|
||||
|
||||
*mouse_buttons = 0;
|
||||
EFI_SIMPLE_POINTER_STATE state;
|
||||
gPointerProtocol->GetState(gPointerProtocol, &state);
|
||||
|
||||
*mouse_buttons |= state.LeftButton ? LEFT_MOUSE_BUTTON : 0;
|
||||
*mouse_buttons |= state.RightButton ? RIGHT_MOUSE_BUTTON : 0;
|
||||
|
||||
*mouse_x += state.RelativeMovementX / mouse_resx;
|
||||
*mouse_y += state.RelativeMovementY / mouse_resy;
|
||||
}
|
BIN
boot/sound/chime.mp3
Normal file
BIN
boot/sound/chime.mp3
Normal file
Binary file not shown.
1
boot/sound/license.txt
Normal file
1
boot/sound/license.txt
Normal file
|
@ -0,0 +1 @@
|
|||
AxBoot Sounds © 2025 by Jozef Nagy is licensed under CC BY-SA 4.0. To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/
|
7
boot/sound/note.txt
Normal file
7
boot/sound/note.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
1. Convert an audio file to .raw format:
|
||||
|
||||
ffmpeg -i $file -acodec pcm_s16le -f s16le -ac 2 $file.raw
|
||||
|
||||
2. Convert .raw to C header:
|
||||
|
||||
python3 utils/gen_sound_header.py $file.raw
|
|
@ -1,51 +0,0 @@
|
|||
# Soapine configuration
|
||||
To work and do what you told it to do, Soapine uses a configuration file.
|
||||
|
||||
## Location
|
||||
Soapine will search for the configuration in:
|
||||
* `(boot partition)\soapine.cfg`
|
||||
* `(boot partition)\soapine\soapine.cfg`
|
||||
* `(boot partition)\EFI\BOOT\soapine.cfg`
|
||||
* `(boot partition)\EFI\soapine.cfg`
|
||||
|
||||
If Soapine finds the config file, he parses it and jump to his usual menu. Else, Soapine will display a stop screen saying that you need to fix your configuration
|
||||
|
||||
## Accepted value types
|
||||
* String literal (`"Hello, World!"`)
|
||||
* Decimal (`2`)
|
||||
* Hexadecimal (`0x2`)
|
||||
* Hexadecimal color (`#FFFFFF`)
|
||||
* Boolean (`true/false`)
|
||||
|
||||
## Declarations
|
||||
Declarations are values that components of Soapine will search for:
|
||||
If you declare `VERBOSE` with a value of true, Soapine will itself put in verbose mode.
|
||||
|
||||
You can do a declaration by writing the name + an equal sign + the value (using the accepted value types), that will make `NAME=VALUE`.
|
||||
|
||||
If an unused declaration is provided (for example `FORCE_SOAPINE_TO_LIKE_ME=true`), Soapine will simply ignore it, but it will still be present.
|
||||
|
||||
Here are some example declarations:
|
||||
* `MENU_BRANDING="Raphaël's Custom Soapine!!"` (string literal)
|
||||
* `MENU_HEADERBAR_BG=#FFFFFF` (Hexadecimal color)
|
||||
* `MENU_HEADERBAR_MARGIN=1` (decimal)
|
||||
* `VERBOSE=true` (boolean)
|
||||
* `LOAD_ADDRESS=0x1000` (hexadecimal)
|
||||
|
||||
## Menu entries
|
||||
Menu entries allow you to show an operating system (that can be loaded with the supported protocols!) on the menu.
|
||||
They are declared like that:
|
||||
|
||||
```c
|
||||
menu_entry "Project Jupiter" {
|
||||
|
||||
};
|
||||
```
|
||||
*(yes i decided to give a C-like syntax to it)*
|
||||
|
||||
You can put a small number of declarations inside the menu entries. (PROTOCOL, IMAGE_PATH, CMDLINE, RESOLUTION) (Providing the `PROTOCOL` and `IMAGE_PATH` declarations is required for Soapine to boot your OS!)
|
||||
|
||||
## Supported declarations
|
||||
None for now (we just got the config parser working!)
|
||||
|
||||
At least, you can still define entries!
|
|
@ -1,10 +0,0 @@
|
|||
# Soapine's philosophy
|
||||
Soapine is meant to be lightweight, while being useful to everyone:
|
||||
|
||||
* Ship the bootloader with multiple features (even the weirdest features)
|
||||
* Ability to extend the bootloader with ELF extensions: If you wanna write an extension to support PE loading, ***DO IT***.
|
||||
|
||||
Soapine is also meant to be customizable:
|
||||
|
||||
* You can modify each bit of the bootloader: If you wanna center the headerbar text, you ***CAN***
|
||||
* You can change the default values in Soapine's source code.
|
17
docs/boot/TRANSLATING.md
Normal file
17
docs/boot/TRANSLATING.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Translating AxBoot
|
||||
|
||||
To translate AxBoot, copy `en_US.c` in the `common/i18n` directory and rename it (and the translation structure) to the target language code.
|
||||
Before translating each string, open `common/i18n/i18n.c` and register the new language:
|
||||
|
||||
```c
|
||||
extern struct language i18n_xxXX;
|
||||
|
||||
struct language_selection i18n_languages[] = {
|
||||
{
|
||||
"English", // Localized language name (eg. English, Čeština, Svenska, ...)
|
||||
"en_US", // Language code
|
||||
&i18n_enUS // reference to the language structure
|
||||
},
|
||||
/* ... */
|
||||
}
|
||||
```
|
|
@ -47,15 +47,12 @@ KERNEL_CFLAGS := $(foreach d, $(INCLUDE_DIRS), -I$d) \
|
|||
-fno-omit-frame-pointer \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fpic \
|
||||
-fpie \
|
||||
-MMD \
|
||||
-MP
|
||||
|
||||
KERNEL_LDFLAGS := -Tarch/$(ARCH)/linker.ld \
|
||||
-nostdlib \
|
||||
-static \
|
||||
-no-pie
|
||||
-static
|
||||
|
||||
ifeq ($(BUILD_TYPE),debug)
|
||||
KERNEL_CFLAGS += -O0 -g3
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
KERNEL_CFLAGS += -m64 \
|
||||
-march=x86-64 \
|
||||
-mabi=sysv \
|
||||
-mcmodel=kernel \
|
||||
-mno-red-zone \
|
||||
-mno-80387 \
|
||||
-mno-mmx \
|
||||
|
|
|
@ -31,8 +31,7 @@ PHDRS
|
|||
|
||||
SECTIONS
|
||||
{
|
||||
/* TODO: 0xffffffff80000000 */
|
||||
. = 0x1000;
|
||||
. = 0xffffffff80000000;
|
||||
|
||||
_linker_start_text = .;
|
||||
|
||||
|
|
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. */
|
||||
/*********************************************************************************/
|
||||
|
||||
#include <boot/aurix.h>
|
||||
#include <debug/uart.h>
|
||||
|
||||
void _start(void)
|
||||
void _start(struct aurix_parameters *params)
|
||||
{
|
||||
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");
|
||||
|
||||
for (;;) {
|
||||
|
|
|
@ -75,6 +75,7 @@ if [ "$unamestr" = 'Linux' ]; then
|
|||
exit 200
|
||||
elif [ "$unamestr" = 'Darwin' ]; then
|
||||
diskutil unmount "$tempmountdir" >/dev/null 2>&1
|
||||
diskutil unmountDisk "$loopback" >/dev/null 2>&1
|
||||
hdiutil detach "$loopback" >/dev/null 2>&1
|
||||
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=1 count=2 skip=510 seek=510 >/dev/null 2>&1
|
||||
|
||||
sync
|
||||
|
||||
printf " done.\n"
|
||||
|
|
|
@ -13,12 +13,10 @@ tempmountdir=$(mktemp -d 2>/dev/null)
|
|||
# Create UEFI image
|
||||
dd if=/dev/zero of=$uefi_image bs=1k count=1440 >/dev/null 2>&1
|
||||
mformat -i $uefi_image -f 1440 :: >/dev/null 2>&1
|
||||
mmd -i $uefi_image ::/EFI >/dev/null 2>&1
|
||||
mmd -i $uefi_image ::/EFI/BOOT >/dev/null 2>&1
|
||||
mcopy -i $uefi_image $SYSROOT_DIR/EFI/BOOT/BOOTX64.EFI ::/EFI/BOOT >/dev/null 2>&1
|
||||
## !FIXME: Huge hack! Make a filesystem.
|
||||
mmd -i $uefi_image ::/System >/dev/null 2>&1
|
||||
mcopy -i $uefi_image $SYSROOT_DIR/System/axkrnl ::/System >/dev/null 2>&1
|
||||
mcopy -i $uefi_image -s $SYSROOT_DIR/EFI :: >/dev/null 2>&1
|
||||
mcopy -i $uefi_image -s $SYSROOT_DIR/System :: >/dev/null 2>&1
|
||||
mcopy -i $uefi_image -s $SYSROOT_DIR/AxBoot :: >/dev/null 2>&1
|
||||
|
||||
# Create directory structure
|
||||
mkdir -p $tempmountdir/boot
|
||||
|
|
46
utils/bin_to_header.py
Normal file
46
utils/bin_to_header.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python3
|
||||
###################################################################################
|
||||
## Module Name: gen_sound_header.py ##
|
||||
## 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. ##
|
||||
###################################################################################
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
input_file = sys.argv[1]
|
||||
output_file = sys.argv[2]
|
||||
var_name = Path(input_file).stem
|
||||
filesize = os.path.getsize(input_file)
|
||||
raw_input = ""
|
||||
|
||||
with open(input_file, "rb") as f:
|
||||
raw_input = f.read()
|
||||
f.close()
|
||||
|
||||
with open(output_file, "w") as f:
|
||||
f.write("// THIS FILE IS AUTOMATICALLY GENERATED! DO NOT EDIT!\n\n")
|
||||
f.write("const unsigned int {var}_len = {size};\n".format(var = var_name, size = filesize))
|
||||
f.write("static const unsigned char *{var}_data = {{\n\t".format(var = var_name))
|
||||
for i in range(0, filesize):
|
||||
f.write("{bytes},".format(bytes = format(raw_input[i], '#04x')))
|
||||
if (i % 16) == 15:
|
||||
f.write("\n\t")
|
||||
else:
|
||||
f.write(" ")
|
||||
f.write("};\n")
|
||||
f.close()
|
Loading…
Add table
Add a link
Reference in a new issue