A physical page allocator.
Esempio n. 1
0
        public static void Setup()
        {
            // Initialize GDT before IDT, because IDT Entries requires a valid Segment Selector
            Multiboot.Setup();
            GDT.Setup();

            // At this stage, allocating memory does not work, so you are only allowed to use ValueTypes or static classes.
            IDT.SetInterruptHandler(null);
            Panic.Setup();

            // Initialize interrupts
            PIC.Setup();
            IDT.Setup();

            // Initializing the memory management
            PageFrameAllocator.Setup();
            PageTable.Setup();
            VirtualPageAllocator.Setup();
            GC.Setup();

            // At this point we can use objects
            Scheduler.Setup();
            SmbiosManager.Setup();
            ConsoleManager.Setup();

            Logger.Log("Kernel initialized");
        }
Esempio n. 2
0
        public static void Setup()
        {
            // Initialize GDT before IDT, because IDT Entries requies a valid Segment Selector
            // This never happend before, because on fast computers GDT.Setup() was called
            // before a Interrupt,for example clock, got triggered.
            Multiboot.Setup();
            GDT.Setup();

            // At this stage, allocating memory does not work, so you are only allowed to use ValueTypes or static classes.
            IDT.SetInterruptHandler(null);
            Panic.Setup();
            Debugger.Setup(Serial.COM1);

            // Initialize interrupts
            PIC.Setup();
            IDT.Setup();

            // Initializing the memory management
            PageFrameAllocator.Setup();
            PageTable.Setup();
            VirtualPageAllocator.Setup();
            GC.Setup();

            // At this point we can use objects
            Scheduler.Setup();
            SmbiosManager.Setup();
            ConsoleManager.Setup();
            Internal.Setup();
        }
Esempio n. 3
0
        public static void Setup()
        {
            // At this stage, allocating memory does not work, so you are only allowed to use ValueTypes or static classes.
            IDT.SetInterruptHandler(null);
            Panic.Setup();
            Debugger.Setup(Serial.COM1);

            // Initialize interrupts
            PIC.Setup();
            IDT.Setup();

            // Initializing the memory management
            Multiboot.Setup();
            GDT.Setup();
            PageFrameAllocator.Setup();
            PageTable.Setup();
            VirtualPageAllocator.Setup();
            GC.Setup();

            // At this point we can use objects
            Scheduler.Setup();
            SmbiosManager.Setup();
            ConsoleManager.Setup();
            Internal.Setup();
        }
Esempio n. 4
0
        /// <summary>
        /// Handle Page Faults
        /// </summary>
        /// <param name="errorCode">The error code.</param>
        public static void Fault(uint errorCode)
        {
            uint virtualpage = Native.GetCR2();

            if (virtualpage == 0x0)
            {
                Panic.Now(2);                   // Can't map null! what happened?
            }

            // TODO: acquire lock

            uint physicalpage = PageFrameAllocator.Allocate();

            if (physicalpage == 0x0)
            {
                Panic.Now(1);                   // Panic! Out of memory
            }
            PageTable.MapVirtualAddressToPhysical(virtualpage, physicalpage);

            // TODO: release lock
        }
Esempio n. 5
0
        /// <summary>
        /// Handle Page Faults
        /// </summary>
        /// <param name="errorCode">The error code.</param>
        public static void Fault(uint errorCode)
        {
            uint virtualpage = Native.GetCR2();

            if (virtualpage == 0x0)
            {
                Panic.Now(2);                   // Can't map null! what happened?
            }

            //bool taken = false;
            //spinLock.Enter(ref taken);

            uint physicalpage = PageFrameAllocator.Allocate();

            if (physicalpage == 0x0)
            {
                Panic.Now(1);                   // Panic! Out of memory
            }
            PageTable.MapVirtualAddressToPhysical(virtualpage, physicalpage);

            //spinLock.Exit();
        }
Esempio n. 6
0
 public static void Setup()
 {
     SmbiosManager.Setup();
     Screen.Clear();
     Screen.Color = 0x0E;
     Screen.Goto(24, 0);
     Screen.Write('1');
     Multiboot.Setup();
     Screen.Goto(24, 1);
     Screen.Write('2');
     PIC.Setup();
     Screen.Goto(24, 2);
     Screen.Write('3');
     GDT.Setup();
     Screen.Goto(24, 3);
     Screen.Write('4');
     IDT.Setup();
     Screen.Goto(24, 4);
     Screen.Write('5');
     PageFrameAllocator.Setup();
     Screen.Goto(24, 5);
     Screen.Write('6');
     PageTable.Setup();
     Screen.Goto(24, 6);
     Screen.Write('7');
     VirtualPageAllocator.Setup();
     Screen.Goto(24, 7);
     Screen.Write('8');
     Screen.Goto(24, 8);
     ProcessManager.Setup();
     Screen.Write('9');
     Screen.Goto(24, 9);
     TaskManager.Setup();
     Screen.Write('A');
     Screen.Goto(24, 10);
     SmbiosManager.Setup();
 }
Esempio n. 7
0
        /// <summary>
        /// Interrupts the handler.
        /// </summary>
        /// <param name="stackStatePointer">The stack state pointer.</param>
        private unsafe static void ProcessInterrupt(uint stackStatePointer)
        {
            var stack = (IDTStack *)stackStatePointer;

            Debugger.Process(stack);

            switch (stack->Interrupt)
            {
            case 0:
                Error(stack, "Divide Error");
                break;

            case 4:
                Error(stack, "Arithmetic Overflow Exception");
                break;

            case 5:
                Error(stack, "Bound Check Error");
                break;

            case 6:
                Error(stack, "Invalid Opcode");
                break;

            case 7:
                Error(stack, "Co-processor Not Available");
                break;

            case 8:

                //TODO: Analyze the double fault
                Error(stack, "Double Fault");
                break;

            case 9:
                Error(stack, "Co-processor Segment Overrun");
                break;

            case 10:
                Error(stack, "Invalid TSS");
                break;

            case 11:
                Error(stack, "Segment Not Present");
                break;

            case 12:
                Error(stack, "Stack Exception");
                break;

            case 13:
                Error(stack, "General Protection Exception");
                break;

            case 14:

                // Check if Null Pointer Exception
                // Otherwise handle as Page Fault

                var cr2 = Native.GetCR2();

                if ((cr2 >> 5) < 0x1000)
                {
                    Error(stack, "Null Pointer Exception");
                }

                if (cr2 >= 0xF0000000u)
                {
                    Error(stack, "Invalid Access Above 0xF0000000");
                    break;
                }

                var physicalpage = PageFrameAllocator.Allocate();

                if (physicalpage == IntPtr.Zero)
                {
                    Error(stack, "Out of Memory");
                    break;
                }

                PageTable.MapVirtualAddressToPhysical(cr2, (uint)physicalpage.ToInt32());

                break;

            case 16:
                Error(stack, "Co-processor Error");
                break;

            case 19:
                Error(stack, "SIMD Floating-Point Exception");
                break;

            case Scheduler.ClockIRQ:
                Interrupt?.Invoke(stack->Interrupt, stack->ErrorCode);
                Scheduler.ClockInterrupt(new IntPtr(stackStatePointer));
                break;

            case Scheduler.ThreadTerminationSignalIRQ:
                Scheduler.TerminateCurrentThread();
                break;

            default:
            {
                Interrupt?.Invoke(stack->Interrupt, stack->ErrorCode);
                break;
            }
            }

            PIC.SendEndOfInterrupt(stack->Interrupt);
        }
Esempio n. 8
0
        /// <summary>
        /// Interrupts the handler.
        /// </summary>
        /// <param name="stack">The stack.</param>
        private unsafe static void ProcessInterrupt(IDTStack *stack)
        {
            DebugClient.Process();

            switch (stack->Interrupt)
            {
            case 0:
                Error(stack->EBP, stack->EIP, "Divide Error");
                break;

            case 4:
                Error(stack->EBP, stack->EIP, "Arithmetic Overflow Exception");
                break;

            case 5:
                Error(stack->EBP, stack->EIP, "Bound Check Error");
                break;

            case 6:
                Error(stack->EBP, stack->EIP, "Invalid Opcode");
                break;

            case 7:
                Error(stack->EBP, stack->EIP, "Co-processor Not Available");
                break;

            case 8:

                //TODO: Analyze the double fault
                Error(stack->EBP, stack->EIP, "Double Fault");
                break;

            case 9:
                Error(stack->EBP, stack->EIP, "Co-processor Segment Overrun");
                break;

            case 10:
                Error(stack->EBP, stack->EIP, "Invalid TSS");
                break;

            case 11:
                Error(stack->EBP, stack->EIP, "Segment Not Present");
                break;

            case 12:
                Error(stack->EBP, stack->EIP, "Stack Exception");
                break;

            case 13:
                Error(stack->EBP, stack->EIP, "General Protection Exception");
                break;

            case 14:

                // Check if Null Pointer Exception
                // Otherwise handle as Page Fault

                var cr2 = Native.GetCR2() >> 5;
                if (cr2 < 0x1000)
                {
                    Error(stack->EBP, stack->EIP, "Null Pointer Exception");
                }

                //spinLock.Enter(ref taken);

                uint physicalpage = PageFrameAllocator.Allocate();

                if (physicalpage == 0x0)
                {
                    // Panic! Out of memory
                    Panic.SetStackPointer(stack->EBP, stack->EIP);
                    Panic.Error(cr2);
                }

                PageTable.MapVirtualAddressToPhysical(Native.GetCR2(), physicalpage);

                //spinLock.Exit();

                break;

            case 16:
                Error(stack->EBP, stack->EIP, "Co-processor Error");
                break;

            case 19:
                Error(stack->EBP, stack->EIP, "SIMD Floating-Point Exception");
                break;

            default:
                if (interruptHandler != null)
                {
                    interruptHandler(stack->Interrupt, stack->ErrorCode);
                }
                break;
            }

            PIC.SendEndOfInterrupt(stack->Interrupt);
        }
Esempio n. 9
0
        /// <summary>
        /// Interrupts the handler.
        /// </summary>
        /// <param name="stack">The stack.</param>
        private unsafe static void ProcessInterrupt(IDTStack *stack)
        {
            Debugger.Process(stack);

            switch (stack->Interrupt)
            {
            case 0:
                Error(stack, "Divide Error");
                break;

            case 4:
                Error(stack, "Arithmetic Overflow Exception");
                break;

            case 5:
                Error(stack, "Bound Check Error");
                break;

            case 6:
                Error(stack, "Invalid Opcode");
                break;

            case 7:
                Error(stack, "Co-processor Not Available");
                break;

            case 8:

                //TODO: Analyze the double fault
                Error(stack, "Double Fault");
                break;

            case 9:
                Error(stack, "Co-processor Segment Overrun");
                break;

            case 10:
                Error(stack, "Invalid TSS");
                break;

            case 11:
                Error(stack, "Segment Not Present");
                break;

            case 12:
                Error(stack, "Stack Exception");
                break;

            case 13:
                Error(stack, "General Protection Exception");
                break;

            case 14:

                // Check if Null Pointer Exception
                // Otherwise handle as Page Fault

                var cr2 = Native.GetCR2();

                if ((cr2 >> 5) < 0x1000)
                {
                    Error(stack, "Null Pointer Exception");
                }

                uint physicalpage = PageFrameAllocator.Allocate();

                if (physicalpage == 0x0)
                {
                    Error(stack, "Out of Memory");
                }

                PageTable.MapVirtualAddressToPhysical(cr2, physicalpage);

                break;

            case 16:
                Error(stack, "Co-processor Error");
                break;

            case 19:
                Error(stack, "SIMD Floating-Point Exception");
                break;

            default:
                interruptHandler?.Invoke(stack->Interrupt, stack->ErrorCode);
                break;
            }

            PIC.SendEndOfInterrupt(stack->Interrupt);
        }