The latest 64-bit architecture can on both AArch64 and AArch32 state.
Can someone tell me how to utilize this feature so that I can seamlessly integrate algorithms (which are optimized with 32-bit and 64-bit instructions) with applications which are build for 32-bit and 64-bit modes.
Here is the specifics of situation which I am facing right now.
I want to link an ARM shared library which is optimized with 64-bit instructions with my application which is built in 32 bit mode.
At the time of linking I am getting the following error. "skipping incompatible xxxx.so file".
My build environment is android and unfortunately I don't have the option to build my application in 64-bit mode.
Appreciate your help with inputs.
although I am not familiar with ARMv8-A, I think PMR_ELn register would be used in order to change the execution mode between AArch32 and AArch64.
Because this change needs the warm reset, I am afraid that your intention might be impossible.
I think you meant RMR_EL3 (Reset Management Register) :-)
Execution state (AArch32/AArch64) can change on when you take or return from an exception, and there is a change of Exception level (EL). There also restrictions on how you can mix 32-bit and 64-bit levels. Below is a slide we use is training to illustrate this:
What this means is that you could host a mix of 32-bit and 64-bit applications under the same 64-bit kernel. But you can't, for example, dynamically link a 32-bit app against a 64-bit shared library (or vice verse).
It is not possible to link a 64-bit library with a 32-bit application.
In ARMv8, interworking between 64-bit execution state (AArch64) and 32-bit execution state (AArch32) happens only at boundaries between exception levels (that is, privilege levels). So you can execute a 32-bit application -- linked with 32-bit libraries -- at the lowest execution level (EL0) within the context of a 64-bit operating system at the kernel execution level (EL1). By the way, the converse is not true -- you cannot run 64-bit applications under a 32-bit operating system.
So when creating your application you have to choose: 32-bit or 64-bit. This does also mean that if you want your operating system to support both 32-bit and 64-bit then you must have both 32-bit and 64-bit libraries.
As I understand it, this is the same for other major architectures that support both 32-bit and 64-bit operation, though I could be wrong.
It also depends on whether your hardware supports both AArch32 and AArch64 at all exception levels. The Cortex processors from ARM do, but not all ARMv8-A processors support all the combinations. See section D1.20 of the "ARM Architecture Reference Manual, ARMv8, for ARMv8-A architecture profile" manual for more details.
If the hardware supports AArch32 and AArch64 at all exception levels then the RMR_ELx register (where x is the highest implemented exception level, typically x=3) might be used to switch the execution state at the highest exception level by resetting the processor. But that assumes you have access to the highest exception level. (EL3 is 2 levels above where the OS kernel executes, for example).
I think you need to write some code in A64 for execution when the processor reset or in a exception level higher than EL0. The code need to set the ELR to your 32bit code start address, and set the PE state of CPSR to aarch32, then return from this EL to EL0 where your code executes from this state. After than your 32bit code can run correctly.
Can you teach me? I'm just an ARM beginners, just learning STM32 for a month
Assuming my OS has a syscall to switch from AARCH32 to AARCH64, it should be possible to mix 32-bit and 64-bit code. But which major OS and toolchain would implement this? Usually it's easier to compile the app as 64-bit if there is a 64-bit library to be used. Besides memory footprint concerns, is there really anything that prevents switching to 64-bit ?
Actually, there might be a few use cases where somebody wants to run a 3rd party 32-bit library with 64-bit code. There this switch-syscall could come handy. And in your case you'd build a 64-bit wrapper application then that runs most of the actual app as 32-bit code. Just for the 64-bit library you'd use a trampoline via the 64-bit wrapper to call the 64-bit library then.
I think that is the right reply for this question. It just isn't possible in Android and I don't think anyone plans to support anything like that. The most that happens like that is that a driver or system routine can be in 64 bit mode and be invoked by a 32 bit application. You an do like you say with 32 bit ARM and Thumb code but the overall environment doesn't change when one does that.
If the library task is a longish one you might be able to pipe the data between a process in 32 bit mode and one in 64 bit mode. It sounds though like you have very little control over the 32 bit application.
There is a 32 bit mode using the 64 bit instructions being developed, but I don't think it will be on Android and its main purposes are to simplify porting 32 bit legacy code with less baggage and to run some benchmark tests in a way that'll produce compatible results with x86 chips. It would need a different library too but the changes would be less than backporting to ARM 32 bit code.
The terms 32-bit and 64-bit refer to the way a computer's processor (also called a CPU), handles information. Processor calls data from Memory i.e. RAM by giving its address to MAR (Memory Address Register). Selector electronics then finds that address in the memory bank and retrieves the data and puts it in MDR (Memory Data Register) This data is recorded in one of the Registers in the Processor for further processing. Thats why size of Data Bus determines the size of Registers in Processor. Now, if my processor has 32 bit register, it can call data of 4 bytes size only, at a time. And if the data size exceeds 32 bits, then it would required two cycles of fetching to have the data in it. This slows down the speed of 32 bit Machine compared to 64 bit, which would complete the operation in ONE fetch cycle only. So, obviosly for the smaller data, it makes no difference if my processors are clocked at the same speed. Again, with 64 bit processor and 64 bit OS, my instructions will be of 64 bit size always... which unnecessarily uses up more memory space.
The restrictions on execution state are that a change can only occur at a change of exception level, and that an exception level cannot use wider registers than the one above it in website
View all questions in Cortex-A / A-Profile forum