commit c95e490a219d92376b41a8042e3cd3dab81caa88 Author: Ilja Kartašov Date: Sat Feb 23 21:22:20 2019 +0100 Initiated diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a45d40f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.elf +.o +build/ diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..6489b6a --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Elias Löwe diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6a40d7a --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +# Lion's Share License -> LSL +# Löwenware Software Distribution -> LSD diff --git a/README.md b/README.md new file mode 100644 index 0000000..b262918 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Löwe OS +Operating System for ARMv8 (aarch64) architecture. + diff --git a/kernel/arm64/Makefile b/kernel/arm64/Makefile new file mode 100644 index 0000000..0d06677 --- /dev/null +++ b/kernel/arm64/Makefile @@ -0,0 +1,34 @@ +ASM=clang +TARGET=aarch64-none-elf +CPU=cortex-a57 +LD=ld.lld +OBJCOPY=objcopy --target elf64-littleaarch64 + +all: build/core.bin build/core.elf + +# compilation ----------------------------------------------------------------- + +build/core.o: core/core.s + $(ASM) -c -triple --target=$(TARGET) -mcpu=$(CPU) -O0 -g $< -o $@ + +build/uart.o: core/uart.s + $(ASM) -c --target=$(TARGET) -mcpu=$(CPU) -O0 -g $< -o $@ + +# ELF ------------------------------------------------------------------------- + +build/core.elf: build/core.o build/uart.o + $(LD) -Tcore/core.ld $^ -o $@ + +# BIN ------------------------------------------------------------------------- + +build/core.bin: build/core.elf + $(OBJCOPY) -O binary $< $@ + +build/core.sym: build/core.elf + $(OBJCOPY) --only-keep-debug $< $@ + $(OBJCOPY) --strip-debug build/core.elf + +# Clean ----------------------------------------------------------------------- + +clean: + rm -f build/* diff --git a/kernel/arm64/core.ld b/kernel/arm64/core.ld new file mode 100644 index 0000000..e59786f --- /dev/null +++ b/kernel/arm64/core.ld @@ -0,0 +1,12 @@ +ENTRY(_core_init) + +SECTIONS +{ + . = 0x40000000; + .text : { *(.text) } + .data : { *(.text) } + .bss : { *(.bss COMMON) } + . = ALIGN(10); + . = . + 0x1000; + stack_ptr = . ; +} diff --git a/kernel/arm64/core.s b/kernel/arm64/core.s new file mode 100644 index 0000000..2fc6bdc --- /dev/null +++ b/kernel/arm64/core.s @@ -0,0 +1,38 @@ +# file: core.s +# project: Löwe OS +# authors: Elias Löwe + +# ----------------------------------------------------------------------------- + + .global _core_init + .extern _uart_puts + +# ----------------------------------------------------------------------------- + + .text + +_core_init: + # set up stack pointer using x30 register + LDR x30, =0x40001000 + MOV sp, x30 + bl 1f + +1: + LDR x0, =some_int + BL _uart_putx + LDR x0, =greeting + BL _uart_puts +2: + B 2b + +# ----------------------------------------------------------------------------- + + .data + +greeting: + .asciz "\nStarting Lowe OS\n" + + + .equ some_int, 0x1234567890ABCDEF + +# ----------------------------------------------------------------------------- diff --git a/kernel/arm64/uart.s b/kernel/arm64/uart.s new file mode 100644 index 0000000..1bceca7 --- /dev/null +++ b/kernel/arm64/uart.s @@ -0,0 +1,93 @@ +# file : uart.s +# project : Löwe OS +# authors : Elias Löwe + +# address of UART for virt device in qemu + +# ----------------------------------------------------------------------------- + + .global _uart_putc # print single character uart + .global _uart_putx # print integer in HEX format to uart + .global _uart_puts # print null-terminated string to uart + +# ----------------------------------------------------------------------------- + + .text + +# helper to avoid extra data moving +# @x1 character print +uart_putc: + STP x2, lr, [sp, -16]! + + MOV x2, 0x09000000 # set UART address + STRB w1, [x2] # put character out + + LDP x2, lr, [sp], 16 + RET + +# ----------------------------------------------------------------------------- + + +# print character to uart +# @x0 character print +_uart_putc: + STR lr, [sp, -16]! + + MOV x1, x0 # set arguments + BL uart_putc # put character out + + LDR lr, [sp], 16 + RET + + +# ----------------------------------------------------------------------------- + +# @x0 integer to print +_uart_putx: + STP lr, x3, [sp, -32]! + STP x0, x1, [sp, 16] + + LDR x3, =60 # init bits counter 64-4 + +1: + LSR x1, x0, x3 # shift to digit + AND x1, x1, 0xF # keep only digit + CMP x1, 9 # compare it to 9 + BLS 2f # less or equal + ADD x1, x1, 0x37 # turn into ASCII HEX char + B 3f # continue to output + +2: + ADD x1, x1, 0x30 # turn into ASCII num char + +3: + BL uart_putc # output carachter + CBZ x3, 0f # if counter == 0 return + SUB x3, x3, 4 # otherwise subtract counter by 4 + B 1b # repeat + +0: + LDP lr, x3, [sp], 16 + LDP x0, x1, [sp], 16 + RET + +# ----------------------------------------------------------------------------- + +# @x0 pointer to string + +_uart_puts: + STR lr, [sp, -16]! + STP x0, x1, [sp, -16]! + +1: + LDRB w1, [x0], 1 # load byte of string from address in x0 + CBZ w1, 0f # return if zero + BL uart_putc # put charcter out + B 1b # loop + +0: + LDP x0, x1, [sp], 16 + LDR lr, [sp], 16 + RET + +# -----------------------------------------------------------------------------