Beispiel #1
0
 public static void Throw_IndexOutOfRangeException()
 {
     HaltReason = "Index out of range exception.";
     FOS_System.Exception ex = new FOS_System.Exceptions.IndexOutOfRangeException(0, 0);
     ex.InstructionAddress = *((uint *)BasePointer + 1);
     Throw(ex);
 }
Beispiel #2
0
        public static unsafe void Throw(FOS_System.Exception ex)
        {
            Kernel.FOS_System.GC.IncrementRefCount(ex);

            //BasicConsole.WriteLine("Exception thrown:");
            //BasicConsole.WriteLine(ex.Message);

            if (State->CurrentHandlerPtr->Ex != null)
            {
                //GC ref count remains consistent because the Ex pointer below is going to be replaced but
                //  same pointer stored in InnerException.
                // Result is ref count goes: +1 here, -1 below
                ex.InnerException = (Kernel.FOS_System.Exception)Utilities.ObjectUtilities.GetObject(State->CurrentHandlerPtr->Ex);
            }
            if (ex.InstructionAddress == 0)
            {
                ex.InstructionAddress = *((uint *)BasePointer + 1);
            }
            State->CurrentHandlerPtr->Ex        = Utilities.ObjectUtilities.GetHandle(ex);
            State->CurrentHandlerPtr->ExPending = 1;

            HandleException();

            // We never expect to get here...
            HaltReason = "HandleException returned!";
            BasicConsole.WriteLine(HaltReason);
            // Try to cause fault
            *((byte *)0x800000000) = 0;
        }
Beispiel #3
0
        public static unsafe void WriteLine(FOS_System.String str)
        {
            if (!Initialised)
            {
                return;
            }
            if (str == null)
            {
                return;
            }

            if (PrimaryOutputEnabled)
            {
                //This block shifts the video memory up the required number of lines.
                if (offset == cols * rows)
                {
                    char *vidMemPtr_Old = vidMemBasePtr;
                    char *vidMemPtr_New = vidMemBasePtr + cols;
                    char *maxVidMemPtr  = vidMemBasePtr + (cols * rows);
                    while (vidMemPtr_New < maxVidMemPtr)
                    {
                        vidMemPtr_Old[0] = vidMemPtr_New[0];
                        vidMemPtr_Old++;
                        vidMemPtr_New++;
                    }
                    offset -= cols;
                }
            }

            //This outputs the string
            Write(str);

            if (PrimaryOutputEnabled)
            {
                //This block "writes" the new line by filling in the remainder (if any) of the
                //  line with blank characters and correct background colour.
                int diff = offset;
                while (diff > cols)
                {
                    diff -= cols;
                }
                diff = cols - diff;

                char *vidMemPtr = vidMemBasePtr + offset;
                while (diff > 0)
                {
                    vidMemPtr[0] = bg_colour;

                    diff--;
                    vidMemPtr++;
                    offset++;
                }
            }

            if (SecondaryOutput != null && SecondaryOutputEnabled)
            {
                SecondaryOutput("\r\n");
            }
        }
Beispiel #4
0
 /// <summary>
 /// Throws a divide by zero exception storing the specified exception address.
 /// </summary>
 /// <param name="address">The address of the code that caused the exception.</param>
 /// <remarks>
 /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
 /// </remarks>
 public static void Throw_DivideByZeroException(uint address)
 {
     HaltReason = "Divide by zero exception.";
     BasicConsole.SetTextColour(BasicConsole.error_colour);
     BasicConsole.WriteLine(HaltReason);
     BasicConsole.SetTextColour(BasicConsole.default_colour);
     Throw(new FOS_System.Exceptions.DivideByZeroException(address));
 }
Beispiel #5
0
 /// <summary>
 /// Throws an overflow exception.
 /// </summary>
 /// <remarks>
 /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
 /// </remarks>
 public static void Throw_OverflowException()
 {
     HaltReason = "Overflow exception.";
     BasicConsole.SetTextColour(BasicConsole.error_colour);
     BasicConsole.WriteLine(HaltReason);
     BasicConsole.SetTextColour(BasicConsole.default_colour);
     Throw(new FOS_System.Exceptions.OverflowException("Processor reported an overflow."));
 }
Beispiel #6
0
 /// <summary>
 /// Throws a stack exception.
 /// </summary>
 /// <remarks>
 /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
 /// </remarks>
 public static void Throw_StackException()
 {
     HaltReason = "Stack exception.";
     BasicConsole.SetTextColour(BasicConsole.error_colour);
     BasicConsole.WriteLine(HaltReason);
     BasicConsole.SetTextColour(BasicConsole.default_colour);
     Throw(new FOS_System.Exceptions.StackException());
 }
Beispiel #7
0
 /// <summary>
 /// Throws an invalid op code exception.
 /// </summary>
 /// <remarks>
 /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
 /// </remarks>
 public static void Throw_InvalidOpCodeException()
 {
     HaltReason = "Invalid op code exception.";
     BasicConsole.SetTextColour(BasicConsole.error_colour);
     BasicConsole.WriteLine(HaltReason);
     BasicConsole.SetTextColour(BasicConsole.default_colour);
     Throw(new FOS_System.Exceptions.InvalidOpCodeException());
 }
Beispiel #8
0
        public static unsafe void Write(FOS_System.String str)
        {
            if (!Initialised)
            {
                return;
            }
            //If string is null, just don't write anything
            if (str == null)
            {
                //Do not make this throw an exception. The BasicConsole
                //  is largely a debugging tool - it should be reliable,
                //  robust and not throw exceptions.
                return;
            }

            if (PrimaryOutputEnabled)
            {
                int strLength = str.length;
                int maxOffset = rows * cols;

                //This block shifts the video memory up the required number of lines.
                if (offset + strLength > maxOffset)
                {
                    int amountToShift = (offset + strLength) - maxOffset;
                    amountToShift = amountToShift + (80 - (amountToShift % 80));
                    offset       -= amountToShift;

                    char *vidMemPtr_Old = vidMemBasePtr;
                    char *vidMemPtr_New = vidMemBasePtr + amountToShift;
                    char *maxVidMemPtr  = vidMemBasePtr + (cols * rows);
                    while (vidMemPtr_New < maxVidMemPtr)
                    {
                        vidMemPtr_Old[0] = vidMemPtr_New[0];
                        vidMemPtr_Old++;
                        vidMemPtr_New++;
                    }
                }

                //This block outputs the string in the current foreground / background colours.
                char *vidMemPtr = vidMemBasePtr + offset;
                char *strPtr    = str.GetCharPointer();
                while (strLength > 0)
                {
                    vidMemPtr[0] = (char)((*strPtr & 0x00FF) | colour);

                    strLength--;
                    vidMemPtr++;
                    strPtr++;
                    offset++;
                }
            }

            if (SecondaryOutput != null && SecondaryOutputEnabled)
            {
                SecondaryOutput(str);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Returns Description of the command passed to it
        /// </summary>
        /// <param name="command">Name of the command to find the description of</param>
        /// <returns>Description of the command (FOS_System.String)</returns>
        public static FOS_System.String GetCommandDescription(FOS_System.String command)
        {
            for (int i = 0; i < CommandDescriptions.Count; i++)
            {
                CommandDescription cmdDesc = (CommandDescription)CommandHelp.CommandDescriptions[i];

                if (cmdDesc.CommandNameLower == command)
                {
                    return(cmdDesc.Description);
                }
            }
            return("[No command description found]");
        }
Beispiel #10
0
        /// <summary>
        /// Sets the current text (foreground) colour.
        /// </summary>
        /// <param name="col">The colour to set as the text colour.</param>
        public virtual void Colour(byte col)
        {
            CurrentAttr = (ushort)((CurrentAttr & 0x00FF) | (col << 8));

            FOS_System.String str = (FOS_System.String)Buffer[CurrentLine];

            //Set the attr of all characters in the rest of the line to
            //  the current colour.
            for (int i = CurrentChar; i < str.length; i++)
            {
                str[i] = (char)((str[i] & 0x00FF) | CurrentAttr);
            }
        }
Beispiel #11
0
        public static unsafe void HandleException()
        {
            //BasicConsole.WriteLine("Handle exception");

            if (State != null)
            {
                if (State->CurrentHandlerPtr != null)
                {
                    if (State->CurrentHandlerPtr->InHandler != 0)
                    {
                        State->CurrentHandlerPtr->InHandler = 0;
                        if (State->CurrentHandlerPtr->PrevHandlerPtr != null)
                        {
                            State->CurrentHandlerPtr->PrevHandlerPtr->Ex        = State->CurrentHandlerPtr->Ex;
                            State->CurrentHandlerPtr->PrevHandlerPtr->ExPending = State->CurrentHandlerPtr->ExPending;
                        }
                        State->CurrentHandlerPtr = State->CurrentHandlerPtr->PrevHandlerPtr;
                        State->depth--;
                        State->history[State->history_pos++] = (uint)State->CurrentHandlerPtr->HandlerAddress;
                        if (State->history_pos > 31)
                        {
                            State->history_pos = 0;
                        }
                    }
                }

                ExceptionHandlerInfo *CurrHandlerPtr = State->CurrentHandlerPtr;
                if (CurrHandlerPtr != null)
                {
                    if ((uint)CurrHandlerPtr->HandlerAddress != 0x00000000u)
                    {
                        if ((uint)CurrHandlerPtr->FilterAddress != 0x00000000u)
                        {
                            //Catch handler
                            CurrHandlerPtr->ExPending = 0;
                        }

                        CurrHandlerPtr->InHandler = 1;

                        ArbitaryReturn(CurrHandlerPtr->EBP, CurrHandlerPtr->ESP, CurrHandlerPtr->HandlerAddress);
                    }
                }
            }

            // If we get to here, it's an unhandled exception
            HaltReason = "Unhandled / improperly handled exception!";
            BasicConsole.WriteLine(HaltReason);
            // Try to cause fault
            *((byte *)0x800000000) = 0;
        }
Beispiel #12
0
        public static void Throw_NullReferenceException(uint address)
        {
            HaltReason = "Null reference exception. Instruction: 0x        ";
            FillString(address, 48, HaltReason);

            bool BCPOEnabled = BasicConsole.PrimaryOutputEnabled;

            BasicConsole.PrimaryOutputEnabled = true;
            BasicConsole.WriteLine(HaltReason);
            BasicConsole.DelayOutput(10);
            BasicConsole.PrimaryOutputEnabled = BCPOEnabled;

            FOS_System.Exception ex = new FOS_System.Exceptions.NullReferenceException();
            ex.InstructionAddress = address;
            Throw(ex);
        }
Beispiel #13
0
        /// <summary>
        /// Creates a blank line (a line filled with spaces set with the current attribute).
        /// </summary>
        /// <returns>The new line.</returns>
        protected FOS_System.String CreateBlankLine()
        {
            //Create a blank line (all characters set to 0s)
            FOS_System.String str = FOS_System.String.New(LineLength);

            //Set the attribute of all characters in the new blank line to
            //  the current character.
            //This is so that typed characters at least appear in current
            //  colour otherwise they wouldn't show at all.
            for (int i = 0; i < str.length; i++)
            {
                str[i] |= (char)CurrentAttr;
            }

            //Return the new blank line.
            return(str);
        }
Beispiel #14
0
        public static void PrintStackTrace()
        {
            uint *EBP = (uint *)BasePointer;

            while ((uint)EBP % 4096 != 0)
            {
                FOS_System.String msg = "EBP: 0x        , Return Address: 0x        , Prev EBP: 0x        ";
                //EBP: 14
                //Return address: 42
                //Prev EBP: 64

                uint ReturnAddress = *(EBP + 1);
                uint PrevEBP       = *(EBP);
                FillString((uint)EBP, 14, msg);
                FillString(ReturnAddress, 42, msg);
                FillString(PrevEBP, 64, msg);
                BasicConsole.WriteLine(msg);

                EBP = (uint *)PrevEBP;
            }
        }
Beispiel #15
0
        /// <summary>
        /// Writes a new line to the output.
        /// </summary>
        public virtual void WriteLine()
        {
            FOS_System.String line = null;
            //If we've reached the maximum number of lines
            //  to store in the buffer
            if (Buffer.Count == MaxBufferSize)
            {
                // Remove the first line (oldest line - appears at the top
                //   of the screen if the user scrolls all the way to the top)
                //   to create space.
                line = (FOS_System.String)Buffer[0];
                Buffer.RemoveAt(0);

                // And make it into a new blank line
                for (int i = 0; i < line.length; i++)
                {
                    line[i] = ' ';
                }
            }
            else
            {
                //Create a new blank line
                line = CreateBlankLine();
            }
            // Add the blank line to the bottom of the buffer
            Buffer.Add(line);

            //Update the current line / character
            CurrentLine = Buffer.Count - 1;
            CurrentChar = 0;

            //Update the screen
            Update();

            //Update the cursor position
            SetCursorPosition((ushort)(CurrentChar - GetDisplayOffset_Char()),
                              (ushort)(CurrentLine - GetDisplayOffset_Line()));
        }
Beispiel #16
0
        public static unsafe void PrintTestString()
        {
            if (!Initialised)
            {
                return;
            }
            //This does not use the Write functions as it is a test function to
            //  test that strings and the video memory output work.

            FOS_System.String str = "1234567890!\"£$%^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM[];'#,./{}:@~<>?\\|`¬¦";
            int   strLength       = str.length;
            char *strPtr          = str.GetCharPointer();
            char *vidMemPtr       = vidMemBasePtr;

            while (strLength > 0)
            {
                vidMemPtr[0] = (char)((*strPtr & 0x00FF) | colour);

                strPtr++;
                vidMemPtr++;
                strLength--;
            }
        }
Beispiel #17
0
        public static unsafe void HandleException()
        {
            //BasicConsole.WriteLine("Handle exception");

            if (State != null)
            {
                if (State->CurrentHandlerPtr != null)
                {
                    if (State->CurrentHandlerPtr->InHandler != 0)
                    {
                        State->CurrentHandlerPtr->InHandler = 0;
                        if (State->CurrentHandlerPtr->PrevHandlerPtr != null)
                        {
                            State->CurrentHandlerPtr->PrevHandlerPtr->Ex = State->CurrentHandlerPtr->Ex;
                            State->CurrentHandlerPtr->PrevHandlerPtr->ExPending = State->CurrentHandlerPtr->ExPending;
                        }
                        State->CurrentHandlerPtr = State->CurrentHandlerPtr->PrevHandlerPtr;
                        State->depth--;
                        State->history[State->history_pos++] = (uint)State->CurrentHandlerPtr->HandlerAddress;
                        if (State->history_pos > 31)
                        {
                            State->history_pos = 0;
                        }
                    }
                }

                ExceptionHandlerInfo* CurrHandlerPtr = State->CurrentHandlerPtr;
                if (CurrHandlerPtr != null)
                {
                    if ((uint)CurrHandlerPtr->HandlerAddress != 0x00000000u)
                    {
                        if ((uint)CurrHandlerPtr->FilterAddress != 0x00000000u)
                        {
                            //Catch handler
                            CurrHandlerPtr->ExPending = 0;
                        }

                        CurrHandlerPtr->InHandler = 1;

                        ArbitaryReturn(CurrHandlerPtr->EBP, CurrHandlerPtr->ESP, CurrHandlerPtr->HandlerAddress);
                    }
                }
            }
            
            // If we get to here, it's an unhandled exception
            HaltReason = "Unhandled / improperly handled exception!";
            BasicConsole.WriteLine(HaltReason);
            // Try to cause fault
            *((byte*)0x800000000) = 0;
        }
Beispiel #18
0
        public static unsafe void Throw(FOS_System.Exception ex)
        {
            Kernel.FOS_System.GC.IncrementRefCount(ex);

            BasicConsole.WriteLine("Exception thrown:");
            BasicConsole.WriteLine(ex.Message);

            if (State->CurrentHandlerPtr->Ex != null)
            {
                //GC ref count remains consistent because the Ex pointer below is going to be replaced but
                //  same pointer stored in InnerException.
                // Result is ref count goes: +1 here, -1 below
                ex.InnerException = (Kernel.FOS_System.Exception)Utilities.ObjectUtilities.GetObject(State->CurrentHandlerPtr->Ex);
            }
            if (ex.InstructionAddress == 0)
            {
                ex.InstructionAddress = *((uint*)BasePointer + 1);
            }
            State->CurrentHandlerPtr->Ex = Utilities.ObjectUtilities.GetHandle(ex);
            State->CurrentHandlerPtr->ExPending = 1;

            HandleException();

            // We never expect to get here...
            HaltReason = "HandleException returned!";
            BasicConsole.WriteLine(HaltReason);
            // Try to cause fault
            *((byte*)0x800000000) = 0;
        }
Beispiel #19
0
 /// <summary>
 /// Throws an Array Type Mismatch exception.
 /// </summary>
 /// <remarks>
 /// Used by compiler to handle the creation of the exception object and calling Throw.
 /// </remarks>
 //[Drivers.Compiler.Attributes.ThrowArrayTypeMismatchExceptionMethod]
 public static void Throw_ArrayTypeMismatchException()
 {
     HaltReason = "Array type mismatch exception.";
     Throw(new FOS_System.Exceptions.ArrayTypeMismatchException());
 }
Beispiel #20
0
        /// <summary>
        /// Writes the specified number as an unsigned decimal string.
        /// </summary>
        /// <param name="num">The number to write as a decimal.</param>
        public virtual void Write_AsDecimal(UInt32 num)
        {
            FOS_System.String result = "";
            //If the number is already 0, just output 0
            //  straight off. The algorithm below does not
            //  work if num is 0.
            if (num != 0)
            {
                //Loop through outputting the units value (base 10)
                //  and then dividing by 10 to move to the next digit.
                while (num > 0)
                {
                    //Get the units
                    uint rem = num % 10;
                    //Output the units character
                    switch (rem)
                    {
                    case 0:
                        result = "0" + result;
                        break;

                    case 1:
                        result = "1" + result;
                        break;

                    case 2:
                        result = "2" + result;
                        break;

                    case 3:
                        result = "3" + result;
                        break;

                    case 4:
                        result = "4" + result;
                        break;

                    case 5:
                        result = "5" + result;
                        break;

                    case 6:
                        result = "6" + result;
                        break;

                    case 7:
                        result = "7" + result;
                        break;

                    case 8:
                        result = "8" + result;
                        break;

                    case 9:
                        result = "9" + result;
                        break;
                    }
                    //Divide by 10 to move to the next digit.
                    num /= 10;
                }
            }
            else
            {
                result = "0";
            }
            //Write the resulting number
            Write(result);
        }
Beispiel #21
0
        /// <summary>
        /// Throws a page fault exception.
        /// </summary>
        /// <param name="errorCode">The error code associated with the page fault.</param>
        /// <param name="address">The address which caused the fault.</param>
        /// <remarks>
        /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
        /// </remarks>
        public static void Throw_PageFaultException(uint eip, uint errorCode, uint address)
        {
            if (ThePageFaultHandler != null)
            {
                ThePageFaultHandler(eip, errorCode, address);
            }
            else
            {
                BasicConsole.SetTextColour(BasicConsole.error_colour);
                BasicConsole.WriteLine("Page fault exception!");

                HaltReason = "Page fault exception. Address: 0x        , errorCode: 0x        , eip: 0x        ";

                uint y = address;
                int offset = 40;
                #region Address
                while (offset > 32)
                {
                    uint rem = y & 0xFu;
                    switch (rem)
                    {
                        case 0:
                            HaltReason[offset] = '0';
                            break;
                        case 1:
                            HaltReason[offset] = '1';
                            break;
                        case 2:
                            HaltReason[offset] = '2';
                            break;
                        case 3:
                            HaltReason[offset] = '3';
                            break;
                        case 4:
                            HaltReason[offset] = '4';
                            break;
                        case 5:
                            HaltReason[offset] = '5';
                            break;
                        case 6:
                            HaltReason[offset] = '6';
                            break;
                        case 7:
                            HaltReason[offset] = '7';
                            break;
                        case 8:
                            HaltReason[offset] = '8';
                            break;
                        case 9:
                            HaltReason[offset] = '9';
                            break;
                        case 10:
                            HaltReason[offset] = 'A';
                            break;
                        case 11:
                            HaltReason[offset] = 'B';
                            break;
                        case 12:
                            HaltReason[offset] = 'C';
                            break;
                        case 13:
                            HaltReason[offset] = 'D';
                            break;
                        case 14:
                            HaltReason[offset] = 'E';
                            break;
                        case 15:
                            HaltReason[offset] = 'F';
                            break;
                    }
                    y >>= 4;
                    offset--;
                }

                #endregion

                y = errorCode;
                offset = 63;
                #region Error Code

                while (offset > 55)
                {
                    uint rem = y & 0xFu;
                    switch (rem)
                    {
                        case 0:
                            HaltReason[offset] = '0';
                            break;
                        case 1:
                            HaltReason[offset] = '1';
                            break;
                        case 2:
                            HaltReason[offset] = '2';
                            break;
                        case 3:
                            HaltReason[offset] = '3';
                            break;
                        case 4:
                            HaltReason[offset] = '4';
                            break;
                        case 5:
                            HaltReason[offset] = '5';
                            break;
                        case 6:
                            HaltReason[offset] = '6';
                            break;
                        case 7:
                            HaltReason[offset] = '7';
                            break;
                        case 8:
                            HaltReason[offset] = '8';
                            break;
                        case 9:
                            HaltReason[offset] = '9';
                            break;
                        case 10:
                            HaltReason[offset] = 'A';
                            break;
                        case 11:
                            HaltReason[offset] = 'B';
                            break;
                        case 12:
                            HaltReason[offset] = 'C';
                            break;
                        case 13:
                            HaltReason[offset] = 'D';
                            break;
                        case 14:
                            HaltReason[offset] = 'E';
                            break;
                        case 15:
                            HaltReason[offset] = 'F';
                            break;
                    }
                    y >>= 4;
                    offset--;
                }

                #endregion

                y = eip;
                offset = 80;
                #region EIP

                while (offset > 72)
                {
                    uint rem = y & 0xFu;
                    switch (rem)
                    {
                        case 0:
                            HaltReason[offset] = '0';
                            break;
                        case 1:
                            HaltReason[offset] = '1';
                            break;
                        case 2:
                            HaltReason[offset] = '2';
                            break;
                        case 3:
                            HaltReason[offset] = '3';
                            break;
                        case 4:
                            HaltReason[offset] = '4';
                            break;
                        case 5:
                            HaltReason[offset] = '5';
                            break;
                        case 6:
                            HaltReason[offset] = '6';
                            break;
                        case 7:
                            HaltReason[offset] = '7';
                            break;
                        case 8:
                            HaltReason[offset] = '8';
                            break;
                        case 9:
                            HaltReason[offset] = '9';
                            break;
                        case 10:
                            HaltReason[offset] = 'A';
                            break;
                        case 11:
                            HaltReason[offset] = 'B';
                            break;
                        case 12:
                            HaltReason[offset] = 'C';
                            break;
                        case 13:
                            HaltReason[offset] = 'D';
                            break;
                        case 14:
                            HaltReason[offset] = 'E';
                            break;
                        case 15:
                            HaltReason[offset] = 'F';
                            break;
                    }
                    y >>= 4;
                    offset--;
                }

                #endregion

                BasicConsole.WriteLine(HaltReason);
                BasicConsole.SetTextColour(BasicConsole.default_colour);

                Throw(new FOS_System.Exceptions.PageFaultException(errorCode, address));
            }
        }
Beispiel #22
0
        /// <summary>
        /// Throws a double fault exception.
        /// </summary>
        /// <remarks>
        /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
        /// </remarks>
        public static void Throw_DoubleFaultException(uint address, uint errorCode)
        {
            HaltReason = "Double fault exception. Address: 0x         Error code: 0x        ";

            uint y = address;
            int offset = 42;
            #region Address
            while (offset > 34)
            {
                uint rem = y & 0xFu;
                switch (rem)
                {
                    case 0:
                        HaltReason[offset] = '0';
                        break;
                    case 1:
                        HaltReason[offset] = '1';
                        break;
                    case 2:
                        HaltReason[offset] = '2';
                        break;
                    case 3:
                        HaltReason[offset] = '3';
                        break;
                    case 4:
                        HaltReason[offset] = '4';
                        break;
                    case 5:
                        HaltReason[offset] = '5';
                        break;
                    case 6:
                        HaltReason[offset] = '6';
                        break;
                    case 7:
                        HaltReason[offset] = '7';
                        break;
                    case 8:
                        HaltReason[offset] = '8';
                        break;
                    case 9:
                        HaltReason[offset] = '9';
                        break;
                    case 10:
                        HaltReason[offset] = 'A';
                        break;
                    case 11:
                        HaltReason[offset] = 'B';
                        break;
                    case 12:
                        HaltReason[offset] = 'C';
                        break;
                    case 13:
                        HaltReason[offset] = 'D';
                        break;
                    case 14:
                        HaltReason[offset] = 'E';
                        break;
                    case 15:
                        HaltReason[offset] = 'F';
                        break;
                }
                y >>= 4;
                offset--;
            }

            #endregion

            y = errorCode;
            offset = 65;
            #region Error Code
            while (offset > 57)
            {
                uint rem = y & 0xFu;
                switch (rem)
                {
                    case 0:
                        HaltReason[offset] = '0';
                        break;
                    case 1:
                        HaltReason[offset] = '1';
                        break;
                    case 2:
                        HaltReason[offset] = '2';
                        break;
                    case 3:
                        HaltReason[offset] = '3';
                        break;
                    case 4:
                        HaltReason[offset] = '4';
                        break;
                    case 5:
                        HaltReason[offset] = '5';
                        break;
                    case 6:
                        HaltReason[offset] = '6';
                        break;
                    case 7:
                        HaltReason[offset] = '7';
                        break;
                    case 8:
                        HaltReason[offset] = '8';
                        break;
                    case 9:
                        HaltReason[offset] = '9';
                        break;
                    case 10:
                        HaltReason[offset] = 'A';
                        break;
                    case 11:
                        HaltReason[offset] = 'B';
                        break;
                    case 12:
                        HaltReason[offset] = 'C';
                        break;
                    case 13:
                        HaltReason[offset] = 'D';
                        break;
                    case 14:
                        HaltReason[offset] = 'E';
                        break;
                    case 15:
                        HaltReason[offset] = 'F';
                        break;
                }
                y >>= 4;
                offset--;
            }

            #endregion

            BasicConsole.SetTextColour(BasicConsole.error_colour);
            BasicConsole.WriteLine(HaltReason);
            BasicConsole.SetTextColour(BasicConsole.default_colour);
            Throw(new FOS_System.Exceptions.DoubleFaultException(errorCode));
        }
Beispiel #23
0
 /// <summary>
 /// Throws a divide by zero exception storing the specified exception address.
 /// </summary>
 /// <param name="address">The address of the code that caused the exception.</param>
 /// <remarks>
 /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
 /// </remarks>
 public static void Throw_DivideByZeroException(uint address)
 {
     HaltReason = "Divide by zero exception.";
     BasicConsole.SetTextColour(BasicConsole.error_colour);
     BasicConsole.WriteLine(HaltReason);
     BasicConsole.SetTextColour(BasicConsole.default_colour);
     Throw(new FOS_System.Exceptions.DivideByZeroException(address));
 }
Beispiel #24
0
        /// <summary>
        /// Writes the specified text to the output. Overflows to the next line if necessary.
        /// "\n" characters will result in a new line being started.
        /// </summary>
        /// <param name="str">The string to write.</param>
        public virtual void Write(FOS_System.String str)
        {
            //Loop through each character, outputting them.
            for (int i = 0; i < str.length; i++)
            {
                //If we have reached the end of the current line,
                //  create a new one using WriteLine()
                if (CurrentChar == LineLength)
                {
                    WriteLine();
                }

                // This take cares if the text has CRLF line termination instead of expected LF
                if (str[i] == '\r')         // Checks for Carriage return (\r)
                {
                    if (str[i + 1] == '\n') // Checks that the next character is a Line feed
                    {
                        i++;
                    }
                }
                //If a \n (newline) character is found,
                //  create a new line using WriteLine()
                if (str[i] == '\n')
                {
                    WriteLine();
                }
                //Else if \b (backspace) character is found
                //  delete a character or line
                else if (str[i] == '\b')
                {
                    //If at very start of a line
                    if (CurrentChar == 0)
                    {
                        //Delete a line
                        Buffer.RemoveAt(CurrentLine);
                        CurrentLine--;
                        CurrentChar = LineLength;
                    }

                    //Check there is still a line to edit
                    if (CurrentLine > -1)
                    {
                        //Always delete a visible character
                        ((FOS_System.String)Buffer[CurrentLine])[--CurrentChar] = (char)((' ' & 0xFF) | CurrentAttr);
                    }
                }
                //Otherwise, just output the character to the current position
                //  and move current position to the next character.
                else
                {
                    // Check for tab character - if so, output four spaces (rudimentary tab support)
                    if (str[i] == '\t')
                    {
                        Write("    ");
                    }
                    else
                    {
                        //The character must also be or'ed with the current attribute so it appears the correct
                        //  colour.
                        //Strings in the core kernel are stored as 2-byte unicode but we output only ASCII
                        //  so the character must be and'ed with 0xFF to clear the top byte else it would
                        //  interfere with the attribute (colour).
                        ((FOS_System.String)Buffer[CurrentLine])[CurrentChar++] = (char)((str[i] & 0xFF) | CurrentAttr);
                    }
                }
            }
            //Call update to update the screen with the new text.
            Update();
            //Update the cursor position.
            SetCursorPosition((ushort)(CurrentChar - GetDisplayOffset_Char()),
                              (ushort)(CurrentLine - GetDisplayOffset_Line()));
        }
Beispiel #25
0
        public static void Halt(uint lastAddress)
        {
            BasicConsole.PrimaryOutputEnabled = true;

            try
            {
                Hardware.Devices.Keyboard.CleanDefault();
                Hardware.Devices.Timer.CleanDefault();
            }
            catch
            {
            }

            BasicConsole.SetTextColour(BasicConsole.warning_colour);
            BasicConsole.Write("Halt Reason: ");
            BasicConsole.WriteLine(ExceptionMethods.HaltReason);

            FOS_System.String LastAddressStr = "Last address: 0x        ";
            uint y      = lastAddress;
            int  offset = 23;

            #region Address
            while (offset > 15)
            {
                uint rem = y & 0xFu;
                switch (rem)
                {
                case 0:
                    LastAddressStr[offset] = '0';
                    break;

                case 1:
                    LastAddressStr[offset] = '1';
                    break;

                case 2:
                    LastAddressStr[offset] = '2';
                    break;

                case 3:
                    LastAddressStr[offset] = '3';
                    break;

                case 4:
                    LastAddressStr[offset] = '4';
                    break;

                case 5:
                    LastAddressStr[offset] = '5';
                    break;

                case 6:
                    LastAddressStr[offset] = '6';
                    break;

                case 7:
                    LastAddressStr[offset] = '7';
                    break;

                case 8:
                    LastAddressStr[offset] = '8';
                    break;

                case 9:
                    LastAddressStr[offset] = '9';
                    break;

                case 10:
                    LastAddressStr[offset] = 'A';
                    break;

                case 11:
                    LastAddressStr[offset] = 'B';
                    break;

                case 12:
                    LastAddressStr[offset] = 'C';
                    break;

                case 13:
                    LastAddressStr[offset] = 'D';
                    break;

                case 14:
                    LastAddressStr[offset] = 'E';
                    break;

                case 15:
                    LastAddressStr[offset] = 'F';
                    break;
                }
                y >>= 4;
                offset--;
            }

            #endregion
            BasicConsole.WriteLine(LastAddressStr);

            BasicConsole.SetTextColour(BasicConsole.default_colour);

            if (ExceptionMethods.CurrentException != null)
            {
                BasicConsole.SetTextColour(BasicConsole.error_colour);
                BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
                if (ExceptionMethods.CurrentException is FOS_System.Exceptions.PageFaultException)
                {
                    BasicConsole.Write("Address: ");
                    BasicConsole.WriteLine(((FOS_System.Exceptions.PageFaultException)ExceptionMethods.CurrentException).address);
                    BasicConsole.Write("Code: ");
                    BasicConsole.WriteLine(((FOS_System.Exceptions.PageFaultException)ExceptionMethods.CurrentException).errorCode);
                }
                else if (ExceptionMethods.CurrentException is FOS_System.Exceptions.DoubleFaultException)
                {
                    BasicConsole.Write("Code: ");
                    BasicConsole.WriteLine(((FOS_System.Exceptions.DoubleFaultException)ExceptionMethods.CurrentException).ErrorCode);
                }
                BasicConsole.SetTextColour(BasicConsole.default_colour);
            }

            BasicConsole.SetTextColour(BasicConsole.error_colour);
            BasicConsole.WriteLine("Kernel halting!");
            BasicConsole.SetTextColour(BasicConsole.default_colour);
            PreReqs.Reset();
        }
Beispiel #26
0
 /// <summary>
 /// Writes the specified string followed by a new line.
 /// </summary>
 /// <param name="str">The string to write before the new line.</param>
 public virtual void WriteLine(FOS_System.String str)
 {
     //Write the string followed by a new line
     Write(str);
     WriteLine();
 }
Beispiel #27
0
        public static unsafe void HandleEndFinally()
        {
            if (State == null ||
                State->CurrentHandlerPtr == null)
            {
                // If we get to here, it's an unhandled exception
                if (State == null)
                {
                    HaltReason = "Cannot end finally in null state!";
                }
                else if (State->CurrentHandlerPtr == null)
                {
                    HaltReason = "Cannot end finally on null handler!";
                }
                else
                {
                    HaltReason = "Cannot end finally for unexpected reason!";
                }
                BasicConsole.WriteLine(HaltReason);
                BasicConsole.DelayOutput(5);

                // Try to cause fault
                *((byte *)0x800000000) = 0;
            }

            // Leaving a "finally" critical section cleanly
            // We need to handle 2 cases:
            // Case 1 : Pending exception
            // Case 2 : No pending exception

            //BasicConsole.WriteLine("Handle end finally");

            if (State->CurrentHandlerPtr->ExPending != 0)
            {
                // Case 1 : Pending exception

                HandleException();
            }
            else
            {
                // Case 2 : No pending exception

                State->CurrentHandlerPtr->InHandler = 0;

                uint  EBP     = State->CurrentHandlerPtr->EBP;
                uint  ESP     = State->CurrentHandlerPtr->ESP;
                byte *retAddr = State->CurrentHandlerPtr->HandlerAddress;//(byte*)*((uint*)(BasePointer + 4));

                //BasicConsole.Write("Continue ptr (from HandlerAddress): ");
                //BasicConsole.WriteLine((uint)State->CurrentHandlerPtr->HandlerAddress);
                //BasicConsole.Write("Actual continue addr (from EBP): ");
                //BasicConsole.WriteLine(*((uint*)(BasePointer + 4)));

                State->CurrentHandlerPtr = State->CurrentHandlerPtr->PrevHandlerPtr;
                State->depth--;
                State->history[State->history_pos++] = (uint)State->CurrentHandlerPtr->HandlerAddress;
                if (State->history_pos > 31)
                {
                    State->history_pos = 0;
                }

                ArbitaryReturn(EBP,
                               ESP + (uint)sizeof(ExceptionHandlerInfo),
                               retAddr);
            }
        }
Beispiel #28
0
        public static unsafe void HandleLeave(void *continuePtr)
        {
            if (State == null ||
                State->CurrentHandlerPtr == null)
            {
                // If we get to here, it's an unhandled exception
                HaltReason = "";
                if (State == null)
                {
                    HaltReason = "Cannot leave on null handler! Address: 0x         - Null state";
                }
                else if (State->CurrentHandlerPtr == null)
                {
                    HaltReason = "Cannot leave on null handler! Address: 0x         - Null handler";
                }
                else
                {
                    HaltReason = "Cannot leave on null handler! Address: 0x         - Unexpected reason";
                }


                uint y      = *((uint *)(BasePointer + 4));
                int  offset = 48;
                #region Address
                while (offset > 40)
                {
                    uint rem = y & 0xFu;
                    switch (rem)
                    {
                    case 0:
                        HaltReason[offset] = '0';
                        break;

                    case 1:
                        HaltReason[offset] = '1';
                        break;

                    case 2:
                        HaltReason[offset] = '2';
                        break;

                    case 3:
                        HaltReason[offset] = '3';
                        break;

                    case 4:
                        HaltReason[offset] = '4';
                        break;

                    case 5:
                        HaltReason[offset] = '5';
                        break;

                    case 6:
                        HaltReason[offset] = '6';
                        break;

                    case 7:
                        HaltReason[offset] = '7';
                        break;

                    case 8:
                        HaltReason[offset] = '8';
                        break;

                    case 9:
                        HaltReason[offset] = '9';
                        break;

                    case 10:
                        HaltReason[offset] = 'A';
                        break;

                    case 11:
                        HaltReason[offset] = 'B';
                        break;

                    case 12:
                        HaltReason[offset] = 'C';
                        break;

                    case 13:
                        HaltReason[offset] = 'D';
                        break;

                    case 14:
                        HaltReason[offset] = 'E';
                        break;

                    case 15:
                        HaltReason[offset] = 'F';
                        break;
                    }
                    y >>= 4;
                    offset--;
                }

                #endregion

                BasicConsole.WriteLine(HaltReason);

                if (State != null)
                {
                    if (State->depth > 0)
                    {
                        BasicConsole.WriteLine("    -- Positive depth");
                    }
                    else if (State->depth == 0)
                    {
                        BasicConsole.WriteLine("    -- Zero depth");
                    }
                    else if (State->depth < 0)
                    {
                        BasicConsole.WriteLine("    -- Negative depth");
                    }

                    int pos = State->history_pos;
                    do
                    {
                        BasicConsole.Write(State->history[pos]);
                        BasicConsole.Write(" ");

                        pos--;
                        if (pos == -1)
                        {
                            pos = 31;
                        }
                    }while (pos != State->history_pos);
                }

                BasicConsole.DelayOutput(5);

                // Try to cause fault
                *((byte *)0x800000000) = 0;
            }

            // Leaving a critical section cleanly
            // We need to handle 2 cases:
            // Case 1 : Leaving "try" or "catch" of a try-catch
            // Case 2 : Leaving the "try" of a try-finally

            if ((uint)State->CurrentHandlerPtr->FilterAddress != 0x0u)
            {
                // Case 1 : Leaving "try" or "catch" of a try-catch
                //BasicConsole.WriteLine("Leave try or catch of try-catch");

                if (State->CurrentHandlerPtr->Ex != null)
                {
                    FOS_System.GC.DecrementRefCount((FOS_System.Object)Utilities.ObjectUtilities.GetObject(State->CurrentHandlerPtr->Ex));
                    State->CurrentHandlerPtr->Ex = null;
                }

                State->CurrentHandlerPtr->InHandler = 0;

                uint EBP = State->CurrentHandlerPtr->EBP;
                uint ESP = State->CurrentHandlerPtr->ESP;

                State->CurrentHandlerPtr = State->CurrentHandlerPtr->PrevHandlerPtr;
                State->depth--;
                State->history[State->history_pos++] = (uint)State->CurrentHandlerPtr->HandlerAddress;
                if (State->history_pos > 31)
                {
                    State->history_pos = 0;
                }

                ArbitaryReturn(EBP, ESP + (uint)sizeof(ExceptionHandlerInfo), (byte *)continuePtr);
            }
            else
            {
                // Case 2 : Leaving the "try" of a try-finally

                State->CurrentHandlerPtr->InHandler = 1;

                byte *handlerAddress = State->CurrentHandlerPtr->HandlerAddress;

                //BasicConsole.WriteLine("Leave try of try-finally");
                //BasicConsole.Write("Handler address: ");
                //BasicConsole.WriteLine((uint)handlerAddress);
                //BasicConsole.Write("Continue ptr: ");
                //BasicConsole.WriteLine((uint)continuePtr);

                State->CurrentHandlerPtr->HandlerAddress = (byte *)continuePtr;

                ArbitaryReturn(State->CurrentHandlerPtr->EBP,
                               State->CurrentHandlerPtr->ESP,
                               handlerAddress);
            }
        }
Beispiel #29
0
        public static unsafe void HandleLeave(void* continuePtr)
        {
            if (State == null || 
                State->CurrentHandlerPtr == null)
            {
                // If we get to here, it's an unhandled exception
                HaltReason = "";
                if (State == null)
                {
                    HaltReason = "Cannot leave on null handler! Address: 0x         - Null state";
                }
                else if (State->CurrentHandlerPtr == null)
                {
                    HaltReason = "Cannot leave on null handler! Address: 0x         - Null handler";                
                }
                else
                {
                    HaltReason = "Cannot leave on null handler! Address: 0x         - Unexpected reason";
                }


                uint y = *((uint*)(BasePointer + 4));
                int offset = 48;
                #region Address
                while (offset > 40)
                {
                    uint rem = y & 0xFu;
                    switch (rem)
                    {
                        case 0:
                            HaltReason[offset] = '0';
                            break;
                        case 1:
                            HaltReason[offset] = '1';
                            break;
                        case 2:
                            HaltReason[offset] = '2';
                            break;
                        case 3:
                            HaltReason[offset] = '3';
                            break;
                        case 4:
                            HaltReason[offset] = '4';
                            break;
                        case 5:
                            HaltReason[offset] = '5';
                            break;
                        case 6:
                            HaltReason[offset] = '6';
                            break;
                        case 7:
                            HaltReason[offset] = '7';
                            break;
                        case 8:
                            HaltReason[offset] = '8';
                            break;
                        case 9:
                            HaltReason[offset] = '9';
                            break;
                        case 10:
                            HaltReason[offset] = 'A';
                            break;
                        case 11:
                            HaltReason[offset] = 'B';
                            break;
                        case 12:
                            HaltReason[offset] = 'C';
                            break;
                        case 13:
                            HaltReason[offset] = 'D';
                            break;
                        case 14:
                            HaltReason[offset] = 'E';
                            break;
                        case 15:
                            HaltReason[offset] = 'F';
                            break;
                    }
                    y >>= 4;
                    offset--;
                }

                #endregion

                BasicConsole.WriteLine(HaltReason);

                if (State != null)
                {
                    if (State->depth > 0)
                    {
                        BasicConsole.WriteLine("    -- Positive depth");
                    }
                    else if (State->depth == 0)
                    {
                        BasicConsole.WriteLine("    -- Zero depth");
                    }
                    else if (State->depth < 0)
                    {
                        BasicConsole.WriteLine("    -- Negative depth");
                    }

                    int pos = State->history_pos;
                    do
                    {
                        BasicConsole.Write(State->history[pos]);
                        BasicConsole.Write(" ");

                        pos--;
                        if (pos == -1)
                        {
                            pos = 31;
                        }
                    }
                    while (pos != State->history_pos);
                }

                BasicConsole.DelayOutput(5);

                // Try to cause fault
                *((byte*)0x800000000) = 0;
            }

            // Leaving a critical section cleanly
            // We need to handle 2 cases:
            // Case 1 : Leaving "try" or "catch" of a try-catch
            // Case 2 : Leaving the "try" of a try-finally

            if ((uint)State->CurrentHandlerPtr->FilterAddress != 0x0u)
            {
                // Case 1 : Leaving "try" or "catch" of a try-catch
                //BasicConsole.WriteLine("Leave try or catch of try-catch");

                if (State->CurrentHandlerPtr->Ex != null)
                {
                    FOS_System.GC.DecrementRefCount((FOS_System.Object)Utilities.ObjectUtilities.GetObject(State->CurrentHandlerPtr->Ex));
                    State->CurrentHandlerPtr->Ex = null;
                }

                State->CurrentHandlerPtr->InHandler = 0;

                uint EBP = State->CurrentHandlerPtr->EBP;
                uint ESP = State->CurrentHandlerPtr->ESP;

                State->CurrentHandlerPtr = State->CurrentHandlerPtr->PrevHandlerPtr;
                State->depth--;
                State->history[State->history_pos++] = (uint)State->CurrentHandlerPtr->HandlerAddress;
                if (State->history_pos > 31)
                {
                    State->history_pos = 0;
                }

                ArbitaryReturn(EBP, ESP + (uint)sizeof(ExceptionHandlerInfo), (byte*)continuePtr);
            }
            else
            {
                // Case 2 : Leaving the "try" of a try-finally
                
                State->CurrentHandlerPtr->InHandler = 1;

                byte* handlerAddress = State->CurrentHandlerPtr->HandlerAddress;

                //BasicConsole.WriteLine("Leave try of try-finally");
                //BasicConsole.Write("Handler address: ");
                //BasicConsole.WriteLine((uint)handlerAddress);
                //BasicConsole.Write("Continue ptr: ");
                //BasicConsole.WriteLine((uint)continuePtr);

                State->CurrentHandlerPtr->HandlerAddress = (byte*)continuePtr;

                ArbitaryReturn(State->CurrentHandlerPtr->EBP,
                               State->CurrentHandlerPtr->ESP,
                               handlerAddress);
            }

        }
Beispiel #30
0
        public static unsafe void HandleEndFinally()
        {
            if (State == null ||
                State->CurrentHandlerPtr == null)
            {
                // If we get to here, it's an unhandled exception
                if (State == null)
                {
                    HaltReason = "Cannot end finally in null state!";
                }
                else if (State->CurrentHandlerPtr == null)
                {
                    HaltReason = "Cannot end finally on null handler!";
                }
                else
                {
                    HaltReason = "Cannot end finally for unexpected reason!";
                }
                BasicConsole.WriteLine(HaltReason);
                BasicConsole.DelayOutput(5);
                
                // Try to cause fault
                *((byte*)0x800000000) = 0;
            }

            // Leaving a "finally" critical section cleanly
            // We need to handle 2 cases:
            // Case 1 : Pending exception
            // Case 2 : No pending exception

            //BasicConsole.WriteLine("Handle end finally");

            if (State->CurrentHandlerPtr->ExPending != 0)
            {
                // Case 1 : Pending exception
                
                HandleException();
            }
            else
            {
                // Case 2 : No pending exception
                
                State->CurrentHandlerPtr->InHandler = 0;

                uint EBP = State->CurrentHandlerPtr->EBP;
                uint ESP = State->CurrentHandlerPtr->ESP;
                byte* retAddr = State->CurrentHandlerPtr->HandlerAddress;//(byte*)*((uint*)(BasePointer + 4));

                //BasicConsole.Write("Continue ptr (from HandlerAddress): ");
                //BasicConsole.WriteLine((uint)State->CurrentHandlerPtr->HandlerAddress);
                //BasicConsole.Write("Actual continue addr (from EBP): ");
                //BasicConsole.WriteLine(*((uint*)(BasePointer + 4)));

                State->CurrentHandlerPtr = State->CurrentHandlerPtr->PrevHandlerPtr;
                State->depth--;
                State->history[State->history_pos++] = (uint)State->CurrentHandlerPtr->HandlerAddress;
                if (State->history_pos > 31)
                {
                    State->history_pos = 0;
                }

                ArbitaryReturn(EBP,
                    ESP + (uint)sizeof(ExceptionHandlerInfo),
                    retAddr);
            }
        }
Beispiel #31
0
        /// <summary>
        /// Throws a page fault exception.
        /// </summary>
        /// <param name="errorCode">The error code associated with the page fault.</param>
        /// <param name="address">The address which caused the fault.</param>
        /// <remarks>
        /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
        /// </remarks>
        public static void Throw_PageFaultException(uint eip, uint errorCode, uint address)
        {
            if (ThePageFaultHandler != null)
            {
                ThePageFaultHandler(eip, errorCode, address);
            }
            else
            {
                BasicConsole.SetTextColour(BasicConsole.error_colour);
                BasicConsole.WriteLine("Page fault exception!");
                BasicConsole.DelayOutput(10);

                HaltReason = "Page fault exception. Address: 0x        , errorCode: 0x        , eip: 0x        ";

                uint y      = address;
                int  offset = 40;
                #region Address
                while (offset > 32)
                {
                    uint rem = y & 0xFu;
                    switch (rem)
                    {
                    case 0:
                        HaltReason[offset] = '0';
                        break;

                    case 1:
                        HaltReason[offset] = '1';
                        break;

                    case 2:
                        HaltReason[offset] = '2';
                        break;

                    case 3:
                        HaltReason[offset] = '3';
                        break;

                    case 4:
                        HaltReason[offset] = '4';
                        break;

                    case 5:
                        HaltReason[offset] = '5';
                        break;

                    case 6:
                        HaltReason[offset] = '6';
                        break;

                    case 7:
                        HaltReason[offset] = '7';
                        break;

                    case 8:
                        HaltReason[offset] = '8';
                        break;

                    case 9:
                        HaltReason[offset] = '9';
                        break;

                    case 10:
                        HaltReason[offset] = 'A';
                        break;

                    case 11:
                        HaltReason[offset] = 'B';
                        break;

                    case 12:
                        HaltReason[offset] = 'C';
                        break;

                    case 13:
                        HaltReason[offset] = 'D';
                        break;

                    case 14:
                        HaltReason[offset] = 'E';
                        break;

                    case 15:
                        HaltReason[offset] = 'F';
                        break;
                    }
                    y >>= 4;
                    offset--;
                }

                #endregion

                y      = errorCode;
                offset = 63;
                #region Error Code

                while (offset > 55)
                {
                    uint rem = y & 0xFu;
                    switch (rem)
                    {
                    case 0:
                        HaltReason[offset] = '0';
                        break;

                    case 1:
                        HaltReason[offset] = '1';
                        break;

                    case 2:
                        HaltReason[offset] = '2';
                        break;

                    case 3:
                        HaltReason[offset] = '3';
                        break;

                    case 4:
                        HaltReason[offset] = '4';
                        break;

                    case 5:
                        HaltReason[offset] = '5';
                        break;

                    case 6:
                        HaltReason[offset] = '6';
                        break;

                    case 7:
                        HaltReason[offset] = '7';
                        break;

                    case 8:
                        HaltReason[offset] = '8';
                        break;

                    case 9:
                        HaltReason[offset] = '9';
                        break;

                    case 10:
                        HaltReason[offset] = 'A';
                        break;

                    case 11:
                        HaltReason[offset] = 'B';
                        break;

                    case 12:
                        HaltReason[offset] = 'C';
                        break;

                    case 13:
                        HaltReason[offset] = 'D';
                        break;

                    case 14:
                        HaltReason[offset] = 'E';
                        break;

                    case 15:
                        HaltReason[offset] = 'F';
                        break;
                    }
                    y >>= 4;
                    offset--;
                }

                #endregion

                y      = eip;
                offset = 80;
                #region EIP

                while (offset > 72)
                {
                    uint rem = y & 0xFu;
                    switch (rem)
                    {
                    case 0:
                        HaltReason[offset] = '0';
                        break;

                    case 1:
                        HaltReason[offset] = '1';
                        break;

                    case 2:
                        HaltReason[offset] = '2';
                        break;

                    case 3:
                        HaltReason[offset] = '3';
                        break;

                    case 4:
                        HaltReason[offset] = '4';
                        break;

                    case 5:
                        HaltReason[offset] = '5';
                        break;

                    case 6:
                        HaltReason[offset] = '6';
                        break;

                    case 7:
                        HaltReason[offset] = '7';
                        break;

                    case 8:
                        HaltReason[offset] = '8';
                        break;

                    case 9:
                        HaltReason[offset] = '9';
                        break;

                    case 10:
                        HaltReason[offset] = 'A';
                        break;

                    case 11:
                        HaltReason[offset] = 'B';
                        break;

                    case 12:
                        HaltReason[offset] = 'C';
                        break;

                    case 13:
                        HaltReason[offset] = 'D';
                        break;

                    case 14:
                        HaltReason[offset] = 'E';
                        break;

                    case 15:
                        HaltReason[offset] = 'F';
                        break;
                    }
                    y >>= 4;
                    offset--;
                }

                #endregion

                BasicConsole.WriteLine(HaltReason);
                BasicConsole.SetTextColour(BasicConsole.default_colour);

                Throw(new FOS_System.Exceptions.PageFaultException(errorCode, address));
            }
        }
Beispiel #32
0
 /// <summary>
 /// Throws an invalid op code exception.
 /// </summary>
 /// <remarks>
 /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
 /// </remarks>
 public static void Throw_InvalidOpCodeException()
 {
     HaltReason = "Invalid op code exception.";
     BasicConsole.SetTextColour(BasicConsole.error_colour);
     BasicConsole.WriteLine(HaltReason);
     BasicConsole.SetTextColour(BasicConsole.default_colour);
     Throw(new FOS_System.Exceptions.InvalidOpCodeException());
 }
Beispiel #33
0
 /// <summary>
 /// Throws an overflow exception.
 /// </summary>
 /// <remarks>
 /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
 /// </remarks>
 public static void Throw_OverflowException()
 {
     HaltReason = "Overflow exception.";
     BasicConsole.SetTextColour(BasicConsole.error_colour);
     BasicConsole.WriteLine(HaltReason);
     BasicConsole.SetTextColour(BasicConsole.default_colour);
     Throw(new FOS_System.Exceptions.OverflowException("Processor reported an overflow."));
 }
Beispiel #34
0
 /// <summary>
 /// Throws a stack exception.
 /// </summary>
 /// <remarks>
 /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
 /// </remarks>
 public static void Throw_StackException()
 {
     HaltReason = "Stack exception.";
     BasicConsole.SetTextColour(BasicConsole.error_colour);
     BasicConsole.WriteLine(HaltReason);
     BasicConsole.SetTextColour(BasicConsole.default_colour);
     Throw(new FOS_System.Exceptions.StackException());
 }
Beispiel #35
0
        public static void Throw_NullReferenceException(uint address)
        {
            HaltReason = "Null reference exception. Instruction: 0x        ";
            FillString(address, 48, HaltReason);
            
            bool BCPOEnabled = BasicConsole.PrimaryOutputEnabled;
            BasicConsole.PrimaryOutputEnabled = true;
            BasicConsole.WriteLine(HaltReason);
            BasicConsole.DelayOutput(10);
            BasicConsole.PrimaryOutputEnabled = BCPOEnabled;

            FOS_System.Exception ex = new FOS_System.Exceptions.NullReferenceException();
            ex.InstructionAddress = address;
            Throw(ex);
        }
Beispiel #36
0
        /// <summary>
        /// Writes the specified number as an signed decimal string.
        /// </summary>
        /// <param name="num">The number to write as a decimal.</param>
        public virtual void Write_AsDecimal(Int32 num)
        {
            //This functions exactly the same as its unsigned
            //  counterpart but it adds a minus sign if the number
            //  is negative.
            FOS_System.String result = "";
            if (num != 0)
            {
                bool neg = num < 0;
                if (neg)
                {
                    num = -num;
                }

                while (num > 0)
                {
                    int rem = num % 10;
                    switch (rem)
                    {
                    case 0:
                        result = "0" + result;
                        break;

                    case 1:
                        result = "1" + result;
                        break;

                    case 2:
                        result = "2" + result;
                        break;

                    case 3:
                        result = "3" + result;
                        break;

                    case 4:
                        result = "4" + result;
                        break;

                    case 5:
                        result = "5" + result;
                        break;

                    case 6:
                        result = "6" + result;
                        break;

                    case 7:
                        result = "7" + result;
                        break;

                    case 8:
                        result = "8" + result;
                        break;

                    case 9:
                        result = "9" + result;
                        break;
                    }
                    num /= 10;
                }

                if (neg)
                {
                    result = "-" + result;
                }
            }
            else
            {
                result = "0";
            }
            Write(result);
        }
Beispiel #37
0
 //[Drivers.Compiler.Attributes.ThrowArrayTypeMismatchExceptionMethod]
 public static void Throw_ArrayTypeMismatchException()
 {
     HaltReason = "Array type mismatch exception.";
     Throw(new FOS_System.Exceptions.ArrayTypeMismatchException());
 }
Beispiel #38
0
 public static void Throw_IndexOutOfRangeException()
 {
     HaltReason = "Index out of range exception.";
     FOS_System.Exception ex = new FOS_System.Exceptions.IndexOutOfRangeException(0, 0);
     ex.InstructionAddress = *((uint*)BasePointer + 1);
     Throw(ex);
 }
Beispiel #39
0
        public static void FillString(uint value, int offset, FOS_System.String str)
        {
            int end = offset - 8;

            while (offset > end)
            {
                uint rem = value & 0xFu;
                switch (rem)
                {
                case 0:
                    str[offset] = '0';
                    break;

                case 1:
                    str[offset] = '1';
                    break;

                case 2:
                    str[offset] = '2';
                    break;

                case 3:
                    str[offset] = '3';
                    break;

                case 4:
                    str[offset] = '4';
                    break;

                case 5:
                    str[offset] = '5';
                    break;

                case 6:
                    str[offset] = '6';
                    break;

                case 7:
                    str[offset] = '7';
                    break;

                case 8:
                    str[offset] = '8';
                    break;

                case 9:
                    str[offset] = '9';
                    break;

                case 10:
                    str[offset] = 'A';
                    break;

                case 11:
                    str[offset] = 'B';
                    break;

                case 12:
                    str[offset] = 'C';
                    break;

                case 13:
                    str[offset] = 'D';
                    break;

                case 14:
                    str[offset] = 'E';
                    break;

                case 15:
                    str[offset] = 'F';
                    break;
                }
                value >>= 4;
                offset--;
            }
        }
Beispiel #40
0
 private static void BasicConsole_SecondaryOutput(FOS_System.String str)
 {
     Hardware.IO.Serial.Serial.COM1.Write(str);
 }
Beispiel #41
0
        /// <summary>
        /// Throws a double fault exception.
        /// </summary>
        /// <remarks>
        /// Used by CPU interrupts to handle the creation of the exception object and calling Throw.
        /// </remarks>
        public static void Throw_DoubleFaultException(uint address, uint errorCode)
        {
            HaltReason = "Double fault exception. Address: 0x         Error code: 0x        ";

            uint y      = address;
            int  offset = 42;

            #region Address
            while (offset > 34)
            {
                uint rem = y & 0xFu;
                switch (rem)
                {
                case 0:
                    HaltReason[offset] = '0';
                    break;

                case 1:
                    HaltReason[offset] = '1';
                    break;

                case 2:
                    HaltReason[offset] = '2';
                    break;

                case 3:
                    HaltReason[offset] = '3';
                    break;

                case 4:
                    HaltReason[offset] = '4';
                    break;

                case 5:
                    HaltReason[offset] = '5';
                    break;

                case 6:
                    HaltReason[offset] = '6';
                    break;

                case 7:
                    HaltReason[offset] = '7';
                    break;

                case 8:
                    HaltReason[offset] = '8';
                    break;

                case 9:
                    HaltReason[offset] = '9';
                    break;

                case 10:
                    HaltReason[offset] = 'A';
                    break;

                case 11:
                    HaltReason[offset] = 'B';
                    break;

                case 12:
                    HaltReason[offset] = 'C';
                    break;

                case 13:
                    HaltReason[offset] = 'D';
                    break;

                case 14:
                    HaltReason[offset] = 'E';
                    break;

                case 15:
                    HaltReason[offset] = 'F';
                    break;
                }
                y >>= 4;
                offset--;
            }

            #endregion

            y      = errorCode;
            offset = 65;
            #region Error Code
            while (offset > 57)
            {
                uint rem = y & 0xFu;
                switch (rem)
                {
                case 0:
                    HaltReason[offset] = '0';
                    break;

                case 1:
                    HaltReason[offset] = '1';
                    break;

                case 2:
                    HaltReason[offset] = '2';
                    break;

                case 3:
                    HaltReason[offset] = '3';
                    break;

                case 4:
                    HaltReason[offset] = '4';
                    break;

                case 5:
                    HaltReason[offset] = '5';
                    break;

                case 6:
                    HaltReason[offset] = '6';
                    break;

                case 7:
                    HaltReason[offset] = '7';
                    break;

                case 8:
                    HaltReason[offset] = '8';
                    break;

                case 9:
                    HaltReason[offset] = '9';
                    break;

                case 10:
                    HaltReason[offset] = 'A';
                    break;

                case 11:
                    HaltReason[offset] = 'B';
                    break;

                case 12:
                    HaltReason[offset] = 'C';
                    break;

                case 13:
                    HaltReason[offset] = 'D';
                    break;

                case 14:
                    HaltReason[offset] = 'E';
                    break;

                case 15:
                    HaltReason[offset] = 'F';
                    break;
                }
                y >>= 4;
                offset--;
            }

            #endregion

            BasicConsole.SetTextColour(BasicConsole.error_colour);
            BasicConsole.WriteLine(HaltReason);
            BasicConsole.SetTextColour(BasicConsole.default_colour);
            Throw(new FOS_System.Exceptions.DoubleFaultException(errorCode));
        }