kernel: add aarch64 architecture support

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
2025-01-10 17:26:26 +02:00
parent 07abdd9f6c
commit e6933acfb0
62 changed files with 1009 additions and 299 deletions

View File

@ -1,118 +1,137 @@
{
"configurations": [
{
"name": "Fennix x64 (Linux, GCC, debug)",
"includePath": [
"${workspaceFolder}/include",
"${workspaceFolder}/include/**"
],
"defines": [
"__debug_vscode__",
"KERNEL_NAME=\"Fennix\"",
"KERNEL_VERSION=\"1.0\"",
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
"GIT_COMMIT_SHORT=\"0000000\"",
"DEBUG=\"1\""
],
"compilerPath": "${workspaceFolder}/../tools/cross/bin/x86_64-fennix-gcc",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "gcc-x64",
"configurationProvider": "ms-vscode.makefile-tools",
"compilerArgs": [
// Compiler flags
"-fPIC",
"-fPIE",
"-pie",
"-mno-80387",
"-mno-mmx",
"-mno-3dnow",
"-mno-red-zone",
"-mno-sse",
"-mno-sse2",
"-march=x86-64",
"-pipe",
"-ffunction-sections",
"-msoft-float",
"-fno-builtin",
// C++ flags
"-fexceptions",
// Linker flags
"-fPIC",
"-fPIE",
"-pie",
"-Wl,-eDriverEntry",
"-Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment",
"-nostdlib",
"-nodefaultlibs",
"-nolibc",
"-zmax-page-size=0x1000",
"-static",
// VSCode flags
"-ffreestanding",
"-nostdinc",
"-nostdinc++"
]
},
{
"name": "Fennix x32 (Linux, GCC, debug)",
"includePath": [
"${workspaceFolder}/include/**"
],
"defines": [
"__debug_vscode__",
"KERNEL_NAME=\"Fennix\"",
"KERNEL_VERSION=\"1.0\"",
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
"GIT_COMMIT_SHORT=\"0000000\"",
"DEBUG=\"1\""
],
"compilerPath": "${workspaceFolder}/../tools/cross/bin/i386-elf-gcc",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "gcc-x86",
"configurationProvider": "ms-vscode.makefile-tools",
"compilerArgs": [
// Compiler flags
"-fPIC",
"-fPIE",
"-pie",
"-mno-80387",
"-mno-mmx",
"-mno-3dnow",
"-mno-red-zone",
"-mno-sse",
"-mno-sse2",
"-march=i386",
"-pipe",
"-ffunction-sections",
"-msoft-float",
"-fno-builtin",
// C++ flags
"-fexceptions",
// Linker flags
"-fPIC",
"-fPIE",
"-pie",
"-Wl,-eDriverEntry",
"-Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment",
"-nostdlib",
"-nodefaultlibs",
"-nolibc",
"-zmax-page-size=0x1000",
"-static",
// VSCode flags
"-ffreestanding",
"-nostdinc",
"-nostdinc++"
]
}
],
"version": 4
"configurations": [
{
"name": "Fennix x64 (Linux, GCC, debug)",
"includePath": [
"${workspaceFolder}/include",
"${workspaceFolder}/include/**"
],
"defines": [
"__debug_vscode__",
"KERNEL_NAME=\"Fennix\"",
"KERNEL_VERSION=\"1.0\"",
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
"GIT_COMMIT_SHORT=\"0000000\"",
"DEBUG=\"1\""
],
"compilerPath": "${workspaceFolder}/../tools/cross/bin/x86_64-fennix-gcc",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "gcc-x64",
"configurationProvider": "ms-vscode.makefile-tools",
"compilerArgs": [
// Compiler flags
"-fPIC",
"-fPIE",
"-pie",
"-mno-80387",
"-mno-mmx",
"-mno-3dnow",
"-mno-red-zone",
"-mno-sse",
"-mno-sse2",
"-march=x86-64",
"-pipe",
"-ffunction-sections",
"-msoft-float",
"-fno-builtin",
// C++ flags
"-fexceptions",
// Linker flags
"-fPIC",
"-fPIE",
"-pie",
"-Wl,-eDriverEntry",
"-Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment",
"-nostdlib",
"-nodefaultlibs",
"-nolibc",
"-zmax-page-size=0x1000",
"-static",
// VSCode flags
"-ffreestanding",
"-nostdinc",
"-nostdinc++"
]
},
{
"name": "Fennix x32 (Linux, GCC, debug)",
"includePath": [
"${workspaceFolder}/include/**"
],
"defines": [
"__debug_vscode__",
"KERNEL_NAME=\"Fennix\"",
"KERNEL_VERSION=\"1.0\"",
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
"GIT_COMMIT_SHORT=\"0000000\"",
"DEBUG=\"1\""
],
"compilerPath": "${workspaceFolder}/../tools/cross/bin/i386-elf-gcc",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "gcc-x86",
"configurationProvider": "ms-vscode.makefile-tools",
"compilerArgs": [
// Compiler flags
"-fPIC",
"-fPIE",
"-pie",
"-mno-80387",
"-mno-mmx",
"-mno-3dnow",
"-mno-red-zone",
"-mno-sse",
"-mno-sse2",
"-march=i386",
"-pipe",
"-ffunction-sections",
"-msoft-float",
"-fno-builtin",
// C++ flags
"-fexceptions",
// Linker flags
"-fPIC",
"-fPIE",
"-pie",
"-Wl,-eDriverEntry",
"-Wl,-static,--no-dynamic-linker,-ztext,--no-warn-rwx-segment",
"-nostdlib",
"-nodefaultlibs",
"-nolibc",
"-zmax-page-size=0x1000",
"-static",
// VSCode flags
"-ffreestanding",
"-nostdinc",
"-nostdinc++"
]
},
{
"name": "Fennix Aarch64 (Linux, GCC, debug)",
"includePath": [
"${workspaceFolder}/include",
"${workspaceFolder}/include/**"
],
"defines": [
"__debug_vscode__",
"KERNEL_NAME=\"Fennix\"",
"KERNEL_VERSION=\"1.0\"",
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
"GIT_COMMIT_SHORT=\"0000000\"",
"DEBUG=\"1\""
],
"compilerPath": "${workspaceFolder}/../tools/cross/bin/aarch64-fennix-gcc",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-arm64",
"configurationProvider": "ms-vscode.makefile-tools",
"compilerArgs": [
"-ffreestanding",
"-nostdinc",
"-nostdinc++"
]
}
],
"version": 4
}

View File

@ -47,12 +47,14 @@ build:
cp -rf ../Kernel/include/interface/* include/
mkdir -p out
make -C library build
ifneq ($(filter amd64 i386,$(OSARCH)),)
make -C audio build
make -C input build
make -C misc build
make -C network build
make -C storage build
make -C filesystem build
endif
prepare:
$(info Nothing to prepare)
@ -60,9 +62,11 @@ prepare:
clean:
rm -rf out
make -C library clean
ifneq ($(filter amd64 i386,$(OSARCH)),)
make -C audio clean
make -C input clean
make -C misc clean
make -C network clean
make -C storage clean
make -C filesystem clean
endif

View File

@ -40,6 +40,15 @@ static inline scarg syscall0(scarg syscall)
: "rcx", "r11", "memory");
#elif defined(__i386__)
#warning "i386 syscall wrapper not implemented"
#elif defined(__arm__)
#warning "arm syscall wrapper not implemented"
#elif defined(__aarch64__)
register long x8 __asm__("x8") = syscall;
register long x0 __asm__("x0");
__asm__ __volatile__("svc 0"
: "=r"(x0)
: "r"(x8)
: "memory", "cc");
#else
#error "Unsupported architecture"
#endif
@ -65,6 +74,15 @@ static inline scarg syscall1(scarg syscall, scarg arg1)
: "rcx", "r11", "memory");
#elif defined(__i386__)
#warning "i386 syscall wrapper not implemented"
#elif defined(__arm__)
#warning "arm syscall wrapper not implemented"
#elif defined(__aarch64__)
register long x8 __asm__("x8") = syscall;
register long x0 __asm__("x0") = arg1;
__asm__ __volatile__("svc 0"
: "=r"(ret)
: "r"(x8), "0"(x0)
: "memory", "cc");
#else
#error "Unsupported architecture"
#endif
@ -91,6 +109,16 @@ static inline scarg syscall2(scarg syscall, scarg arg1, scarg arg2)
: "rcx", "r11", "memory");
#elif defined(__i386__)
#warning "i386 syscall wrapper not implemented"
#elif defined(__arm__)
#warning "arm syscall wrapper not implemented"
#elif defined(__aarch64__)
register long x8 __asm__("x8") = syscall;
register long x0 __asm__("x0") = arg1;
register long x1 __asm__("x1") = arg2;
__asm__ __volatile__("svc 0"
: "=r"(ret)
: "r"(x8), "0"(x0), "r"(x1)
: "memory", "cc");
#else
#error "Unsupported architecture"
#endif
@ -118,6 +146,17 @@ static inline scarg syscall3(scarg syscall, scarg arg1, scarg arg2, scarg arg3)
: "rcx", "r11", "memory");
#elif defined(__i386__)
#warning "i386 syscall wrapper not implemented"
#elif defined(__arm__)
#warning "arm syscall wrapper not implemented"
#elif defined(__aarch64__)
register long x8 __asm__("x8") = syscall;
register long x0 __asm__("x0") = arg1;
register long x1 __asm__("x1") = arg2;
register long x2 __asm__("x2") = arg3;
__asm__ __volatile__("svc 0"
: "=r"(ret)
: "r"(x8), "0"(x0), "r"(x1), "r"(x2)
: "memory", "cc");
#else
#error "Unsupported architecture"
#endif
@ -147,6 +186,18 @@ static inline scarg syscall4(scarg syscall, scarg arg1, scarg arg2, scarg arg3,
: "rcx", "r11", "memory");
#elif defined(__i386__)
#warning "i386 syscall wrapper not implemented"
#elif defined(__arm__)
#warning "arm syscall wrapper not implemented"
#elif defined(__aarch64__)
register long x8 __asm__("x8") = syscall;
register long x0 __asm__("x0") = arg1;
register long x1 __asm__("x1") = arg2;
register long x2 __asm__("x2") = arg3;
register long x3 __asm__("x3") = arg4;
__asm__ __volatile__("svc 0"
: "=r"(ret)
: "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3)
: "memory", "cc");
#else
#error "Unsupported architecture"
#endif
@ -178,6 +229,19 @@ static inline scarg syscall5(scarg syscall, scarg arg1, scarg arg2, scarg arg3,
: "rcx", "r11", "memory");
#elif defined(__i386__)
#warning "i386 syscall wrapper not implemented"
#elif defined(__arm__)
#warning "arm syscall wrapper not implemented"
#elif defined(__aarch64__)
register long x8 __asm__("x8") = syscall;
register long x0 __asm__("x0") = arg1;
register long x1 __asm__("x1") = arg2;
register long x2 __asm__("x2") = arg3;
register long x3 __asm__("x3") = arg4;
register long x4 __asm__("x4") = arg5;
__asm__ __volatile__("svc 0"
: "=r"(ret)
: "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4)
: "memory", "cc");
#else
#error "Unsupported architecture"
#endif
@ -211,6 +275,20 @@ static inline scarg syscall6(scarg syscall, scarg arg1, scarg arg2, scarg arg3,
: "rcx", "r11", "memory");
#elif defined(__i386__)
#warning "i386 syscall wrapper not implemented"
#elif defined(__arm__)
#warning "arm syscall wrapper not implemented"
#elif defined(__aarch64__)
register long x8 __asm__("x8") = syscall;
register long x0 __asm__("x0") = arg1;
register long x1 __asm__("x1") = arg2;
register long x2 __asm__("x2") = arg3;
register long x3 __asm__("x3") = arg4;
register long x4 __asm__("x4") = arg5;
register long x5 __asm__("x5") = arg6;
__asm__ __volatile__("svc 0"
: "=r"(ret)
: "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5)
: "memory", "cc");
#else
#error "Unsupported architecture"
#endif

View File

@ -36,7 +36,15 @@ CFLAGS += -pipe -fno-builtin -fPIC
endif
CRT_CFLAGS := -fPIC -fPIE -pie -mno-red-zone -std=c++20 -I$(INCLUDE_DIR)
CRT_CFLAGS := -fPIC -fPIE -pie -std=c++20 -I$(INCLUDE_DIR)
ifeq ($(OSARCH), amd64)
CRT_CFLAGS += -mno-red-zone
else ifeq ($(OSARCH), i386)
CRT_CFLAGS += -mno-red-zone
else ifeq ($(OSARCH), aarch64)
CRT_CFLAGS +=
endif
ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fstack-usage

View File

@ -73,7 +73,11 @@ DefineFunction(void, KernelPrint, const char *format, ...)
{
__builtin_va_list args;
__builtin_va_start(args, format);
#if defined(__amd64__) || defined(__i386__)
__KernelPrint(DriverID, (long)format, (long)args);
#elif defined(__aarch64__)
__KernelPrint(DriverID, (long)format, (long)__builtin_va_arg(args, void *));
#endif
__builtin_va_end(args);
}
@ -81,7 +85,11 @@ DefineFunction(void, KernelLog, const char *format, ...)
{
__builtin_va_list args;
__builtin_va_start(args, format);
#if defined(__amd64__) || defined(__i386__)
__KernelLog(DriverID, (long)format, (long)args);
#elif defined(__aarch64__)
__KernelLog(DriverID, (long)format, (long)__builtin_va_arg(args, void *));
#endif
__builtin_va_end(args);
}