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.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/kernel/main.c b/src/kernel/main.c
index ab8eb91..97226bd 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -60,6 +60,7 @@ struct boot_device_tag {
enum mem_type {
AVAILABLE = 1,
+ HARDWARET = 2,
ACPI = 3,
PRESERVE = 4,
DEFECTIVE = 5
@@ -78,7 +79,8 @@ bool have_mmap = false;
enum error_codes {
NO_BOOT_DEVICE = 0x00000000,
NO_MMAP = 0x00000001,
- INSUFF_MEMORY = 0x00000002
+ INSUFF_MEMORY = 0x00000002,
+ MMAP_TOO_SMALL = 0x00000003
};
struct tag_start *tag_pointer;
@@ -128,7 +130,9 @@ uint32_t main(void) {
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 *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");
@@ -147,20 +151,21 @@ uint32_t main(void) {
entry->whose = FREE;
usable += entry->length;
break;
- case ACPI:
- put_sz(": ACPI info\n");
- entry->whose = HARDWARE;
- break;
+ case HARDWARET:
case PRESERVE:
put_sz(": hardware use\n");
entry->whose = HARDWARE;
break;
+ case ACPI:
+ put_sz(": ACPI info\n");
+ entry->whose = HARDWARE;
+ break;
case DEFECTIVE:
put_sz(": defective\n");
entry->whose = HARDWARE;
break;
default:
- put_sz(": hardware use (0x");
+ put_sz(": assuming hardware use (0x");
put_32_hex(tag->type);
put_sz(")\n");
entry->whose = HARDWARE;
@@ -168,12 +173,18 @@ uint32_t main(void) {
}
*last_next = entry;
last_next = &entry->next;
+ mmap_bitmap[byte] |= bitmask;
++entry;
+ if (!(bitmask <<= 1)) {
+ bitmask = 0x00000001;
+ if (++byte == MMAP_SIZE)
+ return MMAP_TOO_SMALL;
+ }
}
tag = (struct mmap_tag_entry *)((uint32_t)tag + size);
}
- put_sz(" Total usable memory: ");
+ put_sz(" Total usable memory: 0x");
put_32_hex(usable);
put_char('\n');
@@ -185,6 +196,7 @@ uint32_t main(void) {
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 {
@@ -211,17 +223,17 @@ uint32_t main(void) {
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;
+ put_sz("\nReady!\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_char('\n');
- put_sz("Welcome to Portland version 0.0.9!\n");
+ put_sz("\nWelcome to Portland version 0.0.9!\n");
while (1)
- put_sz("|\b/\b-\b\\\b");
+ asm ("hlt");
}
void wrapped_main(void) {