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.c93
1 files changed, 59 insertions, 34 deletions
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 75edeec..ab8eb91 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -23,8 +23,6 @@ OF THIS SOFTWARE.
#include "proc.h"
#include <stdbool.h>
-extern uint32_t info_pointer;
-
enum tag_type {
BOOT_COMMAND = 1,
LOADER_NAME = 2,
@@ -52,7 +50,6 @@ enum tag_type {
struct tag_start {
uint32_t type;
uint32_t size;
- uint8_t rest;
} __attribute__ ((__packed__));
struct boot_device_tag {
@@ -79,52 +76,68 @@ bool have_boot_device = false;
bool have_mmap = false;
enum error_codes {
- NO_BOOT_DEVICE = 000000000000,
- NO_MMAP = 000000000001,
- INSUFF_MEMORY = 000000000002
+ NO_BOOT_DEVICE = 0x00000000,
+ NO_MMAP = 0x00000001,
+ INSUFF_MEMORY = 0x00000002
};
-uint32_t main(void) {
- for (uint32_t *i = (uint32_t *)VGA_BUFFER; i < (uint32_t *)0x000b8fa0; ++i)
- *i = 0x70207020;
-
- put_sz("Starting...\n");
-
- uint32_t info_size = *(uint32_t *)info_pointer;
- struct tag_start *tag_pointer = (struct tag_start *)(info_pointer + 2);
+struct tag_start *tag_pointer;
+uint32_t main(void) {
+ clear();
+
+ /*
+ uint32_t *debug_ptr = (uint32_t *)tag_pointer - 2;
+ uint32_t debug_size = *debug_ptr / 4;
+ for (uint32_t i = 0; i < debug_size; ++i) {
+ put_32_hex(debug_ptr[i]);
+ put_char(' ');
+ }
+ */
+
+ put_sz("Multiboot info:\n");
while (tag_pointer->type) {
+ put_sz(" Tag type 0x");
+ put_32_hex(tag_pointer->type);
+ put_sz(" with size 0x");
+ put_32_hex(tag_pointer->size);
switch (tag_pointer->type) {
case BOOT_DEVICE:
- boot_device = *(struct boot_device_tag *)&tag_pointer->rest;
+ boot_device = *(struct boot_device_tag *)(tag_pointer + 1);
have_boot_device = true;
- put_sz("Boot device: 0x");
+ put_sz(": boot device\n BIOS code: ");
put_32_hex(boot_device.bios_device);
if (boot_device.partition != 0xffffffff) {
- put_sz(", 0x");
+ put_sz("\n Partition number: ");
put_32_hex(boot_device.partition);
if (boot_device.subpartition != 0xffffffff) {
- put_sz(", 0x");
+ put_sz("\n Subpartition number: ");
put_32_hex(boot_device.subpartition);
+ put_char('\n');
}
+ else
+ put_sz("\n No subpartition\n");
}
- put_char('\n');
+ else
+ put_sz("\n No partition\n");
break;
case MEMORY_MAP:
{
- struct mmap_tag_entry *tag = (struct mmap_tag_entry *)((uint32_t)&tag_pointer->rest + 8);
- uint32_t size = *(uint32_t *)&tag_pointer->rest;
+ uint32_t size = *(uint32_t *)(tag_pointer + 1);
+ struct mmap_tag_entry *tag = (struct mmap_tag_entry *)(tag_pointer + 2);
+ struct mmap_tag_entry *end = (struct mmap_tag_entry *)((uint32_t)tag_pointer + tag_pointer->size);
struct mmap_entry *entry = (struct mmap_entry *)tag;
struct mmap_entry **last_next = &mmap_start;
uint32_t usable = 0;
- while (tag) {
+ put_sz(": memory map\n Regions:\n");
+ while (tag != end) {
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_sz(" 0x");
put_32_hex(entry->base);
put_sz(" - 0x");
put_32_hex(entry->base + entry->length - 1);
@@ -147,7 +160,9 @@ uint32_t main(void) {
entry->whose = HARDWARE;
break;
default:
- put_sz(": unrecognized type, assuming hardware use\n");
+ put_sz(": hardware use (0x");
+ put_32_hex(tag->type);
+ put_sz(")\n");
entry->whose = HARDWARE;
break;
}
@@ -158,13 +173,13 @@ uint32_t main(void) {
tag = (struct mmap_tag_entry *)((uint32_t)tag + size);
}
- put_sz("Total usable memory: 0x");
+ put_sz(" Total usable memory: ");
put_32_hex(usable);
put_char('\n');
- bool clean;
+ bool dirty;
do {
- clean = true;
+ dirty = false;
for (struct mmap_entry *current = mmap_start; current; current = current->next)
for (struct mmap_entry *against = mmap_start; against; against = against->next)
if ((current->base + current->length == against->base) &&
@@ -177,27 +192,29 @@ uint32_t main(void) {
;
current->next = against->next;
}
- clean = false;
+ dirty = true;
}
- } while (clean);
+ } while (dirty);
have_mmap = true;
break;
}
default:
- put_sz("Ignoring multiboot tag 0x");
- put_32_hex(tag_pointer->type);
- put_char('\n');
+ put_sz(": ignoring\n");
}
- tag_pointer = (struct tag_start *)((uint32_t)tag_pointer + tag_pointer->size);
- };
+ tag_pointer = (struct tag_start *)(((uint32_t)tag_pointer + tag_pointer->size - 1 & 0xfffffff8) + 8);
+ }
if (!have_boot_device)
return NO_BOOT_DEVICE;
if (!have_mmap)
return NO_MMAP;
+ put_sz("Halting.");
+ while (1)
+ ;
+
if (!((proc_table = allocate_block(sizeof(struct proc_info) * 65536, KERNEL)) &&
(file_table = allocate_block(sizeof(struct file_info) * 65536, KERNEL))))
return INSUFF_MEMORY;
@@ -206,3 +223,11 @@ uint32_t main(void) {
while (1)
put_sz("|\b/\b-\b\\\b");
}
+
+void wrapped_main(void) {
+ uint32_t error = main();
+ set_color(0x47);
+ clear();
+ put_sz("Error: 0x");
+ put_32_hex(error);
+}