Index: arch/amd64/_link.ld
===================================================================
--- arch/amd64/_link.ld	(revision 776c91a7127e18d9afb8dc8910bfaf527da701f3)
+++ arch/amd64/_link.ld	(revision c4b3e3e3d61c7d230f47366698e425a72b4051ec)
@@ -18,4 +18,5 @@
 		*(K_TEXT_START_2);
 		unmapped_ktext_end = .;
+
 		unmapped_kdata_start = .;
 		*(K_DATA_START);
@@ -23,5 +24,5 @@
 	}
 
-	.mapped (0xffffffff80000000+SIZEOF(.unmapped)+0x8000) : AT (0x8000+SIZEOF(.unmapped)) {
+	.mapped (0xffffffff80100000+0x8000+SIZEOF(.unmapped)) : AT (0x8000+SIZEOF(.unmapped)) {
 		ktext_start = .;
 		*(BOOT_DATA);
@@ -38,4 +39,8 @@
 		hardcoded_kdata_size = .;
 		QUAD(kdata_end - kdata_start + (unmapped_kdata_end - unmapped_kdata_start));
+		hardcoded_unmapped_ktext_size = .;
+		LONG(unmapped_ktext_end - unmapped_ktext_start);
+		hardcoded_unmapped_kdata_size = .;
+		LONG(unmapped_kdata_end - unmapped_kdata_start);
 		*(COMMON);		/* global variables */
 
@@ -51,5 +56,7 @@
 		kdata_end = .;
 	}
-	_map_address = 0xffffffff80000000;
+	_map_address = 0xffffffff80100000;
+	_hardcoded_kernel_size = (ktext_end - ktext_start) + (unmapped_ktext_end - unmapped_ktext_start) + (kdata_end - kdata_start) + (unmapped_kdata_end - unmapped_kdata_start);
+
 	e820table_boot = e820table - _map_address;
 	e820counter_boot = e820counter - _map_address;
Index: arch/amd64/include/boot/boot.h
===================================================================
--- arch/amd64/include/boot/boot.h	(revision 776c91a7127e18d9afb8dc8910bfaf527da701f3)
+++ arch/amd64/include/boot/boot.h	(revision c4b3e3e3d61c7d230f47366698e425a72b4051ec)
@@ -31,5 +31,5 @@
 
 #define BOOTSTRAP_OFFSET			0x8000
-#define BOOT_OFFSET				0x0
+#define BOOT_OFFSET				0x100000
 
 #define MULTIBOOT_HEADER_MAGIC		0x1BADB002
Index: arch/amd64/include/cpuid.h
===================================================================
--- arch/amd64/include/cpuid.h	(revision 776c91a7127e18d9afb8dc8910bfaf527da701f3)
+++ arch/amd64/include/cpuid.h	(revision c4b3e3e3d61c7d230f47366698e425a72b4051ec)
@@ -30,8 +30,10 @@
 #define __CPUID_H__
 
-#include <arch/types.h>
-
 #define AMD_CPUID_EXTENDED 0x80000001
 #define AMD_EXT_NOEXECUTE    20
+
+#ifndef __ASM__
+
+#include <arch/types.h>
 
 struct cpu_info {
@@ -49,3 +51,4 @@
 extern __u64 rdtsc(void);
 
+#endif /* __ASM__ */
 #endif
Index: arch/amd64/src/boot/boot.S
===================================================================
--- arch/amd64/src/boot/boot.S	(revision 776c91a7127e18d9afb8dc8910bfaf527da701f3)
+++ arch/amd64/src/boot/boot.S	(revision c4b3e3e3d61c7d230f47366698e425a72b4051ec)
@@ -33,6 +33,7 @@
 #include <arch/pm.h>
 #include <arch/cpu.h>
+#include <arch/cpuid.h>
+#include <arch/boot/boot.h>
 
-#define START_STACK     0x7c00	
 #define START_STACK_64  0xffffffff80007c00
 					
@@ -45,4 +46,7 @@
 # switch to protected mode.
 #
+
+#define START_STACK (BOOTSTRAP_OFFSET-0x400)
+	
 .section K_TEXT_START
 .code16
@@ -53,5 +57,5 @@
 	movw %ax,%ds
 	movw %ax,%ss            # initialize stack segment register
-	movl $(START_STACK),%esp	# initialize stack pointer
+	movl $(START_STACK), %esp	# initialize stack pointer
 	
 	call memmap_arch_init
@@ -61,5 +65,5 @@
 	cmp $0x80000000, %eax 	# any function > 80000000h?
 	jbe no_long_mode
-	movl $0x80000001, %eax	# Extended function code 80000001
+	movl $(AMD_CPUID_EXTENDED), %eax # Extended function code 80000001
 	cpuid
 	bt $29, %edx 		# Test if long mode is supported.
@@ -89,4 +93,10 @@
 	movw %ax, %ss
 
+	movb $0xd1, %al		# enable A20 using the keyboard controller
+	outb %al, $0x64
+	movb $0xdf, %al
+	outb %al, $0x60
+
+	
 	# Enable 64-bit page transaltion entries - CR4.PAE = 1.
 	# Paging is not enabled until after long mode is enabled
@@ -98,5 +108,5 @@
 	leal ptl_0, %eax
 	movl %eax, %cr3
-		
+	
 	# Enable long mode
 	movl $EFER_MSR_NUM, %ecx   # EFER MSR number
@@ -115,5 +125,12 @@
 .code64
 start64:
-	movq $(START_STACK_64), %rsp
+	movq $(PA2KA(START_STACK)), %rsp
+
+	# Copy kernel to higher physical memory
+	movq $BOOTSTRAP_OFFSET, %rsi
+	movq $BOOTSTRAP_OFFSET + BOOT_OFFSET, %rdi
+	movq $_hardcoded_kernel_size, %rcx
+	cld
+	rep movsb
 	
 	call main_bsp   # never returns
@@ -154,8 +171,8 @@
 bsp_bootstrap_gdtr:
 	.word gdtselector(GDT_ITEMS)
-	.long KA2PA(gdt)
+	.long KA2PA(gdt)-BOOT_OFFSET
 
 .global ap_bootstrap_gdtr
 ap_bootstrap_gdtr:
 	.word gdtselector(GDT_ITEMS)
-	.long KA2PA(gdt)
+	.long KA2PA(gdt)-BOOT_OFFSET
Index: arch/ia32/include/boot/boot.h
===================================================================
--- arch/ia32/include/boot/boot.h	(revision 776c91a7127e18d9afb8dc8910bfaf527da701f3)
+++ arch/ia32/include/boot/boot.h	(revision c4b3e3e3d61c7d230f47366698e425a72b4051ec)
@@ -31,5 +31,5 @@
 
 #define BOOTSTRAP_OFFSET			0x8000
-#define BOOT_OFFSET					0x100000
+#define BOOT_OFFSET				0x100000
 
 #define MULTIBOOT_HEADER_MAGIC		0x1BADB002
