This commit is contained in:
Niklas Gollenstede
2025-10-31 22:37:36 +01:00
commit 174fe17e89
197 changed files with 79558 additions and 0 deletions

46
kernel/compiler/libc.cc Normal file
View File

@@ -0,0 +1,46 @@
#include "libc.h"
/*! \brief Function pointer for initialization/finalization functions for global
* objects required since GCC 4.7 and later.
*
* These symbols appear kind of magically due to the compiler
*/
extern void (*__preinit_array_start[])();
extern void (*__preinit_array_end[])();
extern void (*__init_array_start[])();
extern void (*__init_array_end[])();
extern void (*__fini_array_start[])();
extern void (*__fini_array_end[])();
namespace CSU {
void initializer() {
const unsigned int preinit_size =
__preinit_array_end - __preinit_array_start;
for (unsigned int i = 0; i != preinit_size; ++i) {
(*__preinit_array_start[i])();
}
const size_t size = __init_array_end - __init_array_start;
for (size_t i = 0; i < size; i++) {
(*__init_array_start[i])();
}
}
void finalizer() {
const unsigned int fini_size = __fini_array_end - __fini_array_start;
for (unsigned int i = 0; i != fini_size; ++i) {
(*__fini_array_start[i])();
}
}
} // namespace CSU
extern "C" int atexit(void (*func)(void)) {
// Registers a function that will be executed on exit.
// We simply ignore those functions, as we don't need them for our operating
// systems.
(void)func;
return 0;
}

23
kernel/compiler/libc.h Normal file
View File

@@ -0,0 +1,23 @@
/*! \file
* \brief Initialization functions for global objects required by the compiler
*/
#pragma once
#include "types.h"
/*! \brief C StartUp (CSU)
* required by the compiler and provided by the c standard library
*/
namespace CSU {
/*! \brief Call global constructors and initialization functions
* (this is usually done by __libc_csu_init)
*/
void initializer();
/*! \brief Call global destructors and finalizer functions
* (this is usually done by __libc_csu_fini)
*/
void finalizer();
} // namespace CSU

33
kernel/compiler/libcxx.cc Normal file
View File

@@ -0,0 +1,33 @@
/*! \file
* \brief C++ runtime support functions
*/
#include "../debug/assert.h"
#include "../types.h"
void* operator new([[maybe_unused]] size_t size, void* place) { return place; }
void* operator new(size_t size) {
(void)size;
assert(!"Memory allocation not supported");
}
void* operator new[](size_t size) {
(void)size;
assert(!"Memory allocation not supported");
}
void operator delete(void* ptr) { (void)ptr; }
void operator delete(void* ptr, [[maybe_unused]] size_t size) {
operator delete(ptr);
}
void operator delete[](void* ptr) { operator delete(ptr); }
void operator delete[](void* ptr, size_t size) { operator delete(ptr, size); }
extern "C" [[noreturn]] void __cxa_pure_virtual() {
// Pure virtual function was called -- this if obviously not valid,
// therefore we wait infinitely.
while (true) {
}
}

106
kernel/compiler/sections.ld Normal file
View File

@@ -0,0 +1,106 @@
/* Entry in our OS -- label 'startup_bsp' in file boot/startup.asm */
ENTRY(startup_bsp)
SECTIONS
{
/* start address of our kernel */
. = 16M;
___KERNEL_START___ = .;
.boot :
{
/* Multiboot Header should be at the very beginning */
*(.multiboot_header)
}
.text :
{
*(".text")
*(".text$")
*(".init")
*(".fini")
*(".gnu.linkonce.*")
KEEP(*(.note.gnu.build-id))
}
/* lists containing the start address of global constructors and destructors (generated by the compiler) */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
}
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.data :
{
*(".data")
*(".data$")
*(".rodata")
___CTOR_LIST__ = .;
*(".ctors")
*(".ctor")
___CTOR_LIST_END__ = .;
___DTOR_LIST__ = .;
*(".dtors")
*(".dtor")
___DTOR_LIST_END__ = .;
*(".got")
*(".got.plt")
*(".eh_frame")
*(".eh_fram")
*(".jcr")
}
/* Start for application processors, relocated by APIC::init()
* to a below 1 MB address to boot from real mode.
* It is possible to let the linker place it at a below 1 MB address,
* while all the rest starts at 16 MB. This will work for multiboot
* compliant boot loader like GRUB and PXELINUX, however,
* the qemu boot loader cannot handle such ELF files (yet)...
* That's why we have to do it in our software */
.setup_ap_seg ALIGN(0x10) :
{
___SETUP_AP_START__ = .;
*(".setup_ap_seg")
*(".setup_ap_seg$")
}
___SETUP_AP_END__ = .;
.bss :
{
*(".bss")
*(".bss.*")
*(COMMON)
}
___KERNEL_END___ = .;
/DISCARD/ :
{
*(".note")
*(".comment")
/* Keep debug information
*(".debug_line")
*(".debug_info")
*(".debug_abbrev")
*(".debug_aranges")
*/
}
}