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