Merge remote-tracking branch 'Kernel/master'

This commit is contained in:
EnderIce2
2024-11-20 05:00:33 +02:00
468 changed files with 112800 additions and 1 deletions

113
Kernel/profiling/cyg.cpp Normal file
View File

@ -0,0 +1,113 @@
/*
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 <printf.h>
#include <uart.hpp>
#include "../kernel.h"
bool EnableProfiler = false;
bool Wait = false;
unsigned long long LogDepth = 0;
unsigned int Level = 0;
using namespace UniversalAsynchronousReceiverTransmitter;
UART com2(COM2);
static inline nsa NIF void profiler_uart_wrapper(char c, void *unused)
{
bool renable = EnableProfiler;
EnableProfiler = false;
com2.Write(c);
UNUSED(unused);
if (renable)
EnableProfiler = true;
}
EXTERNC nsa NIF void __cyg_profile_func_enter(void *Function, void *CallSite)
{
if (!EnableProfiler)
return;
while (Wait)
#if defined(a86)
asmv("pause");
#elif defined(aa64)
asmv("yield");
#endif
Wait = true;
if (Level > 40)
Level--;
Level++;
if (!KernelSymbolTable)
fctprintf(profiler_uart_wrapper, nullptr, "%lld [%02d]: \033[42m->\033[0m%*c \033[33m%p\033[0m - \033[33m%p\033[0m\n",
LogDepth++,
Level - 1,
Level,
' ',
Function,
CallSite);
else
fctprintf(profiler_uart_wrapper, nullptr, "%lld [%02d]: \033[42m->\033[0m%*c \033[33m%s\033[0m - \033[33m%s\033[0m\n",
LogDepth++,
Level - 1,
Level,
' ',
KernelSymbolTable->GetSymbol((uintptr_t)Function),
KernelSymbolTable->GetSymbol((uintptr_t)CallSite));
Wait = false;
}
EXTERNC nsa NIF void __cyg_profile_func_exit(void *Function, void *CallSite)
{
if (!EnableProfiler)
return;
while (Wait)
#if defined(a86)
asmv("pause");
#elif defined(aa64)
asmv("yield");
#endif
Wait = true;
if (Level > 40)
Level--;
Level--;
if (!KernelSymbolTable)
fctprintf(profiler_uart_wrapper, nullptr, "%lld [%02d]: \033[41m<-\033[0m%*c \033[33m%p\033[0m - \033[33m%p\033[0m\n",
LogDepth++,
Level - 1,
Level,
' ',
Function,
CallSite);
else
fctprintf(profiler_uart_wrapper, nullptr, "%lld [%02d]: \033[41m<-\033[0m%*c \033[33m%s\033[0m - \033[33m%s\033[0m\n",
LogDepth++,
Level - 1,
Level,
' ',
KernelSymbolTable->GetSymbol((uintptr_t)Function),
KernelSymbolTable->GetSymbol((uintptr_t)CallSite));
Wait = false;
}

88
Kernel/profiling/gcov.cpp Normal file
View File

@ -0,0 +1,88 @@
/*
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 <printf.h>
#include <uart.hpp>
#include "../kernel.h"
using namespace UniversalAsynchronousReceiverTransmitter;
#if BITS_PER_LONG >= 64
typedef long gcov_type;
#else
typedef long long gcov_type;
#endif
struct gcov_fn_info
{
unsigned int ident;
unsigned int checksum;
unsigned int n_ctrs[0];
};
struct gcov_ctr_info
{
unsigned int num;
gcov_type *values;
void (*merge)(gcov_type *, unsigned int);
};
struct gcov_info
{
unsigned int version;
struct gcov_info *next;
unsigned int stamp;
const char *filename;
unsigned int n_functions;
const struct gcov_fn_info *functions;
unsigned int ctr_mask;
struct gcov_ctr_info counts[0];
};
static inline nsa NIF void gcov_uart_wrapper(char c, void *unused)
{
UART(COM2).Write(c);
UNUSED(unused);
}
// TODO: Implement
EXTERNC nsa NIF void __gcov_init(gcov_info *p __unused)
{
}
EXTERNC nsa NIF void __gcov_exit(void)
{
}
EXTERNC nsa NIF void __gcov_flush(void)
{
}
EXTERNC nsa NIF void __gcov_merge_add(gcov_type *counters, unsigned int n_counters)
{
UNUSED(counters);
UNUSED(n_counters);
}
EXTERNC nsa NIF void __gcov_merge_single(gcov_type *counters, unsigned int n_counters)
{
UNUSED(counters);
UNUSED(n_counters);
}

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 <types.h>
#include <printf.h>
#include <uart.hpp>
#include "../kernel.h"
using namespace UniversalAsynchronousReceiverTransmitter;
static inline nsa NIF void gprof_uart_wrapper(char c, void *unused)
{
UART(COM2).Write(c);
UNUSED(unused);
}
EXTERNC nsa NIF void mcount(unsigned long frompc, unsigned long selfpc)
{
// TODO: Implement
/* https://docs.kernel.org/trace/ftrace-design.html */
UNUSED(frompc);
UNUSED(selfpc);
}