コード例 #1
0
        /// <summary>
        /// Interrupt 14
        /// </summary>
        public static void PageFault(IDTStack *stack)
        {
            // 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");
                return;
            }

            Error(stack, "Not mapped");

            // var physicalpage = PageFrameManager.AllocatePage(PageFrameRequestFlags.Default);

            // if (physicalpage == null)
            // {
            //     Error(stack, "Out of Memory");
            //     return;
            // }

            // PageTable.MapVirtualAddressToPhysical(cr2, (uint)physicalpage);
        }
コード例 #2
0
        public static void Undefined(IDTStack *stack)
        {
            var handler = IDTManager.Handlers[stack->Interrupt];

            if (handler.NotifyUnhandled)
            {
                handler.NotifyUnhandled = false;
                KernelMessage.WriteLine("Unhandled Interrupt {0}", stack->Interrupt);
            }
        }
コード例 #3
0
        /// <summary>
        /// Interrupt 32
        /// </summary>
        public static void ClockTimer(IDTStack *stack)
        {
            //Screen.Goto(15, 5);
            //Screen.Write(IDTManager.RaisedCount);

            // to clock events...

            // at least, call scheduler. Keep in mind, it may not return because of thread switching
            Scheduler.ClockInterrupt(new IntPtr(stack));
        }
コード例 #4
0
ファイル: IDT.cs プロジェクト: tralivali1234/MOSA-Project
 private unsafe static 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);
 }
コード例 #5
0
        public static void Service(IDTStack *stack)
        {
            var handler = IDTManager.Handlers[stack->Interrupt];

            if (handler.Service == null)
            {
                KernelMessage.WriteLine("handler.Service == null");
                return;
            }

            var ctx = new SysCallContext
            {
                CallingType = CallingType.Async, // Important! Otherwise stack will corrupted
            };

            var msg = new SystemMessage(SysCallTarget.Interrupt)
            {
                Arg1 = stack->Interrupt,
            };

            Scheduler.SaveThreadState(Scheduler.GetCurrentThread().ThreadID, (IntPtr)stack);
            handler.Service.SwitchToThreadMethod(&ctx, &msg);
        }
コード例 #6
0
        private static void InterruptHandler(IDTStack *stack, CallingType callingMethod)
        {
            var args = new SystemMessage
            {
                Target = (SysCallTarget)stack->EAX,
                Arg1   = stack->EBX,
                Arg2   = stack->ECX,
                Arg3   = stack->EDX,
                Arg4   = stack->ESI,
                Arg5   = stack->EDI,
                Arg6   = stack->EBP,
            };

            var commandNum = GetCommandNum(args.Target);

            if (KConfig.Log.SysCall)
            {
                KernelMessage.WriteLine("Got SysCall cmd={0} arg1={1} arg2={2} arg3={3} arg4={4} arg5={5} arg6={6}", (uint)args.Target, args.Arg1, args.Arg2, args.Arg3, args.Arg4, args.Arg5, args.Arg6);
            }

            Scheduler.SaveThreadState(Scheduler.GetCurrentThread().ThreadID, (IntPtr)stack);

            var info = Commands[commandNum];

            if (info == null)
            {
                Panic.Error("Undefined SysCall");
            }

            var ctx = new SysCallContext
            {
                CallingType = callingMethod,
            };

            stack->EAX = info.Handler(&ctx, &args);
        }
コード例 #7
0
 /// <summary>
 /// Interrupt 4
 /// </summary>
 public static void ArithmeticOverflowException(IDTStack *stack)
 {
     Error(stack, "Arithmetic Overflow Exception");
 }
コード例 #8
0
 /// <summary>
 /// Interrupt 0
 /// </summary>
 public static void DivideError(IDTStack *stack)
 {
     Error(stack, "Divide Error");
 }
コード例 #9
0
 /// <summary>
 /// Interrupt 7
 /// </summary>
 public static void CoProcessorNotAvailable(IDTStack *stack)
 {
     Error(stack, "Co-processor Not Available");
 }
コード例 #10
0
 /// <summary>
 /// Interrupt 10
 /// </summary>
 public static void InvalidTSS(IDTStack *stack)
 {
     Error(stack, "Invalid TSS");
 }
コード例 #11
0
 /// <summary>
 /// Interrupt 19
 /// </summary>
 public static void SIMDFloatinPointException(IDTStack *stack)
 {
     Error(stack, "SIMD Floating-Point Exception");
 }
コード例 #12
0
ファイル: Debugger.cs プロジェクト: charsleysa/MOSA-Project
        internal static unsafe void Process(IDTStack* stack)
        {
            idt_stack = stack;

            Process();
        }
コード例 #13
0
 /// <summary>
 /// Interrupt 8
 /// </summary>
 public static void DoubleFault(IDTStack *stack)
 {
     //TODO: Analyze Double Fault
     Error(stack, "Double Fault");
 }
コード例 #14
0
 /// <summary>
 /// Interrupt 16
 /// </summary>
 public static void CoProcessorError(IDTStack *stack)
 {
     Error(stack, "Co-Processor Error");
 }
コード例 #15
0
 /// <summary>
 /// Interrupt 13
 /// </summary>
 public static void GeneralProtectionException(IDTStack *stack)
 {
     Error(stack, "General Protection Exception");
 }
コード例 #16
0
 /// <summary>
 /// Interrupt 12
 /// </summary>
 public static void StackException(IDTStack *stack)
 {
     Error(stack, "Stack Exception");
 }
コード例 #17
0
 /// <summary>
 /// Interrupt 11
 /// </summary>
 public static void SegmentNotPresent(IDTStack *stack)
 {
     Error(stack, "Segment Not Present");
 }
コード例 #18
0
 /// <summary>
 /// Interrupt 5
 /// </summary>
 public static void BoundCheckError(IDTStack *stack)
 {
     Error(stack, "Bound Check Error");
 }
コード例 #19
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);
        }
コード例 #20
0
 /// <summary>
 /// Interrupt 6
 /// </summary>
 public static void InvalidOpcode(IDTStack *stack)
 {
     Error(stack, "Invalid Opcode");
 }
コード例 #21
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);
        }
コード例 #22
0
 private static void ActionInterruptHandler(IDTStack *stack)
 {
     InterruptHandler(stack, CallingType.Async);
 }
コード例 #23
0
 /// <summary>
 /// Interrupt 32
 /// </summary>
 public static void ClockTimer(IDTStack *stack)
 {
     //Screen.Goto(15, 5);
     //Screen.Write(IDTManager.RaisedCount);
 }
コード例 #24
0
        public static void Keyboard(IDTStack *stack)
        {
            //Screen.Goto(15, 5);
            //Screen.Write(IDTManager.RaisedCount);
            var code = (uint)Native.In8(0x60);

            //KernelMessage.WriteLine("Got Keyboard scancode: {0:X2}", code);

            // for debugging
            switch (code)
            {
            case 0x02:
                Key1();
                break;

            case 0x03:
                Key2();
                break;

            case 0x04:
                Key3();
                break;

            case 0x05:
                Key4();
                break;

            case 0x06:
                Key5();
                break;

            case 0x07:
                Key6();
                break;

            case 0x3B:
                KeyF1();
                break;

            case 0x3C:
                KeyF2();
                break;

            case 0x3D:
                KeyF3();
                break;

            case 0x3E:
                KeyF4();
                break;

            case 0x3F:
                KeyF5();
                break;

            case 0x40:
                KeyF6();
                break;

            case 0x41:
                KeyF7();
                break;

            case 0x42:
                KeyF8();
                break;

            case 0x43:
                KeyF9();
                break;

            case 0x44:
                KeyF10();
                break;

            case 0x57:
                KeyF11();
                break;

            case 0x58:
                KeyF12();
                break;
            }
        }
コード例 #25
0
 /// <summary>
 /// Interrupt 9
 /// </summary>
 public static void CoProcessorSegmentOverrun(IDTStack *stack)
 {
     Error(stack, "Co-processor Segment Overrun");
 }
コード例 #26
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);
        }
コード例 #27
0
 public static void TermindateCurrentThread(IDTStack *stack)
 {
     Scheduler.TerminateCurrentThread();
 }
コード例 #28
0
        internal unsafe static void Process(IDTStack *stack)
        {
            idt_stack = stack;

            Process();
        }
コード例 #29
0
 private static void UndefinedHandler(IDTStack *stack)
 {
     NativeCalls.BochsDebug();
 }