Index: boot/genarch/ofw.c
===================================================================
--- boot/genarch/ofw.c	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/genarch/ofw.c	(revision 63cda71efb0a2f95861470401dbc781d7f284896)
@@ -27,5 +27,6 @@
  */
  
-#include "ofw.h"
+#include <ofw.h>
+#include <ofwarch.h>
 #include <printf.h>
 #include <asm.h>
@@ -41,4 +42,38 @@
 phandle ofw_aliases;
 
+void ofw_init(void)
+{
+	ofw_chosen = ofw_find_device("/chosen");
+	if (ofw_chosen == -1)
+		halt();
+	
+	if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)
+		ofw_stdout = 0;
+	
+	ofw_root = ofw_find_device("/");
+	if (ofw_root == -1) {
+		puts("\r\nError: Unable to find / device, halted.\r\n");
+		halt();
+	}
+	
+	if (ofw_get_property(ofw_chosen, "mmu",  &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
+		puts("\r\nError: Unable to get mmu property, halted.\r\n");
+		halt();
+	}
+
+	ofw_memory = ofw_find_device("/memory");
+	if (ofw_memory == -1) {
+		puts("\r\nError: Unable to find /memory device, halted.\r\n");
+		halt();
+	}
+	
+	ofw_aliases = ofw_find_device("/aliases");
+	if (ofw_aliases == -1) {
+		puts("\r\nError: Unable to find /aliases device, halted.\r\n");
+		halt();
+	}
+}
+
+
 static unsigned long ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...)
 {
@@ -80,11 +115,11 @@
 
 
-static unsigned int ofw_get_address_cells(const phandle device)
-{
-	unsigned int ret;
+unsigned int ofw_get_address_cells(const phandle device)
+{
+	unsigned int ret = 1;
 	
 	if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0)
 		if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0)
-			ret = 1;
+			ret = OFW_ADDRESS_CELLS;
 	
 	return ret;
@@ -92,5 +127,5 @@
 
 
-static unsigned int ofw_get_size_cells(const phandle device)
+unsigned int ofw_get_size_cells(const phandle device)
 {
 	unsigned int ret;
@@ -98,5 +133,5 @@
 	if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0)
 		if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0)
-			ret = 1;
+			ret = OFW_SIZE_CELLS;
 	
 	return ret;
@@ -107,38 +142,4 @@
 {
 	return ofw_call("open", 1, 1, NULL, name);
-}
-
-
-void init(void)
-{
-	ofw_chosen = ofw_find_device("/chosen");
-	if (ofw_chosen == -1)
-		halt();
-	
-	if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)
-		ofw_stdout = 0;
-	
-	ofw_root = ofw_find_device("/");
-	if (ofw_root == -1) {
-		puts("\r\nError: Unable to find / device, halted.\r\n");
-		halt();
-	}
-	
-	if (ofw_get_property(ofw_chosen, "mmu",  &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
-		puts("\r\nError: Unable to get mmu property, halted.\r\n");
-		halt();
-	}
-	
-	ofw_memory = ofw_find_device("/memory");
-	if (ofw_memory == -1) {
-		puts("\r\nError: Unable to find /memory device, halted.\r\n");
-		halt();
-	}
-	
-	ofw_aliases = ofw_find_device("/aliases");
-	if (ofw_aliases == -1) {
-		puts("\r\nError: Unable to find /aliases device, halted.\r\n");
-		halt();
-	}
 }
 
@@ -170,5 +171,5 @@
 	else
 		shift = 0;
-		
+
 	return (void *) ((result[2]<<shift)|result[3]);
 }
@@ -207,17 +208,17 @@
 int ofw_memmap(memmap_t *map)
 {
-	unsigned long buf[BUF_SIZE];
-	int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf));
-	if (ret <= 0)
-		return false;
-		
 	unsigned int ac = ofw_get_address_cells(ofw_memory);
 	unsigned int sc = ofw_get_size_cells(ofw_memory);
-	
+
+	uint32_t buf[((ac+sc)*MEMMAP_MAX_RECORDS)];
+	int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf));
+	if (ret <= 0)		/* ret is the number of written bytes */
+		return false;
+
 	int pos;
 	map->total = 0;
 	map->count = 0;
-	for (pos = 0; (pos < ret / sizeof(unsigned long)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
-		void * start = (void *) buf[pos + ac - 1];
+	for (pos = 0; (pos < ret / sizeof(uint32_t)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
+		void * start = (void *) ((uintptr_t) buf[pos + ac - 1]);
 		unsigned int size = buf[pos + ac + sc - 1];
 		
@@ -229,4 +230,6 @@
 		}
 	}
+	
+	return true;
 }
 
@@ -235,4 +238,5 @@
 {
 	char device_name[BUF_SIZE];
+	uint32_t virtaddr;
 	
 	if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(device_name)) <= 0)
@@ -243,7 +247,9 @@
 		return false;
 	
-	if (ofw_get_property(device, "address", &screen->addr, sizeof(screen->addr)) <= 0)
-		return false;
-	
+	if (ofw_get_property(device, "address", &virtaddr, sizeof(virtaddr)) <= 0)
+		return false;
+
+	screen->addr = (void *) ((uintptr_t) virtaddr);
+
 	if (ofw_get_property(device, "width", &screen->width, sizeof(screen->width)) <= 0)
 		return false;
