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 # Shortcuts
CC=clang --target=aarch64-none-elf -mcpu=cortex-a57 CC=clang --target=aarch64-none-elf -mcpu=cortex-a57
# CC=$(AARCH64_TOOLCHAIN)-gcc LD=ld.lld
LD=$(AARCH64_TOOLCHAIN)-ld
OBJCOPY=$(AARCH64_TOOLCHAIN)-objcopy --target elf64-littleaarch64 OBJCOPY=$(AARCH64_TOOLCHAIN)-objcopy --target elf64-littleaarch64
CFLAGS += -O0 CFLAGS += -O0
CFLAGS += -g CFLAGS += -g
CFLAGS += -nostdlib #CFLAGS += -nostdlib
CFLAGS += -march=armv8-a #CFLAGS += -march=armv8-a
#CFLAGS += -std=c99 #CFLAGS += -std=c99
#CFLAGS += -pedantic #CFLAGS += -pedantic
#CFLAGS += -Wall #CFLAGS += -Wall
@ -26,7 +25,7 @@ BUILD_DIR=build
# Files # Files
KERNEL_MEMMAP = sys/memmap KERNEL_MEMMAP = aarch64/memmap
KERNEL_SOURCES = \ KERNEL_SOURCES = \
aarch64/boot.s \ aarch64/boot.s \
@ -45,7 +44,7 @@ kernel: $(BUILD_DIR)/kernel.elf # $(BUILD_DIR)/kernel.sym
$(BUILD_DIR)/kernel.elf: $(KERNEL_OBJS) $(BUILD_DIR)/kernel.elf: $(KERNEL_OBJS)
$(info linking target: $@) $(info linking target: $@)
$(LD) -T$(KERNEL_MEMMAP) $^ -o $@ $(LD) -T$(KERNEL_MEMMAP) -nostdlib $^ -o $@
$(info done: $@) $(info done: $@)
$(BUILD_DIR)/kernel.bin: $(BUILD_DIR)/kernel.elf $(BUILD_DIR)/kernel.bin: $(BUILD_DIR)/kernel.elf
@ -66,14 +65,15 @@ $(BUILD_DIR)/%.o: %
# helpers # helpers
QEMU_CMD = \ QEMU_CMD = \
qemu-system-aarch64 \ qemu-system-aarch64 \
-M virt \
-cpu cortex-a57 \ -cpu cortex-a57 \
-machine type=virt \
-nographic \ -nographic \
-smp 4 \ -smp 4 \
-m 4098 \ -m 4096 \
-kernel build/kernel.elf \ -kernel build/kernel.elf \
-serial stdio \ -serial stdio \
-monitor none -monitor none \
clean: clean:
rm -Rf ./$(BUILD_DIR)/* rm -Rf ./$(BUILD_DIR)/*
@ -83,4 +83,8 @@ run: kernel
debug: 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 .globl _start
.extern k_main
.extern stack_ptr
_start: _start:
mrs x0, mpidr_el1 // Check CPU ID mrs x0, mpidr_el1 // Check CPU ID
mov x1, 0xC1000000 mov x1, 0xC1000000
bic x0, x0, x1 bic x0, x0, x1
@ -12,13 +9,9 @@ _start:
b idle b idle
set_stack: set_stack:
ldr x30, stack_ptr // defined in sys/memmap ldr x30, =stack_ptr // defined in sys/memmap
mov sp, x30 mov sp, x30
bl start bl k_main
start:
mov x0, x30
bl k_main
idle: idle:
b idle b 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_init();
uart_putc('L'); uart_puts((unsigned char *) "Lowe OS\n");
uart_putc('o');
uart_putc('w');
uart_putc('e');
uart_putc('\n');
for (;;) { 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" #include "uart.h"
unsigned int *uart_base = (unsigned int *)UART_BASE; volatile unsigned int *UART0 = (unsigned int *)UART_BASE;
void void
@ -24,10 +24,18 @@ uart_init(void)
} }
void void
uart_putc(unsigned char c) uart_putc(unsigned char c)
{ {
*uart_base = c; *UART0 = (unsigned int) c;
if(c == '\n') }
*uart_base = '\r';
void
uart_puts(const unsigned char *s)
{
while(*s) {
*UART0 = (unsigned int) *(s++);
}
} }

View File

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