diff --git a/.gitignore b/.gitignore index 6ad03c0..908a65d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ temp/ tools/x86_64-elf-tools -!src/global/*.o \ No newline at end of file +!src/global/*.o +!src/assets/z*.o \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ef1a762..6838c86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,10 @@ #project config cmake_minimum_required(VERSION 3.10) +set(CMAKE_CXX_COMPILER x86_64-elf-g++) set(CMAKE_C_COMPILER x86_64-elf-gcc) -# cheat the compile test +# cheat the compile test set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) SET(CMAKE_SYSTEM_NAME Generic) SET(CMAKE_CROSSCOMPILING 1) @@ -63,4 +64,4 @@ add_executable(kernel) target_sources(kernel PUBLIC ${src_preamble} PUBLIC ${src_files} PUBLIC ${src_no_sse} PUBLIC ${lib_files} PUBLIC ${src_epilogue}) target_compile_options(kernel PRIVATE -ffreestanding -O0 -Wall -Wextra -Wall -Werror -fPIC -fno-exceptions -fno-omit-frame-pointer -mno-red-zone -fno-stack-protector -ggdb3) -target_link_options(kernel PRIVATE -T linker.ld -ffreestanding -O2 -nostdlib -nostartfiles -lgcc) +target_link_options(kernel PRIVATE -T ${CMAKE_SOURCE_DIR}/linker.ld -ffreestanding -O2 -nostdlib -nostartfiles -lgcc) diff --git a/inc/editor/main.h b/inc/editor/main.h index 3eef68b..12be83b 100644 --- a/inc/editor/main.h +++ b/inc/editor/main.h @@ -5,6 +5,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /** * This file contains most of the symbols required to start and run the Chroma Editor. * @@ -116,4 +120,8 @@ void GetLine(EditorState* state, size_t line); void SetLine(EditorState* state, struct EditorLine* line); void AppendLine(EditorState* state, struct EditorLine* line); void AppendToLine(EditorState* state, struct EditorLine* line, size_t textLength, char* text); -void RemoveLine(EditorState* state, size_t line); \ No newline at end of file +void RemoveLine(EditorState* state, size_t line); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/kernel/boot/boot.h b/inc/kernel/boot/boot.h index 2a66234..00731fa 100644 --- a/inc/kernel/boot/boot.h +++ b/inc/kernel/boot/boot.h @@ -1,7 +1,4 @@ - -#ifndef _BOOTLOADER_H_ -#define _BOOTLOADER_H_ - +#pragma once /************************ *** Team Kitty, 2020 *** *** Chroma *** @@ -161,5 +158,3 @@ typedef struct { #ifdef __cplusplus } #endif - -#endif diff --git a/inc/kernel/chroma.h b/inc/kernel/chroma.h index accbd3f..665b000 100644 --- a/inc/kernel/chroma.h +++ b/inc/kernel/chroma.h @@ -9,6 +9,10 @@ * It also provides the symbols for the framebuffer and configuration file, which are both equually important. */ +#ifdef __cplusplus +extern "C" { +#endif + #define UNUSED(x) (void)x #include @@ -25,9 +29,6 @@ #include #include -//Removed cause "wacky copyrighted stuff" -//#include - extern size_t LoadAddr; extern bootinfo bootldr; extern unsigned char* environment; @@ -82,4 +83,8 @@ int Main(); void Exit(); -void SomethingWentWrong(const char* Message); \ No newline at end of file +void SomethingWentWrong(const char* Message); + +#ifdef __cplusplus +} // extern "C" +#endif \ No newline at end of file diff --git a/inc/kernel/system/descriptors.h b/inc/kernel/system/descriptors.h index 1069795..7d41c43 100644 --- a/inc/kernel/system/descriptors.h +++ b/inc/kernel/system/descriptors.h @@ -8,6 +8,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + typedef struct __attribute__((packed)) { uint16_t LowLimit; uint16_t BaseLow; @@ -73,3 +77,6 @@ typedef struct __attribute__((packed)) { uint16_t IOMap; } TSS64; +#ifdef __cplusplus +} // extern "C" +#endif \ No newline at end of file diff --git a/inc/kernel/system/driver/keyboard.h b/inc/kernel/system/driver/keyboard.h index 98d89ed..18b7f9b 100644 --- a/inc/kernel/system/driver/keyboard.h +++ b/inc/kernel/system/driver/keyboard.h @@ -5,6 +5,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { char Char; char Scancode; @@ -17,4 +21,8 @@ extern KeyboardCallback KeyboardCallbacks[16]; int SetupKBCallback(void (*Handler)(KeyboardData Frame)); -void UninstallKBCallback(int Index); \ No newline at end of file +void UninstallKBCallback(int Index); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/kernel/system/heap.h b/inc/kernel/system/heap.h deleted file mode 100644 index 91adb33..0000000 --- a/inc/kernel/system/heap.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -/************************ - *** Team Kitty, 2020 *** - *** Chroma *** - ***********************/ - -#include -#include - -uint8_t HeapEnabled = 0; - diff --git a/inc/kernel/system/interrupts.h b/inc/kernel/system/interrupts.h index 186402e..43f5ea7 100644 --- a/inc/kernel/system/interrupts.h +++ b/inc/kernel/system/interrupts.h @@ -6,6 +6,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + extern const char* ExceptionStrings[]; @@ -89,3 +93,7 @@ void IRQ12Handler(INTERRUPT_FRAME* Frame); void IRQ13Handler(INTERRUPT_FRAME* Frame); void IRQ14Handler(INTERRUPT_FRAME* Frame); void IRQ15Handler(INTERRUPT_FRAME* Frame); + +#ifdef __cplusplus +} // extern "C" +#endif \ No newline at end of file diff --git a/inc/kernel/system/io.h b/inc/kernel/system/io.h index e4c748a..d9f057b 100644 --- a/inc/kernel/system/io.h +++ b/inc/kernel/system/io.h @@ -1,5 +1,9 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + #include /************************ @@ -73,4 +77,8 @@ int SerialPrintf(const char* restrict format, ...); int Printf(const char* restrict Format, ...); void* memcpy(void* dest, void const* src, size_t len); -void* memset(void* dst, int src, size_t len); \ No newline at end of file +void* memset(void* dst, int src, size_t len); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/kernel/system/memory.h b/inc/kernel/system/memory.h index 56ec302..d94a630 100644 --- a/inc/kernel/system/memory.h +++ b/inc/kernel/system/memory.h @@ -1,3 +1,9 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include @@ -288,4 +294,8 @@ void PageFaultHandler(INTERRUPT_FRAME Frame); extern void *PREFIX(malloc)(size_t); ///< The standard function. extern void *PREFIX(realloc)(void *, size_t); ///< The standard function. extern void *PREFIX(calloc)(size_t, size_t); ///< The standard function. -extern void PREFIX(free)(void *); ///< The standard function. \ No newline at end of file +extern void PREFIX(free)(void *); ///< The standard function. + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/kernel/system/pci.h b/inc/kernel/system/pci.h index d5c9665..0942c55 100644 --- a/inc/kernel/system/pci.h +++ b/inc/kernel/system/pci.h @@ -1,4 +1,9 @@ #pragma once + +#ifdef __cplusplus +extern "C" { +#endif + #include #include @@ -171,4 +176,8 @@ typedef struct { extern pci_device_t** pci_root_devices; -extern pci_entry_t* pci_map; \ No newline at end of file +extern pci_entry_t* pci_map; + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/kernel/system/process/process.h b/inc/kernel/system/process/process.h index 6a7a219..c9b63c3 100644 --- a/inc/kernel/system/process/process.h +++ b/inc/kernel/system/process/process.h @@ -14,8 +14,6 @@ #define MAX_PROCESSES 128 #define PROCESS_STACK 65535 -static size_t - /** * @brief All the data a process needs. * @@ -73,6 +71,7 @@ class Process { ProcessState State; bool User; // Is this process originated in userspace? + bool System; // Was this process started by the system (ie. not user interaction) size_t UniquePID; // Globally Unique ID. size_t KernelPID; // If in kernel space, the PID. @@ -85,14 +84,14 @@ class Process { bool ORS = false; bool IsActive = false; bool IsInterrupted = false; // True if an interrupt was fired while this process is active - + uint8_t Signals[8]; // Interrupt / IRQ / Signal handlers. uint8_t Sleeping; // 0 if active, else the process is waiting for something. TODO: remove this, use State? ProcessMessage* Messages; // A queue of IPC messages. size_t LastMessage; // The index of the current message. - uint8_t* ProcessMemory; + uint8_t* ProcessMemory; size_t ProcessMemorySize; // TODO: Stack Trace & MFS @@ -101,10 +100,10 @@ class Process { Process(size_t KPID) : State(PROCESS_AVAILABLE), UniquePID(-1), KernelPID(KPID) { }; - + Process(const char* ProcessName, size_t KPID, size_t UPID, size_t EntryPoint, bool Userspace) : UniquePID(UPID), KernelPID(KPID), Entry(EntryPoint), ORS(false), LastMessage(0), User(Userspace), Sleeping(0) { - + memcpy((void*) ProcessName, Name, strlen(Name) + 1); }; @@ -120,11 +119,40 @@ class Process { /*************************************************************/ void InitMemory(); - + void InitMessages(); + void Kill() { + State = ProcessState::PROCESS_REAP; + Sleeping = -1; + }; + + void Destroy(); + + void Rename(const char* NewName) { + memcpy(Name, NewName, strlen(Name) > strlen(NewName) ? strlen(Name) : strlen(NewName)); + } + + size_t* AllocateProcessSpace(size_t Bytes); + size_t FreeProcessSpace(size_t* Address, size_t Bytes); + + bool OwnsAddress(size_t* Address, size_t Bytes); + /*************************************************************/ - + + void SetParent(size_t PID) { ParentPID = PID; }; + + void SetSystem(bool Status) { + System = Status; + if(System && User) { + // TODO: Log error. + } + }; + + void SetState(ProcessState NewState) { State = NewState; }; + + void SetActive(bool NewState) { IsActive = NewState; }; + void SetCore(size_t CoreID) { Core = CoreID; }; void IncreaseSleep(size_t Interval) { Sleeping += Interval; }; @@ -134,8 +162,15 @@ class Process { ProcessHeader* GetHeader() { return &Header; }; + const char* GetName() const { return Name; }; + + size_t GetPID() const { return UniquePID; }; + size_t GetKPID() const { return KernelPID; }; + size_t GetParent() const { return ParentPID; }; + ProcessState GetState() const { return State; }; + bool IsValid() const { return KernelPID != 0; }; bool IsUsed() const { return (State != ProcessState::PROCESS_AVAILABLE && State != ProcessState::PROCESS_CRASH && State != ProcessState::PROCESS_REAP) && IsValid(); }; @@ -148,10 +183,21 @@ class Process { bool flag = !(ORS && !IsActive); return State == ProcessState::PROCESS_WAITING && Core == CPU && KernelPID != 0 && flag && !IsSleeping(); - } + }; size_t GetCore() const { return Core; }; + bool IsUserspace() { return User; }; + bool IsSystem() { return System; }; + + + /*************************************************************/ + + static Process* FromName(const char* name); + static Process* FromPID(size_t PID); + static Process* Current(); + + static void SetCurrent(Process* Target); }; @@ -166,17 +212,17 @@ class ProcessManagement { void Wait(); void Initialize(); void InitialiseCore(int APIC, int ID); - + void NotifyAllCores(); // TODO: Process* size_t SwitchContext(INTERRUPT_FRAME* CurrentFrame); void MapThreadMemory(size_t from, size_t to, size_t length); - + void InitProcess(/*func EntryPoint*/ int argc, char** argv); void InitProcessPagetable(bool Userspace); void InitProcessArch(); - + size_t HandleRequest(size_t CPU); diff --git a/inc/kernel/system/stack.h b/inc/kernel/system/stack.h index 14bedec..2fb393e 100644 --- a/inc/kernel/system/stack.h +++ b/inc/kernel/system/stack.h @@ -1,4 +1,9 @@ #pragma once + +#ifdef __cplusplus +extern "C" { +#endif + #include #include @@ -12,4 +17,8 @@ typedef struct stackframe { size_t rip; } stackframe_t; -void StackTrace(size_t cycles); \ No newline at end of file +void StackTrace(size_t cycles); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/kernel/video/bitmapfont.h b/inc/kernel/video/bitmapfont.h index f028ca8..c5d48b9 100644 --- a/inc/kernel/video/bitmapfont.h +++ b/inc/kernel/video/bitmapfont.h @@ -3,6 +3,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + // This file contains all of the bitmap fonts made by me (Curle) and taken from the public domain // eg. http://dimensionalrift.homelinux.net/combuster/mos3/?p=viewsource&file=/modules/gfx/font8_8.asm @@ -463,4 +467,8 @@ const unsigned char bitfont_block[32][8] = { { 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00}, // U+259D (box top right) { 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F}, // U+259E (boxes top right and bottom left) { 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF}, // U+259F (boxes right and bottom) -}; \ No newline at end of file +}; + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/kernel/video/draw.h b/inc/kernel/video/draw.h index 1919d74..ae386bd 100644 --- a/inc/kernel/video/draw.h +++ b/inc/kernel/video/draw.h @@ -5,6 +5,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /** * Drawing routines for screen manipulation. * This will be pulled out into the Helix library soon. @@ -55,4 +59,8 @@ void DrawLineRoundedRect(size_t x, size_t y, size_t width, size_t height, size_t void DrawFilledCircle(size_t centerX, size_t centerY, size_t radius); void DrawLineCircle(size_t centerX, size_t centerY, size_t radius); -void DrawLineCircleCorners(size_t centerX, size_t centerY, size_t radius, char cornerMask); \ No newline at end of file +void DrawLineCircleCorners(size_t centerX, size_t centerY, size_t radius, char cornerMask); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/lainlib/compression/lzg.h b/inc/lainlib/compression/lzg.h index 89e139d..e859569 100644 --- a/inc/lainlib/compression/lzg.h +++ b/inc/lainlib/compression/lzg.h @@ -33,8 +33,8 @@ extern "C" { #endif #define LZG_VERSION "1.0.10" /**< @brief LZG library version string */ -#define LZG_VERNUM 0x0100000a /**< @brief LZG library version number (strictly - incremental) */ +#define LZG_VERNUM 0x0100000a /**< @brief LZG library version number (strictly */ + /* incremental) */ #define LZG_VER_MAJOR 1 /**< @brief LZG library major version */ #define LZG_VER_MINOR 0 /**< @brief LZG library minor version */ #define LZG_VER_REVISION 10 /**< @brief LZG library revision */ diff --git a/inc/lainlib/ethernet/e1000/e1000.h b/inc/lainlib/ethernet/e1000/e1000.h index dcabf21..adc199c 100644 --- a/inc/lainlib/ethernet/e1000/e1000.h +++ b/inc/lainlib/ethernet/e1000/e1000.h @@ -3,6 +3,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include @@ -179,3 +183,7 @@ void E1000InterruptFired(INTERRUPT_FRAME* InterruptContext); uint8_t* E1000GetMAC(e1000_device_t* Device); // Send a packet int E1000Send(e1000_device_t* Device, const void* Data, uint16_t Length); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/lainlib/lainlib.h b/inc/lainlib/lainlib.h index a701ad5..5199581 100644 --- a/inc/lainlib/lainlib.h +++ b/inc/lainlib/lainlib.h @@ -1,19 +1,20 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + /************************ *** Team Kitty, 2020 *** *** Chroma *** ***********************/ - /* Defines all of the temporary library functions. * All of this must be moved into the Chroma stdlib. * They exist here as guidance, and as utility for the kernel itself. * If need be, they can also be moved into a trimmed-down "kernel libc" or "libk". */ -#include - #include #include @@ -22,3 +23,7 @@ #include #include + +#ifdef __cplusplus +} // extern "C" +#endif \ No newline at end of file diff --git a/inc/lainlib/list/list.h b/inc/lainlib/list/list.h index 697e32c..e507e4d 100644 --- a/inc/lainlib/list/list.h +++ b/inc/lainlib/list/list.h @@ -1,5 +1,9 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + typedef struct list_entry { struct list_entry* Previous; struct list_entry* Next; @@ -31,4 +35,8 @@ bool ListIsEmpty(list_entry_t* Head); #define LISTFOREACHENTRY(pos, head, member) \ for(pos = UNSAFE_CAST((head)->next, typeof(*(pos)), member); &pos->member != (head); pos = LISTNEXT(pos, member)) -#define LASTENTRY 0 \ No newline at end of file +#define LASTENTRY 0 + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/lainlib/mutex/spinlock.h b/inc/lainlib/mutex/spinlock.h index 5c8f0d1..b2ceb58 100644 --- a/inc/lainlib/mutex/spinlock.h +++ b/inc/lainlib/mutex/spinlock.h @@ -5,6 +5,9 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif typedef volatile int spinlock_t; @@ -20,3 +23,6 @@ typedef volatile int spinlock_t; __sync_synchronize(); \ name = 0; +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/lainlib/mutex/ticketlock.h b/inc/lainlib/mutex/ticketlock.h index 02720fe..e9024fd 100644 --- a/inc/lainlib/mutex/ticketlock.h +++ b/inc/lainlib/mutex/ticketlock.h @@ -7,14 +7,19 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + + /* This file provides a simple implementation of a ticket-based locking system. * You should probably prefer Spinlock over Ticketlock. - * - * Create a new lock with NEW_TICKETLOCK(), + * + * Create a new lock with NEW_TICKETLOCK(), * lock a resource with TicketLock(). - * + * * Use TicketUnlock() to free the resource after you are done. - * + * */ typedef struct { @@ -30,3 +35,6 @@ bool TicketAttemptLock(ticketlock_t* Lock); void TicketUnlock(ticketlock_t* Lock); +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/lainlib/string/str.h b/inc/lainlib/string/str.h index 0f590ae..828eb6b 100644 --- a/inc/lainlib/string/str.h +++ b/inc/lainlib/string/str.h @@ -1,10 +1,19 @@ #pragma once +#include /************************ *** Team Kitty, 2021 *** *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + size_t strlen(const char* String); -bool strcmp(char* a, const char* b); \ No newline at end of file +bool strcmp(char* a, const char* b); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/inc/lainlib/vector/vector.h b/inc/lainlib/vector/vector.h deleted file mode 100644 index ad76e02..0000000 --- a/inc/lainlib/vector/vector.h +++ /dev/null @@ -1,30 +0,0 @@ -/************************ - *** Team Kitty, 2020 *** - *** Chroma *** - ***********************/ - - -#pragma once - -#include -#include -#include - -struct vector_t { - void** items; - size_t n; - - spinlock_t vector_lock; -}; - -int VectorRemoveItem(struct vector_t* vec, void* item); - -int VectorRemove(struct vector_t* vec, size_t index); - -void* VectorGet(struct vector_t* vec, size_t index); - -int VectorInsert(struct vector_t* vec, void* item, size_t index); - -int VectorAppend(struct vector_t* vec, void* item); - -int VectorDestroy(struct vector_t* vec); \ No newline at end of file diff --git a/linker.ld b/linker.ld index ea78291..e52790c 100644 --- a/linker.ld +++ b/linker.ld @@ -1,5 +1,3 @@ - -memstart = 0x14400; mmio = 0xfffffffff8000000; fb = 0xfffffffffc000000; @@ -16,7 +14,7 @@ SECTIONS environment = .; . += 4096; .text : { - + _kernel_text_start = .; KEEP(*(.text.boot)) *(.text .text.*) _kernel_rodata_start = .; diff --git a/src/editor/EditorDraw.c b/src/editor/EditorDraw.c new file mode 100644 index 0000000..670f099 --- /dev/null +++ b/src/editor/EditorDraw.c @@ -0,0 +1,7 @@ +#include +#include + +/************************ + *** Team Kitty, 2021 *** + *** Chroma *** + ***********************/ \ No newline at end of file diff --git a/src/editor/EditorMain.c b/src/editor/EditorMain.c index f5620eb..7209f36 100644 --- a/src/editor/EditorMain.c +++ b/src/editor/EditorMain.c @@ -21,10 +21,10 @@ void StartEditor(int callbackID) { layout.ScreenWidth = PrintInfo.screenWidth; layout.HeaderHeight = layout.ScreenHeight / 100 * 3; - layout.TextBoxHeight = (layout.ScreenHeight - layout.HeaderHeight) / 100 * 95; + layout.TextBoxHeight = ((layout.ScreenHeight - layout.HeaderHeight) / 100) * 95; layout.TextBoxY = ((layout.ScreenHeight + layout.HeaderHeight) - layout.TextBoxHeight) / 2; - layout.TextBoxWidth = layout.ScreenWidth / 100 * 95; + layout.TextBoxWidth = (layout.ScreenWidth / 100) * 95; layout.TextBoxX = (layout.ScreenWidth - layout.TextBoxWidth) / 2; SetForegroundColor(0x000084); diff --git a/src/editor/EditorWrite.c b/src/editor/EditorWrite.c new file mode 100644 index 0000000..670f099 --- /dev/null +++ b/src/editor/EditorWrite.c @@ -0,0 +1,7 @@ +#include +#include + +/************************ + *** Team Kitty, 2021 *** + *** Chroma *** + ***********************/ \ No newline at end of file diff --git a/src/kernel.c b/src/kernel.c index e36b7fb..f012cc9 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -8,6 +8,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /* This file is the entry point to the system. * It dictates the order of operations of everything the kernel actually does. * If a function isn't fired here, directly or indirectly, it is not run. @@ -150,4 +154,8 @@ void SomethingWentWrong(const char* Message) { void Exit(int ExitCode) { SerialPrintf("Kernel stopped with code %x\r\n", ExitCode); -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/lainlib/compression/lzgmini.c b/src/lainlib/compression/lzgmini.c index c00d401..bb06ee8 100644 --- a/src/lainlib/compression/lzgmini.c +++ b/src/lainlib/compression/lzgmini.c @@ -27,6 +27,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /*-- PRIVATE -----------------------------------------------------------------*/ /* Internal definitions */ @@ -188,3 +192,7 @@ lzg_uint32_t LZG_Decode(const unsigned char *in, lzg_uint32_t insize, else return decodedSize; } + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/lainlib/ethernet/e1000/E1000Driver.c b/src/lainlib/ethernet/e1000/E1000Driver.c index 0d03ad4..1829450 100644 --- a/src/lainlib/ethernet/e1000/E1000Driver.c +++ b/src/lainlib/ethernet/e1000/E1000Driver.c @@ -1,27 +1,32 @@ -/************************* - *** Team Kitty, 2021 *** - *** Lainlib *** - ************************/ #include #include #include #include +/************************* + *** Team Kitty, 2021 *** + *** Lainlib *** + ************************/ + +#ifdef __cplusplus +extern "C" { +#endif + /** * This file handles all the logic for interfacing with the E1000 networking device. * This card is labelled either the Intel I217, or Intel Gigabit 82577LM. * These cards are identical, and this driver will work identically for both of them. - * + * * To use this driver, allocate an e1000_device struct and pass it to the E1000Init() function, * along with its' PCI device header. - * + * * TODO: usage information */ /** * Write data to the device's command registers. * If we use BAR type 0, we use MMIO, otherwise ports. - * + * * @param Device The device to which we write the data. * @param Address The address to write the data at. For MMIO, the offset from base. * @param Data The data to write into the register. @@ -349,4 +354,8 @@ int E1000Send(e1000_device_t* Device, const void* Data, uint16_t Length) { while(!(Device->TransmitPackets[temp]->Status & 0xFF)); return 0; -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/lainlib/ethernet/ethernet.h b/src/lainlib/ethernet/ethernet.h index 7a9a095..0ddb69c 100644 --- a/src/lainlib/ethernet/ethernet.h +++ b/src/lainlib/ethernet/ethernet.h @@ -1,9 +1,13 @@ +#include + /************************ *** Team Kitty, 2021 *** - *** Chroma *** + *** Lainlib *** ***********************/ -#include +#ifdef __cplusplus +extern "C" { +#endif struct mac_address { uint8_t MAC[6]; @@ -20,4 +24,8 @@ struct ethernet_packet { mac_address Source; uint16_t Type; uint8_t Payload[]; -}; \ No newline at end of file +}; + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/lainlib/list/basic_list.c b/src/lainlib/list/basic_list.c index b070140..5d13657 100644 --- a/src/lainlib/list/basic_list.c +++ b/src/lainlib/list/basic_list.c @@ -1,5 +1,9 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + void ListAdd(list_entry_t* Head, list_entry_t* New) { New->Next = Head->Next; New->Previous = Head; @@ -24,4 +28,8 @@ void ListRemove(list_entry_t* Entry) { bool ListIsEmpty(list_entry_t* Head) { return Head->Next == Head; -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/lainlib/mutex/ticketlock.c b/src/lainlib/mutex/ticketlock.c index 6d73794..03fc4e7 100644 --- a/src/lainlib/mutex/ticketlock.c +++ b/src/lainlib/mutex/ticketlock.c @@ -1,6 +1,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + void TicketLock(ticketlock_t* Lock) { size_t Ticket = atomic_fetch_add_explicit(&Lock->NextTicket, 1, memory_order_relaxed); @@ -18,4 +22,8 @@ bool TicketAttemptLock(ticketlock_t* Lock) { void TicketUnlock(ticketlock_t* Lock) { size_t NextTicket = atomic_load_explicit(&Lock->NowServing, memory_order_relaxed) + 1; atomic_store_explicit(&Lock->NowServing, NextTicket, memory_order_release); -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/lainlib/string/str.c b/src/lainlib/string/str.c index 88bd40d..4e3262d 100644 --- a/src/lainlib/string/str.c +++ b/src/lainlib/string/str.c @@ -1,11 +1,16 @@ -/************************ - *** Team Kitty, 2021 *** - *** Chroma *** - ***********************/ #include #include #include +/************************ + *** Team Kitty, 2021 *** + *** Lainlib *** + ***********************/ + +#ifdef __cplusplus +extern "C" { +#endif + size_t strlen(const char* String) { size_t Len = 0; while(String[Len] != '\0') { @@ -22,4 +27,8 @@ bool strcmp(char* a, const char* b) { aI++; bI++; } -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/lainlib/vector.c b/src/lainlib/vector.c deleted file mode 100644 index 89919b8..0000000 --- a/src/lainlib/vector.c +++ /dev/null @@ -1,68 +0,0 @@ -#include - -/************************ - *** Team Kitty, 2020 *** - *** Chroma *** - ***********************/ - -/* This file provides a Chroma implementation of std::vector, a C++ standard library class. - * It has a lot of work left to be done, but it's usable for its intended function (Graphics) - */ - -int VectorRemoveItem(struct vector_t* vec, void* item) { - //TODO - return -1; - -} - -int VectorRemove(struct vector_t* vec, size_t index) { - - if (!vec) return 0; - - //TODO: Vector spinlock - // AcqSpinlock(&vec->lock); - - if((index + 1) > vec->n) return 0; - - vec->items[index] = NULL; - - for (int i = 0; i < vec->n; i++) { - vec->items[i] = vec->items[i + 1]; - } - - //TODO: vector reallocate - // realloc(vec->items, vec->n - 1); - - vec->n--; - - // ReleaseSpinlock(&vec->lock); - - return 1; - -} - -void* VectorGet(struct vector_t* vec, size_t index) { - - if(!vec) return 0; - - //TODO: Vector spinlock - // AcqSpinlock(&vec->lock); - - if((index + 1) > vec->n) return NULL; - - // ReleaseSpinlock(&vec->lock); - return vec->items[index]; - -} - -int VectorInsert(struct vector_t* vec, void* item, size_t index) { - -} - -int VectorAppend(struct vector_t* vec, void* item) { - -} - -int VectorDestroy(struct vector_t* vec) { - -} \ No newline at end of file diff --git a/src/system/cpu.c b/src/system/cpu.c index 545b24d..23c5513 100644 --- a/src/system/cpu.c +++ b/src/system/cpu.c @@ -6,6 +6,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /* This class provides functions for setting up and preparing the CPU for the things the kernel will do. * Mainly, it allows you to: * @@ -265,5 +269,6 @@ void SetupIDT() { } - - +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/system/drivers/elf.c b/src/system/drivers/elf.c index 1529c6f..5aff89b 100644 --- a/src/system/drivers/elf.c +++ b/src/system/drivers/elf.c @@ -4,9 +4,13 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /* * This file provides utility functions for parsing ELF headers. - * This exists so that the kernel can find itself for remapping, + * This exists so that the kernel can find itself for remapping, * but I may end up using ELF as the kernel's executable format. * Writing an ELF loader is on the to-do list, after all. ! This needs to be cleaned up. @@ -17,10 +21,10 @@ extern size_t KernelLocation; int ParseKernelHeader(size_t InitrdPtr) { int flag = 0; - + SerialPrintf("[ boot] Searching for kernel... Constants start at 0x%p / 0x%p\r\n", ((size_t) (&_kernel_text_start) - KernelAddr) + InitrdPtr, (size_t) (&_kernel_text_start)); // We stop at the constants in the kernel, otherwise we'll read the constant ELF64MAGIC which is stored inside the kernel... - + size_t headerLoc = 0; for(size_t i = InitrdPtr; i < ((size_t) (&_kernel_text_start) - KernelAddr) + InitrdPtr; i++) { if(*((volatile uint32_t*)(i)) == ELF64MAGIC) { @@ -54,21 +58,21 @@ int ParseKernelHeader(size_t InitrdPtr) { uint16_t ExecutableType = (uint16_t) *((volatile uint8_t*)(headerLoc + ELFTYPE_OFF)); uint16_t MachineType = (uint16_t) *((volatile uint8_t*)(headerLoc + ELFMACHINE_OFF)); - + SerialPrintf( "[ boot] ELF header at 0x%p.\r\n\tConsidering ELF with:\r\n\tBitness %d: %d\r\n\tEntry point 0x%p\r\n\tFile type %s : 0x%x\r\n\tArchitecture %s : 0x%x\r\n", headerLoc, HeaderClass == 2 ? 64 : 32, HeaderClass, EntryPoint, - ExecutableType == FIXENDIAN16(0x0200) ? "EXECUTABLE" : "OTHER", - FIXENDIAN16(ExecutableType), - MachineType == FIXENDIAN16(0x3E00) ? "AMD64" : "OTHER", + ExecutableType == FIXENDIAN16(0x0200) ? "EXECUTABLE" : "OTHER", + FIXENDIAN16(ExecutableType), + MachineType == FIXENDIAN16(0x3E00) ? "AMD64" : "OTHER", FIXENDIAN16(MachineType)); - - - + + + if(EntryPoint == (size_t) (&_kernel_text_start)) { SerialPrintf("[ boot] Header at 0x%p matches kernel header.\r\n", headerLoc); flag = 1; @@ -89,3 +93,6 @@ int ParseKernelHeader(size_t InitrdPtr) { } +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/system/drivers/keyboard.c b/src/system/drivers/keyboard.c index dbf8a60..9014eed 100644 --- a/src/system/drivers/keyboard.c +++ b/src/system/drivers/keyboard.c @@ -6,6 +6,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /* This file contains (mostly unused) implementations of a full PS/2 keyboard driver. * * It provides provisions for full 2-way communication, as well as auxiliary key commands. @@ -147,4 +151,8 @@ void WaitFor8042() { while(full) { full = ReadPort(0x64, 1) & 1; } -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/system/interrupts.c b/src/system/interrupts.c index 4161c9e..6701ed6 100644 --- a/src/system/interrupts.c +++ b/src/system/interrupts.c @@ -1,8 +1,17 @@ +#include +#include +#include +#include + /************************ *** Team Kitty, 2020 *** *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /* This file contains all of the ISR and IRQ * (Interrupt Service Request) functions. * @@ -32,11 +41,6 @@ * these having a size_t input as an error code. */ -#include -#include -#include -#include - const char* ExceptionStrings[] = { "Division by Zero", "Debug", @@ -457,4 +461,8 @@ __attribute__((interrupt)) void IRQ14Handler(INTERRUPT_FRAME* Frame) { } __attribute__((interrupt)) void IRQ15Handler(INTERRUPT_FRAME* Frame) { IRQ_Common(Frame, 15); -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/system/memory/abstract_allocator.c b/src/system/memory/abstract_allocator.c index a1aa18d..bc641ae 100644 --- a/src/system/memory/abstract_allocator.c +++ b/src/system/memory/abstract_allocator.c @@ -4,12 +4,14 @@ #include #include - /************************ *** Team Kitty, 2020 *** *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif /************************************************ * C O N S T A N T S A N D M A C R O S @@ -66,12 +68,12 @@ alloc_decl int Alloc_FindLastOne_64(size_t size) { int high = (int)(size >> 32); int bits = 0; - - if(high) + + if(high) bits = 32 + Alloc_FindLastOne(high); - else + else bits = Alloc_FindLastOne((int)size & 0xFFFFFFFF); - + return bits; } @@ -795,4 +797,8 @@ void* AllocatorRealloc(allocator_t Allocator, void* Address, size_t NewSize) { } return Pointer; -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/system/memory/liballoc.c b/src/system/memory/liballoc.c index 78bd064..c626771 100644 --- a/src/system/memory/liballoc.c +++ b/src/system/memory/liballoc.c @@ -3,6 +3,10 @@ /** Durand's Amazing Super Duper Memory functions. */ +#ifdef __cplusplus +extern "C" { +#endif + #define VERSION "1.1" #define ALIGNMENT 16ul//4ul ///< This is the byte alignment that memory must be allocated on. IMPORTANT for GTK and other stuff. @@ -858,3 +862,6 @@ void* PREFIX(realloc)(void *p, size_t size) return ptr; } +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/system/memory/paging.c b/src/system/memory/paging.c index db4aad7..4883942 100644 --- a/src/system/memory/paging.c +++ b/src/system/memory/paging.c @@ -5,6 +5,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + #define PAGE_TABLES_GET_PDPT(address) \ (address & ((size_t) 0x1FF << 39)) >> 39 #define PAGE_TABLES_GET_PDP(address) \ @@ -328,3 +332,7 @@ size_t* CreateNewPageTable(address_space_t* AddressSpace) { return NewPML4; } + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/system/memory/physmem.c b/src/system/memory/physmem.c index 6d3a9cb..a514e75 100644 --- a/src/system/memory/physmem.c +++ b/src/system/memory/physmem.c @@ -1,5 +1,4 @@ #include -#include #include /************************ @@ -7,6 +6,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /* This file contains functions for physical memory management. * * This is also called blocking, or block memory allocation. @@ -341,4 +344,6 @@ void* memset(void* dst, int src, size_t len) { return dst; } - +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/system/memory/stack.c b/src/system/memory/stack.c index b8d9553..12e4365 100644 --- a/src/system/memory/stack.c +++ b/src/system/memory/stack.c @@ -4,15 +4,19 @@ *** Chroma *** ***********************/ -/* +#ifdef __cplusplus +extern "C" { +#endif + +/* * This file aims to implement stack unwinding * to trace faulty functions. - * + * * I was in the middle of debugging a jump to null * when i started creating this, so there will be a * lot of functionality here left over from that * initial goal, probably... - * + * * //TODO: Rework this to allow unwinding function parameters on call. */ @@ -26,4 +30,8 @@ void StackTrace(size_t cycles) { stack = stack->rbp; } SerialPrintf("[Trace] Stack trace over.\r\n"); -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/system/pci.c b/src/system/pci.c index f8fc482..4a40a60 100644 --- a/src/system/pci.c +++ b/src/system/pci.c @@ -5,11 +5,15 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /* This file contains functions for accessing the PCI bus, * and devices contained wherein. - * + * * It allows you to query the bus, as well as communicate with individual devices. - * + * */ pci_device_t** pci_root_devices = NULL; @@ -520,4 +524,8 @@ const char* PCIGetClassName(uint8_t DeviceClass) { } return "Invalid device!"; -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/system/rw.c b/src/system/rw.c index 230034f..18c6d35 100644 --- a/src/system/rw.c +++ b/src/system/rw.c @@ -5,11 +5,15 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /* This file serves to allow us to communicate with the computer through raw I/O. * It provides interfaces for Ports and commonly used Registers (Control Registers, Model-Specific Registers, GDT, IDT..) - * + * * Additionally, there are wrapper functions for MMIO accesses. - * + * */ uint32_t ReadPort(uint16_t Port, int Length) { @@ -255,3 +259,6 @@ void WriteTSR(uint16_t TSRData) { } +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/system/serial.c b/src/system/serial.c index 4968b3c..3ed2cdb 100644 --- a/src/system/serial.c +++ b/src/system/serial.c @@ -4,6 +4,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /* This file provides functions related to the Serial port. * Through this file, you send and receive text and extra debugging information if available. */ @@ -45,4 +49,8 @@ void WriteSerialString(const char* str, size_t len) { for(size_t i = 0; i < len; i++) { WriteSerialChar(str[i]); } -} \ No newline at end of file +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/video/draw.c b/src/video/draw.c index d81abb5..b7877ef 100644 --- a/src/video/draw.c +++ b/src/video/draw.c @@ -7,6 +7,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /** * This file contains all of the draw-to-screen routines. * It (currently; 23/08/20) handles the keyboard input test routine, @@ -470,3 +474,6 @@ void DrawFilledCircle(size_t centerX, size_t centerY, size_t radius) { DrawFilledCircleInternal(centerX, centerY, radius, 3, 0); } +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/video/print.c b/src/video/print.c index 1599299..c7c2a60 100644 --- a/src/video/print.c +++ b/src/video/print.c @@ -5,6 +5,10 @@ *** Chroma *** ***********************/ +#ifdef __cplusplus +extern "C" { +#endif + /* This file contains all of the String / Print related functions * that are required by the core of the kernel. * @@ -191,3 +195,7 @@ int Printf(const char* restrict Format, ...) { va_end(Parameters); return CharsWritten; } + +#ifdef __cplusplus +} +#endif \ No newline at end of file