2009-05-02 23:03:37 +02:00
|
|
|
/*
|
2009-05-03 00:28:34 +02:00
|
|
|
* Copyright (C) 2002-2007 The DOSBox Team
|
2009-05-02 23:03:37 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-05-03 00:02:15 +02:00
|
|
|
* GNU General Public License for more details.
|
2009-05-02 23:03:37 +02:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
/* $Id: debug.cpp,v 1.85 2007/02/25 18:38:00 c2woody Exp $ */
|
|
|
|
|
|
|
|
#include "dosbox.h"
|
|
|
|
#if C_DEBUG
|
2009-05-02 23:03:37 +02:00
|
|
|
|
|
|
|
#include <string.h>
|
2009-05-02 23:12:18 +02:00
|
|
|
#include <list>
|
2009-05-03 00:18:08 +02:00
|
|
|
#include <ctype.h>
|
2009-05-03 00:28:34 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
using namespace std;
|
2009-05-02 23:03:37 +02:00
|
|
|
|
|
|
|
#include "debug.h"
|
2009-05-03 00:02:15 +02:00
|
|
|
#include "cross.h" //snprintf
|
2009-05-02 23:03:37 +02:00
|
|
|
#include "cpu.h"
|
|
|
|
#include "video.h"
|
|
|
|
#include "pic.h"
|
2009-05-03 00:02:15 +02:00
|
|
|
#include "mapper.h"
|
2009-05-02 23:03:37 +02:00
|
|
|
#include "cpu.h"
|
|
|
|
#include "callback.h"
|
|
|
|
#include "inout.h"
|
|
|
|
#include "mixer.h"
|
2009-05-02 23:20:05 +02:00
|
|
|
#include "timer.h"
|
2009-05-02 23:53:27 +02:00
|
|
|
#include "paging.h"
|
2009-05-03 00:02:15 +02:00
|
|
|
#include "support.h"
|
2009-05-02 23:53:27 +02:00
|
|
|
#include "shell.h"
|
2009-05-03 00:02:15 +02:00
|
|
|
#include "programs.h"
|
|
|
|
#include "debug_inc.h"
|
2009-05-03 00:18:08 +02:00
|
|
|
#include "../cpu/lazyflags.h"
|
|
|
|
#include "keyboard.h"
|
2009-05-02 23:03:37 +02:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
void WIN32_Console();
|
2009-05-02 23:35:44 +02:00
|
|
|
#else
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
static struct termios consolesettings;
|
|
|
|
int old_cursor_state;
|
2009-05-02 23:03:37 +02:00
|
|
|
#endif
|
2009-05-02 23:43:00 +02:00
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
// Forwards
|
|
|
|
static void DrawCode(void);
|
|
|
|
static void DEBUG_RaiseTimerIrq(void);
|
2009-05-03 00:18:08 +02:00
|
|
|
static void SaveMemory(Bitu seg, Bitu ofs1, Bit32u num);
|
|
|
|
static void SaveMemoryBin(Bitu seg, Bitu ofs1, Bit32u num);
|
2009-05-03 00:02:15 +02:00
|
|
|
static void LogGDT(void);
|
|
|
|
static void LogLDT(void);
|
|
|
|
static void LogIDT(void);
|
2009-05-03 00:18:08 +02:00
|
|
|
static void LogPages(char* selname);
|
|
|
|
static void LogCPUInfo(void);
|
2009-05-03 00:02:15 +02:00
|
|
|
static void OutputVecTable(char* filename);
|
|
|
|
static void DrawVariables(void);
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
char* AnalyzeInstruction(char* inst, bool saveSelector);
|
|
|
|
Bit32u GetHexValue(char* str, char*& hex);
|
2009-05-03 00:02:15 +02:00
|
|
|
|
2009-05-03 00:18:08 +02:00
|
|
|
class DebugPageHandler : public PageHandler {
|
|
|
|
public:
|
|
|
|
Bitu readb(PhysPt addr) {
|
|
|
|
}
|
|
|
|
Bitu readw(PhysPt addr) {
|
|
|
|
}
|
|
|
|
Bitu readd(PhysPt addr) {
|
|
|
|
}
|
|
|
|
void writeb(PhysPt addr,Bitu val) {
|
|
|
|
}
|
|
|
|
void writew(PhysPt addr,Bitu val) {
|
|
|
|
}
|
|
|
|
void writed(PhysPt addr,Bitu val) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
2009-05-03 00:02:15 +02:00
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
class DEBUG;
|
|
|
|
|
|
|
|
DEBUG* pDebugcom = 0;
|
|
|
|
bool exitLoop = false;
|
|
|
|
|
2009-05-03 00:02:15 +02:00
|
|
|
|
2009-05-02 23:53:27 +02:00
|
|
|
// Heavy Debugging Vars for logging
|
|
|
|
#if C_HEAVY_DEBUG
|
2009-05-03 00:28:34 +02:00
|
|
|
static ofstream cpuLogFile;
|
2009-05-02 23:53:27 +02:00
|
|
|
static bool cpuLog = false;
|
|
|
|
static int cpuLogCounter = 0;
|
2009-05-03 00:18:08 +02:00
|
|
|
static int cpuLogType = 1; // log detail
|
2009-05-03 00:28:34 +02:00
|
|
|
static bool zeroProtect = false;
|
|
|
|
bool logHeavy = false;
|
2009-05-02 23:53:27 +02:00
|
|
|
#endif
|
|
|
|
|
2009-05-03 00:02:15 +02:00
|
|
|
|
|
|
|
|
2009-05-02 23:03:37 +02:00
|
|
|
static struct {
|
|
|
|
Bit32u eax,ebx,ecx,edx,esi,edi,ebp,esp,eip;
|
|
|
|
} oldregs;
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
static char curSelectorName[3] = { 0,0,0 };
|
2009-05-02 23:03:37 +02:00
|
|
|
|
|
|
|
static Segment oldsegs[6];
|
2009-05-03 00:18:08 +02:00
|
|
|
static Bitu oldflags,oldcpucpl;
|
2009-05-02 23:03:37 +02:00
|
|
|
DBGBlock dbg;
|
|
|
|
static Bitu input_count;
|
|
|
|
Bitu cycle_count;
|
|
|
|
static bool debugging;
|
2009-05-03 00:02:15 +02:00
|
|
|
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
static void SetColor(Bitu test) {
|
2009-05-02 23:03:37 +02:00
|
|
|
if (test) {
|
|
|
|
if (has_colors()) { wattrset(dbg.win_reg,COLOR_PAIR(PAIR_BYELLOW_BLACK));}
|
|
|
|
} else {
|
|
|
|
if (has_colors()) { wattrset(dbg.win_reg,0);}
|
|
|
|
}
|
|
|
|
}
|
2009-05-02 23:12:18 +02:00
|
|
|
|
|
|
|
struct SCodeViewData {
|
|
|
|
int cursorPos;
|
|
|
|
Bit16u firstInstSize;
|
|
|
|
Bit16u useCS;
|
|
|
|
Bit32u useEIPlast, useEIPmid;
|
|
|
|
Bit32u useEIP;
|
|
|
|
Bit16u cursorSeg;
|
|
|
|
Bit32u cursorOfs;
|
|
|
|
bool inputMode;
|
|
|
|
char inputStr[255];
|
|
|
|
|
|
|
|
} codeViewData;
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
static Bit16u dataSeg;
|
|
|
|
static Bit32u dataOfs;
|
2009-05-02 23:35:44 +02:00
|
|
|
static bool showExtend = true;
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
/***********/
|
|
|
|
/* Helpers */
|
|
|
|
/***********/
|
|
|
|
|
|
|
|
Bit32u PhysMakeProt(Bit16u selector, Bit32u offset)
|
|
|
|
{
|
|
|
|
Descriptor desc;
|
|
|
|
if (cpu.gdt.GetDescriptor(selector,desc)) return desc.GetBase()+offset;
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
Bit32u GetAddress(Bit16u seg, Bit32u offset)
|
|
|
|
{
|
2009-05-02 23:53:27 +02:00
|
|
|
if (seg==SegValue(cs)) return SegPhys(cs)+offset;
|
2009-05-03 00:18:08 +02:00
|
|
|
if (cpu.pmode && !(reg_flags & FLAG_VM)) {
|
2009-05-02 23:53:27 +02:00
|
|
|
Descriptor desc;
|
|
|
|
if (cpu.gdt.GetDescriptor(seg,desc)) return PhysMakeProt(seg,offset);
|
|
|
|
}
|
2009-05-02 23:43:00 +02:00
|
|
|
return (seg<<4)+offset;
|
2009-05-02 23:53:27 +02:00
|
|
|
}
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
|
|
|
|
bool GetDescriptorInfo(char* selname, char* out1, char* out2)
|
|
|
|
{
|
2009-05-02 23:53:27 +02:00
|
|
|
Bitu sel;
|
2009-05-02 23:43:00 +02:00
|
|
|
Descriptor desc;
|
|
|
|
|
2009-05-03 00:18:08 +02:00
|
|
|
if (strstr(selname,"cs") || strstr(selname,"CS")) sel = SegValue(cs);
|
|
|
|
else if (strstr(selname,"ds") || strstr(selname,"DS")) sel = SegValue(ds);
|
|
|
|
else if (strstr(selname,"es") || strstr(selname,"ES")) sel = SegValue(es);
|
|
|
|
else if (strstr(selname,"fs") || strstr(selname,"FS")) sel = SegValue(fs);
|
|
|
|
else if (strstr(selname,"gs") || strstr(selname,"GS")) sel = SegValue(gs);
|
|
|
|
else if (strstr(selname,"ss") || strstr(selname,"SS")) sel = SegValue(ss);
|
|
|
|
else {
|
|
|
|
sel = GetHexValue(selname,selname);
|
|
|
|
if (*selname==0) selname=" ";
|
|
|
|
}
|
2009-05-02 23:43:00 +02:00
|
|
|
if (cpu.gdt.GetDescriptor(sel,desc)) {
|
2009-05-03 00:18:08 +02:00
|
|
|
switch (desc.Type()) {
|
|
|
|
case DESC_TASK_GATE:
|
|
|
|
sprintf(out1,"%s: s:%08X type:%02X p",selname,desc.GetSelector(),desc.saved.gate.type);
|
|
|
|
sprintf(out2," TaskGate dpl : %01X %1X",desc.saved.gate.dpl,desc.saved.gate.p);
|
|
|
|
return true;
|
|
|
|
case DESC_LDT:
|
|
|
|
case DESC_286_TSS_A:
|
|
|
|
case DESC_286_TSS_B:
|
|
|
|
case DESC_386_TSS_A:
|
|
|
|
case DESC_386_TSS_B:
|
|
|
|
sprintf(out1,"%s: b:%08X type:%02X pag",selname,desc.GetBase(),desc.saved.seg.type);
|
|
|
|
sprintf(out2," l:%08X dpl : %01X %1X%1X%1X",desc.GetLimit(),desc.saved.seg.dpl,desc.saved.seg.p,desc.saved.seg.avl,desc.saved.seg.g);
|
|
|
|
return true;
|
|
|
|
case DESC_286_CALL_GATE:
|
|
|
|
case DESC_386_CALL_GATE:
|
|
|
|
sprintf(out1,"%s: s:%08X type:%02X p params: %02X",selname,desc.GetSelector(),desc.saved.gate.type,desc.saved.gate.paramcount);
|
|
|
|
sprintf(out2," o:%08X dpl : %01X %1X",desc.GetOffset(),desc.saved.gate.dpl,desc.saved.gate.p);
|
|
|
|
return true;
|
|
|
|
case DESC_286_INT_GATE:
|
|
|
|
case DESC_286_TRAP_GATE:
|
|
|
|
case DESC_386_INT_GATE:
|
|
|
|
case DESC_386_TRAP_GATE:
|
|
|
|
sprintf(out1,"%s: s:%08X type:%02X p",selname,desc.GetSelector(),desc.saved.gate.type);
|
|
|
|
sprintf(out2," o:%08X dpl : %01X %1X",desc.GetOffset(),desc.saved.gate.dpl,desc.saved.gate.p);
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-02 23:43:00 +02:00
|
|
|
sprintf(out1,"%s: b:%08X type:%02X parbg",selname,desc.GetBase(),desc.saved.seg.type);
|
|
|
|
sprintf(out2," l:%08X dpl : %01X %1X%1X%1X%1X%1X",desc.GetLimit(),desc.saved.seg.dpl,desc.saved.seg.p,desc.saved.seg.avl,desc.saved.seg.r,desc.saved.seg.big,desc.saved.seg.g);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
strcpy(out1," ");
|
|
|
|
strcpy(out2," ");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:35:44 +02:00
|
|
|
/********************/
|
|
|
|
/* DebugVar stuff */
|
|
|
|
/********************/
|
|
|
|
|
|
|
|
class CDebugVar
|
|
|
|
{
|
|
|
|
public:
|
2009-05-03 00:18:08 +02:00
|
|
|
CDebugVar(char* _name, PhysPt _adr) { adr=_adr; safe_strncpy(name,_name,16); };
|
2009-05-02 23:35:44 +02:00
|
|
|
|
|
|
|
char* GetName(void) { return name; };
|
|
|
|
PhysPt GetAdr (void) { return adr; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
PhysPt adr;
|
|
|
|
char name[16];
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void InsertVariable (char* name, PhysPt adr);
|
|
|
|
static CDebugVar* FindVar (PhysPt adr);
|
|
|
|
static void DeleteAll ();
|
|
|
|
static bool SaveVars (char* name);
|
|
|
|
static bool LoadVars (char* name);
|
|
|
|
|
|
|
|
static std::list<CDebugVar*> varList;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::list<CDebugVar*> CDebugVar::varList;
|
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
|
|
|
|
/********************/
|
|
|
|
/* Breakpoint stuff */
|
|
|
|
/********************/
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
bool skipFirstInstruction = false;
|
|
|
|
|
2009-05-02 23:53:27 +02:00
|
|
|
enum EBreakpoint { BKPNT_UNKNOWN, BKPNT_PHYSICAL, BKPNT_INTERRUPT, BKPNT_MEMORY, BKPNT_MEMORY_PROT, BKPNT_MEMORY_LINEAR };
|
2009-05-02 23:12:18 +02:00
|
|
|
|
|
|
|
#define BPINT_ALL 0x100
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
class CBreakpoint
|
|
|
|
{
|
|
|
|
public:
|
2009-05-02 23:12:18 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
CBreakpoint(void);
|
2009-05-02 23:43:00 +02:00
|
|
|
void SetAddress (Bit16u seg, Bit32u off) { location = GetAddress(seg,off); type = BKPNT_PHYSICAL; segment = seg; offset = off; };
|
2009-05-02 23:20:05 +02:00
|
|
|
void SetAddress (PhysPt adr) { location = adr; type = BKPNT_PHYSICAL; };
|
|
|
|
void SetInt (Bit8u _intNr, Bit16u ah) { intNr = _intNr, ahValue = ah; type = BKPNT_INTERRUPT; };
|
|
|
|
void SetOnce (bool _once) { once = _once; };
|
2009-05-02 23:27:47 +02:00
|
|
|
void SetType (EBreakpoint _type) { type = _type; };
|
|
|
|
void SetValue (Bit8u value) { ahValue = value; };
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
bool IsActive (void) { return active; };
|
|
|
|
void Activate (bool _active);
|
|
|
|
|
|
|
|
EBreakpoint GetType (void) { return type; };
|
|
|
|
bool GetOnce (void) { return once; };
|
2009-05-02 23:27:47 +02:00
|
|
|
PhysPt GetLocation (void) { if (GetType()!=BKPNT_INTERRUPT) return location; else return 0; };
|
2009-05-02 23:20:05 +02:00
|
|
|
Bit16u GetSegment (void) { return segment; };
|
|
|
|
Bit32u GetOffset (void) { return offset; };
|
2009-05-02 23:27:47 +02:00
|
|
|
Bit8u GetIntNr (void) { if (GetType()==BKPNT_INTERRUPT) return intNr; else return 0; };
|
|
|
|
Bit16u GetValue (void) { if (GetType()!=BKPNT_PHYSICAL) return ahValue; else return 0; };
|
2009-05-02 23:20:05 +02:00
|
|
|
|
|
|
|
// statics
|
|
|
|
static CBreakpoint* AddBreakpoint (Bit16u seg, Bit32u off, bool once);
|
|
|
|
static CBreakpoint* AddIntBreakpoint (Bit8u intNum, Bit16u ah, bool once);
|
2009-05-02 23:27:47 +02:00
|
|
|
static CBreakpoint* AddMemBreakpoint (Bit16u seg, Bit32u off);
|
2009-05-02 23:20:05 +02:00
|
|
|
static void ActivateBreakpoints (PhysPt adr, bool activate);
|
|
|
|
static bool CheckBreakpoint (PhysPt adr);
|
2009-05-02 23:43:00 +02:00
|
|
|
static bool CheckBreakpoint (Bitu seg, Bitu off);
|
2009-05-02 23:20:05 +02:00
|
|
|
static bool CheckIntBreakpoint (PhysPt adr, Bit8u intNr, Bit16u ahValue);
|
|
|
|
static bool IsBreakpoint (PhysPt where);
|
|
|
|
static bool IsBreakpointDrawn (PhysPt where);
|
|
|
|
static bool DeleteBreakpoint (PhysPt where);
|
|
|
|
static bool DeleteByIndex (Bit16u index);
|
|
|
|
static void DeleteAll (void);
|
|
|
|
static void ShowList (void);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
EBreakpoint type;
|
|
|
|
// Physical
|
|
|
|
PhysPt location;
|
|
|
|
Bit8u oldData;
|
|
|
|
Bit16u segment;
|
|
|
|
Bit32u offset;
|
|
|
|
// Int
|
|
|
|
Bit8u intNr;
|
|
|
|
Bit16u ahValue;
|
|
|
|
// Shared
|
|
|
|
bool active;
|
|
|
|
bool once;
|
|
|
|
|
|
|
|
static std::list<CBreakpoint*> BPoints;
|
2009-05-02 23:27:47 +02:00
|
|
|
public:
|
2009-05-02 23:20:05 +02:00
|
|
|
static CBreakpoint* ignoreOnce;
|
|
|
|
};
|
2009-05-02 23:12:18 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
CBreakpoint::CBreakpoint(void):
|
|
|
|
location(0),
|
|
|
|
active(false),once(false),
|
|
|
|
segment(0),offset(0),intNr(0),ahValue(0),
|
|
|
|
type(BKPNT_UNKNOWN) { };
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
void CBreakpoint::Activate(bool _active)
|
2009-05-02 23:12:18 +02:00
|
|
|
{
|
2009-05-02 23:20:05 +02:00
|
|
|
#if !C_HEAVY_DEBUG
|
2009-05-03 00:28:34 +02:00
|
|
|
if (GetType()==BKPNT_PHYSICAL) {
|
2009-05-02 23:20:05 +02:00
|
|
|
if (_active) {
|
|
|
|
// Set 0xCC and save old value
|
|
|
|
Bit8u data = mem_readb(location);
|
|
|
|
if (data!=0xCC) {
|
|
|
|
oldData = data;
|
|
|
|
mem_writeb(location,0xCC);
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Remove 0xCC and set old value
|
|
|
|
if (mem_readb (location)==0xCC) {
|
|
|
|
mem_writeb(location,oldData);
|
|
|
|
};
|
|
|
|
}
|
2009-05-02 23:12:18 +02:00
|
|
|
}
|
2009-05-03 00:28:34 +02:00
|
|
|
#endif
|
2009-05-02 23:20:05 +02:00
|
|
|
active = _active;
|
2009-05-02 23:03:37 +02:00
|
|
|
};
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
// Statics
|
|
|
|
std::list<CBreakpoint*> CBreakpoint::BPoints;
|
|
|
|
CBreakpoint* CBreakpoint::ignoreOnce = 0;
|
2009-05-02 23:43:00 +02:00
|
|
|
Bitu ignoreAddressOnce = 0;
|
2009-05-02 23:20:05 +02:00
|
|
|
|
|
|
|
CBreakpoint* CBreakpoint::AddBreakpoint(Bit16u seg, Bit32u off, bool once)
|
2009-05-02 23:12:18 +02:00
|
|
|
{
|
2009-05-02 23:20:05 +02:00
|
|
|
CBreakpoint* bp = new CBreakpoint();
|
|
|
|
bp->SetAddress (seg,off);
|
|
|
|
bp->SetOnce (once);
|
|
|
|
BPoints.push_front (bp);
|
|
|
|
return bp;
|
|
|
|
};
|
|
|
|
|
|
|
|
CBreakpoint* CBreakpoint::AddIntBreakpoint(Bit8u intNum, Bit16u ah, bool once)
|
|
|
|
{
|
|
|
|
CBreakpoint* bp = new CBreakpoint();
|
|
|
|
bp->SetInt (intNum,ah);
|
|
|
|
bp->SetOnce (once);
|
|
|
|
BPoints.push_front (bp);
|
|
|
|
return bp;
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:27:47 +02:00
|
|
|
CBreakpoint* CBreakpoint::AddMemBreakpoint(Bit16u seg, Bit32u off)
|
|
|
|
{
|
|
|
|
CBreakpoint* bp = new CBreakpoint();
|
|
|
|
bp->SetAddress (seg,off);
|
|
|
|
bp->SetOnce (false);
|
|
|
|
bp->SetType (BKPNT_MEMORY);
|
|
|
|
BPoints.push_front (bp);
|
|
|
|
return bp;
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
void CBreakpoint::ActivateBreakpoints(PhysPt adr, bool activate)
|
|
|
|
{
|
|
|
|
// activate all breakpoints
|
|
|
|
std::list<CBreakpoint*>::iterator i;
|
|
|
|
CBreakpoint* bp;
|
2009-05-02 23:12:18 +02:00
|
|
|
for(i=BPoints.begin(); i != BPoints.end(); i++) {
|
2009-05-03 00:28:34 +02:00
|
|
|
bp = (*i);
|
2009-05-02 23:20:05 +02:00
|
|
|
// Do not activate, when bp is an actual adress
|
|
|
|
if (activate && (bp->GetType()==BKPNT_PHYSICAL) && (bp->GetLocation()==adr)) {
|
2009-05-02 23:27:47 +02:00
|
|
|
// Do not activate :)
|
2009-05-02 23:20:05 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bp->Activate(activate);
|
|
|
|
};
|
|
|
|
};
|
2009-05-02 23:12:18 +02:00
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
bool CBreakpoint::CheckBreakpoint(Bitu seg, Bitu off)
|
2009-05-02 23:20:05 +02:00
|
|
|
// Checks if breakpoint is valid an should stop execution
|
2009-05-02 23:12:18 +02:00
|
|
|
{
|
2009-05-02 23:43:00 +02:00
|
|
|
if ((ignoreAddressOnce!=0) && (GetAddress(seg,off)==ignoreAddressOnce)) {
|
|
|
|
ignoreAddressOnce = 0;
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
ignoreAddressOnce = 0;
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
// Search matching breakpoint
|
|
|
|
std::list<CBreakpoint*>::iterator i;
|
|
|
|
CBreakpoint* bp;
|
2009-05-02 23:12:18 +02:00
|
|
|
for(i=BPoints.begin(); i != BPoints.end(); i++) {
|
2009-05-03 00:28:34 +02:00
|
|
|
bp = (*i);
|
2009-05-02 23:43:00 +02:00
|
|
|
if ((bp->GetType()==BKPNT_PHYSICAL) && bp->IsActive() && (bp->GetSegment()==seg) && (bp->GetOffset()==off)) {
|
2009-05-02 23:27:47 +02:00
|
|
|
// Ignore Once ?
|
|
|
|
if (ignoreOnce==bp) {
|
|
|
|
ignoreOnce=0;
|
|
|
|
bp->Activate(true);
|
|
|
|
return false;
|
|
|
|
};
|
2009-05-02 23:20:05 +02:00
|
|
|
// Found,
|
|
|
|
if (bp->GetOnce()) {
|
|
|
|
// delete it, if it should only be used once
|
|
|
|
(BPoints.erase)(i);
|
|
|
|
bp->Activate(false);
|
|
|
|
delete bp;
|
2009-05-02 23:27:47 +02:00
|
|
|
} else {
|
|
|
|
ignoreOnce = bp;
|
|
|
|
};
|
2009-05-02 23:20:05 +02:00
|
|
|
return true;
|
2009-05-02 23:27:47 +02:00
|
|
|
}
|
|
|
|
#if C_HEAVY_DEBUG
|
|
|
|
// Memory breakpoint support
|
2009-05-02 23:53:27 +02:00
|
|
|
else if (bp->IsActive()) {
|
|
|
|
if ((bp->GetType()==BKPNT_MEMORY) || (bp->GetType()==BKPNT_MEMORY_PROT) || (bp->GetType()==BKPNT_MEMORY_LINEAR)) {
|
|
|
|
// Watch Protected Mode Memoryonly in pmode
|
|
|
|
if (bp->GetType()==BKPNT_MEMORY_PROT) {
|
|
|
|
// Check if pmode is active
|
|
|
|
if (!cpu.pmode) return false;
|
|
|
|
// Check if descriptor is valid
|
|
|
|
Descriptor desc;
|
|
|
|
if (!cpu.gdt.GetDescriptor(bp->GetSegment(),desc)) return false;
|
|
|
|
if (desc.GetLimit()==0) return false;
|
|
|
|
}
|
2009-05-02 23:43:00 +02:00
|
|
|
|
2009-05-02 23:53:27 +02:00
|
|
|
Bitu address;
|
|
|
|
if (bp->GetType()==BKPNT_MEMORY_LINEAR) address = bp->GetOffset();
|
|
|
|
else address = GetAddress(bp->GetSegment(),bp->GetOffset());
|
|
|
|
Bit8u value = mem_readb(address);
|
|
|
|
if (bp->GetValue() != value) {
|
|
|
|
// Yup, memory value changed
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Memory breakpoint %s: %04X:%04X - %02X -> %02X\n",(bp->GetType()==BKPNT_MEMORY_PROT)?"(Prot)":"",bp->GetSegment(),bp->GetOffset(),bp->GetValue(),value);
|
2009-05-02 23:53:27 +02:00
|
|
|
bp->SetValue(value);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
2009-05-02 23:12:18 +02:00
|
|
|
};
|
2009-05-02 23:27:47 +02:00
|
|
|
#endif
|
2009-05-02 23:20:05 +02:00
|
|
|
};
|
|
|
|
return false;
|
|
|
|
};
|
2009-05-02 23:12:18 +02:00
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
bool CBreakpoint::CheckIntBreakpoint(PhysPt adr, Bit8u intNr, Bit16u ahValue)
|
|
|
|
// Checks if interrupt breakpoint is valid an should stop execution
|
2009-05-02 23:12:18 +02:00
|
|
|
{
|
2009-05-02 23:43:00 +02:00
|
|
|
if ((ignoreAddressOnce!=0) && (adr==ignoreAddressOnce)) {
|
|
|
|
ignoreAddressOnce = 0;
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
ignoreAddressOnce = 0;
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
// Search matching breakpoint
|
|
|
|
std::list<CBreakpoint*>::iterator i;
|
|
|
|
CBreakpoint* bp;
|
2009-05-02 23:12:18 +02:00
|
|
|
for(i=BPoints.begin(); i != BPoints.end(); i++) {
|
2009-05-03 00:28:34 +02:00
|
|
|
bp = (*i);
|
2009-05-02 23:20:05 +02:00
|
|
|
if ((bp->GetType()==BKPNT_INTERRUPT) && bp->IsActive() && (bp->GetIntNr()==intNr)) {
|
|
|
|
if ((bp->GetValue()==BPINT_ALL) || (bp->GetValue()==ahValue)) {
|
2009-05-02 23:27:47 +02:00
|
|
|
// Ignoie it once ?
|
|
|
|
if (ignoreOnce==bp) {
|
|
|
|
ignoreOnce=0;
|
|
|
|
bp->Activate(true);
|
|
|
|
return false;
|
|
|
|
};
|
2009-05-02 23:20:05 +02:00
|
|
|
// Found
|
|
|
|
if (bp->GetOnce()) {
|
|
|
|
// delete it, if it should only be used once
|
|
|
|
(BPoints.erase)(i);
|
|
|
|
bp->Activate(false);
|
|
|
|
delete bp;
|
2009-05-02 23:27:47 +02:00
|
|
|
} else {
|
|
|
|
ignoreOnce = bp;
|
|
|
|
}
|
2009-05-02 23:20:05 +02:00
|
|
|
return true;
|
2009-05-02 23:12:18 +02:00
|
|
|
}
|
|
|
|
};
|
2009-05-02 23:20:05 +02:00
|
|
|
};
|
|
|
|
return false;
|
|
|
|
};
|
2009-05-02 23:12:18 +02:00
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
void CBreakpoint::DeleteAll()
|
2009-05-02 23:12:18 +02:00
|
|
|
{
|
2009-05-02 23:20:05 +02:00
|
|
|
std::list<CBreakpoint*>::iterator i;
|
|
|
|
CBreakpoint* bp;
|
|
|
|
for(i=BPoints.begin(); i != BPoints.end(); i++) {
|
2009-05-03 00:28:34 +02:00
|
|
|
bp = (*i);
|
2009-05-02 23:20:05 +02:00
|
|
|
bp->Activate(false);
|
|
|
|
delete bp;
|
|
|
|
};
|
|
|
|
(BPoints.clear)();
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
bool CBreakpoint::DeleteByIndex(Bit16u index)
|
2009-05-02 23:12:18 +02:00
|
|
|
{
|
2009-05-02 23:20:05 +02:00
|
|
|
// Search matching breakpoint
|
|
|
|
int nr = 0;
|
|
|
|
std::list<CBreakpoint*>::iterator i;
|
|
|
|
CBreakpoint* bp;
|
|
|
|
for(i=BPoints.begin(); i != BPoints.end(); i++) {
|
|
|
|
if (nr==index) {
|
2009-05-03 00:28:34 +02:00
|
|
|
bp = (*i);
|
2009-05-02 23:20:05 +02:00
|
|
|
(BPoints.erase)(i);
|
|
|
|
bp->Activate(false);
|
|
|
|
delete bp;
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-02 23:27:47 +02:00
|
|
|
nr++;
|
2009-05-02 23:20:05 +02:00
|
|
|
};
|
|
|
|
return false;
|
2009-05-02 23:12:18 +02:00
|
|
|
};
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
bool CBreakpoint::DeleteBreakpoint(PhysPt where)
|
2009-05-02 23:12:18 +02:00
|
|
|
{
|
2009-05-02 23:20:05 +02:00
|
|
|
// Search matching breakpoint
|
|
|
|
std::list<CBreakpoint*>::iterator i;
|
|
|
|
CBreakpoint* bp;
|
2009-05-02 23:12:18 +02:00
|
|
|
for(i=BPoints.begin(); i != BPoints.end(); i++) {
|
2009-05-03 00:28:34 +02:00
|
|
|
bp = (*i);
|
2009-05-02 23:20:05 +02:00
|
|
|
if ((bp->GetType()==BKPNT_PHYSICAL) && (bp->GetLocation()==where)) {
|
|
|
|
(BPoints.erase)(i);
|
|
|
|
bp->Activate(false);
|
|
|
|
delete bp;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool CBreakpoint::IsBreakpoint(PhysPt adr)
|
|
|
|
// is there a breakpoint at address ?
|
|
|
|
{
|
|
|
|
// Search matching breakpoint
|
|
|
|
std::list<CBreakpoint*>::iterator i;
|
|
|
|
CBreakpoint* bp;
|
|
|
|
for(i=BPoints.begin(); i != BPoints.end(); i++) {
|
2009-05-03 00:28:34 +02:00
|
|
|
bp = (*i);
|
2009-05-02 23:43:00 +02:00
|
|
|
if ((bp->GetType()==BKPNT_PHYSICAL) && (bp->GetSegment()==adr)) {
|
|
|
|
return true;
|
|
|
|
};
|
2009-05-02 23:20:05 +02:00
|
|
|
if ((bp->GetType()==BKPNT_PHYSICAL) && (bp->GetLocation()==adr)) {
|
2009-05-02 23:12:18 +02:00
|
|
|
return true;
|
|
|
|
};
|
2009-05-02 23:20:05 +02:00
|
|
|
};
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool CBreakpoint::IsBreakpointDrawn(PhysPt adr)
|
|
|
|
// valid breakpoint, that should be drawn ?
|
|
|
|
{
|
|
|
|
// Search matching breakpoint
|
|
|
|
std::list<CBreakpoint*>::iterator i;
|
|
|
|
CBreakpoint* bp;
|
|
|
|
for(i=BPoints.begin(); i != BPoints.end(); i++) {
|
2009-05-03 00:28:34 +02:00
|
|
|
bp = (*i);
|
2009-05-02 23:20:05 +02:00
|
|
|
if ((bp->GetType()==BKPNT_PHYSICAL) && (bp->GetLocation()==adr)) {
|
|
|
|
// Only draw, if breakpoint is not only once,
|
|
|
|
return !bp->GetOnce();
|
|
|
|
};
|
|
|
|
};
|
2009-05-02 23:12:18 +02:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
void CBreakpoint::ShowList(void)
|
|
|
|
{
|
|
|
|
// iterate list
|
|
|
|
int nr = 0;
|
|
|
|
std::list<CBreakpoint*>::iterator i;
|
|
|
|
for(i=BPoints.begin(); i != BPoints.end(); i++) {
|
2009-05-03 00:28:34 +02:00
|
|
|
CBreakpoint* bp = (*i);
|
2009-05-02 23:20:05 +02:00
|
|
|
if (bp->GetType()==BKPNT_PHYSICAL) {
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("%02X. BP %04X:%04X\n",nr,bp->GetSegment(),bp->GetOffset());
|
2009-05-02 23:20:05 +02:00
|
|
|
nr++;
|
|
|
|
} else if (bp->GetType()==BKPNT_INTERRUPT) {
|
2009-05-03 00:08:43 +02:00
|
|
|
if (bp->GetValue()==BPINT_ALL) DEBUG_ShowMsg("%02X. BPINT %02X\n",nr,bp->GetIntNr());
|
|
|
|
else DEBUG_ShowMsg("%02X. BPINT %02X AH=%02X\n",nr,bp->GetIntNr(),bp->GetValue());
|
2009-05-02 23:20:05 +02:00
|
|
|
nr++;
|
2009-05-02 23:27:47 +02:00
|
|
|
} else if (bp->GetType()==BKPNT_MEMORY) {
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("%02X. BPMEM %04X:%04X (%02X)\n",nr,bp->GetSegment(),bp->GetOffset(),bp->GetValue());
|
2009-05-02 23:27:47 +02:00
|
|
|
nr++;
|
2009-05-03 00:18:08 +02:00
|
|
|
} else if (bp->GetType()==BKPNT_MEMORY_PROT) {
|
|
|
|
DEBUG_ShowMsg("%02X. BPPM %04X:%08X (%02X)\n",nr,bp->GetSegment(),bp->GetOffset(),bp->GetValue());
|
|
|
|
nr++;
|
2009-05-02 23:20:05 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool DEBUG_Breakpoint(void)
|
|
|
|
{
|
|
|
|
/* First get the phyiscal address and check for a set Breakpoint */
|
2009-05-03 00:02:15 +02:00
|
|
|
if (!CBreakpoint::CheckBreakpoint(SegValue(cs),reg_eip)) return false;
|
2009-05-02 23:20:05 +02:00
|
|
|
// Found. Breakpoint is valid
|
2009-05-03 00:28:34 +02:00
|
|
|
PhysPt where=GetAddress(SegValue(cs),reg_eip);
|
2009-05-02 23:43:00 +02:00
|
|
|
CBreakpoint::ActivateBreakpoints(where,false); // Deactivate all breakpoints
|
2009-05-02 23:20:05 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool DEBUG_IntBreakpoint(Bit8u intNum)
|
|
|
|
{
|
|
|
|
/* First get the phyiscal address and check for a set Breakpoint */
|
2009-05-03 00:02:15 +02:00
|
|
|
PhysPt where=GetAddress(SegValue(cs),reg_eip);
|
2009-05-02 23:20:05 +02:00
|
|
|
if (!CBreakpoint::CheckIntBreakpoint(where,intNum,reg_ah)) return false;
|
|
|
|
// Found. Breakpoint is valid
|
2009-05-02 23:43:00 +02:00
|
|
|
CBreakpoint::ActivateBreakpoints(where,false); // Deactivate all breakpoints
|
2009-05-02 23:20:05 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
static bool StepOver()
|
|
|
|
{
|
2009-05-02 23:43:00 +02:00
|
|
|
exitLoop = false;
|
|
|
|
PhysPt start=GetAddress(SegValue(cs),reg_eip);
|
2009-05-02 23:12:18 +02:00
|
|
|
char dline[200];Bitu size;
|
2009-05-02 23:43:00 +02:00
|
|
|
size=DasmI386(dline, start, reg_eip, cpu.code.big);
|
2009-05-02 23:12:18 +02:00
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
if (strstr(dline,"call") || strstr(dline,"int") || strstr(dline,"loop") || strstr(dline,"rep")) {
|
|
|
|
CBreakpoint::AddBreakpoint (SegValue(cs),reg_eip+size, true);
|
2009-05-02 23:43:00 +02:00
|
|
|
CBreakpoint::ActivateBreakpoints(start, true);
|
2009-05-02 23:12:18 +02:00
|
|
|
debugging=false;
|
|
|
|
DrawCode();
|
|
|
|
DOSBOX_SetNormalLoop();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
bool DEBUG_ExitLoop(void)
|
2009-05-02 23:12:18 +02:00
|
|
|
{
|
2009-05-03 00:02:15 +02:00
|
|
|
#if C_HEAVY_DEBUG
|
|
|
|
DrawVariables();
|
|
|
|
#endif
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
if (exitLoop) {
|
|
|
|
exitLoop = false;
|
|
|
|
return true;
|
2009-05-02 23:12:18 +02:00
|
|
|
}
|
2009-05-02 23:20:05 +02:00
|
|
|
return false;
|
2009-05-02 23:12:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/********************/
|
|
|
|
/* Draw windows */
|
|
|
|
/********************/
|
|
|
|
|
|
|
|
static void DrawData(void) {
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
Bit8u ch;
|
|
|
|
Bit32u add = dataOfs;
|
|
|
|
Bit32u address;
|
2009-05-02 23:12:18 +02:00
|
|
|
/* Data win */
|
|
|
|
for (int y=0; y<8; y++) {
|
|
|
|
// Adress
|
2009-05-03 00:18:08 +02:00
|
|
|
if (add<0x10000) mvwprintw (dbg.win_data,1+y,0,"%04X:%04X ",dataSeg,add);
|
|
|
|
else mvwprintw (dbg.win_data,1+y,0,"%04X:%08X ",dataSeg,add);
|
2009-05-02 23:12:18 +02:00
|
|
|
for (int x=0; x<16; x++) {
|
2009-05-02 23:43:00 +02:00
|
|
|
address = GetAddress(dataSeg,add);
|
2009-05-02 23:53:27 +02:00
|
|
|
if (!(paging.tlb.handler[address >> 12]->flags & PFLAG_INIT)) {
|
|
|
|
ch = mem_readb(address);
|
|
|
|
} else ch = 0;
|
2009-05-03 00:18:08 +02:00
|
|
|
mvwprintw (dbg.win_data,1+y,14+3*x,"%02X",ch);
|
|
|
|
if (ch<32 || !isprint(*reinterpret_cast<unsigned char*>(&ch))) ch='.';
|
|
|
|
mvwprintw (dbg.win_data,1+y,63+x,"%c",ch);
|
2009-05-02 23:12:18 +02:00
|
|
|
add++;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
wrefresh(dbg.win_data);
|
|
|
|
};
|
2009-05-02 23:03:37 +02:00
|
|
|
|
|
|
|
static void DrawRegisters(void) {
|
|
|
|
/* Main Registers */
|
|
|
|
SetColor(reg_eax!=oldregs.eax);oldregs.eax=reg_eax;mvwprintw (dbg.win_reg,0,4,"%08X",reg_eax);
|
|
|
|
SetColor(reg_ebx!=oldregs.ebx);oldregs.ebx=reg_ebx;mvwprintw (dbg.win_reg,1,4,"%08X",reg_ebx);
|
|
|
|
SetColor(reg_ecx!=oldregs.ecx);oldregs.ecx=reg_ecx;mvwprintw (dbg.win_reg,2,4,"%08X",reg_ecx);
|
|
|
|
SetColor(reg_edx!=oldregs.edx);oldregs.edx=reg_edx;mvwprintw (dbg.win_reg,3,4,"%08X",reg_edx);
|
|
|
|
|
|
|
|
SetColor(reg_esi!=oldregs.esi);oldregs.esi=reg_esi;mvwprintw (dbg.win_reg,0,18,"%08X",reg_esi);
|
|
|
|
SetColor(reg_edi!=oldregs.edi);oldregs.edi=reg_edi;mvwprintw (dbg.win_reg,1,18,"%08X",reg_edi);
|
|
|
|
SetColor(reg_ebp!=oldregs.ebp);oldregs.ebp=reg_ebp;mvwprintw (dbg.win_reg,2,18,"%08X",reg_ebp);
|
|
|
|
SetColor(reg_esp!=oldregs.esp);oldregs.esp=reg_esp;mvwprintw (dbg.win_reg,3,18,"%08X",reg_esp);
|
|
|
|
SetColor(reg_eip!=oldregs.eip);oldregs.eip=reg_eip;mvwprintw (dbg.win_reg,1,42,"%08X",reg_eip);
|
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
SetColor(SegValue(ds)!=oldsegs[ds].val);oldsegs[ds].val=SegValue(ds);mvwprintw (dbg.win_reg,0,31,"%04X",SegValue(ds));
|
|
|
|
SetColor(SegValue(es)!=oldsegs[es].val);oldsegs[es].val=SegValue(es);mvwprintw (dbg.win_reg,0,41,"%04X",SegValue(es));
|
|
|
|
SetColor(SegValue(fs)!=oldsegs[fs].val);oldsegs[fs].val=SegValue(fs);mvwprintw (dbg.win_reg,0,51,"%04X",SegValue(fs));
|
|
|
|
SetColor(SegValue(gs)!=oldsegs[gs].val);oldsegs[gs].val=SegValue(gs);mvwprintw (dbg.win_reg,0,61,"%04X",SegValue(gs));
|
|
|
|
SetColor(SegValue(ss)!=oldsegs[ss].val);oldsegs[ss].val=SegValue(ss);mvwprintw (dbg.win_reg,0,71,"%04X",SegValue(ss));
|
|
|
|
SetColor(SegValue(cs)!=oldsegs[cs].val);oldsegs[cs].val=SegValue(cs);mvwprintw (dbg.win_reg,1,31,"%04X",SegValue(cs));
|
2009-05-02 23:03:37 +02:00
|
|
|
|
|
|
|
/*Individual flags*/
|
2009-05-03 00:28:34 +02:00
|
|
|
Bitu changed_flags = reg_flags ^ oldflags;
|
|
|
|
oldflags = reg_flags;
|
2009-05-02 23:03:37 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
SetColor(changed_flags&FLAG_CF);
|
2009-05-02 23:43:00 +02:00
|
|
|
mvwprintw (dbg.win_reg,1,53,"%01X",GETFLAG(CF) ? 1:0);
|
2009-05-03 00:28:34 +02:00
|
|
|
SetColor(changed_flags&FLAG_ZF);
|
2009-05-02 23:43:00 +02:00
|
|
|
mvwprintw (dbg.win_reg,1,56,"%01X",GETFLAG(ZF) ? 1:0);
|
2009-05-03 00:28:34 +02:00
|
|
|
SetColor(changed_flags&FLAG_SF);
|
2009-05-02 23:43:00 +02:00
|
|
|
mvwprintw (dbg.win_reg,1,59,"%01X",GETFLAG(SF) ? 1:0);
|
2009-05-03 00:28:34 +02:00
|
|
|
SetColor(changed_flags&FLAG_OF);
|
2009-05-02 23:43:00 +02:00
|
|
|
mvwprintw (dbg.win_reg,1,62,"%01X",GETFLAG(OF) ? 1:0);
|
2009-05-03 00:28:34 +02:00
|
|
|
SetColor(changed_flags&FLAG_AF);
|
2009-05-02 23:43:00 +02:00
|
|
|
mvwprintw (dbg.win_reg,1,65,"%01X",GETFLAG(AF) ? 1:0);
|
2009-05-03 00:28:34 +02:00
|
|
|
SetColor(changed_flags&FLAG_PF);
|
2009-05-02 23:43:00 +02:00
|
|
|
mvwprintw (dbg.win_reg,1,68,"%01X",GETFLAG(PF) ? 1:0);
|
|
|
|
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
SetColor(changed_flags&FLAG_DF);
|
2009-05-02 23:43:00 +02:00
|
|
|
mvwprintw (dbg.win_reg,1,71,"%01X",GETFLAG(DF) ? 1:0);
|
2009-05-03 00:28:34 +02:00
|
|
|
SetColor(changed_flags&FLAG_IF);
|
2009-05-02 23:43:00 +02:00
|
|
|
mvwprintw (dbg.win_reg,1,74,"%01X",GETFLAG(IF) ? 1:0);
|
2009-05-03 00:28:34 +02:00
|
|
|
SetColor(changed_flags&FLAG_TF);
|
2009-05-02 23:43:00 +02:00
|
|
|
mvwprintw (dbg.win_reg,1,77,"%01X",GETFLAG(TF) ? 1:0);
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
SetColor(changed_flags&FLAG_IOPL);
|
2009-05-03 00:18:08 +02:00
|
|
|
mvwprintw (dbg.win_reg,2,72,"%01X",GETFLAG(IOPL)>>12);
|
2009-05-03 00:28:34 +02:00
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
|
2009-05-03 00:18:08 +02:00
|
|
|
SetColor(cpu.cpl ^ oldcpucpl);
|
|
|
|
mvwprintw (dbg.win_reg,2,78,"%01X",cpu.cpl);
|
|
|
|
oldcpucpl=cpu.cpl;
|
|
|
|
|
2009-05-02 23:53:27 +02:00
|
|
|
if (cpu.pmode) {
|
|
|
|
if (reg_flags & FLAG_VM) mvwprintw(dbg.win_reg,0,76,"VM86");
|
|
|
|
else if (cpu.code.big) mvwprintw(dbg.win_reg,0,76,"Pr32");
|
|
|
|
else mvwprintw(dbg.win_reg,0,76,"Pr16");
|
|
|
|
} else
|
|
|
|
mvwprintw(dbg.win_reg,0,76,"Real");
|
2009-05-02 23:43:00 +02:00
|
|
|
|
|
|
|
// Selector info, if available
|
2009-05-03 00:28:34 +02:00
|
|
|
if ((cpu.pmode) && curSelectorName[0]) {
|
2009-05-02 23:43:00 +02:00
|
|
|
char out1[200], out2[200];
|
|
|
|
GetDescriptorInfo(curSelectorName,out1,out2);
|
|
|
|
mvwprintw(dbg.win_reg,2,28,out1);
|
|
|
|
mvwprintw(dbg.win_reg,3,28,out2);
|
|
|
|
}
|
2009-05-02 23:03:37 +02:00
|
|
|
|
|
|
|
wattrset(dbg.win_reg,0);
|
|
|
|
mvwprintw(dbg.win_reg,3,60,"%d ",cycle_count);
|
|
|
|
wrefresh(dbg.win_reg);
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
static void DrawCode(void)
|
|
|
|
{
|
2009-05-02 23:43:00 +02:00
|
|
|
bool saveSel;
|
2009-05-02 23:12:18 +02:00
|
|
|
Bit32u disEIP = codeViewData.useEIP;
|
2009-05-02 23:43:00 +02:00
|
|
|
PhysPt start = GetAddress(codeViewData.useCS,codeViewData.useEIP);
|
2009-05-02 23:03:37 +02:00
|
|
|
char dline[200];Bitu size;Bitu c;
|
2009-05-03 00:28:34 +02:00
|
|
|
static char line20[21] = " ";
|
2009-05-02 23:12:18 +02:00
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
for (int i=0;i<10;i++) {
|
|
|
|
saveSel = false;
|
2009-05-02 23:12:18 +02:00
|
|
|
if (has_colors()) {
|
|
|
|
if ((codeViewData.useCS==SegValue(cs)) && (disEIP == reg_eip)) {
|
|
|
|
wattrset(dbg.win_code,COLOR_PAIR(PAIR_GREEN_BLACK));
|
|
|
|
if (codeViewData.cursorPos==-1) {
|
|
|
|
codeViewData.cursorPos = i; // Set Cursor
|
|
|
|
codeViewData.cursorSeg = SegValue(cs);
|
|
|
|
codeViewData.cursorOfs = disEIP;
|
|
|
|
}
|
2009-05-02 23:43:00 +02:00
|
|
|
saveSel = (i == codeViewData.cursorPos);
|
2009-05-02 23:12:18 +02:00
|
|
|
} else if (i == codeViewData.cursorPos) {
|
|
|
|
wattrset(dbg.win_code,COLOR_PAIR(PAIR_BLACK_GREY));
|
|
|
|
codeViewData.cursorSeg = codeViewData.useCS;
|
|
|
|
codeViewData.cursorOfs = disEIP;
|
2009-05-02 23:43:00 +02:00
|
|
|
saveSel = true;
|
2009-05-02 23:20:05 +02:00
|
|
|
} else if (CBreakpoint::IsBreakpointDrawn(start)) {
|
2009-05-02 23:12:18 +02:00
|
|
|
wattrset(dbg.win_code,COLOR_PAIR(PAIR_GREY_RED));
|
|
|
|
} else {
|
|
|
|
wattrset(dbg.win_code,0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
|
|
|
|
Bitu drawsize=size=DasmI386(dline, start, disEIP, cpu.code.big);
|
|
|
|
bool toolarge = false;
|
2009-05-02 23:12:18 +02:00
|
|
|
mvwprintw(dbg.win_code,i,0,"%04X:%04X ",codeViewData.useCS,disEIP);
|
2009-05-02 23:43:00 +02:00
|
|
|
|
|
|
|
if (drawsize>10) { toolarge = true; drawsize = 9; };
|
|
|
|
for (c=0;c<drawsize;c++) wprintw(dbg.win_code,"%02X",mem_readb(start+c));
|
2009-05-03 00:28:34 +02:00
|
|
|
if (toolarge) { waddstr(dbg.win_code,".."); drawsize++; };
|
|
|
|
// Spacepad up to 20 characters
|
|
|
|
if(drawsize && (drawsize < 10)) {
|
|
|
|
line20[20 - drawsize*2] = 0;
|
|
|
|
waddstr(dbg.win_code,line20);
|
|
|
|
line20[20 - drawsize*2] = ' ';
|
|
|
|
} else waddstr(dbg.win_code,line20);
|
|
|
|
|
2009-05-02 23:35:44 +02:00
|
|
|
char* res = 0;
|
2009-05-02 23:43:00 +02:00
|
|
|
if (showExtend) res = AnalyzeInstruction(dline, saveSel);
|
2009-05-03 00:28:34 +02:00
|
|
|
// Spacepad it up to 28 characters
|
|
|
|
size_t dline_len = strlen(dline);
|
|
|
|
if(dline_len < 28) for (c = dline_len; c < 28;c++) dline[c] = ' '; dline[28] = 0;
|
2009-05-02 23:03:37 +02:00
|
|
|
waddstr(dbg.win_code,dline);
|
2009-05-03 00:28:34 +02:00
|
|
|
// Spacepad it up to 20 characters
|
|
|
|
size_t res_len = strlen(res);
|
|
|
|
if(res_len && (res_len < 21)) {
|
2009-05-02 23:35:44 +02:00
|
|
|
waddstr(dbg.win_code,res);
|
2009-05-03 00:28:34 +02:00
|
|
|
line20[20-res_len] = 0;
|
|
|
|
waddstr(dbg.win_code,line20);
|
|
|
|
line20[20-res_len] = ' ';
|
|
|
|
} else waddstr(dbg.win_code,line20);
|
|
|
|
|
2009-05-02 23:03:37 +02:00
|
|
|
start+=size;
|
2009-05-02 23:12:18 +02:00
|
|
|
disEIP+=size;
|
2009-05-02 23:03:37 +02:00
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
if (i==0) codeViewData.firstInstSize = size;
|
|
|
|
if (i==4) codeViewData.useEIPmid = disEIP;
|
2009-05-02 23:03:37 +02:00
|
|
|
}
|
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
codeViewData.useEIPlast = disEIP;
|
2009-05-02 23:03:37 +02:00
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
wattrset(dbg.win_code,0);
|
|
|
|
if (!debugging) {
|
2009-05-03 00:28:34 +02:00
|
|
|
mvwprintw(dbg.win_code,10,0,"(Running)",codeViewData.inputStr);
|
|
|
|
} else {
|
|
|
|
if(!*codeViewData.inputStr) { //Clear old commands
|
|
|
|
mvwprintw(dbg.win_code,10,0," ");
|
|
|
|
}
|
|
|
|
mvwprintw(dbg.win_code,10,0,"-> %s_ ",codeViewData.inputStr);
|
|
|
|
}
|
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
wrefresh(dbg.win_code);
|
2009-05-02 23:03:37 +02:00
|
|
|
}
|
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
static void SetCodeWinStart()
|
|
|
|
{
|
|
|
|
if ((SegValue(cs)==codeViewData.useCS) && (reg_eip>=codeViewData.useEIP) && (reg_eip<=codeViewData.useEIPlast)) {
|
|
|
|
// in valid window - scroll ?
|
|
|
|
if (reg_eip>=codeViewData.useEIPmid) codeViewData.useEIP += codeViewData.firstInstSize;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// totally out of range.
|
|
|
|
codeViewData.useCS = SegValue(cs);
|
|
|
|
codeViewData.useEIP = reg_eip;
|
|
|
|
}
|
|
|
|
codeViewData.cursorPos = -1; // Recalc Cursor position
|
|
|
|
};
|
2009-05-02 23:03:37 +02:00
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
/********************/
|
|
|
|
/* User input */
|
|
|
|
/********************/
|
|
|
|
|
|
|
|
Bit32u GetHexValue(char* str, char*& hex)
|
|
|
|
{
|
|
|
|
Bit32u value = 0;
|
2009-05-03 00:28:34 +02:00
|
|
|
Bit32u regval = 0;
|
2009-05-02 23:12:18 +02:00
|
|
|
hex = str;
|
|
|
|
while (*hex==' ') hex++;
|
2009-05-03 00:28:34 +02:00
|
|
|
if (strstr(hex,"EAX")==hex) { hex+=3; regval = reg_eax; };
|
|
|
|
if (strstr(hex,"EBX")==hex) { hex+=3; regval = reg_ebx; };
|
|
|
|
if (strstr(hex,"ECX")==hex) { hex+=3; regval = reg_ecx; };
|
|
|
|
if (strstr(hex,"EDX")==hex) { hex+=3; regval = reg_edx; };
|
|
|
|
if (strstr(hex,"ESI")==hex) { hex+=3; regval = reg_esi; };
|
|
|
|
if (strstr(hex,"EDI")==hex) { hex+=3; regval = reg_edi; };
|
|
|
|
if (strstr(hex,"EBP")==hex) { hex+=3; regval = reg_ebp; };
|
|
|
|
if (strstr(hex,"ESP")==hex) { hex+=3; regval = reg_esp; };
|
|
|
|
if (strstr(hex,"EIP")==hex) { hex+=3; regval = reg_eip; };
|
|
|
|
if (strstr(hex,"AX")==hex) { hex+=2; regval = reg_ax; };
|
|
|
|
if (strstr(hex,"BX")==hex) { hex+=2; regval = reg_bx; };
|
|
|
|
if (strstr(hex,"CX")==hex) { hex+=2; regval = reg_cx; };
|
|
|
|
if (strstr(hex,"DX")==hex) { hex+=2; regval = reg_dx; };
|
|
|
|
if (strstr(hex,"SI")==hex) { hex+=2; regval = reg_si; };
|
|
|
|
if (strstr(hex,"DI")==hex) { hex+=2; regval = reg_di; };
|
|
|
|
if (strstr(hex,"BP")==hex) { hex+=2; regval = reg_bp; };
|
|
|
|
if (strstr(hex,"SP")==hex) { hex+=2; regval = reg_sp; };
|
|
|
|
if (strstr(hex,"IP")==hex) { hex+=2; regval = reg_ip; };
|
|
|
|
if (strstr(hex,"CS")==hex) { hex+=2; regval = SegValue(cs); };
|
|
|
|
if (strstr(hex,"DS")==hex) { hex+=2; regval = SegValue(ds); };
|
|
|
|
if (strstr(hex,"ES")==hex) { hex+=2; regval = SegValue(es); };
|
|
|
|
if (strstr(hex,"FS")==hex) { hex+=2; regval = SegValue(fs); };
|
|
|
|
if (strstr(hex,"GS")==hex) { hex+=2; regval = SegValue(gs); };
|
|
|
|
if (strstr(hex,"SS")==hex) { hex+=2; regval = SegValue(ss); };
|
2009-05-02 23:12:18 +02:00
|
|
|
|
|
|
|
while (*hex) {
|
2009-05-03 00:28:34 +02:00
|
|
|
if ((*hex>='0') && (*hex<='9')) value = (value<<4)+*hex-'0';
|
|
|
|
else if ((*hex>='A') && (*hex<='F')) value = (value<<4)+*hex-'A'+10;
|
|
|
|
else {
|
|
|
|
if(*hex == '+') {hex++;return regval + value + GetHexValue(hex,hex); };
|
|
|
|
if(*hex == '-') {hex++;return regval + value - GetHexValue(hex,hex); };
|
|
|
|
break; // No valid char
|
|
|
|
}
|
2009-05-02 23:12:18 +02:00
|
|
|
hex++;
|
|
|
|
};
|
2009-05-03 00:28:34 +02:00
|
|
|
return regval + value;
|
2009-05-02 23:12:18 +02:00
|
|
|
};
|
2009-05-02 23:03:37 +02:00
|
|
|
|
2009-05-02 23:27:47 +02:00
|
|
|
bool ChangeRegister(char* str)
|
|
|
|
{
|
|
|
|
char* hex = str;
|
|
|
|
while (*hex==' ') hex++;
|
2009-05-02 23:43:00 +02:00
|
|
|
if (strstr(hex,"EAX")==hex) { hex+=3; reg_eax = GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"EBX")==hex) { hex+=3; reg_ebx = GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"ECX")==hex) { hex+=3; reg_ecx = GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"EDX")==hex) { hex+=3; reg_edx = GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"ESI")==hex) { hex+=3; reg_esi = GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"EDI")==hex) { hex+=3; reg_edi = GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"EBP")==hex) { hex+=3; reg_ebp = GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"ESP")==hex) { hex+=3; reg_esp = GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"EIP")==hex) { hex+=3; reg_eip = GetHexValue(hex,hex); } else
|
2009-05-02 23:53:27 +02:00
|
|
|
if (strstr(hex,"AX")==hex) { hex+=2; reg_ax = (Bit16u)GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"BX")==hex) { hex+=2; reg_bx = (Bit16u)GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"CX")==hex) { hex+=2; reg_cx = (Bit16u)GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"DX")==hex) { hex+=2; reg_dx = (Bit16u)GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"SI")==hex) { hex+=2; reg_si = (Bit16u)GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"DI")==hex) { hex+=2; reg_di = (Bit16u)GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"BP")==hex) { hex+=2; reg_bp = (Bit16u)GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"SP")==hex) { hex+=2; reg_sp = (Bit16u)GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"IP")==hex) { hex+=2; reg_ip = (Bit16u)GetHexValue(hex,hex); } else
|
|
|
|
if (strstr(hex,"CS")==hex) { hex+=2; SegSet16(cs,(Bit16u)GetHexValue(hex,hex)); } else
|
|
|
|
if (strstr(hex,"DS")==hex) { hex+=2; SegSet16(ds,(Bit16u)GetHexValue(hex,hex)); } else
|
|
|
|
if (strstr(hex,"ES")==hex) { hex+=2; SegSet16(es,(Bit16u)GetHexValue(hex,hex)); } else
|
|
|
|
if (strstr(hex,"FS")==hex) { hex+=2; SegSet16(fs,(Bit16u)GetHexValue(hex,hex)); } else
|
|
|
|
if (strstr(hex,"GS")==hex) { hex+=2; SegSet16(gs,(Bit16u)GetHexValue(hex,hex)); } else
|
|
|
|
if (strstr(hex,"SS")==hex) { hex+=2; SegSet16(ss,(Bit16u)GetHexValue(hex,hex)); } else
|
2009-05-02 23:43:00 +02:00
|
|
|
if (strstr(hex,"AF")==hex) { hex+=2; SETFLAGBIT(AF,GetHexValue(hex,hex)); } else
|
|
|
|
if (strstr(hex,"CF")==hex) { hex+=2; SETFLAGBIT(CF,GetHexValue(hex,hex)); } else
|
2009-05-03 00:18:08 +02:00
|
|
|
if (strstr(hex,"DF")==hex) { hex+=2; SETFLAGBIT(DF,GetHexValue(hex,hex)); } else
|
2009-05-02 23:43:00 +02:00
|
|
|
if (strstr(hex,"IF")==hex) { hex+=2; SETFLAGBIT(IF,GetHexValue(hex,hex)); } else
|
2009-05-03 00:28:34 +02:00
|
|
|
if (strstr(hex,"OF")==hex) { hex+=2; SETFLAGBIT(OF,GetHexValue(hex,hex)); } else
|
|
|
|
if (strstr(hex,"ZF")==hex) { hex+=2; SETFLAGBIT(ZF,GetHexValue(hex,hex)); } else
|
|
|
|
if (strstr(hex,"PF")==hex) { hex+=2; SETFLAGBIT(PF,GetHexValue(hex,hex)); } else
|
|
|
|
if (strstr(hex,"SF")==hex) { hex+=2; SETFLAGBIT(SF,GetHexValue(hex,hex)); } else
|
2009-05-03 00:18:08 +02:00
|
|
|
{ return false; };
|
2009-05-02 23:27:47 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
bool ParseCommand(char* str) {
|
2009-05-02 23:12:18 +02:00
|
|
|
char* found = str;
|
2009-05-02 23:35:44 +02:00
|
|
|
for(char* idx = found;*idx != 0; idx++)
|
|
|
|
*idx = toupper(*idx);
|
|
|
|
|
|
|
|
found = trim(found);
|
2009-05-03 00:28:34 +02:00
|
|
|
string s_found(found);
|
|
|
|
istringstream stream(s_found);
|
|
|
|
string command;
|
|
|
|
stream >> command;
|
|
|
|
string::size_type next = s_found.find_first_not_of(' ',command.size());
|
|
|
|
if(next == string::npos) next = command.size();
|
|
|
|
(s_found.erase)(0,next);
|
|
|
|
found = const_cast<char*>(s_found.c_str());
|
|
|
|
|
|
|
|
if (command == "MEMDUMP") { // Dump memory to file
|
2009-05-02 23:53:27 +02:00
|
|
|
Bit16u seg = (Bit16u)GetHexValue(found,found); found++;
|
2009-05-02 23:35:44 +02:00
|
|
|
Bit32u ofs = GetHexValue(found,found); found++;
|
|
|
|
Bit32u num = GetHexValue(found,found); found++;
|
|
|
|
SaveMemory(seg,ofs,num);
|
|
|
|
return true;
|
|
|
|
};
|
2009-05-03 00:28:34 +02:00
|
|
|
|
|
|
|
if (command == "MEMDUMPBIN") { // Dump memory to file bineary
|
2009-05-03 00:18:08 +02:00
|
|
|
Bit16u seg = (Bit16u)GetHexValue(found,found); found++;
|
|
|
|
Bit32u ofs = GetHexValue(found,found); found++;
|
|
|
|
Bit32u num = GetHexValue(found,found); found++;
|
|
|
|
SaveMemoryBin(seg,ofs,num);
|
|
|
|
return true;
|
|
|
|
};
|
2009-05-02 23:35:44 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "IV") { // Insert variable
|
2009-05-02 23:53:27 +02:00
|
|
|
Bit16u seg = (Bit16u)GetHexValue(found,found); found++;
|
|
|
|
Bit32u ofs = (Bit16u)GetHexValue(found,found); found++;
|
2009-05-02 23:35:44 +02:00
|
|
|
char name[16];
|
|
|
|
for (int i=0; i<16; i++) {
|
2009-05-03 00:28:34 +02:00
|
|
|
if (found[i] && (found[i]!=' ')) name[i] = found[i];
|
2009-05-02 23:35:44 +02:00
|
|
|
else { name[i] = 0; break; };
|
|
|
|
};
|
|
|
|
name[15] = 0;
|
2009-05-03 00:28:34 +02:00
|
|
|
|
|
|
|
if(!name[0]) return false;
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Created debug var %s at %04X:%04X\n",name,seg,ofs);
|
2009-05-02 23:43:00 +02:00
|
|
|
CDebugVar::InsertVariable(name,GetAddress(seg,ofs));
|
2009-05-02 23:35:44 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (command == "SV") { // Save variables
|
2009-05-02 23:35:44 +02:00
|
|
|
char name[13];
|
|
|
|
for (int i=0; i<12; i++) {
|
2009-05-03 00:28:34 +02:00
|
|
|
if (found[i] && (found[i]!=' ')) name[i] = found[i];
|
2009-05-02 23:35:44 +02:00
|
|
|
else { name[i] = 0; break; };
|
|
|
|
};
|
2009-05-03 00:28:34 +02:00
|
|
|
name[12] = 0;
|
|
|
|
if(!name[0]) return false;
|
|
|
|
DEBUG_ShowMsg("DEBUG: Variable list save (%s) : %s.\n",name,(CDebugVar::SaveVars(name)?"ok":"failure"));
|
2009-05-02 23:35:44 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
2009-05-02 23:35:44 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "LV") { // load variables
|
2009-05-02 23:35:44 +02:00
|
|
|
char name[13];
|
|
|
|
for (int i=0; i<12; i++) {
|
2009-05-03 00:28:34 +02:00
|
|
|
if (found[i] && (found[i]!=' ')) name[i] = found[i];
|
2009-05-02 23:35:44 +02:00
|
|
|
else { name[i] = 0; break; };
|
|
|
|
};
|
2009-05-03 00:28:34 +02:00
|
|
|
name[12] = 0;
|
|
|
|
if(!name[0]) return false;
|
|
|
|
DEBUG_ShowMsg("DEBUG: Variable list load (%s) : %s.\n",name,(CDebugVar::SaveVars(name)?"ok":"failure"));
|
2009-05-02 23:35:44 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (command == "SR") { // Set register value
|
|
|
|
DEBUG_ShowMsg("DEBUG: Set Register success.\n",(ChangeRegister(found)?"success":"failure"));
|
2009-05-03 00:02:15 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (command == "SM") { // Set memory with following values
|
2009-05-03 00:02:15 +02:00
|
|
|
Bit16u seg = (Bit16u)GetHexValue(found,found); found++;
|
|
|
|
Bit32u ofs = GetHexValue(found,found); found++;
|
|
|
|
Bit16u count = 0;
|
|
|
|
while (*found) {
|
|
|
|
while (*found==' ') found++;
|
|
|
|
if (*found) {
|
2009-05-03 00:28:34 +02:00
|
|
|
Bit8u value = (Bit8u)GetHexValue(found,found);
|
|
|
|
if(*found) found++;
|
2009-05-03 00:02:15 +02:00
|
|
|
mem_writeb(GetAddress(seg,ofs+count),value);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
};
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Memory changed.\n");
|
2009-05-03 00:02:15 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
2009-05-02 23:35:44 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "BP") { // Add new breakpoint
|
2009-05-02 23:53:27 +02:00
|
|
|
Bit16u seg = (Bit16u)GetHexValue(found,found);found++; // skip ":"
|
2009-05-02 23:12:18 +02:00
|
|
|
Bit32u ofs = GetHexValue(found,found);
|
2009-05-02 23:20:05 +02:00
|
|
|
CBreakpoint::AddBreakpoint(seg,ofs,false);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Set breakpoint at %04X:%04X\n",seg,ofs);
|
2009-05-02 23:12:18 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
2009-05-02 23:27:47 +02:00
|
|
|
#if C_HEAVY_DEBUG
|
2009-05-03 00:28:34 +02:00
|
|
|
|
|
|
|
if (command == "BPM") { // Add new breakpoint
|
2009-05-02 23:53:27 +02:00
|
|
|
Bit16u seg = (Bit16u)GetHexValue(found,found);found++; // skip ":"
|
2009-05-02 23:27:47 +02:00
|
|
|
Bit32u ofs = GetHexValue(found,found);
|
|
|
|
CBreakpoint::AddMemBreakpoint(seg,ofs);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Set memory breakpoint at %04X:%04X\n",seg,ofs);
|
2009-05-02 23:27:47 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (command == "BPPM") { // Add new breakpoint
|
2009-05-02 23:53:27 +02:00
|
|
|
Bit16u seg = (Bit16u)GetHexValue(found,found);found++; // skip ":"
|
|
|
|
Bit32u ofs = GetHexValue(found,found);
|
|
|
|
CBreakpoint* bp = CBreakpoint::AddMemBreakpoint(seg,ofs);
|
2009-05-03 00:28:34 +02:00
|
|
|
if (bp) {
|
2009-05-03 00:18:08 +02:00
|
|
|
bp->SetType(BKPNT_MEMORY_PROT);
|
|
|
|
DEBUG_ShowMsg("DEBUG: Set prot-mode memory breakpoint at %04X:%08X\n",seg,ofs);
|
|
|
|
}
|
2009-05-02 23:53:27 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (command == "BPLM") { // Add new breakpoint
|
|
|
|
Bit32u ofs = GetHexValue(found,found);
|
2009-05-02 23:53:27 +02:00
|
|
|
CBreakpoint* bp = CBreakpoint::AddMemBreakpoint(0,ofs);
|
|
|
|
if (bp) bp->SetType(BKPNT_MEMORY_LINEAR);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Set linear memory breakpoint at %08X\n",ofs);
|
2009-05-02 23:53:27 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
2009-05-02 23:27:47 +02:00
|
|
|
#endif
|
2009-05-03 00:28:34 +02:00
|
|
|
|
|
|
|
if (command == "BPINT") { // Add Interrupt Breakpoint
|
|
|
|
Bit8u intNr = (Bit8u)GetHexValue(found,found);
|
|
|
|
bool all = !(*found);found++;
|
2009-05-02 23:53:27 +02:00
|
|
|
Bit8u valAH = (Bit8u)GetHexValue(found,found);
|
2009-05-03 00:28:34 +02:00
|
|
|
if ((valAH==0x00) && (*found=='*' || all)) {
|
2009-05-02 23:20:05 +02:00
|
|
|
CBreakpoint::AddIntBreakpoint(intNr,BPINT_ALL,false);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Set interrupt breakpoint at INT %02X\n",intNr);
|
2009-05-02 23:12:18 +02:00
|
|
|
} else {
|
2009-05-02 23:20:05 +02:00
|
|
|
CBreakpoint::AddIntBreakpoint(intNr,valAH,false);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Set interrupt breakpoint at INT %02X AH=%02X\n",intNr,valAH);
|
2009-05-02 23:12:18 +02:00
|
|
|
}
|
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (command == "BPLIST") {
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("Breakpoint list:\n");
|
|
|
|
DEBUG_ShowMsg("-------------------------------------------------------------------------\n");
|
2009-05-02 23:20:05 +02:00
|
|
|
CBreakpoint::ShowList();
|
2009-05-02 23:12:18 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "BPDEL") { // Delete Breakpoints
|
2009-05-02 23:53:27 +02:00
|
|
|
Bit8u bpNr = (Bit8u)GetHexValue(found,found);
|
2009-05-02 23:12:18 +02:00
|
|
|
if ((bpNr==0x00) && (*found=='*')) { // Delete all
|
2009-05-02 23:20:05 +02:00
|
|
|
CBreakpoint::DeleteAll();
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Breakpoints deleted.\n");
|
2009-05-02 23:12:18 +02:00
|
|
|
} else {
|
|
|
|
// delete single breakpoint
|
2009-05-02 23:20:05 +02:00
|
|
|
CBreakpoint::DeleteByIndex(bpNr);
|
2009-05-02 23:03:37 +02:00
|
|
|
}
|
2009-05-02 23:12:18 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (command == "C") { // Set code overview
|
2009-05-02 23:53:27 +02:00
|
|
|
Bit16u codeSeg = (Bit16u)GetHexValue(found,found); found++;
|
2009-05-02 23:12:18 +02:00
|
|
|
Bit32u codeOfs = GetHexValue(found,found);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Set code overview to %04X:%04X\n",codeSeg,codeOfs);
|
2009-05-02 23:12:18 +02:00
|
|
|
codeViewData.useCS = codeSeg;
|
|
|
|
codeViewData.useEIP = codeOfs;
|
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (command == "D") { // Set data overview
|
2009-05-02 23:53:27 +02:00
|
|
|
dataSeg = (Bit16u)GetHexValue(found,found); found++;
|
2009-05-02 23:12:18 +02:00
|
|
|
dataOfs = GetHexValue(found,found);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Set data overview to %04X:%04X\n",dataSeg,dataOfs);
|
2009-05-02 23:12:18 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
2009-05-02 23:53:27 +02:00
|
|
|
#if C_HEAVY_DEBUG
|
2009-05-03 00:18:08 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "LOG") { // Create Cpu normal log file
|
|
|
|
cpuLogType = 1;
|
|
|
|
command = "logcode";
|
2009-05-03 00:18:08 +02:00
|
|
|
}
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "LOGS") { // Create Cpu short log file
|
2009-05-03 00:18:08 +02:00
|
|
|
cpuLogType = 0;
|
2009-05-03 00:28:34 +02:00
|
|
|
command = "logcode";
|
|
|
|
}
|
2009-05-03 00:18:08 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "LOGL") { // Create Cpu long log file
|
|
|
|
cpuLogType = 2;
|
|
|
|
command = "logcode";
|
2009-05-03 00:18:08 +02:00
|
|
|
}
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "logcode") { //Shared code between all logs
|
2009-05-03 00:18:08 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Starting log\n");
|
2009-05-03 00:28:34 +02:00
|
|
|
cpuLogFile.open("LOGCPU.TXT");
|
|
|
|
if (!cpuLogFile.is_open()) {
|
2009-05-03 00:18:08 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Logfile couldn't be created.\n");
|
2009-05-02 23:53:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
2009-05-03 00:28:34 +02:00
|
|
|
//Initialize log object
|
|
|
|
cpuLogFile << hex << noshowbase << setfill('0') << uppercase;
|
2009-05-02 23:53:27 +02:00
|
|
|
cpuLog = true;
|
|
|
|
cpuLogCounter = GetHexValue(found,found);
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
debugging = false;
|
2009-05-02 23:53:27 +02:00
|
|
|
CBreakpoint::ActivateBreakpoints(SegPhys(cs)+reg_eip,true);
|
|
|
|
ignoreAddressOnce = SegPhys(cs)+reg_eip;
|
|
|
|
DOSBOX_SetNormalLoop();
|
2009-05-02 23:20:05 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
2009-05-02 23:53:27 +02:00
|
|
|
#endif
|
2009-05-03 00:28:34 +02:00
|
|
|
|
|
|
|
if (command == "INTT") { //trace int.
|
2009-05-02 23:53:27 +02:00
|
|
|
Bit8u intNr = (Bit8u)GetHexValue(found,found);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Tracing INT %02X\n",intNr);
|
2009-05-02 23:53:27 +02:00
|
|
|
CPU_HW_Interrupt(intNr);
|
2009-05-02 23:20:05 +02:00
|
|
|
SetCodeWinStart();
|
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (command == "INT") { // start int.
|
2009-05-02 23:53:27 +02:00
|
|
|
Bit8u intNr = (Bit8u)GetHexValue(found,found);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Starting INT %02X\n",intNr);
|
2009-05-03 00:28:34 +02:00
|
|
|
CBreakpoint::AddBreakpoint(SegValue(cs),reg_eip, true);
|
2009-05-02 23:20:05 +02:00
|
|
|
CBreakpoint::ActivateBreakpoints(SegPhys(cs)+reg_eip-1,true);
|
2009-05-03 00:28:34 +02:00
|
|
|
debugging = false;
|
2009-05-02 23:20:05 +02:00
|
|
|
DrawCode();
|
|
|
|
DOSBOX_SetNormalLoop();
|
2009-05-02 23:53:27 +02:00
|
|
|
CPU_HW_Interrupt(intNr);
|
2009-05-02 23:20:05 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (command == "SELINFO") {
|
|
|
|
while (found[0] == ' ') found++;
|
2009-05-02 23:43:00 +02:00
|
|
|
char out1[200],out2[200];
|
|
|
|
GetDescriptorInfo(found,out1,out2);
|
2009-05-03 00:28:34 +02:00
|
|
|
DEBUG_ShowMsg("SelectorInfo %s:\n%s\n%s\n",found,out1,out2);
|
2009-05-02 23:43:00 +02:00
|
|
|
};
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "GDT") {LogGDT(); return true;}
|
|
|
|
|
|
|
|
if (command == "LDT") {LogLDT(); return true;}
|
|
|
|
|
|
|
|
if (command == "IDT") {LogIDT(); return true;}
|
|
|
|
|
|
|
|
if (command == "PAGING") {LogPages(found); return true;}
|
2009-05-03 00:18:08 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "CPU") {LogCPUInfo(); return true;}
|
2009-05-03 00:18:08 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "INTVEC") {
|
|
|
|
if (found[0] != 0) {
|
2009-05-02 23:53:27 +02:00
|
|
|
OutputVecTable(found);
|
2009-05-03 00:28:34 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2009-05-02 23:53:27 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "INTHAND") {
|
|
|
|
if (found[0] != 0) {
|
2009-05-02 23:53:27 +02:00
|
|
|
Bit8u intNr = (Bit8u)GetHexValue(found,found);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Set code overview to interrupt handler %X\n",intNr);
|
2009-05-02 23:53:27 +02:00
|
|
|
codeViewData.useCS = mem_readw(intNr*4+2);
|
|
|
|
codeViewData.useEIP = mem_readw(intNr*4);
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if(command == "EXTEND") { //Toggle additional data.
|
|
|
|
showExtend = !showExtend;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
if(command == "TIMERIRQ") { //Start a timer irq
|
|
|
|
DEBUG_RaiseTimerIrq();
|
|
|
|
DEBUG_ShowMsg("Debug: Timer Int started.\n");
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:53:27 +02:00
|
|
|
|
2009-05-02 23:27:47 +02:00
|
|
|
#if C_HEAVY_DEBUG
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "HEAVYLOG") { // Create Cpu log file
|
2009-05-02 23:27:47 +02:00
|
|
|
logHeavy = !logHeavy;
|
2009-05-03 00:28:34 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Heavy cpu logging %s.\n",logHeavy?"on":"off");
|
2009-05-02 23:27:47 +02:00
|
|
|
return true;
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (command == "ZEROPROTECT") { //toggle zero protection
|
|
|
|
zeroProtect = !zeroProtect;
|
|
|
|
DEBUG_ShowMsg("DEBUG: Zero code execution protection %s.\n",zeroProtect?"on":"off");
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:27:47 +02:00
|
|
|
#endif
|
2009-05-03 00:28:34 +02:00
|
|
|
if (command == "HELP" || command == "?") {
|
|
|
|
DEBUG_ShowMsg("Debugger commands (enter all values in hex or as register):\n");
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("--------------------------------------------------------------------------\n");
|
|
|
|
DEBUG_ShowMsg("F5 - Run.\n");
|
|
|
|
DEBUG_ShowMsg("F9 - Set/Remove breakpoint.\n");
|
|
|
|
DEBUG_ShowMsg("F10/F11 - Step over / trace into instruction.\n");
|
2009-05-03 00:28:34 +02:00
|
|
|
DEBUG_ShowMsg("ALT + D/E/S/X/B - Set data view to DS:SI/ES:DI/SS:SP/DS:DX/ES:BX.\n");
|
|
|
|
DEBUG_ShowMsg("Escape - clear input line.");
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("Up/Down - Move code view cursor.\n");
|
2009-05-03 00:28:34 +02:00
|
|
|
DEBUG_ShowMsg("Page Up/Down - Scroll data view.\n");
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("BP [segment]:[offset] - Set breakpoint.\n");
|
|
|
|
DEBUG_ShowMsg("BPINT [intNr] * - Set interrupt breakpoint.\n");
|
|
|
|
DEBUG_ShowMsg("BPINT [intNr] [ah] - Set interrupt breakpoint with ah.\n");
|
2009-05-02 23:27:47 +02:00
|
|
|
#if C_HEAVY_DEBUG
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("BPM [segment]:[offset] - Set memory breakpoint (memory change).\n");
|
|
|
|
DEBUG_ShowMsg("BPPM [selector]:[offset]- Set pmode-memory breakpoint (memory change).\n");
|
|
|
|
DEBUG_ShowMsg("BPLM [linear address] - Set linear memory breakpoint (memory change).\n");
|
2009-05-02 23:27:47 +02:00
|
|
|
#endif
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("BPLIST - List breakpoints.\n");
|
|
|
|
DEBUG_ShowMsg("BPDEL [bpNr] / * - Delete breakpoint nr / all.\n");
|
|
|
|
DEBUG_ShowMsg("C / D [segment]:[offset] - Set code / data view address.\n");
|
|
|
|
DEBUG_ShowMsg("INT [nr] / INTT [nr] - Execute / Trace into interrupt.\n");
|
2009-05-02 23:27:47 +02:00
|
|
|
#if C_HEAVY_DEBUG
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("LOG [num] - Write cpu log file.\n");
|
2009-05-03 00:18:08 +02:00
|
|
|
DEBUG_ShowMsg("LOGS/LOGL [num] - Write short/long cpu log file.\n");
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("HEAVYLOG - Enable/Disable automatic cpu when dosbox exits.\n");
|
2009-05-03 00:28:34 +02:00
|
|
|
DEBUG_ShowMsg("ZEROPROTECT - Enable/Disable zero code execution detecion.\n");
|
2009-05-02 23:27:47 +02:00
|
|
|
#endif
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("SR [reg] [value] - Set register value.\n");
|
|
|
|
DEBUG_ShowMsg("SM [seg]:[off] [val] [.]..- Set memory with following values.\n");
|
2009-05-02 23:35:44 +02:00
|
|
|
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("IV [seg]:[off] [name] - Create var name for memory address.\n");
|
|
|
|
DEBUG_ShowMsg("SV [filename] - Save var list in file.\n");
|
2009-05-03 00:18:08 +02:00
|
|
|
DEBUG_ShowMsg("LV [filename] - Load var list from file.\n");
|
2009-05-02 23:35:44 +02:00
|
|
|
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("MEMDUMP [seg]:[off] [len] - Write memory to file memdump.txt.\n");
|
2009-05-03 00:18:08 +02:00
|
|
|
DEBUG_ShowMsg("MEMDUMPBIN [s]:[o] [len] - Write memory to file memdump.bin.\n");
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("SELINFO [segName] - Show selector info.\n");
|
2009-05-02 23:53:27 +02:00
|
|
|
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("INTVEC [filename] - Writes interrupt vector table to file.\n");
|
|
|
|
DEBUG_ShowMsg("INTHAND [intNum] - Set code view to interrupt handler.\n");
|
2009-05-02 23:53:27 +02:00
|
|
|
|
2009-05-03 00:18:08 +02:00
|
|
|
DEBUG_ShowMsg("CPU - Display CPU status information.\n");
|
|
|
|
DEBUG_ShowMsg("GDT - Lists descriptors of the GDT.\n");
|
|
|
|
DEBUG_ShowMsg("LDT - Lists descriptors of the LDT.\n");
|
|
|
|
DEBUG_ShowMsg("IDT - Lists descriptors of the IDT.\n");
|
|
|
|
DEBUG_ShowMsg("PAGING [page] - Display content of page table.\n");
|
2009-05-03 00:28:34 +02:00
|
|
|
DEBUG_ShowMsg("EXTEND - Toggle additional info.\n");
|
|
|
|
DEBUG_ShowMsg("TIMERIRQ - Run the system timer.\n");
|
2009-05-03 00:18:08 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
DEBUG_ShowMsg("HELP - Help\n");
|
2009-05-02 23:35:44 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
return true;
|
|
|
|
};
|
2009-05-02 23:03:37 +02:00
|
|
|
return false;
|
2009-05-02 23:12:18 +02:00
|
|
|
};
|
2009-05-02 23:03:37 +02:00
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
char* AnalyzeInstruction(char* inst, bool saveSelector)
|
2009-05-02 23:35:44 +02:00
|
|
|
{
|
|
|
|
static char result[256];
|
|
|
|
|
|
|
|
char instu[256];
|
|
|
|
char prefix[3];
|
|
|
|
Bit16u seg;
|
|
|
|
|
|
|
|
strcpy(instu,inst);
|
|
|
|
upcase(instu);
|
|
|
|
|
|
|
|
result[0] = 0;
|
|
|
|
char* pos = strchr(instu,'[');
|
|
|
|
if (pos) {
|
|
|
|
// Segment prefix ?
|
|
|
|
if (*(pos-1)==':') {
|
|
|
|
char* segpos = pos-3;
|
|
|
|
prefix[0] = tolower(*segpos);
|
|
|
|
prefix[1] = tolower(*(segpos+1));
|
|
|
|
prefix[2] = 0;
|
2009-05-02 23:53:27 +02:00
|
|
|
seg = (Bit16u)GetHexValue(segpos,segpos);
|
2009-05-02 23:35:44 +02:00
|
|
|
} else {
|
|
|
|
if (strstr(pos,"SP") || strstr(pos,"BP")) {
|
|
|
|
seg = SegValue(ss);
|
|
|
|
strcpy(prefix,"ss");
|
|
|
|
} else {
|
|
|
|
seg = SegValue(ds);
|
|
|
|
strcpy(prefix,"ds");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
Bit32u adr = GetHexValue(pos,pos);
|
|
|
|
while (*pos!=']') {
|
|
|
|
if (*pos=='+') {
|
|
|
|
pos++;
|
|
|
|
adr += GetHexValue(pos,pos);
|
|
|
|
} else if (*pos=='-') {
|
|
|
|
pos++;
|
|
|
|
adr -= GetHexValue(pos,pos);
|
|
|
|
} else
|
|
|
|
pos++;
|
|
|
|
};
|
2009-05-02 23:43:00 +02:00
|
|
|
Bit32u address = GetAddress(seg,adr);
|
2009-05-02 23:53:27 +02:00
|
|
|
if (!(paging.tlb.handler[address >> 12]->flags & PFLAG_INIT)) {
|
|
|
|
static char outmask[] = "%s:[%04X]=%02X";
|
|
|
|
|
|
|
|
if (cpu.pmode) outmask[6] = '8';
|
|
|
|
switch (DasmLastOperandSize()) {
|
|
|
|
case 8 : { Bit8u val = mem_readb(address);
|
|
|
|
outmask[12] = '2';
|
|
|
|
sprintf(result,outmask,prefix,adr,val);
|
|
|
|
} break;
|
|
|
|
case 16: { Bit16u val = mem_readw(address);
|
|
|
|
outmask[12] = '4';
|
|
|
|
sprintf(result,outmask,prefix,adr,val);
|
|
|
|
} break;
|
|
|
|
case 32: { Bit32u val = mem_readd(address);
|
|
|
|
outmask[12] = '8';
|
|
|
|
sprintf(result,outmask,prefix,adr,val);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sprintf(result,"[illegal]");
|
2009-05-02 23:35:44 +02:00
|
|
|
}
|
|
|
|
// Variable found ?
|
2009-05-02 23:43:00 +02:00
|
|
|
CDebugVar* var = CDebugVar::FindVar(address);
|
2009-05-02 23:35:44 +02:00
|
|
|
if (var) {
|
|
|
|
// Replace occurance
|
|
|
|
char* pos1 = strchr(inst,'[');
|
|
|
|
char* pos2 = strchr(inst,']');
|
|
|
|
if (pos1 && pos2) {
|
|
|
|
char temp[256];
|
|
|
|
strcpy(temp,pos2); // save end
|
|
|
|
pos1++; *pos1 = 0; // cut after '['
|
|
|
|
strcat(inst,var->GetName()); // add var name
|
|
|
|
strcat(inst,temp); // add end
|
|
|
|
};
|
|
|
|
};
|
2009-05-02 23:43:00 +02:00
|
|
|
// show descriptor info, if available
|
|
|
|
if ((cpu.pmode) && saveSelector) {
|
|
|
|
strcpy(curSelectorName,prefix);
|
|
|
|
};
|
2009-05-02 23:35:44 +02:00
|
|
|
};
|
2009-05-02 23:53:27 +02:00
|
|
|
// If it is a callback add additional info
|
|
|
|
pos = strstr(inst,"callback");
|
|
|
|
if (pos) {
|
|
|
|
pos += 9;
|
|
|
|
Bitu nr = GetHexValue(pos,pos);
|
|
|
|
const char* descr = CALLBACK_GetDescription(nr);
|
|
|
|
if (descr) {
|
|
|
|
strcat(inst," ("); strcat(inst,descr); strcat(inst,")");
|
|
|
|
}
|
|
|
|
};
|
2009-05-03 00:08:43 +02:00
|
|
|
// Must be a jump
|
|
|
|
if (instu[0] == 'J')
|
|
|
|
{
|
2009-05-03 00:18:08 +02:00
|
|
|
bool jmp = false;
|
2009-05-03 00:08:43 +02:00
|
|
|
switch (instu[1]) {
|
2009-05-03 00:18:08 +02:00
|
|
|
case 'A' : { jmp = (get_CF()?false:true) && (get_ZF()?false:true); // JA
|
2009-05-03 00:08:43 +02:00
|
|
|
} break;
|
|
|
|
case 'B' : { if (instu[2] == 'E') {
|
2009-05-03 00:28:34 +02:00
|
|
|
jmp = (get_CF()?true:false) || (get_ZF()?true:false); // JBE
|
2009-05-03 00:08:43 +02:00
|
|
|
} else {
|
2009-05-03 00:18:08 +02:00
|
|
|
jmp = get_CF()?true:false; // JB
|
2009-05-03 00:08:43 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case 'C' : { if (instu[2] == 'X') {
|
|
|
|
jmp = reg_cx == 0; // JCXZ
|
|
|
|
} else {
|
2009-05-03 00:18:08 +02:00
|
|
|
jmp = get_CF()?true:false; // JC
|
2009-05-03 00:08:43 +02:00
|
|
|
}
|
|
|
|
} break;
|
2009-05-03 00:18:08 +02:00
|
|
|
case 'E' : { jmp = get_ZF()?true:false; // JE
|
2009-05-03 00:08:43 +02:00
|
|
|
} break;
|
|
|
|
case 'G' : { if (instu[2] == 'E') {
|
2009-05-03 00:28:34 +02:00
|
|
|
jmp = (get_SF()?true:false)==(get_OF()?true:false); // JGE
|
2009-05-03 00:08:43 +02:00
|
|
|
} else {
|
2009-05-03 00:28:34 +02:00
|
|
|
jmp = (get_ZF()?false:true) && ((get_SF()?true:false)==(get_OF()?true:false)); // JG
|
2009-05-03 00:08:43 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case 'L' : { if (instu[2] == 'E') {
|
2009-05-03 00:28:34 +02:00
|
|
|
jmp = (get_ZF()?true:false) || ((get_SF()?true:false)!=(get_OF()?true:false)); // JLE
|
2009-05-03 00:08:43 +02:00
|
|
|
} else {
|
2009-05-03 00:28:34 +02:00
|
|
|
jmp = (get_SF()?true:false)!=(get_OF()?true:false); // JL
|
2009-05-03 00:08:43 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case 'M' : { jmp = true; // JMP
|
|
|
|
} break;
|
|
|
|
case 'N' : { switch (instu[2]) {
|
|
|
|
case 'B' :
|
2009-05-03 00:18:08 +02:00
|
|
|
case 'C' : { jmp = get_CF()?false:true; // JNB / JNC
|
2009-05-03 00:08:43 +02:00
|
|
|
} break;
|
2009-05-03 00:18:08 +02:00
|
|
|
case 'E' : { jmp = get_ZF()?false:true; // JNE
|
2009-05-03 00:08:43 +02:00
|
|
|
} break;
|
2009-05-03 00:18:08 +02:00
|
|
|
case 'O' : { jmp = get_OF()?false:true; // JNO
|
2009-05-03 00:08:43 +02:00
|
|
|
} break;
|
2009-05-03 00:18:08 +02:00
|
|
|
case 'P' : { jmp = get_PF()?false:true; // JNP
|
2009-05-03 00:08:43 +02:00
|
|
|
} break;
|
2009-05-03 00:18:08 +02:00
|
|
|
case 'S' : { jmp = get_SF()?false:true; // JNS
|
2009-05-03 00:08:43 +02:00
|
|
|
} break;
|
2009-05-03 00:18:08 +02:00
|
|
|
case 'Z' : { jmp = get_ZF()?false:true; // JNZ
|
2009-05-03 00:08:43 +02:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} break;
|
2009-05-03 00:28:34 +02:00
|
|
|
case 'O' : { jmp = get_OF()?true:false; // JO
|
2009-05-03 00:08:43 +02:00
|
|
|
} break;
|
|
|
|
case 'P' : { if (instu[2] == 'O') {
|
2009-05-03 00:18:08 +02:00
|
|
|
jmp = get_PF()?false:true; // JPO
|
2009-05-03 00:08:43 +02:00
|
|
|
} else {
|
2009-05-03 00:18:08 +02:00
|
|
|
jmp = get_SF()?true:false; // JP / JPE
|
2009-05-03 00:08:43 +02:00
|
|
|
}
|
|
|
|
} break;
|
2009-05-03 00:18:08 +02:00
|
|
|
case 'S' : { jmp = get_SF()?true:false; // JS
|
2009-05-03 00:08:43 +02:00
|
|
|
} break;
|
2009-05-03 00:18:08 +02:00
|
|
|
case 'Z' : { jmp = get_ZF()?true:false; // JZ
|
2009-05-03 00:08:43 +02:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (jmp) {
|
|
|
|
pos = strchr(instu,'+');
|
|
|
|
if (pos) {
|
|
|
|
strcpy(result,"(down)");
|
|
|
|
} else {
|
|
|
|
strcpy(result,"(up)");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sprintf(result,"(no jmp)");
|
|
|
|
}
|
|
|
|
}
|
2009-05-02 23:35:44 +02:00
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-02 23:03:37 +02:00
|
|
|
Bit32u DEBUG_CheckKeys(void) {
|
2009-05-02 23:53:27 +02:00
|
|
|
Bits ret=0;
|
2009-05-03 00:28:34 +02:00
|
|
|
int key=getch();
|
2009-05-02 23:03:37 +02:00
|
|
|
if (key>0) {
|
2009-05-03 00:28:34 +02:00
|
|
|
#if defined(WIN32) && defined(__PDCURSES__)
|
|
|
|
switch (key) {
|
|
|
|
case ALT_D:
|
|
|
|
if (ungetch('D') != ERR) key=27;
|
2009-05-02 23:03:37 +02:00
|
|
|
break;
|
2009-05-03 00:28:34 +02:00
|
|
|
case ALT_E:
|
|
|
|
if (ungetch('E') != ERR) key=27;
|
2009-05-02 23:03:37 +02:00
|
|
|
break;
|
2009-05-03 00:28:34 +02:00
|
|
|
case ALT_X:
|
|
|
|
if (ungetch('X') != ERR) key=27;
|
2009-05-02 23:03:37 +02:00
|
|
|
break;
|
2009-05-03 00:28:34 +02:00
|
|
|
case ALT_B:
|
|
|
|
if (ungetch('B') != ERR) key=27;
|
2009-05-02 23:03:37 +02:00
|
|
|
break;
|
2009-05-03 00:28:34 +02:00
|
|
|
case ALT_S:
|
|
|
|
if (ungetch('S') != ERR) key=27;
|
2009-05-02 23:03:37 +02:00
|
|
|
break;
|
2009-05-03 00:28:34 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
switch (toupper(key)) {
|
|
|
|
case 27: // escape (a bit slow): Clears line. and processes alt commands.
|
|
|
|
key=getch();
|
|
|
|
if(key < 0) { //Purely escape Clear line
|
|
|
|
codeViewData.inputStr[0] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(toupper(key)) {
|
|
|
|
case 'D' : // ALT - D: DS:SI
|
|
|
|
dataSeg = SegValue(ds);
|
|
|
|
if (cpu.pmode && !(reg_flags & FLAG_VM)) dataOfs = reg_esi;
|
|
|
|
else dataOfs = reg_si;
|
|
|
|
break;
|
|
|
|
case 'E' : //ALT - E: es:di
|
|
|
|
dataSeg = SegValue(es);
|
|
|
|
if (cpu.pmode && !(reg_flags & FLAG_VM)) dataOfs = reg_edi;
|
|
|
|
else dataOfs = reg_di;
|
|
|
|
break;
|
|
|
|
case 'X': //ALT - X: ds:dx
|
|
|
|
dataSeg = SegValue(ds);
|
|
|
|
if (cpu.pmode && !(reg_flags & FLAG_VM)) dataOfs = reg_edx;
|
|
|
|
else dataOfs = reg_dx;
|
|
|
|
break;
|
|
|
|
case 'B' : //ALT -B: es:bx
|
|
|
|
dataSeg = SegValue(es);
|
|
|
|
if (cpu.pmode && !(reg_flags & FLAG_VM)) dataOfs = reg_ebx;
|
|
|
|
else dataOfs = reg_bx;
|
|
|
|
break;
|
|
|
|
case 'S': //ALT - S: ss:sp
|
|
|
|
dataSeg = SegValue(ss);
|
|
|
|
if (cpu.pmode && !(reg_flags & FLAG_VM)) dataOfs = reg_esp;
|
|
|
|
else dataOfs = reg_sp;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-05-02 23:03:37 +02:00
|
|
|
break;
|
2009-05-03 00:28:34 +02:00
|
|
|
case KEY_PPAGE : dataOfs -= 16; break;
|
|
|
|
case KEY_NPAGE : dataOfs += 16; break;
|
|
|
|
|
2009-05-02 23:12:18 +02:00
|
|
|
case KEY_DOWN: // down
|
2009-05-03 00:28:34 +02:00
|
|
|
if (codeViewData.cursorPos<9) codeViewData.cursorPos++;
|
|
|
|
else codeViewData.useEIP += codeViewData.firstInstSize;
|
|
|
|
break;
|
2009-05-02 23:12:18 +02:00
|
|
|
case KEY_UP: // up
|
2009-05-03 00:28:34 +02:00
|
|
|
if (codeViewData.cursorPos>0) codeViewData.cursorPos--;
|
|
|
|
else {
|
|
|
|
Bitu bytes = 0;
|
|
|
|
char dline[200];
|
|
|
|
Bitu size = 0;
|
|
|
|
Bit32u newEIP = codeViewData.useEIP - 1;
|
|
|
|
if(codeViewData.useEIP) {
|
|
|
|
for (; bytes < 10; bytes++) {
|
|
|
|
PhysPt start = GetAddress(codeViewData.useCS,newEIP);
|
|
|
|
size = DasmI386(dline, start, newEIP, cpu.code.big);
|
|
|
|
if(codeViewData.useEIP == newEIP+size) break;
|
|
|
|
newEIP--;
|
|
|
|
}
|
|
|
|
if (bytes>=10) newEIP = codeViewData.useEIP - 1;
|
|
|
|
}
|
|
|
|
codeViewData.useEIP = newEIP;
|
|
|
|
}
|
|
|
|
break;
|
2009-05-03 00:08:43 +02:00
|
|
|
case KEY_HOME: // Home: scroll log page up
|
2009-05-03 00:28:34 +02:00
|
|
|
DEBUG_RefreshPage(-1);
|
|
|
|
break;
|
2009-05-03 00:08:43 +02:00
|
|
|
case KEY_END: // End: scroll log page down
|
2009-05-03 00:28:34 +02:00
|
|
|
DEBUG_RefreshPage(1);
|
|
|
|
break;
|
2009-05-02 23:12:18 +02:00
|
|
|
case KEY_F(5): // Run Programm
|
2009-05-03 00:28:34 +02:00
|
|
|
debugging=false;
|
|
|
|
CBreakpoint::ActivateBreakpoints(SegPhys(cs)+reg_eip,true);
|
|
|
|
ignoreAddressOnce = SegPhys(cs)+reg_eip;
|
|
|
|
DOSBOX_SetNormalLoop();
|
|
|
|
break;
|
2009-05-02 23:12:18 +02:00
|
|
|
case KEY_F(9): // Set/Remove TBreakpoint
|
2009-05-03 00:28:34 +02:00
|
|
|
{ PhysPt ptr = GetAddress(codeViewData.cursorSeg,codeViewData.cursorOfs);
|
|
|
|
if (CBreakpoint::IsBreakpoint(ptr)) CBreakpoint::DeleteBreakpoint(ptr);
|
|
|
|
else CBreakpoint::AddBreakpoint(codeViewData.cursorSeg, codeViewData.cursorOfs, false);
|
|
|
|
}
|
2009-05-02 23:12:18 +02:00
|
|
|
break;
|
|
|
|
case KEY_F(10): // Step over inst
|
2009-05-03 00:28:34 +02:00
|
|
|
if (StepOver()) return 0;
|
|
|
|
else {
|
|
|
|
exitLoop = false;
|
|
|
|
skipFirstInstruction = true; // for heavy debugger
|
|
|
|
CPU_Cycles = 1;
|
|
|
|
ret=(*cpudecoder)();
|
|
|
|
SetCodeWinStart();
|
|
|
|
CBreakpoint::ignoreOnce = 0;
|
|
|
|
}
|
|
|
|
break;
|
2009-05-02 23:12:18 +02:00
|
|
|
case KEY_F(11): // trace into
|
2009-05-03 00:28:34 +02:00
|
|
|
exitLoop = false;
|
|
|
|
skipFirstInstruction = true; // for heavy debugger
|
|
|
|
CPU_Cycles = 1;
|
|
|
|
ret = (*cpudecoder)();
|
|
|
|
SetCodeWinStart();
|
|
|
|
CBreakpoint::ignoreOnce = 0;
|
|
|
|
break;
|
|
|
|
case 0x0A: //Parse typed Command
|
|
|
|
codeViewData.inputMode = true;
|
|
|
|
if(ParseCommand(codeViewData.inputStr)) codeViewData.inputStr[0] = 0;
|
|
|
|
break;
|
|
|
|
case 0x107: //backspace (linux)
|
|
|
|
case 0x7f: //backspace in some terminal emulators (linux)
|
|
|
|
case 0x08: // delete
|
|
|
|
if (strlen(codeViewData.inputStr)>0) codeViewData.inputStr[strlen(codeViewData.inputStr)-1] = 0;
|
|
|
|
break;
|
|
|
|
default : if ((key>=32) && (key<=128) && (strlen(codeViewData.inputStr)<253)) {
|
|
|
|
Bit32u len = strlen(codeViewData.inputStr);
|
|
|
|
codeViewData.inputStr[len] = char(key);
|
|
|
|
codeViewData.inputStr[len+1] = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
}
|
2009-05-03 00:28:34 +02:00
|
|
|
if (ret<0) return ret;
|
|
|
|
if (ret>0) {
|
2009-05-02 23:53:27 +02:00
|
|
|
ret=(*CallBack_Handlers[ret])();
|
|
|
|
if (ret) {
|
|
|
|
exitLoop=true;
|
|
|
|
CPU_Cycles=CPU_CycleLeft=0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret=0;
|
2009-05-02 23:03:37 +02:00
|
|
|
DEBUG_DrawScreen();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
Bitu DEBUG_Loop(void) {
|
|
|
|
//TODO Disable sound
|
|
|
|
GFX_Events();
|
2009-05-02 23:12:18 +02:00
|
|
|
// Interrupt started ? - then skip it
|
|
|
|
Bit16u oldCS = SegValue(cs);
|
|
|
|
Bit32u oldEIP = reg_eip;
|
2009-05-02 23:03:37 +02:00
|
|
|
PIC_runIRQs();
|
2009-05-03 00:02:15 +02:00
|
|
|
SDL_Delay(1);
|
2009-05-02 23:12:18 +02:00
|
|
|
if ((oldCS!=SegValue(cs)) || (oldEIP!=reg_eip)) {
|
2009-05-02 23:20:05 +02:00
|
|
|
CBreakpoint::AddBreakpoint(oldCS,oldEIP,true);
|
|
|
|
CBreakpoint::ActivateBreakpoints(SegPhys(cs)+reg_eip,true);
|
2009-05-02 23:12:18 +02:00
|
|
|
debugging=false;
|
|
|
|
DOSBOX_SetNormalLoop();
|
|
|
|
return 0;
|
|
|
|
}
|
2009-05-02 23:03:37 +02:00
|
|
|
return DEBUG_CheckKeys();
|
|
|
|
}
|
|
|
|
|
2009-05-03 00:18:08 +02:00
|
|
|
void DEBUG_Enable(bool pressed) {
|
|
|
|
if (!pressed)
|
|
|
|
return;
|
2009-05-03 00:08:43 +02:00
|
|
|
static bool showhelp=false;
|
2009-05-02 23:03:37 +02:00
|
|
|
debugging=true;
|
2009-05-02 23:12:18 +02:00
|
|
|
SetCodeWinStart();
|
|
|
|
DEBUG_DrawScreen();
|
2009-05-02 23:03:37 +02:00
|
|
|
DOSBOX_SetLoop(&DEBUG_Loop);
|
2009-05-03 00:08:43 +02:00
|
|
|
if(!showhelp) {
|
|
|
|
showhelp=true;
|
2009-05-03 00:28:34 +02:00
|
|
|
DEBUG_ShowMsg("***| TYPE HELP (+ENTER) TO GET AN OVERVIEW OF ALL COMMANDS |***\n");
|
2009-05-03 00:08:43 +02:00
|
|
|
}
|
2009-05-03 00:18:08 +02:00
|
|
|
KEYBOARD_ClrBuffer();
|
2009-05-02 23:03:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DEBUG_DrawScreen(void) {
|
2009-05-02 23:12:18 +02:00
|
|
|
DrawData();
|
2009-05-02 23:03:37 +02:00
|
|
|
DrawCode();
|
2009-05-02 23:43:00 +02:00
|
|
|
DrawRegisters();
|
2009-05-03 00:02:15 +02:00
|
|
|
DrawVariables();
|
2009-05-02 23:03:37 +02:00
|
|
|
}
|
2009-05-02 23:53:27 +02:00
|
|
|
|
2009-05-02 23:03:37 +02:00
|
|
|
static void DEBUG_RaiseTimerIrq(void) {
|
|
|
|
PIC_ActivateIRQ(0);
|
|
|
|
}
|
|
|
|
|
2009-05-03 00:02:15 +02:00
|
|
|
static void LogGDT(void)
|
2009-05-02 23:53:27 +02:00
|
|
|
{
|
|
|
|
char out1[512];
|
|
|
|
Descriptor desc;
|
|
|
|
Bitu length = cpu.gdt.GetLimit();
|
|
|
|
PhysPt address = cpu.gdt.GetBase();
|
|
|
|
PhysPt max = address + length;
|
|
|
|
Bitu i = 0;
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)("GDT Base:%08X Limit:%08X",address,length);
|
|
|
|
while (address<max) {
|
|
|
|
desc.Load(address);
|
|
|
|
sprintf(out1,"%04X: b:%08X type: %02X parbg",(i<<3),desc.GetBase(),desc.saved.seg.type);
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
sprintf(out1," l:%08X dpl : %01X %1X%1X%1X%1X%1X",desc.GetLimit(),desc.saved.seg.dpl,desc.saved.seg.p,desc.saved.seg.avl,desc.saved.seg.r,desc.saved.seg.big,desc.saved.seg.g);
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
address+=8; i++;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2009-05-03 00:02:15 +02:00
|
|
|
static void LogLDT(void)
|
2009-05-02 23:53:27 +02:00
|
|
|
{
|
|
|
|
char out1[512];
|
|
|
|
Descriptor desc;
|
|
|
|
Bitu ldtSelector = cpu.gdt.SLDT();
|
|
|
|
cpu.gdt.GetDescriptor(ldtSelector,desc);
|
|
|
|
Bitu length = desc.GetLimit();
|
|
|
|
PhysPt address = desc.GetBase();
|
|
|
|
PhysPt max = address + length;
|
|
|
|
Bitu i = 0;
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)("LDT Base:%08X Limit:%08X",address,length);
|
|
|
|
while (address<max) {
|
|
|
|
desc.Load(address);
|
|
|
|
sprintf(out1,"%04X: b:%08X type: %02X parbg",(i<<3)|4,desc.GetBase(),desc.saved.seg.type);
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
sprintf(out1," l:%08X dpl : %01X %1X%1X%1X%1X%1X",desc.GetLimit(),desc.saved.seg.dpl,desc.saved.seg.p,desc.saved.seg.avl,desc.saved.seg.r,desc.saved.seg.big,desc.saved.seg.g);
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
address+=8; i++;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2009-05-03 00:02:15 +02:00
|
|
|
static void LogIDT(void)
|
2009-05-02 23:53:27 +02:00
|
|
|
{
|
|
|
|
char out1[512];
|
|
|
|
Descriptor desc;
|
|
|
|
Bitu address = 0;
|
|
|
|
while (address<256*8) {
|
|
|
|
cpu.idt.GetDescriptor(address,desc);
|
|
|
|
sprintf(out1,"%04X: sel:%04X off:%02X",address/8,desc.GetSelector(),desc.GetOffset());
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
address+=8;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2009-05-03 00:18:08 +02:00
|
|
|
void LogPages(char* selname)
|
|
|
|
{
|
|
|
|
char out1[512];
|
|
|
|
if (paging.enabled) {
|
|
|
|
Bitu sel = GetHexValue(selname,selname);
|
|
|
|
if ((sel==0x00) && ((*selname==0) || (*selname=='*'))) {
|
|
|
|
for (int i=0; i<0xfffff; i++) {
|
|
|
|
Bitu table_addr=(paging.base.page<<12)+(i >> 10)*4;
|
|
|
|
X86PageEntry table;
|
|
|
|
table.load=phys_readd(table_addr);
|
|
|
|
if (table.block.p) {
|
|
|
|
X86PageEntry entry;
|
|
|
|
Bitu entry_addr=(table.block.base<<12)+(i & 0x3ff)*4;
|
|
|
|
entry.load=phys_readd(entry_addr);
|
|
|
|
if (entry.block.p) {
|
|
|
|
sprintf(out1,"page %05Xxxx -> %04Xxxx flags [uw] %x:%x::%x:%x",i,entry.block.base,entry.block.us,table.block.us,entry.block.wr,table.block.wr);
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Bitu table_addr=(paging.base.page<<12)+(sel >> 10)*4;
|
|
|
|
X86PageEntry table;
|
|
|
|
table.load=phys_readd(table_addr);
|
|
|
|
if (table.block.p) {
|
|
|
|
X86PageEntry entry;
|
|
|
|
Bitu entry_addr=(table.block.base<<12)+(sel & 0x3ff)*4;
|
|
|
|
entry.load=phys_readd(entry_addr);
|
|
|
|
sprintf(out1,"page %05Xxxx -> %04Xxxx flags [puw] %x:%x::%x:%x::%x:%x",sel,entry.block.base,entry.block.p,table.block.p,entry.block.us,table.block.us,entry.block.wr,table.block.wr);
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
} else {
|
|
|
|
sprintf(out1,"pagetable %03X not present, flags [puw] %x::%x::%x",(sel >> 10),table.block.p,table.block.us,table.block.wr);
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void LogCPUInfo(void)
|
|
|
|
{
|
|
|
|
char out1[512];
|
|
|
|
sprintf(out1,"cr0:%08X cr2:%08X cr3:%08X cpl=%x",cpu.cr0,paging.cr2,paging.cr3,cpu.cpl);
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
sprintf(out1,"eflags:%08X [vm=%x iopl=%x nt=%x]",reg_flags,GETFLAG(VM)>>17,GETFLAG(IOPL)>>12,GETFLAG(NT)>>14);
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
sprintf(out1,"GDT base=%08X limit=%08X",cpu.gdt.GetBase(),cpu.gdt.GetLimit());
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
sprintf(out1,"IDT base=%08X limit=%08X",cpu.idt.GetBase(),cpu.idt.GetLimit());
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
|
|
|
|
Bitu sel;
|
|
|
|
Descriptor desc;
|
|
|
|
CPU_STR(sel);
|
|
|
|
cpu.gdt.GetDescriptor(sel,desc);
|
|
|
|
sprintf(out1,"TR selector=%04X, base=%08X limit=%08X*%X",sel,desc.GetBase(),desc.GetLimit(),desc.saved.seg.g?0x4000:1);
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
sel=cpu.gdt.SLDT();
|
|
|
|
cpu.gdt.GetDescriptor(sel,desc);
|
|
|
|
sprintf(out1,"LDT selector=%04X, base=%08X limit=%08X*%X",sel,desc.GetBase(),desc.GetLimit(),desc.saved.seg.g?0x4000:1);
|
|
|
|
LOG(LOG_MISC,LOG_ERROR)(out1);
|
|
|
|
};
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
#if C_HEAVY_DEBUG
|
|
|
|
static void LogInstruction(Bit16u segValue, Bit32u eipValue, ofstream& out) {
|
|
|
|
static char empty[23] = { 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0 };
|
2009-05-02 23:35:44 +02:00
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
PhysPt start = GetAddress(segValue,eipValue);
|
2009-05-02 23:27:47 +02:00
|
|
|
char dline[200];Bitu size;
|
2009-05-02 23:43:00 +02:00
|
|
|
size = DasmI386(dline, start, reg_eip, cpu.code.big);
|
2009-05-02 23:35:44 +02:00
|
|
|
char* res = empty;
|
2009-05-03 00:28:34 +02:00
|
|
|
if (showExtend && (cpuLogType > 0) ) {
|
2009-05-02 23:43:00 +02:00
|
|
|
res = AnalyzeInstruction(dline,false);
|
2009-05-03 00:28:34 +02:00
|
|
|
if (!res || !(*res)) res = empty;
|
|
|
|
Bitu reslen = strlen(res);
|
|
|
|
if (reslen<22) for (Bitu i=0; i<22-reslen; i++) res[reslen+i] = ' '; res[22] = 0;
|
2009-05-02 23:35:44 +02:00
|
|
|
};
|
2009-05-03 00:28:34 +02:00
|
|
|
Bitu len = strlen(dline);
|
|
|
|
if (len<30) for (Bitu i=0; i<30-len; i++) dline[len + i] = ' '; dline[30] = 0;
|
2009-05-03 00:18:08 +02:00
|
|
|
|
2009-05-02 23:27:47 +02:00
|
|
|
// Get register values
|
2009-05-03 00:28:34 +02:00
|
|
|
|
|
|
|
if(cpuLogType == 0) {
|
|
|
|
out << setw(4) << SegValue(cs) << ":" << setw(4) << reg_eip << " " << dline;
|
|
|
|
} else if (cpuLogType == 1) {
|
|
|
|
out << setw(4) << SegValue(cs) << ":" << setw(8) << reg_eip << " " << dline << " " << res;
|
|
|
|
} else if (cpuLogType == 2) {
|
2009-05-03 00:18:08 +02:00
|
|
|
char ibytes[200]=""; char tmpc[200];
|
|
|
|
for (Bitu i=0; i<size; i++) {
|
|
|
|
sprintf(tmpc,"%02X ",mem_readb(start+i));
|
|
|
|
strcat(ibytes,tmpc);
|
|
|
|
}
|
2009-05-03 00:28:34 +02:00
|
|
|
len = strlen(ibytes);
|
|
|
|
if (len<21) { for (Bitu i=0; i<21-len; i++) ibytes[len + i] =' '; ibytes[21]=0;} //NOTE THE BRACKETS
|
|
|
|
out << setw(4) << SegValue(cs) << ":" << setw(8) << reg_eip << " " << dline << " " << res << " " << ibytes;
|
2009-05-03 00:18:08 +02:00
|
|
|
}
|
2009-05-03 00:28:34 +02:00
|
|
|
|
|
|
|
out << " EAX:" << setw(8) << reg_eax << " EBX:" << setw(8) << reg_ebx
|
|
|
|
<< " ECX:" << setw(8) << reg_ecx << " EDX:" << setw(8) << reg_edx
|
|
|
|
<< " ESI:" << setw(8) << reg_esi << " EDI:" << setw(8) << reg_edi
|
|
|
|
<< " EBP:" << setw(8) << reg_ebp << " ESP:" << setw(8) << reg_esp
|
|
|
|
<< " DS:" << setw(4) << SegValue(ds)<< " ES:" << setw(4) << SegValue(es);
|
|
|
|
|
|
|
|
if(cpuLogType == 0) {
|
|
|
|
out << " SS:" << setw(4) << SegValue(ss) << " C" << get_CF() << " Z" << get_ZF()
|
|
|
|
<< " S" << get_SF() << " O" << get_OF() << " I" << GETFLAGBOOL(IF);
|
|
|
|
} else {
|
|
|
|
out << " FS:" << setw(4) << SegValue(fs) << " GS:" << setw(4) << SegValue(gs)
|
|
|
|
<< " SS:" << setw(4) << SegValue(ss)
|
|
|
|
<< " CF:" << get_CF() << " ZF:" << get_ZF() << " SF:" << get_SF()
|
|
|
|
<< " OF:" << get_OF() << " AF:" << get_AF() << " PF:" << get_PF()
|
|
|
|
<< " IF:" << GETFLAGBOOL(IF);
|
|
|
|
}
|
|
|
|
if(cpuLogType == 2) {
|
|
|
|
out << " TF:" << GETFLAGBOOL(TF) << " VM:" << GETFLAGBOOL(VM) <<" FLG:" << setw(8) << reg_flags
|
|
|
|
<< " CR0:" << setw(8) << cpu.cr0;
|
|
|
|
}
|
|
|
|
out << endl;
|
2009-05-02 23:27:47 +02:00
|
|
|
};
|
2009-05-03 00:28:34 +02:00
|
|
|
#endif
|
2009-05-02 23:20:05 +02:00
|
|
|
|
|
|
|
// DEBUG.COM stuff
|
|
|
|
|
|
|
|
class DEBUG : public Program {
|
|
|
|
public:
|
|
|
|
DEBUG() { pDebugcom = this; active = false; };
|
|
|
|
~DEBUG() { pDebugcom = 0; };
|
|
|
|
|
|
|
|
bool IsActive() { return active; };
|
|
|
|
|
|
|
|
void Run(void)
|
|
|
|
{
|
|
|
|
char filename[128];
|
2009-05-02 23:27:47 +02:00
|
|
|
char args[256];
|
2009-05-02 23:20:05 +02:00
|
|
|
cmd->FindCommand(1,temp_line);
|
2009-05-03 00:18:08 +02:00
|
|
|
safe_strncpy(filename,temp_line.c_str(),128);
|
2009-05-02 23:27:47 +02:00
|
|
|
// Read commandline
|
|
|
|
Bit16u i =2;
|
|
|
|
bool ok = false;
|
|
|
|
args[0] = 0;
|
2009-05-03 00:28:34 +02:00
|
|
|
for (;cmd->FindCommand(i++,temp_line)==true;) {
|
2009-05-02 23:27:47 +02:00
|
|
|
strncat(args,temp_line.c_str(),256);
|
|
|
|
strncat(args," ",256);
|
2009-05-03 00:28:34 +02:00
|
|
|
}
|
2009-05-02 23:20:05 +02:00
|
|
|
// Start new shell and execute prog
|
|
|
|
active = true;
|
2009-05-02 23:27:47 +02:00
|
|
|
// Save cpu state....
|
|
|
|
Bit16u oldcs = SegValue(cs);
|
|
|
|
Bit32u oldeip = reg_eip;
|
|
|
|
Bit16u oldss = SegValue(ss);
|
|
|
|
Bit32u oldesp = reg_esp;
|
|
|
|
|
|
|
|
// Workaround : Allocate Stack Space
|
|
|
|
Bit16u segment;
|
|
|
|
Bit16u size = 0x200 / 0x10;
|
|
|
|
if (DOS_AllocateMemory(&segment,&size)) {
|
|
|
|
SegSet16(ss,segment);
|
|
|
|
reg_sp = 0x200;
|
|
|
|
// Start shell
|
|
|
|
DOS_Shell shell;
|
|
|
|
shell.Execute(filename,args);
|
|
|
|
DOS_FreeMemory(segment);
|
|
|
|
}
|
|
|
|
// set old reg values
|
|
|
|
SegSet16(ss,oldss);
|
|
|
|
reg_esp = oldesp;
|
|
|
|
SegSet16(cs,oldcs);
|
|
|
|
reg_eip = oldeip;
|
2009-05-02 23:20:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool active;
|
|
|
|
};
|
|
|
|
|
|
|
|
void DEBUG_CheckExecuteBreakpoint(Bit16u seg, Bit32u off)
|
|
|
|
{
|
|
|
|
if (pDebugcom && pDebugcom->IsActive()) {
|
|
|
|
CBreakpoint::AddBreakpoint(seg,off,true);
|
|
|
|
CBreakpoint::ActivateBreakpoints(SegPhys(cs)+reg_eip,true);
|
|
|
|
pDebugcom = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
Bitu DEBUG_EnableDebugger(void)
|
|
|
|
{
|
|
|
|
exitLoop = true;
|
2009-05-03 00:18:08 +02:00
|
|
|
DEBUG_Enable(true);
|
2009-05-02 23:53:27 +02:00
|
|
|
CPU_Cycles=CPU_CycleLeft=0;
|
2009-05-02 23:43:00 +02:00
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
static void DEBUG_ProgramStart(Program * * make) {
|
|
|
|
*make=new DEBUG;
|
|
|
|
}
|
|
|
|
|
|
|
|
// INIT
|
|
|
|
|
|
|
|
void DEBUG_SetupConsole(void)
|
|
|
|
{
|
2009-05-02 23:03:37 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
WIN32_Console();
|
2009-05-02 23:35:44 +02:00
|
|
|
#else
|
|
|
|
tcgetattr(0,&consolesettings);
|
|
|
|
printf("\e[8;50;80t"); //resize terminal
|
|
|
|
fflush(NULL);
|
2009-05-02 23:20:05 +02:00
|
|
|
#endif
|
2009-05-02 23:03:37 +02:00
|
|
|
memset((void *)&dbg,0,sizeof(dbg));
|
|
|
|
debugging=false;
|
|
|
|
dbg.active_win=3;
|
|
|
|
input_count=0;
|
|
|
|
/* Start the Debug Gui */
|
|
|
|
DBGUI_StartUp();
|
2009-05-02 23:20:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void DEBUG_ShutDown(Section * sec)
|
|
|
|
{
|
|
|
|
CBreakpoint::DeleteAll();
|
2009-05-02 23:35:44 +02:00
|
|
|
CDebugVar::DeleteAll();
|
|
|
|
#ifndef WIN32
|
|
|
|
curs_set(old_cursor_state);
|
|
|
|
tcsetattr(0, TCSANOW,&consolesettings);
|
2009-05-03 00:18:08 +02:00
|
|
|
// printf("\e[0m\e[2J"); //Seems to destroy scrolling
|
|
|
|
printf("\ec");
|
2009-05-02 23:35:44 +02:00
|
|
|
fflush(NULL);
|
|
|
|
#endif
|
2009-05-02 23:20:05 +02:00
|
|
|
};
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
Bitu debugCallback;
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
void DEBUG_Init(Section* sec) {
|
|
|
|
|
2009-05-03 00:08:43 +02:00
|
|
|
MSG_Add("DEBUG_CONFIGFILE_HELP","Debugger related options.\n");
|
2009-05-02 23:03:37 +02:00
|
|
|
DEBUG_DrawScreen();
|
|
|
|
/* Add some keyhandlers */
|
2009-05-03 00:18:08 +02:00
|
|
|
MAPPER_AddHandler(DEBUG_Enable,MK_pause,MMOD2,"debugger","Debugger");
|
2009-05-02 23:12:18 +02:00
|
|
|
/* Clear the TBreakpoint list */
|
|
|
|
memset((void*)&codeViewData,0,sizeof(codeViewData));
|
2009-05-02 23:20:05 +02:00
|
|
|
/* setup debug.com */
|
|
|
|
PROGRAMS_MakeFile("DEBUG.COM",DEBUG_ProgramStart);
|
2009-05-02 23:43:00 +02:00
|
|
|
/* Setup callback */
|
|
|
|
debugCallback=CALLBACK_Allocate();
|
2009-05-03 00:08:43 +02:00
|
|
|
CALLBACK_Setup(debugCallback,DEBUG_EnableDebugger,CB_RETF,"debugger");
|
2009-05-02 23:20:05 +02:00
|
|
|
/* shutdown function */
|
|
|
|
sec->AddDestroyFunction(&DEBUG_ShutDown);
|
2009-05-02 23:03:37 +02:00
|
|
|
}
|
2009-05-02 23:12:18 +02:00
|
|
|
|
2009-05-02 23:35:44 +02:00
|
|
|
// DEBUGGING VAR STUFF
|
|
|
|
|
|
|
|
void CDebugVar::InsertVariable(char* name, PhysPt adr)
|
|
|
|
{
|
|
|
|
varList.push_back(new CDebugVar(name,adr));
|
|
|
|
};
|
|
|
|
|
|
|
|
void CDebugVar::DeleteAll(void)
|
|
|
|
{
|
|
|
|
std::list<CDebugVar*>::iterator i;
|
|
|
|
CDebugVar* bp;
|
|
|
|
for(i=varList.begin(); i != varList.end(); i++) {
|
|
|
|
bp = static_cast<CDebugVar*>(*i);
|
|
|
|
delete bp;
|
|
|
|
};
|
|
|
|
(varList.clear)();
|
|
|
|
};
|
|
|
|
|
|
|
|
CDebugVar* CDebugVar::FindVar(PhysPt pt)
|
|
|
|
{
|
|
|
|
std::list<CDebugVar*>::iterator i;
|
|
|
|
CDebugVar* bp;
|
|
|
|
for(i=varList.begin(); i != varList.end(); i++) {
|
|
|
|
bp = static_cast<CDebugVar*>(*i);
|
|
|
|
if (bp->GetAdr()==pt) return bp;
|
|
|
|
};
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool CDebugVar::SaveVars(char* name)
|
|
|
|
{
|
|
|
|
FILE* f = fopen(name,"wb+");
|
|
|
|
if (!f) return false;
|
|
|
|
|
|
|
|
// write number of vars
|
|
|
|
Bit16u num = varList.size();
|
|
|
|
fwrite(&num,1,sizeof(num),f);
|
|
|
|
|
|
|
|
std::list<CDebugVar*>::iterator i;
|
|
|
|
CDebugVar* bp;
|
|
|
|
for(i=varList.begin(); i != varList.end(); i++) {
|
|
|
|
bp = static_cast<CDebugVar*>(*i);
|
|
|
|
// name
|
|
|
|
fwrite(bp->GetName(),1,16,f);
|
|
|
|
// adr
|
|
|
|
PhysPt adr = bp->GetAdr();
|
|
|
|
fwrite(&adr,1,sizeof(adr),f);
|
|
|
|
};
|
|
|
|
fclose(f);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool CDebugVar::LoadVars(char* name)
|
|
|
|
{
|
|
|
|
FILE* f = fopen(name,"rb");
|
|
|
|
if (!f) return false;
|
|
|
|
|
|
|
|
// read number of vars
|
|
|
|
Bit16u num;
|
|
|
|
fread(&num,1,sizeof(num),f);
|
|
|
|
|
|
|
|
for (Bit16u i=0; i<num; i++) {
|
|
|
|
char name[16];
|
|
|
|
// name
|
|
|
|
fread(name,1,16,f);
|
|
|
|
// adr
|
|
|
|
PhysPt adr;
|
|
|
|
fread(&adr,1,sizeof(adr),f);
|
|
|
|
// insert
|
|
|
|
InsertVariable(name,adr);
|
|
|
|
};
|
|
|
|
fclose(f);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2009-05-03 00:18:08 +02:00
|
|
|
static void SaveMemory(Bitu seg, Bitu ofs1, Bit32u num)
|
2009-05-02 23:35:44 +02:00
|
|
|
{
|
|
|
|
FILE* f = fopen("MEMDUMP.TXT","wt");
|
|
|
|
if (!f) {
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Memory dump failed.\n");
|
2009-05-02 23:35:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char buffer[128];
|
|
|
|
char temp[16];
|
|
|
|
|
|
|
|
while(num>0) {
|
|
|
|
|
|
|
|
sprintf(buffer,"%04X:%04X ",seg,ofs1);
|
|
|
|
for (Bit16u x=0; x<16; x++) {
|
2009-05-02 23:43:00 +02:00
|
|
|
sprintf (temp,"%02X ",mem_readb(GetAddress(seg,ofs1+x)));
|
2009-05-02 23:35:44 +02:00
|
|
|
strcat (buffer,temp);
|
|
|
|
};
|
|
|
|
ofs1+=16;
|
|
|
|
num-=16;
|
|
|
|
|
|
|
|
fprintf(f,"%s\n",buffer);
|
|
|
|
};
|
|
|
|
fclose(f);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Memory dump success.\n");
|
2009-05-02 23:35:44 +02:00
|
|
|
};
|
|
|
|
|
2009-05-03 00:18:08 +02:00
|
|
|
static void SaveMemoryBin(Bitu seg, Bitu ofs1, Bit32u num) {
|
|
|
|
FILE* f = fopen("MEMDUMP.BIN","wb");
|
|
|
|
if (!f) {
|
|
|
|
DEBUG_ShowMsg("DEBUG: Memory binary dump failed.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Bitu x = 0; x < num;x++) {
|
|
|
|
Bit8u val = mem_readb(GetAddress(seg,ofs1+x));
|
|
|
|
fwrite(&val,1,1,f);
|
|
|
|
};
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
DEBUG_ShowMsg("DEBUG: Memory dump binary success.\n");
|
|
|
|
};
|
|
|
|
|
2009-05-03 00:02:15 +02:00
|
|
|
static void OutputVecTable(char* filename)
|
2009-05-02 23:53:27 +02:00
|
|
|
{
|
|
|
|
FILE* f = fopen(filename, "wt");
|
|
|
|
if (!f)
|
|
|
|
{
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Output of interrupt vector table failed.\n");
|
2009-05-02 23:53:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0; i<256; i++)
|
|
|
|
fprintf(f,"INT %02X: %04X:%04X\n", i, mem_readw(i*4+2), mem_readw(i*4));
|
|
|
|
|
|
|
|
fclose(f);
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Interrupt vector table written to %s.\n", filename);
|
2009-05-02 23:53:27 +02:00
|
|
|
}
|
|
|
|
|
2009-05-03 00:02:15 +02:00
|
|
|
#define DEBUG_VAR_BUF_LEN 16
|
|
|
|
static void DrawVariables(void)
|
|
|
|
{
|
|
|
|
std::list<CDebugVar*>::iterator i;
|
|
|
|
CDebugVar *dv;
|
|
|
|
char buffer[DEBUG_VAR_BUF_LEN];
|
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
for(i=CDebugVar::varList.begin(); i != CDebugVar::varList.end(); i++, idx++) {
|
|
|
|
|
|
|
|
if (idx == 4*3) {
|
|
|
|
/* too many variables */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dv = static_cast<CDebugVar*>(*i);
|
|
|
|
|
|
|
|
Bit16u value = mem_readw(dv->GetAdr());
|
|
|
|
snprintf(buffer,DEBUG_VAR_BUF_LEN, "0x%04x", value);
|
|
|
|
|
|
|
|
int y = idx / 3;
|
|
|
|
int x = (idx % 3) * 26;
|
|
|
|
mvwprintw(dbg.win_var, y, x, dv->GetName());
|
|
|
|
mvwprintw(dbg.win_var, y, (x + DEBUG_VAR_BUF_LEN + 1) , buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
wrefresh(dbg.win_var);
|
2009-05-03 00:28:34 +02:00
|
|
|
};
|
2009-05-03 00:02:15 +02:00
|
|
|
#undef DEBUG_VAR_BUF_LEN
|
2009-05-02 23:20:05 +02:00
|
|
|
// HEAVY DEBUGGING STUFF
|
|
|
|
|
|
|
|
#if C_HEAVY_DEBUG
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
const Bit32u LOGCPUMAX = 20000;
|
2009-05-02 23:27:47 +02:00
|
|
|
|
|
|
|
static Bit16u logCpuCS [LOGCPUMAX];
|
|
|
|
static Bit32u logCpuEIP[LOGCPUMAX];
|
|
|
|
static Bit32u logCount = 0;
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
struct TLogInst {
|
|
|
|
Bit16u s_cs;
|
|
|
|
Bit32u eip;
|
|
|
|
Bit32u eax;
|
|
|
|
Bit32u ebx;
|
|
|
|
Bit32u ecx;
|
|
|
|
Bit32u edx;
|
|
|
|
Bit32u esi;
|
|
|
|
Bit32u edi;
|
|
|
|
Bit32u ebp;
|
|
|
|
Bit32u esp;
|
|
|
|
Bit16u s_ds;
|
|
|
|
Bit16u s_es;
|
|
|
|
Bit16u s_fs;
|
|
|
|
Bit16u s_gs;
|
|
|
|
Bit16u s_ss;
|
|
|
|
bool c;
|
|
|
|
bool z;
|
|
|
|
bool s;
|
|
|
|
bool o;
|
|
|
|
bool a;
|
|
|
|
bool p;
|
|
|
|
bool i;
|
|
|
|
char dline[31];
|
|
|
|
char res[23];
|
|
|
|
};
|
2009-05-02 23:27:47 +02:00
|
|
|
|
|
|
|
TLogInst logInst[LOGCPUMAX];
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
void DEBUG_HeavyLogInstruction(void) {
|
|
|
|
|
|
|
|
static char empty[23] = { 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0 };
|
|
|
|
|
|
|
|
PhysPt start = GetAddress(SegValue(cs),reg_eip);
|
|
|
|
char dline[200];
|
|
|
|
Bitu size = DasmI386(dline, start, reg_eip, cpu.code.big);
|
|
|
|
char* res = empty;
|
|
|
|
if (showExtend) {
|
|
|
|
res = AnalyzeInstruction(dline,false);
|
|
|
|
if (!res || !(*res)) res = empty;
|
|
|
|
Bitu reslen = strlen(res);
|
|
|
|
if (reslen<22) for (Bitu i=0; i<22-reslen; i++) res[reslen+i] = ' '; res[22] = 0;
|
2009-05-02 23:35:44 +02:00
|
|
|
};
|
2009-05-03 00:28:34 +02:00
|
|
|
|
|
|
|
Bitu len = strlen(dline);
|
|
|
|
if (len < 30) for (Bitu i=0; i < 30-len; i++) dline[len+i] = ' ';
|
|
|
|
dline[30] = 0;
|
|
|
|
|
|
|
|
TLogInst & inst = logInst[logCount];
|
|
|
|
strcpy(inst.dline,dline);
|
|
|
|
inst.s_cs = SegValue(cs);
|
|
|
|
inst.eip = reg_eip;
|
|
|
|
strcpy(inst.res,res);
|
|
|
|
inst.eax = reg_eax;
|
|
|
|
inst.ebx = reg_ebx;
|
|
|
|
inst.ecx = reg_ecx;
|
|
|
|
inst.edx = reg_edx;
|
|
|
|
inst.esi = reg_esi;
|
|
|
|
inst.edi = reg_edi;
|
|
|
|
inst.ebp = reg_ebp;
|
|
|
|
inst.esp = reg_esp;
|
|
|
|
inst.s_ds = SegValue(ds);
|
|
|
|
inst.s_es = SegValue(es);
|
|
|
|
inst.s_fs = SegValue(fs);
|
|
|
|
inst.s_gs = SegValue(gs);
|
|
|
|
inst.s_ss = SegValue(ss);
|
|
|
|
inst.c = get_CF();
|
|
|
|
inst.z = get_ZF();
|
|
|
|
inst.s = get_SF();
|
|
|
|
inst.o = get_OF();
|
|
|
|
inst.a = get_AF();
|
|
|
|
inst.p = get_PF();
|
|
|
|
inst.i = GETFLAGBOOL(IF);
|
|
|
|
|
|
|
|
if (++logCount >= LOGCPUMAX) logCount = 0;
|
2009-05-02 23:27:47 +02:00
|
|
|
};
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
void DEBUG_HeavyWriteLogInstruction(void) {
|
2009-05-02 23:27:47 +02:00
|
|
|
if (!logHeavy) return;
|
2009-05-02 23:35:44 +02:00
|
|
|
logHeavy = false;
|
2009-05-02 23:27:47 +02:00
|
|
|
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Creating cpu log LOGCPU_INT_CD.TXT\n");
|
2009-05-02 23:27:47 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
ofstream out("LOGCPU_INT_CD.TXT");
|
|
|
|
if (!out.is_open()) {
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Failed.\n");
|
2009-05-02 23:27:47 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-05-03 00:28:34 +02:00
|
|
|
out << hex << noshowbase << setfill('0') << uppercase;
|
2009-05-02 23:35:44 +02:00
|
|
|
Bit32u startLog = logCount;
|
2009-05-02 23:27:47 +02:00
|
|
|
do {
|
|
|
|
// Write Intructions
|
2009-05-03 00:28:34 +02:00
|
|
|
TLogInst & inst = logInst[startLog];
|
|
|
|
out << setw(4) << inst.s_cs << ":" << setw(8) << inst.eip << " "
|
|
|
|
<< inst.dline << " " << inst.res << " EAX:" << setw(8)<< inst.eax
|
|
|
|
<< " EBX:" << setw(8) << inst.ebx << " ECX:" << setw(8) << inst.ecx
|
|
|
|
<< " EDX:" << setw(8) << inst.edx << " ESI:" << setw(8) << inst.esi
|
|
|
|
<< " EDI:" << setw(8) << inst.edi << " EBP:" << setw(8) << inst.ebp
|
|
|
|
<< " ESP:" << setw(8) << inst.esp << " DS:" << setw(4) << inst.s_ds
|
|
|
|
<< " ES:" << setw(4) << inst.s_es<< " FS:" << setw(4) << inst.s_fs
|
|
|
|
<< " GS:" << setw(4) << inst.s_gs<< " SS:" << setw(4) << inst.s_ss
|
|
|
|
<< " CF:" << inst.c << " ZF:" << inst.z << " SF:" << inst.s
|
|
|
|
<< " OF:" << inst.o << " AF:" << inst.a << " PF:" << inst.p
|
|
|
|
<< " IF:" << inst.i << endl;
|
|
|
|
|
|
|
|
/* fprintf(f,"%04X:%08X %s %s EAX:%08X EBX:%08X ECX:%08X EDX:%08X ESI:%08X EDI:%08X EBP:%08X ESP:%08X DS:%04X ES:%04X FS:%04X GS:%04X SS:%04X CF:%01X ZF:%01X SF:%01X OF:%01X AF:%01X PF:%01X IF:%01X\n",
|
|
|
|
logInst[startLog].s_cs,logInst[startLog].eip,logInst[startLog].dline,logInst[startLog].res,logInst[startLog].eax,logInst[startLog].ebx,logInst[startLog].ecx,logInst[startLog].edx,logInst[startLog].esi,logInst[startLog].edi,logInst[startLog].ebp,logInst[startLog].esp,
|
|
|
|
logInst[startLog].s_ds,logInst[startLog].s_es,logInst[startLog].s_fs,logInst[startLog].s_gs,logInst[startLog].s_ss,
|
|
|
|
logInst[startLog].c,logInst[startLog].z,logInst[startLog].s,logInst[startLog].o,logInst[startLog].a,logInst[startLog].p,logInst[startLog].i);*/
|
|
|
|
if (++startLog >= LOGCPUMAX) startLog = 0;
|
|
|
|
} while (startLog != logCount);
|
2009-05-02 23:27:47 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
out.close();
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: Done.\n");
|
2009-05-02 23:27:47 +02:00
|
|
|
};
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
bool DEBUG_HeavyIsBreakpoint(void) {
|
|
|
|
static Bitu zero_count = 0;
|
2009-05-02 23:53:27 +02:00
|
|
|
if (cpuLog) {
|
|
|
|
if (cpuLogCounter>0) {
|
2009-05-03 00:28:34 +02:00
|
|
|
LogInstruction(SegValue(cs),reg_eip,cpuLogFile);
|
2009-05-02 23:53:27 +02:00
|
|
|
cpuLogCounter--;
|
|
|
|
}
|
|
|
|
if (cpuLogCounter<=0) {
|
2009-05-03 00:28:34 +02:00
|
|
|
cpuLogFile.close();
|
2009-05-03 00:08:43 +02:00
|
|
|
DEBUG_ShowMsg("DEBUG: cpu log LOGCPU.TXT created\n");
|
2009-05-02 23:53:27 +02:00
|
|
|
cpuLog = false;
|
|
|
|
DEBUG_EnableDebugger();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-05-02 23:27:47 +02:00
|
|
|
// LogInstruction
|
|
|
|
if (logHeavy) DEBUG_HeavyLogInstruction();
|
2009-05-03 00:28:34 +02:00
|
|
|
if(zeroProtect && mem_readd(SegPhys(cs) + reg_eip) == 0) zero_count++; else zero_count = 0;
|
|
|
|
if(zeroProtect && GCC_UNLIKELY(zero_count == 10)) E_Exit("running zeroed code");
|
2009-05-02 23:27:47 +02:00
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
if (skipFirstInstruction) {
|
|
|
|
skipFirstInstruction = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PhysPt where = SegPhys(cs)+reg_eip;
|
2009-05-02 23:43:00 +02:00
|
|
|
if (CBreakpoint::CheckBreakpoint(SegValue(cs),reg_eip)) {
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-02 23:20:05 +02:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
#endif // HEAVY DEBUG
|
|
|
|
|
2009-05-03 00:02:15 +02:00
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
#endif // DEBUG
|
2009-05-02 23:12:18 +02:00
|
|
|
|
2009-05-02 23:35:44 +02:00
|
|
|
|