summaryrefslogtreecommitdiffstats
path: root/arch/x86/boot/multiboot
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/boot/multiboot')
-rw-r--r--arch/x86/boot/multiboot/Makefile25
-rw-r--r--arch/x86/boot/multiboot/multiboot.s11
2 files changed, 30 insertions, 6 deletions
diff --git a/arch/x86/boot/multiboot/Makefile b/arch/x86/boot/multiboot/Makefile
new file mode 100644
index 0000000..995237d
--- /dev/null
+++ b/arch/x86/boot/multiboot/Makefile
@@ -0,0 +1,25 @@
+# If you want run this makefile immediately, then set environment
+# variables (CC, LD, AS, OBJDUMP) to path of your cross-compiler.
+#
+# The best way to build multiboot header is to run the corresponding
+# target in the main Makefile, which is in the root of the
+# project (.../path/to/os/Makefile)
+
+MULTIBOOT_HEADER = $(ARCH_INCLUDE)/multiboot.h
+BARE_MULTIBOOT_HEADER = bare_multiboot.h
+
+.PHONY: all clean
+
+all: $(BARE_MULTIBOOT_HEADER)
+
+$(BARE_MULTIBOOT_HEADER): $(MULTIBOOT_HEADER)
+ $(CC) -E -dM -undef -fsyntax-only $(MULTIBOOT_HEADER) > $(BARE_MULTIBOOT_HEADER)
+# Delete all defines that have double underscore
+ sed -i '/__/d' $(BARE_MULTIBOOT_HEADER)
+# Replace "#define" with ".set" on each line
+ sed -i 's/#define/.set/g' $(BARE_MULTIBOOT_HEADER)
+# Put a comma after the macro name
+ sed -i 's/\>/,/2' $(BARE_MULTIBOOT_HEADER)
+
+clean:
+ rm $(BARE_MULTIBOOT_HEADER)
diff --git a/arch/x86/boot/multiboot/multiboot.s b/arch/x86/boot/multiboot/multiboot.s
index 33e54f1..e6e8c21 100644
--- a/arch/x86/boot/multiboot/multiboot.s
+++ b/arch/x86/boot/multiboot/multiboot.s
@@ -1,13 +1,12 @@
# https://www.gnu.org/software/grub/manual/multiboot/multiboot.html
+.include "bare_multiboot.h" # the file is auto-generated
+
/*
Declare constants for the multiboot header.
*/
-.set ALIGN, 1 << 0 # align loaded modules on page boundaries
-.set MEMINFO, 1 << 1 # provide memory map
-.set FLAGS, ALIGN | MEMINFO # this is the Multiboot 'flag' field
-.set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header
-.set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot
+.set FLAGS, MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO # this is the Multiboot 'flag' field
+.set CHECKSUM, -(MULTIBOOT_HEADER_MAGIC + FLAGS) # checksum of above, to prove we are multiboot
/*
Declare a multiboot header that marks the program as a kernel.
@@ -19,7 +18,7 @@ its own section so the header can be forced to be within the first
*/
.section .multiboot
.align 4
-.long MAGIC
+.long MULTIBOOT_HEADER_MAGIC
.long FLAGS
.long CHECKSUM