diff --git a/xtoskrnl/ar/amd64/procsup.c b/xtoskrnl/ar/amd64/procsup.c index 9e8fb20..5c165ec 100644 --- a/xtoskrnl/ar/amd64/procsup.c +++ b/xtoskrnl/ar/amd64/procsup.c @@ -73,6 +73,40 @@ ArInitializeProcessor(VOID) ArpIdentifyProcessor(); } +/** + * Updates an existing AMD64 GDT entry with new base address. + * + * @param Gdt + * Supplies a pointer to the GDT. + * + * @param Selector + * Specifies a segment selector of the GDT entry. + * + * @param Base + * Specifies a base address value of the descriptor. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +ArSetGdtEntryBase(IN PKGDTENTRY Gdt, + IN USHORT Selector, + IN ULONG_PTR Base) +{ + PKGDTENTRY GdtEntry; + + /* Get GDT entry */ + GdtEntry = (PKGDTENTRY)((ULONG_PTR)Gdt + (Selector & ~RPL_MASK)); + + /* Set new GDT descriptor base */ + GdtEntry->BaseLow = (Base & 0xFFFF); + GdtEntry->Bytes.BaseMiddle = ((Base >> 16) & 0xFF); + GdtEntry->Bytes.BaseHigh = ((Base >> 24) & 0xFF); + GdtEntry->BaseUpper = (Base >> 32); +} + /** * Identifies processor type (vendor, model, stepping) as well as looks for available CPU features and stores them * in Processor Control Block (PRCB). @@ -450,14 +484,14 @@ ArpSetGdtEntry(IN PKGDTENTRY Gdt, GdtEntry = (PKGDTENTRY)((ULONG_PTR)Gdt + (Selector & ~RPL_MASK)); /* Set GDT descriptor base */ - GdtEntry->BaseLow = Base & 0xFFFF; - GdtEntry->Bytes.BaseMiddle = (Base >> 16) & 0xFF; - GdtEntry->Bytes.BaseHigh = (Base >> 24) & 0xFF; - GdtEntry->BaseUpper = Base >> 32; + GdtEntry->BaseLow = (Base & 0xFFFF); + GdtEntry->Bytes.BaseMiddle = ((Base >> 16) & 0xFF); + GdtEntry->Bytes.BaseHigh = ((Base >> 24) & 0xFF); + GdtEntry->BaseUpper = (Base >> 32); /* Set descriptor limit */ - GdtEntry->LimitLow = Limit & 0xFFFF; - GdtEntry->Bits.LimitHigh = (Limit >> 16) & 0xF; + GdtEntry->LimitLow = (Limit & 0xFFFF); + GdtEntry->Bits.LimitHigh = ((Limit >> 16) & 0xF); /* Initialize GDT entry */ GdtEntry->Bits.DefaultBig = !!(SegmentMode & 2); diff --git a/xtoskrnl/ar/i686/procsup.c b/xtoskrnl/ar/i686/procsup.c index 5bd037e..77d258e 100644 --- a/xtoskrnl/ar/i686/procsup.c +++ b/xtoskrnl/ar/i686/procsup.c @@ -71,6 +71,39 @@ ArInitializeProcessor(VOID) ArpIdentifyProcessor(); } +/** + * Updates an existing i686 GDT entry with new base address. + * + * @param Gdt + * Supplies a pointer to the GDT. + * + * @param Selector + * Specifies a segment selector of the GDT entry. + * + * @param Base + * Specifies a base address value of the descriptor. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +ArSetGdtEntryBase(IN PKGDTENTRY Gdt, + IN USHORT Selector, + IN ULONG_PTR Base) +{ + PKGDTENTRY GdtEntry; + + /* Get GDT entry */ + GdtEntry = (PKGDTENTRY)((ULONG_PTR)Gdt + (Selector & ~RPL_MASK)); + + /* Set new GDT descriptor base */ + GdtEntry->BaseLow = (Base & 0xFFFF); + GdtEntry->Bytes.BaseMiddle = ((Base >> 16) & 0xFF); + GdtEntry->Bytes.BaseHigh = ((Base >> 24) & 0xFF); +} + /** * Identifies processor type (vendor, model, stepping) as well as looks for available CPU features and stores them * in Processor Control Block (PRCB). @@ -416,7 +449,7 @@ ArpSetDoubleFaultTssEntry(IN PKPROCESSOR_BLOCK ProcessorBlock) } /** - * Fills in an AMD64 GDT entry. + * Fills in an i686 GDT entry. * * @param Gdt * Supplies a pointer to the GDT. diff --git a/xtoskrnl/includes/amd64/arpfuncs.h b/xtoskrnl/includes/amd64/arpfuncs.h index 4ef72f4..3f4978a 100644 --- a/xtoskrnl/includes/amd64/arpfuncs.h +++ b/xtoskrnl/includes/amd64/arpfuncs.h @@ -12,6 +12,12 @@ #include +XTAPI +VOID +ArSetGdtEntryBase(IN PKGDTENTRY Gdt, + IN USHORT Selector, + IN ULONG_PTR Base); + XTCDECL VOID ArpHandleSystemCall32(); diff --git a/xtoskrnl/includes/i686/arpfuncs.h b/xtoskrnl/includes/i686/arpfuncs.h index 9b96a2b..c37eb1a 100644 --- a/xtoskrnl/includes/i686/arpfuncs.h +++ b/xtoskrnl/includes/i686/arpfuncs.h @@ -12,6 +12,12 @@ #include +XTAPI +VOID +ArSetGdtEntryBase(IN PKGDTENTRY Gdt, + IN USHORT Selector, + IN ULONG_PTR Base); + XTCDECL VOID ArpHandleTrap00();