CN106021041A - Finite state machine based multi-cycle non-flow line CPU debugging method - Google Patents
Finite state machine based multi-cycle non-flow line CPU debugging method Download PDFInfo
- Publication number
- CN106021041A CN106021041A CN201610291250.4A CN201610291250A CN106021041A CN 106021041 A CN106021041 A CN 106021041A CN 201610291250 A CN201610291250 A CN 201610291250A CN 106021041 A CN106021041 A CN 106021041A
- Authority
- CN
- China
- Prior art keywords
- cpu
- depositor
- state machine
- debugging
- finite state
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 20
- 238000010586 diagram Methods 0.000 description 2
- 230000006870 function Effects 0.000 description 2
- 238000012938 design process Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/22—Detection or location of defective computer hardware by testing during standby operation or during idle time, e.g. start-up testing
- G06F11/2205—Detection or location of defective computer hardware by testing during standby operation or during idle time, e.g. start-up testing using arrangements specific to the hardware being tested
- G06F11/2236—Detection or location of defective computer hardware by testing during standby operation or during idle time, e.g. start-up testing using arrangements specific to the hardware being tested to test CPU or processors
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/22—Detection or location of defective computer hardware by testing during standby operation or during idle time, e.g. start-up testing
- G06F11/2273—Test methods
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
- Advance Control (AREA)
Abstract
本发明公开了一种基于有限状态机的多周期非流水线CPU调试方法,该方法可以在不改变CPU寄存器组、程序计数器、状态寄存器及其他CPU运行现场的情况下将CPU工作“暂停”,在该状态下可以将CPU的状态读出,以达到调试的目的;此外,该方案引入的额外电路较少,且该功能在正常工作模式下不会影响到CPU的运行状态及效率。
The invention discloses a multi-cycle non-pipeline CPU debugging method based on a finite state machine. The method can "pause" the CPU work without changing the CPU register group, program counter, status register and other CPU operation sites. In this state, the state of the CPU can be read out to achieve the purpose of debugging; in addition, this solution introduces less additional circuits, and this function will not affect the operating state and efficiency of the CPU in the normal working mode.
Description
技术领域technical field
本发明涉及计算机技术领域,尤其涉及一种基于有限状态机的多周期非流水线CPU调试方法。The invention relates to the technical field of computers, in particular to a multi-cycle non-pipeline CPU debugging method based on a finite state machine.
背景技术Background technique
在处理器设计过程中,往往会耗费大量的人力物力来对CPU的正确性进行验证,一旦出现问题,则需要有一可靠的手段来定位问题。In the processor design process, a lot of manpower and material resources are often spent to verify the correctness of the CPU. Once a problem occurs, a reliable means is needed to locate the problem.
然而,现有技术中,对正在运行的CPU进行调试时会需要引入较为复杂的电路,同时,还对于CPU的运行状态及效率产生一定的影响。However, in the prior art, it is necessary to introduce relatively complex circuits when debugging a running CPU, and at the same time, it also has a certain impact on the running state and efficiency of the CPU.
发明内容Contents of the invention
本发明的目的是提供一种基于有限状态机的多周期非流水线CPU调试方法,其引入额外电路较少,且在CPU正常工作模式下不会影响到CPU的运行状态及效率。The purpose of the present invention is to provide a multi-cycle non-pipeline CPU debugging method based on a finite state machine, which introduces fewer additional circuits, and does not affect the operating state and efficiency of the CPU in the normal operating mode of the CPU.
本发明的目的是通过以下技术方案实现的:The purpose of the present invention is achieved through the following technical solutions:
一种基于有限状态机的多周期非流水线CPU调试方法,包括:A multi-cycle non-pipeline CPU debugging method based on a finite state machine, comprising:
CPU处理每条指令的步骤依次为取指、译码、执行、访存与回写,步骤之间的跳转通过有限状态机来实现;The steps for the CPU to process each instruction are instruction fetching, decoding, execution, memory access, and write-back in sequence, and the jump between steps is realized by a finite state machine;
通过引入寄存器A与寄存器B来实现CPU调试,所述寄存器A用于设置运行模式,所述寄存器B用于指令计数;实现CPU调试的步骤如下:Realize CPU debugging by introducing register A and register B, described register A is used for setting operation mode, and described register B is used for instruction counting; The steps of realizing CPU debugging are as follows:
在初始状态或者当前指令执行完回写步骤后所述有限状态机根据寄存器A的值来判断当前的运行模式;In the initial state or after the current instruction executes the write-back step, the finite state machine judges the current operating mode according to the value of the register A;
若为多步调试模式,则进入调试状态,并判断寄存器B的值;当寄存器B不为零时,将寄存器B的值减1,并由所述有限状态机跳过该调试状态,由CPU继续处理下一条指令,如此循环直至寄存器B的值减为零后,由所述有限状态机将CPU阻塞在调试状态;If it is multi-step debugging mode, then enter the debugging state, and judge the value of register B; when register B is not zero, the value of register B is subtracted by 1, and this debugging state is skipped by described finite state machine, by CPU Continue to process the next instruction, so that after the value of register B is reduced to zero, the CPU is blocked in the debugging state by the finite state machine;
若为单步调试模式,由所述有限状态机将CPU阻塞在调试状态,直至寄存器B有新的指令计数写入,并由所述有限状态机控制离开调试状态,同时,将寄存器B的值清零。If it is a single-step debugging mode, the CPU is blocked in the debugging state by the finite state machine until the register B has a new instruction count to write, and the finite state machine controls to leave the debugging state, and at the same time, the value of the register B cleared.
进一步的,若根据寄存器A的值判定当前为正常工作模式,则由CPU继续处理下一条指令。Further, if it is determined according to the value of the register A that the current mode is in the normal working mode, the CPU continues to process the next instruction.
由上述本发明提供的技术方案可以看出,可以在不改变CPU寄存器组、程序计数器、状态寄存器及其他CPU运行现场的情况下将CPU工作“暂停”,在该状态下可以将CPU的状态读出,以达到调试的目的;此外,该方案引入的额外电路较少,且该功能在正常工作模式下不会影响到CPU的运行状态及效率。As can be seen from the technical solution provided by the present invention above, the CPU work can be "suspended" without changing the CPU register group, program counter, status register and other CPU operation sites, and the status of the CPU can be read in this state. In order to achieve the purpose of debugging; in addition, this solution introduces less additional circuits, and this function will not affect the running status and efficiency of the CPU in normal working mode.
附图说明Description of drawings
为了更清楚地说明本发明实施例的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域的普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他附图。In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the accompanying drawings that need to be used in the description of the embodiments. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For Those of ordinary skill in the art can also obtain other drawings based on these drawings on the premise of not paying creative work.
图1为本发明实施例提供的CPU处理每条指令的示意图;FIG. 1 is a schematic diagram of CPU processing each instruction provided by an embodiment of the present invention;
图2为本发明实施例提供的基于有限状态机的多周期非流水线CPU调试方法的示意图;2 is a schematic diagram of a multi-cycle non-pipeline CPU debugging method based on a finite state machine provided by an embodiment of the present invention;
图3为本发明实施例提供的实现CPU调试的流程图。FIG. 3 is a flow chart for implementing CPU debugging provided by an embodiment of the present invention.
具体实施方式detailed description
下面结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明的保护范围。The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.
如图1所示,CPU处理每条指令的步骤依次为取指、译码、执行、访存与回写;步骤之间的跳转通过有限状态机来实现;As shown in Figure 1, the steps for the CPU to process each instruction are fetching, decoding, executing, accessing memory, and writing back in sequence; the jump between steps is realized by a finite state machine;
本发明实施例中,通过引入寄存器A与寄存器B来实现CPU调试,同时,在有限状态机中插入一个判定状态,如图2所示。In the embodiment of the present invention, CPU debugging is realized by introducing register A and register B, and at the same time, a decision state is inserted into the finite state machine, as shown in FIG. 2 .
本发明实施例中,所述寄存器A用于设置运行模式,所述寄存器B用于指令计数。In the embodiment of the present invention, the register A is used to set the running mode, and the register B is used to count instructions.
实现CPU调试的步骤图3所示,其主要包括:The steps to realize CPU debugging are shown in Figure 3, which mainly include:
在初始状态或者当前指令执行完回写步骤后所述有限状态机根据寄存器A的值来判断当前的运行模式;In the initial state or after the current instruction executes the write-back step, the finite state machine judges the current operating mode according to the value of the register A;
若为多步调试模式,则进入调试状态,并判断寄存器B的值;当寄存器B不为零时,将寄存器B的值减1,并由所述有限状态机跳过该调试状态,由CPU继续处理下一条指令,如此循环直至寄存器B的值减为零后,由所述有限状态机将CPU阻塞在调试状态;If it is multi-step debugging mode, then enter the debugging state, and judge the value of register B; when register B is not zero, the value of register B is subtracted by 1, and this debugging state is skipped by described finite state machine, by CPU Continue to process the next instruction, so that after the value of register B is reduced to zero, the CPU is blocked in the debugging state by the finite state machine;
若为单步调试模式,由所述有限状态机将CPU阻塞在调试状态,直至寄存器B有新的指令计数写入,并由所述有限状态机控制离开调试状态,同时,将寄存器B的值清零。If it is a single-step debugging mode, the CPU is blocked in the debugging state by the finite state machine until the register B has a new instruction count to write, and the finite state machine controls to leave the debugging state, and at the same time, the value of the register B cleared.
当有限状态机将CPU阻塞在调试状态后,则可将CPU的状态读出,以达到调试的目的。After the finite state machine blocks the CPU in the debugging state, the state of the CPU can be read out to achieve the purpose of debugging.
此外,若根据寄存器A的值判定当前为正常工作模式,则由CPU继续处理下一条指令。In addition, if it is determined according to the value of the register A that the current operation mode is normal, the CPU will continue to process the next instruction.
由上述过程可见,运行模式主要包括:正常工作模式、多步调试模式、单步调试模式,各个运行模式对应的数值可以预先设定并存储在寄存器A中。It can be seen from the above process that the operating modes mainly include: normal working mode, multi-step debugging mode, and single-step debugging mode, and the values corresponding to each operating mode can be preset and stored in register A.
示例性的,寄存器A可取0、1、2三个值,0为正常工作模式(此模式为默认状态),1为单步调试模式,2为多步调试模式。Exemplarily, the register A can take three values: 0, 1, and 2, 0 is the normal working mode (this mode is the default state), 1 is the single-step debugging mode, and 2 is the multi-step debugging mode.
单步调试模式使用过程如下:The process of using the single-step debugging mode is as follows:
1)将寄存器A置为1,进入单步调试模式,CPU执行完当前指令后将会阻塞。1) Set register A to 1 to enter the single-step debugging mode, and the CPU will block after executing the current instruction.
2)向寄存器B写数据(不关心写入值),执行下一条指令。2) Write data to register B (don't care about the written value), and execute the next instruction.
3)通过调试接口读取CPU状态(PC、状态寄存器、寄存器文件及数据RAM等)。3) Read the CPU state (PC, state register, register file and data RAM, etc.) through the debug interface.
4)重复执行2、3两步骤,直至调试结束。4) Repeat steps 2 and 3 until the debugging is completed.
5)将寄存器A置为0,返回正常工作模式,CPU继续工作。5) Set register A to 0, return to the normal working mode, and the CPU continues to work.
多步调试模式使用过程如下:The process of using the multi-step debugging mode is as follows:
1)将寄存器A置为2,进入多步调试模式,此时寄存器B的值应为0,CPU执行完当前指令后将会阻塞。1) Set register A to 2 to enter the multi-step debugging mode. At this time, the value of register B should be 0, and the CPU will block after executing the current instruction.
2)向寄存器B写入数据。2) Write data to register B.
3)CPU继续执行指令,每执行一条指令,将寄存器B数据减1,直至寄存器B的值变为0后将会阻塞。3) The CPU continues to execute instructions, and every time an instruction is executed, the data in register B is decremented by 1 until the value of register B becomes 0, and then it will block.
4)通过调试接口读取CPU状态(PC、状态寄存器、寄存器文件及数据RAM等)4) Read the CPU status (PC, status register, register file and data RAM, etc.) through the debug interface
5)如需继续多步调试,则执行2、3、4步骤,否则执行6步骤。5) If you need to continue multi-step debugging, execute steps 2, 3, and 4; otherwise, execute step 6.
6)将寄存器A的值置为0,返回正常工作模式,CPU继续工作。6) Set the value of register A to 0, return to the normal working mode, and the CPU continues to work.
本发明实施例的上述方案中,可以在不改变CPU寄存器组、程序计数器、状态寄存器及其他CPU运行现场的情况下将CPU工作“暂停”,在该状态下可以将CPU的状态读出,以达到调试的目的;此外,该方案引入的额外电路较少,且该功能在正常工作模式下不会影响到CPU的运行状态及效率。In the above solution of the embodiment of the present invention, the CPU work can be "suspended" without changing the CPU register group, program counter, status register and other CPU operation sites. In this state, the state of the CPU can be read out to The purpose of debugging is achieved; in addition, this solution introduces less additional circuits, and this function will not affect the running state and efficiency of the CPU in the normal working mode.
以上所述,仅为本发明较佳的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明披露的技术范围内,可轻易想到的变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应该以权利要求书的保护范围为准。The above is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person familiar with the technical field can easily conceive of changes or changes within the technical scope disclosed in the present invention. Replacement should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be determined by the protection scope of the claims.
Claims (2)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610291250.4A CN106021041B (en) | 2016-04-29 | 2016-04-29 | Multi-cycle non-pipeline CPU debugging method based on finite state machine |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610291250.4A CN106021041B (en) | 2016-04-29 | 2016-04-29 | Multi-cycle non-pipeline CPU debugging method based on finite state machine |
Publications (2)
Publication Number | Publication Date |
---|---|
CN106021041A true CN106021041A (en) | 2016-10-12 |
CN106021041B CN106021041B (en) | 2020-01-03 |
Family
ID=57081086
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610291250.4A Active CN106021041B (en) | 2016-04-29 | 2016-04-29 | Multi-cycle non-pipeline CPU debugging method based on finite state machine |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106021041B (en) |
Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US4674089A (en) * | 1985-04-16 | 1987-06-16 | Intel Corporation | In-circuit emulator |
CN1904851A (en) * | 2005-07-29 | 2007-01-31 | 中国科学院计算技术研究所 | Method and apparatus of single step execution debugging function |
CN101154178A (en) * | 2006-09-29 | 2008-04-02 | 松下电器产业株式会社 | Microcomputer debugging system |
CN101178685A (en) * | 2007-09-27 | 2008-05-14 | 上海大学 | An Enhanced Microprocessor On-Chip Dynamic Tracing Method with Special Function Register Breakpoints |
CN101339581A (en) * | 2008-08-29 | 2009-01-07 | 北京中星微电子有限公司 | Embedded system on-line debugging emulation method based on communication interruption |
CN101814054A (en) * | 2010-03-23 | 2010-08-25 | 苏州国芯科技有限公司 | Instruction tracing controller for debugging microcontroller |
CN103299282A (en) * | 2010-12-02 | 2013-09-11 | 超威半导体公司 | Debug state machine and processor including the same |
CN103440216A (en) * | 2013-08-22 | 2013-12-11 | 深圳市汇顶科技股份有限公司 | Chip and method for debugging MCU through I2C slave unit |
-
2016
- 2016-04-29 CN CN201610291250.4A patent/CN106021041B/en active Active
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US4674089A (en) * | 1985-04-16 | 1987-06-16 | Intel Corporation | In-circuit emulator |
CN1904851A (en) * | 2005-07-29 | 2007-01-31 | 中国科学院计算技术研究所 | Method and apparatus of single step execution debugging function |
CN101154178A (en) * | 2006-09-29 | 2008-04-02 | 松下电器产业株式会社 | Microcomputer debugging system |
CN101178685A (en) * | 2007-09-27 | 2008-05-14 | 上海大学 | An Enhanced Microprocessor On-Chip Dynamic Tracing Method with Special Function Register Breakpoints |
CN101339581A (en) * | 2008-08-29 | 2009-01-07 | 北京中星微电子有限公司 | Embedded system on-line debugging emulation method based on communication interruption |
CN101814054A (en) * | 2010-03-23 | 2010-08-25 | 苏州国芯科技有限公司 | Instruction tracing controller for debugging microcontroller |
CN103299282A (en) * | 2010-12-02 | 2013-09-11 | 超威半导体公司 | Debug state machine and processor including the same |
CN103440216A (en) * | 2013-08-22 | 2013-12-11 | 深圳市汇顶科技股份有限公司 | Chip and method for debugging MCU through I2C slave unit |
Non-Patent Citations (1)
Title |
---|
邹志斌: "基于MIPS指令集的RISC微处理器控制模块的设计与实现", 《中国优秀硕士学位论文全文数》 * |
Also Published As
Publication number | Publication date |
---|---|
CN106021041B (en) | 2020-01-03 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
KR101519845B1 (en) | Method For Anti-Debugging | |
US9996127B2 (en) | Method and apparatus for proactive throttling for improved power transitions in a processor core | |
US9459989B2 (en) | Method and apparatus for reverse debugging source code using causal analysis | |
CN104169889A (en) | Run-time instrumentation sampling in transactional-execution mode | |
CN107851021B (en) | Vector processing using dynamic vector length loops | |
CN106648546A (en) | Collaborative optimization compilation method used for GPU register allocation and parallelism management | |
CN107436752A (en) | Abnormal in-situ FTIR spectroelectrochemitry method, apparatus and computer-readable recording medium | |
CN107092466A (en) | Method and device for controlling MXCSR | |
CN100405324C (en) | Method for Realizing Kernel Mode Program Verification in Microprocessor User Mode Random Verification | |
US10223117B2 (en) | Execution flow protection in microcontrollers | |
CN107526622B (en) | Rapid exception handling method and device for Linux | |
US8127181B1 (en) | Hardware warning protocol for processing units | |
KR102603377B1 (en) | data processing | |
CN105824750B (en) | A kind of soft breakpoint analogy method in the debugging of the NorFlash program spaces | |
US9081895B2 (en) | Identifying and tagging breakpoint instructions for facilitation of software debug | |
CN106021041A (en) | Finite state machine based multi-cycle non-flow line CPU debugging method | |
CN108021563A (en) | The detection method and device that a kind of inter-instruction data relies on | |
CN106095631B (en) | Multi-cycle non-pipeline CPU dynamic debugging method based on finite state machine | |
CN110597554A (en) | A method for automatic generation and optimization of instruction function of instruction set simulator | |
US8726244B2 (en) | Software breakpoint handling by eliminating instruction replacement and execution under certain conditions | |
CN109947414A (en) | A kind of dynamic Hook Function implementation method based on Vxworks system | |
CN107291617B (en) | A vulnerability analysis method based on implicit taint propagation | |
CN100385391C (en) | Hardware Implementation Method of Embedded Real-time Accurate Exception Mechanism | |
CN105242905B (en) | The treating method and apparatus that data false appearance is closed | |
JPS63214804A (en) | Processor for plc and plc |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |