Restructured and rewritten entire codebase

This commit is contained in:
Alex
2023-10-09 01:16:24 +03:00
parent 446a571018
commit 889e1522a3
484 changed files with 15683 additions and 14032 deletions

View File

@ -0,0 +1,103 @@
/*
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 <typeinfo>
#include <debug.h>
namespace __cxxabiv1
{
__class_type_info::~__class_type_info() {}
bool __class_type_info::__do_upcast(const __class_type_info *Destination,
const void *Object,
__upcast_result &__restrict Result) const
{
if (*this != *Destination)
return false;
Result.dst_ptr = Object;
Result.base_type = nonvirtual_base_type;
Result.part2dst = __contained_public;
return true;
}
bool __class_type_info::__do_upcast(const __class_type_info *DestinationType,
void **ObjectPointer) const
{
__upcast_result Result(__vmi_class_type_info::__flags_unknown_mask);
__do_upcast(DestinationType, *ObjectPointer, Result);
if (!((Result.part2dst &
__class_type_info::__contained_public) ==
__class_type_info::__contained_public))
return false;
*ObjectPointer = const_cast<void *>(Result.dst_ptr);
return true;
}
bool __class_type_info::__do_catch(const type_info *ThrowType,
void **ThrowObject,
unsigned Outer) const
{
if (*this == *ThrowType)
return true;
if (Outer >= 4)
return false;
return ThrowType->__do_upcast(this, ThrowObject);
}
bool __class_type_info::__do_dyncast(ptrdiff_t,
__sub_kind AccessPath,
const __class_type_info *DestinationType,
const void *ObjectPointer,
const __class_type_info *SourceType,
const void *SourcePointer,
__dyncast_result &__restrict Result) const
{
if (ObjectPointer == SourcePointer &&
*this == *SourceType)
{
Result.whole2src = AccessPath;
return false;
}
if (*this == *DestinationType)
{
Result.dst_ptr = ObjectPointer;
Result.whole2dst = AccessPath;
Result.dst2src = __not_contained;
return false;
}
return false;
}
__class_type_info::__sub_kind __class_type_info::__do_find_public_src(ptrdiff_t,
const void *ObjectPointer,
const __class_type_info *,
const void *SourcePointer) const
{
if (SourcePointer == ObjectPointer)
return __contained_public;
return __not_contained;
}
}

View File

@ -0,0 +1,251 @@
/*
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 <cxxabi.h>
#include <memory.hpp>
#include <debug.h>
#include <smp.hpp>
#include "../../kernel.h"
void __dso_handle_stub() { stub; }
/* extern */ void *__dso_handle = (void *)&__dso_handle_stub;
namespace __cxxabiv1
{
atexit_func_entry_t __atexit_funcs[ATEXIT_MAX_FUNCS];
uarch_t __atexit_func_count = 0;
__cxa_eh_globals *__cxa_get_globals() noexcept
{
return &GetCurrentCPU()->EHGlobals;
}
/**
* @param f The destructor
* @param objptr The object to be destructed
* @param dso The DSO from which the object was obtained (unused in our case)
* @return Zero on success, non-zero on failure
*/
extern "C" int __cxa_atexit(void (*f)(void *), void *objptr, void *dso)
{
if (KernelSymbolTable)
{
debug("Registering atexit function for \"%s\" with destructor \"%s\"",
KernelSymbolTable->GetSymbolFromAddress((uintptr_t)objptr),
KernelSymbolTable->GetSymbolFromAddress((uintptr_t)f));
}
else
{
debug("Registering atexit function for %p with destructor %p",
objptr, f);
}
if (__atexit_func_count >= ATEXIT_MAX_FUNCS)
return -1;
__atexit_funcs[__atexit_func_count].destructor_func = f;
__atexit_funcs[__atexit_func_count].obj_ptr = objptr;
__atexit_funcs[__atexit_func_count].dso_handle = dso;
__atexit_func_count++;
return 0;
}
extern "C" void __cxa_finalize(void *f)
{
function("%p", f);
uarch_t i = __atexit_func_count;
if (f == nullptr)
{
while (i--)
{
if (__atexit_funcs[i].destructor_func)
{
if (KernelSymbolTable)
{
debug("Calling atexit function \"%s\"",
KernelSymbolTable->GetSymbolFromAddress((uintptr_t)__atexit_funcs[i].destructor_func));
}
else
{
debug("Calling atexit function %p",
__atexit_funcs[i].destructor_func);
}
(*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr);
}
}
return;
}
while (i--)
{
if (__atexit_funcs[i].destructor_func == f)
{
(*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr);
__atexit_funcs[i].destructor_func = 0;
}
}
}
extern "C" _Unwind_Reason_Code __gxx_personality_v0(int version, _Unwind_Action actions, _Unwind_Exception_Class exception_class, _Unwind_Exception *ue_header, _Unwind_Context *context)
{
fixme("__gxx_personality_v0( %d %p %p %p %p ) called.", version, actions, exception_class, ue_header, context);
return _URC_NO_REASON;
}
extern "C" void *__cxa_begin_catch(void *thrown_object) noexcept
{
function("%p", thrown_object);
__cxa_exception *Exception = (__cxa_exception *)thrown_object - 1;
__cxa_eh_globals *Globals = __cxa_get_globals();
Exception->handlerCount++;
Globals->uncaughtExceptions--;
Exception->nextException = Globals->caughtExceptions;
Globals->caughtExceptions = Exception;
return Exception + 1;
}
extern "C" void __cxa_end_catch()
{
fixme("__cxa_end_catch() called.");
}
static __always_inline inline size_t align_exception_allocation_size(size_t a, size_t b)
{
return (a + b - 1) & ~(b - 1);
}
static __always_inline inline void INIT_EXCEPTION_CLASS(_Unwind_Exception_Class *c)
{
char *ptr = (char *)c;
ptr[0] = 'G';
ptr[1] = 'N';
ptr[2] = 'U';
ptr[3] = 'C';
ptr[4] = 'C';
ptr[5] = '+';
ptr[6] = '+';
ptr[7] = '\0';
}
void unexpected_header_stub() { fixme("unexpected() called."); }
void terminate_header_stub()
{
if (TaskManager && !TaskManager->IsPanic())
{
TaskManager->KillThread(thisThread, Tasking::KILL_CXXABI_EXCEPTION);
TaskManager->Yield();
}
error("No task manager to kill thread!");
CPU::Stop(); /* FIXME: Panic */
}
void exception_cleanup_stub(_Unwind_Reason_Code Code,
_Unwind_Exception *Exception)
{
fixme("exception_cleanup( %d %p ) called.",
Code, Exception);
}
extern "C" void *__cxa_allocate_exception(size_t thrown_size) throw()
{
debug("Allocating exception of size %d.", thrown_size);
size_t alloc_size = align_exception_allocation_size(thrown_size + sizeof(__cxa_exception), alignof(__cxa_exception));
__cxa_exception *Exception = (__cxa_exception *)kmalloc(alloc_size);
memset(Exception, 0, alloc_size);
return Exception + 1;
}
extern "C" __noreturn void __cxa_throw(void *thrown_object,
std::type_info *tinfo,
void (*dest)(void *))
{
trace("Throwing exception of type \"%s\". ( object: %p, destructor: %p )",
tinfo->name(), thrown_object, dest);
__cxa_eh_globals *Globals = __cxa_get_globals();
Globals->uncaughtExceptions++;
__cxa_exception *Exception = (__cxa_exception *)thrown_object - 1;
Exception->exceptionType = (std::type_info *)tinfo;
Exception->exceptionDestructor = dest;
Exception->unexpectedHandler = &unexpected_header_stub;
Exception->terminateHandler = &terminate_header_stub;
Exception->unwindHeader.exception_cleanup = &exception_cleanup_stub;
INIT_EXCEPTION_CLASS(&Exception->unwindHeader.exception_class);
Exception->adjustedPtr = thrown_object;
_Unwind_RaiseException(&Exception->unwindHeader);
__cxa_begin_catch(&Exception->unwindHeader);
error("Uncaught exception!");
CPU::Stop(); /* FIXME: Panic */
}
extern "C" void __cxa_rethrow()
{
fixme("__cxa_rethrow() called.");
}
extern "C" void __cxa_pure_virtual()
{
fixme("__cxa_pure_virtual() called.");
}
extern "C" void __cxa_throw_bad_array_new_length()
{
fixme("__cxa_throw_bad_array_new_length() called.");
}
extern "C" void __cxa_free_exception(void *thrown_exception)
{
fixme("__cxa_free_exception( %p ) called.",
thrown_exception);
}
__extension__ typedef int __guard __attribute__((mode(__DI__)));
extern "C" int __cxa_guard_acquire(__guard *g)
{
fixme("__cxa_guard_acquire( %p ) called.", g);
return !*(char *)(g);
}
extern "C" void __cxa_guard_release(__guard *g)
{
fixme("__cxa_guard_release( %p ) called.", g);
*(char *)g = 1;
}
extern "C" void __cxa_guard_abort(__guard *g)
{
fixme("__cxa_guard_abort( %p ) called.", g);
}
extern "C" __noreturn void __cxa_bad_typeid()
{
fixme("__cxa_bad_typeid() called.");
CPU::Stop(); /* FIXME: Crash the system */
}
}

View File

@ -0,0 +1,23 @@
/*
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 <typeinfo>
namespace __cxxabiv1
{
__fundamental_type_info::~__fundamental_type_info() {}
}

View File

@ -0,0 +1,91 @@
/*
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 <typeinfo>
namespace __cxxabiv1
{
__pbase_type_info::~__pbase_type_info() {}
bool __pbase_type_info::__do_catch(const type_info *ThrowType,
void **ThrowObject,
unsigned outer) const
{
#ifndef __GXX_RTTI
UNUSED(ThrowType);
UNUSED(ThrowObject);
UNUSED(outer);
return false;
#else
if (*this == *ThrowType)
return true;
if (*ThrowType == typeid(nullptr))
{
if (typeid(*this) == typeid(__pointer_type_info))
{
*ThrowObject = nullptr;
return true;
}
else if (typeid(*this) == typeid(__pointer_to_member_type_info))
{
if (this->Pointee->__is_function_p())
{
using pmf_type = void (__pbase_type_info::*)();
static const pmf_type pmf = nullptr;
*ThrowObject = const_cast<pmf_type *>(&pmf);
return true;
}
else
{
using pm_type = int __pbase_type_info::*;
static const pm_type pm = nullptr;
*ThrowObject = const_cast<pm_type *>(&pm);
return true;
}
}
}
if (typeid(*this) != typeid(*ThrowType))
return false;
if (!(outer & 1))
return false;
const __pbase_type_info *ThrownType =
static_cast<const __pbase_type_info *>(ThrowType);
unsigned TypeFlags = ThrownType->Flags;
const unsigned FlagQualificationMask = __transaction_safe_mask | __noexcept_mask;
unsigned ThrowFlagQualification = (TypeFlags & FlagQualificationMask);
unsigned CatchFlagQualification = (Flags & FlagQualificationMask);
if (ThrowFlagQualification & ~CatchFlagQualification)
TypeFlags &= CatchFlagQualification;
if (CatchFlagQualification & ~ThrowFlagQualification)
return false;
if (TypeFlags & ~Flags)
return false;
if (!(Flags & __const_mask))
outer &= ~1;
return __pointer_catch(ThrownType, ThrowObject, outer);
#endif
}
}

View File

@ -0,0 +1,45 @@
/*
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 <typeinfo>
namespace __cxxabiv1
{
__pointer_type_info::~__pointer_type_info() {}
bool __pointer_type_info::__is_pointer_p() const { return true; }
bool __pointer_type_info::__pointer_catch(const __pbase_type_info *ThrownType,
void **ThrowObject,
unsigned Outer) const
{
#ifndef __GXX_RTTI
UNUSED(ThrownType);
UNUSED(ThrowObject);
UNUSED(Outer);
return false;
#else
if (Outer < 2 && *this->Pointee == typeid(void))
return !ThrownType->Pointee->__is_function_p();
return __pbase_type_info::__pointer_catch(ThrownType,
ThrowObject,
Outer);
#endif
}
}

View File

@ -0,0 +1,102 @@
/*
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 <typeinfo>
#include <debug.h>
namespace __cxxabiv1
{
template <typename T>
inline const T *adjust_pointer(const void *Base,
ptrdiff_t Offset)
{
return reinterpret_cast<const T *>(reinterpret_cast<const char *>(Base) + Offset);
}
__si_class_type_info::~__si_class_type_info() {}
__class_type_info::__sub_kind __si_class_type_info::
__do_find_public_src(ptrdiff_t SourceToDestination,
const void *ObjectPointer,
const __class_type_info *SourceType,
const void *SourcePointer) const
{
if (SourcePointer == ObjectPointer && *this == *SourceType)
return __contained_public;
return this->BaseType->__do_find_public_src(SourceToDestination,
ObjectPointer,
SourceType,
SourcePointer);
}
bool __si_class_type_info::__do_dyncast(ptrdiff_t SourceToDestination,
__sub_kind AccessPath,
const __class_type_info *DestinationType,
const void *ObjectPointer,
const __class_type_info *SourceType,
const void *SourcePointer,
__dyncast_result &__restrict Result) const
{
if (*this == *DestinationType)
{
Result.dst_ptr = ObjectPointer;
Result.whole2dst = AccessPath;
if (SourceToDestination == -2)
{
Result.dst2src = __not_contained;
return false;
}
if (SourceToDestination >= 0)
{
Result.dst2src = adjust_pointer<void>(ObjectPointer,
SourceToDestination) == SourcePointer
? __contained_public
: __not_contained;
}
return false;
}
if (ObjectPointer == SourcePointer &&
*this == *SourceType)
{
Result.whole2src = AccessPath;
return false;
}
return this->BaseType->__do_dyncast(SourceToDestination,
AccessPath,
DestinationType,
ObjectPointer,
SourceType,
SourcePointer,
Result);
}
bool __si_class_type_info::__do_upcast(const __class_type_info *Destination,
const void *ObjectPointer,
__upcast_result &__restrict Result) const
{
if (__class_type_info::__do_upcast(Destination, ObjectPointer, Result))
return true;
return this->BaseType->__do_upcast(Destination, ObjectPointer, Result);
}
}

View File

@ -0,0 +1,41 @@
/*
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 <unwind.h>
#include <cxxabi.h>
#include <debug.h>
#include <cpu.hpp>
#include <smp.hpp>
#include "../../kernel.h"
using namespace __cxxabiv1;
#if (1) /* Stubs if libgcc is not present */
extern "C" _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception *Exception)
{
fixme("_Unwind_RaiseException( %p ) called.", Exception);
error("Unhandled exception.");
return _URC_FATAL_PHASE1_ERROR;
// return _URC_NO_REASON;
}
extern "C" void _Unwind_Resume(struct _Unwind_Exception *Exception)
{
fixme("_Unwind_Resume( %p ) called.", Exception);
}
#endif