Example #1
0
 private static unsafe void Error(IDTStack* stack, string message)
 {
     Panic.ESP = stack->ESP;
     Panic.EBP = stack->EBP;
     Panic.EIP = stack->EIP;
     Panic.EAX = stack->EAX;
     Panic.EBX = stack->EBX;
     Panic.ECX = stack->ECX;
     Panic.EDX = stack->EDX;
     Panic.EDI = stack->EDI;
     Panic.ESI = stack->ESI;
     Panic.CS = stack->CS;
     Panic.ErrorCode = stack->ErrorCode;
     Panic.EFLAGS = stack->EFLAGS;
     Panic.Interrupt = stack->Interrupt;
     Panic.Error(message);
 }
Example #2
0
        /// <summary>
        /// Interrupts the handler.
        /// </summary>
        /// <param name="stack">The stack.</param>
        private static unsafe 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);
        }
Example #3
0
        /// <summary>
        /// Interrupts the handler.
        /// </summary>
        /// <param name="stack">The stack.</param>
        private static unsafe 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:

                    // 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");

                    //bool taken = false;
                    //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, "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);
        }
Example #4
0
        /// <summary>
        /// Interrupts the handler.
        /// </summary>
        /// <param name="stack">The stack.</param>
        private static unsafe 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);
        }
Example #5
0
        internal static unsafe void Process(IDTStack* stack)
        {
            idt_stack = stack;

            Process();
        }