From e5b5905eb3134a409638a5a20462000ef159e1e6 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 7 Apr 2018 07:28:20 +0300 Subject: [PATCH] initial commit --- .gitignore | 6 ++++++ Makefile | 44 ++++++++++++++++++++++++++++++++++++++++++++ pcboot.ld | 22 ++++++++++++++++++++++ src/boot/boot.s | 37 +++++++++++++++++++++++++++++++++++++ src/startup.s | 11 +++++++++++ 5 files changed, 120 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 pcboot.ld create mode 100644 src/boot/boot.s create mode 100644 src/startup.s diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50d3557 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.o +*.swp +*.d +*.bin +test +*.map diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d034876 --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +csrc = $(wildcard src/*.c) $(wildcard src/libc/*.c) +ssrc = $(wildcard src/*.s) $(wildcard src/libc/*.s) $(wildcard src/boot/*.s) +obj = $(csrc:.c=.o) $(ssrc:.s=.o) +dep = $(obj:.o=.d) +elf = test +bin = test.bin + +warn = -pedantic -Wall +dbg = -g +inc = -Isrc -Isrc/libc + +CFLAGS = $(ccarch) $(warn) $(dbg) -nostdinc -fno-builtin $(inc) $(def) +ASFLAGS = $(asarch) $(dbg) -nostdinc -fno-builtin $(inc) +LDFLAGS = $(ldarch) -T pcboot.ld -print-gc-sections + + +ifneq ($(shell uname -m), i386) + ccarch = -m32 + asarch = --32 + ldarch = -m elf_i386 +endif + +$(bin): $(elf) + objcopy -O binary $< $@ + +$(elf): $(obj) + $(LD) -o $@ $(obj) -Map link.map $(LDFLAGS) + +-include $(dep) + +%.d: %.c + @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ + +.PHONY: clean +clean: + rm -f $(obj) $(bin) + +.PHONY: cleandep +cleandep: + rm -f $(dep) + +.PHONY: run +run: $(bin) + qemu-system-i386 -fda $(bin) diff --git a/pcboot.ld b/pcboot.ld new file mode 100644 index 0000000..f629124 --- /dev/null +++ b/pcboot.ld @@ -0,0 +1,22 @@ +OUTPUT_ARCH(i386) + +SECTIONS { + /* BIOS will load us at 0x7c000h */ + . = 0x7c000; + + .boot : { * (.boot); } + .startup : { * (.startup); } + .text : { * (.text); } + .rodata : { * (.rodata); } + .data : { * (.data); } + + .bss ALIGN(4): { + _bss_start = .; + * (.bss); + . = ALIGN(4); + _bss_end = .; + } + _bss_size = SIZEOF(.bss); + + _mem_start = .; +} diff --git a/src/boot/boot.s b/src/boot/boot.s new file mode 100644 index 0000000..e3fd206 --- /dev/null +++ b/src/boot/boot.s @@ -0,0 +1,37 @@ + .code16 + .section .boot,"a" + + mov $0x13, %ax + int $0x10 + + mov $1, %al + mov $0x3c8, %dx + outb %al, %dx + mov $0x3c9, %dx + mov $63, %al + outb %al, %dx + xor %al, %al + outb %al, %dx + outb %al, %dx + + mov $200, %ebx + mov $0x00000101, %eax + pushl $0xa000 + popl %es + xor %di, %di +fill: + mov %ebx, %ecx + and $1, %ecx + jnz 0f + rol $16, %eax +0: mov $80, %ecx + rep stosl + dec %ebx + jnz fill + + cli + hlt + + .org 510 + .byte 0x55 + .byte 0xaa diff --git a/src/startup.s b/src/startup.s new file mode 100644 index 0000000..8e2c2ea --- /dev/null +++ b/src/startup.s @@ -0,0 +1,11 @@ + .code32 + .section .startup + + .extern _bss_start + .extern _bss_end + + xor %eax, %eax + mov _bss_start, %edi + mov _bss_size, %ecx + shr $4, %ecx + rep stosl -- 1.7.10.4