Index: arch/amd64/src/mm/page.c
===================================================================
--- arch/amd64/src/mm/page.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ arch/amd64/src/mm/page.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -32,5 +32,5 @@
 #include <mm/page.h>
 #include <mm/frame.h>
-#include <mm/asid.h>
+#include <mm/as.h>
 #include <arch/interrupt.h>
 #include <arch/asm.h>
@@ -58,5 +58,5 @@
 		 */
 		for (cur = 0; cur < last_frame; cur += FRAME_SIZE) {
-			page_mapping_insert(PA2KA(cur), ASID_KERNEL, cur, PAGE_CACHEABLE | PAGE_EXEC, KA2PA(dba));
+			page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, PAGE_CACHEABLE | PAGE_EXEC, KA2PA(dba));
 		}
 
Index: arch/ia32/src/drivers/ega.c
===================================================================
--- arch/ia32/src/drivers/ega.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ arch/ia32/src/drivers/ega.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -30,5 +30,5 @@
 #include <putchar.h>
 #include <mm/page.h>
-#include <mm/asid.h>
+#include <mm/as.h>
 #include <arch/mm/page.h>
 #include <synch/spinlock.h>
@@ -60,5 +60,5 @@
 	__u8 hi, lo;
 
-	page_mapping_insert(PA2KA(VIDEORAM), ASID_KERNEL, VIDEORAM, PAGE_NOT_CACHEABLE, 0);
+	page_mapping_insert(AS_KERNEL, PA2KA(VIDEORAM), VIDEORAM, PAGE_NOT_CACHEABLE, 0);
 	outb(0x3d4,0xe);
 	hi = inb(0x3d5);
Index: arch/ia32/src/mm/page.c
===================================================================
--- arch/ia32/src/mm/page.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ arch/ia32/src/mm/page.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -32,5 +32,5 @@
 #include <mm/frame.h>
 #include <mm/page.h>
-#include <mm/asid.h>
+#include <mm/as.h>
 #include <arch/types.h>
 #include <config.h>
@@ -62,5 +62,5 @@
 		 */
 		for (cur = 0; cur < last_frame; cur += FRAME_SIZE)
-			page_mapping_insert(PA2KA(cur), ASID_KERNEL, cur, PAGE_CACHEABLE, KA2PA(dba));
+			page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, PAGE_CACHEABLE, KA2PA(dba));
 
 		exc_register(14, "page_fault", page_fault);
Index: arch/ia32/src/smp/smp.c
===================================================================
--- arch/ia32/src/smp/smp.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ arch/ia32/src/smp/smp.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -45,5 +45,5 @@
 #include <mm/page.h>
 #include <mm/heap.h>
-#include <mm/asid.h>
+#include <mm/as.h>
 #include <print.h>
 #include <memstr.h>
@@ -66,8 +66,7 @@
 
 	if (config.cpu_count > 1) {		
-		page_mapping_insert((__address)l_apic, ASID_KERNEL, (__address)l_apic, 
+		page_mapping_insert(AS_KERNEL, (__address) l_apic, (__address) l_apic, 
 				  PAGE_NOT_CACHEABLE, 0);
-		page_mapping_insert((__address) io_apic, ASID_KERNEL,
-				  (__address) io_apic,
+		page_mapping_insert(AS_KERNEL, (__address) io_apic, (__address) io_apic,
 				  PAGE_NOT_CACHEABLE, 0);
         }
Index: arch/mips32/src/mm/tlb.c
===================================================================
--- arch/mips32/src/mm/tlb.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ arch/mips32/src/mm/tlb.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -340,5 +340,5 @@
 	 * Check if the mapping exists in page tables.
 	 */	
-	pte = page_mapping_find(badvaddr, AS->asid, 0);
+	pte = page_mapping_find(AS, badvaddr, 0);
 	if (pte && pte->lo.v) {
 		/*
@@ -357,5 +357,5 @@
 			 * The mapping ought to be in place.
 			 */
-			pte = page_mapping_find(badvaddr, AS->asid, 0);
+			pte = page_mapping_find(AS, badvaddr, 0);
 			ASSERT(pte && pte->lo.v);
 			return pte;
Index: genarch/include/mm/page_pt.h
===================================================================
--- genarch/include/mm/page_pt.h	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ genarch/include/mm/page_pt.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -88,6 +88,6 @@
 extern page_operations_t page_pt_operations;
 
-extern void page_mapping_insert_pt(__address page, __address frame, int flags, __address root);
-extern pte_t *page_mapping_find_pt(__address page, __address root);
+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);
 
 #endif
Index: genarch/src/acpi/acpi.c
===================================================================
--- genarch/src/acpi/acpi.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ genarch/src/acpi/acpi.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -30,5 +30,5 @@
 #include <genarch/acpi/madt.h>
 #include <arch/bios/bios.h>
-#include <mm/asid.h>
+#include <mm/as.h>
 #include <mm/page.h>
 #include <print.h>
@@ -80,5 +80,5 @@
 static void map_sdt(struct acpi_sdt_header *sdt)
 {
-	page_mapping_insert((__address) sdt, ASID_KERNEL, (__address) sdt, PAGE_NOT_CACHEABLE, 0);
+	page_mapping_insert(AS_KERNEL, (__address) sdt, (__address) sdt, PAGE_NOT_CACHEABLE, 0);
 	map_structure((__address) sdt, sdt->length);
 }
Index: genarch/src/mm/page_ht.c
===================================================================
--- genarch/src/mm/page_ht.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ genarch/src/mm/page_ht.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -31,4 +31,5 @@
 #include <mm/frame.h>
 #include <mm/heap.h>
+#include <mm/as.h>
 #include <arch/mm/asid.h>
 #include <arch/types.h>
@@ -53,6 +54,6 @@
 pte_t *page_ht = NULL;
 
-static void ht_mapping_insert(__address page, asid_t asid, __address frame, int flags, __address root);
-static pte_t *ht_mapping_find(__address page, asid_t asid, __address root);
+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);
 
 page_operations_t page_ht_operations = {
@@ -68,11 +69,11 @@
  * chain.
  *
+ * @param as Address space to which page belongs. Must be locked prior the call.
  * @param page Virtual address of the page to be mapped.
- * @param asid Address space to which page belongs.
  * @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(__address page, asid_t asid, __address frame, int flags, __address root)
+void ht_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
 {
 	pte_t *t, *u;
@@ -81,6 +82,6 @@
 	ipl = interrupts_disable();
 	spinlock_lock(&page_ht_lock);
-	
-	t = HT_HASH(page, asid);
+
+	t = HT_HASH(page, as->asid);
 	if (!HT_SLOT_EMPTY(t)) {
 	
@@ -92,5 +93,5 @@
 		do {
 			u = t;
-			if (HT_COMPARE(page, asid, t)) {
+			if (HT_COMPARE(page, as->asid, t)) {
 				/*
 				 * Nothing to do,
@@ -110,5 +111,5 @@
 	}
 	
-	HT_SET_RECORD(t, page, asid, frame, flags);
+	HT_SET_RECORD(t, page, as->asid, frame, flags);
 	HT_SET_NEXT(t, NULL);
 	
@@ -123,20 +124,20 @@
  * Interrupts must be disabled.
  *
+ * @param as Address space to wich page belongs. Must be locked prior the call.
  * @param page Virtual page.
- * @param asid Address space to wich page belongs.
  * @param root Ignored.
  *
  * @return NULL if there is no such mapping; requested mapping otherwise.
  */
-pte_t *ht_mapping_find(__address page, asid_t asid, __address root)
+pte_t *ht_mapping_find(as_t *as, __address page, __address root)
 {
 	pte_t *t;
 	
 	spinlock_lock(&page_ht_lock);
-	t = HT_HASH(page, asid);
+	t = HT_HASH(page, as->asid);
 	if (!HT_SLOT_EMPTY(t)) {
-		while (!HT_COMPARE(page, asid, t) && HT_GET_NEXT(t))
+		while (!HT_COMPARE(page, as->asid, t) && HT_GET_NEXT(t))
 			t = HT_GET_NEXT(t);
-		t = HT_COMPARE(page, asid, t) ? t : NULL;
+		t = HT_COMPARE(page, as->asid, t) ? t : NULL;
 	} else {
 		t = NULL;
Index: genarch/src/mm/page_pt.c
===================================================================
--- genarch/src/mm/page_pt.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ genarch/src/mm/page_pt.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -31,5 +31,5 @@
 #include <mm/frame.h>
 #include <arch/mm/page.h>
-#include <arch/mm/asid.h>
+#include <arch/mm/as.h>
 #include <arch/types.h>
 #include <typedefs.h>
@@ -37,6 +37,6 @@
 #include <memstr.h>
 
-static void pt_mapping_insert(__address page, asid_t asid, __address frame, int flags, __address root);
-static pte_t *pt_mapping_find(__address page, asid_t asid, __address root);
+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);
 
 page_operations_t page_pt_operations = {
@@ -50,11 +50,11 @@
  * using 'flags'.
  *
+ * @param as Ignored.
  * @param page Virtual address of the page to be mapped.
- * @param asid Ignored.
  * @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(__address page, asid_t asid, __address frame, int flags, __address root)
+void pt_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
 {
 	pte_t *ptl0, *ptl1, *ptl2, *ptl3;
@@ -98,11 +98,11 @@
  * Find mapping for virtual page.
  *
+ * @param as Ignored.
  * @param page Virtual page.
- * @param asid Ignored.
  * @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(__address page, asid_t asid, __address root)
+pte_t *pt_mapping_find(as_t *as, __address page, __address root)
 {
 	pte_t *ptl0, *ptl1, *ptl2, *ptl3;
Index: generic/include/mm/as.h
===================================================================
--- generic/include/mm/as.h	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ generic/include/mm/as.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -49,5 +49,5 @@
 #define UDATA_ADDRESS	UDATA_ADDRESS_ARCH
 
-#define AS_KERNEL	(1<<0)		/**< Kernel address space. */
+#define FLAG_AS_KERNEL	(1<<0)		/**< Kernel address space. */
 
 enum as_area_type {
@@ -85,5 +85,7 @@
 };
 
-extern as_t * as_create(pte_t *ptl0, int flags);
+extern as_t *AS_KERNEL;
+
+extern as_t *as_create(pte_t *ptl0, 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/page.h
===================================================================
--- generic/include/mm/page.h	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ generic/include/mm/page.h	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -62,6 +62,6 @@
 /** Operations to manipulate page mappings. */
 struct page_operations {
-	void (* mapping_insert)(__address page, asid_t asid, __address frame, int flags, __address root);
-	pte_t *(* mapping_find)(__address page, asid_t asid, __address root);
+	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);
 };
 typedef struct page_operations page_operations_t;
@@ -70,6 +70,6 @@
 
 extern void page_init(void);
-extern void page_mapping_insert(__address page, asid_t asid, __address frame, int flags, __address root);
-extern pte_t *page_mapping_find(__address page, asid_t asid, __address root);
+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 map_structure(__address s, size_t size);
 
Index: generic/src/main/main.c
===================================================================
--- generic/src/main/main.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ generic/src/main/main.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -78,4 +78,7 @@
 size_t init_size = 0;
 
+/** Kernel address space. */
+as_t *AS_KERNEL = NULL;
+
 void main_bsp(void);
 void main_ap(void);
@@ -153,5 +156,8 @@
 	 */
 	exc_init();
-	
+
+	/*
+	 * Memory management subsystems initialization.
+	 */	
 	arch_pre_mm_init();
 	early_heap_init(config.heap_addr, config.heap_size + config.heap_delta);
@@ -186,5 +192,5 @@
 	 * Create kernel address space.
 	 */
-	as = as_create(GET_PTL0_ADDRESS(), AS_KERNEL);
+	as = as_create(GET_PTL0_ADDRESS(), FLAG_AS_KERNEL);
 	if (!as)
 		panic("can't create kernel address space\n");
Index: generic/src/mm/as.c
===================================================================
--- generic/src/mm/as.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ generic/src/mm/as.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -77,5 +77,5 @@
 		list_initialize(&as->as_area_head);
 
-		if (flags & AS_KERNEL)
+		if (flags & FLAG_AS_KERNEL)
 			as->asid = ASID_KERNEL;
 		else
@@ -187,5 +187,5 @@
 	 */
 	
-	page_mapping_insert(page, as->asid, frame, get_area_flags(area), (__address) as->ptl0);
+	page_mapping_insert(as, page, frame, get_area_flags(area), (__address) as->ptl0);
 	
 	spinlock_unlock(&area->lock);
@@ -267,5 +267,5 @@
 	 * inserted into page tables.
 	 */
-	page_mapping_insert(page, AS->asid, frame, get_area_flags(area), (__address) AS->ptl0);
+	page_mapping_insert(AS, page, frame, get_area_flags(area), (__address) AS->ptl0);
 	
 	spinlock_unlock(&area->lock);
Index: generic/src/mm/page.c
===================================================================
--- generic/src/mm/page.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ generic/src/mm/page.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -34,5 +34,5 @@
 #include <arch/mm/page.h>
 #include <arch/mm/asid.h>
-#include <mm/asid.h>
+#include <mm/as.h>
 #include <mm/frame.h>
 #include <arch/types.h>
@@ -49,5 +49,5 @@
 {
 	page_arch_init();
-	page_mapping_insert(0x0, 0, 0x0, PAGE_NOT_PRESENT, 0);
+	page_mapping_insert(AS_KERNEL, 0x0, 0x0, PAGE_NOT_PRESENT, 0);
 }
 
@@ -69,5 +69,5 @@
 
 	for (i = 0; i < cnt; i++)
-		page_mapping_insert(s + i*PAGE_SIZE, ASID_KERNEL, s + i*PAGE_SIZE, PAGE_NOT_CACHEABLE, 0);
+		page_mapping_insert(AS_KERNEL, s + i*PAGE_SIZE, s + i*PAGE_SIZE, PAGE_NOT_CACHEABLE, 0);
 
 }
@@ -78,16 +78,16 @@
  * using 'flags'. Allocate and setup any missing page tables.
  *
+ * @param as Address space to wich page belongs. Must be locked prior the call.
  * @param page Virtual address of the page to be mapped.
- * @param asid Address space to wich page belongs.
  * @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(__address page, asid_t asid, __address frame, int flags, __address root)
+void page_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
 {
 	ASSERT(page_operations);
 	ASSERT(page_operations->mapping_insert);
 	
-	page_operations->mapping_insert(page, asid, frame, flags, root);
+	page_operations->mapping_insert(as, page, frame, flags, root);
 }
 
@@ -96,15 +96,15 @@
  * Find mapping for virtual page.
  *
+ * @param as Address space to wich page belongs must be locked prior the call.
  * @param page Virtual page.
- * @param asid Address space to wich page belongs.
  * @param root PTL0 address if non-zero.
  *
  * @return NULL if there is no such mapping; requested mapping otherwise.
  */
-pte_t *page_mapping_find(__address page,  asid_t asid, __address root)
+pte_t *page_mapping_find(as_t *as, __address page, __address root)
 {
 	ASSERT(page_operations);
 	ASSERT(page_operations->mapping_find);
 
-	return page_operations->mapping_find(page, asid, root);
+	return page_operations->mapping_find(as, page, root);
 }
Index: test/mm/mapping1/test.c
===================================================================
--- test/mm/mapping1/test.c	(revision 6a3c9a77923487a0b7ff489449084ef0796d88ef)
+++ test/mm/mapping1/test.c	(revision fc1e4f6fda536ab9535536af72ca0eb08473cd3f)
@@ -30,5 +30,5 @@
 #include <mm/page.h>
 #include <mm/frame.h>
-#include <mm/asid.h>
+#include <mm/as.h>
 #include <arch/mm/page.h>
 #include <arch/types.h>
@@ -57,7 +57,7 @@
 	
 	printf("Mapping virtual address %P to physical address %P.\n", PAGE0, KA2PA(frame0));
-	page_mapping_insert(PAGE0, ASID_KERNEL, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE, 0);
+	page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE, 0);
 	printf("Mapping virtual address %P to physical address %P.\n", PAGE1, KA2PA(frame1));	
-	page_mapping_insert(PAGE1, ASID_KERNEL, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE, 0);
+	page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE, 0);
 	
 	printf("Value at virtual address %P is %L.\n", PAGE0, v0 = *((__u32 *) PAGE0));
