Index: kernel/arch/amd64/include/mm/frame.h
===================================================================
--- kernel/arch/amd64/include/mm/frame.h	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/amd64/include/mm/frame.h	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -45,4 +45,5 @@
 #ifndef __ASM__
 extern uintptr_t last_frame;
+extern uintptr_t end_frame;
 extern void frame_arch_init(void);
 extern void physmem_print(void);
Index: kernel/arch/amd64/src/mm/page.c
===================================================================
--- kernel/arch/amd64/src/mm/page.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/amd64/src/mm/page.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -215,4 +215,10 @@
 }
 
+void hw_area(uintptr_t *physaddr, pfn_t *frames)
+{
+	*physaddr = end_frame;
+	*frames = ADDR2PFN(0xfffffffffffff - end_frame);
+}
+
 /** @}
  */
Index: kernel/arch/arm32/include/mm/frame.h
===================================================================
--- kernel/arch/arm32/include/mm/frame.h	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/arm32/include/mm/frame.h	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -52,4 +52,5 @@
 
 extern uintptr_t last_frame;
+extern uintptr_t end_frame;
 
 extern void frame_arch_init(void);
Index: kernel/arch/arm32/src/mm/frame.c
===================================================================
--- kernel/arch/arm32/src/mm/frame.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/arm32/src/mm/frame.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -42,4 +42,5 @@
 /** Address of the last frame in the memory. */
 uintptr_t last_frame = 0;
+uintptr_t end_frame = 0;
 
 /** Creates memory zones. */
@@ -50,5 +51,6 @@
 	    BOOT_PAGE_TABLE_START_FRAME + BOOT_PAGE_TABLE_SIZE_IN_FRAMES, 0);
 	last_frame = machine_get_memory_size();
-
+	end_frame = last_frame;
+	
 	/* blacklist boot page table */
 	frame_mark_unavailable(BOOT_PAGE_TABLE_START_FRAME,
Index: kernel/arch/arm32/src/mm/page.c
===================================================================
--- kernel/arch/arm32/src/mm/page.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/arm32/src/mm/page.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -107,4 +107,10 @@
 }
 
+void hw_area(uintptr_t *physaddr, pfn_t *frames)
+{
+	*physaddr = end_frame;
+	*frames = ADDR2PFN(0xffffffff - end_frame);
+}
+
 /** @}
  */
Index: kernel/arch/ia32/include/mm/frame.h
===================================================================
--- kernel/arch/ia32/include/mm/frame.h	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/ia32/include/mm/frame.h	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -45,4 +45,5 @@
 
 extern uintptr_t last_frame;
+extern uintptr_t end_frame;
 
 extern void frame_arch_init(void);
Index: kernel/arch/ia32/src/mm/frame.c
===================================================================
--- kernel/arch/ia32/src/mm/frame.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/ia32/src/mm/frame.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -51,4 +51,5 @@
 
 uintptr_t last_frame = 0;
+uintptr_t end_frame = 0;
 
 static void init_e820_memory(pfn_t minconf)
@@ -74,6 +75,8 @@
 				last_frame =
 				    ALIGN_UP(e820table[i].base_address + e820table[i].size, FRAME_SIZE);
-		}			
+		}
 	}
+	
+	end_frame = last_frame;
 }
 
@@ -114,4 +117,5 @@
 	if (config.cpu_active == 1) {
 		minconf = 1;
+		
 #ifdef CONFIG_SMP
 		minconf = max(minconf,
@@ -120,5 +124,5 @@
 #endif
 		init_e820_memory(minconf);
-
+		
 		/* Reserve frame 0 (BIOS data) */
 		frame_mark_unavailable(0, 1);
Index: kernel/arch/ia32/src/mm/page.c
===================================================================
--- kernel/arch/ia32/src/mm/page.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/ia32/src/mm/page.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -94,4 +94,10 @@
 }
 
+void hw_area(uintptr_t *physaddr, pfn_t *frames)
+{
+	*physaddr = end_frame;
+	*frames = ADDR2PFN(0xffffffff - end_frame);
+}
+
 void page_fault(int n __attribute__((unused)), istate_t *istate)
 {
@@ -103,5 +109,5 @@
 	if (istate->error_word & PFERR_CODE_RSVD)
 		panic("Reserved bit set in page directory.");
-
+	
 	if (istate->error_word & PFERR_CODE_RW)
 		access = PF_ACCESS_WRITE;
Index: kernel/arch/ia64/include/mm/frame.h
===================================================================
--- kernel/arch/ia64/include/mm/frame.h	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/ia64/include/mm/frame.h	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -45,4 +45,5 @@
 
 extern uintptr_t last_frame;
+extern uintptr_t end_frame;
 
 extern void frame_arch_init(void);
Index: kernel/arch/ia64/src/mm/frame.c
===================================================================
--- kernel/arch/ia64/src/mm/frame.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/ia64/src/mm/frame.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -52,4 +52,5 @@
 
 uintptr_t last_frame = 0;
+uintptr_t end_frame = 0;
 
 void frame_arch_init(void)
Index: kernel/arch/ia64/src/mm/page.c
===================================================================
--- kernel/arch/ia64/src/mm/page.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/ia64/src/mm/page.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -275,4 +275,10 @@
 }
 
+void hw_area(uintptr_t *physaddr, pfn_t *frames)
+{
+	*physaddr = end_frame;
+	*frames = ADDR2PFN(0x7fffffffffffffffUL - end_frame);
+}
+
 /** @}
  */
Index: kernel/arch/mips32/include/mm/frame.h
===================================================================
--- kernel/arch/mips32/include/mm/frame.h	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/mips32/include/mm/frame.h	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -36,12 +36,16 @@
 #define KERN_mips32_FRAME_H_
 
-#define FRAME_WIDTH		14	/* 16K */
-#define FRAME_SIZE		(1 << FRAME_WIDTH)
+#define FRAME_WIDTH  14  /* 16K */
+#define FRAME_SIZE   (1 << FRAME_WIDTH)
 
 #ifdef KERNEL
 #ifndef __ASM__
 
+#include <typedefs.h>
+
 extern void frame_arch_init(void);
 extern void physmem_print(void);
+
+extern uintptr_t end_frame;
 
 #endif /* __ASM__ */
Index: kernel/arch/mips32/src/drivers/msim.c
===================================================================
--- kernel/arch/mips32/src/drivers/msim.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/mips32/src/drivers/msim.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -42,5 +42,4 @@
 #include <ddi/ddi.h>
 
-static parea_t msim_parea;
 static chardev_t console;
 static irq_t msim_irq;
@@ -157,10 +156,4 @@
 	sysinfo_set_item_val("kbd.address.virtual", NULL, MSIM_KBD_ADDRESS);
 	
-	msim_parea.pbase = KA2PA(MSIM_VIDEORAM);
-	msim_parea.vbase = MSIM_VIDEORAM;
-	msim_parea.frames = 1;
-	msim_parea.cacheable = false;
-	ddi_parea_register(&msim_parea);
-	
 	sysinfo_set_item_val("fb", NULL, true);
 	sysinfo_set_item_val("fb.kind", NULL, 3);
Index: kernel/arch/mips32/src/mm/frame.c
===================================================================
--- kernel/arch/mips32/src/mm/frame.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/mips32/src/mm/frame.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -65,4 +65,6 @@
 static count_t phys_regions_count = 0;
 static phys_region_t phys_regions[MAX_REGIONS];
+
+uintptr_t end_frame = 0;
 
 
@@ -237,5 +239,7 @@
 	}
 	
-	frame_add_region(start_frame, frame);
+	end_frame = frame;
+	
+	frame_add_region(start_frame, end_frame);
 	
 	/* Blacklist interrupt vector frame */
Index: kernel/arch/mips32/src/mm/page.c
===================================================================
--- kernel/arch/mips32/src/mm/page.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/mips32/src/mm/page.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup mips32mm	
+/** @addtogroup mips32mm
  * @{
  */
@@ -36,4 +36,5 @@
 #include <genarch/mm/page_pt.h>
 #include <mm/page.h>
+#include <mm/frame.h>
 
 void page_arch_init(void)
@@ -51,4 +52,10 @@
 }
 
+void hw_area(uintptr_t *physaddr, pfn_t *frames)
+{
+	*physaddr = end_frame;
+	*frames = ADDR2PFN(0xffffffff - end_frame);
+}
+
 /** @}
  */
Index: kernel/arch/ppc32/include/mm/frame.h
===================================================================
--- kernel/arch/ppc32/include/mm/frame.h	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/ppc32/include/mm/frame.h	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -42,7 +42,8 @@
 #ifndef __ASM__
 
-#include <arch/types.h> 
+#include <arch/types.h>
 
 extern uintptr_t last_frame;
+extern uintptr_t end_frame;
 
 extern void frame_arch_init(void);
Index: kernel/arch/ppc32/src/mm/frame.c
===================================================================
--- kernel/arch/ppc32/src/mm/frame.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/ppc32/src/mm/frame.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -41,4 +41,5 @@
 
 uintptr_t last_frame = 0;
+uintptr_t end_frame = 0;
 
 void physmem_print(void)
@@ -75,5 +76,7 @@
 			last_frame = ALIGN_UP(bootinfo.memmap.zones[i].start + bootinfo.memmap.zones[i].size, FRAME_SIZE);
 	}
-
+	
+	end_frame = last_frame;
+	
 	/* First is exception vector, second is 'implementation specific',
 	   third and fourth is reserved, other contain real mode code */
Index: kernel/arch/ppc32/src/mm/page.c
===================================================================
--- kernel/arch/ppc32/src/mm/page.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/ppc32/src/mm/page.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -64,4 +64,10 @@
 }
 
+void hw_area(uintptr_t *physaddr, pfn_t *frames)
+{
+	*physaddr = end_frame;
+	*frames = ADDR2PFN(0xffffffff - end_frame);
+}
+
 /** @}
  */
Index: kernel/arch/sparc64/include/mm/frame.h
===================================================================
--- kernel/arch/sparc64/include/mm/frame.h	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/sparc64/include/mm/frame.h	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -74,4 +74,5 @@
 
 extern uintptr_t last_frame;
+extern uintptr_t end_frame;
 extern void frame_arch_init(void);
 #define physmem_print()
Index: kernel/arch/sparc64/src/drivers/sgcn.c
===================================================================
--- kernel/arch/sparc64/src/drivers/sgcn.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/sparc64/src/drivers/sgcn.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -162,17 +162,8 @@
 
 /**
- * Registers the physical area of the SRAM so that the userspace SGCN
- * driver can map it. Moreover, it sets some sysinfo values (SRAM address
- * and SRAM size).
- */
-static void register_sram_parea(uintptr_t sram_begin_physical)
-{
-	static parea_t sram_parea;
-	sram_parea.pbase = sram_begin_physical;
-	sram_parea.vbase = (uintptr_t) sram_begin;
-	sram_parea.frames = MAPPED_AREA_SIZE / FRAME_SIZE;
-	sram_parea.cacheable = false;
-	ddi_parea_register(&sram_parea);
-	
+ * Set some sysinfo values (SRAM address and SRAM size).
+ */
+static void register_sram(uintptr_t sram_begin_physical)
+{
 	sysinfo_set_item_val("sram.area.size", NULL, MAPPED_AREA_SIZE);
 	sysinfo_set_item_val("sram.address.physical", NULL,
@@ -212,5 +203,5 @@
 	sram_begin = hw_map(sram_begin_physical, MAPPED_AREA_SIZE);
 	
-	register_sram_parea(sram_begin_physical);
+	register_sram(sram_begin_physical);
 }
 
Index: kernel/arch/sparc64/src/mm/frame.c
===================================================================
--- kernel/arch/sparc64/src/mm/frame.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/sparc64/src/mm/frame.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -42,4 +42,5 @@
 
 uintptr_t last_frame = NULL;
+uintptr_t end_frame = NULL;
 
 /** Create memory zones according to information stored in bootinfo.
@@ -81,4 +82,5 @@
 	}
 	
+	end_frame = last_frame;
 }
 
Index: kernel/arch/sparc64/src/mm/page.c
===================================================================
--- kernel/arch/sparc64/src/mm/page.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/arch/sparc64/src/mm/page.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -148,5 +148,5 @@
 		    sizemap[order].pagesize_code, true, false);
 	
-#ifdef CONFIG_SMP	
+#ifdef CONFIG_SMP
 		/*
 		 * Second, save the information about the mapping for APs.
@@ -165,5 +165,10 @@
 }
 
+void hw_area(uintptr_t *physaddr, pfn_t *frames)
+{
+	*physaddr = end_frame;
+	*frames = ADDR2PFN(0x7ffffffffff - end_frame);
+}
+
 /** @}
  */
-
Index: kernel/genarch/src/drivers/ega/ega.c
===================================================================
--- kernel/genarch/src/drivers/ega/ega.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/genarch/src/drivers/ega/ega.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -54,6 +54,4 @@
  * Simple and short. Function for displaying characters and "scrolling".
  */
-
-static parea_t ega_parea;	/**< Physical memory area for EGA video RAM. */
 
 SPINLOCK_INITIALIZE(egalock);
@@ -153,10 +151,4 @@
 	stdout = &ega_console;
 	
-	ega_parea.pbase = videoram_phys;
-	ega_parea.vbase = (uintptr_t) videoram;
-	ega_parea.frames = 1;
-	ega_parea.cacheable = false;
-	ddi_parea_register(&ega_parea);
-	
 	sysinfo_set_item_val("fb", NULL, true);
 	sysinfo_set_item_val("fb.kind", NULL, 2);
Index: kernel/genarch/src/fb/fb.c
===================================================================
--- kernel/genarch/src/fb/fb.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/genarch/src/fb/fb.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -52,7 +52,4 @@
 
 SPINLOCK_INITIALIZE(fb_lock);
-
-/**< Physical memory area for fb. */
-static parea_t fb_parea;
 
 static uint8_t *fb_addr;
@@ -520,10 +517,4 @@
 	fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize);
 	
-	fb_parea.pbase = (uintptr_t) props->addr + props->offset;
-	fb_parea.vbase = (uintptr_t) fb_addr;
-	fb_parea.frames = SIZE2FRAMES(fbsize);
-	fb_parea.cacheable = false;
-	ddi_parea_register(&fb_parea);
-	
 	sysinfo_set_item_val("fb", NULL, true);
 	sysinfo_set_item_val("fb.kind", NULL, 1);
Index: kernel/generic/include/ddi/ddi.h
===================================================================
--- kernel/generic/include/ddi/ddi.h	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/generic/include/ddi/ddi.h	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -39,11 +39,12 @@
 #include <arch/types.h>
 #include <proc/task.h>
+#include <adt/list.h>
 
 /** Structure representing contiguous physical memory area. */
 typedef struct {
-	uintptr_t pbase;	/**< Physical base of the area. */
-	uintptr_t vbase;	/**< Virtual base of the area. */
-	count_t frames;		/**< Number of frames in the area. */
-	bool cacheable;		/**< Cacheability. */
+	uintptr_t pbase;    /**< Physical base of the area. */
+	pfn_t frames;       /**< Number of frames in the area. */
+	
+	link_t link;        /**< Linked list link */
 } parea_t;
 
Index: kernel/generic/include/mm/page.h
===================================================================
--- kernel/generic/include/mm/page.h	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/generic/include/mm/page.h	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -43,5 +43,5 @@
 typedef struct {
 	void (* mapping_insert)(as_t *as, uintptr_t page, uintptr_t frame,
-		int flags);
+	    int flags);
 	void (* mapping_remove)(as_t *as, uintptr_t page);
 	pte_t *(* mapping_find)(as_t *as, uintptr_t page);
@@ -60,5 +60,7 @@
 extern void page_table_destroy(pte_t *page_table);
 extern void map_structure(uintptr_t s, size_t size);
+
 extern uintptr_t hw_map(uintptr_t physaddr, size_t size);
+extern void hw_area(uintptr_t *physaddr, pfn_t *frames);
 
 #endif
Index: kernel/generic/src/adt/avl.c
===================================================================
--- kernel/generic/src/adt/avl.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/generic/src/adt/avl.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -44,5 +44,5 @@
  * Every node has a pointer to its parent which allows insertion of multiple
  * identical keys into the tree.
- * 
+ *
  * Be careful when using this tree because of the base atribute which is added
  * to every inserted node key. There is no rule in which order nodes with the
Index: kernel/generic/src/console/cmd.c
===================================================================
--- kernel/generic/src/console/cmd.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/generic/src/console/cmd.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -530,5 +530,5 @@
 	}
 	
-	spinlock_unlock(&cmd_lock);	
+	spinlock_unlock(&cmd_lock);
 
 	return 1;
Index: kernel/generic/src/console/console.c
===================================================================
--- kernel/generic/src/console/console.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/generic/src/console/console.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -127,7 +127,5 @@
 	
 	klog_parea.pbase = (uintptr_t) faddr;
-	klog_parea.vbase = (uintptr_t) klog;
 	klog_parea.frames = SIZE2FRAMES(KLOG_SIZE);
-	klog_parea.cacheable = true;
 	ddi_parea_register(&klog_parea);
 
Index: kernel/generic/src/ddi/ddi.c
===================================================================
--- kernel/generic/src/ddi/ddi.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/generic/src/ddi/ddi.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -48,5 +48,5 @@
 #include <synch/spinlock.h>
 #include <syscall/copy.h>
-#include <adt/btree.h>
+#include <adt/list.h>
 #include <arch.h>
 #include <align.h>
@@ -56,11 +56,15 @@
 SPINLOCK_INITIALIZE(parea_lock);
 
-/** B+tree with enabled physical memory areas. */
-static btree_t parea_btree;
+/** List with enabled physical memory areas. */
+static LIST_INITIALIZE(parea_head);
+
+/** Physical memory area for devices. */
+static parea_t dev_area;
 
 /** Initialize DDI. */
 void ddi_init(void)
 {
-	btree_create(&parea_btree);
+	hw_area(&dev_area.pbase, &dev_area.frames);
+	ddi_parea_register(&dev_area);
 }
 
@@ -75,5 +79,5 @@
 {
 	ipl_t ipl;
-
+	
 	ipl = interrupts_disable();
 	spinlock_lock(&parea_lock);
@@ -81,11 +85,11 @@
 	/*
 	 * TODO: we should really check for overlaps here.
-	 * However, we should be safe because the kernel is pretty sane and
-	 * memory of different devices doesn't overlap. 
-	 */
-	btree_insert(&parea_btree, (btree_key_t) parea->pbase, parea, NULL);
-
+	 * However, we should be safe because the kernel is pretty sane.
+	 */
+	link_initialize(&parea->link);
+	list_append(&parea->link, &parea_head);
+	
 	spinlock_unlock(&parea_lock);
-	interrupts_restore(ipl);	
+	interrupts_restore(ipl);
 }
 
@@ -98,14 +102,14 @@
  *
  * @return 0 on success, EPERM if the caller lacks capabilities to use this
- * 	syscall, ENOENT if there is no task matching the specified ID or the
- * 	physical address space is not enabled for mapping and ENOMEM if there
- * 	was a problem in creating address space area.
- */
-static int ddi_physmem_map(uintptr_t pf, uintptr_t vp, count_t pages, int flags)
+ *  syscall, ENOENT if there is no task matching the specified ID or the
+ *  physical address space is not enabled for mapping and ENOMEM if there
+ *  was a problem in creating address space area.
+ */
+static int ddi_physmem_map(uintptr_t pf, uintptr_t vp, pfn_t pages, int flags)
 {
 	ipl_t ipl;
 	cap_t caps;
 	mem_backend_data_t backend_data;
-
+	
 	backend_data.base = pf;
 	backend_data.frames = pages;
@@ -117,28 +121,33 @@
 	if (!(caps & CAP_MEM_MANAGER))
 		return EPERM;
-
+	
 	ipl = interrupts_disable();
-
+	
 	/*
 	 * Check if the physical memory area is enabled for mapping.
-	 * If the architecture supports virtually indexed caches, intercept
-	 * attempts to create an illegal address alias.
 	 */
 	spinlock_lock(&parea_lock);
-	parea_t *parea;
-	btree_node_t *nodep;
-	parea = (parea_t *) btree_search(&parea_btree, (btree_key_t) pf, &nodep);
-	if (!parea || parea->frames < pages || ((flags & AS_AREA_CACHEABLE) &&
-	    !parea->cacheable) || (!(flags & AS_AREA_CACHEABLE) &&
-	    parea->cacheable)) {
+	
+	bool fnd = false;
+	link_t *cur;
+	
+	for (cur = parea_head.next; cur != &parea_head; cur = cur->next) {
+		parea_t *parea = list_get_instance(cur, parea_t, link);
+		if ((parea->pbase <= pf) && (ADDR2PFN(pf - parea->pbase) + pages <= parea->frames)) {
+			fnd = true;
+			break;
+		}
+	}
+	
+	spinlock_unlock(&parea_lock);
+	
+	if (!fnd) {
 		/*
-		 * This physical memory area cannot be mapped.
+		 * Physical memory area cannot be mapped.
 		 */
-		spinlock_unlock(&parea_lock);
 		interrupts_restore(ipl);
 		return ENOENT;
 	}
-	spinlock_unlock(&parea_lock);
-
+	
 	spinlock_lock(&TASK->lock);
 	
@@ -227,5 +236,5 @@
 	return (unative_t) ddi_physmem_map(ALIGN_DOWN((uintptr_t) phys_base,
 	    FRAME_SIZE), ALIGN_DOWN((uintptr_t) virt_base, PAGE_SIZE),
-	    (count_t) pages, (int) flags);
+	    (pfn_t) pages, (int) flags);
 }
 
@@ -259,11 +268,11 @@
 unative_t sys_preempt_control(int enable)
 {
-        if (!cap_get(TASK) & CAP_PREEMPT_CONTROL)
-                return EPERM;
-        if (enable)
-                preemption_enable();
-        else
-                preemption_disable();
-        return 0;
+	if (!cap_get(TASK) & CAP_PREEMPT_CONTROL)
+		return EPERM;
+	if (enable)
+		preemption_enable();
+	else
+		preemption_disable();
+	return 0;
 }
 
Index: kernel/generic/src/lib/rd.c
===================================================================
--- kernel/generic/src/lib/rd.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/generic/src/lib/rd.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -89,7 +89,5 @@
 	rd_parea.pbase = ALIGN_DOWN((uintptr_t) KA2PA((void *) header + hsize),
 	    FRAME_SIZE);
-	rd_parea.vbase = (uintptr_t) ((void *) header + hsize);
 	rd_parea.frames = SIZE2FRAMES(dsize);
-	rd_parea.cacheable = true;
 	ddi_parea_register(&rd_parea);
 
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/generic/src/proc/task.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -340,5 +340,5 @@
 		
 		thr = list_get_instance(cur, thread_t, th_link);
-			
+		
 		spinlock_lock(&thr->lock);
 		thr->interrupted = true;
Index: kernel/generic/src/time/clock.c
===================================================================
--- kernel/generic/src/time/clock.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ kernel/generic/src/time/clock.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -89,7 +89,5 @@
 
 	clock_parea.pbase = (uintptr_t) faddr;
-	clock_parea.vbase = (uintptr_t) uptime;
 	clock_parea.frames = 1;
-	clock_parea.cacheable = true;
 	ddi_parea_register(&clock_parea);
 
Index: uspace/srv/fb/ega.c
===================================================================
--- uspace/srv/fb/ega.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ uspace/srv/fb/ega.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -374,5 +374,5 @@
 	scr_height = sysinfo_value("fb.height");
 
-	if(sysinfo_value("fb.blinking")) {
+	if (sysinfo_value("fb.blinking")) {
 		ega_normal_color &= 0x77;
 		ega_inverted_color &= 0x77;
@@ -386,6 +386,7 @@
 	scr_addr = as_get_mappable_page(sz);
 
-	physmem_map(ega_ph_addr, scr_addr, ALIGN_UP(sz, PAGE_SIZE) >>
-	    PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
+	if (physmem_map(ega_ph_addr, scr_addr, ALIGN_UP(sz, PAGE_SIZE) >>
+	    PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0)
+		return -1;
 
 	async_set_client_connection(ega_client_connection);
Index: uspace/srv/fb/fb.c
===================================================================
--- uspace/srv/fb/fb.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ uspace/srv/fb/fb.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -1672,6 +1672,7 @@
 	void *fb_addr = as_get_mappable_page(fbsize);
 	
-	physmem_map(fb_ph_addr + fb_offset, fb_addr,
-	    ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
+	if (physmem_map(fb_ph_addr + fb_offset, fb_addr,
+	    ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0)
+		return -1;
 	
 	if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual))
Index: uspace/srv/fb/msim.c
===================================================================
--- uspace/srv/fb/msim.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ uspace/srv/fb/msim.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -60,5 +60,6 @@
 	virt_addr = (char *) as_get_mappable_page(1);
 	
-	physmem_map(phys_addr, virt_addr, 1, AS_AREA_READ | AS_AREA_WRITE);
+	if (physmem_map(phys_addr, virt_addr, 1, AS_AREA_READ | AS_AREA_WRITE) != 0)
+		return -1;
 	
 	serial_console_init(msim_putc, WIDTH, HEIGHT);
Index: uspace/srv/fb/sgcn.c
===================================================================
--- uspace/srv/fb/sgcn.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ uspace/srv/fb/sgcn.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -122,16 +122,10 @@
 int sgcn_init(void)
 {
-	sram_virt_addr = (uintptr_t) as_get_mappable_page(
-		sysinfo_value("sram.area.size"));
-	int result = physmem_map(
-		(void *) sysinfo_value("sram.address.physical"),
-		(void *) sram_virt_addr,
-		sysinfo_value("sram.area.size") / PAGE_SIZE,
-		AS_AREA_READ | AS_AREA_WRITE
-		);
-	if (result != 0) {
-		printf("SGCN: uspace driver couldn't map physical memory: %d\n",
-			result);
-	}
+	sram_virt_addr = (uintptr_t) as_get_mappable_page(sysinfo_value("sram.area.size"));
+	
+	if (physmem_map((void *) sysinfo_value("sram.address.physical"),
+	    (void *) sram_virt_addr, sysinfo_value("sram.area.size") / PAGE_SIZE,
+	    AS_AREA_READ | AS_AREA_WRITE) != 0)
+		return -1;
 	
 	serial_console_init(sgcn_putc, WIDTH, HEIGHT);
Index: uspace/srv/kbd/arch/sparc64/src/sgcn.c
===================================================================
--- uspace/srv/kbd/arch/sparc64/src/sgcn.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ uspace/srv/kbd/arch/sparc64/src/sgcn.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -98,15 +98,9 @@
 void sgcn_init(void)
 {
-	sram_virt_addr = (uintptr_t) as_get_mappable_page(
-		sysinfo_value("sram.area.size"));
-	int result = physmem_map(
-		(void *) sysinfo_value("sram.address.physical"),
-		(void *) sram_virt_addr,
-		sysinfo_value("sram.area.size") / PAGE_SIZE,
-		AS_AREA_READ | AS_AREA_WRITE
-		);
-	if (result != 0) {
+	sram_virt_addr = (uintptr_t) as_get_mappable_page(sysinfo_value("sram.area.size"));
+	if (physmem_map((void *) sysinfo_value("sram.address.physical"),
+	    (void *) sram_virt_addr, sysinfo_value("sram.area.size") / PAGE_SIZE,
+	    AS_AREA_READ | AS_AREA_WRITE) != 0)
 		printf("SGCN: uspace driver could not map physical memory.");
-	}
 	
 	sram_buffer_offset = sysinfo_value("sram.buffer.offset");
Index: uspace/srv/ns/ns.c
===================================================================
--- uspace/srv/ns/ns.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ uspace/srv/ns/ns.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -109,9 +109,8 @@
 }
 
-static void get_as_area(ipc_callid_t callid, ipc_call_t *call, char *name,
-    void **addr)
+static void get_as_area(ipc_callid_t callid, ipc_call_t *call, char *name, void **addr)
 {
 	void *ph_addr;
-
+	
 	if (!*addr) {
 		ph_addr = (void *) sysinfo_value(name);
@@ -121,6 +120,9 @@
 		}
 		*addr = as_get_mappable_page(PAGE_SIZE);
-		physmem_map(ph_addr, *addr, 1,
-		    AS_AREA_READ | AS_AREA_CACHEABLE);
+		if (physmem_map(ph_addr, *addr, 1,
+		    AS_AREA_READ | AS_AREA_CACHEABLE) != 0) {
+			ipc_answer_0(callid, ENOENT);
+			return;
+		}
 	}
 	ipc_answer_2(callid, EOK, (ipcarg_t) *addr, AS_AREA_READ);
@@ -151,10 +153,8 @@
 			switch (IPC_GET_ARG3(call)) {
 			case SERVICE_MEM_REALTIME:
-				get_as_area(callid, &call, "clock.faddr",
-				    &clockaddr);
+				get_as_area(callid, &call, "clock.faddr", &clockaddr);
 				break;
 			case SERVICE_MEM_KLOG:
-				get_as_area(callid, &call, "klog.faddr",
-				    &klogaddr);
+				get_as_area(callid, &call, "klog.faddr", &klogaddr);
 				break;
 			default:
Index: uspace/srv/rd/rd.c
===================================================================
--- uspace/srv/rd/rd.c	(revision 17f168ea0a58301762156920e112c588faa90d23)
+++ uspace/srv/rd/rd.c	(revision ae318d3535cba06a6996f270db31a961fae402ad)
@@ -258,5 +258,5 @@
 	int retval = physmem_map(rd_ph_addr, rd_addr,
 	    ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
-
+	
 	if (retval < 0) {
 		printf(NAME ": Error mapping RAM disk\n");
