From 5bfc7f37466cd3848e8a74380c1aa702a82679b6 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Wed, 1 Nov 2017 13:23:42 +0000 Subject: [PATCH] Only support Multiboot 2 because of modules --- Makefile | 3 --- arch/Makefile | 6 +----- arch/boot.s | 28 +++++++++------------------- arch/linker.ld | 3 +-- arch/main.c | 16 +++++++++------- arch/{multiboot2.c => multiboot.c} | 4 ++-- arch/{multiboot2.h => multiboot.h} | 2 +- iso/Makefile | 4 ---- iso/rootfs/boot/grub/grub.cfg | 6 +----- 9 files changed, 24 insertions(+), 48 deletions(-) rename arch/{multiboot2.c => multiboot.c} (97%) rename arch/{multiboot2.h => multiboot.h} (99%) diff --git a/Makefile b/Makefile index a374788..23a8245 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,6 @@ all: all-kernel all-iso clean: clean-iso clean-kernel -run-kernel: - make run -C arch I=$(shell pwd)/include - all-kernel: make all -C arch I=$(shell pwd)/include diff --git a/arch/Makefile b/arch/Makefile index a193465..017a148 100644 --- a/arch/Makefile +++ b/arch/Makefile @@ -7,10 +7,7 @@ CCPREFIX = i686-elf- AS = $(CCPREFIX)as CC = $(CCPREFIX)gcc -OBJS = boot.s.o main.c.o logger.c.o console.c.o gdt.c.o gdt.asm.o idt.c.o idt.asm.o isr.c.o isr.asm.o multiboot2.c.o - -run: kernel - qemu-system-i386 -kernel kernel -d guest_errors +OBJS = boot.s.o main.c.o logger.c.o console.c.o gdt.c.o gdt.asm.o idt.c.o idt.asm.o isr.c.o isr.asm.o multiboot.c.o all: kernel @@ -19,7 +16,6 @@ clean: kernel: $(OBJS) $(CC) -T linker.ld -o $@ -ffreestanding -nostdlib -lgcc $(OBJS) - grub-file --is-x86-multiboot $@ grub-file --is-x86-multiboot2 $@ %.c.o: %.c diff --git a/arch/boot.s b/arch/boot.s index e698770..869fc7d 100644 --- a/arch/boot.s +++ b/arch/boot.s @@ -1,27 +1,17 @@ -.set MULTIBOOT_1_MAGIC, 0x1BADB002 -.set MULTIBOOT_1_FLAGS, (1 << 0) | (1 << 1) // Align, meminfo -.set MULTIBOOT_1_CHECKSUM, -(MULTIBOOT_1_MAGIC + MULTIBOOT_1_FLAGS) +.set MULTIBOOT_MAGIC, 0xE85250D6 +.set MULTIBOOT_ARCH, 0 +.set MULTIBOOT_LENGTH, 16 + 8 +.set MULTIBOOT_CHECKSUM, -(MULTIBOOT_MAGIC + MULTIBOOT_ARCH + MULTIBOOT_LENGTH) -.set MULTIBOOT_2_MAGIC, 0xE85250D6 -.set MULTIBOOT_2_ARCH, 0 -.set MULTIBOOT_2_LENGTH, 16 + 8 -.set MULTIBOOT_2_CHECKSUM, -(MULTIBOOT_2_MAGIC + MULTIBOOT_2_ARCH + MULTIBOOT_2_LENGTH) - -.section .multiboot2 +.section .multiboot .align 4 -.long MULTIBOOT_2_MAGIC -.long MULTIBOOT_2_ARCH -.long MULTIBOOT_2_LENGTH -.long MULTIBOOT_2_CHECKSUM +.long MULTIBOOT_MAGIC +.long MULTIBOOT_ARCH +.long MULTIBOOT_LENGTH +.long MULTIBOOT_CHECKSUM .long 0 .long 8 -.section .multiboot1 -.align 4 -.long MULTIBOOT_1_MAGIC -.long MULTIBOOT_1_FLAGS -.long MULTIBOOT_1_CHECKSUM - .section .bss .align 16 stack_bottom: diff --git a/arch/linker.ld b/arch/linker.ld index fb05265..7569f55 100644 --- a/arch/linker.ld +++ b/arch/linker.ld @@ -6,8 +6,7 @@ SECTIONS .text BLOCK(4K) : ALIGN(4K) { - *(.multiboot2) - *(.multiboot1) + *(.multiboot) *(.text) } diff --git a/arch/main.c b/arch/main.c index d3c72d1..c1d6064 100644 --- a/arch/main.c +++ b/arch/main.c @@ -1,7 +1,7 @@ #include #include "logger.h" -#include "multiboot2.h" +#include "multiboot.h" #include "gdt.h" #include "idt.h" @@ -9,15 +9,17 @@ void main(unsigned int multiboot_magic, unsigned long multiboot_info) { logger_initialize(); - if (multiboot_magic == KERNELMQ_MULTIBOOT_1_MAGIC) { - logger_info("Loaded with Multiboot-compliant bootloader, specification version 1."); - } - else if (multiboot_magic == KERNELMQ_MULTIBOOT_2_MAGIC) { + if (multiboot_magic == KERNELMQ_MULTIBOOT_2_MAGIC) { logger_info("Loaded with Multiboot-compliant bootloader, specification version 2."); - print_multiboot2_info(multiboot_info); + print_multiboot_info(multiboot_info); + } + else if (multiboot_magic == KERNELMQ_MULTIBOOT_1_MAGIC) { + logger_fail("Loaded with Multiboot-compliant bootloader, but specification version 1."); + return; } else { - logger_warn("Loaded with no Multiboot-compliant bootloader."); + logger_fail("Loaded with no Multiboot-compliant bootloader."); + return; } logger_info("Kernel initialization started."); diff --git a/arch/multiboot2.c b/arch/multiboot.c similarity index 97% rename from arch/multiboot2.c rename to arch/multiboot.c index e38cfd5..fb77800 100644 --- a/arch/multiboot2.c +++ b/arch/multiboot.c @@ -1,11 +1,11 @@ -#include "multiboot2.h" +#include "multiboot.h" #include "console.h" static void itoa(char *buf, int base, int d); static void printf(const char *format, ...); -void print_multiboot2_info(unsigned long addr) +void print_multiboot_info(unsigned long addr) { struct multiboot_tag *tag; unsigned size; diff --git a/arch/multiboot2.h b/arch/multiboot.h similarity index 99% rename from arch/multiboot2.h rename to arch/multiboot.h index 3b7ed43..3550052 100644 --- a/arch/multiboot2.h +++ b/arch/multiboot.h @@ -1,7 +1,7 @@ #ifndef MULTIBOOT_HEADER #define MULTIBOOT_HEADER 1 -void print_multiboot2_info(unsigned long addr); +void print_multiboot_info(unsigned long addr); /* * How many bytes from the start of the file we search for the header. diff --git a/iso/Makefile b/iso/Makefile index 6cfda53..ed2bc88 100644 --- a/iso/Makefile +++ b/iso/Makefile @@ -2,10 +2,6 @@ ifneq (ok, $(shell test -f '$(K)' && echo 'ok')) $(error 'Kernel "$(K)" does not exist') endif -ifneq (ok, $(shell grub-file --is-x86-multiboot '$(K)' && echo 'ok')) -$(error 'Kernel "$(K)" is not compliant with Multiboot 1') -endif - ifneq (ok, $(shell grub-file --is-x86-multiboot2 '$(K)' && echo 'ok')) $(error 'Kernel "$(K)" is not compliant with Multiboot 2') endif diff --git a/iso/rootfs/boot/grub/grub.cfg b/iso/rootfs/boot/grub/grub.cfg index 935301d..67787c9 100644 --- a/iso/rootfs/boot/grub/grub.cfg +++ b/iso/rootfs/boot/grub/grub.cfg @@ -1,8 +1,4 @@ -menuentry "KernelMQ, multiboot 1" { - multiboot /boot/kernelmq -} - -menuentry "KernelMQ, multiboot 2" { +menuentry "KernelMQ" { multiboot2 /boot/kernelmq module2 /boot/grub/grub.cfg qwe rty module2 /boot/kernelmq foo bar