/// <summary> /// Dump multiboot info. /// </summary> public void Dump(uint row, uint col) { Screen.Row = row; Screen.Column = col; Screen.Color = 0x0A; Screen.Write('C'); Screen.Write('M'); Screen.Write('O'); Screen.Write('S'); Screen.Write(':'); Screen.NextLine(); for (byte i = 0; i < 19; i++) { Screen.Column = col; Screen.Color = 0x0F; Screen.Write(i, 16, 2); Screen.Write(':'); Screen.Write(' '); Screen.Write(Get(i), 16, 2); Screen.Write(' '); Screen.Color = 0x07; Screen.Write(Get(i), 10, 3); Screen.NextLine(); } }
/// <summary> /// Dumps multiboot info. /// </summary> public static void Dump(uint row, uint col) { uint location = MultibootStructure; Screen.Row = row; Screen.Column = col; Screen.Color = 0x0A; Screen.Write('M'); Screen.Write('e'); Screen.Write('m'); Screen.Write('o'); Screen.Write('r'); Screen.Write('y'); Screen.Write('d'); Screen.Write('u'); Screen.Write('m'); Screen.Write('p'); Screen.NextLine(); Screen.NextLine(); for (uint i = 0; i < 80; i = i + 8) { Screen.Column = col; Screen.Color = 0x0F; Screen.Write(i, 10, 2); Screen.Write(':'); Screen.Write(' '); Screen.Color = 0x07; Screen.Write(Native.Get32(location + i), 16, 16); Screen.NextLine(); } }
public static void DumpRegisters() { Screen.Write("EIP: "); Screen.Write(EIP, 16, 8); Screen.Write(" ESP: "); Screen.Write(ESP, 16, 8); Screen.Write(" EBP: "); Screen.Write(EBP, 16, 8); Screen.Write(" EFLAGS: "); Screen.Write(EFLAGS, 16, 8); Screen.Write(" CR2: "); Screen.Write(CR2, 16, 8); Screen.NextLine(); Screen.Write("EAX: "); Screen.Write(EAX, 16, 8); Screen.Write(" EBX: "); Screen.Write(EBX, 16, 8); Screen.Write(" ECX: "); Screen.Write(ECX, 16, 8); Screen.Write(" CS: "); Screen.Write(CS, 16, 8); Screen.NextLine(); Screen.Write("EDX: "); Screen.Write(EDX, 16, 8); Screen.Write(" EDI: "); Screen.Write(EDI, 16, 8); Screen.Write(" EDX: "); Screen.Write(EDX, 16, 8); Screen.Write(" ERROR: "); Screen.Write(ErrorCode, 16, 2); Screen.Write(" IRQ: "); Screen.Write(Interrupt, 16, 2); Screen.NextLine(); }
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); }
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); }
/// <summary> /// Dumps this instance. /// </summary> public static void Dump2(uint row, uint col) { uint location = MemoryMapStart; Screen.Row = row; for (uint i = 0; i < 80; i = i + 4) { Screen.Column = col; Screen.Write(i, 10, 2); Screen.Write(':'); Screen.Write(' '); Screen.Write(Native.Get32(location + i), 16, 8); Screen.NextLine(); } }
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(); } }
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; } }
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); }
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); }
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); }
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); }
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); } } }
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; } }