From da4cc8b645cd80969ce1c5b3123032b23127a904 Mon Sep 17 00:00:00 2001 From: "L. Bradley LaBoon" Date: Fri, 6 Dec 2013 13:47:22 -0500 Subject: [PATCH] Separated functionality into separate files. Added initial (untested) support for ARM. --- Makefile | 34 ++++++ arch/arm-none-eabi/boot.s | 33 ++++++ arch/arm-none-eabi/linker.ld | 42 +++++++ {boot => arch/i586-elf}/boot.s | 0 linker.ld => arch/i586-elf/linker.ld | 0 driver/video/vga.c | 91 +++++++++++++++ include/brados/string.h | 8 ++ include/video/vga.h | 64 +++++++++++ kernel/brados.c | 160 ++++----------------------- lib/string.c | 12 ++ 10 files changed, 308 insertions(+), 136 deletions(-) create mode 100644 Makefile create mode 100644 arch/arm-none-eabi/boot.s create mode 100644 arch/arm-none-eabi/linker.ld rename {boot => arch/i586-elf}/boot.s (100%) rename linker.ld => arch/i586-elf/linker.ld (100%) create mode 100644 driver/video/vga.c create mode 100644 include/brados/string.h create mode 100644 include/video/vga.h create mode 100644 lib/string.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f6d0d8c --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +# Build environment +PREFIX ?= /home/brad/brados/brados-gcc +ARCH ?= i586-elf +GNU ?= $(PREFIX)/$(ARCH)/bin/$(ARCH) + +# Source files +SOURCES_ASM := arch/$(ARCH)/boot.s +SOURCES_C := driver/video/vga.c kernel/brados.c lib/string.c + +# Object files +OBJS := $(patsubst %.s,%.o,$(SOURCES_ASM)) +OBJS += $(patsubst %.c,%.o,$(SOURCES_C)) + +# Build flags +CFLAGS = -std=gnu99 -ffreestanding -Iinclude/ -O2 -Wall -Wextra +LDFLAGS = -ffreestanding -O2 -nostdlib -lgcc + +# Build rules +all: brados.bin +.PHONY: all clean + +brados.bin: $(OBJS) arch/$(ARCH)/linker.ld + $(GNU)-gcc -T arch/$(ARCH)/linker.ld -o $@ $(LDFLAGS) $(OBJS) + +clean: + rm -f $(OBJS) brados.bin + +# C +%.o: %.c Makefile + $(GNU)-gcc -c $< -o $@ $(CFLAGS) + +# Assembly +%.o: %.s Makefile + $(GNU)-as $< -o $@ diff --git a/arch/arm-none-eabi/boot.s b/arch/arm-none-eabi/boot.s new file mode 100644 index 0000000..27438f4 --- /dev/null +++ b/arch/arm-none-eabi/boot.s @@ -0,0 +1,33 @@ +.section ".text.boot" + +.globl Start +Start: + // Setup the stack + mov sp, #0x8000 + + // Clear out bss + ldr r4, =_bss_start + ldr r9, =_bss_end + mov r5, #0 + mov r6, #0 + mov r7, #0 + mov r8, #0 + b 2f + +1: + // Store multiple at r4 + stmia r4!, {r5-r8} + +2: + // If we are still below bss_end, loop + cmp r4, r9 + blo 1b + + // Call brados_main + ldr r3, =brados_main + blx r3 + +halt: + // Halt + wfe + b halt diff --git a/arch/arm-none-eabi/linker.ld b/arch/arm-none-eabi/linker.ld new file mode 100644 index 0000000..af831ea --- /dev/null +++ b/arch/arm-none-eabi/linker.ld @@ -0,0 +1,42 @@ +ENTRY(Start) + +SECTIONS +{ + /* Starts at LOADER_ADDR */ + . = 0x8000 + _start = .; + _text_start = .; + .text: + { + KEEP(*(.text.boot)) + *(.text) + } + . = ALIGN(4096); + _text_end = .; + + _rodata_start = .; + .rodata: + { + *(.rodata) + } + . = ALIGN(4096) + _rodata_end = .; + + _data_start = .; + .data: + { + *(.data) + } + . = ALIGN(4096); + _data_end = .; + + _bss_start = .; + .bss: + { + bss = .; + *(.bss) + } + . = ALIGN(4096) + _bss_end = .; + _end = .; +} diff --git a/boot/boot.s b/arch/i586-elf/boot.s similarity index 100% rename from boot/boot.s rename to arch/i586-elf/boot.s diff --git a/linker.ld b/arch/i586-elf/linker.ld similarity index 100% rename from linker.ld rename to arch/i586-elf/linker.ld diff --git a/driver/video/vga.c b/driver/video/vga.c new file mode 100644 index 0000000..832c450 --- /dev/null +++ b/driver/video/vga.c @@ -0,0 +1,91 @@ +#include +#include + +#include +#include