Ejemplo n.º 1
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();
            DebugClient.Setup(Serial.COM1);

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

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

            //At this point we can use objects, that allocates memory
            Runtime.Setup();
            TaskManager.Setup();
            SmbiosManager.Setup();
            ConsoleManager.Setup();
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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, "Coprocessor 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, "Coprocessor 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:

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

                //PageFaultHandler.Fault(errorCode);
                Panic.SetStackPointer(stack->EBP, stack->EIP);
                Panic.Error(cr2);
                break;

            case 16:
                Error(stack->EBP, stack->EIP, "Coprocessor 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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Interrupts the handler.
        /// </summary>
        /// <param name="edi">The edi.</param>
        /// <param name="esi">The esi.</param>
        /// <param name="ebp">The ebp.</param>
        /// <param name="esp">The esp.</param>
        /// <param name="ebx">The ebx.</param>
        /// <param name="edx">The edx.</param>
        /// <param name="ecx">The ecx.</param>
        /// <param name="eax">The eax.</param>
        /// <param name="interrupt">The interrupt.</param>
        /// <param name="errorCode">The error code.</param>
        private static void ProcessInterrupt(uint edi, uint esi, uint ebp, uint esp, uint ebx, uint edx, uint ecx, uint eax, uint interrupt, uint errorCode, uint eip, uint cs, uint eflags)
        {
            DebugClient.Process();

            switch (interrupt)
            {
            case 0:
                Error(ebp, eip, "Divide Error");
                break;

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

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

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

            case 7:
                Error(ebp, eip, "Coprocessor Not Available");
                break;

            case 8:
                //TODO: Analyze the double fault
                Error(ebp, eip, "Double Fault");
                break;

            case 9:
                Error(ebp, eip, "Coprocessor Segment Overrun");
                break;

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

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

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

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

            case 14:
                // Page Fault!
                var cr2 = Native.GetCR2() >> 5;
                if (cr2 < 0x1000)
                {
                    Error(ebp, eip, "Null Pointer Exception");
                    break;
                }

                PageFaultHandler.Fault(errorCode);
                break;

            case 16:
                Error(ebp, eip, "Coprocessor Error");
                break;

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

            default:
                if (interruptHandler != null)
                {
                    interruptHandler(interrupt, errorCode);
                }
                break;
            }

            PIC.SendEndOfInterrupt(interrupt);
        }