summaryrefslogtreecommitdiff
path: root/src/kernel/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/main.c')
-rw-r--r--src/kernel/main.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 74fd8bf..29c0a4d 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -68,6 +68,12 @@ enum mem_type {
DEFECTIVE = 5
};
+struct mmap_tag_entry {
+ uint64_t base;
+ uint64_t length;
+ uint32_t type;
+} __attribute__ ((__packed__));
+
struct boot_device_tag boot_device;
bool have_boot_device = false;
bool have_mmap = false;
@@ -102,50 +108,49 @@ uint32_t main(void) {
break;
case MEMORY_MAP:
- mmap_start = (struct mmap_entry *)((uint32_t)&tag_pointer->rest + 8);
+ {
+ struct mmap_tag_entry *tag = (struct mmap_tag_entry *)((uint32_t)&tag_pointer->rest + 8);
uint32_t size = *(uint32_t *)&tag_pointer->rest;
- struct mmap_entry *next = mmap_start;
- struct mmap_entry **fill_last = &mmap_start;
+ struct mmap_entry *entry = (struct mmap_entry *)tag;
+ struct mmap_entry **last_next = &mmap_start;
uint32_t usable = 0;
- while (next) {
- if (!(next->base & 0xffffffff00000000)) {
- *fill_last = next;
- fill_last = &next->next;
- if ((next->base + next->length - 1) & 0xffffffff00000000)
- next->length = 1 + ~(next->base);
+ while (tag) {
+ if (!(tag->base & 0xffffffff00000000)) {
+ entry->base = (uint32_t)tag->base;
+ entry->length = (tag->base + tag->length - 1) & 0xffffffff00000000 ?
+ 1 + ~(uint32_t)tag->base : (uint32_t)tag->length;
put_sz("Memory: 0x");
- put_32_hex((uint32_t)(next->base >> 32));
- put_char('_');
- put_32_hex((uint32_t)next->base);
- put_sz(" - ");
- put_32_hex((uint32_t)(next->length >> 32));
- put_char('_');
- put_32_hex((uint32_t)next->length);
- switch (next->whose) {
+ put_32_hex(entry->base);
+ put_sz(" - 0x");
+ put_32_hex(entry->base + entry->length - 1);
+ switch (tag->type) {
case AVAILABLE:
put_sz(": usable\n");
- next->whose = FREE;
- usable += next->length;
+ entry->whose = FREE;
+ usable += entry->length;
break;
case ACPI:
put_sz(": ACPI info\n");
- next->whose = HARDWARE;
+ entry->whose = HARDWARE;
break;
case PRESERVE:
put_sz(": hardware use\n");
- next->whose = HARDWARE;
+ entry->whose = HARDWARE;
break;
case DEFECTIVE:
put_sz(": defective\n");
- next->whose = HARDWARE;
+ entry->whose = HARDWARE;
break;
default:
put_sz(": unrecognized type, assuming hardware use\n");
- next->whose = HARDWARE;
+ entry->whose = HARDWARE;
break;
}
+ *last_next = entry;
+ last_next = &entry->next;
+ ++entry;
}
- next = next->next = (struct mmap_entry *)((uint32_t)next + size);
+ tag = (struct mmap_tag_entry *)((uint32_t)tag + size);
}
put_sz("Total usable memory: 0x");
@@ -173,14 +178,14 @@ uint32_t main(void) {
have_mmap = true;
break;
-
+ }
default:
put_sz("Ignoring multiboot tag 0x");
put_32_hex(tag_pointer->type);
put_char('\n');
}
- tag_pointer = (struct tag_start *)((uint8_t *)tag_pointer + tag_pointer->size);
+ tag_pointer = (struct tag_start *)((uint32_t)tag_pointer + tag_pointer->size);
};
if (!have_boot_device)
@@ -193,7 +198,7 @@ uint32_t main(void) {
return INSUFF_MEMORY;
;
- put_sz("Welcome to Portland version 0.0.8!\n");
+ put_sz("Welcome to Portland version 0.0.9!\n");
while (1)
put_sz("|\b/\b-\b\\\b");
}