Set development environment with UART debug output for aarch64

This commit is contained in:
Ilja Kartašov 2019-05-30 08:44:01 +02:00
parent 8718f035a5
commit 08ffb6ee94
8 changed files with 50 additions and 63 deletions

View File

@ -6,14 +6,13 @@ AARCH64_TOOLCHAIN ?= aarch64-linux-gnu
# Shortcuts
CC=clang --target=aarch64-none-elf -mcpu=cortex-a57
# CC=$(AARCH64_TOOLCHAIN)-gcc
LD=$(AARCH64_TOOLCHAIN)-ld
LD=ld.lld
OBJCOPY=$(AARCH64_TOOLCHAIN)-objcopy --target elf64-littleaarch64
CFLAGS += -O0
CFLAGS += -g
CFLAGS += -nostdlib
CFLAGS += -march=armv8-a
#CFLAGS += -nostdlib
#CFLAGS += -march=armv8-a
#CFLAGS += -std=c99
#CFLAGS += -pedantic
#CFLAGS += -Wall
@ -26,7 +25,7 @@ BUILD_DIR=build
# Files
KERNEL_MEMMAP = sys/memmap
KERNEL_MEMMAP = aarch64/memmap
KERNEL_SOURCES = \
aarch64/boot.s \
@ -45,7 +44,7 @@ kernel: $(BUILD_DIR)/kernel.elf # $(BUILD_DIR)/kernel.sym
$(BUILD_DIR)/kernel.elf: $(KERNEL_OBJS)
$(info linking target: $@)
$(LD) -T$(KERNEL_MEMMAP) $^ -o $@
$(LD) -T$(KERNEL_MEMMAP) -nostdlib $^ -o $@
$(info done: $@)
$(BUILD_DIR)/kernel.bin: $(BUILD_DIR)/kernel.elf
@ -66,14 +65,15 @@ $(BUILD_DIR)/%.o: %
# helpers
QEMU_CMD = \
qemu-system-aarch64 \
-M virt \
-cpu cortex-a57 \
-machine type=virt \
-nographic \
-smp 4 \
-m 4098 \
-m 4096 \
-kernel build/kernel.elf \
-serial stdio \
-monitor none
-monitor none \
clean:
rm -Rf ./$(BUILD_DIR)/*
@ -83,4 +83,8 @@ run: kernel
debug: kernel
$(QEMU_CMD) -gdb tcp::1234 -S
$(QEMU_CMD) -S -gdb tcp::1234 & \
gdb-multiarch -q \
-ex 'file build/kernel.elf' \
-ex 'target remote localhost:1234'
kill %1

View File

@ -1,22 +0,0 @@
.global _boot
.extern k_main
_boot:
mrs x0, mpidr_el1 // Check CPU ID
mov x1, 0xC1000000
bic x0, x0, x1
cbz x0, set_stack
b idle
set_stack:
ldr x30, =0x40001000
mov sp, x30
bl start
start:
mov x0, x30
bl k_main
idle: b idle

View File

@ -1,10 +1,7 @@
.text
.globl _start
.extern k_main
.extern stack_ptr
_start:
mrs x0, mpidr_el1 // Check CPU ID
mov x1, 0xC1000000
bic x0, x0, x1
@ -12,12 +9,8 @@ _start:
b idle
set_stack:
ldr x30, stack_ptr // defined in sys/memmap
ldr x30, =stack_ptr // defined in sys/memmap
mov sp, x30
bl start
start:
mov x0, x30
bl k_main
idle:

16
aarch64/memmap Normal file
View File

@ -0,0 +1,16 @@
ENTRY(_start)
SECTIONS
{
/* For some reason qemu UART doesn't work with smaller address */
. = 0x40000000;
.boot . : { boot.o(.text) }
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss COMMON) }
. = ALIGN(8);
. = . + 0x1000;
stack_ptr = . ;
}

View File

@ -25,13 +25,10 @@ k_main(void)
{
uart_init();
uart_putc('L');
uart_putc('o');
uart_putc('w');
uart_putc('e');
uart_putc('\n');
uart_puts((unsigned char *) "Lowe OS\n");
for (;;) {
__asm__("WFE");
}
}

View File

@ -1,12 +0,0 @@
ENTRY(_start)
SECTIONS
{
. = 0x40000000;
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss COMMON) }
. = ALIGN(8);
. = . + 0x1000;
stack_ptr = . ;
}

View File

@ -15,7 +15,7 @@
#include "uart.h"
unsigned int *uart_base = (unsigned int *)UART_BASE;
volatile unsigned int *UART0 = (unsigned int *)UART_BASE;
void
@ -24,10 +24,18 @@ uart_init(void)
}
void
uart_putc(unsigned char c)
{
*uart_base = c;
if(c == '\n')
*uart_base = '\r';
*UART0 = (unsigned int) c;
}
void
uart_puts(const unsigned char *s)
{
while(*s) {
*UART0 = (unsigned int) *(s++);
}
}

View File

@ -22,9 +22,12 @@
void
uart_init(void);
void
uart_putc(unsigned char c);
void
uart_puts(const unsigned char *s);
#endif /* !UART_H */