Exemplo n.º 1
0
 public static void Write(FlingOops.String str)
 {
     for (int i = 0; i < str.length; i++)
     {
         Write(str[i]);
     }
 }
Exemplo n.º 2
0
        public FlingOops.String PadLeft(int totalLength, char padChar)
        {
            FlingOops.String result = New(totalLength);

            if (this.length >= totalLength)
            {
                for (int i = 0; i < result.length; i++)
                {
                    result[i] = this[i];
                }
                return(result);
            }

            int offset = totalLength - this.length;

            for (int i = 0; i < this.length; i++)
            {
                result[i + offset] = this[i];
            }
            for (int i = 0; i < offset; i++)
            {
                result[i] = padChar;
            }
            return(result);
        }
Exemplo n.º 3
0
        public static unsafe void Throw(FlingOops.Exception ex)
        {
            FlingOops.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 = (FlingOops.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 *)0xDEADBEEF) = 0;
        }
Exemplo n.º 4
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.

            FlingOops.String str = "1234567890!\"£$%^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM[];'#,./{}:@~<>?\\|`¬¦";
#if MIPS
            UART.Write(str);
#elif x86
            int   strLength = str.length;
            char *strPtr    = str.GetCharPointer();
            char *vidMemPtr = vidMemBasePtr;
            while (strLength > 0)
            {
                vidMemPtr[0] = (char)((*strPtr & 0x00FF) | colour);

                strPtr++;
                vidMemPtr++;
                strLength--;
            }
#endif
        }
Exemplo n.º 5
0
 public static void Throw_IndexOutOfRangeException()
 {
     HaltReason = "Index out of range exception.";
     BasicConsole.WriteLine(HaltReason);
     //FlingOops.Exception ex = new FlingOops.Exceptions.IndexOutOfRangeException(0, 0);
     //ex.InstructionAddress = *((uint*)BasePointer + 1);
     //Throw(ex);
 }
Exemplo n.º 6
0
        public static void Disable(FlingOops.String caller)
        {
            //BasicConsole.Write(caller);
            //BasicConsole.WriteLine(" disabling GC.");
            //BasicConsole.DelayOutput(2);

            GC.Enabled = false;
        }
Exemplo n.º 7
0
        public static void Throw_NullReferenceException(uint address)
        {
            HaltReason = "Null reference exception. Instruction: 0x        ";
            FillString(address, 48, HaltReason);
            BasicConsole.WriteLine(HaltReason);

            //FlingOops.Exception ex = new FlingOops.Exceptions.NullReferenceException();
            //ex.InstructionAddress = address;
            //Throw(ex);
        }
Exemplo n.º 8
0
        public static void WriteError(FlingOops.String message)
        {
            SetTextColour(error_colour);
            WriteLine(message);
            SetTextColour(default_colour);

#if x86
            DelayOutput(20);
#endif
        }
Exemplo n.º 9
0
        public static void *AllocZeroed(UInt32 size, UInt32 boundary, FlingOops.String caller)
        {
            void *result = Alloc(size, boundary, caller);

            if (result == null)
            {
                return(null);
            }
            return(Utilities.MemoryUtils.ZeroMem(result, size));
        }
Exemplo n.º 10
0
        public static unsafe void HandleEndFinally()
        {
            if (State == null ||
                State->CurrentHandlerPtr == null)
            {
                // If we get to here, it's an unhandled exception
                HaltReason = "Cannot end finally on null handler!";
                BasicConsole.WriteLine(HaltReason);
                BasicConsole.DelayOutput(5);

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

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

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

                //BasicConsole.WriteLine("End finally with ex");

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

                //BasicConsole.WriteLine("End finally without ex");

                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;

                ArbitaryReturn(EBP,
                               ESP + (uint)sizeof(ExceptionHandlerInfo),
                               retAddr);
            }
        }
Exemplo n.º 11
0
        public static unsafe FlingOops.String Concat(FlingOops.String str1, FlingOops.String str2)
        {
            FlingOops.String newStr = New(str1.length + str2.length);

            for (int i = 0; i < str1.length; i++)
            {
                newStr[i] = str1[i];
            }
            for (int i = 0; i < str2.length; i++)
            {
                newStr[i + str1.length] = str2[i];
            }
            return(newStr);
        }
Exemplo n.º 12
0
 public static unsafe FlingOops.String New(int length)
 {
     if (length < 0)
     {
         BasicConsole.WriteLine("ArgumentException! String.New, length less than zero.");
         ExceptionMethods.Throw(new Exception("Parameter \"length\" cannot be less than 0 in FlingOops.String.New(int length)."));
     }
     FlingOops.String result = (FlingOops.String)Utilities.ObjectUtilities.GetObject(GC.NewString(length));
     if (result == null)
     {
         BasicConsole.WriteLine("NullReferenceException! String.New, result is null.");
         ExceptionMethods.Throw(new Exception());
     }
     return(result);
 }
Exemplo n.º 13
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;
                    }
                }

                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 *)0xDEADBEEF) = 0;
        }
Exemplo n.º 14
0
        public static void *AllocZeroedAPB(UInt32 size, UInt32 boundary, FlingOops.String caller)
        {
            void * result   = null;
            void * oldValue = null;
            UInt32 resultAddr;

            do
            {
                oldValue   = result;
                result     = AllocZeroed(size, boundary, caller);
                resultAddr = (UInt32)result;
                if (oldValue != null)
                {
                    Free(oldValue);
                }
            }while (resultAddr / 0x1000 != (resultAddr + size - 1) / 0x1000);

            return(result);
        }
Exemplo n.º 15
0
 public static void *AllocZeroed(UInt32 size, FlingOops.String caller)
 {
     return(AllocZeroed(size, 1, caller));
 }
Exemplo n.º 16
0
        /// <summary>
        /// Tests: Array declaration using strings as elements, 
        /// Input: An array with four elements, 
        /// Result: Correct values for each element.
        /// </summary>
        /// <remarks>
        /// <para>
        /// FlingOS does allow array declaration of the form: 
        /// int[] array = new int[4] {5, 10, 15, 20} or 
        /// int[] array = new int[] {5, 10, 15, 20}. 
        /// Array elements must be explicitly declared as in this test case. 
        /// To declare an array of strings, we need to use the FlingOS built-in string type, NOT just string because that is part of .NET.
        /// </para>
        /// </remarks>
        public static void Test_Array_String()
        {
            FlingOops.String[] array = new FlingOops.String[4];
            array[0] = "elementZero";
            array[1] = "elementOne";
            array[2] = "elementTwo";
            array[3] = "elementThree";
            Int32 a = array.Length;
            if (a == 4)
            {
                Log.WriteSuccess("Test_Array_Length_String okay.");
            }
            else
            {
                Log.WriteError("Test_Array_Length_String NOT okay.");
            }
            if (array[0] == "elementZero")
            {
                Log.WriteSuccess("Test_Array_Decl_String[0] okay.");
            }
            else
            {
                Log.WriteError("Test_Array_Decl_String[0] Not okay.");
            }

            if (array[1] == "elementOne")
            {
                Log.WriteSuccess("Test_Array_Decl_String[1] okay.");
            }
            else
            {
                Log.WriteError("Test_Array_Decl_String[1] Not okay");
            }

            if (array[2] == "elementTwo")
            {
                Log.WriteSuccess("Test_Array_Decl_String[2] okay.");
            }
            else
            {
                Log.WriteError("Test_Array_Decl_String[2] Not okay");
            }

            if (array[3] == "elementThree")
            {
                Log.WriteSuccess("Test_Array_Decl_String[3] okay.");
            }
            else
            {
                Log.WriteError("Test_Array_Decl_String[3] Not okay");
            }
        }
Exemplo n.º 17
0
        public static unsafe void WriteLine(FlingOops.String str)
        {
            if (!Initialised)
            {
                return;
            }
            if (str == null)
            {
                return;
            }
#if MIPS
            //This outputs the string
            Write(str);
            Write("\n");
#elif x86
            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");
            }
#endif
        }
Exemplo n.º 18
0
        public static void *NewString(int length)
        {
            if (!Enabled)
            {
                BasicConsole.SetTextColour(BasicConsole.warning_colour);
                BasicConsole.WriteLine("Warning! GC returning null pointer because GC not enabled.");
                BasicConsole.DelayOutput(10);
                BasicConsole.SetTextColour(BasicConsole.default_colour);

                return(null);
            }

            //try
            {
                if (length < 0)
                {
                    BasicConsole.SetTextColour(BasicConsole.error_colour);
                    BasicConsole.WriteLine("Error! GC can't create a new string because \"length\" is less than 0.");
                    BasicConsole.DelayOutput(5);
                    BasicConsole.SetTextColour(BasicConsole.default_colour);

                    return(null);
                    //ExceptionMethods.Throw_OverflowException();
                }

                InsideGC = true;

                //Alloc space for GC header that prefixes object data
                //Alloc space for new string object
                //Alloc space for new string chars

                uint totalSize = ((FlingOops.Type) typeof(FlingOops.String)).Size;
                totalSize += /*char size in bytes*/ 2 * (uint)length;
                totalSize += (uint)sizeof(GCHeader);

                GCHeader *newObjPtr = (GCHeader *)Heap.AllocZeroed(totalSize, "GC : NewString");

                if ((UInt32)newObjPtr == 0)
                {
                    InsideGC = false;

                    BasicConsole.SetTextColour(BasicConsole.error_colour);
                    BasicConsole.WriteLine("Error! GC can't create a new string because the heap returned a null pointer.");
                    BasicConsole.DelayOutput(10);
                    BasicConsole.SetTextColour(BasicConsole.default_colour);

                    return(null);
                }

                NumObjs++;
                NumStrings++;

                //Initialise the GCHeader
                SetSignature(newObjPtr);
                //RefCount to 0 initially because of FlingOops.String.New should be used
                //      - In theory, New should be called, creates new string and passes it back to caller
                //        Caller is then required to store the string in a variable resulting in inc.
                //        ref count so ref count = 1 in only stored location.
                //        Caller is not allowed to just "discard" (i.e. use Pop IL op or C# that generates
                //        Pop IL op) so ref count will always at some point be incremented and later
                //        decremented by managed code. OR the variable will stay in a static var until
                //        the OS exits...

                newObjPtr->RefCount = 0;

                FlingOops.String newStr = (FlingOops.String)Utilities.ObjectUtilities.GetObject(newObjPtr + 1);
                newStr._Type  = (FlingOops.Type) typeof(FlingOops.String);
                newStr.length = length;

                //Move past GCHeader
                byte *newObjBytePtr = (byte *)(newObjPtr + 1);

                InsideGC = false;

                return(newObjBytePtr);
            }
            //finally
            {
                //ExitCritical();
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// Creates a new exception with specified message.
 /// </summary>
 /// <param name="aMessage">The exception message.</param>
 public Exception(FlingOops.String aMessage)
     : base()
 {
     Message = aMessage;
 }
Exemplo n.º 20
0
 public static void Throw_IndexOutOfRangeException()
 {
     HaltReason = "Index out of range exception.";
     BasicConsole.WriteLine(HaltReason);
     //FlingOops.Exception ex = new FlingOops.Exceptions.IndexOutOfRangeException(0, 0);
     //ex.InstructionAddress = *((uint*)BasePointer + 1);
     //Throw(ex);
 }
Exemplo n.º 21
0
        public static unsafe void HandleEndFinally()
        {
            if (State == null ||
                State->CurrentHandlerPtr == null)
            {
                // If we get to here, it's an unhandled exception
                HaltReason = "Cannot end finally on null handler!";
                BasicConsole.WriteLine(HaltReason);
                BasicConsole.DelayOutput(5);

                // Try to cause fault
                *((byte*)0xDEADBEEF) = 0;
            }
            
            // Leaving a "finally" critical section cleanly
            // We need to handle 2 cases:
            // Case 1 : Pending exception
            // Case 2 : No pending exception

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

                //BasicConsole.WriteLine("End finally with ex");

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

                //BasicConsole.WriteLine("End finally without ex");

                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;

                ArbitaryReturn(EBP,
                    ESP + (uint)sizeof(ExceptionHandlerInfo),
                    retAddr);
            }
        }
Exemplo n.º 22
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 = "Cannot leave on null handler! Address: 0x        ";

                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);
                BasicConsole.DelayOutput(5);

                // Try to cause fault
                *((byte*)0xDEADBEEF) = 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

                if (State->CurrentHandlerPtr->Ex != null)
                {
                    FlingOops.GC.DecrementRefCount((FlingOops.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;

                //BasicConsole.WriteLine("Leave try or catch of try-catch");
                //BasicConsole.WriteLine((uint)continuePtr);

                State->CurrentHandlerPtr = State->CurrentHandlerPtr->PrevHandlerPtr;

                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);
            }
        }
Exemplo n.º 23
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;
                    }
                }

                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*)0xDEADBEEF) = 0;
        }
Exemplo n.º 24
0
        public static unsafe void Write(FlingOops.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 MIPS
            UART.Write(str);
#elif x86
            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);
            }
#endif
        }
Exemplo n.º 25
0
        public static void *Alloc(UInt32 size, UInt32 boundary, FlingOops.String caller)
        {
#if HEAP_TRACE
            BasicConsole.SetTextColour(BasicConsole.warning_colour);
            BasicConsole.WriteLine("Attempt to alloc mem....");
            BasicConsole.SetTextColour(BasicConsole.default_colour);
#endif
            HeapBlock *b;
            byte *     bm;
            UInt32     bcnt;
            UInt32     x, y, z;
            UInt32     bneed;
            byte       nid;

#if MIPS
            if (boundary < 4)
            {
                boundary = 4;
            }
#endif

            if (boundary > 1)
            {
                size += (boundary - 1);
            }

            /* iterate blocks */
            for (b = fblock; (UInt32)b != 0; b = b->next)
            {
                /* check if block has enough room */
                if (b->size - (b->used * b->bsize) >= size)
                {
                    bcnt  = b->size / b->bsize;
                    bneed = (size / b->bsize) * b->bsize < size ? size / b->bsize + 1 : size / b->bsize;
                    bm    = (byte *)&b[1];

                    for (x = (b->lfb + 1 >= bcnt ? 0 : b->lfb + 1); x != b->lfb; ++x)
                    {
                        /* just wrap around */
                        if (x >= bcnt)
                        {
                            x = 0;
                        }

                        if (bm[x] == 0)
                        {
                            /* count free blocks */
                            for (y = 0; bm[x + y] == 0 && y < bneed && (x + y) < bcnt; ++y)
                            {
                                ;
                            }

                            /* we have enough, now allocate them */
                            if (y == bneed)
                            {
                                /* find ID that does not match left or right */
                                nid = GetNID(bm[x - 1], bm[x + y]);

                                /* allocate by setting id */
                                for (z = 0; z < y; ++z)
                                {
                                    bm[x + z] = nid;
                                }

                                /* optimization */
                                b->lfb = (x + bneed) - 2;

                                /* count used blocks NOT bytes */
                                b->used += y;

                                void *result = (void *)(x * b->bsize + (UInt32)(&b[1]));
                                if (boundary > 1)
                                {
                                    result = (void *)((((UInt32)result) + (boundary - 1)) & ~(boundary - 1));

#if HEAP_TRACE
                                    ExitCritical();
                                    BasicConsole.WriteLine(((FlingOops.String) "Allocated address ") + (uint)result + " on boundary " + boundary + " for " + caller);
                                    EnterCritical("Alloc:Boundary condition");
#endif
                                }

                                return(result);
                            }

                            /* x will be incremented by one ONCE more in our FOR loop */
                            x += (y - 1);
                            continue;
                        }
                    }
                }
            }

#if HEAP_TRACE
            BasicConsole.SetTextColour(BasicConsole.error_colour);
            BasicConsole.WriteLine("!!Heap out of memory!!");
            BasicConsole.SetTextColour(BasicConsole.default_colour);
            BasicConsole.DelayOutput(2);
#endif

            return(null);
        }
Exemplo n.º 26
0
 public static void WriteSuccess(FlingOops.String message)
 {
     SetTextColour(success_colour);
     WriteLine(message);
     SetTextColour(default_colour);
 }
Exemplo n.º 27
0
        public static void FillString(uint value, int offset, FlingOops.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--;
            }
        }
Exemplo n.º 28
0
 public static void Throw_NullReferenceException(uint address)
 {
     HaltReason = "Null reference exception. Instruction: 0x        ";
     FillString(address, 48, HaltReason);
     BasicConsole.WriteLine(HaltReason);
     
     //FlingOops.Exception ex = new FlingOops.Exceptions.NullReferenceException();
     //ex.InstructionAddress = address;
     //Throw(ex);
 }
Exemplo n.º 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 = "Cannot leave on null handler! Address: 0x        ";

                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);
                BasicConsole.DelayOutput(5);

                // Try to cause fault
                *((byte *)0xDEADBEEF) = 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

                if (State->CurrentHandlerPtr->Ex != null)
                {
                    FlingOops.GC.DecrementRefCount((FlingOops.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;

                //BasicConsole.WriteLine("Leave try or catch of try-catch");
                //BasicConsole.WriteLine((uint)continuePtr);

                State->CurrentHandlerPtr = State->CurrentHandlerPtr->PrevHandlerPtr;

                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);
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// Creates a new exception with specified message.
 /// </summary>
 /// <param name="aMessage">The exception message.</param>
 public Exception(FlingOops.String aMessage)
     : base()
 {
     Message = aMessage;
 }
Exemplo n.º 31
0
        public static unsafe void Throw(FlingOops.Exception ex)
        {
            FlingOops.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 = (FlingOops.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*)0xDEADBEEF) = 0;
        }