Thu, 14 Dec 2017 23:46:15 +0100
5 files changed,
102 insertions(+),
0 deletions(-)
A
boot.s
@@ -0,0 +1,50 @@
+.section .text + + # disable interrupts + cli + + # canonicalize %CS:%EIP to a known value + ljmp $0, $start +start: + + # setup segments + mov $0x0000, %ax + mov %ax, %ss + mov %ax, %ds + mov %ax, %es + mov %ax, %fs + + # setup stack + mov $0x9000, %ax + mov %ax, %bp + mov %ax, %sp + + # select display page 0 + movb $0, %al + movb 0x05, %ah + int $0x10 + + # print hello world + mov $message, %si + mov $0x0000, %bx + mov $0x0E, %ah + +print_loop: + lodsb + or %al, %al + jz print_end + int $0x10 + jmp print_loop +print_end: + + # loop forever +loop: + jmp loop + + # some data + message: .ascii "Hello World!\n\0" + +end: + .=510 + .byte 0x55 + .byte 0xAA
A
link.txt
@@ -0,0 +1,18 @@
+INPUT(build/boot.o) +OUTPUT_FORMAT(binary) +OUTPUT_ARCH(i386) + +PAGE_SIZE = 1 << 12; + +MEMORY +{ + BOOT : ORIGIN = 0x00007C00, LENGTH = 0x00000300 +} + +SECTIONS +{ + BOOT : + { + build/boot.o(.text) + } >BOOT +}
A
makefile
@@ -0,0 +1,27 @@
+.RECIPEPREFIX = > + +CURRENT_DIR = $(shell pwd) +BUILD_DIR = $(CURRENT_DIR)/build + +GCC_PREFIX = $(HOME)/opt/cross/i686-elf-/bin/i686-elf- +GCC_OPTIONS = -O0 -std=c++0x -Wno-write-strings -Wall -Wextra -fno-exceptions -fno-rtti -ffreestanding + +# OBJ_FILES = $(wildcard obj/asm/*.o) $(wildcard obj/cpp/*.o) + +.PHONY: build +build: $(BUILD_DIR)/base.img +> + +.PHONY: clear +clear: +> rm $(BUILD_DIR)/*.* + +.PHONY: run +run: +> ./run.sh + +$(BUILD_DIR)/base.img: $(BUILD_DIR)/boot.o +> $(GCC_PREFIX)ld -T link.txt -Map=mapfile.txt -o $(BUILD_DIR)/base.img --oformat binary + +$(BUILD_DIR)/boot.o: boot.s +> $(GCC_PREFIX)as -o $(BUILD_DIR)/boot.o boot.s