ARMv7-M Code Execution on ARMv8-M Non-Secure Mode

The ARMv8-M architecture introduces significant enhancements over its predecessor, ARMv7-M, particularly in the areas of security and performance. One of the most frequently asked questions is whether code compiled for ARMv7-M can run unmodified on ARMv8-M, specifically in the non-secure mode. The ARMv8-M architecture is designed to be upward compatible with ARMv6-M and ARMv7-M, which implies that, in theory, ARMv7-M code should execute on ARMv8-M without modification. However, this compatibility is not absolute and depends on several factors, including the specific features used in the ARMv7-M code, the configuration of the ARMv8-M processor, and the presence of new architectural features in ARMv8-M that may affect execution.

The ARMv8-M architecture introduces a dual-security model, dividing the processor into Secure and Non-Secure states. The Non-Secure state is designed to be compatible with ARMv7-M, allowing legacy code to run without modification. However, the Secure state introduces new instructions and security features that are not present in ARMv7-M. This means that while ARMv7-M code can run in the Non-Secure state, certain considerations must be taken into account to ensure seamless execution.

The upward compatibility of ARMv8-M with ARMv7-M is primarily achieved through the retention of the Thumb-2 instruction set, which is common to both architectures. Thumb-2 is a variable-length instruction set that provides a good balance between code density and performance, making it ideal for embedded systems. However, ARMv8-M introduces new instructions and architectural features that are not present in ARMv7-M, such as the TrustZone security extensions, which can impact the execution of ARMv7-M code.

Potential Issues with ARMv7-M Code on ARMv8-M

While ARMv8-M is designed to be upward compatible with ARMv7-M, there are several potential issues that can arise when running ARMv7-M code on ARMv8-M. These issues can be broadly categorized into three areas: instruction set compatibility, memory model differences, and security model implications.

Instruction Set Compatibility

The ARMv8-M architecture retains the Thumb-2 instruction set, which is also used in ARMv7-M. However, ARMv8-M introduces new instructions that are not present in ARMv7-M, such as those related to the TrustZone security extensions. While these new instructions are primarily used in the Secure state, their presence can still impact the execution of ARMv7-M code in the Non-Secure state. For example, if an ARMv7-M code sequence inadvertently triggers a Secure state operation, it could lead to unexpected behavior or even a fault.

Additionally, ARMv8-M introduces new instructions for handling the dual-security model, such as the SG (Secure Gateway) instruction, which is used to transition from the Non-Secure to the Secure state. If an ARMv7-M code sequence inadvertently uses an ARMv8-M-specific instruction, it could result in an undefined instruction exception. Therefore, it is essential to ensure that the ARMv7-M code does not contain any instructions that are specific to ARMv8-M.

Memory Model Differences

The memory model in ARMv8-M is more complex than that in ARMv7-M due to the introduction of the dual-security model. In ARMv8-M, memory regions can be configured as Secure or Non-Secure, and access to these regions is controlled by the Security Attribution Unit (SAU) and the Implementation Defined Attribution Unit (IDAU). This means that an ARMv7-M code sequence that accesses memory in a certain way may behave differently on ARMv8-M if the memory regions are configured differently.

For example, if an ARMv7-M code sequence assumes that all memory is accessible in the same way, it may fail on ARMv8-M if some memory regions are configured as Secure and inaccessible from the Non-Secure state. This could lead to data aborts or other memory-related faults. Therefore, it is important to review the memory configuration of the ARMv8-M processor and ensure that the ARMv7-M code is compatible with the memory model.

Security Model Implications

The introduction of the TrustZone security extensions in ARMv8-M adds a new layer of complexity to the architecture. While ARMv7-M code running in the Non-Secure state should not be directly affected by the Secure state, there are still potential implications. For example, if the ARMv7-M code relies on certain peripherals or resources that are now configured as Secure, it may not be able to access them from the Non-Secure state. This could lead to functional failures or unexpected behavior.

Additionally, the presence of the Secure state means that certain system-level operations, such as interrupt handling, may be handled differently in ARMv8-M. For example, interrupts can be configured as Secure or Non-Secure, and the handling of these interrupts may differ from ARMv7-M. If the ARMv7-M code assumes a certain behavior for interrupt handling, it may not work correctly on ARMv8-M if the interrupts are configured differently.

Ensuring Seamless Execution of ARMv7-M Code on ARMv8-M

To ensure that ARMv7-M code runs seamlessly on ARMv8-M, several steps should be taken to address the potential issues discussed above. These steps include reviewing the instruction set, configuring the memory model, and understanding the security model implications.

Reviewing the Instruction Set

The first step in ensuring compatibility is to review the ARMv7-M code to ensure that it does not contain any instructions that are specific to ARMv8-M. This can be done by disassembling the code and checking for any ARMv8-M-specific instructions. If any such instructions are found, they should be replaced with equivalent ARMv7-M instructions or removed entirely.

Additionally, it is important to ensure that the ARMv7-M code does not inadvertently trigger any Secure state operations. This can be done by reviewing the code for any operations that could potentially access Secure resources or trigger Secure state transitions. If any such operations are found, they should be modified to ensure that they only operate in the Non-Secure state.

Configuring the Memory Model

The next step is to configure the memory model of the ARMv8-M processor to ensure that it is compatible with the ARMv7-M code. This involves configuring the SAU and IDAU to define the Secure and Non-Secure memory regions. The goal is to ensure that the ARMv7-M code can access all the memory regions it needs to without encountering any access violations.

It is also important to ensure that the memory map of the ARMv8-M processor is compatible with the memory map assumed by the ARMv7-M code. This may involve adjusting the base addresses of certain memory regions or reconfiguring the memory protection unit (MPU) to match the requirements of the ARMv7-M code.

Understanding the Security Model Implications

Finally, it is important to understand the implications of the TrustZone security extensions on the ARMv7-M code. This involves configuring the Secure and Non-Secure interrupts and ensuring that the ARMv7-M code can handle them correctly. It may also involve configuring the peripherals and resources used by the ARMv7-M code to ensure that they are accessible from the Non-Secure state.

In some cases, it may be necessary to modify the ARMv7-M code to handle the new security model. For example, if the ARMv7-M code relies on certain peripherals that are now configured as Secure, it may be necessary to modify the code to use alternative peripherals or to request access to the Secure peripherals through a Secure gateway.

Testing and Validation

Once the above steps have been taken, it is essential to thoroughly test the ARMv7-M code on the ARMv8-M processor to ensure that it runs correctly. This involves running the code in the Non-Secure state and verifying that it behaves as expected. It is also important to test the code under different memory and security configurations to ensure that it is robust and can handle different scenarios.

In conclusion, while ARMv8-M is designed to be upward compatible with ARMv7-M, there are several potential issues that can arise when running ARMv7-M code on ARMv8-M. By carefully reviewing the instruction set, configuring the memory model, and understanding the security model implications, it is possible to ensure that ARMv7-M code runs seamlessly on ARMv8-M. Thorough testing and validation are also essential to ensure that the code behaves correctly under different conditions.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *