Index: kernel/arch/amd64/include/arch.h
===================================================================
--- kernel/arch/amd64/include/arch.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,45 +1,0 @@
-/*
- * Copyright (c) 2005 Ondrej Palkovsky
- * 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 amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_ARCH_H_
-#define KERN_amd64_ARCH_H_
-
-#include <genarch/multiboot/multiboot.h>
-
-extern void arch_pre_main(uint32_t, void *);
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/arch/arch.h
===================================================================
--- kernel/arch/amd64/include/arch/arch.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/arch.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2005 Ondrej Palkovsky
+ * 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 amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_ARCH_H_
+#define KERN_amd64_ARCH_H_
+
+#include <genarch/multiboot/multiboot.h>
+
+extern void arch_pre_main(uint32_t, void *);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/asm.h
===================================================================
--- kernel/arch/amd64/include/arch/asm.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/asm.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,525 @@
+/*
+ * 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.
+ */
+
+/** @addtogroup amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_ASM_H_
+#define KERN_amd64_ASM_H_
+
+#include <config.h>
+#include <typedefs.h>
+#include <arch/cpu.h>
+#include <trace.h>
+
+#define IO_SPACE_BOUNDARY	((void *) (64 * 1024))
+
+/** Return base address of current stack.
+ *
+ * Return the base address of the current stack.
+ * The stack is assumed to be STACK_SIZE bytes long.
+ * The stack must start on page boundary.
+ *
+ */
+NO_TRACE static inline uintptr_t get_stack_base(void)
+{
+	uintptr_t v;
+	
+	asm volatile (
+		"andq %%rsp, %[v]\n"
+		: [v] "=r" (v)
+		: "0" (~((uint64_t) STACK_SIZE - 1))
+	);
+	
+	return v;
+}
+
+NO_TRACE static inline void cpu_sleep(void)
+{
+	asm volatile (
+		"hlt\n"
+	);
+}
+
+NO_TRACE static inline void __attribute__((noreturn)) cpu_halt(void)
+{
+	while (true) {
+		asm volatile (
+			"hlt\n"
+		);
+	}
+}
+
+/** Byte from port
+ *
+ * Get byte from port
+ *
+ * @param port Port to read from
+ * @return Value read
+ *
+ */
+NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port)
+{
+	if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
+		uint8_t val;
+		
+		asm volatile (
+			"inb %w[port], %b[val]\n"
+			: [val] "=a" (val)
+			: [port] "d" (port)
+		);
+		
+		return val;
+	} else
+		return (uint8_t) *port;
+}
+
+/** Word from port
+ *
+ * Get word from port
+ *
+ * @param port Port to read from
+ * @return Value read
+ *
+ */
+NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port)
+{
+	if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
+		uint16_t val;
+		
+		asm volatile (
+			"inw %w[port], %w[val]\n"
+			: [val] "=a" (val)
+			: [port] "d" (port)
+		);
+		
+		return val;
+	} else
+		return (uint16_t) *port;
+}
+
+/** Double word from port
+ *
+ * Get double word from port
+ *
+ * @param port Port to read from
+ * @return Value read
+ *
+ */
+NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port)
+{
+	if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
+		uint32_t val;
+		
+		asm volatile (
+			"inl %w[port], %[val]\n"
+			: [val] "=a" (val)
+			: [port] "d" (port)
+		);
+		
+		return val;
+	} else
+		return (uint32_t) *port;
+}
+
+/** Byte to port
+ *
+ * Output byte to port
+ *
+ * @param port Port to write to
+ * @param val Value to write
+ *
+ */
+NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t val)
+{
+	if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
+		asm volatile (
+			"outb %b[val], %w[port]\n"
+			:: [val] "a" (val), [port] "d" (port)
+		);	
+	} else
+		*port = val;
+}
+
+/** Word to port
+ *
+ * Output word to port
+ *
+ * @param port Port to write to
+ * @param val Value to write
+ *
+ */
+NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t val)
+{
+	if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
+		asm volatile (
+			"outw %w[val], %w[port]\n"
+			:: [val] "a" (val), [port] "d" (port)
+		);
+	} else
+		*port = val;
+}
+
+/** Double word to port
+ *
+ * Output double word to port
+ *
+ * @param port Port to write to
+ * @param val Value to write
+ *
+ */
+NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t val)
+{
+	if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
+		asm volatile (
+			"outl %[val], %w[port]\n"
+			:: [val] "a" (val), [port] "d" (port)
+		);
+	} else
+		*port = val;
+}
+
+/** Swap Hidden part of GS register with visible one */
+NO_TRACE static inline void swapgs(void)
+{
+	asm volatile (
+		"swapgs"
+	);
+}
+
+/** Enable interrupts.
+ *
+ * Enable interrupts and return previous
+ * value of EFLAGS.
+ *
+ * @return Old interrupt priority level.
+ *
+ */
+NO_TRACE static inline ipl_t interrupts_enable(void) {
+	ipl_t v;
+	
+	asm volatile (
+		"pushfq\n"
+		"popq %[v]\n"
+		"sti\n"
+		: [v] "=r" (v)
+	);
+	
+	return v;
+}
+
+/** Disable interrupts.
+ *
+ * Disable interrupts and return previous
+ * value of EFLAGS.
+ *
+ * @return Old interrupt priority level.
+ *
+ */
+NO_TRACE static inline ipl_t interrupts_disable(void) {
+	ipl_t v;
+	
+	asm volatile (
+		"pushfq\n"
+		"popq %[v]\n"
+		"cli\n"
+		: [v] "=r" (v)
+	);
+	
+	return v;
+}
+
+/** Restore interrupt priority level.
+ *
+ * Restore EFLAGS.
+ *
+ * @param ipl Saved interrupt priority level.
+ *
+ */
+NO_TRACE static inline void interrupts_restore(ipl_t ipl) {
+	asm volatile (
+		"pushq %[ipl]\n"
+		"popfq\n"
+		:: [ipl] "r" (ipl)
+	);
+}
+
+/** Return interrupt priority level.
+ *
+ * Return EFLAFS.
+ *
+ * @return Current interrupt priority level.
+ *
+ */
+NO_TRACE static inline ipl_t interrupts_read(void) {
+	ipl_t v;
+	
+	asm volatile (
+		"pushfq\n"
+		"popq %[v]\n"
+		: [v] "=r" (v)
+	);
+	
+	return v;
+}
+
+/** Check interrupts state.
+ *
+ * @return True if interrupts are disabled.
+ *
+ */
+NO_TRACE static inline bool interrupts_disabled(void)
+{
+	ipl_t v;
+	
+	asm volatile (
+		"pushfq\n"
+		"popq %[v]\n"
+		: [v] "=r" (v)
+	);
+	
+	return ((v & RFLAGS_IF) == 0);
+}
+
+/** Write to MSR */
+NO_TRACE static inline void write_msr(uint32_t msr, uint64_t value)
+{
+	asm volatile (
+		"wrmsr\n"
+		:: "c" (msr),
+		   "a" ((uint32_t) (value)),
+		   "d" ((uint32_t) (value >> 32))
+	);
+}
+
+NO_TRACE static inline sysarg_t read_msr(uint32_t msr)
+{
+	uint32_t ax, dx;
+	
+	asm volatile (
+		"rdmsr\n"
+		: "=a" (ax), "=d" (dx)
+		: "c" (msr)
+	);
+	
+	return ((uint64_t) dx << 32) | ax;
+}
+
+/** Enable local APIC
+ *
+ * Enable local APIC in MSR.
+ *
+ */
+NO_TRACE static inline void enable_l_apic_in_msr()
+{
+	asm volatile (
+		"movl $0x1b, %%ecx\n"
+		"rdmsr\n"
+		"orl $(1 << 11),%%eax\n"
+		"orl $(0xfee00000),%%eax\n"
+		"wrmsr\n"
+		::: "%eax", "%ecx", "%edx"
+	);
+}
+
+/** Invalidate TLB Entry.
+ *
+ * @param addr Address on a page whose TLB entry is to be invalidated.
+ *
+ */
+NO_TRACE static inline void invlpg(uintptr_t addr)
+{
+	asm volatile (
+		"invlpg %[addr]\n"
+		:: [addr] "m" (*((sysarg_t *) addr))
+	);
+}
+
+/** Load GDTR register from memory.
+ *
+ * @param gdtr_reg Address of memory from where to load GDTR.
+ *
+ */
+NO_TRACE static inline void gdtr_load(ptr_16_64_t *gdtr_reg)
+{
+	asm volatile (
+		"lgdtq %[gdtr_reg]\n"
+		:: [gdtr_reg] "m" (*gdtr_reg)
+	);
+}
+
+/** Store GDTR register to memory.
+ *
+ * @param gdtr_reg Address of memory to where to load GDTR.
+ *
+ */
+NO_TRACE static inline void gdtr_store(ptr_16_64_t *gdtr_reg)
+{
+	asm volatile (
+		"sgdtq %[gdtr_reg]\n"
+		:: [gdtr_reg] "m" (*gdtr_reg)
+	);
+}
+
+/** Load IDTR register from memory.
+ *
+ * @param idtr_reg Address of memory from where to load IDTR.
+ *
+ */
+NO_TRACE static inline void idtr_load(ptr_16_64_t *idtr_reg)
+{
+	asm volatile (
+		"lidtq %[idtr_reg]\n"
+		:: [idtr_reg] "m" (*idtr_reg));
+}
+
+/** Load TR from descriptor table.
+ *
+ * @param sel Selector specifying descriptor of TSS segment.
+ *
+ */
+NO_TRACE static inline void tr_load(uint16_t sel)
+{
+	asm volatile (
+		"ltr %[sel]"
+		:: [sel] "r" (sel)
+	);
+}
+
+#define GEN_READ_REG(reg) NO_TRACE static inline sysarg_t read_ ##reg (void) \
+	{ \
+		sysarg_t res; \
+		asm volatile ( \
+			"movq %%" #reg ", %[res]" \
+			: [res] "=r" (res) \
+		); \
+		return res; \
+	}
+
+#define GEN_WRITE_REG(reg) NO_TRACE static inline void write_ ##reg (sysarg_t regn) \
+	{ \
+		asm volatile ( \
+			"movq %[regn], %%" #reg \
+			:: [regn] "r" (regn) \
+		); \
+	}
+
+GEN_READ_REG(cr0)
+GEN_READ_REG(cr2)
+GEN_READ_REG(cr3)
+GEN_WRITE_REG(cr3)
+
+GEN_READ_REG(dr0)
+GEN_READ_REG(dr1)
+GEN_READ_REG(dr2)
+GEN_READ_REG(dr3)
+GEN_READ_REG(dr6)
+GEN_READ_REG(dr7)
+
+GEN_WRITE_REG(dr0)
+GEN_WRITE_REG(dr1)
+GEN_WRITE_REG(dr2)
+GEN_WRITE_REG(dr3)
+GEN_WRITE_REG(dr6)
+GEN_WRITE_REG(dr7)
+
+extern void asm_delay_loop(uint32_t);
+extern void asm_fake_loop(uint32_t);
+
+extern uintptr_t int_0;
+extern uintptr_t int_1;
+extern uintptr_t int_2;
+extern uintptr_t int_3;
+extern uintptr_t int_4;
+extern uintptr_t int_5;
+extern uintptr_t int_6;
+extern uintptr_t int_7;
+extern uintptr_t int_8;
+extern uintptr_t int_9;
+extern uintptr_t int_10;
+extern uintptr_t int_11;
+extern uintptr_t int_12;
+extern uintptr_t int_13;
+extern uintptr_t int_14;
+extern uintptr_t int_15;
+extern uintptr_t int_16;
+extern uintptr_t int_17;
+extern uintptr_t int_18;
+extern uintptr_t int_19;
+extern uintptr_t int_20;
+extern uintptr_t int_21;
+extern uintptr_t int_22;
+extern uintptr_t int_23;
+extern uintptr_t int_24;
+extern uintptr_t int_25;
+extern uintptr_t int_26;
+extern uintptr_t int_27;
+extern uintptr_t int_28;
+extern uintptr_t int_29;
+extern uintptr_t int_30;
+extern uintptr_t int_31;
+extern uintptr_t int_32;
+extern uintptr_t int_33;
+extern uintptr_t int_34;
+extern uintptr_t int_35;
+extern uintptr_t int_36;
+extern uintptr_t int_37;
+extern uintptr_t int_38;
+extern uintptr_t int_39;
+extern uintptr_t int_40;
+extern uintptr_t int_41;
+extern uintptr_t int_42;
+extern uintptr_t int_43;
+extern uintptr_t int_44;
+extern uintptr_t int_45;
+extern uintptr_t int_46;
+extern uintptr_t int_47;
+extern uintptr_t int_48;
+extern uintptr_t int_49;
+extern uintptr_t int_50;
+extern uintptr_t int_51;
+extern uintptr_t int_52;
+extern uintptr_t int_53;
+extern uintptr_t int_54;
+extern uintptr_t int_55;
+extern uintptr_t int_56;
+extern uintptr_t int_57;
+extern uintptr_t int_58;
+extern uintptr_t int_59;
+extern uintptr_t int_60;
+extern uintptr_t int_61;
+extern uintptr_t int_62;
+extern uintptr_t int_63;
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/atomic.h
===================================================================
--- kernel/arch/amd64/include/arch/atomic.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/atomic.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ */
+
+/** @addtogroup amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_ATOMIC_H_
+#define KERN_amd64_ATOMIC_H_
+
+#include <typedefs.h>
+#include <arch/barrier.h>
+#include <preemption.h>
+#include <trace.h>
+
+NO_TRACE static inline void atomic_inc(atomic_t *val)
+{
+#ifdef CONFIG_SMP
+	asm volatile (
+		"lock incq %[count]\n"
+		: [count] "+m" (val->count)
+	);
+#else
+	asm volatile (
+		"incq %[count]\n"
+		: [count] "+m" (val->count)
+	);
+#endif /* CONFIG_SMP */
+}
+
+NO_TRACE static inline void atomic_dec(atomic_t *val)
+{
+#ifdef CONFIG_SMP
+	asm volatile (
+		"lock decq %[count]\n"
+		: [count] "+m" (val->count)
+	);
+#else
+	asm volatile (
+		"decq %[count]\n"
+		: [count] "+m" (val->count)
+	);
+#endif /* CONFIG_SMP */
+}
+
+NO_TRACE static inline atomic_count_t atomic_postinc(atomic_t *val)
+{
+	atomic_count_t r = 1;
+	
+	asm volatile (
+		"lock xaddq %[r], %[count]\n"
+		: [count] "+m" (val->count),
+		  [r] "+r" (r)
+	);
+	
+	return r;
+}
+
+NO_TRACE static inline atomic_count_t atomic_postdec(atomic_t *val)
+{
+	atomic_count_t r = -1;
+	
+	asm volatile (
+		"lock xaddq %[r], %[count]\n"
+		: [count] "+m" (val->count),
+		  [r] "+r" (r)
+	);
+	
+	return r;
+}
+
+#define atomic_preinc(val)  (atomic_postinc(val) + 1)
+#define atomic_predec(val)  (atomic_postdec(val) - 1)
+
+NO_TRACE static inline atomic_count_t test_and_set(atomic_t *val)
+{
+	atomic_count_t v = 1;
+	
+	asm volatile (
+		"xchgq %[v], %[count]\n"
+		: [v] "+r" (v),
+		  [count] "+m" (val->count)
+	);
+	
+	return v;
+}
+
+/** amd64 specific fast spinlock */
+NO_TRACE static inline void atomic_lock_arch(atomic_t *val)
+{
+	atomic_count_t tmp;
+	
+	preemption_disable();
+	asm volatile (
+		"0:\n"
+		"	pause\n"
+		"	mov %[count], %[tmp]\n"
+		"	testq %[tmp], %[tmp]\n"
+		"	jnz 0b\n"       /* lightweight looping on locked spinlock */
+		
+		"	incq %[tmp]\n"  /* now use the atomic operation */
+		"	xchgq %[count], %[tmp]\n"
+		"	testq %[tmp], %[tmp]\n"
+		"	jnz 0b\n"
+		: [count] "+m" (val->count),
+		  [tmp] "=&r" (tmp)
+	);
+	
+	/*
+	 * Prevent critical section code from bleeding out this way up.
+	 */
+	CS_ENTER_BARRIER();
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/barrier.h
===================================================================
--- kernel/arch/amd64/include/arch/barrier.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/barrier.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,1 @@
+../../../ia32/include/arch/barrier.h
Index: kernel/arch/amd64/include/arch/bios
===================================================================
--- kernel/arch/amd64/include/arch/bios	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/bios	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,1 @@
+../../../ia32/include/arch/bios
Index: kernel/arch/amd64/include/arch/boot/boot.h
===================================================================
--- kernel/arch/amd64/include/arch/boot/boot.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/boot/boot.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2005 Ondrej Palkovsky
+ * 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 amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_BOOT_H_
+#define KERN_amd64_BOOT_H_
+
+#define BOOT_OFFSET      0x108000
+#define AP_BOOT_OFFSET   0x008000
+#define BOOT_STACK_SIZE  0x000400
+
+#ifndef __ASM__
+
+#ifdef CONFIG_SMP
+
+/* This is only a symbol so the type is dummy. Obtain the value using &. */
+extern int _hardcoded_unmapped_size;
+
+#endif /* CONFIG_SMP */
+
+#endif /* __ASM__ */
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/boot/memmap.h
===================================================================
--- kernel/arch/amd64/include/arch/boot/memmap.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/boot/memmap.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,1 @@
+../../../../ia32/include/arch/boot/memmap.h
Index: kernel/arch/amd64/include/arch/context.h
===================================================================
--- kernel/arch/amd64/include/arch/context.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/context.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2005 Ondrej Palkovsky
+ * 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 amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_CONTEXT_H_
+#define KERN_amd64_CONTEXT_H_
+
+#include <typedefs.h>
+
+/*
+ * According to ABI the stack MUST be aligned on
+ * 16-byte boundary. If it is not, the va_arg calling will
+ * panic sooner or later
+ */
+#define SP_DELTA  16
+
+#define context_set(c, _pc, stack, size) \
+	do { \
+		(c)->pc = (uintptr_t) (_pc); \
+		(c)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \
+		(c)->rbp = 0; \
+	} while (0)
+
+/* We include only registers that must be preserved
+ * during function call
+ */
+typedef struct {
+	uintptr_t sp;
+	uintptr_t pc;
+	
+	uint64_t rbx;
+	uint64_t rbp;
+	
+	uint64_t r12;
+	uint64_t r13;
+	uint64_t r14;
+	uint64_t r15;
+	
+	ipl_t ipl;
+} __attribute__ ((packed)) context_t;
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/context_offset.h
===================================================================
--- kernel/arch/amd64/include/arch/context_offset.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/context_offset.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2005 Ondrej Palkovsky
+ * 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 KERN_amd64_CONTEXT_OFFSET_H_
+#define KERN_amd64_CONTEXT_OFFSET_H_
+
+#define OFFSET_SP   0x00
+#define OFFSET_PC   0x08
+#define OFFSET_RBX  0x10
+#define OFFSET_RBP  0x18
+#define OFFSET_R12  0x20
+#define OFFSET_R13  0x28
+#define OFFSET_R14  0x30
+#define OFFSET_R15  0x38
+
+#ifdef KERNEL
+	#define OFFSET_IPL  0x40
+#else
+	#define OFFSET_TLS  0x40
+#endif
+
+#ifdef __ASM__
+
+# ctx: address of the structure with saved context
+# pc: return address
+.macro CONTEXT_SAVE_ARCH_CORE ctx:req pc:req
+	movq \pc, OFFSET_PC(\ctx)
+	movq %rsp, OFFSET_SP(\ctx)
+	
+	movq %rbx, OFFSET_RBX(\ctx)
+	movq %rbp, OFFSET_RBP(\ctx)
+	movq %r12, OFFSET_R12(\ctx)
+	movq %r13, OFFSET_R13(\ctx)
+	movq %r14, OFFSET_R14(\ctx)
+	movq %r15, OFFSET_R15(\ctx)
+.endm
+
+# ctx: address of the structure with saved context
+.macro CONTEXT_RESTORE_ARCH_CORE ctx:req pc:req
+	movq OFFSET_R15(\ctx), %r15
+	movq OFFSET_R14(\ctx), %r14
+	movq OFFSET_R13(\ctx), %r13
+	movq OFFSET_R12(\ctx), %r12
+	movq OFFSET_RBP(\ctx), %rbp
+	movq OFFSET_RBX(\ctx), %rbx
+	
+	movq OFFSET_SP(\ctx), %rsp   # ctx->sp -> %rsp
+	
+	movq OFFSET_PC(\ctx), \pc
+.endm
+
+#endif
+
+#endif
Index: kernel/arch/amd64/include/arch/cpu.h
===================================================================
--- kernel/arch/amd64/include/arch/cpu.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/cpu.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+/** @addtogroup amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_CPU_H_
+#define KERN_amd64_CPU_H_
+
+#define RFLAGS_CF  (1 << 0)
+#define RFLAGS_PF  (1 << 2)
+#define RFLAGS_AF  (1 << 4)
+#define RFLAGS_ZF  (1 << 6)
+#define RFLAGS_SF  (1 << 7)
+#define RFLAGS_TF  (1 << 8)
+#define RFLAGS_IF  (1 << 9)
+#define RFLAGS_DF  (1 << 10)
+#define RFLAGS_OF  (1 << 11)
+#define RFLAGS_NT  (1 << 14)
+#define RFLAGS_RF  (1 << 16)
+
+#define EFER_MSR_NUM    0xc0000080
+#define AMD_SCE_FLAG    0
+#define AMD_LME_FLAG    8
+#define AMD_LMA_FLAG    10
+#define AMD_FFXSR_FLAG  14
+#define AMD_NXE_FLAG    11
+
+/* MSR registers */
+#define AMD_MSR_STAR    0xc0000081
+#define AMD_MSR_LSTAR   0xc0000082
+#define AMD_MSR_SFMASK  0xc0000084
+#define AMD_MSR_FS      0xc0000100
+#define AMD_MSR_GS      0xc0000101
+
+#ifndef __ASM__
+
+#include <arch/pm.h>
+
+typedef struct {
+	int vendor;
+	int family;
+	int model;
+	int stepping;
+	tss_t *tss;
+	
+	size_t iomapver_copy;  /** Copy of TASK's I/O Permission bitmap generation count. */
+} cpu_arch_t;
+
+struct star_msr {
+};
+
+struct lstar_msr {
+};
+
+extern void set_efer_flag(int flag);
+extern uint64_t read_efer_flag(void);
+void cpu_setup_fpu(void);
+
+#endif /* __ASM__ */
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/cpuid.h
===================================================================
--- kernel/arch/amd64/include/arch/cpuid.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/cpuid.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2001-2004 Ondrej Palkovsky
+ * 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 amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_CPUID_H_
+#define KERN_amd64_CPUID_H_
+
+#define AMD_CPUID_EXTENDED  0x80000001
+#define AMD_EXT_NOEXECUTE   20
+#define AMD_EXT_LONG_MODE   29
+
+#define INTEL_CPUID_LEVEL     0x00000000
+#define INTEL_CPUID_STANDARD  0x00000001
+#define INTEL_CPUID_EXTENDED  0x80000000
+#define INTEL_SSE2            26
+#define INTEL_FXSAVE          24
+
+#ifndef __ASM__
+
+#include <typedefs.h>
+
+typedef struct {
+	uint32_t cpuid_eax;
+	uint32_t cpuid_ebx;
+	uint32_t cpuid_ecx;
+	uint32_t cpuid_edx;
+} __attribute__ ((packed)) cpu_info_t;
+
+extern int has_cpuid(void);
+
+extern void cpuid(uint32_t cmd, cpu_info_t *info);
+
+#endif /* !def __ASM__ */
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/cycle.h
===================================================================
--- kernel/arch/amd64/include/arch/cycle.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/cycle.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2006 Martin Decky
+ * 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 amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_CYCLE_H_
+#define KERN_amd64_CYCLE_H_
+
+#include <trace.h>
+
+NO_TRACE static inline uint64_t get_cycle(void)
+{
+	uint32_t lower;
+	uint32_t upper;
+	
+	asm volatile (
+		"rdtsc\n"
+		: "=a" (lower),
+		  "=d" (upper)
+	);
+	
+	return ((uint64_t) lower) | (((uint64_t) upper) << 32);
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/ddi/ddi.h
===================================================================
--- kernel/arch/amd64/include/arch/ddi/ddi.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/ddi/ddi.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -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 amd64ddi
+ * @{
+ */
+
+/**
+ * @file
+ * @brief amd64 specific DDI declarations and macros.
+ */
+
+#ifndef KERN_amd64_DDI_H_
+#define KERN_amd64_DDI_H_
+
+extern void io_perm_bitmap_install(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/drivers
===================================================================
--- kernel/arch/amd64/include/arch/drivers	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/drivers	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,1 @@
+../../../ia32/include/arch/drivers
Index: kernel/arch/amd64/include/arch/elf.h
===================================================================
--- kernel/arch/amd64/include/arch/elf.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/elf.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2006 Sergey Bondari
+ * 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 amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_ELF_H_
+#define KERN_amd64_ELF_H_
+
+#define ELF_MACHINE        EM_X86_64
+#define ELF_DATA_ENCODING  ELFDATA2LSB
+#define ELF_CLASS          ELFCLASS64
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/faddr.h
===================================================================
--- kernel/arch/amd64/include/arch/faddr.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/faddr.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2005 Ondrej Palkovsky
+ * 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 amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_FADDR_H_
+#define KERN_amd64_FADDR_H_
+
+#include <typedefs.h>
+
+#define FADDR(fptr)  ((uintptr_t) (fptr))
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/fpu_context.h
===================================================================
--- kernel/arch/amd64/include/arch/fpu_context.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/fpu_context.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,1 @@
+../../../ia32/include/arch/fpu_context.h
Index: kernel/arch/amd64/include/arch/interrupt.h
===================================================================
--- kernel/arch/amd64/include/arch/interrupt.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/interrupt.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+
+/** @addtogroup amd64interrupt
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_INTERRUPT_H_
+#define KERN_amd64_INTERRUPT_H_
+
+#include <typedefs.h>
+#include <arch/istate.h>
+#include <arch/pm.h>
+
+#define IVT_ITEMS  IDT_ITEMS
+#define IVT_FIRST  0
+
+#define EXC_COUNT  32
+#define IRQ_COUNT  16
+
+#define IVT_EXCBASE   0
+#define IVT_IRQBASE   (IVT_EXCBASE + EXC_COUNT)
+#define IVT_FREEBASE  (IVT_IRQBASE + IRQ_COUNT)
+
+#define IRQ_CLK       0
+#define IRQ_KBD       1
+#define IRQ_PIC1      2
+#define IRQ_PIC_SPUR  7
+#define IRQ_MOUSE     12
+
+/* This one must have four least significant bits set to ones */
+#define VECTOR_APIC_SPUR  (IVT_ITEMS - 1)
+
+#if (((VECTOR_APIC_SPUR + 1) % 16) || VECTOR_APIC_SPUR >= IVT_ITEMS)
+#error Wrong definition of VECTOR_APIC_SPUR
+#endif
+
+#define VECTOR_DEBUG              1
+#define VECTOR_CLK                (IVT_IRQBASE + IRQ_CLK)
+#define VECTOR_PIC_SPUR           (IVT_IRQBASE + IRQ_PIC_SPUR)
+#define VECTOR_SYSCALL            IVT_FREEBASE
+#define VECTOR_TLB_SHOOTDOWN_IPI  (IVT_FREEBASE + 1)
+#define VECTOR_DEBUG_IPI          (IVT_FREEBASE + 2)
+
+extern void (* disable_irqs_function)(uint16_t);
+extern void (* enable_irqs_function)(uint16_t);
+extern void (* eoi_function)(void);
+extern const char *irqs_info;
+
+extern void interrupt_init(void);
+extern void trap_virtual_enable_irqs(uint16_t);
+extern void trap_virtual_disable_irqs(uint16_t);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/istate.h
===================================================================
--- kernel/arch/amd64/include/arch/istate.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/istate.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+/** @addtogroup amd64interrupt
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_ISTATE_H_
+#define KERN_amd64_ISTATE_H_
+
+#include <trace.h>
+
+/** This is passed to interrupt handlers */
+typedef struct istate {
+	uint64_t rax;
+	uint64_t rbx;
+	uint64_t rcx;
+	uint64_t rdx;
+	uint64_t rsi;
+	uint64_t rdi;
+	uint64_t rbp;
+	uint64_t r8;
+	uint64_t r9;
+	uint64_t r10;
+	uint64_t r11;
+	uint64_t r12;
+	uint64_t r13;
+	uint64_t r14;
+	uint64_t r15;
+	uint64_t alignment;   /* align rbp_frame on multiple of 16 */
+	uint64_t rbp_frame;   /* imitation of frame pointer linkage */
+	uint64_t rip_frame;   /* imitation of return address linkage */
+	uint64_t error_word;  /* real or fake error word */
+	uint64_t rip;
+	uint64_t cs;
+	uint64_t rflags;
+	uint64_t rsp;         /* only if istate_t is from uspace */
+	uint64_t ss;          /* only if istate_t is from uspace */
+} istate_t;
+
+#define RPL_USER	3
+
+/** Return true if exception happened while in userspace */
+NO_TRACE static inline int istate_from_uspace(istate_t *istate)
+{
+	return (istate->cs & RPL_USER) == RPL_USER;
+}
+
+NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
+    uintptr_t retaddr)
+{
+	istate->rip = retaddr;
+}
+
+NO_TRACE static inline uintptr_t istate_get_pc(istate_t *istate)
+{
+	return istate->rip;
+}
+
+NO_TRACE static inline uintptr_t istate_get_fp(istate_t *istate)
+{
+	return istate->rbp;
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/mm/as.h
===================================================================
--- kernel/arch/amd64/include/arch/mm/as.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/mm/as.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2005 Ondrej Palkovsky
+ * 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 amd64mm
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_AS_H_
+#define KERN_amd64_AS_H_
+
+#define ADDRESS_SPACE_HOLE_START  UINT64_C(0x0000800000000000)
+#define ADDRESS_SPACE_HOLE_END    UINT64_C(0xffff7fffffffffff)
+
+#define KERNEL_ADDRESS_SPACE_SHADOWED_ARCH  0
+
+#define KERNEL_ADDRESS_SPACE_START_ARCH  UINT64_C(0xffff800000000000)
+#define KERNEL_ADDRESS_SPACE_END_ARCH    UINT64_C(0xffffffffffffffff)
+#define USER_ADDRESS_SPACE_START_ARCH    UINT64_C(0x0000000000000000)
+#define USER_ADDRESS_SPACE_END_ARCH      UINT64_C(0x00007fffffffffff)
+
+#define as_constructor_arch(as, flags)  (as != as)
+#define as_destructor_arch(as)          (as != as)
+#define as_create_arch(as, flags)       (as != as)
+
+#define as_install_arch(as)
+#define as_deinstall_arch(as)
+#define as_invalidate_translation_cache(as, page, cnt)
+
+typedef struct {
+} as_arch_t;
+
+#include <genarch/mm/as_pt.h>
+
+extern void as_arch_init(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/mm/asid.h
===================================================================
--- kernel/arch/amd64/include/arch/mm/asid.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/mm/asid.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,1 @@
+../../../../ia32/include/arch/mm/asid.h
Index: kernel/arch/amd64/include/arch/mm/frame.h
===================================================================
--- kernel/arch/amd64/include/arch/mm/frame.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/mm/frame.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2005 Ondrej Palkovsky
+ * 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 amd64mm
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_FRAME_H_
+#define KERN_amd64_FRAME_H_
+
+#define FRAME_WIDTH  12  /* 4K */
+#define FRAME_SIZE   (1 << FRAME_WIDTH)
+
+#ifndef __ASM__
+
+#include <typedefs.h>
+
+extern void frame_low_arch_init(void);
+extern void frame_high_arch_init(void);
+extern void physmem_print(void);
+
+#endif /* __ASM__ */
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/mm/km.h
===================================================================
--- kernel/arch/amd64/include/arch/mm/km.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/mm/km.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2011 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 amd64mm
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_KM_H_
+#define KERN_amd64_KM_H_
+
+#include <typedefs.h>
+
+#define KM_AMD64_IDENTITY_START		UINT64_C(0xffff800000000000)
+#define KM_AMD64_IDENTITY_SIZE		UINT64_C(0x0000400000000000)
+
+#define KM_AMD64_NON_IDENTITY_START	UINT64_C(0xffffc00000000000)
+#define KM_AMD64_NON_IDENTITY_SIZE	UINT64_C(0x0000400000000000)
+
+extern void km_identity_arch_init(void);
+extern void km_non_identity_arch_init(void);
+extern bool km_is_non_identity_arch(uintptr_t);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/mm/page.h
===================================================================
--- kernel/arch/amd64/include/arch/mm/page.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/mm/page.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2005 Ondrej Palkovsky
+ * 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 amd64mm
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_PAGE_H_
+#define KERN_amd64_PAGE_H_
+
+#include <arch/mm/frame.h>
+#include <trace.h>
+
+#define PAGE_WIDTH  FRAME_WIDTH
+#define PAGE_SIZE   FRAME_SIZE
+
+#ifndef __ASM__
+
+#define KA2PA(x)  (((uintptr_t) (x)) - UINT64_C(0xffff800000000000))
+#define PA2KA(x)  (((uintptr_t) (x)) + UINT64_C(0xffff800000000000))
+
+#else /* __ASM__ */
+
+#define KA2PA(x)  ((x) - 0xffff800000000000)
+#define PA2KA(x)  ((x) + 0xffff800000000000)
+
+#endif /* __ASM__ */
+
+/* Number of entries in each level. */
+#define PTL0_ENTRIES_ARCH  512
+#define PTL1_ENTRIES_ARCH  512
+#define PTL2_ENTRIES_ARCH  512
+#define PTL3_ENTRIES_ARCH  512
+
+/* Page table sizes for each level. */
+#define PTL0_SIZE_ARCH  ONE_FRAME
+#define PTL1_SIZE_ARCH  ONE_FRAME
+#define PTL2_SIZE_ARCH  ONE_FRAME
+#define PTL3_SIZE_ARCH  ONE_FRAME
+
+/* Macros calculating indices into page tables in each level. */
+#define PTL0_INDEX_ARCH(vaddr)  (((vaddr) >> 39) & 0x1ffU)
+#define PTL1_INDEX_ARCH(vaddr)  (((vaddr) >> 30) & 0x1ffU)
+#define PTL2_INDEX_ARCH(vaddr)  (((vaddr) >> 21) & 0x1ffU)
+#define PTL3_INDEX_ARCH(vaddr)  (((vaddr) >> 12) & 0x1ffU)
+
+/* Get PTE address accessors for each level. */
+#define GET_PTL1_ADDRESS_ARCH(ptl0, i) \
+	((pte_t *) ((((uint64_t) ((pte_t *) (ptl0))[(i)].addr_12_31) << 12) | \
+	    (((uint64_t) ((pte_t *) (ptl0))[(i)].addr_32_51) << 32)))
+#define GET_PTL2_ADDRESS_ARCH(ptl1, i) \
+	((pte_t *) ((((uint64_t) ((pte_t *) (ptl1))[(i)].addr_12_31) << 12) | \
+	    (((uint64_t) ((pte_t *) (ptl1))[(i)].addr_32_51) << 32)))
+#define GET_PTL3_ADDRESS_ARCH(ptl2, i) \
+	((pte_t *) ((((uint64_t) ((pte_t *) (ptl2))[(i)].addr_12_31) << 12) | \
+	    (((uint64_t) ((pte_t *) (ptl2))[(i)].addr_32_51) << 32)))
+#define GET_FRAME_ADDRESS_ARCH(ptl3, i) \
+	((uintptr_t *) \
+	    ((((uint64_t) ((pte_t *) (ptl3))[(i)].addr_12_31) << 12) | \
+	    (((uint64_t) ((pte_t *) (ptl3))[(i)].addr_32_51) << 32)))
+
+/* Set PTE address accessors for each level. */
+#define SET_PTL0_ADDRESS_ARCH(ptl0) \
+	(write_cr3((uintptr_t) (ptl0)))
+#define SET_PTL1_ADDRESS_ARCH(ptl0, i, a) \
+	set_pt_addr((pte_t *) (ptl0), (size_t) (i), a)
+#define SET_PTL2_ADDRESS_ARCH(ptl1, i, a) \
+	set_pt_addr((pte_t *) (ptl1), (size_t) (i), a)
+#define SET_PTL3_ADDRESS_ARCH(ptl2, i, a) \
+	set_pt_addr((pte_t *) (ptl2), (size_t) (i), a)
+#define SET_FRAME_ADDRESS_ARCH(ptl3, i, a) \
+	set_pt_addr((pte_t *) (ptl3), (size_t) (i), a)
+
+/* Get PTE flags accessors for each level. */
+#define GET_PTL1_FLAGS_ARCH(ptl0, i) \
+	get_pt_flags((pte_t *) (ptl0), (size_t) (i))
+#define GET_PTL2_FLAGS_ARCH(ptl1, i) \
+	get_pt_flags((pte_t *) (ptl1), (size_t) (i))
+#define GET_PTL3_FLAGS_ARCH(ptl2, i) \
+	get_pt_flags((pte_t *) (ptl2), (size_t) (i))
+#define GET_FRAME_FLAGS_ARCH(ptl3, i) \
+	get_pt_flags((pte_t *) (ptl3), (size_t) (i))
+
+/* Set PTE flags accessors for each level. */
+#define SET_PTL1_FLAGS_ARCH(ptl0, i, x) \
+	set_pt_flags((pte_t *) (ptl0), (size_t) (i), (x))
+#define SET_PTL2_FLAGS_ARCH(ptl1, i, x) \
+	set_pt_flags((pte_t *) (ptl1), (size_t) (i), (x))
+#define SET_PTL3_FLAGS_ARCH(ptl2, i, x) \
+	set_pt_flags((pte_t *) (ptl2), (size_t) (i), (x))
+#define SET_FRAME_FLAGS_ARCH(ptl3, i, x) \
+	set_pt_flags((pte_t *) (ptl3), (size_t) (i), (x))
+
+/* Set PTE present bit accessors for each level. */
+#define SET_PTL1_PRESENT_ARCH(ptl0, i) \
+	set_pt_present((pte_t *) (ptl0), (size_t) (i))
+#define SET_PTL2_PRESENT_ARCH(ptl1, i) \
+	set_pt_present((pte_t *) (ptl1), (size_t) (i))
+#define SET_PTL3_PRESENT_ARCH(ptl2, i) \
+	set_pt_present((pte_t *) (ptl2), (size_t) (i))
+#define SET_FRAME_PRESENT_ARCH(ptl3, i) \
+	set_pt_present((pte_t *) (ptl3), (size_t) (i))
+
+/* Macros for querying the last-level PTE entries. */
+#define PTE_VALID_ARCH(p) \
+	(*((uint64_t *) (p)) != 0)
+#define PTE_PRESENT_ARCH(p) \
+	((p)->present != 0)
+#define PTE_GET_FRAME_ARCH(p) \
+	((((uintptr_t) (p)->addr_12_31) << 12) | \
+	    ((uintptr_t) (p)->addr_32_51 << 32))
+#define PTE_WRITABLE_ARCH(p) \
+	((p)->writeable != 0)
+#define PTE_EXECUTABLE_ARCH(p) \
+	((p)->no_execute == 0)
+
+#ifndef __ASM__
+
+#include <mm/mm.h>
+#include <arch/interrupt.h>
+#include <typedefs.h>
+
+/* Page fault error codes. */
+
+/** When bit on this position is 0, the page fault was caused by a not-present
+ * page.
+ */
+#define PFERR_CODE_P  (1 << 0)
+
+/** When bit on this position is 1, the page fault was caused by a write. */
+#define PFERR_CODE_RW  (1 << 1)
+
+/** When bit on this position is 1, the page fault was caused in user mode. */
+#define PFERR_CODE_US  (1 << 2)
+
+/** When bit on this position is 1, a reserved bit was set in page directory. */
+#define PFERR_CODE_RSVD  (1 << 3)
+
+/** When bit on this position os 1, the page fault was caused during instruction
+ * fecth.
+ */
+#define PFERR_CODE_ID  (1 << 4)
+
+/** Page Table Entry. */
+typedef struct {
+	unsigned int present : 1;
+	unsigned int writeable : 1;
+	unsigned int uaccessible : 1;
+	unsigned int page_write_through : 1;
+	unsigned int page_cache_disable : 1;
+	unsigned int accessed : 1;
+	unsigned int dirty : 1;
+	unsigned int unused: 1;
+	unsigned int global : 1;
+	unsigned int soft_valid : 1;  /**< Valid content even if present bit is cleared. */
+	unsigned int avl : 2;
+	unsigned int addr_12_31 : 30;
+	unsigned int addr_32_51 : 21;
+	unsigned int no_execute : 1;
+} __attribute__ ((packed)) pte_t;
+
+NO_TRACE static inline unsigned int get_pt_flags(pte_t *pt, size_t i)
+{
+	pte_t *p = &pt[i];
+	
+	return ((!p->page_cache_disable) << PAGE_CACHEABLE_SHIFT |
+	    (!p->present) << PAGE_PRESENT_SHIFT |
+	    p->uaccessible << PAGE_USER_SHIFT |
+	    1 << PAGE_READ_SHIFT |
+	    p->writeable << PAGE_WRITE_SHIFT |
+	    (!p->no_execute) << PAGE_EXEC_SHIFT |
+	    p->global << PAGE_GLOBAL_SHIFT);
+}
+
+NO_TRACE static inline void set_pt_addr(pte_t *pt, size_t i, uintptr_t a)
+{
+	pte_t *p = &pt[i];
+	
+	p->addr_12_31 = (a >> 12) & UINT32_C(0xfffff);
+	p->addr_32_51 = a >> 32;
+}
+
+NO_TRACE static inline void set_pt_flags(pte_t *pt, size_t i, int flags)
+{
+	pte_t *p = &pt[i];
+	
+	p->page_cache_disable = !(flags & PAGE_CACHEABLE);
+	p->present = !(flags & PAGE_NOT_PRESENT);
+	p->uaccessible = (flags & PAGE_USER) != 0;
+	p->writeable = (flags & PAGE_WRITE) != 0;
+	p->no_execute = (flags & PAGE_EXEC) == 0;
+	p->global = (flags & PAGE_GLOBAL) != 0;
+	
+	/*
+	 * Ensure that there is at least one bit set even if the present bit is cleared.
+	 */
+	p->soft_valid = 1;
+}
+
+NO_TRACE static inline void set_pt_present(pte_t *pt, size_t i)
+{
+	pte_t *p = &pt[i];
+
+	p->present = 1;
+}
+
+extern void page_arch_init(void);
+extern void page_fault(unsigned int, istate_t *);
+
+#endif /* __ASM__ */
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/mm/ptl.h
===================================================================
--- kernel/arch/amd64/include/arch/mm/ptl.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/mm/ptl.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2005 Ondrej Palkovsky
+ * 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 amd64mm
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_PTL_H_
+#define KERN_amd64_PTL_H_
+
+#define PTL_NO_EXEC        (1 << 63)
+#define PTL_ACCESSED       (1 << 5)
+#define PTL_CACHE_DISABLE  (1 << 4)
+#define PTL_CACHE_THROUGH  (1 << 3)
+#define PTL_USER           (1 << 2)
+#define PTL_WRITABLE       (1 << 1)
+#define PTL_PRESENT        1
+#define PTL_2MB_PAGE       (1 << 7)
+
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/mm/tlb.h
===================================================================
--- kernel/arch/amd64/include/arch/mm/tlb.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/mm/tlb.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+/** @addtogroup amd64mm
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_TLB_H_
+#define KERN_amd64_TLB_H_
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/pm.h
===================================================================
--- kernel/arch/amd64/include/arch/pm.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/pm.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,186 @@
+/*
+ * 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.
+ */
+
+/** @addtogroup amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_PM_H_
+#define KERN_amd64_PM_H_
+
+#ifndef __ASM__
+	#include <typedefs.h>
+	#include <arch/context.h>
+#endif
+
+#define IDT_ITEMS  64
+#define GDT_ITEMS  8
+
+
+#define NULL_DES     0
+/* Warning: Do not reorder the following items, unless you look into syscall.c! */
+#define KTEXT_DES    1
+#define KDATA_DES    2
+#define UDATA_DES    3
+#define UTEXT_DES    4
+#define KTEXT32_DES  5
+/* End of warning */
+#define TSS_DES      6
+
+#ifdef CONFIG_FB
+
+#define VESA_INIT_DES      8
+#define VESA_INIT_SEGMENT  0x8000
+
+#undef GDT_ITEMS
+#define GDT_ITEMS  9
+
+#endif /* CONFIG_FB */
+
+#define GDT_SELECTOR(des)  ((des) << 3)
+
+#define PL_KERNEL  0
+#define PL_USER    3
+
+#define AR_PRESENT    (1 << 7)
+#define AR_DATA       (2 << 3)
+#define AR_CODE       (3 << 3)
+#define AR_WRITABLE   (1 << 1)
+#define AR_READABLE   (1 << 1)
+#define AR_TSS        (0x09U)
+#define AR_INTERRUPT  (0x0eU)
+#define AR_TRAP       (0x0fU)
+
+#define DPL_KERNEL  (PL_KERNEL << 5)
+#define DPL_USER    (PL_USER << 5)
+
+#define TSS_BASIC_SIZE  104
+#define TSS_IOMAP_SIZE  (8 * 1024 + 1)  /* 8K for bitmap + 1 terminating byte for convenience */
+
+#define IO_PORTS  (64 * 1024)
+
+#ifndef __ASM__
+
+typedef struct {
+	unsigned limit_0_15: 16;
+	unsigned base_0_15: 16;
+	unsigned base_16_23: 8;
+	unsigned access: 8;
+	unsigned limit_16_19: 4;
+	unsigned available: 1;
+	unsigned longmode: 1;
+	unsigned special: 1;
+	unsigned granularity : 1;
+	unsigned base_24_31: 8;
+} __attribute__ ((packed)) descriptor_t;
+
+typedef struct {
+	unsigned limit_0_15: 16;
+	unsigned base_0_15: 16;
+	unsigned base_16_23: 8;
+	unsigned type: 4;
+	unsigned : 1;
+	unsigned dpl : 2;
+	unsigned present : 1;
+	unsigned limit_16_19: 4;
+	unsigned available: 1;
+	unsigned : 2;
+	unsigned granularity : 1;
+	unsigned base_24_31: 8;	
+	unsigned base_32_63 : 32;
+	unsigned  : 32;
+} __attribute__ ((packed)) tss_descriptor_t;
+
+typedef struct {
+	unsigned offset_0_15: 16;
+	unsigned selector: 16;
+	unsigned ist:3;
+	unsigned unused: 5;
+	unsigned type: 5;
+	unsigned dpl: 2;
+	unsigned present : 1;
+	unsigned offset_16_31: 16;
+	unsigned offset_32_63: 32;
+	unsigned  : 32;
+} __attribute__ ((packed)) idescriptor_t;
+
+typedef struct {
+	uint16_t limit;
+	uint64_t base;
+} __attribute__ ((packed)) ptr_16_64_t;
+
+typedef struct {
+	uint16_t limit;
+	uint32_t base;
+} __attribute__ ((packed)) ptr_16_32_t;
+
+typedef struct {
+	uint32_t reserve1;
+	uint64_t rsp0;
+	uint64_t rsp1;
+	uint64_t rsp2;
+	uint64_t reserve2;
+	uint64_t ist1;
+	uint64_t ist2;
+	uint64_t ist3;
+	uint64_t ist4;
+	uint64_t ist5;
+	uint64_t ist6;
+	uint64_t ist7;
+	uint64_t reserve3;
+	uint16_t reserve4;
+	uint16_t iomap_base;
+	uint8_t iomap[TSS_IOMAP_SIZE];
+} __attribute__ ((packed)) tss_t;
+
+extern tss_t *tss_p;
+
+extern descriptor_t gdt[];
+extern idescriptor_t idt[];
+
+extern ptr_16_64_t gdtr;
+extern ptr_16_32_t protected_ap_gdtr;
+
+extern void pm_init(void);
+
+extern void gdt_tss_setbase(descriptor_t *d, uintptr_t base);
+extern void gdt_tss_setlimit(descriptor_t *d, uint32_t limit);
+
+extern void idt_init(void);
+extern void idt_setoffset(idescriptor_t *d, uintptr_t offset);
+
+extern void tss_initialize(tss_t *t);
+
+#endif /* __ASM__ */
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/proc/task.h
===================================================================
--- kernel/arch/amd64/include/arch/proc/task.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/proc/task.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,51 @@
+/*
+ * 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 amd64proc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_TASK_H_
+#define KERN_amd64_TASK_H_
+
+#include <typedefs.h>
+#include <adt/bitmap.h>
+
+typedef struct {
+	/** I/O Permission bitmap Generation counter. */
+	size_t iomapver;
+	/** I/O Permission bitmap. */
+	bitmap_t iomap;
+} task_arch_t;
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/proc/thread.h
===================================================================
--- kernel/arch/amd64/include/arch/proc/thread.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/proc/thread.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2005 Ondrej Palkovsky
+ * 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 amd64proc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_THREAD_H_
+#define KERN_amd64_THREAD_H_
+
+/* CAUTION: keep these in sync with low level assembly code in syscall_entry */
+#define SYSCALL_USTACK_RSP  0
+#define SYSCALL_KSTACK_RSP  1
+
+typedef struct {
+	sysarg_t tls;
+	/** User and kernel RSP for syscalls. */
+	uint64_t syscall_rsp[2];
+} thread_arch_t;
+
+#define thr_constructor_arch(t)
+#define thr_destructor_arch(t)
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/smp
===================================================================
--- kernel/arch/amd64/include/arch/smp	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/smp	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,1 @@
+../../../ia32/include/arch/smp
Index: kernel/arch/amd64/include/arch/syscall.h
===================================================================
--- kernel/arch/amd64/include/arch/syscall.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/syscall.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_SYSCALL_H_
+#define KERN_amd64_SYSCALL_H_
+
+extern void syscall_setup_cpu(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/types.h
===================================================================
--- kernel/arch/amd64/include/arch/types.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
+++ kernel/arch/amd64/include/arch/types.h	(revision 40a0e3bd205a795440ad80ae31717206bcbd7cce)
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+/** @addtogroup amd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_TYPES_H_
+#define KERN_amd64_TYPES_H_
+
+typedef uint64_t size_t;
+typedef int64_t ssize_t;
+
+typedef uint64_t uintptr_t;
+typedef uint64_t pfn_t;
+
+typedef uint64_t ipl_t;
+
+typedef uint64_t sysarg_t;
+typedef int64_t native_t;
+typedef uint64_t atomic_count_t;
+
+typedef struct {
+} fncptr_t;
+
+#define INTN_C(c)   INT64_C(c)
+#define UINTN_C(c)  UINT64_C(c)
+
+#define PRIdn  PRId64  /**< Format for native_t. */
+#define PRIun  PRIu64  /**< Format for sysarg_t. */
+#define PRIxn  PRIx64  /**< Format for hexadecimal sysarg_t. */
+#define PRIua  PRIu64  /**< Format for atomic_count_t. */
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/asm.h
===================================================================
--- kernel/arch/amd64/include/asm.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,525 +1,0 @@
-/*
- * 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.
- */
-
-/** @addtogroup amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_ASM_H_
-#define KERN_amd64_ASM_H_
-
-#include <config.h>
-#include <typedefs.h>
-#include <arch/cpu.h>
-#include <trace.h>
-
-#define IO_SPACE_BOUNDARY	((void *) (64 * 1024))
-
-/** Return base address of current stack.
- *
- * Return the base address of the current stack.
- * The stack is assumed to be STACK_SIZE bytes long.
- * The stack must start on page boundary.
- *
- */
-NO_TRACE static inline uintptr_t get_stack_base(void)
-{
-	uintptr_t v;
-	
-	asm volatile (
-		"andq %%rsp, %[v]\n"
-		: [v] "=r" (v)
-		: "0" (~((uint64_t) STACK_SIZE - 1))
-	);
-	
-	return v;
-}
-
-NO_TRACE static inline void cpu_sleep(void)
-{
-	asm volatile (
-		"hlt\n"
-	);
-}
-
-NO_TRACE static inline void __attribute__((noreturn)) cpu_halt(void)
-{
-	while (true) {
-		asm volatile (
-			"hlt\n"
-		);
-	}
-}
-
-/** Byte from port
- *
- * Get byte from port
- *
- * @param port Port to read from
- * @return Value read
- *
- */
-NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port)
-{
-	if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
-		uint8_t val;
-		
-		asm volatile (
-			"inb %w[port], %b[val]\n"
-			: [val] "=a" (val)
-			: [port] "d" (port)
-		);
-		
-		return val;
-	} else
-		return (uint8_t) *port;
-}
-
-/** Word from port
- *
- * Get word from port
- *
- * @param port Port to read from
- * @return Value read
- *
- */
-NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port)
-{
-	if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
-		uint16_t val;
-		
-		asm volatile (
-			"inw %w[port], %w[val]\n"
-			: [val] "=a" (val)
-			: [port] "d" (port)
-		);
-		
-		return val;
-	} else
-		return (uint16_t) *port;
-}
-
-/** Double word from port
- *
- * Get double word from port
- *
- * @param port Port to read from
- * @return Value read
- *
- */
-NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port)
-{
-	if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
-		uint32_t val;
-		
-		asm volatile (
-			"inl %w[port], %[val]\n"
-			: [val] "=a" (val)
-			: [port] "d" (port)
-		);
-		
-		return val;
-	} else
-		return (uint32_t) *port;
-}
-
-/** Byte to port
- *
- * Output byte to port
- *
- * @param port Port to write to
- * @param val Value to write
- *
- */
-NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t val)
-{
-	if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
-		asm volatile (
-			"outb %b[val], %w[port]\n"
-			:: [val] "a" (val), [port] "d" (port)
-		);	
-	} else
-		*port = val;
-}
-
-/** Word to port
- *
- * Output word to port
- *
- * @param port Port to write to
- * @param val Value to write
- *
- */
-NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t val)
-{
-	if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
-		asm volatile (
-			"outw %w[val], %w[port]\n"
-			:: [val] "a" (val), [port] "d" (port)
-		);
-	} else
-		*port = val;
-}
-
-/** Double word to port
- *
- * Output double word to port
- *
- * @param port Port to write to
- * @param val Value to write
- *
- */
-NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t val)
-{
-	if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
-		asm volatile (
-			"outl %[val], %w[port]\n"
-			:: [val] "a" (val), [port] "d" (port)
-		);
-	} else
-		*port = val;
-}
-
-/** Swap Hidden part of GS register with visible one */
-NO_TRACE static inline void swapgs(void)
-{
-	asm volatile (
-		"swapgs"
-	);
-}
-
-/** Enable interrupts.
- *
- * Enable interrupts and return previous
- * value of EFLAGS.
- *
- * @return Old interrupt priority level.
- *
- */
-NO_TRACE static inline ipl_t interrupts_enable(void) {
-	ipl_t v;
-	
-	asm volatile (
-		"pushfq\n"
-		"popq %[v]\n"
-		"sti\n"
-		: [v] "=r" (v)
-	);
-	
-	return v;
-}
-
-/** Disable interrupts.
- *
- * Disable interrupts and return previous
- * value of EFLAGS.
- *
- * @return Old interrupt priority level.
- *
- */
-NO_TRACE static inline ipl_t interrupts_disable(void) {
-	ipl_t v;
-	
-	asm volatile (
-		"pushfq\n"
-		"popq %[v]\n"
-		"cli\n"
-		: [v] "=r" (v)
-	);
-	
-	return v;
-}
-
-/** Restore interrupt priority level.
- *
- * Restore EFLAGS.
- *
- * @param ipl Saved interrupt priority level.
- *
- */
-NO_TRACE static inline void interrupts_restore(ipl_t ipl) {
-	asm volatile (
-		"pushq %[ipl]\n"
-		"popfq\n"
-		:: [ipl] "r" (ipl)
-	);
-}
-
-/** Return interrupt priority level.
- *
- * Return EFLAFS.
- *
- * @return Current interrupt priority level.
- *
- */
-NO_TRACE static inline ipl_t interrupts_read(void) {
-	ipl_t v;
-	
-	asm volatile (
-		"pushfq\n"
-		"popq %[v]\n"
-		: [v] "=r" (v)
-	);
-	
-	return v;
-}
-
-/** Check interrupts state.
- *
- * @return True if interrupts are disabled.
- *
- */
-NO_TRACE static inline bool interrupts_disabled(void)
-{
-	ipl_t v;
-	
-	asm volatile (
-		"pushfq\n"
-		"popq %[v]\n"
-		: [v] "=r" (v)
-	);
-	
-	return ((v & RFLAGS_IF) == 0);
-}
-
-/** Write to MSR */
-NO_TRACE static inline void write_msr(uint32_t msr, uint64_t value)
-{
-	asm volatile (
-		"wrmsr\n"
-		:: "c" (msr),
-		   "a" ((uint32_t) (value)),
-		   "d" ((uint32_t) (value >> 32))
-	);
-}
-
-NO_TRACE static inline sysarg_t read_msr(uint32_t msr)
-{
-	uint32_t ax, dx;
-	
-	asm volatile (
-		"rdmsr\n"
-		: "=a" (ax), "=d" (dx)
-		: "c" (msr)
-	);
-	
-	return ((uint64_t) dx << 32) | ax;
-}
-
-/** Enable local APIC
- *
- * Enable local APIC in MSR.
- *
- */
-NO_TRACE static inline void enable_l_apic_in_msr()
-{
-	asm volatile (
-		"movl $0x1b, %%ecx\n"
-		"rdmsr\n"
-		"orl $(1 << 11),%%eax\n"
-		"orl $(0xfee00000),%%eax\n"
-		"wrmsr\n"
-		::: "%eax", "%ecx", "%edx"
-	);
-}
-
-/** Invalidate TLB Entry.
- *
- * @param addr Address on a page whose TLB entry is to be invalidated.
- *
- */
-NO_TRACE static inline void invlpg(uintptr_t addr)
-{
-	asm volatile (
-		"invlpg %[addr]\n"
-		:: [addr] "m" (*((sysarg_t *) addr))
-	);
-}
-
-/** Load GDTR register from memory.
- *
- * @param gdtr_reg Address of memory from where to load GDTR.
- *
- */
-NO_TRACE static inline void gdtr_load(ptr_16_64_t *gdtr_reg)
-{
-	asm volatile (
-		"lgdtq %[gdtr_reg]\n"
-		:: [gdtr_reg] "m" (*gdtr_reg)
-	);
-}
-
-/** Store GDTR register to memory.
- *
- * @param gdtr_reg Address of memory to where to load GDTR.
- *
- */
-NO_TRACE static inline void gdtr_store(ptr_16_64_t *gdtr_reg)
-{
-	asm volatile (
-		"sgdtq %[gdtr_reg]\n"
-		:: [gdtr_reg] "m" (*gdtr_reg)
-	);
-}
-
-/** Load IDTR register from memory.
- *
- * @param idtr_reg Address of memory from where to load IDTR.
- *
- */
-NO_TRACE static inline void idtr_load(ptr_16_64_t *idtr_reg)
-{
-	asm volatile (
-		"lidtq %[idtr_reg]\n"
-		:: [idtr_reg] "m" (*idtr_reg));
-}
-
-/** Load TR from descriptor table.
- *
- * @param sel Selector specifying descriptor of TSS segment.
- *
- */
-NO_TRACE static inline void tr_load(uint16_t sel)
-{
-	asm volatile (
-		"ltr %[sel]"
-		:: [sel] "r" (sel)
-	);
-}
-
-#define GEN_READ_REG(reg) NO_TRACE static inline sysarg_t read_ ##reg (void) \
-	{ \
-		sysarg_t res; \
-		asm volatile ( \
-			"movq %%" #reg ", %[res]" \
-			: [res] "=r" (res) \
-		); \
-		return res; \
-	}
-
-#define GEN_WRITE_REG(reg) NO_TRACE static inline void write_ ##reg (sysarg_t regn) \
-	{ \
-		asm volatile ( \
-			"movq %[regn], %%" #reg \
-			:: [regn] "r" (regn) \
-		); \
-	}
-
-GEN_READ_REG(cr0)
-GEN_READ_REG(cr2)
-GEN_READ_REG(cr3)
-GEN_WRITE_REG(cr3)
-
-GEN_READ_REG(dr0)
-GEN_READ_REG(dr1)
-GEN_READ_REG(dr2)
-GEN_READ_REG(dr3)
-GEN_READ_REG(dr6)
-GEN_READ_REG(dr7)
-
-GEN_WRITE_REG(dr0)
-GEN_WRITE_REG(dr1)
-GEN_WRITE_REG(dr2)
-GEN_WRITE_REG(dr3)
-GEN_WRITE_REG(dr6)
-GEN_WRITE_REG(dr7)
-
-extern void asm_delay_loop(uint32_t);
-extern void asm_fake_loop(uint32_t);
-
-extern uintptr_t int_0;
-extern uintptr_t int_1;
-extern uintptr_t int_2;
-extern uintptr_t int_3;
-extern uintptr_t int_4;
-extern uintptr_t int_5;
-extern uintptr_t int_6;
-extern uintptr_t int_7;
-extern uintptr_t int_8;
-extern uintptr_t int_9;
-extern uintptr_t int_10;
-extern uintptr_t int_11;
-extern uintptr_t int_12;
-extern uintptr_t int_13;
-extern uintptr_t int_14;
-extern uintptr_t int_15;
-extern uintptr_t int_16;
-extern uintptr_t int_17;
-extern uintptr_t int_18;
-extern uintptr_t int_19;
-extern uintptr_t int_20;
-extern uintptr_t int_21;
-extern uintptr_t int_22;
-extern uintptr_t int_23;
-extern uintptr_t int_24;
-extern uintptr_t int_25;
-extern uintptr_t int_26;
-extern uintptr_t int_27;
-extern uintptr_t int_28;
-extern uintptr_t int_29;
-extern uintptr_t int_30;
-extern uintptr_t int_31;
-extern uintptr_t int_32;
-extern uintptr_t int_33;
-extern uintptr_t int_34;
-extern uintptr_t int_35;
-extern uintptr_t int_36;
-extern uintptr_t int_37;
-extern uintptr_t int_38;
-extern uintptr_t int_39;
-extern uintptr_t int_40;
-extern uintptr_t int_41;
-extern uintptr_t int_42;
-extern uintptr_t int_43;
-extern uintptr_t int_44;
-extern uintptr_t int_45;
-extern uintptr_t int_46;
-extern uintptr_t int_47;
-extern uintptr_t int_48;
-extern uintptr_t int_49;
-extern uintptr_t int_50;
-extern uintptr_t int_51;
-extern uintptr_t int_52;
-extern uintptr_t int_53;
-extern uintptr_t int_54;
-extern uintptr_t int_55;
-extern uintptr_t int_56;
-extern uintptr_t int_57;
-extern uintptr_t int_58;
-extern uintptr_t int_59;
-extern uintptr_t int_60;
-extern uintptr_t int_61;
-extern uintptr_t int_62;
-extern uintptr_t int_63;
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/atomic.h
===================================================================
--- kernel/arch/amd64/include/atomic.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,145 +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.
- */
-
-/** @addtogroup amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_ATOMIC_H_
-#define KERN_amd64_ATOMIC_H_
-
-#include <typedefs.h>
-#include <arch/barrier.h>
-#include <preemption.h>
-#include <trace.h>
-
-NO_TRACE static inline void atomic_inc(atomic_t *val)
-{
-#ifdef CONFIG_SMP
-	asm volatile (
-		"lock incq %[count]\n"
-		: [count] "+m" (val->count)
-	);
-#else
-	asm volatile (
-		"incq %[count]\n"
-		: [count] "+m" (val->count)
-	);
-#endif /* CONFIG_SMP */
-}
-
-NO_TRACE static inline void atomic_dec(atomic_t *val)
-{
-#ifdef CONFIG_SMP
-	asm volatile (
-		"lock decq %[count]\n"
-		: [count] "+m" (val->count)
-	);
-#else
-	asm volatile (
-		"decq %[count]\n"
-		: [count] "+m" (val->count)
-	);
-#endif /* CONFIG_SMP */
-}
-
-NO_TRACE static inline atomic_count_t atomic_postinc(atomic_t *val)
-{
-	atomic_count_t r = 1;
-	
-	asm volatile (
-		"lock xaddq %[r], %[count]\n"
-		: [count] "+m" (val->count),
-		  [r] "+r" (r)
-	);
-	
-	return r;
-}
-
-NO_TRACE static inline atomic_count_t atomic_postdec(atomic_t *val)
-{
-	atomic_count_t r = -1;
-	
-	asm volatile (
-		"lock xaddq %[r], %[count]\n"
-		: [count] "+m" (val->count),
-		  [r] "+r" (r)
-	);
-	
-	return r;
-}
-
-#define atomic_preinc(val)  (atomic_postinc(val) + 1)
-#define atomic_predec(val)  (atomic_postdec(val) - 1)
-
-NO_TRACE static inline atomic_count_t test_and_set(atomic_t *val)
-{
-	atomic_count_t v = 1;
-	
-	asm volatile (
-		"xchgq %[v], %[count]\n"
-		: [v] "+r" (v),
-		  [count] "+m" (val->count)
-	);
-	
-	return v;
-}
-
-/** amd64 specific fast spinlock */
-NO_TRACE static inline void atomic_lock_arch(atomic_t *val)
-{
-	atomic_count_t tmp;
-	
-	preemption_disable();
-	asm volatile (
-		"0:\n"
-		"	pause\n"
-		"	mov %[count], %[tmp]\n"
-		"	testq %[tmp], %[tmp]\n"
-		"	jnz 0b\n"       /* lightweight looping on locked spinlock */
-		
-		"	incq %[tmp]\n"  /* now use the atomic operation */
-		"	xchgq %[count], %[tmp]\n"
-		"	testq %[tmp], %[tmp]\n"
-		"	jnz 0b\n"
-		: [count] "+m" (val->count),
-		  [tmp] "=&r" (tmp)
-	);
-	
-	/*
-	 * Prevent critical section code from bleeding out this way up.
-	 */
-	CS_ENTER_BARRIER();
-}
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/barrier.h
===================================================================
--- kernel/arch/amd64/include/barrier.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../ia32/include/barrier.h
Index: kernel/arch/amd64/include/bios
===================================================================
--- kernel/arch/amd64/include/bios	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../ia32/include/bios
Index: kernel/arch/amd64/include/boot/boot.h
===================================================================
--- kernel/arch/amd64/include/boot/boot.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,56 +1,0 @@
-/*
- * Copyright (c) 2005 Ondrej Palkovsky
- * 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 amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_BOOT_H_
-#define KERN_amd64_BOOT_H_
-
-#define BOOT_OFFSET      0x108000
-#define AP_BOOT_OFFSET   0x008000
-#define BOOT_STACK_SIZE  0x000400
-
-#ifndef __ASM__
-
-#ifdef CONFIG_SMP
-
-/* This is only a symbol so the type is dummy. Obtain the value using &. */
-extern int _hardcoded_unmapped_size;
-
-#endif /* CONFIG_SMP */
-
-#endif /* __ASM__ */
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/boot/memmap.h
===================================================================
--- kernel/arch/amd64/include/boot/memmap.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../../ia32/include/boot/memmap.h
Index: kernel/arch/amd64/include/context.h
===================================================================
--- kernel/arch/amd64/include/context.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,75 +1,0 @@
-/*
- * Copyright (c) 2005 Ondrej Palkovsky
- * 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 amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_CONTEXT_H_
-#define KERN_amd64_CONTEXT_H_
-
-#include <typedefs.h>
-
-/*
- * According to ABI the stack MUST be aligned on
- * 16-byte boundary. If it is not, the va_arg calling will
- * panic sooner or later
- */
-#define SP_DELTA  16
-
-#define context_set(c, _pc, stack, size) \
-	do { \
-		(c)->pc = (uintptr_t) (_pc); \
-		(c)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \
-		(c)->rbp = 0; \
-	} while (0)
-
-/* We include only registers that must be preserved
- * during function call
- */
-typedef struct {
-	uintptr_t sp;
-	uintptr_t pc;
-	
-	uint64_t rbx;
-	uint64_t rbp;
-	
-	uint64_t r12;
-	uint64_t r13;
-	uint64_t r14;
-	uint64_t r15;
-	
-	ipl_t ipl;
-} __attribute__ ((packed)) context_t;
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/context_offset.h
===================================================================
--- kernel/arch/amd64/include/context_offset.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,79 +1,0 @@
-/*
- * Copyright (c) 2005 Ondrej Palkovsky
- * 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 KERN_amd64_CONTEXT_OFFSET_H_
-#define KERN_amd64_CONTEXT_OFFSET_H_
-
-#define OFFSET_SP   0x00
-#define OFFSET_PC   0x08
-#define OFFSET_RBX  0x10
-#define OFFSET_RBP  0x18
-#define OFFSET_R12  0x20
-#define OFFSET_R13  0x28
-#define OFFSET_R14  0x30
-#define OFFSET_R15  0x38
-
-#ifdef KERNEL
-	#define OFFSET_IPL  0x40
-#else
-	#define OFFSET_TLS  0x40
-#endif
-
-#ifdef __ASM__
-
-# ctx: address of the structure with saved context
-# pc: return address
-.macro CONTEXT_SAVE_ARCH_CORE ctx:req pc:req
-	movq \pc, OFFSET_PC(\ctx)
-	movq %rsp, OFFSET_SP(\ctx)
-	
-	movq %rbx, OFFSET_RBX(\ctx)
-	movq %rbp, OFFSET_RBP(\ctx)
-	movq %r12, OFFSET_R12(\ctx)
-	movq %r13, OFFSET_R13(\ctx)
-	movq %r14, OFFSET_R14(\ctx)
-	movq %r15, OFFSET_R15(\ctx)
-.endm
-
-# ctx: address of the structure with saved context
-.macro CONTEXT_RESTORE_ARCH_CORE ctx:req pc:req
-	movq OFFSET_R15(\ctx), %r15
-	movq OFFSET_R14(\ctx), %r14
-	movq OFFSET_R13(\ctx), %r13
-	movq OFFSET_R12(\ctx), %r12
-	movq OFFSET_RBP(\ctx), %rbp
-	movq OFFSET_RBX(\ctx), %rbx
-	
-	movq OFFSET_SP(\ctx), %rsp   # ctx->sp -> %rsp
-	
-	movq OFFSET_PC(\ctx), \pc
-.endm
-
-#endif
-
-#endif
Index: kernel/arch/amd64/include/cpu.h
===================================================================
--- kernel/arch/amd64/include/cpu.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,93 +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.
- */
-
-/** @addtogroup amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_CPU_H_
-#define KERN_amd64_CPU_H_
-
-#define RFLAGS_CF  (1 << 0)
-#define RFLAGS_PF  (1 << 2)
-#define RFLAGS_AF  (1 << 4)
-#define RFLAGS_ZF  (1 << 6)
-#define RFLAGS_SF  (1 << 7)
-#define RFLAGS_TF  (1 << 8)
-#define RFLAGS_IF  (1 << 9)
-#define RFLAGS_DF  (1 << 10)
-#define RFLAGS_OF  (1 << 11)
-#define RFLAGS_NT  (1 << 14)
-#define RFLAGS_RF  (1 << 16)
-
-#define EFER_MSR_NUM    0xc0000080
-#define AMD_SCE_FLAG    0
-#define AMD_LME_FLAG    8
-#define AMD_LMA_FLAG    10
-#define AMD_FFXSR_FLAG  14
-#define AMD_NXE_FLAG    11
-
-/* MSR registers */
-#define AMD_MSR_STAR    0xc0000081
-#define AMD_MSR_LSTAR   0xc0000082
-#define AMD_MSR_SFMASK  0xc0000084
-#define AMD_MSR_FS      0xc0000100
-#define AMD_MSR_GS      0xc0000101
-
-#ifndef __ASM__
-
-#include <arch/pm.h>
-
-typedef struct {
-	int vendor;
-	int family;
-	int model;
-	int stepping;
-	tss_t *tss;
-	
-	size_t iomapver_copy;  /** Copy of TASK's I/O Permission bitmap generation count. */
-} cpu_arch_t;
-
-struct star_msr {
-};
-
-struct lstar_msr {
-};
-
-extern void set_efer_flag(int flag);
-extern uint64_t read_efer_flag(void);
-void cpu_setup_fpu(void);
-
-#endif /* __ASM__ */
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/cpuid.h
===================================================================
--- kernel/arch/amd64/include/cpuid.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,67 +1,0 @@
-/*
- * Copyright (c) 2001-2004 Ondrej Palkovsky
- * 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 amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_CPUID_H_
-#define KERN_amd64_CPUID_H_
-
-#define AMD_CPUID_EXTENDED  0x80000001
-#define AMD_EXT_NOEXECUTE   20
-#define AMD_EXT_LONG_MODE   29
-
-#define INTEL_CPUID_LEVEL     0x00000000
-#define INTEL_CPUID_STANDARD  0x00000001
-#define INTEL_CPUID_EXTENDED  0x80000000
-#define INTEL_SSE2            26
-#define INTEL_FXSAVE          24
-
-#ifndef __ASM__
-
-#include <typedefs.h>
-
-typedef struct {
-	uint32_t cpuid_eax;
-	uint32_t cpuid_ebx;
-	uint32_t cpuid_ecx;
-	uint32_t cpuid_edx;
-} __attribute__ ((packed)) cpu_info_t;
-
-extern int has_cpuid(void);
-
-extern void cpuid(uint32_t cmd, cpu_info_t *info);
-
-#endif /* !def __ASM__ */
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/cycle.h
===================================================================
--- kernel/arch/amd64/include/cycle.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,57 +1,0 @@
-/*
- * Copyright (c) 2006 Martin Decky
- * 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 amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_CYCLE_H_
-#define KERN_amd64_CYCLE_H_
-
-#include <trace.h>
-
-NO_TRACE static inline uint64_t get_cycle(void)
-{
-	uint32_t lower;
-	uint32_t upper;
-	
-	asm volatile (
-		"rdtsc\n"
-		: "=a" (lower),
-		  "=d" (upper)
-	);
-	
-	return ((uint64_t) lower) | (((uint64_t) upper) << 32);
-}
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/ddi/ddi.h
===================================================================
--- kernel/arch/amd64/include/ddi/ddi.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,46 +1,0 @@
-/*
- * 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 amd64ddi
- * @{
- */
-
-/**
- * @file
- * @brief amd64 specific DDI declarations and macros.
- */
-
-#ifndef KERN_amd64_DDI_H_
-#define KERN_amd64_DDI_H_
-
-extern void io_perm_bitmap_install(void);
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/drivers
===================================================================
--- kernel/arch/amd64/include/drivers	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../ia32/include/drivers
Index: kernel/arch/amd64/include/elf.h
===================================================================
--- kernel/arch/amd64/include/elf.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,45 +1,0 @@
-/*
- * Copyright (c) 2006 Sergey Bondari
- * 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 amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_ELF_H_
-#define KERN_amd64_ELF_H_
-
-#define ELF_MACHINE        EM_X86_64
-#define ELF_DATA_ENCODING  ELFDATA2LSB
-#define ELF_CLASS          ELFCLASS64
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/faddr.h
===================================================================
--- kernel/arch/amd64/include/faddr.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,45 +1,0 @@
-/*
- * Copyright (c) 2005 Ondrej Palkovsky
- * 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 amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_FADDR_H_
-#define KERN_amd64_FADDR_H_
-
-#include <typedefs.h>
-
-#define FADDR(fptr)  ((uintptr_t) (fptr))
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/fpu_context.h
===================================================================
--- kernel/arch/amd64/include/fpu_context.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../ia32/include/fpu_context.h
Index: kernel/arch/amd64/include/interrupt.h
===================================================================
--- kernel/arch/amd64/include/interrupt.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,84 +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.
- */
-
-/** @addtogroup amd64interrupt
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_INTERRUPT_H_
-#define KERN_amd64_INTERRUPT_H_
-
-#include <typedefs.h>
-#include <arch/istate.h>
-#include <arch/pm.h>
-
-#define IVT_ITEMS  IDT_ITEMS
-#define IVT_FIRST  0
-
-#define EXC_COUNT  32
-#define IRQ_COUNT  16
-
-#define IVT_EXCBASE   0
-#define IVT_IRQBASE   (IVT_EXCBASE + EXC_COUNT)
-#define IVT_FREEBASE  (IVT_IRQBASE + IRQ_COUNT)
-
-#define IRQ_CLK       0
-#define IRQ_KBD       1
-#define IRQ_PIC1      2
-#define IRQ_PIC_SPUR  7
-#define IRQ_MOUSE     12
-
-/* This one must have four least significant bits set to ones */
-#define VECTOR_APIC_SPUR  (IVT_ITEMS - 1)
-
-#if (((VECTOR_APIC_SPUR + 1) % 16) || VECTOR_APIC_SPUR >= IVT_ITEMS)
-#error Wrong definition of VECTOR_APIC_SPUR
-#endif
-
-#define VECTOR_DEBUG              1
-#define VECTOR_CLK                (IVT_IRQBASE + IRQ_CLK)
-#define VECTOR_PIC_SPUR           (IVT_IRQBASE + IRQ_PIC_SPUR)
-#define VECTOR_SYSCALL            IVT_FREEBASE
-#define VECTOR_TLB_SHOOTDOWN_IPI  (IVT_FREEBASE + 1)
-#define VECTOR_DEBUG_IPI          (IVT_FREEBASE + 2)
-
-extern void (* disable_irqs_function)(uint16_t);
-extern void (* enable_irqs_function)(uint16_t);
-extern void (* eoi_function)(void);
-extern const char *irqs_info;
-
-extern void interrupt_init(void);
-extern void trap_virtual_enable_irqs(uint16_t);
-extern void trap_virtual_disable_irqs(uint16_t);
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/istate.h
===================================================================
--- kernel/arch/amd64/include/istate.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,95 +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.
- */
-
-/** @addtogroup amd64interrupt
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_ISTATE_H_
-#define KERN_amd64_ISTATE_H_
-
-#include <trace.h>
-
-/** This is passed to interrupt handlers */
-typedef struct istate {
-	uint64_t rax;
-	uint64_t rbx;
-	uint64_t rcx;
-	uint64_t rdx;
-	uint64_t rsi;
-	uint64_t rdi;
-	uint64_t rbp;
-	uint64_t r8;
-	uint64_t r9;
-	uint64_t r10;
-	uint64_t r11;
-	uint64_t r12;
-	uint64_t r13;
-	uint64_t r14;
-	uint64_t r15;
-	uint64_t alignment;   /* align rbp_frame on multiple of 16 */
-	uint64_t rbp_frame;   /* imitation of frame pointer linkage */
-	uint64_t rip_frame;   /* imitation of return address linkage */
-	uint64_t error_word;  /* real or fake error word */
-	uint64_t rip;
-	uint64_t cs;
-	uint64_t rflags;
-	uint64_t rsp;         /* only if istate_t is from uspace */
-	uint64_t ss;          /* only if istate_t is from uspace */
-} istate_t;
-
-#define RPL_USER	3
-
-/** Return true if exception happened while in userspace */
-NO_TRACE static inline int istate_from_uspace(istate_t *istate)
-{
-	return (istate->cs & RPL_USER) == RPL_USER;
-}
-
-NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
-    uintptr_t retaddr)
-{
-	istate->rip = retaddr;
-}
-
-NO_TRACE static inline uintptr_t istate_get_pc(istate_t *istate)
-{
-	return istate->rip;
-}
-
-NO_TRACE static inline uintptr_t istate_get_fp(istate_t *istate)
-{
-	return istate->rbp;
-}
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/mm/as.h
===================================================================
--- kernel/arch/amd64/include/mm/as.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,66 +1,0 @@
-/*
- * Copyright (c) 2005 Ondrej Palkovsky
- * 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 amd64mm
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_AS_H_
-#define KERN_amd64_AS_H_
-
-#define ADDRESS_SPACE_HOLE_START  UINT64_C(0x0000800000000000)
-#define ADDRESS_SPACE_HOLE_END    UINT64_C(0xffff7fffffffffff)
-
-#define KERNEL_ADDRESS_SPACE_SHADOWED_ARCH  0
-
-#define KERNEL_ADDRESS_SPACE_START_ARCH  UINT64_C(0xffff800000000000)
-#define KERNEL_ADDRESS_SPACE_END_ARCH    UINT64_C(0xffffffffffffffff)
-#define USER_ADDRESS_SPACE_START_ARCH    UINT64_C(0x0000000000000000)
-#define USER_ADDRESS_SPACE_END_ARCH      UINT64_C(0x00007fffffffffff)
-
-#define as_constructor_arch(as, flags)  (as != as)
-#define as_destructor_arch(as)          (as != as)
-#define as_create_arch(as, flags)       (as != as)
-
-#define as_install_arch(as)
-#define as_deinstall_arch(as)
-#define as_invalidate_translation_cache(as, page, cnt)
-
-typedef struct {
-} as_arch_t;
-
-#include <genarch/mm/as_pt.h>
-
-extern void as_arch_init(void);
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/mm/asid.h
===================================================================
--- kernel/arch/amd64/include/mm/asid.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../../ia32/include/mm/asid.h
Index: kernel/arch/amd64/include/mm/frame.h
===================================================================
--- kernel/arch/amd64/include/mm/frame.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,54 +1,0 @@
-/*
- * Copyright (c) 2005 Ondrej Palkovsky
- * 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 amd64mm
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_FRAME_H_
-#define KERN_amd64_FRAME_H_
-
-#define FRAME_WIDTH  12  /* 4K */
-#define FRAME_SIZE   (1 << FRAME_WIDTH)
-
-#ifndef __ASM__
-
-#include <typedefs.h>
-
-extern void frame_low_arch_init(void);
-extern void frame_high_arch_init(void);
-extern void physmem_print(void);
-
-#endif /* __ASM__ */
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/mm/km.h
===================================================================
--- kernel/arch/amd64/include/mm/km.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,53 +1,0 @@
-/*
- * Copyright (c) 2011 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 amd64mm
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_KM_H_
-#define KERN_amd64_KM_H_
-
-#include <typedefs.h>
-
-#define KM_AMD64_IDENTITY_START		UINT64_C(0xffff800000000000)
-#define KM_AMD64_IDENTITY_SIZE		UINT64_C(0x0000400000000000)
-
-#define KM_AMD64_NON_IDENTITY_START	UINT64_C(0xffffc00000000000)
-#define KM_AMD64_NON_IDENTITY_SIZE	UINT64_C(0x0000400000000000)
-
-extern void km_identity_arch_init(void);
-extern void km_non_identity_arch_init(void);
-extern bool km_is_non_identity_arch(uintptr_t);
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/mm/page.h
===================================================================
--- kernel/arch/amd64/include/mm/page.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,242 +1,0 @@
-/*
- * Copyright (c) 2005 Ondrej Palkovsky
- * 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 amd64mm
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_PAGE_H_
-#define KERN_amd64_PAGE_H_
-
-#include <arch/mm/frame.h>
-#include <trace.h>
-
-#define PAGE_WIDTH  FRAME_WIDTH
-#define PAGE_SIZE   FRAME_SIZE
-
-#ifndef __ASM__
-
-#define KA2PA(x)  (((uintptr_t) (x)) - UINT64_C(0xffff800000000000))
-#define PA2KA(x)  (((uintptr_t) (x)) + UINT64_C(0xffff800000000000))
-
-#else /* __ASM__ */
-
-#define KA2PA(x)  ((x) - 0xffff800000000000)
-#define PA2KA(x)  ((x) + 0xffff800000000000)
-
-#endif /* __ASM__ */
-
-/* Number of entries in each level. */
-#define PTL0_ENTRIES_ARCH  512
-#define PTL1_ENTRIES_ARCH  512
-#define PTL2_ENTRIES_ARCH  512
-#define PTL3_ENTRIES_ARCH  512
-
-/* Page table sizes for each level. */
-#define PTL0_SIZE_ARCH  ONE_FRAME
-#define PTL1_SIZE_ARCH  ONE_FRAME
-#define PTL2_SIZE_ARCH  ONE_FRAME
-#define PTL3_SIZE_ARCH  ONE_FRAME
-
-/* Macros calculating indices into page tables in each level. */
-#define PTL0_INDEX_ARCH(vaddr)  (((vaddr) >> 39) & 0x1ffU)
-#define PTL1_INDEX_ARCH(vaddr)  (((vaddr) >> 30) & 0x1ffU)
-#define PTL2_INDEX_ARCH(vaddr)  (((vaddr) >> 21) & 0x1ffU)
-#define PTL3_INDEX_ARCH(vaddr)  (((vaddr) >> 12) & 0x1ffU)
-
-/* Get PTE address accessors for each level. */
-#define GET_PTL1_ADDRESS_ARCH(ptl0, i) \
-	((pte_t *) ((((uint64_t) ((pte_t *) (ptl0))[(i)].addr_12_31) << 12) | \
-	    (((uint64_t) ((pte_t *) (ptl0))[(i)].addr_32_51) << 32)))
-#define GET_PTL2_ADDRESS_ARCH(ptl1, i) \
-	((pte_t *) ((((uint64_t) ((pte_t *) (ptl1))[(i)].addr_12_31) << 12) | \
-	    (((uint64_t) ((pte_t *) (ptl1))[(i)].addr_32_51) << 32)))
-#define GET_PTL3_ADDRESS_ARCH(ptl2, i) \
-	((pte_t *) ((((uint64_t) ((pte_t *) (ptl2))[(i)].addr_12_31) << 12) | \
-	    (((uint64_t) ((pte_t *) (ptl2))[(i)].addr_32_51) << 32)))
-#define GET_FRAME_ADDRESS_ARCH(ptl3, i) \
-	((uintptr_t *) \
-	    ((((uint64_t) ((pte_t *) (ptl3))[(i)].addr_12_31) << 12) | \
-	    (((uint64_t) ((pte_t *) (ptl3))[(i)].addr_32_51) << 32)))
-
-/* Set PTE address accessors for each level. */
-#define SET_PTL0_ADDRESS_ARCH(ptl0) \
-	(write_cr3((uintptr_t) (ptl0)))
-#define SET_PTL1_ADDRESS_ARCH(ptl0, i, a) \
-	set_pt_addr((pte_t *) (ptl0), (size_t) (i), a)
-#define SET_PTL2_ADDRESS_ARCH(ptl1, i, a) \
-	set_pt_addr((pte_t *) (ptl1), (size_t) (i), a)
-#define SET_PTL3_ADDRESS_ARCH(ptl2, i, a) \
-	set_pt_addr((pte_t *) (ptl2), (size_t) (i), a)
-#define SET_FRAME_ADDRESS_ARCH(ptl3, i, a) \
-	set_pt_addr((pte_t *) (ptl3), (size_t) (i), a)
-
-/* Get PTE flags accessors for each level. */
-#define GET_PTL1_FLAGS_ARCH(ptl0, i) \
-	get_pt_flags((pte_t *) (ptl0), (size_t) (i))
-#define GET_PTL2_FLAGS_ARCH(ptl1, i) \
-	get_pt_flags((pte_t *) (ptl1), (size_t) (i))
-#define GET_PTL3_FLAGS_ARCH(ptl2, i) \
-	get_pt_flags((pte_t *) (ptl2), (size_t) (i))
-#define GET_FRAME_FLAGS_ARCH(ptl3, i) \
-	get_pt_flags((pte_t *) (ptl3), (size_t) (i))
-
-/* Set PTE flags accessors for each level. */
-#define SET_PTL1_FLAGS_ARCH(ptl0, i, x) \
-	set_pt_flags((pte_t *) (ptl0), (size_t) (i), (x))
-#define SET_PTL2_FLAGS_ARCH(ptl1, i, x) \
-	set_pt_flags((pte_t *) (ptl1), (size_t) (i), (x))
-#define SET_PTL3_FLAGS_ARCH(ptl2, i, x) \
-	set_pt_flags((pte_t *) (ptl2), (size_t) (i), (x))
-#define SET_FRAME_FLAGS_ARCH(ptl3, i, x) \
-	set_pt_flags((pte_t *) (ptl3), (size_t) (i), (x))
-
-/* Set PTE present bit accessors for each level. */
-#define SET_PTL1_PRESENT_ARCH(ptl0, i) \
-	set_pt_present((pte_t *) (ptl0), (size_t) (i))
-#define SET_PTL2_PRESENT_ARCH(ptl1, i) \
-	set_pt_present((pte_t *) (ptl1), (size_t) (i))
-#define SET_PTL3_PRESENT_ARCH(ptl2, i) \
-	set_pt_present((pte_t *) (ptl2), (size_t) (i))
-#define SET_FRAME_PRESENT_ARCH(ptl3, i) \
-	set_pt_present((pte_t *) (ptl3), (size_t) (i))
-
-/* Macros for querying the last-level PTE entries. */
-#define PTE_VALID_ARCH(p) \
-	(*((uint64_t *) (p)) != 0)
-#define PTE_PRESENT_ARCH(p) \
-	((p)->present != 0)
-#define PTE_GET_FRAME_ARCH(p) \
-	((((uintptr_t) (p)->addr_12_31) << 12) | \
-	    ((uintptr_t) (p)->addr_32_51 << 32))
-#define PTE_WRITABLE_ARCH(p) \
-	((p)->writeable != 0)
-#define PTE_EXECUTABLE_ARCH(p) \
-	((p)->no_execute == 0)
-
-#ifndef __ASM__
-
-#include <mm/mm.h>
-#include <arch/interrupt.h>
-#include <typedefs.h>
-
-/* Page fault error codes. */
-
-/** When bit on this position is 0, the page fault was caused by a not-present
- * page.
- */
-#define PFERR_CODE_P  (1 << 0)
-
-/** When bit on this position is 1, the page fault was caused by a write. */
-#define PFERR_CODE_RW  (1 << 1)
-
-/** When bit on this position is 1, the page fault was caused in user mode. */
-#define PFERR_CODE_US  (1 << 2)
-
-/** When bit on this position is 1, a reserved bit was set in page directory. */
-#define PFERR_CODE_RSVD  (1 << 3)
-
-/** When bit on this position os 1, the page fault was caused during instruction
- * fecth.
- */
-#define PFERR_CODE_ID  (1 << 4)
-
-/** Page Table Entry. */
-typedef struct {
-	unsigned int present : 1;
-	unsigned int writeable : 1;
-	unsigned int uaccessible : 1;
-	unsigned int page_write_through : 1;
-	unsigned int page_cache_disable : 1;
-	unsigned int accessed : 1;
-	unsigned int dirty : 1;
-	unsigned int unused: 1;
-	unsigned int global : 1;
-	unsigned int soft_valid : 1;  /**< Valid content even if present bit is cleared. */
-	unsigned int avl : 2;
-	unsigned int addr_12_31 : 30;
-	unsigned int addr_32_51 : 21;
-	unsigned int no_execute : 1;
-} __attribute__ ((packed)) pte_t;
-
-NO_TRACE static inline unsigned int get_pt_flags(pte_t *pt, size_t i)
-{
-	pte_t *p = &pt[i];
-	
-	return ((!p->page_cache_disable) << PAGE_CACHEABLE_SHIFT |
-	    (!p->present) << PAGE_PRESENT_SHIFT |
-	    p->uaccessible << PAGE_USER_SHIFT |
-	    1 << PAGE_READ_SHIFT |
-	    p->writeable << PAGE_WRITE_SHIFT |
-	    (!p->no_execute) << PAGE_EXEC_SHIFT |
-	    p->global << PAGE_GLOBAL_SHIFT);
-}
-
-NO_TRACE static inline void set_pt_addr(pte_t *pt, size_t i, uintptr_t a)
-{
-	pte_t *p = &pt[i];
-	
-	p->addr_12_31 = (a >> 12) & UINT32_C(0xfffff);
-	p->addr_32_51 = a >> 32;
-}
-
-NO_TRACE static inline void set_pt_flags(pte_t *pt, size_t i, int flags)
-{
-	pte_t *p = &pt[i];
-	
-	p->page_cache_disable = !(flags & PAGE_CACHEABLE);
-	p->present = !(flags & PAGE_NOT_PRESENT);
-	p->uaccessible = (flags & PAGE_USER) != 0;
-	p->writeable = (flags & PAGE_WRITE) != 0;
-	p->no_execute = (flags & PAGE_EXEC) == 0;
-	p->global = (flags & PAGE_GLOBAL) != 0;
-	
-	/*
-	 * Ensure that there is at least one bit set even if the present bit is cleared.
-	 */
-	p->soft_valid = 1;
-}
-
-NO_TRACE static inline void set_pt_present(pte_t *pt, size_t i)
-{
-	pte_t *p = &pt[i];
-
-	p->present = 1;
-}
-
-extern void page_arch_init(void);
-extern void page_fault(unsigned int, istate_t *);
-
-#endif /* __ASM__ */
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/mm/ptl.h
===================================================================
--- kernel/arch/amd64/include/mm/ptl.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/*
- * Copyright (c) 2005 Ondrej Palkovsky
- * 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 amd64mm
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_PTL_H_
-#define KERN_amd64_PTL_H_
-
-#define PTL_NO_EXEC        (1 << 63)
-#define PTL_ACCESSED       (1 << 5)
-#define PTL_CACHE_DISABLE  (1 << 4)
-#define PTL_CACHE_THROUGH  (1 << 3)
-#define PTL_USER           (1 << 2)
-#define PTL_WRITABLE       (1 << 1)
-#define PTL_PRESENT        1
-#define PTL_2MB_PAGE       (1 << 7)
-
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/mm/tlb.h
===================================================================
--- kernel/arch/amd64/include/mm/tlb.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,41 +1,0 @@
-/*
- * 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.
- */
-
-/** @addtogroup amd64mm
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_TLB_H_
-#define KERN_amd64_TLB_H_
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/pm.h
===================================================================
--- kernel/arch/amd64/include/pm.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,186 +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.
- */
-
-/** @addtogroup amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_PM_H_
-#define KERN_amd64_PM_H_
-
-#ifndef __ASM__
-	#include <typedefs.h>
-	#include <arch/context.h>
-#endif
-
-#define IDT_ITEMS  64
-#define GDT_ITEMS  8
-
-
-#define NULL_DES     0
-/* Warning: Do not reorder the following items, unless you look into syscall.c! */
-#define KTEXT_DES    1
-#define KDATA_DES    2
-#define UDATA_DES    3
-#define UTEXT_DES    4
-#define KTEXT32_DES  5
-/* End of warning */
-#define TSS_DES      6
-
-#ifdef CONFIG_FB
-
-#define VESA_INIT_DES      8
-#define VESA_INIT_SEGMENT  0x8000
-
-#undef GDT_ITEMS
-#define GDT_ITEMS  9
-
-#endif /* CONFIG_FB */
-
-#define GDT_SELECTOR(des)  ((des) << 3)
-
-#define PL_KERNEL  0
-#define PL_USER    3
-
-#define AR_PRESENT    (1 << 7)
-#define AR_DATA       (2 << 3)
-#define AR_CODE       (3 << 3)
-#define AR_WRITABLE   (1 << 1)
-#define AR_READABLE   (1 << 1)
-#define AR_TSS        (0x09U)
-#define AR_INTERRUPT  (0x0eU)
-#define AR_TRAP       (0x0fU)
-
-#define DPL_KERNEL  (PL_KERNEL << 5)
-#define DPL_USER    (PL_USER << 5)
-
-#define TSS_BASIC_SIZE  104
-#define TSS_IOMAP_SIZE  (8 * 1024 + 1)  /* 8K for bitmap + 1 terminating byte for convenience */
-
-#define IO_PORTS  (64 * 1024)
-
-#ifndef __ASM__
-
-typedef struct {
-	unsigned limit_0_15: 16;
-	unsigned base_0_15: 16;
-	unsigned base_16_23: 8;
-	unsigned access: 8;
-	unsigned limit_16_19: 4;
-	unsigned available: 1;
-	unsigned longmode: 1;
-	unsigned special: 1;
-	unsigned granularity : 1;
-	unsigned base_24_31: 8;
-} __attribute__ ((packed)) descriptor_t;
-
-typedef struct {
-	unsigned limit_0_15: 16;
-	unsigned base_0_15: 16;
-	unsigned base_16_23: 8;
-	unsigned type: 4;
-	unsigned : 1;
-	unsigned dpl : 2;
-	unsigned present : 1;
-	unsigned limit_16_19: 4;
-	unsigned available: 1;
-	unsigned : 2;
-	unsigned granularity : 1;
-	unsigned base_24_31: 8;	
-	unsigned base_32_63 : 32;
-	unsigned  : 32;
-} __attribute__ ((packed)) tss_descriptor_t;
-
-typedef struct {
-	unsigned offset_0_15: 16;
-	unsigned selector: 16;
-	unsigned ist:3;
-	unsigned unused: 5;
-	unsigned type: 5;
-	unsigned dpl: 2;
-	unsigned present : 1;
-	unsigned offset_16_31: 16;
-	unsigned offset_32_63: 32;
-	unsigned  : 32;
-} __attribute__ ((packed)) idescriptor_t;
-
-typedef struct {
-	uint16_t limit;
-	uint64_t base;
-} __attribute__ ((packed)) ptr_16_64_t;
-
-typedef struct {
-	uint16_t limit;
-	uint32_t base;
-} __attribute__ ((packed)) ptr_16_32_t;
-
-typedef struct {
-	uint32_t reserve1;
-	uint64_t rsp0;
-	uint64_t rsp1;
-	uint64_t rsp2;
-	uint64_t reserve2;
-	uint64_t ist1;
-	uint64_t ist2;
-	uint64_t ist3;
-	uint64_t ist4;
-	uint64_t ist5;
-	uint64_t ist6;
-	uint64_t ist7;
-	uint64_t reserve3;
-	uint16_t reserve4;
-	uint16_t iomap_base;
-	uint8_t iomap[TSS_IOMAP_SIZE];
-} __attribute__ ((packed)) tss_t;
-
-extern tss_t *tss_p;
-
-extern descriptor_t gdt[];
-extern idescriptor_t idt[];
-
-extern ptr_16_64_t gdtr;
-extern ptr_16_32_t protected_ap_gdtr;
-
-extern void pm_init(void);
-
-extern void gdt_tss_setbase(descriptor_t *d, uintptr_t base);
-extern void gdt_tss_setlimit(descriptor_t *d, uint32_t limit);
-
-extern void idt_init(void);
-extern void idt_setoffset(idescriptor_t *d, uintptr_t offset);
-
-extern void tss_initialize(tss_t *t);
-
-#endif /* __ASM__ */
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/proc/task.h
===================================================================
--- kernel/arch/amd64/include/proc/task.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/*
- * 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 amd64proc
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_TASK_H_
-#define KERN_amd64_TASK_H_
-
-#include <typedefs.h>
-#include <adt/bitmap.h>
-
-typedef struct {
-	/** I/O Permission bitmap Generation counter. */
-	size_t iomapver;
-	/** I/O Permission bitmap. */
-	bitmap_t iomap;
-} task_arch_t;
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/proc/thread.h
===================================================================
--- kernel/arch/amd64/include/proc/thread.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,54 +1,0 @@
-/*
- * Copyright (c) 2005 Ondrej Palkovsky
- * 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 amd64proc
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_THREAD_H_
-#define KERN_amd64_THREAD_H_
-
-/* CAUTION: keep these in sync with low level assembly code in syscall_entry */
-#define SYSCALL_USTACK_RSP  0
-#define SYSCALL_KSTACK_RSP  1
-
-typedef struct {
-	sysarg_t tls;
-	/** User and kernel RSP for syscalls. */
-	uint64_t syscall_rsp[2];
-} thread_arch_t;
-
-#define thr_constructor_arch(t)
-#define thr_destructor_arch(t)
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/smp
===================================================================
--- kernel/arch/amd64/include/smp	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../ia32/include/smp
Index: kernel/arch/amd64/include/syscall.h
===================================================================
--- kernel/arch/amd64/include/syscall.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,43 +1,0 @@
-/*
- * Copyright (c) 2006 Ondrej Palkovsky
- * 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 amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_SYSCALL_H_
-#define KERN_amd64_SYSCALL_H_
-
-extern void syscall_setup_cpu(void);
-
-#endif
-
-/** @}
- */
Index: kernel/arch/amd64/include/types.h
===================================================================
--- kernel/arch/amd64/include/types.h	(revision d59c04658e0199d07b5c3ae2ee72998bdb6b8ee9)
+++ 	(revision )
@@ -1,64 +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.
- */
-
-/** @addtogroup amd64
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_amd64_TYPES_H_
-#define KERN_amd64_TYPES_H_
-
-typedef uint64_t size_t;
-typedef int64_t ssize_t;
-
-typedef uint64_t uintptr_t;
-typedef uint64_t pfn_t;
-
-typedef uint64_t ipl_t;
-
-typedef uint64_t sysarg_t;
-typedef int64_t native_t;
-typedef uint64_t atomic_count_t;
-
-typedef struct {
-} fncptr_t;
-
-#define INTN_C(c)   INT64_C(c)
-#define UINTN_C(c)  UINT64_C(c)
-
-#define PRIdn  PRId64  /**< Format for native_t. */
-#define PRIun  PRIu64  /**< Format for sysarg_t. */
-#define PRIxn  PRIx64  /**< Format for hexadecimal sysarg_t. */
-#define PRIua  PRIu64  /**< Format for atomic_count_t. */
-
-#endif
-
-/** @}
- */
