diff --git a/include/kernel.h b/include/kernel.h index d160298..9392824 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -59,7 +59,7 @@ typedef struct MemoryMap_t MemoryMap_t; typedef struct MapEntry_t MapEntry_t; typedef struct GdtEntry_t GdtEntry_t; typedef struct GdtPtr_t GdtPtr_t; -typedef struct TssEntry_t TssEntry_t; +typedef struct Tss_t Tss_t; typedef struct TssDescriptor_t TssDescriptor_t; //----------------------------------------------------------------------------// diff --git a/include/mm/mm.h b/include/mm/mm.h index c50e3c0..f724260 100644 --- a/include/mm/mm.h +++ b/include/mm/mm.h @@ -32,6 +32,7 @@ //----------------------------------------------------------------------------// #define MINIMUM_RAM_SIZE 16 // Mio, the minimum RAM size. +#define IOMAP_SIZE (8 * 1024) #define AVAILABLE_ZONE 1 // Fully usable RAM zone #define RESERVED_ZONE 2 // Used by the firmware @@ -57,39 +58,55 @@ struct MemoryMap_t { MapEntry_t entry[MAX_ENTRIES]; } __attribute__((__packed__)); -// The gdt +// The gdt entry struct GdtEntry_t { ushort lowLimit; // lower 16 bits ushort lowBase; // lower 16 bits uchar middleBase; // next 8 bits uchar access; // determine what ring this segment can be used in - uchar granularity; + uchar flags; uchar highBase; // last 8 bits } __attribute__((__packed__)); struct TssDescriptor_t { - ushort limitLow; - ushort base00; - uchar base16; - uchar access; - uchar size; - uchar base24; - uint base32; - uint reserved; + ushort lowLimit; + ushort lowBase; + uchar middleBase; + uchar access; + unsigned middleLimit: 4; + unsigned flags: 4; + uchar highBase; + uint veryHighBase; + uint reserved; } __attribute__ ((packed)); -struct TssEntry_t +struct Tss_t { - uint reserved0; + uint reserved1; - ulong privStackPointer[3]; // stack pointers for CPL 0-2 - ulong intStackTable[8]; // /!\ [0] is reserved + // Stack pointers (RSP) for privilege levels 0-2 + ulong rsp0; + ulong rsp1; + ulong rsp2; + ulong reserved2; + + // Interrupt stack table pointers + ulong ist1; + ulong ist2; + ulong ist3; + ulong ist4; + ulong ist5; + ulong ist6; + ulong ist7; + ulong reserved3; + ushort reserved4; + + // Offset to the I/O permission bit map from the 64-bit TSS base + ushort iomap_base; + uchar iomap[IOMAP_SIZE]; - ulong reserved1; - ushort reserved2; - ushort ioMapOffset; } __attribute__ ((packed)); @@ -98,7 +115,7 @@ struct TssEntry_t struct GdtPtr_t { uchar limit; // upper 16 bits - ushort base; // address of the first entry + ulong base; // address of the first entry } __attribute__((__packed__)); //----------------------------------------------------------------------------// diff --git a/kaleid/kernel/mm/gdt.c b/kaleid/kernel/mm/gdt.c index e736c5a..ef56e74 100644 --- a/kaleid/kernel/mm/gdt.c +++ b/kaleid/kernel/mm/gdt.c @@ -24,56 +24,57 @@ #include -GdtEntry_t gdtEntries[5] = { 0 }; -TssEntry_t tssEntry = { 0 }; +ulong gdtEntries[2] = +{ + (0L), // NULL descriptor + ((1L<<43) | (1L<<44) | (1L<<47) | (1L<<53)) // KERNEL CS 0x8 +}; + + +//Tss_t tssEntry = { 0 }; GdtPtr_t gdtPtr; -static void SetGdtEntry(int index, uint base, uint limit, uchar access) -{ - gdtEntries[index].lowBase = (base & 0xFFFF); - gdtEntries[index].middleBase = (base >> 16) & 0xFF; - gdtEntries[index].highBase = (base >> 24) & 0xFF; +/* static void SetGdtEntry(int index, uint base, uint limit, uchar access) */ +/* { */ +/* gdtEntries[index].lowBase = (base & 0xFFFF); */ +/* gdtEntries[index].middleBase = (base >> 16) & 0xFF; */ +/* gdtEntries[index].highBase = (base >> 24) & 0xFF; */ - gdtEntries[index].lowLimit = (limit & 0xFFFF); - gdtEntries[index].granularity = (limit >> 16) & 0x0F; +/* gdtEntries[index].lowLimit = (limit & 0xFFFF); */ +/* gdtEntries[index].granularity = (limit >> 16) & 0x0F; */ - gdtEntries[index].granularity |= 0xA0; +/* gdtEntries[index].granularity |= 0xA0; */ - // 0x10 is system - // 0x80 is present - gdtEntries[index].access = access | 0x10 | 0x80; -} +/* // 0x10 is system */ +/* // 0x80 is present */ +/* gdtEntries[index].access = access | 0x10 | 0x80; */ +/* } */ -static void SetTssEntry(uchar index, ulong base, ulong limit) -{ - TssDescriptor_t tssDesc = { 0 }; +/* static void SetTssEntry(uchar index, ulong base, ulong limit) */ +/* { */ +/* TssDescriptor_t tssDesc = { 0 }; */ - tssDesc.limitLow = limit & 0xffff; - tssDesc.size = (limit >> 16) & 0xf; +/* tssDesc.limitLow = limit & 0xffff; */ +/* tssDesc.size = (limit >> 16) & 0xf; */ - tssDesc.base00 = base & 0xffff; - tssDesc.base16 = (base >> 16) & 0xff; - tssDesc.base24 = (base >> 24) & 0xff; - tssDesc.base32 = (base >> 32) & 0xffffffff; - tssDesc.reserved = 0; +/* tssDesc.base00 = base & 0xffff; */ +/* tssDesc.base16 = (base >> 16) & 0xff; */ +/* tssDesc.base24 = (base >> 24) & 0xff; */ +/* tssDesc.base32 = (base >> 32) & 0xffffffff; */ +/* tssDesc.reserved = 0; */ - tssDesc.access = 0x01 | 0x08 | 0x10 | 0x80; +/* tssDesc.access = 0x01 | 0x08 | 0x10 | 0x80; */ - memmove(&gdtEntries[index], &tssDesc, sizeof(TssDescriptor_t)); -} +/* memmove(&gdtEntries[index], &tssDesc, sizeof(TssDescriptor_t)); */ +/* } */ void MmInitGdt(void) { - //MmStoreGdt(); + gdtPtr.limit = sizeof(gdtEntries) - 1; + gdtPtr.base = (ulong)&gdtEntries; - /* SetGdtEntry(1, 0x0, 0xfffff, 0x02 | 0x08); */ - - /* tssEntry.ioMapOffset = sizeof(TssEntry_t); */ - - /* SetTssEntry(2, (ulong)&tssEntry, sizeof(TssEntry_t)); */ - - //MmLoadGdt(); + MmLoadGdt(); } diff --git a/kaleid/kernel/po/shtdwn.c b/kaleid/kernel/po/shtdwn.c index 5bcc4cd..6cf2f39 100644 --- a/kaleid/kernel/po/shtdwn.c +++ b/kaleid/kernel/po/shtdwn.c @@ -33,7 +33,7 @@ noreturn void PoShutdownQemu(void) IoWriteWordOnPort(0x604, 0x2000); - KeCrashSystem(); + KeStartPanic("Shutdown failed lol ;)"); __builtin_unreachable(); } @@ -45,7 +45,7 @@ noreturn void PoShutdownVirtualbox(void) IoWriteWordOnPort(0x4004, 0x3400); - KeCrashSystem(); + KeStartPanic("Shutdown failed lol ;)"); __builtin_unreachable(); } @@ -57,7 +57,7 @@ noreturn void PoShutdownBochs(void) IoWriteWordOnPort(0xB004, 0x2000); - KeCrashSystem(); + KeStartPanic("Shutdown failed lol ;)"); __builtin_unreachable(); }