2013-12-06 14:20:46 -05:00
|
|
|
#include <stddef.h>
|
2014-01-31 16:12:04 -05:00
|
|
|
#include <stdint.h>
|
2013-12-06 14:20:46 -05:00
|
|
|
|
2014-01-31 16:12:04 -05:00
|
|
|
#include <brados/printk.h>
|
2013-12-06 14:20:46 -05:00
|
|
|
#include <brados/string.h>
|
|
|
|
#include <video/vga.h>
|
2014-01-31 16:12:04 -05:00
|
|
|
#include <multiboot.h>
|
2013-12-06 14:20:46 -05:00
|
|
|
|
|
|
|
// Make sure we are using the right compiler
|
|
|
|
#if defined(__linux__)
|
|
|
|
#error "You are using the wrong compiler."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Main kernel function
|
2014-01-31 16:12:04 -05:00
|
|
|
void brados_main(uint32_t multiMagic, uint32_t multiAddr)
|
2013-12-06 14:20:46 -05:00
|
|
|
{
|
2014-01-31 16:12:04 -05:00
|
|
|
// Initialize VGA terminal
|
2013-12-06 14:20:46 -05:00
|
|
|
struct vgastate term;
|
|
|
|
term_init(&term);
|
|
|
|
|
|
|
|
// Welcome message
|
2014-02-11 11:57:26 -05:00
|
|
|
printk(&term, "Welcome to BRaDOS!\n");
|
|
|
|
printk(&term, "written by L. Bradley LaBoon\n\n");
|
2014-01-31 16:12:04 -05:00
|
|
|
|
|
|
|
// Get multiboot info
|
|
|
|
if (multiMagic != 0x2BADB002) {
|
2014-02-11 11:57:26 -05:00
|
|
|
printk(&term, "Error! Multiboot header not present. Quitting.\n");
|
2014-01-31 16:12:04 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct multiboot_header *multiHead = (struct multiboot_header *) multiAddr;
|
2014-02-11 11:57:26 -05:00
|
|
|
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) {
|
2014-08-26 14:11:53 -04:00
|
|
|
printk(&term, "%#llx - %#llx: Unknown\n", lastAddr, memmap[i].base_addr - 1);
|
2014-02-11 11:57:26 -05:00
|
|
|
lastAddr = memmap[i].base_addr;
|
|
|
|
}
|
|
|
|
|
2014-08-26 14:11:53 -04:00
|
|
|
printk(&term, "%#llx - %#llx: ", memmap[i].base_addr, memmap[i].base_addr + memmap[i].length - 1);
|
2014-02-11 11:57:26 -05:00
|
|
|
if (memmap[i].type == 1)
|
|
|
|
printk(&term, "Available\n");
|
|
|
|
else
|
|
|
|
printk(&term, "Reserved\n");
|
|
|
|
|
|
|
|
lastAddr = memmap[i].base_addr + memmap[i].length;
|
|
|
|
}
|
|
|
|
|
2013-12-06 14:20:46 -05:00
|
|
|
|
2014-01-31 16:12:04 -05:00
|
|
|
// Done
|
2014-08-26 14:11:53 -04:00
|
|
|
printk(&term, "\nDone.");
|
2013-12-06 14:20:46 -05:00
|
|
|
}
|