Compare commits

...

2 Commits

Author SHA1 Message Date
fbe9fbfbd1
kernel: add arm architecture support
Some checks failed
Build OS / Deploy Documentation to GitHub Pages (push) Failing after 5m35s
Build OS / Analyze (${{ matrix.language }}) (manual, c-cpp) (push) Has been cancelled
Build OS / Build Cross-Compiler & Toolchain (push) Has been cancelled
Build OS / Build amd64 (push) Has been cancelled
Build OS / Build i386 (push) Has been cancelled
Build OS / Build aarch64 (push) Has been cancelled
Build OS / Build arm (push) Has been cancelled
Signed-off-by: EnderIce2 <enderice2@protonmail.com>
2025-01-10 18:55:34 +02:00
e6933acfb0
kernel: add aarch64 architecture support
Signed-off-by: EnderIce2 <enderice2@protonmail.com>
2025-01-10 17:26:26 +02:00
90 changed files with 2027 additions and 327 deletions

View File

@ -35,10 +35,8 @@
"-ffunction-sections",
"-msoft-float",
"-fno-builtin",
// C++ flags
"-fexceptions",
// Linker flags
"-fPIC",
"-fPIE",
@ -50,7 +48,6 @@
"-nolibc",
"-zmax-page-size=0x1000",
"-static",
// VSCode flags
"-ffreestanding",
"-nostdinc",
@ -91,10 +88,8 @@
"-ffunction-sections",
"-msoft-float",
"-fno-builtin",
// C++ flags
"-fexceptions",
// Linker flags
"-fPIC",
"-fPIE",
@ -106,12 +101,36 @@
"-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

@ -137,6 +137,33 @@
"-nostdinc++"
]
},
{
"name": "Fennix Arm (Linux, GCC, debug)",
"includePath": [
"${workspaceFolder}/include",
"${workspaceFolder}/include/**",
"${workspaceFolder}/include_std",
"${workspaceFolder}/include_std/**",
"${workspaceFolder}/arch/aarch64/include"
],
"forcedInclude": [
"${workspaceFolder}/.vscode/preinclude.h"
],
"defines": [
"DEBUG=\"1\""
],
"compilerPath": "${workspaceFolder}/../tools/cross/bin/arm-fennix-gcc",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-arm",
"configurationProvider": "ms-vscode.makefile-tools",
"compilerArgs": [
// VSCode flags
"-ffreestanding",
"-nostdinc",
"-nostdinc++"
]
},
{
"name": "Fennix Aarch64 (Linux, GCC, debug)",
"includePath": [
@ -158,38 +185,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,20 @@ 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), arm)
CFLAGS += -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16
LDFLAGS += -Tarch/arm/linker.ld
WARNCFLAG += -w
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 +71,11 @@ ifeq ($(DEBUG), 1)
ifeq ($(OSARCH), amd64)
CFLAGS += -fverbose-asm
endif # amd64
ifneq ($(OSARCH), aarch64)
CFLAGS += -fstack-check
ifeq ($(OSARCH), arm)
CFLAGS += -fstack-check -fverbose-asm
endif # arm
ifeq ($(OSARCH), aarch64)
CFLAGS += -fstack-check -fverbose-asm
endif # aarch64
LDFLAGS += -ggdb3 -O0
ASFLAGS += -g --gstabs+ --gdwarf-5 -D
@ -119,6 +126,8 @@ ifeq ($(OSARCH), amd64)
$(__CONF_OBJCOPY) -O elf64-x86-64 -I binary $< $@
else ifeq ($(OSARCH), i386)
$(__CONF_OBJCOPY) -O elf32-i386 -I binary $< $@
else ifeq ($(OSARCH), arm)
$(__CONF_OBJCOPY) -O elf32-littlearm -I binary $< $@
else ifeq ($(OSARCH), aarch64)
$(__CONF_OBJCOPY) -O elf64-littleaarch64 -I binary $< $@
endif
@ -129,6 +138,8 @@ ifeq ($(OSARCH), amd64)
$(__CONF_OBJCOPY) -O elf64-x86-64 -I binary $< $@
else ifeq ($(OSARCH), i386)
$(__CONF_OBJCOPY) -O elf32-i386 -I binary $< $@
else ifeq ($(OSARCH), arm)
$(__CONF_OBJCOPY) -O elf32-littlearm -I binary $< $@
else ifeq ($(OSARCH), aarch64)
$(__CONF_OBJCOPY) -O elf64-littlearch64 -I binary $< $@
endif

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:

40
Kernel/arch/arm/aeabi.c Normal file
View File

@ -0,0 +1,40 @@
/*
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/>.
*/
unsigned __aeabi_uidiv(unsigned a, unsigned b) { return a / b; }
unsigned __aeabi_idiv(unsigned a, unsigned b) { return a / b; }
unsigned __aeabi_l2d(unsigned a) { return a; }
unsigned __aeabi_d2lz(unsigned a) { return a; }
unsigned __aeabi_ldivmod(unsigned a, unsigned b, unsigned *r) { *r = a % b; return a / b; }
unsigned __aeabi_uldivmod(unsigned a, unsigned b, unsigned *r) { *r = a % b; return a / b; }
unsigned __aeabi_uidivmod(unsigned a, unsigned b, unsigned *r) { *r = a % b; return a / b; }
unsigned __aeabi_idivmod(unsigned a, unsigned b, unsigned *r) { *r = a % b; return a / b; }
unsigned __aeabi_unwind_cpp_pr1(void) { return 0; }
unsigned __aeabi_atexit(void) { return 0; }
unsigned __cxa_end_cleanup(void) { return 0; }
unsigned __aeabi_unwind_cpp_pr0(void) { return 0; }

View File

@ -0,0 +1,18 @@
/* Based on this tutorial:
https://github.com/s-matyukevich/raspberry-pi-os */
.section ".text.boot", "a"
.extern _bss_start
.extern _bss_end
.global _start
_start:
b CPU_Loop
Halt:
wfe
b Halt
CPU_Loop:
b CPU_Loop

View File

@ -0,0 +1,46 @@
/*
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 <display.hpp>
#include <bitmap.hpp>
#include <convert.h>
#include <printf.h>
#include <lock.hpp>
#include <rand.hpp>
#include <uart.hpp>
#include <debug.h>
#include <smp.hpp>
#include <cpu.hpp>
#include <io.h>
#if defined(__amd64__)
#include "../../arch/amd64/cpu/gdt.hpp"
#include "../arch/amd64/cpu/apic.hpp"
#elif defined(__i386__)
#include "../../arch/i386/cpu/gdt.hpp"
#include "../arch/i386/cpu/apic.hpp"
#elif defined(__aarch64__)
#endif
#include "../../../../kernel.h"
extern void ExPrint(const char *Format, ...);
arch nsa void DisplayDetailsScreen(CPU::ExceptionFrame *Frame)
{
ExPrint("\nException Frame:\n");
}

View File

@ -0,0 +1,59 @@
/*
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 <smp.hpp>
#include <ints.hpp>
#include <memory.hpp>
#include <cpu.hpp>
#include "../../../kernel.h"
volatile bool CPUEnabled = false;
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
static __aligned(0x1000) CPUData CPUs[MAX_CPU] = {0};
CPUData *GetCPU(uint64_t id) { return &CPUs[id]; }
CPUData *GetCurrentCPU()
{
uint64_t ret = 0;
if (!CPUs[ret].IsActive)
{
error("CPU %d is not active!", ret);
return &CPUs[0];
}
if (CPUs[ret].Checksum != CPU_DATA_CHECKSUM)
{
error("CPU %d data is corrupted!", ret);
return &CPUs[0];
}
return &CPUs[ret];
}
namespace SMP
{
int CPUCores = 0;
void Initialize(void *madt)
{
fixme("SMP::Initialize() is not implemented!");
}
}

27
Kernel/arch/arm/entry.cpp Normal file
View File

@ -0,0 +1,27 @@
/*
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 <types.h>
#include <debug.h>
#include <cpu.hpp>
EXTERNC void arm64Entry(uint64_t dtb_ptr32, uint64_t x1, uint64_t x2, uint64_t x3)
{
trace("Hello, World!");
CPU::Halt(true);
}

View File

89
Kernel/arch/arm/linker.ld Normal file
View File

@ -0,0 +1,89 @@
/*
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/>.
*/
ENTRY(_start)
SECTIONS
{
_bootstrap_start = .;
.text.boot :
{
*(.text.boot)
. += CONSTANT(MAXPAGESIZE);
_bss_start = .;
*(.text.bss)
_bss_end = .;
}
_bootstrap_end = .;
_kernel_start = .;
_kernel_text_start = .;
.text :
{
KEEP(*(.text.boot))
*(.text .text.*)
}
. = ALIGN(4096);
_kernel_text_end = .;
_kernel_data_start = .;
.data :
{
*(.data .data.*)
}
. = ALIGN(4096);
_kernel_data_end = .;
_kernel_rodata_start = .;
.rodata :
{
*(.rodata .rodata.*)
}
. = ALIGN(4096);
.init_array :
{
PROVIDE_HIDDEN(__init_array_start = .);
KEEP(*(.init_array .ctors))
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
PROVIDE_HIDDEN (__init_array_end = .);
}
.fini_array :
{
PROVIDE_HIDDEN(__fini_array_start = .);
KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP(*(.fini_array .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
_kernel_rodata_end = .;
_kernel_bss_start = .;
.bss :
{
*(.bss .bss.*)
}
. = ALIGN(4096);
_kernel_bss_end = .;
_kernel_end = .;
_bss_size = _kernel_end - _kernel_rodata_end;
/DISCARD/ :
{
*(.comment*)
}
}

97
Kernel/arch/arm/madt.cpp Normal file
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

@ -0,0 +1,69 @@
/*
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 <memory.hpp>
#include <convert.h>
#include <debug.h>
namespace Memory
{
bool Virtual::Check(void *VirtualAddress, PTFlag Flag, MapType Type)
{
#warning "arm not implemented"
return 0;
}
void *Virtual::GetPhysical(void *VirtualAddress)
{
#warning "arm not implemented"
return nullptr;
}
Virtual::MapType Virtual::GetMapType(void *VirtualAddress)
{
#warning "arm not implemented"
return MapType::NoMapType;
}
PageDirectoryEntry *Virtual::GetPDE(void *VirtualAddress, MapType Type)
{
#warning "arm not implemented"
return nullptr;
}
PageTableEntry *Virtual::GetPTE(void *VirtualAddress, MapType Type)
{
#warning "arm not implemented"
return nullptr;
}
void Virtual::Map(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags, MapType Type)
{
#warning "arm not implemented"
}
void Virtual::Unmap(void *VirtualAddress, MapType Type)
{
#warning "arm not implemented"
}
void Virtual::Remap(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags, MapType Type)
{
#warning "arm not implemented"
}
}

View File

@ -0,0 +1,30 @@
/*
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 <syscalls.hpp>
#include <cpu.hpp>
extern "C" __used __no_stack_protector void SystemCallHandlerStub()
{
}
extern "C" uint64_t SystemCallsHandler(SyscallsFrame *regs);
void InitializeSystemCalls()
{
}

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 "arm not implemented"
return false;
}
void Signal::RestoreHandleSignal(SyscallsFrame *sf, void *thread)
{
#warning "arm 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;
@ -301,6 +304,7 @@ namespace Interrupts
fixme("APIC not found for core %d", Core);
// 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

@ -551,9 +551,9 @@ struct heap_t
};
/* Keep in sync with heap_t inside rpmalloc_compat.cpp */
#ifndef __i386__
#if !defined(__i386__) && !defined(__arm__)
static_assert(sizeof(heap_t) == 56408, "heap_t size mismatch");
#endif // __i386__
#endif // __i386__ || __arm__
// Size class for defining a block size bucket
struct size_class_t
@ -3105,7 +3105,11 @@ rpcalloc(size_t num, size_t size)
{
size_t total;
#if ENABLE_VALIDATE_ARGS
#ifdef __arm__
int err = __builtin_umull_overflow(num, size, (unsigned long *)&total);
#else
int err = __builtin_umull_overflow(num, size, &total);
#endif
assert(!err && (total < MAX_ALLOC_SIZE));
#else
total = num * size;
@ -3150,7 +3154,11 @@ rpaligned_calloc(size_t alignment, size_t num, size_t size)
{
size_t total;
#if ENABLE_VALIDATE_ARGS
#ifdef __arm__
int err = __builtin_umull_overflow(num, size, (unsigned long *)&total);
#else
int err = __builtin_umull_overflow(num, size, &total);
#endif
assert(!err && (total < MAX_ALLOC_SIZE));
#else
total = num * size;

View File

@ -93,7 +93,7 @@ namespace Memory
#if defined(__amd64__) || defined(__aarch64__)
Elf64_Xword SymbolSize = 0;
Elf64_Xword StringSize = 0;
#elif defined(__i386__)
#elif defined(__i386__) || defined(__arm__)
Elf32_Word SymbolSize = 0;
Elf32_Word StringSize = 0;
#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,23 @@ 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"
#elif defined(__arm__)
"stub",
"stub",
#warning "arm not implemented"
#endif
#if defined(__amd64__) || defined(__i386__)
Frame->InterruptNumber);
#elif defined(__aarch64__)
0);
#warning "aarch64 not implemented"
#elif defined(__arm__)
0);
#warning "arm not implemented"
#endif
#if defined(__amd64__) || defined(__i386__)
ExPrint("Cause: %s\n", x86Exceptions[Frame->InterruptNumber].Cause);
#endif
@ -314,8 +327,11 @@ nsa void DisplayMainScreen(CPU::ExceptionFrame *Frame)
Frame->rip);
#elif defined(__i386__)
Frame->eip);
#elif defined(__arm__)
0);
#elif defined(__aarch64__)
Frame->pc);
0);
#warning "aarch64 not implemented"
#endif
CPUData *core = GetCurrentCPU();
@ -342,7 +358,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 +369,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 +379,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 +575,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 +676,7 @@ nsa void DisplayCrashScreen(CPU::ExceptionFrame *Frame)
ExPrint(keyBuf);
}
#endif
#endif // DEBUG
debug("cpu halted");
CPU::Halt(true);
}
@ -966,7 +986,9 @@ nsa void UserInput(char *Input)
else if (strcmp(Input, "pt") == 0)
{
/* 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

@ -104,7 +104,7 @@ namespace SymbolResolver
#if defined(__amd64__) || defined(__aarch64__)
Elf64_Xword SymbolSize = 0;
// Elf64_Xword StringSize = 0;
#elif defined(__i386__)
#elif defined(__i386__) || defined(__arm__)
Elf32_Word SymbolSize = 0;
// Elf32_Word StringSize = 0;
#endif
@ -220,7 +220,7 @@ namespace SymbolResolver
#if defined(__amd64__) || defined(__aarch64__)
Elf64_Ehdr *Header = (Elf64_Ehdr *)ImageAddress;
#elif defined(__i386__)
#elif defined(__i386__) || defined(__arm__)
Elf32_Ehdr *Header = (Elf32_Ehdr *)ImageAddress;
#endif
if (Header->e_ident[0] != 0x7F &&

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

@ -80,9 +80,11 @@ typedef struct
#if defined(__amd64__)
typedef Elf64_auxv_t Elf_auxv_t;
#elif defined(__i386__)
typedef Elf64_auxv_t Elf_auxv_t;
typedef Elf32_auxv_t Elf_auxv_t;
#elif defined(__aarch64__)
typedef Elf64_auxv_t Elf_auxv_t;
#elif defined(__arm__)
typedef Elf32_auxv_t Elf_auxv_t;
#endif
typedef struct

View File

@ -90,8 +90,8 @@ extern "C"
long unsigned strlen_sse4_1(const char s[]);
long unsigned strlen_sse4_2(const char s[]);
long unsigned strlen(const char s[]);
int strncmp(const char *s1, const char *s2, unsigned long n);
size_t strlen(const char s[]);
int strncmp(const char *s1, const char *s2, size_t n);
char *strcat_unsafe(char *destination, const char *source);
char *strcpy_unsafe(char *destination, const char *source);
char *strncpy(char *destination, const char *source, unsigned long num);

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
@ -1074,48 +1072,102 @@ namespace CPU
}
}
namespace arm
{
struct TrapFrame
{
uint32_t R0; /* Register R0 (argument / scratch) */
uint32_t R1; /* Register R1 (argument / scratch) */
uint32_t R2; /* Register R2 (argument / scratch) */
uint32_t R3; /* Register R3 (argument / scratch) */
uint32_t R4; /* Register R4 (callee-saved) */
uint32_t R5; /* Register R5 (callee-saved) */
uint32_t R6; /* Register R6 (callee-saved) */
uint32_t R7; /* Register R7 (callee-saved) */
uint32_t R8; /* Register R8 (callee-saved) */
uint32_t R9; /* Register R9 (platform-specific) */
uint32_t R10; /* Register R10 (callee-saved) */
uint32_t FP; /* Frame Pointer (R11) */
uint32_t IP; /* Intra-Procedure Scratch (R12) */
uint32_t SP; /* Stack Pointer (R13) */
uint32_t LR; /* Link Register (R14) */
uint32_t PC; /* Program Counter (R15) */
uint32_t CPSR; /* Current Program Status Register */
};
struct SchedulerFrame
{
uint32_t R0; /* Register R0 (argument / scratch) */
uint32_t R1; /* Register R1 (argument / scratch) */
uint32_t R2; /* Register R2 (argument / scratch) */
uint32_t R3; /* Register R3 (argument / scratch) */
uint32_t R4; /* Register R4 (callee-saved) */
uint32_t R5; /* Register R5 (callee-saved) */
uint32_t R6; /* Register R6 (callee-saved) */
uint32_t R7; /* Register R7 (callee-saved) */
uint32_t R8; /* Register R8 (callee-saved) */
uint32_t R9; /* Register R9 (platform-specific) */
uint32_t R10; /* Register R10 (callee-saved) */
uint32_t FP; /* Frame Pointer (R11) */
uint32_t IP; /* Intra-Procedure Scratch (R12) */
uint32_t SP; /* Stack Pointer (R13) */
uint32_t LR; /* Link Register (R14) */
uint32_t PC; /* Program Counter (R15) */
uint32_t CPSR; /* Current Program Status Register */
};
struct ExceptionFrame
{
uint32_t R0; /* Register R0 (argument / scratch) */
uint32_t R1; /* Register R1 (argument / scratch) */
uint32_t R2; /* Register R2 (argument / scratch) */
uint32_t R3; /* Register R3 (argument / scratch) */
uint32_t R4; /* Register R4 (callee-saved) */
uint32_t R5; /* Register R5 (callee-saved) */
uint32_t R6; /* Register R6 (callee-saved) */
uint32_t R7; /* Register R7 (callee-saved) */
uint32_t R8; /* Register R8 (callee-saved) */
uint32_t R9; /* Register R9 (platform-specific) */
uint32_t R10; /* Register R10 (callee-saved) */
uint32_t FP; /* Frame Pointer (R11) */
uint32_t IP; /* Intra-Procedure Scratch (R12) */
uint32_t SP; /* Stack Pointer (R13) */
uint32_t LR; /* Link Register (R14) */
uint32_t PC; /* Program Counter (R15) */
uint32_t CPSR; /* Current Program Status Register */
};
}
namespace aarch64
{
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 */
};
}
@ -1137,6 +1189,15 @@ namespace CPU
typedef x32::TrapFrame TrapFrame;
typedef x32::SchedulerFrame SchedulerFrame;
typedef x32::ExceptionFrame ExceptionFrame;
#elif defined(__arm__)
/**
* CPU trap frame for the current architecture
*
* @note This is for arm
*/
typedef arm::TrapFrame TrapFrame;
typedef arm::SchedulerFrame SchedulerFrame;
typedef arm::ExceptionFrame ExceptionFrame;
#elif defined(__aarch64__)
/**
* CPU trap frame for the current architecture
@ -1145,7 +1206,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

@ -962,7 +962,7 @@ typedef Elf64_Rel Elf_Rel;
typedef Elf64_Sym Elf_Sym;
typedef Elf64_Dyn Elf_Dyn;
typedef Elf64_Rela Elf_Rela;
#elif defined(__i386__)
#elif defined(__i386__) || defined(__arm__)
typedef Elf32_Addr Elf_Addr;
typedef Elf32_Half Elf_Half;
typedef Elf32_Off Elf_Off;

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

@ -59,7 +59,7 @@
#define USER_STACK_END 0xFFFFEFFF00000000 /* 256 MiB */
#define USER_STACK_BASE 0xFFFFEFFFFFFF0000
#elif defined(__i386__)
#elif defined(__i386__) || defined(__arm__)
#define KERNEL_VMA_OFFSET 0xC0000000
#define USER_ALLOC_BASE 0x80000000

View File

@ -60,8 +60,21 @@ typedef struct SyscallsFrame
uint32_t StackPointer;
uint32_t StackSegment;
#elif defined(__aarch64__)
uint32_t ReturnAddress;
uint64_t ReturnAddress; /* x0 */
uint64_t x[30];
uint64_t StackPointer;
uint64_t ExceptionLinkRegister;
uint64_t ExceptionSyndromeRegister;
uint64_t FaultAddressRegister;
uint64_t SavedProgramStatusRegister;
#elif defined(__arm__)
uint32_t ReturnAddress; /* r0 */
uint32_t x[14];
uint32_t StackPointer;
uint32_t ExceptionLinkRegister;
uint32_t ExceptionSyndromeRegister;
uint32_t FaultAddressRegister;
uint32_t SavedProgramStatusRegister;
#endif
uintptr_t ReturnValue() const
@ -71,7 +84,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return ax;
#elif defined(__aarch64__)
return x0;
return x[0];
#endif
}
@ -82,7 +95,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return di;
#elif defined(__aarch64__)
return x0;
return x[0];
#endif
}
@ -93,7 +106,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return cx;
#elif defined(__aarch64__)
return x1;
return x[1];
#endif
}
@ -104,7 +117,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return dx;
#elif defined(__aarch64__)
return x2;
return x[2];
#endif
}
@ -115,7 +128,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return si;
#elif defined(__aarch64__)
return x3;
return x[3];
#endif
}
@ -126,7 +139,7 @@ typedef struct SyscallsFrame
#elif defined(__i386__)
return di;
#elif defined(__aarch64__)
return x4;
return x[4];
#endif
}
@ -137,7 +150,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
@ -552,6 +553,8 @@ namespace Tasking
return x64;
#elif defined(__i386__)
return x32;
#elif defined(__arm__)
return ARM32;
#elif defined(__aarch64__)
return ARM64;
#endif

View File

@ -171,7 +171,7 @@ typedef uint32_t uid_t;
typedef uint32_t gid_t;
typedef int64_t clock_t;
typedef int32_t pid_t;
#elif defined(__i386__)
#elif defined(__i386__) || defined(__arm__)
typedef int32_t off_t;
typedef long long off64_t;
typedef uint32_t mode_t;

View File

@ -27,4 +27,12 @@
#define DBL_MANT_DIG 24
#define DBL_MAX_10_EXP 38
#define DBL_MAX 3.4028234663852886e+38
#elif __arm__
#define DBL_MANT_DIG __DBL_MANT_DIG__
#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
#define DBL_MAX __DBL_MAX__
#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,14 @@ 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(__arm__)
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

@ -79,13 +79,13 @@ namespace std
[[nodiscard]] void *operator new(std::size_t count);
[[nodiscard]] void *operator new[](std::size_t count);
// [[nodiscard]] void *operator new(std::size_t count, std::align_val_t al);
// [[nodiscard]] void *operator new[](std::size_t count, std::align_val_t al);
[[nodiscard]] void *operator new(std::size_t count, std::align_val_t al);
[[nodiscard]] void *operator new[](std::size_t count, std::align_val_t al);
// [[nodiscard]] void *operator new(std::size_t count, const std::nothrow_t &tag) noexcept;
// [[nodiscard]] void *operator new[](std::size_t count, const std::nothrow_t &tag) noexcept;
// [[nodiscard]] void *operator new(std::size_t count, std::align_val_t al, const std::nothrow_t &) noexcept;
// [[nodiscard]] void *operator new[](std::size_t count, std::align_val_t al, const std::nothrow_t &) noexcept;
[[nodiscard]] void *operator new(std::size_t count, const std::nothrow_t &tag) noexcept;
[[nodiscard]] void *operator new[](std::size_t count, const std::nothrow_t &tag) noexcept;
[[nodiscard]] void *operator new(std::size_t count, std::align_val_t al, const std::nothrow_t &) noexcept;
[[nodiscard]] void *operator new[](std::size_t count, std::align_val_t al, const std::nothrow_t &) noexcept;
[[nodiscard]] void *operator new(std::size_t count, void *ptr) noexcept;
[[nodiscard]] void *operator new[](std::size_t count, void *ptr) noexcept;

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

@ -62,7 +62,7 @@ EXTERNC int strncmp(const char *s1, const char *s2, size_t n)
return 0;
}
EXTERNC long unsigned strlen(const char s[])
EXTERNC size_t strlen(const char s[])
{
if (Config.SIMD)
{

View File

@ -192,7 +192,9 @@ extern "C" __noreturn void __cxa_throw(void *thrown_object,
Exception->terminateHandler = &terminate_header_stub;
Exception->unwindHeader.exception_cleanup = &exception_cleanup_stub;
INIT_EXCEPTION_CLASS(&Exception->unwindHeader.exception_class);
#ifndef __arm__
Exception->adjustedPtr = thrown_object;
#endif
_Unwind_RaiseException(&Exception->unwindHeader);
__cxa_begin_catch(&Exception->unwindHeader);

View File

@ -134,7 +134,7 @@ void md5Finalize(MD5Context *ctx)
(uint32_t)(ctx->input[(j * 4)]);
}
input[14] = (uint32_t)(ctx->size * 8);
#ifdef __i386__
#if defined(__i386__) || defined(__arm__)
input[15] = (uint32_t)((uint64_t)(((uint64_t)ctx->size >> 32) | ((uint64_t)ctx->size << 32)) >> 32);
#else
input[15] = (uint32_t)((ctx->size * 8) >> 32);

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

@ -42,8 +42,37 @@ void *operator new[](std::size_t count)
throw std::bad_alloc{};
}
// void *operator new(std::size_t count, std::align_val_t al)
// void *operator new[](std::size_t count, std::align_val_t al)
void *operator new(std::size_t count, std::align_val_t al)
{
if (count == 0)
++count;
std::size_t alignment = static_cast<std::size_t>(al);
void *ptr = kmalloc(count + alignment - 1 + sizeof(void *));
if (!ptr)
throw std::bad_alloc{};
void *aligned_ptr = reinterpret_cast<void *>(
(reinterpret_cast<std::size_t>(ptr) + sizeof(void *) + alignment - 1) & ~(alignment - 1));
reinterpret_cast<void **>(aligned_ptr)[-1] = ptr;
return aligned_ptr;
}
void *operator new[](std::size_t count, std::align_val_t al)
{
if (count == 0)
++count;
std::size_t alignment = static_cast<std::size_t>(al);
void *ptr = kmalloc(count + alignment - 1 + sizeof(void *));
if (!ptr)
throw std::bad_alloc{};
void *aligned_ptr = reinterpret_cast<void *>(
(reinterpret_cast<std::size_t>(ptr) + sizeof(void *) + alignment - 1) & ~(alignment - 1));
reinterpret_cast<void **>(aligned_ptr)[-1] = ptr;
return aligned_ptr;
}
// void *operator new(std::size_t count, const std::nothrow_t &tag)
// void *operator new[](std::size_t count, const std::nothrow_t &tag)
@ -62,8 +91,24 @@ void operator delete(void *ptr) noexcept { kfree(ptr); }
void operator delete[](void *ptr) noexcept { kfree(ptr); }
// void operator delete(void *ptr, std::align_val_t al) noexcept
// void operator delete[](void *ptr, std::align_val_t al) noexcept
void operator delete(void *ptr, std::align_val_t al) noexcept
{
if (!ptr)
return;
void *original_ptr = reinterpret_cast<void **>(ptr)[-1];
kfree(original_ptr);
}
void operator delete[](void *ptr, std::align_val_t al) noexcept
{
if (!ptr)
return;
void *original_ptr = reinterpret_cast<void **>(ptr)[-1];
kfree(original_ptr);
}
void operator delete(void *ptr, std::size_t) noexcept { kfree(ptr); }
void operator delete[](void *ptr, std::size_t sz) noexcept { kfree(ptr); }

View File

@ -314,6 +314,44 @@ 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];
#elif defined(__arm__)
__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;
#else
#error "Unsupported architecture"
#endif
@ -351,7 +389,7 @@ struct __old_kernel_stat
unsigned short st_uid;
unsigned short st_gid;
unsigned short st_rdev;
#ifdef __i386__
#if defined(__i386__) || defined(__arm__)
unsigned long st_size;
unsigned long st_atime;
unsigned long st_mtime;

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))
@ -1090,6 +1091,7 @@ static int linux_mprotect(SysFrm *, void *addr, size_t len, int prot)
pte->UserSupervisor = p_Read;
pte->ReadWrite = p_Write;
// 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;
}
@ -613,9 +610,11 @@ namespace Tasking
}
// 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++)
@ -482,6 +483,7 @@ namespace KernelConsole
// ;
// 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

@ -66,6 +66,15 @@ QEMUFLAGS += -M q35 \
-device intel-hda \
-device ich9-intel-hda \
-acpitable file=tools/acpi/SSDT1.dat
else ifeq ($(OSARCH), arm)
QEMUFLAGS += -M raspi2b \
-monitor pty \
-cpu cortex-a15 \
-serial file:serial.log \
-serial file:COM2.dmp \
-serial file:COM3.dmp \
-serial stdio \
-kernel $(OSNAME).img
else ifeq ($(OSARCH), aarch64)
QEMUFLAGS += -M raspi3b \
-monitor pty \
@ -74,8 +83,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:
@ -161,7 +169,7 @@ ifeq ($(BOOTLOADER), grub)
cp tools/grub.cfg iso_tmp_data/boot/grub/
grub-mkrescue -o $(OSNAME).iso iso_tmp_data
endif
ifeq ($(OSARCH), aarch64)
ifneq ($(filter aarch64 arm,$(OSARCH)),)
$(__CONF_OBJCOPY) Kernel/fennix.elf -O binary $(OSNAME).img
endif
@ -180,6 +188,10 @@ ifeq ($(OSARCH), i386)
QEMU_SMP = -smp $(shell nproc)
endif
ifeq ($(OSARCH), arm)
QEMU_SMP = -smp 4
endif
ifeq ($(OSARCH), aarch64)
QEMU_SMP = -smp 4
endif
@ -190,6 +202,9 @@ QEMUMEMORY = -m 4G
else ifeq ($(OSARCH), i386)
QEMUHWACCELERATION = -machine q35 -enable-kvm
QEMUMEMORY = -m 4G
else ifeq ($(OSARCH), arm)
QEMUHWACCELERATION =
QEMUMEMORY = -m 1G
else ifeq ($(OSARCH), aarch64)
QEMUHWACCELERATION =
QEMUMEMORY = -m 1G

View File

@ -81,6 +81,48 @@
"-nostdinc",
"-nostdinc++"
]
},
{
"name": "Fennix Arm (Linux, GCC, debug)",
"includePath": [
"${workspaceFolder}/libc/include/**",
"${workspaceFolder}/libs/include/**"
],
"defines": [
"__debug_vscode__",
"DEBUG=\"1\""
],
"compilerPath": "${workspaceFolder}/../tools/cross/bin/arm-fennix-gcc",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-arm",
"configurationProvider": "ms-vscode.makefile-tools",
"compilerArgs": [
"-ffreestanding",
"-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

@ -50,7 +50,7 @@ extern "C"
#define P_tmpdir "/tmp/"
typedef long fpos_t;
typedef unsigned long size_t;
typedef __SIZE_TYPE__ size_t;
struct _IO_FILE
{

View File

@ -46,7 +46,7 @@ extern "C"
long rem;
} ldiv_t;
typedef unsigned long size_t;
typedef __SIZE_TYPE__ size_t;
// typedef __WCHAR_TYPE__ wchar_t;
long a64l(const char *);

View File

@ -108,7 +108,7 @@ extern "C"
char __data;
} pthread_barrier_t;
typedef unsigned long size_t;
typedef __SIZE_TYPE__ size_t;
typedef long ssize_t;
typedef long suseconds_t;

View File

@ -182,6 +182,22 @@ 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,
R_ARM_NONE = 0,
R_ARM_COPY = 1024,
R_ARM_GLOB_DAT = 1025,
R_ARM_JUMP_SLOT = 1026,
R_ARM_RELATIVE = 1027,
R_ARM_TLS_DTPMOD32 = 1028,
R_ARM_TLS_DTPOFF32 = 1029,
R_ARM_TLS_TPOFF32 = 1030,
#if defined(__x86_64__)
R_NONE = R_X86_64_NONE,
R_COPY = R_X86_64_COPY,
@ -200,6 +216,24 @@ 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,
#elif defined(__arm__)
R_NONE = R_ARM_NONE,
R_COPY = R_ARM_COPY,
R_GLOB_DAT = R_ARM_GLOB_DAT,
R_JMP_SLOT = R_ARM_JUMP_SLOT,
R_RELATIVE = R_ARM_RELATIVE,
R_DTPMOD64 = R_ARM_TLS_DTPMOD32,
R_DTPOFF64 = R_ARM_TLS_DTPOFF32,
R_TPOFF64 = R_ARM_TLS_TPOFF32,
#endif
};
@ -986,7 +1020,7 @@ typedef Elf64_Rela Elf_Rela;
#define ELF_ST_BIND(info) ELF64_ST_BIND(info)
#define ELF_ST_TYPE(info) ELF64_ST_TYPE(info)
#define ELF_ST_INFO(bind, type) ELF64_ST_INFO(bind, type)
#elif defined(__i386__)
#elif defined(__i386__) || defined(__arm__)
typedef Elf32_Addr Elf_Addr;
typedef Elf32_Half Elf_Half;
typedef Elf32_Off Elf_Off;

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,10 @@ __attribute__((naked, used, no_stack_protector)) void _start()
"call _exit\n"); /* Call _exit */
#elif defined(__i386__)
#warning "i386 _start not implemented"
#elif defined(__arm__)
#warning "arm _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,10 @@ __attribute__((naked, used, no_stack_protector, section(".text"))) void _start()
"call _exit\n");
#elif defined(__i386__)
#warning "i386 _start not implemented"
#elif defined(__arm__)
#warning "arm _start not implemented"
#elif defined(__aarch64__)
#warning "aarch64 _start not implemented"
#else
#error "Unsupported architecture"
#endif

View File

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

View File

@ -0,0 +1,194 @@
/*
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;
}
int __aeabi_dcmple(long double a, long double b)
{
return a <= b;
}
long long __aeabi_d2lz(double a)
{
return (long long)a;
}
int __aeabi_dcmplt(long double a, long double b)
{
return a < b;
}
typedef union
{
double d;
struct
{
__UINT64_TYPE__ mantissa : 52;
__UINT64_TYPE__ exponent : 11;
__UINT64_TYPE__ sign : 1;
} parts;
} aeabi_double_t;
aeabi_double_t __aeabi_ddiv(aeabi_double_t a, aeabi_double_t b)
{
aeabi_double_t result;
result.d = a.d / b.d;
return result;
}
aeabi_double_t __aeabi_dmul(aeabi_double_t a, aeabi_double_t b)
{
aeabi_double_t result;
result.d = a.d * b.d;
return result;
}
aeabi_double_t __aeabi_dadd(aeabi_double_t a, aeabi_double_t b)
{
aeabi_double_t result;
result.d = a.d + b.d;
return result;
}
int __aeabi_dcmpgt(aeabi_double_t a, aeabi_double_t b)
{
return a.d > b.d;
}
int __aeabi_dcmpge(aeabi_double_t a, aeabi_double_t b)
{
return a.d >= b.d;
}
aeabi_double_t __aeabi_dsub(aeabi_double_t a, aeabi_double_t b)
{
aeabi_double_t result;
result.d = a.d - b.d;
return result;
}
aeabi_double_t __aeabi_i2d(int a)
{
aeabi_double_t result;
result.d = (double)a;
return result;
}
aeabi_double_t __aeabi_l2d(long long a)
{
aeabi_double_t result;
result.d = (double)a;
return result;
}
int __aeabi_dcmpeq(aeabi_double_t a, aeabi_double_t b)
{
return a.d == b.d;
}
int __aeabi_d2iz(aeabi_double_t a)
{
return (int)a.d;
}
struct ldivmod_result
{
long quot;
long rem;
};
struct ldivmod_result __aeabi_ldivmod(long numerator, long denominator)
{
struct ldivmod_result result;
result.quot = numerator / denominator;
result.rem = numerator % denominator;
return result;
}
signed __aeabi_idiv(signed numerator, signed denominator)
{
return numerator / denominator;
}
signed __aeabi_idivmod(signed numerator, signed denominator)
{
signed quotient = numerator / denominator;
signed remainder = numerator % denominator;
return (quotient << 16) | remainder;
}
unsigned __aeabi_uidiv(unsigned numerator, unsigned denominator)
{
return numerator / denominator;
}
unsigned __aeabi_uidivmod(unsigned numerator, unsigned denominator)
{
unsigned quotient = numerator / denominator;
unsigned remainder = numerator % denominator;
return (quotient << 16) | remainder;
}
__UINT64_TYPE__ __udivmoddi4(__UINT64_TYPE__ numerator, __UINT64_TYPE__ denominator, __UINT64_TYPE__ *remainder)
{
__UINT64_TYPE__ quotient = 0;
__UINT64_TYPE__ bit = 1;
if (denominator == 0)
{
*remainder = numerator;
return ~0ULL;
}
while (denominator < numerator && (denominator & (1ULL << 63)) == 0)
{
denominator <<= 1;
bit <<= 1;
}
while (bit)
{
if (numerator >= denominator)
{
numerator -= denominator;
quotient |= bit;
}
denominator >>= 1;
bit >>= 1;
}
if (remainder)
*remainder = numerator;
return quotient;
}
struct udivmod_result
{
__UINT64_TYPE__ quot;
__UINT64_TYPE__ rem;
};
struct udivmod_result __aeabi_uldivmod(__UINT64_TYPE__ numerator, __UINT64_TYPE__ denominator)
{
struct udivmod_result result;
result.quot = __udivmoddi4(numerator, denominator, &result.rem);
return result;
}

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