Refactor CPU preparation into cpu.c, work on enabling AVX and SSE
This commit is contained in:
parent
0ff9705fc8
commit
b86d8af721
|
@ -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);
|
||||
|
||||
|
|
|
@ -34,15 +34,13 @@ int Main(void) {
|
|||
|
||||
WriteStringWithFont("Initty Testing");
|
||||
|
||||
SetupInitialGDT();
|
||||
SetupIDT();
|
||||
InitInterrupts();
|
||||
PrepareCPU();
|
||||
|
||||
PCIEnumerate();
|
||||
|
||||
InitMemoryManager();
|
||||
|
||||
DrawSplash();
|
||||
//DrawSplash();
|
||||
|
||||
InitPaging();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user