From 89d948e09391955b7c4f64b9f4e217fa3a3fe057 Mon Sep 17 00:00:00 2001 From: Elia Sulimanov Date: Thu, 20 Aug 2020 15:30:17 +0300 Subject: [PATCH] Done INTs API --- source/Cosmos.Core/INTs.cs | 205 ++++++++++++++++++++++++++++++++++--- 1 file changed, 193 insertions(+), 12 deletions(-) diff --git a/source/Cosmos.Core/INTs.cs b/source/Cosmos.Core/INTs.cs index cb0fb7bc5..38d26cd87 100644 --- a/source/Cosmos.Core/INTs.cs +++ b/source/Cosmos.Core/INTs.cs @@ -228,22 +228,44 @@ namespace Cosmos.Core { } #endregion + /// + /// Last known address. + /// [AsmMarker(AsmMarker.Type.Int_LastKnownAddress)] private static uint mLastKnownAddress; + /// + /// IRQ handlers. + /// private static IRQDelegate[] mIRQ_Handlers = new IRQDelegate[256]; // We used to use: //Interrupts.IRQ01 += HandleKeyboardInterrupt; // But at one point we had issues with multi cast delegates, so we changed to this single cast option. // [1:48:37 PM] Matthijs ter Woord: the issues were: "they didn't work, would crash kernel". not sure if we still have them.. + /// + /// Set interrupt handler. + /// + /// Interrupt index. + /// IRQ handler. public static void SetIntHandler(byte aIntNo, IRQDelegate aHandler) { mIRQ_Handlers[aIntNo] = aHandler; } + + /// + /// Set IRQ handler. + /// + /// IRQ index. + /// IRQ handler. public static void SetIrqHandler(byte aIrqNo, IRQDelegate aHandler) { SetIntHandler((byte)(0x20 + aIrqNo), aHandler); } + /// + /// Set IRQ context to IRQ handler. + /// + /// IRQ handler index. + /// IRQ context. private static void IRQ(uint irq, ref IRQContext aContext) { var xCallback = mIRQ_Handlers[irq]; if (xCallback != null) { @@ -265,24 +287,40 @@ namespace Cosmos.Core { } } + /// + /// IRQ delegate. + /// + /// IRQ context. public delegate void IRQDelegate(ref IRQContext aContext); + /// + /// Exception interrupt delegate. + /// + /// IRQ context. + /// True if handled. public delegate void ExceptionInterruptDelegate(ref IRQContext aContext, ref bool aHandled); #region Default Interrupt Handlers - //IRQ 0 - System timer. Reserved for the system. Cannot be changed by a user. + /// + /// IRQ 0 - System timer. Reserved for the system. Cannot be changed by a user. + /// + /// IRQ context. public static void HandleInterrupt_20(ref IRQContext aContext) { IRQ(0x20, ref aContext); Global.PIC.EoiMaster(); } //public static IRQDelegate IRQ01; - //IRQ 1 - Keyboard. Reserved for the system. Cannot be altered even if no keyboard is present or needed. + /// + /// IRQ 1 - Keyboard. Reserved for the system. Cannot be altered even if no keyboard is present or needed. + /// + /// IRQ context. public static void HandleInterrupt_21(ref IRQContext aContext) { IRQ(0x21, ref aContext); Global.PIC.EoiMaster(); } + public static void HandleInterrupt_22(ref IRQContext aContext) { IRQ(0x22, ref aContext); @@ -318,25 +356,29 @@ namespace Cosmos.Core { IRQ(0x28, ref aContext); Global.PIC.EoiSlave(); } - //IRQ 09 - (Added for AMD PCNet network card) - //public static IRQDelegate IRQ09; + /// + /// IRQ 09 - (Added for AMD PCNet network card). + /// + /// IRQ context. public static void HandleInterrupt_29(ref IRQContext aContext) { IRQ(0x29, ref aContext); Global.PIC.EoiSlave(); } - //IRQ 10 - (Added for VIA Rhine network card) - //public static IRQDelegate IRQ10; - + /// + /// IRQ 10 - (Added for VIA Rhine network card). + /// + /// IRQ context. public static void HandleInterrupt_2A(ref IRQContext aContext) { IRQ(0x2A, ref aContext); Global.PIC.EoiSlave(); } - //IRQ 11 - (Added for RTL8139 network card) - //public static IRQDelegate IRQ11; - + /// + /// IRQ 11 - (Added for RTL8139 network card). + /// + /// IRQ context. public static void HandleInterrupt_2B(ref IRQContext aContext) { IRQ(0x2B, ref aContext); Global.PIC.EoiSlave(); @@ -353,12 +395,20 @@ namespace Cosmos.Core { IRQ(0x2D, ref aContext); Global.PIC.EoiSlave(); } - //IRQ 14 - Primary IDE. If no Primary IDE this can be changed + + /// + /// IRQ 14 - Primary IDE. If no Primary IDE this can be changed. + /// + /// IRQ context. public static void HandleInterrupt_2E(ref IRQContext aContext) { IRQ(0x2E, ref aContext); Global.PIC.EoiSlave(); } - //IRQ 15 - Secondary IDE + + /// + /// IRQ 15 - Secondary IDE. + /// + /// IRQ context. public static void HandleInterrupt_2F(ref IRQContext aContext) { IRQ(0x2F, ref aContext); Global.PIC.EoiSlave(); @@ -414,61 +464,149 @@ namespace Cosmos.Core { #region CPU Exceptions + /// + /// General protection fault IRQ delegate. + /// public static IRQDelegate GeneralProtectionFault; + /// + /// Divide By Zero Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_00(ref IRQContext aContext) { HandleException(aContext.EIP, "Divide by zero", "EDivideByZero", ref aContext, aContext.EIP); } + /// + /// Debug Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_01(ref IRQContext aContext) { HandleException(aContext.EIP, "Debug Exception", "Debug Exception", ref aContext); } + /// + /// Non Maskable Interrupt Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_02(ref IRQContext aContext) { HandleException(aContext.EIP, "Non Maskable Interrupt Exception", "Non Maskable Interrupt Exception", ref aContext); } + /// + /// Breakpoint Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_03(ref IRQContext aContext) { HandleException(aContext.EIP, "Breakpoint Exception", "Breakpoint Exception", ref aContext); } + /// + /// Into Detected Overflow Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_04(ref IRQContext aContext) { HandleException(aContext.EIP, "Into Detected Overflow Exception", "Into Detected Overflow Exception", ref aContext); } + /// + /// Out of Bounds Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_05(ref IRQContext aContext) { HandleException(aContext.EIP, "Out of Bounds Exception", "Out of Bounds Exception", ref aContext); } + /// + /// Invalid Opcode. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_06(ref IRQContext aContext) { // although mLastKnownAddress is a static, we need to get it here, any subsequent calls will change the value!!! var xLastKnownAddress = mLastKnownAddress; HandleException(aContext.EIP, "Invalid Opcode", "EInvalidOpcode", ref aContext, xLastKnownAddress); } + /// + /// No Coprocessor Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_07(ref IRQContext aContext) { HandleException(aContext.EIP, "No Coprocessor Exception", "No Coprocessor Exception", ref aContext); } + /// + /// Double Fault Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_08(ref IRQContext aContext) { HandleException(aContext.EIP, "Double Fault Exception", "Double Fault Exception", ref aContext); } + /// + /// Coprocessor Segment Overrun Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_09(ref IRQContext aContext) { HandleException(aContext.EIP, "Coprocessor Segment Overrun Exception", "Coprocessor Segment Overrun Exception", ref aContext); } + /// + /// Bad TSS Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_0A(ref IRQContext aContext) { HandleException(aContext.EIP, "Bad TSS Exception", "Bad TSS Exception", ref aContext); } + /// + /// Segment Not Present. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_0B(ref IRQContext aContext) { HandleException(aContext.EIP, "Segment Not Present", "Segment Not Present", ref aContext); } + /// + /// Stack Fault Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_0C(ref IRQContext aContext) { HandleException(aContext.EIP, "Stack Fault Exception", "Stack Fault Exception", ref aContext); } + + /// + /// General Protection Fault. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_0D(ref IRQContext aContext) { if (GeneralProtectionFault != null) { GeneralProtectionFault(ref aContext); @@ -477,25 +615,62 @@ namespace Cosmos.Core { } } + /// + /// Page Fault Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_0E(ref IRQContext aContext) { HandleException(aContext.EIP, "Page Fault Exception", "Page Fault Exception", ref aContext); } + /// + /// Unknown Interrupt Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_0F(ref IRQContext aContext) { HandleException(aContext.EIP, "Unknown Interrupt Exception", "Unknown Interrupt Exception", ref aContext); } + /// + /// x87 Floating Point Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_10(ref IRQContext aContext) { HandleException(aContext.EIP, "x87 Floating Point Exception", "Coprocessor Fault Exception", ref aContext); } + /// + /// Alignment Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_11(ref IRQContext aContext) { HandleException(aContext.EIP, "Alignment Exception", "Alignment Exception", ref aContext); } + /// + /// Machine Check Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_12(ref IRQContext aContext) { HandleException(aContext.EIP, "Machine Check Exception", "Machine Check Exception", ref aContext); } + + /// + /// SIMD Floating Point Exception. + /// + /// IRQ context. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void HandleInterrupt_13(ref IRQContext aContext) { HandleException(aContext.EIP, "SIMD Floating Point Exception", "SIMD Floating Point Exception", ref aContext); } @@ -608,6 +783,12 @@ namespace Cosmos.Core { // This is to trick IL2CPU to compile it in //TODO: Make a new attribute that IL2CPU sees when scanning to force inclusion so we dont have to do this. // We dont actually need to call this method + /// + /// Dummy function, used by the bootstrap. + /// + /// This is to trick IL2CPU to compile it in. + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. public static void Dummy() { // Compiler magic bool xTest = false;