test: ia32init.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# ia32init.c

Go to the documentation of this file.

    00001 /*++
    00002
    00003
    00004 Module Name:
    00005
    00006     ia32init.c
    00007
    00008 Abstract:
    00009
    00010     This module contains code to support iA32 resources structures
    00011
    00012 Author:
    00013
    00014
    00015 Revision History:
    00016
    00017 --*/
    00018
    00019 #include    "ki.h"
    00020
    00021 #if defined(WX86)
    00022
    00023 VOID
    00024 KiInitializeGdtEntry (
    00025     OUT PKGDTENTRY GdtEntry,
    00026     IN ULONG Base,
    00027     IN ULONG Limit,
    00028     IN USHORT Type,
    00029     IN USHORT Dpl,
    00030     IN USHORT Granularity
    00031     )
    00032
    00033 /*++
    00034
    00035 Routine Description:
    00036
    00037     This function initializes a GDT entry.  Base, Limit, Type (code,
    00038     data), and Dpl (0 or 3) are set according to parameters.  All other
    00039     fields of the entry are set to match standard system values.
    00040
    00041 Arguments:
    00042
    00043     GdtEntry - GDT descriptor to be filled in.
    00044
    00045     Base - Linear address of the first byte mapped by the selector.
    00046
    00047     Limit - Size of the selector in pages.  Note that 0 is 1 page
    00048             while 0xffffff is 1 megapage = 4 gigabytes.
    00049
    00050     Type - Code or Data.  All code selectors are marked readable,
    00051             all data selectors are marked writeable.
    00052
    00053     Dpl - User (3) or System (0)
    00054
    00055     Granularity - 0 for byte, 1 for page
    00056
    00057 Return Value:
    00058
    00059     Pointer to the GDT entry.
    00060
    00061 --*/
    00062
    00063 {
    00064     GdtEntry->LimitLow = (USHORT)(Limit & 0xffff);
    00065     GdtEntry->BaseLow = (USHORT)(Base & 0xffff);
    00066     GdtEntry->HighWord.Bytes.BaseMid = (UCHAR)((Base & 0xff0000) >> 16);
    00067     GdtEntry->HighWord.Bits.Type = Type;
    00068     GdtEntry->HighWord.Bits.Dpl = Dpl;
    00069     GdtEntry->HighWord.Bits.Pres = 1;
    00070     GdtEntry->HighWord.Bits.LimitHi = (Limit & 0xf0000) >> 16;
    00071     GdtEntry->HighWord.Bits.Sys = 0;
    00072     GdtEntry->HighWord.Bits.Reserved_0 = 0;
    00073     GdtEntry->HighWord.Bits.Default_Big = 1;
    00074     GdtEntry->HighWord.Bits.Granularity = Granularity;
    00075     GdtEntry->HighWord.Bytes.BaseHi = (UCHAR)((Base & 0xff000000) >> 24);
    00076 }
    00077
    00078
    00079 VOID
    00080 KiInitializeXDescriptor (
    00081     OUT PKXDESCRIPTOR Descriptor,
    00082     IN ULONG Base,
    00083     IN ULONG Limit,
    00084     IN USHORT Type,
    00085     IN USHORT Dpl,
    00086     IN USHORT Granularity
    00087     )
    00088
    00089 /*++
    00090
    00091 Routine Description:
    00092
    00093     This function initializes a unscrambled Descriptor.
    00094     Base, Limit, Type (code, data), and Dpl (0 or 3) are set according
    00095     to parameters.  All other fields of the entry are set to match
    00096     standard system values.
    00097     The Descriptor will be initialized to 0 first, and then setup as requested
    00098
    00099 Arguments:
    00100
    00101     Descriptor - descriptor to be filled in.
    00102
    00103     Base - Linear address of the first byte mapped by the selector.
    00104
    00105     Limit - Size of the selector in pages.  Note that 0 is 1 page
    00106             while 0xffffff is 1 megapage = 4 gigabytes.
    00107
    00108     Type - Code or Data.  All code selectors are marked readable,
    00109             all data selectors are marked writeable.
    00110
    00111     Dpl - User (3) or System (0)
    00112
    00113     Granularity - 0 for byte, 1 for page
    00114
    00115 Return Value:
    00116
    00117     Pointer to the Descriptor
    00118
    00119 --*/
    00120
    00121 {
    00122     Descriptor->Words.DescriptorWords = 0;
    00123
    00124     Descriptor->Words.Bits.Base = Base;
    00125     Descriptor->Words.Bits.Limit = Limit;
    00126     Descriptor->Words.Bits.Type = Type;
    00127     Descriptor->Words.Bits.Dpl = Dpl;
    00128     Descriptor->Words.Bits.Pres = 1;
    00129     Descriptor->Words.Bits.Default_Big = 1;
    00130     Descriptor->Words.Bits.Granularity = Granularity;
    00131 }
    00132
    00133 VOID
    00134 KeiA32ResourceCreate (
    00135     IN PEPROCESS Process,
    00136     IN PTEB Teb
    00137     )
    00138 /*++
    00139
    00140 Routine Description:
    00141
    00142     To initial Gdt Table for the target user thread
    00143     Only called from KiInitializeContextThread()
    00144
    00145 Arguments:
    00146
    00147     Thread - Pointer to KTHREAD object
    00148
    00149 Return value:
    00150
    00151     None
    00152
    00153 --*/
    00154 {
    00155     ULONG i;
    00156     PUCHAR Gdt;
    00157
    00158
    00159     ASSERT (sizeof(KTRAP_FRAME) == sizeof(KIA32_FRAME));
    00160
    00161     //
    00162     // Initialize each required Gdt entry
    00163     //
    00164
    00165     Gdt = (PUCHAR) Teb->Gdt;
    00166
    00167     RtlZeroMemory(Gdt, GDT_TABLE_SIZE);
    00168
    00169     KiInitializeGdtEntry((PKGDTENTRY)(Gdt + KGDT_R3_CODE), 0,
    00170         (ULONG)-1, TYPE_CODE_USER, DPL_USER, GRAN_PAGE);
    00171
    00172     KiInitializeGdtEntry((PKGDTENTRY)(Gdt + KGDT_R3_DATA), 0,
    00173         (ULONG)-1, TYPE_DATA_USER, DPL_USER, GRAN_PAGE);
    00174
    00175     //
    00176     // Set user TEB descriptor
    00177     //
    00178
    00179     KiInitializeGdtEntry((PKGDTENTRY)(Gdt + KGDT_R3_TEB), Teb,
    00180         sizeof(TEB)-1, TYPE_DATA_USER, DPL_USER, GRAN_BYTE);
    00181
    00182     //
    00183     // The FS descriptor for ISA transitions. This needs to be in
    00184     // unscrambled format
    00185     //
    00186
    00187     KiInitializeXDescriptor((PKXDESCRIPTOR)&(Teb->FsDescriptor), Teb,
    00188         sizeof(TEB)-1, TYPE_DATA_USER, DPL_USER, GRAN_BYTE);
    00189
    00190     // Set BIOS descriptor
    00191
    00192     //
    00193     // Set LDT descriptor, just copy whatever the Proecss has
    00194     //
    00195     *(PKGDTENTRY)(Gdt+KGDT_LDT) = (Process->Pcb).LdtDescriptor;
    00196
    00197     // Set Video display buffer descriptor
    00198
    00199     //
    00200     // Setup ISA transition GdtDescriptor - needs to be unscrambled
    00201     // But according tot he seamless EAS, only the base and limit
    00202     // are actually used...
    00203     //
    00204
    00205     KiInitializeXDescriptor((PKXDESCRIPTOR)&(Teb->GdtDescriptor), (ULONG)Gdt,
    00206         GDT_TABLE_SIZE-1, TYPE_DATA_USER, DPL_USER, GRAN_BYTE);
    00207     //
    00208     // Setup ISA transition LdtDescriptor - needs to be unscrambled
    00209     //
    00210
    00211     Teb->LdtDescriptor = (ULONGLONG)((Process->Pcb).UnscrambledLdtDescriptor);
    00212 }
    00213
    00214 #endif  // defined(WX86)