did some stuff, will probably refactor later

This commit is contained in:
Jozef Nagy 2025-05-11 22:20:45 +02:00
parent 10ee4fcbd9
commit bc4ec556e2
Signed by untrusted user who does not match committer: crz
GPG key ID: 459A4811CEAC7068
46 changed files with 1013 additions and 35635 deletions

View file

@ -17,7 +17,10 @@
/* SOFTWARE. */
/*********************************************************************************/
#include <config/config.h>
#include <config/ini.h>
#include <lib/string.h>
#include <loader/loader.h>
#include <mm/mman.h>
#include <vfs/vfs.h>
#include <print.h>
@ -26,20 +29,47 @@
#include <stdint.h>
#include <stddef.h>
#define DEFAULT_ENTRY 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,
//.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)
{
char *config_buf;
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;
@ -52,7 +82,25 @@ void config_init(void)
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;
}

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

View file

@ -17,9 +17,13 @@
/* SOFTWARE. */
/*********************************************************************************/
#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()
@ -32,5 +36,20 @@ void axboot_init()
while (1);
}
ui_init();
//config_init();
//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;
}
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)
{

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);
debug("mem_alloc(): Allocated %u bytes\n", n);
return alloc;
}
@ -122,7 +123,7 @@ 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;
}
@ -137,9 +138,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;
@ -169,6 +170,8 @@ void mem_free(void *addr)
return;
}
debug("mem_free(): Freed 0x%llx\n", addr);
remove_alloc(addr);
}

View file

@ -44,13 +44,13 @@ void aurix_load(char *kernel_path)
// TODO: Halt
while (1);
}
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)_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
if (!stack) {
debug("aurix_load(): Failed to allocate stack! Halting...\n");

View file

@ -17,9 +17,62 @@
/* SOFTWARE. */
/*********************************************************************************/
#include <mm/mman.h>
// TODO: Remove this if statement once I fix stb_truetype compilation
#if 0
//#define STBTT_malloc(x,u) ((void)(u),mem_alloc(x))
//#define STBTT_free(x,u) ((void)(u),mem_free(x))
//#define STB_TRUETYPE_IMPLEMENTATION
//#include <ui/stb_truetype.h>
#include <mm/mman.h>
#include <arch/lib/math.h>
#include <lib/string.h>
#include <lib/assert.h>
#include <vfs/vfs.h>
#include <print.h>
__attribute__((used)) static volatile int _fltused = 0;
#define STB_TRUETYPE_IMPLEMENTATION
#define STBTT_ifloor(x) _ifloor(x)
#define STBTT_iceil(x) _iceil(x)
#define STBTT_sqrt(x) _sqrt(x)
#define STBTT_pow(x, y) _pow(x, y)
#define STBTT_fmod(x, y) _fmod(x, y)
#define STBTT_cos(x) _cos(x)
#define STBTT_acos(x) _acos(x)
#define STBTT_fabs(x) __builtin_fabs(x)
#define STBTT_malloc(x, u) ((void)(u), mem_alloc(x))
#define STBTT_free(x, u) ((void)(u), mem_free(x))
#define STBTT_assert(x) assert(x, #x)
#define STBTT_strlen(x) strlen(x)
#define STBTT_memcpy memcpy
#define STBTT_memset memset
#include "stb_truetype.h"
unsigned char *font_buf = NULL;
stbtt_fontinfo font_info;
float font_scale;
int font_ascent, font_descent;
int font_linegap;
int font_size;
void font_init(char *font_path, int initial_size)
{
vfs_read(font_path, &font_buf);
if (!font_buf) {
debug("Font not loaded, returning...\n");
return;
}
font_size = initial_size;
stbtt_InitFont(&font_info, &font_buf, 0);
font_scale = stbtt_ScaleForPixelHeight(&font_info, font_size);
stbtt_GetFontVMetrics(&font_info, &font_ascent, &font_descent, &font_linegap);
font_ascent *= font_scale;
font_descent *= font_scale;
}
#endif

File diff suppressed because it is too large Load diff

View file

@ -18,39 +18,39 @@
/*********************************************************************************/
#include <ui/framebuffer.h>
#include <ui/mouse.h>
#include <ui/font.h>
#include <ui/ui.h>
#include <config/config.h>
#include <print.h>
#include <stdint.h>
struct ui_config {
uintptr_t fb_addr;
struct fb_mode *fb_modes;
int total_modes;
int current_mode;
};
struct ui_config config;
void ui_init()
{
struct fb_mode *available_fb_modes = NULL;
int total_modes = 0;
int current_mode = 0;
struct ui_context ctx;
if (!get_framebuffer(&config.fb_addr, &config.fb_modes, &config.total_modes, &config.current_mode)) {
if (!get_framebuffer(&ctx.fb_addr, &ctx.fb_modes, &ctx.total_modes, &ctx.current_mode)) {
debug("Failed to acquire a framebuffer!\n");
while (1);
}
debug("Dumping framebuffer information\n");
debug("--------------------------------\n");
debug("Address: 0x%llx\n", config.fb_addr);
debug("Address: 0x%llx\n", ctx.fb_addr);
for (int i = 0; i < config.total_modes; i++) {
debug("\nMode %u:%s\n", i, (i == config.current_mode) ? " (current)" : "");
debug("Resolution: %ux%u\n", config.fb_modes[i].width, config.fb_modes[i].height);
debug("Bits Per Pixel: %u\n", config.fb_modes[i].bpp);
debug("Pitch: %u\n", config.fb_modes[i].pitch);
for (int i = 0; i < ctx.total_modes; i++) {
debug("\nMode %u:%s\n", i, (i == ctx.current_mode) ? " (current)" : "");
debug("Resolution: %ux%u\n", ctx.fb_modes[i].width, ctx.fb_modes[i].height);
debug("Bits Per Pixel: %u\n", ctx.fb_modes[i].bpp);
debug("Pitch: %u\n", ctx.fb_modes[i].pitch);
debug("Format: %s\n", ctx.fb_modes[i].format == FB_RGBA ? "RGBA" : "BGRA");
}
while(1);
}
//font_init("\\AxBoot\\fonts\\DreamOrphans.ttf", 20);
//while (1) {
//get_mouse(&m_x, &m_y, &m_but);
//debug("Mouse X = %u | Mouse Y = %u\n", m_x, m_y);
//}
}