Initial import

This commit is contained in:
Jozef Nagy 2025-01-20 21:52:47 +01:00
commit 94aad4b8e1
Signed by untrusted user who does not match committer: crz
GPG key ID: 459A4811CEAC7068
77 changed files with 4414 additions and 0 deletions

49
boot/Makefile Normal file
View file

@ -0,0 +1,49 @@
###################################################################################
## Module Name: Makefile ##
## 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. ##
###################################################################################
.DEFAULT_GOAL := all
export INCLUDE_DIRS := $(BOOT_ROOT)/include
export BUILD_DIR ?= build
export SYSROOT_DIR ?= sysroot
export ASFLAGS :=
export CFLAGS := -D__$(ARCH) -D_AXBOOT -ffreestanding -fno-stack-protector -fno-stack-check -MMD -MP
export LDFLAGS := -nostdlib
export BOOT_ROOT := $(ROOT_DIR)/boot
ifeq ($(DEBUG),yes)
CFLAGS += -O0 -g3
else
CFLAGS += -O2
endif
.PHONY: all
all:
@$(MAKE) -C platform/$(PLATFORM) all
.PHONY: install
install:
@$(MAKE) -C platform/$(PLATFORM) install
.PHONY: clean
clean:
@$(MAKE) -C platform/$(PLATFORM) clean

View file

@ -0,0 +1,69 @@
/*********************************************************************************/
/* Module Name: boot.S */
/* 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. */
/*********************************************************************************/
.section ".text.boot"
.global _start
_start:
//
// hello, am i on the main core?
//
mrs x1, mpidr_el1
and x1, x1, #3
cbz x1, 2f
//
// no? alright then, sorry for interrupting. *leaves*
//
1:
wfe
b 1b
//
// ok cool now execute this huge pile of horrible code
// thanks :>
//
2:
//
// let the stack live below our code
//
ldr x1, =_start
mov sp, x1
//
// no junk allowed in .bss!
//
ldr x1, =__bss_start
ldr w2, =__bss_size
3: cbz w2, 4f
str xzr, [x1], #8
sub w2, w2, #1
cbnz w2, 3b
4:
bl menu_main
//
// crazy? i was crazy once.
// they locked me in a room. a rubber room. a rubber room with rats.
// and rats make me crazy.
// (bootloader returned, just halt the whole thing)
//
b 1b

View file

@ -0,0 +1,57 @@
/*********************************************************************************/
/* Module Name: linker.ld */
/* 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. */
/*********************************************************************************/
SECTIONS
{
. = 0x80000;
.text : {
*(.text .text.*)
*(.gnu.linkonce.t*)
}
.rodata : {
*(.rodata .rodata.*)
*(.gnu.linkonce.r*)
}
PROVIDE(_data = .);
.data : {
*(.data .data.*)
*(.gnu.linkonce.d*)
}
.bss (NOLOAD) : {
. = ALIGN(16);
__bss_start = .;
*(.bss .bss.*)
*(COMMON)
__bss_end = .;
}
_end = .;
/DISCARD/ : {
*(.comment)
*(.gnu*)
*(.note*)
*(.eh_frame*)
}
}
/*__bss_size = (__bss_end - __bss_start) >> 3;*/

View file

View file

@ -0,0 +1,80 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Module Name: boot-cd.asm ;;
;; 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. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[bits 16]
[org 0x7c00]
jmp 0x0000:AxBootEntry
times 8-($-$$) db 0
bi_PrimaryVolumeDescriptor dd 0
bi_BootFileLocation dd 0
bi_BootFileLength dd 0
bi_Checksum dd 0
bi_Reserved times 40 db 0
;;
;; BIOS bootloader on i686 is just a placeholder
;; incase it ever becomes a thing... for now it just
;; notifies the user that you can't boot AurixOS
;; without UEFI on i686.
;;
%include "arch/strings.inc"
AxBootEntry:
;;
;; Set 80x50 text mode and clear the screen
;;
mov ax, 0x03
int 0x10
xor bx, bx
mov ax, 0x1112
int 0x10
mov ah, 0
int 0x10
;;
;; Display an error message and halt
;;
mov si, sErrorUnbootable
call PrintString
mov si, sPressToReboot
call PrintString
jmp AxBootHalt
PrintString:
lodsb
or al, al
jz .done
mov ah, 0x0e
mov bx, 0x0007
int 0x10
jmp PrintString
.done:
ret
AxBootHalt:
cli
hlt
jmp AxBootHalt
times 510-($-$$) db 0
dw 0xaa55

View file

@ -0,0 +1,72 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Module Name: boot-hdd.asm ;;
;; 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. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[bits 16]
[org 0x7c00]
jmp 0x0000:AxBootEntry
;;
;; BIOS bootloader on i686 is just a placeholder
;; incase it ever becomes a thing... for now it just
;; notifies the user that you can't boot AurixOS
;; without UEFI on i686.
;;
%include "arch/strings.inc"
AxBootEntry:
;;
;; Set 80x50 text mode and clear the screen
;;
mov ax, 0x03
int 0x10
xor bx, bx
mov ax, 0x1112
int 0x10
mov ah, 0
int 0x10
;;
;; Display an error message and halt
;;
mov si, sErrorUnbootable
call PrintString
mov si, sPressToReboot
call PrintString
jmp AxBootHalt
PrintString:
lodsb
or al, al
jz .done
mov ah, 0x0e
mov bx, 0x0007
int 0x10
jmp PrintString
.done:
ret
AxBootHalt:
cli
hlt
jmp AxBootHalt
times 510-($-$$) db 0
dw 0xaa55

View file

@ -0,0 +1,21 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Module Name: strings.inc ;;
;; 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. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sErrorUnbootable: db 0x0d, 0x0a, 0x0d, 0x0a, "Error: AurixOS can only be booted via UEFI on i686!", 0x0d, 0x0a, 0
sPressToReboot: db "Press Ctrl+Alt+Del to reboot", 0

View file

View file

@ -0,0 +1,35 @@
/*********************************************************************************/
/* Module Name: gdt.c */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#include <arch/cpu/gdt.h>
#include <arch/mm/paging.h>
#include <stdint.h>
void gdt_set_entry(struct gdt_descriptor *entry, uint32_t base, uint32_t limit, uint8_t access,
uint8_t flags)
{
entry->limit_low = (limit >> 8) & 0xffff;
entry->base_low = (base >> 8) & 0xffff;
entry->base_mid = (base >> 16) & 0xff;
entry->access = access;
entry->limit_high = (limit >> 16) & 0xf;
entry->flags = flags;
entry->base_high = (base >> 24) & 0xff;
}

View file

@ -0,0 +1,60 @@
/*********************************************************************************/
/* Module Name: serial.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 <debug/serial.h>
#include <arch/cpu/cpu.h>
#include <stdint.h>
#define COM1 0x3f8
static int is_tx_empty(void)
{
return inb(COM1 + 5) & 0x20;
}
void serial_init(void)
{
// TODO: Initialize all COM ports
outb(COM1 + 1, 0x00);
outb(COM1 + 3, 0x80);
outb(COM1, 0x03);
outb(COM1 + 1, 0x00);
outb(COM1 + 3, 0x03);
outb(COM1 + 2, 0xC7);
outb(COM1 + 4, 0x0B);
outb(COM1 + 4, 0x0F);
}
void serial_send(char c)
{
while (is_tx_empty() == 0);
outb(COM1, c);
}
void serial_sendstr(char *s)
{
while (*s != '\0') {
if (*s == '\r') {
s++;
continue;
}
serial_send(*s++);
}
}

View file

@ -0,0 +1,79 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Module Name: boot-cd.asm ;;
;; 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. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[bits 16]
[org 0x7c00]
jmp 0x0000:AxBootEntry
times 8-($-$$) db 0
bi_PrimaryVolumeDescriptor dd 0
bi_BootFileLocation dd 0
bi_BootFileLength dd 0
bi_Checksum dd 0
bi_Reserved times 40 db 0
;;
;; BIOS bootloader on x86_64 is just a placeholder
;; incase it ever becomes a thing... for now it just
;; notifies the user that you can't boot AurixOS
;; without UEFI on x86_64.
;;
%include "strings.inc"
AxBootEntry:
;;
;; Set 80x50 text mode and clear the screen
;;
mov ax, 0x03
int 0x10
xor bx, bx
mov ax, 0x1112
int 0x10
mov ah, 0
int 0x10
;;
;; Display an error message and halt
;;
mov si, sErrorUnbootable
call PrintString
mov si, sPressToReboot
call PrintString
jmp AxBootHalt
PrintString:
lodsb
or al, al
jz .done
mov ah, 0x0e
mov bx, 0x0007
int 0x10
jmp PrintString
.done:
ret
AxBootHalt:
hlt
jmp AxBootHalt
times 510-($-$$) db 0
dw 0xaa55

View file

@ -0,0 +1,71 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Module Name: boot-hdd.asm ;;
;; 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. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[bits 16]
[org 0x7c00]
jmp 0x0000:AxBootEntry
;;
;; BIOS bootloader on x86_64 is just a placeholder
;; incase it ever becomes a thing... for now it just
;; notifies the user that you can't boot AurixOS
;; without UEFI on x86_64.
;;
%include "strings.inc"
AxBootEntry:
;;
;; Set 80x50 text mode and clear the screen
;;
mov ax, 0x03
int 0x10
xor bx, bx
mov ax, 0x1112
int 0x10
mov ah, 0
int 0x10
;;
;; Display an error message and halt
;;
mov si, sErrorUnbootable
call PrintString
mov si, sPressToReboot
call PrintString
jmp AxBootHalt
PrintString:
lodsb
or al, al
jz .done
mov ah, 0x0e
mov bx, 0x0007
int 0x10
jmp PrintString
.done:
ret
AxBootHalt:
hlt
jmp AxBootHalt
times 510-($-$$) db 0
dw 0xaa55

View file

@ -0,0 +1,21 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Module Name: strings.inc ;;
;; 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. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sErrorUnbootable: db 0x0d, 0x0a, 0x0d, 0x0a, "Error: AurixOS can only be booted via UEFI on x86_64!", 0x0d, 0x0a, 0
sPressToReboot: db "Press Ctrl+Alt+Del to reboot", 0

View file

12
boot/base/axboot.cfg Normal file
View file

@ -0,0 +1,12 @@
; This is a comment
entry "AurixOS" {
PROTOCOL="aurix"
IMAGE_PATH="boot:///System/axkrnl.sys"
}
;; UEFI only
entry "Windows" {
PROTOCOL="chainload"
IMAGE_PATH="boot:///EFI/Microsoft/bootmgfw.efi"
}

View file

@ -0,0 +1,78 @@
/*********************************************************************************/
/* Module Name: config.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 <firmware/file.h>
#include <lib/string.h>
#include <print.h>
#include <axboot.h>
#include <stdint.h>
#include <stddef.h>
char *config_paths[] = {
"\\axboot.cfg",
"\\System\\axboot.cfg",
"\\EFI\\axboot.cfg",
"\\EFI\\BOOT\\axboot.cfg",
};
void config_init(void)
{
FILE *config_file;
char *config_buffer;
int filesize;
for (size_t i = 0; i < ARRAY_LENGTH(config_paths); i++) {
config_file = fw_file_open(NULL, config_paths[i]);
if (config_file != NULL) {
break;
}
}
if (config_file == NULL) {
//print("No configuration file found! Please refer to the AxBoot documentation.\n");
//print("Entering console...\n\n");
//console();
}
filesize = fw_file_size(config_file);
config_buffer = malloc(filesize);
if (config_buffer == NULL) {
log("Entering console...\r\n\r\n");
//console();
}
fw_file_read(config_file, filesize, config_buffer);
// TODO: parse configuration file
free(config_buffer);
/*
if (config_errors != 0 || config_get_menu_root() == NULL) {
//print("\nConfiguration invalid!\n");
//print("Please correct your config file.\n");
//print("Entering console...\n\n");
//console();
}
*/
fw_file_close(config_file);
}

128
boot/common/lib/string.c Normal file
View file

@ -0,0 +1,128 @@
/*********************************************************************************/
/* Module Name: string.c */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#include <lib/string.h>
#include <stdint.h>
#include <stddef.h>
size_t mbstowcs(wchar_t *dest, const char **src, size_t len)
{
char *lsrc = (char *)*src;
size_t count = len;
if (dest == NULL) {
return 0;
}
while (count) {
if ((*dest = *lsrc) == 0) {
lsrc = NULL;
break;
}
if (*dest >= 0x80) {
return -1;
}
lsrc++;
dest++;
count--;
}
return len - count;
}
size_t strlen(const char *str)
{
size_t count = 0;
if (str == NULL) {
return 0;
}
do {
count++;
} while (str[count] != '\0');
return count;
}
char *strcpy(char *dest, const char *src)
{
if (dest == NULL || src == NULL) {
return NULL;
}
char *pdest = dest;
while (*src != '\0') {
*dest = *src;
dest++;
src++;
}
*dest = '\0';
return pdest;
}
void *memset(void *dest, int val, size_t len)
{
unsigned char *ptr = dest;
while (len-- > 0) {
*ptr++ = (unsigned char)val;
}
return dest;
}
void *memcpy(void *dest, void *src, size_t len)
{
char *d = (char *)dest;
const char *s = (const char *)src;
while (len-- > 0) {
*d++ = *s++;
}
return dest;
}
int memcmp(const void *a, const void *b, size_t len)
{
unsigned char *ap = (unsigned char *)a;
unsigned char *bp = (unsigned char *)b;
int ret = 0;
if (a == b) {
return 0;
}
while (len > 0) {
if (*ap != *bp) {
ret = (*ap > *bp) ? 1 : -1;
break;
}
len--;
ap++;
bp++;
}
return ret;
}

64
boot/common/print.c Normal file
View file

@ -0,0 +1,64 @@
/*********************************************************************************/
/* Module Name: print.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. */
/*********************************************************************************/
#define NANOPRINTF_IMPLEMENTATION
#define NANOPRINTF_USE_FIELD_WIDTH_FORMAT_SPECIFIERS 1
#define NANOPRINTF_USE_PRECISION_FORMAT_SPECIFIERS 1
#define NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS 1
#define NANOPRINTF_USE_LARGE_FORMAT_SPECIFIERS 1
#define NANOPRINTF_USE_BINARY_FORMAT_SPECIFIERS 0
#define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 0
#include <nanoprintf.h>
#include <debug/serial.h>
#include <print.h>
#include <stddef.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
int32_t _fltused = 0;
int32_t __eqdf2 = 0;
int32_t __ltdf2 = 0;
void log(const char *fmt, ...)
{
va_list args;
char buf[4096];
va_start(args, fmt);
npf_vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
//printstr(buf);
}
void debug(const char *fmt, ...)
{
va_list args;
char buf[4096];
va_start(args, fmt);
npf_vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
//serial_sendstr(buf);
}

View file

@ -0,0 +1,38 @@
/*********************************************************************************/
/* Module Name: paging.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 _MM_PAGING_H
#define _MM_PAGING_H
#include <firmware/memmap.h>
#include <stddef.h>
#include <stdint.h>
#define PAGE_SIZE 0x1000
int paging_init(struct memory_map_info *memmap);
void paging_identity_map(uint64_t addr);
void paging_map(uint64_t phys, uint64_t virt);
void paging_unmap(uint64_t virt);
void *paging_allocate(size_t np);
#endif /* _MM_PAGING_H */

View file

View file

View file

View file

@ -0,0 +1,116 @@
/*********************************************************************************/
/* Module Name: cpu.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _ARCH_CPU_CPU_H
#define _ARCH_CPU_CPU_H
#include <stdint.h>
////
// Utilities
///
static inline void cpu_disable_interrupts(void)
{
__asm__ volatile("cli" ::: "memory");
}
static inline uint64_t read_cr0()
{
uint64_t val;
__asm__ volatile("mov %%cr0, %0"
: "=r"(val));
return val;
}
static inline uint64_t read_cr2()
{
uint64_t val;
__asm__ volatile("mov %%cr2, %0"
: "=r"(val));
return val;
}
static inline uint64_t read_cr3()
{
uint64_t val;
__asm__ volatile("mov %%cr3, %0"
: "=r"(val));
return val;
}
static inline uint64_t read_cr4()
{
uint64_t val;
__asm__ volatile("mov %%cr4, %0"
: "=r"(val));
return val;
}
static inline uint64_t read_cr8()
{
uint64_t val;
__asm__ volatile("mov %%cr8, %0"
: "=r"(val));
return val;
}
static inline void write_cr0(uint64_t val)
{
__asm__ volatile("mov %0, %%cr0"
:: "r"(val));
}
static inline void write_cr2(uint64_t val)
{
__asm__ volatile("mov %0, %%cr2"
:: "r"(val));
}
static inline void write_cr3(uint64_t val)
{
__asm__ volatile("mov %0, %%cr3"
:: "r"(val) : "memory");
}
static inline void write_cr4(uint64_t val)
{
__asm__ volatile("mov %0, %%cr4"
:: "r"(val));
}
static inline void write_cr8(uint64_t val)
{
__asm__ volatile("mov %0, %%cr8"
:: "r"(val));
}
static inline uint8_t inb(uint16_t port)
{
uint8_t ret;
__asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory");
return ret;
}
static inline void outb(uint16_t port, uint8_t val)
{
__asm__ volatile("outb %b0, %w1" :: "a"(val), "Nd"(port) : "memory");
}
#endif /* _ARCH_CPU_CPU_H */

View file

@ -0,0 +1,67 @@
/*********************************************************************************/
/* Module Name: gdt.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _ARCH_CPU_GDT_H
#define _ARCH_CPU_GDT_H
#include <stdint.h>
struct gdt_descriptor {
uint16_t limit_low;
uint16_t base_low;
uint8_t base_mid;
uint8_t access;
uint8_t limit_high : 4;
uint8_t flags : 4;
uint8_t base_high;
} __attribute__((packed));
struct tss_descriptor {
struct gdt_descriptor gdt;
uint32_t base_high;
uint32_t reserved;
} __attribute__((packed));
struct tss {
uint32_t reserved;
uint32_t rsp0[2];
uint32_t rsp1[2];
uint32_t rsp2[2];
uint32_t reserved0[2];
uint32_t ist0[2];
uint32_t ist1[2];
uint32_t ist2[2];
uint32_t ist3[2];
uint32_t ist4[2];
uint32_t ist5[2];
uint32_t ist6[2];
uint32_t ist7[2];
uint32_t reserved1[4];
uint16_t iomap_base;
} __attribute__((packed));
struct gdtr {
uint16_t limit;
uint64_t base;
} __attribute__((packed));
void gdt_set_entry(struct gdt_descriptor *entry, uint32_t base, uint32_t limit, uint8_t access,
uint8_t flags);
#endif /* _ARCH_CPU_GDT_H */

View file

@ -0,0 +1,29 @@
/*********************************************************************************/
/* Module Name: paging.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 _MM_PAGING_H
#define _MM_PAGING_H
#include <firmware/memmap.h>
#include <stdint.h>
#define PAGE_SIZE 0x1000
#endif /* _MM_PAGING_H */

View file

32
boot/include/axboot.h Normal file
View file

@ -0,0 +1,32 @@
/*********************************************************************************/
/* Module Name: axboot.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 _AXBOOT_H
#define _AXBOOT_H
#include <utils.h>
#define BOOTLOADER_NAME_STR "AxBoot"
#define BOOTLOADER_VERSION_STR "0.1"
#ifndef UNREACHABLE
#define UNREACHABLE()
#endif
#endif /* _AXBOOT_H */

1137
boot/include/nanoprintf.h Normal file

File diff suppressed because it is too large Load diff

32
boot/include/print.h Normal file
View file

@ -0,0 +1,32 @@
/*********************************************************************************/
/* Module Name: print.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 _PRINT_H
#define _PRINT_H
#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>
void log(const char *fmt, ...);
void debug(const char *fmt, ...);
void printstr(const char *str);
#endif /* _PRINT_H */

28
boot/include/utils.h Normal file
View file

@ -0,0 +1,28 @@
/*********************************************************************************/
/* Module Name: utils.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 _UTILS_H
#define _UTILS_H
#define ARRAY_LENGTH(x) ((sizeof(x)) / (sizeof((x[0]))))
#define ROUND_DOWN(x, a) (((x)) & (~((a) - 1)))
#define ROUND_UP(x, a) ((((x)) + (a) - 1) & (~((a) - 1)))
#endif /* _UTILS_H */

View file

@ -0,0 +1,64 @@
###################################################################################
## Module Name: Makefile ##
## 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. ##
###################################################################################
ARCH_COMMON := x86
INCLUDE_DIRS += include/arch/$(ARCH)
BOOT_AS := nasm
BOOT_CC := $(ARCH)-elf-gcc
BOOT_LD := $(ARCH)-elf-ld
BOOT_ASFLAGS := $(ASFLAGS) \
$(foreach d, $(INCLUDE_DIRS), -I$d)
BOOT_CFLAGS := $(CFLAGS) \
-mno-red-zone \
-mno-stack-arg-probe
BOOT_LDFLAGS := $(LDFLAGS)
$(shell find . -type d \( -name arch -o -name platform \) -prune -name '*.c')
BOOT_ASFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH) -type d -name arch/$(ARCH)/uefi -prune -name '*.S')
BOOT_CFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH) -type d -name arch/$(ARCH)/uefi -prune -name '*.c')
BOOT_OBJ := $(BOOT_CFILES:%.c=$(BUILD_DIR)/boot/boot/%.c.o) \
$(BOOT_ASFILES:%.S=$(BUILD_DIR)/boot/boot/%.S.o) \
$(COMMON_CFILES:common/%.c=$(BUILD_DIR)/boot/boot/common/%.c.o)
# stage 1 bootloader
STAGE1_HDD := $(BUILD_DIR)/boot/pc-bios/stage1-hdd.bin
STAGE1_CD := $(BUILD_DIR)/boot/pc-bios/stage1-cd.bin
STAGE1 := $(STAGE1_HDD) $(STAGE1_CD)
.PHONY: all
all: $(STAGE1)
.PHONY: install
install:
@:
# stage 1
$(STAGE1_HDD): $(BOOT_ROOT)/arch/$(ARCH)/stage1/boot-hdd.asm
@mkdir -p $(@D)
@printf " AS\tboot/arch/$(ARCH)/stage1/stage1-hdd.bin\n"
@nasm -fbin -I$(BOOT_ROOT)/arch/$(ARCH)/stage1 $< -o $@
$(STAGE1_CD): $(BOOT_ROOT)/arch/$(ARCH)/stage1/boot-cd.asm
@mkdir -p $(@D)
@printf " AS\tboot/arch/$(ARCH)/stage1/stage1-cd.bin\n"
@nasm -fbin -I$(BOOT_ROOT)/arch/$(ARCH)/stage1 $< -o $@

View file

@ -0,0 +1,85 @@
###################################################################################
## Module Name: Makefile ##
## 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. ##
###################################################################################
BOOTFILE := $(BUILD_DIR)/boot/raspi4/axboot.elf
INCLUDE_DIRS += $(BOOT_ROOT)/include \
$(BOOT_ROOT)/include/arch/$(ARCH) \
$(BOOT_ROOT)/include/platform/$(PLATFORM)
BOOT_AS := $(ARCH)-elf-gcc
BOOT_CC := $(ARCH)-elf-gcc
BOOT_LD := $(ARCH)-elf-ld
BOOT_ASFLAGS := $(ASFLAGS) \
$(foreach d, $(INCLUDE_DIRS), -I$d)
BOOT_CFLAGS := $(CFLAGS) \
$(foreach d, $(INCLUDE_DIRS), -I$d)
BOOT_LDFLAGS := $(LDFLAGS)
COMMON_CFILES := $(shell find $(BOOT_ROOT)/common -name '*.c')
COMMON_ARCH_CFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH)/common -name '*.c')
COMMON_ARCH_ASFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH)/common -name '*.S')
PLATFORM_CFILES := $(shell find $(BOOT_ROOT)/platform/$(PLATFORM) -name '*.c')
PLATFORM_ASFILES := $(shell find $(BOOT_ROOT)/platform/$(PLATFORM) -name '*.S')
BOOT_OBJ := $(COMMON_CFILES:$(BOOT_ROOT)/common/%.c=$(BUILD_DIR)/boot/raspi4/common/%.c.o) \
$(COMMON_ARCH_CFILES:$(BOOT_ROOT)/arch/$(ARCH)/common/%.c=$(BUILD_DIR)/boot/raspi4/arch/%.c.o) \
$(COMMON_ARCH_ASFILES:$(BOOT_ROOT)/arch/$(ARCH)/common/%.S=$(BUILD_DIR)/boot/raspi4/arch/%.S.o) \
$(PLATFORM_CFILES:$(BOOT_ROOT)/platform/$(PLATFORM)/%.c=$(BUILD_DIR)/boot/raspi4/%.c.o) \
$(PLATFORM_ASFILES:$(BOOT_ROOT)/platform/$(PLATFORM)/%.S=$(BUILD_DIR)/boot/raspi4/%.S.o)
.PHONY: all
all: $(BOOTFILE)
@:
.PHONY: install
install: all
@mkdir -p $(SYSROOT_DIR)
@printf " INSTALL\t/kernel.elf\n"
@cp $(BOOTFILE) $(SYSROOT_DIR)/kernel.elf
$(BOOTFILE): $(BOOT_OBJ)
@mkdir -p $(@D)
@printf " LD\t$(notdir $@)\n"
@$(BOOT_LD) $(BOOT_LDFLAGS) $^ -o $@
-include $(wildcard $(BUILD_DIR)/boot/*.d)
$(BUILD_DIR)/boot/raspi4/%.c.o: $(BOOT_ROOT)/platform/$(PLATFORM)/%.c
@mkdir -p $(@D)
@printf " CC\t$(subst $(ROOT_DIR)/,,$<)\n"
@$(BOOT_CC) $(BOOT_CFLAGS) -c $< -o $@
$(BUILD_DIR)/boot/raspi4/common/%.c.o: $(BOOT_ROOT)/common/%.c
@mkdir -p $(@D)
@printf " CC\t$(subst $(ROOT_DIR)/,,$<)\n"
@$(BOOT_CC) $(BOOT_CFLAGS) -c $< -o $@
$(BUILD_DIR)/boot/raspi4/arch/%.c.o: $(BOOT_ROOT)/arch/$(ARCH)/common/%.c
@mkdir -p $(@D)
@printf " CC\t$(subst $(ROOT_DIR)/,,$<)\n"
@$(BOOT_CC) $(BOOT_CFLAGS) -c $< -o $@
$(BUILD_DIR)/boot/raspi4/arch/%.S.o: $(BOOT_ROOT)/arch/$(ARCH)/common/%.S
@mkdir -p $(@D)
@printf " AS\t$(subst $(ROOT_DIR)/,,$<)\n"
@$(BOOT_AS) $(BOOT_ASFLAGS) -c $< -o $@

116
boot/platform/uefi/Makefile Normal file
View file

@ -0,0 +1,116 @@
###################################################################################
## Module Name: Makefile ##
## 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. ##
###################################################################################
ifeq ($(ARCH),x86_64)
UEFISUF := X64
else ifeq ($(ARCH),i686)
UEFISUF := IA32
else ifeq ($(ARCH),arm)
UEFISUF := ARM
else ifeq ($(ARCH),aarch64)
UEFISUF := AA64
else ifeq ($(ARCH),riscv64)
UEFISUF := RISCV64
else
$(error Architecture not supported!)
endif
UEFI_BOOTFILE := $(BUILD_DIR)/boot/uefi/BOOT$(UEFISUF).EFI
INCLUDE_DIRS += $(BOOT_ROOT)/include \
$(BOOT_ROOT)/include/arch/$(ARCH) \
$(BOOT_ROOT)/include/arch/$(ARCH)/uefi \
$(BOOT_ROOT)/include/platform/$(PLATFORM) \
$(BOOT_ROOT)/platform/uefi/libefi
UEFI_AS := $(ARCH)-w64-mingw32-as
UEFI_CC := clang
UEFI_LD := clang
UEFI_ASFLAGS := $(ASFLAGS) \
-DAXBOOT_UEFI=1 \
$(foreach d, $(INCLUDE_DIRS), -I$d)
UEFI_CFLAGS := $(CFLAGS) \
-DAXBOOT_UEFI=1 \
$(foreach d, $(INCLUDE_DIRS), -I$d) \
-target $(ARCH)-unknown-windows \
-fshort-wchar \
-mno-red-zone \
-mno-stack-arg-probe
ifneq (,$(filter $(ARCH),i686 x86_64))
UEFI_CFLAGS += -mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2
endif
UEFI_LDFLAGS := $(LDFLAGS) \
-target $(ARCH)-unknown-windows \
-fuse-ld=lld-link \
-Wl,-subsystem:efi_application \
-Wl,-entry:uefi_entry
COMMON_CFILES := $(shell find $(BOOT_ROOT)/common -name '*.c')
COMMON_ARCH_CFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH)/common -name '*.c')
COMMON_ARCH_ASFILES := $(shell find $(BOOT_ROOT)/arch/$(ARCH)/common -name '*.S')
UEFI_CFILES := $(shell find $(BOOT_ROOT)/platform/uefi -name '*.c') $(shell find $(BOOT_ROOT)/arch/$(ARCH)/uefi -name '*.c')
UEFI_ASFILES := $(shell find $(BOOT_ROOT)/platform/uefi -name '*.S') $(shell find $(BOOT_ROOT)/arch/$(ARCH)/uefi -name '*.S')
UEFI_OBJ := $(UEFI_CFILES:$(BOOT_ROOT)/platform/uefi/%.c=$(BUILD_DIR)/boot/uefi/%.c.o) \
$(UEFI_ASFILES:$(BOOT_ROOT)/platform/uefi/%.S=$(BUILD_DIR)/boot/uefi/%.S.o) \
$(COMMON_CFILES:$(BOOT_ROOT)/common/%.c=$(BUILD_DIR)/boot/uefi/common/%.c.o) \
$(COMMON_ARCH_CFILES:$(BOOT_ROOT)/arch/$(ARCH)/common/%.c=$(BUILD_DIR)/boot/uefi/arch/%.c.o) \
$(COMMON_ARCH_ASFILES:$(BOOT_ROOT)/arch/$(ARCH)/common/%.asm=$(BUILD_DIR)/boot/uefi/arch/%.asm.o)
.PHONY: all
all: $(UEFI_BOOTFILE)
.PHONY: install
install:
@mkdir -p $(SYSROOT_DIR)/EFI/BOOT
@printf " INSTALL\t/EFI/BOOT/BOOT$(UEFISUF).EFI\n"
@cp $(UEFI_BOOTFILE) $(SYSROOT_DIR)/EFI/BOOT/
$(UEFI_BOOTFILE): $(UEFI_OBJ)
@mkdir -p $(@D)
@printf " LD\t$(notdir $@)\n"
@$(UEFI_LD) $(UEFI_LDFLAGS) $^ -o $@
-include $(wildcard $(BUILD_DIR)/boot/*.d)
$(BUILD_DIR)/boot/uefi/%.c.o: $(BOOT_ROOT)/platform/uefi/%.c
@mkdir -p $(@D)
@printf " CC\t$(subst $(ROOT_DIR)/,,$<)\n"
@$(UEFI_CC) $(UEFI_CFLAGS) -c $< -o $@
$(BUILD_DIR)/boot/uefi/common/%.c.o: $(BOOT_ROOT)/common/%.c
@mkdir -p $(@D)
@printf " CC\t$(subst $(ROOT_DIR)/,,$<)\n"
@$(UEFI_CC) $(UEFI_CFLAGS) -c $< -o $@
$(BUILD_DIR)/boot/uefi/arch/%.c.o: $(BOOT_ROOT)/arch/$(ARCH)/common/%.c
@mkdir -p $(@D)
@printf " CC\t$(subst $(ROOT_DIR)/,,$<)\n"
@$(UEFI_CC) $(UEFI_CFLAGS) -c $< -o $@
$(BUILD_DIR)/boot/uefi/arch/%.asm.o: $(BOOT_ROOT)/arch/$(ARCH)/common/%.asm
@mkdir -p $(@D)
@printf " AS\t$(subst $(ROOT_DIR)/,,$<)\n"
@$(UEFI_AS) $(UEFI_ASFLAGS) -c $< -o $@

View file

@ -0,0 +1,46 @@
/*********************************************************************************/
/* 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 <efi.h>
#include <efilib.h>
#include <print.h>
#include <stddef.h>
EFI_STATUS uefi_entry(EFI_HANDLE ImageHandle,
EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status;
gImageHandle = ImageHandle;
gSystemTable = SystemTable;
// clear the screen
gSystemTable->ConOut->ClearScreen(gSystemTable->ConOut);
// disable UEFI watchdog
Status = gSystemTable->BootServices->SetWatchdogTimer(0, 0, 0, NULL);
if (EFI_ERROR(Status)) {
debug("Couldn't disable UEFI watchdog!\n");
}
while(1);
return EFI_SUCCESS;
}

@ -0,0 +1 @@
Subproject commit 00ed5f5d53641d48024d8a1346edef07d1d79421

View file

@ -0,0 +1,31 @@
/*********************************************************************************/
/* Module Name: print.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 <firmware/firmware.h>
#include <lib/string.h>
#include <efi.h>
#include <efilib.h>
void printstr(const char *str)
{
CHAR16 wstr[4096];
mbstowcs(wstr, &str, strlen(str));
wstr[strlen(str)] = '\0';
gSystemTable->ConOut->OutputString(gSystemTable->ConOut, wstr);
}