Goto() public static method

Goto the specified row and column.
public static Goto ( uint row, uint col ) : void
row uint The row.
col uint The col.
return void
Exemplo n.º 1
0
        private static void CompressedWriteMemory()
        {
            uint id      = GetID();
            uint address = GetDataUInt32(0);
            uint length  = GetDataUInt32(4);
            uint size    = GetDataUInt32(8);

            //uint uncompresscrc = GetDataUInt32(12);

            LZF.Decompress(new IntPtr(Address.DebuggerBuffer + HeaderSize), length, new IntPtr(address), size);

            Screen.Goto(15, 0);
            Screen.ClearRow();
            Screen.Write("[CompressedWriteMemory]");
            Screen.NextLine();
            Screen.ClearRow();
            Screen.Write("ID: ");
            Screen.Write(id, 10, 5);
            Screen.Write(" Address: ");
            Screen.Write(address, 16, 8);
            Screen.Write(" Len: ");
            Screen.Write(length, 10, 5);
            Screen.Write(" Size: ");
            Screen.Write(size, 10, 5);
            Screen.Write(" CRC: ");

            //Screen.Write(uncompresscrc, 16, 8);

            //if (uncompresscrc == computedcrc)
            //	Screen.Write(" OK");
            //else
            //	Screen.Write(" BAD");

            SendResponse(id, DebugCode.CompressedWriteMemory);
        }
Exemplo n.º 2
0
 private static void Halt()
 {
     Screen.Goto(Screen.Rows - 1, 0);
     while (true)
     {
         Native.Hlt();
     }
 }
Exemplo n.º 3
0
        public static void ProcessQueue()
        {
            if (queueNext == queueCurrent)
            {
                return;
            }

            if (!UnitTestRunner.IsReady())
            {
                return;
            }

            uint marker = Native.Get32(queueCurrent);

            if (marker == uint.MaxValue)
            {
                queueCurrent = Address.UnitTestQueue;
            }

            uint len      = Native.Get32(queueCurrent);
            uint id       = Native.Get32(queueCurrent + 4);
            uint address  = Native.Get32(queueCurrent + 8);
            uint type     = Native.Get32(queueCurrent + 12);
            uint paramcnt = Native.Get32(queueCurrent + 16);

            UnitTestRunner.SetUnitTestMethodAddress(address);
            UnitTestRunner.SetUnitTestResultType(type);
            UnitTestRunner.SetUnitTestMethodParameterCount(paramcnt);

            for (uint index = 0; index < paramcnt; index++)
            {
                uint value = Native.Get32(queueCurrent + 20 + (index * 4));
                UnitTestRunner.SetUnitTestMethodParameter(index, value);
            }

            queueCurrent = queueCurrent + len + 4;
            --count;

            Screen.Goto(17, 0);
            Screen.ClearRow();
            Screen.Write("[Unit Test]");
            Screen.NextLine();
            Screen.ClearRow();
            Screen.Write("ID: ");
            Screen.Write(id, 10, 5);
            Screen.Write(" Address: ");
            Screen.Write(address, 16, 8);
            Screen.Write(" Param: ");
            Screen.Write(paramcnt, 10, 2);
            Screen.Write(" Len: ");
            Screen.Write(len, 10, 4);
            Screen.Write(" - Cnt: ");
            Screen.Write(count, 10, 4);

            UnitTestRunner.StartTest(id);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Interrupts the handler.
        /// </summary>
        /// <param name="stackStatePointer">The stack state pointer.</param>
        private unsafe static void ProcessInterrupt(uint stackStatePointer)
        {
            //KernelMessage.WriteLine("Interrupt occured");

            var stack = (IDTStack *)stackStatePointer;
            var irq   = stack->Interrupt;
            var info  = IDTManager.handlers[irq];

            IDTManager.RaisedCount++;

            if (info.CountStatistcs)
            {
                IDTManager.RaisedCountCustom++;
            }
            if (info.Trace)
            {
                KernelMessage.WriteLine("Interrupt: {0}", irq);
            }

            var col = Screen.column;
            var row = Screen.row;

            Screen.column = 0;
            Screen.Goto(2, 35);
            Screen.Write("Interrupts: ");
            Screen.Write(IDTManager.RaisedCount);
            Screen.Goto(3, 35);
            Screen.Write("IntNoClock: ");
            Screen.Write(IDTManager.RaisedCountCustom);
            Screen.row    = row;
            Screen.column = col;

            if (irq < 0 || irq > 255)
            {
                Panic.Error("Invalid Interrupt");
            }

            if (info.Handler == null)
            {
                //Panic.Error("Handlr is null");
            }
            else
            {
            }

            info.Handler(stack);

            PIC.SendEndOfInterrupt(irq);
        }
Exemplo n.º 5
0
        public static void Error(string message)
        {
            IDT.SetInterruptHandler(null);

            Screen.BackgroundColor = Color.Blue;

            Screen.Clear();
            Screen.Goto(1, 0);
            Screen.Color = Color.White;
            Screen.Write("*** Kernel Panic ***");

            if (firstError)
            {
                firstError = false;
            }
            else
            {
                Screen.Write(" (multiple)");
            }

            Screen.NextLine();
            Screen.NextLine();
            Screen.Write(message);
            Screen.NextLine();
            Screen.NextLine();
            Screen.Write("REGISTERS:");
            Screen.NextLine();
            Screen.NextLine();
            DumpRegisters();
            Screen.NextLine();
            Screen.Write("STACK TRACE:");
            Screen.NextLine();
            Screen.NextLine();
            DumpStackTrace();

            while (true)
            {
                // keep debugger running
                unsafe
                {
                    Debugger.Process(null);
                }

                //Native.Hlt();
            }
        }
Exemplo n.º 6
0
        private static void ProcessCommand()
        {
            // [0]![1]ID[5]CODE[6]LEN[10]DATA[LEN]

            int  code = GetCode();
            uint id   = GetID();
            uint len  = GetLength();

            Screen.Goto(13, 0);
            Screen.ClearRow();
            Screen.Write("[Data]");
            Screen.NextLine();
            Screen.ClearRow();
            Screen.Write("ID: ");
            Screen.Write(id, 10, 5);
            Screen.Write(" Code: ");
            Screen.Write((uint)code, 10, 4);
            Screen.Write(" Len: ");
            Screen.Write(len, 10, 5);

            switch (code)
            {
            case DebugCode.Ping: SendResponse(GetID(), DebugCode.Ping); return;

            case DebugCode.ReadMemory: ReadMemory(); return;

            case DebugCode.ReadCR3: SendResponse(GetID(), DebugCode.ReadCR3, (int)Native.GetCR3()); return;

            case DebugCode.Scattered32BitReadMemory: Scattered32BitReadMemory(); return;

            case DebugCode.WriteMemory: WriteMemory(); return;

            case DebugCode.CompressedWriteMemory: CompressedWriteMemory(); return;

            case DebugCode.ClearMemory: ClearMemory(); return;

            case DebugCode.HardJump: HardJump(); return;

            case DebugCode.ExecuteUnitTest: QueueUnitTest(); return;

            case DebugCode.GetMemoryCRC: GetMemoryCRC(); return;

            default: return;
            }
        }
Exemplo n.º 7
0
        private unsafe static void HardJump()
        {
            uint id      = GetID();
            uint address = GetUInt32(16);

            SendResponse(id, DebugCode.HardJump);

            idt_stack->EIP = address;

            Screen.Goto(15, 0);
            Screen.ClearRow();
            Screen.Write("[HardJump]");
            Screen.NextLine();
            Screen.ClearRow();
            Screen.Write("ID: ");
            Screen.Write((uint)id, 10, 5);
            Screen.Write(" Address: ");
            Screen.Write(address, 16, 8);
        }
Exemplo n.º 8
0
        private static void WriteMemory()
        {
            uint id      = GetID();
            uint address = GetUInt32(16);
            uint length  = GetUInt32(20);

            SendResponse(id, DebugCode.WriteMemory);

            uint at = 0;

            while (at + 4 < length)
            {
                uint value = GetUInt32(24 + at);

                Native.Set32(address + at, value);

                at = at + 4;
            }

            while (at < length)
            {
                byte value = GetByte(24 + at);

                Native.Set8(address + at, value);

                at = at + 1;
            }

            Screen.Goto(15, 0);
            Screen.ClearRow();
            Screen.Write("[WriteMemory]");
            Screen.NextLine();
            Screen.ClearRow();
            Screen.Write("ID: ");
            Screen.Write((uint)id, 10, 5);
            Screen.Write(" Address: ");
            Screen.Write(address, 16, 8);
            Screen.Write(" Len: ");
            Screen.Write(length, 10, 5);
        }
Exemplo n.º 9
0
        private static void WriteMemory()
        {
            uint id      = GetID();
            var  address = GetDataPointer(0);
            uint length  = GetDataUInt32(4);

            SendResponse(id, DebugCode.WriteMemory);

            uint at = 0;

            while (at + 4 < length)
            {
                uint value = GetDataUInt32(8 + at);

                Intrinsic.Store32(address, at, value);

                at += 4;
            }

            while (at < length)
            {
                byte value = GetDataByte(8 + at);

                Intrinsic.Store8(address, at, value);

                at++;
            }

            Screen.Goto(15, 0);
            Screen.ClearRow();
            Screen.Write("[WriteMemory]");
            Screen.NextLine();
            Screen.ClearRow();
            Screen.Write("ID: ");
            Screen.Write(id, 10, 5);
            Screen.Write(" Address: ");
            Screen.Write((uint)address.ToInt32(), 16, 8);
            Screen.Write(" Len: ");
            Screen.Write(length, 10, 5);
        }
Exemplo n.º 10
0
        private static void CompressedWriteMemory()
        {
            uint id            = GetID();
            uint address       = GetUInt32(16);
            uint length        = GetUInt32(20);
            uint size          = GetUInt32(24);
            uint uncompresscrc = GetUInt32(28);

            LZF.Decompress(Address.DebuggerBuffer + 32, length, address, size);

            uint computedcrc = ComputeMemoryCRC(address, size);

            Screen.Goto(15, 0);
            Screen.ClearRow();
            Screen.Write("[CompressedWriteMemory]");
            Screen.NextLine();
            Screen.ClearRow();
            Screen.Write("ID: ");
            Screen.Write((uint)id, 10, 5);
            Screen.Write(" Address: ");
            Screen.Write(address, 16, 8);
            Screen.Write(" Len: ");
            Screen.Write(length, 10, 5);
            Screen.Write(" Size: ");
            Screen.Write(size, 10, 5);
            Screen.Write(" CRC: ");
            Screen.Write(uncompresscrc, 16, 8);

            if (uncompresscrc == computedcrc)
            {
                Screen.Write(" OK");
            }
            else
            {
                Screen.Write(" BAD");
            }

            SendResponse(id, DebugCode.CompressedWriteMemory);
        }
Exemplo n.º 11
0
        private static void PrepareScreen(string title)
        {
            IDT.SetInterruptHandler(null);
            Screen.BackgroundColor = Colors.Black;
            Screen.Clear();
            Screen.Goto(1, 1);
            Screen.Color = Colors.LightGray;
            Screen.Write("*** ");
            Screen.Write(title);

            if (firstError)
            {
                firstError = false;
            }
            else
            {
                Screen.Write(" (multiple)");
            }

            Screen.Write(" ***");
            Screen.Goto(3, 1);
        }
Exemplo n.º 12
0
 public static void Setup()
 {
     SmbiosManager.Setup();
     Screen.Clear();
     Screen.Color = 0x0E;
     Screen.Goto(24, 0);
     Screen.Write('1');
     Multiboot.Setup();
     Screen.Goto(24, 1);
     Screen.Write('2');
     PIC.Setup();
     Screen.Goto(24, 2);
     Screen.Write('3');
     GDT.Setup();
     Screen.Goto(24, 3);
     Screen.Write('4');
     IDT.Setup();
     Screen.Goto(24, 4);
     Screen.Write('5');
     PageFrameAllocator.Setup();
     Screen.Goto(24, 5);
     Screen.Write('6');
     PageTable.Setup();
     Screen.Goto(24, 6);
     Screen.Write('7');
     VirtualPageAllocator.Setup();
     Screen.Goto(24, 7);
     Screen.Write('8');
     Screen.Goto(24, 8);
     ProcessManager.Setup();
     Screen.Write('9');
     Screen.Goto(24, 9);
     TaskManager.Setup();
     Screen.Write('A');
     Screen.Goto(24, 10);
     SmbiosManager.Setup();
 }
Exemplo n.º 13
0
        public static void EnterTestReadyLoop()
        {
            uint testCount = 0;

            Debugger.Ready();

            Screen.Write("Waiting for unit tests...");
            Screen.NextLine();
            Screen.NextLine();

            // allocate space on stack for parameters
            uint esp = Native.AllocateStackSpace(MaxParameters * 4);

            Screen.Write("Stack @ ");
            Screen.Write((uint)esp, 16, 8);

            Screen.NextLine();
            Screen.NextLine();

            uint row = Screen.Row;

            while (true)
            {
                if (testReady == 1)
                {
                    Screen.Goto(row, 0);
                    Screen.ClearRow();

                    Screen.Write("Test #: ");
                    Screen.Write(++testCount, 10, 7);

                    testResult         = 0;
                    testResultReady    = 0;
                    testResultReported = 0;
                    testReady          = 0;

                    // copy parameters into stack
                    for (uint index = 0; index < testParameters; index++)
                    {
                        uint value = new Pointer(Address.UnitTestStack).Load32(index * 4);

                        new Pointer(esp).Store32(index * 4, value);
                    }

                    switch (testResultType)
                    {
                    case 0: Native.FrameCall(testMethodAddress); break;

                    case 1: testResult = Native.FrameCallRetU4(testMethodAddress); break;

                    case 2: testResult = Native.FrameCallRetU8(testMethodAddress); break;

                    case 3: testResult = Native.FrameCallRetR8(testMethodAddress); break;

                    default: break;
                    }

                    testResultReady = 1;

                    Native.Int(255);
                }
            }
        }
Exemplo n.º 14
0
        private static void ProcessCommand()
        {
            // [0]MAGIC[4]ID[8]CODE[12]LEN[16]DATA[LEN]CHECKSUM

            int  code        = GetCode();
            uint id          = GetID();
            uint len         = GetLength();
            uint receivedCRC = GetCRC();

            uint computedCRC = ComputeCRC();

            Screen.Goto(13, 0);
            Screen.ClearRow();
            Screen.Write("[Data]");
            Screen.NextLine();
            Screen.ClearRow();
            Screen.Write("ID: ");
            Screen.Write((uint)id, 10, 5);
            Screen.Write(" Code: ");
            Screen.Write((uint)code, 10, 4);
            Screen.Write(" Len: ");
            Screen.Write(len, 10, 5);
            Screen.Write(" CRC: ");
            Screen.Write(receivedCRC, 16, 8);

            if (receivedCRC == computedCRC)
            {
                Screen.Write(" OK");
            }
            else
            {
                Screen.Write(" BAD");
            }

            // TODO: if crc is invalid

            switch (code)
            {
            case DebugCode.Ping: SendResponse(GetID(), DebugCode.Ping); return;

            case DebugCode.ReadMemory: ReadMemory(); return;

            case DebugCode.ReadCR3: SendResponse(GetID(), DebugCode.ReadCR3, (int)Native.GetCR3()); return;

            case DebugCode.Scattered32BitReadMemory: Scattered32BitReadMemory(); return;

            case DebugCode.WriteMemory: WriteMemory(); return;

            case DebugCode.CompressedWriteMemory: CompressedWriteMemory(); return;

            case DebugCode.ClearMemory: ClearMemory(); return;

            case DebugCode.HardJump: HardJump(); return;

            case DebugCode.ExecuteUnitTest: QueueUnitTest(); return;

            case DebugCode.GetMemoryCRC: GetMemoryCRC(); return;

            default: return;
            }
        }
Exemplo n.º 15
0
        private static bool ProcessSerial()
        {
            if (!Serial.IsDataReady(com))
            {
                return(false);
            }

            byte b = Serial.Read(com);

            bool bad = false;

            if (index == 0 && b != (byte)'M')
            {
                bad = true;
            }
            else if (index == 1 && b != (byte)'O')
            {
                bad = true;
            }
            else if (index == 2 && b != (byte)'S')
            {
                bad = true;
            }
            else if (index == 3 && b != (byte)'A')
            {
                bad = true;
            }

            if (bad)
            {
                BadDataAbort();
                return(true);
            }

            Native.Set8(Address.DebuggerBuffer + index, b);
            index++;

            uint length = 0;

            if (index >= 16)
            {
                length = GetLength();

                if (length > MaxBuffer || index > MaxBuffer)
                {
                    BadDataAbort();
                    return(true);
                }

                if (length + 20 == index)
                {
                    ProcessCommand();
                    ResetBuffer();
                }
            }

            Screen.Goto(24, 0);
            Screen.Write("INDEX: ");
            Screen.Write(index, 10, 5);
            Screen.Write(" LENGTH: ");
            Screen.Write((uint)length, 10, 5);

            unsafe
            {
                Screen.Write(" EIP: ");
                Screen.Write((uint)idt_stack->EIP, 16, 8);
            }

            return(true);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Interrupts the handler.
        /// </summary>
        /// <param name="stack">The stack.</param>
        private unsafe static void ProcessInterrupt(IDTStack *stack)
        {
            Debugger.Process(stack);

            switch (stack->Interrupt)
            {
            case 0:
                Error(stack, "Divide Error");
                break;

            case 4:
                Error(stack, "Arithmetic Overflow Exception");
                break;

            case 5:
                Error(stack, "Bound Check Error");
                break;

            case 6:
                Error(stack, "Invalid Opcode");
                break;

            case 7:
                Error(stack, "Co-processor Not Available");
                break;

            case 8:

                //TODO: Analyze the double fault
                Error(stack, "Double Fault");
                break;

            case 9:
                Error(stack, "Co-processor Segment Overrun");
                break;

            case 10:
                Error(stack, "Invalid TSS");
                break;

            case 11:
                Error(stack, "Segment Not Present");
                break;

            case 12:
                Error(stack, "Stack Exception");
                break;

            case 13:
                Error(stack, "General Protection Exception");
                break;

            case 14:

                // Check if Null Pointer Exception
                // Otherwise handle as Page Fault

                var cr2 = Native.GetCR2();

                if ((cr2 >> 5) < 0x1000)
                {
                    Error(stack, "Null Pointer Exception");
                }

                uint r = Screen.Row;
                uint c = Screen.Column;
                Screen.Goto(10, 0);
                Screen.Write(stack->EIP, 16, 8);
                Screen.Write(' ');
                Screen.Write(cr2, 16, 8);

                if (cr2 >= 0xF0000000u)
                {
                    Error(stack, "Invalid Access Above 0xF0000000");
                    break;
                }

                uint physicalpage = PageFrameAllocator.Allocate();

                Screen.Write(' ');
                Screen.Write(physicalpage, 16, 8);

                if (physicalpage == 0x0)
                {
                    Error(stack, "Out of Memory");
                    break;
                }

                PageTable.MapVirtualAddressToPhysical(cr2, physicalpage);

                uint pp = PageTable.GetPhysicalAddressFromVirtual(cr2);

                Screen.Write(' ');
                Screen.Write(pp, 16, 8);
                Screen.Goto(r, c);

                break;

            case 16:
                Error(stack, "Co-processor Error");
                break;

            case 19:
                Error(stack, "SIMD Floating-Point Exception");
                break;

            default:
                interruptHandler?.Invoke(stack->Interrupt, stack->ErrorCode);
                break;
            }

            PIC.SendEndOfInterrupt(stack->Interrupt);
        }