Index: arch/amd64/include/mm/frame.h
===================================================================
--- arch/amd64/include/mm/frame.h	(revision eef75f671c5a16e1de01ece7fb216c921e210d41)
+++ arch/amd64/include/mm/frame.h	(revision 95498e5ceffe58b6aeaf97f1d9ab530773fb6ada)
@@ -30,9 +30,14 @@
 #define __amd64_FRAME_H__
 
+#ifndef __ASM__
+#include <arch/types.h>
+#endif /* __ASM__ */
+
 #define FRAME_SIZE		4096
 
 #ifndef __ASM__
+extern __address last_frame;
 extern void frame_arch_init(void);
-#endif
+#endif /* __ASM__ */
 
 #endif
Index: arch/amd64/src/mm/page.c
===================================================================
--- arch/amd64/src/mm/page.c	(revision eef75f671c5a16e1de01ece7fb216c921e210d41)
+++ arch/amd64/src/mm/page.c	(revision 95498e5ceffe58b6aeaf97f1d9ab530773fb6ada)
@@ -27,13 +27,12 @@
  */
 
+#include <arch/mm/page.h>
+#include <arch/mm/frame.h>
 #include <mm/page.h>
 #include <mm/frame.h>
-#include <arch/mm/page.h>
 #include <arch/interrupt.h>
 #include <arch/asm.h>
 #include <config.h>
-
 #include <memstr.h>
-
 
 __address bootstrap_dba; 
@@ -42,5 +41,5 @@
 {
 	__address dba;
-	count_t i;
+	__address cur;
 
 	if (config.cpu_active == 1) {
@@ -53,6 +52,6 @@
 		 * PA2KA(identity) mapping for all frames.
 		 */
-		for (i = 0; i < config.memory_size/FRAME_SIZE; i++) {
-			page_mapping_insert(PA2KA(i * PAGE_SIZE), i * PAGE_SIZE, PAGE_CACHEABLE | PAGE_EXEC, KA2PA(dba));
+		for (cur = 0; cur < last_frame; cur += FRAME_SIZE) {
+			page_mapping_insert(PA2KA(cur), cur, PAGE_CACHEABLE | PAGE_EXEC, KA2PA(dba));
 		}
 
Index: arch/ia32/include/boot/memmap.h
===================================================================
--- arch/ia32/include/boot/memmap.h	(revision eef75f671c5a16e1de01ece7fb216c921e210d41)
+++ arch/ia32/include/boot/memmap.h	(revision 95498e5ceffe58b6aeaf97f1d9ab530773fb6ada)
@@ -56,5 +56,5 @@
 	__u64 size;
 	__u32 type;
-	} __attribute__ ((packed));
+} __attribute__ ((packed));
 
 extern struct e820memmap_ e820table[MEMMAP_E820_MAX_RECORDS];
@@ -62,5 +62,5 @@
 extern __u8 e820counter; 
 
-extern __u32 e801memorysize; // size of memory in KB
+extern __u32 e801memorysize; /**< Size of available memory in KB. */
 
 #endif
Index: arch/ia32/include/mm/frame.h
===================================================================
--- arch/ia32/include/mm/frame.h	(revision eef75f671c5a16e1de01ece7fb216c921e210d41)
+++ arch/ia32/include/mm/frame.h	(revision 95498e5ceffe58b6aeaf97f1d9ab530773fb6ada)
@@ -35,4 +35,5 @@
 
 extern __address bootstrap_dba;
+extern __address last_frame;
 
 extern void frame_arch_init(void);
Index: arch/ia32/src/mm/frame.c
===================================================================
--- arch/ia32/src/mm/frame.c	(revision eef75f671c5a16e1de01ece7fb216c921e210d41)
+++ arch/ia32/src/mm/frame.c	(revision 95498e5ceffe58b6aeaf97f1d9ab530773fb6ada)
@@ -35,7 +35,10 @@
 #include <panic.h>
 #include <debug.h>
+#include <align.h>
 
 size_t hardcoded_unmapped_ktext_size = 0;
 size_t hardcoded_unmapped_kdata_size = 0;
+
+__address last_frame = 0;
 
 void frame_arch_init(void)
@@ -54,6 +57,8 @@
 		for (i = 0; i < e820counter; i++) {
 			if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) {
-				zone_create_in_region(e820table[i].base_address,  e820table[i].size & ~(FRAME_SIZE-1));
-			}
+				zone_create_in_region(e820table[i].base_address, e820table[i].size & ~(FRAME_SIZE-1));
+				if (last_frame < ALIGN(e820table[i].base_address + e820table[i].size, FRAME_SIZE))
+					last_frame = ALIGN(e820table[i].base_address + e820table[i].size, FRAME_SIZE);
+			}			
 		}
 	}
Index: arch/ia32/src/mm/page.c
===================================================================
--- arch/ia32/src/mm/page.c	(revision eef75f671c5a16e1de01ece7fb216c921e210d41)
+++ arch/ia32/src/mm/page.c	(revision 95498e5ceffe58b6aeaf97f1d9ab530773fb6ada)
@@ -27,10 +27,11 @@
  */
 
+#include <arch/mm/page.h>
+#include <arch/mm/frame.h>
+#include <mm/frame.h>
+#include <mm/page.h>
 #include <arch/types.h>
 #include <config.h>
 #include <func.h>
-#include <mm/frame.h>
-#include <mm/page.h>
-#include <arch/mm/page.h>
 #include <arch/interrupt.h>
 #include <arch/asm.h>
@@ -45,5 +46,5 @@
 {
 	__address dba;
-	__u32 i;
+	__address cur;
 
 	if (config.cpu_active == 1) {
@@ -54,8 +55,8 @@
 		
 		/*
-		 * PA2KA(identity) mapping for all frames.
+		 * PA2KA(identity) mapping for all frames until last_frame.
 		 */
-		for (i = 0; i < config.memory_size/PAGE_SIZE; i++)
-			page_mapping_insert(PA2KA(i * PAGE_SIZE), i * PAGE_SIZE, PAGE_CACHEABLE, KA2PA(dba));
+		for (cur = 0; cur < last_frame; cur += FRAME_SIZE)
+			page_mapping_insert(PA2KA(cur), cur, PAGE_CACHEABLE, KA2PA(dba));
 
 		trap_register(14, page_fault);
