Method and device for selecting jump address of jump instruction, equipment and storage medium

By calculating the candidate addresses and constraints of the jump instructions during the processor verification process and redetermining the jump address range, the problem of the jump address being stuck due to the CPU running beyond the reasonable range is solved, and the probability of verification coverage is increased.

CN119718425AActive Publication Date: 2025-03-28BEIJING INSTITUTE OF OPEN SOURCE CHIP

Patent Information

Application Number
CN202510237746.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-28
Publication Date
2025-03-28
Estimated Expiration
2045-02-28

AI Technical Summary

Technical Problem

During the processor verification process, if the jump address of the jump instruction exceeds the reasonable range of the instruction flow, the CPU will be stuck and the verification will not be possible.

Method used

By generating an instruction stream and determining a first difference between adjacent instruction addresses, the candidate jump address and constraints of the jump instruction are calculated. When the candidate address does not meet the constraints, redetermine the jump address range and select the target jump address from the range for instruction jump.

Benefits of technology

Increases the probability of jumping instructions to a reasonable range, ensuring that verification can cover all modules of the processor and prevents CPU from running stuck.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718425A_ABST
    Figure CN119718425A_ABST
Patent Text Reader

Abstract

The invention provides a jump instruction jump address selection method and device, electronic equipment and a computer readable storage medium, and the method comprises the steps: generating an instruction stream, determining instruction information of a jump instruction in the instruction stream, determining a first difference value between addresses of adjacent instructions in the instruction stream, and according to the first difference value and the instruction information of the jump instruction, selecting a jump address of the jump instruction, determining candidate jump addresses of the jump instructions and constraint conditions for the jump addresses of all the jump instructions according to the instruction information of the jump instructions and the number of the instructions in the instruction stream, and when the candidate jump addresses of the jump instructions do not conform to the constraint conditions, determining a jump address range according to the first difference value, the instruction information of the jump instructions and the number of the instructions in the instruction stream, and determining a target jump address of the jump instruction from the jump address range, and performing instruction jump according to the target jump address when the jump instruction is executed. The probability that the jump instruction jumps to a reasonable range can be improved, and verification covers all modules of the processor as much as possible.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of integrated circuit technology, and in particular to a method, device, electronic device and computer-readable storage medium for selecting a jump address of a jump instruction. Background Art

[0002] During the verification phase of the CPU (Central Processing Unit) core, an instruction stream is generated by an instruction generator, and each instruction in the instruction stream is often used to verify the CPU module.

[0003] During the verification process, the instruction stream usually includes a large number of instructions, such as immediate jump instructions. After generating the immediate jump instruction, the related technology calculates the jump address of the jump instruction and performs the instruction jump according to the jump address.

[0004] If a jump instruction is executed during verification and the jump address of the jump instruction is outside the reasonable range of the instruction stream, the CPU pointer will point to an address without an instruction, causing the entire CPU to freeze and the CPU module to be unable to continue verification. Summary of the invention

[0005] The embodiments of the present application provide a method, device, 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 the present application provides a method for selecting a jump address of a jump instruction, the method comprising: 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; Determine, according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream, a candidate jump address of the jump instruction and a constraint condition for the jump addresses of all the jump instructions; When the candidate jump address of the jump instruction does not meet the constraint condition, 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; A target jump address of the jump instruction is determined from the jump address range, and when the jump instruction is executed, the instruction jump is performed according to the target jump address.

[0007] In a second aspect, an embodiment of the present application provides a device for selecting a jump address of a jump instruction, the device comprising: A generating module, used for generating an instruction stream, determining instruction information of a jump instruction in the instruction stream, and determining a first difference between addresses of adjacent instructions in the instruction stream; a calculation module, configured to determine, according to the first difference, instruction information of the jump instruction, and the number of instructions in the instruction stream, a candidate jump address of the jump instruction and a constraint condition for the jump addresses of all the jump instructions; A judgment module, configured to determine a jump address range according to the first difference, 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; The execution module is used to determine the target jump address of the jump instruction from the jump address range, and perform instruction jump according to the target jump address when executing the jump instruction.

[0008] In a third aspect, an embodiment of the present application further provides an electronic device, comprising a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the method of the first aspect.

[0009] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, which, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to execute the method of the first aspect.

[0010] In an 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 instruction 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, according to the first difference, the instruction information of the jump instruction and the number of instructions in the instruction stream, determine the jump address range. The present application re-determines the jump address range of the jump instruction when the candidate jump address of the jump instruction does not meet the constraint conditions, that is, not within a reasonable range. And from the jump address range, determine the target jump address of the jump instruction, and when executing the jump instruction, perform instruction jump according to the target jump address, can improve the probability that the jump instruction jumps to a reasonable range, make verification cover all modules of the processor as much as possible.

[0011] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0013] Figure 1 It is a flowchart of the steps of a method for selecting a jump address of a jump instruction provided in an embodiment of the present application; Figure 2 It is a flowchart of the specific steps of a method for selecting a jump address of a jump instruction provided in an embodiment of the present application; Figure 3 It is a block diagram of a device for selecting a jump address of a jump instruction provided in an embodiment of the present application; Figure 4 is a block diagram of an electronic device provided in an embodiment of the present application; Figure 5 It is a block diagram of another electronic device according to another embodiment of the present application. DETAILED DESCRIPTION

[0014] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0015] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally a class, 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 specification and claims is used to describe the association relationship of associated objects, indicating that three kinds of relationships can exist, for example, A and / or B can be represented: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the front and back associated objects are a kind of "or" relationship. In the embodiment of the present application, the term "multiple" refers to two or more, and other quantifiers are similar.

[0016] Figure 1 is a flowchart of a method for selecting a jump address of a jump instruction provided in an embodiment of the present application. Figure 1 As shown, the method may include: Step 101: 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.

[0017] For example, each instruction in the instruction stream is an instruction in the instruction set of the processor, for example, it may be an addition instruction, a subtraction instruction, a write instruction, a read instruction, a jump instruction, and other instructions.

[0018] For example, a jump instruction can be an immediate-addressed jump instruction or a register-addressed jump instruction, and the target jump address of the jump instruction is the sum of the base address and the address offset. In an immediate-addressed jump instruction, the jump instruction includes an immediate number, which is used to represent the offset of the jump address, and the base address is the address of the jump instruction, which is the address allocated to the jump instruction in the process of generating the jump instruction. In a register-addressed 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.

[0019] For example, the instruction information of the jump instruction may include: the number of the jump instruction and the immediate value of the jump instruction. For example, when the instruction generator generates an instruction stream, each instruction generated records the serial number of the instruction. For the jump instruction, the serial number of the jump instruction is the number of the jump instruction. The immediate value of the jump instruction is a value randomly generated according to the fixed position encoding of the instruction code of the jump instruction, which is used to represent the offset of the jump address.

[0020] For example, 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 the difference may be predetermined.

[0021] Step 102: Determine candidate jump addresses of the jump instructions and constraints for jump addresses of all the jump instructions based on the first difference, instruction information of the jump instructions, and the number of instructions in the instruction stream.

[0022] For example, the instruction information of a jump instruction includes: the number of the jump instruction and the immediate value of the jump instruction. Assuming that the 27th instruction is an immediate jump instruction, and the immediate value in the immediate jump instruction is binary 1010, the number of the immediate jump instruction is 27, and the decimal number corresponding to the immediate value of the immediate jump instruction is 12, and the instruction information of the jump instruction includes 27 and 12. Assuming that the 51st instruction is an immediate jump instruction, and the immediate value in the immediate jump instruction is binary 111110111110, the number of the immediate jump instruction is 51, and the decimal number corresponding to the immediate value of the immediate jump instruction is -66, and the instruction information of the jump instruction includes 51 and -66. Assuming that the 80th instruction is an immediate jump instruction, and the immediate number in the immediate jump instruction is binary 11111, the number of the immediate jump instruction is 80, the decimal number corresponding to the immediate number of the immediate jump instruction is 31, and the instruction information of the jump instruction includes 80 and 31.

[0023] For example, the present application calculates the candidate jump address of the jump instruction based on the first difference and the instruction information of the jump instruction. Further, the candidate jump address of the jump instruction is calculated based on the first difference, the number of the jump instruction and the immediate number of the jump instruction. For example, the calculation formula is: candidate jump address = (number of jump instruction-1) × first difference + immediate number of jump instruction × first difference. Assuming that the number of the immediate jump instruction is 27, the decimal number corresponding to the immediate number of the immediate jump instruction is 12, and the first difference is 4, then the candidate jump address of the immediate jump instruction is (27-1) × 4 + 12 × 4 = 152. Assuming that the number of the immediate jump instruction is 51, the decimal number corresponding to the immediate number of the immediate jump instruction is -66, and the first difference is 4, then the candidate jump address of the immediate jump instruction is (51-1) × 4 + (-66) × 4 = -64. Assume that the number of the immediate jump instruction is 80, the decimal number corresponding to the immediate number of the immediate jump instruction is 31, and the first difference is 4, then the candidate jump address of the immediate jump instruction is (80-1)×4+31×4=480.

[0024] For example, since the jump address calculated according to the immediate number of the jump instruction may not be within the reasonable range of the instruction stream, the present application determines the constraints 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 addresses of the jump instructions are within the constraints according to the constraints. If the candidate jump address of the jump instruction is within the constraints, it means that the immediate number of the randomly generated jump instruction is reasonable, and the target jump address can be calculated based on the immediate number. If the candidate jump address of the jump instruction is not within the constraints, it means that the immediate number of the randomly generated jump instruction is unreasonable, and it needs to be adjusted so that the jump address of the jump instruction is within the reasonable range of the instruction stream.

[0025] Step 103: 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.

[0026] For example, the candidate jump address of the jump instruction does not meet the constraint condition, that is, the candidate jump address of the jump instruction is not within the constraint condition. The jump address range is used to reflect the address offset that can be selected by the jump instruction.

[0027] For example, assuming that the number of the immediate jump instruction is 80, the decimal number corresponding to the immediate number of the immediate jump instruction is 31, and the first difference is 4, then the candidate jump address of the immediate 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 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. For example, the calculation formula is: the jump address range can be [-(the number of jump instructions-1)×the first difference, (the number of instructions in the instruction stream-the number of jump instructions)×the first difference]. Assuming that the number of the immediate jump instruction is 80, the decimal number corresponding to the immediate number of the immediate jump instruction is 31, and the first difference is 4, then the jump address range of the immediate jump instruction is [-79×4, 20×4].

[0028] For example, assuming that the number of the immediate jump instruction is 51, the decimal number corresponding to the immediate number of the immediate jump instruction is -66, and the first difference is 4, then the candidate jump address of the 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 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. For example, the calculation formula is: the jump address range can be [-(the number of jump instructions-1)×the first difference, (the number of instructions in the instruction stream-the number of jump instructions)×the first difference]. Assuming that the number of the immediate jump instruction is 51, the decimal number corresponding to the immediate number of the immediate jump instruction is -66, and the first difference is 4, then the jump address range of the immediate jump instruction is [-50×4, 49×4].

[0029] Step 104: 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.

[0030] For example, the jump address range gives the range of the migration address of the jump instruction. After obtaining the jump address range, a jump address is selected from the jump address range as the migration address of the jump instruction, and then the target jump address of the jump address is obtained according to the migration address and the base address of the jump address.

[0031] For example, assume that the number of the immediate jump instruction is 80, the decimal number corresponding to the immediate number of the immediate jump instruction is 31, the first difference is 4, and the jump address range of the immediate jump instruction is [-79×4, 20×4]. From the jump address range [-79×4, 20×4], select a jump address as the migration address of the jump instruction numbered 80. Take 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.

[0032] For example, assume that the number of the immediate jump instruction is 51, the decimal number corresponding to the immediate number of the immediate jump instruction is -66, the first difference is 4, and the jump address range of the immediate jump instruction is [-50×4, 49×4]. From the jump address range [-50×4, 49×4], select a jump address as the migration address of the jump instruction numbered 51. Take 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.

[0033] For example, each instruction in the instruction set can be generated, and the execution of the instruction can be simulated to obtain the corresponding target result. During the running of the test program, when a certain instruction is executed, the actual result of the instruction execution process can be obtained, and the actual result can be compared with the target result to verify whether the various functions of the processor are normal.

[0034] In summary, in an 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 instruction 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, according to the first difference, the instruction information of the jump instruction and the number of instructions in the instruction stream, determine the jump address range. The present application re-determines the jump address range of the jump instruction when the candidate jump address of the jump instruction does not meet the constraint conditions, that is, it is not within a reasonable range. And from the jump address range, determine the target jump address of the jump instruction, and when executing the jump instruction, perform instruction jump according to the target jump address, which can improve the probability that the jump instruction jumps to a reasonable range, so that verification covers all modules of the processor as much as possible.

[0035] Figure 2 is a flowchart of the specific steps of a method for selecting a jump address of a jump instruction provided in an embodiment of the present application, such as Figure 2 As shown, the method may include: Step 201: 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.

[0036] This step may specifically refer to the above step 101, and will not be described in detail here.

[0037] Optionally, step 201 may specifically include: Sub-step 2011, obtaining the name of the instruction in the instruction stream; 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 name of the jump instruction.

[0038] For sub-steps 2011 and 2012, the preset set may be a SET_IJ set. In the process of generating the instruction stream, the name of each instruction is recorded, and whether the instruction is an immediate jump instruction is determined based on whether the name of the instruction is in the SET_IJ set. For example, the SET_IJ set includes two immediate jump instructions, namely JPI and BHI. Based on whether the name of the instruction is JPI or BHI, it is determined whether the instruction is an immediate jump instruction.

[0039] For example, if the name of the instruction is in the SET_IJ set, the instruction is judged to be an immediate jump instruction, and if the name of the instruction is not in the SET_IJ set, the instruction is judged not to be an immediate jump instruction. For example, the SET_IJ set includes two immediate jump instructions, JPI and BHI. If the name of the instruction is JPI or BHI, the instruction is an immediate jump instruction, otherwise, the instruction is not an immediate jump instruction.

[0040] For example, when generating an instruction stream, if it is determined that the instruction is an immediate jump instruction, the serial number of the instruction can be marked, and further, the serial number of the instruction can be marked as is_IJ. Thus, it can be determined whether the instruction is an immediate jump instruction based on whether there is an is_IJ flag in the serial number.

[0041] Step 202: subtract the jump instruction number from a first preset value to obtain a second difference, and multiply the second difference by the first difference to obtain a first product result; the instruction information of the jump instruction includes: the jump instruction number; the jump instruction number is used to characterize the order in which the jump instructions are generated in the instruction stream.

[0042] For example, the number of the jump instruction may 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 jump instruction is 27, then the number of the jump instruction is 27.

[0043] For example, the first difference is the difference between the addresses of any two adjacent instructions in the instruction stream, which may be preset. For example, the first difference may be 4.

[0044] For example, the first preset value is used to characterize 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, the first preset value is 1. The first product result is used to characterize 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, the jump instruction number 27 is subtracted from the first preset value 1 to obtain the second difference 26, and then the second difference 26 is multiplied 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.

[0045] Step 203, multiplying 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.

[0046] For example, the immediate number 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 that the immediate number in the jump instruction is binary 1010, the binary number is converted to a decimal number to obtain a value of 12. Then, the decimal immediate number 12 contained in the jump instruction is multiplied by the first difference 4 to obtain a second product result 48, that is, the specific offset address of the jump instruction is 48.

[0047] Step 204: perform a sum operation on the first multiplication result and the second multiplication result, and determine the sum result as a decimal candidate jump address of the jump instruction.

[0048] For example, taking the jump instruction numbered 27 as an example, the first product result is 104, the second product result is 48, and then the first product result and the second product result are added to obtain the decimal candidate jump address 152 of the jump instruction.

[0049] Step 205: Determine the constraints on the jump addresses of all the jump instructions according to the first difference and the number of instructions in the instruction stream.

[0050] This step may be specifically referred to as the above step 102, and will not be described in detail here.

[0051] Optionally, step 205 may specifically include: Sub-step 2051: 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 product operation on the third difference and the first difference to obtain a third product result; Sub-step 2052: determining the second preset value as the lower limit of the constraint condition, and determining the third product result as the upper limit of the constraint condition; The method further comprises: 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.

[0052] For sub-steps 2051-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, which is the upper limit of the constraint condition. For example, the number of instructions in the instruction stream is 100, the first preset value is 1, and the third difference is 99. Then, the third difference is multiplied by the first difference to obtain the third product result 396. At this time, the lower limit of the constraint condition is 0 and the upper limit is 396.

[0053] For example, when the lower limit of the constraint is 0 and the upper limit is 396, when the candidate jump address of the jump instruction is less than or equal to 0, it is determined that the candidate jump address of the jump instruction does not meet the constraint; when the candidate jump address of the jump instruction is greater than or equal to 396, it is determined that the candidate jump address of the jump instruction does not meet the constraint.

[0054] 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.

[0055] This step may be specifically referred to as the above step 103, and will not be described in detail here.

[0056] Optionally, the instruction information of the jump instruction includes: the number of the jump instruction; step 206 may specifically include: Sub-step 2061: performing a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and performing a product operation on the second difference and the first difference to obtain a first product result; Sub-step 2062: 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 product operation on the fourth difference and the first difference to obtain a fourth product result; Sub-step 2063: 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.

[0057] For sub-steps 2061 to 2063, taking the jump instruction number 51 and the starting address of the instruction stream as 0 as an example, the jump instruction number 51 is subtracted from the first preset value 1 to obtain a second difference 50, and then the second difference 50 is multiplied by the first difference 4 to obtain a first product result 200. Taking the number of instructions in the instruction stream as 100 as an example, the number of instructions in the instruction stream is 100. The number of jump instructions is subtracted from the jump instruction number 51 to obtain a fourth difference 49, and the fourth difference 49 is multiplied by the first difference 4 to obtain a 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 80 and the starting address of the instruction stream as 0 as an example, the jump instruction number 80 is subtracted from the first preset value 1 to obtain a second difference 79, and then the second difference 79 is multiplied by the first difference 4 to obtain a first product result 316. Taking the number of instructions in the instruction stream as 100 as an example, the number of instructions in the instruction stream is 100. The number of jump instructions is subtracted from the jump instruction number 80 to obtain a fourth difference 20, and the fourth difference 20 is multiplied by the first difference 4 to obtain a 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].

[0058] Step 207: 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.

[0059] This step may be specifically referred to as the above step 104, and will not be described in detail here.

[0060] Optionally, the instruction information of the jump instruction includes: the number of the jump instruction; step 207 may specifically include: Sub-step 2071: performing a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and performing a product operation on the second difference and the first difference to obtain a first product result; Sub-step 2072: randomly selecting a jump address from the jump address range, and determining the jump address as a migration address; the migration address is used to represent the offset of the jump address; Sub-step 2073: perform a sum operation on the first multiplication result and the migration address, and determine the sum result as the decimal target jump address.

[0061] For sub-steps 2071 to 2073, taking the jump instruction number 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.

[0062] For example, 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. When the jump instruction 51 is executed, the instruction jump is performed according to the address corresponding to the target jump address 396.

[0063] For example, taking the jump instruction numbered 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 the jump instruction 51 is executed, the instruction jump is performed according to the address corresponding to the target jump address 0.

[0064] Optionally, after step 207, the method further includes: Step 208: 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.

[0065] For example, in the jump instruction numbered 51, after obtaining the target jump address 396, the target immediate number corresponding to the target jump address is calculated based on the target jump address, and then the immediate number of the jump instruction is modified based on the target immediate number. This can increase the probability that the jump instruction jumps to a reasonable range, so that the verification covers all modules of the processor as much as possible.

[0066] For example, in the jump instruction numbered 80, after obtaining the target jump address 0, the target immediate number corresponding to the target jump address is calculated based on the target jump address, and then the immediate number of the jump instruction is modified based on the target immediate number. This can increase the probability that the jump instruction jumps to a reasonable range, so that the verification covers all modules of the processor as much as possible.

[0067] Optionally, the instruction information of the jump instruction includes: the number of the jump instruction; step 208 may specifically include: Sub-step 2081: performing a subtraction operation on the number of the jump instruction and a first preset value to obtain a second difference, and performing a product operation on the second difference and the first difference to obtain a first product result; Sub-step 2082: subtract the target jump address from the first multiplication result, divide the subtraction result by the first difference, and determine the division result as the target immediate value.

[0068] For sub-steps 2081 and 2082, taking the jump instruction number 51 as an example, the second difference of the jump instruction is 50, and the second difference is multiplied by 4 to obtain a first product result of 200, then the target jump address 396 is subtracted from 200, and then divided by 4 to obtain the target immediate number 49. Taking the jump instruction number 80 as an example, the second difference of the jump instruction is 79, and the second difference is multiplied by 4 to obtain a first product result of 316, then the target jump address 0 is subtracted from 316, and then divided by 4 to obtain the target immediate number -79.

[0069] Optionally, the method further includes: 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.

[0070] 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 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.

[0071] For example, taking the jump instruction numbered 27 as an example, the decimal candidate jump address of the jump instruction is 152, which 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.

[0072] In summary, in an 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 instruction 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, according to the first difference, the instruction information of the jump instruction and the number of instructions in the instruction stream, determine the jump address range. The present application re-determines the jump address range of the jump instruction when the candidate jump address of the jump instruction does not meet the constraint conditions, that is, it is not within a reasonable range. And from the jump address range, determine the target jump address of the jump instruction, and when executing the jump instruction, perform instruction jump according to the target jump address, which can improve the probability that the jump instruction jumps to a reasonable range, so that verification covers all modules of the processor as much as possible.

[0073] Figure 3is a block diagram of a jump instruction jump address selection device 30 provided in an embodiment of the present application, the device comprising: A generating 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; A calculation module 302, configured to determine a candidate jump address of the jump instruction and a 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 303, configured to determine a jump address range according to the first difference, 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; The execution module 304 is used to determine the target jump address of the jump instruction from the jump address range, and perform instruction jump according to the target jump address when executing the jump instruction.

[0074] 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 the order in which the jump instruction is generated in the instruction stream; The computing module comprises: A first subtraction-product submodule is used 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 product operation on the second difference and the first difference to obtain a first product result; A product submodule, used for performing a product operation on the immediate value of the jump instruction and the first difference to obtain a second product result; The first adding submodule is used to perform an addition operation on the first product result and the second product result, and determine the addition result as a decimal candidate jump address of the jump instruction.

[0075] Optionally, the computing module includes: A second subtraction-product submodule is used 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 product operation on the third difference and the first difference to obtain a third product result; A determination submodule, 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; The device also includes: The first determination module is used 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.

[0076] Optionally, the instruction information of the jump instruction includes: a number of the jump instruction; The judging module comprises: a third subtraction-product submodule, 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 product operation on the second difference and the first difference to obtain a first product result; a fourth subtraction-product submodule, 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 product operation on the fourth difference and the first difference to obtain a fourth product result; The first determining submodule is used 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.

[0077] Optionally, the instruction information of the jump instruction includes: a number of the jump instruction; The execution module comprises: a fifth subtraction-product submodule, 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 product operation on the second difference and the first difference to obtain a first product result; A second determination submodule is used to randomly select a jump address from the jump address range, and determine the jump address as a migration address; the migration address is used to represent the offset of the jump address; The second adding submodule is used to perform a sum operation on the first multiplication result and the migration address, and determine the sum result as the decimal target jump address.

[0078] Optionally, the device further comprises: The modification module is used to obtain the 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.

[0079] Optionally, the instruction information of the jump instruction includes: a number of the jump instruction; The modification module comprises: a sixth subtraction-product submodule, 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 product operation on the second difference and the first difference to obtain a first product result; The subtraction and division submodule is used to perform a subtraction operation on the target jump address and the first multiplication result, and to perform a division operation on the subtraction result and the first difference, and to determine the division result as the target immediate value.

[0080] Optionally, the generating module includes: An acquisition submodule, used to acquire the name of the instruction in the instruction stream; The third determination submodule is used to determine that the instruction is the jump instruction if the name of the instruction is in a preset set; the preset set records the name of the jump instruction.

[0081] Optionally, the device further comprises: The second determination module is used 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.

[0082] In summary, in an 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 instruction 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, according to the first difference, the instruction information of the jump instruction and the number of instructions in the instruction stream, determine the jump address range. The present application re-determines the jump address range of the jump instruction when the candidate jump address of the jump instruction does not meet the constraint conditions, that is, it is not within a reasonable range. And from the jump address range, determine the target jump address of the jump instruction, and when executing the jump instruction, perform instruction jump according to the target jump address, which can improve the probability that the jump instruction jumps to a reasonable range, so that verification covers all modules of the processor as much as possible.

[0083] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0084] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0085] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0086] An embodiment of the present application provides a device for selecting a jump address of a jump instruction, comprising a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors to include methods for performing one or more of the methods described in the above-mentioned embodiments.

[0087] Figure 4 4 is a block diagram of an electronic device 400 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.

[0088] Reference Figure 4 , the electronic device 400 may include one or more of the following components: a processing component 402 , a memory 404 , a power 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 .

[0089] The processing component 402 generally controls the overall operation of the electronic device 400, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. 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-mentioned 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.

[0090] 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, etc. 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, magnetic disk or optical disk.

[0091] The power supply component 406 provides power to the 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 to the electronic device 400.

[0092] 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 may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide 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 may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

[0093] The audio component 410 is used to output and / or input audio signals. For example, the audio component 410 includes a microphone (MIC), and when the electronic device 400 is in an operation mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is used to receive an external audio signal. The received audio signal can be further stored in the memory 404 or sent via the communication component 416. In some embodiments, the audio component 410 also includes a speaker for outputting audio signals.

[0094] I / O interface 412 provides an interface between processing component 402 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.

[0095] The sensor assembly 414 includes one or more sensors for providing various aspects of status assessment for the electronic device 400. For example, the sensor assembly 414 can detect the open / closed state of the electronic device 400, the relative positioning of the components, such as the display and keypad of the electronic device 400, and the sensor assembly 414 can also detect the position change of the electronic device 400 or a component of the electronic device 400, the presence or absence of contact between the user and 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 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 414 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 414 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0096] The communication component 416 is used to facilitate wired or wireless communication between the electronic device 400 and other devices. The electronic device 400 can access a wireless network based on a communication standard, 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 also 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.

[0097] In an exemplary embodiment, the electronic device 400 may 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 to implement the methods provided in the embodiments of the present application.

[0098] 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 instructions can be executed by a processor 420 of an electronic device 400 to perform the above method. 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, an optical data storage device, etc.

[0099] Figure 5 is a block diagram of an electronic device 500 according to an exemplary embodiment. For example, the electronic device 500 may be provided as a server. Figure 5 , the electronic device 500 includes a processing component 522, which further includes one or more processors, and a memory resource represented by a memory 532, for storing instructions that can be executed by the processing component 522, such as an application. The application 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 instructions to perform the method provided in the embodiment of the present application.

[0100] The electronic device 500 may also include a power supply 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 Server TM, Mac OS X TM, Unix TM, Linux TM, FreeBSD TM or the like.

[0101] An embodiment of the present application further provides a computer program product, including a computer program, which implements the method described in the above embodiment when executed by a processor.

[0102] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the application disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0103] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A method for selecting a jump address of a jump instruction, characterized in that: The method comprises: 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; Determine, according to the first difference, the instruction information of the jump instruction, and the number of instructions in the instruction stream, a candidate jump address of the jump instruction and a constraint condition for the jump addresses of all the jump instructions; When the candidate jump address of the jump instruction does not meet the constraint condition, 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; A target jump address of the jump instruction is determined from the jump address range, and when the jump instruction is executed, the instruction jump is performed according to the target jump address.

2. The method according to claim 1, characterized in that 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 the offset of the jump address; the number of the jump instruction is used to represent the order in which the jump instruction is generated in the instruction stream; The step of determining a candidate jump address of the jump instruction according to the first difference and the instruction information of the jump instruction includes: Subtracting the number of the jump instruction from a first preset value to obtain a second difference, and multiplying the second difference by the first difference to obtain a first product result; Perform a product operation on the immediate value of the jump instruction and the first difference to obtain a second product result; The first multiplication result and the second multiplication result are added together, and the addition result is determined as a decimal candidate jump address of the jump instruction.

3. The method according to claim 1, characterized in that Determining 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 includes: Subtracting the number of instructions in the instruction stream from a first preset value to obtain a third difference, and multiplying the third difference by the first difference to obtain a third product result; 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; The method further comprises: 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: The instruction information of the jump instruction includes: the number of the jump instruction; The step of 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: Subtracting the number of the jump instruction from a first preset value to obtain a second difference, and multiplying the second difference by the first difference to obtain a first product result; Subtracting the number of instructions in the instruction stream from the number of the jump instruction to obtain a fourth difference, and multiplying the fourth difference by the first difference to obtain a fourth product result; The opposite value of the first multiplication result is determined as the lower limit of the jump address range, and the fourth multiplication result is determined as the upper limit of the jump address range.

5. The method according to claim 1, characterized in that The instruction information of the jump instruction includes: the number of the jump instruction; Determining the target jump address of the jump instruction from the jump address range includes: Subtracting the number of the jump instruction from a first preset value to obtain a second difference, and multiplying the second difference by the first difference to obtain a first product result; Randomly selecting a jump address from the jump address range, and determining the jump address as a migration address; the migration address is used to represent the offset of the jump address; The first multiplication result and the migration address are summed, and the summed result is determined as the target jump address in decimal.

6. The method according to claim 1, characterized in that After determining the target jump address of the jump instruction from the jump address range, the method further comprises: According to the target jump address, a target immediate number of the jump instruction is obtained, and the immediate number of the jump instruction is modified to the target immediate number.

7. The method according to claim 6, characterized in that The instruction information of the jump instruction includes: the number of the jump instruction; The step of obtaining a target immediate value of the jump instruction according to the target jump address comprises: Subtracting the number of the jump instruction from a first preset value to obtain a second difference, and multiplying the second difference by the first difference to obtain a first product result; A subtraction operation is performed on the target jump address and the first multiplication result, and a division operation is performed on the subtraction result and the first difference value, and the division result is determined as the target immediate value.

8. The method according to claim 1, characterized in that Determining the jump instruction in the instruction stream includes: Obtain the name of the instruction in the instruction stream; If the name of the instruction is in the preset set, it is determined that the instruction is the jump instruction; the preset set records the name of the jump instruction.

9. The method according to claim 1, characterized in that: The method further comprises: When the candidate jump address of the jump instruction meets the constraint condition, the candidate jump address of the jump instruction is determined as the target jump address of the jump instruction.

10. A device for selecting a jump address of a jump instruction, characterized in that: The device comprises: A generating module, used for generating an instruction stream, determining instruction information of a jump instruction in the instruction stream, and determining a first difference between addresses of adjacent instructions in the instruction stream; a calculation module, configured to determine, according to the first difference, instruction information of the jump instruction, and the number of instructions in the instruction stream, a candidate jump address of the jump instruction and a constraint condition for the jump addresses of all the jump instructions; A judgment module, configured to determine a jump address range according to the first difference, 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; The execution module is used to determine the target jump address of the jump instruction from the jump address range, and perform instruction jump according to the target jump address when executing the jump instruction.

11. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method as claimed in any one of claims 1 to 9.

12. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the method as claimed in any one of claims 1 to 9.

Citation Information

Patent Citations

  • Test program generation method and device, equipment and readable storage medium

    CN115017053A

  • Instruction processing method and device, electronic equipment and readable storage medium

    CN118626153A

  • Mitigation of code reuse attacks by restricted indirect branch instruction

    US20190005230A1

Cited By

  • Instant number configuration method and device of jump instruction, equipment and storage medium

    CN119960830A

  • Processor architecture and method based on dynamic overwrite instruction stream

    CN120803536A