Fixed merge conflict

This commit is contained in:
Jozef Nagy 2025-05-21 22:18:09 +02:00
commit 35c922d5ed
Signed by untrusted user who does not match committer: crz
GPG key ID: 459A4811CEAC7068
64 changed files with 3940 additions and 154 deletions

2
.gitmodules vendored
View file

@ -1,3 +1,3 @@
[submodule "boot/platform/uefi/libefi"] [submodule "boot/platform/uefi/libefi"]
path = boot/platform/uefi/libefi path = boot/platform/uefi/libefi
url = https://github.com/aurixos/efi url = https://git.piraterna.org/Piraterna/libsefi

View file

@ -10,6 +10,7 @@ brew "make"
brew "gptfdisk" brew "gptfdisk"
brew "xorriso" brew "xorriso"
brew "qemu" brew "qemu"
brew "ffmpeg"
brew "llvm" brew "llvm"
brew "lld" brew "lld"
brew "util-linux" if OS.mac? brew "util-linux" if OS.mac?

View file

@ -33,7 +33,7 @@ export BUILD_DIR ?= $(ROOT_DIR)/build
export SYSROOT_DIR ?= $(ROOT_DIR)/sysroot export SYSROOT_DIR ?= $(ROOT_DIR)/sysroot
export RELEASE_DIR ?= $(ROOT_DIR)/release export RELEASE_DIR ?= $(ROOT_DIR)/release
NOUEFI ?= n export NOUEFI ?= n
## ##
# Image generation and running # Image generation and running
@ -43,7 +43,16 @@ LIVECD := $(RELEASE_DIR)/aurix-$(GITREV)-livecd_$(ARCH)-$(PLATFORM).iso
LIVEHDD := $(RELEASE_DIR)/aurix-$(GITREV)-livehdd_$(ARCH)-$(PLATFORM).img LIVEHDD := $(RELEASE_DIR)/aurix-$(GITREV)-livehdd_$(ARCH)-$(PLATFORM).img
LIVESD := $(RELEASE_DIR)/aurix-$(GITREV)-livesd_$(ARCH)-$(PLATFORM).img LIVESD := $(RELEASE_DIR)/aurix-$(GITREV)-livesd_$(ARCH)-$(PLATFORM).img
QEMU_FLAGS := -m 2G -smp 4 -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
QEMU_FLAGS += -machine q35
## ##
# General info # General info
@ -75,16 +84,7 @@ all: boot kernel
.PHONY: boot .PHONY: boot
boot: boot:
@printf ">>> Building bootloader...\n" @printf ">>> Building bootloader...\n"
ifneq (,$(filter $(ARCH),i686 x86_64)) @$(MAKE) -C boot all
@$(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
.PHONY: kernel .PHONY: kernel
kernel: kernel:
@ -142,6 +142,7 @@ run-uefi: livecd ovmf
.PHONY: clean .PHONY: clean
clean: clean:
@$(MAKE) -C boot clean
@rm -rf $(BUILD_DIR) $(SYSROOT_DIR) @rm -rf $(BUILD_DIR) $(SYSROOT_DIR)
.PHONY: distclean .PHONY: distclean

1
boot/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
include/sounds

View file

@ -40,13 +40,37 @@ CFLAGS += -O2
endif endif
.PHONY: all .PHONY: all
all: all: sounds
ifneq (,$(filter $(ARCH),i686 x86_64))
@$(MAKE) -C platform/pc-bios all
else
@$(MAKE) -C platform/$(PLATFORM) all @$(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 .PHONY: install
install: install:
@$(MAKE) -C platform/$(PLATFORM) install @$(MAKE) -C platform/$(PLATFORM) install
# @$(MAKE) -C drivers install
@mkdir -p $(SYSROOT_DIR)/AxBoot
@cp -r base/* $(SYSROOT_DIR)/AxBoot
.PHONY: clean .PHONY: clean
clean: clean:
@$(MAKE) -C platform/$(PLATFORM) clean @rm -rf $(BOOT_ROOT)/include/sounds

View 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++;
}
}

View file

@ -1,12 +1,13 @@
; This is a comment ;; please leave this here, the parser breaks without it
entry "AurixOS" { default = 0
PROTOCOL="aurix" timeout = 30
IMAGE_PATH="boot:///System/axkrnl.sys" ui = text
}
;; UEFI only [AurixOS]
entry "Windows" { protocol = aurix
PROTOCOL="chainload" image = boot:///System/axkrnl.sys
IMAGE_PATH="boot:///EFI/Microsoft/bootmgfw.efi"
} [Windows 10]
protocol = efi-chainload
image = boot:///EFI/Microsoft/bootmgfw.efi

Binary file not shown.

Binary file not shown.

View file

@ -17,7 +17,10 @@
/* SOFTWARE. */ /* SOFTWARE. */
/*********************************************************************************/ /*********************************************************************************/
#include <config/config.h>
#include <config/ini.h>
#include <lib/string.h> #include <lib/string.h>
#include <loader/loader.h>
#include <mm/mman.h> #include <mm/mman.h>
#include <vfs/vfs.h> #include <vfs/vfs.h>
#include <print.h> #include <print.h>
@ -26,20 +29,51 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.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[] = { char *config_paths[] = {
"\\AxBoot\\axboot.cfg",
"\\axboot.cfg", "\\axboot.cfg",
"\\System\\axboot.cfg",
"\\EFI\\axboot.cfg", "\\EFI\\axboot.cfg",
"\\EFI\\BOOT\\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
};
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) void config_init(void)
{ {
char *config_buf; char *config_buf = NULL;
uint8_t open = 0; uint8_t open = 0;
for (size_t i = 0; i < ARRAY_LENGTH(config_paths); i++) { 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) { if (config_buf != NULL) {
open = 1; open = 1;
break; break;
@ -52,7 +86,30 @@ void config_init(void)
while (1); while (1);
} }
// TODO: parse configuration file
mem_free(config_buf); 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
View 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;
}

29
boot/common/i18n/cs_CZ.c Normal file
View 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
View 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
View 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

View file

@ -17,21 +17,50 @@
/* SOFTWARE. */ /* SOFTWARE. */
/*********************************************************************************/ /*********************************************************************************/
#include <vfs/vfs.h> #include <config/config.h>
#include <mm/mman.h> #include <loader/loader.h>
#include <mm/vmm.h>
#include <proto/aurix.h> #include <proto/aurix.h>
#include <uart/uart.h>
#include <vfs/vfs.h>
#include <ui/ui.h>
#include <axboot.h>
#include <print.h> #include <print.h>
void axboot_init() void axboot_init()
{ {
uart_init(115200);
if (!vfs_init("\\")) { if (!vfs_init("\\")) {
debug("axboot_init(): Failed to mount boot drive! Halting...\n"); debug("axboot_init(): Failed to mount boot drive! Halting...\n");
// TODO: Halt // TODO: Halt
while (1); while (1);
} }
aurix_load("\\System\\axkrnl"); #ifdef AXBOOT_UEFI
#include <driver.h>
load_drivers();
#endif
while (1); //config_init();
// boot straight away
if (config_get_timeout() < 1) {
struct axboot_entry *entries = config_get_entries();
loader_load(&(entries[config_get_default()]));
}
ui_init();
debug("axboot_init(): Returned from main menu, something went wrong. Halting!");
//UNREACHABLE();
// just boot aurixos for now
struct axboot_entry axos = {
.name = "AurixOS",
.description = "",
.image_path = "\\System\\axkrnl",
.protocol = PROTO_AURIX
};
loader_load(&axos);
UNREACHABLE();
} }

View file

@ -143,6 +143,38 @@ char *strcpy(char *dest, const char *src)
return pdest; 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 // TODO: Get rid of this function
char *strdup(const char *s) char *strdup(const char *s)
{ {

View 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)
{
debug("loader_load(): Booting \"%s\"...\n", entry->name);
switch (entry->protocol) {
case PROTO_AURIX: {
aurix_load(entry->image_path);
break;
}
default: {
debug("Entry doesn't have a supported protocol!\n");
break;
}
}
UNREACHABLE();
}

View file

@ -113,6 +113,7 @@ void *mem_alloc(size_t n)
add_alloc(alloc, n); add_alloc(alloc, n);
debug("mem_alloc(): Allocated %u bytes\n", n);
return alloc; return alloc;
} }
@ -122,7 +123,7 @@ int mem_allocat(void *addr, size_t npages)
status = gBootServices->AllocatePages(AllocateAddress, EfiLoaderData, (EFI_UINTN)npages, addr); status = gBootServices->AllocatePages(AllocateAddress, EfiLoaderData, (EFI_UINTN)npages, addr);
if (EFI_ERROR(status)) { 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; return 0;
} }
@ -137,9 +138,9 @@ void *mem_realloc(void *addr, size_t n)
void *new = NULL; void *new = NULL;
int i = find_alloc(addr); int i = find_alloc(addr);
if (i == -1) { if (i == -1 || addr == NULL) {
debug("mem_realloc(): Couldn't find allocation for 0x%lx.\n"); debug("mem_realloc(): Couldn't find allocation for 0x%lx, allocating new memory.\n");
return NULL; return mem_alloc(n);
} }
old_size = allocation_list[i].size; old_size = allocation_list[i].size;
@ -169,6 +170,8 @@ void mem_free(void *addr)
return; return;
} }
debug("mem_free(): Freed 0x%llx\n", addr);
remove_alloc(addr); remove_alloc(addr);
} }

View file

@ -19,13 +19,14 @@
#define NANOPRINTF_IMPLEMENTATION #define NANOPRINTF_IMPLEMENTATION
#define NANOPRINTF_USE_FIELD_WIDTH_FORMAT_SPECIFIERS 1 #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_FLOAT_FORMAT_SPECIFIERS 0
#define NANOPRINTF_USE_LARGE_FORMAT_SPECIFIERS 1 #define NANOPRINTF_USE_LARGE_FORMAT_SPECIFIERS 1
#define NANOPRINTF_USE_BINARY_FORMAT_SPECIFIERS 0 #define NANOPRINTF_USE_BINARY_FORMAT_SPECIFIERS 0
#define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 0 #define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 0
#include <nanoprintf.h> #include <nanoprintf.h>
#include <uart/uart.h>
#include <print.h> #include <print.h>
#include <stddef.h> #include <stddef.h>
@ -46,10 +47,7 @@ void log(const char *fmt, ...)
npf_vsnprintf(buf, sizeof(buf), fmt, args); npf_vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args); va_end(args);
// TODO: Get rid of this uart_sendstr(buf);
#ifdef AXBOOT_UEFI
printstr(buf);
#endif
} }
void debug(const char *fmt, ...) void debug(const char *fmt, ...)
@ -61,15 +59,19 @@ void debug(const char *fmt, ...)
npf_vsnprintf(buf, sizeof(buf), fmt, args); npf_vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args); va_end(args);
#ifdef AXBOOT_UEFI uart_sendstr(buf);
printstr(buf);
#endif
} }
void snprintf(char *buf, size_t size, const char *fmt, ...) void snprintf(char *buf, size_t size, const char *fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
npf_vsnprintf(buf, size, fmt, args); npf_vsnprintf(buf, size, fmt, args);
va_end(args); va_end(args);
} }
void vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
npf_vsnprintf(buf, size, fmt, args);
}

View file

@ -46,6 +46,7 @@ void aurix_load(char *kernel_path)
} }
axboot_memmap *memmap = get_memmap(pm); axboot_memmap *memmap = get_memmap(pm);
(void)memmap;
map_pages(pm, (uintptr_t)pm, (uintptr_t)pm, PAGE_SIZE, VMM_WRITABLE); map_pages(pm, (uintptr_t)pm, (uintptr_t)pm, PAGE_SIZE, VMM_WRITABLE);
map_pages(pm, (uintptr_t)_aurix_handoff_start, (uintptr_t)_aurix_handoff_start, (uint64_t)_aurix_handoff_end - (uint64_t)_aurix_handoff_start, 0); map_pages(pm, (uintptr_t)_aurix_handoff_start, (uintptr_t)_aurix_handoff_start, (uint64_t)_aurix_handoff_end - (uint64_t)_aurix_handoff_start, 0);
@ -61,11 +62,12 @@ void aurix_load(char *kernel_path)
void *kernel_entry = (void *)elf_load(kbuf, pm); void *kernel_entry = (void *)elf_load(kbuf, pm);
if (!kernel_entry) { if (!kernel_entry) {
debug("aurix_load(): Failed to load '%s'! Halting...\n", kernel_path); debug("aurix_load(): Failed to load '%s'! Halting...\n", kernel_path);
mem_free(kbuf);
while (1); while (1);
} }
// mem_free(kbuf);
void *parameters = NULL; void *parameters = NULL;
(void)parameters;
debug("aurix_load(): Handoff state: pm=0x%llx, stack=0x%llx, kernel_entry=0x%llx\n", pm, stack, kernel_entry); debug("aurix_load(): Handoff state: pm=0x%llx, stack=0x%llx, kernel_entry=0x%llx\n", pm, stack, kernel_entry);
@ -76,6 +78,6 @@ void aurix_load(char *kernel_path)
__asm__ volatile("movq %[pml4], %%cr3\n" __asm__ volatile("movq %[pml4], %%cr3\n"
"movq %[stack], %%rsp\n" "movq %[stack], %%rsp\n"
"callq *%[entry]\n" "callq *%[entry]\n"
:: [pml4]"r"(pm), [stack]"r"(stack), [entry]"r"(kernel_entry) : "memory"); :: [pml4]"r"(pm), [stack]"r"(stack + (16 * 1024)), [entry]"r"(kernel_entry) : "memory");
__builtin_unreachable(); __builtin_unreachable();
} }

91
boot/common/ui/font.c Normal file
View 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
View 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
View 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();
}
}
}

View 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 */

View file

@ -29,6 +29,9 @@
#define UNREACHABLE() __builtin_unreachable() #define UNREACHABLE() __builtin_unreachable()
#endif #endif
// TODO: This is hacky
#define axboot_halt() while (1);
void axboot_init(void); void axboot_init(void);
#endif /* _AXBOOT_H */ #endif /* _AXBOOT_H */

View file

@ -0,0 +1,52 @@
/*********************************************************************************/
/* 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;
};
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 */

86
boot/include/config/ini.h Normal file
View file

@ -0,0 +1,86 @@
/*********************************************************************************/
/* Module Name: ini.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_INI_H
#define _CONFIG_INI_H
enum token_type {
SECTION,
KEY,
VALUE,
EOF,
ILLEGAL,
};
struct string_view {
char *data;
unsigned int len;
};
struct token {
enum token_type type;
struct string_view lit;
};
struct token_array {
struct token *items;
unsigned int count;
unsigned int capacity;
};
struct lexer {
char *input;
unsigned int pos;
unsigned int read_pos;
char ch;
};
struct parser {
struct token_array *tokens;
unsigned int pos;
unsigned int read_pos;
struct token *cur_token;
};
struct key_value {
struct string_view key;
struct string_view value;
};
struct section {
struct string_view name;
struct key_value *items;
unsigned int count;
unsigned int capacity;
};
struct ini_file {
struct section root;
struct section *items;
unsigned int count;
unsigned int capacity;
};
void parse_ini(struct ini_file *ini, char *buf);
char *ini_get_value(struct ini_file *ini, char *section, char *key);
int ini_get_value_int(struct ini_file *ini, char *section, char *key);
#endif /* _CONFIG_INI_H */

41
boot/include/data/da.h Normal file
View 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
View 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 */

View file

@ -1,5 +1,5 @@
/*********************************************************************************/ /*********************************************************************************/
/* Module Name: print.c */ /* Module Name: driver.h */
/* Project: AurixOS */ /* Project: AurixOS */
/* */ /* */
/* Copyright (c) 2024-2025 Jozef Nagy */ /* Copyright (c) 2024-2025 Jozef Nagy */
@ -17,14 +17,23 @@
/* SOFTWARE. */ /* SOFTWARE. */
/*********************************************************************************/ /*********************************************************************************/
#include <lib/string.h> #ifndef _DRIVER_H
#include <efi.h> #define _DRIVER_H
#include <efilib.h>
void printstr(const char *str) #ifdef AXBOOT_UEFI
{
CHAR16 wstr[4096]; #include <stddef.h>
mbstowcs(wstr, &str, strlen(str)); #include <efi.h>
wstr[strlen(str)] = '\0';
gSystemTable->ConOut->OutputString(gSystemTable->ConOut, wstr); struct driver {
} EFI_HANDLE handle;
char *binary;
size_t binsize;
EFI_MEMMAP_DEVICE_PATH devpath[2];
};
#endif
void load_drivers();
#endif /* _DRIVER_H */

40
boot/include/i18n.h Normal file
View 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
View 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 */

View file

@ -30,6 +30,8 @@ size_t strlen(const char *str);
int strcmp(const char *s1, const char *s2); int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n); int strncmp(const char *s1, const char *s2, size_t n);
char *strcpy(char *dest, const char *src); 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 *strdup(const char *s);
char *strtok(char *str, const char *delim); char *strtok(char *str, const char *delim);
char *strchr(char *s, int c); char *strchr(char *s, int c);

View 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 */

View file

@ -20,6 +20,7 @@
#ifndef _MEM_MEMMAP_H #ifndef _MEM_MEMMAP_H
#define _MEM_MEMMAP_H #define _MEM_MEMMAP_H
#include <mm/vmm.h>
#include <stdint.h> #include <stdint.h>
enum AxBootMemMapType { enum AxBootMemMapType {
@ -45,6 +46,6 @@ typedef struct _axboot_memmap {
int type; int type;
} axboot_memmap; } axboot_memmap;
axboot_memmap *get_memmap(); axboot_memmap *get_memmap(pagetable *pm);
#endif /* _MEM_MEMMAP_H */ #endif /* _MEM_MEMMAP_H */

30
boot/include/power.h Normal file
View 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 */

View file

@ -31,5 +31,6 @@ void debug(const char *fmt, ...);
void printstr(const char *str); void printstr(const char *str);
void snprintf(char *buf, size_t size, const char *fmt, ...); 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 */ #endif /* _PRINT_H */

35
boot/include/time/dt.h Normal file
View 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
View 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
View 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 */

View 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,
FB_BGRA
};
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 */

View 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
View 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

File diff suppressed because it is too large Load diff

View 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
View 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 */

View file

@ -37,7 +37,8 @@ INCLUDE_DIRS += $(BOOT_ROOT)/include \
$(BOOT_ROOT)/include/arch/$(ARCH) \ $(BOOT_ROOT)/include/arch/$(ARCH) \
$(BOOT_ROOT)/include/arch/$(ARCH)/uefi \ $(BOOT_ROOT)/include/arch/$(ARCH)/uefi \
$(BOOT_ROOT)/include/platform/$(PLATFORM) \ $(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_AS := $(ARCH)-w64-mingw32-as
UEFI_CC := clang UEFI_CC := clang
@ -51,7 +52,10 @@ UEFI_CFLAGS := $(CFLAGS) \
-DAXBOOT_UEFI=1 \ -DAXBOOT_UEFI=1 \
$(foreach d, $(INCLUDE_DIRS), -I$d) \ $(foreach d, $(INCLUDE_DIRS), -I$d) \
-target $(ARCH)-unknown-windows \ -target $(ARCH)-unknown-windows \
-std=c11 \
-flto \
-fshort-wchar \ -fshort-wchar \
-msoft-float \
-mno-red-zone \ -mno-red-zone \
-mno-stack-arg-probe -mno-stack-arg-probe
@ -67,6 +71,7 @@ UEFI_LDFLAGS := $(LDFLAGS) \
-fuse-ld=lld-link \ -fuse-ld=lld-link \
-Wl,-subsystem:efi_application \ -Wl,-subsystem:efi_application \
-Wl,-entry:uefi_entry -Wl,-entry:uefi_entry
COMMON_CFILES := $(shell find $(BOOT_ROOT)/common -name '*.c') COMMON_CFILES := $(shell find $(BOOT_ROOT)/common -name '*.c')
COMMON_ARCH_CFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH)/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') COMMON_ARCH_ASFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH)/common -name '*.S')

View 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))) {
debug("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()) {
debug("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;
// debug("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)) {
// debug("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)) {
// debug("load_drivers(): Failed to start driver '%s': %s (%llx)\n", driver_name, efi_status_to_str(status), status);
// return;
// }
}

View file

@ -25,28 +25,72 @@
#include <lib/string.h> #include <lib/string.h>
#include <print.h> #include <print.h>
#include <stdint.h>
#include <stddef.h> #include <stddef.h>
#define INI_IMPLEMENTATION
#include <config/ini.h>
EFI_HANDLE gImageHandle; EFI_HANDLE gImageHandle;
EFI_SYSTEM_TABLE *gSystemTable; EFI_SYSTEM_TABLE *gSystemTable;
EFI_BOOT_SERVICES *gBootServices; EFI_BOOT_SERVICES *gBootServices;
EFI_SIMPLE_POINTER_PROTOCOL *gPointerProtocol;
uint16_t mouse_resx;
uint16_t mouse_resy;
EFI_STATUS uefi_entry(EFI_HANDLE ImageHandle, 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; gImageHandle = ImageHandle;
gSystemTable = SystemTable; gSystemTable = SystemTable;
gBootServices = SystemTable->BootServices; gBootServices = SystemTable->BootServices;
// reset input
gSystemTable->ConIn->Reset(gSystemTable->ConIn, EFI_FALSE);
// clear the screen // clear the screen
gSystemTable->ConOut->ClearScreen(gSystemTable->ConOut); gSystemTable->ConOut->ClearScreen(gSystemTable->ConOut);
// disable UEFI watchdog // disable UEFI watchdog
Status = gSystemTable->BootServices->SetWatchdogTimer(0, 0, 0, NULL); Status = gSystemTable->BootServices->SetWatchdogTimer(0, 0, 0, NULL);
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
debug("Couldn't disable UEFI watchdog: %s (%x)\n", efi_status_to_str(Status), 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(); axboot_init();

@ -1 +1 @@
Subproject commit c6a93ef5d4f6129cc579b3376d1f2990515210f9 Subproject commit 37d4b5459f6473324b4a30b067cc013dcab7821f

View file

@ -67,12 +67,12 @@ static int efi_type_to_axboot(uint32_t efi_type)
axboot_memmap *get_memmap(pagetable *pm) axboot_memmap *get_memmap(pagetable *pm)
{ {
EFI_MEMORY_DESCRIPTOR *efi_map; EFI_MEMORY_DESCRIPTOR *efi_map = NULL;
EFI_UINTN efi_map_key; EFI_UINTN efi_map_key = 0;
EFI_UINTN size = 0; EFI_UINTN size = 0;
EFI_UINTN desc_size; EFI_UINTN desc_size = 0;
EFI_UINT32 desc_ver; EFI_UINT32 desc_ver = 0;
EFI_STATUS status; EFI_STATUS status = 0;
status = gBootServices->GetMemoryMap(&size, efi_map, &efi_map_key, &desc_size, &desc_ver); status = gBootServices->GetMemoryMap(&size, efi_map, &efi_map_key, &desc_size, &desc_ver);
if (EFI_ERROR(status) && status != EFI_BUFFER_TOO_SMALL) { if (EFI_ERROR(status) && status != EFI_BUFFER_TOO_SMALL) {
@ -99,7 +99,7 @@ axboot_memmap *get_memmap(pagetable *pm)
uint32_t entry_count = size / desc_size; uint32_t entry_count = size / desc_size;
// map all the memory // map all the memory
for (int i = 0; i < entry_count; i++) { for (uint32_t i = 0; i < entry_count; i++) {
uint64_t flags; uint64_t flags;
switch (cur_entry->Type) { switch (cur_entry->Type) {
case EfiConventionalMemory: case EfiConventionalMemory:
@ -139,11 +139,13 @@ axboot_memmap *get_memmap(pagetable *pm)
cur_entry = efi_map; cur_entry = efi_map;
// translate efi memmap to axboot memmap // translate efi memmap to axboot memmap
for (int i = 0; i < entry_count; i++) { for (uint32_t i = 0; i < entry_count; i++) {
new_map[i].base = cur_entry->PhysicalStart; new_map[i].base = cur_entry->PhysicalStart;
new_map[i].size = cur_entry->NumberOfPages * PAGE_SIZE; new_map[i].size = cur_entry->NumberOfPages * PAGE_SIZE;
new_map[i].type = efi_type_to_axboot(efi_map[i].Type); new_map[i].type = efi_type_to_axboot(efi_map[i].Type);
debug("get_memmap(): Entry %d: base=0x%llx, size=%u bytes, type=%x\n", i, new_map[i].base, new_map[i].size, new_map[i].type);
cur_entry = (EFI_MEMORY_DESCRIPTOR *)((uint8_t *)cur_entry + desc_size); cur_entry = (EFI_MEMORY_DESCRIPTOR *)((uint8_t *)cur_entry + desc_size);
} }

View 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) {
debug("platform_is_reboot_to_fw_possible(): Boot to firmware UI is possible!\n");
return true;
}
} else {
debug("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)) {
debug("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);
}

View 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)) {
debug("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;
}

View file

@ -0,0 +1,89 @@
/*********************************************************************************/
/* 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)) {
debug("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)) {
debug("Unable to get native mode\n");
return false;
} else {
nativeMode = gop->Mode->Mode;
numModes = gop->Mode->MaxMode;
}
*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 {
debug("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;
}

View 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;
}
}

View 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

Binary file not shown.

1
boot/sound/license.txt Normal file
View 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
View 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

View file

@ -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!

View file

@ -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
View 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
},
/* ... */
}
```

View file

@ -13,12 +13,10 @@ tempmountdir=$(mktemp -d 2>/dev/null)
# Create UEFI image # Create UEFI image
dd if=/dev/zero of=$uefi_image bs=1k count=1440 >/dev/null 2>&1 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 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. ## !FIXME: Huge hack! Make a filesystem.
mmd -i $uefi_image ::/System >/dev/null 2>&1 mcopy -i $uefi_image -s $SYSROOT_DIR/EFI :: >/dev/null 2>&1
mcopy -i $uefi_image $SYSROOT_DIR/System/axkrnl ::/System >/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 # Create directory structure
mkdir -p $tempmountdir/boot mkdir -p $tempmountdir/boot

46
utils/bin_to_header.py Normal file
View 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()