Index: trunk/hal/x86_64/core/hal_apic.c
===================================================================
--- trunk/hal/x86_64/core/hal_apic.c	(revision 202)
+++ trunk/hal/x86_64/core/hal_apic.c	(revision 203)
@@ -268,19 +268,37 @@
 }
 
-void hal_ioapic_disable_entry(uint8_t index)
-{
-	const uint64_t data = IOREDTBL_MSK;
-
-	hal_ioapic_write(IOREDTBL + index * 2, (uint32_t)(data & 0xFFFFFFFF));
-	hal_ioapic_write(IOREDTBL + index * 2 + 1, (uint32_t)(data >> 32));
-}
-
-void hal_ioapic_set_entry(uint8_t index, uint8_t vec, uint8_t dest)
+void hal_ioapic_bind_irq(uint8_t irq, uint8_t vec, uint8_t dest)
 {
 	const uint64_t data = ((uint64_t)dest << IOREDTBL_DES_SHIFT) |
-	    IOREDTBL_DEM_PHYS | IOREDTBL_DEL_FIXED | vec;
-
-	hal_ioapic_write(IOREDTBL + index * 2, (uint32_t)(data & 0xFFFFFFFF));
-	hal_ioapic_write(IOREDTBL + index * 2 + 1, (uint32_t)(data >> 32));
+	    IOREDTBL_DEM_PHYS | IOREDTBL_DEL_FIXED | IOREDTBL_MSK | vec;
+
+	hal_ioapic_write(IOREDTBL + irq * 2, (uint32_t)(data & 0xFFFFFFFF));
+	hal_ioapic_write(IOREDTBL + irq * 2 + 1, (uint32_t)(data >> 32));
+}
+
+void hal_ioapic_enable_irq(uint8_t irq)
+{
+	uint32_t data[2];
+
+	data[0] = hal_ioapic_read(IOREDTBL + irq * 2);
+	data[1] = hal_ioapic_read(IOREDTBL + irq * 2 + 1);
+
+	data[0] &= ~IOREDTBL_MSK;
+
+	hal_ioapic_write(IOREDTBL + irq * 2, data[0]);
+	hal_ioapic_write(IOREDTBL + irq * 2 + 1, data[1]);
+}
+
+void hal_ioapic_disable_irq(uint8_t irq)
+{
+	uint32_t data[2];
+
+	data[0] = hal_ioapic_read(IOREDTBL + irq * 2);
+	data[1] = hal_ioapic_read(IOREDTBL + irq * 2 + 1);
+
+	data[0] |= IOREDTBL_MSK;
+
+	hal_ioapic_write(IOREDTBL + irq * 2, data[0]);
+	hal_ioapic_write(IOREDTBL + irq * 2 + 1, data[1]);
 }
 
@@ -295,5 +313,5 @@
 	/* Explicitly disable (mask) each vector */
 	for (i = 0; i < ioapic_pins; i++) {
-		hal_ioapic_disable_entry(i);
+		hal_ioapic_disable_irq(i);
 	}
 
@@ -301,6 +319,8 @@
 
 	/* Now, enable the com1 port and the keyboard */
-	hal_ioapic_set_entry(IRQ_COM1, IOAPIC_COM1_VECTOR, 0);
-	hal_ioapic_set_entry(IRQ_KEYBOARD, IOAPIC_KEYBOARD_VECTOR, 0);
+	hal_ioapic_bind_irq(IRQ_COM1, IOAPIC_COM1_VECTOR, 0);
+	hal_ioapic_enable_irq(IRQ_COM1);
+	hal_ioapic_bind_irq(IRQ_KEYBOARD, IOAPIC_KEYBOARD_VECTOR, 0);
+	hal_ioapic_enable_irq(IRQ_KEYBOARD);
 }
 
Index: trunk/hal/x86_64/core/hal_apic.h
===================================================================
--- trunk/hal/x86_64/core/hal_apic.h	(revision 202)
+++ trunk/hal/x86_64/core/hal_apic.h	(revision 203)
@@ -25,6 +25,10 @@
 void hal_com_init_early();
 
-void hal_ioapic_disable_entry(uint8_t index);
-void hal_ioapic_set_entry(uint8_t index, uint8_t vec, uint8_t dest);
+void hal_ioapic_bind_irq(uint8_t irq, uint8_t vec, uint8_t dest);
+void hal_ioapic_enable_irq(uint8_t irq);
+void hal_ioapic_disable_irq(uint8_t irq);
+
+void hal_ioapic_disable_entry(uint8_t irq);
+void hal_ioapic_set_entry(uint8_t irq, uint8_t vec, uint8_t dest);
 
 uint32_t hal_lapic_gid();
Index: trunk/hal/x86_64/core/hal_init.c
===================================================================
--- trunk/hal/x86_64/core/hal_init.c	(revision 202)
+++ trunk/hal/x86_64/core/hal_init.c	(revision 203)
@@ -419,4 +419,29 @@
 /* -------------------------------------------------------------------------- */
 
+struct {
+	bool_t busy[256];
+} idt_bitmap __in_kdata;
+
+int idt_slot_alloc()
+{
+	size_t i;
+
+	for (i = 0; i < 256; i++) {
+		if (!idt_bitmap.busy[i])
+			break;
+	}
+	if (i == 256) {
+		return -1;
+	}
+
+	idt_bitmap.busy[i] = true;
+	return (int)i;
+}
+
+void idt_slot_free(int slot)
+{
+	idt_bitmap.busy[slot] = false;
+}
+
 static void
 idt_set_seg(struct idt_seg *seg, void *func, int ist, int type, int dpl, int sel)
@@ -441,4 +466,5 @@
 	size_t i;
 
+	memset(&idt_bitmap, 0, sizeof(idt_bitmap));
 	idt = (struct idt_seg *)&idtstore;
 
@@ -453,4 +479,5 @@
 		idt_set_seg(&idt[i], (void *)x86_traps[i - CPUVEC_MIN], 0,
 		    SDT_SYS386IGT, SEL_KPL, GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL));
+		idt_bitmap.busy[i] = true;
 	}
 
@@ -459,4 +486,5 @@
 		idt_set_seg(&idt[i], (void *)x86_intrs[i - DYNVEC_MIN], 0,
 		    SDT_SYS386IGT, SEL_KPL, GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL));
+		idt_bitmap.busy[i] = true;
 	}
 }
Index: trunk/hal/x86_64/core/hal_internal.h
===================================================================
--- trunk/hal/x86_64/core/hal_internal.h	(revision 202)
+++ trunk/hal/x86_64/core/hal_internal.h	(revision 203)
@@ -30,4 +30,8 @@
 		x86_panic((char *)__func__); \
 	}
+
+/* hal_init.c */
+int idt_slot_alloc();
+void idt_slot_free(int slot);
 
 /* hal_cpu.S */
Index: trunk/hal/x86_64/core/hal_kentry.S
===================================================================
--- trunk/hal/x86_64/core/hal_kentry.S	(revision 202)
+++ trunk/hal/x86_64/core/hal_kentry.S	(revision 203)
@@ -172,48 +172,4 @@
 	addq	$16,%rsp
 	iretq
-
-	/*
-	 * The XCU interrupt entries.
-	 */
-
-#define XCU_WTI_ENTRY(n) 		\
-ASM_ENTRY(x86_xcu_wti_ ## n)		\
-	pushq	$0		;	\
-	pushq	$T_ASTFLT	;	\
-	INTR_SAVE_REGS		;	\
-				;	\
-	call	hal_do_interrupt;	\
-				;	\
-	INTR_RESTORE_REGS	;	\
-	addq	$16,%rsp	;	\
-	iretq
-
-#define XCU_HWI_ENTRY(n) 		\
-ASM_ENTRY(x86_xcu_hwi_ ## n)		\
-	pushq	$0		;	\
-	pushq	$T_ASTFLT	;	\
-	INTR_SAVE_REGS		;	\
-				;	\
-	call	hal_do_interrupt;	\
-				;	\
-	INTR_RESTORE_REGS	;	\
-	addq	$16,%rsp	;	\
-	iretq
-
-#define XCU_PTI_ENTRY(n) 		\
-ASM_ENTRY(x86_xcu_pti_ ## n)		\
-	pushq	$0		;	\
-	pushq	$T_ASTFLT	;	\
-	INTR_SAVE_REGS		;	\
-				;	\
-	call	hal_do_interrupt;	\
-				;	\
-	INTR_RESTORE_REGS	;	\
-	addq	$16,%rsp	;	\
-	iretq
-
-XCU_WTI_ENTRY(0)
-XCU_HWI_ENTRY(0)
-XCU_PTI_ENTRY(0)
 
 /*
@@ -259,8 +215,4 @@
 x86_intrs:
 	.quad	x86_lapic_spurious
-	.quad	x86_xcu_wti_0
-	.quad	x86_xcu_hwi_0
-	.quad	x86_xcu_pti_0
-
 	.quad	x86_lapic_timer
 	.quad	x86_ioapic_com1
Index: trunk/hal/x86_64/core/hal_segmentation.h
===================================================================
--- trunk/hal/x86_64/core/hal_segmentation.h	(revision 202)
+++ trunk/hal/x86_64/core/hal_segmentation.h	(revision 203)
@@ -205,18 +205,14 @@
 #define CPUVEC_MAX	32	/* reserved entries for CPU exceptions */
 
-#define DYNVEC_MIN	CPUVEC_MAX
-#define DYNVEC_MAX	(DYNVEC_MIN + 7)
+#define DYNVEC_MIN	(CPUVEC_MAX + 0)
+#define DYNVEC_MAX	(CPUVEC_MAX + 4)
 
 #define VECTOR_APIC_SPURIOU	(DYNVEC_MIN + 0)
-#define VECTOR_APIC_XCU_WTI	(DYNVEC_MIN + 1)
-#define VECTOR_APIC_XCU_HWI	(DYNVEC_MIN + 2)
-#define VECTOR_APIC_XCU_PTI	(DYNVEC_MIN + 3)
 
 /* debug only, will be moved soon */
-#define LAPIC_TIMER_VECTOR	(DYNVEC_MIN + 4)
-#define IOAPIC_COM1_VECTOR	(DYNVEC_MIN + 5)
-#define IOAPIC_KEYBOARD_VECTOR	(DYNVEC_MIN + 6)
+#define LAPIC_TIMER_VECTOR	(DYNVEC_MIN + 1)
+#define IOAPIC_COM1_VECTOR	(DYNVEC_MIN + 2)
+#define IOAPIC_KEYBOARD_VECTOR	(DYNVEC_MIN + 3)
 
 #define NIDT	256	/* total number of IDT entries */
 
-
