initial commit
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 7 Apr 2018 04:28:20 +0000 (07:28 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 7 Apr 2018 04:28:20 +0000 (07:28 +0300)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
pcboot.ld [new file with mode: 0644]
src/boot/boot.s [new file with mode: 0644]
src/startup.s [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..50d3557
--- /dev/null
@@ -0,0 +1,6 @@
+*.o
+*.swp
+*.d
+*.bin
+test
+*.map
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 (file)
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 (file)
index 0000000..e3fd206
--- /dev/null
@@ -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 (file)
index 0000000..8e2c2ea
--- /dev/null
@@ -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