diff --git a/Kernel/arch/amd64/bootstrap/limine/limine.c b/Kernel/arch/amd64/bootstrap/limine/limine.c index d2c1678d..b5b34662 100644 --- a/Kernel/arch/amd64/bootstrap/limine/limine.c +++ b/Kernel/arch/amd64/bootstrap/limine/limine.c @@ -92,7 +92,7 @@ __naked __used __no_stack_protector void InitLimine() asmv("jmp InitLimineAfterStack"); } -nsa NIF void InitLimineAfterStack() +nsa nif void InitLimineAfterStack() { struct BootInfo binfo = {}; struct limine_bootloader_info_response *BootloaderInfoResponse = BootloaderInfoRequest.response; diff --git a/Kernel/arch/amd64/bootstrap/multiboot/Paging/mb_64bit_map.cpp b/Kernel/arch/amd64/bootstrap/multiboot/Paging/mb_64bit_map.cpp index 0c55959d..b394b602 100644 --- a/Kernel/arch/amd64/bootstrap/multiboot/Paging/mb_64bit_map.cpp +++ b/Kernel/arch/amd64/bootstrap/multiboot/Paging/mb_64bit_map.cpp @@ -38,14 +38,14 @@ union __attribute__((packed)) PageTableEntry }; uint64_t raw; - __always_inline inline nsa NIF void SetAddress(uintptr_t _Address) + __always_inline inline nsa nif void SetAddress(uintptr_t _Address) { _Address &= 0x000000FFFFFFFFFF; this->raw &= 0xFFF0000000000FFF; this->raw |= (_Address << 12); } - __always_inline inline nsa NIF uintptr_t GetAddress() { return (this->raw & 0x000FFFFFFFFFF000) >> 12; } + __always_inline inline nsa nif uintptr_t GetAddress() { return (this->raw & 0x000FFFFFFFFFF000) >> 12; } }; struct __attribute__((packed)) PageTableEntryPtr @@ -72,14 +72,14 @@ union __attribute__((packed)) PageDirectoryEntry }; uint64_t raw; - __always_inline inline nsa NIF void SetAddress(uintptr_t _Address) + __always_inline inline nsa nif void SetAddress(uintptr_t _Address) { _Address &= 0x000000FFFFFFFFFF; this->raw &= 0xFFF0000000000FFF; this->raw |= (_Address << 12); } - __always_inline inline nsa NIF uintptr_t GetAddress() { return (this->raw & 0x000FFFFFFFFFF000) >> 12; } + __always_inline inline nsa nif uintptr_t GetAddress() { return (this->raw & 0x000FFFFFFFFFF000) >> 12; } }; struct __attribute__((packed)) PageDirectoryEntryPtr @@ -106,14 +106,14 @@ union __attribute__((packed)) PageDirectoryPointerTableEntry }; uint64_t raw; - __always_inline inline nsa NIF void SetAddress(uintptr_t _Address) + __always_inline inline nsa nif void SetAddress(uintptr_t _Address) { _Address &= 0x000000FFFFFFFFFF; this->raw &= 0xFFF0000000000FFF; this->raw |= (_Address << 12); } - __always_inline inline nsa NIF uintptr_t GetAddress() { return (this->raw & 0x000FFFFFFFFFF000) >> 12; } + __always_inline inline nsa nif uintptr_t GetAddress() { return (this->raw & 0x000FFFFFFFFFF000) >> 12; } }; struct __attribute__((packed)) PageDirectoryPointerTableEntryPtr @@ -140,14 +140,14 @@ union __attribute__((packed)) PageMapLevel4 }; uint64_t raw; - __always_inline inline nsa NIF void SetAddress(uintptr_t _Address) + __always_inline inline nsa nif void SetAddress(uintptr_t _Address) { _Address &= 0x000000FFFFFFFFFF; this->raw &= 0xFFF0000000000FFF; this->raw |= (_Address << 12); } - __always_inline inline nsa NIF uintptr_t GetAddress() { return (this->raw & 0x000FFFFFFFFFF000) >> 12; } + __always_inline inline nsa nif uintptr_t GetAddress() { return (this->raw & 0x000FFFFFFFFFF000) >> 12; } }; struct PageTable4 @@ -161,7 +161,7 @@ extern uintptr_t _kernel_start, _kernel_end; __attribute__((section(".bootstrap.data"))) static PageTable4 *BPTable = (PageTable4 *)BootPageTable; __attribute__((section(".bootstrap.data"))) static size_t BPT_Allocated = 0x4000; -__always_inline inline nsa NIF void *RequestPage() +__always_inline inline nsa nif void *RequestPage() { void *Page = (void *)(BootPageTable + BPT_Allocated); BPT_Allocated += 0x1000; @@ -180,7 +180,7 @@ public: uintptr_t PDPTEIndex = 0; uintptr_t PDEIndex = 0; uintptr_t PTEIndex = 0; - __always_inline inline nsa NIF PageMapIndexer(uintptr_t VirtualAddress) + __always_inline inline nsa nif PageMapIndexer(uintptr_t VirtualAddress) { uintptr_t Address = VirtualAddress; Address >>= 12; @@ -194,7 +194,7 @@ public: } }; -__attribute__((section(".bootstrap.text"))) nsa NIF void MB2_64_Map(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags) +__attribute__((section(".bootstrap.text"))) nsa nif void MB2_64_Map(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags) { PageMapIndexer Index = PageMapIndexer((uintptr_t)VirtualAddress); // Clear any flags that are not 1 << 0 (Present) - 1 << 5 (Accessed) because rest are for page table entries only @@ -280,7 +280,7 @@ __attribute__((section(".bootstrap.text"))) nsa NIF void MB2_64_Map(void *Virtua : "memory"); } -EXTERNC __attribute__((section(".bootstrap.text"))) nsa NIF __attribute__((section(".bootstrap.text"))) void UpdatePageTable64() +EXTERNC __attribute__((section(".bootstrap.text"))) nsa nif __attribute__((section(".bootstrap.text"))) void UpdatePageTable64() { BPTable = (PageTable4 *)BootPageTable; diff --git a/Kernel/core/debugger.cpp b/Kernel/core/debugger.cpp index 0deac1c1..f6f0fa00 100644 --- a/Kernel/core/debugger.cpp +++ b/Kernel/core/debugger.cpp @@ -27,12 +27,12 @@ NewLock(DebuggerLock); extern bool serialports[8]; -EXTERNC NIF void uart_wrapper(char c, void *) +EXTERNC nif void uart_wrapper(char c, void *) { uart.DebugWrite(c); } -static inline NIF bool WritePrefix(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, va_list args) +static inline nif bool WritePrefix(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, va_list args) { const char *DbgLvlString; switch (Level) @@ -79,7 +79,7 @@ static inline NIF bool WritePrefix(DebugLevel Level, const char *File, int Line, namespace SysDbg { - NIF void Write(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) + nif void Write(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) { va_list args; va_start(args, Format); @@ -92,7 +92,7 @@ namespace SysDbg va_end(args); } - NIF void WriteLine(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) + nif void WriteLine(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) { va_list args; va_start(args, Format); @@ -106,7 +106,7 @@ namespace SysDbg uart_wrapper('\n', nullptr); } - NIF void LockedWrite(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) + nif void LockedWrite(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) { SmartTimeoutLock(DebuggerLock, 1000); va_list args; @@ -120,7 +120,7 @@ namespace SysDbg va_end(args); } - NIF void LockedWriteLine(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) + nif void LockedWriteLine(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) { SmartTimeoutLock(DebuggerLock, 1000); va_list args; @@ -137,7 +137,7 @@ namespace SysDbg } // C compatibility -extern "C" NIF void SysDbgWrite(enum DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) +extern "C" nif void SysDbgWrite(enum DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) { va_list args; va_start(args, Format); @@ -151,7 +151,7 @@ extern "C" NIF void SysDbgWrite(enum DebugLevel Level, const char *File, int Lin } // C compatibility -extern "C" NIF void SysDbgWriteLine(enum DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) +extern "C" nif void SysDbgWriteLine(enum DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) { va_list args; va_start(args, Format); @@ -166,7 +166,7 @@ extern "C" NIF void SysDbgWriteLine(enum DebugLevel Level, const char *File, int } // C compatibility -extern "C" NIF void SysDbgLockedWrite(enum DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) +extern "C" nif void SysDbgLockedWrite(enum DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) { SmartTimeoutLock(DebuggerLock, 1000); va_list args; @@ -181,7 +181,7 @@ extern "C" NIF void SysDbgLockedWrite(enum DebugLevel Level, const char *File, i } // C compatibility -extern "C" NIF void SysDbgLockedWriteLine(enum DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) +extern "C" nif void SysDbgLockedWriteLine(enum DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...) { SmartTimeoutLock(DebuggerLock, 1000); va_list args; diff --git a/Kernel/core/memory/memory.cpp b/Kernel/core/memory/memory.cpp index 5092ffde..e1af342d 100644 --- a/Kernel/core/memory/memory.cpp +++ b/Kernel/core/memory/memory.cpp @@ -52,7 +52,7 @@ Xalloc::V1 *XallocV1Allocator = nullptr; Xalloc::V2 *XallocV2Allocator = nullptr; #ifdef DEBUG -NIF void tracepagetable(PageTable *pt) +nif void tracepagetable(PageTable *pt) { for (int i = 0; i < 512; i++) { @@ -71,7 +71,7 @@ NIF void tracepagetable(PageTable *pt) } #endif -NIF void MapEntries(PageTable *PT) +nif void MapEntries(PageTable *PT) { debug("mapping %d memory entries", bInfo.Memory.Entries); Virtual vmm = Virtual(PT); @@ -89,7 +89,7 @@ NIF void MapEntries(PageTable *PT) vmm.Unmap((void *)0); } -NIF void MapFramebuffer(PageTable *PT) +nif void MapFramebuffer(PageTable *PT) { debug("Mapping Framebuffer"); Virtual vmm = Virtual(PT); @@ -123,7 +123,7 @@ NIF void MapFramebuffer(PageTable *PT) } } -NIF void MapKernel(PageTable *PT) +nif void MapKernel(PageTable *PT) { debug("Mapping Kernel"); @@ -237,7 +237,7 @@ NIF void MapKernel(PageTable *PT) info("Cannot determine kernel file address. Ignoring."); } -NIF void CreatePageTable(PageTable *pt) +nif void CreatePageTable(PageTable *pt) { static int check_cpuid = 0; @@ -286,7 +286,7 @@ NIF void CreatePageTable(PageTable *pt) #endif } -NIF void InitializeMemoryManagement() +nif void InitializeMemoryManagement() { #ifdef DEBUG #ifndef __i386__ diff --git a/Kernel/core/symbols.cpp b/Kernel/core/symbols.cpp index 739b4db9..68a2eade 100644 --- a/Kernel/core/symbols.cpp +++ b/Kernel/core/symbols.cpp @@ -26,7 +26,7 @@ namespace SymbolResolver { - const NIF char *Symbols::GetSymbol(uintptr_t Address) + const nif char *Symbols::GetSymbol(uintptr_t Address) { SymbolTable Result{}; diff --git a/Kernel/include/types.h b/Kernel/include/types.h index 53be2096..6be985f5 100644 --- a/Kernel/include/types.h +++ b/Kernel/include/types.h @@ -461,7 +461,7 @@ typedef uint48_t uint_fast48_t; #define NoSecurityAnalysis __no_stack_protector __no_sanitize_address __no_sanitize_undefined __no_sanitize_thread #define nsa NoSecurityAnalysis -#define NIF __no_instrument_function +#define nif __no_instrument_function #define int3 \ __asm__ __volatile__("int3" \ diff --git a/Kernel/kernel.cpp b/Kernel/kernel.cpp index cfd4830b..e8f14d63 100644 --- a/Kernel/kernel.cpp +++ b/Kernel/kernel.cpp @@ -33,7 +33,6 @@ #include "tests/t.h" bool DebuggerIsAttached = false; -extern bool EnableProfiler; NewLock(KernelLock); __aligned(16) BootInfo bInfo{}; @@ -117,7 +116,7 @@ EXTERNC void KPrint(const char *Format, ...) #endif } -EXTERNC NIF cold void Main() +EXTERNC nif cold void Main() { Display = new Video::Display(bInfo.Framebuffer[0]); KernelConsole::EarlyInit(); @@ -259,7 +258,7 @@ typedef void (*CallPtr)(void); extern CallPtr __init_array_start[0], __init_array_end[0]; extern CallPtr __fini_array_start[0], __fini_array_end[0]; -EXTERNC __no_stack_protector NIF cold void Entry(BootInfo *Info) +EXTERNC __no_stack_protector nif cold void Entry(BootInfo *Info) { memcpy(&bInfo, Info, sizeof(BootInfo)); @@ -352,7 +351,6 @@ EXTERNC __no_stack_protector NIF cold void Entry(BootInfo *Info) #warning "FIXME: Test_stl() is not implemented for other architectures" #endif #endif // DEBUG - EnableProfiler = true; Main(); } diff --git a/Kernel/kernel_vfs.cpp b/Kernel/kernel_vfs.cpp index 37e2eada..64f90c1c 100644 --- a/Kernel/kernel_vfs.cpp +++ b/Kernel/kernel_vfs.cpp @@ -49,7 +49,7 @@ void SearchForInitrd() } } -EXTERNC NIF void KernelVFS() +EXTERNC nif void KernelVFS() { KPrint("Initializing Virtual File System"); diff --git a/Kernel/library/printf.c b/Kernel/library/printf.c index 7032a34d..633ff9c9 100644 --- a/Kernel/library/printf.c +++ b/Kernel/library/printf.c @@ -268,14 +268,14 @@ typedef union // 1. Some compilers are finicky about this; // 2. Some people may want to convert this to C89; // 3. If you try to use it as C++, only C++20 supports compound literals -static inline NIF double_with_bit_access get_bit_access(double x) +static inline nif double_with_bit_access get_bit_access(double x) { double_with_bit_access dwba; dwba.F = x; return dwba; } -static inline NIF int get_sign_bit(double x) +static inline nif int get_sign_bit(double x) { // The sign is stored in the highest bit return (int)(get_bit_access(x).U >> (DOUBLE_SIZE_IN_BITS - 1)); @@ -319,7 +319,7 @@ typedef struct // or alternatively, that '\0' can be passed to the function in the output // gadget. The former assumption holds within the printf library. It also // assumes that the output gadget has been properly initialized. -static inline NIF void putchar_via_gadget(output_gadget_t *gadget, char c) +static inline nif void putchar_via_gadget(output_gadget_t *gadget, char c) { printf_size_t write_pos = gadget->pos++; // We're _always_ increasing pos, so as to count how may characters @@ -342,7 +342,7 @@ static inline NIF void putchar_via_gadget(output_gadget_t *gadget, char c) } // Possibly-write the string-terminating '\0' character -static inline NIF void append_termination_with_gadget(output_gadget_t *gadget) +static inline nif void append_termination_with_gadget(output_gadget_t *gadget) { if (gadget->function != NULL || gadget->max_chars == 0) { @@ -360,13 +360,13 @@ extern void putchar(char c); // We can't use putchar_ as is, since our output gadget // only takes pointers to functions with an extra argument -static inline NIF void putchar_wrapper(char c, void *unused) +static inline nif void putchar_wrapper(char c, void *unused) { putchar(c); UNUSED(unused); } -static inline NIF output_gadget_t discarding_gadget(void) +static inline nif output_gadget_t discarding_gadget(void) { output_gadget_t gadget; gadget.function = NULL; @@ -377,7 +377,7 @@ static inline NIF output_gadget_t discarding_gadget(void) return gadget; } -static inline NIF output_gadget_t buffer_gadget(char *buffer, size_t buffer_size) +static inline nif output_gadget_t buffer_gadget(char *buffer, size_t buffer_size) { printf_size_t usable_buffer_size = (buffer_size > PRINTF_MAX_POSSIBLE_BUFFER_SIZE) ? PRINTF_MAX_POSSIBLE_BUFFER_SIZE : (printf_size_t)buffer_size; output_gadget_t result = discarding_gadget(); @@ -389,7 +389,7 @@ static inline NIF output_gadget_t buffer_gadget(char *buffer, size_t buffer_size return result; } -static inline NIF output_gadget_t function_gadget(void (*function)(char, void *), void *extra_arg) +static inline nif output_gadget_t function_gadget(void (*function)(char, void *), void *extra_arg) { output_gadget_t result = discarding_gadget(); result.function = function; @@ -398,7 +398,7 @@ static inline NIF output_gadget_t function_gadget(void (*function)(char, void *) return result; } -static inline NIF output_gadget_t extern_putchar_gadget(void) +static inline nif output_gadget_t extern_putchar_gadget(void) { return function_gadget(putchar_wrapper, NULL); } @@ -407,7 +407,7 @@ static inline NIF output_gadget_t extern_putchar_gadget(void) // @return The length of the string (excluding the terminating 0) limited by 'maxsize' // @note strlen uses size_t, but wes only use this function with printf_size_t // variables - hence the signature. -static inline NIF printf_size_t strnlen_s_(const char *str, printf_size_t maxsize) +static inline nif printf_size_t strnlen_s_(const char *str, printf_size_t maxsize) { const char *s; for (s = str; *s && maxsize--; ++s) @@ -417,13 +417,13 @@ static inline NIF printf_size_t strnlen_s_(const char *str, printf_size_t maxsiz // internal test if char is a digit (0-9) // @return true if char is a digit -static inline NIF bool is_digit_(char ch) +static inline nif bool is_digit_(char ch) { return (ch >= '0') && (ch <= '9'); } // internal ASCII string to printf_size_t conversion -static NIF printf_size_t atou_(const char **str) +static nif printf_size_t atou_(const char **str) { printf_size_t i = 0U; while (is_digit_(**str)) @@ -434,7 +434,7 @@ static NIF printf_size_t atou_(const char **str) } // output the specified string in reverse, taking care of any zero-padding -static NIF void out_rev_(output_gadget_t *output, const char *buf, printf_size_t len, printf_size_t width, printf_flags_t flags) +static nif void out_rev_(output_gadget_t *output, const char *buf, printf_size_t len, printf_size_t width, printf_flags_t flags) { const printf_size_t start_pos = output->pos; @@ -465,7 +465,7 @@ static NIF void out_rev_(output_gadget_t *output, const char *buf, printf_size_t // Invoked by print_integer after the actual number has been printed, performing necessary // work on the number's prefix (as the number is initially printed in reverse order) -static NIF void print_integer_finalization(output_gadget_t *output, char *buf, printf_size_t len, bool negative, numeric_base_t base, printf_size_t precision, printf_size_t width, printf_flags_t flags) +static nif void print_integer_finalization(output_gadget_t *output, char *buf, printf_size_t len, bool negative, numeric_base_t base, printf_size_t precision, printf_size_t width, printf_flags_t flags) { printf_size_t unpadded_len = len; @@ -549,7 +549,7 @@ static NIF void print_integer_finalization(output_gadget_t *output, char *buf, p } // An internal itoa-like function -static NIF void print_integer(output_gadget_t *output, printf_unsigned_value_t value, bool negative, numeric_base_t base, printf_size_t precision, printf_size_t width, printf_flags_t flags) +static nif void print_integer(output_gadget_t *output, printf_unsigned_value_t value, bool negative, numeric_base_t base, printf_size_t precision, printf_size_t width, printf_flags_t flags) { char buf[PRINTF_INTEGER_BUFFER_SIZE]; printf_size_t len = 0U; @@ -608,7 +608,7 @@ static const double powers_of_10[NUM_DECIMAL_DIGITS_IN_INT64_T] = { // Break up a double number - which is known to be a finite non-negative number - // into its base-10 parts: integral - before the decimal point, and fractional - after it. // Taken the precision into account, but does not change it even internally. -static struct NIF double_components get_components(double number, printf_size_t precision) +static struct nif double_components get_components(double number, printf_size_t precision) { struct double_components number_; number_.is_negative = get_sign_bit(number); @@ -745,7 +745,7 @@ static struct double_components get_normalized_components(bool negative, printf_ } #endif // PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS -static NIF void print_broken_up_decimal( +static nif void print_broken_up_decimal( struct double_components number_, output_gadget_t *output, printf_size_t precision, printf_size_t width, printf_flags_t flags, char *buf, printf_size_t len) { @@ -847,7 +847,7 @@ static NIF void print_broken_up_decimal( } // internal ftoa for fixed decimal floating point -static NIF void print_decimal_number(output_gadget_t *output, double number, printf_size_t precision, printf_size_t width, printf_flags_t flags, char *buf, printf_size_t len) +static nif void print_decimal_number(output_gadget_t *output, double number, printf_size_t precision, printf_size_t width, printf_flags_t flags, char *buf, printf_size_t len) { struct double_components value_ = get_components(number, precision); print_broken_up_decimal(value_, output, precision, width, flags, buf, len); @@ -920,7 +920,7 @@ static double pow10_of_int(int floored_exp10) return dwba.F; } -static NIF void print_exponential_number(output_gadget_t *output, double number, printf_size_t precision, printf_size_t width, printf_flags_t flags, char *buf, printf_size_t len) +static nif void print_exponential_number(output_gadget_t *output, double number, printf_size_t precision, printf_size_t width, printf_flags_t flags, char *buf, printf_size_t len) { const bool negative = get_sign_bit(number); // This number will decrease gradually (by factors of 10) as we "extract" the exponent out of it @@ -1043,7 +1043,7 @@ static NIF void print_exponential_number(output_gadget_t *output, double number, } #endif // PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS -static NIF void print_floating_point(output_gadget_t *output, double value, printf_size_t precision, printf_size_t width, printf_flags_t flags, bool prefer_exponential) +static nif void print_floating_point(output_gadget_t *output, double value, printf_size_t precision, printf_size_t width, printf_flags_t flags, bool prefer_exponential) { char buf[PRINTF_DECIMAL_BUFFER_SIZE]; printf_size_t len = 0U; @@ -1102,7 +1102,7 @@ static NIF void print_floating_point(output_gadget_t *output, double value, prin // Advances the format pointer past the flags, and returns the parsed flags // due to the characters passed -static NIF printf_flags_t parse_flags(const char **format) +static nif printf_flags_t parse_flags(const char **format) { printf_flags_t flags = 0U; do @@ -1135,7 +1135,7 @@ static NIF printf_flags_t parse_flags(const char **format) } while (true); } -static inline NIF void format_string_loop(output_gadget_t *output, const char *format, va_list args) +static inline nif void format_string_loop(output_gadget_t *output, const char *format, va_list args) { #if PRINTF_CHECK_FOR_NUL_IN_FORMAT_SPECIFIER #define ADVANCE_IN_FORMAT_STRING(cptr_) \ @@ -1517,7 +1517,7 @@ static inline NIF void format_string_loop(output_gadget_t *output, const char *f } // internal vsnprintf - used for implementing _all library functions -static NIF int vsnprintf_impl(output_gadget_t *output, const char *format, va_list args) +static nif int vsnprintf_impl(output_gadget_t *output, const char *format, va_list args) { // Note: The library only calls vsnprintf_impl() with output->pos being 0. However, it is // possible to call this function with a non-zero pos value for some "remedial printing". @@ -1532,30 +1532,30 @@ static NIF int vsnprintf_impl(output_gadget_t *output, const char *format, va_li /////////////////////////////////////////////////////////////////////////////// -NIF int vprintf(const char *format, va_list arg) +nif int vprintf(const char *format, va_list arg) { output_gadget_t gadget = extern_putchar_gadget(); return vsnprintf_impl(&gadget, format, arg); } -NIF int vsnprintf(char *s, size_t n, const char *format, va_list arg) +nif int vsnprintf(char *s, size_t n, const char *format, va_list arg) { output_gadget_t gadget = buffer_gadget(s, n); return vsnprintf_impl(&gadget, format, arg); } -NIF int vsprintf(char *s, const char *format, va_list arg) +nif int vsprintf(char *s, const char *format, va_list arg) { return vsnprintf(s, PRINTF_MAX_POSSIBLE_BUFFER_SIZE, format, arg); } -NIF int vfctprintf(void (*out)(char c, void *extra_arg), void *extra_arg, const char *format, va_list arg) +nif int vfctprintf(void (*out)(char c, void *extra_arg), void *extra_arg, const char *format, va_list arg) { output_gadget_t gadget = function_gadget(out, extra_arg); return vsnprintf_impl(&gadget, format, arg); } -NIF int printf(const char *format, ...) +nif int printf(const char *format, ...) { va_list args; va_start(args, format); @@ -1564,7 +1564,7 @@ NIF int printf(const char *format, ...) return ret; } -NIF int sprintf(char *s, const char *format, ...) +nif int sprintf(char *s, const char *format, ...) { va_list args; va_start(args, format); @@ -1573,7 +1573,7 @@ NIF int sprintf(char *s, const char *format, ...) return ret; } -NIF int snprintf(char *s, size_t n, const char *format, ...) +nif int snprintf(char *s, size_t n, const char *format, ...) { va_list args; va_start(args, format); @@ -1582,7 +1582,7 @@ NIF int snprintf(char *s, size_t n, const char *format, ...) return ret; } -NIF int fctprintf(void (*out)(char c, void *extra_arg), void *extra_arg, const char *format, ...) +nif int fctprintf(void (*out)(char c, void *extra_arg), void *extra_arg, const char *format, ...) { va_list args; va_start(args, format); diff --git a/Kernel/profiling/cyg.cpp b/Kernel/profiling/cyg.cpp index f5e291d8..da7c89bf 100644 --- a/Kernel/profiling/cyg.cpp +++ b/Kernel/profiling/cyg.cpp @@ -16,95 +16,15 @@ */ #include -#include -#include -#include "../kernel.h" - -bool EnableProfiler = false; -bool Wait = false; -unsigned long long LogDepth = 0; -unsigned int Level = 0; - -static inline nsa NIF void profiler_uart_wrapper(char c, void *unused) +EXTERNC nsa nif void __cyg_profile_func_enter(void *this_fn, void *call_site) { - bool renable = EnableProfiler; - EnableProfiler = false; - UNUSED(unused); - if (renable) - EnableProfiler = true; + UNUSED(this_fn); + UNUSED(call_site); } -EXTERNC nsa NIF void __cyg_profile_func_enter(void *Function, void *CallSite) +EXTERNC nsa nif void __cyg_profile_func_exit(void *this_fn, void *call_site) { - if (!EnableProfiler) - return; - - while (Wait) -#if defined(__amd64__) || defined(__i386__) - asmv("pause"); -#elif defined(__aarch64__) - 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(__amd64__) || defined(__i386__) - asmv("pause"); -#elif defined(__aarch64__) - 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; + UNUSED(this_fn); + UNUSED(call_site); } diff --git a/Kernel/profiling/gcov.cpp b/Kernel/profiling/gcov.cpp index c9b4fa44..a4128da7 100644 --- a/Kernel/profiling/gcov.cpp +++ b/Kernel/profiling/gcov.cpp @@ -16,10 +16,6 @@ */ #include -#include -#include - -#include "../kernel.h" #if BITS_PER_LONG >= 64 typedef long gcov_type; @@ -53,33 +49,26 @@ struct gcov_info struct gcov_ctr_info counts[0]; }; -static inline nsa NIF void gcov_uart_wrapper(char c, void *unused) +EXTERNC nsa nif void __gcov_init(gcov_info *info) { - UNUSED(c); - UNUSED(unused); + UNUSED(info); } -// TODO: Implement - -EXTERNC nsa NIF void __gcov_init(gcov_info *p __unused) +EXTERNC nsa nif void __gcov_exit(void) { } -EXTERNC nsa NIF void __gcov_exit(void) +EXTERNC nsa nif void __gcov_flush(void) { } -EXTERNC nsa NIF void __gcov_flush(void) -{ -} - -EXTERNC nsa NIF void __gcov_merge_add(gcov_type *counters, unsigned int n_counters) +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) +EXTERNC nsa nif void __gcov_merge_single(gcov_type *counters, unsigned int n_counters) { UNUSED(counters); UNUSED(n_counters); diff --git a/Kernel/profiling/gprof.cpp b/Kernel/profiling/gprof.cpp index d7692862..1645b3ff 100644 --- a/Kernel/profiling/gprof.cpp +++ b/Kernel/profiling/gprof.cpp @@ -16,18 +16,8 @@ */ #include -#include -#include -#include "../kernel.h" - -static inline nsa NIF void gprof_uart_wrapper(char c, void *unused) -{ - UNUSED(c); - UNUSED(unused); -} - -EXTERNC nsa NIF void mcount(unsigned long frompc, unsigned long selfpc) +EXTERNC nsa nif void mcount(void *frompc, size_t selfpc) { // TODO: Implement /* https://docs.kernel.org/trace/ftrace-design.html */ diff --git a/Kernel/tasking/scheduler/custom.cpp b/Kernel/tasking/scheduler/custom.cpp index 02555815..97e66198 100644 --- a/Kernel/tasking/scheduler/custom.cpp +++ b/Kernel/tasking/scheduler/custom.cpp @@ -300,7 +300,7 @@ namespace Tasking::Scheduler Info->KernelTime += TimePassed; } - hot nsa NIF bool Custom::FindNewProcess(void *CPUDataPointer) + hot nsa nif bool Custom::FindNewProcess(void *CPUDataPointer) { CPUData *CurrentCPU = (CPUData *)CPUDataPointer; fnp_schedbg("%d processes", ProcessList.size()); @@ -347,7 +347,7 @@ namespace Tasking::Scheduler return false; } - hot nsa NIF bool Custom::GetNextAvailableThread(void *CPUDataPointer) + hot nsa nif bool Custom::GetNextAvailableThread(void *CPUDataPointer) { CPUData *CurrentCPU = (CPUData *)CPUDataPointer; @@ -399,7 +399,7 @@ namespace Tasking::Scheduler return false; } - hot nsa NIF bool Custom::GetNextAvailableProcess(void *CPUDataPointer) + hot nsa nif bool Custom::GetNextAvailableProcess(void *CPUDataPointer) { CPUData *CurrentCPU = (CPUData *)CPUDataPointer; @@ -447,7 +447,7 @@ namespace Tasking::Scheduler return false; } - hot nsa NIF bool Custom::SchedulerSearchProcessThread(void *CPUDataPointer) + hot nsa nif bool Custom::SchedulerSearchProcessThread(void *CPUDataPointer) { CPUData *CurrentCPU = (CPUData *)CPUDataPointer; @@ -480,7 +480,7 @@ namespace Tasking::Scheduler return false; } - nsa NIF void Custom::UpdateProcessState() + nsa nif void Custom::UpdateProcessState() { for (auto process : ProcessList) { @@ -513,7 +513,7 @@ namespace Tasking::Scheduler } } - nsa NIF void Custom::WakeUpThreads() + nsa nif void Custom::WakeUpThreads() { for (auto process : ProcessList) { @@ -547,7 +547,7 @@ namespace Tasking::Scheduler } } - nsa NIF void Custom::CleanupTerminated() + nsa nif void Custom::CleanupTerminated() { for (auto pcb : ProcessList) { @@ -566,7 +566,7 @@ namespace Tasking::Scheduler } } - hot nsa NIF void Custom::Schedule(CPU::SchedulerFrame *Frame) + hot nsa nif void Custom::Schedule(CPU::SchedulerFrame *Frame) { if (unlikely(StopScheduler)) { @@ -723,7 +723,7 @@ namespace Tasking::Scheduler this->SchedulerTicks.store(size_t(TimeManager->GetCounter() - SchedTmpTicks)); } - hot nsa NIF void Custom::OnInterruptReceived(CPU::SchedulerFrame *Frame) + hot nsa nif void Custom::OnInterruptReceived(CPU::SchedulerFrame *Frame) { SmartCriticalSection(SchedulerLock); this->Schedule(Frame);