Basics on ARM processor

I am also teaching "Laboratory of Microprocessors" focusing ARM. I use ARM Lab Manual for the first experiences. 

I have been asking students to install a tool chain in ubuntu to develop experiments in the simulator provided by arm-...-gdb. Last year, one team made everything as the docker image:
https://github.com/EpicEric/gcc-arm.git



In order to use it: 

  • git clone https://github.com/EpicEric/gcc-arm.git
  • See README.md 
  • cd gcc-arm/
  • ./build_docker.sh emacs # any other editor that you prefer; perhaps, you will need sudo,and perhaps gedit suchs as: 
  •               sudo ./build_docker.sh gedit
  • docker run --rm -ti -v "$PWD/src":/home/student/src epiceric/gcc-arm



Note that your directory $PWD/src is attached to /home/student/src.
In this docker image, we have 2 tool-chains: arm-elf and arm-none-eabi. In the first part of the course, we are using arm-elf. We will use arm-none-eabi to deal with the versatille board, emulated by qemu.
The environment contains the alias:

student:~/src$ alias 
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias arm='arm-elf-gcc -S'
alias e7t='arm-elf-gdb -tui --command=/home/student/.gdbinit/evaluator7t'
alias eabi-as='arm-none-eabi-as -c -mcpu=arm926ej-s -g'
alias eabi-bin='arm-none-eabi-objcopy -O binary'
alias eabi-gcc='arm-none-eabi-gcc -c -mcpu=arm926ej-s -Wall -Wextra -g'
alias eabi-gdb='arm-none-eabi-gdb -tui --command=/home/student/.gdbinit/default'
alias eabi-ld='arm-none-eabi-ld'
alias eabi-qemu='arm-none-eabi-gdb -tui --command=/home/student/.gdbinit/qemu'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias gcc='arm-elf-gcc -Wall -Wextra -g'
alias gdb='arm-elf-gdb -tui --command=/home/student/.gdbinit/default'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
alias qemu='qemu-system-arm -M versatilepb -m 128M -nographic -s -S -kernel'

Let us one very silly program.
Edit hello.c:

void main() {
     printf("hello");
}

If you can not create hello.c, it must be due to permission. In this case, try:
~/gcc-arm$ chmod 777 src

Let us compile it:

arm-elf-gcc -Wall -g -o hello hello.c

-g: for debug in the ARM simulator provided by arm-elf-gdb:

To run and debug:
arm-elf-gdb hello

(gdb) target sim
(gdb) load
(gdb) break main
(gdb) run
(gdb) continue

Making "C-x A" (control-x A) you may see the following screen:


If you do: "C-x 2", you may see the C code or the machine code. Pretty cool, isn't it?
Compile hello.c to see the machine code as in:
arm-elf-gcc -S hello.c
which generates hello.s 

student:~/src$ arm-elf-gcc -S hello.c
hello.c: In function `main':
hello.c:1: warning: return type of 'main' is not `int'
student:~/src$ ls -alt |more
total 404
-rw-rw-r-- 1 student student    396 Apr 23 18:01 hello.s

See hello.s:

student:~/src$ more hello.s
.file "hello.c"
.section .rodata
.align 2
.LC0:
.ascii "hello\000"
.text
.align 2
.global main
.type main, %function
main:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 1, uses_anonymous_args = 0
mov ip, sp
stmfd sp!, {fp, ip, lr, pc}
sub fp, ip, #4
ldr r0, .L2
bl printf
ldmfd sp, {fp, sp, pc}
.L3:
.align 2
.L2:
.word .LC0
.size main, .-main
.ident "GCC: (GNU) 3.4.3"

You may use this file hello.s to generate the ARM executable file as in:
arm-elf-gcc -Wall -g -o alo hello.s

Comentários

Postar um comentário

Postagens mais visitadas deste blog

Assignments - 1

Assignments 2- 2021