Index: arch/amd64/Makefile.inc
===================================================================
--- arch/amd64/Makefile.inc	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/amd64/Makefile.inc	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -88,4 +88,5 @@
 	arch/$(ARCH)/src/bios/bios.c \
 	arch/$(ARCH)/src/interrupt.c \
+	arch/$(ARCH)/src/mm/as.c \
 	arch/$(ARCH)/src/mm/frame.c \
 	arch/$(ARCH)/src/mm/page.c \
Index: arch/amd64/include/mm/as.h
===================================================================
--- arch/amd64/include/mm/as.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/amd64/include/mm/as.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -43,3 +43,5 @@
 #define as_install_arch(as)
 
+extern void as_arch_init(void);
+
 #endif
Index: arch/amd64/src/mm/as.c
===================================================================
--- arch/amd64/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
+++ arch/amd64/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -0,0 +1,1 @@
+../../../ia32/src/mm/as.c
Index: arch/amd64/src/mm/page.c
===================================================================
--- arch/amd64/src/mm/page.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/amd64/src/mm/page.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -39,9 +39,6 @@
 #include <interrupt.h>
 
-static __address bootstrap_dba; 
-
 void page_arch_init(void)
 {
-	__address dba;
 	__address cur;
 
@@ -49,21 +46,16 @@
 		page_operations = &page_pt_operations;
 	
-		dba = frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL);
-		memsetb(dba, PAGE_SIZE, 0);
-
-		bootstrap_dba = dba;
-
 		/*
 		 * PA2KA(identity) mapping for all frames.
 		 */
 		for (cur = 0; cur < last_frame; cur += FRAME_SIZE) {
-			page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, PAGE_CACHEABLE | PAGE_EXEC, KA2PA(dba));
+			page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, PAGE_CACHEABLE | PAGE_EXEC);
 		}
 
 		exc_register(14, "page_fault", page_fault);
-		write_cr3(KA2PA(dba));
+		write_cr3((__address) AS_KERNEL->page_table);
 	}
 	else {
-		write_cr3(KA2PA(bootstrap_dba));
+		write_cr3((__address) AS_KERNEL->page_table);
 	}
 }
Index: arch/ia32/Makefile.inc
===================================================================
--- arch/ia32/Makefile.inc	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/ia32/Makefile.inc	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -111,4 +111,5 @@
 	arch/$(ARCH)/src/userspace.c \
 	arch/$(ARCH)/src/cpu/cpu.c \
+	arch/$(ARCH)/src/mm/as.c \
 	arch/$(ARCH)/src/mm/frame.c \
 	arch/$(ARCH)/src/mm/memory_init.c \
Index: arch/ia32/include/mm/as.h
===================================================================
--- arch/ia32/include/mm/as.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/ia32/include/mm/as.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -43,3 +43,5 @@
 #define as_install_arch(as)
 
+extern void as_arch_init(void);
+
 #endif
Index: arch/ia32/src/drivers/ega.c
===================================================================
--- arch/ia32/src/drivers/ega.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/ia32/src/drivers/ega.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -60,5 +60,5 @@
 	__u8 hi, lo;
 
-	page_mapping_insert(AS_KERNEL, PA2KA(VIDEORAM), VIDEORAM, PAGE_NOT_CACHEABLE, 0);
+	page_mapping_insert(AS_KERNEL, PA2KA(VIDEORAM), VIDEORAM, PAGE_NOT_CACHEABLE);
 	outb(0x3d4,0xe);
 	hi = inb(0x3d5);
Index: arch/ia32/src/mm/as.c
===================================================================
--- arch/ia32/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
+++ arch/ia32/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#include <arch/mm/as.h>
+#include <genarch/mm/as_pt.h>
+
+/** Architecture dependent address space init. */
+void as_arch_init(void)
+{
+	as_operations = &as_pt_operations;
+}
Index: arch/ia32/src/mm/page.c
===================================================================
--- arch/ia32/src/mm/page.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/ia32/src/mm/page.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -43,9 +43,6 @@
 #include <interrupt.h>
 
-static __address bootstrap_dba; 
-
 void page_arch_init(void)
 {
-	__address dba;
 	__address cur;
 
@@ -53,20 +50,15 @@
 		page_operations = &page_pt_operations;
 	
-		dba = frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL);
-		memsetb(dba, PAGE_SIZE, 0);
-
-		bootstrap_dba = dba;
-		
 		/*
 		 * PA2KA(identity) mapping for all frames until last_frame.
 		 */
 		for (cur = 0; cur < last_frame; cur += FRAME_SIZE)
-			page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, PAGE_CACHEABLE, KA2PA(dba));
+			page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, PAGE_CACHEABLE);
 
 		exc_register(14, "page_fault", page_fault);
-		write_cr3(KA2PA(dba));
+		write_cr3((__address) AS_KERNEL->page_table);
 	}
 	else {
-		write_cr3(KA2PA(bootstrap_dba));
+		write_cr3((__address) AS_KERNEL->page_table);
 	}
 
Index: arch/ia32/src/smp/smp.c
===================================================================
--- arch/ia32/src/smp/smp.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/ia32/src/smp/smp.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -67,7 +67,7 @@
 	if (config.cpu_count > 1) {		
 		page_mapping_insert(AS_KERNEL, (__address) l_apic, (__address) l_apic, 
-				  PAGE_NOT_CACHEABLE, 0);
+				  PAGE_NOT_CACHEABLE);
 		page_mapping_insert(AS_KERNEL, (__address) io_apic, (__address) io_apic,
-				  PAGE_NOT_CACHEABLE, 0);
+				  PAGE_NOT_CACHEABLE);
         }
 
Index: arch/ia64/Makefile.inc
===================================================================
--- arch/ia64/Makefile.inc	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/ia64/Makefile.inc	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -65,4 +65,5 @@
 	arch/$(ARCH)/src/ivt.S \
 	arch/$(ARCH)/src/interrupt.c \
+	arch/$(ARCH)/src/mm/as.c \
 	arch/$(ARCH)/src/mm/frame.c \
 	arch/$(ARCH)/src/mm/page.c \
Index: arch/ia64/include/mm/as.h
===================================================================
--- arch/ia64/include/mm/as.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/ia64/include/mm/as.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -43,3 +43,5 @@
 #define as_install_arch(as)
 
+extern void as_arch_init(void);
+
 #endif
Index: arch/ia64/include/mm/page.h
===================================================================
--- arch/ia64/include/mm/page.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/ia64/include/mm/page.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -44,9 +44,8 @@
 #define PA2KA(x)	((__address) (x))
 
-#define GET_PTL0_ADDRESS_ARCH()			((pte_t *) 0)
-#define SET_PTL0_ADDRESS_ARCH(ptl0)
+#define SET_PTL0_ADDRESS_ARCH(x)	/**< To be removed as situation permits. */
 
 /** Implementation of page hash table interface. */
-#define HT_ENTRIES_ARCH					(VHPT_SIZE/sizeof(pte_t))
+#define HT_WIDTH_ARCH					20	/* 1M */
 #define HT_HASH_ARCH(page, asid)			vhpt_hash((page), (asid))
 #define HT_COMPARE_ARCH(page, asid, t)			vhpt_compare((page), (asid), (t))
Index: arch/ia64/src/mm/as.c
===================================================================
--- arch/ia64/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
+++ arch/ia64/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#include <arch/mm/as.h>
+#include <genarch/mm/as_ht.h>
+
+/** Architecture dependent address space init. */
+void as_arch_init(void)
+{
+	as_operations = &as_ht_operations;
+}
Index: arch/ia64/src/mm/tlb.c
===================================================================
--- arch/ia64/src/mm/tlb.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/ia64/src/mm/tlb.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -34,9 +34,5 @@
 #include <arch/mm/asid.h>
 
-/** Invalidate all TLB entries.
- *
- * Because of ASID management, region registers must be reset
- * with new RIDs derived from the potentionally new ASID.
- */
+/** Invalidate all TLB entries. */
 void tlb_invalidate_all(void)
 {
Index: arch/mips32/include/mm/as.h
===================================================================
--- arch/mips32/include/mm/as.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/mips32/include/mm/as.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -42,3 +42,5 @@
 #define UDATA_ADDRESS_ARCH	0x01001000
 
+extern void as_arch_init(void);
+
 #endif
Index: arch/mips32/src/mm/as.c
===================================================================
--- arch/mips32/src/mm/as.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/mips32/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -28,4 +28,5 @@
 
 #include <arch/mm/as.h>
+#include <genarch/mm/as_pt.h>
 #include <arch/mm/tlb.h>
 #include <mm/tlb.h>
@@ -33,4 +34,10 @@
 #include <arch/cp0.h>
 #include <arch.h>
+
+/** Architecture dependent address space init. */
+void as_arch_init(void)
+{
+        as_operations = &as_pt_operations;
+}
 
 /** Install address space.
@@ -57,2 +64,3 @@
 	interrupts_restore(ipl);
 }
+
Index: arch/mips32/src/mm/tlb.c
===================================================================
--- arch/mips32/src/mm/tlb.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/mips32/src/mm/tlb.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -340,5 +340,5 @@
 	 * Check if the mapping exists in page tables.
 	 */	
-	pte = page_mapping_find(AS, badvaddr, 0);
+	pte = page_mapping_find(AS, badvaddr);
 	if (pte && pte->lo.v) {
 		/*
@@ -357,5 +357,5 @@
 			 * The mapping ought to be in place.
 			 */
-			pte = page_mapping_find(AS, badvaddr, 0);
+			pte = page_mapping_find(AS, badvaddr);
 			ASSERT(pte && pte->lo.v);
 			return pte;
Index: arch/ppc32/Makefile.inc
===================================================================
--- arch/ppc32/Makefile.inc	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/ppc32/Makefile.inc	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -61,4 +61,5 @@
 	arch/$(ARCH)/src/asm.S \
 	arch/$(ARCH)/src/cpu/cpu.c \
+	arch/$(ARCH)/src/mm/as.c \
 	arch/$(ARCH)/src/mm/frame.c \
 	arch/$(ARCH)/src/mm/memory_init.c \
Index: arch/ppc32/include/mm/as.h
===================================================================
--- arch/ppc32/include/mm/as.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/ppc32/include/mm/as.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -43,3 +43,5 @@
 #define as_install_arch(as)
 
+extern void as_arch_init(void);
+
 #endif
Index: arch/ppc32/src/mm/as.c
===================================================================
--- arch/ppc32/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
+++ arch/ppc32/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#include <arch/mm/as.h>
+#include <genarch/mm/as_pt.h>
+
+/** Architecture dependent address space init. */
+void as_arch_init(void)
+{
+	as_operations = &as_pt_operations;
+}
Index: arch/sparc64/Makefile.inc
===================================================================
--- arch/sparc64/Makefile.inc	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/sparc64/Makefile.inc	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -65,4 +65,5 @@
 	arch/$(ARCH)/src/context.S \
 	arch/$(ARCH)/src/dummy.s \
+	arch/$(ARCH)/src/mm/as.c \
 	arch/$(ARCH)/src/mm/frame.c \
 	arch/$(ARCH)/src/mm/page.c \
Index: arch/sparc64/include/mm/as.h
===================================================================
--- arch/sparc64/include/mm/as.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/sparc64/include/mm/as.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -43,3 +43,5 @@
 #define as_install_arch(as)
 
+extern void as_arch_init(void);
+
 #endif
Index: arch/sparc64/include/mm/frame.h
===================================================================
--- arch/sparc64/include/mm/frame.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/sparc64/include/mm/frame.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -32,5 +32,6 @@
 #include <arch/types.h>
 
-#define FRAME_SIZE		8192
+#define FRAME_WIDTH		13
+#define FRAME_SIZE		(1<<FRAME_WIDTH)
 
 union frame_address {
Index: arch/sparc64/include/mm/page.h
===================================================================
--- arch/sparc64/include/mm/page.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ arch/sparc64/include/mm/page.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -39,9 +39,8 @@
 #define PA2KA(x)	((__address) (x))
 
-#define GET_PTL0_ADDRESS_ARCH()		0
-#define SET_PTL0_ADDRESS_ARCH(ptl0)
+#define SET_PTL0_ADDRESS_ARCH(x)	/**< To be removed as situation permits. */
 
 /** Implementation of page hash table interface. */
-#define HT_ENTRIES_ARCH			0
+#define HT_WIDTH_ARCH			20	/* 1M */
 #define HT_HASH_ARCH(page, asid)	0
 #define HT_COMPARE_ARCH(page, asid, t)	0
Index: arch/sparc64/src/mm/as.c
===================================================================
--- arch/sparc64/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
+++ arch/sparc64/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#include <arch/mm/as.h>
+#include <genarch/mm/as_ht.h>
+
+/** Architecture dependent address space init. */
+void as_arch_init(void)
+{
+	as_operations = &as_ht_operations;
+}
Index: genarch/Makefile.inc
===================================================================
--- genarch/Makefile.inc	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ genarch/Makefile.inc	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -40,9 +40,11 @@
 ifeq ($(CONFIG_PAGE_PT),y)
 	GENARCH_SOURCES += \
-		genarch/src/mm/page_pt.c
+		genarch/src/mm/page_pt.c \
+		genarch/src/mm/as_pt.c
 endif
 ifeq ($(CONFIG_PAGE_HT),y)
 	GENARCH_SOURCES += \
-		genarch/src/mm/page_ht.c
+		genarch/src/mm/page_ht.c \
+		genarch/src/mm/as_ht.c
 endif
 ifeq ($(CONFIG_ASID),y)
Index: genarch/include/mm/as_ht.h
===================================================================
--- genarch/include/mm/as_ht.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
+++ genarch/include/mm/as_ht.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#ifndef __AS_HT_H__
+#define __AS_HT_H__
+
+#include <mm/as.h>
+
+extern as_operations_t as_ht_operations;
+
+#endif
Index: genarch/include/mm/as_pt.h
===================================================================
--- genarch/include/mm/as_pt.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
+++ genarch/include/mm/as_pt.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#ifndef __AS_PT_H__
+#define __AS_PT_H__
+
+#include <mm/as.h>
+
+extern as_operations_t as_pt_operations;
+
+#endif
Index: genarch/include/mm/page_ht.h
===================================================================
--- genarch/include/mm/page_ht.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ genarch/include/mm/page_ht.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -39,6 +39,8 @@
 #include <typedefs.h>
 
-/** Number of slots in page hash table. */
-#define HT_ENTRIES			HT_ENTRIES_ARCH
+/** Page hash table size. */
+#define HT_WIDTH			HT_WIDTH_ARCH
+#define HT_SIZE				(1<<HT_WIDTH)
+#define HT_ENTRIES			(HT_SIZE/sizeof(pte_t))
 
 /** Hash function.
@@ -100,5 +102,4 @@
 #define HT_SET_RECORD(t, page, asid, frame, flags)	HT_SET_RECORD_ARCH(t, page, asid, frame, flags)
 
-
 extern page_operations_t page_ht_operations;
 extern spinlock_t page_ht_lock;
Index: genarch/include/mm/page_pt.h
===================================================================
--- genarch/include/mm/page_pt.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ genarch/include/mm/page_pt.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -88,6 +88,6 @@
 extern page_operations_t page_pt_operations;
 
-extern void page_mapping_insert_pt(as_t *as, __address page, __address frame, int flags, __address root);
-extern pte_t *page_mapping_find_pt(as_t *as, __address page, __address root);
+extern void page_mapping_insert_pt(as_t *as, __address page, __address frame, int flags);
+extern pte_t *page_mapping_find_pt(as_t *as, __address page);
 
 #endif
Index: genarch/src/acpi/acpi.c
===================================================================
--- genarch/src/acpi/acpi.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ genarch/src/acpi/acpi.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -80,5 +80,5 @@
 static void map_sdt(struct acpi_sdt_header *sdt)
 {
-	page_mapping_insert(AS_KERNEL, (__address) sdt, (__address) sdt, PAGE_NOT_CACHEABLE, 0);
+	page_mapping_insert(AS_KERNEL, (__address) sdt, (__address) sdt, PAGE_NOT_CACHEABLE);
 	map_structure((__address) sdt, sdt->length);
 }
Index: genarch/src/mm/as_ht.c
===================================================================
--- genarch/src/mm/as_ht.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
+++ genarch/src/mm/as_ht.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#include <genarch/mm/as_ht.h>
+#include <genarch/mm/page_ht.h>
+#include <mm/as.h>
+#include <mm/frame.h>
+#include <arch/types.h>
+#include <typedefs.h>
+#include <memstr.h>
+
+static pte_t *ht_create(int flags);
+
+as_operations_t as_ht_operations = {
+	.page_table_create = ht_create
+};
+
+
+/** Page hash table create.
+ *
+ * The page hash table will be created only once
+ * and will be shared by all address spaces.
+ *
+ * @param flags Ignored.
+ *
+ * @return Address of global page hash table.
+ */
+pte_t *ht_create(int flags)
+{
+	if (!page_ht) {
+		page_ht = (pte_t *) frame_alloc(FRAME_KA | FRAME_PANIC, HT_WIDTH - FRAME_WIDTH, NULL);
+		memsetb((__address) page_ht, HT_SIZE, 0);
+	}
+	return page_ht;
+}
Index: genarch/src/mm/as_pt.c
===================================================================
--- genarch/src/mm/as_pt.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
+++ genarch/src/mm/as_pt.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#include <genarch/mm/page_pt.h>
+#include <mm/page.h>
+#include <mm/frame.h>
+#include <mm/as.h>
+#include <arch/mm/page.h>
+#include <arch/mm/as.h>
+#include <arch/types.h>
+#include <typedefs.h>
+#include <memstr.h>
+#include <arch.h>
+
+static pte_t *ptl0_create(int flags);
+
+as_operations_t as_pt_operations = {
+	.page_table_create = ptl0_create
+};
+
+/** Create PTL0.
+ *
+ * PTL0 of 4-level page table will be created for each address space.
+ *
+ * @param flags Flags can specify whether ptl0 is for the kernel address space.
+ *
+ * @return New PTL0.
+ */
+pte_t *ptl0_create(int flags)
+{
+	pte_t *src_ptl0, *dst_ptl0;
+	ipl_t ipl;
+
+	dst_ptl0 = (pte_t *) frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL);
+
+	if (flags & FLAG_AS_KERNEL) {
+		memsetb((__address) dst_ptl0, PAGE_SIZE, 0);
+	} else {
+		/*
+		 * Copy the kernel address space portion to new PTL0.
+		 * TODO: copy only kernel address space.
+		 */
+		 
+		ipl = interrupts_disable();
+		spinlock_lock(&AS_KERNEL->lock);
+		src_ptl0 = (pte_t *) PA2KA((__address) AS_KERNEL->page_table);
+		memcpy((void *) dst_ptl0,(void *) src_ptl0, PAGE_SIZE);
+		spinlock_unlock(&AS_KERNEL->lock);
+		interrupts_restore(ipl);
+	}
+
+	return (pte_t *) KA2PA((__address) dst_ptl0);
+}
Index: genarch/src/mm/page_ht.c
===================================================================
--- genarch/src/mm/page_ht.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ genarch/src/mm/page_ht.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -39,10 +39,8 @@
 #include <arch.h>
 #include <debug.h>
+#include <memstr.h>
 
 /**
- * This lock protects the page hash table. Note that software must
- * be still careful about ordering of writes to ensure consistent
- * view of the page hash table for hardware helpers such as VHPT
- * walker on ia64.
+ * This lock protects the page hash table.
  */
 SPINLOCK_INITIALIZE(page_ht_lock);
@@ -54,10 +52,10 @@
 pte_t *page_ht = NULL;
 
-static void ht_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root);
-static pte_t *ht_mapping_find(as_t *as, __address page, __address root);
+static void ht_mapping_insert(as_t *as, __address page, __address frame, int flags);
+static pte_t *ht_mapping_find(as_t *as, __address page);
 
 page_operations_t page_ht_operations = {
 	.mapping_insert = ht_mapping_insert,
-	.mapping_find = ht_mapping_find
+	.mapping_find = ht_mapping_find,
 };
 
@@ -65,15 +63,14 @@
  *
  * Map virtual address 'page' to physical address 'frame'
- * using 'flags'. In order not to disturb hardware searching,
- * new mappings are appended to the end of the collision
- * chain.
+ * using 'flags'. 
  *
- * @param as Address space to which page belongs. Must be locked prior the call.
+ * The address space must be locked and interruptsmust be disabled.
+ *
+ * @param as Address space to which page belongs.
  * @param page Virtual address of the page to be mapped.
  * @param frame Physical address of memory frame to which the mapping is done.
  * @param flags Flags to be used for mapping.
- * @param root Ignored.
  */
-void ht_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
+void ht_mapping_insert(as_t *as, __address page, __address frame, int flags)
 {
 	pte_t *t, *u;
@@ -122,13 +119,12 @@
  * Find mapping for virtual page.
  *
- * Interrupts must be disabled.
+ * The address space must be locked and interrupts must be disabled.
  *
- * @param as Address space to wich page belongs. Must be locked prior the call.
+ * @param as Address space to wich page belongs.
  * @param page Virtual page.
- * @param root Ignored.
  *
  * @return NULL if there is no such mapping; requested mapping otherwise.
  */
-pte_t *ht_mapping_find(as_t *as, __address page, __address root)
+pte_t *ht_mapping_find(as_t *as, __address page)
 {
 	pte_t *t;
Index: genarch/src/mm/page_pt.c
===================================================================
--- genarch/src/mm/page_pt.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ genarch/src/mm/page_pt.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -30,4 +30,5 @@
 #include <mm/page.h>
 #include <mm/frame.h>
+#include <mm/as.h>
 #include <arch/mm/page.h>
 #include <arch/mm/as.h>
@@ -37,6 +38,6 @@
 #include <memstr.h>
 
-static void pt_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root);
-static pte_t *pt_mapping_find(as_t *as, __address page, __address root);
+static void pt_mapping_insert(as_t *as, __address page, __address frame, int flags);
+static pte_t *pt_mapping_find(as_t *as, __address page);
 
 page_operations_t page_pt_operations = {
@@ -50,16 +51,17 @@
  * using 'flags'.
  *
- * @param as Ignored.
+ * The address space must be locked and interrupts must be disabled.
+ *
+ * @param as Address space to wich page belongs.
  * @param page Virtual address of the page to be mapped.
  * @param frame Physical address of memory frame to which the mapping is done.
  * @param flags Flags to be used for mapping.
- * @param root Explicit PTL0 address.
  */
-void pt_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
+void pt_mapping_insert(as_t *as, __address page, __address frame, int flags)
 {
 	pte_t *ptl0, *ptl1, *ptl2, *ptl3;
 	__address newpt;
 
-	ptl0 = (pte_t *) PA2KA(root ? root : (__address) GET_PTL0_ADDRESS());
+	ptl0 = (pte_t *) PA2KA((__address) as->page_table);
 
 	if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
@@ -98,15 +100,16 @@
  * Find mapping for virtual page.
  *
- * @param as Ignored.
+ * The address space must be locked and interrupts must be disabled.
+ *
+ * @param as Address space to which page belongs.
  * @param page Virtual page.
- * @param root PTL0 address if non-zero.
  *
  * @return NULL if there is no such mapping; entry from PTL3 describing the mapping otherwise.
  */
-pte_t *pt_mapping_find(as_t *as, __address page, __address root)
+pte_t *pt_mapping_find(as_t *as, __address page)
 {
 	pte_t *ptl0, *ptl1, *ptl2, *ptl3;
 
-	ptl0 = (pte_t *) PA2KA(root ? root : (__address) GET_PTL0_ADDRESS());
+	ptl0 = (pte_t *) PA2KA((__address) as->page_table);
 
 	if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT)
Index: generic/include/mm/as.h
===================================================================
--- generic/include/mm/as.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ generic/include/mm/as.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -81,11 +81,22 @@
 	SPINLOCK_DECLARE(lock);
 	link_t as_area_head;
-	pte_t *ptl0;
-	asid_t asid;			/**< Address space identifier. */
+
+	/** Page table pointer. Constant on architectures that use global page hash table. */
+	pte_t *page_table;
+
+	/** Address space identifier. Constant on architectures that do not support ASIDs.*/
+	asid_t asid;
 };
 
+struct as_operations {
+	pte_t *(* page_table_create)(int flags);
+};
+typedef struct as_operations as_operations_t;
+
 extern as_t *AS_KERNEL;
+extern as_operations_t *as_operations;
 
-extern as_t *as_create(pte_t *ptl0, int flags);
+extern void as_init(void);
+extern as_t *as_create(int flags);
 extern as_area_t *as_area_create(as_t *as, as_area_type_t type, size_t size, __address base);
 extern void as_set_mapping(as_t *as, __address page, __address frame);
Index: generic/include/mm/buddy.h
===================================================================
--- generic/include/mm/buddy.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ generic/include/mm/buddy.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -58,4 +58,3 @@
 extern void buddy_system_structure_print(buddy_system_t *b, size_t elem_size);
 
-
 #endif
Index: generic/include/mm/page.h
===================================================================
--- generic/include/mm/page.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ generic/include/mm/page.h	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -62,6 +62,6 @@
 /** Operations to manipulate page mappings. */
 struct page_operations {
-	void (* mapping_insert)(as_t *as, __address page, __address frame, int flags, __address root);
-	pte_t *(* mapping_find)(as_t *as, __address page, __address root);
+	void (* mapping_insert)(as_t *as, __address page, __address frame, int flags);
+	pte_t *(* mapping_find)(as_t *as, __address page);
 };
 typedef struct page_operations page_operations_t;
@@ -70,6 +70,7 @@
 
 extern void page_init(void);
-extern void page_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root);
-extern pte_t *page_mapping_find(as_t *as, __address page, __address root);
+extern void page_mapping_insert(as_t *as, __address page, __address frame, int flags);
+extern pte_t *page_mapping_find(as_t *as, __address page);
+extern pte_t *page_table_create(int flags);
 extern void map_structure(__address s, size_t size);
 
Index: generic/src/main/kinit.c
===================================================================
--- generic/src/main/kinit.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ generic/src/main/kinit.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -148,5 +148,5 @@
 			panic("config.init_addr is not frame aligned");
 		
-		as = as_create(NULL, 0);
+		as = as_create(0);
 		if (!as)
 			panic("as_create\n");
@@ -159,5 +159,5 @@
 		
 		/*
-		 * Create the text as_area and copy the userspace code there.
+		 * Create the text as_area and initialize its mapping.
 		 */
 		
@@ -170,5 +170,8 @@
 		if (!a)
 			panic("as_area_create: text\n");
-		
+
+		for (i = 0; i < frames; i++)
+			as_set_mapping(as, UTEXT_ADDRESS + i * PAGE_SIZE, frame + i * FRAME_SIZE);
+
 		/*
 		 * Create the data as_area.
@@ -178,11 +181,4 @@
 			panic("as_area_create: stack\n");
 
-		/*
-		 * Initialize text area mapping.
-		 */
-		for (i = 0; i < frames; i++)
-			as_set_mapping(as, UTEXT_ADDRESS + i * PAGE_SIZE, frame + i * FRAME_SIZE);
-
-	
 		thread_ready(t);
 	}
Index: generic/src/main/main.c
===================================================================
--- generic/src/main/main.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ generic/src/main/main.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -139,5 +139,4 @@
 void main_bsp_separated_stack(void) 
 {
-	as_t *as;
 	task_t *k;
 	thread_t *t;
@@ -152,5 +151,6 @@
 	kconsole_init();
 
-	/* Exception handler initialization, before architecture
+	/*
+	 * Exception handler initialization, before architecture
 	 * starts adding its own handlers
 	 */
@@ -163,4 +163,5 @@
 	early_heap_init(config.heap_addr, config.heap_size + config.heap_delta);
 	frame_init();
+	as_init();
 	page_init();
 	tlb_init();
@@ -190,14 +191,7 @@
 
 	/*
-	 * Create kernel address space.
-	 */
-	as = as_create(GET_PTL0_ADDRESS(), FLAG_AS_KERNEL);
-	if (!as)
-		panic("can't create kernel address space\n");
-
-	/*
 	 * Create kernel task.
 	 */
-	k = task_create(as);
+	k = task_create(AS_KERNEL);
 	if (!k)
 		panic("can't create kernel task\n");
Index: generic/src/mm/as.c
===================================================================
--- generic/src/mm/as.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ generic/src/mm/as.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -34,5 +34,5 @@
 
 #include <mm/as.h>
-#include <mm/asid.h>
+#include <arch/mm/as.h>
 #include <mm/page.h>
 #include <mm/frame.h>
@@ -43,5 +43,4 @@
 #include <mm/asid.h>
 #include <arch/mm/asid.h>
-#include <arch/mm/as.h>
 #include <arch/types.h>
 #include <typedefs.h>
@@ -56,16 +55,19 @@
 #include <print.h>
 
-#define KAS_START_INDEX		PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)
-#define KAS_END_INDEX		PTL0_INDEX(KERNEL_ADDRESS_SPACE_END)
-#define KAS_INDICES		(1+(KAS_END_INDEX-KAS_START_INDEX))
+as_operations_t *as_operations = NULL;
 
 static int get_area_flags(as_area_t *a);
 
+/** Initialize address space subsystem. */
+void as_init(void)
+{
+	as_arch_init();
+	AS_KERNEL = as_create(FLAG_AS_KERNEL);
+        if (!AS_KERNEL)
+                panic("can't create kernel address space\n");
+}
+
 /** Create address space. */
-/*
- * FIXME: this interface must be meaningful for all possible VAT
- * 	  (Virtual Address Translation) mechanisms.
- */
-as_t *as_create(pte_t *ptl0, int flags)
+as_t *as_create(int flags)
 {
 	as_t *as;
@@ -82,18 +84,5 @@
 			as->asid = ASID_INVALID;
 
-		as->ptl0 = ptl0;
-		if (!as->ptl0) {
-			pte_t *src_ptl0, *dst_ptl0;
-		
-			src_ptl0 = (pte_t *) PA2KA((__address) GET_PTL0_ADDRESS());
-			dst_ptl0 = (pte_t *) frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL);
-
-//			memsetb((__address) dst_ptl0, PAGE_SIZE, 0);
-//			memcpy((void *) &dst_ptl0[KAS_START_INDEX], (void *) &src_ptl0[KAS_START_INDEX], KAS_INDICES);
-			
-			memcpy((void *) dst_ptl0,(void *) src_ptl0, PAGE_SIZE);
-
-			as->ptl0 = (pte_t *) KA2PA((__address) dst_ptl0);
-		}
+		as->page_table = page_table_create(flags);
 	}
 
@@ -187,5 +176,5 @@
 	 */
 	
-	page_mapping_insert(as, page, frame, get_area_flags(area), (__address) as->ptl0);
+	page_mapping_insert(as, page, frame, get_area_flags(area));
 	
 	spinlock_unlock(&area->lock);
@@ -267,5 +256,5 @@
 	 * inserted into page tables.
 	 */
-	page_mapping_insert(AS, page, frame, get_area_flags(area), (__address) AS->ptl0);
+	page_mapping_insert(AS, page, frame, get_area_flags(area));
 	
 	spinlock_unlock(&area->lock);
@@ -287,6 +276,6 @@
 	ipl = interrupts_disable();
 	spinlock_lock(&as->lock);
-	ASSERT(as->ptl0);
-	SET_PTL0_ADDRESS(as->ptl0);
+	ASSERT(as->page_table);
+	SET_PTL0_ADDRESS(as->page_table);
 	spinlock_unlock(&as->lock);
 	interrupts_restore(ipl);
@@ -328,2 +317,19 @@
 	return flags;
 }
+
+/** Create page table.
+ *
+ * Depending on architecture, create either address space
+ * private or global page table.
+ *
+ * @param flags Flags saying whether the page table is for kernel address space.
+ *
+ * @return First entry of the page table.
+ */
+pte_t *page_table_create(int flags)
+{
+        ASSERT(as_operations);
+        ASSERT(as_operations->page_table_create);
+
+        return as_operations->page_table_create(flags);
+}
Index: generic/src/mm/page.c
===================================================================
--- generic/src/mm/page.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ generic/src/mm/page.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -49,5 +49,4 @@
 {
 	page_arch_init();
-	page_mapping_insert(AS_KERNEL, 0x0, 0x0, PAGE_NOT_PRESENT, 0);
 }
 
@@ -69,5 +68,5 @@
 
 	for (i = 0; i < cnt; i++)
-		page_mapping_insert(AS_KERNEL, s + i*PAGE_SIZE, s + i*PAGE_SIZE, PAGE_NOT_CACHEABLE, 0);
+		page_mapping_insert(AS_KERNEL, s + i*PAGE_SIZE, s + i*PAGE_SIZE, PAGE_NOT_CACHEABLE);
 
 }
@@ -78,16 +77,17 @@
  * using 'flags'. Allocate and setup any missing page tables.
  *
- * @param as Address space to wich page belongs. Must be locked prior the call.
+ * The address space must be locked and interrupts must be disabled.
+ *
+ * @param as Address space to wich page belongs..
  * @param page Virtual address of the page to be mapped.
  * @param frame Physical address of memory frame to which the mapping is done.
  * @param flags Flags to be used for mapping.
- * @param root Explicit PTL0 address.
  */
-void page_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
+void page_mapping_insert(as_t *as, __address page, __address frame, int flags)
 {
 	ASSERT(page_operations);
 	ASSERT(page_operations->mapping_insert);
 	
-	page_operations->mapping_insert(as, page, frame, flags, root);
+	page_operations->mapping_insert(as, page, frame, flags);
 }
 
@@ -96,15 +96,16 @@
  * Find mapping for virtual page.
  *
- * @param as Address space to wich page belongs must be locked prior the call.
+ * The address space must be locked and interrupts must be disabled.
+ *
+ * @param as Address space to wich page belongs.
  * @param page Virtual page.
- * @param root PTL0 address if non-zero.
  *
  * @return NULL if there is no such mapping; requested mapping otherwise.
  */
-pte_t *page_mapping_find(as_t *as, __address page, __address root)
+pte_t *page_mapping_find(as_t *as, __address page)
 {
 	ASSERT(page_operations);
 	ASSERT(page_operations->mapping_find);
 
-	return page_operations->mapping_find(as, page, root);
+	return page_operations->mapping_find(as, page);
 }
Index: test/mm/mapping1/test.c
===================================================================
--- test/mm/mapping1/test.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
+++ test/mm/mapping1/test.c	(revision ef67bab91625cc0f0eaecd741316d269bbfd5094)
@@ -57,7 +57,7 @@
 	
 	printf("Mapping virtual address %P to physical address %P.\n", PAGE0, KA2PA(frame0));
-	page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE, 0);
+	page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE);
 	printf("Mapping virtual address %P to physical address %P.\n", PAGE1, KA2PA(frame1));	
-	page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE, 0);
+	page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE);
 	
 	printf("Value at virtual address %P is %L.\n", PAGE0, v0 = *((__u32 *) PAGE0));
