:: limine / test / multiboot.c 3.4 KB raw

1
#include <e9print.h>
2
#include <stdint.h>
3
#include <multiboot1.h>
4
5
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2badb002
6
7
void multiboot_main(uint32_t magic, struct multiboot1_info *info) {
8
    if (magic != MULTIBOOT_BOOTLOADER_MAGIC) {
9
        e9_printf("multiboot: Invalid magic: %x\n", magic);
10
        goto out;
11
    }
12
13
    e9_printf("Welcome to the multiboot1 test kernel: ");
14
15
    e9_printf("\t flags: %x", info->flags);
16
17
    e9_printf("\t mem_lower: %x", info->mem_lower);
18
    e9_printf("\t mem_upper: %x", info->mem_upper);
19
20
    e9_printf("\t boot_device: %x", info->boot_device);
21
    e9_printf("\t cmdline: %s", info->cmdline);
22
23
    {
24
        struct multiboot1_module *start = (struct multiboot1_module *)info->mods_addr;
25
        struct multiboot1_module *end = (struct multiboot1_module *)(info->mods_addr + info->mods_count);
26
27
        e9_printf("\t modules:");
28
        for (struct multiboot1_module* entry = start; entry < end; entry++) {
29
            e9_printf("\t\t begin=%x", entry->begin);
30
            e9_printf("\t\t end=%x", entry->end);
31
            e9_printf("\t\t cmdline=%s", entry->cmdline);
32
        }
33
    }
34
35
    {
36
        struct multiboot1_mmap_entry *start = (struct multiboot1_mmap_entry *)info->mmap_addr;
37
        struct multiboot1_mmap_entry *end = (struct multiboot1_mmap_entry *)(info->mmap_addr + info->mmap_length);
38
39
        e9_printf("\t usable_entries_mmap:");
40
41
        size_t total_mem = 0;
42
43
        // For now we only print the usable memory map entries since
44
        // printing the whole memory map blows my terminal up. We also
45
        // iterate through the available memory map entries and add up
46
        // to find the total amount of usable memory.
47
        for (struct multiboot1_mmap_entry* entry = start; entry < end; entry++) {
48
            // Check if the memory map entry is marked as usable!
49
            if (entry->type != 1) {
50
                continue;
51
            }
52
53
            e9_printf("\t\t addr=%x", entry->addr);
54
            e9_printf("\t\t length=%x", entry->len);
55
            e9_printf("\t\t type=Usable");
56
57
            // Now this might be a bit confusing since but `entry->size` represents the
58
            // is the size of the associated structure in bytes and `entry->len` represents the
59
            // size of the memory region.
60
            total_mem += entry->len;
61
        }
62
63
        e9_printf("Total usable memory: %x", total_mem);
64
    }
65
66
    // TODO(Andy-Python-Programmer): Drives are unimplemented
67
    // TODO(Andy-Python-Programmer): ROM config is unimplemented
68
69
    e9_printf("\t bootloader_name: %s", info->bootloader_name);
70
71
    // TODO(Andy-Python-Programmer): APM table is unimplemented
72
    // TODO(Andy-Python-Programmer): VBE tag is unimplemented
73
74
    e9_printf("\t fb_addr: %x", info->fb_addr);
75
    e9_printf("\t fb_pitch: %x", info->fb_pitch);
76
    e9_printf("\t fb_width: %x", info->fb_width);
77
    e9_printf("\t fb_height: %x", info->fb_height);
78
    e9_printf("\t fb_bpp: %x", info->fb_bpp);
79
    e9_printf("\t fb_type: %x", info->fb_type);
80
81
    e9_printf("\t fb_red_mask_shift: %x", info->fb_red_mask_shift);
82
    e9_printf("\t fb_red_mask_size: %x", info->fb_red_mask_size);
83
84
    e9_printf("\t fb_green_mask_shift: %x", info->fb_green_mask_shift);
85
    e9_printf("\t fb_green_mask_size: %x", info->fb_green_mask_size);
86
87
    e9_printf("\t fb_blue_mask_shift: %x", info->fb_blue_mask_shift);
88
    e9_printf("\t fb_blue_mask_size: %x", info->fb_blue_mask_size);
89
90
out:
91
    for (;;);
92
}
tab: 248 wrap: offon