diff options
-rw-r--r-- | atags.c | 6 | ||||
-rw-r--r-- | setup.c | 42 |
2 files changed, 47 insertions, 1 deletions
@@ -38,7 +38,11 @@ uint32_t find_memory_size(struct atag_header *atags) // our design assumes address 0x0 is available, so we reject mem // atag saying otherwise if (mem_tag->start != 0) - return 0; + { + puts("ignoring information about memory, " + "that doesn't start at 0x0"); + return 0; + } return mem_tag->size; } @@ -3,6 +3,8 @@ #include "demo_functionality.h" #include "paging.h" #include "atags.h" +// for POWER_OF_2() macro... perhaps the macro should be moved +#include "memory.h" void setup(uint32_t r0, uint32_t machine_type, struct atag_header *atags) @@ -17,6 +19,8 @@ void setup(uint32_t r0, uint32_t machine_type, puts("Hello, kernel World!"); prints("ARM machine type: 0x"); printhext(machine_type); puts(""); + + uint32_t memory_size = 0; // value 3 introduced by stage1 code means no atags was found if (r0 == 3) @@ -31,8 +35,46 @@ void setup(uint32_t r0, uint32_t machine_type, print_atags(atags); puts("__ end of ATAGS contents __"); + + memory_size = find_memory_size(atags); } + if (memory_size) + { + char *unit; + uint32_t size_in_unit; + + if (memory_size % POWER_OF_2(10)) + { + unit = "B"; + size_in_unit = memory_size; + } + else if (memory_size % POWER_OF_2(20)) + { + unit = "KB"; + size_in_unit = memory_size / POWER_OF_2(10); + } + else if (memory_size % POWER_OF_2(30)) + { + unit = "MB"; + size_in_unit = memory_size / POWER_OF_2(20); + } + else + { + unit = "GB"; + size_in_unit = memory_size / POWER_OF_2(30); + } + + prints("memory available: "); + printdect(size_in_unit); puts(unit); + } + else + { + // Most Pis have move, but qemu might give us little + puts("Couldn't determine available memory - assuming 192MB"); + memory_size = 192 * POWER_OF_2(20); + } + // prints some info demo_paging_support(); |