summaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
Diffstat (limited to 'boot')
-rw-r--r--boot/Makefile6
-rw-r--r--boot/arch/amd64/Makefile6
-rw-r--r--boot/arch/amd64/mbr/Makefile16
-rw-r--r--boot/arch/amd64/mbr/link.ld21
-rw-r--r--boot/arch/amd64/mbr/mbr.S17
5 files changed, 66 insertions, 0 deletions
diff --git a/boot/Makefile b/boot/Makefile
new file mode 100644
index 0000000..8b744d3
--- /dev/null
+++ b/boot/Makefile
@@ -0,0 +1,6 @@
+.PHONY: all
+all: machine
+
+.PHONY: machine
+machine:
+ cd arch/$(CONFIG_TARGET_ARCH)/; $(MAKE)
diff --git a/boot/arch/amd64/Makefile b/boot/arch/amd64/Makefile
new file mode 100644
index 0000000..e92fecb
--- /dev/null
+++ b/boot/arch/amd64/Makefile
@@ -0,0 +1,6 @@
+.PHONY: all
+all: mbr
+
+.PHONY: mbr
+mbr:
+ cd mbr/; $(MAKE)
diff --git a/boot/arch/amd64/mbr/Makefile b/boot/arch/amd64/mbr/Makefile
new file mode 100644
index 0000000..f41e5cc
--- /dev/null
+++ b/boot/arch/amd64/mbr/Makefile
@@ -0,0 +1,16 @@
+CC = clang
+CFLAGS = \
+ -ffreestanding \
+ -nostdlib \
+ -nostdinc \
+ -mno-red-zone \
+ -mno-sse \
+ -mno-sse2 \
+ -target i386-unknown-elf
+
+.PHONY: all
+all: mbr
+
+.PHONY: mbr
+mbr:
+ clang -Tlink.ld $(CFLAGS) mbr.S -o $(GLOBAL_PROJECT_ROOT)/artifacts/mbr.bin
diff --git a/boot/arch/amd64/mbr/link.ld b/boot/arch/amd64/mbr/link.ld
new file mode 100644
index 0000000..6d25985
--- /dev/null
+++ b/boot/arch/amd64/mbr/link.ld
@@ -0,0 +1,21 @@
+OUTPUT_FORMAT(binary)
+
+SECTIONS {
+ . = 0x7C00;
+
+ .text : {
+ *(.text)
+ }
+
+ .data : {
+ *(.data)
+ }
+
+ .rodata : {
+ *(.rodata)
+ }
+
+ .bss : {
+ *(.bss)
+ }
+}
diff --git a/boot/arch/amd64/mbr/mbr.S b/boot/arch/amd64/mbr/mbr.S
new file mode 100644
index 0000000..e071a41
--- /dev/null
+++ b/boot/arch/amd64/mbr/mbr.S
@@ -0,0 +1,17 @@
+ .code16
+_start:
+ /* Normalize CS + other selectors */
+ ljmp $0x00,$1f
+1: xor %ax, %ax
+ mov %ax, %ds
+ mov %ax, %ss
+ mov %ax, %es
+ mov %ax, %gs
+ mov %ax, %fs
+2: cli
+ hlt
+ jmp 2b
+
+ .org 510
+ .byte 0x55
+ .byte 0xAA