Browse Source

initial commit

greatbridf 4 years ago
commit
cb2c39a5dc
5 changed files with 92 additions and 0 deletions
  1. 5 0
      .gitignore
  2. 36 0
      Makefile
  3. 9 0
      bochs.conf
  4. 9 0
      ldscript.ld
  5. 33 0
      src/boot.s

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+build/
+
+.vscode/
+
+test/

+ 36 - 0
Makefile

@@ -0,0 +1,36 @@
+BUILD_DIR=build
+MBR_NAME=$(BUILD_DIR)/mbr.bin
+BOOT_IMAGE_NAME=$(BUILD_DIR)/boot.img
+
+BOOT_SOURCE=src/boot.s
+
+AS=as
+CC=gcc
+DD=dd
+LD=ld
+
+$(BOOT_IMAGE_NAME): $(MBR_NAME)
+	$(DD) if=$(MBR_NAME) of=$(BOOT_IMAGE_NAME)
+	$(DD) if=/dev/zero of=$(BOOT_IMAGE_NAME) seek=1 bs=512 count=2879
+
+$(MBR_NAME): $(BUILD_DIR)/boot.o
+	$(LD) -t ldscript.ld $(BUILD_DIR)/boot.o -o $(MBR_NAME) --oformat=binary
+
+$(BUILD_DIR)/boot.o: $(BOOT_SOURCE)
+	$(AS) $< -o $@
+
+%.o: %.s
+	$(AS) $< -o $(BUILD_DIR)/$@
+
+%.o: %.c
+	$(CC) -c $< -o $(BUILD_DIR)/$@
+
+.PHONY: run
+run: $(BOOT_IMAGE_NAME)
+	-bochs -f bochs.conf
+
+.PHONY: clean
+clean:
+	-rm $(BUILD_DIR)/*.o
+	-rm $(MBR_NAME)
+	-rm $(BOOT_IMAGE_NAME)

+ 9 - 0
bochs.conf

@@ -0,0 +1,9 @@
+megs: 4
+
+floppya: 1_44=build/boot.img, status=inserted
+
+boot: floppy
+
+mouse: enabled=0
+
+display_library: x, options="gui_debug"

+ 9 - 0
ldscript.ld

@@ -0,0 +1,9 @@
+OUTPUT_FORMAT(binary)
+
+SECTIONS
+{
+    .text :
+    {
+        *(.text*)
+    }
+}

+ 33 - 0
src/boot.s

@@ -0,0 +1,33 @@
+.text
+.code16
+
+.globl _start
+
+_start:
+jmp $0x07c0, $(real_start-_start)
+
+real_start:
+movw %cs, %ax
+movw %ax, %ds
+movw %ax, %es
+movw %ax, %ss
+xorw %sp, %sp
+
+// print hello world
+mov $(string_hello-_start), %ax
+mov %ax, %bp
+movw $0x1301, %ax
+movw $0x000f, %bx
+movw $12, %cx
+movw $0, %dx
+int $0x10
+
+die:
+hlt
+jmp die
+
+string_hello:
+.string "Hello World!"
+
+.space 510 - (.-_start)
+.word 0xaa55