ARMv7-A Bare Bones: Difference between revisions
[unchecked revision] | [unchecked revision] |
No edit summary |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{TutorialExplain}} |
|||
{{BeginnersWarning}} |
|||
{{Rating|1}}{{Kernel designs}} |
{{Rating|1}}{{Kernel designs}} |
||
In this tutorial, |
In this tutorial, you will write a basic ARM kernel and boot it. You will target the ARM |
||
Versatile Express development board for the Cortex-A15. |
Versatile Express development board for the Cortex-A15. |
||
<b>You should read [[Getting Started]] and [[Beginner Mistakes]]</b> before |
|||
starting this tutorial. |
|||
== Rationale == |
== Rationale == |
||
=== Why ARMv7-A? === |
|||
ARMv7 is likely the last purely 32-bit iteration of the ARM architecture, so |
ARMv7 is likely the last purely 32-bit iteration of the ARM architecture, so |
||
processors based on it are likely to be supported the longest. The 'A' profile is |
processors based on it are likely to be supported the longest. The 'A' profile is |
||
Line 15: | Line 14: | ||
most interest to OS developers. |
most interest to OS developers. |
||
=== Why the Cortex-A15? === |
|||
Largely because it's the most powerful ARMv7-A processor supported by QEMU, and it |
Largely because it's the most powerful ARMv7-A processor supported by QEMU, and it |
||
also has its own development board. |
also has its own development board. |
||
=== Why the Versatile Express? === |
|||
This board was designed by ARM Holdings as a prototyping board, so it makes sense |
This board was designed by ARM Holdings as a prototyping board, so it makes sense |
||
to target a relatively neutral platform built with the Cortex-A15 in mind. |
to target a relatively neutral platform built with the Cortex-A15 in mind. |
||
Line 25: | Line 24: | ||
== Toolchain == |
== Toolchain == |
||
You will be using the [[GNU Toolchain]] for this, so go read [[GCC Cross-Compiler]] if you |
|||
haven't already. The target platform is <code>arm-none-eabi</code>. You will need at |
haven't already. The target platform is <code>arm-none-eabi</code>. You will need at |
||
least [[GAS]], [[GCC]], and [[LD]], but it is also suggested to have [[GDB]], [[Objcopy]], and [[Objdump]]. |
|||
least <code>as</code>, <code>gcc</code>, and <code>ld</code>, but I suggest also |
|||
having <code>gdb</code>, <code>objcopy</code>, and <code>objdump</code>. |
|||
== Code == |
== Code == |
||
Line 34: | Line 32: | ||
_start.arm: |
_start.arm: |
||
<syntaxhighlight lang="asm"> |
|||
<pre> |
|||
.global _start |
.global _start |
||
_start: |
_start: |
||
ldr sp, =STACK_TOP |
|||
bl start |
bl start |
||
1: |
1: |
||
b 1b |
b 1b |
||
.size _start, . - _start |
.size _start, . - _start |
||
</syntaxhighlight> |
|||
</pre> |
|||
start.c: |
start.c: |
||
<syntaxhighlight lang="c"> |
<syntaxhighlight lang="c"> |
||
#include <stdint.h> |
|||
#define UART0_BASE 0x1c090000 |
#define UART0_BASE 0x1c090000 |
||
void start() |
void start() { |
||
{ |
|||
*(volatile uint32_t *)(UART0_BASE) = 'A'; |
*(volatile uint32_t *)(UART0_BASE) = 'A'; |
||
} |
} |
||
Line 56: | Line 55: | ||
linker.ld: |
linker.ld: |
||
<syntaxhighlight lang="c"> |
|||
<pre> |
|||
ENTRY(_start) |
ENTRY(_start) |
||
Line 63: | Line 62: | ||
* memory map provided in the CoreTile TRM (see below). |
* memory map provided in the CoreTile TRM (see below). |
||
*/ |
*/ |
||
. = 0x80010000 |
. = 0x80010000; |
||
/* Make sure our entry stub goes first */ |
/* Make sure our entry stub goes first */ |
||
Line 72: | Line 71: | ||
.bss : { *(.bss COMMON) } |
.bss : { *(.bss COMMON) } |
||
STACK_BASE = . |
STACK_BASE = .; |
||
. += 0x10000 |
. += 0x10000; |
||
STACK_TOP = . |
STACK_TOP = .; |
||
} |
} |
||
</syntaxhighlight> |
|||
</pre> |
|||
== Building and Running == |
== Building and Running == |
||
<syntaxhighlight lang="bash"> |
|||
<pre> |
|||
arm-none-eabi-as -march=armv7-a -mcpu=cortex-a15 _start.arm -o _start.o |
|||
arm-none-eabi-gcc -ffreestanding -Wall -Wextra -Werror -c start.c -o start.o |
|||
arm-none-eabi-ld -T linker.ld _start.o start.o -o kernel.elf |
|||
qemu-system-arm -M vexpress-a15 -cpu cortex-a15 -kernel kernel.elf -nographic |
|||
</syntaxhighlight> |
|||
</pre> |
|||
== Resources == |
|||
It's a lot of material, but these are invaluable references for developing on ARM platforms. |
|||
== See Also == |
|||
=== External Links === |
|||
* [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.subset.boards.express/index.html ARMv7 Cortex-A Series Programmer's Guide] |
* [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.subset.boards.express/index.html ARMv7 Cortex-A Series Programmer's Guide] |
||
* [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406c/index.html ARMv7-A Architecture Reference Manual] |
* [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406c/index.html ARMv7-A Architecture Reference Manual] |
||
Line 96: | Line 93: | ||
* [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.subset.boards.express/index.html CoreTile Express A-15 Technical Reference Manual] |
* [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.subset.boards.express/index.html CoreTile Express A-15 Technical Reference Manual] |
||
* [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.subset.boards.express/index.html Motherboard Express μATX Technical Reference Manual] |
* [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.subset.boards.express/index.html Motherboard Express μATX Technical Reference Manual] |
||
[[Category:ARM]] |
|||
[[Category:Bare bones tutorials]] |
Latest revision as of 05:19, 9 June 2024
Difficulty level |
---|
![]() Beginner |
Kernel Designs |
---|
Models |
Other Concepts |
In this tutorial, you will write a basic ARM kernel and boot it. You will target the ARM Versatile Express development board for the Cortex-A15.
Rationale
Why ARMv7-A?
ARMv7 is likely the last purely 32-bit iteration of the ARM architecture, so processors based on it are likely to be supported the longest. The 'A' profile is targeted at complex computing devices like smartphones, and is therefore of the most interest to OS developers.
Why the Cortex-A15?
Largely because it's the most powerful ARMv7-A processor supported by QEMU, and it also has its own development board.
Why the Versatile Express?
This board was designed by ARM Holdings as a prototyping board, so it makes sense to target a relatively neutral platform built with the Cortex-A15 in mind.
Toolchain
You will be using the GNU Toolchain for this, so go read GCC Cross-Compiler if you
haven't already. The target platform is arm-none-eabi
. You will need at
least GAS, GCC, and LD, but it is also suggested to have GDB, Objcopy, and Objdump.
Code
_start.arm:
.global _start
_start:
ldr sp, =STACK_TOP
bl start
1:
b 1b
.size _start, . - _start
start.c:
#include <stdint.h>
#define UART0_BASE 0x1c090000
void start() {
*(volatile uint32_t *)(UART0_BASE) = 'A';
}
linker.ld:
ENTRY(_start)
SECTIONS {
/* QEMU loads the kernel in Flash here. I strongly suggest you look at the
* memory map provided in the CoreTile TRM (see below).
*/
. = 0x80010000;
/* Make sure our entry stub goes first */
.stub : { _start.o(.text) }
.text : { *(.text) }
.rodata : { *(.rodata) }
.data : { *(.data) }
.bss : { *(.bss COMMON) }
STACK_BASE = .;
. += 0x10000;
STACK_TOP = .;
}
Building and Running
arm-none-eabi-as -march=armv7-a -mcpu=cortex-a15 _start.arm -o _start.o
arm-none-eabi-gcc -ffreestanding -Wall -Wextra -Werror -c start.c -o start.o
arm-none-eabi-ld -T linker.ld _start.o start.o -o kernel.elf
qemu-system-arm -M vexpress-a15 -cpu cortex-a15 -kernel kernel.elf -nographic