0
votes

First of all, I'm new when it comes to ARM assembly. I actually have some pieces of code written for ARM instruction set, but my target is a Cortex-M4 architecture using Thumb-2 instruction set. Do I have to re-write the whole code, change some of it or keep it the way it is?

I actually have several files of approximately 250 lines each. Here is a sample

msr cpsr_c, #(CPSR_IRQ_LOCKED | CPSR_SVC_MODE)
stmfd sp!, {r0-r2,lr}
mrs r1, spsr
stmfd sp!, {r1}
ldr r1, =nested_kernel_entrance_counter
ldr r2, [r1]
add r2, r2, #1
str r2, [r1]
cmp r2, #1
bhi skip_kernel_enter

#if WITH_MEMORY_PROTECTION == YES
stmfd sp!, {r3}
bl tpl_mp_kernel_enter
ldmfd sp!, {r3}
#endif
ldr r1, =tpl_kern
mov r2, #NO_NEED_SWITCH
strb r2, [r1, #TPL_KERN_OFFSET_NEED_SWITCH]
1
i hope your old code isn't massive. wiki.ubuntu.com/ARM/Thumb2PortingHowtoJacky Cheng
The majority of your code will have to be rewritten. The 2 instruction sets operate on the same register set, but take a very different approach. The only instructions which can be left alone are NEON.BitBank
just try it, assemble for cortex-m4 and patch up the assembler complaints, that is the fastest way...If you have or had used the unified syntax then it would cross over with no complaints.old_timer
I think one of the features of thumb2 is getting most of the arm syntax/features back but using a variable length instruction set to save a little on code space without as much sacrifice on performance. early thumb was only about 10% slower than arm for the same taskold_timer

1 Answers

1
votes

You may not need to rewrite too much depending on what features of the ARM instruction set and ARM variant you've used. It's also possible that your ARM code is already compatible with Thumb-2.

ARM created Unified Assembly Language once Thumb-2 was introduced in order to increase the portability of code. You can find information on it here: ARM UAL. I've found that it is not a significant deviation from ARM assembly of olden days, with the biggest change being the introduction of the IT(E) directive for conditional execution. Wikipedia has an example here.

There are some other constructs that won't port directly, and if you are using features of a more advanced or complex ARM core that the Cortex-M4 doesn't have, then that will require a rewrite of that portion.

I think if the code is not already written in ARM UAL that, while it would take time, it would be relatively simple to run a script over the code that can flag the usage of features that are not written correctly for UAL. A simple regular expression could check for conditionals on the end of instructions, and it may even be relatively easy to then convert those constructs to use IT(E) <cond>.