Question

.syntax unified
.thumb

.cpu cortex-m4
.arch armv7e-m
.fpu fpv4-sp-d16

/* Changes from unprivileged to privileged mode. */
.thumb_func
.section    .kernel
.global     raise_privilege
.type       raise_privilege, %function
raise_privilege:
mrs     r0, control
bic     r0, r0, #1
msr     control, r0
dsb
isb
bx      lr

this is part of arm assembly code. I can check chip manual to figure out the meaning of the instructions. But I don't know how to figure out the behavior of assembler directives like .thumb_func. What's more, I also don't know how to use this part code, it doesn't' look like regular function. So I don't know how to "call" it.

Was it helpful?

Solution

  • The instructions starting with a . are really assembler directives. You can look them up in GAS: ARM machine directives
  • .syntax unified signals the use of unified ARM / Thumb assembly syntax. The concept is explained here and here.
  • .thumb_func signals the start of a Thumb mode function for ARM-Thumb interwork. The concept is explained here and here.
  • raise_privilege looks exactly like a void raise_privilege(void) leaf function (i.e. it doesn't call other functions) in C to me. Call it with:
bl raise_privilege

OTHER TIPS

gnu assembler is broken, goofy, awkward, choose your word...

in this case .thumb_func plus a label is all you need in order to be able to call that label the thumb_func tells the assembler the following label is something I may want to call or load the address and use bx.

so in this code or other you can simply

bl raise_priviliedge 

(if the bl can reach and/or the linker adds the trampoline). or you can

ldr rX,=raise_priviledge  
blx rX 

where rX is some general purpose register (r3 for example).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top