Index: arch/ppc32/loader/ofw.c
===================================================================
--- arch/ppc32/loader/ofw.c	(revision 7dcde32d363538bd4d1700610a95e357a435c0a8)
+++ arch/ppc32/loader/ofw.c	(revision a8844e02e7d1892e89644ed8ff394ce3660d5266)
@@ -32,5 +32,5 @@
 
 #define MAX_OFW_ARGS	10
-#define STRING_SIZE		1024
+#define BUF_SIZE		1024
 
 typedef unsigned int ofw_arg_t;
@@ -54,10 +54,12 @@
 
 phandle ofw_chosen;
+ihandle ofw_stdout;
+phandle ofw_root;
+ihandle ofw_mmu;
+phandle ofw_memory;
 phandle ofw_aliases;
-ihandle ofw_mmu;
-ihandle ofw_stdout;
-
-
-static int ofw_call(const char *service, const int nargs, const int nret, ...)
+
+
+static int ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...)
 {
 	va_list list;
@@ -69,5 +71,5 @@
 	args.nret = nret;
 	
-	va_start(list, nret);
+	va_start(list, rets);
 	for (i = 0; i < nargs; i++)
 		args.args[i] = va_arg(list, ofw_arg_t);
@@ -79,4 +81,7 @@
 	ofw(&args);
 	
+	for (i = 1; i < nret; i++)
+		rets[i - 1] = args.args[i + nargs];
+	
 	return args.args[nargs];
 }
@@ -85,5 +90,5 @@
 static phandle ofw_find_device(const char *name)
 {
-	return ofw_call("finddevice", 1, 1, name);
+	return ofw_call("finddevice", 1, 1, NULL, name);
 }
 
@@ -91,10 +96,35 @@
 static int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen)
 {
-	return ofw_call("getprop", 4, 1, device, name, buf, buflen);
-}
+	return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen);
+}
+
+
+static unsigned int ofw_get_address_cells(const phandle device)
+{
+	unsigned int ret;
+	
+	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;
+	
+	return ret;
+}
+
+
+static unsigned int ofw_get_size_cells(const phandle device)
+{
+	unsigned int ret;
+	
+	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;
+	
+	return ret;
+}
+
 
 static ihandle ofw_open(const char *name)
 {
-	return ofw_call("open", 1, 1, name);
+	return ofw_call("open", 1, 1, NULL, name);
 }
 
@@ -106,16 +136,27 @@
 		halt();
 	
-	if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)	
+	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("\nUnable to find /aliases device\n");
-		halt();
-	}
-	
-	ofw_mmu = ofw_open("/mmu");
-	if (ofw_mmu == -1) {
-		puts("\nUnable to open /mmu node\n");
+		puts("\r\nError: Unable to find /aliases device, halted.\r\n");
 		halt();
 	}
@@ -128,5 +169,5 @@
 		return;
 	
-	ofw_call("write", 3, 1, ofw_stdout, str, len);
+	ofw_call("write", 3, 1, NULL, ofw_stdout, str, len);
 }
 
@@ -134,5 +175,11 @@
 void *ofw_translate(const void *virt)
 {
-	return (void *) ofw_call("call-method", 7, 1, "translate", ofw_mmu, virt, 0, 0, 0, 0);
+	ofw_arg_t result[3];
+	
+	if (ofw_call("call-method", 4, 4, result, "translate", ofw_mmu, virt, 1) != 0) {
+		puts("Error: MMU method translate() failed, halting.\n");
+		halt();
+	}
+	return (void *) result[2];
 }
 
@@ -140,5 +187,5 @@
 int ofw_map(const void *phys, const void *virt, const int size, const int mode)
 {
-	return ofw_call("call-method", 6, 1, "map", ofw_mmu, mode, size, virt, phys);
+	return ofw_call("call-method", 6, 1, NULL, "map", ofw_mmu, mode, size, virt, phys);
 }
 
@@ -146,22 +193,25 @@
 int ofw_memmap(memmap_t *map)
 {
-	int i;
-	int ret;
-
-	phandle handle = ofw_find_device("/memory");
-	if (handle == -1)
-		return false;
-	
-	ret = ofw_get_property(handle, "reg", &map->zones, sizeof(map->zones));
-	if (ret == -1)
-		return false;
-	
+	unsigned int buf[BUF_SIZE];
+	int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(unsigned int) * BUF_SIZE);
+	if (ret <= 0)
+		return false;
+		
+	unsigned int ac = ofw_get_address_cells(ofw_memory);
+	unsigned int sc = ofw_get_size_cells(ofw_memory);
+	
+	int pos;
 	map->total = 0;
 	map->count = 0;
-	for (i = 0; i < MEMMAP_MAX_RECORDS; i++) {
-		if (map->zones[i].size == 0)
-			break;
-		map->count++;
-		map->total += map->zones[i].size;
+	for (pos = 0; (pos < ret / sizeof(unsigned int)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
+		void * start = (void *) buf[pos + ac - 1];
+		unsigned int size = buf[pos + ac + sc - 1];
+		
+		if (size > 0) {
+			map->zones[map->count].start = start;
+			map->zones[map->count].size = size;
+			map->count++;
+			map->total += size;
+		}
 	}
 }
@@ -170,7 +220,7 @@
 int ofw_screen(screen_t *screen)
 {
-	char device_name[STRING_SIZE];
-	
-	if (ofw_get_property(ofw_aliases, "screen", device_name, STRING_SIZE) <= 0)
+	char device_name[BUF_SIZE];
+	
+	if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(char) * BUF_SIZE) <= 0)
 		return false;
 	
