MCU Chip Patching via SVC Interrupt Long Address Jump
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Current patch technology for MCU chips is limited by the ability of jump instructions to only perform short address jumps, restricting the range of addressable memory locations and increasing hardware requirements and costs to support more patches.
Innovation Solution
Implementing a method that uses interrupt instructions, specifically the SVC interrupt, to enable long address jumps by storing correspondence relationships between function addresses and interrupt instructions in a hardware register, allowing for patching without the limitations of traditional jump instructions.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of operation
If jump instructions are used for patching, then the implementation is simple, but the address jump range is limited and cannot achieve long address jumps
Solution Approach 1:
The patent introduces an intermediary mechanism (interrupt service routine with return address modification) between the original program execution and the patch function. Instead of directly jumping to the patch function, the system uses an interrupt that redirects execution flow, allowing the patch function to be located anywhere in the memory space while maintaining simple implementation through standard interrupt handling mechanisms.
2Device complexity
If traditional jump instructions are used, then the patching mechanism is straightforward, but strict requirements are imposed on storage location of replacement function
Solution Approach 1:
The patent segments the patching mechanism into two independent parts: the interrupt service routine (which handles the redirection) and the patch function (which contains the actual repair code). This segmentation allows the patch function to be placed independently in memory without being constrained by the interrupt handler's location, providing flexible memory layout design.
3Adaptability or versatility
If long address jumps are enabled, then memory layout flexibility improves, but hardware requirements and costs increase
Solution Approach 1:
The system uses existing interrupt handling hardware and mechanisms to achieve long address jumps, rather than requiring specialized long-jump hardware. The interrupt service routine automatically captures the return address and modifies it to point to the patch function, utilizing self-service capabilities of the processor to eliminate the need for additional hardware components.
Data Source
Figure 1~2
Figure 3~4
Figure 5~7
AI summary
An embodiment of the present application discloses a method for patching a chip and a chip, which can perform transfer through an interrupt instruction to obtain a function address of a patch function, so as to replace a function that needs to be replaced. This method does not need to carry address information of the patch function in the instruction, and thus can realize a long address jump without limitation of a jump address range. The chip includes a first program, and the method includes: when a function that needs to be replaced in the first program is run, executing an interrupt service routine according to a pre-stored correspondence relationship between an address of the function that needs to be replaced and an interrupt instruction, where the interrupt service routine is a service routine scheduled by an interrupt instruction corresponding to the function that needs to be replaced, and a return address of the interrupt service routine is an address of a patch function of the function that needs to be replaced (S410); and running the patch function according to the address of the patch function, to perform patch processing on the first program (S420).