First commit

This commit is contained in:
giomba 2018-12-28 09:20:09 +01:00
commit 49f0237874
6 changed files with 124 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
bin/
obj/
.swp

33
Makefile Normal file
View File

@ -0,0 +1,33 @@
.POSIX:
CCX=arm-none-eabi-g++
CCFLAGS=-c -Wall -fno-stack-protector -ffreestanding -march=armv7-a -nostdlib -Iinclude -g
C_HDR=$(wildcard include/*.h)
C_SRC=$(wildcard src/*.cpp)
C_OBJ=$(patsubst src/%.cpp, obj/c_%.o, $(C_SRC))
A_SRC=$(wildcard src/*.s)
A_OBJ=$(patsubst src/%.s, obj/s_%.o, $(A_SRC))
.PHONY: all environ clean
all: environ bin/kernel.elf
environ:
mkdir -p bin
mkdir -p obj
bin/kernel.elf: environ $(A_OBJ) $(C_OBJ)
arm-none-eabi-ld --nmagic -nostdlib -T src/linker.ld -o bin/kernel.elf obj/*.o
# maybe -msomearch
obj/s_%.o: src/%.s
$(CCX) $(CCFLAGS) -o $@ $<
obj/c_%.o: src/%.cpp $(C_HDR)
$(CCX) $(CCFLAGS) -o $@ $<
clean:
rm -f bin/*
rm -f obj/*

4
dbg/qemu.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
qemu-system-arm -M virt -cpu cortex-a15 -nographic -kernel bin/kernel.elf -s -S

3
src/kernel.cpp Normal file
View File

@ -0,0 +1,3 @@
extern "C" int f(int a) {
return a + 1;
}

65
src/kernel.s Normal file
View File

@ -0,0 +1,65 @@
.extern f
.text
my_string:
.string "HELLO WORLD!\r\n\r\n"
.quad 0x00
.quad 0x5a
.align 4
.global _start
_start:
/* does nothing special */
mov r13, #0x8000
mov r1, #16
1:
ldr r0, =my_string
bl printk
sub r1, #1
cmp r1, #0
b 1b
lup:
b lup
.global printk
printk:
stmfd r13!, {r0, r1, r2, r3, r4, r14}
/* disable UART interrupts */
mov r2, #0x8004
movt r2, #0x01c2
ldr r1, [r2]
and r1, #0xfffffffc
str r1, [r2]
/* mask interrupts in CPU */
cpsid if
/* TBR */
mov r2, #0x8000
movt r2, #0x01c2
1:
ldr r1, [r0]
add r0, #4
mov r4, #4
2:
and r3, r1, #0xff
mov r1, r1, lsr#8
cmp r3, #0
beq 3f
str r3, [r2]
sub r4, #1
cmp r4, #0
bne 2b
b 1b
3:
ldmfd r13!, {r0, r1, r2, r3, r4, r15}

15
src/linker.ld Normal file
View File

@ -0,0 +1,15 @@
ENTRY(_start)
SECTIONS
{
. = 0x10000;
.text : {
*(.text)
}
.data : ALIGN(0x1000) {
*(.data)
}
.bss : ALIGN(0x1000) {
*(.bss)
}
}