⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debugtooldlg.cpp

📁 usb-jtag转换,sparc芯片反汇编,sparc芯片调试的工具,可以对芯片内的gpio,sdram,flash进行读写,还可以一次下载64K大小的数据,反汇编,在线调试.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// DebugToolDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DebugTool.h"
#include "DebugToolDlg.h"
#include "Jsm.h"
#include "sparc_disas.h"
#include "amtxhal.h"
#include "usbjtag.h"
#include "elf.h"
#include "string.h"
#include "process.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


// declare Jtag parameter
class  Cusbjtag  Jtag ;

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

/////////////// amba bus scan 

/////
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDebugToolDlg dialog

CDebugToolDlg::CDebugToolDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDebugToolDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDebugToolDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDebugToolDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDebugToolDlg)
	DDX_Control(pDX, IDC_PC, m_pc);
	DDX_Control(pDX, IDC_DISAS, m_Disas);
	DDX_Control(pDX, IDC_DemoList, m_list);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDebugToolDlg, CDialog)
	//{{AFX_MSG_MAP(CDebugToolDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_Read, OnRead)
	ON_BN_CLICKED(IDC_Open, OnOpen)
	ON_BN_CLICKED(IDC_Close, OnClose)
	ON_BN_CLICKED(IDC_Write, OnWrite)
	ON_BN_CLICKED(IDC_OpenFile, OnOpenFile)
	ON_BN_CLICKED(IDC_Down, OnDown)
	ON_BN_CLICKED(IDC_Clear, OnClear)
	ON_BN_CLICKED(IDC_RUN, OnRun)
	ON_BN_CLICKED(IDC_FlashDown, OnFlashDown)
	ON_BN_CLICKED(IDC_FlashWrite, OnFlashWrite)
	ON_BN_CLICKED(IDC_FlashRead, OnFlashRead)
	ON_BN_CLICKED(IDC_Erase, OnErase)
	ON_BN_CLICKED(IDC_BUTTON1, OnStep)
	ON_BN_CLICKED(IDC_BUTTON2, OnSetBP)
	ON_BN_CLICKED(IDC_BUTTON3, OnOpenSvf)
	ON_BN_CLICKED(IDC_BUTTON4, OnUpLoadSvf)
	ON_BN_CLICKED(IDC_BUTTON5, OnSch)
	ON_BN_CLICKED(IDC_BUTTON6, OnSms4)
	ON_BN_CLICKED(IDC_BUTTON7, OnTimer)
	ON_BN_CLICKED(IDC_BUTTON8, OnFlash)
	ON_BN_CLICKED(IDC_BUTTON9, OnI2c)
	ON_BN_CLICKED(IDC_BUTTON10, OnXram)
	ON_BN_CLICKED(IDC_BUTTON11, OnGpio)
	ON_BN_CLICKED(IDC_BUTTON12, OnStop)
	ON_BN_CLICKED(IDC_BUTTON13, OnApbuart)
	ON_BN_CLICKED(IDC_BUTTON14, OnSysReg)
	ON_BN_CLICKED(IDC_7816, On7816)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDebugToolDlg message handlers

BOOL CDebugToolDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	GetDlgItem(IDC_ReadAddr)->SetWindowText(_T("0x0d000000"));
	GetDlgItem(IDC_FileAddr)->SetWindowText(_T("0x0c000000"));
	GetDlgItem(IDC_WriteAddr)->SetWindowText(_T("0x0d000000"));
	GetDlgItem(IDC_WriteData)->SetWindowText(_T("0xffffffff"));
	GetDlgItem(IDC_BPADDR)->SetWindowText(_T("0x0c0000dc"));
	GetDlgItem(IDC_FileName)->SetWindowText(_T("c:\\jsm\\proc2s60.exe"));
	GetDlgItem(IDC_SVFPATH)->SetWindowText(_T("c:\\jsm\\proc2s60.svf"));
	GetDlgItem(IDC_FREQENCE)->SetWindowText(_T("6000000"));
	m_sFwName = _T("");
	m_svfName = _T("");
	m_bOpen = FALSE;
	m_index = 0;
	m_inbp = false;
	m_pcindex = 0; // used to pointer current pc
	m_prePc = 0x0c000000;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDebugToolDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CDebugToolDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDebugToolDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}



/****************************************/
// function: read a block memory data and
//			 screenshot
// input: 
//			none
// output:
//			none
/****************************************/
void CDebugToolDlg::OnRead()
{
	CString	sReadAddr = _T("");
	CString sRead = "";
	int	nReadAddr = 0;
	int	nBit = 0;
	CString sAddr = _T("");
	CString sResult = _T("");
	GetDlgItem(IDC_ReadAddr)->GetWindowText(sReadAddr);
	// get address value 
	if((sReadAddr.GetAt(1) == 'x')||(sReadAddr.GetAt(1) == 'X'))
	{
		for(int i = 2; i<sReadAddr.GetLength(); i++)
		{
             sAddr = sAddr+sReadAddr.GetAt(i);
		}
	}
	else
	{
		sAddr = sReadAddr;
	}
	nReadAddr = StrToHex(sAddr);
	
	msg(m_index++, "Read data(hex):");
	
	//	printf format "Addr     data1     data2       data3     data4"
	for(int m = 0; m<4; m++)
	{
		sResult.Format("%s   %08.8x    %08.8x   %08.8x   %08.8x",sAddr,Jtag.UsbJtagRead(nReadAddr),Jtag.UsbJtagRead(nReadAddr+0x00000004),Jtag.UsbJtagRead(nReadAddr+0x00000008),Jtag.UsbJtagRead(nReadAddr+0x0000000c));
		msg(m_index++, sResult);
		nReadAddr = nReadAddr +0x00000010;
		sAddr.Format("%x",nReadAddr);
		nBit = sAddr.GetLength();
		while(nBit<8)
		{
			sAddr = "0" + sAddr;
			nBit++;
		}
	}
	msg(m_index++, ">>");
	m_list.SetTopIndex(m_index - 1);
	
}
/****************************************/
// function: printf message
// input: 
//			CString msg
// output:
//			none
/****************************************/
void CDebugToolDlg::msg(int index, CString msg)
{
	m_list.InsertString(index, msg);
}

/****************************************/
// function: printf sparc V8
// input: 
//			CString disas
// output:
//			none
/****************************************/
void CDebugToolDlg::showV8(int index, CString disas)
{
	m_Disas.InsertString(index, disas);
}

/****************************************/
// function: printf pc
// input: 
//			int index
// output:
//			none
/****************************************/
void CDebugToolDlg::showpc(int index, CString str)
{
	m_pc.InsertString(index, str);
}

/****************************************/
// function: delete PC
// input: 
//			int index
// output:
//			none
/****************************************/
void CDebugToolDlg::delpc(int index)
{
	m_pc.DeleteString(index);
}

/****************************************/
// function: translate char to Hex
// input: 
//			CString charstr
// output:
//			BYTE
/****************************************/
BYTE CDebugToolDlg::NibbleToHex(CString charStr )
{
	BYTE bTemp = 0;
	if (charStr.GetAt(0) == '0') bTemp = 0;
	if (charStr.GetAt(0) == '1') bTemp = 1;
	if (charStr.GetAt(0) == '2') bTemp = 2;
	if (charStr.GetAt(0) == '3') bTemp = 3;
	if (charStr.GetAt(0) == '4') bTemp = 4;
	if (charStr.GetAt(0) == '5') bTemp = 5;
	if (charStr.GetAt(0) == '6') bTemp = 6;
	if (charStr.GetAt(0) == '7') bTemp = 7;
	if (charStr.GetAt(0) == '8') bTemp = 8;
	if (charStr.GetAt(0) == '9') bTemp = 9;

	if (charStr.GetAt(0) == 'A') bTemp = 10;
	if (charStr.GetAt(0) == 'B') bTemp = 11;
	if (charStr.GetAt(0) == 'C') bTemp = 12;
	if (charStr.GetAt(0) == 'D') bTemp = 13;
	if (charStr.GetAt(0) == 'E') bTemp = 14;
	if (charStr.GetAt(0) == 'F') bTemp = 15;

	if (charStr.GetAt(0) == 'a') bTemp = 10;
	if (charStr.GetAt(0) == 'b') bTemp = 11;
	if (charStr.GetAt(0) == 'c') bTemp = 12;
	if (charStr.GetAt(0) == 'd') bTemp = 13;
	if (charStr.GetAt(0) == 'e') bTemp = 14;
	if (charStr.GetAt(0) == 'f') bTemp = 15;
	return bTemp;
}

/****************************************/
// function: translate CString to Hex
// input: 
//			CString c4harstr
// output:
//			BYTE
/****************************************/
int CDebugToolDlg::StrToHex( CString char4Str )
{
	int bTemp=0;
	CString nibbleStr=_T("");
	int i = char4Str.GetLength();
	int j = 0;
	while(j<i)
	{
		nibbleStr = char4Str.GetAt(j);
		if (nibbleStr != " ")
		{
			bTemp = (bTemp*16) + NibbleToHex(nibbleStr);
		}
		j = j + 1;
	}
	return bTemp;
}

int CDebugToolDlg::StrToDec( CString char4Str )
{
	int bTemp = 0;
	CString nibbleStr = _T("");
	int i = char4Str.GetLength();
	int j = 0;
	while(j<i)
	{
		nibbleStr = char4Str.GetAt(j);
		if (nibbleStr != " ")
		{
			bTemp = (bTemp*10) + NibbleToHex(nibbleStr);
		}
		j = j + 1;
	}
	return bTemp;
}

/****************************************/
// function: examine jtag chain device
//			 and get deviceID
// input: 
//			long icehandle
//			long portID
// output:
//			none
/****************************************/
long CDebugToolDlg::ExamineJtagChain( long portID)
{
	long status = AMTXHAL_STATUS_SUCCESS;
    long safeChainStatus;  
	long safeTrstLevel;
	long safeFrequency;            
	long safeTapNum; 
	long i;
	long tapError;
	long tapID;
	CString str;
	status = Jtag.GetJtagChainInfo(portID, &safeChainStatus, &safeTrstLevel, &safeFrequency, &safeTapNum);  

	if (status == AMTXHAL_STATUS_SUCCESS)
	{
		if (safeChainStatus == AMTXHAL_JTAGXPLORE_CHAIN_STATUS_SUCCESS)
		{
			str.Format("JTAG chain number of TAPs: %d\n", safeTapNum);
			msg(m_index++, str);
			// we could print the IDCODE of each TAPs found
     
			for (i = safeTapNum; i > 0; i--) 
			{
				// read TAPID 3 times to be sure the tapID is right 
				// kenichi 05 2007.7.30 >>
				Jtag.GetTapID(portID, i-1, &tapError, &tapID);
				Jtag.GetTapID(portID, i-1, &tapError, &tapID);
				Jtag.GetTapID(portID, i-1, &tapError, &tapID);
				// <<
				if (tapError == AMTXHAL_JTAGXPLORE_TAP_STATUS_SUCCESS)
				{
					// kenichi 03 2007.7.27 >>
					msg(m_index++, "JTAG chain:");
					DetectIRLength(tapID);
					// <<
				}
			}
		}
		else
		{
			msg(m_index++, "JTAG chain is corrupted, broken or not stable !");
			status = 1;
		}
	}
    else
    {
	  str.Format("JTAG chain is NOT found on ICE PORT %d !\n", portID);
      msg(m_index++, str);
	  str.Format("Please check your physical JTAG connection, and try again.");
      msg(m_index++, str);
	  msg(m_index++, ">>");
	  m_list.SetTopIndex(m_index - 1);
      status = 1;
	  
    }

	return status;
}

/****************************************/
// function: detect ir length
// input: 
//			long tapid
// output:
//			none
/****************************************/
// kenichi 03 2007.7.27 >>
void CDebugToolDlg::DetectIRLength(long tapid)
{
	int i;
	CString s;
	for (i = 0; i < 7; i++)
	{
		if (jtagdevice[i].idcode == tapid)
		{
			// kenichi 04 2007.7.30 >>
			Jtag.irLength = jtagdevice[i].ir_len;
			// <<

			s.Format("%s(%x)", jtagdevice[i].Name, tapid);
			msg(m_index++, s);
			s.Format("ir length: %d", jtagdevice[i].ir_len);
			msg(m_index++, s);
			break;
		}		
	}
	
	if (i >= 7 || tapid == 0x00000000)
		msg(m_index++, "Detect ir length fail !");

	return ;
}
// kenichi 03 2007.7.27 <<
/****************************************/
// function: open jtag
// input: 
//			none
// output:
//			none
/****************************************/
void CDebugToolDlg::OnOpen() 
{
    OpenJtagType nOpenJtag;
	if (m_bOpen)
	{
		msg(m_index++, "jtagkey is open, please close first!");
		msg(m_index++, ">>");	
		m_list.SetTopIndex(m_index - 1);
		return ;
	}
	else
		nOpenJtag = Jtag.OpenJtag();
	long status = 0;
	if(nOpenJtag == IceOpenSuccess)
	{
		m_bOpen = TRUE;
		msg(m_index++, "GRMONRCP PROC2S60 debug monitor v1.1.1a (evaluation version)");
		msg(m_index++, "Copyright (C) 2007 JSM Research - all rights reserved.");
		msg(m_index++, "Comments or bug-reports to Kenichi@jetsec.com.cn");
		msg(m_index++, "");
		msg(m_index++, "using AMONTEC USB JTAG cable");
		if (ExamineJtagChain(AMTXHAL_PORT_ID_DEFAULT))
			return;
		msg(m_index++, "");
		msg(m_index++, "Initializing...");
		long frequencyIsSafe;           // O - return AMTXHAL_JTAG_FREQUENCY_IS_SAFE_
		long frequencyIsInCMDQ;     // O - return AMTXHAL_JTAG_FREQUENCY_IS_IN_QUEUE_ 
		long frequencyInCMDQ;    // O - return JTAG frequency in the CMDQ if isInCMDQ
		long frequencyInICE;
		CString freqValue(_T(""));
		long freqData = 0;

		// set jtag ice frequency
		GetDlgItem(IDC_FREQENCE)->GetWindowText(freqValue);
		freqData = StrToDec(freqValue);
		if (freqData >= 100 && freqData <= 6000000)
		{
			if ( Jtag.SetJtagFrequency(freqData) != AMTXHAL_STATUS_SUCCESS)
			{
				msg(m_index++, "Set jtag frequency fail !");
				return;
			}
		}
		else
		{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -