[go: up one dir, main page]

CN109933451B - An exception and interrupt processing system and method based on RISC-V architecture - Google Patents

An exception and interrupt processing system and method based on RISC-V architecture Download PDF

Info

Publication number
CN109933451B
CN109933451B CN201910205345.3A CN201910205345A CN109933451B CN 109933451 B CN109933451 B CN 109933451B CN 201910205345 A CN201910205345 A CN 201910205345A CN 109933451 B CN109933451 B CN 109933451B
Authority
CN
China
Prior art keywords
exception
interrupt
processor
register
mode
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.)
Active
Application number
CN201910205345.3A
Other languages
Chinese (zh)
Other versions
CN109933451A (en
Inventor
吴俊�
顾冲
李青
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Amlogic Shanghai Co Ltd
Original Assignee
Amlogic Shanghai Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Amlogic Shanghai Co Ltd filed Critical Amlogic Shanghai Co Ltd
Priority to CN201910205345.3A priority Critical patent/CN109933451B/en
Publication of CN109933451A publication Critical patent/CN109933451A/en
Application granted granted Critical
Publication of CN109933451B publication Critical patent/CN109933451B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

本发明涉及低功耗内核中断处理技术领域,尤其涉及一种基于RISC‑V架构的异常和中断处理系统及方法,包括模式寄存器、异常向量基址寄存器、状态寄存器、异常原因寄存器、异常返回地址寄存器、中断向量基址寄存器、中断状态寄存器、中断返回地址寄存器。有益效果:通过在处理器的内核中分别增加模式寄存器、中断向量基址寄存器、中断状态寄存器及中断返回地址寄存器,将处理器的中断处理模式与异常处理模式分开处理,以使得异常嵌套中断时,处理器的程序能从异常处理模式与中断处理模式中退出,在存在异常嵌套中断时系统能够恢复。

Figure 201910205345

The invention relates to the technical field of low-power-consumption kernel interrupt processing, and in particular, to an exception and interrupt processing system and method based on a RISC-V architecture, including a mode register, an exception vector base address register, a status register, an exception cause register, and an exception return address Register, interrupt vector base address register, interrupt status register, interrupt return address register. Beneficial effect: by adding a mode register, an interrupt vector base address register, an interrupt status register and an interrupt return address register in the core of the processor, the interrupt processing mode and the exception processing mode of the processor are processed separately, so that the exception nests interrupt At this time, the program of the processor can exit from the exception handling mode and the interrupt handling mode, and the system can recover when there is an exception nested interrupt.

Figure 201910205345

Description

RISC-V architecture based exception and interrupt handling system and method
Technical Field
The invention relates to the technical field of low-power-consumption kernel interrupt processing, in particular to an exception and interrupt processing system and method based on a RISC-V framework.
Background
The Interrupt mechanism (Interrupt) is that the processor core is interrupted by another request suddenly in the process of executing the program instruction stream in sequence to stop executing the current program, and then processes another thing until the processor core finishes processing another thing, and then returns to the point of the previous program Interrupt to continue executing the previous program instruction stream. The "other requests" interrupting the execution of the program instruction stream by the processor are referred to as Interrupt requests (Interrupt requests), and the Source of the Interrupt requests is referred to as an Interrupt Source (Interrupt Source), and usually the Interrupt Source is mainly from a peripheral hardware device. The processor going to handle something else is called an Interrupt Service Routine (ISR).
Interrupt handling is a normal mechanism, not an error. After the processor receives the interrupt request, the current program site needs to be protected, which is referred to as a protection site for short. After the interrupt service routine is processed, the processor needs to resume the previous site to continue executing the previously interrupted routine, referred to as the resume site.
Exception (Exception) mechanism, i.e. the processor core suddenly encounters an Exception during the sequential execution of the program instruction stream and terminates the execution of the current program, and then handles the Exception. The "something unusual" encountered by the processor is called an Exception (Exception). An exception is caused by an event within the processor or an event in the execution of a program, such as a hardware fault, a program fault, or the execution of a special system service instruction, and is simply an internal cause. After the exception occurs, the processor may enter an exception service handler. Therefore, the RISC-V architecture has a problem that the system cannot be restored when the interrupt is abnormally nested.
Disclosure of Invention
In view of the above problems in the prior art, a system and method for processing exceptions and interrupts based on RISC-V architecture is now provided.
The specific technical scheme is as follows:
an RISC-V architecture based exception and interrupt handling system comprising:
a mode register for indicating the current operating mode of the system;
an abnormal vector base address register for storing the base address of the abnormal vector when the abnormal request occurs;
a status register for storing the status of exception handling when an exception request occurs;
an exception reason register, is used for storing the exception reason when the request of the exception takes place;
an exception return address register for storing the return address after exception processing when an exception request occurs;
an interrupt vector base register for storing the base of the interrupt vector when an interrupt occurs;
an interrupt status register for storing the status of interrupt processing when an interrupt occurs;
and the interrupt return address register is used for storing the return address after the interrupt processing is finished when the interrupt occurs.
Preferably, the exception and interrupt handling system further comprises an error address or instruction register for storing the access address of the memory or the illegal instruction encoding causing the current exception.
Preferably, the exception vector base address register and the exception return address register are both CSR registers.
Preferably, the status register is a CSR register.
Preferably, the working mode includes a machine sub-mode, a normal mode, an interrupt processing mode, an exception processing mode and a non-mask interrupt mode.
Preferably, the exception handling mode at least comprises an exception priority mode, an exception entering handling mode, an exception exit handling mode, an exception service program mode and an exception nesting mode;
the interrupt processing mode at least comprises an interrupt shielding mode, an interrupt priority and arbitration mode, an interrupt processing mode, an interrupt service program exiting interrupt processing mode, and an interrupt nesting mode.
The invention also includes an abnormality and interrupt processing method based on RISC-V architecture, which is used for any one of the above-mentioned abnormality and interrupt processing systems based on RISC-V architecture, and the abnormality and interrupt processing method based on RISC-V architecture includes an interrupt processing method, the interrupt processing method includes the following steps:
step S10, when the kernel of the processor responds to the interrupt request, the current state of the processor and the return address of the interrupt processing program of the processor are updated, the base address of the interrupt vector of the processor is obtained, and the interrupt processing mode corresponding to the interrupt request is executed;
Step S11, after the interrupt processing mode corresponding to the interrupt request is executed, updating the state of interrupt processing and the current state of the processor, recovering the instruction address of the processor from the return address of the interrupt handler of the processor, and exiting the interrupt processing mode corresponding to the interrupt request.
Preferably, the interrupt processing method further includes the steps of:
step S20, when the kernel of the processor responds to the interrupt request, the current state of the processor and the return address of the processor are updated, the base address of the interrupt vector of the processor is obtained, and the interrupt processing mode corresponding to the interrupt request is executed;
step S21, when the interrupt processing mode corresponding to the interrupt request is executed, an exception occurs, at this time, the kernel of the processor immediately responds to exception information, updates the current state of the processor and the return address of the exception handler storing the processor, respectively, and obtains the base address of the exception vector of the processor, and executes the corresponding exception processing mode;
step S22, after the exception handling mode is executed, updating the exception handling state and the current state of the processor, recovering the instruction address of the processor from the return address of the exception handling program of the processor, exiting the exception handling mode, and returning to the interrupt handling mode corresponding to the interrupt request again for execution;
Step S23, after the interrupt processing mode corresponding to the interrupt request is executed, updating the exception handling state and the current state of the processor, recovering the instruction address of the processor from the return address of the interrupt handler of the processor, and exiting the interrupt processing mode corresponding to the interrupt request.
The invention also comprises an abnormality and interrupt processing method based on the RISC-V architecture, which is used for any one of the above abnormality and interrupt processing systems based on the RISC-V architecture, wherein the abnormality and interrupt processing method based on the RISC-V architecture comprises an abnormality processing method, and the abnormality processing method comprises the following steps:
step S30, when the kernel of the processor responds to the abnormal request, updating the current state of the processor and the return address of the abnormal processing program for storing the processor, acquiring the base address of the abnormal vector of the processor, and starting to execute the abnormal processing mode corresponding to the abnormal request;
step S31, after the exception handling mode corresponding to the exception request is executed, updating the exception handling state and the current state of the processor, recovering the instruction address of the processor from the return address of the exception handler of the processor, and exiting the exception handling mode corresponding to the exception request.
Preferably, the exception handling method further includes the steps of:
step S40, when the kernel of the processor responds to the abnormal request, updating the current state of the processor and the return address of the abnormal processing program for storing the processor, acquiring the base address of the abnormal vector of the processor, and starting to execute the abnormal processing mode corresponding to the abnormal request;
step S41, when the exception handling mode corresponding to the exception request is executed, an exception occurs again, and at this time, the interrupt controller of the core of the processor determines whether the processor is in the exception handling mode before the exception handling mode according to the value of the state of the exception handling;
if yes, go to step S42;
if not, go to the step S44;
when the kernel of the processor responds to the exception again request in step S42, updating the current state of the processor and the return address of the exception handler storing the processor, acquiring the base address of the exception vector of the processor, and starting to execute the exception handling mode corresponding to the exception again;
step S43, after the execution of the exception handling mode corresponding to the reoccurrence of the exception request is completed, updating the state of the exception handling and the current state of the processor, recovering the instruction address of the processor from the return address of the exception handling program of the processor, exiting the exception handling mode corresponding to the reoccurrence of the exception request, and returning to the exception handling mode corresponding to the exception request again for execution;
Step S44, after the exception handling mode corresponding to the exception request is executed, updating the exception handling state and the current state of the processor, recovering the instruction address of the processor from the return address of the exception handler of the processor, and exiting the exception handling mode corresponding to the exception request.
The technical scheme of the invention has the beneficial effects that: the interrupt processing mode and the exception processing mode of the processor are processed separately by respectively adding the mode register, the interrupt vector base address register, the interrupt state register and the interrupt return address register in the kernel of the processor, so that the response speed of the interrupt is accelerated, and the program of the processor can exit from the exception processing mode and the interrupt processing mode when the exception nested interrupt is performed.
Drawings
Embodiments of the present invention will now be described more fully hereinafter with reference to the accompanying drawings. The drawings are, however, to be regarded as illustrative and explanatory only and are not restrictive of the scope of the invention.
FIG. 1 is a functional block diagram of an RISC-V architecture based exception and interrupt handling system according to an embodiment of the present invention;
FIG. 2 is a functional block diagram of the newly added registers of the RISC-V architecture based exception and interrupt handling system of an embodiment of the present invention;
FIG. 3 is a flowchart illustrating the steps of a first embodiment of an interrupt handling method of an exception and interrupt handling method based on RISC-V architecture according to an embodiment of the present invention;
FIG. 4 is a flowchart illustrating the steps of a second embodiment of an interrupt handling method of an exception and interrupt handling method based on RISC-V architecture according to an embodiment of the present invention;
FIG. 5 is a flowchart illustrating the steps of a first embodiment of an exception handling method of the RISC-V architecture based exception and interrupt handling method according to an embodiment of the present invention;
FIG. 6 is a flowchart illustrating the steps of a second embodiment of an interrupt handling method of an exception and interrupt handling method based on RISC-V architecture according to an embodiment of the present invention;
FIG. 7 is a schematic flow diagram of an embodiment of the RISC-V architecture based exception and interrupt handling method of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be obtained by a person skilled in the art without inventive efforts based on the embodiments of the present invention, shall fall within the scope of protection of the present invention.
It should be noted that the embodiments and features of the embodiments of the present invention may be combined with each other without conflict.
The invention is further described with reference to the following drawings and specific examples, which are not intended to be limiting.
In the prior art, the RISC-V architecture defines the CSR register mtvec register, mcause register, and mecc register. The mtvec register is the base address of an interrupt and exception handling entry, the mcause register is an exception cause register, and the mepc register is an exception return address register. The handling of interrupts and exceptions may share these registers. Therefore, if an external interrupt occurs, the processor automatically jumps to an mtvec register to execute (meanwhile, the value of the mecc register is automatically updated to a next unexecuted instruction by hardware), then software queries the mcause register to determine that the cause of the exception is the external interrupt, and then the software jumps to a corresponding external interrupt processing function to execute; similarly, when an exception occurs, the processor jumps to an mtvec register to execute (meanwhile, the value of the mecc register is automatically updated to the abnormal PC by hardware), then software queries the mcause register to determine which exception is the cause of the exception, and then the software jumps to a corresponding exception handling function to execute the exception. It should be noted that the exception may not be masked, that is, once the exception occurs, the processor must stop the current operation and enter the exception handling mode. Thus, an interrupt may be interrupted by an exception at any time. In practical application, if an exception (i.e. an exception nested interrupt) occurs in an interrupt service routine, for the RISC-V architecture, a mecc register and the like automatically saved by hardware when the interrupt occurs are covered when the exception occurs, so that non-recoverable (non-recoverable) results.
Therefore, in view of the above-mentioned drawbacks of the prior art, the present invention discloses an exception and interrupt handling system based on RISC-V architecture, which comprises:
a mode register 1 for indicating the current system operation mode;
an abnormal vector base address register 2, which is used for storing the base address of the abnormal vector when the abnormal request occurs;
a status register 3, for storing the status of exception handling when exception request occurs;
an exception cause register 4 for storing the exception cause when an exception request occurs;
an exception return address register 5, for storing the return address after the exception processing when the exception request occurs;
an interrupt vector base register 6 for storing the base of the interrupt vector when the interrupt occurs;
an interrupt status register 7 for storing the status of interrupt processing when an interrupt occurs;
and the interrupt return address register 8 is used for storing a return address after the interrupt processing is finished when the interrupt occurs.
Through the above-mentioned technical solution of the exception and interrupt handling system based on RISC-V architecture, as shown in fig. 1 and 2, the mode register 1 is an msubmode register, the exception vector base register 2 is an mtvec register, the status register 3 is an mstatus register, the error address or instruction register 9 is an mtval register, the exception cause register 4 is an mcause register, the exception return address register 5 is a mepc register, the interrupt vector base register 6 is a mivec register, the interrupt status register 7 is an istatus register, and the interrupt return address register 8 is a mipc register. It should be noted that the msubmode register, mtvec register, mstatus register, mtval register, mcause register, mcp register, mivec register, istatus register, and mipc register in this solution are different from the corresponding registers in the prior art because the functions of the respective registers are different.
Furthermore, compared with the architecture defined by RISC-V, the exception and interrupt processing system reserves the CSR registers such as the original mtvec register, mstatus register, mtval register, mcause register and mepc register, and also adds 4 CSR registers such as the mivec register, istatus register, mipc register and msubmode register, meanwhile, the mcause register defined in the RISC-V architecture is not used for interrupt processing any more, but is specially used for exception processing, only the MIE domain in the mstatus register is still used for interrupt processing, and other bits are specially used for exception processing.
Further, in the technical scheme, the mtvec register is no longer used as an entry address for interrupt processing, wherein a special entry address mivec register is interrupted; the MPIE field in the mstatus register is no longer related to the interrupt, the actual register of the interrupt has a special MPIE field, the MPS field in the mstatus register is no longer related to the interrupt, and the actual register of the interrupt has a special MPS field; the mcp register is no longer associated with interrupts, which have a dedicated mipc register for storing the return address of the interrupt.
In the technical scheme, the state of the processor when the interrupt occurs is saved through the interrupt return address register 8 and the interrupt state register 7, and only the values in the exception return address register 5 and the state register 3 are changed when the exception occurs, so that exception nesting and interrupt restorability are ensured under the condition that the interrupt return address register 8 and the interrupt state register 7 are not influenced.
Furthermore, the mode register 1, the interrupt vector base address register 6, the interrupt state register 7 and the interrupt return address register 8 are respectively added in the kernel of the processor, so that the interrupt processing mode and the exception processing mode of the processor are separately processed, the response speed of the interrupt is increased, and the program of the processor can exit from the exception processing mode and the interrupt processing mode when the exception nested interrupt occurs.
In the above technical solution, the exception and interrupt handling system further includes an error address or instruction register 9, which is used for storing an access address of the memory causing the current exception or an illegal instruction code.
In the above technical solution, the exception vector base register 2 and the exception return address register 5 are both CSR registers, and are readable and writable under the exception vector base register 2 and the exception return address register 5. Namely, the mtvec register and the mepc register are both CSR registers, and the mtvec register and the mepc register can be read and written.
In the above technical solution, the status register 3 is a CSR register, and under the status register 3, the MIE domain, the MPIE domain, the MPP domain, and the MPS domain are all readable and writable. Further, the MPIE field, the MPP field and the MPS field are respectively used for automatically storing the values of the MIE field, the privileged mode and the machine submode before entering the interrupt processing mode, and are used for automatically recovering when exiting the exception processing mode. Namely, the mstatus register is a CSR register, and the MIE domain, the MPIE domain, the MPP domain and the MPS domain of the mstatus register are readable and writable. Wherein, the bit of the MIE domain is 3, the bit of the MPIE domain is 7, and the bit of the MPP domain is 12-11.
Specifically, in the mstatus register, an MIE field is used for representing the global interrupt enable, an MPIE field is used for saving the value of the MIE field before the exception is entered, and an MPS field is used for saving the value of the privileged mode before the exception is entered; in the actual register, MPIE field is used to save the value of MIE field before the interrupt is entered, MPS field is used to save the value of privileged mode before the interrupt is entered.
In a preferred embodiment, the working mode includes machine sub-mode, normal mode, interrupt processing mode, exception processing mode, and unmasked interrupt mode.
Further, the exception handling mode includes at least a priority mode of the exception, an enter exception handling mode, an exit exception handling mode, an exception service routine mode, and an exception nesting mode.
Specifically, the exception in the processor core may not be masked, that is, once the exception occurs, the processor must stop the current operation and enter the exception handling mode.
Further, the priority pattern of the abnormality means that the smaller the number of abnormality numbers, the higher the priority of the abnormality. Further, when entering the exception handling mode, the hardware behavior of the processor includes: stopping executing the current program flow, and starting to execute from the PC address defined by the CSR mtvec register; the hardware is provided with a CSR register mcas register, a mcp register, an mtval register and a mstatus register at the same time, wherein the mcas register is updated to be a currently generated exception type, an exception return address mcp register is updated to be a currently generated exception instruction PC, the mtval register is updated to be a memory access address or an illegal instruction code causing current exception, and the mstatus register updates the value of an MIE field to be 0 and updates the value of an MPP field to be a Privilege Mode (Privilege Mode) before exception generation and updates the value of an MPS field to be a Machine Sub-Mode (Machine Sub-Mode) before exception generation; hardware updates the processor core's Privilege Mode (Privilege Mode) and Machine Sub-Mode (Machine Sub-Mode), mstatus register, MPIE field's value is updated to mstatus register before exception occurs, MIE field's value, processor core's Privilege Mode (Privilege Mode) is updated to normal (Machine Mode), processor core's Machine Sub-Mode (Machine Sub-Mode) is updated to exception handling Mode.
Further, when the exception handling mode is exited, the hardware behavior of the processor includes: stopping executing the current program flow, and starting to execute from the PC address defined by the CSR register mepc register; hardware updates the CSR register mstatus register, the value of MIE field is restored to the value of the current mstatus register MPIE field, the value of the current mstatus register MPIE field is updated to 1; the hardware updates both the processor core's privileged Mode (Privilege Mode) which returns to the mstatus register MPP field value and the Machine Sub-Mode (Machine Sub-Mode) which returns to the mstatus register MPP field value.
Further, anomalous nesting refers to: after entering the exception handler, the exception may be encountered again, which is called a Double exception Fault (Double Fault), and is often a very serious Fault. The value of the MPS domain determines whether the exception handling mode was in the exception handling mode before entry (i.e., the exception was nested) by determining its mstatus register after entry into the exception service routine.
Furthermore, the mode register 1, the interrupt vector base address register 6, the interrupt state register 7 and the interrupt return address register 8 are respectively added in the kernel of the processor, so that the interrupt processing mode and the exception processing mode of the processor are separately processed, the response speed of the interrupt is increased, and the program of the processor can exit from the exception processing mode and the interrupt processing mode when the exception nested interrupt occurs.
In a preferred embodiment, the interrupt handling modes include at least an interrupt mask mode, an interrupt priority and arbitration mode, an entry into an interrupt handling mode, an exit from an interrupt handling mode, an interrupt service routine mode, and an interrupt nesting mode.
Specifically, interrupt mask mode includes the MIE field of the mstatus register being used to control the global enabling of interrupts.
Furthermore, the interrupt mask mode further includes implementing an interrupt controller, where the interrupt controller manages all the interrupt sources in a unified manner, and the interrupt controller allocates a respective interrupt enable register to each interrupt source, so that a user can manage the mask of each interrupt source by configuring the register of the interrupt controller.
Further, the interrupt priority and arbitration mode refers to that the interrupt controller manages arbitration of all interrupt sources uniformly, the interrupt controller allocates a respective interrupt priority register for each interrupt source, and a user can manage the priority of each interrupt source by configuring the register of the interrupt controller.
Further, when entering the interrupt handling mode, the hardware behavior of the kernel of the processor includes: stopping executing the current program flow and starting to execute from the PC address defined by the CSR register mivec register; it also allows the hardware to update several other CSR registers simultaneously: a mipc register, an mstatus register, and an istatus register, the interrupt return address mipc register being pointed to the next instruction that has not yet been executed, the mstatus register, the value of the MIE field being updated to 0, the istatus register, the value of the MPIE field being updated to the mstatus register before the interrupt occurred, the value of the MIE field, the istatus register, the value of the MPP field being updated to the Privilege Mode (Privilege Mode) before the interrupt occurred, the istatus register, the value of the MPS field being updated to the Machine Sub-Mode (Machine Sub-Mode) before the interrupt occurred; in addition, entering the interrupt updates the Privilege Mode (privillemode) and the Machine Sub-Mode (Machine Sub-Mode) of the processor core, the Privilege Mode (privillemode) of the processor core is updated to the normal (Machine Mode), and the Machine Sub-Mode (Machine Sub-Mode) of the processor core is updated to the interrupt processing Mode.
Further, the hardware behavior of the kernel of the processor when exiting the interrupt handling mode includes: stopping executing the current program flow, and starting to execute from the PC address defined by the CSR register mipc register; updating CSR register mstatus register, istatus register, and update Privilege Mode (Privilege Mode), and Machine Sub-Mode (Machine Sub-Mode), mstatus register, the value of MIE field is restored to the value of current istatus register MPIE field, the value of the istatus register MPIE field is updated to 1, the Privilege Mode (Privilege Mode) of the processor is the value of the istatus register MPP field, and the Machine Sub-Mode (Machine Sub-Mode) of the processor is updated to the value of the istatus register MPS Sub-field.
Further, the specific implementation of interrupt nesting includes: after the program jumps into the interrupt service program, the software can force to rewrite the value of the mstatus register, and change the value of the MIE field to 1, which means that the interrupt is globally opened again, and from this moment, the processor can respond to the interrupt again; the interrupt controller of the processor core will ensure that only new interrupts of higher priority are allowed to be dispatched to the processor core; during interrupt nesting, software needs to take care to save the context to the memory stack or to restore the context from the memory stack (same as function nesting). During interrupt nesting, software also needs to take care to save or restore values of the mipc and istatus registers to or from the memory stack (same way as function nesting).
The invention also comprises an abnormality and interruption processing method based on the RISC-V architecture, wherein the abnormality and interruption processing method based on the RISC-V architecture comprises an interruption processing method.
Specifically, as shown in fig. 3, the first embodiment of the interrupt processing method includes the steps of:
step S10, when the kernel of the processor responds to the interrupt request, the current state of the processor and the return address of the interrupt processing program of the storage processor are updated, the base address of the interrupt vector of the processor is obtained, and the interrupt processing mode corresponding to the interrupt request is executed;
step S11, after the execution of the interrupt processing mode corresponding to the interrupt request is completed, the state of the interrupt processing and the current state of the processor are updated, the instruction address of the processor is restored from the return address of the interrupt processing program of the processor, and the interrupt processing mode corresponding to the interrupt request is exited.
Further, as shown in fig. 4, the first embodiment of the interrupt processing method includes the steps of:
step S20, when the kernel of the processor responds to the interrupt request, the current state of the processor and the return address of the storage processor are updated, the base address of the interrupt vector of the processor is obtained, and the interrupt processing mode corresponding to the interrupt request is started to be executed;
Step S21, when the interrupt processing mode corresponding to the interrupt request is executed, an exception occurs, at this time, the kernel of the processor immediately responds to the exception information, respectively updates the current state of the processor and the return address of the exception handling program of the storage processor, acquires the base address of the exception vector of the processor, and executes the corresponding exception processing mode;
step S22, after the exception handling mode is executed, updating the exception handling state and the current state of the processor, recovering the instruction address of the processor from the return address of the exception handler of the processor, exiting the exception handling mode, and returning to the interrupt handling mode corresponding to the interrupt request again for execution;
step S23, after the interrupt processing mode corresponding to the interrupt request is executed, the exception handling state and the current state of the processor are updated, the instruction address of the processor is recovered from the return address of the interrupt processing program of the processor, and the interrupt processing mode corresponding to the interrupt request is exited.
The invention also comprises an abnormality and interruption processing method based on the RISC-V architecture, wherein the abnormality and interruption processing method based on the RISC-V architecture comprises an abnormality processing method.
Specifically, as shown in fig. 5, the first embodiment of the exception handling method includes the steps of:
step S30, when the kernel of the processor responds to the abnormal request, the current state of the processor and the return address of the abnormal processing program of the storage processor are updated, the base address of the abnormal vector of the processor is obtained, and the abnormal processing mode corresponding to the abnormal request is executed;
step S31, after the exception handling mode corresponding to the exception request is executed, the state of the exception handling and the current state of the processor are updated, the instruction address of the processor is recovered from the return address of the exception handling program of the processor, and the exception handling mode corresponding to the exception request is exited.
Further, as shown in fig. 6, the second embodiment of the exception handling method includes the steps of:
step S40, when the kernel of the processor responds to the abnormal request, the current state of the processor and the return address of the abnormal processing program of the storage processor are updated, the base address of the abnormal vector of the processor is obtained, and the abnormal processing mode corresponding to the abnormal request is executed;
step S41, when the exception handling mode corresponding to the exception request is executed, an exception occurs again, and at this time, the interrupt controller of the core of the processor determines whether the processor is in the exception handling mode before according to the value of the state of the exception handling;
If yes, go to step S42;
if not, go to step S44;
step S42, when the kernel of the processor responds to the abnormal request again, the current state of the processor and the return address of the abnormal processing program of the storage processor are updated, the base address of the abnormal vector of the processor is obtained, and the abnormal processing mode corresponding to the abnormal request which occurs again is executed;
step S43, after executing the exception handling mode corresponding to the reoccurrence of the exception request, updating the exception handling state and the current state of the processor, recovering the instruction address of the processor from the return address of the exception handling program of the processor, exiting the exception handling mode corresponding to the reoccurrence of the exception request, and returning to the exception handling mode corresponding to the exception request again for execution;
step S44, after the exception handling mode corresponding to the exception request is executed, updates the exception handling state and the current state of the processor, restores the instruction address of the processor from the return address of the exception handler of the processor, and exits the exception handling mode corresponding to the exception request.
In a preferred embodiment, with the above technical solution of the method for nesting exceptions and interrupts based on the RISC-V architecture, as shown in fig. 7, a step1, a processor core responds to a Request of an Interrupt Request (Interrupt Request1), updates a mipc register, an istatus register and a submode register, jumps to a mivec register, and starts to execute an Interrupt handler corresponding to the Interrupt Request (Interrupt Request 1);
step2, the processor core generates an exception in the middle of executing the Interrupt processing program corresponding to the Interrupt Request (Interrupt Request1), at the moment, the processor core immediately responds to the exception, updates a mcp register, a mstatus register and a msubmode register, jumps to an mtvec register and executes the corresponding exception processing program;
step3, after the processor kernel executes the abnormal processing program, updating the mstatus register and the msubmode register, recovering the PC address from the mepc register, exiting the abnormal processing program, and returning to the Interrupt processing program corresponding to the Interrupt Request (Interrupt Request1) for execution;
after the Interrupt handler corresponding to the Interrupt Request (Interrupt Request1) is executed, step4 updates the mstatus register and the msubmode register, restores the PC address from the mipc register, and exits the Interrupt handler corresponding to the Interrupt Request (Interrupt Request 1).
Furthermore, in the flow of the abnormal nested interrupt, the state of the processor when the interrupt occurs is saved through the mipc register and the istatus register, and the values in the mcp register and the mstatus register are only changed when the exception occurs, without influencing the mipc register and the istatus register, so that the abnormal nested interrupt is ensured to be recoverable.
While the invention has been described with reference to a preferred embodiment, it will be understood by those skilled in the art that various changes in form and detail may be made without departing from the spirit and scope of the invention.

Claims (10)

1.一种基于RISC-V架构的异常和中断处理系统,其特征在于,包括:1. an exception and interrupt processing system based on RISC-V architecture, is characterized in that, comprises: 一模式寄存器,用于指示当前系统的工作模式;A mode register, used to indicate the working mode of the current system; 一异常向量基址寄存器,用于发生异常请求时存储异常向量的基址;An exception vector base address register, used to store the base address of the exception vector when an exception request occurs; 一状态寄存器,用于发生异常请求时存储异常处理的状态;A status register, used to store the status of exception handling when an exception request occurs; 一异常原因寄存器,用于发生异常请求时存储异常原因;An exception cause register, which is used to store the exception cause when an exception request occurs; 一异常返回地址寄存器,用于发生异常请求时存储异常处理完毕后的返回地址;An exception return address register, which is used to store the return address after the exception processing is completed when an exception request occurs; 一中断向量基址寄存器,用于发生中断时存储中断向量的基址;An interrupt vector base address register, which is used to store the base address of the interrupt vector when an interrupt occurs; 一中断状态寄存器,用于发生中断时存储中断处理的状态;An interrupt status register, which is used to store the state of interrupt processing when an interrupt occurs; 一中断返回地址寄存器,用于发生中断时存储中断处理完毕后的返回地址。An interrupt return address register is used to store the return address after the interrupt is processed when an interrupt occurs. 2.根据权利要求1所述的基于RISC-V架构的异常和中断处理系统,其特征在于,所述异常和中断处理系统还包括一出错地址或指令寄存器,用于存储引起当前异常的存储器的访问地址或者非法指令编码。2. the abnormal and interrupt processing system based on RISC-V architecture according to claim 1, is characterized in that, described abnormal and interrupt processing system also comprises an error address or instruction register, for storing the memory that causes current abnormality. Access address or illegal instruction code. 3.根据权利要求1所述的基于RISC-V架构的异常和中断处理系统,其特征在于,所述异常向量基址寄存器、所述异常返回地址寄存器均为CSR寄存器。3. The RISC-V architecture-based exception and interrupt processing system according to claim 1, wherein the exception vector base address register and the exception return address register are both CSR registers. 4.根据权利要求1所述的基于RISC-V架构的异常和中断处理系统,其特征在于,所述状态寄存器为CSR寄存器。4. The exception and interrupt processing system based on RISC-V architecture according to claim 1, wherein the status register is a CSR register. 5.根据权利要求1所述的基于RISC-V架构的异常和中断处理系统,其特征在于,所述工作模式包括机器子模式、普通模式、中断处理模式、异常处理模式、非屏蔽中断模式。5 . The exception and interrupt processing system based on RISC-V architecture according to claim 1 , wherein the working modes include machine sub-mode, normal mode, interrupt processing mode, exception processing mode, and non-maskable interrupt mode. 6 . 6.根据权利要求5所述的基于RISC-V架构的异常和中断处理系统,其特征在于,所述异常处理模式至少包括异常的优先级模式、进入异常处理模式、退出异常处理模式、异常服务程序模式和异常嵌套模式;6. The exception and interrupt processing system based on RISC-V architecture according to claim 5, wherein the exception processing mode at least comprises an exception priority mode, entering exception processing mode, exiting exception processing mode, exception service Program mode and exception nesting mode; 所述中断处理模式至少包括中断屏蔽模式、中断优先级与仲裁模式、进入中断处理模式、退出中断处理模式、中断服务程序模式和中断嵌套模式。The interrupt processing modes include at least interrupt mask mode, interrupt priority and arbitration mode, entering interrupt processing mode, exiting interrupt processing mode, interrupt service routine mode and interrupt nesting mode. 7.一种基于RISC-V架构的异常和中断处理方法,其特征在于,用于上述权利要求1-6任意一项所述的基于RISC-V架构的异常和中断处理系统,所述基于RISC-V架构的异常和中断处理方法包括一中断处理方法,所述中断处理方法包括以下步骤:7. An exception and interrupt processing method based on RISC-V architecture, characterized in that, for the exception and interrupt processing system based on RISC-V architecture according to any one of the above claims 1-6, the RISC-based exception and interrupt processing system The exception and interrupt handling method of the -V architecture includes an interrupt handling method, and the interrupt handling method includes the following steps: 步骤S10、处理器的内核响应到中断请求时,更新所述处理器的当前状态及存储所述处理器的中断处理程序的返回地址,并获取所述处理器的中断向量的基址,开始执行所述中断请求对应的中断处理模式;Step S10, when the core of the processor responds to the interrupt request, updates the current state of the processor and stores the return address of the interrupt handler of the processor, and obtains the base address of the interrupt vector of the processor, and starts executing an interrupt processing mode corresponding to the interrupt request; 步骤S11、在执行完所述中断请求对应的所述中断处理模式之后,更新中断处理的状态及所述处理器的当前状态,将处理器的指令地址从所述处理器的中断处理程序的返回地址中恢复,退出所述中断请求对应的所述中断处理模式。Step S11: After executing the interrupt processing mode corresponding to the interrupt request, update the state of interrupt processing and the current state of the processor, and return the instruction address of the processor from the interrupt handler of the processor. recover from the address, and exit the interrupt processing mode corresponding to the interrupt request. 8.根据权利要求7所述的基于RISC-V架构的异常和中断处理方法,其特征在于,所述中断处理方法还包括以下步骤:8. The exception and interrupt processing method based on RISC-V architecture according to claim 7, wherein the interrupt processing method further comprises the following steps: 步骤S20、处理器的内核响应到中断请求时,更新所述处理器的当前状态及存储所述处理器的返回地址,并获取所述处理器的中断向量的基址,开始执行所述中断请求对应的中断处理模式;Step S20, when the core of the processor responds to the interrupt request, updates the current state of the processor and stores the return address of the processor, and obtains the base address of the interrupt vector of the processor, and starts to execute the interrupt request Corresponding interrupt handling mode; 步骤S21、在执行所述中断请求对应的所述中断处理模式时,发生了异常,此时,所述处理器的内核马上响应到异常信息,分别更新所述处理器的当前状态及存储所述处理器的异常处理程序的返回地址,并获取所述处理器的异常向量的基址,执行对应的异常处理模式;Step S21: When executing the interrupt processing mode corresponding to the interrupt request, an exception occurs. At this time, the core of the processor immediately responds to the exception information, updates the current state of the processor and stores the The return address of the exception handler of the processor, and the base address of the exception vector of the processor is obtained, and the corresponding exception handling mode is executed; 步骤S22、在执行完所述异常处理模式之后,更新所述异常处理的状态与所述处理器的当前状态,将所述处理器的指令地址从所述处理器的异常处理程序的返回地址中恢复,退出所述异常处理模式,重新回到所述中断请求对应的所述中断处理模式中执行;Step S22: After executing the exception handling mode, update the state of the exception handling and the current state of the processor, and change the instruction address of the processor from the return address of the exception handling program of the processor. recover, exit the exception processing mode, and return to the interrupt processing mode corresponding to the interrupt request for execution; 步骤S23、在执行完所述中断请求对应的所述中断处理模式之后,更新所述异常处理状态及所述处理器的当前状态,将所述处理器的指令地址从所述处理器的中断处理程序的返回地址中恢复,退出所述中断请求对应的所述中断处理模式。Step S23: After executing the interrupt processing mode corresponding to the interrupt request, update the exception processing state and the current state of the processor, and change the instruction address of the processor from the interrupt processing of the processor. The program resumes in the return address, and exits the interrupt processing mode corresponding to the interrupt request. 9.一种基于RISC-V架构的异常和中断处理方法,其特征在于,用于上述权利要求1-6任意一项所述的基于RISC-V架构的异常和中断处理系统,所述基于RISC-V架构的异常和中断处理方法包括一异常处理方法,所述异常处理方法包括以下步骤:9. An exception and interrupt processing method based on RISC-V architecture, characterized in that it is used in the exception and interrupt processing system based on RISC-V architecture according to any one of the above claims 1-6, and said RISC-based exception and interrupt processing system The exception and interrupt handling method of the -V architecture includes an exception handling method, and the exception handling method includes the following steps: 步骤S30、处理器的内核响应到异常请求时,更新所述处理器的当前状态及存储所述处理器的异常处理程序的返回地址,并获取所述处理器的异常向量的基址,开始执行所述异常请求对应的异常处理模式;Step S30, when the core of the processor responds to the exception request, updates the current state of the processor and stores the return address of the exception handler of the processor, and obtains the base address of the exception vector of the processor, and starts to execute the exception handling mode corresponding to the exception request; 步骤S31、在执行完所述异常请求对应的所述异常处理模式之后,更新异常处理的状态及所述处理器的当前状态,将处理器的指令地址从所述处理器的异常处理程序的返回地址中恢复,退出所述异常请求对应的所述异常处理模式。Step S31: After executing the exception processing mode corresponding to the exception request, update the status of exception processing and the current status of the processor, and return the instruction address of the processor from the exception processing program of the processor. recovery from the address, and exit the exception processing mode corresponding to the exception request. 10.根据权利要求9所述的基于RISC-V架构的异常和中断处理方法,其特征在于,所述异常处理方法还包括以下步骤:10. The exception and interrupt processing method based on RISC-V architecture according to claim 9, wherein the exception processing method further comprises the following steps: 步骤S40、处理器的内核响应到异常请求时,更新所述处理器的当前状态及存储所述处理器的异常处理程序的返回地址,并获取所述处理器的异常向量的基址,开始执行所述异常请求对应的异常处理模式;Step S40, when the core of the processor responds to the exception request, updates the current state of the processor and stores the return address of the exception handling program of the processor, and obtains the base address of the exception vector of the processor, and starts execution. the exception handling mode corresponding to the exception request; 步骤S41、在执行所述异常请求对应的所述异常处理模式时,再次发生异常,此时,所述处理器的内核的中断控制器根据所述异常处理的状态的值判断之前所述处理器是否处于所述异常处理模式;Step S41: When the exception processing mode corresponding to the exception request is executed, an exception occurs again. At this time, the interrupt controller of the core of the processor judges the previous processor according to the value of the status of the exception processing. Whether it is in the exception handling mode; 若是,则转向步骤S42;If yes, go to step S42; 若否,则转向步骤S44;If not, go to step S44; 所述步骤S42、所述处理器的内核响应到再次异常请求时,更新所述处理器的当前状态及存储所述处理器的异常处理程序的返回地址,并获取所述处理器的异常向量的基址,开始执行再次发生异常请求对应的异常处理模式;In step S42, when the core of the processor responds to the exception request again, the current state of the processor is updated and the return address of the exception handler of the processor is stored, and the exception vector of the processor is obtained. Base address, start executing the exception handling mode corresponding to the reoccurrence of the exception request; 步骤S43、在执行完再次发生异常请求对应的异常处理模式之后,更新所述异常处理的状态与所述处理器的当前状态,将所述处理器的指令地址从所述处理器的异常处理程序的返回地址中恢复,退出再次发生异常请求对应的所述异常处理模式,重新回到所述异常请求对应的所述异常处理模式中执行;Step S43: After executing the exception handling mode corresponding to the reoccurrence request, update the state of the exception handling and the current state of the processor, and change the instruction address of the processor from the exception handling program of the processor. recovery from the return address, exit the exception handling mode corresponding to the reoccurrence request, and return to the exception handling mode corresponding to the exception request for execution; 步骤S44、在执行完所述异常请求对应的所述异常处理模式之后,更新所述异常处理的状态与所述处理器的当前状态,将所述处理器的指令地址从所述处理器的异常处理程序的返回地址中恢复,退出所述异常请求对应的所述异常处理模式。Step S44: After executing the exception processing mode corresponding to the exception request, update the status of the exception processing and the current status of the processor, and change the instruction address of the processor from the exception processing mode of the processor. The return address of the handler is recovered, and the exception processing mode corresponding to the exception request is exited.
CN201910205345.3A 2019-03-18 2019-03-18 An exception and interrupt processing system and method based on RISC-V architecture Active CN109933451B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910205345.3A CN109933451B (en) 2019-03-18 2019-03-18 An exception and interrupt processing system and method based on RISC-V architecture

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910205345.3A CN109933451B (en) 2019-03-18 2019-03-18 An exception and interrupt processing system and method based on RISC-V architecture

Publications (2)

Publication Number Publication Date
CN109933451A CN109933451A (en) 2019-06-25
CN109933451B true CN109933451B (en) 2022-06-28

Family

ID=66987521

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910205345.3A Active CN109933451B (en) 2019-03-18 2019-03-18 An exception and interrupt processing system and method based on RISC-V architecture

Country Status (1)

Country Link
CN (1) CN109933451B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110515871B (en) * 2019-08-09 2021-05-25 苏州浪潮智能科技有限公司 Interrupt method, device, FPGA and storage medium
CN112905374A (en) * 2021-02-08 2021-06-04 烽火通信科技股份有限公司 Method and device for improving robustness of embedded software
CN114968370A (en) * 2021-02-25 2022-08-30 华为技术有限公司 An exception handling method and related device
CN114519332B (en) * 2022-02-18 2022-12-27 超睿科技(长沙)有限公司 Processor verification method and device based on assertion and electronic equipment
CN116382856B (en) * 2023-06-02 2023-09-26 麒麟软件有限公司 Method for enhancing system instantaneity based on virtualized nesting
CN117056062B (en) * 2023-10-13 2024-04-02 武汉天喻信息产业股份有限公司 Method and device for forcedly exiting interrupt service routine

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5386563A (en) * 1992-10-13 1995-01-31 Advanced Risc Machines Limited Register substitution during exception processing
CN108595256A (en) * 2018-03-20 2018-09-28 武汉市聚芯微电子有限责任公司 A method of software realization interrupt nesting is used based on RISC-V framework chips
CN109376000A (en) * 2018-10-24 2019-02-22 胡振波 Quick-speed interruption control system and method for RISC-V framework

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
FR2894693A1 (en) * 2005-12-09 2007-06-15 St Microelectronics Sa Register saving/restoring instruction executing method for e.g. microcontroller, involves updating register`s save/restoration advancement state for each generation of micro instructions, and storing state upon save/restoration interruption

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5386563A (en) * 1992-10-13 1995-01-31 Advanced Risc Machines Limited Register substitution during exception processing
CN108595256A (en) * 2018-03-20 2018-09-28 武汉市聚芯微电子有限责任公司 A method of software realization interrupt nesting is used based on RISC-V framework chips
CN109376000A (en) * 2018-10-24 2019-02-22 胡振波 Quick-speed interruption control system and method for RISC-V framework

Also Published As

Publication number Publication date
CN109933451A (en) 2019-06-25

Similar Documents

Publication Publication Date Title
CN109933451B (en) An exception and interrupt processing system and method based on RISC-V architecture
US11360803B2 (en) Method and apparatus for executing non-maskable interrupt
CN102804134B (en) Apparatus and method for handling exception events
US8898666B2 (en) Virtual machine system and virtual machine system control method for controlling program execution on a plurality of processors that have a plurality of privileged modes
JP5699213B2 (en) Incorrect mode change operation
CN102308285B (en) Memory bug application of application program
JP2002268914A (en) Method for monitoring execution of privileged instruction
CN101730881A (en) System including multiple processors and method of operating the same
CN111414626A (en) TEE extension-based real-time guaranteeing method and system
CN105224403B (en) A kind of interruption processing method and device
US20170177431A1 (en) Computer system
JP2009134565A (en) Virtual computer system and control method of virtual computer system
JP4533713B2 (en) Information processing apparatus and data transfer control method
JPH0810437B2 (en) Guest execution control method for virtual machine system
JP2016531363A (en) Handling time-consuming instructions
CN110059040B (en) RISC-V architecture based system and method for nesting abnormal and unmasked interrupts
CN109947550B (en) Non-shielding interrupt processing system and method suitable for RISC-V architecture
JP7418670B2 (en) Computer, control method and control program
JPWO2012104950A1 (en) Start control device, information device, and start control method
JP2008225710A (en) Computer system and process-switching method used in the system
JP4535663B2 (en) State machine control method and state machine
CN115756936A (en) Kernel instruction adaptation method, device, computer equipment and storage medium
JPS58182766A (en) Program tracing device
JP2016177331A (en) Electronic control device
CN1963767A (en) Method to realize interruption of component embedded operation system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant