Interrupt control method, processor system, chip and electronic device

By introducing the interrupt controller and stack pointer to the interrupt program stack in the processor system, the problem of slow interrupt response speed and high hardware cost in the RISC-V interrupt controller solution is solved, and the effect of fast response and hardware cost saving is achieved .

CN117573318BActive Publication Date: 2024-11-08BEIJING SMARTCHIP MICROELECTRONICS TECHNOLOGY CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202311581174.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-24
Publication Date
2024-11-08
Estimated Expiration
2043-11-24

AI Technical Summary

Technical Problem

The standard RISC-V interrupt controller scheme requires a large amount of context to save and restore instructions when supporting interrupt operations, resulting in slow interrupt response and high hardware costs.

Method used

By introducing interrupt controller, register, task stack and interrupt program stack into the processor system, the stack pointer is used to point to the interrupt program stack, only one stack space required for interrupt processing is reserved, and different tasks share the same interrupt program stack. Implement hardware and software operation optimization.

Benefits of technology

Simplify interrupt response operations, improve interrupt response speed, greatly optimize interrupt response time, and significantly save hardware costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117573318B_ABST
    Figure CN117573318B_ABST
Patent Text Reader

Abstract

The present disclosure provides an interrupt control method, a processor system, a chip and an electronic device. The processor system includes: a processor core, an interrupt controller, a register, a task stack and an interrupt program stack, wherein: when an interrupt request is received during the process of the processor core running a task, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, and points the stack pointer to the interrupt program stack. Then, the processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the interrupt request, wherein, when the processor core runs the task, the stack pointer points to the task stack and saves the interrupt program stack address value; after executing the interrupt processing flow, the processor core restores the value of the stack pointer to the saved value, saves the interrupt program stack address value, and restores the value of the register from the stack pointed to by the stack pointer.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of kernel interrupt processing, and in particular to an interrupt control method, a processor system, a chip and an electronic device. Background Art

[0002] RISC-V is an open source instruction set architecture (ISA) based on the Reduced Instruction Set Architecture (RISC) principle. The design of the RISC-V instruction set takes into account practical requirements such as small size, fast speed, and low power consumption. It is a CPU design that can be freely used under the BSD license, equivalent to "open source hardware", and has been widely used in related industries. However, the standard RISC-V interrupt controller solution has the disadvantage that a large amount of context is required to save and restore instructions when supporting interrupt operations. Summary of the invention

[0003] In order to solve the problems in the related art, the present disclosure provides an interrupt control method, a processor system, a chip and an electronic device.

[0004] In a first aspect, an embodiment of the present disclosure provides a processor system, including: a processor core, an interrupt controller, a register, a task stack, and an interrupt program stack, wherein:

[0005] When the interrupt controller receives an interrupt request during the execution of a task by the processor core, the interrupt controller notifies the processor core of the occurrence of an interrupt;

[0006] In response to the interrupt, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, points the stack pointer to the interrupt program stack, and then the processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the interrupt request, wherein the task stack is a stack used by the task, the interrupt program stack is a stack used by the interrupt processing program, and when the processor core runs the task, the stack pointer points to the task stack;

[0007] After the processor core completes executing the interrupt processing flow, the processor core restores the value of the stack pointer to the saved value, saves the interrupt program stack address value, and restores the value of the register from the stack pointed to by the stack pointer.

[0008] According to an embodiment of the present disclosure, the interrupt program stack and the task stack occupy different stack spaces, and different tasks share the same interrupt program stack.

[0009] According to an embodiment of the present disclosure, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, and points the stack pointer to the interrupt program stack, including:

[0010] The processor core pushes the value of the register into the stack pointed to by the stack pointer, then saves the value of the stack pointer and points the stack pointer to the interrupt program stack.

[0011] According to an embodiment of the present disclosure, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, and points the stack pointer to the interrupt program stack, including:

[0012] The processor core saves the value of the stack pointer, points the stack pointer to the interrupt program stack, and then pushes the value of the register into the stack pointed to by the stack pointer.

[0013] According to an embodiment of the present disclosure, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, points the stack pointer to the interrupt program stack, and the processor core restores the value of the stack pointer to the saved value, saves the interrupt program stack address value, and restores the value of the register from the stack pointed to by the stack pointer, which is an operation implemented by hardware.

[0014] According to an embodiment of the present disclosure, the processor core uses the stack pointed to by the stack pointer to execute an operation in which the interrupt processing flow corresponding to the interrupt request is implemented by software.

[0015] According to an embodiment of the present disclosure, the registers include general registers and control and status registers;

[0016] The processor core pushes the register value into the stack pointed to by the stack pointer, including the processor core updating the control and status register value and then pushing the control and status register value and the general register value into the stack pointed to by the stack pointer.

[0017] According to an embodiment of the present disclosure, when the interrupt controller receives another interrupt request during the execution of the interrupt handling process by the processor core, the interrupt controller notifies the processor core of the other interrupt request;

[0018] In response to the another interrupt, the processor core updates the value of the control and status register, and pushes the value of the general register and the value of the control and status register into the stack pointed to by the stack pointer;

[0019] The processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the other interrupt request;

[0020] After the processor core completes executing the interrupt processing flow corresponding to the other interrupt request, the processor core restores the values ​​of the general register and the control and status register from the stack pointed to by the stack pointer.

[0021] According to an embodiment of the present disclosure, the control and status registers include an instruction address register and a status register;

[0022] The processor core updates the value of the control and status register, including: setting the value of the instruction address register to the next instruction address of the current instruction executed by the processor core; setting the value of the status register to disable global interrupts;

[0023] After the processor core restores the values ​​of the control and status registers from the stack pointed to by the stack pointer, it continues to execute corresponding instructions according to the value of the instruction address register and sets the value of the status register to enable global interrupts.

[0024] According to an embodiment of the present disclosure, the control and status register further includes a cause register for storing an exception or interrupt cause.

[0025] According to an embodiment of the present disclosure, the general registers include caller-save registers and callee-save registers;

[0026] The processor core pushes the value of the general register into the stack pointed to by the stack pointer, comprising: the processor core pushes the value of the caller save register into the stack pointed to by the stack pointer;

[0027] The processor core restores the value of the general register from the stack pointed to by the stack pointer, including: the processor core restores the value of the caller save register from the stack pointed to by the stack pointer.

[0028] According to an embodiment of the present disclosure, the interrupt processing process executed by the processor core includes:

[0029] Save the values ​​of the callee-save registers;

[0030] Execute the interrupt handler;

[0031] Restore the values ​​of the saved callee-save registers.

[0032] According to an embodiment of the present disclosure, the processor system further includes an extended interrupt nesting control register, and the extended interrupt nesting control register includes an interrupt nesting count field for recording an interrupt nesting state.

[0033] According to an embodiment of the present disclosure, when an interrupt request is received, the processor core determines whether the processor core is in the process of executing a task or in the process of handling an interrupt according to the value of the interrupt nesting count field.

[0034] According to an embodiment of the present disclosure, the extended interrupt nesting control register also includes a maximum interrupt nesting level field, which stores the maximum number of nesting levels allowed by the interrupt nesting function. When the interrupt nesting level represented by the interrupt nesting count field reaches the value of the maximum interrupt nesting level field, the interrupt is not enabled.

[0035] According to an embodiment of the present disclosure, the extended interrupt nesting controller further includes an interrupt nesting water level field, and the interrupt nesting water level field stores the maximum interrupt nesting depth since the system is started.

[0036] According to an embodiment of the present disclosure, when the value of the interrupt nesting water level field is equal to the maximum interrupt nesting level field, it indicates that the system design needs to be optimized.

[0037] According to an embodiment of the present disclosure, the extended interrupt nesting control register further includes a pointer exchange switch field, and the processor core determines whether to change the stack pointed to by the stack pointer according to the pointer exchange switch field.

[0038] According to an embodiment of the present disclosure, the processor system also includes a stack address register for storing an interrupt program stack address value, wherein setting the stack pointer to point to the interrupt program stack includes setting the value of the stack pointer to the interrupt program stack address value stored in the stack address register.

[0039] In a second aspect, an embodiment of the present disclosure provides a chip comprising one or more of the processor systems described above.

[0040] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising any one or more of the processor systems of the first aspect, or the chip of the second aspect.

[0041] In a fourth aspect, an embodiment of the present disclosure provides an interrupt control method, the method being applied to a processor system including a processor core, an interrupt controller, a register, a task stack, and an interrupt program stack, the method comprising:

[0042] When the interrupt controller receives an interrupt request during the execution of a task by the processor core, the interrupt controller notifies the processor core of the occurrence of an interrupt;

[0043] In response to the interrupt, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, points the stack pointer to the interrupt program stack, and then the processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the interrupt request, wherein the task stack is a stack used by the task, the interrupt program stack is a stack used by the interrupt processing program, and when the processor core runs the task, the stack pointer points to the task stack;

[0044] After the processor core completes executing the interrupt processing flow, the processor core restores the value of the stack pointer to the saved value, saves the interrupt program stack address value, and restores the value of the register from the stack pointed to by the stack pointer.

[0045] According to an embodiment of the present disclosure, the interrupt program stack and the task stack occupy different stack spaces, and different tasks share the same interrupt program stack.

[0046] According to an embodiment of the present disclosure, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, and points the stack pointer to the interrupt program stack, including:

[0047] The processor core pushes the value of the register into the stack pointed to by the stack pointer, then saves the value of the stack pointer and points the stack pointer to the interrupt program stack.

[0048] According to an embodiment of the present disclosure, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, and points the stack pointer to the interrupt program stack, including:

[0049] The processor core saves the value of the stack pointer, points the stack pointer to the interrupt program stack, and then pushes the value of the register into the stack pointed to by the stack pointer.

[0050] According to an embodiment of the present disclosure, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, points the stack pointer to the interrupt program stack, and the processor core restores the value of the stack pointer to the saved value, saves the interrupt program stack address value, and restores the value of the register from the stack pointed to by the stack pointer, which is an operation implemented by hardware.

[0051] According to an embodiment of the present disclosure, the processor core uses the stack pointed to by the stack pointer to execute an operation in which the interrupt processing flow corresponding to the interrupt request is implemented by software.

[0052] According to an embodiment of the present disclosure, the registers include general registers and control and status registers;

[0053] The processor core pushes the register value into the stack pointed to by the stack pointer, including the processor core updating the control and status register value and then pushing the control and status register value and the general register value into the stack pointed to by the stack pointer.

[0054] According to an embodiment of the present disclosure, the method further includes:

[0055] When the interrupt controller receives another interrupt request during the execution of the interrupt processing procedure by the processor core, the interrupt controller notifies the processor core of the other interrupt request;

[0056] In response to the another interrupt, the processor core updates the value of the control and status register, and pushes the value of the general register and the value of the control and status register into the stack pointed to by the stack pointer;

[0057] The processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the other interrupt request;

[0058] After the processor core completes executing the interrupt processing flow corresponding to the other interrupt request, the processor core restores the values ​​of the general register and the control and status register from the stack pointed to by the stack pointer.

[0059] According to an embodiment of the present disclosure, the control and status registers include an instruction address register and a status register;

[0060] The processor core updates the value of the control and status register, including: setting the value of the instruction address register to the next instruction address of the current instruction executed by the processor core; setting the value of the status register to disable global interrupts;

[0061] After the processor core restores the values ​​of the control and status registers from the stack pointed to by the stack pointer, it continues to execute corresponding instructions according to the value of the instruction address register and sets the value of the status register to enable global interrupts.

[0062] According to an embodiment of the present disclosure, the control and status register further includes a cause register for storing an exception or interrupt cause.

[0063] According to an embodiment of the present disclosure, the general registers include caller-save registers and callee-save registers;

[0064] The processor core pushes the value of the general register into the stack pointed to by the stack pointer, comprising: the processor core pushes the value of the caller save register into the stack pointed to by the stack pointer;

[0065] The processor core restores the value of the general register from the stack pointed to by the stack pointer, including: the processor core restores the value of the caller save register from the stack pointed to by the stack pointer.

[0066] According to an embodiment of the present disclosure, the interrupt processing process executed by the processor core includes:

[0067] Save the values ​​of the callee-save registers;

[0068] Execute the interrupt handler;

[0069] Restore the values ​​of the saved callee-save registers.

[0070] According to an embodiment of the present disclosure, the processor system further includes an extended interrupt nesting control register, the extended interrupt nesting control register includes an interrupt nesting count field for recording an interrupt nesting state, and the method further includes:

[0071] When the processor core is not currently in an interrupt processing flow, the value of the interrupt nesting calculation field is set to 0, the value of the interrupt nesting count field is increased by 1 each time an interrupt is responded to, and the value of the interrupt nesting count field is decreased by 1 when the interrupt processing flow is exited.

[0072] According to an embodiment of the present disclosure, the method further includes:

[0073] When receiving an interrupt request, the processor core determines whether the processor core is in a task execution process or in an interrupt processing process according to the value of the interrupt nesting count field.

[0074] According to an embodiment of the present disclosure, the extended interrupt nesting control register also includes a maximum interrupt nesting level field, which stores the maximum number of nesting levels allowed by the interrupt nesting function. When the interrupt nesting level represented by the interrupt nesting count field reaches the value of the maximum interrupt nesting level field, the interrupt is not enabled.

[0075] According to an embodiment of the present disclosure, the extended interrupt nesting controller further includes an interrupt nesting water level field, and the interrupt nesting water level field stores the maximum interrupt nesting depth since the system is started.

[0076] According to an embodiment of the present disclosure, when the value of the interrupt nesting water level field is equal to the maximum interrupt nesting level field, it indicates that the system design needs to be optimized.

[0077] According to an embodiment of the present disclosure, the extended interrupt nesting control register further includes a pointer exchange switch field, and the method further includes: the processor core determines whether to change the stack pointed to by the stack pointer according to the pointer exchange switch field.

[0078] According to an embodiment of the present disclosure, the processor system further includes a stack address register for storing an interrupt program stack address value, and setting the stack pointer to point to the interrupt program stack includes setting the value of the stack pointer to the interrupt program stack address value stored in the stack address register.

[0079] The disclosed embodiment simplifies the interrupt response operation and improves the interrupt response speed. In addition, the disclosed embodiment implements the stack push operation of the caller save register and the control and status register through hardware, which greatly optimizes the interrupt response time. By pointing the stack pointer to the interrupt program stack operation, the interrupt program stack is used during the interrupt processing process, and only one stack space required for interrupt processing needs to be reserved, without reserving a stack space for interrupt operation for each task, which greatly saves hardware costs.

[0080] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0081] Other features, objectives and advantages of the present disclosure will become more apparent through the following detailed description of non-limiting embodiments in conjunction with the accompanying drawings. In the accompanying drawings:

[0082] Figure 1 A processor system according to an embodiment of the present disclosure is shown.

[0083] Figure 2 A schematic diagram showing the interrupt response flow of the standard CLIC is shown.

[0084] Figure 3 A schematic diagram of the nested interrupt response process of the standard CLIC is shown.

[0085] Figure 4 A schematic diagram of an interrupt response process according to an embodiment of the present disclosure is shown.

[0086] Figure 5 A schematic diagram of an extended interrupt nesting register is shown.

[0087] Figure 6 A flow chart of an interrupt control method according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0088] Hereinafter, exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings so that those skilled in the art can easily implement them. In addition, for the sake of clarity, parts not related to the description of the exemplary embodiments are omitted in the accompanying drawings.

[0089] In the present disclosure, it should be understood that terms such as "include" or "have" are intended to indicate the presence of features, numbers, steps, behaviors, components, parts, or a combination thereof disclosed in the present specification, and are not intended to exclude the possibility that one or more other features, numbers, steps, behaviors, components, parts, or a combination thereof exist or are added.

[0090] It should also be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0091] As mentioned above, the standard RISC-V interrupt controller solution has the disadvantages of requiring a large amount of context to save and restore instructions when supporting interrupt operations. For example, in an embedded multi-tasking system, each task has an independent stack space, and the context needs to be saved when interrupt processing. A general simple system also has at least 10 tasks, and the time of interruption is unpredictable. An interruption event may occur when any task is running, so each task stack must reserve the stack space required for processing interrupts when the task is running, which greatly increases the system hardware cost. Specifically, assuming that a simple interrupt occupies 256 bytes (there are 31 general registers, and stacking requires more than 120 bytes, so 256 bytes are generally not enough). Assuming that we have 10 tasks, then in the prior art, 256x10 bytes of stack space are required. Assuming that the nesting is five levels, a total of 256x10x5 bytes of stack space are required. However, using the present invention, only 256x5 bytes of stack space are required, so the present invention has significant savings in RAM space.

[0092] The present disclosure provides a processor system that can achieve a fast response to interrupts and save the context space used for processing interrupts. The processor system according to an embodiment of the present disclosure includes: a processor core, an interrupt controller, a register, a task stack, and an interrupt program stack, wherein: when the interrupt controller receives an interrupt request during the process of the processor core running a task, the interrupt controller notifies the processor core that an interrupt occurs; in response to the interrupt, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, and points the stack pointer to the interrupt program stack, and then the processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the interrupt request, wherein the task stack is the stack used by the task, the interrupt program stack is the stack used by the interrupt processing program, and when the processor core runs the task, the stack pointer points to the task stack; after the processor core completes the interrupt processing flow, the processor core restores the value of the stack pointer to the saved value, saves the interrupt program stack address value, and restores the value of the register from the stack pointed to by the stack pointer. According to the embodiment of the present disclosure, the interrupt program stack and the task stack occupy different stack spaces, and different tasks share the same interrupt program stack. Only one stack space required for interrupt processing needs to be reserved, which can significantly save system hardware costs.

[0093] Figure 1 An example of a processor system according to an embodiment of the present disclosure is shown.

[0094] like Figure 1As shown, according to an embodiment of the present disclosure, a processor system 100 includes a processor core 101, an interrupt controller 102, a register 103, a task stack 104, and an interrupt program stack 105, wherein the task stack 104 and the interrupt program stack 105 can be implemented in a random access memory RAM, and the interrupt program stack 105 is a space allocated in the RAM after the system is started, which is different from the task stack, and different tasks can use this interrupt program stack

[0095] According to an embodiment of the present disclosure, the processor core 101 uses a task stack 104 when running a task, and uses an interrupt program stack 105 when running an interrupt handler. When the processor core 101 runs a task, the stack pointer (sp) points to the task stack 104. According to an embodiment of the present disclosure, a task is a program or process other than an exception handler, such as an application program, an operating system process, etc.

[0096] When the interrupt controller 102 receives an interrupt request during the execution of a task by the processor core 101, the interrupt controller 102 notifies the processor core 101 that an interrupt has occurred. In response to the interrupt, the processor core 101 pushes the value of the register 103 into the stack pointed to by the stack pointer, i.e., into the task stack 104, saves the value of the stack pointer, and then points the stack pointer to the interrupt program stack 105. The processor system according to an embodiment of the present disclosure may include a stack address register, and after the system is started, the address of the interrupt program stack is configured in the stack address register. Pointing the stack pointer to the interrupt program stack 105 can be implemented by setting the value of the stack pointer to the address of the interrupt program stack saved in the stack address register. Further, the stack address register can also be used to save the value of the stack pointer. Then, the processor core 101 uses the stack pointed to by the stack pointer, i.e., uses the interrupt program stack 105 to execute the interrupt processing flow corresponding to the interrupt request. According to an embodiment of the present disclosure, the processor core 101 executes an interrupt processing flow corresponding to an interrupt request, which may include the processor core 101 executing an interrupt processing program corresponding to the interrupt request, and since the stack pointer points to the interrupt program stack 105, the processor core 101 uses the interrupt program stack 105 to execute the interrupt processing program. After the processor core 101 completes the interrupt processing flow, the processor core 101 saves the interrupt stack address value, for example, saves the current value of the stack pointer in a register, and then restores the value of the stack pointer to the saved value, that is, the stack pointer points to the task stack 104. Then, the processor core 101 restores the value of the register from the stack pointed to by the stack pointer, that is, restores the value of the register 102 pushed into the stack before entering the interrupt processing flow from the task stack 104, and continues to run the task.

[0097] According to the embodiments of the present disclosure, only one stack space required for interrupt processing needs to be reserved, and different tasks can use the same interrupt program stack space to process interrupts, which can significantly save system hardware costs.

[0098] According to an embodiment of the present disclosure, the processor core pushes the value of the register into the stack pointed to by the stack pointer, points the value of the stack pointer to the interrupt program, saves the original task stack address value, and the processor core points the stack pointer to the original task stack, saves the interrupt program stack address value, and restores the value of the register from the stack pointed to by the stack pointer, which is an operation implemented by hardware. According to an embodiment of the present disclosure, the processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the interrupt request, which is an operation implemented by software.

[0099] like Figure 1 As shown, according to an embodiment of the present disclosure, register 103 includes a general register and a control and status register, and the processor core pushes the value of the register into the stack pointed to by the stack pointer, including the processor core updating the value of the control and status register, and then pushing the value of the control and status register and the value of the general register into the stack pointed to by the stack pointer.

[0100] According to an embodiment of the present disclosure, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, and points the stack pointer to the interrupt program stack, including: the processor core pushes the value of the register into the stack pointed to by the stack pointer, then saves the value of the stack pointer, and points the stack pointer to the interrupt program stack, which is called the post-swap method. Alternatively, the processor core may first save the value of the stack pointer, point the stack pointer to the interrupt program stack, and then push the value of the register into the stack pointed to by the stack pointer, which is called the pre-swap method.

[0101] When the registers include general registers and control and status registers, the processor core first pushes the values ​​of the general registers and the values ​​of the control and status registers into the stack pointed to by the stack pointer, and then saves the value of the stack pointer and points the stack pointer to the interrupt program stack. Alternatively, the processor core may first save the value of the stack pointer and point the stack pointer to the interrupt program stack, and then push the values ​​of the general registers and the values ​​of the control and status registers into the stack pointed to by the stack pointer.

[0102] According to an embodiment of the present disclosure, the control and status registers include an instruction address register and a status register, and the processor core updates the values ​​of the control and status registers, including: setting the value of the instruction address register to the next instruction address of the current instruction executed by the processor core; setting the value of the status register to turn off global interrupts; after the processor core restores the values ​​of the control and status registers from the stack pointed to by the stack pointer, triggering the processor core to continue executing corresponding instructions according to the value of the instruction address register, and setting the value of the status register to allow global interrupts.

[0103] According to an embodiment of the present disclosure, the control and status register further includes a cause register for storing an exception or interrupt cause.

[0104] According to an embodiment of the present disclosure, the general register includes a caller-save register and a callee-save register, and the processor core pushes the value of the general register into the stack pointed to by the stack pointer, including: the processor core pushes the value of the caller-save register into the stack pointed to by the stack pointer, and the processor core restores the value of the general register from the stack pointed to by the stack pointer, including: the processor core restores the value of the caller-save register from the stack pointed to by the stack pointer.

[0105] According to an embodiment of the present disclosure, the interrupt handling process executed by the processor core includes: saving the value of the callee save register; executing the interrupt handling program; and restoring the saved value of the callee save register.

[0106] The processor system according to the embodiment of the present disclosure can be implemented by expanding the RISC-V standard. The existing RISC-V interrupt control mainly adopts two methods: a platform-level interrupt controller (PLIC) suitable for multi-core systems and a core-local interrupt controller (CLIC) suitable for single-core systems. PLIC is aimed at multi-core systems, and it distributes peripheral interrupts to different cores. Each core has an independent local interrupt controller CLINT for timer and soft interrupt management. However, single-core systems do not require interrupt distribution, and the distribution design of PLIC is redundant, which also increases the hardware cost. CLIC is aimed at single-core systems. It can choose to provide a separate trap entry address for each interrupt source, interrupt preemption (nesting) with adjustable priority threshold control, and support back-to-back interrupts to reduce context switching. However, the CLIC interrupt controller software still has the disadvantages of slow interrupt response speed and the need for a large amount of context to save and restore instructions when supporting nested interrupts or cumbersome operations.

[0107] According to the RISC-V standard, the control and status registers (CSRs) include the instruction address register mepc, the status register mstatus, and the cause register mcause. The general registers (GPRs) include the caller-save registers and the callee-save registers. The C function calling specification stipulates that when a function is called, the general register values ​​needed in the function are saved on the stack, and the general register values ​​need to be restored to their original values ​​before the function ends. The general registers include two groups of registers, Callee-save and Caller-save. When function A (caller) calls function B (callee), the Caller-save type is protected by the Caller, and the Callee-save type is protected by the Callee. The compiler tool will add a prologue before the C function (including the C interrupt service function) to save the Caller-save registers, and add an epilogue when exiting to restore the 16 groups of Caller-save registers. The prologue / epilogue are jointly responsible for the stack balance of saving / restoring hardware register values ​​in the function. For ordinary functions, adding prologue / epilogue is necessary and reasonable. However, adding a large number of prologue / epilogue to interrupt service functions will result in the interrupt being unable to respond quickly, and may even bring disadvantages such as difficulty in software development and low work efficiency in some real-time fields.

[0108] Figure 2 A schematic diagram of the interrupt response process of the standard CLIC is shown.

[0109] like Figure 2 As shown in the figure, when an interrupt event occurs during task execution, CLIC notifies the processor core of the interrupt. In response to the interrupt, the processor core updates mepc to save the address of the next instruction of the current instruction; updates mstatus, copies the MIE field of mstatus to the MPIE field of mstatus, and then clears the MIE field of mstatus, where the MIE field is the global interrupt switch, and clearing the MIE field means turning off the global interrupt; updates the mcause register. Then, the processor core calculates the interrupt entry address and jumps to the address to execute. The above process is completed by hardware.

[0110] Next, the software interrupt processing flow is entered. The processor core runs the software and pushes the general registers GPRs used in the interrupt processing function onto the stack first, that is, saves them to the memory area pointed to by the current stack pointer sp. Then, if interrupt nesting needs to be supported, the control and status registers CSRs such as mepc, mstatus, and mcause need to be pushed onto the stack, and then the interrupt is enabled, that is, the MIE field of the mstatus register is set. Then, the interrupt handler is executed, and then the interrupt is disabled again, and the previously pushed CSRs and GPRs registers are restored. The interrupt processing finally executes the mret instruction, which triggers the hardware to restore to the address saved by mepc and restore the value of the mstatus register, that is, use the MPIE field of mstatus to restore the MIE field, thereby enabling global interrupts. If interrupt nesting does not need to be supported, there is no need to save and restore CSRs in the above process, nor is there a need to enable and disable interrupts by software.

[0111] Figure 3 A schematic diagram of the nested interrupt response process of the standard CLIC is shown.

[0112] like Figure 3 As shown in the figure, when an interrupt event occurs during task execution, CLIC notifies the processor core of the interrupt. In response to the interrupt, the processor core updates mepc to save the address of the next instruction of the current instruction; updates mstatus, copies the MIE field of mstatus to the MPIE field of mstatus, and then clears the MIE field of mstatus, where the MIE field is the global interrupt switch, and clearing the MIE field means turning off the global interrupt; updates the mcause register. Then, CLIC calculates the interrupt entry address and jumps to the address to execute. The above process is completed by hardware.

[0113] Next, the software interrupt handling process is entered. The processor core runs the software and pushes the general registers GPRs used in the interrupt handling function onto the stack first, that is, saves them to the memory area pointed to by the current stack pointer sp. Then, the control and status registers CSRs such as mepc, mstatus, and mcause are pushed onto the stack, and then the interrupt is enabled, that is, the MIE field of the mstatus register is set. At this time, if another interrupt request is received, the processor core updates CSRs such as mepc, mstatus, and mcause in response to the other interrupt request, interrupts the entry address and jumps to the address for execution. The above process is completed by hardware. Next, the software interrupt handling process is entered. The processor core runs the software and pushes the general registers GPRs used in the interrupt handling function onto the stack first, that is, saves them to the memory area pointed to by the current stack pointer sp. Then push the control and status registers CSRs such as mepc, mstatus, and mcause, and then enable the interrupt, execute the interrupt handler, and then disable the interrupt again, restore the previously stacked CSRs and GPRs registers, and finally execute the mret instruction in the interrupt handler, which triggers the hardware to restore to the address saved by mepc and restore the value of the mstatus register, that is, use the MPIE field of mstatus to restore the MIE field, thereby enabling global interrupts. Then, the processor core disables the interrupt and restores the stacked CSRs and GPRs values, and continues to execute the program before the interrupt according to the mepc value, restoring the mstatus status.

[0114] It can be seen that the interrupt response process according to the standard CLIC requires frequent switching between the software process and the hardware process, which is cumbersome to operate and slow to respond. In addition, a stack space for interrupt operations needs to be reserved for each task, which results in high hardware costs.

[0115] The disclosed embodiment improves the standard CLIC, which can effectively increase the interrupt response speed and save stack space.

[0116] Figure 4 A schematic diagram of an interrupt response process according to an embodiment of the present disclosure is shown.

[0117] like Figure 4As shown, upon receiving an interrupt request, CLIC notifies the processor core of an interrupt. In response to the interrupt, the processor core updates the values ​​of the control and status registers, including: setting the value of the instruction address register to the next instruction address of the current instruction executed by the processor core, setting the value of the status register to disable the global interrupt, and setting the value of the cause register to save the exception or interrupt cause, wherein the instruction address register may be the mepc register, the status register may be the mstatus register, and the cause register may be the mcause register. Then, the processor core pushes the values ​​of the control and status registers into the stack pointed to by the stack pointer.

[0118] The processor core pushes the value of the general register into the stack pointed to by the stack pointer, including pushing the value of the caller-save register into the stack pointed to by the stack pointer. For example, the caller-save register may be a caller-save register.

[0119] The processor core determines whether the interrupt request is received during the execution of a task or during the execution of an interrupt handling procedure.

[0120] The embodiment of the present disclosure uses an extended interrupt nesting control register mxntctrl to record the interrupt nesting state. The processor core can determine whether the interrupt request is received during the execution of a task or during the execution of an interrupt processing flow according to the value of the interrupt nesting control register mxntctrl.

[0121] Figure 5 FIG. 1 shows a schematic diagram of an extended interrupt nesting register. Figure 5 As shown, the extended interrupt nesting control register mxntctrl may include an interrupt nesting count field mncnt, which is used to record the interrupt nesting status. For example, if the mncnt value is 0, it means that the current system is not in the interrupt processing flow. The mncnt value increases by 1 each time an interrupt is responded to, and decreases by 1 when the interrupt processing flow is exited.

[0122] The extended interrupt nesting control register mxntctrl may also include a maximum interrupt nesting level field mnmax, which stores the maximum number of nesting levels allowed by the interrupt nesting function. When the interrupt nesting level represented by the interrupt nesting count field reaches the value of the maximum interrupt nesting level field, the interrupt is not enabled. The maximum interrupt nesting level is configurable to avoid serious problems such as stack overflow caused by excessive interrupt nesting, which in turn causes the entire system to crash. The mnmax field can effectively avoid the possible stack overflow problem caused by too deep system interrupt nesting, thereby improving the stability of the system.

[0123] The extended interrupt nesting control register mxntctrl may also include an interrupt nesting water level field mnwl, which stores the maximum interrupt nesting depth since the system was started. This field can help software developers debug. If mnwl reaches mnmax after a long period of testing, it means that there is a risk that high-priority interrupts cannot be responded to in time, and the product may have software and hardware design defects such as the software interrupt function is too large / the execution time is too long.

[0124] According to an embodiment of the present disclosure, the extended interrupt nesting control register mxntctrl may further include a reserved field reserve and a pointer exchange switch field msrcsp, and the value of the pointer exchange switch field msrcsp indicates whether to change the stack pointed to by the stack pointer. According to an embodiment of the present disclosure, when the value of the interrupt nesting count field mncnt is 0, the pointer exchange switch field msrcsp is set to 1, indicating that the stack pointer should point to the interrupt program stack, and when the value of the interrupt nesting count field mncnt is not 0, the pointer exchange switch field msrcsp is set to 0, indicating that the stack pointed to by the stack pointer is not changed.

[0125] like Figure 4 As shown, the processor core determines whether the interrupt request is received during the task execution or during the interrupt processing flow according to the interrupt nesting count field mncnt of the extended interrupt nesting control register mxntctrl. If the value of the interrupt nesting count field mncnt is 0, the interrupt request is received during the task execution, otherwise the interrupt request is received during the interrupt processing flow.

[0126] If the value of the interrupt nesting count field mncnt is 0, indicating that the interrupt request is received during the execution of the task, the processor core points the stack pointer to the interrupt program stack, otherwise the stack pointed to by the stack pointer is not changed.

[0127] Alternatively, the processor core can determine whether to change the pointer pointing according to the value of the pointer exchange switch field msrcsp. If the value of the pointer exchange switch field msrcsp is 1, the pointer pointing is changed, otherwise the pointer pointing is not changed.

[0128] According to an embodiment of the present disclosure, the mscratch register in the RISC-V standard can be used as a stack address register to implement stack pointer switching backup. The mscratch register is used to temporarily store word-sized data in the RISC-V standard, and there is no provision for what data to be temporarily stored, so it can be used as a pointer switching backup to save hardware design costs. After the system is started, the value of the mscratch register is configured to be the memory address of the interrupt program stack. When processing an interrupt received during task execution, the value of the stack pointer is set to the value of the mscratch register, thereby using the interrupt program stack to execute the interrupt processing flow. The mscratch register can also be used to save the task stack address value pointed to by the stack pointer.

[0129] The processor core adds 1 to the value of the interrupt nesting count field mncnt, and then compares it with the value of mnmax. If it is less than mnmax, the interrupt is enabled, the interrupt entry address is obtained, and execution is jumped to the address. If it is equal to mnmax, the interrupt is not enabled and will be enabled again after the current interrupt is processed.

[0130] The above operations are all completed by hardware. Then, the processor core runs the interrupt processing flow executed by the software.

[0131] like Figure 4 As shown, the processor core saves the value of the callee saved register. In this embodiment, the value of the callee saved register can be pushed into the interrupt program stack. In the C function, the compiler automatically saves the value of the callee saved register used in the function. The value of the status register is set to enable global interrupts. After enabling, nested interrupts can be enabled, that is, other interrupt requests can be responded to during the interrupt processing process.

[0132] The processor core then runs the interrupt handler corresponding to the current interrupt request.

[0133] After the interrupt handler is finished running, the processor core restores the value of the callee's saved register. In this embodiment, the stack pointed to by the stack pointer, that is, the interrupt program stack, takes out the value of the callee's saved register and sets the value of the status register to disable the global interrupt.

[0134] Next, the hardware executes the interrupt exit process. The processor core decrements the value of the interrupt nesting count field in the extended interrupt nesting control register by 1, and then checks the interrupt nesting count field in the extended interrupt nesting control register. If the interrupt nesting count field is 0, it means that the processor core is not currently in the interrupt processing process. At this time, the stack pointer points to the interrupt program stack, otherwise the stack pointed to by the stack pointer is not changed.

[0135] The processor core then restores the values ​​of the general purpose registers and the control and status registers from the stack pointed to by the stack pointer.

[0136] The interrupt controller triggers the processor core to continue executing the corresponding instruction according to the value of the instruction address register. In this embodiment, it executes the mret instruction of RISC-V, triggering the hardware to resume execution at the address saved by mepc.

[0137] The processor core sets the value of the status register to enable global interrupts, for example, using the value of the MPIE field of mstatus to restore the value of the MIE field.

[0138] It can be seen that the embodiment of the present disclosure unifies the interrupt response process during task execution and during the interrupt processing process. The difference between the two is whether the stack pointed to by the stack pointer is changed. Therefore, the embodiment of the present disclosure simplifies the operation of the interrupt response and improves the interrupt response speed. In addition, the embodiment of the present disclosure implements the push operation of the caller save register and the control and status register through hardware, which greatly optimizes the interrupt response time. By changing the stack pointed to by the stack pointer, the interrupt program stack is used during the interrupt processing process. Only one stack space required for interrupt processing needs to be reserved, and there is no need to reserve a stack space for interrupt operations for each task, which greatly saves hardware costs.

[0139] As described above, the processor core pushes the value of the register into the stack pointed to by the stack pointer, then saves the value of the stack pointer, and points the stack pointer to the interrupt program stack. This practice is called the post-exchange method. Alternatively, the processor core can save the value of the stack pointer, point the stack pointer to the interrupt program stack, and then push the value of the register into the stack pointed to by the stack pointer. This practice is called the pre-exchange method. In a multi-task system, each task has its own task stack space. Considering the task switching scenario, if a task switch is encountered during the interrupt processing process, when the post-exchange method is used, the caller save register and the state control register in the general register have been saved in the stack space of the original task A. When switching to the new task B, it is only necessary to save the callee save register in the general register to the stack space of task A. When the pre-exchange method is used, the caller save register and the state control register in the general register are saved in the interrupt program stack before switching the task, so before switching, the caller save register, the callee save register and the state control register in the general register need to be saved to the stack space of task A. Therefore, the post-exchange method is more conducive to realizing a simpler task switching process.

[0140] The embodiment of the present disclosure also provides a chip, comprising the processor system as described above.

[0141] An embodiment of the present disclosure further provides an electronic device, comprising the processor system as described above or the chip as described above.

[0142] Figure 6 A flowchart of an interrupt control method according to an embodiment of the present disclosure is shown, and the method is applied to a processor system including a processor core, an interrupt controller, a register, a task stack, and an interrupt program stack.

[0143] like Figure 6 As shown, the interrupt control method according to the embodiment of the present disclosure includes steps S101-S103.

[0144] In step S101 , when an interrupt controller receives an interrupt request during the execution of a task by the processor core, the interrupt controller notifies the processor core of an interrupt occurrence.

[0145] In step S102, in response to the interrupt, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, points the stack pointer to the interrupt program stack, and then, the processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the interrupt request, wherein the task stack is the stack used by the task, and the interrupt program stack is the stack used by the interrupt handler, and when the processor core runs the task, the stack pointer points to the task stack.

[0146] In step S103, after the processor core completes the interrupt processing flow, the processor core restores the value of the stack pointer to the saved value, saves the interrupt program stack address value, and restores the value of the register from the stack pointed to by the stack pointer.

[0147] According to an embodiment of the present disclosure, the interrupt program stack and the task stack occupy different stack spaces, and different tasks share the same interrupt program stack.

[0148] According to an embodiment of the present disclosure, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, and points the stack pointer to the interrupt program stack, including: the processor core pushes the value of the register into the stack pointed to by the stack pointer, then saves the value of the stack pointer, and points the stack pointer to the interrupt program stack.

[0149] According to an embodiment of the present disclosure, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, and points the stack pointer to the interrupt program stack, including: the processor core saves the value of the stack pointer, points the stack pointer to the interrupt program stack, and then pushes the value of the register into the stack pointed to by the stack pointer.

[0150] According to an embodiment of the present disclosure, the processor core pushes the value of the register into the stack pointed to by the stack pointer, saves the value of the stack pointer, points the stack pointer to the interrupt program stack, and the processor core restores the value of the stack pointer to the saved value, saves the interrupt program stack address value, and restores the value of the register from the stack pointed to by the stack pointer, which is an operation implemented by hardware.

[0151] According to an embodiment of the present disclosure, the processor core uses the stack pointed to by the stack pointer to execute an operation in which the interrupt processing flow corresponding to the interrupt request is implemented by software.

[0152] According to an embodiment of the present disclosure, the registers include general registers and control and status registers; the processor core pushes the values ​​of the registers into the stack pointed to by the stack pointer, including the processor core updating the values ​​of the control and status registers, and then pushing the values ​​of the control and status registers and the general registers into the stack pointed to by the stack pointer.

[0153] According to an embodiment of the present disclosure, the method also includes: when the interrupt controller receives another interrupt request during the execution of the interrupt processing flow by the processor core, the interrupt controller notifies the processor core of the other interrupt request; in response to the other interrupt, the processor core updates the value of the control and status register, and pushes the value of the general register and the value of the control and status register into the stack pointed to by the stack pointer; the processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the other interrupt request; after the processor core completes the execution of the interrupt processing flow corresponding to the other interrupt request, the processor core restores the value of the general register and the control and status register from the stack pointed to by the stack pointer.

[0154] According to an embodiment of the present disclosure, the control and status registers include an instruction address register and a status register; the processor core updates the values ​​of the control and status registers, including: setting the value of the instruction address register to the next instruction address of the current instruction executed by the processor core; setting the value of the status register to turn off global interrupts; after the processor core restores the values ​​of the control and status registers from the stack pointed to by the stack pointer, it continues to execute corresponding instructions according to the value of the instruction address register, and sets the value of the status register to enable global interrupts.

[0155] According to an embodiment of the present disclosure, the control and status register further includes a cause register for storing an exception or interrupt cause.

[0156] According to an embodiment of the present disclosure, the general registers include caller-save registers and callee-save registers; the processor core pushes the value of the general register into the stack pointed to by the stack pointer, including: the processor core pushes the value of the caller-save register into the stack pointed to by the stack pointer; the processor core restores the value of the general register from the stack pointed to by the stack pointer, including: the processor core restores the value of the caller-save register from the stack pointed to by the stack pointer.

[0157] According to an embodiment of the present disclosure, the interrupt handling process executed by the processor core includes: saving the value of the callee save register; executing the interrupt handling program; and restoring the saved value of the callee save register.

[0158] According to an embodiment of the present disclosure, the processor system further includes an extended interrupt nesting control register, the extended interrupt nesting control register includes an interrupt nesting count field for recording an interrupt nesting state, and the method further includes:

[0159] When the processor core is not currently in an interrupt processing flow, the value of the interrupt nesting calculation field is set to 0, the value of the interrupt nesting count field is increased by 1 each time an interrupt is responded to, and the value of the interrupt nesting count field is decreased by 1 when the interrupt processing flow is exited.

[0160] According to an embodiment of the present disclosure, the method further includes: upon receiving an interrupt request, the processor core determines, according to the value of the interrupt nesting count field, whether the processor core is in a task execution process or in an interrupt processing process.

[0161] According to an embodiment of the present disclosure, the extended interrupt nesting control register also includes a maximum interrupt nesting level field, which stores the maximum number of nesting levels allowed by the interrupt nesting function. When the interrupt nesting level represented by the interrupt nesting count field reaches the value of the maximum interrupt nesting level field, the interrupt is not enabled.

[0162] According to an embodiment of the present disclosure, the extended interrupt nesting controller further includes an interrupt nesting water level field, and the interrupt nesting water level field stores the maximum interrupt nesting depth since the system is started.

[0163] According to an embodiment of the present disclosure, when the value of the interrupt nesting water level field is equal to the maximum interrupt nesting level field, it indicates that the system design needs to be optimized.

[0164] According to an embodiment of the present disclosure, the extended interrupt nesting control register further includes a pointer exchange switch field, and the method further includes: the processor core determines whether the stack pointed to by the stack pointer should be changed according to the pointer exchange switch field.

[0165] The method according to the embodiment of the present disclosure can be implemented by expanding the RISC-V standard. According to the RISC-V standard, the control and status registers (CSRs) include the instruction address register mepc, the status register mstatus, and the cause register mcause, and the general registers (GPRs) include the caller save register (Caller-save) and the callee save register (Callee-save). According to the embodiment of the present disclosure, the mscratch register in the RISC-V standard can be used as a stack pointer switching backup. The mscratch register is used to temporarily store a word-sized data in the RISC-V standard, and there is no specific provision for what data is temporarily stored, so it can be used as a pointer switching backup to save hardware design costs. After the system is started, the value of the mscratch register is configured to be the memory address of the interrupt program stack. When processing an interrupt received during task execution, the value of the stack pointer is set to the value of the mscratch register, so that the interrupt program stack is used to execute the interrupt processing flow. The mscratch register can also be used to save the task stack address value pointed to by the stack pointer.

[0166] Each step in the accompanying drawings may represent a portion of a processor system, chip, or program segment that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the steps may also occur in an order different from that noted in the accompanying drawings. For example, two steps may actually be performed substantially in parallel, and they may sometimes be performed in reverse order, depending on the functions involved.

[0167] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present disclosure is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other.

Claims

1. A processor system based on the RISC-V standard, characterized in that: include: Processor core, interrupt controller, caller save register, callee save register, control and status register, mscratch register, extended interrupt nesting control register, task stack, interrupt program stack, including: When the interrupt controller receives an interrupt request during the execution of a task by the processor core, the interrupt controller notifies the processor core of the occurrence of an interrupt; In response to the interrupt, the processor core updates the value of the control and status register through hardware-implemented operations, pushes the value of the caller save register and the value of the control and status register into the stack pointed to by the stack pointer, saves the value of the stack pointer in the mscratch register, and points the stack pointer to the interrupt program stack. Then, the processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the interrupt request through software-implemented operations, including: saving the value of the callee save register; executing the interrupt processing program; restoring the saved value of the callee save register, wherein the task stack is the stack used by the task, and the interrupt program stack is the stack used by the interrupt processing program. When the processor core runs the task, the stack pointer points to the task stack; After the processor core completes the interrupt handling process, the processor core restores the value of the stack pointer to the value saved in the mscratch register through hardware-implemented operations, saves the interrupt program stack address value in the mscratch register, and restores the value of the caller save register and the value of the control and status register from the stack pointed to by the stack pointer; The extended interrupt nesting control register includes an interrupt nesting count field and a pointer exchange switch field. The processor core determines whether to change the stack pointed to by the stack pointer according to the pointer exchange switch field. When the interrupt nesting count field value is 0, the pointer exchange switch field is set to indicate that the stack pointed to by the stack pointer should be changed. When the interrupt nesting count field value is not 0, the pointer exchange switch field is set to indicate that the stack pointed to by the stack pointer should not be changed.

2. The processor system according to claim 1, wherein: The interrupt program stack and the task stack occupy different stack spaces, and different tasks share the same interrupt program stack.

3. The processor system according to claim 1, wherein: The step of pushing the value of the caller save register and the value of the control and status register into the stack pointed to by the stack pointer, saving the value of the stack pointer in the mscratch register, and pointing the stack pointer to the interrupt program stack comprises: The value of the caller save register and the value of the control and status register are pushed into the stack pointed to by the stack pointer, and then the value of the stack pointer is saved in the mscratch register, and the stack pointer is pointed to the interrupt program stack.

4. The processor system according to claim 1, wherein: The step of pushing the value of the caller save register and the value of the control and status register into the stack pointed to by the stack pointer, saving the value of the stack pointer in the mscratch register, and pointing the stack pointer to the interrupt program stack comprises: The value of the stack pointer is saved in the mscratch register, the stack pointer is pointed to the interrupt program stack, and then the value of the caller save register and the value of the control and status register are pushed into the stack pointed to by the stack pointer.

5. The processor system of claim 1 , wherein: When the interrupt controller receives another interrupt request during the execution of the interrupt processing procedure by the processor core, the interrupt controller notifies the processor core of the other interrupt request; In response to the another interrupt, the processor core updates the value of the control and status register, and pushes the value of the caller save register and the value of the control and status register into the stack pointed to by the stack pointer; The processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the other interrupt request; After the processor core completes executing the interrupt handling process corresponding to the other interrupt request, the processor core restores the values ​​of the caller save register and the control and status register from the stack pointed to by the stack pointer.

6. The processor system of claim 1, wherein: The control and status registers include an instruction address register and a status register; The processor core updates the value of the control and status register, including: setting the value of the instruction address register to the next instruction address of the current instruction executed by the processor core; setting the value of the status register to disable global interrupts; After the processor core restores the values ​​of the control and status registers from the stack pointed to by the stack pointer, it continues to execute corresponding instructions according to the value of the instruction address register and sets the value of the status register to enable global interrupts.

7. The processor system of claim 1, wherein: The control and status register also includes a cause register for storing the cause of the exception or interruption. 8 . The processor system according to claim 1 , wherein the interrupt nesting count field is used to record an interrupt nesting state.

9. The processor system of claim 8, wherein: When receiving an interrupt request, the processor core determines whether the processor core is in a task execution process or in an interrupt processing process according to the value of the interrupt nesting count field.

10. The processor system of claim 1, wherein: The extended interrupt nesting control register also includes a maximum interrupt nesting level field, which stores the maximum number of nesting levels allowed by the interrupt nesting function. When the interrupt nesting level represented by the interrupt nesting count field reaches the value of the maximum interrupt nesting level field, the interrupt is not enabled.

11. The processor system of claim 1, wherein: The extended interrupt nesting controller further includes an interrupt nesting water level field, and the interrupt nesting water level field stores the maximum interrupt nesting depth since the system is started.

12. The processor system of claim 11, wherein: When the value of the interrupt nesting water level field is equal to the maximum interrupt nesting level field, it indicates that the system design needs to be optimized.

13. The processor system of claim 1, wherein: The mscratch register is used to store the interrupt program stack address value, and setting the stack pointer to point to the interrupt program stack includes setting the value of the stack pointer to the interrupt program stack address value stored in the mscratch register.

14. A chip comprising the processor system according to any one of claims 1-13.

15. An electronic device, comprising the processor system according to any one of claims 1 to 13, or comprising the chip according to claim 14.

16. An interrupt control method, characterized in that: The method is applied to a processor system based on the RISC-V standard including a processor core, an interrupt controller, a caller save register, a callee save register, a control and status register, an mscratch register, an extended interrupt nesting control register, a task stack, and an interrupt program stack, and the method includes: When the interrupt controller receives an interrupt request during the execution of a task by the processor core, the interrupt controller notifies the processor core of the occurrence of an interrupt; In response to the interrupt, the processor core updates the value of the control and status register through hardware-implemented operations, pushes the value of the caller save register and the value of the control and status register into the stack pointed to by the stack pointer, saves the value of the stack pointer in the mscratch register, and points the stack pointer to the interrupt program stack. Then, the processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the interrupt request through software-implemented operations, including: saving the value of the callee save register; executing the interrupt processing program; restoring the saved value of the callee save register, wherein the task stack is the stack used by the task, and the interrupt program stack is the stack used by the interrupt processing program. When the processor core runs the task, the stack pointer points to the task stack; After the processor core completes the interrupt handling process, the processor core restores the value of the stack pointer to the value saved in the mscratch register through hardware-implemented operations, saves the interrupt program stack address value in the mscratch register, and restores the value of the caller save register and the value of the control and status register from the stack pointed to by the stack pointer; The extended interrupt nesting control register includes an interrupt nesting count field and a pointer exchange switch field. The processor core determines whether to change the stack pointed to by the stack pointer according to the pointer exchange switch field. When the interrupt nesting count field value is 0, the pointer exchange switch field is set to indicate that the stack pointed to by the stack pointer should be changed. When the interrupt nesting count field value is not 0, the pointer exchange switch field is set to indicate that the stack pointed to by the stack pointer should not be changed.

17. The method according to claim 16, wherein: The interrupt program stack and the task stack occupy different stack spaces, and different tasks share the same interrupt program stack.

18. The method according to claim 16, wherein: The step of pushing the value of the caller save register and the value of the control and status register into the stack pointed to by the stack pointer, saving the value of the stack pointer in the mscratch register, and pointing the stack pointer to the interrupt program stack comprises: The value of the caller save register and the value of the control and status register are pushed into the stack pointed to by the stack pointer, and then the value of the stack pointer is saved in the mscratch register, and the stack pointer is pointed to the interrupt program stack.

19. The method according to claim 16, wherein: The step of pushing the value of the caller save register and the value of the control and status register into the stack pointed to by the stack pointer, saving the value of the stack pointer in the mscratch register, and pointing the stack pointer to the interrupt program stack comprises: The value of the stack pointer is saved in the mscratch register, the stack pointer is pointed to the interrupt program stack, and then the value of the caller save register and the value of the control and status register are pushed into the stack pointed to by the stack pointer.

20. The method of claim 16, further comprising: When the interrupt controller receives another interrupt request during the execution of the interrupt processing procedure by the processor core, the interrupt controller notifies the processor core of the other interrupt request; In response to the another interrupt, the processor core updates the value of the control and status register, and pushes the value of the caller save register and the value of the control and status register into the stack pointed to by the stack pointer; The processor core uses the stack pointed to by the stack pointer to execute the interrupt processing flow corresponding to the other interrupt request; After the processor core completes executing the interrupt handling process corresponding to the other interrupt request, the processor core restores the values ​​of the caller save register and the control and status register from the stack pointed to by the stack pointer.

21. The method of claim 16, wherein: The control and status registers include an instruction address register and a status register; The processor core updates the value of the control and status register, including: setting the value of the instruction address register to the next instruction address of the current instruction executed by the processor core; setting the value of the status register to disable global interrupts; After the processor core restores the values ​​of the control and status registers from the stack pointed to by the stack pointer, it continues to execute corresponding instructions according to the value of the instruction address register and sets the value of the status register to enable global interrupts.

22. The method according to claim 16, wherein: The control and status register also includes a cause register for storing the cause of the exception or interruption.

23. The method according to claim 16, wherein the interrupt nesting count field is used to record the interrupt nesting state, the method further comprising: When the processor core is not currently in an interrupt processing flow, the value of the interrupt nesting calculation field is set to 0, the value of the interrupt nesting count field is increased by 1 each time an interrupt is responded to, and the value of the interrupt nesting count field is decreased by 1 when the interrupt processing flow is exited.

24. The method according to claim 23, further comprising: When receiving an interrupt request, the processor core determines whether the processor core is in a task execution process or in an interrupt processing process according to the value of the interrupt nesting count field.

25. The method of claim 16, wherein: The extended interrupt nesting control register also includes a maximum interrupt nesting level field, which stores the maximum number of nesting levels allowed by the interrupt nesting function. When the interrupt nesting level represented by the interrupt nesting count field reaches the value of the maximum interrupt nesting level field, the interrupt is not enabled.

26. The method of claim 16, wherein: The extended interrupt nesting controller further includes an interrupt nesting water level field, and the interrupt nesting water level field stores the maximum interrupt nesting depth since the system is started.

27. The method according to claim 26, wherein: When the value of the interrupt nesting water level field is equal to the maximum interrupt nesting level field, it indicates that the system design needs to be optimized.

28. The method of claim 16, wherein: The mscratch register is used to store the interrupt program stack address value, and setting the stack pointer to point to the interrupt program stack includes setting the value of the stack pointer to the interrupt program stack address value stored in the mscratch register.

Citation Information

Patent Citations

  • Independent interrupt stack-based method for preemptive scheduling during interrupt exiting

    CN102012842A

  • Interrupt processing method and device

    CN103778009A

  • Memory managing system and task controller in multitask system

    CN1584840A

  • Interrupt system for RISC-v architecture

    US20210034558A1