CN1312588C - Realizing method of cross regulator based on EJTAG components of targeting machine - Google Patents
Realizing method of cross regulator based on EJTAG components of targeting machine Download PDFInfo
- Publication number
- CN1312588C CN1312588C CNB2004100090019A CN200410009001A CN1312588C CN 1312588 C CN1312588 C CN 1312588C CN B2004100090019 A CNB2004100090019 A CN B2004100090019A CN 200410009001 A CN200410009001 A CN 200410009001A CN 1312588 C CN1312588 C CN 1312588C
- Authority
- CN
- China
- Prior art keywords
- ejtag
- register
- return
- breakpoint
- function
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
Images
Landscapes
- Debugging And Monitoring (AREA)
Abstract
Description
技术领域technical field
基于目标机上的EJTAG部件的交叉调试器实现方法属于计算机系统调试工具领域。The method for implementing a cross-debugger based on EJTAG components on a target machine belongs to the field of computer system debugging tools.
背景技术Background technique
在开发和生产新的电子、电脑产品时,经常会面对以下几个方面的问题:(1)电路的器件布局日益复杂;(2)元器件小型化、复杂的封装、密集的管脚;和(3)电路板小型化、使用表面焊接技术等。这给产品的线路测试、故障检查以及排除带来很大的麻烦。用传统的线路检测设备已经很难,甚至无法使用。解决这个问题的一个方法是使用边界扫描技术即BST(Boundary Scan Technology)。该技术由IEEE技术委员会的联接测试行动小组(JTAG,JointTest Action Group)制定(工业标准IEEE1149.1),可用于测试电路板上的:(1)各器件本身的逻辑是否正确;(2)各器件之间的连接情况;和(3)组合起来的器件是否完成了预定的功能等。扩展JTAG即EJTAG(Enhanced JTAG)规范是在JTAG规范基础上进行的扩展。EJTAG的操作对象是MIPS公司的MIPS微处理器或是包含MIPS核的片上系统即SOC(System-on-a-Chip)芯片组件。EJTAG提供了应用程序和核心代码软件调试的应用接口。它具有以下一些功能:When developing and producing new electronic and computer products, we often face the following problems: (1) The device layout of the circuit is becoming increasingly complex; (2) The miniaturization of components, complex packaging, and dense pins; and (3) circuit board miniaturization, use of surface soldering technology, etc. This brings a lot of trouble to the line test, fault inspection and elimination of the product. It is difficult or even impossible to use traditional line detection equipment. One way to solve this problem is to use Boundary Scan Technology (BST (Boundary Scan Technology). This technology is developed by the Joint Test Action Group (JTAG, Joint Test Action Group) of the IEEE Technical Committee (industry standard IEEE1149.1), and can be used to test the circuit board: (1) whether the logic of each device itself is correct; (2) each The connection between the devices; and (3) whether the combined devices have completed the intended functions, etc. Extended JTAG EJTAG (Enhanced JTAG) specification is an extension based on the JTAG specification. The operating object of EJTAG is the MIPS microprocessor of MIPS Company or the system-on-a-chip (SOC) chip component that contains the MIPS core. EJTAG provides the application interface for application program and core code software debugging. It has some of the following features:
1)设置硬件断点(Hardware Breakpoint);1) Set a hardware breakpoint (Hardware Breakpoint);
2)单步执行(Single Step Excution);2) Single Step Execution;
3)支持测试访问端口即TAP(Test Access Port)接口:EJTAG使用TAP接口将测试数据传入或者传出CPU核心。除了支持标准的JTAG指令以外,EJTAG还具有自己新定义的指令。3) Support the test access port, namely TAP (Test Access Port) interface: EJTAG uses the TAP interface to transfer test data into or out of the CPU core. In addition to supporting standard JTAG commands, EJTAG also has its own newly defined commands.
4)支持软件断点指令:SDBBP(Software Debug Breakpoint)。4) Support software breakpoint instruction: SDBBP (Software Debug Breakpoint).
基于EJTAG的调试器可用于调试监控程序、操作系统,并且可以通过调试诊断程序,分析确定CPU及主板的故障,是CPU研制工作顺利进行的重要工具。我们提出了一种利用软件有效控制和使用目标机上的EJTAG部件的方案,据此完成了基于EJTAG的交叉调试器的设计与实现,大大降低了成本,并具有很好的可移植性(支持不同的微处理器只需要修改少量的代码)。The EJTAG-based debugger can be used to debug monitoring programs and operating systems, and can analyze and determine CPU and motherboard faults through debugging diagnostic programs. It is an important tool for the smooth progress of CPU development. We proposed a scheme to use software to effectively control and use the EJTAG components on the target machine, and completed the design and implementation of the EJTAG-based cross-debugger, which greatly reduces the cost and has good portability (supporting different Microprocessor requires only a small amount of code modification).
发明内容Contents of the invention
本发明的目的在于有效控制和使用目标机上的EJTAG部件,以便捷的方式实现运行在宿主机上的汇编级和源码级的调试功能。The purpose of the present invention is to effectively control and use the EJTAG components on the target machine, and to realize the assembly-level and source code-level debugging functions running on the host machine in a convenient manner.
基于目标机上的EJTAG部件的交叉调试器实现方法,其特征在于:调试命令的处理过程是全部在宿主PC机上运行的,该处理过程包含以下步骤:The cross-debugger implementation method based on the EJTAG component on the target machine is characterized in that: the processing process of the debugging command is all run on the host PC, and the processing process includes the following steps:
(1)根据IEEE技术委员会联合测试行动小组Joint Test Action Group简称JTAG制定的IEEEE1149.1工业标准,使扩展了EJTAG部件的目标机MIPS CPU中的测试访问端口即Test Access Port简称TAP接口的下述5个EJTAG/JTAG信号通过信号线与宿主机PC的并行I/O端口相连:(1) According to the IEEE 1149.1 industrial standard formulated by the Joint Test Action Group of the IEEE Technical Committee Joint Test Action Group (JTAG), the test access port in the target machine MIPS CPU that has expanded the EJTAG components, that is, the Test Access Port (TAP interface) is as follows 5 EJTAG/JTAG signals are connected to the parallel I/O port of the host PC through signal lines:
TCK即测试时钟信号,方向从宿主PC机到目标机MIPS CPU;TCK is the test clock signal, the direction is from the host PC to the target MIPS CPU;
TMS即测试方式选择信号,方向从宿主PC机到目标机MIPS CPU;TMS is the test mode selection signal, the direction is from the host PC to the target MIPS CPU;
TDI即测试数据输入信号,方向从宿主PC机到目标机MIPS CPU;TDI is the test data input signal, the direction is from the host PC to the target MIPS CPU;
TDO即测试数据输出信号,方向从目标机MIPS CPU到宿主PC机;TDO is the test data output signal, the direction is from the target MIPS CPU to the host PC;
TRST*即测试复位信号,该信号是可选信号;TRST * is the test reset signal, which is an optional signal;
(2)在宿主PC机的存储器上建立以下模块:(2) Establish the following modules on the memory of the host PC:
对于运行在Windows系统下的汇编级调试器,它建有以下模块:For an assembly-level debugger running on Windows, it has the following modules:
a.人机界面模块,采用图形用户接口GUI界面,被调试目标代码的显示格式使用反汇编代码,它通过以下函数来提供操作界面:a. The man-machine interface module adopts the graphical user interface GUI interface, and the display format of the debugged object code uses disassembled code, which provides the operation interface through the following functions:
OnOpenDocument():把反汇编显示格式的代码读入内存,并设定以下变量之值:OnOpenDocument(): Read the code in the disassembly display format into the memory, and set the values of the following variables:
存储每行代码的长度,store the length of each line of code,
存储代码,store code,
当前行特征位flag,1表示为当前行,0表示非当前行,The flag of the current row, 1 means the current row, 0 means not the current row,
断点表,存储断点信息,0表示无断点,非0表示有断点,相应数字即断点类型,Breakpoint table, store breakpoint information, 0 means no breakpoint, non-zero means there is a breakpoint, the corresponding number is the type of breakpoint,
代码行特征位flag,1表示为代码行,0表示非代码行;Code line feature bit flag, 1 means code line, 0 means non-code line;
OnDownload():下载汇编得到的代码到目标机指定地址开始的存储区域;OnDownload(): Download the compiled code to the storage area starting from the specified address of the target machine;
OnDraw():以不同颜色显示代码;OnDraw(): Display codes in different colors;
OnEditBrk():添加断点,向接口发出断点指令;OnEditBrk(): Add a breakpoint and issue a breakpoint command to the interface;
OnEditMem():得到并显示指定地址内存的内容;OnEditMem(): Get and display the contents of the memory at the specified address;
OnEditReg():得到并显示所有寄存器的值;OnEditReg(): Get and display the values of all registers;
OnRestart():发送重启指令,重启CPU;OnRestart(): Send a restart command to restart the CPU;
OnSingleStep():发送单步操作命令,并获得单步操作后寄存器的值;OnSingleStep(): Send a single-step operation command and obtain the value of the register after the single-step operation;
OnRemoveBreakPoint():移除断点;OnRemoveBreakPoint(): remove the breakpoint;
Pack():根据RSP协议,为包的内容添置包头包尾,所述RSP为Remote SerialProtocol的缩写;Pack (): According to the RSP protocol, add a header and a tail for the content of the packet, and the RSP is the abbreviation of Remote Serial Protocol;
b.调试请求处理模块,它是上层的人机界面模块和下层的EJTAG/JTAG信号转换及处理模块的应用程序API,它把人机界面的调试请求转换成为符合Remote Serial Protocol协议的数据包,发送给EJTAG/JTAG信号转换及处理模块,再接收其响应,该EJTAG/JTAG信号转换及处理模块设有以下9类调试命令:b. The debugging request processing module, which is the application program API of the upper human-machine interface module and the lower EJTAG/JTAG signal conversion and processing module, which converts the debugging request of the human-machine interface into a data packet conforming to the Remote Serial Protocol protocol, Send to the EJTAG/JTAG signal conversion and processing module, and then receive its response. The EJTAG/JTAG signal conversion and processing module has the following 9 types of debugging commands:
g命令:读所有的寄存器,g command: read all registers,
G命令:写入所有的寄存器,G command: write all registers,
m命令:读存储器,m command: read memory,
M命令:写存储器,R命令:复位,发出CPU中断后执行的起始地址,M command: write memory, R command: reset, start address executed after CPU interrupt is issued,
c命令:继续,发出清除单步标志后继续执行的起始地址,c command: continue, issue the starting address to continue execution after clearing the single-step flag,
s命令:单步操作,发出开始单步执行的起始地址,s command: single-step operation, issue the starting address to start single-step execution,
z命令:插入断点,设定某一地址范围为断点,z command: insert a breakpoint, set a certain address range as a breakpoint,
Z命令:移除断点,取消某一地址范围的断点,Z command: remove the breakpoint, cancel the breakpoint of a certain address range,
相应地,调试请求处理模块设定以下各个调试请求所用到的函数:Correspondingly, the debugging request processing module sets the following functions used by each debugging request:
CallAPI():根据从人机界面传来的调试命令,分别调用EJTAG/JTAG信号转换及处理模块给出的CallR(),Callg(),CallG(),Callm(),CallM(),Callc(),Calls(),Callz(),CallZ()函数,再返回调试结果,CallAPI(): Call CallR(), Callg(), CallG(), Callm(), CallM(), Callc( ), Calls(), Callz(), CallZ() functions, and then return the debugging results,
VerifyCommand():验证指令包是否合法,并从中提取有用部分,VerifyCommand(): Verify whether the instruction package is legal, and extract useful parts from it,
GetFirstChar():提取指令的第一个字符,GetFirstChar(): Extract the first character of the instruction,
StrFreeCpy():拷贝一个串;StrFreeCpy(): copy a string;
c.EJTAG/JTAG信号转换及处理模块,它把RSP格式的调试命令请求转换为JTAG信号,使得与目标机CPU的处理过程同步,并返回响应信息,相应于上述9类调试命令,它对应地设有以下接口函数:c. EJTAG/JTAG signal conversion and processing module, which converts the debugging command request in RSP format into JTAG signal, so that it is synchronized with the processing process of the target machine CPU, and returns the response information, corresponding to the above 9 types of debugging commands, it corresponds to It has the following interface functions:
CallR():执行R命令,返回结果,CallR(): Execute the R command and return the result,
Callg():执行g命令,返回结果,Callg(): Execute the g command and return the result,
CallG():执行G命令,返回结果,CallG(): Execute the G command and return the result,
Callm():执行m命令,返回结果,Callm(): Execute the m command and return the result,
CallM():执行M命令,返回结果,CallM(): Execute the M command and return the result,
Callc():执行c命令,返回结果,Callc(): Execute the c command and return the result,
Calls():执行s命令,返回结果,Calls(): Execute the s command and return the result,
Callz():执行z命令,返回结果,Callz(): Execute the z command and return the result,
CallZ():执行Z命令,返回结果;CallZ(): Execute the Z command and return the result;
这些接口函数的实现用到了如下函数:The implementation of these interface functions uses the following functions:
Pack():根据RSP协议,为包的内容添置包头包尾,Pack(): According to the RSP protocol, add a header and tail to the contents of the packet,
SetWord():通过EJTAG TAP设置一个32位EJTAG寄存器的值,返回值为0;SetWord(): Set the value of a 32-bit EJTAG register through EJTAG TAP, and the return value is 0;
GetWord():通过EJTAG TAP接口取得一个32位EJTAG寄存器的值,返回寄存器的值,GetWord(): Obtain the value of a 32-bit EJTAG register through the EJTAG TAP interface, and return the value of the register,
IsDigit():判断一个字符是否代表一个十六进制数字,是则返回值1,非则返回值,IsDigit(): Determine whether a character represents a hexadecimal digit, if yes, return
SendSignal():通过并行I/O端口将信号发送到EJTAG TAP接口并接受反馈;SendSignal(): Send the signal to the EJTAG TAP interface through the parallel I/O port and receive feedback;
对于运行在Linux系统下的高级语言级调试器,人机界面通过一种常用的调试程序GDB实现,调试命令通过下述的EJTAG驱动程序模块传递给上述EJTAG/JTAG信号转换及处理模块;For the high-level language debugger running under the Linux system, the human-machine interface is realized by a common debugging program GDB, and the debugging command is passed to the above-mentioned EJTAG/JTAG signal conversion and processing module through the following EJTAG driver module;
d.EJTAG驱动程序模块,实现了开始调试、结束调试、发送调试请求、读取调试响应四项功能;它与上述EJTAG/JTAG信号转换及处理模块之间进行的调试命令的交换是采用GDB的RSP协议格式,因此汇编级调试器和高级语言级调试器共享EJTAG/JTAG信号转换及处理模块;该EJTAG驱动程序采用可装载的内核模块的方式:用insmod命令装入该模块,用rmmod命令卸载该模块;在EJTAG模块装入Linux系统以后,建立了一个符合GDB的串口调试要求的设备文件/dev/ejtag;d. The EJTAG driver module realizes the four functions of starting debugging, ending debugging, sending debugging requests, and reading debugging responses; it uses GDB to exchange debugging commands with the above-mentioned EJTAG/JTAG signal conversion and processing modules RSP protocol format, so the assembly-level debugger and the high-level language-level debugger share the EJTAG/JTAG signal conversion and processing module; the EJTAG driver uses a loadable kernel module: load the module with the insmod command, and unload it with the rmmod command This module; after the EJTAG module is loaded into the Linux system, a device file /dev/ejtag that meets the GDB serial port debugging requirements is established;
(3)运行于Windows系统下的汇编级调试器的执行过程:(3) The execution process of the assembly-level debugger running under the Windows system:
a.通过函数OnOpenDocument()将反汇编格式的被调试目标代码装入内存,a. Load the debugged object code in the disassembled format into the memory through the function OnOpenDocument(),
b.通过函数OnDraw()以不同颜色显示代码,b. Display the code in different colors through the function OnDraw(),
c.若需要,通过函数OnDownload()将代码下载到目标机,c. If necessary, download the code to the target machine through the function OnDownload(),
d.根据需要,通过函数OnEditBrk(),OnEditMem(),OnEditReg(),OnRestart(),OnSingleStep(),OnRemoveBreakPoint()实现添加断点,得到并显示指定地址内存的内容,得到并显示所有寄存器的值,重启CPU,发送单步操作命令并获得单步操作后寄存器的值,移除断点的操作,d. According to the needs, add breakpoints through the functions OnEditBrk(), OnEditMem(), OnEditReg(), OnRestart(), OnSingleStep(), OnRemoveBreakPoint(), obtain and display the contents of the specified address memory, and obtain and display the contents of all registers value, restart the CPU, send a single-step operation command and obtain the value of the register after the single-step operation, remove the breakpoint operation,
e.多次选择执行调试命令调用以上函数,执行完调试命令后退出调试器;e. Choose to execute the debugging command multiple times to call the above function, and exit the debugger after executing the debugging command;
(4)运行于Linux系统下的高级语言级调试器的执行过程:(4) The execution process of the high-level language debugger running under the Linux system:
a.用insmod命令装入EJTAG驱动程序模块,a. Load the EJTAG driver module with the insmod command,
b.通过GDB命令实现需要完成的调试操作,b. Realize the debugging operation that needs to be completed through the GDB command,
c.执行完调试操作后退出GDB,c. Exit GDB after executing the debugging operation,
d.用rmmod命令卸载EJTAG驱动程序模块;d. Uninstall the EJTAG driver module with the rmmod command;
(5)对于运行于Windows系统下的汇编级调试器,调试请求处理模块的主函数CallAPI(),利用函数VerifyCommand()和GetFirstChar()对调试命令进行校验及合法性检验,然后再根据调试命令分别调用EJTAG/JTAG信号转换及处理模块给出的CallR(),Callg(),CallG(),Callm(),CallM(),Callc(),Calls(),Callz(),CallZ()函数,再返回调试结果;(5) For the assembly-level debugger running under the Windows system, the main function CallAPI() of the debugging request processing module uses the functions VerifyCommand() and GetFirstChar() to verify and check the validity of the debugging command, and then according to the debugging The commands respectively call the CallR(), Callg(), CallG(), Callm(), CallM(), Callc(), Calls(), Callz(), CallZ() functions given by the EJTAG/JTAG signal conversion and processing module , and then return the debugging result;
(6)与汇编级调试器类似,对于运行于Linux系统下的高级语言级调试器,连接GDB的EJTAG驱动程序模块使GDB发出的调试命令分别调用EJTAG/JTAG信号转换及处理模块给出的CallR(),Callg(),CallG(),Callm(),CallM(),Callc(),Calls(),Callz(),CallZ()等函数,再返回调试结果;(6) Similar to the assembly-level debugger, for the high-level language-level debugger running under the Linux system, connect the EJTAG driver module of GDB so that the debugging commands issued by GDB call the CallR given by the EJTAG/JTAG signal conversion and processing module respectively (), Callg(), CallG(), Callm(), CallM(), Callc(), Calls(), Callz(), CallZ() and other functions, and then return the debugging results;
(7)对于运行于Windows系统下的汇编级调试器以及运行于Linux系统下的高级语言级调试器,二者共用的EJTAG/JTAG信号转换及处理模块给出下述CallR(),Callg(),CallG(),Callm(),CallM(),Callc(),Calls(),Callz(),CallZ()函数的实现:(7) For the assembly-level debugger running under the Windows system and the high-level language-level debugger running under the Linux system, the EJTAG/JTAG signal conversion and processing modules shared by the two give the following CallR(), Callg() , CallG(), Callm(), CallM(), Callc(), Calls(), Callz(), CallZ() function implementation:
(8)函数CallR()的处理过程:(8) Processing procedure of function CallR():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.将EJTAG控制寄存器即ECR寄存器中的复位标志位Rocc置0,以及EJTAG中断请求位EjtabBrk,虚拟内存段dseg,即debug segment有效位ProbEn,和调试例外向量地址控制位ProbTrap皆置1;b. Set the EJTAG control register, that is, the reset flag bit Rocc in the ECR register to 0, and the EJTAG interrupt request bit EjtabBrk, the virtual memory segment dseg, that is, the debug segment effective bit ProbEn, and the debug exception vector address control bit ProbTrap are all set to 1;
c.设置调试例外程序计数器DEBUG Exception Program Counter即DEPC的值;c. Set the debug exception program counter DEBUG Exception Program Counter, which is the value of DEPC;
d.如b,c执行过程出错,即Rocc被置为1,处理器未处于预期的暂停状态则返回,并置出错标志;d. If there is an error in the execution process of b and c, that is, Rocc is set to 1, and the processor returns if it is not in the expected pause state, and an error flag is set;
e.返回;e. return;
(9)函数Callg()的处理过程:(9) Processing procedure of function Callg():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.通过MIPS Store指令得到32个通用寄存器的数值;b. Obtain the values of 32 general-purpose registers through the MIPS Store instruction;
c.通过MIPS MFC0和Store指令得到27个cp0寄存器的数值;c. Obtain the values of 27 cp0 registers through MIPS MFC0 and Store instructions;
d.如b,c执行过程出错,即Rocc被置为1,处理器未处于预期的暂停状态则返回,并置出错标志;d. If there is an error in the execution process of b and c, that is, Rocc is set to 1, and the processor returns if it is not in the expected pause state, and an error flag is set;
e.返回通用寄存器和cp0寄存器的内容;e. Return the contents of the general-purpose register and the cp0 register;
(10)函数CallG()的处理过程:(10) Processing procedure of function CallG():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.通过MIPS Load和MTC0指令设置27个cp0寄存器的数值;b. Set the value of 27 cp0 registers through MIPS Load and MTC0 instructions;
c.通过MIPS Load指令设置32个通用寄存器的数值;c. Set the value of 32 general-purpose registers through the MIPS Load instruction;
d.如b,c执行过程出错,即Rocc被置为1,处理器未处于预期的暂停状态则返回,并置出错标志;d. If there is an error in the execution process of b and c, that is, Rocc is set to 1, and the processor returns if it is not in the expected pause state, and an error flag is set;
e.返回“OK”;e. Return "OK";
(11)函数Callm()的处理过程:(11) The processing of the function Callm():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.将内存内容装入到通用寄存器;b. Load the contents of the memory into the general-purpose registers;
c.通过MIPS Store指令得到通用寄存器的数值;c. Obtain the value of the general-purpose register through the MIPS Store instruction;
d.如b,c执行过程出错,即Rocc被置为1,处理器未处于预期的暂停状态则返回,并置出错标志;d. If there is an error in the execution process of b and c, that is, Rocc is set to 1, and the processor returns if it is not in the expected pause state, and an error flag is set;
e.返回内存内容;e. Return memory content;
(12)函数CallM()的处理过程:(12) Processing procedure of function CallM():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.通过MIPS Load指令得到通用寄存器的数值;b. Obtain the value of the general-purpose register through the MIPS Load instruction;
c.将通用寄存器数值存入到内存中去;c. Store the general-purpose register value into memory;
d.如b,c执行过程出错,即Rocc被置为1,处理器未处于预期的暂停状态则返回,并置出错标志;d. If there is an error in the execution process of b and c, that is, Rocc is set to 1, and the processor returns if it is not in the expected pause state, and an error flag is set;
e.返回“OK”;e. Return "OK";
(13)函数Callc()的处理过程:(13) The processing of the function Callc():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.清除Debug寄存器中的SSt位;b. Clear the SSt bit in the Debug register;
c.设置调试例外程序计数器DEPC的值;c. Set the value of the debug exception program counter DEPC;
d.把MIPS DERET指令填入TAP的DATA寄存器;d. Fill the MIPS DERET instruction into the DATA register of TAP;
e.调用Callg()得到寄存器内容;e. Call Callg() to get the contents of the register;
f.如b,c,d,e执行过程出错,即Rocc被置为1,处理器未处于预期的暂停状态则返回,并置出错标志;f. If there is an error in the execution process of b, c, d, e, that is, Rocc is set to 1, the processor will return if it is not in the expected pause state, and set the error flag;
g.返回结果;g. return the result;
(14)函数Calls()的处理过程:(14) The processing of the function Calls():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.清除Debug寄存器中的SSt位;b. Clear the SSt bit in the Debug register;
c.设置调试例外程序计数器DEPC的值;c. Set the value of the debug exception program counter DEPC;
d.把MIPS DERET指令填入TAP的数据寄存器;d. Fill the MIPS DERET instruction into the data register of TAP;
e.调用Callg()得到寄存器内容;e. Call Callg() to get the contents of the register;
f.如b,c,d,e执行过程出错,即Rocc被置为1,处理器未处于预期的暂停状态则返回,并置出错标志;f. If there is an error in the execution process of b, c, d, e, that is, Rocc is set to 1, the processor will return if it is not in the expected pause state, and set the error flag;
g.返回结果;g. return the result;
(15)函数Callz()的处理过程:(15) Processing procedure of function Callz():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.断点对应的指令断点状态寄存器中的IBC域中的标志位ASIDuse置为0,BE置为1,若为数据断点,还需设置数据断点状态寄存器DBC域中的标志位BAL置为0,BLM置为1;b. The flag bit ASIDuse in the IBC field of the instruction breakpoint state register corresponding to the breakpoint is set to 0, BE is set to 1, if it is a data breakpoint, the flag bit BAL in the DBC field of the data breakpoint state register needs to be set Set to 0, BLM to 1;
c.设置断点对应的指令断点状态寄存器中的IBA域;c. Set the IBA field in the instruction breakpoint status register corresponding to the breakpoint;
d.设置断点对应的指令断点状态寄存器中的IBM域;d. Set the IBM domain in the instruction breakpoint status register corresponding to the breakpoint;
e.如b,c,d执行过程出错,即Rocc被置为1,处理器未处于预期的暂停状态则返回,并置出错标志;e. If there is an error in the execution process of b, c, and d, that is, Rocc is set to 1, and the processor is not in the expected pause state, it will return and set the error flag;
f.返回“OK”;f. Return "OK";
(16)函数CallZ()的处理过程:(16) Processing procedure of function CallZ():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.断点对应的指令断点状态寄存器中的IBC域中的标志位BE置为0;b. The flag bit BE in the IBC field in the instruction breakpoint status register corresponding to the breakpoint is set to 0;
c.如b执行过程出错,即Rocc被置为1,处理器未处于预期的暂停状态,则返回,并置出错标志;c. If there is an error in the execution process of b, that is, Rocc is set to 1, and the processor is not in the expected pause state, return and set the error flag;
d.返回“OK”;d. Return "OK";
(17)上述(8)到(16)所述的EJTAG/JTAG信号转换及处理过程把调试命令转换成为一个机器指令的序列,然后通过TAP接口一条一条地送给CPU执行,并取回结果内容,进行打包后返回;根据TAP的控制流程,在调试器命令的处理过程中,TAP寄存器的读写是在数据寄存器移位或指令寄存器移位状态进行的,在测试时钟信号下降沿串行地将测试数据移出,在上升沿串行地将测试数据移入;在写TAP寄存器时移入新数据;读TAP寄存器时保存移出的数据以供返回,同时移入新数据;(17) The EJTAG/JTAG signal conversion and processing process described in (8) to (16) above converts the debugging command into a sequence of machine instructions, and then sends them to the CPU one by one through the TAP interface for execution, and retrieves the result content , and return after packaging; according to the control flow of TAP, during the processing of debugger commands, the reading and writing of TAP registers is carried out in the state of data register shift or instruction register shift, and serially at the falling edge of the test clock signal Shift out the test data, shift in the test data serially on the rising edge; shift in new data when writing the TAP register; save the shifted out data for return when reading the TAP register, and shift in new data at the same time;
(18)调试命令的完成需要与目标机CPU进行配合,其基本工作过程为:(18) The completion of the debugging command needs to cooperate with the CPU of the target machine, and its basic working process is:
a.调试器循环检测ECR寄存器的PrAcc位,若为0,继续检测;若为1,表示处理器已经完成请求的操作而暂停,转以下步骤b;a. The debugger cyclically detects the PrAcc bit of the ECR register. If it is 0, continue to detect; if it is 1, it means that the processor has completed the requested operation and paused, and then go to the following step b;
b.调试器根据运行的状态,决定下一步动作:b. The debugger determines the next action according to the running state:
·如果是等待CPU中断,表示CPU已进入调试例外处理,等待例外处理的代码;那么把特定指令放入TAP的数据寄存器;·If it is waiting for CPU interrupt, it means that the CPU has entered the debugging exception processing, waiting for the code of exception processing; then put the specific instruction into the data register of TAP;
·如果是刚让CPU执行了装入或存储指令,并且操作数地址位于dseg段,那么需要提供操作数,即装入指令往TAP的数据寄存器写,或者读出数据,即存储指令从TAP的数据寄存器读);If the CPU has just executed a load or store instruction, and the operand address is located in the dseg segment, then the operand needs to be provided, that is, the load instruction is written to the data register of TAP, or the data is read, that is, the store instruction is from the TAP data register read);
c.调试器把EJTAG控制寄存器ECR的PrAcc位置为0,表示调试器就绪,CPU可以继续;c. The debugger sets the PrAcc position of the EJTAG control register ECR to 0, indicating that the debugger is ready and the CPU can continue;
d.转a;d. turn to a;
(19)上述(8)到(16)返回结果最终会反映到用户界面,之后调试器的运行过程如(3)、(4)所述。(19) The results returned from (8) to (16) above will eventually be reflected on the user interface, and then the running process of the debugger is as described in (3) and (4).
根据本发明实现的基于目标机上的EJTAG部件的交叉调试器的思路是:The idea of the cross-debugger based on the EJTAG parts on the target machine realized according to the present invention is:
(1)本调试器适用的目标机为MIPS系列体系结构的CPU,并且它扩展了支持EJTAG规范的部件;参见图1,非透明填充背景的部分为EJTAG增加的部分;只需要CPU可以执行基本的指令集(包括MTC0/MFC0/LUI/LW/SW/LB/SB/DERET/ADD等)就可以使用。(1) The target machine suitable for this debugger is the CPU of the MIPS series architecture, and it extends the components supporting the EJTAG specification; see Figure 1, the part with the non-transparent filled background is the part added by EJTAG; only the CPU can execute the basic The instruction set (including MTC0/MFC0/LUI/LW/SW/LB/SB/DERET/ADD, etc.) can be used.
(2)测试访问端口TAP接口的5个JTAG信号TCK(测试时钟Test Clock信号)、TMS(测试方式选择Test Mode Select信号)、TDI(测试数据输入Test Data Input信号)、TDO(测试数据输出Test Data Output信号)和TRST*(测试复位Test Reset Input*信号)通过简单的线路与宿主机的并口相连;表1是JTAG信号和宿主机上的I/O端口数据的对应关系。(2) 5 JTAG signals TCK (test clock Test Clock signal), TMS (test mode select Test Mode Select signal), TDI (test data input Test Data Input signal), TDO (test data output Test Data Output signal) and TRST * (test reset Test Reset Input * signal) are connected to the parallel port of the host computer through a simple line; Table 1 is the corresponding relationship between the JTAG signal and the I/O port data on the host computer.
表1 JTAG信号和I/O端口数据信号对照表Table 1 Comparison table of JTAG signal and I/O port data signal
其中BASE代表所用的并口的基地址,在PC机上其默认值是0x378。BASE+1表示并口的状态端口。表中的信号方向是从宿主机(PC)的角度看的。复位信号TRST*是可选信号,表中未列出其对应关系。Among them, BASE represents the base address of the parallel port used, and its default value is 0x378 on the PC. BASE+1 indicates the status port of the parallel port. The signal directions in the table are from the perspective of the host computer (PC). The reset signal TRST * is an optional signal, and its corresponding relationship is not listed in the table.
(3)汇编级调试功能运行于Windows系统,被调试目标代码的显示格式使用反汇编代码;源码级调试功能运行于Linux系统;下载到目标机的格式采用的是Motorola的S-记录即S-Record格式。(3) The assembly-level debugging function runs on the Windows system, and the display format of the debugged target code uses disassembled code; the source code-level debugging function runs on the Linux system; Record format.
(4)调试器的基本功能涉及断点管理(增加、删除、列出断点)、信息查询(查看/修改寄存器的内容、查看/修改指定地址的数据)、执行控制(单步、继续、暂停、复位)及代码管理(装入目标代码用于本地显示、目标代码下载到目标机、显示源代码)等。(4) The basic functions of the debugger involve breakpoint management (add, delete, list breakpoints), information query (check/modify the contents of the register, check/modify the data of the specified address), execution control (single step, continue, pause, reset) and code management (loading target code for local display, downloading target code to target machine, displaying source code), etc.
(5)调试器的工作是一个软硬件协同工作的过程。调试器启动时,将EJTAG控制寄存器即ECR寄存器中的复位标志位Rocc置0,以及EJTAG中断请求位EjtabBrk,虚拟内存段dseg(debug segment)有效位ProbEn,和调试例外向量地址控制位ProbTrap皆置1,使CPU中断正在执行的程序,进入调试模式。CPU进入调试模式后,它依次执行调试器发送过来的指令,并和调试器交换有关内容,从而完成调试工作。(5) The work of the debugger is a process of software and hardware working together. When the debugger starts, set the EJTAG control register, namely the reset flag bit Rocc in the ECR register, to 0, and the EJTAG interrupt request bit EjtabBrk, the effective bit ProbEn of the virtual memory segment dseg (debug segment), and the debug exception vector address control bit ProbTrap. 1. Make the CPU interrupt the program being executed and enter the debug mode. After the CPU enters the debugging mode, it executes the instructions sent by the debugger in turn, and exchanges relevant content with the debugger to complete the debugging work.
(6)调试命令的交换格式采用GNU组织的GDB远程串行协议即RSP(Remote SerialProtocol,)格式,这样运行于Windows系统的汇编级调试和运行于Linux系统的高级语言级调试可以共享用于转换与处理过程的代码。(6) The exchange format of debugging commands adopts the GDB remote serial protocol organized by GNU, that is, the RSP (Remote Serial Protocol,) format, so that assembly-level debugging running on Windows systems and high-level language-level debugging running on Linux systems can be shared for conversion and process code.
(7)高级语言级调试器的前端采用GNU组织的GDB,后端通过驱动程序和EJTAG/JTAG信号转换及处理过程接口。EJTAG驱动程序采用可装载的内核模块(loadable kernelmodule)的方式。(7) The front-end of the high-level language debugger adopts GDB organized by GNU, and the back-end interfaces with the driver program and EJTAG/JTAG signal conversion and processing process. The EJTAG driver uses a loadable kernel module (loadable kernel module) approach.
根据本发明实现的基于EJTAG的交叉调试器的基本工作过程是:The basic work process of the cross-debugger based on EJTAG realized according to the present invention is:
(1)调试器循环检测ECR寄存器的PrAcc位(暂停标志位,Process Access Pending),若为0,继续检测;若为1,表示处理器已经完成请求的操作而暂停,转(2);(1) The debugger circularly detects the PrAcc bit (pause flag, Process Access Pending) of the ECR register, if it is 0, continue to detect; if it is 1, it means that the processor has completed the requested operation and paused, turn to (2);
(2)调试器根据运行的状态,决定下一步动作:(2) The debugger determines the next action according to the running state:
·如果是等待CPU中断,表示CPU已进入调试例外处理,等待例外处理的代码;那么把特定指令放入TAP的DATA寄存器(数据寄存器);If it is waiting for the CPU to interrupt, it means that the CPU has entered the debugging exception handling, waiting for the exception handling code; then put the specific instruction into the DATA register (data register) of TAP;
·如果是刚让CPU执行了load/store指令,并且操作数地址位于dseg段,那么需要提供操作数(load指令,往TAP的DATA寄存器写),或者读出数据(store指令,从TAP的DATA寄存器读);If the CPU has just executed the load/store instruction, and the operand address is located in the dseg segment, then you need to provide the operand (load instruction, write to the DATA register of TAP), or read the data (store instruction, from the DATA of TAP register read);
(3)调试器把ECR的PrAcc位置为0,表示调试器就绪,CPU可以继续;(4)转(1)。(3) The debugger sets the PrAcc position of the ECR to 0, indicating that the debugger is ready and the CPU can continue; (4) turn to (1).
本发明提出的利用软件有效控制和使用目标机上的EJTAG部件的方案体现在调试器命令的处理过程中。各基本调试命令的处理过程基本相似,下面以“查看寄存器的值”为例加以说明:The scheme of effectively controlling and using the EJTAG components on the target machine proposed by the present invention is embodied in the processing process of debugger commands. The processing process of each basic debugging command is basically similar, and the following uses "check the value of the register" as an example to illustrate:
(1)用户通过图形用户界面GUI或者命令行输入调试请求:查看寄存器reg的内容,其命令格式假定为print $reg;(1) The user inputs the debugging request through the graphical user interface GUI or the command line: check the content of the register reg, and the command format is assumed to be print $reg;
(2)分析用户的调试请求命令(print$reg);(2) Analyze the user's debugging request command (print$reg);
取reg寄存器的顺序号no.of $reg;Take the serial number no.of $reg of the reg register;
打包命令:(request=ReadReg,index=no.of$reg,length=sizeof(int));Packaging command: (request=ReadReg, index=no.of$reg, length=sizeof(int));
调用(3);call(3);
转(4);turn(4);
(3)分析调试请求(ReadReg);(3) Analyze the debugging request (ReadReg);
把该请求的处理转换成为一序列的机器指令;其主要部分如下:Convert the processing of the request into a sequence of machine instructions; its main parts are as follows:
MTC0 $t1,DESAVE ;保存$t1寄存器MTC0 $t1, DESAVE ; save $t1 register
LW $t1,HIGH(dseg) ;dseg就是0xFF200000LW $t1, HIGH(dseg) ; dseg is 0xFF200000
SW no.of$reg,0($t1) ;内容送入TAP的DATA寄存器SW no.of$reg, 0($t1) ; the content is sent to the DATA register of TAP
MFC0 $t1,DESAVE ;恢复$t1寄存器MFC0 $t1, DESAVE ; restore $t1 register
把有关命令序列一条一条地通过TAP接口送给CPU执行,并取回寄存器内容;Send the relevant command sequences to the CPU one by one through the TAP interface for execution, and retrieve the contents of the registers;
打包响应:(response=success,length=sizeof(int),value=value of$reg);Package response: (response=success, length=sizeof(int), value=value of $reg);
返回响应;return response;
(4)获得响应(response=success,length=sizeof(int),value=value of$reg);(4) Get a response (response=success, length=sizeof(int), value=value of $reg);
响应转换成用户友好的方式:$reg=0x12345678(假设value=0x12345678);Response converted into user-friendly way: $reg=0x12345678 (assuming value=0x12345678);
显示结果到GUI或者命令行。Display results to GUI or command line.
读写TAP寄存器是完成以上过程的核心步骤之一。根据EJTAG规范,TAP控制器是一个有限状态机,参见图3,它的状态是由TCK和TMS确定的。TAP控制器在TCK上升沿采样TMS信号,然后根据状态转换图进行转换。TAP状态转换图有16个状态,如图2-5所示。图中箭头边上的数字表示在TCK上升沿时,TMS信号的是处于高电平还是低电平。图3中所标识的状态含义如下:Reading and writing the TAP register is one of the core steps to complete the above process. According to the EJTAG specification, the TAP controller is a finite state machine, see Figure 3, its state is determined by TCK and TMS. The TAP controller samples the TMS signal on the rising edge of TCK, and then converts according to the state transition diagram. The TAP state transition diagram has 16 states, as shown in Figure 2-5. The number beside the arrow in the figure indicates whether the TMS signal is at high level or low level at the rising edge of TCK. The states identified in Figure 3 have the following meanings:
Test-Logic-Reset状态:测试逻辑复位状态,它是初始状态,在此状态下,边界扫描测试逻辑是被禁止的;Run-Test/Idle状态:控制寄存器在两个扫描操作之间进入这种状态,并且在TMS输入为‘0’时一直保持在此状态,在此状态下,所有指令寄存器和测试数据寄存器内容保持不变;Select-DR-Scan状态:确定扫描数据寄存器状态,在此状态下,所有测试数据寄存器保持不变;Select-IR-Scan状态:确定扫描指令寄存器状态,在此状态下,所有测试数据寄存器保持不变;Capture-DR状态:对指令寄存器进行译码,确定要扫描的数据寄存器;Shift-DR状态:在这个状态下测试数据寄存器连接到TDI和TDO之间,每个时钟周期数据串行向TDO方向移动;Exit1-DR状态:是暂时的中间状态,在这个状态下数据保持不变;Pause-DR状态:在这个状态下,暂时停止测试数据在TDI和TDO之间的移动;Exit2-DR状态:在这个状态下,刷新在Shift-DR状态移位的数据寄存器;Update-DR状态:在这个状态下,在Shift-DR状态移入的数据存入由指令寄存器指定的寄存器中;Capture-IR状态:在这个状态下,指令寄存器自动装入固定向量(000012);Shift-IR状态:在这个状态下指令寄存器连接到TDI和TDO之间,每个时钟周期数据串行向TDO方向移动;Exit1-IR状态:是暂时的中间状态,在这个状态下数据保持不变;Pause-IR状态:在这个状态下,暂时停止测试数据在TDI和TDO之间的移动;Exit2-IR状态:在这个状态下,刷新在Shift-IR状态移位的指令寄存器;Update-DR状态:在这个状态下,在Shift-IR状态移入的指令生效。Test-Logic-Reset state: test logic reset state, it is the initial state, in this state, the boundary scan test logic is disabled; Run-Test/Idle state: the control register enters this state between two scan operations state, and remains in this state when the TMS input is '0', in this state, the contents of all instruction registers and test data registers remain unchanged; Select-DR-Scan state: determine the state of the scan data register, in this state In this state, all test data registers remain unchanged; Select-IR-Scan state: determine the state of the scan instruction register, in this state, all test data registers remain unchanged; Capture-DR state: decode the instruction register, determine to Scanned data register; Shift-DR state: In this state, the test data register is connected between TDI and TDO, and the data moves serially to TDO in each clock cycle; Exit1-DR state: It is a temporary intermediate state, in this state The data remains unchanged in the state; Pause-DR state: In this state, the movement of test data between TDI and TDO is temporarily stopped; Exit2-DR state: In this state, the data shifted in the Shift-DR state is refreshed Register; Update-DR state: In this state, the data shifted in the Shift-DR state is stored in the register specified by the instruction register; Capture-IR state: In this state, the instruction register is automatically loaded into the fixed vector (000012) ;Shift-IR state: In this state, the instruction register is connected between TDI and TDO, and the data moves serially to TDO in each clock cycle; Exit1-IR state: It is a temporary intermediate state, and in this state the data remains unchanged. Change; Pause-IR state: In this state, temporarily stop the movement of test data between TDI and TDO; Exit2-IR state: In this state, refresh the instruction register shifted in Shift-IR state; Update-DR State: In this state, the commands entered in the Shift-IR state take effect.
TAP寄存器的读写是在Shift-DR或Shift-IR状态进行的,数据在TCK时钟下降沿串行从TDO移出,在上升沿串行从TDI移入。写TAP寄存器时忽略从TDO移出的数据,新数据从TDI移入;读TAP寄存器时保存从TDO移出的数据供返回,同时将其再从TDI移入,以避免破坏寄存器的内容。其主要流程为:The reading and writing of the TAP register is carried out in the Shift-DR or Shift-IR state, and the data is serially shifted out from TDO on the falling edge of the TCK clock, and serially shifted in from TDI on the rising edge. Ignore the data shifted from TDO when writing the TAP register, and move new data in from TDI; when reading the TAP register, save the data shifted from TDO for return, and move it in from TDI at the same time to avoid destroying the contents of the register. Its main process is:
驱动TAP使其转移到Shift-IR状态Drive TAP to shift to Shift-IR state
把寄存器的选择指令写入TAP的指令寄存器IRWrite the register selection instruction into the instruction register IR of TAP
驱动TAP使其转移到Shift-DR状态Drive TAP to shift to Shift-DR state
for(循环次数=0;循环次数<数据寄存器的位数;循环次数++)for (number of loops = 0; number of loops < number of digits in the data register; number of loops ++)
从TDO移出数据(至本地变量)Move data out of TDO (to local variable)
if(是读取操作)if (is a read operation)
保存该数据(到本地变量)Save that data (to a local variable)
TDI(移入数据)=从TDO移出的数据//避免破坏寄存器的内容TDI (data shifted in) = data shifted out of TDO // avoid corrupting the contents of the register
else//是写入操作else//is a write operation
TDI(移入数据)=要写入寄存器的数据TDI (shift data in) = data to be written to the register
从TDI移入数据(至选中的寄存器的最高位)Shift in data from TDI (to the MSB of the selected register)
endforend for
驱动TAP使其转移到Update-DR状态Drive TAP to transfer to Update-DR state
if(是读取操作)if (is a read operation)
返回读出的寄存器内容Returns the contents of the read register
基本调试命令的完成需要与目标机CPU进行配合。本发明提出的利用软件有效控制和使用目标机上的EJTAG部件的方案中,需要目标机CPU的调试例外响应过程如下:The completion of basic debugging commands needs to cooperate with the target CPU. Utilize software to effectively control and use the scheme of the EJTAG parts on the target machine that the present invention proposes, need the debugging exception response process of target machine CPU as follows:
当发生调试例外时,CPU判断ECR(EJTAG控制寄存器)中的ProbTrap位(调试例外向量地址控制位)。如果该位是0,就跳转到0xBFC00480。这个地方是由监控程序或操作系统提供的调试例外程序。最后执行DERET,CPU返回正常模式,继续执行;如果该位是1,就跳转到0xFF200200。在调试模式下,0xFF200200位于实际不存在的虚拟内存段dseg(debugsegment)中。这时候,CPU把PC存入TAP的地址寄存器即ADDRESS寄存器,然后置有关的状态位,等待从TAP送过来指令然后执行。具体过程是:When debug exception occurs, CPU judges the ProbTrap bit (debug exception vector address control bit) in ECR (EJTAG control register). If the bit is 0, jump to 0xBFC00480. This place is the debug exception program provided by the monitoring program or operating system. Finally execute DERET, the CPU returns to normal mode and continues to execute; if the bit is 1, jump to 0xFF200200. In debug mode, 0xFF200200 is located in a virtual memory segment dseg (debugsegment) that does not actually exist. At this time, the CPU stores the PC into the address register of the TAP, that is, the ADDRESS register, and then sets the relevant status bits, waiting for the instruction sent from the TAP to be executed. The specific process is:
(1)处理器把程序计数器即PC送到TAP的ADDRESS寄存器;(1) The processor sends the program counter, PC, to the ADDRESS register of the TAP;
(2)处理器写TAP模块中的ECR寄存器的标志位:PrAcc=1;PRnW(暂停种类:0表示读,1表示写)=0等;(2) processor writes the sign bit of the ECR register in the TAP module: PrAcc=1; PRnW (pause kind: 0 expression reads, and 1 expression writes)=0 etc.;
(3)处理器不停的检测PrAcc位,为1则继续等待;若为0则进入(4);(3) the processor does not stop detecting the PrAcc position, and if it is 1, it continues to wait; if it is 0, it enters (4);
(4)把TAP的Data寄存器中的指令放到IR寄存器中,处理器按如下几种情况依次执行:(4) Put the instruction in the Data register of TAP into the IR register, and the processor executes in sequence according to the following situations:
·如果是DERET指令,则转(6);If it is a DERET instruction, then turn to (6);
·如果不是load/store指令,直接执行,然后转(5);·If it is not a load/store instruction, execute it directly, and then go to (5);
·如果是load/store指令,但是操作数地址不在dseg(0xFF000000-0xFF3F0000)之内,直接执行,然后转(5);·If it is a load/store instruction, but the operand address is not within dseg (0xFF000000-0xFF3F0000), execute it directly, and then go to (5);
·如果是load指令,处理流程为:·If it is a load command, the processing flow is:
把操作数地址放入TAP的ADDRESS寄存器;Put the operand address into the ADDRESS register of TAP;
CPU暂停(置ECR的PrAcc=1,PRnW=0等),等待调试器提供操作数;CPU suspends (set PrAcc=1 of ECR, PRnW=0 etc.), waits for debugger to provide operand;
CPU循环检测ECR的PrAcc,一直到为0进入下一步;The CPU loops to detect the PrAcc of the ECR until it is 0 and enters the next step;
从TAP的DATA寄存器读取操作数,执行该指令;Read the operand from the DATA register of TAP and execute the instruction;
转(5);turn(5);
·如果是store指令,处理流程为:·If it is a store command, the processing flow is:
把操作数地址和寄存器内容分别放入TAP的ADDRESS、DATA寄存器;Put the operand address and register content into the ADDRESS and DATA registers of TAP respectively;
CPU暂停(置ECR的PrAcc=1,PRnW=1等),等待调试器取走数据;CPU suspends (set PrAcc=1 of ECR, PRnW=1 etc.), waits for debugger to take away data;
CPU循环检测ECR的PrAcc,一直到为0进入转(5);CPU cycle detects the PrAcc of ECR, enters and turns (5) until being 0;
(5)处理器把PC值加4,转(1);(5) The processor adds 4 to the PC value and turns to (1);
(6)退出调试模式,继续执行原来的代码。(6) Exit the debug mode and continue to execute the original code.
本发明的特征在于:调试命令的处理过程是全部在宿主PC机上运行的,它包含以下步骤:The present invention is characterized in that: the processing procedure of debugging command is all run on the host PC, and it comprises the following steps:
(1)使扩展了EJTAG部件的目标机MIPS CPU中的测试访问端口即Test Access Port简称TAP接口的由IEEE技术委员会联合测试行动小组Joint Test Action Group简称JTAG制定的IEEEE1149.1工业标准中的下述5个JTAG信号通过信号线与宿主机PC的并行I/O端口相连:(1) The test access port in the target machine MIPS CPU that has expanded the EJTAG component is the Test Access Port referred to as the TAP interface, which is formulated by the IEEE Technical Committee Joint Test Action Group Joint Test Action Group referred to as JTAG under the IEEE1149.1 industry standard The above five JTAG signals are connected to the parallel I/O port of the host PC through signal lines:
TCK即测试时钟Test Clock信号,方向从宿主PC机到目标机MIPS CPU;TCK is the Test Clock signal of the test clock, and the direction is from the host PC to the target MIPS CPU;
TMS即测试方式选择Test Mode Select信号,方向从宿主PC机到目标机MIPS CPU;TMS is the test mode selection Test Mode Select signal, the direction is from the host PC to the target MIPS CPU;
TDI即测试数据输入Test Data Input信号,方向从宿主PC机到目标机MIPS CPU;TDI is the test data input Test Data Input signal, the direction is from the host PC to the target MIPS CPU;
TDO即测试数据输出Test Data Output信号,方向从目标机MIPS CPU到宿主PC机;TDO is the test data output Test Data Output signal, the direction is from the target machine MIPS CPU to the host PC;
TRST*即测试复位Test Reset Input*信号,它是可选信号。TRST * is the test reset Test Reset Input * signal, which is an optional signal.
(2)在宿主PC机的存储器上建立以下模块:(2) Establish the following modules on the memory of the host PC:
对于运行在Windows系统下的汇编级调试器,它建有以下模块:For an assembly-level debugger running on Windows, it has the following modules:
a.人机界面模块,采用图形用户接口GUI界面,被调试目标代码的显示格式使用反汇编代码,它通过以下函数来提供操作界面:a. The man-machine interface module adopts the graphical user interface GUI interface, and the display format of the debugged object code uses disassembled code, which provides the operation interface through the following functions:
OnOpenDocument():把反汇编显示格式的代码读入内存,并设定以下变量之值:OnOpenDocument(): Read the code in the disassembly display format into the memory, and set the values of the following variables:
存储每行代码的长度,store the length of each line of code,
存储代码,store code,
当前行特征位flag,1表示为当前行,0表示非当前行,The flag of the current row, 1 means the current row, 0 means not the current row,
断点表,存储断点信息,0表示无断点,非0表示有断点,相应数字即断点类型Breakpoint table, store breakpoint information, 0 means no breakpoint, non-zero means there is a breakpoint, the corresponding number is the type of breakpoint
代码行特征位flag,1表示为代码行,0表示非代码行(注释等)Code line feature bit flag, 1 means code line, 0 means non-code line (comments, etc.)
OnDownload():下载Motorola的S-记录即S-Record格式的代码到目标机指定地址开始的存储区域;OnDownload(): Download Motorola's S-record, that is, the code in S-Record format, to the storage area starting from the specified address of the target machine;
OnDraw():以不同颜色显示代码;OnDraw(): Display codes in different colors;
OnEditBrk():添加断点,向接口发出断点指令;OnEditBrk(): Add a breakpoint and issue a breakpoint instruction to the interface;
OnEditMem();得到并显示指定地址内存的内容;OnEditMem(); Get and display the content of the specified address memory;
OnEditReg();得到并显示所有寄存器的值;OnEditReg(); Get and display the values of all registers;
OnRestart();发送重启指令,重启CPU;OnRestart(); Send a restart command to restart the CPU;
OnSingleStep();发送单步操作命令,并获得单步操作后寄存器的值;OnSingleStep(); Send a single-step operation command and obtain the value of the register after the single-step operation;
OnRemoveBreakPoint();移除断点;OnRemoveBreakPoint(); remove the breakpoint;
Pack():根据RSP协议,为包的内容添置包头包尾,Pack(): According to the RSP protocol, add a header and tail to the contents of the packet,
b.调试请求处理模块,它是上层的人机界面模块和下层的EJTAG/JTAG信号转换及处理模块的应用程序API,它把人机界面的调试请求转换成为符合Remote Serial Protocol协议的数据包,发送给EJTAG/JTAG信号转换及处理模块,再接收其响应,后者设有以下9类调试命令:b. The debugging request processing module, which is the application program API of the upper human-machine interface module and the lower EJTAG/JTAG signal conversion and processing module, which converts the debugging request of the human-machine interface into a data packet conforming to the Remote Serial Protocol protocol, Send it to the EJTAG/JTAG signal conversion and processing module, and then receive its response. The latter has the following 9 types of debugging commands:
Callg():读所有的寄存器,简称g,Callg(): Read all registers, referred to as g,
CallG():写入所有的寄存器,简称G,CallG(): Write all registers, referred to as G,
Callm():读存储器,简称m,Callm(): read memory, referred to as m,
CallM():写存储器,简称M,CallM(): write memory, referred to as M,
CallR():复位,发出CPU中断后执行的起始地址,简称R,CallR(): reset, the starting address executed after the CPU interrupt is issued, referred to as R,
Callc():继续,发出清除单步标志后继续执行的起始地址,简称c,Callc(): Continue, issue the starting address to continue execution after clearing the single-step flag, referred to as c,
Calls():单步操作,发出开始单步执行的起始地址,简称s,Calls(): single-step operation, issue the starting address to start single-step execution, referred to as s,
Callz():插入断点,设定某一地址范围为断点,简称z,Callz(): Insert a breakpoint, set a certain address range as a breakpoint, referred to as z,
CallZ():移除断点,取消某一地址范围的断点,简称Z;CallZ(): remove the breakpoint, cancel the breakpoint of a certain address range, referred to as Z;
相应地,调试请求处理模块设定以下各个调试请求所用到的函数:Correspondingly, the debugging request processing module sets the following functions used by each debugging request:
CallAPI():通过EJTAG TAP接口执行从人机界面传来的调试命令,据此调试命令分别调用由下层的EJTAG/JTAG信号转换及处理模块给出的以上9类调试命令,再返回调试结果,CallAPI(): Execute the debugging commands sent from the man-machine interface through the EJTAG TAP interface. According to the debugging commands, the above 9 types of debugging commands given by the lower EJTAG/JTAG signal conversion and processing module are respectively called, and then the debugging results are returned.
VerifyCommand():验证指令包是否合法,并从中提取有用部分,VerifyCommand(): Verify whether the instruction package is legal, and extract useful parts from it,
GetFirstChar():提取指令的第一个字符,GetFirstChar(): Extract the first character of the instruction,
StrFreeCpy():拷贝一个串;StrFreeCpy(): copy a string;
c.EJTAG信号转换及处理模块,它把RSP格式的调试命令请求转换为JTAG信号,使得与目标机CPU的处理过程同步,并返回响应信息,相应于上述需要处理的调试命令,它对应地设有以下接口函数:c. EJTAG signal conversion and processing module, which converts the debugging command request in RSP format into JTAG signal, so that it is synchronized with the processing process of the target machine CPU, and returns the response information, corresponding to the debugging command that needs to be processed above, it is set correspondingly There are the following interface functions:
CallR():执行R指令,返回结果,CallR(): Execute the R command and return the result,
Callg():执行g指令,返回结果,Callg(): Execute the g command and return the result,
CallG():执行G指令,返回结果,CallG(): Execute the G command and return the result,
Callm():执行m指令,返回结果,Callm(): Execute the m command and return the result,
CallM():执行M指令,返回结果,CallM(): Execute the M command and return the result,
Callc():执行c指令,返回结果,Callc(): Execute the c command and return the result,
Calls():执行s指令,返回结果,Calls(): Execute the s command and return the result,
Callz():执行z指令,返回结果,Callz(): Execute the z command and return the result,
CallZ():执行Z指令,返回结果。CallZ(): Execute the Z command and return the result.
这些接口函数的实现用到了如下函数:The implementation of these interface functions uses the following functions:
Pack():根据RSP协议,为包的内容添置包头包尾,Pack(): According to the RSP protocol, add a header and tail to the contents of the packet,
SetWord():通过EJTAG TAP设置一个32位EJTAG寄存器的值,返回值为0;SetWord(): Set the value of a 32-bit EJTAG register through EJTAG TAP, and the return value is 0;
GetWord():通过EJTAG TAP接口取得一个32位EJTAG寄存器的值,返回寄存器的值,GetWord(): Obtain the value of a 32-bit EJTAG register through the EJTAG TAP interface, and return the value of the register,
IsDigit():判断一个字符是否代表一个十六进制数字,是则返回值1,非则返回值,IsDigit(): Determine whether a character represents a hexadecimal digit, if yes, return
SendSignal():通过并口将信号发送到EJTAG TAP接口并接受反馈;SendSignal(): Send the signal to the EJTAG TAP interface through the parallel port and receive feedback;
对于运行在Linux系统下的高级语言级即原码级调试器,它的前端采用GDB,后端通过下述的EJTAG驱动程序模块与上述EJTAG/JTAG信号转换及处理模块接口:For the high-level language level debugger running under the Linux system, that is, the source code level debugger, its front end adopts GDB, and the back end interfaces with the above-mentioned EJTAG/JTAG signal conversion and processing module through the following EJTAG driver module:
d.EJTAG驱动程序模块,实现了开始调试、结束调试、发送调试请求、读取调试响应四项功能;它与上述EJTAG/JTAG信号转换及处理模之间进行的调试命令的交换自然也是采用GDB的RSP协议格式,这使得汇编级调试器和原码级调试器共享EJTAG/JTAG信号转换及处理模块;该EJTAG驱动程序采用可装载的内核模块的方式:用insmod命令装入该模块,用rmmod命令卸载该模块;在EJTAG模块装入Linux系统以后,建立了一个设备/dev/ejtag,以符合GDB的串口调试的要求;d. The EJTAG driver module realizes the four functions of starting debugging, ending debugging, sending debugging requests, and reading debugging responses; the exchange of debugging commands between it and the above-mentioned EJTAG/JTAG signal conversion and processing modules naturally also uses GDB The RSP protocol format, which makes the assembly-level debugger and the original code-level debugger share the EJTAG/JTAG signal conversion and processing module; the EJTAG driver uses a loadable kernel module: use the insmod command to load the module, use rmmod command to uninstall the module; after the EJTAG module is loaded into the Linux system, a device /dev/ejtag is established to meet the requirements of GDB's serial port debugging;
(3)运行于Windows系统下的汇编级调试器的执行过程:(3) The execution process of the assembly-level debugger running under the Windows system:
a.通过函数OnOpenDocument()将反汇编格式的被调试目标代码装入内存,a. Load the debugged object code in the disassembled format into the memory through the function OnOpenDocument(),
b.通过函数OnDraw()以不同颜色显示代码,b. Display the code in different colors through the function OnDraw(),
c.若需要,通过函数OnDownload()将代码下载到目标机,c. If necessary, download the code to the target machine through the function OnDownload(),
d.根据需要,通过函数OnEditBrk(),OnEditMem(),OnEditReg(),OnRestart(),OnSingleStep(),OnRemoveBreakPoint()实现添加断点,得到并显示指定地址d. According to the needs, add a breakpoint through the functions OnEditBrk(), OnEditMem(), OnEditReg(), OnRestart(), OnSingleStep(), OnRemoveBreakPoint(), and get and display the specified address
内存的内容,得到并显示所有寄存器的值,重启CPU,发送单步操作命令并获得单步操作后寄存器的值,移除断点的操作,The content of the memory, get and display the value of all registers, restart the CPU, send a single-step operation command and get the value of the register after the single-step operation, remove the breakpoint operation,
e.通过GUI重复以上过程,或退出调试器;e. Repeat the above process through the GUI, or exit the debugger;
(4)运行于Linux系统下的高级语言级调试器的执行过程:(4) The execution process of the high-level language debugger running under the Linux system:
a.用insmod命令装入EJTAG驱动程序模块,a. Load the EJTAG driver module with the insmod command,
b.通过GDB命令实现需要完成的调试操作,b. Realize the debugging operation that needs to be completed through the GDB command,
c.重复步骤b,或退出GDB,c. Repeat step b, or exit GDB,
d.用rmmod命令卸载EJTAG驱动程序模块;d. Uninstall the EJTAG driver module with the rmmod command;
(5)对于运行于Windows系统下的汇编级调试器,调试请求处理模块的主函数CallAPI()对步骤(3)中遇到的调试命令的参数及调试操作构成的数据包,利用函数VerifyCommand()和GetFirstChar()对包进行校验及合法性检验,然后再根据GetFirstChar()的返回值分别调用Callxxx()所代表的EJTAG/JTAG信号转换及处理模块给出的CallR(),Callg(),CallG(),Callm(),CallM(),Callc(),Calls(),Callz(),CallZ()等函数,再返回调试结果;(5) For the assembly-level debugger running under the Windows system, the main function CallAPI() of the debugging request processing module uses the function VerifyCommand( ) and GetFirstChar() to verify and check the validity of the package, and then call CallR() and Callg() respectively given by the EJTAG/JTAG signal conversion and processing module represented by Callxxx() according to the return value of GetFirstChar() , CallG(), Callm(), CallM(), Callc(), Calls(), Callz(), CallZ() and other functions, and then return the debugging results;
(6)类似地,对于运行于Linux系统下的高级语言级调试器,连接GDB的EJTAG驱动程序模块使GDB发出的调试命令分别调用EJTAG/JTAG信号转换及处理模块给出的CallR(),Callg(),CallG(),Callm(),CallM(),Callc(),Calls(),Callz(),CallZ()等函数,再返回调试结果;(6) Similarly, for a high-level language-level debugger running under the Linux system, connect the EJTAG driver module of GDB so that the debugging commands issued by GDB call the CallR() and Callg given by the EJTAG/JTAG signal conversion and processing module respectively. (), CallG(), Callm(), CallM(), Callc(), Calls(), Callz(), CallZ() and other functions, and then return the debugging results;
(7)对于运行于Windows系统下的汇编级调试器以及运行于Linux系统下的高级语言级调试器,二者共用的EJTAG/JTAG信号转换及处理模块给出CallR(),Callg(),CallG(),Callm(),CallM(),Callc(),Calls(),Callz(),CallZ()等函数的实现,实现过程用到上述包括Pack(),SetWord(),GetWord(),IsDigit(),SendSignal()的函数;(7) For the assembly-level debugger running under the Windows system and the high-level language-level debugger running under the Linux system, the EJTAG/JTAG signal conversion and processing modules shared by the two give CallR(), Callg(), CallG (), Callm(), CallM(), Callc(), Calls(), Callz(), CallZ() and other functions, the implementation process uses the above-mentioned Pack(), SetWord(), GetWord(), IsDigit (), the function of SendSignal();
(8)函数CallR()的处理过程:(8) Processing procedure of function CallR():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.将EJTAG控制寄存器即ECR寄存器中的复位标志位Rocc置0,以及EJTAGb. Set the EJTAG control register, the reset flag bit Rocc in the ECR register, to 0, and the EJTAG
中断请求位EjtabBrk,虚拟内存段dseg(debug segment)有效位ProbEn,和调试例外向量地址控制位ProbTrap皆置1;The interrupt request bit EjtabBrk, the virtual memory segment dseg (debug segment) valid bit ProbEn, and the debug exception vector address control bit ProbTrap are all set to 1;
c.设置调试例外程序计数器(DEBUG Exception Program Counter)DEPC的值;c. Set the value of the DEBUG Exception Program Counter (DEBUG Exception Program Counter) DEPC;
d.如b,c执行过程出错(Rocc被置为1,处理器未处于预期的暂停状态),则返回,并置出错标志;d. If there is an error in the execution process of b and c (Rocc is set to 1, the processor is not in the expected pause state), then return and set the error flag;
e.返回“”;e. return "";
(9)函数Callg()的处理过程:(9) Processing procedure of function Callg():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.通过Store指令得到32个通用寄存器的数值;b. Obtain the value of 32 general-purpose registers through the Store command;
c.通过MFC0,Store指令得到27个cp0寄存器的数值;c. Obtain the values of 27 cp0 registers through MFC0 and Store instructions;
d.如b,c执行过程出错(Rocc被置为1,处理器未处于预期的暂停状态),则返回,并置出错标志;d. If there is an error in the execution process of b and c (Rocc is set to 1, the processor is not in the expected pause state), then return and set the error flag;
e.返回通用寄存器和cp0寄存器的内容;e. Return the contents of the general-purpose register and the cp0 register;
(10)函数CallG()的处理过程:(10) Processing procedure of function CallG():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.通过Load,MTC0指令设置27个cp0寄存器的数值;b. Set the values of 27 cp0 registers through the Load and MTC0 instructions;
c.通过Load指令设置32个通用寄存器的数值;c. Set the value of 32 general-purpose registers through the Load command;
d.如b,c执行过程出错(Rocc被置为1,处理器未处于预期的暂停状态),则返回,并置出错标志;d. If there is an error in the execution process of b and c (Rocc is set to 1, the processor is not in the expected pause state), then return and set the error flag;
e.返回“OK”;e. Return "OK";
(11)函数Callm()的处理过程:(11) The processing of the function Callm():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.将内存内容Load到通用寄存器;b. Load the memory content to the general-purpose register;
c.通过Store指令得到通用寄存器的数值;c. Obtain the value of the general-purpose register through the Store command;
d.如b,c执行过程出错(Rocc被置为1,处理器未处于预期的暂停状态),则返回,并置出错标志;d. If there is an error in the execution process of b and c (Rocc is set to 1, the processor is not in the expected pause state), then return and set the error flag;
e.返回内存内容;e. Return memory content;
(12)函数CallM()的处理过程:(12) Processing procedure of function CallM():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.通过Load指令得到通用寄存器的数值;b. Obtain the value of the general-purpose register through the Load command;
c.将通用寄存器数值Store到内存中去;c. Store the general-purpose register value into the memory;
d.如b,c执行过程出错(Rocc被置为l,处理器未处于预期的暂停状态),则返回,并置出错标志;d. as b, c execution process is wrong (Rocc is set to 1, processor is not in the expected pause state), then return, and set error flag;
e.返回“OK”;e. Return "OK";
(13)函数Callc()的处理过程:(13) The processing of the function Callc():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.清除Debug寄存器中的SSt位;b. Clear the SSt bit in the Debug register;
c.设置调试例外程序计数器DEPC的值;c. Set the value of the debug exception program counter DEPC;
d.填入DERET指令;d. Fill in the DERET command;
e.调用Callg()得到寄存器内容;e. Call Callg() to get the contents of the register;
f.如b,c,d,e执行过程出错(Rocc被置为1,处理器未处于预期的暂停状态),则返回,并置出错标志;f. If an error occurs during the execution of b, c, d, e (Rocc is set to 1, the processor is not in the expected pause state), return and set an error flag;
g.返回结果;g. return the result;
(14)函数Calls()的处理过程:(14) The processing of the function Calls():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.清除Debug寄存器中的SSt位;b. Clear the SSt bit in the Debug register;
c.设置调试例外程序计数器DEPC的值;c. Set the value of the debug exception program counter DEPC;
d.填入DERET指令;d. Fill in the DERET command;
e.调用Callg()得到寄存器内容;e. Call Callg() to get the contents of the register;
f.如b,c,d,e执行过程出错(Rocc被置为1,处理器未处于预期的暂停状态),则返回,并置出错标志;f. If an error occurs during the execution of b, c, d, e (Rocc is set to 1, the processor is not in the expected pause state), return and set an error flag;
g.返回结果;g. return the result;
(15)函数Callz()的处理过程:(15) Processing procedure of function Callz():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.断点对应的指令断点状态寄存器中的IBC域中的标志位ASIDuse置为0,BE置为1,若为数据断点,还需设置数据断点状态寄存器DBC域中的标志位BAL置为0,BLM置为1;b. The flag bit ASIDuse in the IBC field of the instruction breakpoint state register corresponding to the breakpoint is set to 0, BE is set to 1, if it is a data breakpoint, the flag bit BAL in the DBC field of the data breakpoint state register needs to be set Set to 0, BLM to 1;
c.设置断点对应的指令断点状态寄存器中的IBA域;c. Set the IBA field in the instruction breakpoint status register corresponding to the breakpoint;
d.设置断点对应的指令断点状态寄存器中的IBM域;d. Set the IBM domain in the instruction breakpoint status register corresponding to the breakpoint;
e.如b,c,d执行过程出错(Rocc被置为1,处理器未处于预期的暂停状态),则返回,并置出错标志;e. If there is an error in the execution process of b, c, and d (Rocc is set to 1, the processor is not in the expected pause state), then return and set the error flag;
f.返回“OK”;f. Return "OK";
(16)函数CallZ()的处理过程:(16) Processing procedure of function CallZ():
a.检查指令格式是否正确,若不正确则返回,并置出错标志;a. Check whether the instruction format is correct, if not, return and set an error flag;
b.断点对应的指令断点状态寄存器中的IBC域中的标志位BE置为0;b. The flag bit BE in the IBC field in the instruction breakpoint status register corresponding to the breakpoint is set to 0;
c.如b执行过程出错(Rocc被置为1,处理器未处于预期的暂停状态),则返回,并置出错标志;c. If there is an error in the execution process of b (Rocc is set to 1, the processor is not in the expected pause state), then return and set the error flag;
d.返回“OK”;d. Return "OK";
(17)上述(8)到(16)所述的EJTAG/JTAG信号转换及处理过程把相应的调试请求转换成为一个机器指令的序列,然后通过TAP接口一条一条地送给CPU执行,并取回结果内容,进行打包后返回;根据TAP的控制流程,在调试器命令的处理过程中,TAP寄存器的读写是在Shift-DR/Shift-IR状态进行的,数据在TCK时钟下降沿串行从TDO移出,在上升沿串行从TDI移入;在写TAP寄存器时,忽略从TDO移出的数据,新数据从TDI移入;读TAP寄存器时保存从TDO移出的数据,以供返回,同时将其再从TDI移入;(17) The EJTAG/JTAG signal conversion and processing process described in (8) to (16) above converts the corresponding debugging request into a sequence of machine instructions, and then sends them to the CPU one by one through the TAP interface for execution, and retrieves The result content is packaged and returned; according to the control flow of TAP, during the processing of debugger commands, the reading and writing of TAP registers is carried out in the Shift-DR/Shift-IR state, and the data is serially read from TDO is shifted out, and it is serially shifted in from TDI on the rising edge; when writing the TAP register, the data shifted out from TDO is ignored, and the new data is shifted in from TDI; when the TAP register is read, the data shifted out from TDO is saved for return, and at the same time it is rewritten Move in from TDI;
(18)调试命令的完成需要与目标机CPU进行配合,其基本工作过程为:(18) The completion of the debugging command needs to cooperate with the CPU of the target machine, and its basic working process is:
a.调试器循环检测ECR寄存器的PrAcc位,若为0,继续检测;若为1,表示处理器已经完成请求的操作而暂停,转b;a. The debugger cyclically detects the PrAcc bit of the ECR register. If it is 0, continue to detect; if it is 1, it means that the processor has completed the requested operation and paused, and then turn to b;
b.调试器根据运行的状态,决定下一步动作:b. The debugger determines the next action according to the running state:
·如果是等待CPU中断,表示CPU已进入调试例外处理,等待例外处理的代码;那么把特定指令放入TAP的DATA寄存器;·If it is waiting for CPU interrupt, it means that the CPU has entered the debugging exception handling, waiting for the exception handling code; then put the specific instruction into the DATA register of TAP;
·如果是刚让CPU执行了load/store指令,并且操作数地址位于dseg段,那么需要提供操作数(load指令,往TAP的DATA寄存器写),或者读出数据(store指令,从TAP的DATA寄存器读);If the CPU has just executed the load/store instruction, and the operand address is located in the dseg segment, then you need to provide the operand (load instruction, write to the DATA register of TAP), or read the data (store instruction, from the DATA of TAP register read);
c.调试器把ECR的PrAcc位置为0,表示调试器就绪,CPU可以继续;c. The debugger sets the PrAcc position of the ECR to 0, indicating that the debugger is ready and the CPU can continue;
d.转a;d. turn to a;
(19)上述(8)到(16)返回结果最终会反映到用户界面,之后调试器的运行过程如(3)、(4)所述。(19) The results returned from (8) to (16) above will eventually be reflected on the user interface, and then the running process of the debugger is as described in (3) and (4).
本发明的特点与效果Features and effects of the present invention
(1)国内未见有关基于EJTAG/JTAG调试器设计工作的报道(1) There are no domestic reports on the design of EJTAG/JTAG-based debuggers
片上调试技术(主要有JTAG和BDM两类规范)的实现与CPU或其它处理器芯片的设计是不可分割的,自行研制片上调试器的工作在国内未见报道。进一步,基于EJTAG的片上调试技术只适用于MIPS系列体系结构的微处理器,然而在国内开展此类体系结构的微处理器研究工作只有清华大学的THUMP系列和中科院计算所的龙芯系列,我们研制的基于EJTAG交叉调试器是专为前者配套完成的,在CPU、开发板及系统软件的调试中发挥了很大作用。The implementation of on-chip debugging technology (mainly JTAG and BDM two types of specifications) is inseparable from the design of CPU or other processor chips, and the work of self-developed on-chip debugger has not been reported in China. Furthermore, the on-chip debugging technology based on EJTAG is only applicable to microprocessors with MIPS series architecture. However, only the THUMP series of Tsinghua University and the Godson series of the Institute of Computing Technology of the Chinese Academy of Sciences have carried out research work on microprocessors of this type of architecture in China. We developed The EJTAG-based cross-debugger is specially designed for the former, and plays an important role in the debugging of CPU, development board and system software.
(2)调试命令的处理与EJTAG信号相互转换部分运行于宿主机(2) The processing of debugging commands and the mutual conversion of EJTAG signals run on the host computer
本发明提出的利用软件有效控制和使用目标机上的EJTAG部件的方案体现在:调试器命令的处理过程全部运行于宿主机。The scheme of using software to effectively control and use the EJTAG components on the target machine proposed by the present invention is embodied in that all the processing procedures of the debugger commands run on the host machine.
国外已有的基于EJTAG调试器的产品,需要在CPU和宿主机之间增加一个硬件实现的仿真器。图17是Abatron公司的BDI系列EJTAG调试器示意图。其中调试命令的处理与EJTAG信号相互转换部分是一个硬件实现的仿真设备BDI2000,它位于宿主机调试器和目标机之间,实现的功能是调试协议的转换,也就是把宿主机的调试请求转换成BDM/EJTAG格式,发送给目标机;然后接收目标机的相应信息,转换成宿主机调试器要求的格式返回给宿主机的调试器。该产品它在国内的售价为3万多人民币。相比较,在我们设计的EJTAG调试器中,调试命令的处理与EJTAG信号相互转换部分也是在宿主机完成的,这对于用户来说在性能/价格比、适应性及可移植性方面是完全不同的选择。The existing foreign products based on EJTAG debugger need to add a hardware-realized emulator between the CPU and the host computer. Figure 17 is a schematic diagram of the BDI series EJTAG debugger of Abatron Company. Among them, the processing of debugging commands and the mutual conversion of EJTAG signals is a hardware-implemented simulation device BDI2000, which is located between the host machine debugger and the target machine. Convert it into BDM/EJTAG format and send it to the target machine; then receive the corresponding information of the target machine, convert it into the format required by the host machine debugger and return it to the host machine debugger. The domestic price of this product is more than 30,000 RMB. In comparison, in the EJTAG debugger we designed, the processing of debugging commands and the mutual conversion of EJTAG signals are also completed on the host computer, which is completely different for users in terms of performance/price ratio, adaptability and portability. s Choice.
(3)良好的适应性(3) Good adaptability
根据该方案,宿主机与目标机之间通过并口链接,只需要4~5根信号线。在开发板上只需引线插口,无需实现任何附加逻辑,因此具有良好的适应性,同时降低了成本。According to this scheme, the host machine and the target machine are connected through a parallel port, and only 4 to 5 signal lines are needed. Only lead sockets are needed on the development board, and no additional logic needs to be implemented, so it has good adaptability and reduces costs at the same time.
相比较,在Abatron公司的方案中,宿主机与目标机之间增加了设备BDI2000。宿主机通过串口或以太网连接到BDI2000;而它在连接到目标机时,对于开发板的要求除了实现特定的EJTAG引线逻辑外,还需提供对电源供给的支持。In comparison, in Abatron's solution, the device BDI2000 is added between the host machine and the target machine. The host computer is connected to the BDI2000 through a serial port or Ethernet; when it is connected to the target computer, the requirements for the development board are not only to implement specific EJTAG lead logic, but also to provide support for power supply.
(4)良好的可移植性(4) Good portability
根据该方案,调试协议的转换工作全部在宿主机端完成,支持不同的目标机系统只需要修改少量的代码,在可移植性方面明显优于现有的基于硬件仿真器的方法。According to this scheme, the conversion of the debugging protocol is all completed on the host computer side, and only a small amount of code modification is required to support different target computer systems, which is obviously superior to the existing hardware emulator-based method in terms of portability.
相比较,Abatron公司的BDI2000在向不同的目标系统移植时,需要更新固件,同时驱动程序和配置文件也少不了会改动,可移植性不够理想。在调研该产品时,发现其要满足我们自己的CPU研制,需要Abatron公司本部的密切配合才有可能,其在国内代理无法做到这一步。正因为此,我们才下决心开展了自主研发基于EJTAG调试器的工作。In comparison, when Abatron's BDI2000 is transplanted to different target systems, the firmware needs to be updated, and the driver and configuration files will inevitably be changed, so the portability is not ideal. When researching this product, we found that it needs the close cooperation of Abatron's headquarters to satisfy our own CPU development, which cannot be achieved by its domestic agent. Because of this, we made up our minds to carry out the work of independent research and development based on EJTAG debugger.
附图说明Description of drawings
图1.带有EJTAG功能的CPU。Figure 1. CPU with EJTAG capability.
图2.调试器的体系结构。Figure 2. Architecture of the debugger.
图3.TAP状态转换图。Figure 3. TAP state transition diagram.
图4.汇编级调试用例图。Figure 4. Assembly-level debugging use case diagram.
图5.调试请求处理流程图。Figure 5. Debug request processing flowchart.
图6.EJTAG/JTAG信号转换及处理。Figure 6. EJTAG/JTAG signal conversion and processing.
图7.R指令的处理。Figure 7. Processing of the R instruction.
图8.g指令的处理。Figure 8. Processing of the g instruction.
图9.G指令的处理。Figure 9. Processing of G commands.
图10.m指令的处理。Figure 10. Processing of the m instruction.
图11.M指令的处理。Figure 11. Processing of the M command.
图12.c指令的处理。Figure 12. Processing of the c instruction.
图13.s指令的处理。Figure 13. Processing of the s instruction.
图14.z指令的处理。Figure 14. Processing of the z instruction.
图15.Z指令的处理。Figure 15. Processing of the Z instruction.
图16.源码级调试器的驱动程序体系结构。Figure 16. Driver architecture for a source-level debugger.
图17.Abatron公司的BDI系列EJTAG调试器示意图。Figure 17. Schematic diagram of the BDI series EJTAG debugger from Abatron.
图18本发明所述方案的各主要模块之间的调用关系(左为Windows环境下汇编级调试过程,右为Linux环境下源级调试)。Fig. 18 is the call relationship between the main modules of the scheme of the present invention (the left is the assembly-level debugging process under the Windows environment, and the right is the source-level debugging under the Linux environment).
图19.图18中人机界面模块的程序流程。Figure 19. The program flow of the HMI module in Figure 18.
图20.图19中OnOpenDocument()函数的处理流程。Figure 20. The processing flow of the OnOpenDocument() function in Figure 19.
图21.图19中OnDownload()函数的处理流程。Figure 21. The processing flow of the OnDownload() function in Figure 19.
图22.图19中OnDraw()函数的处理流程。Figure 22. The processing flow of the OnDraw() function in Figure 19.
图23.图19中OnEditBrk()函数的处理流程。Figure 23. The processing flow of the OnEditBrk() function in Figure 19.
图24.图19中OnEditMem()函数的处理流程。Figure 24. The processing flow of the OnEditMem() function in Figure 19.
图25.图19中OnEditReg()函数的处理流程。Figure 25. The processing flow of the OnEditReg() function in Figure 19.
图26.图19中OnRestart()函数的处理流程。Figure 26. The processing flow of the OnRestart() function in Figure 19.
图27.图19中OnSingleStep()函数的处理流程。Figure 27. The processing flow of the OnSingleStep() function in Figure 19.
图28.图19中OnRemoveBreakPoint()函数的处理流程。Figure 28. The processing flow of the OnRemoveBreakPoint() function in Figure 19.
图29调试请求处理模块中使用的模块(函数)之间的调用关系。Fig. 29 The calling relationship between the modules (functions) used in the debugging request processing module.
图30图29中CallAPI()函数的处理流程。Figure 30 is the processing flow of the CallAPI() function in Figure 29.
图31图29中VerifyCommand()函数的处理流程。Figure 31 Figure 29 in the VerifyCommand () function processing flow.
图32EJTAG模块的装载和卸载流程图:a.装载b.卸载。Figure 32 Flow chart of loading and unloading of EJTAG module: a. Loading b. Unloading.
具体实施方式Detailed ways
根据本发明实现的基于EJTAG的交叉调试器的体系结构如图2所示,其中实线方框部分表示自行实现的主要功能模块:汇编级调试器包括三个:人机界面模块、调试请求处理模块和EJTAG/JTAG信号转换及处理模块;高级语言级调试器包括两个:连接GDB的EJTAG驱动程序模块和EJTAG/JTAG信号转换及处理模块;其中,EJTAG/JTAG信号转换及处理模块为二者共用。The architecture of the EJTAG-based cross-debugger implemented according to the present invention is as shown in Figure 2, wherein the solid line box part represents the main functional modules realized by itself: the assembly-level debugger includes three: man-machine interface module, debugging request processing module and EJTAG/JTAG signal conversion and processing module; the high-level language level debugger includes two: the EJTAG driver module connected to GDB and the EJTAG/JTAG signal conversion and processing module; among them, the EJTAG/JTAG signal conversion and processing module is the two shared.
各模块之间的调用关系如图18所示。The call relationship between modules is shown in Figure 18.
各模块的主要功能、工作原理和过程分别介绍如下:The main functions, working principles and processes of each module are introduced as follows:
(1)汇编级调试器人机界面模块。(1) Assembly-level debugger man-machine interface module.
汇编级调试在Windows环境实现,采用GUI界面,操作容易、直观。它提供如下的操作界面(菜单、或者快捷按钮):开始调试/复位CPU、下载代码到目标机、装入源代码;设置断点、删除断点、查看断点;单步执行、继续执行;查看寄存器、修改寄存器;查看内存、修改内存等。其用例图如图4所示。The assembly-level debugging is implemented in the Windows environment, and the GUI interface is adopted, which is easy and intuitive to operate. It provides the following operation interface (menu, or shortcut button): start debugging/reset CPU, download code to target machine, load source code; set breakpoint, delete breakpoint, view breakpoint; single-step execution, continue execution; View registers, modify registers; view memory, modify memory, etc. Its use case diagram is shown in Figure 4.
反汇编代码中有指令的地址,因此可以根据指令计数器PC(Program Counter)值定位当前行,将其显示在界面上。这也是我们使用反汇编代码而不是汇编源代码进行调试的缘故,因为汇编源代码里面没有地址信息。The disassembled code contains the address of the instruction, so the current line can be located according to the value of the instruction counter PC (Program Counter) and displayed on the interface. This is why we use disassembled code instead of assembly source code for debugging, because there is no address information in assembly source code.
(2)调试请求处理模块。(2) Debug request processing module.
调试请求处理模块的功能通过调用下层的EJTAG/JTAG信号转换及处理模块,给人机界面提供断点管理、寄存器和内存查询修改等应用程序接口API函数。它把人机界面的调试请求转换成为符合Remote Serial Protocol协议的数据包,发送给EJTAG/JTAG信号转换及处理模块,然后接收其响应,从而完成相应的功能。其各个功能的处理流程都类似,如图5所示。The function of the debugging request processing module provides application program interface API functions such as breakpoint management, register and memory query and modification for the human-machine interface by calling the lower-layer EJTAG/JTAG signal conversion and processing module. It converts the debugging request of the man-machine interface into a data packet conforming to the Remote Serial Protocol protocol, sends it to the EJTAG/JTAG signal conversion and processing module, and then receives its response to complete the corresponding function. The processing flow of each function is similar, as shown in FIG. 5 .
(3)EJTAG/JTAG信号转换及处理模块。(3) EJTAG/JTAG signal conversion and processing module.
如图6的虚线以下部分所示,该模块的主要功能包括:读写CPU寄存器、读写目标机内存和读写TAP寄存器。As shown in the part below the dotted line in Figure 6, the main functions of this module include: reading and writing CPU registers, reading and writing target machine memory, and reading and writing TAP registers.
人机界面和调试功能处理模块向EJATAG信号转换及处理模块传递的调试命令格式如表2所示。利用EJTAG TAP接口实现调试器的9条命令(R,g,G,m,M,c,s,z,Z)的处理流程分别见图7,图8,图9,图10,图11,图12,图13,图14,图15;分别对应9个函数模块CallR,Callg,CallG,Callm,CallM,Callc,Calls,Callz和CallZ;出错代号E02表示执行过程中出错,出错代号E03表示指令格式错误。Table 2 shows the debugging command format transmitted from the man-machine interface and the debugging function processing module to the EJATAG signal conversion and processing module. Using the EJTAG TAP interface to realize the processing flow of nine commands (R, g, G, m, M, c, s, z, Z) of the debugger are shown in Fig. 7, Fig. 8, Fig. 9, Fig. 10, Fig. 11, respectively. Figure 12, Figure 13, Figure 14, and Figure 15; corresponding to 9 function modules CallR, Callg, CallG, Callm, CallM, Callc, Calls, Callz and CallZ respectively; error code E02 indicates an error during execution, and error code E03 indicates an instruction wrong format.
(4)连接GDB的EJTAG驱动程序模块。高级语言级调试器的前端采用GDB,后端通过驱动程序和EJTAG/JTAG信号转换及处理模块接口。EJTAG驱动程序采用可装载的内核模块(loadable kernel module)的方式。当需要EJTAG调试的时候,用insmod命令装入该模块,不需要以后,可用rmmod命令卸载该模块,节约系统资源。EJTAG模块装入Linux系统以后,建立一个设备/dev/ejtag,它符合GDB的串口调试的要求。(4) Connect the EJTAG driver module of GDB. The front-end of the high-level language level debugger adopts GDB, and the back-end interfaces with the EJTAG/JTAG signal conversion and processing module through the driver program. The EJTAG driver takes the form of a loadable kernel module. When EJTAG debugging is needed, use the insmod command to load the module, and when it is not needed, use the rmmod command to unload the module to save system resources. After the EJTAG module is loaded into the Linux system, create a device /dev/ejtag, which meets the requirements of GDB's serial port debugging.
实现对接的主要工作包括:(1)驱动程序和操作系统的接口;和(2)符合GDB远程调试要求的接口。其驱动程序的体系结构如图16所示。The main work of realizing the docking includes: (1) the interface between the driver program and the operating system; and (2) the interface that meets the requirements of GDB remote debugging. The architecture of its driver is shown in Figure 16.
表2 向EJATAG信号转换及处理模块传递的调试命令格式Table 2 Debug command format passed to EJATAG signal conversion and processing module
各模块的结构及详细设计如下:The structure and detailed design of each module are as follows:
(1)汇编级调试器人机界面(1) Assembly-level debugger man-machine interface
图19中描述了程序执行流程,首先由BOOL CdebuggerDoc∷OnOpenDocument(LPCTSTR lpszPathName)读取汇编源码,再由void CDebuggerView∷OnDraw(CDC*pDC)将源码按一定格式显示出来,然后由其他函数实现各种调试功能。各模块(函数)分别说明如下:Figure 19 describes the program execution process. Firstly, the assembly source code is read by BOOL CdebuggerDoc::OnOpenDocument(LPCTSTR lpszPathName), and then the source code is displayed in a certain format by void CDebuggerView::OnDraw(CDC * pDC), and then various functions are implemented. Debug function. Each module (function) is described as follows:
模块(函数)说明:BOOL CDebuggerDoc∷OnOpenDocument(LPCTSTR lpszPathName)Module (function) description: BOOL CDebuggerDoc::OnOpenDocument(LPCTSTR lpszPathName)
功能描述:将汇编源码读入内存,做一定处理,并设定以下变量之值:Function description: read the assembly source code into memory, do some processing, and set the values of the following variables:
int m_LineCount; //存储每行代码的长度int m_LineCount; // store the length of each line of code
char*m_charbuffer[MAXLINE]; //存储代码char * m_charbuffer[MAXLINE]; //storage code
int m_currentLine[MAXLINE]; //当前行flag,1表示为当前int m_currentLine[MAXLINE]; //current line flag, 1 means current
//行,0表示非当前行// row, 0 means not the current row
int m_breakPoint[MAXLINE]; //断点表,存储断点信息,0表int m_breakPoint[MAXLINE]; //breakpoint table, store breakpoint information, 0 table
//示无断点,非0表示有断点,相应数字即为断点类型 //Shows no breakpoint, non-zero means there is a breakpoint, and the corresponding number is the breakpoint type
int m_codeLine[MAXLINE];。 //代码行flag,1表示为代码行,int m_codeLine[MAXLINE];. //code line flag, 1 means code line,
//0表示非代码行(注释等)//0 means non-code lines (comments, etc.)
参数表:LPCTSTR lpszPathName:指向汇编文件的指针Parameter table: LPCTSTR lpszPathName: pointer to assembly file
返回值:正常结束时返回TRUE,否则返回FALSEReturn value: Returns TRUE if it ends normally, otherwise returns FALSE
处理流程:见图20Processing flow: see Figure 20
错误信息:TRUE---读取文件成功 FALSE----读取文件失败Error message: TRUE --- read file successfully FALSE --- read file failed
模块(函数)名:void CDebuggerView∷OnDownload()Module (function) name: void CDebuggerView::OnDownload()
功能描述:得到指定地址内存的内容,并将其显示Function description: Get the content of the memory at the specified address and display it
处理流程:见图21Processing flow: see Figure 21
模块(函数)说明:void CDebuggerView∷OnDraw(CDC*pDC)Module (function) description: void CDebuggerView::OnDraw(CDC * pDC)
功能描述 :显示代码,并根据是否当前行,是否注释,是否断点等条件显示不同的颜色Function description : Display the code, and display different colors according to whether it is the current line, whether it is a comment, whether it is a breakpoint, etc.
参数表 :CDC*pDC:指向当前view类的指针Parameter table: CDC * pDC: pointer to the current view class
处理流程:见图22Processing flow: see Figure 22
模块(函数)说明:void CDebuggerView∷OnEditBrk()Module (function) description: void CDebuggerView::OnEditBrk()
功能描述 :添加断点,向接口发出断点指令Function description : Add a breakpoint, send a breakpoint command to the interface
处理流程:见图23Processing flow: see Figure 23
模块(函数)名 :void CDebuggerView∷OnEditMem()Module (function) name: void CDebuggerView::OnEditMem()
功能描述 :得到指定地址内存的内容,并将其显示Function description : Get the content of the memory at the specified address and display it
处理流程:见图24Processing flow: see Figure 24
模块(函数)名 :void CDebuggerView∷OnEditReg()Module (function) name: void CDebuggerView::OnEditReg()
功能描述 :得到所有寄存器的值,并将其显示Function description : Get the values of all registers and display them
处理流程:见图25Processing flow: see Figure 25
模块(函数)名 :void CDebuggerView∷OnRestart()Module (function) name: void CDebuggerView::OnRestart()
功能描述 :发送重启指令,重启CPUFunction description : Send a restart command to restart the CPU
处理流程:见图26Processing flow: see Figure 26
模块(函数)名 :void CDebuggerView∷OnSingleStep()Module (function) name: void CDebuggerView::OnSingleStep()
功能描述 :单步操作,发送单步命令,并获得单步操作后寄存器的值。Function description : Single-step operation, send a single-step command, and get the value of the register after the single-step operation.
处理流程:见图27Processing flow: see Figure 27
备注:此函数流程比较复杂,是由目标机的硬件特性所导致。在EJTAG标准Remarks: The process of this function is relatively complicated, which is caused by the hardware characteristics of the target machine. The EJTAG standard
中,如果当前行有断点,在不将断点移除的条件下,所有继续程序的指In , if there is a breakpoint in the current line, all instructions to continue the program will be executed without removing the breakpoint
令(包括single step,continue等)都无法运行,所以进行单步前,要增加Commands (including single step, continue, etc.) cannot be run, so before performing a single step, you need to add
移除断点的步骤。而在正常使用程序的习惯中,断点运行过以后应该仍The steps to remove the breakpoint. In the habit of using the program normally, after the breakpoint is run, it should still be
然存在,而不是消失,所以在单步后又在原处将断点添加,以符合人们still exists, rather than disappearing, so the breakpoint is added in place after the single step to meet people's
的使用习惯。's usage habits.
模块(函数)名:void CDebuggerView∷OnRemoveBreakPoint()Module (function) name: void CDebuggerView::OnRemoveBreakPoint()
功能描述:移除断点Function description: remove breakpoint
处理流程:见图28Processing flow: see Figure 28
(2)调试请求处理模块。(2) Debug request processing module.
图29为调试请求处理模块中使用的模块(函数)之间的调用关系。其中:Callxxx()代表CallR(),Callg(),CallG(),Callm(),CallM(),Callc(),Calls(),Callz(),CallZ()9个函数,因其执行过程大致相仿,调用函数相同(参见EJTAG/JTAG信号转换及处理模块),故写作Callxxx()便于表达。Callxxx()的处理流程在EJTAG/JTAG信号转换及处理模块中说明。其它的模块(函数),包括Callxxx()用到的模块(函数)分别说明如下:FIG. 29 shows the calling relationship between modules (functions) used in the debugging request processing module. Among them: Callxxx() represents CallR(), Callg(), CallG(), Callm(), CallM(), Callc(), Calls(), Callz(), CallZ() 9 functions, because their execution process is roughly Similarly, the call function is the same (see EJTAG/JTAG signal conversion and processing module), so writing Callxxx() is convenient for expression. The processing flow of Callxxx() is described in the EJTAG/JTAG signal conversion and processing module. Other modules (functions), including the modules (functions) used by Callxxx() are described as follows:
模块(C函数)名:char*CallAPI(char*command)Module (C function) name: char * CallAPI(char * command)
功能描述 :通过EJTAG TAP接口执行从人机界面传来的调试命令,Function description : Execute the debugging commands sent from the man-machine interface through the EJTAG TAP interface,
把执行结果返回给人机界面 Return the execution result to the machine interface
参数表 :command:从人机界面接受的调试命令Parameter table : command: the debugging command received from the man-machine interface
返回值 :返回给人机界面的调试结果Return value : the debugging result returned to the man-machine interface
处理流程:见图30Processing flow: see Figure 30
错误信息 :E00----指令包破损 E01----无法识别的指令Error message: E00----command package damaged E01----unrecognized command
模块(C函数)名:int VerifyCommand(char*&command)Module (C function) name: int VerifyCommand(char * &command)
功能描述 :验证指令包是否合法,并从指令包中提取有用部分Function description : Verify whether the instruction package is legal, and extract useful parts from the instruction package
参数表 :command:指令包,VerifyCommand()结束后,包头包尾被去掉(如,指令包Parameter table : command: command package, after VerifyCommand() ends, the header and tail of the package are removed (for example, the command package
$Rbfc00000#?经VerifyCommand()后变为Rbfc00000)$Rbfc00000#? Change to Rbfc00000 after VerifyCommand())
返回值 :0return value : 0
处理流程:见图31Processing flow: see Figure 31
处理流程:Processing flow:
错误信息 :-1表示指令包不合法Error message: -1 indicates that the instruction package is illegal
模块(C函数)名:char GetFirstChar(char*&command)Module (C function) name: char GetFirstChar(char * &command)
功能描述 :取出指令的第一个字符Function description : Take out the first character of the instruction
参数表 :command:指令,GetFirstChar()结束后,第一个字符被去掉(如,指令Parameter table : command: command, after GetFirstChar() ends, the first character is removed (for example, command
Rbfc00000经GetFirstChar()后变为bfc00000)Rbfc00000 becomes bfc00000 after GetFirstChar())
返回值 :command的第一个字符Return value : the first character of command
模块(C函数)名:char*StrFreeCpy(char*s,int first,int length)Module (C function) name: char * StrFreeCpy(char * s, int first, int length)
功能描述 :复制串s从first开始长度为length的一个子串,并返回Function description : Copy a substring of the string s whose length is length starting from first, and return
参数表 :s:字符串,first:整数,length:整数Parameter table: s: string, first: integer, length: integer
返回值 :串s从first开始长度为length的一个子串Return value : A substring of string s whose length is length starting from first
模块(C函数)名:int IsDigit(char c)Module (C function) name: int IsDigit(char c)
功能描述 :判断一个字符是否代表一个十六进制数字Function description : Determine whether a character represents a hexadecimal number
参数表 :c:待判断的字符Parameter table : c: the character to be judged
返回值 :1Return value : 1
错误信息 :0----该字符不代表十六进制数字Error message : 0----This character does not represent a hexadecimal number
模块(C函数)名:char*pack(char*content)Module (C function) name: char * pack(char * content)
功能描述 :打包函数,为包的内容添置包头包尾,包的格式遵从Remote Serial Protocol;Function description : Packing function, adding header and tail to the contents of the package, the format of the package complies with the Remote Serial Protocol;
(在CdebuggerView类的生成Command功能时也用到)(It is also used when generating the Command function of the CdebuggerView class)
参数表 :content:包的内容Parameter table : content: the content of the package
返回值 :打包后的内容Return value : the packaged content
模块(C函数)名:int GetWord(int IR)Module (C function) name: int GetWord(int IR)
功能描述 :通过EJTAG TAP接口取得一个32位EJTAG寄存器的值Function description : Obtain the value of a 32-bit EJTAG register through the EJTAG TAP interface
参数表 :IR:EJTAG寄存器对应的IRParameter table : IR: IR corresponding to the EJTAG register
返回值 :寄存器的值Return value : the value of the register
处理流程 :设置信号格式存放于字符数组中,通过SendSignal()函数从并口发送到EJTAG TAPProcessing flow: Set the signal format and store it in the character array, and send it from the parallel port to the EJTAG TAP through the SendSignal() function
接口Interface
模块(C函数)名:int SetWord(int IR)Module (C function) name: int SetWord(int IR)
功能描述 :通过EJTAGTAP接口取得一个32位EJTAG寄存器的值Function description : Obtain the value of a 32-bit EJTAG register through the EJTAGTAP interface
参数表 :IR:EJTAG寄存器对应的IRParameter table : IR: IR corresponding to the EJTAG register
返回值 :0return value : 0
处理流程 :设置信号格式存放于字符数组中,通过SendSignal()函数从并口发送到EJTAG TAPProcessing flow: Set the signal format and store it in the character array, and send it from the parallel port to the EJTAG TAP through the SendSignal() function
接口Interface
模块(C函数)名:int SendSignal(int lenOfSignal,char*signal)Module (C function) name: int SendSignal(int lenOfSignal, char * signal)
功能描述 :通过并口将信号发送到EJTAG TAP接口并接受反馈Function description : Send the signal to the EJTAG TAP interface through the parallel port and receive feedback
参数表 :IR:EJTAG寄存器对应的IRParameter table : IR: IR corresponding to the EJTAG register
返回值 :0return value : 0
处理流程 :EJTAG TAP接口反馈值Processing flow: EJTAG TAP interface feedback value
注:指令执行结果及出错信息的返回值在返回人机界面前均经pack()函数打包Note: The return value of the command execution result and error information is packed by the pack() function before returning to the HMI
(3)EJTAG/JTAG信号转换及处理模块。(3) EJTAG/JTAG signal conversion and processing module.
需处理的9条命令(R,g,G, m,M,c,s,z,Z)的处理流程分别见图7,图8,图9,图10,图11,图12,图13,图14,图15;分别对应9个函数模块CallR,Callg,CallG,Callm,CallM,Callc,Calls,Callz和CallZ;对应的函数接口定义分别为:See Figure 7, Figure 8, Figure 9, Figure 10, Figure 11, Figure 12, Figure 13 for the processing flow of the nine commands (R, g, G, m, M, c, s, z, Z) to be processed , Figure 14, Figure 15; respectively correspond to 9 function modules CallR, Callg, CallG, Callm, CallM, Callc, Calls, Callz and CallZ; the corresponding function interface definitions are:
模块(C函数)名:char*CallR(char*command)Module (C function) name: char * CallR(char * command)
功能描述 :执行R指令,返回结果Function description : Execute the R command and return the result
参数表 :command:指令(不包括第一个字符)Parameter table : command: command (excluding the first character)
返回值 :执行成功----返回“”Return value : Execution succeeded ---- return ""
处理流程:见图7Processing flow: see Figure 7
错误信息 :E02----执行过程中出错 E03----指令格式错误Error message: E02----Error during execution E03----Instruction format error
模块(C函数)名:char*Callg(char*command)Module (C function) name: char * Callg(char * command)
功能描述 :执行g指令,返回结果Function description : Execute the g command and return the result
参数表 :command:指令(不包括第一个字符)Parameter table : command: command (excluding the first character)
返回值 :寄存器内容(通用寄存器和cp0)Return value : register contents (general purpose registers and cp0)
处理流程:见图8Processing flow: see Figure 8
错误信息 :E02----执行过程中出错 E03----指令格式错误Error message: E02----Error during execution E03----Instruction format error
模块(C函数)名 :char*CallG(char*command)Module (C function) name: char * CallG(char * command)
功能描述 :执行G指令,返回结果Function description : Execute the G command and return the result
参数表 :command:指令(不包括第一个字符)Parameter table : command: command (excluding the first character)
返回值 :OKreturn value : OK
处理流程:见图9Processing flow: see Figure 9
错误信息 :E02----执行过程中出错 E03----指令格式错误Error message: E02----Error during execution E03----Instruction format error
模块(C函数)名 :char*Callm(char*command)Module (C function) name: char * Callm(char * command)
功能描述 :执行m指令,返回结果Function description : Execute the m command and return the result
参数表 :command:指令(不包括第一个字符)Parameter table : command: command (excluding the first character)
返回值 :OKreturn value : OK
处理流程:见图10Processing flow: see Figure 10
错误信息 :E02----执行过程中出错 E03----指令格式错误Error message: E02----Error during execution E03----Instruction format error
模块(C函数)名 :char*CallM(char*command)Module (C function) name: char * CallM(char * command)
功能描述 :执行M指令,返回结果Function description : Execute the M command and return the result
参数表 :command:指令(不包括第一个字符)Parameter table : command: command (excluding the first character)
返回值 :OKreturn value : OK
处理流程:见图11Processing flow: see Figure 11
错误信息 :E02----执行过程中出错 E03----指令格式错误Error message: E02----Error during execution E03----Instruction format error
模块(C函数)名 :char*Callc(char*command)Module (C function) name: char * Callc(char * command)
功能描述 :执行c指令,返回结果Function description : Execute the c command and return the result
参数表 :command:指令(不包括第一个字符)Parameter table : command: command (excluding the first character)
返回值 :参见表2Return value : See Table 2
处理流程:见图12Processing flow: see Figure 12
错误信息 :E02----执行过程中出错 E03----指令格式错误Error message: E02----Error during execution E03----Instruction format error
模块(C函数)名 :char*Calls(char*command)Module (C function) name: char * Calls(char * command)
功能描述 :执行s指令,返回结果Function description : Execute the s command and return the result
参数表 :command:指令(不包括第一个字符)Parameter table : command: command (excluding the first character)
返回值:参见表2Return value: see Table 2
处理流程 :见图13Processing flow : See Figure 13
错误信息 :E02----执行过程中出错 E03----指令格式错误Error message: E02----Error during execution E03----Instruction format error
模块(C函数)名 :char*Callz(char*command)Module (C function) name: char * Callz(char * command)
功能描述 :执行z指令,返回结果Function description : Execute the z command and return the result
参数表 :command:指令(不包括第一个字符)Parameter table : command: command (excluding the first character)
返回值 :OKreturn value : OK
处理流程:见图14Processing flow: see Figure 14
错误信息 :E02----执行过程中出错 E03----指令格式错误Error message: E02----Error during execution E03----Instruction format error
模块(C函数)名 :char*CallZ(char*command)Module (C function) name: char * CallZ(char * command)
功能描述 :执行Z指令,返回结果Function description : Execute the Z command and return the result
参数表 :command:指令(不包括第一个字符)Parameter table : command: command (excluding the first character)
返回值 :OKreturn value : OK
处理流程:见图15Processing flow: see Figure 15
错误信息 :E02----执行过程中出错 E03----指令格式错误Error message: E02----Error during execution E03----Instruction format error
(4)连接GDB的EJTAG驱动程序模块。(4) Connect the EJTAG driver module of GDB.
驱动程序实现了开始调试、结束调试、发送调试请求、读取调试响应四项功能,其处理过程如下:The driver implements four functions: start debugging, end debugging, send debugging request, and read debugging response. The processing process is as follows:
(a)开始调试:(a) Start debugging:
向Linux Kernel申请I/O地址范围Apply for I/O address range from Linux Kernel
复位目标机Reset the target machine
读取CPU实现的硬件断点、软件断点数量Read the number of hardware breakpoints and software breakpoints implemented by the CPU
(b)结束调试:(b) End debugging:
释放I/O地址范围free I/O address range
(c)发出调试请求:(c) Issue a debug request:
校验、分析调试请求Verify and analyze debugging requests
处理调试请求Handle debug requests
处理的结果放入结果缓冲区The processed result is put into the result buffer
(d)读取调试响应:(d) Read the debug response:
循环测试是否已有结果Does the loop test have results
if(已有结果)if(result already exists)
从结果缓冲区读取处理结果Read processing result from result buffer
驱动程序和操作系统的接口就是EJTAG模块的装载和卸载,如图32所示。The interface between the driver program and the operating system is the loading and unloading of the EJTAG module, as shown in Figure 32.
Claims (1)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CNB2004100090019A CN1312588C (en) | 2004-04-02 | 2004-04-02 | Realizing method of cross regulator based on EJTAG components of targeting machine |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CNB2004100090019A CN1312588C (en) | 2004-04-02 | 2004-04-02 | Realizing method of cross regulator based on EJTAG components of targeting machine |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN1564136A CN1564136A (en) | 2005-01-12 |
| CN1312588C true CN1312588C (en) | 2007-04-25 |
Family
ID=34477762
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CNB2004100090019A Expired - Fee Related CN1312588C (en) | 2004-04-02 | 2004-04-02 | Realizing method of cross regulator based on EJTAG components of targeting machine |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN1312588C (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101510179B (en) * | 2009-03-17 | 2013-01-16 | 中兴通讯股份有限公司 | Signal transmission apparatus and method |
Families Citing this family (22)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| TWI300524B (en) * | 2005-04-13 | 2008-09-01 | Via Tech Inc | System-on-a-chip and test/debug method thereof |
| US7533207B2 (en) * | 2006-12-06 | 2009-05-12 | Microsoft Corporation | Optimized interrupt delivery in a virtualized environment |
| CN100452056C (en) * | 2007-06-25 | 2009-01-14 | 威盛电子股份有限公司 | System and method for analyzing memory content |
| CN101840368B (en) * | 2010-03-26 | 2013-01-16 | 中国科学院计算技术研究所 | JTAG (Joint Test Action Group) real-time on-chip debug method and system of multicore processor |
| CN101989222B (en) * | 2010-11-22 | 2012-10-03 | 连云港杰瑞深软科技有限公司 | Loongson simulator terminal |
| CN102567196A (en) * | 2010-12-27 | 2012-07-11 | 北京国睿中数科技股份有限公司 | Simulation debugging method and device for processor |
| CN102231128A (en) * | 2011-07-06 | 2011-11-02 | 青岛海信信芯科技有限公司 | Online debugging method and debugging host |
| CN102981952B (en) * | 2012-11-06 | 2015-05-20 | 无锡江南计算技术研究所 | Procedure performance analysis method based on target machine |
| CN103488607A (en) * | 2013-09-07 | 2014-01-01 | 安徽华东光电技术研究所 | Communication system and communication method for SOC (system on chip) processor and FPGA (field-programmable gate array) chip on embedded linux platform |
| CN103473173B (en) * | 2013-09-10 | 2016-03-09 | 成都品果科技有限公司 | A kind of method and device iOS system being carried out to assembly level dynamic debugging |
| CN104899144B (en) * | 2015-06-18 | 2018-06-15 | 深圳市新格林耐特通信技术有限公司 | A kind of adjustment method interrupted based on serial ports |
| CN105808423B (en) * | 2016-02-04 | 2018-11-13 | 天津橙子科技有限公司 | The method for building the enforcement engine based on WEB engineering test use-case programming languages |
| CN107885652A (en) * | 2016-09-30 | 2018-04-06 | 电信科学技术研究院 | A kind of method and debugger for carrying out software test |
| US10067854B2 (en) * | 2016-10-25 | 2018-09-04 | Xilinx, Inc. | System and method for debugging software executed as a hardware simulation |
| CN109240902B (en) * | 2017-05-27 | 2021-03-19 | 腾讯科技(深圳)有限公司 | Method and device for acquiring firmware code of electronic equipment |
| CN108829591B (en) * | 2018-05-31 | 2021-05-04 | 北京理工大学 | Web-based collaborative debugging system and method |
| CN111555810B (en) * | 2020-04-22 | 2023-08-08 | 青岛海信宽带多媒体技术有限公司 | Optical module and data transmission method |
| CN111881636B (en) * | 2020-07-07 | 2021-05-04 | 广芯微电子(广州)股份有限公司 | RISC-V chip based simulation debugging method and device |
| CN113342649B (en) * | 2021-05-31 | 2023-11-14 | 上海创景信息科技有限公司 | Methods, media and equipment for unit testing based on real target machines |
| CN114090440B (en) * | 2021-11-21 | 2024-11-12 | 广州链安科技有限公司 | An integrated source code-free debugging method based on Android operating system |
| CN114487758B (en) * | 2022-04-18 | 2022-08-16 | 江苏邑文微电子科技有限公司 | Test method and test system for semiconductor equipment |
| CN115793582A (en) * | 2022-11-25 | 2023-03-14 | 浙江中控技术股份有限公司 | Industrial control algorithm debugging method, system and device and electronic equipment |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6145100A (en) * | 1998-03-04 | 2000-11-07 | Advanced Micro Devices, Inc. | Debug interface including timing synchronization logic |
| WO2001029666A1 (en) * | 1999-10-21 | 2001-04-26 | Sony Electronics, Inc. | Method and system for debugging a microprocessor core |
| JP2004038464A (en) * | 2002-07-02 | 2004-02-05 | Renesas Technology Corp | Microcomputer with built-in debugging function |
| CN1474272A (en) * | 2003-06-19 | 2004-02-11 | Ut斯达康(中国)有限公司 | Method and device for testing single board through JTAG |
-
2004
- 2004-04-02 CN CNB2004100090019A patent/CN1312588C/en not_active Expired - Fee Related
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6145100A (en) * | 1998-03-04 | 2000-11-07 | Advanced Micro Devices, Inc. | Debug interface including timing synchronization logic |
| WO2001029666A1 (en) * | 1999-10-21 | 2001-04-26 | Sony Electronics, Inc. | Method and system for debugging a microprocessor core |
| JP2004038464A (en) * | 2002-07-02 | 2004-02-05 | Renesas Technology Corp | Microcomputer with built-in debugging function |
| CN1474272A (en) * | 2003-06-19 | 2004-02-11 | Ut斯达康(中国)有限公司 | Method and device for testing single board through JTAG |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101510179B (en) * | 2009-03-17 | 2013-01-16 | 中兴通讯股份有限公司 | Signal transmission apparatus and method |
Also Published As
| Publication number | Publication date |
|---|---|
| CN1564136A (en) | 2005-01-12 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN1312588C (en) | Realizing method of cross regulator based on EJTAG components of targeting machine | |
| JP4126105B2 (en) | Digital processor test method | |
| Rashinkar et al. | System-on-a-chip Verification: Methodology and Techniques | |
| US20070198959A1 (en) | Hardware-based HDL code coverage and design analysis | |
| CN104268310B (en) | The method that UVM verification environment is called using special graphical interface | |
| US20050125754A1 (en) | Hardware debugging in a hardware description language | |
| CN101995546A (en) | Automatic test system and method of programmable logic device on basis of boundary scan | |
| CN102841837B (en) | Software and hardware co-verification method based on simulator and system thereof | |
| JPH05334114A (en) | Computer circuit, microprocessor, external command method, and method for operating microprocessor | |
| Dobis et al. | Verification of chisel hardware designs with chiselverify | |
| Barbosa et al. | Assembly-level pre-injection analysis for improving fault injection efficiency | |
| CN116126700A (en) | Chip verification method and system based on SystemC | |
| Wang et al. | Exploration of Using Direct Programming Interface to Improve the Reusability of Verification IP | |
| CN100492315C (en) | Embedded signal processor simulator | |
| US7584456B1 (en) | Method and apparatus for debugging embedded systems having read only memory | |
| CN117290212A (en) | Debugging system based on RISC-V architecture | |
| CN114564394A (en) | Test case determination method, system and related components | |
| US20250258763A1 (en) | Co-simulation for System-on-Chip | |
| CN111008133B (en) | Coarse-grained data flow architecture execution array debugging method and device | |
| CN114691520B (en) | Instruction programmable buffer design system based on processor debugging architecture | |
| Rogin et al. | An integrated SystemC debugging environment | |
| TWI402750B (en) | Computer-readable medium having software program stored thereon and method for creating software program | |
| Banerjee et al. | Efficient online RTL debugging methodology for logic emulation systems | |
| Lee et al. | A low-cost SOC debug platform based on on-chip test architectures | |
| CN115292760A (en) | Chip verification system, method and computer readable storage medium |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| C06 | Publication | ||
| PB01 | Publication | ||
| C10 | Entry into substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| C14 | Grant of patent or utility model | ||
| GR01 | Patent grant | ||
| C19 | Lapse of patent right due to non-payment of the annual fee | ||
| CF01 | Termination of patent right due to non-payment of annual fee |