From 9994b80c0d339a601c624b08da508fba75d8b93b Mon Sep 17 00:00:00 2001 From: "L. Bradley LaBoon" Date: Tue, 11 Feb 2014 11:57:26 -0500 Subject: [PATCH] Prints initial memory map. Improvements to printk. Changed Makefile so that lgcc is linked after everything else. --- Makefile | 4 +- kernel/brados.c | 41 ++++++--- kernel/printk.c | 229 +++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 218 insertions(+), 56 deletions(-) diff --git a/Makefile b/Makefile index 95ce54f..83a6b06 100644 --- a/Makefile +++ b/Makefile @@ -13,14 +13,14 @@ OBJS += $(patsubst %.c,%.o,$(SOURCES_C)) # Build flags CFLAGS = -std=gnu99 -ffreestanding -Iinclude/ -O2 -Wall -Wextra -LDFLAGS = -ffreestanding -O2 -nostdlib -lgcc +LDFLAGS = -ffreestanding -O2 -nostdlib # Build rules all: brados.bin .PHONY: all clean brados.bin: $(OBJS) arch/$(ARCH)/linker.ld - $(GNU)-gcc -T arch/$(ARCH)/linker.ld -o $@ $(LDFLAGS) $(OBJS) + $(GNU)-gcc -T arch/$(ARCH)/linker.ld -o $@ $(LDFLAGS) $(OBJS) -lgcc clean: rm -f $(OBJS) brados.bin diff --git a/kernel/brados.c b/kernel/brados.c index eb1c967..898583f 100644 --- a/kernel/brados.c +++ b/kernel/brados.c @@ -19,24 +19,41 @@ void brados_main(uint32_t multiMagic, uint32_t multiAddr) term_init(&term); // Welcome message - term_writeStr(&term, "Welcome to BRaDOS!\n"); - term_writeStr(&term, "written by L. Bradley LaBoon\n\n"); - - // VGA tests - //term_test(&term); + printk(&term, "Welcome to BRaDOS!\n"); + printk(&term, "written by L. Bradley LaBoon\n\n"); // Get multiboot info - printk(&term, "Multiboot value: %x\n", multiMagic); if (multiMagic != 0x2BADB002) { - term_writeStr(&term, "Error! Multiboot header not present. Quitting.\n"); + printk(&term, "Error! Multiboot header not present. Quitting.\n"); return; } - printk(&term, "Multiboot address: %x\n", multiAddr); struct multiboot_header *multiHead = (struct multiboot_header *) multiAddr; - printk(&term, "Flags: %x\nMem Lower: %x\nMem Upper: %x\n", multiHead->flags, multiHead->mem_lower, multiHead->mem_upper); - char *bootName = (char *) multiHead->boot_loader_name; - printk(&term, "Boot loader: %s\n\n", bootName); + if ((multiHead->flags >> 6) % 2 != 1) { + printk(&term, "Error! Memory map not available from bootloader. Quitting.\n"); + return; + } + struct multiboot_mmap *memmap = (struct multiboot_mmap *) multiHead->mmap_addr; + + // Print memory map + printk(&term, "Memory map:\n"); + int numEntries = multiHead->mmap_length / sizeof(struct multiboot_mmap); + uint64_t lastAddr = 0; + for (int i = 0; i < numEntries; i++) { + if (memmap[i].base_addr != lastAddr) { + printk(&term, "%llx - %llx: Unknown\n", lastAddr, memmap[i].base_addr - 1); + lastAddr = memmap[i].base_addr; + } + + printk(&term, "%llx - %llx: ", memmap[i].base_addr, memmap[i].base_addr + memmap[i].length - 1); + if (memmap[i].type == 1) + printk(&term, "Available\n"); + else + printk(&term, "Reserved\n"); + + lastAddr = memmap[i].base_addr + memmap[i].length; + } + // Done - term_writeStr(&term, "Done."); + term_writeStr(&term, "\nDone."); } diff --git a/kernel/printk.c b/kernel/printk.c index c2f4c90..08e4188 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -6,68 +6,213 @@ #include