Index: boot/genarch/balloc.c
===================================================================
--- boot/genarch/balloc.c	(revision fd375a8d1ed315622d230241a9b3227ec34ba99e)
+++ boot/genarch/balloc.c	(revision 0e6dce8fa8d920149a3d88cbaafcdf1ec7d1aca6)
@@ -28,13 +28,16 @@
 
 #include <balloc.h>
+#include <asm.h>
 #include <types.h>
 #include <align.h>
 
 static ballocs_t *ballocs;
+static uintptr_t phys_base;
 
-void balloc_init(ballocs_t *b, uintptr_t base)
+void balloc_init(ballocs_t *ball, uintptr_t base, uintptr_t kernel_base)
 {
-	ballocs = b;
-	ballocs->base = base;
+	ballocs = ball;
+	phys_base = base;
+	ballocs->base = kernel_base;
 	ballocs->size = 0;
 }
@@ -42,16 +45,19 @@
 void *balloc(size_t size, size_t alignment)
 {
-	uintptr_t addr;
-
 	/* Enforce minimal alignment. */
 	alignment = ALIGN_UP(alignment, 4);
 	
-	addr = ballocs->base + ALIGN_UP(ballocs->size, alignment);
-
+	uintptr_t addr = phys_base + ALIGN_UP(ballocs->size, alignment);
+	
 	if (ALIGN_UP(ballocs->size, alignment) + size > BALLOC_MAX_SIZE)
 		return NULL;
-		
+	
 	ballocs->size = ALIGN_UP(ballocs->size, alignment) + size;
 	
 	return (void *) addr;
 }
+
+void *balloc_rebase(void *ptr)
+{
+	return (void *) ((uintptr_t) ptr - phys_base + ballocs->base);
+}
Index: boot/genarch/balloc.h
===================================================================
--- boot/genarch/balloc.h	(revision fd375a8d1ed315622d230241a9b3227ec34ba99e)
+++ boot/genarch/balloc.h	(revision 0e6dce8fa8d920149a3d88cbaafcdf1ec7d1aca6)
@@ -32,6 +32,4 @@
 #include <types.h>
 
-#define BALLOC_MAX_SIZE		(128 * 1024)
-
 typedef struct {
 	uintptr_t base;
@@ -39,6 +37,7 @@
 } ballocs_t;
 
-extern void balloc_init(ballocs_t *b, uintptr_t base);
+extern void balloc_init(ballocs_t *ball, uintptr_t base, uintptr_t kernel_base);
 extern void *balloc(size_t size, size_t alignment);
+extern void *balloc_rebase(void *ptr);
 
 #endif
Index: boot/genarch/ofw.c
===================================================================
--- boot/genarch/ofw.c	(revision fd375a8d1ed315622d230241a9b3227ec34ba99e)
+++ boot/genarch/ofw.c	(revision 0e6dce8fa8d920149a3d88cbaafcdf1ec7d1aca6)
@@ -33,4 +33,9 @@
 #include <types.h>
 
+#define RED(i)    (((i) >> 5) & ((1 << 3) - 1))
+#define GREEN(i)  (((i) >> 3) & ((1 << 2) - 1))
+#define BLUE(i)   ((i) & ((1 << 3) - 1))
+#define CLIP(i)   ((i) <= 255 ? (i) : 255)
+
 uintptr_t ofw_cif;
 
@@ -85,12 +90,13 @@
 /** Perform a call to OpenFirmware client interface.
  *
- * @param service	String identifying the service requested.
- * @param nargs		Number of input arguments.
- * @param nret		Number of output arguments. This includes the return
- * 			value.
- * @param rets		Buffer for output arguments or NULL. The buffer must
- * 			accommodate nret - 1 items.
- *
- * @return		Return value returned by the client interface.
+ * @param service String identifying the service requested.
+ * @param nargs   Number of input arguments.
+ * @param nret    Number of output arguments. This includes the return
+ *                value.
+ * @param rets    Buffer for output arguments or NULL. The buffer must
+ *                accommodate nret - 1 items.
+ *
+ * @return Return value returned by the client interface.
+ *
  */
 unsigned long
@@ -221,5 +227,5 @@
 }
 
-void *ofw_claim_virt(const void *virt, const int len)
+void *ofw_claim_virt(const void *virt, const unsigned int len)
 {
 	ofw_arg_t retaddr;
@@ -234,41 +240,54 @@
 }
 
-void *ofw_claim_phys(const void *phys, const int len)
-{
-	ofw_arg_t retaddr[2];
-	int shift;
-
+static void *ofw_claim_phys_internal(const void *phys, const unsigned int len, const unsigned int alignment)
+{
+	/*
+	 * Note that the return value check will help
+	 * us to discover conflicts between OpenFirmware
+	 * allocations and our use of physical memory.
+	 * It is better to detect collisions here
+	 * than to cope with weird errors later.
+	 *
+	 * So this is really not to make the loader
+	 * more generic; it is here for debugging
+	 * purposes.
+	 */
+	
 	if (sizeof(unative_t) == 8) {
-		shift = 32;
+		ofw_arg_t retaddr[2];
+		int shift = 32;
+		
 		if (ofw_call("call-method", 6, 3, retaddr, "claim",
-		    ofw_memory_prop, 0, len, ((uintptr_t) phys) >> shift,
+		    ofw_memory_prop, alignment, len, ((uintptr_t) phys) >> shift,
 		    ((uintptr_t) phys) & ((uint32_t) -1)) != 0) {
-			/*
-			 * Note that this will help us to discover
-			 * conflicts between OpenFirmware allocations
-			 * and our use of physical memory.
-			 * It is better to detect collisions here
-			 * than to cope with weird errors later.
-			 *
-			 * So this is really not to make the loader
-			 * more generic; it is here for debugging
-			 * purposes.
-			 */
 			puts("Error: memory method claim() failed, halting.\n");
 			halt();
 		}
+		
+		return (void *) ((retaddr[0] << shift) | retaddr[1]);
 	} else {
-		shift = 0;
-		/*
-		 * FIXME: the number of arguments is probably different...
-		 */
-		puts("Error: 32-bit ofw_claim_phys not implemented.\n");
-		halt();
-	}
-
-	return (void *) ((retaddr[0] << shift) | retaddr[1]);
-}
-
-int ofw_map(const void *phys, const void *virt, const int size, const int mode)
+		ofw_arg_t retaddr[1];
+		
+		if (ofw_call("call-method", 5, 2, retaddr, "claim",
+		    ofw_memory_prop, alignment, len, (uintptr_t) phys) != 0) {
+			puts("Error: memory method claim() failed, halting.\n");
+			halt();
+		}
+		
+		return (void *) retaddr[0];
+	}
+}
+
+void *ofw_claim_phys(const void *phys, const unsigned int len)
+{
+	return ofw_claim_phys_internal(phys, len, 0);
+}
+
+void *ofw_claim_phys_any(const unsigned int len, const unsigned int alignment)
+{
+	return ofw_claim_phys_internal(NULL, len, alignment);
+}
+
+int ofw_map(const void *phys, const void *virt, const unsigned int size, const int mode)
 {
 	uintptr_t phys_hi, phys_lo;
@@ -314,9 +333,9 @@
 
 		/*
- 		 * This is a hot fix of the issue which occurs on machines
- 		 * where there are holes in the physical memory (such as
- 		 * SunBlade 1500). Should we detect a hole in the physical
- 		 * memory, we will ignore any memory detected behind
- 		 * the hole and pretend the hole does not exist.
+		 * This is a hot fix of the issue which occurs on machines
+		 * where there are holes in the physical memory (such as
+		 * SunBlade 1500). Should we detect a hole in the physical
+		 * memory, we will ignore any memory detected behind
+		 * the hole and pretend the hole does not exist.
 		 */
 		if ((map->count > 0) && (map->zones[map->count - 1].start +
@@ -335,48 +354,4 @@
 }
 
-int ofw_screen(screen_t *screen)
-{
-	char device_name[BUF_SIZE];
-	uint32_t virtaddr;
-	
-	if (ofw_get_property(ofw_aliases, "screen", device_name,
-	    sizeof(device_name)) <= 0)
-		return false;
-	
-	phandle device = ofw_find_device(device_name);
-	if (device == -1)
-		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;
-	
-	if (ofw_get_property(device, "height", &screen->height,
-	    sizeof(screen->height)) <= 0)
-		return false;
-	
-	if (ofw_get_property(device, "depth", &screen->bpp,
-	    sizeof(screen->bpp)) <= 0)
-		return false;
-	
-	if (ofw_get_property(device, "linebytes", &screen->scanline,
-	    sizeof(screen->scanline)) <= 0)
-		return false;
-	
-	return true;
-}
-
-#define RED(i)    (((i) >> 5) & ((1 << 3) - 1))
-#define GREEN(i)  (((i) >> 3) & ((1 << 2) - 1))
-#define BLUE(i)   ((i) & ((1 << 3) - 1))
-#define CLIP(i)   ((i) <= 255 ? (i) : 255)
-
-
 /**
  * Sets up the palette for the 8-bit color depth configuration so that the
@@ -392,10 +367,10 @@
 	char device_name[BUF_SIZE];
 	
-	/* resolve alias */
+	/* Resolve alias */
 	if (ofw_get_property(ofw_aliases, "screen", device_name,
 	    sizeof(device_name)) <= 0)
 		return false;
 	
-	/* for depth greater than 8 it makes no sense to set up the palette */
+	/* For depth greater than 8 it makes no sense to set up the palette */
 	uint32_t depth;
 	phandle device = ofw_find_device(device_name);
@@ -407,10 +382,10 @@
 		return false;
 	
-	/* required in order to be able to make a method call */
+	/* Required in order to be able to make a method call */
 	ihandle screen = ofw_open(device_name);
 	if (screen == -1)
 		return false;
 	
-	/* setup the palette so that the (inverted) 3:2:3 scheme is usable */
+	/* Setup the palette so that the (inverted) 3:2:3 scheme is usable */
 	unsigned int i;
 	for (i = 0; i < 256; i++)
Index: boot/genarch/ofw.h
===================================================================
--- boot/genarch/ofw.h	(revision fd375a8d1ed315622d230241a9b3227ec34ba99e)
+++ boot/genarch/ofw.h	(revision 0e6dce8fa8d920149a3d88cbaafcdf1ec7d1aca6)
@@ -33,9 +33,9 @@
 #include <stdarg.h>
 
-#define BUF_SIZE		1024
+#define BUF_SIZE  1024
 
-#define MEMMAP_MAX_RECORDS 	32
+#define MEMMAP_MAX_RECORDS  32
 
-#define MAX_OFW_ARGS            12
+#define MAX_OFW_ARGS  12
 
 typedef unative_t ofw_arg_t;
@@ -47,8 +47,8 @@
  */
 typedef struct {
-	ofw_arg_t service;		/**< Command name. */
-	ofw_arg_t nargs;		/**< Number of in arguments. */
-	ofw_arg_t nret;			/**< Number of out arguments. */
-	ofw_arg_t args[MAX_OFW_ARGS];	/**< List of arguments. */
+	ofw_arg_t service;             /**< Command name. */
+	ofw_arg_t nargs;               /**< Number of in arguments. */
+	ofw_arg_t nret;                /**< Number of out arguments. */
+	ofw_arg_t args[MAX_OFW_ARGS];  /**< List of arguments. */
 } ofw_args_t;
 
@@ -63,17 +63,4 @@
 	memzone_t zones[MEMMAP_MAX_RECORDS];
 } memmap_t;
-
-typedef struct {
-	void *addr;
-	uint32_t width;
-	uint32_t height;
-	uint32_t bpp;
-	uint32_t scanline;
-} screen_t;
-
-typedef struct {
-	void *addr;
-	uint32_t size;
-} macio_t;
 
 typedef struct {
@@ -118,10 +105,9 @@
 extern void *ofw_translate(const void *virt);
 extern int ofw_translate_failed(ofw_arg_t flag);
-extern void *ofw_claim_virt(const void *virt, const int len);
-extern void *ofw_claim_phys(const void *virt, const int len);
-extern int ofw_map(const void *phys, const void *virt, const int size, const int mode);
+extern void *ofw_claim_virt(const void *virt, const unsigned int len);
+extern void *ofw_claim_phys(const void *virt, const unsigned int len);
+extern void *ofw_claim_phys_any(const unsigned int len, const unsigned int alignment);
+extern int ofw_map(const void *phys, const void *virt, const unsigned int size, const int mode);
 extern int ofw_memmap(memmap_t *map);
-extern int ofw_screen(screen_t *screen);
-extern int ofw_macio(macio_t *macio);
 extern int ofw_setup_palette(void);
 extern void ofw_quiesce(void);
Index: boot/genarch/ofw_tree.c
===================================================================
--- boot/genarch/ofw_tree.c	(revision fd375a8d1ed315622d230241a9b3227ec34ba99e)
+++ boot/genarch/ofw_tree.c	(revision 0e6dce8fa8d920149a3d88cbaafcdf1ec7d1aca6)
@@ -29,10 +29,12 @@
 #include <ofw_tree.h>
 #include <ofw.h>
+#include <ofwarch.h>
 #include <types.h>
 #include <string.h>
 #include <balloc.h>
 #include <asm.h>
-
-#define MAX_PATH_LEN	256
+#include <memstr.h>
+
+#define MAX_PATH_LEN  256
 
 static ofw_tree_node_t *ofw_tree_node_alloc(void)
@@ -49,6 +51,4 @@
 static void *ofw_tree_space_alloc(size_t size)
 {
-	char *addr;
-
 	/*
 	 * What we do here is a nasty hack :-)
@@ -61,7 +61,8 @@
 	 * behind the requested memory.
 	 */
-	addr = balloc(size + 1, size);
+	char *addr = balloc(size + 1, size);
 	if (addr)
 		addr[size] = '\0';
+	
 	return addr;
 }
@@ -75,26 +76,19 @@
  * order to prevent stack from overflowing.
  *
- * @param current_node	Pointer to uninitialized ofw_tree_node structure that
- * 			will become the memory represenation of 'current'.
- * @param parent_node	Parent ofw_tree_node structure or NULL in case of root
- * 			node.
- * @param current	OpenFirmware phandle to the current device tree node.
+ * @param current_node Pointer to uninitialized ofw_tree_node structure that
+ *                     will become the memory represenation of 'current'.
+ * @param parent_node  Parent ofw_tree_node structure or NULL in case of root
+ *                     node.
+ * @param current      OpenFirmware phandle to the current device tree node.
+ *
  */
 static void ofw_tree_node_process(ofw_tree_node_t *current_node,
     ofw_tree_node_t *parent_node, phandle current)
 {
-	static char path[MAX_PATH_LEN + 1];
-	static char name[OFW_TREE_PROPERTY_MAX_NAMELEN];
-	static char name2[OFW_TREE_PROPERTY_MAX_NAMELEN];
-	phandle peer;
-	phandle child;
-	size_t len;
-	int i;
-
 	while (current_node) {
 		/*
 		 * Initialize node.
 		 */
-		current_node->parent = parent_node;
+		current_node->parent = (ofw_tree_node_t *) balloc_rebase(parent_node);
 		current_node->peer = NULL;
 		current_node->child = NULL;
@@ -103,45 +97,51 @@
 		current_node->property = NULL;
 		current_node->device = NULL;
-	
+		
 		/*
 		 * Get the disambigued name.
 		 */
-		len = ofw_package_to_path(current, path, MAX_PATH_LEN);
+		static char path[MAX_PATH_LEN + 1];
+		size_t len = ofw_package_to_path(current, path, MAX_PATH_LEN);
 		if (len == -1)
 			return;
-	
+		
 		path[len] = '\0';
-		for (i = len - 1; i >= 0 && path[i] != '/'; i--)
-			;
-		i++;	/* do not include '/' */
-	
+		
+		/* Find last slash */
+		int i;
+		for (i = len - 1; (i >= 0) && (path[i] != '/'); i--);
+		
+		/* Do not include the slash */
+		i++;
 		len -= i;
-
-		/* add space for trailing '\0' */
-		current_node->da_name = ofw_tree_space_alloc(len + 1);
-		if (!current_node->da_name)
-			return;
-	
-		memcpy(current_node->da_name, &path[i], len);
-		current_node->da_name[len] = '\0';
-	
+		
+		/* Add space for trailing '\0' */
+		char *da_name = ofw_tree_space_alloc(len + 1);
+		if (!da_name)
+			return;
+		
+		memcpy(da_name, &path[i], len);
+		da_name[len] = '\0';
+		current_node->da_name = (char *) balloc_rebase(da_name);
+		
 		/*
 		 * Recursively process the potential child node.
 		 */
-		child = ofw_get_child_node(current);
-		if (child != 0 && child != -1) {
-			ofw_tree_node_t *child_node;
-		
-			child_node = ofw_tree_node_alloc();
+		phandle child = ofw_get_child_node(current);
+		if ((child != 0) && (child != -1)) {
+			ofw_tree_node_t *child_node = ofw_tree_node_alloc();
 			if (child_node) {
 				ofw_tree_node_process(child_node, current_node,
 				    child);
-				current_node->child = child_node;
+				current_node->child =
+				    (ofw_tree_node_t *) balloc_rebase(child_node);
 			}
 		}
-	
+		
 		/*
 		 * Count properties.
 		 */
+		static char name[OFW_TREE_PROPERTY_MAX_NAMELEN];
+		static char name2[OFW_TREE_PROPERTY_MAX_NAMELEN];
 		name[0] = '\0';
 		while (ofw_next_property(current, name, name2) == 1) {
@@ -149,50 +149,46 @@
 			memcpy(name, name2, OFW_TREE_PROPERTY_MAX_NAMELEN);
 		}
-
+		
 		if (!current_node->properties)
 			return;
-	
+		
 		/*
 		 * Copy properties.
 		 */
-		current_node->property =
+		ofw_tree_property_t *property =
 		    ofw_tree_properties_alloc(current_node->properties);
-		if (!current_node->property)
+		if (!property)
 			return;
 		
 		name[0] = '\0';
 		for (i = 0; ofw_next_property(current, name, name2) == 1; i++) {
-			size_t size;
-		
 			if (i == current_node->properties)
 				break;
-		
+			
 			memcpy(name, name2, OFW_TREE_PROPERTY_MAX_NAMELEN);
-			memcpy(current_node->property[i].name, name,
-			    OFW_TREE_PROPERTY_MAX_NAMELEN);
-			current_node->property[i].name[
-			    OFW_TREE_PROPERTY_MAX_NAMELEN] = '\0';
-
-			size = ofw_get_proplen(current, name);
-			current_node->property[i].size = size;
+			memcpy(property[i].name, name, OFW_TREE_PROPERTY_MAX_NAMELEN);
+			property[i].name[OFW_TREE_PROPERTY_MAX_NAMELEN] = '\0';
+			
+			size_t size = ofw_get_proplen(current, name);
+			property[i].size = size;
+			
 			if (size) {
-				void *buf;
-			
-				buf = ofw_tree_space_alloc(size);
-				if (current_node->property[i].value = buf) {
+				void *buf = ofw_tree_space_alloc(size);
+				if (buf) {
 					/*
 					 * Copy property value to memory node.
 					 */
-					(void) ofw_get_property(current, name,
-					    buf, size);
+					(void) ofw_get_property(current, name, buf, size);
+					property[i].value = balloc_rebase(buf);
 				}
-			} else {
-				current_node->property[i].value = NULL;
-			}
-		}
-
+			} else
+				property[i].value = NULL;
+		}
+		
 		/* Just in case we ran out of memory. */
 		current_node->properties = i;
-
+		current_node->property = (ofw_tree_property_t *) balloc_rebase(property);
+		
+		
 		/*
 		 * Iteratively process the next peer node.
@@ -202,11 +198,9 @@
 		 * risk of overflowing the stack is too real.
 		 */
-		peer = ofw_get_peer_node(current);
-		if (peer != 0 && peer != -1) {
-			ofw_tree_node_t *peer_node;
-		
-			peer_node = ofw_tree_node_alloc();
-			if (peer_node) { 
-				current_node->peer = peer_node;
+		phandle peer = ofw_get_peer_node(current);
+		if ((peer != 0) && (peer != -1)) {
+			ofw_tree_node_t *peer_node = ofw_tree_node_alloc();
+			if (peer_node) {
+				current_node->peer = (ofw_tree_node_t *) balloc_rebase(peer_node);
 				current_node = peer_node;
 				current = peer;
@@ -217,4 +211,5 @@
 			}
 		}
+		
 		/*
 		 * No more peers on this level.
@@ -226,16 +221,13 @@
 /** Construct memory representation of OpenFirmware device tree.
  *
- * @return		NULL on failure or pointer to the root node.
+ * @return NULL on failure or kernel pointer to the root node.
+ *
  */
 ofw_tree_node_t *ofw_tree_build(void)
 {
-	ofw_tree_node_t *root;
-	phandle ssm_node;
-	ofw_tree_node_t *ssm;
-	
-	root = ofw_tree_node_alloc();
+	ofw_tree_node_t *root = ofw_tree_node_alloc();
 	if (root)
 		ofw_tree_node_process(root, NULL, ofw_root);
-
+	
 	/*
 	 * The firmware client interface does not automatically include the
@@ -243,15 +235,15 @@
 	 * solution is to explicitly stick "ssm" to the OFW tree.
 	 */
-	ssm_node = ofw_find_device("/ssm@0,0");
+	phandle ssm_node = ofw_find_device("/ssm@0,0");
 	if (ssm_node != -1) {
-		ssm = ofw_tree_node_alloc();
+		ofw_tree_node_t *ssm = ofw_tree_node_alloc();
 		if (ssm) {
 			ofw_tree_node_process(ssm, root,
 			    ofw_find_device("/ssm@0,0"));
 			ssm->peer = root->child;
-			root->child = ssm;
+			root->child = (ofw_tree_node_t *) balloc_rebase(ssm);
 		}
 	}
 	
-	return root;
-}
+	return (ofw_tree_node_t *) balloc_rebase(root);
+}
Index: boot/genarch/ofw_tree.h
===================================================================
--- boot/genarch/ofw_tree.h	(revision fd375a8d1ed315622d230241a9b3227ec34ba99e)
+++ boot/genarch/ofw_tree.h	(revision 0e6dce8fa8d920149a3d88cbaafcdf1ec7d1aca6)
@@ -33,31 +33,28 @@
 #include <ofw.h>
 
-#define OFW_TREE_PROPERTY_MAX_NAMELEN	32
-
-typedef struct ofw_tree_node ofw_tree_node_t;
-typedef struct ofw_tree_property ofw_tree_property_t;
-
-/** Memory representation of OpenFirmware device tree node. */
-struct ofw_tree_node {
-	ofw_tree_node_t *parent;
-	ofw_tree_node_t *peer;
-	ofw_tree_node_t *child;
-
-	uint32_t node_handle;			/**< Old OpenFirmware node handle. */
-
-	char *da_name;				/**< Disambigued name. */
-
-	unsigned properties;			/**< Number of properties. */
-	ofw_tree_property_t *property;
-	
-	void *device;				/**< Member used solely by the kernel. */
-};
+#define OFW_TREE_PROPERTY_MAX_NAMELEN  32
 
 /** Memory representation of OpenFirmware device tree node property. */
-struct ofw_tree_property {
+typedef struct {
 	char name[OFW_TREE_PROPERTY_MAX_NAMELEN];
 	size_t size;
 	void *value;
-};
+} ofw_tree_property_t;
+
+/** Memory representation of OpenFirmware device tree node. */
+typedef struct ofw_tree_node {
+	struct ofw_tree_node *parent;
+	struct ofw_tree_node *peer;
+	struct ofw_tree_node *child;
+	
+	uint32_t node_handle;           /**< Old OpenFirmware node handle. */
+	
+	char *da_name;                  /**< Disambigued name. */
+	
+	unsigned int properties;        /**< Number of properties. */
+	ofw_tree_property_t *property;
+	
+	void *device;                   /**< Member used solely by the kernel. */
+} ofw_tree_node_t;
 
 extern ofw_tree_node_t *ofw_tree_build(void);
