diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2019-08-17 00:32:04 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-08-20 15:13:17 +1000 |
commit | 4ab5156c01bfd4a6304e26b1dc2d34163b8637c0 (patch) | |
tree | 921c7cf3c538cfa460ce39458909644aa94b59af /tools/mpy-tool.py | |
parent | ae6fe8b43c08abe215dde355e04e561ad2dd1808 (diff) |
tools/mpy-tool.py: Force native func alignment to halfword/word on ARM.
This is necessary for ARMV6 and V7. Without this change, calling a frozen
native/viper function that is misaligned will crash.
Diffstat (limited to 'tools/mpy-tool.py')
-rwxr-xr-x | tools/mpy-tool.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 648d56fe0..7938ea5dc 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -471,6 +471,14 @@ class RawCodeNative(RawCode): else: self.fun_data_attributes = '__attribute__((section(".text,\\"ax\\",%progbits @ ")))' + # Allow single-byte alignment by default for x86/x64/xtensa, but on ARM we need halfword- or word- alignment. + if config.native_arch == MP_NATIVE_ARCH_ARMV6: + # ARMV6 -- four byte align. + self.fun_data_attributes += ' __attribute__ ((aligned (4)))' + elif MP_NATIVE_ARCH_ARMV6M <= config.native_arch <= MP_NATIVE_ARCH_ARMV7EMDP: + # ARMVxxM -- two byte align. + self.fun_data_attributes += ' __attribute__ ((aligned (2)))' + def _asm_thumb_rewrite_mov(self, pc, val): print(' (%u & 0xf0) | (%s >> 12),' % (self.bytecode[pc], val), end='') print(' (%u & 0xfb) | (%s >> 9 & 0x04),' % (self.bytecode[pc + 1], val), end='') |