Memory patch circuit and system

The memory patch circuit and system efficiently patch non-volatile and volatile memories by dynamically injecting assembly instructions, addressing limitations of existing systems with reduced silicon area and latency, and flexible patching capabilities.

DE102015222096B4Active Publication Date: 2024-11-21RENESAS DESIGN NETHERLANDS BV
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
DE102015222096
Authority / Receiving Office
DE · DE
Patent Type
Patents
Current Assignee / Owner
Priority Date
2015-08-06
Filing Date
2015-11-10
Publication Date
2024-11-21
Estimated Expiration
2035-11-10

AI Technical Summary

Technical Problem

Existing memory patching systems for non-volatile memory (NVM) and volatile memory face limitations such as increased silicon area requirements, limited patching capabilities, and inefficiencies due to dependence on instruction set architecture (ISA), especially when addressing software or hardware faults post-manufacturing.

Method used

A memory patch circuit and system that includes a code generation unit, address memory, and a distance calculation unit to dynamically inject hard-coded assembly instructions, allowing seamless redirection of execution flow while minimizing additional silicon area and latency.

Benefits of technology

Enables efficient patching of multiple memory locations with minimal additional area and latency, supporting transparent and flexible patching of functions, data, or instruction sequences without altering the processing unit's interface.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 00000000_0000_ABST
    Figure 00000000_0000_ABST
Patent Text Reader

Abstract

A patching system and a patching circuit create a type of patch entry that can replace multiple sequential memory locations with hard-coded and dynamically configured assembly instructions, thus injecting a small piece of code. The operation of the injected code can be for any purpose, but it can be used as an example to seamlessly redirect the execution flow of a processing unit.
Need to check novelty before this filing date? Find Prior Art

Description

AREA

[0001] The present disclosure relates to a memory patch circuit and system. BACKGROUND

[0002] Non-volatile memory (NVM) is known to be used in processors, computers, and other types of devices where information must be stored persistently (not erased by a power cycle). There are several types of NVM, including read-only memory (ROM), such as programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or one-time programmable (OTP) NVM, to name a few examples.

[0003] The majority of systems on a chip (SoC) that contain a processing unit also include some type of ROM to store software functions or data tables. A stored collection of functions typically implements a software library that can be used by an application running on the processing unit. Storing a library in ROM reduces the silicon area required to store specific software code on the chip, thus reducing the final cost of the SoC product.

[0004] Data stored in ROM or other types of NVM cannot be easily modified. However, there are cases where it is desirable to modify the contents of this type of memory. For example, there are cases where software functions stored in ROM do not behave as expected. This can be very serious if a bug is discovered only after the SoC is manufactured. Because the information stored in ROM is mask-programmed, it is not possible to modify and repair these functions.

[0005] As a solution to this, it has been proposed to create ROM patch mechanisms that prevent the processor from executing faulty code in the ROM and provide corrected code to be executed instead.

[0006] There are software-based patching mechanisms that utilize specific software structures to provide the patching feature. They typically select a very limited number of functions located in ROM that are suspected of being vulnerable to tampering or that may be critical to system operation. They can then replace all calls to this limited number of functions with code that retrieves the final base address from a table located in RAM. Another solution is to replace all calls to these functions with a call to "hook" functions, one for each function to be patched, that reside in RAM and contain only one call to the final function body.If a bug is detected in these functions after the SoC is manufactured, the table of function pointers or alternative hook functions could be modified, thus redirecting to the corrected function located in RAM and replacing the one in ROM. Other similar implementations can also be used, but a disadvantage of software-based solutions is that they require more code memory space, consume more execution cycles (consequently reducing system response time), and provide the option to patch only a limited number of functions.

[0007] A hardware-based patching system has been disclosed in US 2014 / 0 289 455 A1, in which an address register stores an address pointing to a word located in ROM corresponding to a word that needs to be patched, storing either instructions or data. Another data register stores a single word of data or a single instruction to be used in place of the faulty data stored in ROM. The hardware tracks all transactions on the system bus; if there is a memory transaction pointing to the address programmed into the address register, the patch circuit replaces the data on the bus with the word programmed into the data register. Patching directly from the data register means that the execution latency of the processing unit is not affected by the patching.However, this system requires a lot of additional area on the circuit substrate and only allows a limited number of memory locations to be patched. Furthermore, when patching a function, the efficiency of this circuit is highly dependent on the instruction set architecture (ISA) of the given processing unit.

[0008] US 2008 / 0 112 205 A1 describes a programmable system design and in particular a patching for program codes in a read-only memory (ROM).

[0009] US 2014 / 0 289 455 A1 describes a system for patching a memory with the memory patching circuit and a method for programming the patching circuit.

[0010] JP 2001 - 290 638 A describes a computer system and an instruction exchange method that shortens the time required for instruction exchange processing and reduces the processing load of a CPU.

[0011] JP 2002 - 007 113 A describes a rewriting device including a microprocessor having a function for recovering a defect of a flash memory and a host computer for generating a program to be executed by the microprocessor. SUMMARY

[0012] It would be advantageous to have an improved memory patching circuit for patching a memory for non-volatile memory and also for volatile memory, and an associated system.

[0013] According to a first aspect of the disclosure, a memory patch circuit is provided, comprising: a code generation unit coupled to a memory via an input data bus and coupled to a processor via an output data bus; an address memory storing an address of a location in the memory to be patched; a distance calculation unit configured to: receive a first address from an address bus connecting the memory and the processor, receive a second address from the address memory, compare the first and second addresses, and output a distance indication based on the comparison; wherein the code generation unit is configured to receive the distance indication and, based on the distance indication, either pass the data from the input data bus to the output data bus or inject code into the output data bus.

[0014] Optionally, the code generation unit is arranged to receive the address from the address memory to determine the location for the injected code.

[0015] Optionally, the distance calculation means is arranged to subtract the first address from the second address and provide a signed value as the distance indication.

[0016] Optionally, the distance calculation unit comprises a plurality of subtractors, each coupled to the address bus and arranged to subtract successive offsets from the first address.

[0017] Optionally, the distance calculation unit comprises several comparators, each coupled to one of the subtractors, and the outputs of the comparators provide the distance information.

[0018] Optionally, the distance calculation unit comprises a plurality of adders, each coupled to the address memory and arranged to add successive offsets to the second address.

[0019] Optionally, the distance calculation unit comprises several comparators, each coupled to one of the adders, and the outputs of the comparators provide the distance information.

[0020] Optionally, the distance specification indicates whether the logical distance between the first address and the second address is within a specified range.

[0021] Optionally, the distance specification represents the distance if the logical distance between the first address and the second address is within the specified range, and the distance specification indicates that no address was found within the range if the logical distance between the first address and the second address is not within the specified range.

[0022] Optionally, the memory patch circuit includes a control signal generator that sends a control signal to enable or disable the operation of the memory patch circuit.

[0023] Optionally, the control signal generator comprises a control memory and a configuration unit configured to write a value into the control memory.

[0024] Optionally, the control signal generator is coupled to the distance calculation unit.

[0025] Optionally, a control signal for disabling the memory patch circuit or for disabling the patch entry associated with the distance calculation unit causes the distance calculation unit to output a distance indication indicating that no address within the range has been found.

[0026] Optionally, the control signal generator is coupled to the code generation unit.

[0027] Optionally, a control signal for disabling the memory patch circuit or for disabling a specific patch entry causes the code generation unit to ignore any positive distance indication within the predetermined limits to be ignored, given that no match has been detected from the disabled patch entry, regardless of the output of the corresponding comparison unit.

[0028] Optionally, the memory patch circuit includes a configuration unit for storing a memory address in the address memory.

[0029] Optionally, the memory patch circuit comprises multiple patch groups, each group comprising an address register and a distance calculation unit.

[0030] Optionally, each patch group includes a control register for outputting a control signal.

[0031] Optionally, the memory patch circuit includes a memory that stores a table of pointers to replacement functions, one for each patch group.

[0032] Optionally, the code generation unit comprises an instruction generation unit configured to implement a required sequence of instruction operation codes to implement the predetermined injected code.

[0033] Optionally, the code generation unit comprises a decision unit arranged to receive the distance information from the or each distance calculation unit and to control the data output to the output data bus based on the received distance information.

[0034] According to a second aspect of the disclosure, a system is provided comprising: a memory; a processor; an address bus coupled between the memory and the processor; and a memory patch circuit comprising: a code generation unit coupled to a memory via an input data bus and coupled to a processor via an output data bus; an address memory storing an address of a location in the memory to be patched; a distance calculation unit configured to: receive a first address from an address bus connecting the memory and the processor, receive a second address from the address memory, compare the first and second addresses, and output a distance indication based on the comparison;wherein the code generation unit is arranged to receive the distance indication and, based on the distance indication, either pass the data from the input data bus to the output data bus or inject code into the output data bus;

[0035] According to a third aspect of the disclosure, a method for patching a memory is provided, comprising replacing a plurality of memory locations with hard-coded assembly instructions.

[0036] Optionally, the method includes the dynamic generation of the hard-coded assembly instructions.

[0037] Optionally, the method comprises: at a distance calculation unit; receiving a first address from an address bus connecting a memory and a processor, receiving a second address from an address memory, comparing the first and second addresses, and obtaining a distance indication based on the comparison; and at a code generation unit; based on the distance indication, either passing the data from an input data bus to an output data bus or injecting code into the output data bus. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The disclosure will now be described by way of example only with reference to the accompanying drawings, in which: Fig. 1 is a diagram illustrating aspects of a system for patching a memory including a patch circuit; Fig.2 is a diagram illustrating aspects of a system for patching a memory including a patch circuit including multiple patch entries; Fig. 3 is a flowchart illustrating the system in operation; Fig. 4 is a flowchart illustrating further aspects of the system in operation; and Fig. 5 is a flowchart of a method for programming a patch circuit. DETAILED DESCRIPTION

[0039] Patching can be required for any type of code, but it's useful to consider three main categories. The first is patching a data value (a data patch), the second is patching a specific small sequence of assembly instructions (an instruction patch), and a third is patching an entire function, replacing it entirely with another function (a function patch).

[0040] All processing units (CPUs) provide instructions to their instruction set architecture (ISA) to manage the execution flow. It is common practice to either not provide a direct solution for "functional patching" or to create a solution that imposes some restrictions on the software structure.

[0041] The present disclosure provides a patch system and patch circuit by creating a new type of patch entry that can replace multiple consecutive memory locations with hard-coded and dynamically configured assembly instructions, thus injecting a small piece of code. The operation of the injected code can be for any purpose, but as an example, it can be used to seamlessly redirect the execution flow of a processing unit.

[0042] One proposed solution is to maintain a table of pointers to the replacement functions, one for each hardware function patch entry, in a memory within the chip (such as SRAM). Whenever the hardware detects an address match, it injects a small piece of assembly code that replaces the first few instructions of the problematic function and redirects execution to the function declared in the aforementioned table.

[0043] The disclosure creates the opportunity to maximize patch capabilities while keeping the additional silicon area as small as possible.

[0044] Fig.Figure 1 is a diagram illustrating aspects of a patch system 100 for patching a memory 102, the system including a patch circuit. Although the system is described in detail herein, it is recognized that alternative solutions may be used for many of the features described herein without departing from the scope of the disclosure.

[0045] The memory 102 may be any type of memory and may be implemented using any technology. The memory 102 may be non-volatile memory. For example, the memory 102 may be flash memory, read-only memory (ROM), PROM, EPROM, EEPROM, or any other type of non-volatile memory. The memory 102 may also be memory such as ferroelectric random access memory (FeRAM), conduction bridge RAM (CBRAM), phase change RAM (PRAM), silicon oxide nitride oxide silicon (SONOS), resistive RAM, racetrack memory, nano RAM (NRAM), millipede, etc. The memory 102 may be volatile memory; for example, it may be E.g., a RAM, a dynamic RAM (DRAM), a static RAM (SRAM), a zero-capacitor RAM (Z-RAM), a twin-transistor RAM (TTRAM), an advanced RAM (A-RAM), an ETA-RAM (manufactured by Eta Semiconductor Inc.), a universal serial bus memory (USB memory), etc. The memory can be organized in any suitable manner.

[0046] The memory 102 stores code to be executed by a processing unit 101. The information is exchanged between the memory 102 and the processing unit 101 via an address bus 110 and a data bus. If no patch circuit were provided, the data bus would be coupled directly between the memory 102 and the processing unit 101 (or between an input data bus 111 and an output data bus 112 shown in the figure). However, according to the present disclosure, a code generation unit 151 is arranged between the memory 102 and the processing unit 101. The code generation unit 151 receives data from the memory via an input data bus 111 and sends an output value 152 to the processing unit 101 via an output data bus 112. The input data bus 111 and the output data bus 112 can use any physical arrangement.They may use a parallel or bit-serial connection, or any suitable type of connection to the processing unit 101. The output data bus 112 may or may not have the same or a similar arrangement as the input data bus 111.

[0047] Memory 102 receives an address input 110 that indexes a unique location in the memory space. This location can store a data word of any size, counted in a number of bits or some other encoding format. All memory locations should store the same amount of information per stored location, which can be represented by the same number of bits per word. This disclosure is applicable to any memory organization and all word sizes represented by any number of bits.

[0048] The following description considers an example system with 32 bits (4 bytes) per word, where each address bus value indexes 1 byte. The address bus values ​​are always multiples of 4, thus always indexing a 4-byte word. It can also be considered that any arithmetic operation, such as addition or subtraction, on an address value in multiples of 4 always generates a new address value that indexes an aligned 4-byte word. It is also recognized that this specific example system does not limit the scope of the disclosure.

[0049] The processing unit 101 may comprise a bus master unit, for example, it may comprise the memory interface stage of a central processing unit (CPU), or a cache controller, or a direct memory access (DMA) controller, or a bus bridge connecting two or more bus interfaces, or any controller that includes a bus master unit in its design.

[0050] The patch system may include an address register 120 configured to store a memory address. The address register 120 may include any number of bits for holding addresses in any possible size. The size of the address register 120 may correspond to the size of an address bus 110 or may be smaller if it may be sufficient to index the patched memory area, which may be part or all of the memory area of ​​the memory 102. The memory address in the address bus 110 and in the address register 120 may identify an address in a memory 102.

[0051] The patch system 100 may optionally include a distance calculation unit 130, which is a circuit configured to receive a first address and a second address, compare the first address and the second address, and output a distance indication based on the comparison. The value may be an address value, a value corresponding to the number of memory array positions between the address values, or some other representation of the distance. The distance calculation unit 130 is configured to receive a first address from the address bus 110, compare it to a second address from the address register 120, and provide an output distance indication 150.

[0052] The distance indication 150 may be an indication of the result of a comparison performed by the distance calculation unit 130. For example, if the first and second addresses match based on the performed comparison, the distance indication 150 may be a value of zero ("0") or any type of signal representing the result of an exact match. If the first and second values ​​do not match based on the performed comparison, the distance indicator signal may be a negative or positive value or any type of signal representing the distance between the addresses of the address register 120 and the address bus 110. The distance may be counted in words, halfwords, or bytes, depending on the instruction set architecture (ISA) of the given processing unit 101 and the requirements of the code generation unit 151.

[0053] Alternatively, the distance indication 150 may indicate whether or not a logical distance between the first address and the second address is within a predetermined range. If it is within the predetermined range, the distance indication 150 may represent the distance. If it is not within the predetermined range, the distance indication 150 may be configured to provide an error message or a specific value indicating that no address within the range was found. The value of the distance indication may be received by the code generation unit 151, which then makes a decision based on the value depending on whether the value is within a predetermined range.

[0054] The distance calculation unit 130 may comprise any suitable circuitry for receiving the addresses and outputting a distance indication. According to a first embodiment of the distance calculation device, the distance calculation unit 130 may, for example, be configured to subtract the address received from the address bus 110 from the address stored in the address register 120 and, as a result, provide a signed value that forms the distance indication 150.

[0055] According to a second embodiment of the distance calculation device, the distance calculation unit 130 could comprise k-1 subtractors, each coupled to the address bus 110 and configured to subtract successive offsets from the value output on the address bus 110. In the above-mentioned exemplary 32-bit system, a first subtractor provides the address bus 110 minus 4, a second subtractor provides the address bus 110 minus 8, and any successive subtractors provide the address bus 110 minus successive multiples of 4.

[0056] The value k is the number of words required to implement the injected instruction sequence to be generated by code generation unit 151. The k address values ​​from the k-1 subtractors and address bus 110 may be compared with address register 120 using k comparators. The output of the k comparators may provide the distance information 150.

[0057] According to a third embodiment of the distance calculator, the distance calculator unit 130 may include k-1 adders coupled to the address register 120 and configured to add successive offsets to the value of the address register 120. In the above-mentioned exemplary 32-bit system, a first adder provides the address register 120 plus 4, a second adder provides the address register 120 plus 8, and any successive adders provide the address bus 110 plus successive multiples of 4. The value k represents the same number as described in the second embodiment of the distance calculator. The k address values ​​from the k-1 adders and the address register 120 may be compared to the address bus 110 using k comparators. The output of the k comparators may provide the distance indication 150.

[0058] The distance calculation unit 130 could also be implemented with several other circuit architectures. It is also possible to apply the distance calculation logic 130 not across all bits of the address bus 110, but only across those that carry the information required to index the portion of the memory 102 to which the patch mechanism is to be applied. This consequently reduces the substrate area and the latency of the circuit compared to the case of applying the distance calculation logic 130 across all bits of the address bus 110. Of the three embodiments of the distance calculation device mentioned above, the first two occupy less substrate area than the third, especially when there are multiple address registers 120. The third implementation can introduce minimal latency into the system.The choice of architecture for implementing the distance calculator depends on the system requirements and the constraints of the given manufacturing process and standard cell library, such as the final substrate area used and the final latency that the circuit introduces into the system.

[0059] The patch system may further include a configuration unit 104. The configuration unit 104 may be configured to receive any type of data, memory addresses, or control data. The configuration unit 104 may be further configured to store the memory addresses in the address register 120 or to store a value in the control register 140.

[0060] The patch system may include a control register 140. The control register 140 may be configured to store an indication of whether the patch entry represented by the address register 120 and the distance calculation unit 130 is enabled or whether the patch circuit as a whole (including multiple patch entries, as discussed below) is enabled. The indication may be any suitable indication; for example, one of the control register's bits may contain a "0," which may indicate that the patch entry or the patch circuit is not enabled. It may be connected to either the code generation unit 151 or the comparison unit 130 without affecting the final functionality of the system.Assuming that it is connected to the distance calculation unit 130 and that the patch entry or the patch circuit is not enabled, the distance calculation device 130 may be further configured to provide a value of the distance indication 150 of "not valid" or "distance too large" or whatever encoding signals the code generation unit 151 to select the value from the input data bus 111 as the output value 152 regardless of the relationship between the two address values ​​provided to the distance calculation device 130.

[0061] The system may include a code generation unit 151. The code generation unit 151 may be configured to receive a first value. The first value may come from an input data bus 111 or from any other type of device. The input data bus 111 may be implemented using any technology. The input data bus 111 may be coupled to the memory 102 and / or may be used to read from the memory 102 in such a manner that the memory 102 can input the data stored in the memory at the address specified by the address bus 110 into the input data bus 111.

[0062] Code generation unit 151 may be configured to receive a second value. The second value may be a portion of address register 120. This input may be used to decide the location of the instruction sequence injected into input data bus 111 to generate the final output value 152.

[0063] The code generation unit 151 may be configured to receive a third value. The third value may be the distance indication 150.

[0064] The code generation unit 151 may be further configured to send the output value 152 to an output data bus 112 or to any system or device that transmits data.

[0065] It is desirable and feasible for the patch process to be transparent to processing unit 101, as it can be implemented in a manner that does not change the processing unit's interface with memory 207 via memory controller 206. It is also feasible to provide output value 152 with the minimum possible latency, allowing replacement of input data bus value 111 within the same access cycle, thus avoiding the introduction of any wait cycle into the bus transaction initiated by processing unit 101.

[0066] The code generation unit 151 outputs an output value 152 and is configured to select the output value as either the data received from the input data bus 111 or a substitute value representing a substitute instruction. The substitute instruction is preferably stored in a suitable instruction memory, which may be provided as a component part of the code generation unit 151 and which may store one or more instructions. If multiple instructions are stored, the code generation unit 151 may be configured to select between the multiple stored instructions to be placed on the output data bus 112 as the output value 152 if the value from the input data bus 111 is not selected.

[0067] The patch system may include more than one patch group, referred to as a patch entry. Each patch entry may include an address register 120, a distance calculation unit 130, and a distance indication 150, as set forth above. A control register 140 may be provided as part of each patch entry, or alternatively, a single control register may be provided as part of the patch circuitry, as described below. The configuration unit 104 may be configured to receive an indication of which group is to be programmed with the given addresses and data. The code generation unit 151 may be configured to receive the corresponding set of inputs from each of the patch entries.Whenever the code generation unit 151 receives a matching indication (which may be a distance indication within a predetermined range of values) from more than one of the patch entries, the code generation unit 151 may decide to retain and process only one of the matching distance indication signals 150 and ignore the remaining ones. The decision may be of any type; for example, it may retain the matching distance indication derived from the patch entry with the smaller or larger identification number. It may further be configured to retain the matching distance indication with the minimum absolute value. In this way, collisions may be resolved. In the decision sub-block of the code generation unit, other similar techniques could also be followed to resolve any type of collisions between the signals coming from the multiple patch entries.

[0068] Fig. 2 is a graphical representation illustrating in more detail an example of a system 200 for patching a memory, which includes a patch circuit comprising a plurality of address registers 221, 222, 223. Each address register 221, 222, 223 may be accompanied by a distance calculator 231, 232, 233. Each address register 221, 222, 223 may be an example of the address register 120 of Fig. 1, while each of the distance calculation devices 231, 232, 233 is an example of the distance calculation unit 130 according to Fig. 1 can be.

[0069] The code generation unit 151 in Fig. 1 corresponds to the dashed area 151 after Fig. 2, where the dashed area shows the sub-blocks that form the logic of the code generation unit 151 according to Fig.1 according to this specific embodiment. This code generation unit 151 may be configured to include a decision unit 255 that collects the distance indication information provided by all distance calculators 231, 232, 233 and controls a command generation unit 256, a first multiplexing unit 257, and a second multiplexing unit 258, which ultimately generates the output value 152, which is forwarded to the processing unit 101 via the output data bus 112.

[0070] The code generation unit 151 may be configured to include an instruction generation unit 256. The purpose of this unit is to implement the required sequence of instruction opcodes to implement the specified injected code. This unit can generate sets of assembly instructions of any type and any division of a memory word, including a set of four single-byte instructions (8 bits each), a set of two half-word instructions (16 bits each), or a single-word instruction (32 bits wide), depending on the ISA of the given processing unit 101 and the selected code to be injected. The instruction generation unit 256 may be a circuit that selects an operation code from a predetermined list of operation codes depending on the value of the corresponding address register 221, 222, 223 and the distance indication values ​​from the distance calculators 231, 232, 233.It may further be configured to dynamically modify the operation code depending on the value of the offset or the corresponding address register 231, 232, 233 to form the final assembly instruction.

[0071] This dynamically adjusted and generated set of assembly instructions provided by instruction generation unit 256 can be configured to implement redirection of the CPU's execution flow, but can also be configured to implement other mechanisms depending on the system's needs. Implementing this instruction generation unit with hard-coded combinational logic consumes minimal substrate area and provides minimal response time and latency for the system. Depending on the ultimate system requirements, this unit can also be implemented in other ways, either hard-coded or reconfigurable, either as combinational or sequential logic, by storing the hard-coded operation codes either in combinational logic or in some type of reprogrammable or general purpose array.

[0072] The code generation unit 151 may be configured to further include a first multiplexing unit 257. The first multiplexing unit 257 may be configured to select and arrange the correct instruction set. The code generation unit 151 may also be further configured with a second multiplexing unit 258, which combines the data bus 111 with the decided instruction set provided by the first multiplexing unit 257 and thus constructs and provides the final output value to the processing unit 101.

[0073] Fig. 3 is a flow chart showing the circuit according to Fig.1 in operation. In step 300, processing unit 101 requests, via address bus 110, to read a word, e.g., data or an instruction, from a specific memory address. Memory 102 places the corresponding word on input data bus 111. Simultaneously or sequentially, offset calculation unit 130 checks in step 302 to determine whether the address on address bus 110 exactly matches address register 120; in other words, it checks whether the offset is zero (“0”).

[0074] If the distance calculation unit 130 detects an exact match (a distance of zero “0”), then in step 304 the instruction generation unit 256 generates an assembly instruction set, referred to herein as the assembly instruction set “A”, and outputs the assembly instruction set, which is first combined with the input data bus 111 (which is consistent with step 305 after Fig.3) and is sent to the processing unit 101 in step 306.

[0075] If the distance calculation unit 130 does not detect an exact match (i.e., a distance of "0"), then the distance calculation unit 130 further checks in step 308 whether the value of the distance indication 150 is within a predetermined maximum value k. If there is a match within this range of values, then an alternative assembly instruction set is generated in step 310 and sent to the processing unit 101 in steps 305 and 306.

[0076] If the distance calculator detects that the distance between the address bus 110 and the address register 120 is greater than the predetermined range, then in step 312, the data from the input bus 111 is sent to the processing unit 101 in step 306. In this case, no code is injected by the code generation unit 151.

[0077] The decisions taken by 302 and 308 can be reviewed by the decision unit 255 after Fig. 2. The generation of the corresponding instruction sets according to 304 and 310 can be implemented by the instruction generation unit 256 and the first multiplex unit 257. The combination of the instruction sets with the input data bus 111 or even the forwarding of the input data bus 111 to the processing unit 101, which is designated by steps 305 and 306, can be implemented by the second multiplex unit 258 according to Fig. 2 must be implemented.

[0078] Fig. 4 is a flowchart showing the circuit according to Fig. 1 for the specific example of a 32-bit system, as mentioned above, in operation. Here are the steps that Fig. 3 are illustrated with the same reference numerals. In Fig. 4 requires as in Fig.3 instructs the processing unit 101 in step 300 to read a word which is checked against the address register 120 in step 302, and if there is an exact match, a first assembly instruction set "A" is generated and output in step 304 so that it is combined with the input data bus 111 in step 305 and finally sent to the processing unit 101 in step 306.

[0079] If in this embodiment after Fig. 4, the address on address bus 110 does not exactly match the address register 120, then in this embodiment, the offset indication in step 400 may indicate that the offset is one word or, alternatively, 4 bytes. If there is a match in step 400, then a second assembly instruction set "B" is generated in step 402 and combined with the input data bus in step 305, so that processing unit 101 receives the modified data in step 306.

[0080] If there is no match in step 400, then a third check is performed in step 404, in parallel or sequentially with the other checks, to determine whether the distance between address bus 110 and address register 120 is 2 words or, alternatively, 8 bytes. If there is a match, then a third assembly instruction set "C" is generated and issued in step 406, to be combined with data bus 111 in step 305 and provided to processing unit 101 in step 306. If there is no match in step 404, then the distance is considered to be beyond the predetermined limit, and in step 312 the data from input data bus 111 is not modified, being forwarded as is to processing unit 101 in step 306.

[0081] Fig.5 is a flowchart of a method for programming a patch circuit. In step 500, a corrected function is selected at a base address ADR_P that replaces the function to be patched or other data to be patched. In step 502, the memory address ADR_P is stored in the first position of an array that stores the pointers of the functions that replace (patch) the problematic functions. This array of function pointers can be located in any read / write memory area accessible by the processing unit 101 and located anywhere in the system architecture, inside or outside the SoC. This array of function pointers can be referred to as a patch function pointer table, or otherwise referred to as PFPT. In step 504, a function is selected at a base address ADR_R that needs to be patched or otherwise replaced. In step 506, the memory address ADR_R in the address register 221 is Fig. 2, here being patch entry 1. This step may, for example, involve sending a request to configuration unit 104 to store the ADR_R value in address register 221. In step 508, the programmed address register is activated by sending another request to configuration unit 104 to set control register 140 to the appropriate value. The same process can be followed for all available patch entries, programming the correct PFPT table and register entries.

[0082] Any number of patch entries (distance calculator and address register pairs) may be implemented according to the anticipated number of patches that may be required after the system-on-chip (SoC) is manufactured. Control register 140 can selectively enable or disable each of these patch entries.

[0083] A programming port 203 may be provided and coupled to the configuration unit 104, which is configured to program the address registers 221, 222, 223 (the connecting lines are not shown in the drawing for clarity) and the control register 140. The programming port 203 may be accessed by the processing unit 101 or by any other processing unit of the system, and the programming port 203 may be programmed by the processing unit 101 or by any other processing unit of the system. The bus interface of the programming unit may be of any type and may be connected at any location in the SoC architecture, allowing access from the corresponding processing unit. Fig.2, the programming port 203 is connected to the processing unit 101 with a direct connection as an example, this providing an example without limiting all possible implementation alternatives.

[0084] As mentioned above, the present disclosure is not limited to any particular type of processor or ISA. To further assist the reader in understanding the disclosure, a specific case study of an ARM Cortex-MO processor implementing the smallest subset of the ARMv6-M architecture will now be discussed in more detail.

[0085] The Cortex-MO provides a solution with a special instruction called "SuperVisor Call" (acronym "SVC 'N"). This is a 16-bit assembly instruction that can be used for function patching. Using this instruction imposes several restrictions on the final application code. First, it requires that interrupts remain enabled during any function call. Second, it changes the processing state to exception mode. Third, the SVC handler must have the highest priority among all interrupts. These last two side effects mean that no other interrupt handler can be executed while the SVC handler is executing—that is, while the corrected function is executing. This poses problems, especially for real-time systems.The second side effect means that the CPU state changes to a privileged execution state, which can cause problems, especially in systems that use an operating system.

[0086] The following describes various example implementations for this processor and describes various possible assembly codes that can be injected. It is recognized that other implementations are possible. There may, of course, be many variations for the specific ISA and also other variations for any other ISA. The basic structure of the following code sequences also follows the philosophy of the macro code known as "veneer," which the C compiler typically uses. The "veneer" macro typically extends the scope of a branch by becoming the intermediate target of the branch instruction. The code of this small intermediate function can be used as a starting point for a given ISA to construct the final code that can be injected through a patch circuit.

[0087] Implementation A: Here, it is considered that the aforementioned Patch Function Pointer Table (PFPT) is located at a fixed location in the system memory map, and specifically in this example at the hexadecimal address value OxCO, which is the end of the vector table of the given ISA. The maximum number of function patch entries is 32, which means that one can decide to implement any number of patch entries between 1 and 32. During execution by the processing unit 101 of the code injected by the patch circuit, the processing unit indexes and retrieves from the PFPT the entry corresponding to the matching hardware patch entry with the identification number "P." The patch circuit injects (via the code generation unit 151) a total of five instructions, each 16 bits (one half-word) wide. Fig.1, the five half-word instructions require a distance calculation unit 130 that can detect a distance of up to three words between the address bus 110 and the address register 120.

[0088] The injected assembly code is: PUSH {r0,r1};r0 secure and reserve an additional position in the stack MOVS r0,#0xCO; load the base address of the patch table (a value less than OxFC) LDR r0,[r0,#(4*P)]; select the patch function that adds the offset in the table (P = 0, ..., 31) STR r0,[sp,#0×04}; store the value of r0 at the reserved position in the stack POP {r0,pc};r0 restore and save the value of the reserved stack position in the PC

[0089] The instruction generation unit 256 according to Fig. 2 should be configured to generate the opcodes corresponding to this code sequence. Specifically, for the third instruction, the instruction generation unit 256 may be further configured to dynamically construct the correct instruction opcode to point to the correct patch entry P.

[0090] Implementation A is suitable for most cases because it strikes a good balance between the required substrate area and the maximum available number of patch entries.

[0091] Implementation B: Implementation B is a variant of implementation A, where, to overcome the limitation of 32 patch entries, an additional instruction has been added, thus creating up to 95 patch entries. The additional hardware requirements are relatively limited. They require a distance calculation unit 130 according to Fig. 1, which can detect a distance of up to four words.

[0092] The final injected code is: PUSH {r0,r1} ; Sr0 secure and reserve an additional position in the tapel MOVS r0,#0xCO ; k load the base address of the patch table (a value less than 0xFC) ADDS r0, r0, #(4*PO) ; the first patch function selection (P0 = 0, ..., 63 entries) LDR r0,[r0, #(4*P1)] ; P1 = 0, ..., 31, corresponding to P = 63, ..., 94 (maximum effective value 0×7C) STR r0,[sp,#0×04}; store the value of r0 at the reserved position in the stack POP {r0,pc} ; Restore r0 and save the value of the reserved stack position in the PC

[0093] The implementation C: In this variation, the PFPT patch table can be located at any location in system memory. The maximum number of function patch entries is 32. During execution of the injected code, processing unit 101 indexes the PFPT entry corresponding to the matching hardware patch entry "P" to retrieve the base address of the correct function and then branch to that address.

[0094] The code generation unit 151 injects a total of 7 or 8 half-word instructions (each 16 bits wide) depending on the alignment of the function's base address. In other words, depending on whether the base address is word-aligned or half-word-aligned in the memory array 102. The code generation unit 151 can detect the alignment of the function's base address by fetching the second least significant bit of the address register 120. The distance calculator 130 can be configured to detect a distance of up to five words.

[0095] The C implementation also requires an additional single register, which is located in the Fig. 1 and Fig.2 is not described. It is used by all patch entries, and the configuration unit 104 may be able to index and program any value in this register. This register may be configured to store a word with sufficient register bits to encode an address that the processing unit uses to index the PFPT. During programming of the patch circuit (as in Fig. 5) there must be an additional programming step where the “_patch_table_ptr” value can be stored in this register.

[0096] If the function's base address is word-aligned, the injected assembly code requires a dummy halfword (see the "NOP" instruction). If it is not word-aligned, the dummy "NOP" instruction can be skipped. The decision to skip the dummy instruction is made by the instruction generation unit 256. The code listing is: PUSH {rO,r1} ; Secure r0 and reserve an additional position in the stack LDR r0,[pc,#8] LDR r0,[r0,#(4*P)] ; P = 0, .., 31 (maximum effective value 0x7C) STR r0,[sp,#0x04] POP {rO,pc} NOP ; this dummy halfword is conditionally required to word-align the pointer; DCW _patch table_ ptr_low ; the value stored in a hardware register DCW _patch_table_ptr_high

[0097] The implementation D: This implementation is the same as the C implementation, with the only difference that there is no limit on the number of patch entries.

[0098] The additional cost of implementation D in terms of hardware costs compared to implementation C comes from the addition of another arithmetic unit, which is included in the Fig. 1 and Fig.2 is not described. This new unit should implement the equation provided under the following assembly listing. The equation requires an arithmetic shifter and an adder. The unit may be configured to receive as a first input the value of the "_patch_table_index_ptr" register described in implementation C. It may further be configured to receive as a second input the identification number of the matching patch entry. The instruction generation unit 256 may be further configured to split the output of this arithmetic unit into two half-words, providing it to the first multiplexing unit 257 to construct the correct instruction set.

[0099] The injected assembly code is: PUSH {r0,r1} ; Secure r0 and reserve an additional position in the stack LDR r0,[pc,#8] LDR r0,[r0,#0×0] STR r0,[sp,#0×04] POP {r0,pc}; NOP this dummy halfword is conditionally required to word-align the pointer; DCW _patch_table_p tr_low; the value stored in a hardware register DCW _patch_table_ptr_high

[0100] Note: _patch_table_index_ptr = _patch_table_ptr + 4*P, implemented in hardware.

[0101] It should be noted that the embodiments described above illustrate rather than limit the invention, and those skilled in the art may devise many alternative embodiments without departing from the scope of the appended claims. In the claims, any reference numerals placed between parentheses should not be construed as limiting the claim. The use of the verb "comprise" and its conjugations does not exclude the presence of elements or steps other than those set forth in the claim. The article "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising a plurality of different elements and by means of a suitably programmed computer.In a device claim that lists multiple means, several of these means may be embodied by one and the same piece of hardware. The mere fact that certain measures are set forth in mutually different dependent claims does not indicate that a combination of these measures cannot be used to advantage.

[0102] It should be appreciated that the logical code, programs, modules, processes, methods, and the order in which the respective elements of each method are executed are purely exemplary. Depending on the implementation, they may be executed in any order or in parallel, unless otherwise stated in the present disclosure. Further, the logical code is not related to or limited to any particular programming language and may include one or more modules executable on one or more processors in a distributed, non-distributed, or multiprocessor environment.

Claims

[1] Memory patch circuit that includes: a code generation unit coupled to a memory via an input data bus and coupled to a processor via an output data bus, the code generation unit comprising an instruction generation unit; an address memory storing an address of a location in the memory to be patched; a distance calculation unit designed to: receive a first address from an address bus connecting the memory and the processor, to receive a second address from the address memory, to compare the first and second address and to output a distance indication based on the comparison; wherein the code generation unit is arranged to receive the distance indication and, based on the distance indication, either pass the data from the input data bus to the output data bus or generate code using the instruction generation unit and inject the generated code into the output data bus, such that the output data bus transmits the data from the input data bus and the generated code to the processor. [2] The memory patch circuit of claim 1, wherein the code generation unit is arranged to receive the address from the address memory to determine the location for the injected code. [3] A memory patch circuit according to claim 1 or 2, wherein the distance calculating means is arranged to subtract the first address from the second address and provide a signed value as the distance indication. [4] A memory patch circuit according to any preceding claim, wherein the distance calculation unit comprises a plurality of subtractors, each coupled to the address bus and arranged to subtract successive offsets from the first address. [5] The memory patch circuit of claim 4, wherein the distance calculation unit comprises a plurality of comparators, each coupled to one of the subtractors, and the outputs of the comparators provide the distance indication. [6] A memory patch circuit according to any preceding claim, wherein the distance calculation unit comprises a plurality of adders, each coupled to the address memory and arranged to add successive offsets to the second address. [7] The memory patch circuit of claim 6, wherein the distance calculation unit comprises a plurality of comparators, each coupled to one of the adders, and the outputs of the comparators provide the distance indication. [8] A memory patch circuit according to any preceding claim, wherein the distance indication indicates whether the logical distance between the first address and the second address is within a predetermined range. [9] The memory patch circuit of claim 8, wherein the distance indication represents the distance if the logical distance between the first address and the second address is within the predetermined range, and the distance indication indicates that no address has been found within the range if the logical distance between the first address and the second address is not within the predetermined range. [10] A memory patch circuit according to any preceding claim, comprising a control signal generator that sends a control signal to enable or disable operation of the memory patch circuit. [11] The memory patch circuit of claim 10, wherein the control signal generator comprises a control memory and a configuration unit configured to write a value to the control memory. [12] The memory patch circuit of claim 10 or claim 11, wherein the control signal generator is coupled to the distance calculation unit. [13] The memory patch circuit of claim 12, wherein a control signal for disabling the memory patch circuit or for disabling the patch entry associated with the distance calculation unit causes the distance calculation unit to output a distance indication indicating that no address has been found within the range. [14] Memory patch circuit according to one of claims 10 to 13, wherein the control signal generator is coupled to the code generation unit. [15] A memory patch circuit according to claim 14, wherein a control signal for disabling the memory patch circuit or for disabling a specific patch entry causes the code generation unit to ignore any positive distance indication within the predetermined limits to be ignored in view of the fact that no match has been detected from the disabled patch entry, regardless of the output of the corresponding comparison unit. [16] A memory patch circuit according to any preceding claim, comprising a configuration unit for storing a memory address in the address memory. [17] A memory patch circuit according to any preceding claim, comprising a plurality of patch groups, each group comprising an address register and a distance calculation unit. [18] The memory patch circuit of claim 17, wherein each patch group comprises a control register for outputting a control signal. [19] A memory patch circuit according to claim 17 or claim 18, comprising a memory storing a table of pointers to replacement functions, one for each patch group. [20] A memory patch circuit according to any preceding claim, wherein the code generation unit comprises a decision unit arranged to receive the distance information from the or each distance calculation unit and to control the data output to the output data bus based on the received distance information. [21] System that includes: a memory; a processor; an address bus coupled between the memory and the processor; and a memory patch circuit comprising: a code generation unit coupled to a memory via an input data bus and coupled to a processor via an output data bus, the code generation unit comprising an instruction generation unit; an address memory that stores an address of a location in the memory to be patched; a distance calculation unit designed to: receive a first address from an address bus connecting the memory and the processor, to receive a second address from the address memory, to compare the first and second address and to output a distance indication based on the comparison; wherein the code generation unit is arranged to receive the distance indication and, based on the distance indication, either pass the data from the input data bus to the output data bus or generate code using the instruction generation unit and inject the generated code into the output data bus, such that the output data bus transmits the data from the input data bus and the generated code to the processor.

Citation Information

Patent Citations

  • Microprocessor and host computer and rewriting device

    JP2002007113A

  • Computer system and instruction exchanging method

    JP2001290638A

  • Authentication system and authentication method

    JP2008027113A

  • Circuit and method for patching for program ROM

    US20080112205A1

  • Memory Patching Circuit

    US20140289455A1