Index: kernel/generic/include/align.h
===================================================================
--- kernel/generic/include/align.h	(revision c6ae4c22299e63b14110ce5d5b471aa67f9861c9)
+++ kernel/generic/include/align.h	(revision 7aaed09d88be49fac8360d3017e3328ed9b0635c)
@@ -42,5 +42,5 @@
  *
  * @param s Address or size to be aligned.
- * @param a Size of alignment, must be power of 2.
+ * @param a Size of alignment, must be a power of 2.
  */
 #define ALIGN_DOWN(s, a)  ((s) & ~((a) - 1))
@@ -50,7 +50,14 @@
  *
  * @param s Address or size to be aligned.
- * @param a Size of alignment, must be power of 2.
+ * @param a Size of alignment, must be a power of 2.
  */
 #define ALIGN_UP(s, a)  (((s) + ((a) - 1)) & ~((a) - 1))
+
+/** Check alignment.
+ *
+ * @param s Address or size to be checked for alignment.
+ * @param a Size of alignment, must be a power of 2.
+ */ 
+#define IS_ALIGNED(s, a)	(ALIGN_UP((s), (a)) == (s))
 
 #endif
Index: kernel/generic/include/config.h
===================================================================
--- kernel/generic/include/config.h	(revision c6ae4c22299e63b14110ce5d5b471aa67f9861c9)
+++ kernel/generic/include/config.h	(revision 7aaed09d88be49fac8360d3017e3328ed9b0635c)
@@ -74,12 +74,28 @@
 
 typedef struct {
-	unsigned int cpu_count;      /**< Number of processors detected. */
-	volatile size_t cpu_active;  /**< Number of processors that are up and running. */
+	/** Number of processors detected. */
+	unsigned int cpu_count;
+	/** Number of processors that are up and running. */
+	volatile size_t cpu_active;
 	
 	uintptr_t base;
-	size_t kernel_size;          /**< Size of memory in bytes taken by kernel and stack */
+	/** Size of memory in bytes taken by kernel and stack. */
+	size_t kernel_size;
 	
-	uintptr_t stack_base;        /**< Base adddress of initial stack */
-	size_t stack_size;           /**< Size of initial stack */
+	/** Base adddress of initial stack. */
+	uintptr_t stack_base;
+	/** Size of initial stack. */
+	size_t stack_size;
+
+	bool identity_configured;
+	/** Base address of the kernel identity mapped memory. */
+	uintptr_t identity_base;
+	/** Size of the kernel identity mapped memory. */
+	size_t identity_size;
+
+	bool non_identity_configured;   
+
+	/** End of physical memory. */
+	uint64_t physmem_end;
 } config_t;
 
Index: kernel/generic/include/lib/ra.h
===================================================================
--- kernel/generic/include/lib/ra.h	(revision 7aaed09d88be49fac8360d3017e3328ed9b0635c)
+++ kernel/generic/include/lib/ra.h	(revision 7aaed09d88be49fac8360d3017e3328ed9b0635c)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2011 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup generic
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_RA_H_
+#define KERN_RA_H_
+
+#include <typedefs.h>
+#include <adt/list.h>
+#include <adt/hash_table.h>
+#include <synch/spinlock.h>
+
+typedef struct {
+	SPINLOCK_DECLARE(lock);
+	list_t spans;		/**< List of arena's spans. */
+} ra_arena_t;
+
+typedef struct {
+	link_t span_link;	/**< Arena's list of spans link. */
+
+	list_t segments;	/**< List of span's segments. */
+
+	size_t max_order;	/**< Base 2 logarithm of span's size. */
+	list_t *free;		/**< max_order segment free lists. */
+
+	hash_table_t used;
+
+	uintptr_t base;		/**< Span base. */
+	size_t size;		/**< Span size. */
+} ra_span_t;
+
+#define RA_SEGMENT_FREE		1
+
+/*
+ * We would like to achieve a good ratio of the size of one unit of the
+ * represented resource (e.g. a page) and sizeof(ra_segment_t).  We therefore
+ * attempt to have as few redundant information in the segment as possible. For
+ * example, the size of the segment needs to be calculated from the segment
+ * base and the base of the following segment.
+ */
+typedef struct {
+	link_t segment_link;	/**< Span's segment list link. */
+	link_t fu_link;		/**< Span's free list or used hash link. */
+
+	uintptr_t base;		/**< Segment base. */
+	uint8_t flags;		/**< Segment flags. */
+} ra_segment_t;
+
+extern ra_arena_t *ra_arena_create(void);
+extern bool ra_span_add(ra_arena_t *, uintptr_t, size_t);
+extern uintptr_t ra_alloc(ra_arena_t *, size_t, size_t);
+extern void ra_free(ra_arena_t *, uintptr_t, size_t);
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/include/macros.h
===================================================================
--- kernel/generic/include/macros.h	(revision c6ae4c22299e63b14110ce5d5b471aa67f9861c9)
+++ kernel/generic/include/macros.h	(revision 7aaed09d88be49fac8360d3017e3328ed9b0635c)
@@ -77,4 +77,6 @@
 #endif /* __ASM__ */
 
+#define ispwr2(x)	(((x) & ((x) - 1)) == 0)
+
 #define isdigit(d)     (((d) >= '0') && ((d) <= '9'))
 #define islower(c)     (((c) >= 'a') && ((c) <= 'z'))
Index: kernel/generic/include/mm/frame.h
===================================================================
--- kernel/generic/include/mm/frame.h	(revision c6ae4c22299e63b14110ce5d5b471aa67f9861c9)
+++ kernel/generic/include/mm/frame.h	(revision 7aaed09d88be49fac8360d3017e3328ed9b0635c)
@@ -50,4 +50,5 @@
 typedef uint8_t frame_flags_t;
 
+#define FRAME_NONE        0x0
 /** Convert the frame address to kernel VA. */
 #define FRAME_KA          0x1
@@ -58,24 +59,41 @@
 /** Do not reserve / unreserve memory. */
 #define FRAME_NO_RESERVE  0x8
+/** Allocate a frame which can be identity-mapped. */
+#define FRAME_LOWMEM	  0x10
+/** Allocate a frame which cannot be identity-mapped. */
+#define FRAME_HIGHMEM	  0x20
 
 typedef uint8_t zone_flags_t;
 
+#define ZONE_NONE	0x0
 /** Available zone (free for allocation) */
-#define ZONE_AVAILABLE  0x0
+#define ZONE_AVAILABLE  0x1
 /** Zone is reserved (not available for allocation) */
-#define ZONE_RESERVED   0x8
+#define ZONE_RESERVED   0x2
 /** Zone is used by firmware (not available for allocation) */
-#define ZONE_FIRMWARE   0x10
+#define ZONE_FIRMWARE   0x4
+/** Zone contains memory that can be identity-mapped */
+#define ZONE_LOWMEM	0x8
+/** Zone contains memory that cannot be identity-mapped */
+#define ZONE_HIGHMEM	0x10
 
-/** Currently there is no equivalent zone flags
-    for frame flags */
-#define FRAME_TO_ZONE_FLAGS(frame_flags)  0
+/** Mask of zone bits that must be matched exactly. */
+#define ZONE_EF_MASK	0x7
+
+#define FRAME_TO_ZONE_FLAGS(ff)	\
+	((((ff) & FRAME_LOWMEM) ? ZONE_LOWMEM : \
+	    (((ff) & FRAME_HIGHMEM) ? ZONE_HIGHMEM : ZONE_NONE)) | \
+	    (ZONE_AVAILABLE | ZONE_LOWMEM /* | ZONE_HIGHMEM */)) 
+
+#define ZONE_FLAGS_MATCH(zf, f) \
+	(((((zf) & ZONE_EF_MASK)) == ((f) & ZONE_EF_MASK)) && \
+	    (((zf) & ~ZONE_EF_MASK) & (f)))
 
 typedef struct {
 	size_t refcount;      /**< Tracking of shared frames */
-	uint8_t buddy_order;  /**< Buddy system block order */
 	link_t buddy_link;    /**< Link to the next free block inside
                                    one order */
 	void *parent;         /**< If allocated by slab, this points there */
+	uint8_t buddy_order;  /**< Buddy system block order */
 } frame_t;
 
@@ -129,9 +147,4 @@
 }
 
-NO_TRACE static inline bool zone_flags_available(zone_flags_t flags)
-{
-	return ((flags & (ZONE_RESERVED | ZONE_FIRMWARE)) == 0);
-}
-
 #define IS_BUDDY_ORDER_OK(index, order) \
     ((~(((sysarg_t) -1) << (order)) & (index)) == 0)
@@ -146,4 +159,5 @@
 
 extern void frame_init(void);
+extern bool frame_adjust_zone_bounds(bool, uintptr_t *, size_t *);
 extern void *frame_alloc_generic(uint8_t, frame_flags_t, size_t *);
 extern void *frame_alloc(uint8_t, frame_flags_t);
@@ -161,4 +175,5 @@
 extern void frame_mark_unavailable(pfn_t, size_t);
 extern size_t zone_conf_size(size_t);
+extern pfn_t zone_external_conf_alloc(size_t);
 extern bool zone_merge(size_t, size_t);
 extern void zone_merge_all(void);
Index: kernel/generic/include/mm/km.h
===================================================================
--- kernel/generic/include/mm/km.h	(revision 7aaed09d88be49fac8360d3017e3328ed9b0635c)
+++ kernel/generic/include/mm/km.h	(revision 7aaed09d88be49fac8360d3017e3328ed9b0635c)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2011 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup genericmm
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_KM_H_
+#define KERN_KM_H_
+
+#include <typedefs.h>
+
+extern void km_identity_init(void);
+extern void km_non_identity_init(void);
+
+extern void km_non_identity_span_add(uintptr_t, size_t);
+
+extern uintptr_t km_page_alloc(size_t, size_t);
+extern void km_page_free(uintptr_t, size_t);
+
+extern bool km_is_non_identity(uintptr_t);
+
+#endif
+
+/** @}
+ */
