From 9552b13879a5d78aa580a47713dd345a90eeb95a Mon Sep 17 00:00:00 2001 From: Elia Sulimanov Date: Wed, 19 Aug 2020 20:09:05 +0300 Subject: [PATCH] Started working on INTs API --- source/Cosmos.Core/INTs.cs | 120 +++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/source/Cosmos.Core/INTs.cs b/source/Cosmos.Core/INTs.cs index 71cce306c..cb0fb7bc5 100644 --- a/source/Cosmos.Core/INTs.cs +++ b/source/Cosmos.Core/INTs.cs @@ -3,43 +3,112 @@ using System.Runtime.InteropServices; using IL2CPU.API.Attribs; namespace Cosmos.Core { + /// + /// INTs (INTerruptS) class. + /// public class INTs { #region Enums // TODO: Protect IRQs like memory and ports are // TODO: Make IRQs so they are not hookable, and instead release high priority threads like FreeBSD (When we get threading) + /// + /// EFlags Enum. + /// public enum EFlagsEnum : uint { + /// + /// Set by arithmetic instructions, can be carry or borrow. + /// Carry = 1, + /// + /// Set by most CPU instructions if the LSB of the destination operand contain an even number of 1's. + /// Parity = 1 << 2, + /// + /// Set when an arithmetic carry or borrow has been generated out of the four LSBs. + /// AuxilliaryCarry = 1 << 4, + /// + /// Set to 1 if an arithmetic result is zero, and reset otherwise. + /// Zero = 1 << 6, + /// + /// Set to 1 if the last arithmetic result was positive, and reset otherwise. + /// Sign = 1 << 7, + /// + /// When set to 1, permits single step operations. + /// Trap = 1 << 8, + /// + /// When set to 1, maskable hardware interrupts will be handled, and ignored otherwise. + /// InterruptEnable = 1 << 9, + /// + /// When set to 1, strings is processed from highest address to lowest, and from lowest to highest otherwise. + /// Direction = 1 << 10, + /// + /// Set to 1 if arithmetic overflow has occurred in the last operation. + /// Overflow = 1 << 11, + /// + /// Set to 1 when one system task invoke another by CALL instruction. + /// NestedTag = 1 << 14, + /// + /// When set to 1, enables the option turn off certain exceptions while debugging. + /// Resume = 1 << 16, + /// + /// When set to 1, Virtual8086Mode is enabled. + /// Virtual8086Mode = 1 << 17, + /// + /// When set to 1, enables alignment check. + /// AlignmentCheck = 1 << 18, + /// + /// When set, the program will receive hardware interrupts. + /// VirtualInterrupt = 1 << 19, + /// + /// When set, indicate that there is deferred interrupt pending. + /// VirtualInterruptPending = 1 << 20, + /// + /// When set, indicate that CPUID instruction is available. + /// ID = 1 << 21 } + /// + /// TSS (Task State Segment) struct. + /// [StructLayout(LayoutKind.Explicit, Size = 0x68)] public struct TSS { + /// + /// Reserved. + /// [FieldOffset(0)] public ushort Link; [FieldOffset(4)] public uint ESP0; + /// + /// Reserved. + /// [FieldOffset(8)] public ushort SS0; [FieldOffset(12)] public uint ESP1; + /// + /// Reserved. + /// [FieldOffset(16)] public ushort SS1; [FieldOffset(20)] public uint ESP2; + /// + /// Reserved. + /// [FieldOffset(24)] public ushort SS2; [FieldOffset(28)] @@ -64,20 +133,44 @@ namespace Cosmos.Core { public uint ESI; [FieldOffset(68)] public uint EDI; + /// + /// Reserved. + /// [FieldOffset(72)] public ushort ES; + /// + /// Reserved. + /// [FieldOffset(76)] public ushort CS; + /// + /// Reserved. + /// [FieldOffset(80)] public ushort SS; + /// + /// Reserved. + /// [FieldOffset(84)] public ushort DS; + /// + /// Reserved. + /// [FieldOffset(88)] public ushort FS; + /// + /// Reserved. + /// [FieldOffset(92)] public ushort GS; + /// + /// Reserved. + /// [FieldOffset(96)] public ushort LDTR; + /// + /// Reserved. + /// [FieldOffset(102)] public ushort IOPBOffset; } @@ -158,6 +251,10 @@ namespace Cosmos.Core { } } + /// + /// Handle default interrupt. + /// + /// A IEQ context. public static void HandleInterrupt_Default(ref IRQContext aContext) { if (aContext.Interrupt >= 0x20 && aContext.Interrupt <= 0x2F) { if (aContext.Interrupt >= 0x28) { @@ -406,6 +503,16 @@ namespace Cosmos.Core { #endregion + /// + /// Handle exception. + /// + /// Unused. + /// Unused. + /// Unused. + /// IRQ context. + /// Last known address value. (default = 0) + /// Thrown on fatal error, contact support. + /// Thrown on fatal error, contact support. private static void HandleException(uint aEIP, string aDescription, string aName, ref IRQContext ctx, uint lastKnownAddressValue = 0) { // At this point we are in a very unstable state. // Try not to use any Cosmos routines, just @@ -467,6 +574,12 @@ namespace Cosmos.Core { } } + /// + /// Put error char. + /// + /// Line to put the error char at. + /// Column to put the error char at. + /// Char to put. private static void PutErrorChar(int line, int col, char c) { unsafe { @@ -479,6 +592,13 @@ namespace Cosmos.Core { } } + /// + /// Put error string. + /// + /// Line to put the error string at. + /// Starting column to put the error string at. + /// Error string to put. + /// Thrown if error length in greater then Int32.MaxValue. private static void PutErrorString(int line, int startCol, string error) { for (int i = 0; i < error.Length; i++) { PutErrorChar(line, startCol + i, error[i]);