Chroma/inc/kernel/system/core.hpp

70 lines
1.7 KiB
C++
Raw Permalink Normal View History

2022-02-17 02:03:05 +00:00
#pragma once
#include <kernel/constants.hpp>
#include <kernel/system/descriptors.h>
#include <kernel/system/memory.h>
#include <stddef.h>
#include <stdint.h>
/************************
*** Team Kitty, 2021 ***
*** Chroma ***
***********************/
/**
* The relevant information contained within a stack trace - each call consists of the
* contained information. By navigating the RBP until the base is found, a full backwards call stack can be determined.
*/
struct StackFrame {
StackFrame* rbp;
size_t rip;
};
/**
* Contains the definitions required to define and manage a single physical processing core.
* These include; active GDT and IDT, TSS segments, saved stacks for execution and syscalls.
* There are some utility functions for saving and loading extended registers, as well as
* for identifying individual Cores in a running system.
*
*/
class Core {
public:
2022-07-09 18:52:31 +00:00
Core(){}
2022-02-17 02:03:05 +00:00
Core(size_t LAPIC, size_t ID);
2022-07-09 18:52:31 +00:00
size_t ID = 0;
size_t LocalAPIC = 0;
2022-02-17 02:03:05 +00:00
2022-07-09 18:52:31 +00:00
address_space_t* AddressSpace = nullptr;
2022-02-17 02:03:05 +00:00
2022-07-09 18:52:31 +00:00
uint8_t* SyscallStack = 0;
size_t StackAddress = 0;
uint8_t StackData[Constants::Core::STACK_SIZE] = { 0 };
2022-02-17 02:03:05 +00:00
2022-07-10 20:57:48 +00:00
IDT CoreIDT = { 0, 0 };
GDT CoreGDT = { 0, 0 };
TSS64 CoreTSS = { };
2022-02-17 02:03:05 +00:00
void LoadExtraRegisters(uint8_t* Data);
void SaveExtraRegisters(uint8_t* Data);
void StackTrace(size_t Cycles);
static Core* GetCurrent() {
size_t CoreID = 0;
__asm__ __volatile__("mov %0, %%fs\n" : "=r"(CoreID) : :);
2022-07-09 18:52:31 +00:00
return Processors[CoreID];
2022-02-17 02:03:05 +00:00
}
2022-07-09 18:52:31 +00:00
static Core* GetCore(int ID) { return Processors[ID]; }
2022-02-17 02:03:05 +00:00
2022-07-10 20:57:48 +00:00
static void PreInit();
2022-02-17 02:03:05 +00:00
static void Init();
private:
2022-07-09 18:52:31 +00:00
static Core* Processors[];
2022-02-17 02:03:05 +00:00
void Bootstrap();
2022-07-08 23:20:00 +00:00
};