Index: arch/amd64/include/mm/as.h
===================================================================
--- arch/amd64/include/mm/as.h	(revision ff14c520ac9ef1cfa24af4cbbfd3235d2bda51c5)
+++ arch/amd64/include/mm/as.h	(revision 93165be1285f3a50e69871962061a2e2fcfb9ae6)
@@ -32,5 +32,5 @@
 #include <arch/types.h>
 
-#define KERNEL_ADDRESS_SPACE_START_ARCH		(__address) 0xffffffff80000000
+#define KERNEL_ADDRESS_SPACE_START_ARCH		(__address) 0xffff800000000000
 #define KERNEL_ADDRESS_SPACE_END_ARCH		(__address) 0xffffffffffffffff
 #define USER_ADDRESS_SPACE_START_ARCH		(__address) 0x0000000000000000
Index: arch/amd64/include/mm/page.h
===================================================================
--- arch/amd64/include/mm/page.h	(revision ff14c520ac9ef1cfa24af4cbbfd3235d2bda51c5)
+++ arch/amd64/include/mm/page.h	(revision 93165be1285f3a50e69871962061a2e2fcfb9ae6)
@@ -27,4 +27,16 @@
  */
 
+/** Paging on AMD64
+ *
+ * The space is divided in positive numbers - userspace and
+ * negative numbers - kernel space. The 'negative' space starting
+ * with 0xffff800000000000 and ending with 0xffffffff80000000
+ * (-2GB) is identically mapped physical memory. The area
+ * (0xffffffff80000000 ... 0xffffffffffffffff is again identically
+ * mapped first 2GB.
+ *
+ * ATTENTION - PA2KA(KA2PA(x)) != x if 'x' is in kernel
+ */
+
 #ifndef __amd64_PAGE_H__
 #define __amd64_PAGE_H__
@@ -43,9 +55,30 @@
 
 #ifndef __ASM__
-# define KA2PA(x)      (((__address) (x)) - 0xffffffff80000000)
-# define PA2KA(x)      (((__address) (x)) + 0xffffffff80000000)
+static inline __address ka2pa(__address x)
+{
+	if (x > 0xffffffff80000000)
+		return x - 0xffffffff80000000;
+	else 
+		return x - 0xffff800000000000;
+}
+/* Linker symbol */
+extern int ktext_start;
+extern int kdata_end;
+static inline __address pa2ka(__address x)
+{
+	if (x >= ka2pa((__address)(&kdata_end)) || \
+	    x <= ka2pa((__address)&ktext_start))
+		return x + 0xffff800000000000;
+	else 
+		return x + 0xffffffff80000000;
+}
+# define KA2PA(x)      ka2pa((__address)x)
+# define PA2KA(x)      pa2ka((__address)x)
+# define PA2KA_IDENT(x)      (((__address) (x)) + 0xffff800000000000)
+# define PA2KA_CODE(x)      (((__address) (x)) + 0xffffffff80000000)
 #else
 # define KA2PA(x)      ((x) - 0xffffffff80000000)
 # define PA2KA(x)      ((x) + 0xffffffff80000000)
+# define PA2KA_DATA(x)      ((x) + 0xffff800000000000)
 #endif
 
Index: arch/amd64/src/boot/boot.S
===================================================================
--- arch/amd64/src/boot/boot.S	(revision ff14c520ac9ef1cfa24af4cbbfd3235d2bda51c5)
+++ arch/amd64/src/boot/boot.S	(revision 93165be1285f3a50e69871962061a2e2fcfb9ae6)
@@ -175,5 +175,6 @@
 			xorq %rdx, %rdx
 			movl 0(%esi), %edx					# mods->mod_start
-			addq $0xffffffff80000000, %rdx
+			movq $0xffff800000000000, %r10
+			addq %r10, %rdx
 			movq %rdx, 8(%rdi)
 			
@@ -304,5 +305,7 @@
 ptl_0:
 	.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
-	.fill 510,8,0
+	.fill 255,8,0
+	.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
+	.fill 254,8,0
 	.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
 
Index: arch/amd64/src/mm/page.c
===================================================================
--- arch/amd64/src/mm/page.c	(revision ff14c520ac9ef1cfa24af4cbbfd3235d2bda51c5)
+++ arch/amd64/src/mm/page.c	(revision 93165be1285f3a50e69871962061a2e2fcfb9ae6)
@@ -40,4 +40,5 @@
 #include <print.h>
 #include <panic.h>
+#include <align.h>
 
 /* Definitions for identity page mapper */
@@ -71,9 +72,9 @@
         SET_FRAME_FLAGS_ARCH(ptl3, PTL3_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
     }
-
 void page_arch_init(void)
 {
 	__address cur;
-	int flags;
+	int i;
+	int identity_flags = PAGE_CACHEABLE | PAGE_EXEC | PAGE_GLOBAL;
 
 	if (config.cpu_active == 1) {
@@ -84,9 +85,20 @@
 		 */
 		for (cur = 0; cur < last_frame; cur += FRAME_SIZE) {
-			flags = PAGE_CACHEABLE | PAGE_EXEC;
-			if ((PA2KA(cur) >= config.base) && (PA2KA(cur) < config.base + config.kernel_size))
-				flags |= PAGE_GLOBAL;
-			page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
+			/* Standard identity mapping */
+			page_mapping_insert(AS_KERNEL, PA2KA_IDENT(cur), cur, identity_flags);
 		}
+		/* Upper kernel mapping
+		 * - from zero to top of kernel (include bottom addresses
+		 *   because some are needed for init )
+		 */
+		for (cur = PA2KA_CODE(0); cur < config.base+config.kernel_size; cur += FRAME_SIZE) {
+			page_mapping_insert(AS_KERNEL, cur, KA2PA(cur), identity_flags);
+		}
+		for (i=0; i < init.cnt; i++) {
+			for (cur=init.tasks[i].addr;cur < init.tasks[i].size; cur += FRAME_SIZE) {
+				page_mapping_insert(AS_KERNEL, PA2KA_CODE(KA2PA(cur)), KA2PA(cur), identity_flags);
+			}
+		}
+
 		exc_register(14, "page_fault", (iroutine)page_fault);
 		write_cr3((__address) AS_KERNEL->page_table);
Index: generic/include/macros.h
===================================================================
--- generic/include/macros.h	(revision ff14c520ac9ef1cfa24af4cbbfd3235d2bda51c5)
+++ generic/include/macros.h	(revision 93165be1285f3a50e69871962061a2e2fcfb9ae6)
@@ -40,3 +40,14 @@
 #define max(a,b)	((a)>(b)?(a):(b))
 
+/* Return true if the interlvals overlap */
+static inline int overlaps(__address s1,size_t sz1, __address s2, size_t sz2)
+{
+	__address e1 = s1+sz1;
+	__address e2 = s2+sz2;
+
+	return s1 < e2 && s2 < e1;
+}
+/* Compute overlapping of physical addresses */
+#define PA_overlaps(x,szx,y,szy)  overlaps(KA2PA(x),szx,KA2PA(y), szy)
+
 #endif
Index: generic/include/mm/frame.h
===================================================================
--- generic/include/mm/frame.h	(revision ff14c520ac9ef1cfa24af4cbbfd3235d2bda51c5)
+++ generic/include/mm/frame.h	(revision 93165be1285f3a50e69871962061a2e2fcfb9ae6)
@@ -62,13 +62,4 @@
 #define FRAME_ERROR		2	/* frame_alloc return status */
 
-/* Return true if the interlvals overlap */
-static inline int overlaps(__address s1,__address sz1, __address s2, __address sz2)
-{
-	__address e1 = s1+sz1;
-	__address e2 = s2+sz2;
-
-	return s1 < e2 && s2 < e1;
-}
-
 static inline __address PFN2ADDR(pfn_t frame)
 {
Index: generic/src/ipc/sysipc.c
===================================================================
--- generic/src/ipc/sysipc.c	(revision ff14c520ac9ef1cfa24af4cbbfd3235d2bda51c5)
+++ generic/src/ipc/sysipc.c	(revision 93165be1285f3a50e69871962061a2e2fcfb9ae6)
@@ -165,5 +165,4 @@
 		/* If the users accepted call, connect */
 		if (!IPC_GET_RETVAL(answer->data)) {
-			printf("Connecting Phone %P\n",IPC_GET_ARG3(*olddata));
 			ipc_phone_connect((phone_t *)IPC_GET_ARG3(*olddata),
 					  &TASK->answerbox);
Index: generic/src/main/main.c
===================================================================
--- generic/src/main/main.c	(revision ff14c520ac9ef1cfa24af4cbbfd3235d2bda51c5)
+++ generic/src/main/main.c	(revision 93165be1285f3a50e69871962061a2e2fcfb9ae6)
@@ -56,4 +56,5 @@
 #include <typedefs.h>
 #include <ipc/ipc.h>
+#include <macros.h>
 
 #ifdef CONFIG_SMP
@@ -117,5 +118,5 @@
 	bool overlap = false;
 	for (i = 0; i < init.cnt; i++)
-		if (overlaps(stackaddr, CONFIG_STACK_SIZE, init.tasks[i].addr, init.tasks[i].size)) {
+		if (PA_overlaps(stackaddr, CONFIG_STACK_SIZE, init.tasks[i].addr, init.tasks[i].size)) {
 			stackaddr = ALIGN_UP(init.tasks[i].addr + init.tasks[i].size, CONFIG_STACK_SIZE);
 			init.tasks[i].size = ALIGN_UP(init.tasks[i].size, CONFIG_STACK_SIZE) + CONFIG_STACK_SIZE;
Index: generic/src/mm/frame.c
===================================================================
--- generic/src/mm/frame.c	(revision ff14c520ac9ef1cfa24af4cbbfd3235d2bda51c5)
+++ generic/src/mm/frame.c	(revision 93165be1285f3a50e69871962061a2e2fcfb9ae6)
@@ -52,4 +52,5 @@
 #include <mm/slab.h>
 #include <bitops.h>
+#include <macros.h>
 
 typedef struct {
