I'm trying to write a bootloader for an STM32 in Rust and I can't figure out how to correctly populate the stack pointer. Near as I can tell the code should be:
asm!("MOV SP, $0" :: "0"(stack_pointer)); // set the stack pointer
but the compiler disagrees:
error: invalid operand in inline asm: 'MOV SP, $0'
--> src/main.rs:38:5
|
38 | asm!("MOV SP, $0" :: "0"(stack_pointer)); // set the stack pointer
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: <inline asm>:1:11: error: unexpected token in operand
MOV SP,
^
--> src/main.rs:38:5
|
38 | asm!("MOV SP, $0" :: "0"(stack_pointer)); // set the stack pointer
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What am I doing wrong? It seem to be complaining about the dollar sign, but I got that directly from the documentation.
Per the conversation in the comments, I've tried two things, both of which compile(!) but neither of which seem to work (but that could be for any of a billion reasons, still working on it):
Version A:
asm!("MOV R0, #0x0800");
asm!("LSL R0, R0, #16");
asm!("MOV R1, #0x8000");
asm!("ORR R2, R1, R0");
asm!("LDRT R0, [R2]");
asm!("MOV SP, R0");
entry_point()
Version B:
#[inline(never)]
unsafe fn go(_addr: u32, entry_point: fn()->()) {
asm!("MOV SP, R0");
entry_point()
}