Index: kernel/generic/include/mm/as.h
===================================================================
--- kernel/generic/include/mm/as.h	(revision e71a61d2f187f60c13024e0c300fa8b4703b2c70)
+++ kernel/generic/include/mm/as.h	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
@@ -48,5 +48,4 @@
 #include <arch/mm/asid.h>
 #include <arch/types.h>
-#include <typedefs.h>
 #include <synch/spinlock.h>
 #include <synch/mutex.h>
@@ -67,52 +66,18 @@
 #define FLAG_AS_KERNEL	    (1 << 0)	/**< Kernel address space. */
 
-/** Address space structure.
- *
- * as_t contains the list of as_areas of userspace accessible
- * pages for one or more tasks. Ranges of kernel memory pages are not
- * supposed to figure in the list as they are shared by all tasks and
- * set up during system initialization.
- */
-struct as {
-	/** Protected by asidlock. */
-	link_t inactive_as_with_asid_link;
-
-	mutex_t lock;
-
-	/** Number of references (i.e tasks that reference this as). */
-	count_t refcount;
-
-	/** Number of processors on wich is this address space active. */
-	count_t cpu_refcount;
-
-	/** B+tree of address space areas. */
-	btree_t as_area_btree;
-
-	/** 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;
-	
-	/** Architecture specific content. */
-	as_arch_t arch;
-};
-
-struct as_operations {
+/** Address space area attributes. */
+#define AS_AREA_ATTR_NONE	0
+#define AS_AREA_ATTR_PARTIAL	1	/**< Not fully initialized area. */
+
+#define AS_PF_FAULT		0	/**< The page fault was not resolved by as_page_fault(). */
+#define AS_PF_OK		1	/**< The page fault was resolved by as_page_fault(). */
+#define AS_PF_DEFER		2	/**< The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
+
+typedef struct {
 	pte_t *(* page_table_create)(int flags);
 	void (* page_table_destroy)(pte_t *page_table);
 	void (* page_table_lock)(as_t *as, bool lock);
 	void (* page_table_unlock)(as_t *as, bool unlock);
-};
-typedef struct as_operations as_operations_t;
-
-/** Address space area attributes. */
-#define AS_AREA_ATTR_NONE	0
-#define AS_AREA_ATTR_PARTIAL	1	/**< Not fully initialized area. */
-
-#define AS_PF_FAULT		0	/**< The page fault was not resolved by as_page_fault(). */
-#define AS_PF_OK		1	/**< The page fault was resolved by as_page_fault(). */
-#define AS_PF_DEFER		2	/**< The page fault was caused by memcpy_from_uspace()
-					     or memcpy_to_uspace(). */
+} as_operations_t;
 
 /** This structure contains information associated with the shared address space area. */
@@ -123,13 +88,15 @@
 } share_info_t;
 
-/** Address space area backend structure. */
-typedef struct {
-	int (* page_fault)(as_area_t *area, uintptr_t addr, pf_access_t access);
-	void (* frame_free)(as_area_t *area, uintptr_t page, uintptr_t frame);
-	void (* share)(as_area_t *area);
-} mem_backend_t;
+/** Page fault access type. */
+typedef enum {
+	PF_ACCESS_READ,
+	PF_ACCESS_WRITE,
+	PF_ACCESS_EXEC
+} pf_access_t;
+
+struct mem_backend;
 
 /** Backend data stored in address space area. */
-typedef union {
+typedef union mem_backend_data {
 	struct {	/**< elf_backend members */
 		elf_header_t *elf;
@@ -147,5 +114,5 @@
  * In the future, it should not be difficult to support shared areas.
  */
-struct as_area {
+typedef struct {
 	mutex_t lock;
 	as_t *as;		/**< Containing address space. */
@@ -157,9 +124,16 @@
 	share_info_t *sh_info;	/**< If the address space area has been shared, this pointer will
 			     	     reference the share info structure. */
-	mem_backend_t *backend;	/**< Memory backend backing this address space area. */
+	struct mem_backend *backend;	/**< Memory backend backing this address space area. */
 
 	/** Data to be used by the backend. */
 	mem_backend_data_t backend_data;
-};
+} as_area_t;
+
+/** Address space area backend structure. */
+typedef struct mem_backend {
+	int (* page_fault)(as_area_t *area, uintptr_t addr, pf_access_t access);
+	void (* frame_free)(as_area_t *area, uintptr_t page, uintptr_t frame);
+	void (* share)(as_area_t *area);
+} mem_backend_t;
 
 extern as_t *AS_KERNEL;
@@ -207,8 +181,10 @@
 #endif /* !def as_deinstall_arch */
 
-/* Backend declarations. */
+/* Backend declarations and functions. */
 extern mem_backend_t anon_backend;
 extern mem_backend_t elf_backend;
 extern mem_backend_t phys_backend;
+
+extern int elf_load(elf_header_t *header, as_t *as);
 
 /* Address space area related syscalls. */
Index: kernel/generic/include/mm/asid.h
===================================================================
--- kernel/generic/include/mm/asid.h	(revision e71a61d2f187f60c13024e0c300fa8b4703b2c70)
+++ kernel/generic/include/mm/asid.h	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
@@ -45,5 +45,6 @@
 #include <arch/mm/asid.h>
 #include <synch/spinlock.h>
-#include <typedefs.h>
+#include <adt/list.h>
+#include <mm/as.h>
 
 #endif
Index: kernel/generic/include/mm/buddy.h
===================================================================
--- kernel/generic/include/mm/buddy.h	(revision e71a61d2f187f60c13024e0c300fa8b4703b2c70)
+++ kernel/generic/include/mm/buddy.h	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
@@ -37,5 +37,5 @@
 
 #include <arch/types.h>
-#include <typedefs.h>
+#include <adt/list.h>
 
 #define BUDDY_SYSTEM_INNER_BLOCK	0xff
Index: kernel/generic/include/mm/frame.h
===================================================================
--- kernel/generic/include/mm/frame.h	(revision e71a61d2f187f60c13024e0c300fa8b4703b2c70)
+++ kernel/generic/include/mm/frame.h	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
@@ -38,5 +38,4 @@
 
 #include <arch/types.h>
-#include <typedefs.h>
 #include <adt/list.h>
 #include <synch/spinlock.h>
Index: kernel/generic/include/mm/mm.h
===================================================================
--- kernel/generic/include/mm/mm.h	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
+++ kernel/generic/include/mm/mm.h	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2007 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup genericmm
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_MM_H_
+#define KERN_MM_H_
+
+#define PAGE_CACHEABLE_SHIFT		0
+#define PAGE_NOT_CACHEABLE_SHIFT	PAGE_CACHEABLE_SHIFT
+#define PAGE_PRESENT_SHIFT		1
+#define PAGE_NOT_PRESENT_SHIFT		PAGE_PRESENT_SHIFT
+#define PAGE_USER_SHIFT			2
+#define PAGE_KERNEL_SHIFT		PAGE_USER_SHIFT
+#define PAGE_READ_SHIFT			3
+#define PAGE_WRITE_SHIFT		4
+#define PAGE_EXEC_SHIFT			5
+#define PAGE_GLOBAL_SHIFT		6
+
+#define PAGE_NOT_CACHEABLE	(0 << PAGE_CACHEABLE_SHIFT)
+#define PAGE_CACHEABLE		(1 << PAGE_CACHEABLE_SHIFT)
+
+#define PAGE_PRESENT		(0 << PAGE_PRESENT_SHIFT)
+#define PAGE_NOT_PRESENT	(1 << PAGE_PRESENT_SHIFT)
+
+#define PAGE_USER		(1 << PAGE_USER_SHIFT)
+#define PAGE_KERNEL		(0 << PAGE_USER_SHIFT)
+
+#define PAGE_READ		(1 << PAGE_READ_SHIFT)
+#define PAGE_WRITE		(1 << PAGE_WRITE_SHIFT)
+#define PAGE_EXEC		(1 << PAGE_EXEC_SHIFT)
+
+#define PAGE_GLOBAL		(1 << PAGE_GLOBAL_SHIFT)
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/include/mm/page.h
===================================================================
--- kernel/generic/include/mm/page.h	(revision e71a61d2f187f60c13024e0c300fa8b4703b2c70)
+++ kernel/generic/include/mm/page.h	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
@@ -36,35 +36,7 @@
 #define KERN_PAGE_H_
 
-#include <arch/mm/asid.h>
 #include <arch/types.h>
-#include <typedefs.h>
+#include <mm/as.h>
 #include <memstr.h>
-
-#define PAGE_CACHEABLE_SHIFT		0
-#define PAGE_NOT_CACHEABLE_SHIFT	PAGE_CACHEABLE_SHIFT
-#define PAGE_PRESENT_SHIFT		1
-#define PAGE_NOT_PRESENT_SHIFT		PAGE_PRESENT_SHIFT
-#define PAGE_USER_SHIFT			2
-#define PAGE_KERNEL_SHIFT		PAGE_USER_SHIFT
-#define PAGE_READ_SHIFT			3
-#define PAGE_WRITE_SHIFT		4
-#define PAGE_EXEC_SHIFT			5
-#define PAGE_GLOBAL_SHIFT		6
-
-#define PAGE_NOT_CACHEABLE	(0<<PAGE_CACHEABLE_SHIFT)
-#define PAGE_CACHEABLE		(1<<PAGE_CACHEABLE_SHIFT)
-
-#define PAGE_PRESENT		(0<<PAGE_PRESENT_SHIFT)
-#define PAGE_NOT_PRESENT	(1<<PAGE_PRESENT_SHIFT)
-
-#define PAGE_USER		(1<<PAGE_USER_SHIFT)
-#define PAGE_KERNEL		(0<<PAGE_USER_SHIFT)
-
-#define PAGE_READ		(1<<PAGE_READ_SHIFT)
-#define PAGE_WRITE		(1<<PAGE_WRITE_SHIFT)
-#define PAGE_EXEC		(1<<PAGE_EXEC_SHIFT)
-
-#define PAGE_GLOBAL		(1<<PAGE_GLOBAL_SHIFT)
-
 
 /**
@@ -73,20 +45,11 @@
 #define PAGE_COLOR(va)	(((va) >> PAGE_WIDTH) & ((1 << PAGE_COLOR_BITS) - 1))
 
-/** Page fault access type. */
-enum pf_access {
-	PF_ACCESS_READ,
-	PF_ACCESS_WRITE,
-	PF_ACCESS_EXEC
-};
-typedef enum pf_access pf_access_t;
-
 /** Operations to manipulate page mappings. */
-struct page_mapping_operations {
-	void (* mapping_insert)(as_t *as, uintptr_t page, uintptr_t frame, int
-		flags);
+typedef struct {
+	void (* mapping_insert)(as_t *as, uintptr_t page, uintptr_t frame,
+		int flags);
 	void (* mapping_remove)(as_t *as, uintptr_t page);
 	pte_t *(* mapping_find)(as_t *as, uintptr_t page);
-};
-typedef struct page_mapping_operations page_mapping_operations_t;
+} page_mapping_operations_t;
 
 extern page_mapping_operations_t *page_mapping_operations;
@@ -95,6 +58,6 @@
 extern void page_table_lock(as_t *as, bool lock);
 extern void page_table_unlock(as_t *as, bool unlock);
-extern void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int
-	flags);
+extern void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame,
+	int flags);
 extern void page_mapping_remove(as_t *as, uintptr_t page);
 extern pte_t *page_mapping_find(as_t *as, uintptr_t page);
Index: kernel/generic/include/mm/tlb.h
===================================================================
--- kernel/generic/include/mm/tlb.h	(revision e71a61d2f187f60c13024e0c300fa8b4703b2c70)
+++ kernel/generic/include/mm/tlb.h	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
@@ -38,5 +38,4 @@
 #include <arch/mm/asid.h>
 #include <arch/types.h>
-#include <typedefs.h>
 
 /**
@@ -47,20 +46,18 @@
 
 /** Type of TLB shootdown message. */
-enum tlb_invalidate_type {
+typedef enum {
 	TLB_INVL_INVALID = 0,		/**< Invalid type. */
 	TLB_INVL_ALL,			/**< Invalidate all entries in TLB. */
 	TLB_INVL_ASID,			/**< Invalidate all entries belonging to one address space. */
 	TLB_INVL_PAGES			/**< Invalidate specified page range belonging to one address space. */
-};
-typedef enum tlb_invalidate_type tlb_invalidate_type_t;
+} tlb_invalidate_type_t;
 
 /** TLB shootdown message. */
-struct tlb_shootdown_msg {
+typedef struct {
 	tlb_invalidate_type_t type;	/**< Message type. */
 	asid_t asid;			/**< Address space identifier. */
 	uintptr_t page;			/**< Page address. */
 	count_t count;			/**< Number of pages to invalidate. */
-};
-typedef struct tlb_shootdown_msg tlb_shootdown_msg_t;
+} tlb_shootdown_msg_t;
 
 extern void tlb_init(void);
