summaryrefslogtreecommitdiff
path: root/boot/arch/amd64
diff options
context:
space:
mode:
authorChloe M. <chloe@aptel.org>2026-08-20 05:53:55 +0000
committerChloe M. <chloe@aptel.org>2026-08-20 05:56:44 +0000
commitae526fa3375b708d4380d0227e27d32e06b40b92 (patch)
tree3d8d9a448d4a9530aa4e45a75b292c1bd0b5bc0d /boot/arch/amd64
initial commit
Signed-off-by: Chloe M. <chloe@aptel.org>
Diffstat (limited to 'boot/arch/amd64')
-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
4 files changed, 60 insertions, 0 deletions
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