Search code examples
assemblyarmgnu-assemblercortex-m

Understanding this part arm assembly code


.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.


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