kernel: add aarch64 architecture support

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
EnderIce2 2025-01-10 17:26:26 +02:00
parent 07abdd9f6c
commit e6933acfb0
No known key found for this signature in database
GPG Key ID: 2EE20AF089811A5A
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);
}

View File

@ -158,38 +158,6 @@
"intelliSenseMode": "linux-gcc-arm64",
"configurationProvider": "ms-vscode.makefile-tools",
"compilerArgs": [
// Compiler flags
"-pipe",
"-fno-builtin",
"-msoft-float",
"-fPIC",
"-Wstack-protector",
"-fcoroutines",
// Warnings
"-Wall",
"-Wextra",
"-Wfloat-equal",
"-Wpointer-arith",
"-Wcast-align",
"-Wredundant-decls",
"-Winit-self",
"-Wswitch-default",
"-Wstrict-overflow=5",
"-Wconversion",
// C++ flags
"-fno-rtti",
"-fno-exceptions",
// Linker flags
"-T${workspaceFolder}/arch/aarch64/linker.ld",
"-fPIC",
// Debug flags
"-ggdb3",
"-O0",
"-fdiagnostics-color=always",
"-fverbose-asm",
"-fstack-usage",
"-fstack-check",
"-fsanitize=undefined",
// VSCode flags
"-ffreestanding",
"-nostdinc",

View File

@ -45,16 +45,16 @@ CFLAGS := \
-DKERNEL_VERSION='"$(KERNEL_VERSION)"' \
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"' \
-fno-pic -fno-pie -mno-red-zone -fno-builtin
-fno-pic -fno-pie -fno-builtin
ifeq ($(OSARCH), amd64)
CFLAGS += -march=core2 -mcmodel=kernel -m64
CFLAGS += -march=core2 -mcmodel=kernel -m64 -mno-red-zone
LDFLAGS += -Tarch/amd64/linker.ld
else ifeq ($(OSARCH), i386)
CFLAGS += -march=pentium -m32
CFLAGS += -march=pentium -m32 -mno-red-zone
LDFLAGS += -Tarch/i386/linker.ld
else ifeq ($(OSARCH), aarch64)
CFLAGS +=
CFLAGS += -march=armv9.4-a -mtune=cortex-a72 -mlittle-endian -mcmodel=large
LDFLAGS += -Tarch/aarch64/linker.ld
endif # OSARCH
@ -67,8 +67,8 @@ ifeq ($(DEBUG), 1)
ifeq ($(OSARCH), amd64)
CFLAGS += -fverbose-asm
endif # amd64
ifneq ($(OSARCH), aarch64)
CFLAGS += -fstack-check
ifeq ($(OSARCH), aarch64)
CFLAGS += -fstack-check -fverbose-asm
endif # aarch64
LDFLAGS += -ggdb3 -O0
ASFLAGS += -g --gstabs+ --gdwarf-5 -D

View File

@ -0,0 +1,97 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "acpi.hpp"
#include <memory.hpp>
#include <debug.h>
#include "../../kernel.h"
namespace ACPI
{
MADT::MADT(ACPI::MADTHeader *madt)
{
trace("Initializing MADT");
if (!madt)
{
error("MADT is NULL");
return;
}
CPUCores = 0;
LAPICAddress = (LAPIC *)(uintptr_t)madt->LocalControllerAddress;
for (uint8_t *ptr = (uint8_t *)(madt->Entries);
(uintptr_t)(ptr) < (uintptr_t)(madt) + madt->Header.Length;
ptr += *(ptr + 1))
{
switch (*(ptr))
{
case 0:
{
if (ptr[4] & 1)
{
lapic.push_back((LocalAPIC *)ptr);
KPrint("Local APIC %d (APIC %d) found.", lapic.back()->ACPIProcessorId, lapic.back()->APICId);
CPUCores++;
}
break;
}
case 1:
{
ioapic.push_back((MADTIOApic *)ptr);
KPrint("I/O APIC %d (Address %#lx) found.", ioapic.back()->APICID, ioapic.back()->Address);
Memory::Virtual(KernelPageTable).Map((void *)(uintptr_t)ioapic.back()->Address, (void *)(uintptr_t)ioapic.back()->Address, Memory::PTFlag::RW | Memory::PTFlag::PCD); // Make sure that the address is mapped.
break;
}
case 2:
{
iso.push_back((MADTIso *)ptr);
KPrint("ISO (IRQ:%#lx, BUS:%#lx, GSI:%#lx, %s/%s) found.",
iso.back()->IRQSource, iso.back()->BuSSource, iso.back()->GSI,
iso.back()->Flags & 0x00000004 ? "Active High" : "Active Low",
iso.back()->Flags & 0x00000100 ? "Edge Triggered" : "Level Triggered");
break;
}
case 4:
{
nmi.push_back((MADTNmi *)ptr);
KPrint("NMI %#lx (lint:%#lx) found.", nmi.back()->processor, nmi.back()->lint);
break;
}
case 5:
{
LAPICAddress = (LAPIC *)ptr;
KPrint("APIC found at %#lx", LAPICAddress);
break;
}
default:
{
KPrint("Unknown MADT entry %#lx", *(ptr));
break;
}
}
Memory::Virtual(KernelPageTable).Map((void *)LAPICAddress, (void *)LAPICAddress, Memory::PTFlag::RW | Memory::PTFlag::PCD); // I should map more than one page?
}
CPUCores--; // We start at 0 (BSP) and end at 11 (APs), so we have 12 cores.
KPrint("Total CPU cores: %d", CPUCores + 1);
}
MADT::~MADT()
{
}
}

View File

@ -24,17 +24,46 @@ namespace Memory
{
bool Virtual::Check(void *VirtualAddress, PTFlag Flag, MapType Type)
{
#warning "aarch64 not implemented"
return 0;
}
void *Virtual::GetPhysical(void *VirtualAddress)
{
#warning "aarch64 not implemented"
return nullptr;
}
Virtual::MapType Virtual::GetMapType(void *VirtualAddress)
{
#warning "aarch64 not implemented"
return MapType::NoMapType;
}
PageDirectoryEntry *Virtual::GetPDE(void *VirtualAddress, MapType Type)
{
#warning "aarch64 not implemented"
return nullptr;
}
PageTableEntry *Virtual::GetPTE(void *VirtualAddress, MapType Type)
{
#warning "aarch64 not implemented"
return nullptr;
}
void Virtual::Map(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags, MapType Type)
{
#warning "aarch64 not implemented"
}
void Virtual::Unmap(void *VirtualAddress, MapType Type)
{
#warning "aarch64 not implemented"
}
void Virtual::Remap(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags, MapType Type)
{
#warning "aarch64 not implemented"
}
}

View File

@ -19,9 +19,8 @@
#include <cpu.hpp>
extern "C" __naked __used __no_stack_protector void SystemCallHandlerStub()
extern "C" __used __no_stack_protector void SystemCallHandlerStub()
{
}
extern "C" uint64_t SystemCallsHandler(SyscallsFrame *regs);

View File

@ -0,0 +1,38 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include <signal.hpp>
#include <dumper.hpp>
#include <task.hpp>
#include <errno.h>
/* subsystem/linux/syscall.cpp */
extern int ConvertSignalToLinux(signal_t sig);
namespace Tasking
{
bool Signal::HandleSignal(CPU::SchedulerFrame *tf, void *thread)
{
#warning "aarch64 not implemented"
return false;
}
void Signal::RestoreHandleSignal(SyscallsFrame *sf, void *thread)
{
#warning "aarch64 not implemented"
}
}

View File

@ -0,0 +1,28 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
.global _sig_native_trampoline_start
_sig_native_trampoline_start:
.global _sig_native_trampoline_end
_sig_native_trampoline_end:
.global _sig_linux_trampoline_start
_sig_linux_trampoline_start:
.global _sig_linux_trampoline_end
_sig_linux_trampoline_end:

View File

@ -194,10 +194,14 @@ namespace ACPI
if (FADT)
{
#if defined(__amd64__) || defined(__i386__)
outb(s_cst(uint16_t, FADT->SMI_CommandPort), FADT->AcpiEnable);
/* TODO: Sleep for ~5 seconds before polling PM1a CB? */
while (!(inw(s_cst(uint16_t, FADT->PM1aControlBlock)) & 1))
CPU::Pause();
#elif defined(__aarch64__)
warn("aarch64 is not supported yet");
#endif
}
}

View File

@ -53,7 +53,7 @@ namespace CPU
memcpy(Vendor + 4, &edx, 4);
memcpy(Vendor + 8, &ecx, 4);
#elif defined(__aarch64__)
#error "Not implemented"
#warning "aarch64 not implemented"
#endif
return Vendor;
}
@ -98,7 +98,7 @@ namespace CPU
memcpy(Name + 40, &ecx, 4);
memcpy(Name + 44, &edx, 4);
#elif defined(__aarch64__)
#error "Not implemented"
#warning "aarch64 not implemented"
#endif
return Name;
}
@ -141,7 +141,7 @@ namespace CPU
memcpy(Hypervisor + 4, &ecx, 4);
memcpy(Hypervisor + 8, &edx, 4);
#elif defined(__aarch64__)
#error "Not implemented"
#warning "aarch64 not implemented"
#endif
return Hypervisor;
}
@ -164,9 +164,8 @@ namespace CPU
: "=r"(Flags));
return Flags & (1 << 9);
#elif defined(__aarch64__)
asmv("mrs %0, cpsr"
: "=r"(Flags));
return Flags & (1 << 7);
#warning "aarch64 not implemented"
return 0;
#endif
}
case Enable:
@ -174,7 +173,7 @@ namespace CPU
#if defined(__amd64__) || defined(__i386__)
asmv("sti");
#elif defined(__aarch64__)
asmv("cpsie i");
#warning "aarch64 not implemented"
#endif
return true;
}
@ -183,7 +182,7 @@ namespace CPU
#if defined(__amd64__) || defined(__i386__)
asmv("cli");
#elif defined(__aarch64__)
asmv("cpsid i");
#warning "aarch64 not implemented"
#endif
return true;
}
@ -225,10 +224,7 @@ namespace CPU
if (PT)
{
asmv("msr ttbr0_el1, %0"
:
: "r"(PT)
: "memory");
#warning "aarch64 not implemented"
}
#endif
return ret;
@ -275,6 +271,7 @@ namespace CPU
void InitializeFeatures(int Core)
{
#if defined(__amd64__) || defined(__i386__)
static int BSP = 0;
SupportedFeat feat = GetCPUFeat();
@ -386,6 +383,7 @@ namespace CPU
SSEEnabled = true;
debug("SSE support enabled.");
}
#endif
}
uint64_t Counter()
@ -399,8 +397,8 @@ namespace CPU
"=d"(edx));
Counter = ((uint64_t)eax) | (((uint64_t)edx) << 32);
#elif defined(__aarch64__)
asmv("mrs %0, cntvct_el0"
: "=r"(Counter));
#warning "aarch64 not implemented"
Counter = 0;
#endif
return Counter;
}

View File

@ -76,17 +76,15 @@ namespace v0
cs = Flags & (1 << 9);
asmv("cli");
#elif defined(__arm__) || defined(__aarch64__)
return cs;
uintptr_t Flags;
asmv("mrs %0, cpsr"
: "=r"(Flags));
cs = Flags & (1 << 7);
asmv("cpsid i");
#elif defined(__aarch64__)
stub;
return 0;
#endif
return cs;
}
void LeaveCriticalSection(dev_t DriverID, CriticalState PreviousState)
@ -101,7 +99,7 @@ namespace v0
#elif defined(__arm__) || defined(__aarch64__)
if (PreviousState)
asmv("cpsie i");
stub;
#endif
}
@ -284,15 +282,18 @@ namespace v0
{
dbg_api("%d, %d", DriverID, IRQ);
#if defined(__amd64__) || defined(__i386__)
if (IRQ >= 8)
outb(PIC2_CMD, _PIC_EOI);
outb(PIC1_CMD, _PIC_EOI);
#endif
}
void IRQ_MASK(dev_t DriverID, uint8_t IRQ)
{
dbg_api("%d, %d", DriverID, IRQ);
#if defined(__amd64__) || defined(__i386__)
uint16_t port;
uint8_t value;
@ -306,12 +307,14 @@ namespace v0
value = inb(port) | (1 << IRQ);
outb(port, value);
#endif
}
void IRQ_UNMASK(dev_t DriverID, uint8_t IRQ)
{
dbg_api("%d, %d", DriverID, IRQ);
#if defined(__amd64__) || defined(__i386__)
uint16_t port;
uint8_t value;
@ -325,12 +328,14 @@ namespace v0
value = inb(port) & ~(1 << IRQ);
outb(port, value);
#endif
}
void PS2Wait(dev_t DriverID, const bool Output)
{
dbg_api("%d, %d", DriverID, Output);
#if defined(__amd64__) || defined(__i386__)
int Timeout = 100000;
PS2_STATUSES Status = {.Raw = inb(PS2_STATUS)};
while (Timeout--)
@ -349,38 +354,51 @@ namespace v0
}
warn("PS/2 controller timeout! (Status: %#x, %d)", Status, Output);
#endif
}
void PS2WriteCommand(dev_t DriverID, uint8_t Command)
{
dbg_api("%d, %d", DriverID, Command);
#if defined(__amd64__) || defined(__i386__)
WaitInput;
outb(PS2_CMD, Command);
#endif
}
void PS2WriteData(dev_t DriverID, uint8_t Data)
{
dbg_api("%d, %d", DriverID, Data);
#if defined(__amd64__) || defined(__i386__)
WaitInput;
outb(PS2_DATA, Data);
#endif
}
uint8_t PS2ReadData(dev_t DriverID)
{
dbg_api("%d", DriverID);
#if defined(__amd64__) || defined(__i386__)
WaitOutput;
return inb(PS2_DATA);
#elif defined(__aarch64__)
return 0;
#endif
}
uint8_t PS2ReadStatus(dev_t DriverID)
{
dbg_api("%d", DriverID);
#if defined(__amd64__) || defined(__i386__)
WaitOutput;
return inb(PS2_STATUS);
#elif defined(__aarch64__)
return 0;
#endif
}
uint8_t PS2ReadAfterACK(dev_t DriverID)
@ -388,11 +406,13 @@ namespace v0
dbg_api("%d", DriverID);
uint8_t ret = PS2ReadData(DriverID);
#if defined(__amd64__) || defined(__i386__)
while (ret == PS2_ACK)
{
WaitOutput;
ret = inb(PS2_DATA);
}
#endif
return ret;
}
@ -400,6 +420,7 @@ namespace v0
{
dbg_api("%d", DriverID);
#if defined(__amd64__) || defined(__i386__)
PS2_STATUSES Status;
int timeout = 0x500;
while (timeout--)
@ -409,6 +430,7 @@ namespace v0
return;
inb(PS2_DATA);
}
#endif
}
int PS2ACKTimeout(dev_t DriverID)

View File

@ -61,6 +61,7 @@ namespace ACPI
debug("SCI Handle Triggered");
uint16_t Event = 0;
{
#if defined(__amd64__) || defined(__i386__)
uint16_t a = 0, b = 0;
if (acpi->FADT->PM1aEventBlock)
{
@ -73,6 +74,7 @@ namespace ACPI
outw(s_cst(uint16_t, acpi->FADT->PM1bEventBlock), b);
}
Event = a | b;
#endif
}
#ifdef DEBUG
@ -161,6 +163,7 @@ namespace ACPI
return;
}
#if defined(__amd64__) || defined(__i386__)
if (inw(s_cst(uint16_t, PM1a_CNT) & SCI_EN) == 0)
{
KPrint("ACPI was disabled, enabling...");
@ -195,6 +198,9 @@ namespace ACPI
outw(s_cst(uint16_t, PM1a_CNT), SLP_TYPa | SLP_EN);
if (PM1b_CNT)
outw(s_cst(uint16_t, PM1b_CNT), SLP_TYPb | SLP_EN);
#elif defined(__aarch64__)
warn("ACPI Shutdown not supported");
#endif
}
void DSDT::Reboot()
@ -209,7 +215,11 @@ namespace ACPI
}
case ACPI_GAS_IO:
{
#if defined(__amd64__) || defined(__i386__)
outb(s_cst(uint16_t, acpi->FADT->ResetReg.Address), acpi->FADT->ResetValue);
#elif defined(__aarch64__)
warn("ACPI_GAS_IO not supported");
#endif
break;
}
case ACPI_GAS_PCI:
@ -294,6 +304,7 @@ namespace ACPI
KPrint("ACPI Shutdown is supported");
ACPIShutdownSupported = true;
#if defined(__amd64__) || defined(__i386__)
{
const uint16_t value = /*ACPI_TIMER |*/ ACPI_BUSMASTER | ACPI_GLOBAL |
ACPI_POWER_BUTTON | ACPI_SLEEP_BUTTON | ACPI_RTC_ALARM |
@ -322,6 +333,7 @@ namespace ACPI
}
((APIC::APIC *)Interrupts::apic[0])->RedirectIRQ(0, uint8_t(acpi->FADT->SCI_Interrupt), 1);
#endif
return;
}
warn("Failed to parse _S5_ in ACPI");

View File

@ -110,6 +110,8 @@ namespace Interrupts
/* APIC::APIC */ void *apic[MAX_CPU] = {nullptr};
/* APIC::Timer */ void *apicTimer[MAX_CPU] = {nullptr};
#elif defined(__aarch64__)
/* APIC::APIC */ void *apic[MAX_CPU] = {nullptr};
/* APIC::Timer */ void *apicTimer[MAX_CPU] = {nullptr};
#endif
void Initialize(int Core)
@ -264,6 +266,7 @@ namespace Interrupts
nsa inline void ReturnFromInterrupt()
{
#if defined(__amd64__) || defined(__i386__)
CPUData *CoreData = GetCurrentCPU();
int Core = CoreData->ID;
@ -299,8 +302,9 @@ namespace Interrupts
}
else
fixme("APIC not found for core %d", Core);
// TODO: Handle PIC too
// TODO: Handle PIC too
#endif
assert(!"EOI not handled.");
CPU::Stop();
}
@ -317,24 +321,23 @@ namespace Interrupts
{
#if defined(__amd64__) || defined(__i386__)
asmv("mov %%cr3, %0" : "=r"(Original));
#endif
if (likely(Original == KernelPageTable))
return;
#if defined(__amd64__) || defined(__i386__)
asmv("mov %0, %%cr3" : : "r"(KernelPageTable));
#endif
}
~AutoSwitchPageTable()
{
#if defined(__amd64__) || defined(__i386__)
if (likely(Original == KernelPageTable))
return;
#if defined(__amd64__) || defined(__i386__)
asmv("mov %0, %%cr3" : : "r"(Original));
#endif
}
} SwitchPageTable;
#if defined(__amd64__) || defined(__i386__)
CPU::TrapFrame *Frame = (CPU::TrapFrame *)Data;
// debug("IRQ%ld", Frame->InterruptNumber - 32);
@ -378,10 +381,12 @@ namespace Interrupts
}
ReturnFromInterrupt();
#endif
}
extern "C" nsa void SchedulerInterruptHandler(void *Data)
{
#if defined(__amd64__) || defined(__i386__)
KernelPageTable->Update();
CPU::SchedulerFrame *Frame = (CPU::SchedulerFrame *)Data;
#if defined(__amd64__) || defined(__i386__)
@ -411,6 +416,7 @@ namespace Interrupts
Handler *hnd = (Handler *)it->Data;
hnd->OnInterruptReceived(Frame);
ReturnFromInterrupt();
#endif
}
Handler::Handler(int InterruptNumber, bool Critical)
@ -469,11 +475,15 @@ namespace Interrupts
void Handler::OnInterruptReceived(CPU::TrapFrame *Frame)
{
#if defined(__amd64__) || defined(__i386__)
debug("Unhandled interrupt %d", Frame->InterruptNumber);
#endif
}
void Handler::OnInterruptReceived(CPU::SchedulerFrame *Frame)
{
#if defined(__amd64__) || defined(__i386__)
debug("Unhandled scheduler interrupt %d", Frame->InterruptNumber);
#endif
}
}

View File

@ -194,6 +194,7 @@ namespace Memory
bool VirtualMemoryArea::HandleCoW(uintptr_t PFA)
{
func("%#lx", PFA);
#if defined(__amd64__) || defined(__i386__)
Virtual vmm(this->Table);
PageTableEntry *pte = vmm.GetPTE((void *)PFA);
@ -252,6 +253,9 @@ namespace Memory
}
}
#else
#warning "Not implemented"
#endif
debug("%#lx not found in CoW regions", PFA);
return false;
}
@ -325,7 +329,7 @@ namespace Memory
this->Map(AddressToMap, RealAddress, PAGE_SIZE, Flags);
MgrLock.Lock(__FUNCTION__);
#else
#error "Not implemented"
#warning "Not implemented"
#endif
}

View File

@ -185,8 +185,10 @@ nsa __noreturn void HandleUnrecoverableException(CPU::ExceptionFrame *Frame)
CPU::Pause();
ExPrint("\x1b[0m-----------------------------------------------\n");
#if defined(__amd64__) || defined(__i386__)
ExPrint("\x1b[30;41mUnrecoverable exception %#lx on CPU %d\n",
Frame->InterruptNumber, core->ID);
#endif
#if defined(__amd64__) || defined(__i386__)
ExPrint("CR0=%#lx CR2=%#lx CR3=%#lx CR4=%#lx CR8=%#lx\n",
Frame->cr0, Frame->cr2, Frame->cr3, Frame->cr4, Frame->cr8);
@ -222,7 +224,9 @@ nsa __noreturn void HandleUnrecoverableException(CPU::ExceptionFrame *Frame)
#endif /* a86 */
Display->UpdateBuffer();
#if defined(__amd64__) || defined(__i386__)
error("Unrecoverable Exception: %#lx", Frame->InterruptNumber);
#endif
UnrecoverableLock.store(false, std::memory_order_release);
CPU::Stop();
@ -231,6 +235,7 @@ nsa __noreturn void HandleUnrecoverableException(CPU::ExceptionFrame *Frame)
nsa __noreturn void HandleExceptionInsideException(CPU::ExceptionFrame *Frame)
{
ExPrint("\x1b[0m-----------------------------------------------\n");
#if defined(__amd64__) || defined(__i386__)
ExPrint("Exception inside exception: %#lx at %#lx\n",
Frame->InterruptNumber,
#if defined(__amd64__)
@ -240,6 +245,7 @@ nsa __noreturn void HandleExceptionInsideException(CPU::ExceptionFrame *Frame)
#elif defined(__aarch64__)
Frame->pc);
#endif
#endif // __amd64__ || __i386__
#if defined(__amd64__) || defined(__i386__)
ExPrint("CR0=%#lx CR2=%#lx CR3=%#lx CR4=%#lx CR8=%#lx\n",
Frame->cr0, Frame->cr2, Frame->cr3, Frame->cr4, Frame->cr8);
@ -286,6 +292,8 @@ nsa void HandleException(CPU::ExceptionFrame *Frame)
CPU::PageTable(KernelPageTable);
InitFont();
#if defined(__amd64__) || defined(__i386__)
/* First check the exception */
if (unlikely(Frame->InterruptNumber == CPU::x86::DoubleFault))
{
@ -343,6 +351,7 @@ nsa void HandleException(CPU::ExceptionFrame *Frame)
ExceptionExit:
ExceptionLock.store(false, std::memory_order_release);
#endif
}
nsa void BaseBufferStackError(bool Stack)

View File

@ -65,7 +65,9 @@ __no_sanitize("undefined") nsa bool CrashUHCIKeyboardDriver::Initialize()
/* FIXME: stub */
debug("Initializing controller");
#if defined(__amd64__) || defined(__i386__)
outw((uint16_t)((uintptr_t)io + 0xC0), 0x8F00); /* Disable Legacy Mode Support */
#endif
/* Disable All Interrupts */
io->USBINTR.TOCRC = 0;

View File

@ -137,9 +137,7 @@ nsa const char *ExGetKSymbol(CPU::ExceptionFrame *Frame)
Frame->eip > (uintptr_t)&_kernel_end)
return "<OUTSIDE KERNEL>";
#elif defined(__aarch64__)
if (Frame->pc < (uintptr_t)&_kernel_start &&
Frame->pc > (uintptr_t)&_kernel_end)
return "<OUTSIDE KERNEL>";
#warning "aarch64 not implemented"
#endif
#if defined(__amd64__)
@ -147,7 +145,8 @@ nsa const char *ExGetKSymbol(CPU::ExceptionFrame *Frame)
#elif defined(__i386__)
return ExGetKSymbolByAddress(Frame->eip);
#elif defined(__aarch64__)
return ExGetKSymbolByAddress(Frame->pc);
#warning "aarch64 not implemented"
return "stub";
#endif
}
@ -302,9 +301,16 @@ nsa void DisplayMainScreen(CPU::ExceptionFrame *Frame)
x86Exceptions[Frame->InterruptNumber].Name,
x86Exceptions[Frame->InterruptNumber].Mnemonic,
#elif defined(__aarch64__)
#error "AA64 not implemented"
"stub",
"stub",
#warning "aarch64 not implemented"
#endif
#if defined(__amd64__) || defined(__i386__)
Frame->InterruptNumber);
#elif defined(__aarch64__)
0);
#warning "aarch64 not implemented"
#endif
#if defined(__amd64__) || defined(__i386__)
ExPrint("Cause: %s\n", x86Exceptions[Frame->InterruptNumber].Cause);
#endif
@ -315,7 +321,8 @@ nsa void DisplayMainScreen(CPU::ExceptionFrame *Frame)
#elif defined(__i386__)
Frame->eip);
#elif defined(__aarch64__)
Frame->pc);
0);
#warning "aarch64 not implemented"
#endif
CPUData *core = GetCurrentCPU();
@ -342,7 +349,7 @@ arch void DisplayDetailsScreen(CPU::ExceptionFrame *Frame);
nsa void DisplayStackScreen(CPU::ExceptionFrame *Frame)
{
Memory::Virtual vmm;
struct StackFrame *sf;
struct StackFrame *sf = nullptr;
#if defined(__amd64__)
sf = (struct StackFrame *)Frame->rbp;
#elif defined(__i386__)
@ -353,6 +360,7 @@ nsa void DisplayStackScreen(CPU::ExceptionFrame *Frame)
if (!vmm.Check(sf))
{
#if defined(__amd64__) || defined(__i386__)
void *ptr = ((Memory::PageTable *)Frame->cr3)->Get(sf);
debug("Virtual pointer %#lx -> %#lx", sf, ptr);
if (vmm.Check(ptr))
@ -362,17 +370,18 @@ nsa void DisplayStackScreen(CPU::ExceptionFrame *Frame)
ExPrint("\x1b[31m< No stack trace available. >\x1b[0m\n");
return;
}
#endif
}
/* FIXME: Get symbol offset more efficiently */
uintptr_t fIP;
uintptr_t fIP = 0;
#if defined(__amd64__)
fIP = Frame->rip;
#elif defined(__i386__)
fIP = Frame->eip;
#elif defined(__aarch64__)
fIP = Frame->pc;
#warning "aarch64 not implemented"
#endif
ExPrint("%p", (void *)fIP);
@ -557,6 +566,7 @@ nsa void DisplayCrashScreen(CPU::ExceptionFrame *Frame)
DisplayBottomOverlay();
#ifdef DEBUG
#if defined(__amd64__) || defined(__i386__)
static int once = 0;
static uint8_t com4 = 0xFF;
if (!once++)
@ -657,6 +667,7 @@ nsa void DisplayCrashScreen(CPU::ExceptionFrame *Frame)
ExPrint(keyBuf);
}
#endif
#endif // DEBUG
debug("cpu halted");
CPU::Halt(true);
}
@ -965,8 +976,10 @@ nsa void UserInput(char *Input)
#ifdef DEBUG
else if (strcmp(Input, "pt") == 0)
{
/* Helpful for qemu "info tlb" command */
/* Helpful for qemu "info tlb" command */
#if defined(__amd64__) || defined(__i386__)
CPU::PageTable((void *)ExFrame->cr3);
#endif
ExPrint("Here be dragons\n");
}
else if (strcmp(Input, "ps") == 0)

View File

@ -86,6 +86,7 @@ nsa bool UserModeExceptionHandler(CPU::ExceptionFrame *Frame)
#endif
int sigRet = -1;
#if defined(__amd64__) || defined(__i386__)
switch (Frame->InterruptNumber)
{
case CPU::x86::PageFault:
@ -153,6 +154,7 @@ nsa bool UserModeExceptionHandler(CPU::ExceptionFrame *Frame)
break;
}
}
#endif
if (sigRet == 0)
{

View File

@ -32,6 +32,7 @@ namespace Power
if (((ACPI::DSDT *)this->dsdt)->ACPIShutdownSupported)
((ACPI::DSDT *)this->dsdt)->Reboot();
#if defined(__amd64__) || defined(__i386__)
asmv("cli");
uint8_t temp;
do
@ -41,6 +42,9 @@ namespace Power
inb(0x60);
} while (((temp) & (1 << (1))) != 0);
outb(0x64, 0xFE);
#elif defined(__aarch64__)
warn("aarch64 is not supported yet");
#endif
}
void Power::Shutdown()
@ -55,9 +59,11 @@ namespace Power
}
/* FIXME: Detect emulators and use their shutdown methods */
#ifdef DEBUG
#if defined(__amd64__) || defined(__i386__)
outl(0xB004, 0x2000); // for qemu
outl(0x604, 0x2000); // if qemu not working, bochs and older versions of qemu
outl(0x4004, 0x3400); // virtual box
#endif
#endif
}

View File

@ -67,8 +67,7 @@ EXTERNC __noreturn __no_stack_protector void __stack_chk_fail(void)
asmv("movl %%esp, %0"
: "=r"(Stack));
#elif defined(__aarch64__)
asmv("mov %%sp, %0"
: "=r"(Stack));
#warning "aarch64 not implemented"
#endif
error("Stack address: %#lx", Stack);

View File

@ -36,16 +36,16 @@ public:
asmv("mov %0, %%cr3"
:
: "r"(KernelPageTable));
#endif
debug(" + %#lx %s(%d)", Original,
thisProcess->Name, thisProcess->ID);
#endif
}
~AutoSwitchPageTable()
{
#if defined(__amd64__) || defined(__i386__)
debug("- %#lx %s(%d)", Original,
thisProcess->Name, thisProcess->ID);
#if defined(__amd64__) || defined(__i386__)
asmv("mov %0, %%cr3"
:
: "r"(Original));

View File

@ -48,6 +48,8 @@ namespace Time
return mminq(&hpet->MainCounterValue);
#elif defined(__i386__)
return mminl(&hpet->MainCounterValue);
#else
return 0;
#endif
}
@ -57,6 +59,8 @@ namespace Time
return mminq(&hpet->MainCounterValue) + (Target * ConvertUnit(Unit)) / clk;
#elif defined(__i386__)
return mminl(&hpet->MainCounterValue) + (Target * ConvertUnit(Unit)) / clk;
#else
return 0;
#endif
}
@ -69,6 +73,8 @@ namespace Time
Subtraction *= ConvertUnit(Units::Nanoseconds);
return uint64_t(Subtraction / this->clk);
#else
return 0;
#endif
}

View File

@ -33,6 +33,8 @@ namespace Time
while (this->GetCounter() < Target)
CPU::Pause();
return true;
#elif defined(__aarch64__)
return 0;
#endif
}
@ -40,6 +42,8 @@ namespace Time
{
#if defined(__amd64__) || defined(__i386__)
return CPU::Counter();
#elif defined(__aarch64__)
return 0;
#endif
}
@ -47,6 +51,8 @@ namespace Time
{
#if defined(__amd64__) || defined(__i386__)
return uint64_t((this->GetCounter() + (Target * ConvertUnit(Unit))) / this->clk);
#elif defined(__aarch64__)
return 0;
#endif
}
@ -54,6 +60,8 @@ namespace Time
{
#if defined(__amd64__) || defined(__i386__)
return uint64_t((this->GetCounter() - this->ClassCreationTime) / this->clk);
#elif defined(__aarch64__)
return 0;
#endif
}

View File

@ -60,6 +60,8 @@ namespace UART
while ((inb(s_cst(uint16_t, COM1 + 5)) & 1) == 0)
;
return inb(COM1);
#else
return 0;
#endif
}
@ -82,6 +84,8 @@ namespace UART
while ((inb(s_cst(uint16_t, COM4 + 5)) & 1) == 0)
;
return inb(COM4);
#else
return 0;
#endif
}

View File

@ -188,6 +188,8 @@ namespace Execute
}
#elif defined(__i386__)
return 0xdead;
#elif defined(__aarch64__)
return 0xdead;
#endif
}
}

View File

@ -163,8 +163,6 @@ namespace CPU
"jmp CPUStopLoop");
#elif defined(__aarch64__)
asmv("CPUStopLoop:\n"
"cpsid i\n"
"wfe\n"
"wfi\n"
"b CPUStopLoop");
#endif
@ -1078,44 +1076,32 @@ namespace CPU
{
struct TrapFrame
{
uint64_t x0; // General purpose
uint64_t x1; // General purpose
uint64_t x2; // General purpose
uint64_t x3; // General purpose
uint64_t x4; // General purpose
uint64_t x5; // General purpose
uint64_t x6; // General purpose
uint64_t x7; // General purpose
uint64_t x8; // General purpose
uint64_t x9; // General purpose
uint64_t x10; // General purpose
uint64_t x11; // General purpose
uint64_t x12; // General purpose
uint64_t x13; // General purpose
uint64_t x14; // General purpose
uint64_t x15; // General purpose
uint64_t x16; // General purpose
uint64_t x17; // General purpose
uint64_t x18; // General purpose
uint64_t x19; // General purpose
uint64_t x20; // General purpose
uint64_t x21; // General purpose
uint64_t x22; // General purpose
uint64_t x23; // General purpose
uint64_t x24; // General purpose
uint64_t x25; // General purpose
uint64_t x26; // General purpose
uint64_t x27; // General purpose
uint64_t x28; // General purpose
uint64_t x[31];
uint64_t SP; /* Stack Pointer */
uint64_t ELR; /* Exception Link Register */
uint64_t ESR; /* Exception Syndrome Register */
uint64_t FAR; /* Fault Address Register */
uint64_t SPSR; /* Saved Program Status Register */
};
uint64_t fp; // Frame Pointer (meant for stack frames)
uint64_t lr; // Link Register
struct SchedulerFrame
{
uint64_t x[31];
uint64_t SP; /* Stack Pointer */
uint64_t ELR; /* Exception Link Register */
uint64_t ESR; /* Exception Syndrome Register */
uint64_t FAR; /* Fault Address Register */
uint64_t SPSR; /* Saved Program Status Register */
};
uint64_t sp; // Stack Pointer
uint64_t pc; // Program Counter
uint64_t pstate; // Processor State (flags)
uint64_t esr; // Exception Syndrome Register
uint64_t far; // Fault Address Register
struct ExceptionFrame
{
uint64_t x[31];
uint64_t SP; /* Stack Pointer */
uint64_t ELR; /* Exception Link Register */
uint64_t ESR; /* Exception Syndrome Register */
uint64_t FAR; /* Fault Address Register */
uint64_t SPSR; /* Saved Program Status Register */
};
}
@ -1145,7 +1131,7 @@ namespace CPU
*/
typedef aarch64::TrapFrame TrapFrame;
typedef aarch64::SchedulerFrame SchedulerFrame;
typedef aarch64::TrapFrame ExceptionFrame;
typedef aarch64::ExceptionFrame ExceptionFrame;
#endif
}

View File

@ -55,13 +55,11 @@ typedef uint64_t cpuid_t;
#define __amd_cpuid_init(leaf) \
CPUID##leaf() \
{ \
assert(!"cpuid not implemented for this architecture"); \
}
#define __amd_cpuid_init2(leaf, leaf2, suffix) \
CPUID##leaf##suffix() \
{ \
assert(!"cpuid not implemented for this architecture"); \
}
#endif

View File

@ -55,13 +55,11 @@ typedef uint64_t cpuid_t;
#define __intel_cpuid_init(leaf) \
CPUID##leaf() \
{ \
assert(!"cpuid not implemented for this architecture"); \
}
#define __intel_cpuid_init2(leaf, leaf2, suffix) \
CPUID##leaf##suffix() \
{ \
assert(!"cpuid not implemented for this architecture"); \
}
#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

@ -60,8 +60,13 @@ typedef struct SyscallsFrame
uint32_t StackPointer;
uint32_t StackSegment;
#elif defined(__aarch64__)
uint32_t ReturnAddress;
uint32_t StackPointer;
uint64_t ReturnAddress; /* x0 */
uint64_t x[30];
uint64_t StackPointer;
uint64_t ExceptionLinkRegister;
uint64_t ExceptionSyndromeRegister;
uint64_t FaultAddressRegister;
uint64_t SavedProgramStatusRegister;
#endif
uintptr_t ReturnValue() const
@ -71,7 +76,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return ax;
#elif defined(__aarch64__)
return x0;
return x[0];
#endif
}
@ -82,7 +87,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return di;
#elif defined(__aarch64__)
return x0;
return x[0];
#endif
}
@ -93,7 +98,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return cx;
#elif defined(__aarch64__)
return x1;
return x[1];
#endif
}
@ -104,7 +109,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return dx;
#elif defined(__aarch64__)
return x2;
return x[2];
#endif
}
@ -115,7 +120,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return si;
#elif defined(__aarch64__)
return x3;
return x[3];
#endif
}
@ -126,7 +131,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return di;
#elif defined(__aarch64__)
return x4;
return x[4];
#endif
}
@ -137,7 +142,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return bp;
#elif defined(__aarch64__)
return x5;
return x[5];
#endif
}
} SyscallsFrame;

View File

@ -358,12 +358,13 @@ namespace Tasking
CPU::SchedulerFrame Registers{};
#if defined(__amd64__)
uintptr_t ShadowGSBase, GSBase, FSBase;
__aligned(16) CPU::x64::FXState FPU;
#elif defined(__i386__)
uintptr_t ShadowGSBase, GSBase, FSBase;
#elif defined(__aarch64__)
uintptr_t Registers; // TODO
#endif
__aligned(16) CPU::x64::FXState FPU;
#elif defined(__aarch64__)
uintptr_t __todo; // TODO
#endif
/* Info & Security info */
struct

View File

@ -27,4 +27,8 @@
#define DBL_MANT_DIG 24
#define DBL_MAX_10_EXP 38
#define DBL_MAX 3.4028234663852886e+38
#elif __aarch64__
#define DBL_MANT_DIG __DBL_MANT_DIG__
#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
#define DBL_MAX __DBL_MAX__
#endif

View File

@ -45,6 +45,10 @@ namespace std
static_assert(sizeof(uintptr_t) == sizeof(uint32_t));
const uint32_t FNV_OFFSET_BASIS = 2166136261u;
const uint32_t FNV_PRIME = 16777619u;
#elif defined(__aarch64__)
static_assert(sizeof(uintptr_t) == sizeof(uint64_t));
const uint64_t FNV_OFFSET_BASIS = 14695981039346656037ull;
const uint64_t FNV_PRIME = 1099511628211ull;
#else
#error "Unsupported architecture"
#endif

View File

@ -25,6 +25,10 @@ using namespace vfs;
nsa void cmd_panic(const char *)
{
#if defined(__amd64__) || defined(__i386__)
asmv("int $0x0");
#elif defined(__aarch64__)
asmv("brk #0");
#endif
__unreachable;
}

View File

@ -42,10 +42,12 @@ EXTERNC void *memset_sse2(void *dest, int c, size_t n)
i = 0;
while (((size_t)dest + i) & (16 - 1) && i < n)
{
#if defined(__amd64__) || defined(__i386__)
asmv("stosb\n"
:
: "D"((size_t)dest + i),
"a"(c));
#endif
i++;
}
}
@ -68,9 +70,11 @@ EXTERNC void *memset_sse2(void *dest, int c, size_t n)
#endif
}
#if defined(__amd64__) || defined(__i386__)
asmv("rep stosb\n" ::"a"((size_t)(c)),
"D"(((size_t)dest) + i),
"c"(n - i));
#endif
i += n - i;
return (void *)(((size_t)dest) + i);

View File

@ -31,6 +31,7 @@ long unsigned __strlen(const char s[])
{
size_t ret = (size_t)s;
#if defined(__amd64__) || defined(__i386__)
asmv("._strlenLoop:"
"cmpb $0, 0(%1)\n"
"jz ._strlenExit\n"
@ -76,6 +77,7 @@ long unsigned __strlen(const char s[])
"._strlenExit:"
"mov %1, %0\n"
: "=r"(ret) : "0"(ret));
#endif
return ret - (size_t)s;
}
@ -107,7 +109,8 @@ long unsigned strlen_sse4_1(const char s[])
long unsigned strlen_sse4_2(const char s[])
{
size_t ret;
size_t ret = 0;
#if defined(__amd64__) || defined(__i386__)
asmv("mov $-16, %0\n"
"pxor %%xmm0, %%xmm0\n"
".strlen42Loop:"
@ -117,6 +120,6 @@ long unsigned strlen_sse4_2(const char s[])
"add %2, %0\n"
: "=a"(ret)
: "d"((size_t)s), "c"((size_t)s));
#endif
return ret;
}

View File

@ -314,6 +314,26 @@ struct linux_kstat
unsigned long st_ctime_nsec;
unsigned long __unused4;
unsigned long __unused5;
#elif defined(__aarch64__)
__kernel_ulong_t st_dev;
__kernel_ulong_t st_ino;
__kernel_ulong_t st_nlink;
unsigned int st_mode;
unsigned int st_uid;
unsigned int st_gid;
unsigned int __pad0;
__kernel_ulong_t st_rdev;
__kernel_long_t st_size;
__kernel_long_t st_blksize;
__kernel_long_t st_blocks;
__kernel_ulong_t st_atime;
__kernel_ulong_t st_atime_nsec;
__kernel_ulong_t st_mtime;
__kernel_ulong_t st_mtime_nsec;
__kernel_ulong_t st_ctime;
__kernel_ulong_t st_ctime_nsec;
#undef __unused
__kernel_long_t __unused[3];
#else
#error "Unsupported architecture"
#endif

View File

@ -1077,6 +1077,7 @@ static int linux_mprotect(SysFrm *, void *addr, size_t len, int prot)
return -linux_ENOMEM;
}
#if defined(__amd64__) || defined(__i386__)
if (!pte->Present ||
(!pte->UserSupervisor && p_Read) ||
(!pte->ReadWrite && p_Write))
@ -1089,7 +1090,8 @@ static int linux_mprotect(SysFrm *, void *addr, size_t len, int prot)
// pte->Present = !p_None;
pte->UserSupervisor = p_Read;
pte->ReadWrite = p_Write;
// pte->ExecuteDisable = p_Exec;
// pte->ExecuteDisable = p_Exec;
#endif
debug("Changed permissions of page %#lx to %s %s %s %s",
(void *)i,
@ -1484,7 +1486,9 @@ static pid_t linux_fork(SysFrm *sf)
TaskManager->UpdateFrame();
#if defined(__amd64__) || defined(__i386__)
NewThread->FPU = Thread->FPU;
#endif
NewThread->Stack->Fork(Thread->Stack);
NewThread->Info.Architecture = Thread->Info.Architecture;
NewThread->Info.Compatibility = Thread->Info.Compatibility;
@ -1564,7 +1568,9 @@ static pid_t linux_vfork(SysFrm *sf)
TaskManager->UpdateFrame();
#if defined(__amd64__) || defined(__i386__)
NewThread->FPU = Thread->FPU;
#endif
delete NewThread->Stack;
NewThread->Stack = Thread->Stack;
NewThread->Info.Architecture = Thread->Info.Architecture;

View File

@ -103,7 +103,11 @@
#define wut_schedbg(m, ...)
#endif
__naked __used nsa void __custom_sched_idle_loop()
#if defined(__amd64__) || defined(__i386__)
__naked
#endif
__used nsa void
__custom_sched_idle_loop()
{
#if defined(__amd64__) || defined(__i386__)
asmv("IdleLoop:");
@ -668,10 +672,12 @@ namespace Tasking::Scheduler
CurrentCPU->CurrentProcess->State.store(TaskState::Running);
CurrentCPU->CurrentThread->State.store(TaskState::Running);
#if defined(__amd64__) || defined(__i386__)
if (CurrentCPU->CurrentThread->Registers.cs != GDT_KERNEL_CODE)
CurrentCPU->CurrentThread->Registers.ppt = (uint64_t)(void *)CurrentCPU->CurrentProcess->PageTable;
else
CurrentCPU->CurrentThread->Registers.ppt = (uint64_t)(void *)KernelPageTable;
#endif
// if (!SchedulerUpdateTrapFrame) {} // TODO
@ -701,12 +707,14 @@ namespace Tasking::Scheduler
CurrentCPU->CurrentThread->Registers.rip,
CurrentCPU->CurrentThread->Registers.rbp,
CurrentCPU->CurrentThread->Registers.rsp);
#else
#elif defined(__i386__)
trace("%s[%ld]: EIP=%#lx EBP=%#lx ESP=%#lx",
CurrentCPU->CurrentThread->Name, CurrentCPU->CurrentThread->ID,
CurrentCPU->CurrentThread->Registers.eip,
CurrentCPU->CurrentThread->Registers.ebp,
CurrentCPU->CurrentThread->Registers.esp);
#elif defined(__aarch64__)
#warning "aarch64 not implemented yet"
#endif
}

View File

@ -321,7 +321,7 @@ namespace Tasking
#elif defined(__i386__)
this->Registers.esp = StackPointerReg;
#elif defined(__aarch64__)
this->Registers.sp = StackPointerReg;
#warning "aarch64 not implemented"
#endif
if (argvLen > 0)
@ -349,10 +349,7 @@ namespace Tasking
this->Registers.ecx = (uintptr_t)envpLen; // envc
this->Registers.edx = (uintptr_t)(this->Registers.esp + 4 + (4 * argvLen) + 4); // envp
#elif defined(__aarch64__)
this->Registers.x0 = (uintptr_t)argvLen; // argc
this->Registers.x1 = (uintptr_t)(this->Registers.sp + 8); // argv
this->Registers.x2 = (uintptr_t)envpLen; // envc
this->Registers.x3 = (uintptr_t)(this->Registers.sp + 8 + (8 * argvLen) + 8); // envp
#warning "aarch64 not implemented"
#endif
}
@ -410,8 +407,10 @@ namespace Tasking
uintptr_t *pTLSPointer = (uintptr_t *)this->TLS.pBase + this->TLS.Size;
*pTLSPointer = this->TLS.pBase + this->TLS.Size;
#if defined(__amd64__) || defined(__i386__)
this->GSBase = r_cst(uintptr_t, pTLSPointer);
this->FSBase = r_cst(uintptr_t, pTLSPointer);
#endif
}
TCB::TCB(Task *ctx, PCB *Parent, IP EntryPoint,
@ -470,7 +469,7 @@ namespace Tasking
#elif defined(__i386__)
this->Registers.eip = EntryPoint;
#elif defined(__aarch64__)
this->Registers.pc = EntryPoint;
#warning "aarch64 not implemented"
#endif
switch (this->Parent->Security.ExecutionMode)
@ -506,9 +505,7 @@ namespace Tasking
this->Registers.esp = ((uintptr_t)this->Stack->GetStackTop());
POKE(uintptr_t, this->Registers.esp) = (uintptr_t)ThreadDoExit;
#elif defined(__aarch64__)
this->Registers.pc = EntryPoint;
this->Registers.sp = ((uintptr_t)this->Stack->GetStackTop());
POKE(uintptr_t, this->Registers.sp) = (uintptr_t)ThreadDoExit;
#warning "aarch64 not implemented"
#endif
break;
}
@ -612,10 +609,12 @@ namespace Tasking
this->Parent->Info.RootNode = this->Info.RootNode;
}
// TODO: Is really a good idea to use the FPU in kernel mode?
// TODO: Is really a good idea to use the FPU in kernel mode?
#if defined(__amd64__) || defined(__i386__)
this->FPU.mxcsr = 0b0001111110000000;
this->FPU.mxcsrmask = 0b1111111110111111;
this->FPU.fcw = 0b0000001100111111;
#endif
#ifdef DEBUG
#ifdef __amd64__

View File

@ -23,6 +23,7 @@
__constructor void TestRandom()
{
#if defined(__amd64__) || defined(__i386__)
int RDRANDFlag = 0;
if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
{
@ -38,7 +39,6 @@ __constructor void TestRandom()
if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) == 0)
RDRANDFlag = 0;
#if defined(__amd64__) || defined(__i386__)
if (RDRANDFlag)
{
uintptr_t RDSEEDValue = 0;
@ -46,7 +46,6 @@ __constructor void TestRandom()
: "=r"(RDSEEDValue));
debug("RDSEED: %ld", RDSEEDValue);
}
#endif
Random::ChangeSeed(0xdeadbeef);
uint16_t Seeds16[16];
@ -61,6 +60,7 @@ __constructor void TestRandom()
debug("Random 16: %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld", Seeds16[0], Seeds16[1], Seeds16[2], Seeds16[3], Seeds16[4], Seeds16[5], Seeds16[6], Seeds16[7], Seeds16[8], Seeds16[9], Seeds16[10], Seeds16[11], Seeds16[12], Seeds16[13], Seeds16[14], Seeds16[15]);
debug("Random 32: %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld", Seeds32[0], Seeds32[1], Seeds32[2], Seeds32[3], Seeds32[4], Seeds32[5], Seeds32[6], Seeds32[7], Seeds32[8], Seeds32[9], Seeds32[10], Seeds32[11], Seeds32[12], Seeds32[13], Seeds32[14], Seeds32[15]);
debug("Random 64: %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld", Seeds64[0], Seeds64[1], Seeds64[2], Seeds64[3], Seeds64[4], Seeds64[5], Seeds64[6], Seeds64[7], Seeds64[8], Seeds64[9], Seeds64[10], Seeds64[11], Seeds64[12], Seeds64[13], Seeds64[14], Seeds64[15]);
#endif
}
#endif // DEBUG

View File

@ -146,6 +146,8 @@ void TaskMgr()
Statuses[State], Proc->Name, StatusesSign[State],
ProcessCpuUsage, Proc->Info.KernelTime, Proc->Info.UserTime);
#elif defined(__aarch64__)
UNUSED(State);
#warning "aarch64 not implemented"
#endif
foreach (auto Thd in Proc->Threads)

View File

@ -454,6 +454,7 @@ namespace KernelConsole
void VirtualTerminal::Process(char c)
{
#ifdef DEBUG
#if defined(__amd64__) || defined(__i386__)
static int once = 0;
static uint8_t com4 = 0xFF;
if (!once++)
@ -476,12 +477,13 @@ namespace KernelConsole
outb(0x2E8, c);
}
// while (true)
// {
// while ((inb(0x2E8 + 5) & 1) == 0)
// ;
// outb(0x2E8, inb(0x2E8));
// }
// while (true)
// {
// while ((inb(0x2E8 + 5) & 1) == 0)
// ;
// outb(0x2E8, inb(0x2E8));
// }
#endif
#endif
ANSIParser *parser = &this->Parser;

View File

@ -96,6 +96,7 @@ bool IsVMwareBackdoorAvailable()
cmd.magic = VMWARE_MAGIC;
cmd.port = VMWARE_PORT;
#if defined(__amd64__) || defined(__i386__)
asmv("in %%dx, %0"
: "+a"(cmd.ax),
"+b"(cmd.bx),
@ -103,6 +104,7 @@ bool IsVMwareBackdoorAvailable()
"+d"(cmd.dx),
"+S"(cmd.si),
"+D"(cmd.di));
#endif
if (cmd.bx != VMWARE_MAGIC || cmd.ax == 0xFFFFFFFF)
return false;

View File

@ -74,8 +74,7 @@ QEMUFLAGS += -M raspi3b \
-serial file:COM2.dmp \
-serial file:COM3.dmp \
-serial stdio \
-kernel $(OSNAME).img \
-acpitable file=tools/acpi/SSDT1.dat
-kernel $(OSNAME).img
endif
doxygen:

View File

@ -81,6 +81,27 @@
"-nostdinc",
"-nostdinc++"
]
},
{
"name": "Fennix Aarch64 (Linux, GCC, debug)",
"includePath": [
"${workspaceFolder}/libc/include/**",
"${workspaceFolder}/libs/include/**"
],
"defines": [
"__debug_vscode__",
"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

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

@ -182,6 +182,13 @@ enum RelocationTypes
R_X86_64_REX_GOTPCRELX = 42,
R_X86_64_NUM = 43,
R_AARCH64_NONE = 0,
R_AARCH64_COPY = 1024,
R_AARCH64_GLOB_DAT = 1025,
R_AARCH64_JUMP_SLOT = 1026,
R_AARCH64_RELATIVE = 1027,
R_AARCH64_TLS_DTPMOD64 = 1028,
#if defined(__x86_64__)
R_NONE = R_X86_64_NONE,
R_COPY = R_X86_64_COPY,
@ -200,6 +207,15 @@ enum RelocationTypes
R_DTPMOD64 = R_386_NONE,
R_DTPOFF64 = R_386_NONE,
R_TPOFF64 = R_386_NONE,
#elif defined(__aarch64__)
R_NONE = R_AARCH64_NONE,
R_COPY = R_AARCH64_COPY,
R_GLOB_DAT = R_AARCH64_GLOB_DAT,
R_JMP_SLOT = R_AARCH64_JUMP_SLOT,
R_RELATIVE = R_AARCH64_RELATIVE,
R_DTPMOD64 = R_AARCH64_TLS_DTPMOD64,
R_DTPOFF64 = R_AARCH64_NONE,
R_TPOFF64 = R_AARCH64_NONE,
#endif
};

View File

@ -151,8 +151,8 @@ __attribute__((naked, used, no_stack_protector)) void _dl_runtime_resolve()
"jmp *%r11\n"); /* Jump to the return value */
#elif defined(__i386__)
#warning "i386 _dl_runtime_resolve not implemented"
#else
#error "Unsupported architecture"
#elif defined(__aarch64__)
#warning "aarch64 not implemented"
#endif
}
@ -817,6 +817,7 @@ int RelocateHelper(ElfInfo *Info, Elf_Rela *Rela, short IsRel, void **Relocated)
reloc = Info->BaseAddress;
break;
}
#if defined(__amd64__)
case R_DTPOFF64:
{
printf("dl: i don't know what to do with DTPOFF64\n");
@ -829,6 +830,7 @@ int RelocateHelper(ElfInfo *Info, Elf_Rela *Rela, short IsRel, void **Relocated)
reloc = symAddress + Rela->r_addend;
break;
}
#endif
#endif // __LP64__
default:
{

View File

@ -128,6 +128,8 @@ __attribute__((naked, used, no_stack_protector)) void _start()
"call _exit\n"); /* Call _exit */
#elif defined(__i386__)
#warning "i386 _start not implemented"
#elif defined(__aarch64__)
#warning "aarch64 _start not implemented"
#else
#error "Unsupported architecture"
#endif

View File

@ -17,7 +17,7 @@ build: $(OBJ)
%.o: %.c
$(info Compiling $<)
$(CC) -nostdlib -mno-red-zone -std=c17 -DLIBC_GIT_COMMIT='"$(shell git rev-parse HEAD)"' -c $< -o $@
$(CC) -nostdlib -std=c17 -DLIBC_GIT_COMMIT='"$(shell git rev-parse HEAD)"' -c $< -o $@
%.o: %.S
$(info Compiling $<)

View File

@ -68,6 +68,8 @@ __attribute__((naked, used, no_stack_protector, section(".text"))) void _start()
"call _exit\n");
#elif defined(__i386__)
#warning "i386 _start not implemented"
#elif defined(__aarch64__)
#warning "aarch64 _start not implemented"
#else
#error "Unsupported architecture"
#endif

View File

@ -68,6 +68,8 @@ __attribute__((naked, used, no_stack_protector, section(".text"))) void _start()
"call _exit\n");
#elif defined(__i386__)
#warning "i386 _start not implemented"
#elif defined(__aarch64__)
#warning "aarch64 _start not implemented"
#else
#error "Unsupported architecture"
#endif

View File

@ -0,0 +1,21 @@
/*
This file is part of Fennix C Library.
Fennix C Library is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
double __trunctfdf2(long double a)
{
return (double)a;
}

View File

@ -108,8 +108,12 @@ export int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
export pthread_t pthread_self(void)
{
pthread_t tid;
#if defined(__amd64__) || defined(__i386__)
__asm__ __volatile__("mov %%fs:0, %0"
: "=r"(tid));
#elif defined(__aarch64__)
tid = 0;
#endif
return tid;
}

View File

@ -24,7 +24,10 @@
export __attribute__((naked, used, no_stack_protector)) void *__tls_get_addr(void *__data)
{
#warning "__tls_get_addr not implemented"
#if defined(__amd64__) || defined(__i386__)
__asm__("ud2");
#endif
}
int __init_pthread(void)

View File

@ -287,6 +287,74 @@ index 6a9833e5..bf4c134d 100644
eelf_x86_64_haiku.c \
eelf_x86_64_sol2.c \
ehppa64linux.c \
diff --git a/ld/Makefile.in b/ld/Makefile.in
index 8639e782..24738803 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -676,6 +676,7 @@ ALL_EMULATION_SOURCES = \
earcv2elfx.c \
earm_wince_pe.c \
earmelf.c \
+ earmelf_fennix.c \
earmelf_fbsd.c \
earmelf_fuchsia.c \
earmelf_haiku.c \
@@ -790,6 +791,7 @@ ALL_EMULATION_SOURCES = \
eelf_i386.c \
eelf_i386_be.c \
eelf_i386_fbsd.c \
+ eelf_i386_fennix.c \
eelf_i386_haiku.c \
eelf_i386_ldso.c \
eelf_i386_sol2.c \
@@ -893,6 +895,7 @@ ALL_64_EMULATION_SOURCES = \
eaarch64elf32.c \
eaarch64elf32b.c \
eaarch64elfb.c \
+ eaarch64fennix.c \
eaarch64fbsd.c \
eaarch64fbsdb.c \
eaarch64haiku.c \
@@ -973,6 +976,7 @@ ALL_64_EMULATION_SOURCES = \
eelf_x86_64.c \
eelf_x86_64_cloudabi.c \
eelf_x86_64_fbsd.c \
+ eelf_x86_64_fennix.c \
eelf_x86_64_haiku.c \
eelf_x86_64_sol2.c \
ehppa64linux.c \
@@ -1279,6 +1283,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64elfb.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64fbsd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64fbsdb.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64fennix.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64haiku.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64linux.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64linux32.Po@am__quote@
@@ -1301,6 +1306,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earm_wince_pe.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf_fbsd.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf_fennix.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf_fuchsia.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf_haiku.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf_linux.Po@am__quote@
@@ -1480,6 +1486,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_be.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_fbsd.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_fennix.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_haiku.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_ldso.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_i386_sol2.Po@am__quote@
@@ -1490,6 +1497,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_cloudabi.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fennix.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_sol2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eh8300elf.Po@am__quote@
diff --git a/ld/configure.tgt b/ld/configure.tgt
index f937f78b..3aa8c738 100644
--- a/ld/configure.tgt

View File

@ -104,10 +104,10 @@ index 95c91ee02..cbcaac06b 100644
;;
diff --git a/gcc/config/aarch64/aarch64-fennix.h b/gcc/config/aarch64/aarch64-fennix.h
new file mode 100644
index 000000000..dafd8f253
index 000000000..cf9b0136e
--- /dev/null
+++ b/gcc/config/aarch64/aarch64-fennix.h
@@ -0,0 +1,34 @@
@@ -0,0 +1,23 @@
+/* Definitions for AArch64 running Fennix
+ Copyright (C) 2016-2024 Free Software Foundation, Inc.
+
@ -130,17 +130,6 @@ index 000000000..dafd8f253
+#ifndef GCC_AARCH64_FENNIX_H
+#define GCC_AARCH64_FENNIX_H
+
+// #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
+
+// #undef TARGET_BINDS_LOCAL_P
+// #define TARGET_BINDS_LOCAL_P default_binds_local_p_2
+
+// #undef MCOUNT_NAME
+// #define MCOUNT_NAME ".mcount"
+
+// #undef ASM_GENERATE_INTERNAL_LABEL
+// #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) sprintf(LABEL, "*.L%s%lu", PREFIX, (unsigned long)(NUM))
+
+#endif /* GCC_AARCH64_FENNIX_H */
diff --git a/gcc/config/aarch64/t-aarch64-fennix b/gcc/config/aarch64/t-aarch64-fennix
new file mode 100644
@ -304,14 +293,15 @@ index 000000000..632634dac
+MULTILIB_OPTIONS += mno-red-zone
+MULTILIB_DIRNAMES += no-red-zone
diff --git a/libgcc/config.host b/libgcc/config.host
index e75a7af64..572fff51e 100644
index e75a7af64..10d8017b0 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -418,6 +418,14 @@ aarch64*-*-elf | aarch64*-*-rtems*)
@@ -418,6 +418,15 @@ aarch64*-*-elf | aarch64*-*-rtems*)
tmake_file="${tmake_file} t-dfprules"
md_unwind_header=aarch64/aarch64-unwind.h
;;
+aarch64*-*-fennix*)
+ extra_parts="$extra_parts crti.o crtn.o crtbegin.o crtend.o crtbeginS.o crtendS.o"
+ extra_parts="$extra_parts crtfastmath.o"
+ tmake_file="${tmake_file} ${cpu_type}/t-aarch64"
+ tmake_file="${tmake_file} ${cpu_type}/t-lse t-slibgcc-libgcc"
@ -322,7 +312,7 @@ index e75a7af64..572fff51e 100644
aarch64*-*-freebsd*)
extra_parts="$extra_parts crtfastmath.o"
tmake_file="${tmake_file} ${cpu_type}/t-aarch64"
@@ -512,6 +520,12 @@ arm-wrs-vxworks7*)
@@ -512,6 +521,13 @@ arm-wrs-vxworks7*)
unwind_header=config/arm/unwind-arm.h
extra_parts="$extra_parts crti.o crtn.o"
;;
@ -331,11 +321,12 @@ index e75a7af64..572fff51e 100644
+ tmake_file="${tmake_file} t-softfp-sfdf t-softfp-excl arm/t-softfp t-softfp"
+ tm_file="${tm_file} arm/bpabi-lib.h"
+ unwind_header=config/arm/unwind-arm.h
+ extra_parts="$extra_parts crti.o crtn.o crtbegin.o crtend.o crtbeginS.o crtendS.o"
+ ;;
arm*-*-freebsd*) # ARM FreeBSD EABI
tmake_file="${tmake_file} arm/t-arm t-fixedpoint-gnu-prefix arm/t-elf"
tmake_file="${tmake_file} arm/t-bpabi arm/t-freebsd"
@@ -760,6 +774,14 @@ x86_64-*-dragonfly*)
@@ -760,6 +776,14 @@ x86_64-*-dragonfly*)
tmake_file="${tmake_file} i386/t-dragonfly i386/t-crtstuff"
md_unwind_header=i386/dragonfly-unwind.h
;;