Refactor CPU preparation into cpu.c, work on enabling AVX and SSE

This commit is contained in:
Curle 2020-09-25 16:48:20 +01:00
parent d342772ed3
commit 81313cef42
Signed by: TheCurle
GPG Key ID: 5942F13718443F79
4 changed files with 52 additions and 5 deletions

View File

@ -51,6 +51,9 @@ size_t MemorySize;
void DrawPixel(uint32_t x, uint32_t y, uint32_t color);
void FillScreen(uint32_t color);
void SetupExtensions();
void PrepareCPU();
void WriteString(const char* string);
void WriteChar(const char character);

View File

@ -34,15 +34,13 @@ int Main(void) {
WriteStringWithFont("Initty Testing");
SetupInitialGDT();
SetupIDT();
InitInterrupts();
PrepareCPU();
PCIEnumerate();
InitMemoryManager();
DrawSplash();
//DrawSplash();
InitPaging();

View File

@ -60,6 +60,52 @@ static void RefreshCS() {
}
void PrepareCPU() {
SetupInitialGDT();
SetupIDT();
SetupExtensions();
InitInterrupts();
}
void SetupExtensions() {
// Enable SSE
size_t CR0 = ReadControlRegister(0);
CR0 &= ~(1 << 2);
CR0 |= 1;
WriteControlRegister(0, CR0);
// Enable OSXSAVE and gang
size_t CR4 = ReadControlRegister(4);
CR4 |= (1 << 9);
CR4 |= (1 << 10);
CR4 |= (1 << 18);
WriteControlRegister(4, CR4);
// Enable AVX (and AVX-512 in future)
CR0 = ReadExtendedControlRegister(0);
SerialPrintf("XCR0 is currently %x.\n", CR0);
CR0 |= (1 << 0);
CR0 |= (1 << 1);
CR0 |= (1 << 2);
/*CR0 |= (1 << 5);
CR0 |= (1 << 6);
CR0 |= (1 << 7);*/
SerialPrintf("About to write xcr0: %x\n", CR0);
WriteExtendedControlRegister(0, CR0);
}
void SetupInitialGDT() {
DESC_TBL GDTData = {0};
size_t TSSBase = (uint64_t) (&TSSEntries);

View File

@ -189,7 +189,7 @@ size_t ReadExtendedControlRegister(size_t XCRX) {
//TODO: make this just have an assert as returning data for a write to catch
// errors that shoudlunt really happen doesent make alot of sense
size_t WriteExtendedControlRegister(size_t XCRX, size_t Data){
uint32_t DataLow = Data & 0xffffffff;
uint32_t DataLow = Data & 0x00000000ffffffff;
uint32_t DataHigh = (Data & 0xffffffff00000000) >> 32;
__asm__ __volatile__("xsetbv" : : "a" (DataLow), "c" (XCRX), "d" (DataHigh) :);
return Data;