From 4be5ceeec644a14844f149557eb278d37194b5ca Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Mon, 3 Sep 2012 23:44:36 -0400 Subject: [PATCH] Initial commit --- Makefile | 52 +++++++++++++++++++++++++++++++++++++++++++++ boot/Makefile.inc | 3 +++ boot/start.s | 17 +++++++++++++++ kernel/Makefile.inc | 3 +++ kernel/hello.c | 23 ++++++++++++++++++++ link.ld | 9 ++++++++ 6 files changed, 107 insertions(+) create mode 100644 Makefile create mode 100644 boot/Makefile.inc create mode 100644 boot/start.s create mode 100644 kernel/Makefile.inc create mode 100644 kernel/hello.c create mode 100644 link.ld diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2d05d21 --- /dev/null +++ b/Makefile @@ -0,0 +1,52 @@ +# Aedrix root Makefile +# Copyright (C) 2012 Aaron Lindsay + +# Config options for the code itself (should be separated from the Makefile sometime) +ARCH = arm + +# Config options concerning the build process itself +VERBOSE = 0 # 1 shows all compiler flags, 0 shows cleaner output + +# Define the tools to be used +TOOL_PREFIX = arm-elf- +AS = $(TOOL_PREFIX)as +CC = $(TOOL_PREFIX)gcc +LD = $(TOOL_PREFIX)ld + +# Define the flags we'll need for our tools +KCFLAGS = -Wall -Wextra -Werror -nostdlib -nostartfiles -ffreestanding -std=gnu99 +KLDFLAGS = -T link.ld + +KOBJS = + +include boot/Makefile.inc +include kernel/Makefile.inc + +all: aedrix-kernel +#all: +# @echo $(KOBJS) + +aedrix-kernel: $(KOBJS) + $(if $(VERBOSE:1=),@echo ' LD $@') + $(if $(VERBOSE:1=),@)$(LD) $(KLDFLAGS) -o $@ $(KOBJS) + +%.o: %.c + $(if $(VERBOSE:1=),@echo ' CC $@') + $(if $(VERBOSE:1=),@)$(CC) $(KCFLAGS) -c -o $@ $< + +# Assembly files without preprocessor directives +%.o: %.s + $(if $(VERBOSE:1=),@echo ' AS $@') + $(if $(VERBOSE:1=),@)$(AS) -o $@ $< + +# Assembly files with preprocessor directives +%.o: %.S + $(if $(VERBOSE:1=),@echo ' AS $@') + $(if $(VERBOSE:1=),@)$(AS) -o $@ $< + +.PHONY : clean +clean: + @echo ' CLEAN *.o' + @rm -f $(KOBJS) + @echo ' CLEAN aedrix-kernel' + @rm -f aedrix-kernel diff --git a/boot/Makefile.inc b/boot/Makefile.inc new file mode 100644 index 0000000..d9df028 --- /dev/null +++ b/boot/Makefile.inc @@ -0,0 +1,3 @@ +BOOT_PREFIX = boot + +KOBJS += $(BOOT_PREFIX)/start.o diff --git a/boot/start.s b/boot/start.s new file mode 100644 index 0000000..018e1f3 --- /dev/null +++ b/boot/start.s @@ -0,0 +1,17 @@ +interrupt_vector_table: + b . @ Reset + b . + b . @ SWI instruction + b . + b . + b . + b . + b . + +.comm stack, 0x10000 @ Reserve 64k stack in the BSS +_start: + .globl _start + ldr sp, =stack+0x10000 @ Set up the stack + bl main @ Jump to the main function +1: + b 1b @ Halt diff --git a/kernel/Makefile.inc b/kernel/Makefile.inc new file mode 100644 index 0000000..21907ad --- /dev/null +++ b/kernel/Makefile.inc @@ -0,0 +1,3 @@ +KERNEL_PREFIX = kernel + +KOBJS += $(KERNEL_PREFIX)/hello.o diff --git a/kernel/hello.c b/kernel/hello.c new file mode 100644 index 0000000..694f5e1 --- /dev/null +++ b/kernel/hello.c @@ -0,0 +1,23 @@ +#define SERIAL_BASE 0x16000000 +#define SERIAL_FLAG_REGISTER 0x18 +#define SERIAL_BUFFER_FULL (1 << 5) + +void putc (char c) +{ + /* Wait until the serial buffer is empty */ + while (*(volatile unsigned long*)(SERIAL_BASE + SERIAL_FLAG_REGISTER) + & (SERIAL_BUFFER_FULL)); + /* Put our character, c, into the serial buffer */ + *(volatile unsigned long*)SERIAL_BASE = c; +} + +void puts (const char * str) +{ + while (*str) putc (*str++); +} + +int main (void) +{ + puts ("hello, world!\n"); + return 0; +} diff --git a/link.ld b/link.ld new file mode 100644 index 0000000..89f7549 --- /dev/null +++ b/link.ld @@ -0,0 +1,9 @@ +ENTRY (_start) + +SECTIONS +{ + . = 0; + .text : { *(.text*) *(.rodata*) } + .data : { *(.data*) } + .bss : { *(.bss*) *(COMMON*) } +}