initial import of armv8-hello

This commit is contained in:
Jim Huang
2016-01-05 13:27:51 +08:00
commit 89bacd7f88
8 changed files with 159 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
armv8-hello is written by:
Jim Huang <jserv.tw@gmail.com>
Copyrighted by:
National Cheng Kung University, Taiwan
+26
View File
@@ -0,0 +1,26 @@
armv8-hello is freely redistributable under the two-clause BSD License:
Copyright (C) 2016 National Cheng Kung University, Taiwan.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
+37
View File
@@ -0,0 +1,37 @@
IMAGE := kernel.elf
CROSS_COMPILE = aarch64-linux-gnu-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
CFLAGS = -Wall -fno-common -O0 -g \
-nostdlib -nostartfiles -ffreestanding \
-march=armv8-a
OBJS = hello.o
all: $(IMAGE)
boot.o: boot.S
$(CC) boot.S -c -o boot.o
$(IMAGE): kernel.ld boot.o $(OBJS)
$(LD) boot.o $(OBJS) -T kernel.ld -o $(IMAGE)
$(OBJDUMP) -d kernel.elf > kernel.list
$(OBJDUMP) -t kernel.elf | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym
qemu: $(IMAGE)
@qemu-system-aarch64 -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo
qemu-system-aarch64 -machine virt -cpu cortex-a57 \
-smp 4 -m 4096 \
-nographic -serial mon:stdio \
-kernel $(IMAGE)
clean:
rm -f $(IMAGE) *.o *.list *.sym
.PHONY: all qemu clean
+26
View File
@@ -0,0 +1,26 @@
Hello World for bare metal ARM using QEMU
Prerequisites
-------------
- Install [Linaro toolchain](http://www.linaro.org/downloads/) for Aarch64 little-endian
```
sudo apt-get install gcc-aarch64-linux-gnu
```
- Install recent QEMU with Aarch64 target
```
sudo apt-get install qemu-system-arm
```
Building and Verification
-------------------------
* Changes the current working directory to the specified one and then
```
make
make qemu
```
Licensing
---------
`mini-arm-os` is freely redistributable under the two-clause BSD License.
Use of this source code is governed by a BSD-style license that can be found
in the `LICENSE` file.
+29
View File
@@ -0,0 +1,29 @@
#include "reg.h"
.text
.globl _start
_start:
/* init UART (38400 8N1) */
ldr x4, =UART_BASE // UART base
mov w5, #0x10 // IBRD
str w5, [x4, #0x24]
mov w5, #0xc300
orr w5, w5, #0x0001 // CR
str w5, [x4, #0x30]
/* check CPU ID */
mrs x0, mpidr_el1
tst x0, #15
b.ne other_cpu
b.eq boot_cpu
boot_cpu:
/* configure stack */
adrp x0, stacktop
mov sp, x0
b main
other_cpu:
b other_cpu
+14
View File
@@ -0,0 +1,14 @@
#include "reg.h"
int puts(const char *str)
{
while (*str)
*((unsigned int *) UART_BASE) = *str++;
return 0;
}
void main(void)
{
puts("Hello\n");
while (1);
}
+16
View File
@@ -0,0 +1,16 @@
OUTPUT_FORMAT("elf64-littleaarch64")
OUTPUT_ARCH(aarch64)
TARGET(binary)
STACKTOP = 0x51000000;
SECTIONS
{
. = 0x40010000;
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss) }
. = STACKTOP;
stacktop = .;
}
+6
View File
@@ -0,0 +1,6 @@
#ifndef __REG_H__
#define __REG_H__
#define UART_BASE 0x09000000
#endif