Chroma/inc/kernel/system/core.hpp

81 lines
1.9 KiB
C++
Raw 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
IDT CoreIDT;
GDT CoreGDT;
TSS64 CoreTSS;
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
static void Init();
private:
2022-07-09 18:52:31 +00:00
static Core* Processors[];
2022-02-17 02:03:05 +00:00
// Initialization vectors for all new cores.
// Numbers derived from boot.h space.
// Specifically, the bootloader ROM.
enum Initialization {
PAGETABLES = 0x600,
STARTUP = 0x620,
STACK = 0x670,
GDT = 0x680,
IDT = 0x690
};
void Bootstrap();
void SetupData(size_t ID);
2022-07-08 23:20:00 +00:00
};