Method, apparatus, device, and storage medium for selecting jump address of jump instruction
By calculating the address difference and number in the instruction stream and adjusting the jump address range, the problem of jump instructions exceeding the reasonable range is solved, and the integrity of processor verification is achieved.
Patent Information
- Application Number
- CN202510237746.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-28
- Publication Date
- 2025-07-04
- Estimated Expiration
- 2045-02-28
AI Technical Summary
During the processor verification stage, the jump address of the jump instruction may exceed the reasonable range, resulting in the CPU running stuck and the verification cannot be continued.
By calculating the address difference of adjacent instructions in the instruction stream, the information of jump instructions and the number of instructions, the candidate jump addresses and constraints are determined, and the jump address range is adjusted to ensure that within a reasonable range, the target jump address is selected for command jumps.
Increases the probability of jumping instructions to a reasonable range, ensuring the integrity of processor module verification.
Smart Images

Figure CN119718425B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of integrated circuit technology, and in particular, to a method, apparatus, electronic device, and computer-readable storage medium for selecting a jump address of a jump instruction. Background Art
[0002] During the verification phase of a processor (CPU, Central Processing Unit) core, an instruction stream is generated by an instruction generator, and each instruction in the instruction stream is commonly used to verify the modules of the CPU.
[0003] During the verification process, the instruction stream usually includes a relatively large number of instructions. For example, immediate number jump instructions. In the related art, after generating an immediate number jump instruction, the jump address of the jump instruction is calculated, and the instruction jumps according to the jump address.
[0004] If, after executing a certain jump instruction during the verification process, the jump address of the jump instruction is outside the reasonable range of the instruction stream, it will cause the pointer of the CPU to point to an address without an instruction, thereby causing the entire CPU to freeze and unable to continue verifying the modules of the CPU. Summary of the Invention
[0005] Embodiments of this application provide a method, apparatus, electronic device, and computer-readable storage medium for selecting a jump address of a jump instruction to solve the problems in the related art.
[0006] In a first aspect, an embodiment of this application provides a method for selecting a jump address of a jump instruction, where the method includes:
[0007] Generate an instruction stream, determine the instruction information of the jump instruction in the instruction stream, and determine a first difference between the addresses of adjacent instructions in the instruction stream;
[0008] According to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream, determine a candidate jump address of the jump instruction and a constraint condition for the jump addresses of all the jump instructions;
[0009] When the candidate jump address of the jump instruction does not meet the constraint condition, determine a jump address range according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream;
[0010] Determine a target jump address of the jump instruction from the jump address range, and when executing the jump instruction, perform an instruction jump according to the target jump address.
[0011] In a second aspect, an embodiment of this application provides a device for selecting a jump address of a jump instruction, where the device includes:
[0012] A generation module, configured to generate an instruction stream, determine instruction information of jump instructions in the instruction stream, and determine a first difference between addresses of adjacent instructions in the instruction stream;
[0013] A calculation module, configured to determine a candidate jump address of the jump instruction and constraint conditions for jump addresses of all the jump instructions according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream;
[0014] A judgment module, configured to determine a jump address range according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream when the candidate jump address of the jump instruction does not meet the constraint conditions;
[0015] An execution module, configured to determine a target jump address of the jump instruction from the jump address range, and perform an instruction jump according to the target jump address when executing the jump instruction.
[0016] In a third aspect, an embodiment of the present application further provides an electronic device, including a processor; and a memory for storing executable instructions of the processor; wherein, the processor is configured to execute the instructions to implement the method of the first aspect.
[0017] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, enabling the electronic device to execute the method of the first aspect.
[0018] In the embodiment of the present application, according to the first difference between addresses of adjacent instructions in the instruction stream, the instruction information of jump instructions in the instruction stream, and the number of instructions in the instruction stream, a candidate jump address of the jump instruction and constraint conditions for jump addresses of all jump instructions are determined. When the candidate jump address of the jump instruction does not meet the constraint conditions, that is, it is not within a reasonable range, a jump address range of the jump instruction is re-determined. And a target jump address of the jump instruction is determined from the jump address range, and when executing the jump instruction, an instruction jump is performed according to the target jump address, which can increase the probability that the jump instruction jumps to a reasonable range, so that verification can cover all modules of the processor as much as possible.
[0019] The above description is only an overview of the technical solution of the present application. In order to understand the technical means of the present application more clearly, it can be implemented according to the content of the specification. And in order to make the above and other purposes, features and advantages of the present application more obvious and understandable, the specific embodiments of the present application are specifically exemplified below. Description of the Drawings
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0021] Figure 1 It is a flowchart of the steps of a method for selecting a jump address of a jump instruction provided by an embodiment of the present application;
[0022] Figure 2 It is a specific flowchart of the steps of a method for selecting a jump address of a jump instruction provided by an embodiment of the present application;
[0023] Figure 3 It is a block diagram of a device for selecting a jump address of a jump instruction provided by an embodiment of the present application;
[0024] Figure 4 It is a block diagram of an electronic device provided by an embodiment of the present application;
[0025] Figure 5 It is a block diagram of another electronic device of another embodiment of the present application. Detailed Embodiments
[0026] The following will clearly and completely describe the technical solutions in the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are some, rather than all, of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present application.
[0027] The terms "first", "second", etc. in the description and claims of this application are used to distinguish similar objects, rather than to describe a specific order or sequence. It should be understood that such data used can be interchanged under appropriate circumstances, so that the embodiments of this application can be implemented in an order other than those illustrated or described herein, and the objects distinguished by "first", "second", etc. are generally of the same type, and the number of objects is not limited. For example, the first object can be one or more. In addition, the term "and / or" in the description and claims is used to describe the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. In the embodiments of this application, the term "plurality" refers to two or more, and other quantifiers are similar.
[0028] Figure 1 is a step flowchart of a method for selecting a jump address of a jump instruction provided by an embodiment of this application, as Figure 1 shown, the method may include:
[0029] Step 101, generate an instruction stream, determine the instruction information of the jump instruction in the instruction stream, and determine the first difference between the addresses of adjacent instructions in the instruction stream.
[0030] Exemplarily, each instruction in the instruction stream is an instruction in the instruction set of the processor. For example, it can be an addition instruction, a subtraction instruction, a write instruction, a read instruction, a jump instruction, and other instructions.
[0031] Exemplarily, the jump instruction can be an immediate addressing jump instruction or a register addressing jump instruction. The target jump address of the jump instruction is the sum of the base address and the address offset. In the immediate addressing jump instruction, the jump instruction includes an immediate number, and the immediate number is used to represent the offset of the jump address. The base address is the address of the jump instruction, that is, the address assigned to the jump instruction during the generation of the jump instruction. In the register addressing jump instruction, the jump instruction includes a register identifier and an immediate number, and the address stored in the register represented by the register identifier is the base address.
[0032] Exemplarily, the instruction information of the jump instruction may include: the number of the jump instruction and the immediate number of the jump instruction. For example, when the instruction generator generates an instruction stream, each time an instruction is generated, the sequence number of the instruction is recorded. For the jump instruction, the sequence number of the jump instruction is the number of the jump instruction. The immediate number of the jump instruction is a value randomly generated according to the fixed position encoding of the instruction code of the jump instruction, and is used to represent the offset of the jump address.
[0033] Exemplarily, the first difference is the difference between the addresses of any two adjacent instructions in the instruction stream. It should be noted that the difference between the addresses of any two adjacent instructions is the same, and this difference can be predetermined.
[0034] Step 102: Determine the candidate jump address of the jump instruction and the constraint conditions for the jump addresses of all the jump instructions according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream.
[0035] Exemplarily, taking the instruction information of the jump instruction including the number of the jump instruction and the immediate number of the jump instruction as an example, assume that the 27th instruction is an immediate number type jump instruction, and the immediate number in the immediate number type jump instruction is binary 1010. Then the number of the immediate number type jump instruction is 27, the decimal number corresponding to the immediate number in the immediate number type jump instruction is 12, and the instruction information of the jump instruction includes 27 and 12. Assume that the 51st instruction is an immediate number type jump instruction, and the immediate number in the immediate number type jump instruction is binary 111110111110. Then the number of the immediate number type jump instruction is 51, the decimal number corresponding to the immediate number in the immediate number type jump instruction is -66, and the instruction information of the jump instruction includes 51 and -66. Assume that the 80th instruction is an immediate number type jump instruction, and the immediate number in the immediate number type jump instruction is binary 11111. Then the number of the immediate number type jump instruction is 80, the decimal number corresponding to the immediate number in the immediate number type jump instruction is 31, and the instruction information of the jump instruction includes 80 and 31.
[0036] Exemplarily, the present application calculates the candidate jump address of the jump instruction according to the first difference and the instruction information of the jump instruction. Further, according to the first difference, the number of the jump instruction, and the immediate number of the jump instruction, the candidate jump address of the jump instruction is calculated. For example, the calculation formula is: candidate jump address = (number of the jump instruction - 1) × first difference + immediate number of the jump instruction × first difference. Assume that the number of the immediate number type jump instruction is 27, the decimal number corresponding to the immediate number in the immediate number type jump instruction is 12, and the first difference is 4. Then the candidate jump address of this immediate number type jump instruction is (27 - 1) × 4 + 12 × 4 = 152. Assume that the number of the immediate number type jump instruction is 51, the decimal number corresponding to the immediate number in the immediate number type jump instruction is -66, and the first difference is 4. Then the candidate jump address of this immediate number type jump instruction is (51 - 1) × 4 + (-66) × 4 = -64. Assume that the number of the immediate number type jump instruction is 80, the decimal number corresponding to the immediate number in the immediate number type jump instruction is 31, and the first difference is 4. Then the candidate jump address of this immediate number type jump instruction is (80 - 1) × 4 + 31 × 4 = 480.
[0037] Exemplarily, since the jump address calculated based on the immediate value of the jump instruction may not be within the reasonable range of the instruction stream, the present application determines the constraint conditions for the jump addresses of all jump instructions according to the first difference and the number of instructions in the instruction stream, and judges whether the candidate jump address of the jump instruction is within the constraint conditions according to the constraint conditions. If the candidate jump address of the jump instruction is within the constraint conditions, it indicates that the immediate value of the randomly generated jump instruction is reasonable, and the target jump address can be calculated based on this immediate value. If the candidate jump address of the jump instruction is not within the constraint conditions, it indicates that the immediate value of the randomly generated jump instruction is unreasonable and needs to be adjusted so that the jump address of the jump instruction is within the reasonable range of the instruction stream.
[0038] Step 103, when the candidate jump address of the jump instruction does not meet the constraint conditions, determine the jump address range according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream.
[0039] Exemplarily, the candidate jump address of the jump instruction does not meet the constraint conditions, that is, the candidate jump address of the jump instruction is not within the constraint conditions. The jump address range is used to reflect the address offset that the jump instruction can select.
[0040] Exemplarily, assume that the number of the immediate value type jump instruction is 80, the decimal number corresponding to the immediate value of the immediate value type jump instruction is 31, and the first difference is 4. Then the candidate jump address of this immediate value type jump instruction is (80 - 1)×4 + 31×4 = 480. If the candidate jump address of the jump instruction numbered 80 is not within the constraint conditions, the jump address range is determined according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream. For example, the calculation formula is: the jump address range can be [- (the number of the jump instruction - 1)×the first difference, (the number of instructions in the instruction stream - the number of the jump instruction)×the first difference]. Assume that the number of the immediate value type jump instruction is 80, the decimal number corresponding to the immediate value of the immediate value type jump instruction is 31, and the first difference is 4. Then the jump address range of this immediate value type jump instruction is [-79×4, 20×4].
[0041] For example, assume that the number of the immediate jump instruction is 51, the decimal number corresponding to the immediate value of the immediate jump instruction is -66, and the first difference is 4. Then the candidate jump address of this immediate jump instruction is (51 - 1) × 4 + (-66) × 4 = -64. If the candidate jump address of the jump instruction numbered 51 is not within the constraint conditions, then the jump address range is determined according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream. For example, the calculation formula is: the jump address range can be [-(the number of the jump instruction - 1) × the first difference, (the number of instructions in the instruction stream - the number of the jump instruction) × the first difference]. Assume that the number of the immediate jump instruction is 51, the decimal number corresponding to the immediate value of the immediate jump instruction is -66, and the first difference is 4. Then the jump address range of this immediate jump instruction is [-50 × 4, 49 × 4].
[0042] Step 104, determine the target jump address of the jump instruction from the jump address range, and when executing the jump instruction, perform an instruction jump according to the target jump address.
[0043] For example, the jump address range gives the range of the migration address of the jump instruction. After obtaining the jump address range, select a jump address from this jump address range as the migration address of the jump instruction, and then obtain the target jump address of the jump address according to the migration address and the base address of the jump address.
[0044] For example, assume that the number of the immediate jump instruction is 80, the decimal number corresponding to the immediate value of the immediate jump instruction is 31, and the first difference is 4. The jump address range of this immediate jump instruction is [-79 × 4, 20 × 4]. Select a jump address from the jump address range [-79 × 4, 20 × 4] as the migration address of the jump instruction numbered 80. Taking the migration address of the jump instruction numbered 80 as 80 as an example, since the base address of the jump instruction numbered 80 is 316, the target jump address is 396, which is within a reasonable range.
[0045] For example, assume that the number of the immediate jump instruction is 51, the decimal number corresponding to the immediate value of the immediate jump instruction is -66, and the first difference is 4. The jump address range of this immediate jump instruction is [-50 × 4, 49 × 4]. Select a jump address from the jump address range [-50 × 4, 49 × 4] as the migration address of the jump instruction numbered 51. Taking the migration address of the jump instruction numbered 51 as -200 as an example, since the base address of the jump instruction numbered 51 is 200, the target jump address is 0, which is within a reasonable range.
[0046] Exemplarily, each instruction in the instruction set can be generated, and the instruction can be simulated and executed to obtain the corresponding target result. During the running of the test program, when executing a certain instruction, the actual result during the instruction execution can be obtained, and by comparing whether the actual result is the same as the target result, it can be verified whether the various functions of the processor are normal.
[0047] In summary, in the embodiment of the present application, according to the first difference between the addresses of adjacent instructions in the instruction stream, the instruction information of the jump instructions in the instruction stream, and the number of instructions in the instruction stream, the candidate jump addresses of the jump instructions and the constraint conditions for the jump addresses of all jump instructions are determined. When the candidate jump address of the jump instruction does not meet the constraint conditions, according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream, the jump address range is determined. When the candidate jump address of the jump instruction in the present application does not meet the constraint conditions, that is, it is not within a reasonable range, the jump address range of the jump instruction is re-determined. And from the jump address range, the target jump address of the jump instruction is determined, and when the jump instruction is executed, the instruction jump is performed according to the target jump address, which can increase the probability that the jump instruction jumps to a reasonable range and enable the verification to cover all modules of the processor as much as possible.
[0048] Figure 2 is a specific step flowchart of a method for selecting a jump address of a jump instruction provided by an embodiment of the present application. As Figure 2 shown, the method may include:
[0049] Step 201, generate an instruction stream, determine the instruction information of the jump instructions in the instruction stream, and determine the first difference between the addresses of adjacent instructions in the instruction stream.
[0050] This step can specifically refer to the above step 101 and will not be elaborated here too much.
[0051] Optionally, step 201 may specifically include:
[0052] Sub-step 2011, obtain the names of the instructions in the instruction stream;
[0053] Sub-step 2012, if the name of the instruction is in the preset set, determine that the instruction is the jump instruction; the preset set records the names of the jump instructions.
[0054] For sub-step 2011 - sub-step 2012, the preset set can be the SET_IJ set. During the process of generating the instruction stream, record the name of each instruction. According to whether the name of the instruction is within the SET_IJ set, determine whether the instruction is an immediate jump instruction. For example, the SET_IJ set contains two types of immediate jump instructions, namely JPI and BHI. According to whether the name of the instruction is JPI or BHI, determine whether the instruction is an immediate jump instruction.
[0055] For example, if the name of the instruction is within the SET_IJ set, then determine that the instruction is an immediate jump instruction. If the name of the instruction is not within the SET_IJ set, then determine that the instruction is not an immediate jump instruction. Taking the SET_IJ set including two types of immediate jump instructions JPI and BHI as an example, if the name of the instruction is JPI or BHI, then the instruction is an immediate jump instruction; otherwise, the instruction is not an immediate jump instruction.
[0056] For example, during the generation of the instruction stream, if it is determined that the instruction is an immediate jump instruction, then the sequence number of the instruction can be marked. Further, the sequence number of the instruction can be marked as is_IJ. Thus, according to whether there is an is_IJ flag in the sequence number, it can be determined whether the instruction is an immediate jump instruction.
[0057] Step 202: Perform a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and perform a multiplication operation on the second difference and the first difference to obtain a first product result; the instruction information of the jump instruction includes: the number of the jump instruction; the number of the jump instruction is used to represent the order in which the jump instruction is generated in the instruction stream.
[0058] For example, the number of the jump instruction can be the order in which the jump instruction is generated during the process of generating the instruction stream. For example, if the instruction stream contains 100 instructions in total and the generation order of a certain jump instruction is 27, then the number of this jump instruction is 27.
[0059] For example, the first difference is the difference between the addresses of any two adjacent instructions in the instruction stream and can be preset. For example, the first difference can be 4.
[0060] Exemplarily, the first preset value is used to represent the difference between the starting address of the instruction stream and the starting number of the instructions in the instruction stream. If the starting address of the instruction stream is 0 and the starting number of the instructions in the instruction stream is 1, then the first preset value is 1. The first product result is used to represent the base address of the jump instruction. Taking the jump instruction number 27 and the starting address of the instruction stream as 0 as an example, subtract the jump instruction number 27 from the first preset value 1 to obtain a second difference 26, and then multiply the second difference 26 by the first difference 4 to obtain the first product result 104, that is, the base address of the jump instruction numbered 27 is 104.
[0061] Step 203: Perform a multiplication operation on the immediate value of the jump instruction and the first difference to obtain a second product result; the instruction information of the jump instruction includes: the immediate value of the jump instruction; the immediate value is used to represent the offset of the jump address.
[0062] Exemplarily, the immediate value is used to represent the offset of the jump address, and the second product result is the specific offset address of the jump instruction. Taking the jump instruction number 27 as an example, assuming the immediate value in the jump instruction is binary 1010, convert the binary number to a decimal number to obtain the value 12. Then, perform a multiplication operation on the decimal immediate value 12 included in the jump instruction and the first difference 4 to obtain the second product result 48, that is, the specific offset address of the jump instruction is 48.
[0063] Step 204: Perform an addition operation on the first product result and the second product result, and determine the addition result as the decimal candidate jump address of the jump instruction.
[0064] Exemplarily, taking the jump instruction number 27 as an example, the first product result is 104, the second product result is 48, and then add the first product result and the second product result to obtain the decimal candidate jump address 152 of the jump instruction.
[0065] Step 205: Determine the constraint conditions for the jump addresses of all the jump instructions according to the first difference and the number of instructions in the instruction stream.
[0066] This step can specifically refer to the above step 102 and will not be elaborated here.
[0067] Optionally, step 205 may specifically include:
[0068] Sub-step 2051: Subtract the first preset value from the number of instructions in the instruction stream to obtain a third difference, and perform a multiplication operation on the third difference and the first difference to obtain a third product result;
[0069] Sub-step 2052: Determine the second preset value as the lower limit of the constraint condition, and determine the third product result as the upper limit of the constraint condition;
[0070] The method further includes:
[0071] Step A1: When the candidate jump address of the jump instruction is less than or equal to the lower limit of the constraint condition, or greater than or equal to the upper limit of the constraint condition, determine that the candidate jump address of the jump instruction does not meet the constraint condition.
[0072] For sub-step 2051 - sub-step 2052 and step A1, the second preset value can be 0, which is the lower limit of the constraint condition. The third product result is used to represent the maximum value of the candidate jump address and is the upper limit of the constraint condition. Taking the number of instructions in the instruction stream as 100 and the first preset value as 1, the third difference is 99. Then multiply the third difference by the first difference to get the third product result of 396. At this time, the lower limit of the constraint condition is 0 and the upper limit is 396.
[0073] For example, when the lower limit of the constraint condition is 0 and the upper limit is 396, when the candidate jump address of the jump instruction is less than or equal to 0, determine that the candidate jump address of the jump instruction does not meet the constraint condition. When the candidate jump address of the jump instruction is greater than or equal to 396, determine that the candidate jump address of the jump instruction does not meet the constraint condition.
[0074] Step 206: When the candidate jump address of the jump instruction does not meet the constraint condition, determine the jump address range according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream.
[0075] This step can specifically refer to step 103 above and will not be elaborated here.
[0076] Optionally, the instruction information of the jump instruction includes: the number of the jump instruction; step 206 can specifically include:
[0077] Sub-step 2061: Perform a subtraction operation on the number of the jump instruction and the first preset value to obtain a second difference, and perform a multiplication operation on the second difference and the first difference to obtain a first product result;
[0078] Sub-step 2062: Perform a subtraction operation on the number of instructions in the instruction stream and the number of the jump instruction to obtain a fourth difference, and perform a multiplication operation on the fourth difference and the first difference to obtain a fourth product result;
[0079] Sub-step 2063: Determine the opposite value of the first product result as the lower limit of the jump address range, and determine the fourth product result as the upper limit of the jump address range.
[0080] For sub - steps 2061 - 2063, taking the jump instruction number as 51 and the starting address of the instruction stream as 0 as an example, subtract the jump instruction number 51 from the first preset value 1 to get the second difference 50, then multiply the second difference 50 by the first difference 4 to get the first product result 200. Taking the number of instructions in the instruction stream as 100 as an example, subtract the jump instruction number 51 from the number of instructions 100 in the instruction stream to get the fourth difference 49, and multiply the fourth difference 49 by the first difference 4 to get the fourth product result 196. The lower limit of the jump address range is - 200, and the upper limit of the jump address range is 196, that is, [-200, 196]. Taking the jump instruction number as 80 and the starting address of the instruction stream as 0 as an example, subtract the jump instruction number 80 from the first preset value 1 to get the second difference 79, then multiply the second difference 79 by the first difference 4 to get the first product result 316. Taking the number of instructions in the instruction stream as 100 as an example, subtract the jump instruction number 80 from the number of instructions 100 in the instruction stream to get the fourth difference 20, and multiply the fourth difference 20 by the first difference 4 to get the fourth product result 80. The lower limit of the jump address range is - 316, and the upper limit of the jump address range is 80, that is, [-316, 80].
[0081] Step 207: Determine the target jump address of the jump instruction from the jump address range, and when executing the jump instruction, perform an instruction jump according to the target jump address.
[0082] This step can specifically refer to the above - mentioned step 104 and will not be elaborated here.
[0083] Optionally, the instruction information of the jump instruction includes: the number of the jump instruction; step 207 can specifically include:
[0084] Sub - step 2071: Subtract the number of the jump instruction from the first preset value to get a second difference, and multiply the second difference and the first difference to get a first product result;
[0085] Sub - step 2072: Randomly select a jump address from the jump address range and determine the jump address as the migration address; the migration address is used to represent the offset of the jump address;
[0086] Sub - step 2073: Add the first product result and the migration address, and determine the sum result as the target jump address in decimal.
[0087] For sub-step 2071 - sub-step 2073, taking the number of the jump instruction as 51 as an example, after obtaining the jump address range [-200, 196], a jump address 196 is randomly selected from the jump address range, and 196 is determined as the migration address, that is, the offset of the jump address.
[0088] Exemplarily, the first product result of the jump instruction numbered 51 is 200, which is added to the migration address 196 to obtain the decimal target jump address 396. So that when executing the jump instruction 51, the instruction jumps according to the address corresponding to the target jump address 396.
[0089] Exemplarily, taking the number of the jump instruction as 80 as an example, after obtaining the jump address range [-316, 80], a jump address -316 is randomly selected from the jump address range, and -316 is determined as the migration address, that is, the offset of the jump address. The first product result of the jump instruction numbered 80 is 316, which is added to the migration address -316 to obtain the decimal target jump address 0. So that when executing the jump instruction 51, the instruction jumps according to the address corresponding to the target jump address 0.
[0090] Optionally, after step 207, the method further includes:
[0091] Step 208: Obtain the target immediate number of the jump instruction according to the target jump address, and modify the immediate number of the jump instruction to the target immediate number.
[0092] Exemplarily, for the jump instruction numbered 51, after obtaining the target jump address 396, calculating the target immediate number corresponding to the target jump address according to the target jump address, and thus modifying the immediate number of the jump instruction based on the target immediate number can increase the probability that the jump instruction jumps to a reasonable range, enabling the verification to cover all modules of the processor as much as possible.
[0093] Exemplarily, for the jump instruction numbered 80, after obtaining the target jump address 0, calculating the target immediate number corresponding to the target jump address according to the target jump address, and thus modifying the immediate number of the jump instruction based on the target immediate number can increase the probability that the jump instruction jumps to a reasonable range, enabling the verification to cover all modules of the processor as much as possible.
[0094] Optionally, the instruction information of the jump instruction includes: the number of the jump instruction; step 208 may specifically include:
[0095] Sub-step 2081: Perform a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and perform a product operation on the second difference and the first difference to obtain a first product result;
[0096] Sub-step 2082: Perform a subtraction operation on the target jump address and the first product result, and perform a division operation on the subtraction result and the first difference, and determine the division result as the target immediate value.
[0097] For sub-step 2081 - sub-step 2082, taking the number of the jump instruction as 51 as an example, the second difference of the jump instruction is 50, and multiplying the second difference by 4 gives a first product result of 200. Then, subtract 200 from the target jump address 396 and divide by 4 to obtain the target immediate value 49. Taking the number of the jump instruction as 80 as an example, the second difference of the jump instruction is 79, and multiplying the second difference by 4 gives a first product result of 316. Then, subtract 316 from the target jump address 0 and divide by 4 to obtain the target immediate value -79.
[0098] Optionally, the method further includes:
[0099] Step 209: When the candidate jump address of the jump instruction meets the constraint condition, determine the candidate jump address of the jump instruction as the target jump address of the jump instruction.
[0100] Exemplarily, when the lower limit of the constraint condition is 0 and the upper limit is 396, when the candidate jump address of the jump instruction is greater than or equal to 0 and less than or equal to 396, it is determined that the candidate jump address of the jump instruction meets the constraint condition, and the candidate jump address of the jump instruction is determined as the target jump address of the jump instruction.
[0101] Exemplarily, taking the number of the jump instruction as 27 as an example, the decimal candidate jump address of the jump instruction is 152, and this value is greater than 0 and less than 396. Therefore, the candidate jump address 152 of the jump instruction is the target jump address of the jump instruction.
[0102] In summary, in the embodiments of the present application, according to the first difference between the addresses of adjacent instructions in the instruction stream, the instruction information of the jump instructions in the instruction stream, and the number of instructions in the instruction stream, determine the candidate jump address of the jump instruction and the constraint conditions for the jump addresses of all jump instructions. When the candidate jump address of the jump instruction does not meet the constraint conditions, determine the jump address range according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream. When the candidate jump address of the jump instruction in the present application does not meet the constraint conditions, that is, it is not within a reasonable range, re-determine the jump address range of the jump instruction. And determine the target jump address of the jump instruction from the jump address range, and when executing the jump instruction, perform an instruction jump according to the target jump address, which can increase the probability that the jump instruction jumps to a reasonable range and enable the verification to cover all modules of the processor as much as possible.
[0103] Figure 3It is a block diagram of a device 30 for selecting a jump address of a jump instruction provided by an embodiment of the present application. The device includes:
[0104] A generation module 301, configured to generate an instruction stream, determine instruction information of a jump instruction in the instruction stream, and determine a first difference between addresses of adjacent instructions in the instruction stream;
[0105] A calculation module 302, configured to determine a candidate jump address of the jump instruction and constraint conditions for jump addresses of all the jump instructions according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream;
[0106] A judgment module 303, configured to determine a jump address range according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream when the candidate jump address of the jump instruction does not meet the constraint conditions;
[0107] An execution module 304, configured to determine a target jump address of the jump instruction from the jump address range, and perform an instruction jump according to the target jump address when executing the jump instruction.
[0108] Optionally, the instruction information of the jump instruction includes: an immediate value of the jump instruction and a number of the jump instruction; the immediate value is used to represent an offset of the jump address; the number of the jump instruction is used to represent an order in which the jump instruction is generated in the instruction stream;
[0109] The calculation module includes:
[0110] A first subtraction and multiplication sub-module, configured to perform a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and perform a multiplication operation on the second difference and the first difference to obtain a first multiplication result;
[0111] A multiplication sub-module, configured to perform a multiplication operation on the immediate value of the jump instruction and the first difference to obtain a second multiplication result;
[0112] A first addition sub-module, configured to perform an addition operation on the first multiplication result and the second multiplication result, and determine the addition result as a decimal candidate jump address of the jump instruction.
[0113] Optionally, the calculation module includes:
[0114] A second subtraction and multiplication sub-module, configured to perform a subtraction operation on the number of instructions in the instruction stream and a first preset value to obtain a third difference, and perform a multiplication operation on the third difference and the first difference to obtain a third multiplication result;
[0115] A determination sub-module, configured to determine the second preset value as the lower limit of the constraint condition, and determine the third product result as the upper limit of the constraint condition;
[0116] The apparatus further includes:
[0117] A first determination module, configured to determine that the candidate jump address of the jump instruction does not meet the constraint condition when the candidate jump address of the jump instruction is less than or equal to the lower limit of the constraint condition, or greater than or equal to the upper limit of the constraint condition.
[0118] Optionally, the instruction information of the jump instruction includes: the number of the jump instruction;
[0119] The judgment module includes:
[0120] A third subtraction and multiplication sub-module, configured to perform a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and perform a multiplication operation on the second difference and the first difference to obtain a first product result;
[0121] A fourth subtraction and multiplication sub-module, configured to perform a subtraction operation on the number of instructions in the instruction stream and the number of the jump instruction to obtain a fourth difference, and perform a multiplication operation on the fourth difference and the first difference to obtain a fourth product result;
[0122] A first determination sub-module, configured to determine the opposite value of the first product result as the lower limit of the jump address range, and determine the fourth product result as the upper limit of the jump address range.
[0123] Optionally, the instruction information of the jump instruction includes: the number of the jump instruction;
[0124] The execution module includes:
[0125] A fifth subtraction and multiplication sub-module, configured to perform a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and perform a multiplication operation on the second difference and the first difference to obtain a first product result;
[0126] A second determination sub-module, configured to randomly select a jump address from the jump address range, and determine the jump address as the migration address; the migration address is used to represent the offset of the jump address;
[0127] A second addition sub-module, configured to perform an addition operation on the first product result and the migration address, and determine the addition result as the target jump address in decimal.
[0128] Optionally, the apparatus further includes:
[0129] A modification module, configured to obtain a target immediate value of the jump instruction according to the target jump address, and modify the immediate value of the jump instruction to the target immediate value.
[0130] Optionally, the instruction information of the jump instruction includes: the number of the jump instruction;
[0131] The modification module includes:
[0132] A sixth subtraction and multiplication sub-module, configured to perform a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and perform a multiplication operation on the second difference and the first difference to obtain a first multiplication result;
[0133] A subtraction and division sub-module, configured to perform a subtraction operation on the target jump address and the first multiplication result, and perform a division operation on the subtraction result and the first difference, and determine the division result as the target immediate value.
[0134] Optionally, the generation module includes:
[0135] An acquisition sub-module, configured to acquire the name of an instruction in the instruction stream;
[0136] A third determination sub-module, configured to determine the instruction as the jump instruction if the name of the instruction is in a preset set; the preset set records the names of the jump instructions.
[0137] Optionally, the apparatus further includes:
[0138] A second determination module, configured to determine the candidate jump address of the jump instruction as the target jump address of the jump instruction when the candidate jump address of the jump instruction meets the constraint condition.
[0139] In summary, in the embodiments of the present application, according to the first difference between the addresses of adjacent instructions in the instruction stream, the instruction information of the jump instructions in the instruction stream, and the number of instructions in the instruction stream, the candidate jump address of the jump instruction and the constraint condition for the jump addresses of all jump instructions are determined. When the candidate jump address of the jump instruction does not meet the constraint condition, the jump address range is determined according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream. When the candidate jump address of the jump instruction does not meet the constraint condition, that is, it is not within a reasonable range, the jump address range of the jump instruction is re-determined. And from the jump address range, the target jump address of the jump instruction is determined, and when the jump instruction is executed, the instruction jump is performed according to the target jump address, which can increase the probability that the jump instruction jumps to a reasonable range, and enable the verification to cover all modules of the processor as much as possible.
[0140] For the apparatus embodiments, since they are substantially similar to the method embodiments, they are described relatively simply, and for the relevant parts, reference may be made to the descriptions of the method embodiments.
[0141] Each embodiment in this specification is described in a progressive manner. Each embodiment focuses on the differences from other embodiments, and for the same or similar parts among the embodiments, reference may be made to each other.
[0142] Regarding the apparatus in the above embodiments, the specific manners in which each module performs operations have been described in detail in the embodiments related to the method, and will not be elaborated herein.
[0143] An embodiment of the present application provides a device for selecting a jump address of a jump instruction, including a memory, and more than one program, where the more than one program is stored in the memory and is configured to be executed by more than one processor. The more than one program includes instructions for performing the method described in the above one or more embodiments.
[0144] Figure 4 FIG. 13 is a block diagram of an electronic device 400 shown according to an exemplary embodiment. For example, the electronic device 400 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0145] Refer to Figure 4 , the electronic device 400 may include one or more of the following components: a processing component 402, a memory 404, a power supply component 406, a multimedia component 408, an audio component 410, an input / output (I / O) interface 412, a sensor component 414, and a communication component 416.
[0146] The processing component 402 generally controls the overall operation of the electronic device 400, such as operations associated with display, telephone call, data communication, camera operation, and recording operation. The processing component 402 may include one or more processors 420 to execute instructions to complete all or part of the steps of the above method. In addition, the processing component 402 may include one or more modules to facilitate the interaction between the processing component 402 and other components. For example, the processing component 402 may include a multimedia module to facilitate the interaction between the multimedia component 408 and the processing component 402.
[0147] The memory 404 is used to store various types of data to support the operation of the electronic device 400. Examples of such data include instructions for any application or method operating on the electronic device 400, contact data, phone book data, messages, pictures, multimedia, and the like. The memory 404 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, a magnetic disk, or an optical disk.
[0148] The power supply component 406 provides power for various components of the electronic device 400. The power supply component 406 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 400.
[0149] The multimedia component 408 includes a screen that provides an output interface between the electronic device 400 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can not only sense the boundaries of touch or swipe actions but also detect the duration and pressure associated with the touch or swipe operation. In some embodiments, the multimedia component 408 includes a front camera and / or a rear camera. When the electronic device 400 is in an operating mode, such as a shooting mode or a multimedia mode, the front camera and / or the rear camera can receive external multimedia data. Each of the front camera and the rear camera can be a fixed optical lens system or have a focal length and optical zoom capabilities.
[0150] The audio component 410 is used to output and / or input audio signals. For example, the audio component 410 includes a microphone (MIC) that is used to receive external audio signals when the electronic device 400 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals can be further stored in the memory 404 or transmitted via the communication component 416. In some embodiments, the audio component 410 further includes a speaker for outputting audio signals.
[0151] The I / O interface 412 provides an interface between the processing component 402 and a peripheral interface module, and the peripheral interface module can be a keyboard, a click wheel, buttons, etc. These buttons can include, but are not limited to: a home button, a volume button, a start button, and a lock button.
[0152] The sensor assembly 414 includes one or more sensors for providing a status assessment of various aspects for the electronic device 400. For example, the sensor assembly 414 can detect the on / off state of the electronic device 400, the relative positioning of components, such as the display and keypad of the electronic device 400. The sensor assembly 414 can also detect a change in the position of the electronic device 400 or a component of the electronic device 400, the presence or absence of user contact with the electronic device 400, the orientation or acceleration / deceleration of the electronic device 400, and the temperature change of the electronic device 400. The sensor assembly 414 can include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 414 can also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 414 can also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0153] The communication component 416 is used to facilitate communication between the electronic device 400 and other devices in a wired or wireless manner. The electronic device 400 can access a wireless network based on communication standards, such as WiFi, a carrier network (such as 2G, 3G, 4G, or 5G), or a combination thereof. In an exemplary embodiment, the communication component 416 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 416 further includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0154] In an exemplary embodiment, the electronic device 400 can be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components for implementing the methods provided in the embodiments of the present application.
[0155] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 404 including instructions, and the above instructions can be executed by the processor 420 of the electronic device 400 to complete the above methods. For example, the non-transitory storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device, etc.
[0156] Figure 5is a block diagram of an electronic device 500 shown in accordance with an exemplary embodiment. For example, the electronic device 500 may be provided as a server. Referring to Figure 5 , the electronic device 500 includes a processing component 522, which further includes one or more processors, and memory resources represented by a memory 532 for storing instructions executable by the processing component 522, such as application programs. The application programs stored in the memory 532 may include one or more modules each corresponding to a set of instructions. In addition, the processing component 522 is configured to execute the instructions to perform the method provided in the embodiments of the present application.
[0157] The electronic device 500 may also include a power component 526 configured to perform power management of the electronic device 500, a wired or wireless network interface 550 configured to connect the electronic device 500 to a network, and an input / output (I / O) interface 558. The electronic device 500 may operate based on an operating system stored in the memory 532, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSD TM or the like.
[0158] The embodiments of the present application also provide a computer program product, including a computer program, where the computer program, when executed by a processor, implements the method described in the above embodiments.
[0159] Those skilled in the art will readily conceive of other implementations of the present application after considering the specification and practicing the application disclosed herein. The present application is intended to cover any variations, uses, or adaptations of the present application, which follow the general principles of the present application and include known common knowledge or conventional technical means in the technical field not disclosed in the present disclosure. The specification and embodiments are to be considered as exemplary only, and the true scope and spirit of the present application are pointed out by the following claims.
[0160] It should be understood that the present application is not limited to the exact structures described above and shown in the drawings, and various modifications and changes may be made without departing from its scope. The scope of the present application is only limited by the appended claims.
Claims
1. A method for selecting the jump address of a jump instruction, characterized in that The method includes: generating an instruction stream, determining instruction information of jump instructions in the instruction stream, and determining a first difference between addresses of adjacent instructions in the instruction stream; determining a candidate jump address of the jump instruction and constraint conditions for jump addresses of all the jump instructions according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream; when the candidate jump address of the jump instruction does not meet the constraint conditions, determining a jump address range according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream; determining a target jump address of the jump instruction from the jump address range, and when executing the jump instruction, performing an instruction jump according to the target jump address; the instruction information of the jump instruction includes: the number of the jump instruction; determining the jump address range according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream includes: performing a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and performing a multiplication operation on the second difference and the first difference to obtain a first product result; the first preset value is used to represent a difference between a start address of the instruction stream and a start number of instructions in the instruction stream; performing a subtraction operation on the number of instructions in the instruction stream and the number of the jump instruction to obtain a fourth difference, and performing a multiplication operation on the fourth difference and the first difference to obtain a fourth product result; determining an opposite value of the first product result as a lower limit of the jump address range, and determining the fourth product result as an upper limit of the jump address range.
2. The method according to claim 1, wherein the instruction information of the jump instruction includes: an immediate value of the jump instruction; the immediate value is used to represent an offset of the jump address; the number of the jump instruction is used to represent an order in which the jump instruction is generated in the instruction stream; determining the candidate jump address of the jump instruction according to the first difference and the instruction information of the jump instruction includes: performing a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and performing a multiplication operation on the second difference and the first difference to obtain a first product result; performing a multiplication operation on the immediate value of the jump instruction and the first difference to obtain a second product result; performing an addition operation on the first product result and the second product result, and determining the addition result as a decimal candidate jump address of the jump instruction.
3. The method according to claim 1, wherein determining the constraint conditions for jump addresses of all the jump instructions according to the first difference and the number of instructions in the instruction stream includes: performing a subtraction operation on the number of instructions in the instruction stream and a first preset value to obtain a third difference, and performing a multiplication operation on the third difference and the first difference to obtain a third product result; determining a second preset value as a lower limit of the constraint conditions, and determining the third product result as an upper limit of the constraint conditions; The method further includes: When the candidate jump address of the jump instruction is less than or equal to the lower limit of the constraint condition, or greater than or equal to the upper limit of the constraint condition, it is determined that the candidate jump address of the jump instruction does not meet the constraint condition.
4. The method according to claim 1, characterized in that, Determining the target jump address of the jump instruction from the range of jump addresses includes: Performing a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and performing a multiplication operation on the second difference and the first difference to obtain a first multiplication result; Randomly selecting a jump address from the range of jump addresses and determining the jump address as the migration address; the migration address is used to represent the offset of the jump address; Performing an addition operation on the first multiplication result and the migration address, and determining the addition result as the target jump address in decimal.
5. The method according to claim 1, wherein After determining the target jump address of the jump instruction from the range of jump addresses, the method further includes: Obtaining the target immediate value of the jump instruction according to the target jump address, and modifying the immediate value of the jump instruction to the target immediate value.
6. The method according to claim 5, characterized in that Obtaining the target immediate value of the jump instruction according to the target jump address includes: Performing a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and performing a multiplication operation on the second difference and the first difference to obtain a first multiplication result; Performing a subtraction operation on the target jump address and the first multiplication result, and performing a division operation on the subtraction result and the first difference, and determining the division result as the target immediate value.
7. The method according to claim 1, characterized in that, Determining the jump instruction in the instruction stream includes: Obtaining the name of the instruction in the instruction stream; If the name of the instruction is in the preset set, determining that the instruction is the jump instruction; the preset set records the names of the jump instructions.
8. The method according to claim 1, wherein The method further includes: When the candidate jump address of the jump instruction meets the constraint condition, determining the candidate jump address of the jump instruction as the target jump address of the jump instruction.
9. A selection device for the jump address of a jump instruction, characterized in that The device includes: A generation module, configured to generate an instruction stream, determine the instruction information of the jump instruction in the instruction stream, and determine a first difference between the addresses of adjacent instructions in the instruction stream; A calculation module, configured to determine the candidate jump address of the jump instruction and the constraint condition for the jump addresses of all the jump instructions according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream; A judgment module, configured to determine a range of jump addresses according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream when the candidate jump address of the jump instruction does not meet the constraint condition; An execution module, configured to determine the target jump address of the jump instruction from the range of jump addresses, and perform an instruction jump according to the target jump address when executing the jump instruction; The instruction information of the jump instruction includes: the number of the jump instruction; the judgment module includes: A first calculation sub-module, configured to perform a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and perform a multiplication operation on the second difference and the first difference to obtain a first multiplication result; the first preset value is used to represent the difference between the starting address of the instruction stream and the starting number of the instructions in the instruction stream; A second calculation sub-module, configured to perform a subtraction operation on the number of instructions in the instruction stream and the number of the jump instruction to obtain a fourth difference, and perform a multiplication operation on the fourth difference and the first difference to obtain a fourth multiplication result; A determination sub-module, configured to determine the opposite value of the first multiplication result as the lower limit of the jump address range, and determine the fourth multiplication result as the upper limit of the jump address range.
10. An electronic device, characterized in that, Comprising: A processor; A memory for storing instructions executable by the processor; Wherein, the processor is configured to execute the instructions to implement the method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, When the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is enabled to execute the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Instruction processing method and device, electronic equipment and readable storage medium
CN118626153A