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