Refactor for C++ components

This commit is contained in:
Curle 2021-07-04 21:47:09 +01:00
parent 48e9b81478
commit 6a39a82b08
Signed by: TheCurle
GPG Key ID: 5942F13718443F79
50 changed files with 450 additions and 215 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ tools/x86_64-elf-tools
!src/global/*.o !src/global/*.o
!src/assets/z*.o

View File

@ -1,6 +1,7 @@
#project config #project config
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_COMPILER x86_64-elf-g++)
set(CMAKE_C_COMPILER x86_64-elf-gcc) set(CMAKE_C_COMPILER x86_64-elf-gcc)
# cheat the compile test # cheat the compile test
@ -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_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_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)

View File

@ -5,6 +5,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* This file contains most of the symbols required to start and run the Chroma Editor. * This file contains most of the symbols required to start and run the Chroma Editor.
* *
@ -117,3 +121,7 @@ void SetLine(EditorState* state, struct EditorLine* line);
void AppendLine(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 AppendToLine(EditorState* state, struct EditorLine* line, size_t textLength, char* text);
void RemoveLine(EditorState* state, size_t line); void RemoveLine(EditorState* state, size_t line);
#ifdef __cplusplus
}
#endif

View File

@ -1,7 +1,4 @@
#pragma once
#ifndef _BOOTLOADER_H_
#define _BOOTLOADER_H_
/************************ /************************
*** Team Kitty, 2020 *** *** Team Kitty, 2020 ***
*** Chroma *** *** Chroma ***
@ -161,5 +158,3 @@ typedef struct {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif

View File

@ -9,6 +9,10 @@
* It also provides the symbols for the framebuffer and configuration file, which are both equually important. * 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 #define UNUSED(x) (void)x
#include <stdint.h> #include <stdint.h>
@ -25,9 +29,6 @@
#include <lainlib/lainlib.h> #include <lainlib/lainlib.h>
#include <lainlib/ethernet/e1000/e1000.h> #include <lainlib/ethernet/e1000/e1000.h>
//Removed cause "wacky copyrighted stuff"
//#include <kernel/system/screen.h>
extern size_t LoadAddr; extern size_t LoadAddr;
extern bootinfo bootldr; extern bootinfo bootldr;
extern unsigned char* environment; extern unsigned char* environment;
@ -83,3 +84,7 @@ int Main();
void Exit(); void Exit();
void SomethingWentWrong(const char* Message); void SomethingWentWrong(const char* Message);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@ -8,6 +8,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
typedef struct __attribute__((packed)) { typedef struct __attribute__((packed)) {
uint16_t LowLimit; uint16_t LowLimit;
uint16_t BaseLow; uint16_t BaseLow;
@ -73,3 +77,6 @@ typedef struct __attribute__((packed)) {
uint16_t IOMap; uint16_t IOMap;
} TSS64; } TSS64;
#ifdef __cplusplus
} // extern "C"
#endif

View File

@ -5,6 +5,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
typedef struct { typedef struct {
char Char; char Char;
char Scancode; char Scancode;
@ -18,3 +22,7 @@ extern KeyboardCallback KeyboardCallbacks[16];
int SetupKBCallback(void (*Handler)(KeyboardData Frame)); int SetupKBCallback(void (*Handler)(KeyboardData Frame));
void UninstallKBCallback(int Index); void UninstallKBCallback(int Index);
#ifdef __cplusplus
}
#endif

View File

@ -1,12 +0,0 @@
#pragma once
/************************
*** Team Kitty, 2020 ***
*** Chroma ***
***********************/
#include <stddef.h>
#include <stdint.h>
uint8_t HeapEnabled = 0;

View File

@ -6,6 +6,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
extern const char* ExceptionStrings[]; extern const char* ExceptionStrings[];
@ -89,3 +93,7 @@ void IRQ12Handler(INTERRUPT_FRAME* Frame);
void IRQ13Handler(INTERRUPT_FRAME* Frame); void IRQ13Handler(INTERRUPT_FRAME* Frame);
void IRQ14Handler(INTERRUPT_FRAME* Frame); void IRQ14Handler(INTERRUPT_FRAME* Frame);
void IRQ15Handler(INTERRUPT_FRAME* Frame); void IRQ15Handler(INTERRUPT_FRAME* Frame);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@ -1,5 +1,9 @@
#pragma once #pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <kernel/system/descriptors.h> #include <kernel/system/descriptors.h>
/************************ /************************
@ -74,3 +78,7 @@ int Printf(const char* restrict Format, ...);
void* memcpy(void* dest, void const* src, size_t len); void* memcpy(void* dest, void const* src, size_t len);
void* memset(void* dst, int src, size_t len); void* memset(void* dst, int src, size_t len);
#ifdef __cplusplus
}
#endif

View File

@ -1,3 +1,9 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <kernel/system/interrupts.h> #include <kernel/system/interrupts.h>
@ -289,3 +295,7 @@ extern void *PREFIX(malloc)(size_t); ///< The standard function.
extern void *PREFIX(realloc)(void *, 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(calloc)(size_t, size_t); ///< The standard function.
extern void PREFIX(free)(void *); ///< The standard function. extern void PREFIX(free)(void *); ///< The standard function.
#ifdef __cplusplus
}
#endif

View File

@ -1,4 +1,9 @@
#pragma once #pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
@ -172,3 +177,7 @@ typedef struct {
extern pci_device_t** pci_root_devices; extern pci_device_t** pci_root_devices;
extern pci_entry_t* pci_map; extern pci_entry_t* pci_map;
#ifdef __cplusplus
}
#endif

View File

@ -14,8 +14,6 @@
#define MAX_PROCESSES 128 #define MAX_PROCESSES 128
#define PROCESS_STACK 65535 #define PROCESS_STACK 65535
static size_t
/** /**
* @brief All the data a process needs. * @brief All the data a process needs.
* *
@ -73,6 +71,7 @@ class Process {
ProcessState State; ProcessState State;
bool User; // Is this process originated in userspace? 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 UniquePID; // Globally Unique ID.
size_t KernelPID; // If in kernel space, the PID. size_t KernelPID; // If in kernel space, the PID.
@ -123,8 +122,37 @@ class Process {
void InitMessages(); 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 SetCore(size_t CoreID) { Core = CoreID; };
void IncreaseSleep(size_t Interval) { Sleeping += Interval; }; void IncreaseSleep(size_t Interval) { Sleeping += Interval; };
@ -134,8 +162,15 @@ class Process {
ProcessHeader* GetHeader() { return &Header; }; 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; }; size_t GetParent() const { return ParentPID; };
ProcessState GetState() const { return State; };
bool IsValid() const { return KernelPID != 0; }; bool IsValid() const { return KernelPID != 0; };
bool IsUsed() const { return (State != ProcessState::PROCESS_AVAILABLE && State != ProcessState::PROCESS_CRASH && State != ProcessState::PROCESS_REAP) && IsValid(); }; 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); bool flag = !(ORS && !IsActive);
return State == ProcessState::PROCESS_WAITING && Core == CPU && KernelPID != 0 && flag && !IsSleeping(); return State == ProcessState::PROCESS_WAITING && Core == CPU && KernelPID != 0 && flag && !IsSleeping();
} };
size_t GetCore() const { return Core; }; 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);
}; };

View File

@ -1,4 +1,9 @@
#pragma once #pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@ -13,3 +18,7 @@ typedef struct stackframe {
} stackframe_t; } stackframe_t;
void StackTrace(size_t cycles); void StackTrace(size_t cycles);
#ifdef __cplusplus
}
#endif

View File

@ -3,6 +3,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
// This file contains all of the bitmap fonts made by me (Curle) and taken from the public domain // 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 // eg. http://dimensionalrift.homelinux.net/combuster/mos3/?p=viewsource&file=/modules/gfx/font8_8.asm
@ -464,3 +468,7 @@ const unsigned char bitfont_block[32][8] = {
{ 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F}, // U+259E (boxes top right and bottom left) { 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) { 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF}, // U+259F (boxes right and bottom)
}; };
#ifdef __cplusplus
}
#endif

View File

@ -5,6 +5,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* Drawing routines for screen manipulation. * Drawing routines for screen manipulation.
* This will be pulled out into the Helix library soon. * This will be pulled out into the Helix library soon.
@ -56,3 +60,7 @@ 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 DrawFilledCircle(size_t centerX, size_t centerY, size_t radius);
void DrawLineCircle(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); void DrawLineCircleCorners(size_t centerX, size_t centerY, size_t radius, char cornerMask);
#ifdef __cplusplus
}
#endif

View File

@ -33,8 +33,8 @@ extern "C" {
#endif #endif
#define LZG_VERSION "1.0.10" /**< @brief LZG library version string */ #define LZG_VERSION "1.0.10" /**< @brief LZG library version string */
#define LZG_VERNUM 0x0100000a /**< @brief LZG library version number (strictly #define LZG_VERNUM 0x0100000a /**< @brief LZG library version number (strictly */
incremental) */ /* incremental) */
#define LZG_VER_MAJOR 1 /**< @brief LZG library major version */ #define LZG_VER_MAJOR 1 /**< @brief LZG library major version */
#define LZG_VER_MINOR 0 /**< @brief LZG library minor version */ #define LZG_VER_MINOR 0 /**< @brief LZG library minor version */
#define LZG_VER_REVISION 10 /**< @brief LZG library revision */ #define LZG_VER_REVISION 10 /**< @brief LZG library revision */

View File

@ -3,6 +3,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <kernel/system/pci.h> #include <kernel/system/pci.h>
@ -179,3 +183,7 @@ void E1000InterruptFired(INTERRUPT_FRAME* InterruptContext);
uint8_t* E1000GetMAC(e1000_device_t* Device); uint8_t* E1000GetMAC(e1000_device_t* Device);
// Send a packet // Send a packet
int E1000Send(e1000_device_t* Device, const void* Data, uint16_t Length); int E1000Send(e1000_device_t* Device, const void* Data, uint16_t Length);
#ifdef __cplusplus
}
#endif

View File

@ -1,19 +1,20 @@
#pragma once #pragma once
#ifdef __cplusplus
extern "C" {
#endif
/************************ /************************
*** Team Kitty, 2020 *** *** Team Kitty, 2020 ***
*** Chroma *** *** Chroma ***
***********************/ ***********************/
/* Defines all of the temporary library functions. /* Defines all of the temporary library functions.
* All of this must be moved into the Chroma stdlib. * All of this must be moved into the Chroma stdlib.
* They exist here as guidance, and as utility for the kernel itself. * 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". * If need be, they can also be moved into a trimmed-down "kernel libc" or "libk".
*/ */
#include <lainlib/vector/vector.h>
#include <lainlib/list/list.h> #include <lainlib/list/list.h>
#include <lainlib/mutex/spinlock.h> #include <lainlib/mutex/spinlock.h>
@ -22,3 +23,7 @@
#include <lainlib/string/str.h> #include <lainlib/string/str.h>
#include <lainlib/compression/lzg.h> #include <lainlib/compression/lzg.h>
#ifdef __cplusplus
} // extern "C"
#endif

View File

@ -1,5 +1,9 @@
#include <stdbool.h> #include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct list_entry { typedef struct list_entry {
struct list_entry* Previous; struct list_entry* Previous;
struct list_entry* Next; struct list_entry* Next;
@ -32,3 +36,7 @@ bool ListIsEmpty(list_entry_t* Head);
for(pos = UNSAFE_CAST((head)->next, typeof(*(pos)), member); &pos->member != (head); pos = LISTNEXT(pos, member)) for(pos = UNSAFE_CAST((head)->next, typeof(*(pos)), member); &pos->member != (head); pos = LISTNEXT(pos, member))
#define LASTENTRY 0 #define LASTENTRY 0
#ifdef __cplusplus
}
#endif

View File

@ -5,6 +5,9 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
typedef volatile int spinlock_t; typedef volatile int spinlock_t;
@ -20,3 +23,6 @@ typedef volatile int spinlock_t;
__sync_synchronize(); \ __sync_synchronize(); \
name = 0; name = 0;
#ifdef __cplusplus
}
#endif

View File

@ -7,6 +7,11 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* This file provides a simple implementation of a ticket-based locking system. /* This file provides a simple implementation of a ticket-based locking system.
* You should probably prefer Spinlock over Ticketlock. * You should probably prefer Spinlock over Ticketlock.
* *
@ -30,3 +35,6 @@ bool TicketAttemptLock(ticketlock_t* Lock);
void TicketUnlock(ticketlock_t* Lock); void TicketUnlock(ticketlock_t* Lock);
#ifdef __cplusplus
}
#endif

View File

@ -1,10 +1,19 @@
#pragma once #pragma once
#include <stddef.h>
/************************ /************************
*** Team Kitty, 2021 *** *** Team Kitty, 2021 ***
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
size_t strlen(const char* String); size_t strlen(const char* String);
bool strcmp(char* a, const char* b); bool strcmp(char* a, const char* b);
#ifdef __cplusplus
}
#endif

View File

@ -1,30 +0,0 @@
/************************
*** Team Kitty, 2020 ***
*** Chroma ***
***********************/
#pragma once
#include<stddef.h>
#include<stdint.h>
#include <lainlib/mutex/spinlock.h>
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);

View File

@ -1,5 +1,3 @@
memstart = 0x14400;
mmio = 0xfffffffff8000000; mmio = 0xfffffffff8000000;
fb = 0xfffffffffc000000; fb = 0xfffffffffc000000;

7
src/editor/EditorDraw.c Normal file
View File

@ -0,0 +1,7 @@
#include <kernel/chroma.h>
#include <editor/main.h>
/************************
*** Team Kitty, 2021 ***
*** Chroma ***
***********************/

View File

@ -21,10 +21,10 @@ void StartEditor(int callbackID) {
layout.ScreenWidth = PrintInfo.screenWidth; layout.ScreenWidth = PrintInfo.screenWidth;
layout.HeaderHeight = layout.ScreenHeight / 100 * 3; 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.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; layout.TextBoxX = (layout.ScreenWidth - layout.TextBoxWidth) / 2;
SetForegroundColor(0x000084); SetForegroundColor(0x000084);

7
src/editor/EditorWrite.c Normal file
View File

@ -0,0 +1,7 @@
#include <kernel/chroma.h>
#include <editor/main.h>
/************************
*** Team Kitty, 2021 ***
*** Chroma ***
***********************/

View File

@ -8,6 +8,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* This file is the entry point to the system. /* This file is the entry point to the system.
* It dictates the order of operations of everything the kernel actually does. * 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. * If a function isn't fired here, directly or indirectly, it is not run.
@ -151,3 +155,7 @@ void Exit(int ExitCode) {
SerialPrintf("Kernel stopped with code %x\r\n", ExitCode); SerialPrintf("Kernel stopped with code %x\r\n", ExitCode);
} }
#ifdef __cplusplus
}
#endif

View File

@ -27,6 +27,10 @@
#include <lainlib/lainlib.h> #include <lainlib/lainlib.h>
#ifdef __cplusplus
extern "C" {
#endif
/*-- PRIVATE -----------------------------------------------------------------*/ /*-- PRIVATE -----------------------------------------------------------------*/
/* Internal definitions */ /* Internal definitions */
@ -188,3 +192,7 @@ lzg_uint32_t LZG_Decode(const unsigned char *in, lzg_uint32_t insize,
else else
return decodedSize; return decodedSize;
} }
#ifdef __cplusplus
}
#endif

View File

@ -1,12 +1,17 @@
/*************************
*** Team Kitty, 2021 ***
*** Lainlib ***
************************/
#include <lainlib/ethernet/e1000/e1000.h> #include <lainlib/ethernet/e1000/e1000.h>
#include <kernel/chroma.h> #include <kernel/chroma.h>
#include <kernel/system/memory.h> #include <kernel/system/memory.h>
#include <kernel/system/interrupts.h> #include <kernel/system/interrupts.h>
/*************************
*** Team Kitty, 2021 ***
*** Lainlib ***
************************/
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* This file handles all the logic for interfacing with the E1000 networking device. * 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. * This card is labelled either the Intel I217, or Intel Gigabit 82577LM.
@ -350,3 +355,7 @@ int E1000Send(e1000_device_t* Device, const void* Data, uint16_t Length) {
return 0; return 0;
} }
#ifdef __cplusplus
}
#endif

View File

@ -1,9 +1,13 @@
#include <stdint.h>
/************************ /************************
*** Team Kitty, 2021 *** *** Team Kitty, 2021 ***
*** Chroma *** *** Lainlib ***
***********************/ ***********************/
#include <stdint.h> #ifdef __cplusplus
extern "C" {
#endif
struct mac_address { struct mac_address {
uint8_t MAC[6]; uint8_t MAC[6];
@ -21,3 +25,7 @@ struct ethernet_packet {
uint16_t Type; uint16_t Type;
uint8_t Payload[]; uint8_t Payload[];
}; };
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,9 @@
#include <lainlib/list/list.h> #include <lainlib/list/list.h>
#ifdef __cplusplus
extern "C" {
#endif
void ListAdd(list_entry_t* Head, list_entry_t* New) { void ListAdd(list_entry_t* Head, list_entry_t* New) {
New->Next = Head->Next; New->Next = Head->Next;
New->Previous = Head; New->Previous = Head;
@ -25,3 +29,7 @@ void ListRemove(list_entry_t* Entry) {
bool ListIsEmpty(list_entry_t* Head) { bool ListIsEmpty(list_entry_t* Head) {
return Head->Next == Head; return Head->Next == Head;
} }
#ifdef __cplusplus
}
#endif

View File

@ -1,6 +1,10 @@
#include <kernel/chroma.h> #include <kernel/chroma.h>
#include <lainlib/lainlib.h> #include <lainlib/lainlib.h>
#ifdef __cplusplus
extern "C" {
#endif
void TicketLock(ticketlock_t* Lock) { void TicketLock(ticketlock_t* Lock) {
size_t Ticket = atomic_fetch_add_explicit(&Lock->NextTicket, 1, memory_order_relaxed); size_t Ticket = atomic_fetch_add_explicit(&Lock->NextTicket, 1, memory_order_relaxed);
@ -19,3 +23,7 @@ void TicketUnlock(ticketlock_t* Lock) {
size_t NextTicket = atomic_load_explicit(&Lock->NowServing, memory_order_relaxed) + 1; size_t NextTicket = atomic_load_explicit(&Lock->NowServing, memory_order_relaxed) + 1;
atomic_store_explicit(&Lock->NowServing, NextTicket, memory_order_release); atomic_store_explicit(&Lock->NowServing, NextTicket, memory_order_release);
} }
#ifdef __cplusplus
}
#endif

View File

@ -1,11 +1,16 @@
/************************
*** Team Kitty, 2021 ***
*** Chroma ***
***********************/
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
/************************
*** Team Kitty, 2021 ***
*** Lainlib ***
***********************/
#ifdef __cplusplus
extern "C" {
#endif
size_t strlen(const char* String) { size_t strlen(const char* String) {
size_t Len = 0; size_t Len = 0;
while(String[Len] != '\0') { while(String[Len] != '\0') {
@ -23,3 +28,7 @@ bool strcmp(char* a, const char* b) {
bI++; bI++;
} }
} }
#ifdef __cplusplus
}
#endif

View File

@ -1,68 +0,0 @@
#include <templib/templib.h>
/************************
*** 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) {
}

View File

@ -6,6 +6,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* This class provides functions for setting up and preparing the CPU for the things the kernel will do. /* This class provides functions for setting up and preparing the CPU for the things the kernel will do.
* Mainly, it allows you to: * Mainly, it allows you to:
* *
@ -265,5 +269,6 @@ void SetupIDT() {
} }
#ifdef __cplusplus
}
#endif

View File

@ -4,6 +4,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* /*
* This file provides utility functions for parsing ELF headers. * 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,
@ -89,3 +93,6 @@ int ParseKernelHeader(size_t InitrdPtr) {
} }
#ifdef __cplusplus
}
#endif

View File

@ -6,6 +6,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* This file contains (mostly unused) implementations of a full PS/2 keyboard driver. /* 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. * It provides provisions for full 2-way communication, as well as auxiliary key commands.
@ -148,3 +152,7 @@ void WaitFor8042() {
full = ReadPort(0x64, 1) & 1; full = ReadPort(0x64, 1) & 1;
} }
} }
#ifdef __cplusplus
}
#endif

View File

@ -1,8 +1,17 @@
#include <kernel/chroma.h>
#include <kernel/video/draw.h>
#include <kernel/system/interrupts.h>
#include <stdbool.h>
/************************ /************************
*** Team Kitty, 2020 *** *** Team Kitty, 2020 ***
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* This file contains all of the ISR and IRQ /* This file contains all of the ISR and IRQ
* (Interrupt Service Request) functions. * (Interrupt Service Request) functions.
* *
@ -32,11 +41,6 @@
* these having a size_t input as an error code. * these having a size_t input as an error code.
*/ */
#include <kernel/chroma.h>
#include <kernel/video/draw.h>
#include <kernel/system/interrupts.h>
#include <stdbool.h>
const char* ExceptionStrings[] = { const char* ExceptionStrings[] = {
"Division by Zero", "Division by Zero",
"Debug", "Debug",
@ -458,3 +462,7 @@ __attribute__((interrupt)) void IRQ14Handler(INTERRUPT_FRAME* Frame) {
__attribute__((interrupt)) void IRQ15Handler(INTERRUPT_FRAME* Frame) { __attribute__((interrupt)) void IRQ15Handler(INTERRUPT_FRAME* Frame) {
IRQ_Common(Frame, 15); IRQ_Common(Frame, 15);
} }
#ifdef __cplusplus
}
#endif

View File

@ -4,12 +4,14 @@
#include <kernel/system/memory.h> #include <kernel/system/memory.h>
#include <kernel/system/io.h> #include <kernel/system/io.h>
/************************ /************************
*** Team Kitty, 2020 *** *** Team Kitty, 2020 ***
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/************************************************ /************************************************
* C O N S T A N T S A N D M A C R O S * C O N S T A N T S A N D M A C R O S
@ -796,3 +798,7 @@ void* AllocatorRealloc(allocator_t Allocator, void* Address, size_t NewSize) {
return Pointer; return Pointer;
} }
#ifdef __cplusplus
}
#endif

View File

@ -3,6 +3,10 @@
/** Durand's Amazing Super Duper Memory functions. */ /** Durand's Amazing Super Duper Memory functions. */
#ifdef __cplusplus
extern "C" {
#endif
#define VERSION "1.1" #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. #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; return ptr;
} }
#ifdef __cplusplus
}
#endif

View File

@ -5,6 +5,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
#define PAGE_TABLES_GET_PDPT(address) \ #define PAGE_TABLES_GET_PDPT(address) \
(address & ((size_t) 0x1FF << 39)) >> 39 (address & ((size_t) 0x1FF << 39)) >> 39
#define PAGE_TABLES_GET_PDP(address) \ #define PAGE_TABLES_GET_PDP(address) \
@ -328,3 +332,7 @@ size_t* CreateNewPageTable(address_space_t* AddressSpace) {
return NewPML4; return NewPML4;
} }
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,4 @@
#include <kernel/chroma.h> #include <kernel/chroma.h>
#include <kernel/system/heap.h>
#include <lainlib/lainlib.h> #include <lainlib/lainlib.h>
/************************ /************************
@ -7,6 +6,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* This file contains functions for physical memory management. /* This file contains functions for physical memory management.
* *
* This is also called blocking, or block memory allocation. * This is also called blocking, or block memory allocation.
@ -341,4 +344,6 @@ void* memset(void* dst, int src, size_t len) {
return dst; return dst;
} }
#ifdef __cplusplus
}
#endif

View File

@ -4,6 +4,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* /*
* This file aims to implement stack unwinding * This file aims to implement stack unwinding
* to trace faulty functions. * to trace faulty functions.
@ -27,3 +31,7 @@ void StackTrace(size_t cycles) {
} }
SerialPrintf("[Trace] Stack trace over.\r\n"); SerialPrintf("[Trace] Stack trace over.\r\n");
} }
#ifdef __cplusplus
}
#endif

View File

@ -5,6 +5,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* This file contains functions for accessing the PCI bus, /* This file contains functions for accessing the PCI bus,
* and devices contained wherein. * and devices contained wherein.
* *
@ -521,3 +525,7 @@ const char* PCIGetClassName(uint8_t DeviceClass) {
return "Invalid device!"; return "Invalid device!";
} }
#ifdef __cplusplus
}
#endif

View File

@ -5,6 +5,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* This file serves to allow us to communicate with the computer through raw I/O. /* 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..) * It provides interfaces for Ports and commonly used Registers (Control Registers, Model-Specific Registers, GDT, IDT..)
* *
@ -255,3 +259,6 @@ void WriteTSR(uint16_t TSRData) {
} }
#ifdef __cplusplus
}
#endif

View File

@ -4,6 +4,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* This file provides functions related to the Serial port. /* This file provides functions related to the Serial port.
* Through this file, you send and receive text and extra debugging information if available. * Through this file, you send and receive text and extra debugging information if available.
*/ */
@ -46,3 +50,7 @@ void WriteSerialString(const char* str, size_t len) {
WriteSerialChar(str[i]); WriteSerialChar(str[i]);
} }
} }
#ifdef __cplusplus
}
#endif

View File

@ -7,6 +7,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* This file contains all of the draw-to-screen routines. * This file contains all of the draw-to-screen routines.
* It (currently; 23/08/20) handles the keyboard input test routine, * 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); DrawFilledCircleInternal(centerX, centerY, radius, 3, 0);
} }
#ifdef __cplusplus
}
#endif

View File

@ -5,6 +5,10 @@
*** Chroma *** *** Chroma ***
***********************/ ***********************/
#ifdef __cplusplus
extern "C" {
#endif
/* This file contains all of the String / Print related functions /* This file contains all of the String / Print related functions
* that are required by the core of the kernel. * that are required by the core of the kernel.
* *
@ -191,3 +195,7 @@ int Printf(const char* restrict Format, ...) {
va_end(Parameters); va_end(Parameters);
return CharsWritten; return CharsWritten;
} }
#ifdef __cplusplus
}
#endif