Index: kernel/arch/ia32/src/boot/multiboot.S
===================================================================
--- kernel/arch/ia32/src/boot/multiboot.S	(revision 4928165de7cf0ac048c2faf57cbe0209de03919c)
+++ kernel/arch/ia32/src/boot/multiboot.S	(revision 0637ddb37d7e3d5dd0479648840f57e5a3cce14a)
@@ -221,16 +221,15 @@
 		
 		/* Align address down to 4k */
-		andl $(~4095), %esi
+		andl $(~(PAGE_SIZE - 1)), %esi
 		
 	use_kernel_end:
 		
 		/* Align address to 4k */
-		addl $4095, %esi
-		andl $(~4095), %esi
+		addl $(PAGE_SIZE - 1), %esi
+		andl $(~(PAGE_SIZE - 1)), %esi
 		
 		/* Allocate space for page tables */
 		movl %esi, pt_loc
-		movl $ballocs, %edi
-		andl $0x7fffffff, %edi
+		movl $KA2PA(ballocs), %edi
 		
 		movl %esi, (%edi)
@@ -246,5 +245,5 @@
 			orl %ebx, %eax
 			movl %eax, (%esi, %ecx, 4)
-			addl $(4 * 1024), %ebx
+			addl $PAGE_SIZE, %ebx
 			
 			incl %ecx
@@ -268,5 +267,5 @@
 			/* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
 			movl %eax, (%edi, %ecx, 4)
-			addl $(4 * 1024), %ebx
+			addl $PAGE_SIZE, %ebx
 			
 			incl %ecx
@@ -286,18 +285,15 @@
 /** Calculate unmapped address of the end of the kernel. */
 calc_kernel_end:
-	movl $hardcoded_load_address, %edi
-	andl $0x7fffffff, %edi
+	movl $KA2PA(hardcoded_load_address), %edi
 	movl (%edi), %esi
-	andl $0x7fffffff, %esi
-	
-	movl $hardcoded_ktext_size, %edi
-	andl $0x7fffffff, %edi
+	leal KA2PA(0)(%esi), %esi
+	
+	movl $KA2PA(hardcoded_ktext_size), %edi
 	addl (%edi), %esi
-	andl $0x7fffffff, %esi
-	
-	movl $hardcoded_kdata_size, %edi
-	andl $0x7fffffff, %edi
+	leal KA2PA(0)(%esi), %esi
+	
+	movl $KA2PA(hardcoded_kdata_size), %edi
 	addl (%edi), %esi
-	andl $0x7fffffff, %esi
+	leal KA2PA(0)(%esi), %esi
 	movl %esi, kernel_end
 	
Index: kernel/arch/ia32/src/smp/ap.S
===================================================================
--- kernel/arch/ia32/src/smp/ap.S	(revision 4928165de7cf0ac048c2faf57cbe0209de03919c)
+++ kernel/arch/ia32/src/smp/ap.S	(revision 0637ddb37d7e3d5dd0479648840f57e5a3cce14a)
@@ -75,7 +75,7 @@
 	movw %ax, %es
 	movw %ax, %ss
-	movl $KA2PA(ctx), %eax	/* KA2PA((uintptr_t) &ctx) */
+	movl $KA2PA(ctx), %eax		/* KA2PA((uintptr_t) &ctx) */
 	movl CONTEXT_OFFSET_SP(%eax), %esp
-	subl $PA2KA(0), %esp	/* KA2PA(ctx.sp) */
+	leal KA2PA(0)(%esp), %esp	/* KA2PA(ctx.sp) */
 
 	/*
@@ -85,5 +85,5 @@
 	call map_kernel_pse
 	
-	addl $PA2KA(0), %esp	/* PA2KA(ctx.sp) */
+	addl $PA2KA(0), %esp		/* PA2KA(ctx.sp) */
 	
 	/* create the first stack frame */
