Exemple #1
0
        /// <summary>
        /// Interrupt 14
        /// </summary>
        internal static void PageFault(ref IDTStack stack)
        {
            // Check if Null Pointer Exception
            // Otherwise handle as Page Fault

            var cr2 = Native.GetCR2();

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

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

            Error(ref stack, "Not mapped");

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

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

            // PageTable.MapVirtualAddressToPhysical(cr2, (uint)physicalpage);
        }
Exemple #2
0
        internal static void Undefined(ref IDTStack stack)
        {
            var handler = IDTManager.Handlers[stack.Interrupt];

            if (handler.NotifyUnhandled)
            {
                handler.NotifyUnhandled = false;
                KernelMessage.WriteLine("Unhandled Interrupt {0}", stack.Interrupt);
            }
        }
Exemple #3
0
        /// <summary>
        /// Interrupt 32
        /// </summary>
        internal static void ClockTimer(ref 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(ref stack);
        }
Exemple #4
0
 private static void Error(ref 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.CR2       = Native.GetCR2();
     Panic.FS        = Native.GetFS();
     Panic.Error(message);
 }
Exemple #5
0
        internal static void Service(ref IDTStack stack)
        {
            var handler = IDTManager.Handlers[stack.Interrupt];

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

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

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

            Scheduler.SaveThreadState(Scheduler.GetCurrentThread().ThreadID, ref stack);
            handler.Service.SwitchToThreadMethod(ref ctx, ref msg);
        }
Exemple #6
0
 internal static void TermindateCurrentThread(ref IDTStack stack)
 {
     Scheduler.TerminateCurrentThread();
 }
Exemple #7
0
        internal static void Keyboard(ref 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;
            }
        }
Exemple #8
0
 /// <summary>
 /// Interrupt 8
 /// </summary>
 internal static void DoubleFault(ref IDTStack stack)
 {
     //TODO: Analyze Double Fault
     Error(ref stack, "Double Fault");
 }
Exemple #9
0
 /// <summary>
 /// Interrupt 5
 /// </summary>
 internal static void BoundCheckError(ref IDTStack stack)
 {
     Error(ref stack, "Bound Check Error");
 }
Exemple #10
0
 /// <summary>
 /// Interrupt 12
 /// </summary>
 internal static void StackException(ref IDTStack stack)
 {
     Error(ref stack, "Stack Exception");
 }
Exemple #11
0
 /// <summary>
 /// Interrupt 13
 /// </summary>
 internal static void GeneralProtectionException(ref IDTStack stack)
 {
     Error(ref stack, "General Protection Exception");
 }
Exemple #12
0
 /// <summary>
 /// Interrupt 11
 /// </summary>
 internal static void SegmentNotPresent(ref IDTStack stack)
 {
     Error(ref stack, "Segment Not Present");
 }
Exemple #13
0
 /// <summary>
 /// Interrupt 10
 /// </summary>
 internal static void InvalidTSS(ref IDTStack stack)
 {
     Error(ref stack, "Invalid TSS");
 }
Exemple #14
0
 /// <summary>
 /// Interrupt 9
 /// </summary>
 internal static void CoProcessorSegmentOverrun(ref IDTStack stack)
 {
     Error(ref stack, "Co-processor Segment Overrun");
 }
Exemple #15
0
 /// <summary>
 /// Interrupt 0
 /// </summary>
 internal static void DivideError(ref IDTStack stack)
 {
     Error(ref stack, "Divide Error");
 }
Exemple #16
0
 /// <summary>
 /// Interrupt 16
 /// </summary>
 internal static void CoProcessorError(ref IDTStack stack)
 {
     Error(ref stack, "Co-Processor Error");
 }
Exemple #17
0
 /// <summary>
 /// Interrupt 4
 /// </summary>
 internal static void ArithmeticOverflowException(ref IDTStack stack)
 {
     Error(ref stack, "Arithmetic Overflow Exception");
 }
Exemple #18
0
 /// <summary>
 /// Interrupt 19
 /// </summary>
 internal static void SIMDFloatinPointException(ref IDTStack stack)
 {
     Error(ref stack, "SIMD Floating-Point Exception");
 }
Exemple #19
0
 /// <summary>
 /// Interrupt 6
 /// </summary>
 internal static void InvalidOpcode(ref IDTStack stack)
 {
     Error(ref stack, "Invalid Opcode");
 }
Exemple #20
0
 /// <summary>
 /// Interrupt 7
 /// </summary>
 internal static void CoProcessorNotAvailable(ref IDTStack stack)
 {
     Error(ref stack, "Co-processor Not Available");
 }