Fri, 15 Dec 2017 22:17:16 +0100
7 files changed,
96 insertions(+),
66 deletions(-)
D
boot.s
@@ -1,50 +0,0 @@
-.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
boot/boot.s
@@ -0,0 +1,61 @@
+.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 + mov $0, %al + mov $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: + + # TODO: + # - load kernel into memory starting at adress 0x10000 + # (NOTE: this code can only be jumped to after loading the global descriptor table + # because it uses absolute adresses larger than 16 bit) + # - load global descriptor table and far jump into protected mode + # - activate A20 gate + # - jump to low kernel code + + # loop forever + +loop: + jmp loop + + # some data +message: + .ascii " Hello World!" + .byte 0x00 + +end: + .=510 + .byte 0x55 + .byte 0xAA
A
boot/makefile
@@ -0,0 +1,5 @@
+.RECIPEPREFIX = > + +.PHONY: build +build: boot.s +> $(GCC_PREFIX)as -o $(BUILD_DIR)/boot.o boot.s
M
link.txt
→
link.txt
@@ -6,13 +6,20 @@ PAGE_SIZE = 1 << 12;
MEMORY { - BOOT : ORIGIN = 0x00007C00, LENGTH = 0x00000300 + BOOT : ORIGIN = 0x00007C00, LENGTH = 0x00000200 + SECOND_STAGE : ORIGIN = 0x00010000, LENGTH = 0x00090000 } SECTIONS { - BOOT : + BOOT : AT(0x0000) { build/boot.o(.text) } >BOOT + + SECOND_STAGE : AT(ADDR(BOOT) + SIZEOF(BOOT)) + { + build/second_stage.o(.text) + build/second_stage.o(.data) + } >SECOND_STAGE }
M
makefile
→
makefile
@@ -1,16 +1,18 @@
.RECIPEPREFIX = > -CURRENT_DIR = $(shell pwd) -BUILD_DIR = $(CURRENT_DIR)/build +export CURRENT_DIR = $(shell pwd) +export 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 +export GCC_PREFIX = $(HOME)/opt/cross/i686-elf-/bin/i686-elf- +export 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 -> +build: +> $(MAKE) -C boot build +> $(MAKE) -C second_stage build +> $(GCC_PREFIX)ld -T link.txt -Map=mapfile.txt -o $(BUILD_DIR)/base.img --oformat binary .PHONY: clear clear:@@ -22,11 +24,5 @@ > ./run.sh
.PHONY: rebuild rebuild: -> make clear -> make build - -$(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+> $(MAKE) clear +> $(MAKE) build
A
second_stage/makefile
@@ -0,0 +1,8 @@
+.RECIPEPREFIX = > + +.PHONY: build +build: build/entry.o +> $(GCC_PREFIX)ld -i build/entry.o -o $(BUILD_DIR)/second_stage.o --oformat elf32-i386 + +build/entry.o: entry.s +> $(GCC_PREFIX)as -o $@ $?