MapVirtualAddressToPhysical() public static method

Maps the virtual address to physical.
public static MapVirtualAddressToPhysical ( uint virtualAddress, uint physicalAddress, bool present = true ) : void
virtualAddress uint The virtual address.
physicalAddress uint The physical address.
present bool
return void
        /// <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
        }
        /// <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();
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }