Index: arch/ia32/Makefile.inc
===================================================================
--- arch/ia32/Makefile.inc	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ arch/ia32/Makefile.inc	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -29,5 +29,6 @@
 	arch/smp/ap.S \
 	arch/smp/apic.c \
-	arch/smp/mp.c \
+	arch/smp/mps.c \
+	arch/smp/smp.c \
 	arch/smp/atomic.S \
 	arch/smp/ipi.c \
Index: arch/ia32/include/acpi/madt.h
===================================================================
--- arch/ia32/include/acpi/madt.h	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ arch/ia32/include/acpi/madt.h	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -31,12 +31,5 @@
 
 #include <arch/acpi/acpi.h>
-
-/* Multiple APIC Description Table */
-struct acpi_madt {
-	struct acpi_sdt_header header;
-	__u32 l_apic_address;
-	__u32 flags;
-	__u8  apic_strucure[];
-} __attribute__ ((packed));
+#include <arch/smp/apic.h>
 
 #define	MADT_L_APIC			0
@@ -52,9 +45,21 @@
 #define MADT_RESERVED_SKIP_END		127
 #define MADT_RESERVED_OEM_BEGIN		128
-#define MADT_RESERVED_OEM_END		255
+
+struct madt_apic_header {
+	__u8 type;
+	__u8 length;
+} __attribute__ ((packed));
+
+
+/* Multiple APIC Description Table */
+struct acpi_madt {
+	struct acpi_sdt_header header;
+	__u32 l_apic_address;
+	__u32 flags;
+	struct madt_apic_header apic_header[];
+} __attribute__ ((packed));
 
 struct madt_l_apic {
-	__u8 type;
-	__u8 length;
+	struct madt_apic_header header;
 	__u8 acpi_id;
 	__u8 apic_id;
@@ -63,6 +68,5 @@
 
 struct madt_io_apic {
-	__u8 type;
-	__u8 length;
+	struct madt_apic_header header;
 	__u8 io_apic_id;
 	__u8 reserved;
@@ -72,6 +76,5 @@
 
 struct madt_intr_src_ovrd {
-	__u8 type;
-	__u8 length;
+	struct madt_apic_header header;
 	__u8 bus;
 	__u8 source;
@@ -81,6 +84,5 @@
 
 struct madt_nmi_src {
-	__u8 type;
-	__u8 length;
+	struct madt_apic_header header;
 	__u16 flags;
 	__u32 global_intr;
@@ -88,6 +90,5 @@
 
 struct madt_l_apic_nmi {
-	__u8 type;
-	__u8 length;
+	struct madt_apic_header header;
 	__u8 acpi_id;
 	__u16 flags;
@@ -96,6 +97,5 @@
 
 struct madt_l_apic_addr_ovrd {
-	__u8 type;
-	__u8 length;
+	struct madt_apic_header header;
 	__u16 reserved;
 	__u64 l_apic_address;
@@ -103,6 +103,5 @@
 
 struct madt_io_sapic {
-	__u8 type;
-	__u8 length;
+	struct madt_apic_header header;
 	__u8 io_apic_id;
 	__u8 reserved;
@@ -112,6 +111,5 @@
 
 struct madt_l_sapic {
-	__u8 type;
-	__u8 length;
+	struct madt_apic_header header;
 	__u8 acpi_id;
 	__u8 sapic_id;
@@ -124,6 +122,5 @@
 
 struct madt_platform_intr_src {
-	__u8 type;
-	__u8 length;
+	struct madt_apic_header header;
 	__u16 flags;
 	__u8 intr_type;
@@ -137,3 +134,5 @@
 extern struct acpi_madt *acpi_madt;
 
+extern void acpi_madt_parse(void);
+
 #endif /* __MADT_H__ */
Index: ch/ia32/include/smp/mp.h
===================================================================
--- arch/ia32/include/smp/mp.h	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ 	(revision )
@@ -1,125 +1,0 @@
-/*
- * Copyright (C) 2001-2004 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.
- */
-
-#ifndef __MP_H__
-#define __MP_H__
-
-#include <arch/types.h>
-#include <typedefs.h>
-#include <synch/waitq.h>
-#include <config.h>
-
-#define CT_EXT_ENTRY_TYPE		0
-#define CT_EXT_ENTRY_LEN		1
-
-struct __mpfs {
-	__u32 signature;
-	struct __mpct *configuration_table;
-	__u8 length;
-	__u8 revision;
-	__u8 checksum;
-	__u8 config_type;
-	__u8 mpfib2;
-	__u8 mpfib3;
-	__u8 mpfib4;
-	__u8 mpfib5;
-} __attribute__ ((packed));
-
-struct __mpct {
-	__u32 signature;
-	__u16 base_table_length;
-	__u8 revision;
-	__u8 checksum;
-	__u8 oem_id[8];
-	__u8 product_id[12];
-	__u8 *oem_table;
-	__u16 oem_table_size;
-	__u16 entry_count;
-	__u32 *l_apic;
-	__u16 ext_table_length;
-	__u8 ext_table_checksum;
-	__u8 xxx;
-	__u8 base_table[0];
-} __attribute__ ((packed));
-
-struct __processor_entry {
-	__u8 type;
-	__u8 l_apic_id;
-	__u8 l_apic_version;
-	__u8 cpu_flags;
-	__u8 cpu_signature[4];
-	__u32 feature_flags;
-	__u32 xxx[2];
-} __attribute__ ((packed));
-
-struct __bus_entry {
-	__u8 type;
-	__u8 bus_id;
-	__u8 bus_type[6];
-} __attribute__ ((packed));
-
-struct __io_apic_entry {
-	__u8 type;
-	__u8 io_apic_id;
-	__u8 io_apic_version;
-	__u8 io_apic_flags;
-	__u32 *io_apic;
-} __attribute__ ((packed));
-
-struct __io_intr_entry {
-	__u8 type;
-	__u8 intr_type;
-	__u8 poel;
-	__u8 xxx;
-	__u8 src_bus_id;
-	__u8 src_bus_irq;
-	__u8 dst_io_apic_id;
-	__u8 dst_io_apic_pin;
-} __attribute__ ((packed));
-
-struct __l_intr_entry {
-	__u8 type;
-	__u8 intr_type;
-	__u8 poel;
-	__u8 xxx;
-	__u8 src_bus_id;
-	__u8 src_bus_irq;
-	__u8 dst_l_apic_id;
-	__u8 dst_l_apic_pin;
-} __attribute__ ((packed));
-
-
-extern waitq_t ap_completion_wq;
-extern waitq_t kmp_completion_wq;
-
-extern int mp_irq_to_pin(int irq);
-
-extern void mp_init(void);
-extern void kmp(void *arg);
-
-#endif
Index: arch/ia32/include/smp/mps.h
===================================================================
--- arch/ia32/include/smp/mps.h	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
+++ arch/ia32/include/smp/mps.h	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2001-2004 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.
+ */
+
+#ifndef __MPS_H__
+#define __MPS_H__
+
+#include <arch/types.h>
+#include <typedefs.h>
+#include <synch/waitq.h>
+#include <config.h>
+
+#define CT_EXT_ENTRY_TYPE		0
+#define CT_EXT_ENTRY_LEN		1
+
+struct mps_fs {
+	__u32 signature;
+	struct mps_ct *configuration_table;
+	__u8 length;
+	__u8 revision;
+	__u8 checksum;
+	__u8 config_type;
+	__u8 mpfib2;
+	__u8 mpfib3;
+	__u8 mpfib4;
+	__u8 mpfib5;
+} __attribute__ ((packed));
+
+struct mps_ct {
+	__u32 signature;
+	__u16 base_table_length;
+	__u8 revision;
+	__u8 checksum;
+	__u8 oem_id[8];
+	__u8 product_id[12];
+	__u8 *oem_table;
+	__u16 oem_table_size;
+	__u16 entry_count;
+	__u32 *l_apic;
+	__u16 ext_table_length;
+	__u8 ext_table_checksum;
+	__u8 xxx;
+	__u8 base_table[0];
+} __attribute__ ((packed));
+
+struct __processor_entry {
+	__u8 type;
+	__u8 l_apic_id;
+	__u8 l_apic_version;
+	__u8 cpu_flags;
+	__u8 cpu_signature[4];
+	__u32 feature_flags;
+	__u32 xxx[2];
+} __attribute__ ((packed));
+
+struct __bus_entry {
+	__u8 type;
+	__u8 bus_id;
+	__u8 bus_type[6];
+} __attribute__ ((packed));
+
+struct __io_apic_entry {
+	__u8 type;
+	__u8 io_apic_id;
+	__u8 io_apic_version;
+	__u8 io_apic_flags;
+	__u32 *io_apic;
+} __attribute__ ((packed));
+
+struct __io_intr_entry {
+	__u8 type;
+	__u8 intr_type;
+	__u8 poel;
+	__u8 xxx;
+	__u8 src_bus_id;
+	__u8 src_bus_irq;
+	__u8 dst_io_apic_id;
+	__u8 dst_io_apic_pin;
+} __attribute__ ((packed));
+
+struct __l_intr_entry {
+	__u8 type;
+	__u8 intr_type;
+	__u8 poel;
+	__u8 xxx;
+	__u8 src_bus_id;
+	__u8 src_bus_irq;
+	__u8 dst_l_apic_id;
+	__u8 dst_l_apic_pin;
+} __attribute__ ((packed));
+
+
+extern waitq_t ap_completion_wq;
+extern waitq_t kmp_completion_wq;
+
+extern int mps_irq_to_pin(int irq);
+
+extern void mps_init(void);
+extern void kmp(void *arg);
+
+#endif
Index: arch/ia32/src/acpi/acpi.c
===================================================================
--- arch/ia32/src/acpi/acpi.c	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ arch/ia32/src/acpi/acpi.c	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -79,5 +79,13 @@
 void map_sdt(struct acpi_sdt_header *sdt)
 {
+	int i, cnt, length;
+
 	map_page_to_frame((__address) sdt, (__address) sdt, PAGE_NOT_CACHEABLE, 0);
+	
+	length = sdt->length + ((__address) sdt) - ((__address) sdt)&0xfffff000;
+	cnt = length/PAGE_SIZE + (length%PAGE_SIZE>0);
+	
+	for (i = 1; i < cnt; i++)
+		map_page_to_frame(((__address) sdt) + i*PAGE_SIZE, ((__address) sdt) + i*PAGE_SIZE, PAGE_NOT_CACHEABLE, 0);
 }
 
Index: arch/ia32/src/acpi/madt.c
===================================================================
--- arch/ia32/src/acpi/madt.c	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ arch/ia32/src/acpi/madt.c	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -27,6 +27,59 @@
  */
 
+#include <arch/types.h>
 #include <arch/acpi/acpi.h>
 #include <arch/acpi/madt.h>
+#include <arch/smp/apic.h>
 
 struct acpi_madt *acpi_madt = NULL;
+
+#ifdef __SMP__
+
+char *entry[] = {
+	"L_APIC",
+	"IO_APIC",
+	"INTR_SRC_OVRD",
+	"NMI_SRC",
+	"L_APIC_NMI",
+	"L_APIC_ADDR_OVRD",
+	"IO_SAPIC",
+	"L_SAPIC",
+	"PLATFORM_INTR_SRC"
+};
+
+void acpi_madt_parse(void)
+{
+	struct madt_apic_header *end = (struct madt_apic_header *) (((__u8 *) acpi_madt) + acpi_madt->header.length);
+	struct madt_apic_header *h = &acpi_madt->apic_header[0];
+
+	l_apic = (__u32 *) acpi_madt->l_apic_address;
+
+	while (h < end) {
+		switch (h->type) {
+			case MADT_L_APIC:
+			case MADT_IO_APIC:
+			case MADT_INTR_SRC_OVRD:
+			case MADT_NMI_SRC:
+			case MADT_L_APIC_NMI:
+			case MADT_L_APIC_ADDR_OVRD:
+			case MADT_IO_SAPIC:
+			case MADT_L_SAPIC:
+			case MADT_PLATFORM_INTR_SRC:
+				printf("MADT: skipping %s entry (type=%d)\n", entry[h->type], h->type);
+				break;
+
+			default:
+				if (h->type >= MADT_RESERVED_SKIP_BEGIN && h->type <= MADT_RESERVED_SKIP_END) {
+					printf("MADT: skipping reserved entry (type=%d)\n", h->type);
+				}
+				if (h->type >= MADT_RESERVED_OEM_BEGIN) {
+					printf("MADT: skipping OEM entry (type=%d)\n", h->type);
+				}
+				break;
+		}
+		h = (struct madt_apic_header *) (((__u8 *) h) + h->length);
+	}
+
+}
+
+#endif /* __SMP__ */
Index: arch/ia32/src/ia32.c
===================================================================
--- arch/ia32/src/ia32.c	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ arch/ia32/src/ia32.c	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -94,5 +94,4 @@
 		#ifdef __SMP__
 		acpi_init();
-		mp_init();
 		#endif /* __SMP__ */
 	}
Index: arch/ia32/src/mm/page.c
===================================================================
--- arch/ia32/src/mm/page.c	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ arch/ia32/src/mm/page.c	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -128,4 +128,5 @@
 		pd[pde].frame_address = newpt >> 12;
 	}
+	
 	pt = (struct page_specifier *) (pd[pde].frame_address << 12);
 
Index: arch/ia32/src/smp/apic.c
===================================================================
--- arch/ia32/src/smp/apic.c	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ arch/ia32/src/smp/apic.c	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -30,5 +30,5 @@
 #include <arch/smp/apic.h>
 #include <arch/smp/ap.h>
-#include <arch/smp/mp.h>
+#include <arch/smp/mps.h>
 #include <mm/page.h>
 #include <time/delay.h>
@@ -44,5 +44,5 @@
  * Advanced Programmable Interrupt Controller for MP systems.
  * Tested on:
- *	Bochs 2.0.2 with 2-8 CPUs
+ *	Bochs 2.0.2 - Bochs 2.2-cvs with 2-8 CPUs
  *	ASUS P/I-P65UP5 + ASUS C-P55T2D REV. 1.41 with 2x 200Mhz Pentium CPUs
  */
@@ -83,5 +83,5 @@
 		int pin;
 	
-		if ((pin = mp_irq_to_pin(i)) != -1)
+		if ((pin = mps_irq_to_pin(i)) != -1)
 	    		io_apic_change_ioredtbl(pin,0xf,IVT_IRQBASE+i,LOPRI);
 	}
@@ -380,5 +380,5 @@
 			 * mapping for the respective IRQ number.
 			 */
-			pin = mp_irq_to_pin(i);
+			pin = mps_irq_to_pin(i);
 			if (pin != -1) {
 				reglo = io_apic_read(IOREDTBL + pin*2);
@@ -402,5 +402,5 @@
 			 * mapping for the respective IRQ number.
 			 */
-			pin = mp_irq_to_pin(i);
+			pin = mps_irq_to_pin(i);
 			if (pin != -1) {
 				reglo = io_apic_read(IOREDTBL + pin*2);
Index: ch/ia32/src/smp/mp.c
===================================================================
--- arch/ia32/src/smp/mp.c	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ 	(revision )
@@ -1,510 +1,0 @@
-/*
- * Copyright (C) 2001-2004 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.
- */
-
-#ifdef __SMP__
-
-#include <arch/pm.h>
-#include <config.h>
-#include <print.h>
-#include <panic.h>
-#include <arch/smp/mp.h>
-#include <arch/smp/ap.h>
-#include <arch/smp/apic.h>
-#include <func.h>
-#include <arch/types.h>
-#include <typedefs.h>
-#include <synch/waitq.h>
-#include <time/delay.h>
-#include <mm/heap.h>
-#include <mm/page.h>
-#include <mm/frame.h>
-#include <cpu.h>
-#include <arch/i8259.h>
-#include <arch/asm.h>
-#include <arch/bios/bios.h>
-#include <arch/acpi/madt.h>
-
-/*
- * Multi-Processor Specification detection code.
- */
-
-#define	FS_SIGNATURE	0x5f504d5f
-#define CT_SIGNATURE 	0x504d4350
-
-int mp_fs_check(__u8 *base);
-int mp_ct_check(void);
-
-int configure_via_ct(void);
-int configure_via_default(__u8 n);
-
-int ct_processor_entry(struct __processor_entry *pr);
-void ct_bus_entry(struct __bus_entry *bus);
-void ct_io_apic_entry(struct __io_apic_entry *ioa);
-void ct_io_intr_entry(struct __io_intr_entry *iointr);
-void ct_l_intr_entry(struct __l_intr_entry *lintr);
-
-void ct_extended_entries(void);
-
-static struct __mpfs *fs;
-static struct __mpct *ct;
-
-struct __processor_entry *processor_entries = NULL;
-struct __bus_entry *bus_entries = NULL;
-struct __io_apic_entry *io_apic_entries = NULL;
-struct __io_intr_entry *io_intr_entries = NULL;
-struct __l_intr_entry *l_intr_entries = NULL;
-
-int processor_entry_cnt = 0;
-int bus_entry_cnt = 0;
-int io_apic_entry_cnt = 0;
-int io_intr_entry_cnt = 0;
-int l_intr_entry_cnt = 0;
-
-waitq_t ap_completion_wq;
-waitq_t kmp_completion_wq;
-
-/*
- * Used to check the integrity of the MP Floating Structure.
- */
-int mp_fs_check(__u8 *base)
-{
-	int i;
-	__u8 sum;
-	
-	for (i = 0, sum = 0; i < 16; i++)
-		sum += base[i];
-	
-	return !sum;
-}
-
-/*
- * Used to check the integrity of the MP Configuration Table.
- */
-int mp_ct_check(void)
-{
-	__u8 *base = (__u8 *) ct;
-	__u8 *ext = base + ct->base_table_length;
-	__u8 sum;
-	int i;	
-	
-	/* count the checksum for the base table */
-	for (i=0,sum=0; i < ct->base_table_length; i++)
-		sum += base[i];
-		
-	if (sum)
-		return 0;
-		
-	/* count the checksum for the extended table */
-	for (i=0,sum=0; i < ct->ext_table_length; i++)
-		sum += ext[i];
-		
-	return sum == ct->ext_table_checksum;
-}
-
-void mp_init(void)
-{
-	__u8 *addr[2] = { NULL, (__u8 *) 0xf0000 };
-	int i, j, length[2] = { 1024, 64*1024 };
-	
-
-	/*
-	 * Find MP Floating Pointer Structure
-	 * 1a. search first 1K of EBDA
-	 * 1b. if EBDA is undefined, search last 1K of base memory
-	 *  2. search 64K starting at 0xf0000
-	 */
-
-	addr[0] = (__u8 *) (ebda ? ebda : 639 * 1024);
-	for (i = 0; i < 2; i++) {
-		for (j = 0; j < length[i]; j += 16) {
-			if (*((__u32 *) &addr[i][j]) == FS_SIGNATURE && mp_fs_check(&addr[i][j])) {
-				fs = (struct __mpfs *) &addr[i][j];
-				goto fs_found;
-			}
-		}
-	}
-
-	return;
-	
-fs_found:
-	printf("%L: MP Floating Pointer Structure\n", fs);
-
-	frame_not_free((__address) fs);
-
-	if (fs->config_type == 0 && fs->configuration_table) {
-		if (fs->mpfib2 >> 7) {
-			printf("mp_init: PIC mode not supported\n");
-			return;
-		}
-
-		ct = fs->configuration_table;
-		frame_not_free((__address) ct);
-		config.cpu_count = configure_via_ct();
-	} 
-	else
-		config.cpu_count = configure_via_default(fs->config_type);
-
-	if (config.cpu_count > 1) {
-		map_page_to_frame((__address) l_apic, (__address) l_apic, PAGE_NOT_CACHEABLE, 0);
- 	}		
-	
-	
-	/*
-	 * Must be initialized outside the kmp thread, since it is waited
-	 * on before the kmp thread is created.
-	 */
-	waitq_initialize(&kmp_completion_wq);
-	return;
-}
-
-int configure_via_ct(void)
-{
-	__u8 *cur;
-	int i, cnt;
-		
-	if (ct->signature != CT_SIGNATURE) {
-		printf("configure_via_ct: bad ct->signature\n");
-		return 1;
-	}
-	if (!mp_ct_check()) {
-		printf("configure_via_ct: bad ct checksum\n");
-		return 1;
-	}
-	if (ct->oem_table) {
-		printf("configure_via_ct: ct->oem_table not supported\n");
-		return 1;
-	}
-	
-	l_apic = ct->l_apic;
-
-	cnt = 0;
-	cur = &ct->base_table[0];
-	for (i=0; i < ct->entry_count; i++) {
-		switch (*cur) {
-			/* Processor entry */
-			case 0:	
-				processor_entries = processor_entries ? processor_entries : (struct __processor_entry *) cur;
-				processor_entry_cnt++;
-				cnt += ct_processor_entry((struct __processor_entry *) cur);
-				cur += 20;
-				break;
-
-			/* Bus entry */
-			case 1:
-				bus_entries = bus_entries ? bus_entries : (struct __bus_entry *) cur;
-				bus_entry_cnt++;
-				ct_bus_entry((struct __bus_entry *) cur);
-				cur += 8;
-				break;
-				
-			/* I/O Apic */
-			case 2:
-				io_apic_entries = io_apic_entries ? io_apic_entries : (struct __io_apic_entry *) cur;
-				io_apic_entry_cnt++;
-				ct_io_apic_entry((struct __io_apic_entry *) cur);
-				cur += 8;
-				break;
-				
-			/* I/O Interrupt Assignment */
-			case 3:
-				io_intr_entries = io_intr_entries ? io_intr_entries : (struct __io_intr_entry *) cur;
-				io_intr_entry_cnt++;
-				ct_io_intr_entry((struct __io_intr_entry *) cur);
-				cur += 8;
-				break;
-
-			/* Local Interrupt Assignment */
-			case 4:
-				l_intr_entries = l_intr_entries ? l_intr_entries : (struct __l_intr_entry *) cur;
-				l_intr_entry_cnt++;
-				ct_l_intr_entry((struct __l_intr_entry *) cur);
-		    		cur += 8;
-				break;
-	    
-			default:
-				/*
-				 * Something is wrong. Fallback to UP mode.
-				 */
-				 
-				printf("configure_via_ct: ct badness\n");
-				return 1;
-		}
-	}
-	
-	/*
-	 * Process extended entries.
-	 */
-	ct_extended_entries();
-	return cnt;
-}
-
-int configure_via_default(__u8 n)
-{
-	/*
-	 * Not yet implemented.
-	 */
-	printf("configure_via_default: not supported\n");
-	return 1;
-}
-
-
-int ct_processor_entry(struct __processor_entry *pr)
-{
-	/*
-	 * Ignore processors which are not marked enabled.
-	 */
-	if ((pr->cpu_flags & (1<<0)) == 0)
-		return 0;
-	
-	apic_id_mask |= (1<<pr->l_apic_id); 
-	return 1;
-}
-
-void ct_bus_entry(struct __bus_entry *bus)
-{
-#ifdef MPCT_VERBOSE
-	char buf[7];
-	memcopy((__address) bus->bus_type, (__address) buf,6);
-	buf[6] = 0;
-	printf("bus%d: %s\n", bus->bus_id, buf);
-#endif
-}
-
-void ct_io_apic_entry(struct __io_apic_entry *ioa)
-{
-	static int io_apic_count = 0;
-
-	/* this ioapic is marked unusable */
-	if (ioa->io_apic_flags & 1 == 0)
-		return;
-	
-	if (io_apic_count++ > 0) {
-		/*
-		 * Multiple IO APIC's are currently not supported.
-		 */
-		return;
-	}
-	
-	map_page_to_frame((__address) ioa->io_apic, (__address) ioa->io_apic, PAGE_NOT_CACHEABLE, 0);
-	
-	io_apic = ioa->io_apic;
-}
-
-//#define MPCT_VERBOSE
-void ct_io_intr_entry(struct __io_intr_entry *iointr)
-{
-#ifdef MPCT_VERBOSE
-	switch (iointr->intr_type) {
-	    case 0: printf("INT"); break;
-	    case 1: printf("NMI"); break;
-	    case 2: printf("SMI"); break;
-	    case 3: printf("ExtINT"); break;
-	}
-	putchar(',');
-	switch (iointr->poel&3) {
-	    case 0: printf("bus-like"); break;
-	    case 1: printf("active high"); break;
-	    case 2: printf("reserved"); break;
-	    case 3: printf("active low"); break;
-	}
-	putchar(',');
-	switch ((iointr->poel>>2)&3) {
-	    case 0: printf("bus-like"); break;
-	    case 1: printf("edge-triggered"); break;
-	    case 2: printf("reserved"); break;
-	    case 3: printf("level-triggered"); break;
-	}
-	putchar(',');
-	printf("bus%d,irq%d", iointr->src_bus_id, iointr->src_bus_irq);
-	putchar(',');
-	printf("io_apic%d,pin%d", iointr->dst_io_apic_id, iointr->dst_io_apic_pin);
-	putchar('\n');	
-#endif
-}
-
-void ct_l_intr_entry(struct __l_intr_entry *lintr)
-{
-#ifdef MPCT_VERBOSE
-	switch (lintr->intr_type) {
-	    case 0: printf("INT"); break;
-	    case 1: printf("NMI"); break;
-	    case 2: printf("SMI"); break;
-	    case 3: printf("ExtINT"); break;
-	}
-	putchar(',');
-	switch (lintr->poel&3) {
-	    case 0: printf("bus-like"); break;
-	    case 1: printf("active high"); break;
-	    case 2: printf("reserved"); break;
-	    case 3: printf("active low"); break;
-	}
-	putchar(',');
-	switch ((lintr->poel>>2)&3) {
-	    case 0: printf("bus-like"); break;
-	    case 1: printf("edge-triggered"); break;
-	    case 2: printf("reserved"); break;
-	    case 3: printf("level-triggered"); break;
-	}
-	putchar(',');
-	printf("bus%d,irq%d", lintr->src_bus_id, lintr->src_bus_irq);
-	putchar(',');
-	printf("l_apic%d,pin%d", lintr->dst_l_apic_id, lintr->dst_l_apic_pin);
-	putchar('\n');
-#endif
-}
-
-void ct_extended_entries(void)
-{
-	__u8 *ext = (__u8 *) ct + ct->base_table_length;
-	__u8 *cur;
-
-	for (cur = ext; cur < ext + ct->ext_table_length; cur += cur[CT_EXT_ENTRY_LEN]) {
-		switch (cur[CT_EXT_ENTRY_TYPE]) {
-			default:
-				printf("%L: skipping MP Configuration Table extended entry type %d\n", cur, cur[CT_EXT_ENTRY_TYPE]);
-				break;
-		}
-	}
-}
-
-/*
- * Kernel thread for bringing up application processors. It becomes clear
- * that we need an arrangement like this (AP's being initialized by a kernel
- * thread), for a thread has its dedicated stack. (The stack used during the
- * BSP initialization (prior the very first call to scheduler()) will be used
- * as an initialization stack for each AP.)
- */
-void kmp(void *arg)
-{
-	struct __processor_entry *pr;
-	__address src, dst;
-	__address frame;
-	int i;
-
-	waitq_initialize(&ap_completion_wq);
-
-	/*
-	 * Processor entries immediately follow the configuration table header.
-	 */
-	pr = processor_entries;
-
-	/*
-	 * Grab a frame and map its address to page 0. This is a hack which
-	 * accesses data in frame 0. Note that page 0 is not present because
-	 * of nil reference bug catching.
-	 */
-	frame = frame_alloc(FRAME_KA);
-	map_page_to_frame(frame,0,PAGE_CACHEABLE,0);
-
-	/*
-	 * Set the warm-reset vector to the real-mode address of 4K-aligned ap_boot()
-	 */
-	*((__u16 *) (frame + 0x467+0)) =  ((__address) ap_boot) >> 4;	/* segment */
-	*((__u16 *) (frame + 0x467+2)) =  0x0;	/* offset */
-	
-	/*
-	 * Give back the borrowed frame and restore identity mapping for it.
-	 */
-	map_page_to_frame(frame,frame,PAGE_CACHEABLE,0);
-	frame_free(frame);
-
-	/*
-	 * Save 0xa to address 0xf of the CMOS RAM.
-	 * BIOS will not do the POST after the INIT signal.
-	 */
-	outb(0x70,0xf);
-	outb(0x71,0xa);
-
-	cpu_priority_high();
-
-	pic_disable_irqs(0xffff);
-	apic_init();
-
-	for (i = 0; i < processor_entry_cnt; i++) {
-		struct descriptor *gdt_new;
-	
-		/*
-		 * Skip processors marked unusable.
-		 */
-		if (pr[i].cpu_flags & (1<<0) == 0)
-			continue;
-
-		/*
-		 * The bootstrap processor is already up.
-		 */
-		if (pr[i].cpu_flags & (1<<1))
-			continue;
-
-		if (pr[i].l_apic_id == l_apic_id()) {
-			printf("%L: bad processor entry #%d, will not send IPI to myself\n", &pr[i], i);
-			continue;
-		}
-		
-		/*
-		 * Prepare new GDT for CPU in question.
-		 */
-		if (!(gdt_new = (struct descriptor *) malloc(GDT_ITEMS*sizeof(struct descriptor))))
-			panic(PANIC "couldn't allocate memory for GDT\n");
-
-		memcopy(gdt, gdt_new, GDT_ITEMS*sizeof(struct descriptor));
-		gdtr.base = (__address) gdt_new;
-
-		if (l_apic_send_init_ipi(pr[i].l_apic_id)) {
-			/*
-		         * There may be just one AP being initialized at
-			 * the time. After it comes completely up, it is
-			 * supposed to wake us up.
-		         */
-			waitq_sleep(&ap_completion_wq);
-			cpu_priority_high();
-		}
-		else {
-			printf("INIT IPI for l_apic%d failed\n", pr[i].l_apic_id);
-		}
-	}
-
-	/*
-	 * Wakeup the kinit thread so that
-	 * system initialization can go on.
-	 */
-	waitq_wakeup(&kmp_completion_wq, WAKEUP_FIRST);
-}
-
-int mp_irq_to_pin(int irq)
-{
-	int i;
-	
-	for(i=0;i<io_intr_entry_cnt;i++) {
-		if (io_intr_entries[i].src_bus_irq == irq && io_intr_entries[i].intr_type == 0)
-			return io_intr_entries[i].dst_io_apic_pin;
-	}
-	
-	return -1;
-}
-
-#endif /* __SMP__ */
Index: arch/ia32/src/smp/mps.c
===================================================================
--- arch/ia32/src/smp/mps.c	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
+++ arch/ia32/src/smp/mps.c	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -0,0 +1,510 @@
+/*
+ * Copyright (C) 2001-2005 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.
+ */
+
+#ifdef __SMP__
+
+#include <arch/pm.h>
+#include <config.h>
+#include <print.h>
+#include <panic.h>
+#include <arch/smp/mps.h>
+#include <arch/smp/ap.h>
+#include <arch/smp/apic.h>
+#include <func.h>
+#include <arch/types.h>
+#include <typedefs.h>
+#include <synch/waitq.h>
+#include <time/delay.h>
+#include <mm/heap.h>
+#include <mm/page.h>
+#include <mm/frame.h>
+#include <cpu.h>
+#include <arch/i8259.h>
+#include <arch/asm.h>
+#include <arch/bios/bios.h>
+#include <arch/acpi/madt.h>
+
+/*
+ * MultiProcessor Specification detection code.
+ */
+
+#define	FS_SIGNATURE	0x5f504d5f
+#define CT_SIGNATURE 	0x504d4350
+
+int mps_fs_check(__u8 *base);
+int mps_ct_check(void);
+
+int configure_via_ct(void);
+int configure_via_default(__u8 n);
+
+int ct_processor_entry(struct __processor_entry *pr);
+void ct_bus_entry(struct __bus_entry *bus);
+void ct_io_apic_entry(struct __io_apic_entry *ioa);
+void ct_io_intr_entry(struct __io_intr_entry *iointr);
+void ct_l_intr_entry(struct __l_intr_entry *lintr);
+
+void ct_extended_entries(void);
+
+static struct mps_fs *fs;
+static struct mps_ct *ct;
+
+struct __processor_entry *processor_entries = NULL;
+struct __bus_entry *bus_entries = NULL;
+struct __io_apic_entry *io_apic_entries = NULL;
+struct __io_intr_entry *io_intr_entries = NULL;
+struct __l_intr_entry *l_intr_entries = NULL;
+
+int processor_entry_cnt = 0;
+int bus_entry_cnt = 0;
+int io_apic_entry_cnt = 0;
+int io_intr_entry_cnt = 0;
+int l_intr_entry_cnt = 0;
+
+waitq_t ap_completion_wq;
+waitq_t kmp_completion_wq;
+
+/*
+ * Used to check the integrity of the MP Floating Structure.
+ */
+int mps_fs_check(__u8 *base)
+{
+	int i;
+	__u8 sum;
+	
+	for (i = 0, sum = 0; i < 16; i++)
+		sum += base[i];
+	
+	return !sum;
+}
+
+/*
+ * Used to check the integrity of the MP Configuration Table.
+ */
+int mps_ct_check(void)
+{
+	__u8 *base = (__u8 *) ct;
+	__u8 *ext = base + ct->base_table_length;
+	__u8 sum;
+	int i;	
+	
+	/* count the checksum for the base table */
+	for (i=0,sum=0; i < ct->base_table_length; i++)
+		sum += base[i];
+		
+	if (sum)
+		return 0;
+		
+	/* count the checksum for the extended table */
+	for (i=0,sum=0; i < ct->ext_table_length; i++)
+		sum += ext[i];
+		
+	return sum == ct->ext_table_checksum;
+}
+
+void mps_init(void)
+{
+	__u8 *addr[2] = { NULL, (__u8 *) 0xf0000 };
+	int i, j, length[2] = { 1024, 64*1024 };
+	
+
+	/*
+	 * Find MP Floating Pointer Structure
+	 * 1a. search first 1K of EBDA
+	 * 1b. if EBDA is undefined, search last 1K of base memory
+	 *  2. search 64K starting at 0xf0000
+	 */
+
+	addr[0] = (__u8 *) (ebda ? ebda : 639 * 1024);
+	for (i = 0; i < 2; i++) {
+		for (j = 0; j < length[i]; j += 16) {
+			if (*((__u32 *) &addr[i][j]) == FS_SIGNATURE && mps_fs_check(&addr[i][j])) {
+				fs = (struct mps_fs *) &addr[i][j];
+				goto fs_found;
+			}
+		}
+	}
+
+	return;
+	
+fs_found:
+	printf("%L: MPS Floating Pointer Structure\n", fs);
+
+	frame_not_free((__address) fs);
+
+	if (fs->config_type == 0 && fs->configuration_table) {
+		if (fs->mpfib2 >> 7) {
+			printf("mps_init: PIC mode not supported\n");
+			return;
+		}
+
+		ct = fs->configuration_table;
+		frame_not_free((__address) ct);
+		config.cpu_count = configure_via_ct();
+	} 
+	else
+		config.cpu_count = configure_via_default(fs->config_type);
+
+	if (config.cpu_count > 1) {
+		map_page_to_frame((__address) l_apic, (__address) l_apic, PAGE_NOT_CACHEABLE, 0);
+ 	}		
+	
+	
+	/*
+	 * Must be initialized outside the kmp thread, since it is waited
+	 * on before the kmp thread is created.
+	 */
+	waitq_initialize(&kmp_completion_wq);
+	return;
+}
+
+int configure_via_ct(void)
+{
+	__u8 *cur;
+	int i, cnt;
+		
+	if (ct->signature != CT_SIGNATURE) {
+		printf("configure_via_ct: bad ct->signature\n");
+		return 1;
+	}
+	if (!mps_ct_check()) {
+		printf("configure_via_ct: bad ct checksum\n");
+		return 1;
+	}
+	if (ct->oem_table) {
+		printf("configure_via_ct: ct->oem_table not supported\n");
+		return 1;
+	}
+	
+	l_apic = ct->l_apic;
+
+	cnt = 0;
+	cur = &ct->base_table[0];
+	for (i=0; i < ct->entry_count; i++) {
+		switch (*cur) {
+			/* Processor entry */
+			case 0:	
+				processor_entries = processor_entries ? processor_entries : (struct __processor_entry *) cur;
+				processor_entry_cnt++;
+				cnt += ct_processor_entry((struct __processor_entry *) cur);
+				cur += 20;
+				break;
+
+			/* Bus entry */
+			case 1:
+				bus_entries = bus_entries ? bus_entries : (struct __bus_entry *) cur;
+				bus_entry_cnt++;
+				ct_bus_entry((struct __bus_entry *) cur);
+				cur += 8;
+				break;
+				
+			/* I/O Apic */
+			case 2:
+				io_apic_entries = io_apic_entries ? io_apic_entries : (struct __io_apic_entry *) cur;
+				io_apic_entry_cnt++;
+				ct_io_apic_entry((struct __io_apic_entry *) cur);
+				cur += 8;
+				break;
+				
+			/* I/O Interrupt Assignment */
+			case 3:
+				io_intr_entries = io_intr_entries ? io_intr_entries : (struct __io_intr_entry *) cur;
+				io_intr_entry_cnt++;
+				ct_io_intr_entry((struct __io_intr_entry *) cur);
+				cur += 8;
+				break;
+
+			/* Local Interrupt Assignment */
+			case 4:
+				l_intr_entries = l_intr_entries ? l_intr_entries : (struct __l_intr_entry *) cur;
+				l_intr_entry_cnt++;
+				ct_l_intr_entry((struct __l_intr_entry *) cur);
+		    		cur += 8;
+				break;
+	    
+			default:
+				/*
+				 * Something is wrong. Fallback to UP mode.
+				 */
+				 
+				printf("configure_via_ct: ct badness\n");
+				return 1;
+		}
+	}
+	
+	/*
+	 * Process extended entries.
+	 */
+	ct_extended_entries();
+	return cnt;
+}
+
+int configure_via_default(__u8 n)
+{
+	/*
+	 * Not yet implemented.
+	 */
+	printf("configure_via_default: not supported\n");
+	return 1;
+}
+
+
+int ct_processor_entry(struct __processor_entry *pr)
+{
+	/*
+	 * Ignore processors which are not marked enabled.
+	 */
+	if ((pr->cpu_flags & (1<<0)) == 0)
+		return 0;
+	
+	apic_id_mask |= (1<<pr->l_apic_id); 
+	return 1;
+}
+
+void ct_bus_entry(struct __bus_entry *bus)
+{
+#ifdef MPSCT_VERBOSE
+	char buf[7];
+	memcopy((__address) bus->bus_type, (__address) buf,6);
+	buf[6] = 0;
+	printf("bus%d: %s\n", bus->bus_id, buf);
+#endif
+}
+
+void ct_io_apic_entry(struct __io_apic_entry *ioa)
+{
+	static int io_apic_count = 0;
+
+	/* this ioapic is marked unusable */
+	if (ioa->io_apic_flags & 1 == 0)
+		return;
+	
+	if (io_apic_count++ > 0) {
+		/*
+		 * Multiple IO APIC's are currently not supported.
+		 */
+		return;
+	}
+	
+	map_page_to_frame((__address) ioa->io_apic, (__address) ioa->io_apic, PAGE_NOT_CACHEABLE, 0);
+	
+	io_apic = ioa->io_apic;
+}
+
+//#define MPSCT_VERBOSE
+void ct_io_intr_entry(struct __io_intr_entry *iointr)
+{
+#ifdef MPSCT_VERBOSE
+	switch (iointr->intr_type) {
+	    case 0: printf("INT"); break;
+	    case 1: printf("NMI"); break;
+	    case 2: printf("SMI"); break;
+	    case 3: printf("ExtINT"); break;
+	}
+	putchar(',');
+	switch (iointr->poel&3) {
+	    case 0: printf("bus-like"); break;
+	    case 1: printf("active high"); break;
+	    case 2: printf("reserved"); break;
+	    case 3: printf("active low"); break;
+	}
+	putchar(',');
+	switch ((iointr->poel>>2)&3) {
+	    case 0: printf("bus-like"); break;
+	    case 1: printf("edge-triggered"); break;
+	    case 2: printf("reserved"); break;
+	    case 3: printf("level-triggered"); break;
+	}
+	putchar(',');
+	printf("bus%d,irq%d", iointr->src_bus_id, iointr->src_bus_irq);
+	putchar(',');
+	printf("io_apic%d,pin%d", iointr->dst_io_apic_id, iointr->dst_io_apic_pin);
+	putchar('\n');	
+#endif
+}
+
+void ct_l_intr_entry(struct __l_intr_entry *lintr)
+{
+#ifdef MPSCT_VERBOSE
+	switch (lintr->intr_type) {
+	    case 0: printf("INT"); break;
+	    case 1: printf("NMI"); break;
+	    case 2: printf("SMI"); break;
+	    case 3: printf("ExtINT"); break;
+	}
+	putchar(',');
+	switch (lintr->poel&3) {
+	    case 0: printf("bus-like"); break;
+	    case 1: printf("active high"); break;
+	    case 2: printf("reserved"); break;
+	    case 3: printf("active low"); break;
+	}
+	putchar(',');
+	switch ((lintr->poel>>2)&3) {
+	    case 0: printf("bus-like"); break;
+	    case 1: printf("edge-triggered"); break;
+	    case 2: printf("reserved"); break;
+	    case 3: printf("level-triggered"); break;
+	}
+	putchar(',');
+	printf("bus%d,irq%d", lintr->src_bus_id, lintr->src_bus_irq);
+	putchar(',');
+	printf("l_apic%d,pin%d", lintr->dst_l_apic_id, lintr->dst_l_apic_pin);
+	putchar('\n');
+#endif
+}
+
+void ct_extended_entries(void)
+{
+	__u8 *ext = (__u8 *) ct + ct->base_table_length;
+	__u8 *cur;
+
+	for (cur = ext; cur < ext + ct->ext_table_length; cur += cur[CT_EXT_ENTRY_LEN]) {
+		switch (cur[CT_EXT_ENTRY_TYPE]) {
+			default:
+				printf("%L: skipping MP Configuration Table extended entry type %d\n", cur, cur[CT_EXT_ENTRY_TYPE]);
+				break;
+		}
+	}
+}
+
+/*
+ * Kernel thread for bringing up application processors. It becomes clear
+ * that we need an arrangement like this (AP's being initialized by a kernel
+ * thread), for a thread has its dedicated stack. (The stack used during the
+ * BSP initialization (prior the very first call to scheduler()) will be used
+ * as an initialization stack for each AP.)
+ */
+void kmp(void *arg)
+{
+	struct __processor_entry *pr;
+	__address src, dst;
+	__address frame;
+	int i;
+
+	waitq_initialize(&ap_completion_wq);
+
+	/*
+	 * Processor entries immediately follow the configuration table header.
+	 */
+	pr = processor_entries;
+
+	/*
+	 * Grab a frame and map its address to page 0. This is a hack which
+	 * accesses data in frame 0. Note that page 0 is not present because
+	 * of nil reference bug catching.
+	 */
+	frame = frame_alloc(FRAME_KA);
+	map_page_to_frame(frame,0,PAGE_CACHEABLE,0);
+
+	/*
+	 * Set the warm-reset vector to the real-mode address of 4K-aligned ap_boot()
+	 */
+	*((__u16 *) (frame + 0x467+0)) =  ((__address) ap_boot) >> 4;	/* segment */
+	*((__u16 *) (frame + 0x467+2)) =  0x0;	/* offset */
+	
+	/*
+	 * Give back the borrowed frame and restore identity mapping for it.
+	 */
+	map_page_to_frame(frame,frame,PAGE_CACHEABLE,0);
+	frame_free(frame);
+
+	/*
+	 * Save 0xa to address 0xf of the CMOS RAM.
+	 * BIOS will not do the POST after the INIT signal.
+	 */
+	outb(0x70,0xf);
+	outb(0x71,0xa);
+
+	cpu_priority_high();
+
+	pic_disable_irqs(0xffff);
+	apic_init();
+
+	for (i = 0; i < processor_entry_cnt; i++) {
+		struct descriptor *gdt_new;
+	
+		/*
+		 * Skip processors marked unusable.
+		 */
+		if (pr[i].cpu_flags & (1<<0) == 0)
+			continue;
+
+		/*
+		 * The bootstrap processor is already up.
+		 */
+		if (pr[i].cpu_flags & (1<<1))
+			continue;
+
+		if (pr[i].l_apic_id == l_apic_id()) {
+			printf("%L: bad processor entry #%d, will not send IPI to myself\n", &pr[i], i);
+			continue;
+		}
+		
+		/*
+		 * Prepare new GDT for CPU in question.
+		 */
+		if (!(gdt_new = (struct descriptor *) malloc(GDT_ITEMS*sizeof(struct descriptor))))
+			panic(PANIC "couldn't allocate memory for GDT\n");
+
+		memcopy(gdt, gdt_new, GDT_ITEMS*sizeof(struct descriptor));
+		gdtr.base = (__address) gdt_new;
+
+		if (l_apic_send_init_ipi(pr[i].l_apic_id)) {
+			/*
+		         * There may be just one AP being initialized at
+			 * the time. After it comes completely up, it is
+			 * supposed to wake us up.
+		         */
+			waitq_sleep(&ap_completion_wq);
+			cpu_priority_high();
+		}
+		else {
+			printf("INIT IPI for l_apic%d failed\n", pr[i].l_apic_id);
+		}
+	}
+
+	/*
+	 * Wakeup the kinit thread so that
+	 * system initialization can go on.
+	 */
+	waitq_wakeup(&kmp_completion_wq, WAKEUP_FIRST);
+}
+
+int mps_irq_to_pin(int irq)
+{
+	int i;
+	
+	for(i=0;i<io_intr_entry_cnt;i++) {
+		if (io_intr_entries[i].src_bus_irq == irq && io_intr_entries[i].intr_type == 0)
+			return io_intr_entries[i].dst_io_apic_pin;
+	}
+	
+	return -1;
+}
+
+#endif /* __SMP__ */
Index: arch/ia32/src/smp/smp.c
===================================================================
--- arch/ia32/src/smp/smp.c	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
+++ arch/ia32/src/smp/smp.c	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2005 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.
+ */
+
+#include <smp/smp.h>
+#include <arch/acpi/acpi.h>
+#include <arch/acpi/madt.h>
+#include <arch/smp/mps.h>
+#include <config.h>
+
+#ifdef __SMP__
+
+void smp_init(void)
+{
+	if (acpi_madt) {
+		acpi_madt_parse();
+	}
+	if (config.cpu_count == 1)
+		mps_init();
+}
+
+
+#endif /* __SMP__ */
Index: include/smp/smp.h
===================================================================
--- include/smp/smp.h	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
+++ include/smp/smp.h	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2005 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.
+ */
+
+#ifndef __SMP_H__
+#define __SMP_H__
+
+#ifdef __SMP__
+extern void smp_init(void);
+#else
+#define smp_init()	;
+#endif /* __SMP__ */
+
+#endif /* __SMP_H__ */
Index: src/Makefile
===================================================================
--- src/Makefile	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ src/Makefile	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -30,4 +30,8 @@
 ifdef DEBUG_SPINLOCK
 CFLAGS+=-D$(DEBUG_SPINLOCK)
+endif
+
+ifdef USERSPACE
+CFLAGS+=-D$(USERSPACE)
 endif
 
Index: src/Makefile.config
===================================================================
--- src/Makefile.config	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ src/Makefile.config	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -14,6 +14,9 @@
 DEBUG_SPINLOCK=DEBUG_SPINLOCK
 
+# Uncomment if you want to compile in userspace support
+#USERSPACE=__USERSPACE__
+
 # Uncomment if you want to run in the test mode
-TEST=__TEST__
+#TEST=__TEST__
 
 TEST_FILE=test.c
Index: src/main/kinit.c
===================================================================
--- src/main/kinit.c	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ src/main/kinit.c	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -43,5 +43,5 @@
 
 #ifdef __SMP__
-#include <arch/smp/mp.h>
+#include <arch/smp/mps.h>
 #endif /* __SMP__ */
 
@@ -115,4 +115,5 @@
 	cpu_priority_low();
 
+#ifdef __USERSPACE__
 	/*
 	 * Create the first user task.
@@ -139,4 +140,5 @@
 	
 	thread_ready(t);
+#endif /* __USERSPACE__ */
 
 #ifdef __TEST__
Index: src/main/main.c
===================================================================
--- src/main/main.c	(revision 10a2e2286c964c27a26a6a74e033a32fa0c92749)
+++ src/main/main.c	(revision ed0dd65c9dbd967fb298a751aace9d7aed3c3569)
@@ -42,6 +42,8 @@
 #ifdef __SMP__
 #include <arch/smp/apic.h>
-#include <arch/smp/mp.h>
+#include <arch/smp/mps.h>
 #endif /* __SMP__ */
+
+#include <smp/smp.h>
 
 #include <mm/frame.h>
@@ -118,4 +120,5 @@
 	arch_late_init();
 	
+	smp_init();
 	printf("config.cpu_count=%d\n", config.cpu_count);
 
