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.c94
1 files changed, 49 insertions, 45 deletions
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 36257e9..f49d9e6 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -155,7 +155,8 @@ enum error_codes {
INSUFF_MEMORY = 0x00000002,
MMAP_TOO_SMALL = 0x00000003,
MISSING_RC = 0x00000004,
- BAD_RC_LINE = 0x00000005
+ BAD_RC_LINE = 0x00000005,
+ BAD_MMAP = 0x00000006
};
struct tag_start *tag_pointer;
@@ -172,7 +173,7 @@ uint32_t main(void) {
case BOOT_COMMAND:
put_sz(": boot arguments\n ");
put_sz(*(uint8_t *)(tag_pointer + 1) ?
- (uint8_t *)(tag_pointer + 1) : "No arguments");
+ (uint8_t *)(tag_pointer + 1) : (uint8_t *)"No arguments");
break;
case LOADER_NAME:
@@ -219,20 +220,22 @@ uint32_t main(void) {
break;
case MEMORY_MAP: {
+ mmap_start = (struct mmap_entry *)0;
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 = mmap_bss;
uint32_t bitmask = 0x00000001;
uint32_t byte = 0;
- struct mmap_entry **last_next = &mmap_start;
uint32_t usable = 0;
put_sz(": memory map\n Regions:\n");
while (tag != end) {
- if (!(tag->base & 0xffffffff00000000)) {
+ if (!(tag->base & 0xffffffff00000000) && tag->length) {
entry->base = (uint32_t)tag->base;
entry->length = (tag->base + tag->length - 1) & 0xffffffff00000000 ?
1 + ~(uint32_t)tag->base : (uint32_t)tag->length;
+ if (!entry->base)
+ mmap_start = entry;
put_sz(" 0x");
put_32_hex(entry->base);
put_sz(" - 0x");
@@ -263,8 +266,6 @@ uint32_t main(void) {
entry->whose = HARDWARE;
break;
}
- *last_next = entry;
- last_next = &entry->next;
mmap_bitmap[byte] |= bitmask;
++entry;
if (!(bitmask <<= 1)) {
@@ -279,28 +280,24 @@ uint32_t main(void) {
put_sz(" Total usable memory: 0x");
put_32_hex(usable);
- bool dirty;
- do {
- 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) &&
- (current->whose == against->whose)) {
- current->length += against->length;
- unmark_entry(against);
- if (against == mmap_start)
- mmap_start = against->next;
- else {
- for (current = mmap_start; current->next != against; current = current->next)
- ;
- current->next = against->next;
- }
- dirty = true;
- }
- } while (dirty);
-
- have_mmap = true;
- break;
+ for (struct mmap_entry *b = mmap_bss; b < entry; ++b)
+ for (struct mmap_entry *a = mmap_bss; a < entry; ++a)
+ if (b->base + b->length == a->base)
+ (b->after = a)->before = b;
+
+ for (struct mmap_entry *p = mmap_start; p->after; p = p->after)
+ while (p->whose == p->after->whose) {
+ p->length += p->after->whose;
+ unmark_entry(p->after);
+ if (p->after = p->after->after)
+ p->after->before = p;
+ }
+
+ if (mmap_start) {
+ have_mmap = true;
+ break;
+ }
+ return BAD_MMAP;
}
case VBE_INFO: {
@@ -408,26 +405,33 @@ uint32_t main(void) {
if (!have_mmap)
return NO_MMAP;
- put_sz("\n\nImportant locations:");
+ put_sz("\n\nInfo:");
if (have_text_base) {
- put_sz("\n Text section: 0x");
+ put_sz("\n Text section: 0x");
put_32_hex(text_base);
}
- put_sz("\n Memory map: 0x");
- put_32_hex((uint32_t)mmap_bss);
- put_sz(" - 0x");
- put_32_hex((uint32_t)mmap_bss - 1 +
- sizeof(struct mmap_entry) * MMAP_SIZE);
- put_sz("\n Process table: 0x");
- put_32_hex((uint32_t)proc_table);
- put_sz(" - 0x");
- put_32_hex((uint32_t)proc_table - 1 +
- sizeof(struct proc_info) * 65536);
- put_sz("\n File table: 0x");
- put_32_hex((uint32_t)file_table);
- put_sz(" - 0x");
- put_32_hex((uint32_t)file_table - 1 +
- sizeof(struct file_info) * 65536);
+ put_sz("\n Memory map size: 0x");
+ put_32_hex(sizeof(struct mmap_entry) * MMAP_SIZE);
+ put_sz("\n Process table size: 0x");
+ put_32_hex(sizeof(struct proc_info) * 65536);
+ put_sz("\n File table size: 0x");
+ put_32_hex(sizeof(struct file_info) * 65536);
+ put_sz("\n\nDisks:");
+
+ for (uint8_t i = 0; i < 26; ++i) {
+ detect_disk_parts((uint8_t)'a' + i);
+ if (part_info[i].format) {
+ put_sz("\n ");
+ put_char((uint8_t)'a' + i);
+ if (part_info[i].n_partitions) {
+ put_char('0');
+ uint8_t str[] = "\n 1";
+ for (uint8_t m = part_info[i].n_partitions + (uint8_t)'0'; str[4] < m; ++(str[4]))
+ put_sz(str);
+ }
+ }
+ }
+
put_sz("\n\n");
put_sz("No file support yet. Halting.");