Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/Makefile	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -192,4 +192,5 @@
 	generic/src/synch/futex.c \
 	generic/src/smp/ipi.c \
+	generic/src/smp/smp.c \
 	generic/src/ipc/ipc.c \
 	generic/src/ipc/sysipc.c \
Index: kernel/arch/amd64/src/amd64.c
===================================================================
--- kernel/arch/amd64/src/amd64.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/arch/amd64/src/amd64.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -45,4 +45,8 @@
 #include <arch/drivers/i8254.h>
 #include <arch/drivers/i8259.h>
+
+#ifdef CONFIG_SMP
+#include <arch/smp/apic.h>
+#endif
 
 #include <arch/bios/bios.h>
@@ -157,4 +161,14 @@
 }
 
+void arch_post_cpu_init()
+{
+#ifdef CONFIG_SMP
+	if (config.cpu_active > 1) {
+		l_apic_init();
+		l_apic_debug();
+	}
+#endif
+}
+
 void arch_pre_smp_init(void)
 {
Index: kernel/arch/ia32/include/smp/mps.h
===================================================================
--- kernel/arch/ia32/include/smp/mps.h	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/arch/ia32/include/smp/mps.h	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -121,11 +121,7 @@
 } __attribute__ ((packed));
 
-
-extern waitq_t ap_completion_wq;
-
 extern struct smp_config_operations mps_config_operations;
 
 extern void mps_init(void);
-extern void kmp(void *arg);
 
 #endif
Index: kernel/arch/ia32/src/ia32.c
===================================================================
--- kernel/arch/ia32/src/ia32.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/arch/ia32/src/ia32.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -63,4 +63,8 @@
 #include <console/console.h>
 
+#ifdef CONFIG_SMP
+#include <arch/smp/apic.h>
+#endif
+
 void arch_pre_mm_init(void)
 {
@@ -98,4 +102,14 @@
 		zone_merge_all();
 	}
+}
+
+void arch_post_cpu_init()
+{
+#ifdef CONFIG_SMP
+        if (config.cpu_active > 1) {
+		l_apic_init();
+		l_apic_debug();
+	}
+#endif
 }
 
Index: kernel/arch/ia32/src/smp/mps.c
===================================================================
--- kernel/arch/ia32/src/smp/mps.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/arch/ia32/src/smp/mps.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -85,6 +85,4 @@
 int l_intr_entry_cnt = 0;
 
-waitq_t ap_completion_wq;
-
 /*
  * Implementation of IA-32 SMP configuration interface.
Index: kernel/arch/ia32/src/smp/smp.c
===================================================================
--- kernel/arch/ia32/src/smp/smp.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/arch/ia32/src/smp/smp.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -105,6 +105,4 @@
 	ASSERT(ops != NULL);
 
-	waitq_initialize(&ap_completion_wq);
-
 	/*
 	 * We need to access data in frame 0.
Index: kernel/arch/ia64/src/ia64.c
===================================================================
--- kernel/arch/ia64/src/ia64.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/arch/ia64/src/ia64.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -90,4 +90,8 @@
 }
 
+void arch_post_cpu_init(void)
+{
+}
+
 void arch_pre_smp_init(void)
 {
Index: kernel/arch/mips32/src/mips32.c
===================================================================
--- kernel/arch/mips32/src/mips32.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/arch/mips32/src/mips32.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -132,4 +132,8 @@
 }
 
+void arch_post_cpu_init(void)
+{
+}
+
 void arch_pre_smp_init(void)
 {
Index: kernel/arch/ppc32/src/ppc32.c
===================================================================
--- kernel/arch/ppc32/src/ppc32.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/arch/ppc32/src/ppc32.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -83,4 +83,8 @@
 }
 
+void arch_post_cpu_init(void)
+{
+}
+
 void arch_pre_smp_init(void)
 {
Index: kernel/arch/ppc64/src/ppc64.c
===================================================================
--- kernel/arch/ppc64/src/ppc64.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/arch/ppc64/src/ppc64.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -76,4 +76,8 @@
 }
 
+void arch_post_cpu_init(void)
+{
+}
+
 void arch_pre_smp_init(void)
 {
Index: kernel/arch/sparc64/src/sparc64.c
===================================================================
--- kernel/arch/sparc64/src/sparc64.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/arch/sparc64/src/sparc64.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -79,4 +79,8 @@
 }
 
+void arch_post_cpu_init(void)
+{
+}
+
 void arch_pre_smp_init(void)
 {
Index: kernel/arch/xen32/src/xen32.c
===================================================================
--- kernel/arch/xen32/src/xen32.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/arch/xen32/src/xen32.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -152,4 +152,8 @@
 }
 
+void arch_post_cpu_init(void)
+{
+}
+
 void arch_pre_smp_init(void)
 {
Index: kernel/generic/include/arch.h
===================================================================
--- kernel/generic/include/arch.h	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/generic/include/arch.h	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -76,4 +76,5 @@
 extern void arch_pre_mm_init(void);
 extern void arch_post_mm_init(void);
+extern void arch_post_cpu_init(void);
 extern void arch_pre_smp_init(void);
 extern void arch_post_smp_init(void);
Index: kernel/generic/include/smp/smp.h
===================================================================
--- kernel/generic/include/smp/smp.h	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/generic/include/smp/smp.h	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -36,8 +36,13 @@
 #define KERN_SMP_H_
 
+#include <synch/waitq.h>
+
+extern waitq_t ap_completion_wq;
+
 #ifdef CONFIG_SMP
 extern void smp_init(void);
+extern void kmp(void *arg);
 #else
-#define smp_init()	;
+#define smp_init()
 #endif /* CONFIG_SMP */
 
Index: kernel/generic/src/main/kinit.c
===================================================================
--- kernel/generic/src/main/kinit.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/generic/src/main/kinit.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -64,5 +64,5 @@
 
 #ifdef CONFIG_SMP
-#include <arch/smp/mps.h>
+#include <smp/smp.h>
 #endif /* CONFIG_SMP */
 
@@ -95,4 +95,5 @@
 #ifdef CONFIG_SMP		 	
 	if (config.cpu_count > 1) {
+		waitq_initialize(&ap_completion_wq);
 		/*
 		 * Create the kmp thread and wait for its completion.
Index: kernel/generic/src/main/main.c
===================================================================
--- kernel/generic/src/main/main.c	(revision b44939b3e96b45459ade4081b45ffb74c843202e)
+++ kernel/generic/src/main/main.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -80,9 +80,4 @@
 #include <adt/btree.h>
 #include <console/klog.h>
-
-#ifdef CONFIG_SMP
-#include <arch/smp/apic.h>
-#include <arch/smp/mps.h>
-#endif /* CONFIG_SMP */
 #include <smp/smp.h>
 
@@ -272,5 +267,5 @@
  *
  * Executed by application processors, temporary stack
- * is at ctx.sp which was set during BP boot.
+ * is at ctx.sp which was set during BSP boot.
  * This function passes control directly to
  * main_ap_separated_stack().
@@ -283,7 +278,6 @@
 	/*
 	 * Incrementing the active CPU counter will guarantee that the
-	 * pm_init() will not attempt to build GDT and IDT tables again.
-	 * Neither frame_init() will do the complete thing. Neither cpu_init()
-	 * will do.
+	 * *_init() functions can find out that they need to
+	 * do initialization for AP only.
 	 */
 	config.cpu_active++;
@@ -301,9 +295,6 @@
 	
 	cpu_init();
-	
 	calibrate_delay_loop();
-
-	l_apic_init();
-	l_apic_debug();
+	arch_post_cpu_init();
 
 	the_copy(THE, (the_t *) CPU->stack);
Index: kernel/generic/src/smp/smp.c
===================================================================
--- kernel/generic/src/smp/smp.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
+++ kernel/generic/src/smp/smp.c	(revision 26678e5a1f0f0a6dda91a9e89a03aa3ca86e447c)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2006 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup generic	
+ * @{
+ */
+
+/**
+ * @file
+ */
+ 
+#include <smp/smp.h>
+
+#ifdef CONFIG_SMP
+
+waitq_t ap_completion_wq;
+
+#endif /* CONFIG_SMP */
+
+/** @}
+ */
