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
