diff options
| author | Damien George <damien@micropython.org> | 2022-05-23 22:50:34 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-05-23 23:01:25 +1000 |
| commit | c1b9d2259e77548053cba4a1f2cab726e6429a97 (patch) | |
| tree | 58ed8e2fa0c308bc8e097da86364e06a6e22f865 | |
| parent | 0e28a1f0e5e229f14b199a30d1796770b232f5a1 (diff) | |
py/dynruntime.mk: Add basic support for armv6m architecture.
The examples/natmod features0 and features1 examples now build and run on
ARMv6-M platforms. More complicated examples are not yet supported because
the compiler emits references to built-in functions like __aeabi_uidiv.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | docs/develop/natmod.rst | 3 | ||||
| -rw-r--r-- | py/dynruntime.mk | 7 | ||||
| -rwxr-xr-x | tools/mpy_ld.py | 24 |
3 files changed, 29 insertions, 5 deletions
diff --git a/docs/develop/natmod.rst b/docs/develop/natmod.rst index 8ffe49591..6d15f867b 100644 --- a/docs/develop/natmod.rst +++ b/docs/develop/natmod.rst @@ -34,6 +34,7 @@ options for the ``ARCH`` variable, see below): * ``x86`` (32 bit) * ``x64`` (64 bit x86) +* ``armv6m`` (ARM Thumb, eg Cortex-M0) * ``armv7m`` (ARM Thumb 2, eg Cortex-M3) * ``armv7emsp`` (ARM Thumb 2, single precision float, eg Cortex-M4F, Cortex-M7) * ``armv7emdp`` (ARM Thumb 2, double precision float, eg Cortex-M7) @@ -171,7 +172,7 @@ The file ``Makefile`` contains: # Source files (.c or .py) SRC = factorial.c - # Architecture to build for (x86, x64, armv7m, xtensa, xtensawin) + # Architecture to build for (x86, x64, armv6m, armv7m, xtensa, xtensawin) ARCH = x64 # Include to get the rules for compiling and linking the module diff --git a/py/dynruntime.mk b/py/dynruntime.mk index db06d41e7..09cbb2dd3 100644 --- a/py/dynruntime.mk +++ b/py/dynruntime.mk @@ -55,6 +55,13 @@ CROSS = CFLAGS += -fno-stack-protector MICROPY_FLOAT_IMPL ?= double +else ifeq ($(ARCH),armv6m) + +# thumb +CROSS = arm-none-eabi- +CFLAGS += -mthumb -mcpu=cortex-m0 +MICROPY_FLOAT_IMPL ?= none + else ifeq ($(ARCH),armv7m) # thumb diff --git a/tools/mpy_ld.py b/tools/mpy_ld.py index 618949151..b8652462d 100755 --- a/tools/mpy_ld.py +++ b/tools/mpy_ld.py @@ -38,6 +38,7 @@ import makeqstrdata as qstrutil MPY_VERSION = 6 MP_NATIVE_ARCH_X86 = 1 MP_NATIVE_ARCH_X64 = 2 +MP_NATIVE_ARCH_ARMV6M = 4 MP_NATIVE_ARCH_ARMV7M = 5 MP_NATIVE_ARCH_ARMV7EMSP = 7 MP_NATIVE_ARCH_ARMV7EMDP = 8 @@ -82,7 +83,14 @@ def asm_jump_x86(entry): return struct.pack("<BI", 0xE9, entry - 5) -def asm_jump_arm(entry): +def asm_jump_thumb(entry): + # Only signed values that fit in 12 bits are supported + b_off = entry - 4 + assert b_off >> 11 == 0 or b_off >> 11 == -1, b_off + return struct.pack("<H", 0xE000 | (b_off >> 1 & 0x07FF)) + + +def asm_jump_thumb2(entry): b_off = entry - 4 if b_off >> 11 == 0 or b_off >> 11 == -1: # Signed value fits in 12 bits @@ -129,13 +137,21 @@ ARCH_DATA = { (R_X86_64_GOTPCREL, R_X86_64_REX_GOTPCRELX), asm_jump_x86, ), + "armv6m": ArchData( + "EM_ARM", + MP_NATIVE_ARCH_ARMV6M << 2, + 2, + 4, + (R_ARM_GOT_BREL,), + asm_jump_thumb, + ), "armv7m": ArchData( "EM_ARM", MP_NATIVE_ARCH_ARMV7M << 2, 2, 4, (R_ARM_GOT_BREL,), - asm_jump_arm, + asm_jump_thumb2, ), "armv7emsp": ArchData( "EM_ARM", @@ -143,7 +159,7 @@ ARCH_DATA = { 2, 4, (R_ARM_GOT_BREL,), - asm_jump_arm, + asm_jump_thumb2, ), "armv7emdp": ArchData( "EM_ARM", @@ -151,7 +167,7 @@ ARCH_DATA = { 2, 4, (R_ARM_GOT_BREL,), - asm_jump_arm, + asm_jump_thumb2, ), "xtensa": ArchData( "EM_XTENSA", |
