Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 1000
wzf1943 Avatar asked Mar 14 '14 04:03

wzf1943


People also ask

What is ARM assembly code?

Beau Carnes. Assembly language is a low-level programming language for a computer or other programmable device that is closest to the machine language. It is often specific to a particular computer architecture so there are multiple types of assembly languages. ARM is an increasingly popular assembly language.

What does .align mean in ARM assembly?

The ALIGN directive aligns the current location to a specified boundary by padding with zeros or NOP instructions.

How do you read assembly?

Reading from a FilePut the system call sys_read() number 3, in the EAX register. Put the file descriptor in the EBX register. Put the pointer to the input buffer in the ECX register. Put the buffer size, i.e., the number of bytes to read, in the EDX register.

Is ARM assembly difficult?

ARM has a very complex set of instructions. Not because it has a lot, but mostly because it is extremely difficult to know what are the core instructions which are in most of the versions of the instruction set.


1 Answers

  • 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
like image 115
scottt Avatar answered Sep 29 '22 18:09

scottt