Beispiel #1
0
        /// <summary>
        /// Sets up the GDT table and entries
        /// </summary>
        public static void Setup(Addr addr)
        {
            KernelMessage.Write("Setup GDT...");

            GdtTableAddress = addr;

            GdtTable = (DescriptorTable *)GdtTableAddress;
            GdtTable->Clear();
            GdtTable->AdressOfEntries = GdtTableAddress + DescriptorTable.StructSize;

            //Null segment
            var nullEntry = DescriptorTableEntry.CreateNullDescriptor();

            GdtTable->AddEntry(nullEntry);

            //code segment
            var codeEntry = DescriptorTableEntry.CreateCode(0, 0xFFFFFFFF);

            codeEntry.CodeSegment_Readable = true;
            codeEntry.PriviligeRing        = 0;
            codeEntry.Present     = true;
            codeEntry.AddressMode = DescriptorTableEntry.EAddressMode.Bits32;
            //codeEntry.CodeSegment_Confirming = true;
            GdtTable->AddEntry(codeEntry);

            //data segment
            var dataEntry = DescriptorTableEntry.CreateData(0, 0xFFFFFFFF);

            dataEntry.DataSegment_Writable = true;
            dataEntry.PriviligeRing        = 0;
            dataEntry.Present     = true;
            dataEntry.AddressMode = DescriptorTableEntry.EAddressMode.Bits32;
            GdtTable->AddEntry(dataEntry);

            Flush();

            KernelMessage.WriteLine("Done");
        }
Beispiel #2
0
        /// <summary>
        /// Sets up the GDT table and entries
        /// </summary>
        public static void Setup(Addr addr)
        {
            KernelMessage.Write("Setup GDT...");

            GdtTableAddress = addr;

            GdtTable = (DescriptorTable *)GdtTableAddress;
            GdtTable->Clear();
            GdtTable->AdressOfEntries = GdtTableAddress + DescriptorTable.StructSize;

            // 0 - Null segment
            var entry = DescriptorTableEntry.CreateNullDescriptor();

            GdtTable->AddEntry(entry);

            // 1 - code segment
            entry = DescriptorTableEntry.CreateCode(0, 0xFFFFFFFF);
            entry.CodeSegment_Readable = true;
            entry.PriviligeRing        = 0;
            entry.Present     = true;
            entry.AddressMode = DescriptorTableEntry.EAddressMode.Bits32;
            //codeEntry.CodeSegment_Confirming = true;
            GdtTable->AddEntry(entry);

            // 2 - data segment
            entry = DescriptorTableEntry.CreateData(0, 0xFFFFFFFF);
            entry.DataSegment_Writable = true;
            entry.PriviligeRing        = 0;
            entry.Present     = true;
            entry.AddressMode = DescriptorTableEntry.EAddressMode.Bits32;
            GdtTable->AddEntry(entry);

            // 3 - reserved
            entry = DescriptorTableEntry.CreateData(0, 0xFFFFFFFF);
            entry.DataSegment_Writable = true;
            entry.PriviligeRing        = 0;
            entry.Present     = true;
            entry.AddressMode = DescriptorTableEntry.EAddressMode.Bits32;
            GdtTable->AddEntry(entry);

            //  4 - kernel thread storage
            entry = DescriptorTableEntry.CreateData(0, 0xFFFFFFFF);
            entry.DataSegment_Writable = true;
            entry.PriviligeRing        = 0;
            entry.Present     = true;
            entry.AddressMode = DescriptorTableEntry.EAddressMode.Bits32;
            GdtTable->AddEntry(entry);

            // 5 - reserved
            entry = DescriptorTableEntry.CreateData(0, 0xFFFFFFFF);
            entry.DataSegment_Writable = true;
            entry.PriviligeRing        = 0;
            entry.Present     = true;
            entry.AddressMode = DescriptorTableEntry.EAddressMode.Bits32;
            GdtTable->AddEntry(entry);

            // ---

            // 6 - user code segment
            entry = DescriptorTableEntry.CreateCode(0, 0xFFFFFFFF);
            entry.CodeSegment_Readable = true;
            entry.PriviligeRing        = 3;
            entry.Present                = true;
            entry.AddressMode            = DescriptorTableEntry.EAddressMode.Bits32;
            entry.CodeSegment_Confirming = false;
            GdtTable->AddEntry(entry);

            // 7 - user data segment
            entry = DescriptorTableEntry.CreateData(0, 0xFFFFFFFF);
            entry.DataSegment_Writable = true;
            entry.PriviligeRing        = 3;
            entry.Present     = true;
            entry.AddressMode = DescriptorTableEntry.EAddressMode.Bits32;
            GdtTable->AddEntry(entry);

            // 8 - thread storage segment for FS register
            entry = DescriptorTableEntry.CreateData(0, 0xFFFFFFFF);
            entry.DataSegment_Writable = true;
            entry.PriviligeRing        = 3;
            entry.Present     = true;
            entry.AddressMode = DescriptorTableEntry.EAddressMode.Bits32;
            GdtTable->AddEntry(entry);

            Flush();

            KernelMessage.WriteLine("Done");
        }
Beispiel #3
0
        public static void SetupUserMode(Addr tssAddr)
        {
            KernelMessage.WriteLine("Setup GDT UserMode");

            if (KConfig.UseTaskStateSegment)
            {
                TssAddr  = tssAddr;
                TssTable = (TaskStateSegmentTable *)tssAddr;
                TssTable->Clear();
                TssTable->AdressOfEntries = TssAddr + TaskStateSegmentTable.StructSize;
            }

            //code segment
            var codeEntry = DescriptorTableEntry.CreateCode(0, 0xFFFFFFFF);

            codeEntry.CodeSegment_Readable = true;
            codeEntry.PriviligeRing        = 3;
            codeEntry.Present                = true;
            codeEntry.AddressMode            = DescriptorTableEntry.EAddressMode.Bits32;
            codeEntry.CodeSegment_Confirming = false;
            GdtTable->AddEntry(codeEntry);

            //data segment
            var dataEntry = DescriptorTableEntry.CreateData(0, 0xFFFFFFFF);

            dataEntry.DataSegment_Writable = true;
            dataEntry.PriviligeRing        = 3;
            dataEntry.Present     = true;
            dataEntry.AddressMode = DescriptorTableEntry.EAddressMode.Bits32;
            GdtTable->AddEntry(dataEntry);

            if (KConfig.UseTaskStateSegment)
            {
                //TSS
                Tss = AddTSS();
                //tss->esp0 = kernelStackPointer;
                Tss->SS0          = 0x10;
                Tss->Trace_bitmap = 0xdfff;

                KernelMessage.WriteLine("Addr of tss: {0:X8}", (uint)Tss);

                var tssEntry = DescriptorTableEntry.CreateTSS(Tss);
                tssEntry.PriviligeRing = 0;
                tssEntry.TSS_AVL       = true;
                tssEntry.Present       = true;
                GdtTable->AddEntry(tssEntry);
            }

            Flush();

            if (KConfig.UseTaskStateSegment)
            {
                KernelMessage.WriteLine("LoadTaskRegister...");
                //LoadTaskRegister();

                //Debug, for breakpoint
                //clockTicks++;

                //DebugFunction1();
            }

            KernelMessage.WriteLine("Done");
        }