diff --git a/test/Makefile b/test/Makefile index f11b62d5..11501b60 100644 --- a/test/Makefile +++ b/test/Makefile @@ -14,12 +14,19 @@ INTERNALLDFLAGS := \ --no-dynamic-linker \ -ztext -INTERNALLDFLAGSMBOOT2 := \ - -Tmultiboot2.ld \ - -nostdlib \ - -zmax-page-size=0x1000 \ - -static \ - --no-dynamic-linker \ +INTERNAL_LD_FLAGS_MULTIBOOT2 := \ + -Tmultiboot2.ld \ + -nostdlib \ + -zmax-page-size=0x1000 \ + -static \ + --no-dynamic-linker \ + +INTERNAL_LD_FLAGS_MULTIBOOT1 := \ + -Tmultiboot.ld \ + -nostdlib \ + -zmax-page-size=0x1000 \ + -static \ + --no-dynamic-linker \ INTERNALCFLAGS := \ -I../stivale \ @@ -36,7 +43,7 @@ INTERNALCFLAGS := \ -mno-sse2 \ -mno-red-zone -all: test.elf multiboot2.elf +all: test.elf multiboot2.elf multiboot.elf test.elf: stivale.o stivale2.o e9print.o memory.o $(LD) $^ $(LDFLAGS) $(INTERNALLDFLAGS) -o $@ @@ -44,7 +51,12 @@ test.elf: stivale.o stivale2.o e9print.o memory.o multiboot2.elf: multiboot2_trampoline.o $(CC) $(CFLAGS) $(INTERNALCFLAGS) -I../stage23/protos -m32 -c multiboot2.c -o multiboot2.o $(CC) $(CFLAGS) $(INTERNALCFLAGS) -m32 -c e9print.c -o e9print.o - $(LD) $^ multiboot2.o e9print.o $(LDFLAGS) $(INTERNALLDFLAGSMBOOT2) -m elf_i386 -o $@ + $(LD) $^ multiboot2.o e9print.o $(LDFLAGS) $(INTERNAL_LD_FLAGS_MULTIBOOT2) -m elf_i386 -o $@ + +multiboot.elf: multiboot_trampoline.o + $(CC) $(CFLAGS) $(INTERNALCFLAGS) -I../stage23/protos -m32 -c multiboot.c -o multiboot.o + $(CC) $(CFLAGS) $(INTERNALCFLAGS) -m32 -c e9print.c -o e9print.o + $(LD) $^ multiboot.o e9print.o $(LDFLAGS) $(INTERNAL_LD_FLAGS_MULTIBOOT1) -m elf_i386 -o $@ %.o: %.c $(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@ @@ -53,4 +65,4 @@ multiboot2.elf: multiboot2_trampoline.o nasm -felf32 $< -o $@ clean: - rm -rf test.elf stivale.o stivale2.o e9print.o memory.o multiboot2.o multiboot2.elf multiboot2_trampoline.o + rm -rf test.elf stivale.o stivale2.o e9print.o memory.o multiboot2.o multiboot2.elf multiboot2_trampoline.o multiboot_trampoline.o multiboot.elf diff --git a/test/limine.cfg b/test/limine.cfg index 8ba0940a..d21849c6 100644 --- a/test/limine.cfg +++ b/test/limine.cfg @@ -1,4 +1,4 @@ -DEFAULT_ENTRY=2 +DEFAULT_ENTRY=3 TIMEOUT=3 GRAPHICS=yes VERBOSE=yes @@ -38,6 +38,18 @@ KERNEL_CMDLINE=Woah! Another another example! MODULE_PATH=boot:///boot/bg.bmp MODULE_STRING=This is the background image! +:Multiboot1 Test + +COMMENT=Test of the multiboot1 boot protocol. + +PROTOCOL=multiboot1 +RESOLUTION=800x600 +KERNEL_PATH=boot:///boot/multiboot.elf +KERNEL_CMDLINE=Woah! Another another another example! + +MODULE_PATH=boot:///boot/bg.bmp +MODULE_STRING=This is the background image! Yay! + # Test that this should be NULL: MODULE_PATH=boot:///boot/bg.bmp diff --git a/test/multiboot.c b/test/multiboot.c new file mode 100644 index 00000000..f2db28a7 --- /dev/null +++ b/test/multiboot.c @@ -0,0 +1,94 @@ +#include +#include +#include + +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2badb002 + +void multiboot_main(uint32_t magic, struct multiboot1_info *info) { + if (magic != MULTIBOOT_BOOTLOADER_MAGIC) { + e9_printf("multiboot: Invalid magic: %x\n", magic); + goto out; + } + + e9_printf("Welcome to the multiboot1 test kernel: "); + + e9_printf("\t flags: %x", info->flags); + + e9_printf("\t mem_lower: %x", info->mem_lower); + e9_printf("\t mem_upper: %x", info->mem_upper); + + e9_printf("\t boot_device: %x", info->boot_device); + e9_printf("\t cmdline: %s", info->cmdline); + + { + struct multiboot1_module *start = (struct multiboot1_module *)info->mods_addr; + struct multiboot1_module *end = (struct multiboot1_module *)(info->mods_addr + info->mods_count); + + e9_printf("\t modules:"); + for (struct multiboot1_module* entry = start; entry < end; entry++) { + e9_printf("\t\t begin=%x", entry->begin); + e9_printf("\t\t end=%x", entry->end); + e9_printf("\t\t cmdline=%s", entry->cmdline); + } + } + + // TODO(Andy-Python-Programmer): ELF sections are unimplemented + + { + struct multiboot1_mmap_entry *start = (struct multiboot1_mmap_entry *)info->mmap_addr; + struct multiboot1_mmap_entry *end = (struct multiboot1_mmap_entry *)(info->mmap_addr + info->mmap_length); + + e9_printf("\t useable_entries_mmap:"); + + size_t total_mem = 0; + + // For now we only print the useable memory map entries since + // printing the whole memory map blows my terminal up. We also + // iterate through the avaliable memory map entries and add up + // to find the total amount of useable memory. + for (struct multiboot1_mmap_entry* entry = start; entry < end; entry++) { + // Check if the memory map entry is marked as useable! + if (entry->type != 1) { + continue; + } + + e9_printf("\t\t addr=%x", entry->addr); + e9_printf("\t\t length=%x", entry->len); + e9_printf("\t\t type=Useable"); + + // Now this might be a bit confusing since but `entry->size` represents the + // is the size of the associated structure in bytes and `entry->len` represents the + // size of the memory region. + total_mem += entry->len; + } + + e9_printf("Total usable memory: %x", total_mem); + } + + // TODO(Andy-Python-Programmer): Drives are unimplemented + // TODO(Andy-Python-Programmer): ROM config is unimplemented + + e9_printf("\t bootloader_name: %s", info->bootloader_name); + + // TODO(Andy-Python-Programmer): APM table is unimplemented + // TODO(Andy-Python-Programmer): VBE tag is unimplemented + + e9_printf("\t fb_addr: %x", info->fb_addr); + e9_printf("\t fb_pitch: %x", info->fb_pitch); + e9_printf("\t fb_width: %x", info->fb_width); + e9_printf("\t fb_height: %x", info->fb_height); + e9_printf("\t fb_bpp: %x", info->fb_bpp); + e9_printf("\t fb_type: %x", info->fb_type); + + e9_printf("\t fb_red_mask_shift: %x", info->fb_red_mask_shift); + e9_printf("\t fb_red_mask_size: %x", info->fb_red_mask_size); + + e9_printf("\t fb_green_mask_shift: %x", info->fb_green_mask_shift); + e9_printf("\t fb_green_mask_size: %x", info->fb_green_mask_size); + + e9_printf("\t fb_blue_mask_shift: %x", info->fb_blue_mask_shift); + e9_printf("\t fb_blue_mask_size: %x", info->fb_blue_mask_size); + +out: + for (;;); +} \ No newline at end of file diff --git a/test/multiboot.ld b/test/multiboot.ld new file mode 100644 index 00000000..22de8775 --- /dev/null +++ b/test/multiboot.ld @@ -0,0 +1,35 @@ +ENTRY(_start) + +SECTIONS { + . = 1M; + + .boot : + { + /* Ensure that the multiboot header is at the beginning! */ + *(.multiboot_header) + } + + . = ALIGN(4K); + .text : + { + *(.text .text.*) + } + + . = ALIGN(4K); + .rodata : + { + *(.rodata.*) + } + + . = ALIGN(4K); + .data : + { + *(.data .data.*) + } + + . = ALIGN(4K); + .bss : + { + *(.bss .bss.*) + } +} diff --git a/test/multiboot2.c b/test/multiboot2.c index 0fb7ec55..8f82ae42 100644 --- a/test/multiboot2.c +++ b/test/multiboot2.c @@ -87,7 +87,7 @@ void multiboot2_main(uint32_t magic, struct multiboot_info* mb_info_addr) { e9_printf("\t\t\t addr=%x", entry->addr); e9_printf("\t\t\t len=%x", entry->len); - e9_printf("\t\t\t type=%x", entry->type); + e9_printf("\t\t\t type=Useable"); total_mem += entry->len; } diff --git a/test/multiboot_trampoline.asm b/test/multiboot_trampoline.asm new file mode 100644 index 00000000..4160faaf --- /dev/null +++ b/test/multiboot_trampoline.asm @@ -0,0 +1,37 @@ +%define MULTIBOOT_HEADER_MAGIC 0x1badb002 + +; Flags: +; +; bit 2: request framebuffer +%define MULTIBOOT_HEADER_FLAGS (1 << 2) + +extern multiboot_main + +global _start + +section .multiboot_header + +align 4 +header_start: + dd MULTIBOOT_HEADER_MAGIC ; Magic number (multiboot 1) + dd MULTIBOOT_HEADER_FLAGS ; Flags + dd -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) ; Checksum +header_end: + +section .text +bits 32 + +_start: + cli + + mov esp, stack_top + + push ebx + push eax + + call multiboot_main ; Jump to our multiboot test kernel + +section .bss +stack_bottom: + resb 4096 * 16 +stack_top: