Refactor for C++ components
This commit is contained in:
parent
48e9b81478
commit
6a39a82b08
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -19,3 +19,4 @@ tools/x86_64-elf-tools
|
|||
|
||||
|
||||
!src/global/*.o
|
||||
!src/assets/z*.o
|
|
@ -1,6 +1,7 @@
|
|||
#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
|
||||
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -117,3 +121,7 @@ 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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
|
||||
|
|
|
@ -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 <stdint.h>
|
||||
|
@ -25,9 +29,6 @@
|
|||
#include <lainlib/lainlib.h>
|
||||
#include <lainlib/ethernet/e1000/e1000.h>
|
||||
|
||||
//Removed cause "wacky copyrighted stuff"
|
||||
//#include <kernel/system/screen.h>
|
||||
|
||||
extern size_t LoadAddr;
|
||||
extern bootinfo bootldr;
|
||||
extern unsigned char* environment;
|
||||
|
@ -83,3 +84,7 @@ int Main();
|
|||
void Exit();
|
||||
|
||||
void SomethingWentWrong(const char* Message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
|
@ -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
|
|
@ -5,6 +5,10 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char Char;
|
||||
char Scancode;
|
||||
|
@ -18,3 +22,7 @@ extern KeyboardCallback KeyboardCallbacks[16];
|
|||
int SetupKBCallback(void (*Handler)(KeyboardData Frame));
|
||||
|
||||
void UninstallKBCallback(int Index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2020 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t HeapEnabled = 0;
|
||||
|
|
@ -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
|
|
@ -1,5 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#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* memset(void* dst, int src, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,3 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.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(calloc)(size_t, size_t); ///< The standard function.
|
||||
extern void PREFIX(free)(void *); ///< The standard function.
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,4 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
@ -172,3 +177,7 @@ typedef struct {
|
|||
|
||||
extern pci_device_t** pci_root_devices;
|
||||
extern pci_entry_t* pci_map;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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.
|
||||
|
@ -123,8 +122,37 @@ class Process {
|
|||
|
||||
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);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -13,3 +18,7 @@ typedef struct stackframe {
|
|||
} stackframe_t;
|
||||
|
||||
void StackTrace(size_t cycles);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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
|
||||
|
||||
|
@ -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, 0xFF, 0xFF, 0xFF, 0xFF}, // U+259F (boxes right and bottom)
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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.
|
||||
|
@ -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 DrawLineCircle(size_t centerX, size_t centerY, size_t radius);
|
||||
void DrawLineCircleCorners(size_t centerX, size_t centerY, size_t radius, char cornerMask);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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 */
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <kernel/system/pci.h>
|
||||
|
@ -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
|
|
@ -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 <lainlib/vector/vector.h>
|
||||
|
||||
#include <lainlib/list/list.h>
|
||||
|
||||
#include <lainlib/mutex/spinlock.h>
|
||||
|
@ -22,3 +23,7 @@
|
|||
#include <lainlib/string/str.h>
|
||||
|
||||
#include <lainlib/compression/lzg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
|
@ -1,5 +1,9 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct list_entry {
|
||||
struct list_entry* Previous;
|
||||
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))
|
||||
|
||||
#define LASTENTRY 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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
|
|
@ -7,6 +7,11 @@
|
|||
*** 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.
|
||||
*
|
||||
|
@ -30,3 +35,6 @@ bool TicketAttemptLock(ticketlock_t* Lock);
|
|||
|
||||
void TicketUnlock(ticketlock_t* Lock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,10 +1,19 @@
|
|||
#pragma once
|
||||
#include <stddef.h>
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2021 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
size_t strlen(const char* String);
|
||||
|
||||
bool strcmp(char* a, const char* b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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);
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
memstart = 0x14400;
|
||||
mmio = 0xfffffffff8000000;
|
||||
fb = 0xfffffffffc000000;
|
||||
|
||||
|
|
7
src/editor/EditorDraw.c
Normal file
7
src/editor/EditorDraw.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include <kernel/chroma.h>
|
||||
#include <editor/main.h>
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2021 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
|
@ -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);
|
||||
|
|
7
src/editor/EditorWrite.c
Normal file
7
src/editor/EditorWrite.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include <kernel/chroma.h>
|
||||
#include <editor/main.h>
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2021 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
|
@ -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.
|
||||
|
@ -151,3 +155,7 @@ void Exit(int ExitCode) {
|
|||
SerialPrintf("Kernel stopped with code %x\r\n", ExitCode);
|
||||
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -27,6 +27,10 @@
|
|||
|
||||
#include <lainlib/lainlib.h>
|
||||
|
||||
#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
|
|
@ -1,12 +1,17 @@
|
|||
/*************************
|
||||
*** Team Kitty, 2021 ***
|
||||
*** Lainlib ***
|
||||
************************/
|
||||
#include <lainlib/ethernet/e1000/e1000.h>
|
||||
#include <kernel/chroma.h>
|
||||
#include <kernel/system/memory.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 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;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,9 +1,13 @@
|
|||
#include <stdint.h>
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2021 ***
|
||||
*** Chroma ***
|
||||
*** Lainlib ***
|
||||
***********************/
|
||||
|
||||
#include <stdint.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct mac_address {
|
||||
uint8_t MAC[6];
|
||||
|
@ -21,3 +25,7 @@ struct ethernet_packet {
|
|||
uint16_t Type;
|
||||
uint8_t Payload[];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,5 +1,9 @@
|
|||
#include <lainlib/list/list.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void ListAdd(list_entry_t* Head, list_entry_t* New) {
|
||||
New->Next = Head->Next;
|
||||
New->Previous = Head;
|
||||
|
@ -25,3 +29,7 @@ void ListRemove(list_entry_t* Entry) {
|
|||
bool ListIsEmpty(list_entry_t* Head) {
|
||||
return Head->Next == Head;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,6 +1,10 @@
|
|||
#include <kernel/chroma.h>
|
||||
#include <lainlib/lainlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void TicketLock(ticketlock_t* Lock) {
|
||||
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;
|
||||
atomic_store_explicit(&Lock->NowServing, NextTicket, memory_order_release);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,11 +1,16 @@
|
|||
/************************
|
||||
*** Team Kitty, 2021 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2021 ***
|
||||
*** Lainlib ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
size_t strlen(const char* String) {
|
||||
size_t Len = 0;
|
||||
while(String[Len] != '\0') {
|
||||
|
@ -23,3 +28,7 @@ bool strcmp(char* a, const char* b) {
|
|||
bI++;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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) {
|
||||
|
||||
}
|
|
@ -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
|
|
@ -4,6 +4,10 @@
|
|||
*** 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,
|
||||
|
@ -89,3 +93,6 @@ int ParseKernelHeader(size_t InitrdPtr) {
|
|||
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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.
|
||||
|
@ -148,3 +152,7 @@ void WaitFor8042() {
|
|||
full = ReadPort(0x64, 1) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,8 +1,17 @@
|
|||
#include <kernel/chroma.h>
|
||||
#include <kernel/video/draw.h>
|
||||
#include <kernel/system/interrupts.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/************************
|
||||
*** 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 <kernel/chroma.h>
|
||||
#include <kernel/video/draw.h>
|
||||
#include <kernel/system/interrupts.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
const char* ExceptionStrings[] = {
|
||||
"Division by Zero",
|
||||
"Debug",
|
||||
|
@ -458,3 +462,7 @@ __attribute__((interrupt)) void IRQ14Handler(INTERRUPT_FRAME* Frame) {
|
|||
__attribute__((interrupt)) void IRQ15Handler(INTERRUPT_FRAME* Frame) {
|
||||
IRQ_Common(Frame, 15);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -4,12 +4,14 @@
|
|||
#include <kernel/system/memory.h>
|
||||
#include <kernel/system/io.h>
|
||||
|
||||
|
||||
/************************
|
||||
*** 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
|
||||
|
@ -796,3 +798,7 @@ void* AllocatorRealloc(allocator_t Allocator, void* Address, size_t NewSize) {
|
|||
|
||||
return Pointer;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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
|
|
@ -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
|
|
@ -1,5 +1,4 @@
|
|||
#include <kernel/chroma.h>
|
||||
#include <kernel/system/heap.h>
|
||||
#include <lainlib/lainlib.h>
|
||||
|
||||
/************************
|
||||
|
@ -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
|
|
@ -4,6 +4,10 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file aims to implement stack unwinding
|
||||
* to trace faulty functions.
|
||||
|
@ -27,3 +31,7 @@ void StackTrace(size_t cycles) {
|
|||
}
|
||||
SerialPrintf("[Trace] Stack trace over.\r\n");
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -5,6 +5,10 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This file contains functions for accessing the PCI bus,
|
||||
* and devices contained wherein.
|
||||
*
|
||||
|
@ -521,3 +525,7 @@ const char* PCIGetClassName(uint8_t DeviceClass) {
|
|||
|
||||
return "Invalid device!";
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -5,6 +5,10 @@
|
|||
*** 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..)
|
||||
*
|
||||
|
@ -255,3 +259,6 @@ void WriteTSR(uint16_t TSRData) {
|
|||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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.
|
||||
*/
|
||||
|
@ -46,3 +50,7 @@ void WriteSerialString(const char* str, size_t len) {
|
|||
WriteSerialChar(str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue
Block a user