This commit is contained in:
Niklas Gollenstede
2025-04-14 11:20:52 +02:00
commit 5a2e32aaeb
126 changed files with 16742 additions and 0 deletions

13
compiler/fix.h Normal file
View File

@@ -0,0 +1,13 @@
/*! \file
* \brief Compiler-dependent fixes & idiosyncrasies
*/
#pragma once
#include "../types.h"
#if defined(__GNUC__) && !defined(__clang__)
// Only GCC understands the error attribute
#define ERROR_ON_CALL(MSG) __attribute__((error(MSG)));
#else
#define ERROR_ON_CALL(MSG)
#endif

45
compiler/libc.cc Normal file
View File

@@ -0,0 +1,45 @@
#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
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

21
compiler/libcxx.cc Normal file
View File

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

107
compiler/sections.ld Normal file
View File

@@ -0,0 +1,107 @@
/* 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)
}
___KERNEL_TEXT_START___ = .;
.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 = .);
}
___KERNEL_TEXT_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")
*/
}
}