A processor and an instruction execution method
By introducing a delay switching unit into the processor, determining the consistency between the execution environment and the resource state, and performing public resource switching when necessary, solving the speed reduction caused by public resource storage and clearing operations when switching the world in the prior art is solved. Problem, improving the processor's response speed.
Patent Information
- Application Number
- CN201910111338.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-02-12
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2039-02-12
AI Technical Summary
In processors, the prior art requires unnecessary public resource storage and clearing operations when switching the world, resulting in a reduced switching speed, especially in interrupt responses with high real-time requirements, which makes it difficult to respond quickly.
A processor instruction execution method is designed to judge the consistency between the current execution environment and the resource state through the delay switching unit, and switch only when the public resource access is involved during the instruction execution process, avoid unnecessary public resource switching and improve switching speed. .
By delaying the timing of public resource switching, the processor's execution environment switching speed is significantly accelerated, unnecessary storage and clearing operations are reduced, and real-time interrupt response is improved.
Smart Images

Figure CN111552514B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of processors, and in particular to the field of core switching in processors. Background Art
[0002] In the field of mobile Internet and Internet of Things, for security reasons, a new trusted world state is added to the processor's operating mode. The processors in the trusted world, the system IP with trusted attributes, and sensitive and important software and hardware resources in other systems are divided into the trusted world. Through hardware mechanisms, it is ensured that the resources in the trusted world can only be accessed by members of the trusted world, thereby achieving isolation between the trusted world and the non-trusted world, ensuring the confidentiality and integrity of security resources.
[0003] The existing method of isolating processor resources is to use two copies of resources, one for the trusted world and one for the untrusted world. However, considering that using two copies of all resources will cause unnecessary waste, it is possible to set up common resources that are shared by the trusted world and the untrusted world.
[0004] When switching worlds in the processor, it is usually necessary to store and clear common resources. If the common resources are not used after switching worlds, the storage and clearing operations when switching worlds are unnecessary and reduce the speed of switching worlds. Especially for interrupts with high real-time requirements, it is particularly important to respond to interrupts quickly.
[0005] To this end, a new processor instruction execution scheme is needed that can achieve more flexible access to public resources to speed up the response when switching worlds. Summary of the invention
[0006] To this end, the present invention provides a new processor and an instruction execution method therein, in an effort to solve or at least alleviate at least one of the above problems.
[0007] According to one aspect of the present invention, a processor is provided. The processor has a trusted execution environment and a non-trusted execution environment, and includes: a public resource that can be accessed in both the trusted execution environment and the non-trusted execution environment; an instruction processing device that is suitable for fetching instructions for decoding and executing the decoded instructions. The instruction processing device also includes a delay switching unit that is suitable for: when the instruction decoding result indicates that the instruction involves access to the public resource, judging the consistency between the current execution environment of the processor and the resource state, and judging that the current execution environment and the resource state are inconsistent, then loading the content corresponding to the current execution environment into the public resource, wherein the resource state indicates the execution environment corresponding to the content in the public resource.
[0008] Optionally, in a processor according to the present invention, the delayed switching unit is suitable for: switching the execution environment of the processor from the current execution environment to a first execution environment corresponding to the resource state when the current execution environment and the resource state are inconsistent; using the storage space in the first execution environment to store the content in the common resource; switching the execution environment of the processor from the first execution environment back to the current execution environment; loading the content from the storage space in the current execution environment into the common resource; and setting the resource state to indicate the current execution environment.
[0009] Optionally, in the processor according to the present invention, the instruction processing device comprises: an instruction fetch unit adapted to fetch instructions; an instruction decoding unit adapted to decode the fetched instructions; and an instruction execution unit adapted to execute the decoded instructions.
[0010] Optionally, in the processor according to the present invention, the instruction processing device also includes: an instruction retirement unit, suitable for storing state information of the current execution environment in a storage space in the current execution environment when the instruction involves switching the execution environment of the processor from the current execution environment to the target execution environment; and setting the current execution environment as the target execution environment so that the execution environment of the processor switches from the current execution environment to the target execution environment.
[0011] Optionally, the processor according to the present invention further comprises: a program status register, wherein the execution environment bit of the register indicates the current execution environment of the processor, and the processor is instructed to switch the execution environment by changing the value of the execution environment bit of the program status register.
[0012] Optionally, in a processor according to the present invention, the program status register includes: a trusted program status register; and an untrusted program status register, wherein when the processor is in a trusted execution environment, the trusted program status register is used as the program status register; and when the processor is in an untrusted execution environment, the untrusted program status register is used as the program status register.
[0013] Optionally, the processor according to the present invention also includes: a configuration register, in which the resource status bit indicates the execution environment corresponding to the common resource content, and a delayed switching unit is suitable for determining whether the current execution environment and the resource status are consistent based on the values of the execution environment bit of the program status register and the resource status bit of the configuration register.
[0014] Optionally, the processor according to the present invention further includes: a trusted entry base address register storing a base address of a stack in a trusted execution environment, the stack being suitable for storing common resource content corresponding to the trusted execution environment; and an untrusted entry base address register storing a base address of a stack in an untrusted execution environment, the stack being suitable for storing common resource content corresponding to the untrusted execution environment. The delay switching unit is suitable for storing and / or loading common resource content with reference to the stack base address stored in the trusted entry base address register when the processor is in a trusted execution environment, and storing and / or loading common resource content with reference to the stack base address stored in the untrusted entry base address register when the processor is in an untrusted execution environment.
[0015] Optionally, in the processor according to the present invention, the common resources include common register resources. The common register resources include one or more of the following: general purpose registers; vector general purpose registers; and control registers.
[0016] Optionally, in the processor according to the present invention, the delay switching unit is adapted to instruct the instruction processing device to execute the decoded instruction when it is determined that the current execution environment and the resource state are consistent.
[0017] According to another aspect of the present invention, a method for executing instructions in a processor is provided. The processor has a trusted execution environment and a non-trusted execution environment, and includes public resources that can be accessed in various execution environments. The method includes the steps of: obtaining an instruction and decoding the instruction; if the instruction decoding result indicates that the instruction involves access to public resources, then determining the consistency between the current execution environment of the processor and the resource state, wherein the resource state indicates the execution environment corresponding to the content in the public resource; if it is determined that the current execution environment and the resource state are inconsistent, then loading the content corresponding to the current execution environment into the public resource; and executing the instruction.
[0018] According to the solution of the present invention, when the processor switches the execution environment, it does not store the public resources at the same time, but starts the switching of the public resources when it is found that the instruction involves accessing the public resources during the instruction execution process. In this way, by delaying the switching time of the public resources, the switching speed of the execution environment can be accelerated.
[0019] In addition, according to the solution of the present invention, a resource status mark is introduced to indicate which execution environment the current public resource belongs to. In this way, when executing instructions involving access to public resources, it can be determined whether to switch the public resources based on whether the current execution environment mark and the resource status mark are consistent, thereby providing a convenient public resource switching solution. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] To achieve the above and related purposes, certain illustrative aspects are described herein in conjunction with the following description and accompanying drawings, which indicate various ways in which the principles disclosed herein can be practiced, and all aspects and their equivalents are intended to fall within the scope of the claimed subject matter. The above and other purposes, features and advantages of the present disclosure will become more apparent by reading the following detailed description in conjunction with the accompanying drawings. Throughout the present disclosure, the same reference numerals generally refer to the same parts or elements.
[0021] Figure 1 A schematic diagram of a processor 100 according to an embodiment of the present invention is shown;
[0022] Figure 2 A schematic diagram of a processor 200 according to another embodiment of the present invention is shown;
[0023] Figure 3 A schematic diagram showing an instruction execution method 300 according to another embodiment of the present invention; and
[0024] Figure 4 FIG. 4 is a state diagram of an instruction execution process 400 according to another embodiment of the present invention. DETAILED DESCRIPTION
[0025] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0026] Figure 1 FIG. 1 is a schematic diagram of a processor 100 according to an embodiment of the present invention. Figure 1 As shown, the processor 100 is divided into a trusted core 110 and an untrusted core 120. The trusted core 110 and the untrusted core 120 and related resources constitute a trusted world and an untrusted world respectively. To ensure security, the two are logically independent.
[0027] The processor 100 can be executed in the trusted kernel 110, i.e., the trusted world. At this time, the processor 100 is in a trusted execution environment and can access trusted resources exclusively in the trusted kernel 110. The processor 100 can also be executed in the untrusted kernel 120, i.e., the untrusted world. At this time, the processor 100 is in a untrusted execution environment and can access untrusted resources exclusively in the untrusted kernel 120.
[0028] The processor 100 also includes public resources 130 accessible in both the trusted world and the non-trusted world. According to one embodiment of the present invention, the public resources 130 include various registers that do not contain security information, etc. The public resources 130 load different contents depending on whether the processor 100 is in a trusted execution environment or a non-trusted execution environment.
[0029] According to one embodiment, the common resource 130 includes a general purpose register GPR 132. The GPR 132 is generally used to transmit and temporarily store data, and can also participate in arithmetic and logical operations and save the operation results. Since the access speed of the register is faster than that of the memory, multiple general purpose registers are designed in modern processor architectures to speed up the execution speed of the processor.
[0030] In addition, the common resource 130 also includes a vector general register VGPR 134. Similar to the function of GPR 132, VGPR 134 is also a register used to transmit and temporarily store data, and participate in arithmetic and logical operations. VGPR 134 can have more bits than GPR 134, and can be more efficiently used for floating-point operations in the vector operation unit VDSP and the floating-point operation unit FPU.
[0031] In addition, optionally, the common resource 130 also includes a control register CR 136. The CR 136 can control and determine the operation mode of the processor and set the system operation function, I / O control, etc. The CR 136 in the common resource 130 is generally a register that does not contain security information. The control register CR containing security information can be set for the trusted core 110 and the untrusted core 120 respectively, such as the trusted control register 112 contained in the trusted core 110 and the untrusted control register 122 in the untrusted core 120.
[0032] According to one embodiment of the present invention, in order to support switching between a trusted world and a non-trusted world, the processor 100 further includes a trusted program status register T_PSR 114 and a non-trusted program status register NT_PSR 124 respectively located in the trusted core 110 and the non-trusted core 120. These two registers have substantially the same function and can be accessed in the same logical manner, i.e., in the name of the program status register PSR. That is, when the processor 100 is in a trusted execution environment or a trusted world, when an instruction in the processor 100 accesses the program status register PSR, the instruction accesses the trusted program status register T_PSR 114. When the processor 100 is in a non-trusted execution environment or a non-trusted world, when an instruction in the processor 100 accesses the PSR, the instruction accesses the NT_PSR 124.
[0033] T_PSR 114 and NT_PSR 124 have an execution environment indication bit T. According to one embodiment of the present invention, T is a bit in a register. When the value of T is 1, it indicates that the processor 100 is currently in a trusted execution environment, i.e., a trusted world. When the value of T is 0, it indicates that the processor 100 is currently in a non-trusted execution environment, i.e., a non-trusted world. Therefore, the T bit value of T_PSR 114 is fixed to 1, and the T bit value of NT_PSR 124 is fixed to 0. Optionally, the processor 100 can also be instructed to switch worlds by modifying the T bit value of PSR.
[0034] In addition, the processor 100 also includes a security flag of a public resource, which is used to indicate the world described by the current public resource scene. There are many ways to record the security flag of a public resource. In one embodiment, the trusted kernel 110 also includes a processor trusted configuration register T_PCR 116. This register T_PCR 116 includes an STV bit for a security flag of a public resource, that is, indicating the world to which the public resource scene belongs. When the value of STV is 1, it indicates that the public resource scene belongs to the trusted world, and when the value of STV is 0, it indicates that the public resource scene belongs to the untrusted world. In another embodiment, the public resource stacking flag in other registers can be used to implement the security flag of the public resource. For example, when the value of the public resource stacking flag is 1, it means that the public resource has been stacked by the trusted world, so the public resource can be used in the untrusted world without triggering the stacking operation of the trusted world, which is equivalent to the STV value of T_PCR 116 in the above embodiment being set to 0. Similarly, when the public resource push flag is 1, it means that the public resource has been pushed or initialized in the untrusted world, so the public resource can be used in the trusted world without triggering a push operation in the untrusted world.
[0035] In addition, the processor 100 also includes a trusted entry base address register T_EBR 118 in the trusted kernel 110 and a non-trusted entry base address register NT_EBR 128 in the non-trusted kernel 120. The base address of the entry position of the trusted world storage space is stored in T_EBR 118, and similarly, the base address of the entry position of the non-trusted world storage space is stored in NT_EBR 128. According to one embodiment, the storage space of the trusted and non-trusted worlds can be implemented as a stack, so the base addresses of the trusted stack and the non-trusted stack are stored in the trusted and non-trusted entry base address registers, respectively. The content in the public resource 130 can be stored in the corresponding stack according to the world to which the public resource site belongs. When the public resource site belongs to the trusted world, if the content of the public resource is to be stored at this time, the content of the public resource can be pushed into the trusted stack according to the base address of the trusted stack in T_EBR 118. Similarly, when the public resource site belongs to the untrusted world, if the content of the public resource is to be stored at this time, the content of the public resource can be pushed into the untrusted stack according to the base address of the untrusted stack in the NT_EBR 118. In addition, when the processor 100 is in the trusted execution environment, the base address of the trusted stack stored in the T_EBR 118 can be used to pop the stack to obtain the public resource content that can be used in the trusted world. Similarly, when the processor 100 is in the untrusted execution environment, the base address of the untrusted stack stored in the NT_EBR 128 can be used to pop the stack to obtain the public resource content that can be used in the untrusted world.
[0036] Figure 2 FIG. 2 is a schematic diagram of a processor 200 according to another embodiment of the present invention. Figure 1 Various components of processor 100 in trusted core 110 and untrusted core 120 are shown. Figure 2 The various components of the processor 200 for instruction execution are shown. The processors 100 and 200 show different aspects of the processor 200 of the claimed invention, but both are within the scope of protection of the present invention.
[0037] like Figure 2 As shown, the processor 200 includes an instruction processing device 290. The instruction processing device 290 is an instruction processing component in the processor 200, and the processing content includes fetching instructions for decoding, and then executing various decoded instructions. It should be noted that the instruction processing device 290 is a logical division of the functions of the processor 200, and all instruction-related components in the processor 200 can be divided into a part of the instruction processing device 290 without exceeding the protection scope of the present invention.
[0038] According to one embodiment, the instruction processing device 290 includes an instruction fetch unit 210, an instruction decoding unit 220, an instruction execution unit 230, and an instruction retirement unit 240. The instruction fetch unit 210 fetches instructions to be executed and sends the fetched instructions to the instruction decoding unit 220.
[0039] Instructions generally include an operation code and an address code, wherein the operation code indicates the operation to be performed; and the address code indicates the address or content of the operation object when the operation code is executed. The instruction decoding unit 220 can decode and analyze the instruction to determine the operation code of the instruction and further determine the nature and method of the operation.
[0040] Subsequently, the instruction decoding unit 220 sends the decoded instruction to the instruction execution unit 230, and executes the instruction in the instruction execution unit 230. According to one embodiment of the present invention, the instruction execution unit 230 includes various units for executing special instructions, such as an FPU unit 232 for executing floating-point instructions, a VDSP unit 234 for executing VDSP instructions, etc. The present invention is not limited to the specific form of the instruction execution unit for executing special instructions, and all instruction execution units 230 that can execute instructions are within the protection scope of the present invention.
[0041] Optionally, the processor 200 further includes an instruction retirement unit 240. The processor 200 processes instructions in a pipeline manner. After each instruction is executed in the instruction execution unit 230, the status of each instruction needs to be checked. For instructions that have been executed and have no dependency relationship with other instructions, the instruction execution result can be written back to the corresponding register and the executed instructions can be retired in the original order.
[0042] The instruction decoding unit 220 includes a delay switching unit 222. As described above, instruction decoding is performed in the instruction decoding unit 220, and the instruction decoding unit 220 determines whether the instruction decoding result indicates that the instruction to be executed involves a reference Figure 1 The accesses to common resource 130 are shown to involve, for example, accessing the contents of a GPR 132 or VGPR 134 register.
[0043] If the instruction to be executed does not involve access to the common resource 130, the instruction decoding unit 220 sends the instruction to the instruction execution unit 230 for execution. On the contrary, if the instruction involves access to the common resource 130, the delay switching unit 222 determines whether the current execution environment of the processor 100 is consistent with the resource state of the common resource.
[0044] As described above, the processor 100 can be in a trusted execution environment (trusted world) or a non-trusted execution environment (non-trusted world). If the instruction is to access a public resource at this time, the site of the public resource, that is, the content in the public resource, should belong to the corresponding execution environment. Since the processor 100 does not switch the content in the public resource 130 at the same time when switching the world, there may be inconsistency between the two.
[0045] When the current execution environment of the processor 100 is consistent with the resource state of the common resource, the delay switching unit 222 does not perform resource switching but sends the instruction to the instruction execution unit 230 for subsequent instruction execution. On the contrary, when the current execution environment and the resource state of the common resource 130 are inconsistent, the delay switching unit 222 switches the scene of the common resource to be consistent with the current execution environment, that is, loads the content corresponding to the current execution environment into the common resource, and then sends the instruction to the instruction execution unit 230 for subsequent instruction execution.
[0046] In this way, through the operation in the instruction decoding unit 220, especially in the delayed switching unit 222, it is possible to ensure the consistency of instruction execution while delaying the switching of the common resource 130 in the world switch.
[0047] As above reference Figure 1 As described above, the T bit of the program status register PSR in the processor 100 indicates the current execution environment, and the security flag bit of the public resource, such as the STV bit of the processor trusted configuration register T_PCR 116, indicates the world to which the public resource scene belongs. The delay switching unit 222 can compare the values of the T bit of the PSR and the STV bit of the T_PCR 116 to determine whether the scene of the current execution environment and the public resource 130 are consistent.
[0048] According to an embodiment of the present invention, when the current execution environment and the locale of the common resource 130 are inconsistent, the delay switching unit 222 can switch the locale of the common resource by the following processing. First, the T bit of the PSR is modified to a value corresponding to the STV bit of the T_PCR 116, thereby triggering the processor 100 to perform a world switch and switch the current execution environment to an execution environment consistent with the current common resource locale.
[0049] Subsequently, in the execution environment, the content of the common resource 130 is saved. According to one embodiment, each world (i.e., each core) has a corresponding entry base register (T_EBR 118 or NT_EBR 128), and the base address of the stack of the world can be obtained from the entry base register, and the content of the common resource 130 can be pushed and saved by stacking. At this time, the value of the STV bit of the T_PCR 116 can be modified to indicate that the current common resource scene has been saved, and the common resource can be used in other worlds.
[0050] Next, the T bit of the PSR is modified back to the value corresponding to the original execution environment, so as to trigger the processor 100 to perform a world switch and switch back to the original execution environment, and retrieve the public resource content corresponding to the execution environment in the execution environment. Similarly, the stack base address stored in the entry base address register under the execution environment can be referenced, and the content stored in the stack can be read into the public resource by popping the stack, thereby restoring the public resource scene.
[0051] Through the above operations, the current execution environment has been consistent with the public resource site, so the instruction can be sent to the instruction execution unit 230 for subsequent processing.
[0052] It should be noted that the value of the STV bit of T_PCR 116 can be modified after the processor 100 switches back to the current execution environment. As long as the value of the STV bit has been modified accordingly when the consistency check is performed again after the public resource scene switch, this method is within the protection scope of the present invention.
[0053] As described above, in the present invention, the current execution environment and the common resource site become inconsistent due to the processing during the world switch.
[0054] According to one embodiment of the present invention, the world switch is executed in the instruction retirement unit 240. The instruction retirement unit 240 determines whether to perform a world switch, that is, whether to perform a switch in the execution environment of the processor 100. If the world switch is not performed, the instruction retirement unit 240 instructs the instruction fetch unit 210 to obtain the next instruction to be executed after performing the instruction retirement related operations. When it is determined that a world switch is to be performed, the storage of the current execution environment related state can be performed, for example, some dedicated resource contents in the execution environment are pushed onto the stack. According to one of the methods of the present invention, the stack base address stored in the register, such as various entry base address registers (118 or 128), can be referenced to save the content by pushing onto the stack. Subsequently, the T bit value of the PSR is modified to trigger the processor 100 to switch from the current execution environment to the target execution environment.
[0055] It should be noted that in the world switch operation of the instruction retirement unit 240, the operation of saving the common resource scene is not performed, but the state dedicated to each execution environment is saved, thereby reducing the time required for the scene switch and speeding up the scene switch.
[0056] It should also be noted that the present invention is not limited to the specific scope of common resources. According to one embodiment, considering that some GPR 132, VGPR 134 and CR 136 are commonly used common resources and will be frequently used in the world after switching, the contents of these resources can be pushed and popped when the world is switched, and the common resources that are not frequently used can be delayed switching. The common resources to be delayed switching can be determined according to the application scenario of the processor 200. All methods of delaying switching for some or all common resources are within the protection scope of the present invention.
[0057] Figure 3 FIG. 3 is a schematic diagram showing an instruction execution method 300 in a processor according to an embodiment of the present invention. Figure 1 and 2 The method 300 is executed in the processors 100 and 200 described above, and some steps in the method 300 have been described in the respective steps of the processors 100 and 200, which will not be repeated here.
[0058] The method 300 starts at step S310. In step S310, an instruction is fetched and instruction decoding is performed. This can be performed in the instruction fetch unit 210 and the instruction decoding unit 220. Subsequently, in step S320, it is determined whether the instruction decoding result in step S310 indicates that the instruction involves access to public resources. If the determination result in step S320 indicates that the instruction involves access to public resources, the method 300 sends the instruction to step S380 to execute the instruction. On the contrary, if the determination result in step S320 indicates that the instruction involves access to public resources, the method 300 proceeds to step S330.
[0059] In step S330, it is determined whether the current execution environment of the processor is consistent with the public resource scene, that is, whether the world to which the content in the public resource belongs is consistent with the current world. Figure 2 The implementation method for performing the above judgment has been described and will not be repeated here.
[0060] When the judgment result of step S330 indicates that the current execution environment and the public resource scene are consistent, the method proceeds to step S380 to execute the instruction. On the contrary, when the judgment result of step S330 indicates that the two are inconsistent, the processing of method 300 proceeds to step S340. In step S340, the scene of the public resource is restored to be consistent with the current execution environment or the current world. That is, the content of the public resource corresponding to the current execution environment is loaded into the public resource. Figure 2 The specific implementation method of switching the public resources has been described, and will not be repeated here.
[0061] After the current execution environment and the public resource site are set to be consistent in step S340, step S380 is entered to execute the instruction.
[0062] Optionally, after the execution of the instruction in step S380 is completed, the instruction can be retired in step S390. In step S390, it is further determined whether the execution of the instruction involves world switching. If it involves world switching, the state of the current execution environment is saved and the world switching is performed. When the world switching is performed, the public resource site is not switched, thereby speeding up the world switching speed. Figure 3 The specific implementation method of world switching has been described and will not be repeated here.
[0063] Then, the method returns to step S310 to fetch the next instruction for processing, thereby repeating various processes in the above method 300.
[0064] Figure 4 FIG. 4 is a state diagram of an instruction execution process 400 according to an embodiment of the present invention. Figure 4 Taking the case where the instructions of the processor 100 are executed in a trusted execution environment (trusted world) and then switched to a non-trusted execution environment (non-trusted world) for execution as an example, various state changes during the instruction execution process are described.
[0065] In state 410, the instruction is executed in the trusted world. At this time, the PSR uses T_PSR 114, in which the T bit value is 1. Since it is in the initial state, the value of the STV bit in T_PCR 116 is also equal to 1, indicating that the public resource scene at this time is in the trusted world.
[0066] Subsequently, in state 420, it is determined whether a world switch is sent during the execution of the instruction. If no world switch occurs, the process returns to state 410 to perform a new execution.
[0067] If a world switch occurs, the processor 100 switches to the untrusted world and enters state 430 to execute instructions in the untrusted world. At state 430, the PSR uses NT_PSR 124, and the value of T therein is set to 0, but no public resource context switch occurs, so the STV value in T_PCR 116 is still 1.
[0068] Then, at state 440 , it is determined that the instruction execution involves access to a common resource. At state 450 , it is determined that the T value (0) of NT_PSR 124 and the value (1) of T_PCR 116 are inconsistent, thus triggering a world switch and entering state 460 .
[0069] At state 460, in the trusted world, T_PSR 114 is adopted and the T bit value of T_PSR 114 is 1, and the common resource field is pushed. Then at state 470, after the common resource field is pushed, the STV value of T_PCR 116 is set to 0, and the world switch is triggered again.
[0070] At state 480, in the untrusted world, the NT_PSR 124 is used, and the T bit value therein is 0. At this time, the STV value of the T_PCR 116 is set to 0, and the two are consistent.
[0071] Therefore, at state 490, the access involving access to the public resource is executed. And at state 492, the world switch instruction is executed to return to state 494 in the trusted world. At state 494, the value of T_PSR 114 is 1, and the public resource scene is not switched, so the STV value of T_PCR 116 remains 0. Then, it can continue to return to state 410 and continue to execute new instructions in the trusted world.
[0072] According to the instruction execution scheme of the present invention, when the world is switched, the public resource site is not switched immediately, and after the world switch is completed, when the instruction is executed in the new world, it is found that the instruction involves public resource access, and the public resource is switched. In this way, unnecessary public resource push and pop operations can be reduced, and the speed of world switching can be improved.
[0073] It should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: that the claimed invention requires more features than those explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.
[0074] Those skilled in the art will appreciate that the modules or units or components of the devices in the examples disclosed herein may be arranged in the devices described in the embodiment, or alternatively may be located in one or more devices different from the devices in the examples. The modules in the foregoing examples may be combined into one module or may be divided into multiple submodules.
[0075] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and further may be divided into a plurality of submodules or subunits or subcomponents. All features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device so disclosed may be combined in any combination, except that at least some of such features and / or processes or units are mutually exclusive. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature that provides the same, equivalent or similar purpose.
[0076] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0077] In addition, some of the embodiments are described herein as methods or combinations of method elements that can be implemented by a processor of a computer system or by other devices that perform the functions. Therefore, a processor with necessary instructions for implementing the method or method elements forms a device for implementing the method or method elements. In addition, the elements described herein of the device embodiments are examples of devices for implementing the functions performed by the elements for the purpose of implementing the invention.
[0078] As used herein, unless otherwise specified, the use of ordinal numbers "first," "second," "third," etc. to describe common objects merely indicates that different instances of similar objects are involved, and is not intended to imply that the objects so described must have a given order in time, space, order, or in any other manner.
[0079] Although the present invention has been described according to a limited number of embodiments, it will be apparent to those skilled in the art, with the benefit of the above description, that other embodiments may be envisioned within the scope of the invention thus described. In addition, it should be noted that the language used in this specification is selected primarily for readability and teaching purposes, rather than for explaining or defining the subject matter of the present invention. Therefore, many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the appended claims. The disclosure of the present invention is illustrative, not restrictive, with respect to the scope of the present invention, which is defined by the appended claims.
Claims
1. A processor having a trusted execution environment and a non-trusted execution environment, the processor comprising: Public resources are accessible in both the trusted execution environment and the non-trusted execution environment; Instruction processing equipment adapted to fetch instructions, decode them and execute the decoded instructions, The instruction processing device further comprises a delay switching unit adapted to: When the instruction decoding result indicates that the instruction involves access to the common resource, determining the consistency between the current execution environment of the processor and the resource state, and If it is determined that the current execution environment and the resource state are inconsistent, the content corresponding to the current execution environment is loaded into the public resource, The resource status indicates the execution environment corresponding to the content in the public resource.
2. The processor of claim 1 , wherein the delayed switching unit is adapted to: Switching the execution environment of the processor from the current execution environment to a first execution environment corresponding to the resource state; Using the storage space in the first execution environment to store the content in the public resource; Switching the execution environment of the processor from the first execution environment back to the current execution environment; Loading content from the storage space in the current execution environment into the public resource; as well as The resource state is set to indicate the current execution environment.
3. The processor of claim 1 , wherein the instruction processing device comprises: an instruction fetch unit adapted to fetch instructions; an instruction decoding unit, adapted to decode the fetched instruction; as well as The instruction execution unit is adapted to execute the decoded instructions.
4. The processor according to claim 3, wherein the instruction processing device further comprises: an instruction retirement unit, adapted to store state information of the current execution environment in a storage space in the current execution environment when the instruction involves an execution environment switch of the processor from the current execution environment to a target execution environment; as well as The current execution environment is set as the target execution environment so that the execution environment of the processor is switched from the current execution environment to the target execution environment.
5. The processor of any one of claims 1 to 4, further comprising: A program status register, wherein the execution environment bit indicates the current execution environment of the processor, and the processor is instructed to switch the execution environment by changing the value of the execution environment bit of the program status register.
6. The processor of claim 5, wherein the program status register comprises: Trusted Program Status Register; as well as Untrusted Program Status Register, When the processor is in a trusted execution environment, the trusted program status register is used as the program status register; and when the processor is in an untrusted execution environment, the untrusted program status register is used as the program status register.
7. The processor of any one of claims 1 to 4, further comprising: a configuration register, wherein the resource status bit indicates the execution environment corresponding to the common resource content, and The delay switching unit is adapted to determine whether the current execution environment and the resource state are consistent based on values of an execution environment bit of a program state register and a resource state bit of the configuration register.
8. The processor of any one of claims 1 to 4, further comprising: A trusted entry base address register storing a base address of a stack in a trusted execution environment, wherein the stack is suitable for storing public resource content corresponding to the trusted execution environment; as well as The untrusted entry base address register stores a base address of a stack in the untrusted execution environment, wherein the stack is suitable for storing public resource content corresponding to the untrusted execution environment. Wherein, the delayed switching unit is suitable for storing and / or loading the common resource content with reference to the stack base address stored in the trusted entry base address register when the processor is in a trusted execution environment, and storing and / or loading the common resource content with reference to the stack base address stored in the untrusted entry base address register when the processor is in an untrusted execution environment.
9. The processor according to any one of claims 1 to 4, wherein the common resources include common register resources, and the common register resources include one or more of the following: General registers; vector general purpose registers; and Control register.
10. The processor according to any one of claims 1 to 4, wherein the delay switching unit is adapted to instruct the instruction processing device to execute the decoded instruction when it is determined that the current execution environment and the resource state are consistent.
11. A method for executing instructions in a processor, the processor having a trusted execution environment and a non-trusted execution environment, the processor including a common resource accessible in each execution environment, the method comprising the steps of: Get instructions and decode them; If the instruction decoding result indicates that the instruction involves access to the public resource, then determining the consistency between the current execution environment of the processor and a resource state, wherein the resource state indicates the execution environment corresponding to the content in the public resource; If it is determined that the current execution environment and the resource state are inconsistent, loading the content corresponding to the current execution environment into the public resource; as well as Execute the instructions.
12. The method of claim 11, wherein the step of loading the content corresponding to the current execution environment into the common resource comprises: Switching the execution environment of the processor from the current execution environment to a first execution environment corresponding to the resource state; Using the storage space in the first execution environment to store the content in the public resource; Switching the execution environment of the processor from the first execution environment back to the current execution environment; Loading content from the storage space in the current execution environment into the public resource; as well as The resource state is set to the current execution environment.
13. The method of claim 11, wherein if the instruction involves an execution environment switch from the current execution environment to a target execution environment, then after the step of executing the instruction: storing the state information of the current execution environment in the storage space of the current execution environment; and The current execution environment is set as the target execution environment, and the execution environment of the processor is switched from the current execution environment to the target execution environment.
14. The method according to any one of claims 11 to 13, wherein the processor comprises a program status register, an execution environment bit of the program status register indicates a current execution environment of the processor, and the step of the processor switching the execution environment comprises: The execution environment bit of the program status register is modified.
15. The method of claim 14, wherein the processor comprises a configuration register, a resource status bit of the configuration register indicates an execution environment corresponding to the common resource content, and the step of determining whether the current execution environment of the processor is consistent with the resource status comprises: It is determined whether the values of the execution environment bit of the program status register and the resource status bit of the configuration register are consistent.
16. The method according to any one of claims 11 to 13, wherein the processor comprises an entry base address register corresponding to each execution environment, and the storage space location under each execution environment is determined according to the value in the entry base address register.
17. The method according to any one of claims 11 to 13, wherein the common resource comprises a common register resource, and the common register resource comprises one or more of the following: General registers; vector general purpose registers; and Control register.
18. The method according to any one of claims 11 to 13, further comprising the steps of: If it is determined that the current execution environment is consistent with the resource state, the instruction is directly executed.
