diff --git a/Makefile b/Makefile index f6d0d8c..a27f836 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +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 $@ +# 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 index 27438f4..30a5f49 100644 --- a/arch/arm-none-eabi/boot.s +++ b/arch/arm-none-eabi/boot.s @@ -1,33 +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 +.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 index af831ea..4044ed0 100644 --- a/arch/arm-none-eabi/linker.ld +++ b/arch/arm-none-eabi/linker.ld @@ -1,42 +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 = .; -} +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/arch/i586-elf/boot.s b/arch/i586-elf/boot.s index 7900d1f..9dd64ac 100644 --- a/arch/i586-elf/boot.s +++ b/arch/i586-elf/boot.s @@ -1,40 +1,40 @@ -# Declare constants for creating a multiboot header -.set ALIGN, 1<<0 -.set MEMINFO, 1<<1 -.set FLAGS, ALIGN | MEMINFO -.set MAGIC, 0x1BADB002 -.set CHECKSUM, -(MAGIC + FLAGS) - -# Declare multiboot header -.section .multiboot -.align 4 -.long MAGIC -.long FLAGS -.long CHECKSUM - -# Create a 16 KiB stack -.section .bootstrap_stack -stack_bottom: -.skip 16384 -stack_top: - -# Kernel entry point -.section .text -.global _start -.type _start, @function -_start: - # We are now in kernel mode! - # Setup the stack - movl $stack_top, %esp - - # Call the main kernel function - call brados_main - - # In case the function returns, enter an endless loop - cli - hlt -.Lhang: - jmp .Lhang - -# Set the size of the _start symbol for debugging -.size _start, . - _start +# Declare constants for creating a multiboot header +.set ALIGN, 1<<0 +.set MEMINFO, 1<<1 +.set FLAGS, ALIGN | MEMINFO +.set MAGIC, 0x1BADB002 +.set CHECKSUM, -(MAGIC + FLAGS) + +# Declare multiboot header +.section .multiboot +.align 4 +.long MAGIC +.long FLAGS +.long CHECKSUM + +# Create a 16 KiB stack +.section .bootstrap_stack +stack_bottom: +.skip 16384 +stack_top: + +# Kernel entry point +.section .text +.global _start +.type _start, @function +_start: + # We are now in kernel mode! + # Setup the stack + movl $stack_top, %esp + + # Call the main kernel function + call brados_main + + # In case the function returns, enter an endless loop + cli + hlt +.Lhang: + jmp .Lhang + +# Set the size of the _start symbol for debugging +.size _start, . - _start diff --git a/arch/i586-elf/linker.ld b/arch/i586-elf/linker.ld index 2307515..5390498 100644 --- a/arch/i586-elf/linker.ld +++ b/arch/i586-elf/linker.ld @@ -1,38 +1,38 @@ -/* Kernel entry point */ -ENTRY(_start) - -/* Define the locations of the object file sections */ -SECTIONS -{ - /* Sections begin at 1 MiB */ - . = 1M; - - /* The multiboot header needs to come first, followed by program code */ - .text BLOCK(4K) : ALIGN(4K) - { - *(.multiboot) - *(.text) - } - - /* Read-only data */ - .rodata BLOCK(4K) : ALIGN(4K) - { - *(.rodata) - } - - /* Initialized read-write data */ - .data BLOCK(4K) : ALIGN(4K) - { - *(.data) - } - - /* Uninitialized read-write data and stack */ - .bss BLOCK(4K) : ALIGN(4K) - { - *(COMMON) - *(.bss) - *(.bootstrap_stack) - } - - /* Add other sections here */ -} +/* Kernel entry point */ +ENTRY(_start) + +/* Define the locations of the object file sections */ +SECTIONS +{ + /* Sections begin at 1 MiB */ + . = 1M; + + /* The multiboot header needs to come first, followed by program code */ + .text BLOCK(4K) : ALIGN(4K) + { + *(.multiboot) + *(.text) + } + + /* Read-only data */ + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + /* Initialized read-write data */ + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } + + /* Uninitialized read-write data and stack */ + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + *(.bootstrap_stack) + } + + /* Add other sections here */ +} diff --git a/driver/video/vga.c b/driver/video/vga.c index 832c450..ff335ae 100644 --- a/driver/video/vga.c +++ b/driver/video/vga.c @@ -1,91 +1,91 @@ -#include -#include - -#include -#include