Skip to content

Wrong ARM instructions for saving registers #17

Open
@WestfW

Description

@WestfW

in coopDoYield() and similar functions ( https://github.com/arduino-libraries/Scheduler/blob/master/src/Scheduler.cpp#L84 ), the inline asm code does:

		"stmia r0, {r4-r7};"
		/* store high registers */
		"mov   r1, r8;"      /* move them to low registers first. */
		"mov   r2, r9;"
		"mov   r3, r10;"
		"mov   r4, r11;"
		"mov   r5, r12;"
		"mov   r6, lr;"
		"stmia r0, {r1-r6};"

But the stmia instructions SHOULD be using the write-back syntax:

		"stmia r0!, {r4-r7};"
                 :
		"stmia r0!, {r1-r6};"

For one thing, it is counting on the updated address being written back to r0. For another, only the write-back version of the instruction is implemented in Cortex-M0+ (ARMv6m) See https://developer.arm.com/documentation/dui0497/a/BABCAEDD
Also, recent versions of the assembler (?) apparently generate a warning for this. See https://forums.adafruit.com/viewtopic.php?f=63&t=188637

Also, there is conditional compilation here that tests ARDUINO_ARCH_SAMD, but it really should probably be testing something like ARM_ARCH_6M since the SAMD line now includes ARM-V7m parts (SAMD51)

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions