aboutsummaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/setup.c b/setup.c
index f0a9d0a..b7c03ad 100644
--- a/setup.c
+++ b/setup.c
@@ -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();