Skip to content

Commit 587845c

Browse files
committed
bootloader: improve exec function
Add some comments about what every assembly line does. Mark which c-variables are used and which registers are used so that GCC doesn't do the wrong optimizations.
1 parent 5ce4a18 commit 587845c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/bootloader/bootloader.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,18 @@ static void _render_bootloader_finished_marker(void)
190190
delay_ms(30);
191191
}
192192

193-
void _binExec(void* l_code_addr) __attribute__((noreturn));
193+
// See `exception_table` in `startup_samd51.c` for description of the content at `l_code_addr`.
194+
void _binExec(void* l_code_addr) __attribute__((noreturn, noinline));
194195
void _binExec(void* l_code_addr)
195196
{
196197
__asm__(
197-
"mov r1, r0 \n"
198-
"ldr r0, [r1, #4] \n"
199-
"ldr sp, [r1] \n"
200-
"blx r0");
201-
(void)l_code_addr;
198+
"mov r1, %0 \n" // Copy l_code_addr to r1
199+
"ldr r0, [r1, #4] \n" // Load l_code_addr+4 (address of Reset Handler) to r0
200+
"ldr sp, [r1] \n" // Load l_code_addr (address of Initial Stack Pointer) to SP
201+
"blx r0" // Jump to r0
202+
: /* no outputs */
203+
: "r"(l_code_addr) /* input: l_code_addr */
204+
: "r0", "r1", "sp") /* clobber: r0, r1, sp */;
202205
__builtin_unreachable();
203206
}
204207

0 commit comments

Comments
 (0)