[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Entfernen des kernel/ Ordner und umbenennen des kernel2/ Ordner



+ Löschen des kernel/ Ordner

Signed-off-by: Nico Mayer <mayerNico@xxxxxxxxxx>
---
 buildmk.sh                                    |   2 +-
 src/kernel/.nobuild                           |   0
 src/{kernel2 => kernel}/include/apic.h        |   0
 .../include/arch/amd64/cpu_arch.h             |   0
 .../include/arch/amd64/mm_arch.h              |   0
 .../include/arch/i386/cpu_arch.h              |   0
 .../include/arch/i386/mm_arch.h               |   0
 src/kernel/include/bitops.h                   |  22 -
 src/kernel/include/console.h                  |  37 +
 src/kernel/include/cpu.h                      |  87 +-
 src/kernel/include/debug.h                    |  59 +-
 src/kernel/include/gdt.h                      |  70 +-
 src/{kernel2 => kernel}/include/im.h          |   0
 src/kernel/include/intr.h                     |  80 --
 src/kernel/include/io.h                       |  51 -
 src/kernel/include/kernel.h                   |  74 +-
 src/kernel/include/kmm.h                      |  10 -
 src/kernel/include/kprintf.h                  |  19 +-
 .../include/lostio/client.h                   |   0
 src/{kernel2 => kernel}/include/lostio/core.h |   0
 .../include/lostio/userspace.h                |   0
 src/{kernel2 => kernel}/include/mm.h          |   0
 src/kernel/include/modules.h                  |   9 -
 src/kernel/include/multiboot.h                | 377 ++++----
 src/{kernel2 => kernel}/include/notifier.h    |   0
 src/kernel/include/paging.h                   |  24 -
 src/kernel/include/phys.h                     |  13 -
 src/{kernel2 => kernel}/include/pic.h         |   0
 src/kernel/include/rpc.h                      |  17 -
 src/kernel/include/shm.h                      |  61 --
 src/{kernel2 => kernel}/include/smp.h         |   0
 src/kernel/include/syscall.h                  | 335 ++++++-
 src/kernel/include/tasks.h                    | 319 +++++--
 src/kernel/include/timer.h                    |  13 +-
 src/kernel/include/tss.h                      |  49 -
 src/kernel/include/vm86.h                     |  40 +-
 src/kernel/include/vmm.h                      |  53 --
 src/kernel/src/Makefile.all                   |   6 -
 .../src/arch/amd64/Makefile.all               |   0
 src/{kernel2 => kernel}/src/arch/amd64/cpu.c  |   0
 .../src/arch/amd64/debug.c                    |   0
 src/{kernel2 => kernel}/src/arch/amd64/gdt.c  |   0
 .../src/arch/amd64/header.S                   |   0
 .../src/arch/amd64/im/im.c                    |   0
 .../src/arch/amd64/im/int_stubs.S             |   0
 .../src/arch/amd64/kernel.ld                  |   0
 .../src/arch/amd64/loader/loader.c            |   0
 .../src/arch/amd64/loader/loader.ld           |   0
 .../src/arch/amd64/loader/startup.S           |   0
 .../src/arch/amd64/mm/mm_context.c            |   0
 .../src/arch/amd64/mm/mm_virt.c               |   0
 .../src/arch/amd64/smp/trampoline.S           |   0
 .../src/arch/i386/Makefile.all                |   0
 src/{kernel2 => kernel}/src/arch/i386/cpu.c   |   0
 src/{kernel2 => kernel}/src/arch/i386/debug.c |   0
 src/{kernel2 => kernel}/src/arch/i386/gdt.c   |   0
 .../src/arch/i386/header.asm                  |   0
 .../src/arch/i386/interrupts/im.c             |   0
 .../src/arch/i386/interrupts/int_stubs.S      |   0
 src/{kernel2 => kernel}/src/arch/i386/io.c    |   0
 .../src/arch/i386/kernel.ld                   |   0
 .../src/arch/i386/mm/mm_context.c             |   0
 .../src/arch/i386/mm/virt.c                   |   0
 .../src/arch/i386/smp/trampoline.S            |   0
 .../src/arch/i386/syscall.c                   |   0
 .../src/arch/i386/syscalls/vm86.c             |   0
 src/{kernel2 => kernel}/src/arch/i386/vm86.c  |   0
 src/kernel/src/console.c                      |  31 +-
 src/kernel/src/debug.c                        | 194 +---
 src/kernel/src/gdt.c                          | 137 ---
 src/kernel/src/header.asm                     |  90 --
 src/kernel/src/init.c                         | 386 +++++---
 src/{kernel2 => kernel}/src/interrupts/apic.c |   0
 src/{kernel2 => kernel}/src/interrupts/im.c   |   0
 src/{kernel2 => kernel}/src/interrupts/pic.c  |   0
 src/kernel/src/intr.c                         | 584 ------------
 src/kernel/src/io.c                           | 232 -----
 src/kernel/src/kernel.ld                      |  37 -
 src/kernel/src/kprintf.c                      | 115 ++-
 src/kernel/src/liballoc.c                     |  37 -
 src/{kernel2 => kernel}/src/libc_helper.c     |   0
 src/{kernel2 => kernel}/src/lostio/client.c   |   0
 .../src/lostio/include/lostio_int.h           |   0
 src/{kernel2 => kernel}/src/lostio/lostio.c   |   0
 .../src/lostio/modules/file.c                 |   0
 .../src/lostio/modules/tmp.c                  |   0
 src/{kernel2 => kernel}/src/lostio/pipes.c    |   0
 src/{kernel2 => kernel}/src/lostio/tree.c     |   0
 .../src/lostio/userspace.c                    |   0
 src/kernel/src/mm/Makefile.all                |   1 -
 src/kernel/src/mm/kmm.c                       | 348 -------
 src/kernel/src/mm/paging.c                    | 476 ----------
 src/kernel/src/mm/phys.c                      | 746 ++++++++-------
 src/kernel/src/mm/shm.c                       | 282 ++++--
 src/{kernel2 => kernel}/src/module.mk         |   0
 src/kernel/src/modules.c                      | 371 --------
 src/{kernel2 => kernel}/src/notifier.c        |   0
 src/kernel/src/rpc.c                          | 343 -------
 src/kernel/src/schedule.c                     | 195 ----
 src/{kernel2 => kernel}/src/smp/Makefile.conf |   0
 .../src/smp/rm_trampoline.asm                 |   0
 src/{kernel2 => kernel}/src/smp/smp.c         |   0
 src/kernel/src/stubs.asm                      | 145 ---
 src/kernel/src/syscall.c                      | 899 +++---------------
 src/{kernel2 => kernel}/src/syscalls/io.c     |   0
 .../src/syscalls/lio_server.c                 |   0
 src/{kernel2 => kernel}/src/syscalls/lostio.c |   0
 src/{kernel2 => kernel}/src/syscalls/mem.c    |   0
 src/{kernel2 => kernel}/src/syscalls/misc.c   |   0
 src/{kernel2 => kernel}/src/syscalls/mutex.c  |   0
 src/{kernel2 => kernel}/src/syscalls/pm.c     |   0
 src/{kernel2 => kernel}/src/syscalls/pv.c     |   0
 src/{kernel2 => kernel}/src/syscalls/rpc.c    |   0
 src/{kernel2 => kernel}/src/syscalls/shm.c    |   0
 src/kernel/src/task.c                         | 422 --------
 src/{kernel2 => kernel}/src/tasks/modules.c   |   0
 src/{kernel2 => kernel}/src/tasks/pm.c        |   0
 src/{kernel2 => kernel}/src/tasks/scheduler.c |   0
 src/{kernel2 => kernel}/src/tasks/thread.c    |   0
 src/kernel/src/timer.c                        |  95 +-
 src/kernel/src/tss.c                          |  44 -
 src/kernel/src/vm86.c                         | 392 --------
 src/kernel2/.ignorenobuild                    |   0
 src/kernel2/include/console.h                 |  47 -
 src/kernel2/include/cpu.h                     |  58 --
 src/kernel2/include/debug.h                   |  64 --
 src/kernel2/include/gdt.h                     |  44 -
 src/kernel2/include/kernel.h                  |  63 --
 src/kernel2/include/kprintf.h                 |  12 -
 src/kernel2/include/multiboot.h               | 188 ----
 src/kernel2/include/syscall.h                 | 327 -------
 src/kernel2/include/tasks.h                   | 281 ------
 src/kernel2/include/timer.h                   |  47 -
 src/kernel2/include/vm86.h                    |  43 -
 src/kernel2/src/console.c                     | 609 ------------
 src/kernel2/src/debug.c                       | 105 --
 src/kernel2/src/init.c                        | 357 -------
 src/kernel2/src/kprintf.c                     | 266 ------
 src/kernel2/src/mm/phys.c                     | 615 ------------
 src/kernel2/src/mm/shm.c                      | 237 -----
 src/kernel2/src/syscall.c                     | 180 ----
 src/kernel2/src/timer.c                       | 169 ----
 142 files changed, 2227 insertions(+), 9914 deletions(-)
 delete mode 100644 src/kernel/.nobuild
 rename src/{kernel2 => kernel}/include/apic.h (100%)
 rename src/{kernel2 => kernel}/include/arch/amd64/cpu_arch.h (100%)
 rename src/{kernel2 => kernel}/include/arch/amd64/mm_arch.h (100%)
 rename src/{kernel2 => kernel}/include/arch/i386/cpu_arch.h (100%)
 rename src/{kernel2 => kernel}/include/arch/i386/mm_arch.h (100%)
 delete mode 100644 src/kernel/include/bitops.h
 rename src/{kernel2 => kernel}/include/im.h (100%)
 delete mode 100644 src/kernel/include/intr.h
 delete mode 100644 src/kernel/include/io.h
 delete mode 100644 src/kernel/include/kmm.h
 rename src/{kernel2 => kernel}/include/lostio/client.h (100%)
 rename src/{kernel2 => kernel}/include/lostio/core.h (100%)
 rename src/{kernel2 => kernel}/include/lostio/userspace.h (100%)
 rename src/{kernel2 => kernel}/include/mm.h (100%)
 delete mode 100644 src/kernel/include/modules.h
 rename src/{kernel2 => kernel}/include/notifier.h (100%)
 delete mode 100644 src/kernel/include/paging.h
 delete mode 100644 src/kernel/include/phys.h
 rename src/{kernel2 => kernel}/include/pic.h (100%)
 delete mode 100644 src/kernel/include/rpc.h
 delete mode 100644 src/kernel/include/shm.h
 rename src/{kernel2 => kernel}/include/smp.h (100%)
 delete mode 100644 src/kernel/include/tss.h
 delete mode 100644 src/kernel/include/vmm.h
 delete mode 100644 src/kernel/src/Makefile.all
 rename src/{kernel2 => kernel}/src/arch/amd64/Makefile.all (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/cpu.c (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/debug.c (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/gdt.c (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/header.S (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/im/im.c (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/im/int_stubs.S (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/kernel.ld (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/loader/loader.c (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/loader/loader.ld (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/loader/startup.S (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/mm/mm_context.c (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/mm/mm_virt.c (100%)
 rename src/{kernel2 => kernel}/src/arch/amd64/smp/trampoline.S (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/Makefile.all (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/cpu.c (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/debug.c (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/gdt.c (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/header.asm (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/interrupts/im.c (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/interrupts/int_stubs.S (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/io.c (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/kernel.ld (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/mm/mm_context.c (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/mm/virt.c (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/smp/trampoline.S (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/syscall.c (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/syscalls/vm86.c (100%)
 rename src/{kernel2 => kernel}/src/arch/i386/vm86.c (100%)
 delete mode 100644 src/kernel/src/gdt.c
 delete mode 100644 src/kernel/src/header.asm
 rename src/{kernel2 => kernel}/src/interrupts/apic.c (100%)
 rename src/{kernel2 => kernel}/src/interrupts/im.c (100%)
 rename src/{kernel2 => kernel}/src/interrupts/pic.c (100%)
 delete mode 100644 src/kernel/src/intr.c
 delete mode 100644 src/kernel/src/io.c
 delete mode 100644 src/kernel/src/kernel.ld
 delete mode 100644 src/kernel/src/liballoc.c
 rename src/{kernel2 => kernel}/src/libc_helper.c (100%)
 rename src/{kernel2 => kernel}/src/lostio/client.c (100%)
 rename src/{kernel2 => kernel}/src/lostio/include/lostio_int.h (100%)
 rename src/{kernel2 => kernel}/src/lostio/lostio.c (100%)
 rename src/{kernel2 => kernel}/src/lostio/modules/file.c (100%)
 rename src/{kernel2 => kernel}/src/lostio/modules/tmp.c (100%)
 rename src/{kernel2 => kernel}/src/lostio/pipes.c (100%)
 rename src/{kernel2 => kernel}/src/lostio/tree.c (100%)
 rename src/{kernel2 => kernel}/src/lostio/userspace.c (100%)
 delete mode 100644 src/kernel/src/mm/Makefile.all
 delete mode 100644 src/kernel/src/mm/kmm.c
 delete mode 100644 src/kernel/src/mm/paging.c
 rename src/{kernel2 => kernel}/src/module.mk (100%)
 delete mode 100644 src/kernel/src/modules.c
 rename src/{kernel2 => kernel}/src/notifier.c (100%)
 delete mode 100644 src/kernel/src/rpc.c
 delete mode 100644 src/kernel/src/schedule.c
 rename src/{kernel2 => kernel}/src/smp/Makefile.conf (100%)
 rename src/{kernel2 => kernel}/src/smp/rm_trampoline.asm (100%)
 rename src/{kernel2 => kernel}/src/smp/smp.c (100%)
 delete mode 100644 src/kernel/src/stubs.asm
 rename src/{kernel2 => kernel}/src/syscalls/io.c (100%)
 rename src/{kernel2 => kernel}/src/syscalls/lio_server.c (100%)
 rename src/{kernel2 => kernel}/src/syscalls/lostio.c (100%)
 rename src/{kernel2 => kernel}/src/syscalls/mem.c (100%)
 rename src/{kernel2 => kernel}/src/syscalls/misc.c (100%)
 rename src/{kernel2 => kernel}/src/syscalls/mutex.c (100%)
 rename src/{kernel2 => kernel}/src/syscalls/pm.c (100%)
 rename src/{kernel2 => kernel}/src/syscalls/pv.c (100%)
 rename src/{kernel2 => kernel}/src/syscalls/rpc.c (100%)
 rename src/{kernel2 => kernel}/src/syscalls/shm.c (100%)
 delete mode 100644 src/kernel/src/task.c
 rename src/{kernel2 => kernel}/src/tasks/modules.c (100%)
 rename src/{kernel2 => kernel}/src/tasks/pm.c (100%)
 rename src/{kernel2 => kernel}/src/tasks/scheduler.c (100%)
 rename src/{kernel2 => kernel}/src/tasks/thread.c (100%)
 delete mode 100644 src/kernel/src/tss.c
 delete mode 100644 src/kernel/src/vm86.c
 delete mode 100644 src/kernel2/.ignorenobuild
 delete mode 100644 src/kernel2/include/console.h
 delete mode 100644 src/kernel2/include/cpu.h
 delete mode 100644 src/kernel2/include/debug.h
 delete mode 100644 src/kernel2/include/gdt.h
 delete mode 100644 src/kernel2/include/kernel.h
 delete mode 100644 src/kernel2/include/kprintf.h
 delete mode 100644 src/kernel2/include/multiboot.h
 delete mode 100644 src/kernel2/include/syscall.h
 delete mode 100644 src/kernel2/include/tasks.h
 delete mode 100644 src/kernel2/include/timer.h
 delete mode 100644 src/kernel2/include/vm86.h
 delete mode 100644 src/kernel2/src/console.c
 delete mode 100644 src/kernel2/src/debug.c
 delete mode 100644 src/kernel2/src/init.c
 delete mode 100644 src/kernel2/src/kprintf.c
 delete mode 100644 src/kernel2/src/mm/phys.c
 delete mode 100644 src/kernel2/src/mm/shm.c
 delete mode 100644 src/kernel2/src/syscall.c
 delete mode 100644 src/kernel2/src/timer.c

diff --git a/buildmk.sh b/buildmk.sh
index ccd7d021..e5e61f90 100644
--- a/buildmk.sh
+++ b/buildmk.sh
@@ -134,7 +134,7 @@ AS=\$(AS_BINARY)
 all:
 EOF
 
-if [ "`pwd | grep '/src/kernel2'`" == "" ]; then
+if [ "`pwd | grep '/src/kernel'`" == "" ]; then
 cat <<EOF >> Makefile
 	\$(MAKE) --no-print-directory -s makefiles
 	\$(MAKE) --no-print-directory -s subdirs
diff --git a/src/kernel/.nobuild b/src/kernel/.nobuild
deleted file mode 100644
index e69de29b..00000000
diff --git a/src/kernel2/include/apic.h b/src/kernel/include/apic.h
similarity index 100%
rename from src/kernel2/include/apic.h
rename to src/kernel/include/apic.h
diff --git a/src/kernel2/include/arch/amd64/cpu_arch.h b/src/kernel/include/arch/amd64/cpu_arch.h
similarity index 100%
rename from src/kernel2/include/arch/amd64/cpu_arch.h
rename to src/kernel/include/arch/amd64/cpu_arch.h
diff --git a/src/kernel2/include/arch/amd64/mm_arch.h b/src/kernel/include/arch/amd64/mm_arch.h
similarity index 100%
rename from src/kernel2/include/arch/amd64/mm_arch.h
rename to src/kernel/include/arch/amd64/mm_arch.h
diff --git a/src/kernel2/include/arch/i386/cpu_arch.h b/src/kernel/include/arch/i386/cpu_arch.h
similarity index 100%
rename from src/kernel2/include/arch/i386/cpu_arch.h
rename to src/kernel/include/arch/i386/cpu_arch.h
diff --git a/src/kernel2/include/arch/i386/mm_arch.h b/src/kernel/include/arch/i386/mm_arch.h
similarity index 100%
rename from src/kernel2/include/arch/i386/mm_arch.h
rename to src/kernel/include/arch/i386/mm_arch.h
diff --git a/src/kernel/include/bitops.h b/src/kernel/include/bitops.h
deleted file mode 100644
index 5f3e4e18..00000000
--- a/src/kernel/include/bitops.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef BITOPS_H

-#define BITOPS_H

-

-/* Voraussetzung: Mindestens ein Bit von i muss gesetzt sein. */

-static inline unsigned int bit_scan_forward(unsigned int i)

-{

-    unsigned int j;

-#if 0

-    for(j = 0; j < 32; j++)

-    {

-        if(i & (1 << j))

-        {

-            return j;

-        }

-    }

-#else

-    __asm__("bsfl %1, %0\n\t" : "=r"(j) : "g"(i));

-    return j;

-#endif

-}

-

-#endif /* ndef BITOPS_H */

diff --git a/src/kernel/include/console.h b/src/kernel/include/console.h
index 146e749d..60e7e8e6 100644
--- a/src/kernel/include/console.h
+++ b/src/kernel/include/console.h
@@ -1,6 +1,43 @@
+/*

+ * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.

+ *

+ * This code is derived from software contributed to the tyndur Project

+ * by Burkhard Weseloh.

+ *

+ * Redistribution and use in source and binary forms, with or without

+ * modification, are permitted provided that the following conditions

+ * are met:

+ * 1. Redistributions of source code must retain the above copyright

+ *    notice, this list of conditions and the following disclaimer.

+ * 2. 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.

+ * 3. All advertising materials mentioning features or use of this software

+ *    must display the following acknowledgement:

+ *     This product includes software developed by the tyndur Project

+ *     and its contributors.

+ * 4. Neither the name of the tyndur Project nor the names of its

+ *    contributors may be used to endorse or promote products derived

+ *    from this software without specific prior written permission.

+ *

+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

+ * ``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 COPYRIGHT HOLDERS OR

+ * CONTRIBUTORS 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 CONSOLE_H

 #define CONSOLE_H

 

+extern void init_console(void);

+

 extern void con_putc(const char c); // Zeichen ausgeben ohne Auswertung der ANSI-Codes

 extern void con_putc_ansi(const char c); // Zeichen ausgeben mit Auswertung der ANSI-Codes

 extern void con_puts(const char * s); // Zeichenkette ausgeben mit Auswertung der ANSI-Codes

diff --git a/src/kernel/include/cpu.h b/src/kernel/include/cpu.h
index 7e02c047..97b5cdee 100644
--- a/src/kernel/include/cpu.h
+++ b/src/kernel/include/cpu.h
@@ -1,29 +1,58 @@
-#ifndef CPU_H

-#define CPU_H

-

-#include <stdint.h>

-

-#define CR0_PE		0x00000001 // Protection Enable

-#define CR0_PG		0x80000000 // Paging

-

-#define CR4_PSE		0x00000010 // Page Size Extensions

-

-// eflags register

-#define FL_TF		0x00000100 // Trap Flag

-#define FL_IF		0x00000200 // Interrupt Flag

-#define FL_IOPL0	0x00000000 // I/O Privilege Level 0

-#define FL_IOPL1	0x00001000 // I/O Privilege Level 1

-#define FL_IOPL2	0x00002000 // I/O Privilege Level 2

-#define FL_IOPL3	0x00003000 // I/O Privilege Level 3

-#define FL_NT		0x00004000 // Nested Task

-#define FL_RF		0x00010000 // Resume Flag

-#define FL_VM		0x00020000 // Virtual 8086 mode

-

-static inline uint32_t read_cr2(void)

-{

-    uint32_t ret;

-    __asm volatile ("mov %%cr2, %0" : "=r"(ret));

-    return ret;

-}

-

-#endif /* ndef CPU_H */

+/*
+ * Copyright (c) 2007-2012 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Antoine Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the tyndur Project
+ *     and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``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 COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS 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 _CPU_H_
+#define _CPU_H_
+
+#include <types.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "tasks.h"
+#include "cpu_arch.h"
+
+extern cpu_t cpus[];
+extern size_t cpu_count;
+
+cpu_t* cpu_get_current(void);
+void cpu_dump(machine_state_t* machine_state);
+
+/**
+ * Wird aufgerufen, nachdem zu einem neuen Task gewechselt wurde
+ */
+void cpu_prepare_current_task(void);
+
+#endif //ifndef _CPU_H_
+
+
diff --git a/src/kernel/include/debug.h b/src/kernel/include/debug.h
index ce53df58..d8540b40 100644
--- a/src/kernel/include/debug.h
+++ b/src/kernel/include/debug.h
@@ -1,3 +1,41 @@
+/*

+ * Copyright (c) 2006-2008 The tyndur Project. All rights reserved.

+ *

+ * This code is derived from software contributed to the tyndur Project

+ * by Kevin Wolf.

+ *

+ * Redistribution and use in source and binary forms, with or without

+ * modification, are permitted provided that the following conditions

+ * are met:

+ * 1. Redistributions of source code must retain the above copyright

+ *    notice, this list of conditions and the following disclaimer.

+ * 2. 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.

+ * 3. All advertising materials mentioning features or use of this software

+ *    must display the following acknowledgement:

+ *     This product includes software developed by the tyndur Project

+ *     and its contributors.

+ * 4. Neither the name of the tyndur Project nor the names of its

+ *    contributors may be used to endorse or promote products derived

+ *    from this software without specific prior written permission.

+ *

+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

+ * ``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 COPYRIGHT HOLDERS OR

+ * CONTRIBUTORS 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 _DEBUG_H_

+#define _DEBUG_H_

+

 #include <stdint.h>

 #include <stdbool.h>

 

@@ -7,13 +45,6 @@
 #define DEBUG_FLAG_STACK_BACKTRACE 2

 #define DEBUG_FLAG_PEDANTIC 4

 #define DEBUG_FLAG_SYSCALL 8

-#define DEBUG_FLAG_NO_KCONSOLE 16

-

-/* Int2Str , Wandelt signed ints in Strings um */

-char* int2str(signed int value,char *result);

-

-/* Einfache Print-Funktion f�r grundlegende Ausgaben */

-void print(char *string,const int len);

 

 ///Setzt die richtigen Debug-Flags anhand der Commandline vom bootloader

 void debug_parse_cmdline(char* cmdline);

@@ -23,9 +54,11 @@ bool debug_test_flag(uint32_t flag);
 

 ///Gibt die Debug-Meldung aus, wenn das Flag gesetzt ist

 void debug_print(uint32_t flag, const char* message);

-

-/* 

- * Gibt einen Stack Backtrace aus, beginnend an den �bergebenen Werten

- * f�r ebp und eip

- */

-void stack_backtrace_ebp(uint32_t start_ebp, uint32_t start_eip);

+
+/*
+ * Gibt einen Stack Backtrace aus, beginnend an den �bergebenen Werten
+ * f�r bp und ip
+ */
+void stack_backtrace(uintptr_t start_bp, uintptr_t start_ip);
+
+#endif
diff --git a/src/kernel/include/gdt.h b/src/kernel/include/gdt.h
index 12e78794..426775c8 100644
--- a/src/kernel/include/gdt.h
+++ b/src/kernel/include/gdt.h
@@ -1,26 +1,44 @@
-#ifndef GDT_H
-#define GDT_H
-
-#include <stdint.h>
-
-#define GDT_SIZE 6
-
-#define GDT_CODESEG 0x0A
-#define GDT_DATASEG 0x02
-#define GDT_TSS 0x09
-#define GDT_PRESENT 0x80
-#define GDT_SEGMENT 0x10
-
-#define SYS_CODE_SEL 0x08
-#define SYS_DATA_SEL 0x10
-#define USER_CODE_SEL 0x18
-#define USER_DATA_SEL 0x20
-#define TSS_SEL 0x28
-
-void init_gdt(void);
-void gdt_set_descriptor(int segment, uint32_t size, uint32_t base,
-    uint8_t access, int dpl);
-void gdt_set_descriptor_byte_granularity(int segment, uint32_t size,
-    uint32_t base, uint8_t access, int dpl);
-
-#endif
+/*

+ * Copyright (c) 2007 The tyndur Project. All rights reserved.

+ *

+ * This code is derived from software contributed to the tyndur Project

+ * by Kevin Wolf.

+ *

+ * Redistribution and use in source and binary forms, with or without

+ * modification, are permitted provided that the following conditions

+ * are met:

+ * 1. Redistributions of source code must retain the above copyright

+ *    notice, this list of conditions and the following disclaimer.

+ * 2. 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.

+ * 3. All advertising materials mentioning features or use of this software

+ *    must display the following acknowledgement:

+ *     This product includes software developed by the tyndur Project

+ *     and its contributors.

+ * 4. Neither the name of the tyndur Project nor the names of its

+ *    contributors may be used to endorse or promote products derived

+ *    from this software without specific prior written permission.

+ *

+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

+ * ``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 COPYRIGHT HOLDERS OR

+ * CONTRIBUTORS 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 _GDT_H_

+#define _GDT_H_

+#include <types.h>

+

+void gdt_init(void);

+void gdt_init_local(void);

+

+#endif //ifndef _GDT_H_

+

diff --git a/src/kernel2/include/im.h b/src/kernel/include/im.h
similarity index 100%
rename from src/kernel2/include/im.h
rename to src/kernel/include/im.h
diff --git a/src/kernel/include/intr.h b/src/kernel/include/intr.h
deleted file mode 100644
index 99305021..00000000
--- a/src/kernel/include/intr.h
+++ /dev/null
@@ -1,80 +0,0 @@
-#ifndef INTR_H
-#define INTR_H
-
-#include <stdint.h>
-
-#include "tasks.h"
-
-#define SYSCALL_INTERRUPT 0x30
-
-#define IDT_SIZE 256
-
-#define IDT_TASK_GATE 0x9
-#define IDT_INTERRUPT_GATE 0xe
-#define IDT_TRAP_GATE 0xf
-
-#define IDT_DESC_PRESENT 0x80
-
-void init_idt(void);
-void set_intr(int intr, uint16_t selector, void* handler, int dpl, int type);
-void set_intr_handling_task(uint8_t intr, struct task * task);
-void remove_intr_handling_task(struct task* task);
-
-typedef void(*pfIrqHandler)(int, uint32_t*);
-
-#define IRQ_BASE 0x20
-
-#define PIC1            0x20           /* IO base address for master PIC */
-#define PIC2            0xA0           /* IO base address for slave PIC */
-#define PIC1_COMMAND    PIC1
-#define PIC1_DATA       (PIC1+1)
-#define PIC2_COMMAND    PIC2
-#define PIC2_DATA       (PIC2+1)
-#define PIC_EOI         0x20            /* End - of - interrupt command code */
-
-#define ICW1_ICW4       0x01            /* ICW4 (not) needed */
-#define ICW1_SINGLE     0x02            /* Single (cascade) mode */
-#define ICW1_INTERVAL4  0x04            /* Call address interval 4 (8) */
-#define ICW1_LEVEL      0x08            /* Level triggered (edge) mode */
-#define ICW1_INIT       0x10            /* Initialization - required! */
-
-#define ICW4_8086       0x01            /* 8086/88 (MCS-80/85) mode */
-#define ICW4_AUTO       0x02            /* Auto (normal) EOI */
-#define ICW4_BUF_SLAVE  0x08            /* Buffered mode/slave */
-#define ICW4_BUF_MASTER 0x0C            /* Buffered mode/master */
-#define ICW4_SFNM       0x10            /* Special fully nested (not) */
-
-int request_irq(int irq, void * handler);
-int release_irq(int irq);
-
-inline static void enable_interrupts(void) { __asm__ __volatile__("sti"); }
-inline static void disable_interrupts(void) { __asm__ __volatile__("cli"); }
-
-void disable_irq(uint8_t irq);
-void enable_irq(uint8_t irq);
-
-struct int_stack_frame
-{
-    uint16_t gs  __attribute__((aligned(4)));
-    uint16_t fs  __attribute__((aligned(4)));
-    uint16_t es  __attribute__((aligned(4)));
-    uint16_t ds  __attribute__((aligned(4)));
-    uint32_t edi;
-    uint32_t esi;
-    uint32_t ebp;
-    uint32_t esp_;
-    uint32_t ebx;
-    uint32_t edx;
-    uint32_t ecx;
-    uint32_t eax;
-    uint32_t interrupt_number;
-    uint32_t error_code;
-    uint32_t eip;
-    uint32_t cs;
-    uint32_t eflags;
-    uint32_t esp;
-    uint32_t ss;
-};
-
-
-#endif
diff --git a/src/kernel/include/io.h b/src/kernel/include/io.h
deleted file mode 100644
index bf22d8db..00000000
--- a/src/kernel/include/io.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*  
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS 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 _IO_H_
-#define _IO_H_
-
-#include <stdint.h>
-
-#include "tasks.h"
-
-void init_io_ports(void);
-bool io_ports_request(struct task* task, uint32_t port, uint32_t length);
-bool io_ports_release(struct task* task, uint32_t port, uint32_t length);
-void io_ports_release_all(struct task* task);
-
-//Nur fuer Debugen einsetzen!
-void io_ports_check(struct task* task);
-
-#endif
diff --git a/src/kernel/include/kernel.h b/src/kernel/include/kernel.h
index e5ba427c..aabbb9e5 100644
--- a/src/kernel/include/kernel.h
+++ b/src/kernel/include/kernel.h
@@ -1,27 +1,63 @@
-#ifndef KERNEL_H

-#define KERNEL_H

-    

-//#define COOPERATIVE_MULTITASKING
+/*
+ * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Burkhard Weseloh.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the tyndur Project
+ *     and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``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 COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS 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 _KERNEL_H_
+#define _KERNEL_H_
 
 #include <stdint.h>
-#include <types.h>
 
-__attribute__((noreturn)) void panic(char * message, ...);
+extern uint64_t timer_ticks;
+
+__attribute__((noreturn)) void panic(char* message, ...);
 
-paddr_t phys_alloc_page(void);
-paddr_t phys_alloc_page_range(unsigned int num);
+#define GLUE(x,y) x ## y
+#define BUILD_ASSERT(cnt) GLUE(__cdi_build_assert, cnt)
+#define BUILD_BUG_ON(x) \
+    struct BUILD_ASSERT(__COUNTER__) { int assertion[(x) ? -1 : 1];  };
 
-paddr_t phys_alloc_dma_page(void);
-paddr_t phys_alloc_dma_page_range(unsigned int num);
+#define BUG_ON(c) \
+    do { \
+        if (c) { \
+            panic("BUG: %s:%d: " #c, __FILE__, __LINE__); \
+        } \
+    } while(0)
 
-paddr_t phys_alloc_page_limit(uint32_t lower_limit);
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
 
-void phys_free_page(paddr_t page);
-void phys_free_page_range(paddr_t page, unsigned int num);
+#define DIV_ROUND_UP(x, align)  (((x) + (align) + 1) / (align))
+#define ROUND_UP(x, align) (DIV_ROUND_UP(x, align) * (align))
 
-extern void kernel_start(void);
-extern void kernel_phys_start(void);
-extern void kernel_end(void);

-extern void kernel_phys_end(void);

-

-#endif /* ndef KERNEL_H */

+#endif
diff --git a/src/kernel/include/kmm.h b/src/kernel/include/kmm.h
deleted file mode 100644
index a895fd07..00000000
--- a/src/kernel/include/kmm.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef KMM_H
-#define KMM_H
-
-#include "types.h"
-
-vaddr_t find_contiguous_kernel_pages(int num);
-vaddr_t map_phys_addr(paddr_t paddr, size_t size);
-void free_phys_addr(vaddr_t vaddr, size_t size);
-
-#endif
diff --git a/src/kernel/include/kprintf.h b/src/kernel/include/kprintf.h
index c33ba814..4b7e29ae 100644
--- a/src/kernel/include/kprintf.h
+++ b/src/kernel/include/kprintf.h
@@ -1,7 +1,12 @@
-#ifndef KPRINTF_H

-#define KPRINTF_H

-

-extern void kprintf(char * format, ...);

-extern void kaprintf(char * format, int ** args);

-

-#endif /* ndef KPRINTF_H */

+#ifndef KPRINTF_H
+#define KPRINTF_H
+
+#include <stdint.h>
+#include <stdarg.h>
+
+void kprintf(char* format, ...) __attribute__((format(printf,1,2)));
+void kaprintf(char* format, va_list args);
+
+/// Ist nur zu Testzwecken hier
+void kputn(unsigned long long x, int radix, int pad, char padchar);
+#endif /* ndef KPRINTF_H */
diff --git a/src/kernel2/include/lostio/client.h b/src/kernel/include/lostio/client.h
similarity index 100%
rename from src/kernel2/include/lostio/client.h
rename to src/kernel/include/lostio/client.h
diff --git a/src/kernel2/include/lostio/core.h b/src/kernel/include/lostio/core.h
similarity index 100%
rename from src/kernel2/include/lostio/core.h
rename to src/kernel/include/lostio/core.h
diff --git a/src/kernel2/include/lostio/userspace.h b/src/kernel/include/lostio/userspace.h
similarity index 100%
rename from src/kernel2/include/lostio/userspace.h
rename to src/kernel/include/lostio/userspace.h
diff --git a/src/kernel2/include/mm.h b/src/kernel/include/mm.h
similarity index 100%
rename from src/kernel2/include/mm.h
rename to src/kernel/include/mm.h
diff --git a/src/kernel/include/modules.h b/src/kernel/include/modules.h
deleted file mode 100644
index 1b0da44a..00000000
--- a/src/kernel/include/modules.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef MODULES_H
-#define MODULES_H
-
-#include "multiboot.h"
-
-void load_init_module(struct multiboot_info * multiboot_info);
-void load_multiboot_modules(struct multiboot_info * multiboot_info);
-
-#endif
diff --git a/src/kernel/include/multiboot.h b/src/kernel/include/multiboot.h
index 696679a7..39f116f3 100644
--- a/src/kernel/include/multiboot.h
+++ b/src/kernel/include/multiboot.h
@@ -1,189 +1,188 @@
-/*-

- * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.

- * All rights reserved.

- *

- * This code is derived from software contributed to The NetBSD Foundation

- * by Julio M. Merino Vidal.

- *

- * Redistribution and use in source and binary forms, with or without

- * modification, are permitted provided that the following conditions

- * are met:

- * 1. Redistributions of source code must retain the above copyright

- *    notice, this list of conditions and the following disclaimer.

- * 2. 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.

- * 3. All advertising materials mentioning features or use of this software

- *    must display the following acknowledgement:

- *	This product includes software developed by the NetBSD

- *	Foundation, Inc. and its contributors.

- * 4. Neither the name of The NetBSD Foundation nor the names of its

- *    contributors may be used to endorse or promote products derived

- *    from this software without specific prior written permission.

- *

- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS

- * ``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 FOUNDATION OR CONTRIBUTORS

- * 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 MULTIBOOT_H

-#define MULTIBOOT_H

-

-#include <stdint.h>

-#include <types.h>

-

-/* --------------------------------------------------------------------- */

-

-/*

- * Multiboot header structure.

- */

-#define MULTIBOOT_HEADER_MAGIC		    0x1BADB002

-#define MULTIBOOT_HEADER_MODS_ALIGNED	0x00000001

-#define MULTIBOOT_HEADER_WANT_MEMORY	0x00000002

-#define MULTIBOOT_HEADER_HAS_VBE	    0x00000004

-#define MULTIBOOT_HEADER_HAS_ADDR   	0x00010000

-

-struct multiboot_header {

-	uint32_t   mh_magic;

-	uint32_t   mh_flags;

-	uint32_t   mh_checksum;

-

-	/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */

-	paddr_t mh_header_addr;

-	paddr_t mh_load_addr;

-	paddr_t mh_load_end_addr;

-	paddr_t mh_bss_end_addr;

-	paddr_t mh_entry_addr;

-

-	/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */

-	uint32_t   mh_mode_type;

-	uint32_t   mh_width;

-	uint32_t   mh_height;

-	uint32_t   mh_depth;

-};

-

-/* --------------------------------------------------------------------- */

-

-/*

- * Multiboot information structure.

- */

-#define MULTIBOOT_INFO_MAGIC		    0x2BADB002

-#define MULTIBOOT_INFO_HAS_MEMORY	    0x00000001

-#define MULTIBOOT_INFO_HAS_BOOT_DEVICE	0x00000002

-#define MULTIBOOT_INFO_HAS_CMDLINE	    0x00000004

-#define MULTIBOOT_INFO_HAS_MODS		    0x00000008

-#define MULTIBOOT_INFO_HAS_AOUT_SYMS	0x00000010

-#define MULTIBOOT_INFO_HAS_ELF_SYMS	    0x00000020

-#define MULTIBOOT_INFO_HAS_MMAP		    0x00000040

-#define MULTIBOOT_INFO_HAS_DRIVES	    0x00000080

-#define MULTIBOOT_INFO_HAS_CONFIG_TABLE	0x00000100

-#define MULTIBOOT_INFO_HAS_LOADER_NAME	0x00000200

-#define MULTIBOOT_INFO_HAS_APM_TABLE	0x00000400

-#define MULTIBOOT_INFO_HAS_VBE		    0x00000800

-

-struct multiboot_info {

-	uint32_t	mi_flags;

-

-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */

-	uint32_t	mi_mem_lower;

-	uint32_t	mi_mem_upper;

-

-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */

-	uint8_t	mi_boot_device_part3;

-	uint8_t	mi_boot_device_part2;

-	uint8_t	mi_boot_device_part1;

-	uint8_t	mi_boot_device_drive;

-

-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */

-	char *	mi_cmdline;

-

-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */

-	uint32_t	mi_mods_count;

-	struct multiboot_module * mi_mods_addr;

-

-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */

-	uint32_t	mi_elfshdr_num;

-	uint32_t	mi_elfshdr_size;

-	vaddr_t	mi_elfshdr_addr;

-	uint32_t	mi_elfshdr_shndx;

-

-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */

-	uint32_t	mi_mmap_length;

-	vaddr_t	mi_mmap_addr;

-

-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */

-	uint32_t	mi_drives_length;

-	vaddr_t	mi_drives_addr;

-

-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */

-	void *	unused_mi_config_table;

-

-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */

-	char *	mi_loader_name;

-

-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */

-	void *	unused_mi_apm_table;

-

-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */

-	void *	unused_mi_vbe_control_info;

-	void *	unused_mi_vbe_mode_info;

-	paddr_t	unused_mi_vbe_interface_seg;

-	paddr_t	unused_mi_vbe_interface_off;

-	uint32_t	unused_mi_vbe_interface_len;

-};

-

-extern struct multiboot_info multiboot_info;

-

-/* --------------------------------------------------------------------- */

-

-/*

- * Drive information.  This describes an entry in the drives table as

- * pointed to by mi_drives_addr.

- */

-struct multiboot_drive {

-	uint32_t	md_length;

-	uint8_t	md_number;

-	uint8_t	md_mode;

-	uint16_t	md_cylinders;

-	uint8_t	md_heads;

-	uint8_t	md_sectors;

-

-	/* The variable-sized 'ports' field comes here, so this structure

-	 * can be longer. */

-};

-

-/* --------------------------------------------------------------------- */

-

-/*

- * Memory mapping.  This describes an entry in the memory mappings table

- * as pointed to by mi_mmap_addr.

- *

- * Be aware that mm_size specifies the size of all other fields *except*

- * for mm_size.  In order to jump between two different entries, you

- * have to count mm_size + 4 bytes.

- */

-struct multiboot_mmap {

-	uint32_t	mm_size;

-	uint64_t	mm_base_addr;

-	uint64_t	mm_length;

-	uint32_t	mm_type;

-};

-

-

-struct multiboot_module {

-  vaddr_t start;

-  vaddr_t end;

-  char* cmdline;

-  uint32_t reserved;

-};

-

-#endif

+/*-
+ * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julio M. Merino Vidal.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by the NetBSD
+ *    Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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 MULTIBOOT_H
+#define MULTIBOOT_H
+
+#include <stdint.h>
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Multiboot header structure.
+ */
+#define MULTIBOOT_HEADER_MAGIC            0x1BADB002
+#define MULTIBOOT_HEADER_MODS_ALIGNED    0x00000001
+#define MULTIBOOT_HEADER_WANT_MEMORY    0x00000002
+#define MULTIBOOT_HEADER_HAS_VBE        0x00000004
+#define MULTIBOOT_HEADER_HAS_ADDR       0x00010000
+
+struct multiboot_header {
+    uint32_t   mh_magic;
+    uint32_t   mh_flags;
+    uint32_t   mh_checksum;
+
+    /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */
+    uint32_t   mh_header_addr;
+    uint32_t   mh_load_addr;
+    uint32_t   mh_load_end_addr;
+    uint32_t   mh_bss_end_addr;
+    uint32_t   mh_entry_addr;
+
+    /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */
+    uint32_t   mh_mode_type;
+    uint32_t   mh_width;
+    uint32_t   mh_height;
+    uint32_t   mh_depth;
+} __attribute((packed));
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Multiboot information structure.
+ */
+#define MULTIBOOT_INFO_MAGIC            0x2BADB002
+#define MULTIBOOT_INFO_HAS_MEMORY        0x00000001
+#define MULTIBOOT_INFO_HAS_BOOT_DEVICE    0x00000002
+#define MULTIBOOT_INFO_HAS_CMDLINE        0x00000004
+#define MULTIBOOT_INFO_HAS_MODS            0x00000008
+#define MULTIBOOT_INFO_HAS_AOUT_SYMS    0x00000010
+#define MULTIBOOT_INFO_HAS_ELF_SYMS        0x00000020
+#define MULTIBOOT_INFO_HAS_MMAP            0x00000040
+#define MULTIBOOT_INFO_HAS_DRIVES        0x00000080
+#define MULTIBOOT_INFO_HAS_CONFIG_TABLE    0x00000100
+#define MULTIBOOT_INFO_HAS_LOADER_NAME    0x00000200
+#define MULTIBOOT_INFO_HAS_APM_TABLE    0x00000400
+#define MULTIBOOT_INFO_HAS_VBE            0x00000800
+
+struct multiboot_info {
+    uint32_t    mi_flags;
+
+    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */
+    uint32_t    mi_mem_lower;
+    uint32_t    mi_mem_upper;
+
+    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */
+    uint8_t     mi_boot_device_part3;
+    uint8_t     mi_boot_device_part2;
+    uint8_t     mi_boot_device_part1;
+    uint8_t     mi_boot_device_drive;
+
+    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */
+    uint32_t    mi_cmdline;
+
+    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */
+    uint32_t    mi_mods_count;
+    uint32_t    mi_mods_addr;
+
+    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */
+    uint32_t    mi_elfshdr_num;
+    uint32_t    mi_elfshdr_size;
+    uint32_t    mi_elfshdr_addr;
+    uint32_t    mi_elfshdr_shndx;
+
+    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */
+    uint32_t    mi_mmap_length;
+    uint32_t    mi_mmap_addr;
+
+    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */
+    uint32_t    mi_drives_length;
+    uint32_t    mi_drives_addr;
+
+    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */
+    uint32_t    unused_mi_config_table;
+
+    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */
+    uint32_t    mi_loader_name;
+
+    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */
+    uint32_t    unused_mi_apm_table;
+
+    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */
+    uint32_t    unused_mi_vbe_control_info;
+    uint32_t    unused_mi_vbe_mode_info;
+    uint32_t    unused_mi_vbe_interface_seg;
+    uint32_t    unused_mi_vbe_interface_off;
+    uint32_t    unused_mi_vbe_interface_len;
+} __attribute((packed));
+
+extern struct multiboot_info multiboot_info;
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Drive information.  This describes an entry in the drives table as
+ * pointed to by mi_drives_addr.
+ */
+struct multiboot_drive {
+    uint32_t    md_length;
+    uint8_t     md_number;
+    uint8_t     md_mode;
+    uint16_t    md_cylinders;
+    uint8_t     md_heads;
+    uint8_t     md_sectors;
+
+    /* The variable-sized 'ports' field comes here, so this structure
+     * can be longer. */
+};
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Memory mapping.  This describes an entry in the memory mappings table
+ * as pointed to by mi_mmap_addr.
+ *
+ * Be aware that mm_size specifies the size of all other fields *except*
+ * for mm_size.  In order to jump between two different entries, you
+ * have to count mm_size + 4 bytes.
+ */
+struct multiboot_mmap {
+    uint32_t    mm_size;
+    uint64_t    mm_base_addr;
+    uint64_t    mm_length;
+    uint32_t    mm_type;
+} __attribute((packed));
+
+
+struct multiboot_module {
+  uint32_t start;
+  uint32_t end;
+  uint32_t cmdline;
+  uint32_t reserved;
+};
+
+#endif
diff --git a/src/kernel2/include/notifier.h b/src/kernel/include/notifier.h
similarity index 100%
rename from src/kernel2/include/notifier.h
rename to src/kernel/include/notifier.h
diff --git a/src/kernel/include/paging.h b/src/kernel/include/paging.h
deleted file mode 100644
index 2c81cd21..00000000
--- a/src/kernel/include/paging.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef PAGING_H
-#define PAGING_H
-
-#include <types.h>
-#include <stdint.h>
-
-#include "vmm.h"
-#include "tasks.h"
-
-extern page_directory_t kernel_page_directory;
-
-bool map_page_range(page_directory_t page_directory, vaddr_t vaddr, paddr_t paddr, int flags, int num_pages);
-bool map_page(page_directory_t page_directory, vaddr_t vaddr, paddr_t paddr, int flags);
-bool unmap_page(page_directory_t page_directory, vaddr_t vaddr);
-paddr_t resolve_vaddr(page_directory_t page_directory, vaddr_t vaddr);
-bool is_userspace(vaddr_t start, uint32_t len);
-
-vaddr_t find_contiguous_pages(page_directory_t page_directory, int num,
-    uint32_t lower_limit, uint32_t upper_limit);
-void increase_user_stack_size(struct task * task_ptr, int pages);
-
-extern bool kernel_identity_map(paddr_t paddr, uint32_t bytes);
-
-#endif
diff --git a/src/kernel/include/phys.h b/src/kernel/include/phys.h
deleted file mode 100644
index 7d8e54fa..00000000
--- a/src/kernel/include/phys.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef _PHYS_H_
-#define _PHYS_H_
-
-#include <types.h>
-
-void phys_mark_page_as_free(paddr_t page);
-unsigned long phys_count_free_pages(void);
-unsigned long phys_count_pages(void);
-
-paddr_t phys_alloc_dma_page_range_64k(unsigned int num);
-
-#endif
-
diff --git a/src/kernel2/include/pic.h b/src/kernel/include/pic.h
similarity index 100%
rename from src/kernel2/include/pic.h
rename to src/kernel/include/pic.h
diff --git a/src/kernel/include/rpc.h b/src/kernel/include/rpc.h
deleted file mode 100644
index 11adc234..00000000
--- a/src/kernel/include/rpc.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef _RPC_H_
-#define _RPC_H_
-
-#include <stdint.h>
-#include <stdbool.h>
-
-#include "tasks.h"
-#include "intr.h"
-
-bool fastrpc(struct task * callee, uint32_t metadata_size, void* metadata, uint32_t data_size, void* data);
-bool fastrpc_irq(struct task * callee, uint32_t metadata_size, void* metadata, 
-    uint32_t data_size, void* data, uint8_t irq);
-
-void return_from_rpc(struct int_stack_frame ** esp);
-void rpc_destroy_task_backlinks(struct task* destroyed_task);
-
-#endif
diff --git a/src/kernel/include/shm.h b/src/kernel/include/shm.h
deleted file mode 100644
index 1dc253ca..00000000
--- a/src/kernel/include/shm.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*  
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Mathias Gottschlag.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS 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 SHM_H
-#define SHN_H
-
-#include <stdint.h>
-#include <types.h>
-#include <collections.h>
-
-#include "tasks.h"
-
-typedef struct shm_table_entry_t
-{
-    paddr_t *addresses;
-    uint32_t pagecount;
-    uint32_t id;
-    uint32_t usecount; //Anzahl der angefügten Prozesse
-} shm_table_entry_t;
-
-//Tabelle aller shm-Bereiche
-extern list_t *shm_table;
-
-void init_shared_memory(void);
-uint32_t create_shared_memory(uint32_t size);
-vaddr_t attach_task_to_shm(struct task *task, uint32_t id);
-void detach_task_from_shm(struct task *task, uint32_t id);
-
-#endif
diff --git a/src/kernel2/include/smp.h b/src/kernel/include/smp.h
similarity index 100%
rename from src/kernel2/include/smp.h
rename to src/kernel/include/smp.h
diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h
index 9359ac24..ad941e85 100644
--- a/src/kernel/include/syscall.h
+++ b/src/kernel/include/syscall.h
@@ -1,22 +1,327 @@
-#ifndef SYSCALL_H
-#define SYSCALL_H
+/*
+ * Copyright (c) 2007 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Antoine Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the tyndur Project
+ *     and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``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 COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS 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 _SYSCALL_H_
+#define _SYSCALL_H_
+
+#include <types.h>
 #include <stdint.h>
-#include <stdbool.h>
+#include <syscall_structs.h>
+
+#include "cpu.h"
+
+// Ist das wirklich die korrekte Definition? Dieser Typ sollte der Groesse der
+// Werte die auf dem Stack gespeichert werden entsprechen.
+// FIXME: Doppelte Definition! (modules/include/syscall.h)
+typedef uintptr_t syscall_arg_t;
+
+typedef struct {
+    /// Pointer auf den Handler des Syscalls oder NULL, falls dieser Syscall
+    /// nicht existiert.
+    void* handler;
+    
+    /// Anzahl der Argumente die der Syscall benoetigt
+    size_t arg_count;
+
+    /// true, wenn der Syscall nur aus dem Kernelspace aufgerufen werden darf
+    bool privileged;
+} syscall_t;
+
+/// In diesem Array werden alle Syscalls gespeichert.
+extern syscall_t syscalls[];
+
+
+/// Architektur-Abhaengiger Handler, der die eigentlichen Handler aufruft
+void syscall_arch(machine_state_t* isf);
+
+
+/// Einen neuen Syscall verfuegbar machen
+void syscall_register(syscall_arg_t number, void* handler, size_t arg_count);
+
+/// Syscalls initialisieren
+void syscall_init(void);
+
+// ###########################################################################
+// SYSCALLS
+// ###########################################################################
+
+// Speicherverwaltung
+/// Einen Speicherblock allokieren.
+vaddr_t syscall_mem_allocate(size_t bytes, syscall_arg_t flags, paddr_t* phys);
+
+/// Physischen Speicher mappen
+vaddr_t syscall_mem_allocate_physical(
+    size_t bytes, paddr_t position, syscall_arg_t flags);
+
+/// Einen Speicherblock freigeben
+void syscall_mem_free(vaddr_t start, size_t bytes);
+
+/// Physischen Speicher freigeben
+void syscall_mem_free_physical(vaddr_t start, size_t bytes);
+
+/// Freie Pages und Gesamtspeicher zurueckgeben
+void syscall_mem_info(uint32_t* sum_pages, uint32_t* free_pages);
+
+
+// Prozessverwaltung
+/// PID des aktuellen Prozesses abfragen
+pid_t syscall_pm_get_pid(void);
+
+/// PID des Elternprozesses ausfindig machen
+pid_t syscall_pm_get_parent_pid(pid_t pid);
+
+/// Befehlszeile des aktuellen Prozesses abfragen
+const char* syscall_pm_get_cmdline(void);
+
+/// Kritischen Abschnitt betreten
+int syscall_pm_p(void);
+
+/// Kritischen Abschnitt verlassen
+int syscall_pm_v(pid_t pid);
+
+/// Kritischen Abschnitt verlassen und auf RPC warten
+int syscall_pm_v_and_wait_for_rpc(void);
+
+/// Die Kontrolle an einen anderen Task abgeben
+void syscall_pm_sleep(void);
+
+/// Die Kontrolle an einen anderen Task abgeben
+void kern_syscall_pm_sleep(tid_t yield_to, int status);
+
+/// Warten, bis ein RPC zu bearbeiten ist
+void syscall_pm_wait_for_rpc(void);
+
+/// Prozess erstellen
+pid_t syscall_pm_create_process(vaddr_t start, uid_t uid,
+    const char* cmdline, pid_t parent_pid);
+
+/// Aktuellen Prozess beenden
+void syscall_pm_exit_process(void);
+
+/// Alle Prozesse auflisten
+void* syscall_pm_enumerate_tasks(void);
+
+
+/// Thread erstellen
+tid_t syscall_pm_create_thread(vaddr_t start, void *arg);
+
+/// ID des aktuellen Threads abfragen
+tid_t syscall_pm_get_tid(void);
+
+/// Thread beenden
+void syscall_pm_exit_thread(void);
+
+/// Mutex nehmen
+void syscall_mutex_lock(int* mutex);
+
+/// Mutex freigeben
+void syscall_mutex_unlock(int* mutex);
+
+
+/// Speicher an einen anderen Prozess uebergeben
+void syscall_init_child_page(pid_t pid, vaddr_t src, vaddr_t dest,
+    size_t size);
+
+/// Initialisiert den Prozessparameterblock eines Kindprozesses
+int syscall_init_ppb(pid_t pid, int shm_id);
+int arch_init_ppb(pm_process_t* process, int shm_id, void* ptr, size_t size);
+
+/// IO-Ports anfordern
+int syscall_io_request_port(uint32_t port, uint32_t length);
+
+/// IO-Ports freigeben
+int syscall_io_release_port(uint32_t port, uint32_t length);
+
+/// Aktuelle Zeit abfragen (Mikrosekunden seit Systemstart)
+uint64_t syscall_get_tick_count(void);
+
+
+// SHM
+/// Neuen Shared Memory reservieren
+uint32_t syscall_shm_create(size_t size);
+
+/// Bestehenden Shared Memory oeffnen
+void* syscall_shm_attach(uint32_t id);
+
+/// Shared Memory schliessen
+void syscall_shm_detach(uint32_t id);
+
+/// Größe eines Shared Memory zurückgeben
+int32_t syscall_shm_size(uint32_t id);
+
+/// Einen Timer anlegen
+void syscall_add_timer(uint32_t timer_id, uint32_t usec);
+
+// RPC
+/// RPC-Handler registrieren
+void syscall_set_rpc_handler(vaddr_t address);
+
+/// RPC durchfuehren
+int syscall_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata,
+    size_t data_size, void* data);
+
+/// Von einem RPC zurueckkehren
+void syscall_fastrpc_ret(void);
+
+/// Interrupt registrieren
+void syscall_add_interrupt_handler(uint32_t intr);
+
+
+// LIO
+/// Ressource suchen
+void syscall_lio_resource(const char* path, size_t path_len, int flags,
+    lio_usp_resource_t* res_id);
+
+/// Informationen über eine Ressource abfragen
+int syscall_lio_stat(lio_usp_resource_t* resid, struct lio_stat* sbuf);
+
+/// Ressource öffnen
+void syscall_lio_open(lio_usp_resource_t* resid, int flags,
+    lio_usp_stream_t* stream_id);
+
+/// Pipe erstellen
+int syscall_lio_pipe(lio_usp_stream_t* stream_reader,
+                     lio_usp_stream_t* stream_writer,
+                     bool bidirectional);
+
+/// Ein- und Ausgabestream zusammensetzen
+int syscall_lio_composite_stream(lio_usp_stream_t* read,
+                                 lio_usp_stream_t* write,
+                                 lio_usp_stream_t* result);
+
+/// Stream schließen
+int syscall_lio_close(lio_usp_stream_t* stream_id);
+
+/// Zusätzliche ID für Stream erstellen
+int syscall_lio_dup(lio_usp_stream_t* source, lio_usp_stream_t* dest);
+
+/// Stream an anderen Prozess weitergeben
+int syscall_lio_pass_fd(lio_usp_stream_t* stream_id, pid_t pid);
+
+/// PID des Prozesses, der den Stream dem aktuellen übergeben hat, auslesen
+int syscall_lio_stream_origin(lio_usp_stream_t* stream_id);
+
+/// Aus Stream lesen
+void syscall_lio_read(lio_usp_stream_t* stream_id, uint64_t* offset,
+    size_t bytes, void* buffer, int updatepos, ssize_t* result);
+
+/// In Stream schreiben
+void syscall_lio_write(lio_usp_stream_t* stream_id, uint64_t* offset,
+    size_t bytes, const void* buffer, int updatepos, ssize_t* result);
+
+/// Cursorposition in der Datei ändern
+void syscall_lio_seek(lio_usp_stream_t* stream_id, int64_t* offset,
+    int whence, int64_t* result);
+
+/// Dateigröße ändern
+int syscall_lio_truncate(lio_usp_stream_t* stream_id, uint64_t* size);
+
+/// Veränderte Blocks schreiben
+int syscall_lio_sync(lio_usp_stream_t* stream_id);
+
+/// Verzeichnisinhalt auslesen
+void syscall_lio_read_dir(lio_usp_resource_t* res, size_t start, size_t num,
+    struct lio_usp_dir_entry* dent, ssize_t* result);
+
+/// Ressourcenspezifischen Befehl ausführen
+int syscall_lio_ioctl(lio_usp_stream_t* stream_id, int cmd);
+
+/// Neue Datei anlegen
+void syscall_lio_mkfile(lio_usp_resource_t* parent, const char* name,
+    size_t name_len, lio_usp_resource_t* result);
+
+/// Neues Verzeichnis anlegen
+void syscall_lio_mkdir(lio_usp_resource_t* parent, const char* name,
+    size_t name_len, lio_usp_resource_t* result);
+
+/// Neuen Symlink anlegen
+void syscall_lio_mksymlink(lio_usp_resource_t* parent, const char* name,
+    size_t name_len, const char* target, size_t target_len,
+    lio_usp_resource_t* result);
+
+/// Verzeichniseintrag löschen
+int syscall_lio_unlink(lio_usp_resource_t* parent, const char* name,
+    size_t name_len);
+
+/// Alle Blocks rausschreiben, die sich im Cache befinden
+int syscall_lio_sync_all(int soft);
+
+/// Service finden, der die Ressource als Pipequelle akzeptiert
+int syscall_lio_probe_service(lio_usp_resource_t* res,
+                              struct lio_probe_service_result* probe_data);
+
+// LIO-Server
+/// Neuen lio-Service registrieren
+int syscall_lio_srv_service_register(const char* name, size_t name_len,
+    void* buffer, size_t size);
+
+/// Neuen Tree-Ring registrieren
+int syscall_lio_srv_tree_set_ring(lio_usp_tree_t* tree_id, tid_t tid,
+    void* buffer, size_t size);
+
+/// Ressource fuer Kernel bereitstellen
+int syscall_lio_srv_res_upload(struct lio_server_resource* resource);
+
+/// Neuen Knoten erstellen
+int syscall_lio_srv_node_add(lio_usp_resource_t* parent,
+    lio_usp_resource_t* resource, const char* name, size_t name_len);
+
+/// Knoten loeschen
+int syscall_lio_srv_node_remove(lio_usp_resource_t* parent, const char* name,
+    size_t name_len);
+
+/// Kernel ueber abgearbeitete Operation informieren
+void syscall_lio_srv_op_done(struct lio_op* op, int status, uint64_t* result);
+
+/// Auf LIO-Operationen fuer diesen Prozess warten
+void syscall_lio_srv_wait(void);
+
+/// Cache-Blocks mit Uebersetzungstabelle anfordern
+int syscall_lio_srv_request_translated_blocks(lio_usp_resource_t* res,
+    uint64_t* offset, size_t num, uint64_t* table);
+
 
-#include "intr.h"
-#include "syscallno.h"
-#include <lost/config.h>
+// Diverse
+/// Textausgabe ueber den Kernel
+void syscall_putsn(int char_count, char* source);
 
-#ifdef CONFIG_DEBUG_LAST_SYSCALL
-#define DEBUG_LAST_SYSCALL_DATA_SIZE 4
-extern uint32_t debug_last_syscall_no;
-extern pid_t debug_last_syscall_pid;
-extern uint32_t debug_last_syscall_data[DEBUG_LAST_SYSCALL_DATA_SIZE];
-#endif
+/// -ENOSYS
+int syscall_vm86_old(void* regs, uint32_t* memory);
 
-void syscall(struct int_stack_frame ** esp);
+/// BIOS-Interrupt ausfuehren
+int syscall_vm86(uint8_t intr, void* regs, uint32_t* memory);
 
-bool syscall_rpc(uint32_t callee_pid, uint32_t data_size, char* data);
+#endif //ifndef _SYSCALL_H_
 
-#endif
diff --git a/src/kernel/include/tasks.h b/src/kernel/include/tasks.h
index f943e48a..774ca39f 100644
--- a/src/kernel/include/tasks.h
+++ b/src/kernel/include/tasks.h
@@ -1,82 +1,281 @@
-#ifndef TASKS_H
-#define TASKS_H
+/*
+ * Copyright (c) 2007 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Antoine Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the tyndur Project
+ *     and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``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 COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS 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 _TASKS_H_
+#define _TASKS_H_
 
-#include <types.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <types.h>
+#include <collections.h>
+#include <lost/config.h>
 
-#include "vmm.h"
-#include "collections.h"
-#include "syscall_structs.h"
-
-#define TS_RUNNING 0
-#define TS_WAIT_FOR_RPC 1
+#include "mm_arch.h"
+#include "lock.h"
+#include "multiboot.h"
 
-typedef struct
-{
-    uint32_t *meminfo;
-    vm86_regs_t *regs;
-} vm86_info_t;
+#define PM_STATUS_READY 0
+#define PM_STATUS_BLOCKED 1
+#define PM_STATUS_RUNNING 2
+#define PM_STATUS_WAIT_FOR_RPC 3
+#define PM_STATUS_WAIT_FOR_LIO 4
+#define PM_STATUS_WAIT_FOR_IO_REQUEST 5
+#define PM_STATUS_WAIT_FOR_DATA 6
 
-struct task
-{
+typedef struct pm_process {
+    /// Die eindeutige Prozessnummer
     pid_t pid;
-    uint32_t esp;
-    uint32_t kernel_stack;
-    uint32_t type;
+
+    /// Elternprozess
+    struct pm_process* parent;
+
+    /// Der Kontext fuer die Speicherverwaltung
+    mmc_context_t context;
+
+    /// Liste mit den Threads
+    list_t* threads;
+
+    /// Adresse, an der der naechste Thread seinen Stack ablegen soll
+    vaddr_t next_stack;
+
+    /// Kommandozeile die zum Starten des Prozesses benutzt wurde
+    char* cmdline;
+
+    /// Aktueller Status
+    uint32_t status;
+
+    /// Wird gesperrt, wenn aenderungen am Prozess vorgenommen werden
+    lock_t lock;
+
+    /// Der RPC-Handler fuer diesen Prozess
     vaddr_t rpc_handler;
-    list_t* rpcs;
-    page_directory_t cr3;
-    uint32_t pd_id;
-    uint32_t slices;
+
+    /// Die PID des Prozesses, der RPC fuer diesen Prozess abgestellt hat
     uint32_t blocked_by_pid;
+
+    /// Die Anzahl von p()s (RPC wird erst bei 0 wieder freigegeben)
     uint32_t blocked_count;
+
+    /// Eine Liste von RPC-Backlinks
+    list_t* rpcs;
+
+    /// Eine Liste von geoeffneten SHM-Bereichen
+    list_t* shm;
+
+#if CONFIG_ARCH == ARCH_I386
+    /// IO-Bitmap
+    void* io_bitmap;
+#elif CONFIG_ARCH == ARCH_AMD64
+#else
+#error Architektur nicht unterstuetzt
+#endif
+
+    /**
+     * Eine Liste von Eventhandlern, die beim Loeschen des Prozesses
+     * aufgerufen werden
+     */
+    list_t* on_destroy;
+
+    /// Speicherverbrauch des Prozesses
+    uintmax_t memory_used;
+
+    /// Baum aller geoeffneten LostIO-Streams
+    tree_t* lio_streams;
+} pm_process_t;
+
+typedef struct {
+    /// Adresse des Kernelstack-Pointers
+    vaddr_t kernel_stack;
+
+    /// Anfang des Stacks
+    vaddr_t kernel_stack_bottom;
+
+    /// Groesse des Kernelstacks
+    size_t kernel_stack_size;
+
+    /// Aktueller Stackframe des Userspace-Interrupts
+    vaddr_t user_isf;
+
+    /// Anfang des Usermode-Stacks
     vaddr_t user_stack_bottom;
+
+    /// Der Prozess, dem der Thread gehoert
+    pm_process_t* process;
+
+    /// Aktueller Status
     uint32_t status;
-    
-    struct task* parent_task;
 
-    const char* cmdline;
-    
-    void* io_bitmap;
+    /// Wird gesperrt, wenn aenderungen am Thread vorgenommen werden
+    lock_t lock;
 
-    struct task* next_task;
-
-//Scheduling-Infos
-    ///Das Maximum der Zeit, die der Task die CPU benutzen darf
-    uint8_t schedule_ticks_max;
-    ///Verbleibende Zeit
-    int schedule_ticks_left;
-    
-    //Shared Memory
-    list_t *shmids;
-    list_t *shmaddresses;
-
-    // Benutzter speicher
-    uint32_t memory_used;
-    
-    // VM86-Info
+    /// Gesetzt, wenn der Thread ein VM86-Thread mit allem Drum und Dran ist
     bool vm86;
-    vm86_info_t *vm86_info;
-};
 
-extern struct task* current_task;
-extern struct task* first_task;
+    /// Eindeutige Threadnummer
+    tid_t tid;
 
-void schedule(uint32_t* esp);
-void schedule_to_task(struct task* target_task, uint32_t* esp);
-void set_io_bitmap(void);
+    /// Gesetzt, wenn der Thread beim Beenden den gesamten Prozess beendet
+    bool is_main_thread;
 
-// TODO: Nur wegen vm86.c hier
-pid_t generate_pid(void);
-struct task * create_task(void * entry, const char* cmdline, pid_t parent);
-void destroy_task(struct task* task);
-struct task * get_task(pid_t pid);
+    /**
+     * Eine Liste von Eventhandlern, die beim Loeschen des Threads
+     * aufgerufen werden
+     */
+    list_t* on_destroy;
 
+    /// Eine Liste der von diesem Thread angebotenen LIO-Services
+    list_t* lio_services;
 
-bool block_task(struct task* task, pid_t blocked_by);
-bool unblock_task(struct task* task, pid_t blocked_by);
+    /// Eine Liste aller LIO-Trees, deren Ring dieser Thread verarbeitet
+    list_t* lio_trees;
+} pm_thread_t;
 
-void abort_task(char* format, ...);
+typedef void (*pm_process_destroy_handler)(pm_process_t* process, void* prv);
+typedef void (*pm_thread_destroy_handler)(pm_thread_t* thread, void* prv);
+
+extern list_t* process_list;
+
+/**
+ * Prozessverwaltung
+ */
+/// Prozessverwaltung initialisieren
+void pm_init(void);
+
+/// Prozess erstellen
+pm_process_t* pm_create(pm_process_t* parent, const char* cmdline);
+
+/// Datenstrukturen eines Prozesses freigeben (vor dem Taskwechsel)
+void pm_prepare_destroy(pm_process_t* process);
+
+/// Prozess zerstoeren
+void pm_destroy(pm_process_t* process);
+
+/// Prozess blockieren
+bool pm_block(pm_process_t* process);
+
+/// Prozess entblocken
+bool pm_unblock(pm_process_t* process);
+
+/// Prozess anhand seiner PID suchen
+pm_process_t* pm_get(pid_t pid);
+
+/// RPC-Empfang fuer einen Prozess blockieren
+bool pm_block_rpc(pm_process_t* task, pid_t blocked_by);
+
+/// RPC-Empfang fuer einen Prozess wieder freigeben
+bool pm_unblock_rpc(pm_process_t* task, pid_t blocked_by);
+
+
+/// Handler fuer das Loeschen des Prozesses registrieren
+void pm_register_on_destroy(pm_process_t* process,
+    pm_process_destroy_handler handler, void* prv);
+void pm_unregister_on_destroy(pm_process_t* process,
+    pm_process_destroy_handler handler, void* prv);
+
+/// Handler fuer das Loeschen des Threads registrieren
+void pm_thread_register_on_destroy(pm_thread_t* thread,
+    pm_thread_destroy_handler handler, void* prv);
+
+/// Entfernt den gegebenen Task aus allen RPC-Backlinks
+void rpc_destroy_task_backlinks(pm_process_t* destroyed_process);
+
+/**
+ * Threadverwaltung
+ */
+/// Neuen Thread erstellen
+pm_thread_t* pm_thread_create(pm_process_t* process, vaddr_t entry);
+
+/// Einen Thread zerstoeren
+void pm_thread_destroy(pm_thread_t* thread);
+
+/// Thread blockieren
+bool pm_thread_block(pm_thread_t* thread);
+
+/// Thread anhand der TID (und ggf. Prozess) suchen
+pm_thread_t* pm_thread_get(pm_process_t* process, tid_t tid);
+
+/// Thread entblocken
+bool pm_thread_unblock(pm_thread_t* thread);
+
+/// Darf der Thread einfach auf RUNNING gesetzt werden?
+bool pm_thread_runnable(pm_thread_t* thread);
+
+/**
+ * Scheduling
+ */
+/// Dem Scheduler einen neuen Thread hinzufuegen
+void pm_scheduler_add(pm_thread_t* thread);
+
+/// Einen Thread aus dem Scheduler entfernen
+void pm_scheduler_delete(pm_thread_t* thread);
+
+/// Die Liste im Scheduler aktualisieren
+void pm_scheduler_refresh(void);
+
+/// Einen Thread zum ausfuehren holen
+pm_thread_t* pm_scheduler_pop(void);
+
+/// Einen bestimmten Thread zum Ausfuehren holen
+void pm_scheduler_get(pm_thread_t* thread);
+
+/// Einen ausgefuerten Thread wieder zurueck an den Scheduler geben
+void pm_scheduler_push(pm_thread_t* thread);
+
+/// Kontrolle vom aktuellen Kernelthread an einen anderen Thread abgeben
+void pm_scheduler_yield(void);
+
+/// Kontrolle an einen bestimmten Thread abgeben, mit Folgezustand
+void pm_scheduler_kern_yield(tid_t tid, int status);
+
+/// Versucht einen Taskwechsel zum übergebenen Thread
+void pm_scheduler_try_switch(pm_thread_t* thread);
+
+/**
+ * Initialisierung
+ */
+/// Das Init-Modul laden
+void load_init_module(struct multiboot_info* multiboot_info);
+
+/// Alle weiteren Module an init uebergeben
+void load_multiboot_modules(struct multiboot_info* multiboot_info);
+
+// Kann erst hier eingebunden werden, weil es die Strukturen braucht
+#include "cpu.h"
+
+#define current_thread (cpu_get_current()->thread)
+#define current_process (cpu_get_current()->thread->process)
+
+#endif //ifndef _TASKS_H_
 
-#endif
diff --git a/src/kernel/include/timer.h b/src/kernel/include/timer.h
index c4ef741c..b4d586d7 100644
--- a/src/kernel/include/timer.h
+++ b/src/kernel/include/timer.h
@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.
+ * Copyright (c) 2006-2009 The tyndur Project. All rights reserved.
  *
- * This code is derived from software contributed to the tyndur Project
+ * This code is derived from software contributed to the LOST Project
  * by Kevin Wolf.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -14,9 +14,9 @@
  *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software
  *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
+ *     This product includes software developed by the LOST Project
  *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
+ * 4. Neither the name of the LOST Project nor the names of its
  *    contributors may be used to endorse or promote products derived
  *    from this software without specific prior written permission.
  *
@@ -37,12 +37,11 @@
 #define _TIMER_H_
 
 #include <stdint.h>
-
 #include "tasks.h"
 
 void timer_init(void);
-void timer_register(struct task* task, uint32_t timer_id, uint32_t usec);
+void timer_register(pm_process_t* task, uint32_t timer_id, uint32_t usec);
 void timer_notify(uint64_t microtime);
-void timer_cancel_all(struct task* task);
+void timer_cancel_all(pm_process_t* task);
 
 #endif
diff --git a/src/kernel/include/tss.h b/src/kernel/include/tss.h
deleted file mode 100644
index fb256205..00000000
--- a/src/kernel/include/tss.h
+++ /dev/null
@@ -1,49 +0,0 @@
-#ifndef TSS_H

-#define TSS_H

-

-#include <stdint.h>

-#include <stddef.h>

-

-#define IO_BITMAP_LENGTH 0xffff

-

-// Dieser Wert muss ausserhalb des in der GDT definierten Limits

-// fuer das TSS liegen

-#define TSS_IO_BITMAP_NOT_LOADED (sizeof(tss) + 0x100)

-#define TSS_IO_BITMAP_OFFSET offsetof(tss_t, io_bit_map)

-

-typedef struct tss_s

-{

-	uint32_t backlink;

-	uint32_t esp0;

-	uint32_t ss0;

-	uint32_t esp1;

-	uint32_t ss1;

-	uint32_t esp2;

-	uint32_t ss2;

-	uint32_t cr3;

-	uint32_t eip;

-	uint32_t eflags;

-	uint32_t eax;

-	uint32_t ecx;

-	uint32_t edx;

-	uint32_t ebx;

-	uint32_t esp;

-	uint32_t ebp;

-	uint32_t esi;

-	uint32_t edi;

-	uint32_t es;

-	uint32_t cs;

-	uint32_t ss;

-	uint32_t ds;

-	uint32_t fs;

-	uint32_t gs;

-	uint32_t ldt;

-	uint16_t trace_trap;

-	uint16_t io_bit_map_offset;

-    uint8_t io_bit_map[IO_BITMAP_LENGTH / 8];

-    uint8_t io_bit_map_end;

-} __attribute__((packed)) tss_t;

-

-extern tss_t tss;

-

-#endif /* ndef TSS_H */

diff --git a/src/kernel/include/vm86.h b/src/kernel/include/vm86.h
index 0c0dee0e..978f762f 100644
--- a/src/kernel/include/vm86.h
+++ b/src/kernel/include/vm86.h
@@ -1,8 +1,8 @@
-/*  
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
+/*
+ * Copyright (c) 2010 The tyndur Project. All rights reserved.
  *
  * This code is derived from software contributed to the tyndur Project
- * by Mathias Gottschlag.
+ * by Kevin Wolf.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -20,34 +20,24 @@
  *    contributors may be used to endorse or promote products derived
  *    from this software without specific prior written permission.
  *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS 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 
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS 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 VM86_H
-#define VM86_h
+#ifndef _VM86_H_
+#define _VM86_H_
 
-#include <stdint.h>
-#include <stdbool.h>
-
-#include "tasks.h"
-
-void save_bios_data(void);
-uint16_t *get_ivt_entry(uint16_t interrupt);
-
-struct task * create_vm86_task(uint16_t interrupt, vm86_regs_t *regs,
-    uint32_t *meminfo, struct task *parent);
-
-bool vm86_exception(uint32_t *esp);
+void vm86_init(void);
+int arch_vm86(uint8_t intr, void* regs, uint32_t* memory);
 
 #endif
 
diff --git a/src/kernel/include/vmm.h b/src/kernel/include/vmm.h
deleted file mode 100644
index fefa1dbf..00000000
--- a/src/kernel/include/vmm.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef VMM_H

-#define VMM_H

-

-#define PAGE_DIRECTORY_LENGTH 1024

-#define PAGE_TABLE_LENGTH 1024

-

-#define PAGE_SHIFT 12

-#define PAGE_SIZE (1 << PAGE_SHIFT)

-#define PAGE_MASK (~(PAGE_SIZE - 1))

-

-// Die Anzahl der Pages, die von n Bytes belegt werden.

-#define NUM_PAGES(n) ((((n) + ~PAGE_MASK) & PAGE_MASK) / PAGE_SIZE)

-

-// Rundet eine Adresse auf das kleinste Vielfache von PAGE_SIZE > n auf

-#define PAGE_ALIGN_ROUND_UP(n) (((n) + ~PAGE_MASK) & PAGE_MASK)

-

-// Rundet eine Adresse auf das gr��te Vielfache von PAGE_SIZE < n ab

-#define PAGE_ALIGN_ROUND_DOWN(n) ((n) & PAGE_MASK)

-

-#define PGDIR_SHIFT 22

-

-#define PTE_P       0x001 // present

-#define PTE_W       0x002 // writable

-#define PTE_U       0x004 // user

-#define PTE_PWT     0x008 // write-through

-#define PTE_PCT     0x010 // cache-disable

-#define PTE_A       0x020 // accessed

-#define PTE_D       0x040 // dirty

-#define PTE_PS      0x080 // page size

-

-#define PTE_AVAIL1  0x200 // available for software use

-#define PTE_AVAIL2  0x400 // available for software use

-#define PTE_AVAIL3  0x800 // available for software use

-

-typedef unsigned long * page_directory_t;

-typedef unsigned long * page_table_t;

-

-typedef enum { page_4K, page_4M } page_size_t;

-

-// Die Adresse, an der der Kernel-Adressraum beginnt

-#define KERNEL_BASE 0x00000000

-

-// Die Anzahl der Page Tables, die f�r den Kerneladressraum ben�tigt werden

-#define NUM_KERNEL_PAGE_TABLES (PAGE_DIRECTORY_LENGTH - (KERNEL_BASE >> PGDIR_SHIFT))

-

-// Alle Kernel Page Tables werden nach KERNEL_PAGE_TABLES_VADDR gemappt

-#define KERNEL_PAGE_TABLES_VADDR 0x3fc00000

-

-

-#define USER_MEM_START 0x40000000

-#define USER_MEM_END   0xffffffff

-

-#endif /* ndef VMM_H */

diff --git a/src/kernel/src/Makefile.all b/src/kernel/src/Makefile.all
deleted file mode 100644
index bf927398..00000000
--- a/src/kernel/src/Makefile.all
+++ /dev/null
@@ -1,6 +0,0 @@
-shopt -s extglob
-source $LOST_BUILDMK_ROOT/config.sh
-
-echo "LD   $1/kernel/tyndur"
-$LOST_TOOLS_LD -otyndur.krn -Tkernel.ld *.o $2
-mv tyndur.krn $1/kernel/tyndur
diff --git a/src/kernel2/src/arch/amd64/Makefile.all b/src/kernel/src/arch/amd64/Makefile.all
similarity index 100%
rename from src/kernel2/src/arch/amd64/Makefile.all
rename to src/kernel/src/arch/amd64/Makefile.all
diff --git a/src/kernel2/src/arch/amd64/cpu.c b/src/kernel/src/arch/amd64/cpu.c
similarity index 100%
rename from src/kernel2/src/arch/amd64/cpu.c
rename to src/kernel/src/arch/amd64/cpu.c
diff --git a/src/kernel2/src/arch/amd64/debug.c b/src/kernel/src/arch/amd64/debug.c
similarity index 100%
rename from src/kernel2/src/arch/amd64/debug.c
rename to src/kernel/src/arch/amd64/debug.c
diff --git a/src/kernel2/src/arch/amd64/gdt.c b/src/kernel/src/arch/amd64/gdt.c
similarity index 100%
rename from src/kernel2/src/arch/amd64/gdt.c
rename to src/kernel/src/arch/amd64/gdt.c
diff --git a/src/kernel2/src/arch/amd64/header.S b/src/kernel/src/arch/amd64/header.S
similarity index 100%
rename from src/kernel2/src/arch/amd64/header.S
rename to src/kernel/src/arch/amd64/header.S
diff --git a/src/kernel2/src/arch/amd64/im/im.c b/src/kernel/src/arch/amd64/im/im.c
similarity index 100%
rename from src/kernel2/src/arch/amd64/im/im.c
rename to src/kernel/src/arch/amd64/im/im.c
diff --git a/src/kernel2/src/arch/amd64/im/int_stubs.S b/src/kernel/src/arch/amd64/im/int_stubs.S
similarity index 100%
rename from src/kernel2/src/arch/amd64/im/int_stubs.S
rename to src/kernel/src/arch/amd64/im/int_stubs.S
diff --git a/src/kernel2/src/arch/amd64/kernel.ld b/src/kernel/src/arch/amd64/kernel.ld
similarity index 100%
rename from src/kernel2/src/arch/amd64/kernel.ld
rename to src/kernel/src/arch/amd64/kernel.ld
diff --git a/src/kernel2/src/arch/amd64/loader/loader.c b/src/kernel/src/arch/amd64/loader/loader.c
similarity index 100%
rename from src/kernel2/src/arch/amd64/loader/loader.c
rename to src/kernel/src/arch/amd64/loader/loader.c
diff --git a/src/kernel2/src/arch/amd64/loader/loader.ld b/src/kernel/src/arch/amd64/loader/loader.ld
similarity index 100%
rename from src/kernel2/src/arch/amd64/loader/loader.ld
rename to src/kernel/src/arch/amd64/loader/loader.ld
diff --git a/src/kernel2/src/arch/amd64/loader/startup.S b/src/kernel/src/arch/amd64/loader/startup.S
similarity index 100%
rename from src/kernel2/src/arch/amd64/loader/startup.S
rename to src/kernel/src/arch/amd64/loader/startup.S
diff --git a/src/kernel2/src/arch/amd64/mm/mm_context.c b/src/kernel/src/arch/amd64/mm/mm_context.c
similarity index 100%
rename from src/kernel2/src/arch/amd64/mm/mm_context.c
rename to src/kernel/src/arch/amd64/mm/mm_context.c
diff --git a/src/kernel2/src/arch/amd64/mm/mm_virt.c b/src/kernel/src/arch/amd64/mm/mm_virt.c
similarity index 100%
rename from src/kernel2/src/arch/amd64/mm/mm_virt.c
rename to src/kernel/src/arch/amd64/mm/mm_virt.c
diff --git a/src/kernel2/src/arch/amd64/smp/trampoline.S b/src/kernel/src/arch/amd64/smp/trampoline.S
similarity index 100%
rename from src/kernel2/src/arch/amd64/smp/trampoline.S
rename to src/kernel/src/arch/amd64/smp/trampoline.S
diff --git a/src/kernel2/src/arch/i386/Makefile.all b/src/kernel/src/arch/i386/Makefile.all
similarity index 100%
rename from src/kernel2/src/arch/i386/Makefile.all
rename to src/kernel/src/arch/i386/Makefile.all
diff --git a/src/kernel2/src/arch/i386/cpu.c b/src/kernel/src/arch/i386/cpu.c
similarity index 100%
rename from src/kernel2/src/arch/i386/cpu.c
rename to src/kernel/src/arch/i386/cpu.c
diff --git a/src/kernel2/src/arch/i386/debug.c b/src/kernel/src/arch/i386/debug.c
similarity index 100%
rename from src/kernel2/src/arch/i386/debug.c
rename to src/kernel/src/arch/i386/debug.c
diff --git a/src/kernel2/src/arch/i386/gdt.c b/src/kernel/src/arch/i386/gdt.c
similarity index 100%
rename from src/kernel2/src/arch/i386/gdt.c
rename to src/kernel/src/arch/i386/gdt.c
diff --git a/src/kernel2/src/arch/i386/header.asm b/src/kernel/src/arch/i386/header.asm
similarity index 100%
rename from src/kernel2/src/arch/i386/header.asm
rename to src/kernel/src/arch/i386/header.asm
diff --git a/src/kernel2/src/arch/i386/interrupts/im.c b/src/kernel/src/arch/i386/interrupts/im.c
similarity index 100%
rename from src/kernel2/src/arch/i386/interrupts/im.c
rename to src/kernel/src/arch/i386/interrupts/im.c
diff --git a/src/kernel2/src/arch/i386/interrupts/int_stubs.S b/src/kernel/src/arch/i386/interrupts/int_stubs.S
similarity index 100%
rename from src/kernel2/src/arch/i386/interrupts/int_stubs.S
rename to src/kernel/src/arch/i386/interrupts/int_stubs.S
diff --git a/src/kernel2/src/arch/i386/io.c b/src/kernel/src/arch/i386/io.c
similarity index 100%
rename from src/kernel2/src/arch/i386/io.c
rename to src/kernel/src/arch/i386/io.c
diff --git a/src/kernel2/src/arch/i386/kernel.ld b/src/kernel/src/arch/i386/kernel.ld
similarity index 100%
rename from src/kernel2/src/arch/i386/kernel.ld
rename to src/kernel/src/arch/i386/kernel.ld
diff --git a/src/kernel2/src/arch/i386/mm/mm_context.c b/src/kernel/src/arch/i386/mm/mm_context.c
similarity index 100%
rename from src/kernel2/src/arch/i386/mm/mm_context.c
rename to src/kernel/src/arch/i386/mm/mm_context.c
diff --git a/src/kernel2/src/arch/i386/mm/virt.c b/src/kernel/src/arch/i386/mm/virt.c
similarity index 100%
rename from src/kernel2/src/arch/i386/mm/virt.c
rename to src/kernel/src/arch/i386/mm/virt.c
diff --git a/src/kernel2/src/arch/i386/smp/trampoline.S b/src/kernel/src/arch/i386/smp/trampoline.S
similarity index 100%
rename from src/kernel2/src/arch/i386/smp/trampoline.S
rename to src/kernel/src/arch/i386/smp/trampoline.S
diff --git a/src/kernel2/src/arch/i386/syscall.c b/src/kernel/src/arch/i386/syscall.c
similarity index 100%
rename from src/kernel2/src/arch/i386/syscall.c
rename to src/kernel/src/arch/i386/syscall.c
diff --git a/src/kernel2/src/arch/i386/syscalls/vm86.c b/src/kernel/src/arch/i386/syscalls/vm86.c
similarity index 100%
rename from src/kernel2/src/arch/i386/syscalls/vm86.c
rename to src/kernel/src/arch/i386/syscalls/vm86.c
diff --git a/src/kernel2/src/arch/i386/vm86.c b/src/kernel/src/arch/i386/vm86.c
similarity index 100%
rename from src/kernel2/src/arch/i386/vm86.c
rename to src/kernel/src/arch/i386/vm86.c
diff --git a/src/kernel/src/console.c b/src/kernel/src/console.c
index 383afb10..50afd286 100644
--- a/src/kernel/src/console.c
+++ b/src/kernel/src/console.c
@@ -34,10 +34,8 @@
  */
 
 #include <stdint.h>
-
-#include "string.h"
-#include "ports.h"
-#include <debug.h>
+#include <string.h>
+#include <ports.h>
 
 /*
  * Das hier ist eine sehr beschr�nkte Untermenge der ANSI Escape Codes. Alle
@@ -89,9 +87,9 @@
 #define SCREEN_WIDTH 80
 #define SCREEN_HEIGHT 25
 
-static void con_set_hw_cursor(void);
+void con_set_hw_cursor(void);
 
-static unsigned short * vidmem = (unsigned short*)0xb8000;
+unsigned short * vidmem = (unsigned short*)0xb8000;
 
 // Aktuelle Cursor-Position
 static unsigned int cursor_x;
@@ -366,15 +364,11 @@ static ansi_esc_seq_status_t con_ansi_parse(const char * ansi_buf, unsigned int
                 return SUCCESS;
 
             case 'm': // ESC[#m oder ESC[#;#m - Vorder- und Hintergrundfarbe �ndern, Fettschrift, Blinken
-            {
-                // Attribute sichern
-                unsigned char attr = con_color._color;
-
                 if(!have_n1)
                 {
                     return INVALID;
                 }
-
+                
                 if(handle_ansi_formatting_sequence_number(n1) != SUCCESS)
                 {
                     return INVALID;
@@ -384,14 +378,11 @@ static ansi_esc_seq_status_t con_ansi_parse(const char * ansi_buf, unsigned int
                 {
                     if(handle_ansi_formatting_sequence_number(n2) != SUCCESS)
                     {
-                        // Bereits uebernommene Aenderungen rueckgaengig machen
-                        con_color._color = attr;
                         return INVALID;
                     }
                 }
 
                 return SUCCESS;
-            }
 
             case 's': // ESC[s - Cursor-Position speichern
                 if(have_delimiter || have_n1 || have_n2)
@@ -428,14 +419,14 @@ void con_putc(const char c)
 {
     static char last_char = 0;
 
+    if (c == '\n') {
+        outb(0x3f8, '\r');
+        while ((inb(0x3fd) & 0x20) == 0) asm("nop");
+    }
     outb(0xe9, c);
     outb(0x3f8, c);
     while ((inb(0x3fd) & 0x20) == 0) asm("nop");
     
-    if (debug_test_flag(DEBUG_FLAG_NO_KCONSOLE)) {
-        return;
-    }
-
     switch(c)
     {
         case '\n':
@@ -567,7 +558,7 @@ void con_puts(const char * s)
  */
 void con_putsn(unsigned int n, const char * s)
 {
-    while(*s && n--)
+    while(n-- && *s)
     {
         con_putc_ansi(*s);
         s++;
@@ -600,7 +591,7 @@ void init_console(void)
 /**
  * Aktualisiert die Postition des Hardware Cursors
  */
-static void con_set_hw_cursor(void)
+void con_set_hw_cursor(void)
 {
     //Hardware Cursor verschieben
     uint16_t hw_cursor_pos = cursor_x + cursor_y * SCREEN_WIDTH;
diff --git a/src/kernel/src/debug.c b/src/kernel/src/debug.c
index 34b51c0d..28312dbe 100644
--- a/src/kernel/src/debug.c
+++ b/src/kernel/src/debug.c
@@ -33,159 +33,50 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <elf32.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <string.h>
 
-#include "elf32.h"
+#include <lost/config.h>
 #include "kprintf.h"
 #include "multiboot.h"
-#include "paging.h"
 #include "debug.h"
-#include "string.h"
-#include "intr.h"
-#include "tasks.h"
-
-static Elf32_Shdr * symtab = 0; // Zeiger auf den ELF-Header-Eintrag der Symbol Tabelle ...
-static Elf32_Shdr * strtab = 0; // ... und der String Tabelle
 
 static uint32_t debug_flags = 0;
 
 /**
- * Gibt einen Zeiger auf das Symbol mit der gr��ten Adresse kleiner als addr 
- * zur�ck. Wenn kein Symbol bestimmt werden kann, wird 0 zur�ck gegeben.
- */
-static Elf32_Sym * elf_find_sym(uint32_t addr)
-{
-    Elf32_Sym * sym;
-    int i;
-
-    if(symtab == 0)
-    {
-        return 0;
-    }
-
-    sym = (Elf32_Sym *)symtab->sh_addr;
-
-    for(i = 0; i < symtab->sh_size / sizeof(Elf32_Sym); i++)
-    {
-        if(addr >= (uint32_t)sym[i].st_value && addr < (uint32_t)sym[i].st_value + sym[i].st_size)
-        {
-            return sym + i;
-        }
-    }
-
-    return 0;
-}
-
-/**
- * Gibt den String zum Index in die String Tabelle des Kernels zur�ck.
+ * Ueberprueft ob ein bestimmtes Debug-Flag gesetzt ist
+ *
+ * @param flag Flag-Nummer
+ *
+ * @return TRUE wenn gesetzt, FALSE sonst
  */
-static char * elf_get_str(Elf32_Word index)
+bool debug_test_flag(uint32_t flag)
 {
-    if(strtab == 0)
-    {
-        return "";
-    }
-
-    return (char*)strtab->sh_addr + index;
+    return ((debug_flags & flag) != 0);
 }
 
 /**
- * Mappt den ELF-Header, sowie die ELF-Symbol-Tabelle und die dazugeh�rige
- * String-Tabelle, wenn sie vorhanden sind.
+ * Gibt die Debug-Meldung aus, wenn das Flag gesetzt ist.
+ *
+ * @param flag Flag-Nummer
  */
-void init_stack_backtrace(void)
-{
-    Elf32_Shdr * elfshdr = (Elf32_Shdr *)multiboot_info.mi_elfshdr_addr;
-    int i;
-
-    /* ELF Header mappen */
-    map_page_range(kernel_page_directory, elfshdr, (paddr_t) elfshdr,
-        PTE_W | PTE_P /*| PTE_U*/,
-        NUM_PAGES(multiboot_info.mi_elfshdr_num * sizeof(Elf32_Shdr)));
-
-    if(multiboot_info.mi_flags & MULTIBOOT_INFO_HAS_ELF_SYMS)
-    {
-        /* Symbol Table und String Table suchen */
-        for (i = 0; i < multiboot_info.mi_elfshdr_num; i++)
-        {
-            if(elfshdr[i].sh_type == SHT_SYMTAB)
-            {
-                symtab = &elfshdr[i];
-                strtab = &elfshdr[symtab->sh_link];
-                
-                break;
-            }
-        }
-    }
-
-    if(symtab != 0 && strtab != 0)
-    {
-        /* Symbol Tabelle und String Tabelle mappen */
-
-        kernel_identity_map((paddr_t)symtab->sh_addr, symtab->sh_size);
-        kernel_identity_map((paddr_t)strtab->sh_addr, strtab->sh_size);
-    }
-}
-
-void stack_backtrace_ebp(uint32_t start_ebp, uint32_t start_eip)
+void debug_print(uint32_t flag, const char* message)
 {
-    struct stack_frame
-    {
-        struct stack_frame * ebp;
-        uint32_t eip;
-       /* uint32_t args[0];*/
-    } * stack_frame;
-    Elf32_Sym * sym;
-
-    kprintf("stack backtrace:\n");
-
-    if (start_ebp != 0)
-    {
-        kprintf("ebp %08x eip %08x", start_ebp, start_eip);
-        if((sym = elf_find_sym(start_eip)))
-        {
-            kprintf(" <%s + 0x%x>", elf_get_str(sym->st_name), start_eip - sym->st_value);
-        }
-        kprintf("\n");
-
-        stack_frame = (struct stack_frame*) start_ebp;
-    }
-    else
-    {
-        __asm volatile ("mov %%ebp, %0" : "=r"(stack_frame));
-    }
-
-    for( ; is_userspace(stack_frame, sizeof(*stack_frame)) && stack_frame->ebp != 0; stack_frame = stack_frame->ebp)
-    {
-        kprintf("ebp %08x eip %08x", stack_frame->ebp, stack_frame->eip);
-
-        if((sym = elf_find_sym(stack_frame->eip)))
-        {
-            kprintf(" <%s + 0x%x>", elf_get_str(sym->st_name), stack_frame->eip - sym->st_value);
-        }
-
-        kprintf("\n");
-    }
-
-    if (stack_frame && !is_userspace(stack_frame, sizeof(*stack_frame))) {
-        kprintf("Stack kaputt.\n");
+    if (debug_test_flag(flag)) {
+        kprintf("DEBUG: %s\n", message);
     }
 }
 
-void stack_backtrace(void)
-{
-    stack_backtrace_ebp(0, 0);
-}
-
-///Setzt die richtigen Debug-Flags anhand der Commandline vom bootloader
+///Setzt die richtigen Debug-Flags anhand der Commandline vom Bootloader
 void debug_parse_cmdline(char* cmdline)
 {
     char* pos = strstr(cmdline, "debug=");
     debug_flags = 0;
 
     if(pos == NULL) return;
-    
+
     //Debug= ueberspringen
     pos += 6;
     while((*pos != 0) && (*pos != ' '))
@@ -207,57 +98,8 @@ void debug_parse_cmdline(char* cmdline)
             case 'c':
                 debug_flags |= DEBUG_FLAG_SYSCALL;
                 break;
-
-            case 'n':
-                debug_flags |= DEBUG_FLAG_NO_KCONSOLE;
-                break;
         }
         pos++;
     }
 }
 
-///Ueberprueft ob ein bestimmtes Debug-Flag gesetzt ist
-bool debug_test_flag(uint32_t flag)
-{
-    return ((debug_flags & flag) != 0);
-}
-
-///Gibt die Debug-Meldung aus, wenn das Flag gesetzt ist
-void debug_print(uint32_t flag, const char* message)
-{
-    if(debug_test_flag(flag))
-    {
-        kprintf("DEBUG: %s\n", message);
-    }
-}
-
-
-void print_tasks_backtrace(void)
-{
-    struct task* task = first_task;
-    struct int_stack_frame* isf;
-
-    while (task != NULL)
-    {
-        kprintf("\n\nPID %d: %s\n"
-            "Status %d, blocked_by_pid %d, blocked_count %d\n",
-            task->pid, 
-
-            (task == 0 
-                ? "Kernel-Initialisierung"
-                : (task->cmdline != NULL 
-                    ? task->cmdline 
-                    : "Unbekannter Task")),
-
-            task->status, task->blocked_by_pid, task->blocked_count);
-        
-        __asm("mov %0, %%cr3" : : "r"(resolve_vaddr(kernel_page_directory, task->cr3)));
-        
-        isf = (struct int_stack_frame*) task->esp;
-        stack_backtrace_ebp(isf->ebp, isf->eip);
-
-        task = task->next_task;
-    }
-        
-    __asm("mov %0, %%cr3" : : "r"(resolve_vaddr(kernel_page_directory, current_task->cr3)));
-}
diff --git a/src/kernel/src/gdt.c b/src/kernel/src/gdt.c
deleted file mode 100644
index fe837c76..00000000
--- a/src/kernel/src/gdt.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2006 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	    This product includes software developed by the tyndur Project
- *	    and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE tyndur PROJECT AND CONTRIBUTORS ``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 tyndur PROJECT OR CONTRIBUTORS
- * 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.
- */
-
-/*
- * Vorl�ufige Funktionen zur Verwaltung der GDT
- *
- * Aenderungen:
- *
- * 2006-04-09: taljeth
- *   + Erste Version erstellta
- */
-
-#include <stdint.h>
-
-#include "gdt.h"
-#include "tss.h"
-
-typedef struct {
-  uint16_t size;
-  uint16_t base;
-  uint8_t base2;
-  uint8_t access;
-  uint8_t size2;
-  uint8_t base3;
-} segment_descriptor;
-
-segment_descriptor gdt[GDT_SIZE];
-
-/**
- * Legt eine GDT an und initialisiert sie mit mit jeweils einem Code- und
- * Datendeskriptor f�r Ring 0 und Ring 3 und einem Deskriptor f�r die TSS.
- * Anschlie�end wird sie geladen.
- */
-void init_gdt()
-{
-  // Ring-0-Code- und Datenselektoren eintragen
-  gdt_set_descriptor(1, 0x000FFFFF, 0x00000000, GDT_SEGMENT | GDT_PRESENT | GDT_CODESEG, 0);
-  gdt_set_descriptor(2, 0x000FFFFF, 0x00000000, GDT_SEGMENT | GDT_PRESENT | GDT_DATASEG, 0);
-
-  // Ring-3-Code- und Datenselektoren eintragen
-  gdt_set_descriptor(3, 0x000FFFFF, 0x00000000, GDT_SEGMENT | GDT_PRESENT | GDT_CODESEG, 3);
-  gdt_set_descriptor(4, 0x000FFFFF, 0x00000000, GDT_SEGMENT | GDT_PRESENT | GDT_DATASEG, 3);
-
-  // Task irgendwas
-  gdt_set_descriptor_byte_granularity(5, sizeof(tss) - 1,
-    (uint32_t)&tss, GDT_PRESENT | GDT_TSS, 3);
-
-  // GDTR laden
-  struct {
-    uint16_t size;
-    uint32_t base;
-  }  __attribute__((packed)) gdt_ptr = {
-    .size  = GDT_SIZE*8 - 1,
-    .base  = (uint32_t)gdt,
-  };
-
-  __asm__("lgdtl %0\n\t"
-    "ljmpl $0x08, $1f\n\t"
-    "1:\n\t"
-    "mov $0x10, %%eax\n\t"
-    "mov %%eax, %%ds\n\t"
-    "mov %%eax, %%es\n\t"
-    "mov %%eax, %%fs\n\t"
-    "mov %%eax, %%gs\n\t"
-    "mov %%eax, %%ss\n\t" : : "m" (gdt_ptr) : "eax");
-
-  __asm__("ltr %%ax\n\t" : : "a" (TSS_SEL));
-}
-
-/**
- * Setzt einen Deskriptor in der GDT.
- *
- * \param segment Nummer des Deskriptors
- * \param size Gr��e des Segments in Pages
- * \param base Basisadresse des Segments
- * \param access Access-Byte des Deskriptors
- * \param dpl Descriptor Privilege Level
- */
-void gdt_set_descriptor(int segment, uint32_t size, uint32_t base, uint8_t access,
-    int dpl)
-{
-  gdt[segment].size   = size & 0xFFFF;
-  gdt[segment].size2  = ((size >> 16) & 0x0F) | 0xC0;
-  gdt[segment].base   = base & 0xFFFF;
-  gdt[segment].base2  = (base >> 16) & 0xFF;
-  gdt[segment].base3  = ((base >> 24) & 0xFF);
-  gdt[segment].access = access | ((dpl & 3) << 5);
-}
-
-/**
- * Setzt einen Deskriptor in der GDT, wobei die Gr��e als Byteangabe
- * interpretiert wird.
- *
- * \param segment Nummer des Deskriptors
- * \param size Gr��e des Segments in Bytes
- * \param base Basisadresse des Segments
- * \param access Access-Byte des Deskriptors
- * \param dpl Descriptor Privilege Level
- */
-void gdt_set_descriptor_byte_granularity(int segment, uint32_t size,
-    uint32_t base, uint8_t access, int dpl)
-{
-  gdt_set_descriptor(segment, size, base, access, dpl);
-  gdt[segment].size2  = ((size >> 16) & 0x0F) | 0x40;
-}
diff --git a/src/kernel/src/header.asm b/src/kernel/src/header.asm
deleted file mode 100644
index a3a8d2d9..00000000
--- a/src/kernel/src/header.asm
+++ /dev/null
@@ -1,90 +0,0 @@
-;
-; Copyright (c) 2006 The tyndur Project. All rights reserved.
-;
-; This code is derived from software contributed to the tyndur Project
-; by Kevin Wolf.
-;
-; Redistribution and use in source and binary forms, with or without
-; modification, are permitted provided that the following conditions
-; are met:
-; 1. Redistributions of source code must retain the above copyright
-;    notice, this list of conditions and the following disclaimer.
-; 2. 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.
-; 3. All advertising materials mentioning features or use of this software
-;    must display the following acknowledgement:
-;     This product includes software developed by the tyndur Project
-;     and its contributors.
-; 4. Neither the name of the tyndur Project nor the names of its
-;    contributors may be used to endorse or promote products derived
-;    from this software without specific prior written permission.
-;
-; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-; ``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 COPYRIGHT HOLDERS OR
-; CONTRIBUTORS 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.
-;
-
-; Initialisiert esp und ruft main() auf
-;
-; Aenderungen:
-;
-; 2006-04-09: taljeth
-;   + Erste Version erstellt
-;
-; 2006-04-09: Golum
-;   + Uebergabe der von GRUB bereitgestellten Informationen
-;
-; 2006-04-13: nore
-;   ! falsch gesetztes "kernelstack" Label an die richtige Stelle gesetzt
-;
-; 2006-07-12: Jidder
-;   ! via Paging (statt Segmentation) den Kernel nach 0xc0000000 mappen
-;   ! das log wird mir zu lang, deswegen hab ich mein Zeug mal zensiert ;)
-;
-
-extern init
-global _start
-
-section .text
-_start:
-
-	; Stack initalisieren
-	mov esp, kernelstack
-
-	; Damit die Stack Traces hier enden ein Stack Frame mit Nullwerten f�r die R�cksprungadresse und den alten Stack Frame erstellen
-	push 0
-	push 0
-	mov ebp, esp
-
-	; Die vom Multiboot Loader �bergebenen Informationen auf den Stack legen (init ben�tigt sie)
-	push ebx
-	push eax
-
-	mov eax, init
-	call eax
-	cli
-	hlt
-
-section multiboot
-multiboot_header:
-align 4
-  MULTIBOOT_MAGIC     equ 0x1BADB002
-  MULTIBOOT_FLAGS     equ 0x03
-  MULTIBOOT_CHECKSUM  equ -MULTIBOOT_MAGIC-MULTIBOOT_FLAGS
-
-  dd MULTIBOOT_MAGIC
-  dd MULTIBOOT_FLAGS
-  dd MULTIBOOT_CHECKSUM
-
-section .bss
-  resb  16384
-kernelstack:
diff --git a/src/kernel/src/init.c b/src/kernel/src/init.c
index 5ec14bb2..2a38a759 100644
--- a/src/kernel/src/init.c
+++ b/src/kernel/src/init.c
@@ -33,151 +33,325 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */  
 
- /** 
-  * Kernel-Initialisierung erfolgt hier,
-  * die Funktion init wird von header.asm aufgerufen 
-  */
-
+#include <string.h>
+#include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
+#include <lost/config.h>
+#include <lock.h>
 
-#include "kernel.h"
-#include "gdt.h"
-#include "intr.h"
-#include "kprintf.h"
-#include "ports.h"
 #include "multiboot.h"
-#include "string.h"
-#include "tss.h"
-#include "kprintf.h"
-#include "paging.h"
-#include "modules.h"
-#include "stdlib.h"
-#include <lost/config.h>
+#include "mm.h"
+#include "im.h"
+#include "tasks.h"
 #include "syscall.h"
+
+#include "console.h"
+#include "kprintf.h"
 #include "debug.h"
-#include "io.h"
+#include "apic.h"
+#include "lock.h"
+#include "gdt.h"
 #include "timer.h"
-#include "shm.h"
-#include "vm86.h"
+#include "lostio/core.h"
 
 struct multiboot_info multiboot_info;
 
-extern void init_phys_mem(vaddr_t mmap_addr, uint32_t mmap_length,
-    uint32_t upper_mem);
-extern void init_paging(void);
-extern void init_console(void);
-extern void init_scheduler(void);
-extern void init_stack_backtrace(void);
+#define init_context (&init_thread.process->context)
+
+extern const void kernelstack_bottom;
+extern const void kernelstack;
+
+pm_thread_t init_thread;
+pm_process_t init_process = {
+    .cmdline = "(Kernel)",
+};
+
+lock_t init_lock = 0;
 
-void keyboard_handler(int irq)
+void smp_init(void);
+void gdt_init(void);
+void vm86_init(void);
+void panic(char* message, ...);
+
+/**
+ * Liest die Kernelkommandozeile ein
+ *
+ * Als erster Teilstring wird einfach irgendwas akzeptiert, weil davon
+ * auszugehen ist, dass das der Kernelname ist. GRUB 2 übergibt den
+ * Kernelnamen allerdings nicht, deswegen werden auch an erster Position
+ * Parameter ausgewertet, wenn sie bekannt sind.
+ */
+static void parse_cmdline(char* cmdline)
 {
-    //kprintf("[KEYB]\n");
+    char* p;
+    extern bool enable_smp;
+    bool kernel_name = true;
+
+    p = strtok(cmdline, " ");
+
+    while (p) {
+        if (!strncmp(p, "debug=", 6)) {
+            debug_parse_cmdline(p);
+        } else if (!strcmp(p, "smp")) {
+            enable_smp = true;
+        } else if (kernel_name) {
+            kernel_name = false;
+        } else {
+            kprintf("Unbekannte Option: '%s'\n", p);
+        }
+
+        p = strtok(NULL, " ");
+    }
 }
 
-void init(int multiboot_magic, struct multiboot_info *boot_info)
+/**
+ * Kernel-Initialisierung erfolgt hier,
+ * die Funktion init wird von header.asm aufgerufen (BSP = true) oder aus
+ * smp_trampoline.asm
+ *
+ * @param multiboot_magic Multiboot Magic-Number
+ * @param multiboot_info Pointer zur Multiboot-Info-Struct
+ * @param bsp true, wenn die Funktion auf dem Bootstrap-Prozessor laeuft
+ */
+void init(int multiboot_magic, struct multiboot_info *boot_info, bool bsp)
 {
-    init_console();
+    static lock_t init_lock = LOCK_LOCKED;;
+    // Diese ersten Initialisierungen muessen nur einmal, und ganz am Anfang
+    // gemacht werden.
+    if (bsp == true) {
+        init_console();
 
-    memcpy(&multiboot_info, boot_info, sizeof(struct multiboot_info));
+        // Multiboot-Infos sichern
+        memcpy(&multiboot_info, boot_info, sizeof(struct multiboot_info));
 
-    
-    //Debugparameter verarbeiten
-    if((multiboot_info.mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0)
-    {
-        debug_parse_cmdline(multiboot_info.mi_cmdline);
+        // Hiermit wird eine Laufende Multitasking-Umgebung simuliert. Dies ist
+        // notwendig, damit im restlichen Code keine Aenderungen notwendig sind
+        // fuer die Initialisierung.
+        init_thread = (pm_thread_t) {
+            .process                = &init_process,
+            .kernel_stack_bottom    = (vaddr_t) &kernelstack_bottom,
+            .kernel_stack_size      = (uint8_t*) &kernelstack
+                                    - (uint8_t*) &kernelstack_bottom,
+        };
+
+        cpu_get(0)->thread = &init_thread;
+
+        // Debugparameter verarbeiten, das ist aber nur moeglich, wenn eine
+        // Kernelkommandozeile existiert.
+        if ((multiboot_info.mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0) {
+            parse_cmdline((char*)(uintptr_t)multiboot_info.mi_cmdline);
+        }
+
+#if CONFIG_ARCH == ARCH_I386
+        // IVT fuer den VM86 sichern
+        vm86_init();
+#endif
+
+        debug_print(DEBUG_FLAG_INIT, "Initialisiere physische "
+            "Speicherverwaltung");
+        pmm_init(&multiboot_info);
+
+        // APIC initialisieren (Wird bei der SMP-Initialisierung genutzt
+        apic_init();
+
+        // SMP muss _direkt nach_ der physikalischen Speicherverwaltung
+        // initialisiert werden, da sonst notwendige Strukturen im Speicher
+        // dazu ueberschrieben werden koennten.
+        debug_print(DEBUG_FLAG_INIT, "Initialisiere Mehrprozessor-"
+            "Unterstuetzung");
+        smp_init();
+
+        // GDT und IDT vorbereiten
+        debug_print(DEBUG_FLAG_INIT, "gdt/idt_init");
+        gdt_init();
+        im_init();
+
+        // Eventuellen zusaetzlichen Prozessoren Mitteilen, dass sie mit der
+        // Initialisierung fortfahren duerfen.
+        unlock(&init_lock);
+    } else {
+        lock_wait(&init_lock);
+
+        // APIC initialisieren. Dies ist beim BSP bereits erledigt.
+        apic_init();
     }
-    
-    save_bios_data();
-    
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere physikalische Speicherverwaltung");
-    init_phys_mem(multiboot_info.mi_mmap_addr, multiboot_info.mi_mmap_length, multiboot_info.mi_mem_upper);
-
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere Paging");
-    init_paging();
-
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere Speicherverwaltung");
-    init_memory_manager();
-    init_shared_memory();
-    
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere GDT");
-    init_gdt();
-    
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere Kernel Stack-Backtraces");
-    init_stack_backtrace();
-    
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere IDT");
-    init_idt();
-
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere Scheduler");
-    init_scheduler();
-    
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere Timer");
-    timer_init();
-    
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere IO-Ports");
-    init_io_ports();
-    
-    
-    //Erst das Init-Modul laden, danach Multitasking starten und erst dann die
-    //Module an init weiter geben
-    debug_print(DEBUG_FLAG_INIT, "Lade Init-Modul");
-    load_init_module(&multiboot_info);
-
-    debug_print(DEBUG_FLAG_INIT, "Uebergebe die restlichen Module an das Init-Modul");
-    load_multiboot_modules(&multiboot_info);
-
-    request_irq(1, &keyboard_handler);
-
-    
-    debug_print(DEBUG_FLAG_INIT, "Aktiviere Interrupts");
-    enable_interrupts();
-
-    // An dieser Stelle sofort einen Interrupt auszuf�hren, ist aus zwei 
-    // Gr�nden notwendig:
-    //
-    // 1. Kooperatives Multitasking startet sonst nicht
-    // 2. current_task sollte m�glichst schnell initialisiert werden, da
-    //    es nur an wenigen Stellen auf NULL �berpr�ft wird
-    asm volatile ("int $0x20");   
-    
-    while(1)
-    {
-        __asm__ __volatile__("hlt");
+
+    // Die IDT und die GDT wurden schon vorbereitet und muessen jetzt nur noch
+    // aktiviert werden auf diesem Prozessor.
+    debug_print(DEBUG_FLAG_INIT, "Initialisiere Deskriptortabellen fuer einen "
+        "Prozessor");
+    gdt_init_local();
+    im_init_local();
+
+
+    // Auf dem BSP muss die ganze virtuelle Speicherverwaltung initialisiert
+    // werden. Bei den APs reicht es, wenn sie ihren Stack mappen.
+    static volatile lock_t mm_prepare_lock = LOCK_LOCKED;
+    cpu_get_current()->thread = &init_thread;
+    if (bsp == true) {
+        *init_context = mmc_create_kernel_context();
+        mmc_activate(init_context);
+
+        // Freigabe erteilen, damit die APs ihre Stacks mappen koennen.
+        unlock(&mm_prepare_lock);
+    } else {
+        // Warten, bis wir das Signal vom BSP haben, zum fortfahren
+        lock_wait(&mm_prepare_lock);
+
+        // TODO: Was tun, wenn dieses identity-Mapping schief geht?
+        // Dies ist naehmlich sher warscheinlich.
+        uintptr_t sp;
+        #if CONFIG_ARCH == ARCH_AMD64
+            asm volatile("movq %%rsp, %0" : "=r"(sp));
+        #else
+            asm volatile("movl %%esp, %0" : "=r"(sp));
+        #endif
+        mmc_map(init_context, (vaddr_t) PAGE_ALIGN_ROUND_DOWN(sp),
+            (paddr_t) PAGE_ALIGN_ROUND_DOWN(sp), MM_FLAGS_KERNEL_DATA, 1);
     }
-}
 
-extern void stack_backtrace(void);
+
+    // Warten, bis alle CPUs hier angekommen sind.
+    // TODO: Timeout?
+    static volatile uint32_t cpus_arrived = 0;
+    locked_increment(&cpus_arrived);
+    while (cpus_arrived < cpu_count) asm("nop");
+
+    // SSE aktivieren
+    // Allerdings nur, wenn cpuid sagt, dass die Flags FXSR und SSE da sind,
+    // sonst rennen wir hier in Exceptions.
+    // TODO: Buildscripts fixen?
+    uint32_t edx = 0, dummy = 0;
+    asm volatile("cpuid": "=d" (edx), "=a" (dummy) : "a" (1) : "ebx", "ecx");
+    if ((edx & (1 << 24)) && (edx & (1 << 25))) {
+        #if CONFIG_ARCH == ARCH_AMD64
+            asm volatile(
+                "movq %cr0, %rax;"
+                "andq $0xfffffffffffffffb, %rax;"
+                "orq $2, %rax;"
+                "movq %rax, %cr0;"
+                "movq %cr4, %rax;"
+                "orq $0x600, %rax;"
+                "movq %rax, %cr4;"
+            );
+        #else
+            asm volatile(
+                "movl %cr0, %eax;"
+                "andl $0xfffffffb, %eax;"
+                "orl $2, %eax;"
+                "movl %eax, %cr0;"
+                "movl %cr4, %eax;"
+                "orl $0x600, %eax;"
+                "movl %eax, %cr4;"
+            );
+        #endif
+    }
+
+    static volatile lock_t vmm_lock = LOCK_LOCKED;
+    // ACHTUNG: Hier besteht ein kleines Problem: Da in vmm_init der APIC
+    // gemappt wird, kann nicht mehr darauf zugegriffen werden, bis Paging
+    // aktiviert ist. Das geht sonst schief! Genau das geschieht aber, wenn
+    // mapping-Funktionen aufgerufen werden. Darum muss alles gemappt sein,
+    // bevor vmm_init aufgerufen wird.
+    if (bsp == true) {
+        debug_print(DEBUG_FLAG_INIT, "Initialisiere virtuelle "
+            "Speicherverwaltung");
+        vmm_init(init_context);
+        unlock(&vmm_lock);
+    }
+
+    lock_wait(&vmm_lock);
+    // Hier wird je nach Architektur Paging aktiviert
+    vmm_init_local(init_context);
+
+
+    // Hier geht die initialisierung langsam dem Ende zu. Jetzt fuehrt der BSP
+    // noch ein paar notwendige Dinge durch, wartet dann auf die anderen CPUs
+    // und gibt den endgueltigen Startschuss.
+    static volatile uint32_t final_cpus_arrived = 0;
+    static volatile lock_t final_lock = LOCK_LOCKED;
+    locked_increment(&final_cpus_arrived);
+
+    if (bsp == true) {
+        debug_print(DEBUG_FLAG_INIT, "Initialisiere Kerneldienste");
+
+        // Syscalls initialisieren
+        syscall_init();
+
+        // Prozessverwaltung initialisieren
+        pm_init();
+
+        // Shared Memory initialisieren
+        shm_init();
+
+        // Timer initialisieren
+        timer_init();
+
+        // LostIO initialisieren
+        lio_init();
+
+        // Init-Modul laden
+        debug_print(DEBUG_FLAG_INIT, "Lade Module");
+        load_init_module(&multiboot_info);
+
+        // Alle weiteren Module an init uebergeben
+        load_multiboot_modules(&multiboot_info);
+
+        // Sobald alle CPUs angekommen sind, gehts los!
+        // TODO: Timeout?
+        debug_print(DEBUG_FLAG_INIT, "BSP: Warte auf andere CPUs");
+        while (final_cpus_arrived < cpu_count) asm("nop");
+        unlock(&final_lock);
+    } else {
+        // Warten, bis wir das Signal vom BSP haben, zum fortfahren
+        lock_wait(&final_lock);
+    }
+
+
+    // Ersten Thread auf dieser CPU starten
+    debug_print(DEBUG_FLAG_INIT, "Starte Ausfuehrung von init");
+    current_thread = pm_scheduler_pop();
+    interrupt_stack_frame_t* isf = im_prepare_current_thread();
+    asm volatile("jmp im_run_thread" :: "a" (isf));
+
+    // Hier kommen wir nie hin
+}
 
 __attribute__((noreturn)) void panic(char * message, ...)
 {
-    int * args = ((int*)&message) + 1;
-    disable_interrupts();
+    __asm__ __volatile__("cli");
+    va_list args;
+    va_start(args,message);
+
+    // XXX disable_interrupts();
 
     kprintf("\n"
       "\033[1;37m\033[41m" // weiss auf rot
       "PANIC: ");
-    kaprintf(message, &args);
+    kaprintf(message, args);
     kprintf("\n");
 
+    // FIXME
+    #undef CONFIG_DEBUG_LAST_SYSCALL
     #ifdef CONFIG_DEBUG_LAST_SYSCALL
     {
         uint32_t i;
 
-        kprintf("Letzter Syscall (von PID %d): %d ", debug_last_syscall_pid,
-            debug_last_syscall_no);
+        kprintf("Letzter Syscall: %d ", debug_last_syscall_no);
         for (i = 0; i < DEBUG_LAST_SYSCALL_DATA_SIZE; i++) {
             kprintf("0x%08x ", debug_last_syscall_data[i]);
         }
         kprintf("\n");
     }
-    #endif 
+    #endif
+
+    stack_backtrace(0, 0);
+
+    kprintf("\033[0;37m\033[40m");
 
-    stack_backtrace();
 
     while(1) {
-      __asm__ __volatile__("hlt");
+      cpu_halt();
     }
 }
-
-void syscall_p(void) {}
-void syscall_v(void) {}
diff --git a/src/kernel2/src/interrupts/apic.c b/src/kernel/src/interrupts/apic.c
similarity index 100%
rename from src/kernel2/src/interrupts/apic.c
rename to src/kernel/src/interrupts/apic.c
diff --git a/src/kernel2/src/interrupts/im.c b/src/kernel/src/interrupts/im.c
similarity index 100%
rename from src/kernel2/src/interrupts/im.c
rename to src/kernel/src/interrupts/im.c
diff --git a/src/kernel2/src/interrupts/pic.c b/src/kernel/src/interrupts/pic.c
similarity index 100%
rename from src/kernel2/src/interrupts/pic.c
rename to src/kernel/src/interrupts/pic.c
diff --git a/src/kernel/src/intr.c b/src/kernel/src/intr.c
deleted file mode 100644
index bab6e5a5..00000000
--- a/src/kernel/src/intr.c
+++ /dev/null
@@ -1,584 +0,0 @@
-/*  
- * Copyright (c) 2006 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS 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.
- */  
-
-/*
- * Funktionen zur Verwaltung von Interrupts
- */
-
-#include <stdint.h>
-
-#include "cpu.h"
-#include "ports.h"
-#include "types.h"
-#include "kernel.h"
-#include "intr.h"
-#include "tss.h"
-#include "kprintf.h"
-#include "paging.h"
-#include "string.h"
-#include "syscall.h"
-#include "tasks.h"
-#include "vmm.h"
-#include <lost/config.h>
-#include "debug.h"
-#include "rpc.h"
-#include "vm86.h"
-#include "tss.h"
-
-#define MAX_INTERRUPTS 4
-
-typedef struct {
-  uint16_t lsb_handler;
-  uint16_t selector;
-  uint8_t reserved;
-  uint8_t access;
-  uint16_t msb_handler;
-} gate_descriptor;
-
-gate_descriptor idt[IDT_SIZE];
-
-/**
- * Fuer jeden IRQ genau ein Handler. Wenn es keinen Handler gibt, ist der
- * entsprechende Wert 0.
- */
-pfIrqHandler irq_handlers[16] = { 0 };
-
-static struct task * intr_handling_task[256][MAX_INTERRUPTS] = { { NULL } };
-
-void handle_irq(int irq, uint32_t* esp);
-
-extern void null_handler(void);
-
-extern void exception_stub_0(void);
-extern void exception_stub_1(void);
-extern void exception_stub_2(void);
-extern void exception_stub_3(void);
-extern void exception_stub_4(void);
-extern void exception_stub_5(void);
-extern void exception_stub_6(void);
-extern void exception_stub_7(void);
-extern void exception_stub_8(void);
-extern void exception_stub_9(void);
-extern void exception_stub_10(void);
-extern void exception_stub_11(void);
-extern void exception_stub_12(void);
-extern void exception_stub_13(void);
-extern void exception_stub_14(void);
-extern void exception_stub_16(void);
-extern void exception_stub_17(void);
-extern void exception_stub_18(void);
-extern void exception_stub_19(void);
-
-extern void irq_stub_0(void);
-extern void irq_stub_1(void);
-extern void irq_stub_2(void);
-extern void irq_stub_3(void);
-extern void irq_stub_4(void);
-extern void irq_stub_5(void);
-extern void irq_stub_6(void);
-extern void irq_stub_7(void);
-extern void irq_stub_8(void);
-extern void irq_stub_9(void);
-extern void irq_stub_10(void);
-extern void irq_stub_11(void);
-extern void irq_stub_12(void);
-extern void irq_stub_13(void);
-extern void irq_stub_14(void);
-extern void irq_stub_15(void);
-
-extern void syscall_stub(void);
-
-extern void stack_backtrace_ebp(uint32_t start_ebp, uint32_t start_eip);
-
-void handle_exception(uint32_t* esp);
-
-void send_irqs(uint32_t* esp);
-static uint32_t irqs_to_send[16][MAX_INTERRUPTS];
-extern uint32_t kernel_pd_id;
-
-/*
- * gibt einen neuen Wert fuer esp zurck
- */
-uint32_t handle_int(uint32_t esp)
-{
-    struct int_stack_frame * isf = (struct int_stack_frame *)esp;
-    struct task* old_task = current_task;
-
-//	kprintf("\nTask switch!  esp alter Task:0x%08x", isf->esp);
-	
-	if(isf->interrupt_number <= 31)
-    {
-        handle_exception(&esp);
-    }
-    else if(isf->interrupt_number <= 47)
-    {
-        // Ein IRQ
-        handle_irq(isf->interrupt_number - IRQ_BASE, &esp);
-		isf = (struct int_stack_frame *)esp;
-    }
-    else if(isf->interrupt_number == 48)
-    {
-        // Ein Syscall
-        syscall((struct int_stack_frame **) &esp);
-    }
-    else
-    {
-        // TODO: Abstuerzen, denn diese Interrupts duerften nicht aufgerufen werden
-    }
-
-    send_irqs(&esp);
-    //current_task = schedule();
-
-   // for(;;);
-
-    if ((current_task != NULL) && (old_task != current_task)) {
-        //tss.esp = current_task->kernel_stack;
-        isf = (struct int_stack_frame *)esp;
-        //kprintf("  esp neuer Task:0x%08x", isf->esp);
-
-        tss.esp0 = current_task->kernel_stack;
-        // sicherstellen, dass der Kernel Adressraum im Page Directory des Tasks korrekt gemappt ist
-        //kprintf("PID=%d  cr3=0x%08x  kernel_pd=0x%08x eip=0x%08x\n", 
-        //  current_task->pid, current_task->cr3, (uint32_t)kernel_page_directory, isf->eip);
-        //memcpy((void*)current_task->cr3, kernel_page_directory, 1024);
-
-        // Aktuelles Kernel-PD kopieren, wenn noetig
-        if (kernel_pd_id != current_task->pd_id) {
-            memcpy((void*) current_task->cr3, kernel_page_directory, 1020);
-            current_task->pd_id = kernel_pd_id;
-        }
-
-        // Page Directory des neuen Tasks laden
-        __asm("mov %0, %%cr3" : : "r"(resolve_vaddr(kernel_page_directory, current_task->cr3)));
-    }
-
-    if (current_task && (current_task->status == TS_WAIT_FOR_RPC)) {
-        current_task->status = TS_RUNNING;
-    }
-
-    //kprintf("int_handler: return %08x\n", esp);
-    //kprintf("int_handler: eip=%08x\n", isf->eip);
-    return esp;
-}
-
-/**
- * Legt eine IDT an und installiert die Exception Handler. Nicht genutzte
- * Eintraege werden mit Verweisen auf den Null-Handler initalisiert.
- * Anschliessend wird die IDT geladen.
- */
-void init_idt() {
-  int i;
-
-  // Tabelle initialisieren
-  for (i = 0; i < IDT_SIZE; i++)
-  {
-    set_intr(i, 0x08, &null_handler, 0, IDT_INTERRUPT_GATE);
-  }
-
-  // Register befuellen
-  struct {
-    uint16_t size;
-    uint32_t base;
-  }  __attribute__((packed)) idt_ptr = {
-    .size  = IDT_SIZE*8 - 1,
-    .base  = (uint32_t)idt,
-  };
-
-  // Exception Handler installieren
-  set_intr(0, 0x08, exception_stub_0, 0, IDT_INTERRUPT_GATE);
-  set_intr(1, 0x08, exception_stub_1, 0, IDT_INTERRUPT_GATE);
-  set_intr(2, 0x08, exception_stub_2, 0, IDT_INTERRUPT_GATE);
-  set_intr(3, 0x08, exception_stub_3, 0, IDT_INTERRUPT_GATE);
-  set_intr(4, 0x08, exception_stub_4, 0, IDT_INTERRUPT_GATE);
-  set_intr(5, 0x08, exception_stub_5, 0, IDT_INTERRUPT_GATE);
-  set_intr(6, 0x08, exception_stub_6, 0, IDT_INTERRUPT_GATE);
-  set_intr(7, 0x08, exception_stub_7, 0, IDT_INTERRUPT_GATE);
-  set_intr(8, 0x08, exception_stub_8, 0, IDT_INTERRUPT_GATE);
-  set_intr(9, 0x08, exception_stub_9, 0, IDT_INTERRUPT_GATE);
-  set_intr(10, 0x08, exception_stub_10, 0, IDT_INTERRUPT_GATE);
-  set_intr(11, 0x08, exception_stub_11, 0, IDT_INTERRUPT_GATE);
-  set_intr(12, 0x08, exception_stub_12, 0, IDT_INTERRUPT_GATE);
-  set_intr(13, 0x08, exception_stub_13, 0, IDT_INTERRUPT_GATE);
-  set_intr(14, 0x08, exception_stub_14, 0, IDT_INTERRUPT_GATE);
-  set_intr(16, 0x08, exception_stub_16, 0, IDT_INTERRUPT_GATE);
-  set_intr(17, 0x08, exception_stub_17, 0, IDT_INTERRUPT_GATE);
-  set_intr(18, 0x08, exception_stub_18, 0, IDT_INTERRUPT_GATE);
-  set_intr(19, 0x08, exception_stub_19, 0, IDT_INTERRUPT_GATE);
-
-  set_intr(IRQ_BASE + 0, 0x08, irq_stub_0, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 1, 0x08, irq_stub_1, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 2, 0x08, irq_stub_2, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 3, 0x08, irq_stub_3, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 4, 0x08, irq_stub_4, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 5, 0x08, irq_stub_5, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 6, 0x08, irq_stub_6, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 7, 0x08, irq_stub_7, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 8, 0x08, irq_stub_8, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 9, 0x08, irq_stub_9, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 10, 0x08, irq_stub_10, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 11, 0x08, irq_stub_11, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 12, 0x08, irq_stub_12, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 13, 0x08, irq_stub_13, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 14, 0x08, irq_stub_14, 0, IDT_INTERRUPT_GATE);
-  set_intr(IRQ_BASE + 15, 0x08, irq_stub_15, 0, IDT_INTERRUPT_GATE);
-
-
-  // PIC initalisieren
-  outb_wait(PIC1_COMMAND, ICW1_INIT + ICW1_ICW4);
-  outb_wait(PIC2_COMMAND, ICW1_INIT + ICW1_ICW4);
-
-  // nach IRQ_BASE bis IRQ_BASE + 0xf remappen
-  outb_wait(PIC1_DATA, IRQ_BASE);
-  outb_wait(PIC2_DATA, IRQ_BASE + 8);
-
-  // den Slave auf IRQ 2 setzen
-  outb_wait(PIC1_DATA, 4);
-  outb_wait(PIC2_DATA, 2);
-
-  outb_wait(PIC1_DATA, ICW4_8086);
-  outb_wait(PIC2_DATA, ICW4_8086);
-
-  // alle irqs aktivieren
-  outb_wait(PIC1_DATA, 0x00);
-  outb_wait(PIC2_DATA, 0x00);
-
-  // Handler fuer den System Call installieren
-  // TODO: Sollte eigentlich ein IDT_TRAP_GATE sein, aber irgendwo ist da
-  // noch ein Problem, das dann fuer einen Page Fault sorgt, wenn ich zu
-  // schnell tippe...
-  set_intr(SYSCALL_INTERRUPT, 0x08, syscall_stub, 3, IDT_INTERRUPT_GATE);
-  //set_intr(SYSCALL_INTERRUPT, 0x08, syscall_stub, 3, IDT_TRAP_GATE);
-
-  // IDT laden
-  asm("lidt %0" : : "m" (idt_ptr));
-}
-
-void disable_irq(uint8_t irq)
-{
-    if (irq < 8) {
-        outb(PIC1_DATA, inb(PIC1_DATA) | (1 << irq));
-    } else if (irq < 16) {
-        outb(PIC2_DATA, inb(PIC2_DATA) | (1 << (irq - 8)));
-    } else {
-        panic("Ungueltiger IRQ %d", irq);
-    }
-}
-
-void enable_irq(uint8_t irq)
-{
-    if (irq < 8) {
-        outb(PIC1_DATA, inb(PIC1_DATA) & ~(1 << irq));
-    } else if (irq < 16) {
-        outb(PIC2_DATA, inb(PIC2_DATA) & ~(1 << (irq - 8)));
-    } else {
-        panic("Ungueltiger IRQ %d", irq);
-    }
-}
-
-/**
- * Setzt einen Eintrag in der IDT.
- *
- * \param intr Nummer des Interrupts
- * \param selector Code-Selektor
- * \param handler Funktionspointer auf den Interrupthandler
- * \param dpl Descriptor Privilege Level
- * \param type Deskriptor Typ
- */
-void set_intr(int intr, uint16_t selector, void* handler, int dpl, int type)
-{
-  idt[intr].lsb_handler = ((uint32_t) handler) & 0xFFFF;
-  idt[intr].msb_handler = (((uint32_t) handler) >> 16) & 0xFFFF;
-  idt[intr].access = IDT_DESC_PRESENT | ((dpl & 3) << 5) | type;
-  idt[intr].selector = selector;
-  idt[intr].reserved = 0;
-}
-
-int request_irq(int irq, void * handler)
-{
-    if(irq < 0 || irq > 15)
-    {
-        return 1;
-    }
-
-    if(irq_handlers[irq] != 0)
-    {
-        return 1;
-    }
-
-    irq_handlers[irq] = handler;
-
-    return 0;
-}
-
-int release_irq(int irq)
-{
-    if(irq < 0 || irq > 15)
-    {
-        return 1;
-    }
-
-    irq_handlers[irq] = 0;
-
-    return 0;
-}
-
-
-void handle_irq(int irq, uint32_t* esp)
-{
-    int i;
-
-    //if (irq > 0) {
-    //    kprintf("Interrupt 0x%x\n", irq + IRQ_BASE);
-    //}
-
-    /*if (irq > 0)
-    {
-        uint8_t pic = (irq < 8 ? PIC1 : PIC2);
-        outb(pic + 3, 0x03);
-        if ((inb(pic) & (1 << (irq % 8))) == 0) {
-            kprintf("Spurious IRQ %d\n", irq);
-        }
-    }*/
-
-    // IRQs 7 und 15 koennen unabsichtlich aufgerufen werden
-    // In diesem Fall beim PIC nachschauen, ob wirklich was zu verarbeiten 
-    // ist, ansonsten gleich wieder abbrechen.
-    if ((irq == 7) || (irq == 15))
-    {
-        uint8_t pic = (irq < 8 ? PIC1 : PIC2);
-
-        outb(pic, 0x0B);
-        if ((inb(pic) & 0x80) == 0) {
-            kprintf("Spurious IRQ %d\n", irq);
-
-            // TODO Eigentlich sollte man hier keinen EOI brauchen, aber qemu
-            // scheint ihn zu brauchen
-            goto send_eoi;
-        }
-    }
-
-    for (i = 0; i < MAX_INTERRUPTS; i++) {
-        if (intr_handling_task[irq + IRQ_BASE][i] != NULL) {
-            i = -1;
-            break;
-        }
-    }
-    if (i == -1)
-    {
-        //kprintf("IRQ-Verarbeitung durch ein Modul\n");
-        for (i = 0; i < MAX_INTERRUPTS; i++) {
-            if (intr_handling_task[irq + IRQ_BASE][i] != NULL) {
-                irqs_to_send[irq][i]++;
-            }
-        }
-
-        //printf("disable IRQ %d\n", irq);
-        disable_irq(irq);
-    } 
-    else if (irq_handlers[irq] != 0)
-    {
-        irq_handlers[irq](irq, esp);
-    }
-
-send_eoi:
-    if(irq >= 8)
-    {
-        outb(PIC2_COMMAND, PIC_EOI);
-    }
-    outb(PIC1_COMMAND, PIC_EOI);
-}
-
-void set_intr_handling_task(uint8_t intr, struct task * task)
-{
-    int i;
-
-    //kprintf("Interrupt %d wird jetzt von Task %d behandelt\n", intr, task->pid);
-    for (i = 0; i < MAX_INTERRUPTS; i++) {
-        if ((intr_handling_task[intr][i] == NULL) ||
-            (i == MAX_INTERRUPTS - 1))
-        {
-            intr_handling_task[intr][i] = task;
-            if (intr >= IRQ_BASE && intr < IRQ_BASE + 16) {
-                irqs_to_send[intr - IRQ_BASE][i] = 0;
-            }
-            break;
-        }
-    }
-}
-
-void remove_intr_handling_task(struct task* task)
-{
-    int i, intr;
-
-    for (intr = 0; intr < 256; intr++) {
-        for (i = 0; i < MAX_INTERRUPTS; i++) {
-            if (intr_handling_task[intr][i] == task) {
-                intr_handling_task[intr][i] = NULL;
-            }
-        }
-    }
-}
-
-void handle_exception(uint32_t* esp)
-{
-    struct int_stack_frame * isf = *((struct int_stack_frame **)esp);
-
-    uint32_t cr2;
-    intptr_t diff;
-
-    switch(isf->interrupt_number)
-    {
-        case 13:
-            // Falls der Task seine IO-Bitmap noch nicht bekommen hat,
-            // erledigen wir das jetzt und lassen ihn dann nochmal versuchen.
-            if (tss.io_bit_map_offset == TSS_IO_BITMAP_NOT_LOADED) {
-                set_io_bitmap();
-                return;
-            }
-            break;
-
-        case 14:
-            cr2 = read_cr2();
-            diff = (cr2 >> PAGE_SHIFT) - (isf->esp >> PAGE_SHIFT);
-            // Ueberpruefen ob der Pagefault durch einen Stackoverflow
-            // hervorgerufen wurde
-            if ((diff >= -2) && (diff <= 2)
-                && (current_task != NULL)
-                && ((void*)cr2 >= current_task->user_stack_bottom - 0x1000000))
-            {
-                increase_user_stack_size(current_task, 1);
-                return;
-            }
-
-            kprintf("\033[1;37m\033[41mPage Fault: 0x%x\033[0;37m\033[40m", cr2);
-            break;
-    }
-
-    // Pruefen, ob ein VM86-Task die Exception ausgeloest hat, und evtl reagieren
-    if (isf->eflags & 0x20000) {
-        if (vm86_exception(esp)) {
-            return;
-        }
-    }
-    // Eine Exception. Fehlermeldung ausgeben und weg.
-    // Falls die Exception im Kernel aufgetreten ist, richtig weg, sonst nur
-    // den schuldigen Task beenden.
-    if (((isf->cs & 0x03) == 0) && !(isf->eflags & 0x20000)) {
-        kprintf("\n");
-        kprintf("\033[1;37m\033[41m"); // weiss auf rot
-        kprintf("Es wurde ein Problem festgestellt. tyndur wurde heruntergefahren, damit der\n"
-                "Computer nicht beschaedigt wird.\n"
-                "\n"
-                "Exception #%02d, int: #%d @ 0x%04x:0x%08x, PID %d, %s\n", 
-                isf->interrupt_number, isf->interrupt_number, isf->cs, isf->eip, current_task ? current_task->pid : 0, "(deaktiviert)" /*current_task ? current_task->cmdline : "(kernel)"*/);
-        kprintf("ss:esp= 0x%04x:0x%08x error code: 0x%08x\n", isf->ss, isf->esp, isf->error_code);
-        kprintf("eax:0x%08x, ebx:0x%08x, ecx:0x%08x, edx:0x%08x\n", isf->eax, isf->ebx, isf->ecx, isf->edx);
-        kprintf("ebp:0x%08x, esp:0x%08x, esi:0x%08x, edi:0x%08x\n", isf->ebp, isf->esp, isf->esi, isf->edi);
-        kprintf("eflags:0x%08x, ds:0x%04x, es:0x%04x, fs:0x%04x, gs:0x%04x\n", isf->eflags, isf->ds, isf->es, isf->fs, isf->gs);
-        #ifdef CONFIG_DEBUG_LAST_SYSCALL
-        {
-            uint32_t i;
-
-            kprintf("Letzter Syscall: %d ", debug_last_syscall_no);
-            for (i = 0; i < DEBUG_LAST_SYSCALL_DATA_SIZE; i++) {
-                kprintf("0x%08x ", debug_last_syscall_data[i]);
-            }
-            kprintf("\n");
-        }
-        #endif 
-
-        if(debug_test_flag(DEBUG_FLAG_STACK_BACKTRACE))
-        {
-            stack_backtrace_ebp(isf->ebp, isf->eip);
-        }
-
-        while(1) {
-          asm("cli; hlt");
-        }
-    } else {
-        kprintf(
-            "\n\033[1;37m\033[41mDer folgende Task wurde aufgrund einer "
-            "unbehandelten Ausnahme abgebrochen:\n%s\n\n"
-            "Exception #%02d, int: #%d @ 0x%04x:0x%08x, PID %d\n"
-            "ss:esp= 0x%04x:0x%08x error code: 0x%08x\n"
-            "eax:0x%08x, ebx:0x%08x, ecx:0x%08x, edx:0x%08x\n"
-            "ebp:0x%08x, esp:0x%08x, esi:0x%08x, edi:0x%08x\n"
-            "eflags:0x%08x, ds:0x%04x, es:0x%04x, fs:0x%04x, gs:0x%04x\n"
-            "\033[0;37m\033[40m",
-            
-            (current_task == 0 
-                ? "Kernel-Initialisierung"
-                : (current_task->cmdline != NULL 
-                    ? current_task->cmdline 
-                    : "Unbekannter Task")),
-
-            isf->interrupt_number, isf->interrupt_number, isf->cs, isf->eip, 
-            current_task ? current_task->pid : 0,
-            isf->ss, isf->esp, isf->error_code, 
-            isf->eax, isf->ebx, isf->ecx, isf->edx, 
-            isf->ebp, isf->esp, isf->esi, isf->edi, 
-            isf->eflags, isf->ds, isf->es, isf->fs, isf->gs
-        );
-
-        abort_task("Unbehandelte Ausnahme.");
-    }
-}
-
-void send_irqs(uint32_t* esp) 
-{
-    uint32_t irq;
-    int task;
-
-    for (irq = 0; irq < 16; irq++)
-    {
-        uint32_t rpc_data = irq + IRQ_BASE;
-        for (task = 0; task < MAX_INTERRUPTS; task++) {
-            if (intr_handling_task[irq + IRQ_BASE][task] == NULL) {
-                continue;
-            }
-            while (irqs_to_send[irq][task] > 0) {
-                schedule_to_task(intr_handling_task[irq + IRQ_BASE][task], esp);
-                if (!fastrpc_irq(intr_handling_task[irq + IRQ_BASE][task], 0, 0, 4,
-                    (char*) &rpc_data, irq))
-                {
-                    //kprintf("SYSCALL_RPC = FALSE");
-                    break;
-                }
-                //kprintf("IRQ-Handler aufgerufen");
-                irqs_to_send[irq][task]--;
-            }
-        }
-    }
-}
diff --git a/src/kernel/src/io.c b/src/kernel/src/io.c
deleted file mode 100644
index de701c87..00000000
--- a/src/kernel/src/io.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*  
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */  
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-#include "types.h"
-#include "tasks.h"
-#include "tss.h"
-#include "kernel.h"
-
-/* Gesetztes Bit: Port wird benutzt */
-uint8_t global_port_bitmap[IO_BITMAP_LENGTH / 8] = { 0 };
-
-void init_io_ports(void)
-{
-    // Setze IO-Privilege-Level auf 0
-    asm volatile(
-        "pushf;"
-        "pop %eax;"
-        "andl $0xFFFFCFFF, %eax;"
-        "push %eax;"
-        "popf;"
-    );
-}
-
-/**
- * Reserviert einen einzelnen IO-Port f�r einen Task
- *
- * @param task Task, dem der Port zugeordnet werden soll
- * @param port Nummer des zuzuordnenden IO-Ports
- *
- * @return Gibt true zur�ck, wenn der Task auf den Port zugreifen kann
- * (erfolgreiche oder bereits vorhandene Reservierung f�r denselben Task),
- * ansonsten false.
- */
-static bool io_port_request(struct task* task, uint32_t port)
-{
-    uint32_t index = port / 8;
-    uint8_t bit = 1 << (port % 8);
-    uint8_t* io_bitmap = task->io_bitmap;
-
-    // Pr�fen, ob der Port �berhaupt von der Bitmap abgedeckt wird
-    if (port >= IO_BITMAP_LENGTH) {
-        return false;
-    }
-
-    // Ist der Port noch frei?
-    // Wenn der Port f�r denselben Task schon einmal reserviert wurde,
-    // abbrechen, aber true zur�ckgeben
-    if (global_port_bitmap[index] & bit) {
-        return (io_bitmap && ((io_bitmap[index] & bit) == 0));
-    }
-
-    // Falls der Task noch keine zugeordnete Bitmap hat, wird es jetzt
-    // Zeit, eine anzulegen
-    if (io_bitmap == NULL) {
-        io_bitmap = task->io_bitmap = malloc(IO_BITMAP_LENGTH / 8);
-        memset(io_bitmap, 0xFF, IO_BITMAP_LENGTH / 8);
-    }
-
-    // Die eigentliche Reservierung
-    global_port_bitmap[index] |= bit;
-    io_bitmap[index] &= ~bit;
-
-    return true;
-}
-
-/**
- * Gibt einen einzelnen IO-Port frei.
- *
- * @param task Task, der die Freigabe anfordert
- * @param port Freizugebender Port
- *
- * @return true, wenn der Port freigegeben werden konnte, false wenn der
- * Port nicht f�r den Task reserviert war.
- */
-static bool io_port_release(struct task* task, uint32_t port)
-{
-    uint32_t index = port / 8;
-    uint8_t bit = 1 << (port % 8);
-    uint8_t* io_bitmap = task->io_bitmap;
-
-    // Wenn der Port gar nicht f�r den Task reserviert ist, false zur�ckgeben
-    if ((!io_bitmap) || (io_bitmap[index] & bit)) {
-        return false;
-    }
-
-    // Wenn der Port zwar f�r den Task reserviert ist, aber in der globalen
-    // Tabelle als frei markiert, haben wir einen Kernel-Bug.
-    if ((global_port_bitmap[index] & bit) == 0) {
-        panic("IO-Port-Bitmaps sind beschaedigt (Port %d, PID %d)", port, task->pid);
-    }
-    
-    // Die eigentliche Freigabe
-    global_port_bitmap[index] &= ~bit;
-    io_bitmap[index] |= bit;
-
-    return true;
-}
-
-/**
- * Reserviert einen Bereich von IO-Ports f�r einen Task.
- * Es werden entweder alle angeforderten oder im Fehlerfall gar keine Ports 
- * reserviert. Eine teilweise Reservierung tritt nicht auf.
- *
- * @param task Task, f�r den die Ports reserviert werden sollen
- * @param port Nummer des niedrigsten zu reservierenden Ports
- * @param length Anzahl der Ports, die zu reservieren sind
- */
-bool io_ports_request(struct task* task, uint32_t port, uint32_t length)
-{
-    uint32_t n = length;
-    while (n--) 
-    {
-        if (!io_port_request(task, port++)) 
-        {
-            // Bereits reservierte Ports wieder freigeben
-            while (++n != length) {
-                io_port_release(task, --port);
-            }
-            return false;
-        }
-    }
-
-    return true;
-}
-
-/**
- * Gibt einen Bereich von Ports frei.
- *
- * @param task Task, der die Freigabe anfordert
- * @param port Niedrigster freizugebender Port
- * @param length Anzahl der freizugebenden Ports
- *
- * @return true, wenn alle Ports freigegeben werden konnten. Wenn ein Port
- * nicht freigegeben werden konnte (war nicht f�r den Task reserviert),
- * wird false zur�ckgegeben, die Bearbeitung allerdings nicht abgebrochen,
- * sondern die weiteren Ports versucht freizugeben.
- */
-bool io_ports_release(struct task* task, uint32_t port, uint32_t length)
-{
-    bool success = true;
-
-    while (length--) 
-    {
-        if (!io_port_release(task, port++)) {
-            success = false;
-        }
-    }
-
-    return success;
-}
-
-/**
- * Gibt alle von einem Task reservierten Ports frei
- *
- * @param task Task, dessen Ports freigegeben werden sollen
- */
-void io_ports_release_all(struct task* task)
-{
-    uint32_t i;
-    uint8_t* io_bitmap = task->io_bitmap;
-
-    if (io_bitmap == NULL) {
-        return;
-    }
-
-    for (i = 0; i < IO_BITMAP_LENGTH / 8; i++)
-    {
-        if (io_bitmap[i] != (uint8_t) -1) {
-            io_ports_release(task, 8*i, 8);
-        }
-    }
-}
-
-void io_ports_check(struct task* task)
-{
-    uint32_t i, j;
-    uint8_t* io_bitmap = task->io_bitmap;
-    uint8_t bit;
-
-    if (io_bitmap == NULL) {
-        return;
-    }
-
-    for (i = 0; i < IO_BITMAP_LENGTH / 8; i++) {
-        for (j = 0; j < 8; j++) {
-            bit = 1 << j;
-            if (((io_bitmap[i] & bit) == 0) && ((global_port_bitmap[i] & bit)
-                == 0))
-            {
-                panic("IO-Port-Bitmaps sind beschaedigt (Port %d, PID %d)",
-                    i * 8 + j, task->pid);
-            }
-        }
-    }
-}
diff --git a/src/kernel/src/kernel.ld b/src/kernel/src/kernel.ld
deleted file mode 100644
index 9efbcb07..00000000
--- a/src/kernel/src/kernel.ld
+++ /dev/null
@@ -1,37 +0,0 @@
-LOAD_ADDR = 0x100000;

-LINK_ADDR = 0x100000;

-VIRT_TO_PHYS = LINK_ADDR - LOAD_ADDR;

-

-ENTRY(_start)

-SECTIONS

-{

-	. = LINK_ADDR;

-

-	kernel_start = .;

-	kernel_phys_start = . - VIRT_TO_PHYS;

-

-	.text : AT(ADDR(.text) - VIRT_TO_PHYS)

-	{

-        *(multiboot)

-		*(.text)

-	}

-	.rodata ALIGN(4096) : AT(ADDR(.rodata) - VIRT_TO_PHYS)

-	{

-		*(.rodata)

-	}

-	.data ALIGN(4096) : AT(ADDR(.data) - VIRT_TO_PHYS)

-	{

-		*(.data)

-	}

-	.bss ALIGN(4096) : AT(ADDR(.bss) - VIRT_TO_PHYS)

-	{

-		*(.bss)

-	}

-

-	. = ALIGN(4096);

-

-	kernel_end = .;

-	kernel_phys_end = . - VIRT_TO_PHYS;

-

-	kernel_size = kernel_end - kernel_start;

-}

diff --git a/src/kernel/src/kprintf.c b/src/kernel/src/kprintf.c
index 1f19541c..d2cea6c5 100644
--- a/src/kernel/src/kprintf.c
+++ b/src/kernel/src/kprintf.c
@@ -33,16 +33,31 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  
+#include <stdint.h>
+#include <stddef.h>
+#include <lost/config.h>
+
+#include "kprintf.h"
 #include "console.h"
+#include "lock.h"
+
+
+static lock_t printf_lock;
 
 /* Dividiert ein uint64 durch einen uint32 und gibt das Ergebnis zur�ck */
 unsigned long long divmod(unsigned long long dividend, unsigned int divisor, unsigned int * remainder)
 {
+#if CONFIG_ARCH == ARCH_AMD64
+    if (remainder) {
+        *remainder = dividend % divisor;
+    }
+    return dividend / divisor;
+#else
     unsigned int highword = dividend >> 32;
     unsigned int lowword = dividend & 0xffffffff;
     unsigned long long quotient;
     unsigned int rem;
-
+    
     __asm__("div %%ecx\n\t"
         "xchg %%ebx, %%eax\n\t"
         "div %%ecx\n\t"
@@ -51,16 +66,16 @@ unsigned long long divmod(unsigned long long dividend, unsigned int divisor, uns
         : "a"(highword), "b"(lowword), "c"(divisor), "d"(0)
         );
 
-    if(remainder)
-    {
+    if (remainder) {
         *remainder = rem;
     }
 
     return quotient;
+#endif
 }
 
 /* Gibt eine unsigned 64-bit Zahl mit beliebiger Basis zwischen 2 und 36 aus */
-static void kputn(unsigned long long x, int radix, int pad, char padchar)
+/*static*/ void kputn(unsigned long long x, int radix, int pad, char padchar)
 {
     char b[65];
     char * r = b + 64; // r zeig auf das letzte Zeichen von b[]
@@ -91,11 +106,11 @@ static void kputn(unsigned long long x, int radix, int pad, char padchar)
 }
 
 /* Hilfsfunktion f�r kprintf() */
-void kaprintf(const char * format, int ** args)
+void kaprintf(char* format, va_list args)
 {
     int pad;
     char padfill;
-    signed long long value = 0;
+    unsigned long long value = 0;
 
     while(*format)
     {
@@ -119,27 +134,57 @@ void kaprintf(const char * format, int ** args)
                 pad = pad * 10 + *format++ - '0';
             }
 
-            if(format[0] == 'l' && format[1] == 'l' && (format[2] == 'd' || format[2] == 'i' || format[2] == 'o' || format[2] == 'u' || format[2] == 'x'))
+            if(format[0] == 'l' && format[1] == 'l' && (format[2] == 'd' || format[2] == 'i'))
             {
-                value = *(unsigned long long*)(*args);
-                *args += 2;
-
+                signed long long tmp = va_arg(args, long long int);
+                if (tmp < 0) {
+                    con_putc_ansi('-');
+                    pad--;
+                    value = -tmp;
+                } else {
+                    value = tmp;
+                }
+                format += 2;
+            }
+            else if(format[0] == 'l' && format[1] == 'l' && (format[2] == 'o' || format[2] == 'u' || format[2] == 'x'))
+            {
+                value = va_arg(args, unsigned long long int);
                 format += 2;
             }
-            else if(format[0] == 'd' || format[0] == 'u')
+            else if(format[0] == 'l' && (format[1] == 'd' || format[1] == 'i'))
             {
-                value = *(*args)++;
-                if(value < 0)
-                {
+                signed long int tmp = va_arg(args, long int);
+                if(tmp < 0) {
                     con_putc_ansi('-');
                     pad--;
-                    value = -value;
+                    value = -tmp;
+                } else {
+                    value = tmp;
                 }
+                format++;
+            } else if(format[0] == 'z' && (format[1] == 'u' || format[1] == 'x')) {
+                value = va_arg(args, size_t);
+                format++;
             }
-            else if(format[0] == 'i' || format[0] == 'o' || format[0] == 'p' || format[0] == 'x')
+            else if(format[0] == 'l' && (format[1] == 'o' || format[1] == 'u' || format[1] == 'x'))
             {
-                value = *(*args)++;
-                value = value & 0xffffffff;
+                value = va_arg(args, unsigned long int);
+                format++;
+            }
+            else if(format[0] == 'd' || format[0] == 'i')
+            {
+                int tmp = va_arg(args, int);
+                if(tmp < 0) {
+                    con_putc_ansi('-');
+                    pad--;
+                    value = -tmp;
+                } else {
+                    value = tmp;
+                }
+            } else if(format[0] == 'u' || format[0] == 'o' || format[0] == 'x') {
+                value = va_arg(args, unsigned int);
+            } else if(format[0] == 'p') {
+                value = va_arg(args, uintptr_t);
             }
 
             switch(*format)
@@ -150,7 +195,8 @@ void kaprintf(const char * format, int ** args)
                     con_putc_ansi('%');
                     break;
                 case 'c':
-                    con_putc_ansi(*(*args)++);
+                    //con_putc_ansi(*(*args)++);
+                    con_putc(va_arg(args, int));
                     break;
                 case 'd':
                 case 'i':
@@ -171,7 +217,8 @@ void kaprintf(const char * format, int ** args)
                     kaprintf(format2, args);
                     break;*/
                 case 's':
-                    con_puts((char*)*(*args)++);
+                    //con_puts((char*)*(*args)++);
+                    con_puts(va_arg(args, char*));
                     break;
                 default:
                     con_putc_ansi('%');
@@ -190,18 +237,30 @@ void kaprintf(const char * format, int ** args)
 }
 
 /* printf für den Kernel. Nur für Testzwecke gedacht.
- Unterstützt %c, %d, %i, %o, %p, %u, %s, %x und %lld, %lli, %llo, %llu, %llx. */
-void kprintf(char * format, ...)
+ Unterstützt %c, %d, %i, %o, %p, %u, %s, %x und %lld, %lli, %llo, %llu, %llx, %zu, %zx. */
+void kprintf(char* format, ...)
 {
-    int * args = ((int*)&format) + 1;
-    kaprintf(format, &args);
+    lock(&printf_lock);
+    
+    va_list args;
+    
+    va_start(args,format);
+    kaprintf(format, args);
+    va_end(args);
+
+    unlock(&printf_lock);
 }
 
-int printf(const char * format, ...)
+int printf(const char* format, ...)
 {
-    int * args = ((int*)&format) + 1;
-    kaprintf(format, &args);
-
+    lock(&printf_lock);
+    
+    va_list args;
+    va_start(args,format);
+    kaprintf((char*) format, args);
+    va_end(args);
+    
+    unlock(&printf_lock);
     return 0; // TODO Korrekte printf-R�ckgabe
 }
 
diff --git a/src/kernel/src/liballoc.c b/src/kernel/src/liballoc.c
deleted file mode 100644
index 50300b23..00000000
--- a/src/kernel/src/liballoc.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2013 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS 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.
- */
-
-int __liballoc_lock(void)
-{
-	return 0;
-}
-
-int __liballoc_unlock(void)
-{
-	return 0;
-}
diff --git a/src/kernel2/src/libc_helper.c b/src/kernel/src/libc_helper.c
similarity index 100%
rename from src/kernel2/src/libc_helper.c
rename to src/kernel/src/libc_helper.c
diff --git a/src/kernel2/src/lostio/client.c b/src/kernel/src/lostio/client.c
similarity index 100%
rename from src/kernel2/src/lostio/client.c
rename to src/kernel/src/lostio/client.c
diff --git a/src/kernel2/src/lostio/include/lostio_int.h b/src/kernel/src/lostio/include/lostio_int.h
similarity index 100%
rename from src/kernel2/src/lostio/include/lostio_int.h
rename to src/kernel/src/lostio/include/lostio_int.h
diff --git a/src/kernel2/src/lostio/lostio.c b/src/kernel/src/lostio/lostio.c
similarity index 100%
rename from src/kernel2/src/lostio/lostio.c
rename to src/kernel/src/lostio/lostio.c
diff --git a/src/kernel2/src/lostio/modules/file.c b/src/kernel/src/lostio/modules/file.c
similarity index 100%
rename from src/kernel2/src/lostio/modules/file.c
rename to src/kernel/src/lostio/modules/file.c
diff --git a/src/kernel2/src/lostio/modules/tmp.c b/src/kernel/src/lostio/modules/tmp.c
similarity index 100%
rename from src/kernel2/src/lostio/modules/tmp.c
rename to src/kernel/src/lostio/modules/tmp.c
diff --git a/src/kernel2/src/lostio/pipes.c b/src/kernel/src/lostio/pipes.c
similarity index 100%
rename from src/kernel2/src/lostio/pipes.c
rename to src/kernel/src/lostio/pipes.c
diff --git a/src/kernel2/src/lostio/tree.c b/src/kernel/src/lostio/tree.c
similarity index 100%
rename from src/kernel2/src/lostio/tree.c
rename to src/kernel/src/lostio/tree.c
diff --git a/src/kernel2/src/lostio/userspace.c b/src/kernel/src/lostio/userspace.c
similarity index 100%
rename from src/kernel2/src/lostio/userspace.c
rename to src/kernel/src/lostio/userspace.c
diff --git a/src/kernel/src/mm/Makefile.all b/src/kernel/src/mm/Makefile.all
deleted file mode 100644
index e9b03f45..00000000
--- a/src/kernel/src/mm/Makefile.all
+++ /dev/null
@@ -1 +0,0 @@
-cp *.o ..
diff --git a/src/kernel/src/mm/kmm.c b/src/kernel/src/mm/kmm.c
deleted file mode 100644
index 365df7a2..00000000
--- a/src/kernel/src/mm/kmm.c
+++ /dev/null
@@ -1,348 +0,0 @@
-/*

- * Copyright (c) 2006 The tyndur Project. All rights reserved.

- *

- * This code is derived from software contributed to the tyndur Project

- * by Burkhard Weseloh.

- *

- * Redistribution and use in source and binary forms, with or without

- * modification, are permitted provided that the following conditions

- * are met:

- * 1. Redistributions of source code must retain the above copyright

- *    notice, this list of conditions and the following disclaimer.

- * 2. 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.

- * 3. All advertising materials mentioning features or use of this software

- *    must display the following acknowledgement:

- *     This product includes software developed by the tyndur Project

- *     and its contributors.

- * 4. Neither the name of the tyndur Project nor the names of its

- *    contributors may be used to endorse or promote products derived

- *    from this software without specific prior written permission.

- *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

- * ``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 COPYRIGHT HOLDERS OR

- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,

- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,

- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;

- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,

- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR

- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF

- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

- */

-

-#include "kernel.h"

-#include "paging.h"

-#include "string.h"

-#include "types.h"

-

-

-/**

- * Mappt Speicher 1:1 in den Kernel Adressraum. Kein page alignment erforderlich.

- */

-bool kernel_identity_map(paddr_t paddr, uint32_t bytes)

-{

-    uint32_t aligned_addr = (uint32_t)paddr - ((uint32_t)paddr & ~PAGE_MASK);

-    uint32_t aligned_bytes = bytes + (uint32_t)paddr -

-        ((uint32_t)paddr & PAGE_MASK);

-

-    return map_page_range(kernel_page_directory, (vaddr_t)aligned_addr, (paddr_t)aligned_addr, PTE_W | PTE_P /*| PTE_U*/, NUM_PAGES(aligned_bytes));

-}

-

-// Der Teil des Page Directorys, der den Kernelraum mappt und f�r alle Prozesse gleich ist

-#define kernel_page_tables \

-    ((uint32_t*)(kernel_page_directory + (KERNEL_BASE >> PGDIR_SHIFT)))

-extern page_directory_t kernel_page_directory;

-extern uint32_t kernel_pd_id;

-

-/**

- * Errechnet die virtuelle Adresse der Page Table, die zur Adresse addr geh�rt.

- */

-static page_table_t get_kernel_page_table_addr(uint32_t addr)

-{

-    if(addr < KERNEL_BASE)

-    {

-        /* TODO: Ein panic mit (einem noch zu schreibenden) BUG()-Makro k�nnte hier angebrachter sein */

-        panic("addr(%x) < KERNEL_BASE", addr);

-    }

-

-    return (page_table_t)(KERNEL_PAGE_TABLES_VADDR + (((addr - KERNEL_BASE) >> PGDIR_SHIFT) << PAGE_SHIFT));

-}

-

-/**

- * Mappt eine Page Table in die Kernel Page Tables

- *

- * @param pgdir_index Index in das Page Directory. Die 4 MB an der virtuellen

- *    Adresse (pgdir_index << PGDIR_SHIFT) werden von dieser Page Table gemappt.

- * @param addr Physische Adresse der Page Table, die gemappt werden soll

- */

-static void map_kernel_page_table(int pgdir_index, uint32_t addr)

-{

-    // Da alle Page Tables mit (pgdir_index << PGDIR_SHIFT) >= KERNEL_BASE in

-    // die Gegend nach KERNEL_PAGE_TABLES_VADDR gemappt werden, m�ssen wir die

-    // dazugeh�rige Page Table finden.

-    page_table_t page_table = get_kernel_page_table_addr(KERNEL_PAGE_TABLES_VADDR);

-

-    // Jede Page Table ist genau 4KB gro�, also wird sie mit genau einem Eintrag

-    // in der Page Table der Kernel Page Tables gemappt.

-    page_table[pgdir_index] = (addr & PAGE_MASK) | PTE_W | PTE_P;

-

-    asm volatile("invlpg %0" : : "m" (*page_table));

-}

-

-/**

- * Wandelt eine virtuelle Adresse >= KERNEL_BASE in eine physische

- * Adresse um.

- */

-/*static*/ paddr_t kernel_virt_to_phys(uint32_t vaddr)

-{

-    // Die Page Table f�r diese virtuelle Adresse ermitteln ...

-    page_table_t page_table = get_kernel_page_table_addr(vaddr);

-

-    // ... und auslesen.

-    return (paddr_t)(page_table[(vaddr >> PAGE_SHIFT) & 0x3ff] & PAGE_MASK);

-}

-

-/**

- * Gibt eine Seite (4 KBytes) im Kernel-Adressraum frei.

- */

-void free_kernel_page(vaddr_t page)

-{

-    uint32_t addr = (uint32_t)page;

-    page_table_t page_table;

-    

-    if(addr < KERNEL_BASE)

-    {

-        /* TODO: Ein panic mit (einem noch zu schreibenden) BUG()-Makro k�nnte hier angebrachter sein */

-        panic("Es wurde versucht eine Seite ausserhalb des Kernelraums freizugeben.");

-    }

-

-    // Die physische Seite vor der virtuellen freigeben, weil sonst kernel_virt_to_phys() nicht mehr funktioniert.

-    phys_free_page(kernel_virt_to_phys(addr));

-

-    // Das Mapping aufheben, und die virtuelle Seite somit freigeben.

-    page_table = get_kernel_page_table_addr(addr);

-    page_table[(addr >> PAGE_SHIFT) & 0x3ff] = 0;

-}

-

-/**

- * Findet einen freien Bereich mit num freien Seiten im Kernel-Adressraum.

- *

- * @return Die erste Seite dieses Bereiches

- */

-vaddr_t find_contiguous_kernel_pages(int num)

-{

-    int i, j;

-    int pgdir_index, pgtbl_index;

-    int num_free_pages;

-    page_table_t page_table;

-    

-    num_free_pages = 0;

-    pgdir_index = 0;

-    pgtbl_index = 0;

-

-    for(i = 0; i < NUM_KERNEL_PAGE_TABLES; i++)

-    {

-        if(num_free_pages == 0)

-        {

-            // Dieser Eintrag im Page Directory w�re der erste von unseren Pages

-            pgdir_index = i;

-        }

-

-        if(kernel_page_tables[i] & PTE_P)

-        {

-            // Die virtuelle Adresse der passenden Page Table errechnen

-            page_table = (page_table_t)(KERNEL_PAGE_TABLES_VADDR + (i << PAGE_SHIFT));

-           

-            // Die NULL-Page bleibt grunds�tzlich ungemappt, daher wird bei der ersten

-            // Page Table erst beim zweiten Eintrag mit Suchen angefangen

-            for(j = (i == 0 ? 1 : 0); j < PAGE_TABLE_LENGTH; j++)

-            {

-                if(!(page_table[j] & PTE_P))

-                {

-            

-                    if(num_free_pages == 0)

-                    {

-                        pgtbl_index = j;

-                    }

-

-                    num_free_pages++;

-

-                    if(num_free_pages >= num)

-                    {

-                        // Wenn wir genug freie Seiten gefunden haben, die Suche beenden

-                        break;

-                    }

-                }

-                else

-                {

-                    // Eine belegte Page ist uns dazwischen gekommen, und wir m�ssen mit unserer Suche von vorne anfangen

-                    num_free_pages = 0;

-                }

-            }

-        }

-        else

-        {

-            // Diese Page Table ist zwar nicht vorhanden, aber wir k�nnen trotzdem mit ihr rechnen

-

-            if(i == 0)

-            {

-                // Die NULL-Page wird freigehalten, daher muss hier

-                // eins von der theoretischen Maximalzahl abgezogen

-                // werden

-                pgtbl_index = 1;

-                num_free_pages += PAGE_TABLE_LENGTH - 1;

-            }

-            else

-            {

-                if(num_free_pages == 0)

-                {

-                    // Diese Page w�re die erste von unseren Pages.

-                    pgtbl_index = 0;

-                }

-

-                num_free_pages += PAGE_TABLE_LENGTH;

-            }

-        }

-

-        if(num_free_pages >= num)

-        {

-            // Wenn wir genug freie Seiten gefunden haben, die Suche beenden

-            break;

-        }

-    }

-    

-    if(num_free_pages == 0)

-    {

-        panic("Nicht genug Speicher.");

-    }

-

-    return (vaddr_t)(KERNEL_BASE + (pgdir_index << PGDIR_SHIFT) + (pgtbl_index << PAGE_SHIFT));

-}

-

-/**

- * Allokiert num_pages Seiten im Kernel-Adressraum. 

- *

- * @return Die Adresse der ersten Seite

- */

-vaddr_t alloc_kernel_pages(int num)

-{

-    int i, j;

-    int pgdir_index, pgtbl_index;

-    page_table_t page_table;

-    vaddr_t vaddr;

-    

-    vaddr = find_contiguous_kernel_pages(num);

-    

-    pgdir_index = ((uint32_t)vaddr - KERNEL_BASE) >> PGDIR_SHIFT;

-    pgtbl_index = (((uint32_t)vaddr - KERNEL_BASE) >> PAGE_SHIFT) % PAGE_TABLE_LENGTH;

-

-    for(i = pgdir_index; num; i++)

-    {

-        if(!(kernel_page_tables[i] & PTE_P))
-        {
-            // Eine neue Page Table muss angelegt werden
-            kernel_page_tables[i] = phys_alloc_page() | PTE_W | PTE_P;
-            map_kernel_page_table(i, kernel_page_tables[i]);
-            page_table = (page_table_t)(KERNEL_PAGE_TABLES_VADDR + (i << PAGE_SHIFT));
-
-            // Page Table mit Nullen initialisieren

-            memset(page_table, 0, PAGE_SIZE);
-

-            kernel_pd_id++;

-        }

-        else

-        {

-            // Wir verwenden eine bereits vorhandene Page Table

-            page_table = (page_table_t)(KERNEL_PAGE_TABLES_VADDR + (i << PAGE_SHIFT)); 

-        }

-
-        for(j = (i == pgdir_index) ? pgtbl_index : 0; j < PAGE_TABLE_LENGTH && num; j++, num--)
-        {
-            page_table[j] = phys_alloc_page() | PTE_W | PTE_P;
-            asm volatile("invlpg %0"
-                : : "m" (*(char*)((i * PAGE_TABLE_LENGTH + j) * PAGE_SIZE))
-                : "memory");
-        }

-    }

-

-    return vaddr;

-}

-

-/**

- * Gibt num_pages Seiten beginnend mit der Adresse first_page im

- * Kernel-Adressraum frei.

- */

-void free_kernel_pages(vaddr_t first_page, int num_pages)

-{

-    int i;

-    

-    for(i = 0; i < num_pages; i++)

-    {

-        free_kernel_page((vaddr_t)((uint32_t)first_page + i * PAGE_SIZE));

-    }

-}

-

-

-/**

- * Mapt den physikalische Adressbereich irgendwo hin, und gibt einen Pointer 

- * darauf zurueck.

- * @param addr Adresse

- * @param size Groesse des Speicherbereichs

- * @return Pointer auf gemapte stelle

- */

-vaddr_t map_phys_addr(paddr_t paddr, size_t size)

-{

-    // FIXME Diese Funktion sollte nicht auf kernel_page_directory arbeiten, 

-    // sondern auf dem aktuellen PD.

-    uint32_t aligned_addr = (uint32_t)paddr - ((uint32_t)paddr & ~PAGE_MASK);

-    uint32_t aligned_bytes = size + (uint32_t)paddr -

-        ((uint32_t)paddr & PAGE_MASK);

-    

-    vaddr_t vaddr = find_contiguous_kernel_pages(NUM_PAGES(aligned_bytes));

-    if (vaddr == NULL) {

-        panic("map_phys_addr(0x%08x, 0x%x): vaddr == NULL\n", paddr, size);

-        return NULL;

-    }

-    

-    if(!map_page_range(kernel_page_directory, vaddr, (paddr_t)aligned_addr, PTE_W | PTE_P /*| PTE_U*/, NUM_PAGES(aligned_bytes))) {

-        panic("map_phys_addr(0x%08x, 0x%x): map_page_rang fehlgeschlagen\n", paddr, size);

-        return NULL;

-    }

-    

-    return (vaddr_t)((uint32_t)vaddr + ((uint32_t)paddr & ~PAGE_MASK));

-}

-

-

-/**

- * Free dem physikalische Adressbereich

- * @param addr Adresse

- * @param size Groesse des Speicherbereichs

- */

-void free_phys_addr(vaddr_t vaddr, size_t size)

-{

-    uint32_t aligned_addr = (uint32_t)vaddr - ((uint32_t)vaddr & ~PAGE_MASK);

-    uint32_t aligned_bytes = size + (uint32_t)vaddr -

-        ((uint32_t)vaddr & PAGE_MASK);

-    

-    

-    map_page_range(kernel_page_directory, (vaddr_t) aligned_addr, (paddr_t)0, 0, NUM_PAGES(aligned_bytes));

-}

-

-/**

- * Dient nur als Wrapper fuer malloc()

- */

-void* mem_allocate(uint32_t size, uint32_t flags)

-{

-    return alloc_kernel_pages(PAGE_ALIGN_ROUND_UP(size) >> 12);

-}

-

-/**

- * Dient nur als Wrapper fuer malloc()

- */

-void mem_free(void* address, uint32_t size)

-{

-    free_kernel_pages(address, PAGE_ALIGN_ROUND_UP(size) >> 12);

-}

diff --git a/src/kernel/src/mm/paging.c b/src/kernel/src/mm/paging.c
deleted file mode 100644
index 48f9b7ee..00000000
--- a/src/kernel/src/mm/paging.c
+++ /dev/null
@@ -1,476 +0,0 @@
-/*  
- * Copyright (c) 2006 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */  
-
-#include <stdint.h>
-#include <stdbool.h>
-
-#include "kernel.h"
-#include "string.h"
-#include "vmm.h"
-#include "paging.h"
-#include "kmm.h"
-#include "tasks.h"
-#include "kprintf.h"
-
-
-extern unsigned long * phys_mmap;
-extern unsigned long phys_mmap_size;
-
-bool map_page(page_directory_t page_directory, vaddr_t vaddr, paddr_t paddr, int flags);
-bool map_page_range(page_directory_t page_directory, vaddr_t vaddr, paddr_t paddr, int flags, int num_pages);
-
-page_directory_t kernel_page_directory;
-uint32_t kernel_pd_id = 0;
-
-/**
- * Wenn true, werden Page Tables nicht �ber ihre virtuelle Adresse
- * angesprochen, sondern �ber die physische. In diesem Fall mu� daf�r
- * gesorgt sein, da� die Page Table auch unter dieser Adresse zugreifbar
- * ist (z.B. solange Paging nicht aktiviert ist oder per Identity Mapping)
- *
- * Im normalen Betrieb sollte use_phys_page_tables false sein.
- */
-bool use_phys_page_tables;
-
-
-// TODO: PTE_U wird momentan sehr gro�z�gig vergeben, das sollte sich
-// irgendwann noch �ndern.
-    
-/**
- * Initialisiert die virtuelle Speicherverwaltung. Insbesondere wird ein
- * Page Directory fuer den Kernel angelegt und geladen.
- *
- * Die physische Speicherverwaltung muss dazu bereits initialisiert sein.
- */
-void init_paging(void)
-{
-    use_phys_page_tables = true;
-
-
-    // Ein Page Directory anlegen und initialisieren
-    kernel_page_directory = (unsigned long*) phys_alloc_page_limit(0x1000);
-    memset(kernel_page_directory, 0, PAGE_SIZE);
-
-
-    /* Kernel Page Tables mappen */
-    kernel_page_directory[KERNEL_PAGE_TABLES_VADDR >> PGDIR_SHIFT] = 
-        (uint32_t) kernel_page_directory | PTE_W | PTE_P;
-
-    // Den Kernel mappen
-    map_page_range(kernel_page_directory, kernel_start, (paddr_t) kernel_phys_start,
-        PTE_W | PTE_P /*| PTE_U*/, ((uint32_t)kernel_end - (uint32_t)kernel_start) / PAGE_SIZE);
-
-    // Videospeicher mappen
-    map_page_range(kernel_page_directory, (vaddr_t) 0xB8000, (paddr_t)0xB8000, PTE_W | PTE_P /*| PTE_U*/, ((25*80*2) / PAGE_SIZE) + 1);
-    
-    /* Das Page Directory mappen */
-    map_page(kernel_page_directory, kernel_page_directory, (paddr_t)kernel_page_directory, PTE_P | PTE_W);
-    
-    // Bitmap mit dem physischen Speicher mappen.
-    map_page_range(kernel_page_directory, phys_mmap, (paddr_t)phys_mmap, PTE_W | PTE_P,
-        (sizeof(uint32_t) * phys_mmap_size + PAGE_SIZE - 1) / PAGE_SIZE);
-
-    __asm__(
-        
-        // Page directory laden
-        "movl %0, %%cr3\n\t"
-
-        // Paging aktivieren
-        "mov %%cr0, %%eax\n\t"
-        "or $0x80000000, %%eax\n\t"
-        "mov %%eax, %%cr0\n\t"
-        
-    : : "r"(kernel_page_directory) : "eax");
-    
-    use_phys_page_tables = false;
-}
-
-
-/**
- * Mappt mehrere zusammenh�ngende virtuelle Seiten auf einen physischen
- * Speicherbereich. Beide Adressen muessen dazu 4K-aligned sein.
- *
- * @param page_directory Page Directory, auf das sich die virtuelle 
- *    Adresse bezieht
- *
- * @param vaddr Virtuelle Speicheradresse der ersten Page
- * @param paddr Physische Speicheradresse der ersten Page
- * @param flags Flags, die in der Page Table gesetzt werden sollen
- * @param num Anzahl der Seiten
- * 
- * @return true, wenn der bereich erfolgreich gemappt werden konnte, 
- *    false sonst
- */
-bool map_page_range(page_directory_t page_directory, vaddr_t vaddr, paddr_t paddr, int flags, int num_pages) 
-{
-    int i;
-    vaddr_t va;
-    paddr_t pa;
-
-    for(i = 0; i < num_pages; i++)
-    {
-        va = (vaddr_t)((uint32_t)vaddr + i * PAGE_SIZE);
-        pa = (paddr_t)((uint32_t)paddr + i * PAGE_SIZE);
-
-        if(map_page(page_directory, va, pa, flags) != true)
-        {
-            /* TODO: Das bereits geschehene Mapping r�ckg�ngig machen */
-            return false;
-        }
-    }
-
-    return true;
-}
-
-/**
- * Mappt eine virtuelle Adresse auf eine physische.
- * Beide Adressen muessen dazu 4K-aligned sein.
- *
- * @param page_directory Page Directory, auf das sich die virtuelle 
- *    Adresse bezieht
- *
- * @param vaddr Virtuelle Speicheradresse
- * @param paddr Physische Speicheradresse
- * @param flags Flags, die in der Page Table gesetzt werden sollen
- * 
- * @return true, wenn die virtuelle Seite erfolgreich gemappt werden konnte, 
- *    false sonst
- */
-bool map_page(page_directory_t page_directory, vaddr_t vaddr, paddr_t paddr, int flags) 
-{
-    page_table_t page_table;
-    
-    uint32_t vpage = (uint32_t) vaddr / PAGE_SIZE;
-
-    //kprintf("map_page %x => %x\n", vaddr, paddr);
-
-    // Die NULL-Page bleibt ungemappt
-    if (vaddr == NULL) {
-        panic("Versuchtes Mapping nach virtuell NULL");
-        return false;
-    }
-  
-    if (flags & ~0x01F) {
-        // Boese Flags wollen die Adresse manipulieren.
-        // Fliegt das entsprechende Programm eben beim naechsten Zugriff
-        // auf die Schnauze.
-        
-        return false;
-    }
-
-    if (((uint32_t) vaddr | (uint32_t) paddr) & 0xfff) {
-        panic("Adressen sind nicht 4K-aligned (virt = %x, phys = %x)", vaddr, paddr);
-    }
-
-    // Wenn es noch keine passende Pagetable gibt, muss eine neue her,
-    // ansonsten nehmen wir diese. Und wenn es sich bei dem Eintrag
-    // um eine 4M-Seite handelt, laeuft was schief.
-    if ((page_directory[vpage / PAGE_TABLE_LENGTH] & PTE_P) == 0) {
-        page_table = (page_table_t) phys_alloc_page();
-        
-        page_directory[vpage / PAGE_TABLE_LENGTH] = ((uint32_t) page_table) | flags | PTE_U;
-        
-        if (page_directory == kernel_page_directory) {
-            if (!use_phys_page_tables) {
-                page_table = (page_table_t) (KERNEL_PAGE_TABLES_VADDR + ((sizeof(uint32_t)*vpage) & ~0xfff));
-            }
-        } else {
-            // Die Page Table geh�rt nicht zum Kernel - folglich sollte man nicht direkt auf
-            // ihre Adresse zugreifen, wenn man nicht gerade einen Page Fault ausl�sen will.
-            // Die Page Table muss daher zun�chst in den Kerneladressraum gemappt werden.
-            vaddr_t kernel_page_table = find_contiguous_kernel_pages(1);
-            map_page(kernel_page_directory, kernel_page_table, (paddr_t) page_table, PTE_P | PTE_W);
-            
-            /* 
-            kprintf("Mappe PT in Kerneladressraum; neue PT\n");
-            kprintf("PD = %x\n", page_directory);
-            kprintf("PT Kernel vaddr = %x, paddr = %x\n", kernel_page_table, page_table);
-            */
-
-            page_table = kernel_page_table;
-        }
-
-        if (vaddr < (vaddr_t) 0x40000000) {
-            kernel_pd_id++;
-        }
-        
-        memset(page_table, 0, PAGE_SIZE);
-        
-    } else if (page_directory[vpage / PAGE_TABLE_LENGTH] & PTE_PS) {
-        panic("Doppelbelegung im Page Directory.");
-    } else {
-        if (page_directory == kernel_page_directory) {
-            if (use_phys_page_tables) {
-                page_table = (page_table_t) (page_directory[vpage / PAGE_TABLE_LENGTH] & ~0xFFF);
-            } else {
-                page_table = (page_table_t) (KERNEL_PAGE_TABLES_VADDR + ((sizeof(uint32_t)*vpage) & ~0xfff));
-            }
-        } else {
-            page_table = (page_table_t) (page_directory[vpage / PAGE_TABLE_LENGTH] & ~0xFFF);
-            
-            // Die Page Table geh�rt nicht zum Kernel - folglich sollte man nicht direkt auf
-            // ihre Adresse zugreifen, wenn man nicht gerade einen Page Fault ausl�sen will.
-            // Die Page Table muss daher zun�chst in den Kerneladressraum gemappt werden.
-            
-            vaddr_t kernel_page_table = find_contiguous_kernel_pages(1);
-            map_page(kernel_page_directory, kernel_page_table, (paddr_t) page_table, PTE_P | PTE_W);
-            page_table = kernel_page_table;
-        }
-    }
-    
-    // Wenn der Eintrag in der Pagetable noch nicht gesetzt ist, setzen.
-    // Ansonsten stehen wir vor einer Doppelbelegung.
-    //
-    // Wenn genau dasselbe Mapping doppelt gemacht wird, wird dar�ber hinweggesehen
-    //
-    // Und wenn das Mapping aufgehoben werden soll, sollte man sich auch nicht dar�ber
-    // beschweren, dass der Eintrag schon besteht.
-    if ((page_table[vpage % PAGE_TABLE_LENGTH] & PTE_P) && ((page_table[vpage % PAGE_TABLE_LENGTH] & ~(PTE_A | PTE_D)) != (((uint32_t) paddr) | flags)) && (flags & PTE_P)) {
-        panic("Doppelbelegung in einer Page Table.");
-        return false;
-    } else {
-        page_table[vpage % PAGE_TABLE_LENGTH] = ((uint32_t) paddr) | flags;
-
-        if (page_directory != kernel_page_directory) {
-            // Falls wir die Page Table extra in den Kerneladressraum gemappt haben,
-            // den Speicher wieder freigeben
-            unmap_page(kernel_page_directory, page_table);
-        }
-        // Und falls es um das aktive Page Directory geht, w�re jetzt ein
-        // guter Zeitpunkt, den TLB zu invalidieren.
-        // FIXME: Im moment auch wenn es sich nicht um das aktuelle PD handelt,
-        // aber das sauber zu machen ist zu aufwaendig, da kernel eh ersetzt
-        // wird.
-        __asm__ __volatile__("invlpg %0" : : "m" (* (char*) vaddr));
-
-        return true;
-    }
-    
-}
-
-/**
- * Entfernt das Mapping einer virtuellen Adresse.
- *
- * @param page_directory Page Directory, auf das sich die virtuelle 
- *    Adresse bezieht
- * @param vaddr Virtuelle Speicheradresse
- * 
- * @return true, wenn die virtuelle Seite erfolgreich ungemappt werden konnte, 
- *    false sonst
- */
-bool unmap_page(page_directory_t page_directory, vaddr_t vaddr) 
-{
-    return map_page(page_directory, vaddr, (paddr_t) NULL, 0);
-}
-
-/**
- * Gibt den Pagetable-Eintrag zu einer gegebenen virtuellen Speicheradresse
- * zurueck.
- *
- * @param page_directory Page Directory, auf das sich die Adresse bezieht
- * @param vaddr Aufzuloesende virtuelle Adresse
- *
- * @return Pagetable-Eintrag der 4K-Seite, zu der die gegebene virtuelle
- * Adresse gehoert. 0, wenn die Adresse nicht in einer Seite liegt, die
- * present ist.
- */
-static uint32_t get_pagetable_entry
-    (page_directory_t page_directory, vaddr_t vaddr)
-{
-    page_table_t page_table;
-    paddr_t phys_page_table;
-    uint32_t result;
-    
-    uint32_t vpage = (uint32_t) vaddr / PAGE_SIZE;
-    //kprintf("[Resolv: %x in PD %x]", vaddr, page_directory);
-
-    // Passende Page Table suchen
-    // Bei einer 4M-Page sind wir eigentlich schon am Ziel
-    if ((page_directory[vpage / PAGE_TABLE_LENGTH] & PTE_P) == 0) {
-        return 0;
-    } else if (page_directory[vpage / PAGE_TABLE_LENGTH] & PTE_PS) {
-        return page_directory[vpage / PAGE_TABLE_LENGTH];
-    } else {
-        phys_page_table = (paddr_t)
-            (page_directory[vpage / PAGE_TABLE_LENGTH] & ~0xFFF);
-    }
-        
-    // Die Page-Table-Adresse ist eine physische Adresse. Am sichersten ist es,
-    // die Adresse einfach noch einmal zu mappen.
-    page_table = map_phys_addr(phys_page_table, PAGE_SIZE);
-    
-    // Adresse zusammenbasteln und fertig
-    if (page_table[vpage % PAGE_TABLE_LENGTH] & PTE_P) {
-        result = page_table[vpage % PAGE_TABLE_LENGTH]; 
-    } else {
-        result = 0;
-    }
-        
-    // Falls wir die Page Table extra in den Kerneladressraum gemappt haben,
-    // den Speicher wieder freigeben
-    unmap_page(kernel_page_directory, page_table);
-
-    return result;
-}
-
-/**
- * Loest eine virtuelle Adresse bezueglich eines Page Directory
- * in eine physische Adresse auf.
- *
- * @return Physische Adresse oder NULL, wenn die Page nicht vorhanden ist
- */
-paddr_t resolve_vaddr(page_directory_t page_directory, vaddr_t vaddr)
-{
-    uint32_t pte = get_pagetable_entry(page_directory, vaddr);
-    
-    if ((pte & PTE_P) == 0) {
-        return (paddr_t) NULL;
-    }
-
-    if ((pte & PTE_PS) == 0) {
-        return (paddr_t) ((pte & ~0xFFF) | ((uint32_t) vaddr & 0xFFF));
-    } else {
-        return (paddr_t) ((pte & ~0x3FFFFF) | ((uint32_t) vaddr & 0x3FFFFF));
-    }
-}
-
-/**
- * Prueft, ob ein Speicherbereich im Page Directory des aktuellen Tasks
- * komplett gemappt ist und PTE_U (Zugriffsrecht fuer Usermode) gesetzt hat.
- */
-bool is_userspace(vaddr_t start, uint32_t len)
-{
-    vaddr_t cur;
-
-    if (start + len < start) {
-        return false;
-    }    
-    
-    for (cur = start; 
-        (cur < start + len) && (cur > (vaddr_t) 0xFFF); 
-        cur += PAGE_SIZE) 
-    {
-        uint32_t pte = get_pagetable_entry(current_task->cr3, cur);
-        if ((pte == 0) || !(pte & PTE_U)) {
-            return false;
-        }
-    }
-
-    return true;
-}
-
-
-/**
- * Findet einen freien Bereich mit num freien Seiten
- *
- * @return Die Anfangsadresse der ersten Seite dieses Bereiches
- */
-vaddr_t find_contiguous_pages(page_directory_t page_directory, int num, uint32_t lower_limit, uint32_t upper_limit)
-{
-    uint32_t free_pages = 0;
-    uint32_t cur_page;
-    uint32_t cur_page_table;
-
-    // Die NULL-Page bleibt ungemappt
-    if (lower_limit < PAGE_SIZE) {
-        lower_limit = PAGE_SIZE;
-    }
-
-    cur_page = (lower_limit >> PAGE_SHIFT) % PAGE_TABLE_LENGTH;
-    cur_page_table = (lower_limit >> PGDIR_SHIFT);
-
-    while ((free_pages < num) && ((cur_page_table << PGDIR_SHIFT) < upper_limit)) {
-        if (page_directory[cur_page_table] & PTE_P) {
-
-            page_table_t page_table;
-            vaddr_t kernel_page_table = find_contiguous_kernel_pages(1);
-
-            map_page(kernel_page_directory, kernel_page_table, page_directory[cur_page_table] & PAGE_MASK, PTE_P | PTE_W);
-            page_table = kernel_page_table;
-
-            while (cur_page < PAGE_TABLE_LENGTH) {
-                if ((page_table[cur_page++] & PTE_P) == 0) {
-                    free_pages++;
-                } else {
-                    free_pages = 0;
-                    lower_limit = (cur_page_table << PGDIR_SHIFT) + (cur_page << PAGE_SHIFT);
-                }
-//                kprintf("{%d-%d-%x}", free_pages, cur_page, lower_limit);
-            }
-
-            unmap_page(kernel_page_directory, kernel_page_table);
-            
-        } else {
-            free_pages += PAGE_TABLE_LENGTH;
-        }
-
-        cur_page = 0;
-        cur_page_table++;
-    }
-
-    if ((free_pages >= num) && (lower_limit + (num * PAGE_SIZE) < upper_limit)) {
-        return (vaddr_t) lower_limit;
-    } else {
-        return NULL;
-    }
-}
-
-
-/**
- * Vergr�ssert den Userspace-Stack eines Tasks um pages Seiten
- *
- * @param task_ptr Pointer zur Task-Struktur
- * @param pages Anzahl der zu mappenden Seiten
- */
-void increase_user_stack_size(struct task * task_ptr, int pages)
-{
-	int i;
-	for(i = 0; i < pages; i++)
-	{
-		task_ptr->user_stack_bottom -= PAGE_SIZE;
-		if(resolve_vaddr((page_directory_t) task_ptr->cr3, (vaddr_t) task_ptr->user_stack_bottom) != (paddr_t) NULL)
-		{
-			kprintf("\n"
-                "\033[1;37m\033[41m" // weiss auf rot
-                "Task gestoppt: Konnte den Stack nicht weiter vergroessern\n"
-                "\033[0;37m\033[40m");
-            while(1) { asm("hlt"); }
-		}
-
-        map_page((page_directory_t) task_ptr->cr3, task_ptr->user_stack_bottom, phys_alloc_page(), PTE_P | PTE_W | PTE_U);
-	}
-	
-}
-
diff --git a/src/kernel/src/mm/phys.c b/src/kernel/src/mm/phys.c
index f0154da1..c4a59ec1 100644
--- a/src/kernel/src/mm/phys.c
+++ b/src/kernel/src/mm/phys.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006 The tyndur Project. All rights reserved.
+ * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.
  *
  * This code is derived from software contributed to the tyndur Project
  * by Burkhard Weseloh.
@@ -33,46 +33,77 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * 2006-23-9: malu
- * Dokumentation hinzugef�gt
- */
-
 #include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
 
-#include "bitops.h"
 #include "kernel.h"
 #include "multiboot.h"
-#include "vmm.h"
-#include "phys.h"
-#include "string.h"
+#include "mm.h"
+#include "lock.h"
 
-extern struct multiboot_info multiboot_info;
+#define min(x,y) (((x) < (y)) ? (x) : (y))
 
 /* Diese beiden werden in kernel.ld definiert. */
 extern void kernel_phys_start(void);
 extern void kernel_phys_end(void);
 
-unsigned long * phys_mmap;
-unsigned long phys_mmap_size;
-unsigned long phys_mmap_usable_pages;
+/** Bitmap aller physischen Seiten. Gesetztes Bit steht f�r freie Seite */
+#define PMM_BITS_PER_ELEMENT (8 * sizeof(uint_fast32_t))
+#define PMM_NUM_DMA_ELEMENTS ((16 * 1024 * 1024) / sizeof(uint_fast32_t))
+
+static uint_fast32_t* pmm_bitmap;
+
+/** Lock fuer die physikalische Speicherverwaltung */
+static lock_t pmm_lock = 0;
+
+/** 
+ * Gr��e von pmm_bitmap in Elementen (= 1/8*sizeof(uint_fast32_t) der Anzahl
+ * der physischen Seiten)
+ *
+ * @see pmm_bitmap
+ */
+static size_t pmm_bitmap_length;
+
+/**
+ * Gibt die Startadresse der Bitmap zur�ck
+ */
+void* pmm_get_bitmap_start()
+{
+    return pmm_bitmap;
+}
+
+/**
+ * Setzt die Startadresse der Bitmap. Diese Funktion ist einzig und allein dazu
+ * bestimmt, den �bergang von physischen zu virtuellen Adressen beim
+ * Einschalten von Paging bewerkstelligen zu k�nnen.
+ */
+void pmm_set_bitmap_start(void* bitmap_start)
+{
+    pmm_bitmap = bitmap_start;
+}
 
 /**
- * Gibt die Anzahl der freien Pages zurueck
+ * Gibt die G��e der Bitmap in Bytes zur�ck
+ */
+size_t pmm_get_bitmap_size()
+{
+    return pmm_bitmap_length * PMM_BITS_PER_ELEMENT / 8;
+}
+
+/**
+ * Gibt die Anzahl der freien Seiten zurueck
  *
- * @return Anzahl freie Pages
+ * @return Anzahl freier Seiten
  */
-unsigned long phys_count_free_pages()
+size_t pmm_count_free()
 {
-    unsigned long free_pages = 0;
-    unsigned long i, j;
+    size_t free_pages = 0;
+    size_t i, j;
     
-    for(i = 0; i < phys_mmap_size; i++)
-    {
-        for(j = 0; j < 32; j++)
-        {
-            if((phys_mmap[i] & (1 << j)) != 0)
-            {
+    for (i = 0; i < pmm_bitmap_length; i++) {
+        for (j = 0; j < PMM_BITS_PER_ELEMENT; j++) {
+            if (pmm_bitmap[i] & (1 << j)) {
                 free_pages++;
             }
         }
@@ -84,36 +115,40 @@ unsigned long phys_count_free_pages()
 /**
  * Gibt die Anzahl der Pages zurueck
  */
-unsigned long phys_count_pages()
+size_t pmm_count_pages()
 {
-    return phys_mmap_usable_pages;//ys_mmap_size * 32;
+    return 8 * pmm_get_bitmap_size();
 }
 
 /**
  * Markiert eine Page als frei/unbenutzt.
  *
- * @param page Zeiger auf den Anfang der Page die als frei markiert werden soll.
+ * @param page Zeiger auf den Anfang der Page, die als frei markiert werden 
+ * soll.
  */
 
-void phys_mark_page_as_free(paddr_t page)
+static inline void phys_mark_page_as_free(paddr_t page)
 {
-//    kprintf("[Free %08x]", page);
-    phys_mmap[page / PAGE_SIZE / 32] |= 1 << ((page / PAGE_SIZE) & 31);
+    //lock(&pmm_lock);
+    size_t bitmap_index = (size_t) page / PAGE_SIZE / PMM_BITS_PER_ELEMENT;
+    pmm_bitmap[bitmap_index] |= 1 << (((size_t) page / PAGE_SIZE) & 
+        (PMM_BITS_PER_ELEMENT - 1));
+
+    //unlock(&pmm_lock);
 }
 
 /**
  * Markiert num Pages als frei/unbenutzt.
  *
-  @param page Zeiger auf den Anfang der ersten Page.
+ * @param page Zeiger auf den Anfang der ersten Page.
  * @param num Anzahl der Pages die als frei markiert werden sollen.
  */
 
-void phys_mark_page_range_as_free(paddr_t page, unsigned int num)
+static inline void phys_mark_page_range_as_free(paddr_t page, size_t num)
 {
-    int i;
+    size_t i;
 
-    for(i = 0; i < num; i++)
-    {
+    for(i = 0; i < num; i++) {
         phys_mark_page_as_free(page + i * PAGE_SIZE);
     }
 }
@@ -121,12 +156,17 @@ void phys_mark_page_range_as_free(paddr_t page, unsigned int num)
 /**
  * Markiert eine Page als benutzt.
  *
- * @param page Zeiger auf den Anfang der Page die als benutzt markiert werden soll.
+ * @param page Zeiger auf den Anfang der Page, die als benutzt markiert werden 
+ * soll.
  */
 
-void phys_mark_page_as_used(paddr_t page)
+static inline void phys_mark_page_as_used(paddr_t page)
 {
-    phys_mmap[page / PAGE_SIZE / 32] &= ~(1 << ((page / PAGE_SIZE) & 31));
+    //lock(&pmm_lock);
+    size_t bitmap_index = (size_t) page / PAGE_SIZE / PMM_BITS_PER_ELEMENT;
+    pmm_bitmap[bitmap_index] &= ~(1 << (((size_t) page / PAGE_SIZE) & 
+        (PMM_BITS_PER_ELEMENT - 1)));
+    //unlock(&pmm_lock);
 }
 
 /**
@@ -136,57 +176,21 @@ void phys_mark_page_as_used(paddr_t page)
  * @param num Anzahl der Pages die als benutzt markiert werden sollen.
  */
 
-void phys_mark_page_range_as_used(paddr_t page, unsigned int num)
+static inline void phys_mark_page_range_as_used(paddr_t page, size_t num)
 {
-    int i;
+    size_t i;
 
-    for(i = 0; i < num; i++)
-    {
+    for(i = 0; i < num; i++) {
         phys_mark_page_as_used(page + i * PAGE_SIZE);
     }
 }
 
-/**
- * Sucht eine freie Page und gibt einen Zeiger auf den Anfang zur�ck.
- *
- * @param lower_limit Mindestgr��e der Page.
- *
- * @return Im Erfolgsfall wird ein Zeiger auf den Anfang der Page 
- *      zur�ckgegeben (Bei Erfolg ist der R�ckgabewert immer
- *      durch PAGE_SIZE teilbar). Im Fehlerfall wird 1 zur�ckgegeben.
- */
-
-paddr_t find_free_page(unsigned long lower_limit)
-{
-    unsigned int i, j;
-    paddr_t page = 0;
-
-    i = lower_limit / PAGE_SIZE / 32;
-    if(phys_mmap[i] & (0xffffffff << ((lower_limit / PAGE_SIZE) % 32)))
-    {
-        j = bit_scan_forward(phys_mmap[i] & (0xffffffff << ((lower_limit / PAGE_SIZE) % 32)));
-        page = (i * 32 + j) * PAGE_SIZE;
-        return page;
-    }
-
-    for(i++; i < phys_mmap_size; i++)
-    {
-        if(phys_mmap[i])
-        {
-            j = bit_scan_forward(phys_mmap[i]);
-            page = (i * 32 + j) * PAGE_SIZE;
-            return page;
-        }
-    }
-
-    return 1;
-}
-
 /**
  * Sucht num freie Pages und gibt einen Zeiger auf den Anfang der ersten Page 
  * zur�ck.
  *
- * @param lower_limit Mindestgr��e jeder Page.
+ * @param lower_index Index der niedrigsten erlaubten Page
+ * @param upper_index Index der h�chsten erlaubten Page
  * @param num Anzahl der Pages.
  *
  * @return Zeiger auf den Anfang der ersten Page.
@@ -196,43 +200,41 @@ paddr_t find_free_page(unsigned long lower_limit)
  */
 
 /* TODO: unbedingt testen */
-paddr_t find_free_page_range(unsigned long lower_limit, unsigned int num)
+static paddr_t find_free_page_range
+    (size_t lower_index, size_t upper_index, size_t num)
 {
-    unsigned int i, j;
-    unsigned int found = 0;
+    size_t i, j;
+    size_t found = 0;
     paddr_t page = 0;
 
-    for(i = lower_limit / PAGE_SIZE / 32; i < phys_mmap_size; i++)
+    for(i = lower_index; i < upper_index; i++)
     {
-        if(phys_mmap[i] == 0)
-        {
+        if(pmm_bitmap[i] == 0) {
             found = 0;
             continue;
         }
 
-        if(phys_mmap[i] == 0xffffffff)
+        if(pmm_bitmap[i] == ~0x0)
         {
             if(found == 0)
             {
-                page = i * 32 * PAGE_SIZE;
+                page = i * PMM_BITS_PER_ELEMENT * PAGE_SIZE;
             }
-            found += 32;
+            found += PMM_BITS_PER_ELEMENT;
         }
         else
         {
-            for(j = 0; j < 32; j++)
+            for(j = 0; j < PMM_BITS_PER_ELEMENT; j++)
             {
-                if(phys_mmap[i] & (1 << j))
+                if(pmm_bitmap[i] & (1 << j))
                 {
-                    if(found == 0)
-                    {
-                        page = (i * 32 + j) * PAGE_SIZE;
+                    if(found == 0) {
+                        page = (i * PMM_BITS_PER_ELEMENT + j) * PAGE_SIZE;
                     }
                     found++;
 
-                    if(found > num)
-                    {
-                        return page;
+                    if(found > num) {
+                        break;
                     }
                 }
                 else
@@ -242,8 +244,7 @@ paddr_t find_free_page_range(unsigned long lower_limit, unsigned int num)
             }
         }
 
-        if(found > num)
-        {
+        if(found > num) {
             return page;
         }
     }
@@ -251,349 +252,364 @@ paddr_t find_free_page_range(unsigned long lower_limit, unsigned int num)
     return 1;
 }
 
-/**
- * Markiert eine Page als frei/unbenutzt.
- *
- * @param page Zeiger auf den Anfang der Page die als frei markiert werden soll.
- */
-
-void phys_free_page(paddr_t page)
-{
-    phys_mark_page_as_free(page);
-}
 
 /**
- * Markiert num Pages als frei/unbenutzt.
- *Startp
- * @param page Zeiger auf den Anfang der ersten Page.
- * @param num Anzahl der Pages die als frei markiert werden sollen.
+ * Reserviert num Pages.
+ *
+ * @param lower_limit Niedrigste erlaubte Adresse (Mu� auf 32-Bit-Systemen
+ * auf einer 128K-Grenze liegen. Wenn nicht, wird gerundet)
+ *
+ * @param upper_limit H�chste erlaubte Adresse (Mu� auf 32-Bit-Systemen
+ * auf einer 128K-Grenze liegen. Wenn nicht, wird gerundet)
+ *
+ * @param num Anzahl der zu reservierenden Seiten
+ *
+ * @return Zeiger auf den Anfang der ersten Page.
  */
-
-void phys_free_page_range(paddr_t page, unsigned int num)
+paddr_t pmm_alloc_limits(paddr_t lower_limit, paddr_t upper_limit, size_t num)
 {
-    phys_mark_page_range_as_free(page, num);
-}
+    lock(&pmm_lock);
+    paddr_t page;
+    size_t lower_index = (size_t) lower_limit / PMM_BITS_PER_ELEMENT;
+    size_t upper_index = (size_t) upper_limit / PMM_BITS_PER_ELEMENT;
 
-/**
- * Reserviert eine DMA-Page und markiert sie gleichteitig als benutzt.
- *
- * @return Zeiger auf den Anfang der DMA-Page.
- */
+    if (upper_index > pmm_bitmap_length) {
+        upper_index = pmm_bitmap_length;
+    }
 
-paddr_t phys_alloc_dma_page()
-{
-    paddr_t page = find_free_page(0);
-    if(page & (PAGE_SIZE - 1))
+    if ((upper_index > PMM_NUM_DMA_ELEMENTS) && 
+        (lower_index < PMM_NUM_DMA_ELEMENTS))
+    {
+        page = find_free_page_range(lower_index, upper_index, num);
+    }
+    else
     {
+        page = find_free_page_range(PMM_NUM_DMA_ELEMENTS, upper_index, num);
+    
+        if((size_t) page & (PAGE_SIZE - 1)) {
+            page = find_free_page_range(
+                lower_index, 
+                min(PMM_NUM_DMA_ELEMENTS + num, upper_index), 
+                num
+            );
+        }
+    }
+    
+    if((size_t) page & (PAGE_SIZE - 1)) {
+        unlock(&pmm_lock);
         panic("Kein freier Speicher mehr da.");
+    } else {
+        phys_mark_page_range_as_used(page, num);
+        unlock(&pmm_lock);
+        return page;
     }
-    phys_mark_page_as_used(page);
-    return page;
 }
 
 /**
- * Reserviert eine Page.
+ * Reserviert num Pages, die beliebig im physischen Speicher liegen k�nnen.
  *
- * @return Zeiger auf den Anfang der Page.
+ * @see pmm_alloc_limits
  */
-
-paddr_t phys_alloc_page()
+paddr_t pmm_alloc(size_t num)
 {
-    paddr_t page = find_free_page(16 * 1024 * 1024);
-    if(page & (PAGE_SIZE - 1))
-    {
-        return phys_alloc_dma_page();
-    }
-    phys_mark_page_as_used(page);
-    return page;
-}
-   
-/**
- * Reserviert eine Page nicht unterhalb einer gegebenen Adresse
- */
-paddr_t phys_alloc_page_limit(uint32_t lower_limit)
-{
-    paddr_t page = find_free_page(16 * 1024 * 1024 > lower_limit ? 16 * 1024 * 1024 : lower_limit);
+    paddr_t result = pmm_alloc_limits(
+        0,
+        pmm_bitmap_length * PMM_BITS_PER_ELEMENT * PAGE_SIZE,
+        num
+    );
 
-    if(page & (PAGE_SIZE - 1)) {
-        page = find_free_page(lower_limit);
-    }
-
-    if(page & (PAGE_SIZE - 1)) {
-        panic("Konnte Speicher nicht reservieren");
-    }
-    phys_mark_page_as_used(page);
-    return page;
+    return result;
 }
 
 
 /**
- * Reserviert num DMA-Pages.
+ * Gibt physisch zusammenh�ngende Speicherseiten frei
  *
- * @return Zeiger auf den Anfang der ersten Page.
+ * @param start Zeiger auf das erste Byte der ersten freizugebenden Seite
+ * @param count Anzahl der freizugebenden Seiten
  */
-
-paddr_t phys_alloc_dma_page_range(unsigned int num)
+void pmm_free(paddr_t start, size_t count)
 {
-    paddr_t page = find_free_page_range(0, num);
-    if((uint32_t) page & (PAGE_SIZE - 1))
-    {
-        panic("Keine freier Speicher mehr da.");
-    }
-    phys_mark_page_range_as_used(page, num);
-    return page;
+    // TODO Pr�fen, ob die Seiten vorher auch besetzt waren, sonst Panic
+    phys_mark_page_range_as_free(start, count);
 }
 
-/**
- * Reserviert num Pages.
- *
- * @return Zeiger auf den Anfang der ersten Page.
- */
 
-paddr_t phys_alloc_page_range(unsigned int num)
-{
-    paddr_t page = find_free_page_range(16 * 1024 * 1024, num);
-    if((uint32_t) page & (PAGE_SIZE - 1))
-    {
-        return phys_alloc_dma_page_range(num);
-    }
-    phys_mark_page_range_as_used(page, num);
-    return page;
-}
+struct mem_block {
+    paddr_t start;
+    paddr_t end;
+};
 
 /**
- * Reserviert num DMA-Pages, die keine 64k-Grenzen enthalten
+ * Wird benutzt, um nacheinander alle vom BIOS aus freien Speicherbereiche
+ * aufzuzaehlen. Dies bedeutet nicht, dass die zurueckgegebenen
+ * Speicherbereiche frei benutzt werden koennen. Um festzustellen, ob nicht
+ * tyndur Bereiche benoetigt (z.B. fuer Kernel oder Multiboot-Strukturen), muss
+ * zusaetzlich get_reserved_block() benutzt werden.
  *
- * @return Zeiger auf den Anfang der ersten Page.
+ * @param multiboot_info Pointer auf die Multiboot-Info
+ * @param i Index des freien Speicherbereichs
+ *
+ * @return Beschreibung des freien Speicherblocks. Wenn i groesser als die
+ * Anzahl der freien Blocks ist, wird ein Block mit start > end
+ * zurueckgegeben.
  */
-
-paddr_t phys_alloc_dma_page_range_64k(unsigned int num)
+static struct mem_block get_free_block
+    (struct multiboot_info* multiboot_info, size_t i)
 {
-    uint32_t pos = 0;
-    paddr_t page;
+    struct mem_block result;
+
+    // �berpr�fung der BIOS-Memory-Map
+    struct multiboot_mmap* mmap;
+    uintptr_t mmap_addr = multiboot_info->mi_mmap_addr;
+    uintptr_t mmap_end = mmap_addr + multiboot_info->mi_mmap_length;
 
-    while(1)
+    for(mmap = (struct multiboot_mmap*) (mmap_addr);
+        mmap < (struct multiboot_mmap*) (mmap_end);
+        mmap++)
     {
-        page = find_free_page_range(pos, num);
+        uint64_t start = mmap->mm_base_addr;
+        uint64_t end   = mmap->mm_base_addr + mmap->mm_length - 1;
 
-        if(page & (PAGE_SIZE - 1))
-        {
-            panic("Keine freier Speicher mehr da.");
+        if (start > UINTPTR_MAX) {
+            continue;
+        }
+        if (end > UINTPTR_MAX) {
+            end = UINTPTR_MAX;
         }
 
-        pos = (uint32_t) page;
-        if ((pos % 65536) + (num * PAGE_SIZE) > 65536) {
-            //printf("Kernel: dma_64k: %x + %x ueberschreitet 64k-Grenze\n",
-            //    pos, num);
-            pos = (pos + 32 * PAGE_SIZE);
-        } else {
-            break;
+        // Typ 1 steht f�r freien Speicher
+        if (mmap->mm_type == 1) {
+            if (i-- == 0) {
+                result.start    = (paddr_t)start;
+                result.end      = (paddr_t)end;
+                return result;
+            }
         }
-    } 
+    }
+
+    result.start = (paddr_t) 0xFFFFFFFF;
+    result.end   = (paddr_t) 0;
 
-    phys_mark_page_range_as_used(page, num);
-    return page;
+    return result;
 }
 
 /**
- * Initialisiert den physischen Speicher.
+ * Wird benutzt, um nacheinander alle belegten Speicherbereiche aufzuzaehlen.
+ * Dies sind vor allem Kernel, Module und Multiboot-Strukturen. Vom BIOS als
+ * reserviert gekennzeichnete Bereiche sind hierbei nicht enthalten. Um die
+ * vom BIOS aus freien Bereiche zu erhalten, muss get_free_block() benutzt
+ * werdem.
  *
- * @param mmap_addr Adresse der Memorymap.
- * @param mmap_length L�nge der Memorymap.
- * @param upper_mem Gr��e des upper_mem in Kilobyte, wie in der Multboot-Info
- *      �bergeben.
+ * @param multiboot_info Pointer auf die Multiboot-Info
+ * @param i Index des belegten Speicherbereichs
+ * @param bitmap Wenn true, wird auch der Platz der Speicherbitmap als
+ * reserviert gekennzeichnet. Wenn die Speicherbitmap noch nicht platziert
+ * wurde, muss dieser Parameter false sein.
+ *
+ * @return Beschreibung des reservierten Blocks. Wenn i groesser als die
+ * Anzahl der reservierten Blocks ist, wird ein Block mit start > end
+ * zurueckgegeben.
  */
-
-void init_phys_mem(vaddr_t mmap_addr, uint32_t mmap_length, uint32_t upper_mem)
+static struct mem_block get_reserved_block
+    (struct multiboot_info* multiboot_info, size_t i, bool bitmap)
 {
-    /* freien physischen speicher ermitteln */
-    struct multiboot_mmap * mmap;
-    struct {
-        uint32_t start;
-        uint32_t end;
-    } available_memory[16 + (3 * multiboot_info.mi_mods_count)];
-    int memblocks_count = 0;
-    int i, j;
-    uint32_t upper_end = 0;
-    phys_mmap_usable_pages = 0;
-    /* Die von GRUB gelieferte memory map in unser Format umwandeln. */
-    if (mmap_length) {
-        for(mmap = (struct multiboot_mmap*)mmap_addr;
-            mmap < (struct multiboot_mmap*)(mmap_addr + mmap_length);
-            mmap = (struct multiboot_mmap*)((char*)mmap + mmap->mm_size + 4))
-        {
-            if(mmap->mm_type == 1)
-            {
-                available_memory[memblocks_count].start = PAGE_ALIGN_ROUND_UP(mmap->mm_base_addr);
-                available_memory[memblocks_count].end = PAGE_ALIGN_ROUND_DOWN(mmap->mm_base_addr + mmap->mm_length);
-
-                phys_mmap_usable_pages += (available_memory[memblocks_count].end - available_memory[memblocks_count].start) / PAGE_SIZE;
-
-                memblocks_count++;
-            }
-        }
-    }
-    else
-    {
-        // Wenn GRUB keine Memory Map �bergibt, Defaultwerte annehmen
-        // Dabei vertrauen wir darauf, da� zumindest upper_mem korrekt
-        // gesetzt ist.
-        available_memory[0].start = 0x0;
-        available_memory[0].end = 0x9fc00;
-        
-        available_memory[1].start = 0x100000;
-        available_memory[1].end = 0x100000 + (1024 * upper_mem);
-        
-        phys_mmap_usable_pages += (available_memory[0].end - available_memory[0].start) / PAGE_SIZE;
-        phys_mmap_usable_pages += (available_memory[1].end - available_memory[1].start) / PAGE_SIZE;
-        
-        memblocks_count = 2;
+    struct mem_block result;
+
+    // Bitmap nur beruecksichtigen, wenn sie bereits zugewiesen ist
+    if (bitmap && (i-- == 0)) {
+        result.start = (paddr_t) pmm_bitmap;
+        result.end   = (paddr_t)
+            (pmm_bitmap + ((pmm_bitmap_length / 8) * PMM_BITS_PER_ELEMENT));
+        return result;
     }
 
-    /* In der Liste der physischen Speicherbl�cke (im folgenden einfach
-       Bl�cke bzw. Block) einen Bereich, der von start und end angegeben wird,
-       als nicht verf�gbar definieren.
+    // Der Kernel ist besetzt
+    if (i-- == 0) {
+        result.start    = (paddr_t) kernel_phys_start;
+        result.end      = (paddr_t) kernel_phys_end;
+        return result;
+    }
 
-       Diese Funktion wird durch die Annahmen vereinfacht, dass GRUB den
-       Anfang und das Ende eines Moduls immer in genau einen Speicherblock l�dt.
-       Au�erdem dadurch, dass die Liste der verf�gbaren Speicherbl�cke nicht
-       sortiert sein muss.
-     */
-    void carve(uint32_t start, uint32_t end)
+    // Die Module auch.
     {
-        uint32_t i;
-
-        start = PAGE_ALIGN_ROUND_DOWN(start);
-        end = PAGE_ALIGN_ROUND_UP(end);
+        uint32_t j;
+        struct multiboot_module* multiboot_module;
+        multiboot_module = (struct multiboot_module*) (uintptr_t) 
+            multiboot_info->mi_mods_addr;
 
-        //printf("carve: %x bis %x\n", start, end);
-        
-        for(i = 0; i < memblocks_count; i++)
+        for (j = 0; j < multiboot_info->mi_mods_count; j++) 
         {
-            if(start == available_memory[i].start)
-            {
-                /* Der Bereich beginnt genau an einem Blockanfang */
+            // Die Multiboot-Info zum Modul    
+            if (i-- == 0) {
+                result.start    = (paddr_t) multiboot_module;
+                result.end      = (paddr_t) (multiboot_module + 1);
+                return result;
+            }
 
-                if(end < available_memory[i].end)
-                {
-                    /* Der Bereich endet mittem im Block */
+            // Das Modul selbst
+            if (i-- == 0) {
+                result.start    = (paddr_t) multiboot_module->start;
+                result.end      = (paddr_t) multiboot_module->end;
+                return result;
+            }
 
-                    /* Den Beginn des Blocks hinter den Bereich verschieben */
-                    available_memory[i].start = end;
-                    break;
-                }
-                else if(end == available_memory[i].end)
-                {
-                    /* Der Bereich nimmt den ganzen Block ein */
-
-                    /* Den Block aus der Liste entfernen */
-                    memblocks_count--;
-                    for(j = i; j < memblocks_count; j++)
-                    {
-                        available_memory[j].start = available_memory[j + 1].start;
-                        available_memory[j].end = available_memory[j + 1].end;
-                    }
-                    break;
+            // Die Kommandozeile des Moduls 
+            if (multiboot_module->cmdline) {
+                if (i-- == 0) {
+                    result.start = (paddr_t) multiboot_module->cmdline;
+                    result.end   = (paddr_t) multiboot_module->cmdline +
+                        strlen((char*) (uintptr_t) multiboot_module->cmdline);
+                    return result;
                 }
             }
-            else if(start > available_memory[i].start)
-            {
-                /* Der Bereich beginnt irgendwo im Block */
 
-                if(end < available_memory[i].end)
-                {
-                    /* Der Bereich endet irgendwo mitten im Block. Das bedeutet
-                       ein Block muss in der Mitte zerteilt werden. Dazu muss
-                       ein weiterer Eintrag in der Liste angelegt werden. */
+            multiboot_module++;
+        }
+    }
 
-                    /* Einen neuen Eintrag am Ende anlegen */
-                    available_memory[memblocks_count].start = end;
-                    available_memory[memblocks_count].end = available_memory[i].end;
+    result.start = (paddr_t) 0xFFFFFFFF;
+    result.end   = (paddr_t) 0;
 
-                    /* Den Eintrag verkleinern */
-                    // available_memory[i].start bleibt unver�ndert
-                    available_memory[i].end = start;
+    return result;
+}
 
-                    memblocks_count++;
-                    break;
-                }
-                else if(end == available_memory[i].end)
-                {
-                    /* Der Bereich endet genau mit dem Block */
+/**
+ * Suche einen Platz f�r die Bitmap
+ */
+static paddr_t find_bitmap_mem
+    (struct multiboot_info* multiboot_info, size_t size)
+{
+    if (multiboot_info->mi_flags & MULTIBOOT_INFO_HAS_MMAP) {
+        size_t i, j;
+        struct mem_block free, reserved;
+        paddr_t bitmap = 0x0;
 
-                    /* Das Ende des Bereichs auf den Anfang des Blocks setzen. */
-                    available_memory[i].end = start;
-                    break;
-                }
+        i = 0;
+        do
+        {
+            // Freien Speicherblock suchen und Bitmap an den Anfang legen
+            free = get_free_block(multiboot_info, i++);
+            if (free.start > free.end) {
+                panic("Keinen Platz fuer die Speicherbitmap gefunden");
+            }
+            bitmap = free.start;
 
-                /* Wenn sowohl start als auch end hinter dem Speicherblock
-                   liegen, wird nichts gemacht. */
+            // Probieren, ob der Speicherblock nicht doch besetzt ist und
+            // in diesem Fall ein Stueck weitergehen und nochmal von vorne
+            // durchprobieren
+            j = 0;
+            do
+            {
+                reserved = get_reserved_block(multiboot_info, j++, false);
+                if (!((reserved.start > bitmap + size)
+                    || (reserved.end <= bitmap)))
+                {
+                    j = 0;
+                    bitmap = (paddr_t)
+                        PAGE_ALIGN_ROUND_UP((uintptr_t) reserved.end);
+                }
             }
+            while ((bitmap <= free.end) && (reserved.start < reserved.end));
 
-            /* Wenn der start vor dem Speicherblock liegt, wird nichts gemacht,
-               denn wir gehen davon aus, dass GRUB kein Modul in einen Bereich
-               l�dt, der kein verf�gbarer Speicher ist. */
+            // Wenn die Bitmap nach Beruecksichtigung aller besetzten Bereiche
+            // immer noch im freien Bereich liegt, dann nehmen wir die Adresse
+            if (bitmap <= free.end) {
+                return bitmap;
+            }
         }
+        while(true);
+    } else {
+        return (paddr_t) 0x1000;
     }
+}
 
-    carve((uint32_t)kernel_phys_start, (uint32_t)kernel_phys_end);
-
-    /* foreach(modul in module) { carve(modul.start, module.end); } // pseudocode btw ;) */    
+/**
+ * Bestimmt die ben�tigte Gr��e der Bitmap in Bytes
+ */
+static size_t required_bitmap_size(struct multiboot_info* multiboot_info)
+{
+    // Suche die h�chste Adresse
+    paddr_t upper_end = 0;
+    if (multiboot_info->mi_flags & MULTIBOOT_INFO_HAS_MMAP) 
     {
-        uint32_t i;
-        struct multiboot_module * multiboot_module;
-        multiboot_module = multiboot_info.mi_mods_addr;
+        struct multiboot_mmap* mmap =
+            (struct multiboot_mmap*) (uintptr_t) multiboot_info->mi_mmap_addr;
 
-        for (i = 0; i < multiboot_info.mi_mods_count; i++) {
-            carve((uint32_t) multiboot_module, ((uint32_t) multiboot_module) + sizeof(multiboot_module));
-            carve((uint32_t) multiboot_module->start, (uint32_t) multiboot_module->end);
-            if (multiboot_module->cmdline) {
-                carve((uint32_t) multiboot_module->cmdline, (uint32_t) multiboot_module->cmdline + strlen(multiboot_module->cmdline));
+        size_t i = 0;
+        for (i = 0; i < multiboot_info->mi_mmap_length / sizeof(*mmap); i++)
+        {
+            if (((uint32_t) (mmap[i].mm_base_addr + mmap[i].mm_length)
+                > (uint32_t) (uintptr_t) upper_end) && (mmap[i].mm_type == 1))
+            {
+                upper_end = (paddr_t)(uintptr_t) 
+                    mmap[i].mm_base_addr + mmap[i].mm_length;
             }
-
-            multiboot_module++;
         }
     }
-
-    /* Die obere Grenze des physischen Speichers ermitteln. */
-    for(i = 0; i < memblocks_count; i++)
+    else 
     {
-        if(available_memory[i].end > upper_end)
-        {
-            upper_end = available_memory[i].end;
-        }
+        // Der hintere Cast verhindert Compiler-Warungen
+        upper_end = (paddr_t) (1024 * (1024 + (uintptr_t) 
+            multiboot_info->mi_mem_upper));
     }
-    
-    /* einen ort f�r die tabelle mit den physischen seiten suchen */
-    phys_mmap_size = upper_end / PAGE_SIZE / 32;
-    for(i = 0; i < memblocks_count; i++)
+
+    // Umrechnen auf ben�tigte Bytes f�r die Bitmap
+    return (size_t) upper_end / PAGE_SIZE / 8;
+}
+
+/**
+ * Initialisiert den physischen Speicher.
+ *
+ * @param mmap_addr Adresse der Memorymap.
+ * @param mmap_length L�nge der Memorymap in Bytes.
+ * @param upper_mem Gr��e des upper_mem in Kilobyte, wie in der Multboot-Info
+ *      �bergeben.
+ */
+void pmm_init(struct multiboot_info* multiboot_info)
+{
+    // Finde einen Platz f�r die Bitmap
+    size_t bitmap_size = required_bitmap_size(multiboot_info);
+    pmm_bitmap = (void*) find_bitmap_mem(multiboot_info, bitmap_size);
+    pmm_bitmap_length = 8 * bitmap_size / PMM_BITS_PER_ELEMENT;
+
+    // Am Anfang ist alles besetzt
+    memset(pmm_bitmap, 0x0, bitmap_size);
+
+    // ...anschlie�end die BIOS-Memory-Map abarbeiten
+    size_t i = 0;
+    do
     {
-        if((available_memory[i].start) && (available_memory[i].start + phys_mmap_size * 4 < available_memory[i].end))
-        {
-            phys_mmap = (unsigned long*)available_memory[i].start;
-            available_memory[i].start = PAGE_ALIGN_ROUND_UP(available_memory[i].start + phys_mmap_size * 4);
-            break;
-        }
-        else if (available_memory[i].start + PAGE_SIZE + phys_mmap_size * 4 < available_memory[i].end)
-        {
-            phys_mmap = (unsigned long*)(available_memory[i].start + PAGE_SIZE);
-                    
-            available_memory[memblocks_count].start = available_memory[i].start;
-            available_memory[memblocks_count].end = available_memory[i].start + PAGE_SIZE;
-            memblocks_count++;
-            
-            available_memory[i].start = PAGE_ALIGN_ROUND_UP(available_memory[i].start + PAGE_SIZE + phys_mmap_size * 4);
+        struct mem_block block = get_free_block(multiboot_info, i++);
+
+        // Wenn der Start nach dem Ende liegt, ist der Block ungueltig
+        // und wir sind fertig
+        if (block.start > block.end) {
             break;
         }
+
+        // Reservierten Block als frei markieren
+        phys_mark_page_range_as_free
+            (block.start, NUM_PAGES(block.end - block.start));
     }
-    
-    /* alle seiten als belegt markieren */
-    phys_mark_page_range_as_used(0, upper_end / PAGE_SIZE);
+    while(true);
+
 
-    /* freie seiten als frei markieren */
-    for(i = 0; i < memblocks_count; i++)
+    // ...und dann Kernel usw. wieder reservieren
+    i = 0;
+    do
     {
-        //kprintf("Mark as free: %x, %d Pages\n", available_memory[i].start, (available_memory[i].end - available_memory[i].start) / PAGE_SIZE);
-        phys_mark_page_range_as_free(available_memory[i].start, (available_memory[i].end - available_memory[i].start) / PAGE_SIZE);
+        struct mem_block block = get_reserved_block(multiboot_info, i++, true);
+
+        // Wenn der Start nach dem Ende liegt, ist der Block ungueltig
+        // und wir sind fertig
+        if (block.start > block.end) {
+            break;
+        }
+
+        // Reservierten Block als besetzt markieren
+        phys_mark_page_range_as_used
+            (block.start, NUM_PAGES(block.end - block.start));
     }
+    while(true);
 }
diff --git a/src/kernel/src/mm/shm.c b/src/kernel/src/mm/shm.c
index 0fdb6fea..6d94c52b 100644
--- a/src/kernel/src/mm/shm.c
+++ b/src/kernel/src/mm/shm.c
@@ -1,8 +1,8 @@
-/*  
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
+/*
+ * Copyright (c) 2008 The tyndur Project. All rights reserved.
  *
  * This code is derived from software contributed to the tyndur Project
- * by Mathias Gottschlag.
+ * by Kevin Wolf.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -20,110 +20,218 @@
  *    contributors may be used to endorse or promote products derived
  *    from this software without specific prior written permission.
  *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS 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 
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */  
+ */
 
 #include <stdint.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <collections.h>
 
-#include "shm.h"
-#include "phys.h"
-#include "stdlib.h"
-#include "kernel.h"
-#include "paging.h"
+#include "mm.h"
+#include "cpu.h"
+#include "tasks.h"
 
-list_t *shm_table = 0;
+struct shm_desc {
+    uint64_t            id;
+    struct tree_item    tree_item;
 
-uint32_t lastid = 0;
+    size_t              num_pages;
+    list_t*             processes;
+};
 
-void init_shared_memory(void)
+struct shm_process {
+    struct shm_desc*    shm;
+    pm_process_t*       process;
+    vaddr_t             vaddr;
+};
+
+static tree_t* shms = NULL;
+static uint32_t shm_last_id = 0;
+
+static void shm_destroy_task(pm_process_t* process, void* prv);
+
+/**
+ * Initialisiert die SHM-Verwaltung
+ */
+void shm_init(void)
 {
-	shm_table = list_create();
+    shms = tree_create(struct shm_desc, tree_item, id);
 }
 
-uint32_t create_shared_memory(uint32_t size)
+/**
+ * Neuen Shared Memory reservieren
+ *
+ * @return ID des neu angelegten Shared Memory. Der Aufrufer muss anschliessend
+ * syscall_shm_attach aufrufen, um auf den Speicher zugreifen zu koennen.
+ */
+uint32_t shm_create(size_t size)
 {
-    shm_table_entry_t *entry = malloc(sizeof(shm_table_entry_t));
-    
-    entry->pagecount = size / PAGE_SIZE;
-    if (size%PAGE_SIZE) {
-        entry->pagecount++;
+    uint32_t id = ++shm_last_id;
+    struct shm_desc* shm;
+
+    while (tree_search(shms, id)) {
+        id++;
     }
-    entry->addresses = malloc(entry->pagecount * sizeof(paddr_t));
-    int i;
-    for (i = 0; i < entry->pagecount; i++) {
-        entry->addresses[i] = phys_alloc_page();
+
+    shm = calloc(1, sizeof(*shm));
+    shm->id = id;
+    shm->num_pages = NUM_PAGES(size);
+    shm->processes = list_create();
+
+    tree_insert(shms, shm);
+
+    return id;
+}
+
+/**
+ * Bestehenden Shared Memory oeffnen.
+ *
+ * @param process Prozess, der den Shared Memory oeffnet
+ * @param id ID des zu oeffnenden Shared Memory
+ * @return Virtuelle Adresse des geoeffneten Shared Memory; NULL, wenn der
+ * Shared Memory mit der angegebenen ID nicht existiert.
+ */
+void* shm_attach(pm_process_t* process, uint32_t id)
+{
+    struct shm_desc* shm = tree_search(shms, id);
+    void* ret;
+    struct shm_process* shm_proc;
+
+    if (shm == NULL) {
+        return NULL;
     }
-    entry->usecount = 0;
-    entry->id = ++lastid;
-    list_push(shm_table, entry);
-    return entry->id;
+
+    if (list_is_empty(shm->processes)) {
+        // Erster Prozess, der den SHM oeffnet: Speicher allozieren
+        ret = mmc_valloc(&process->context, shm->num_pages,
+            MM_FLAGS_USER_DATA);
+    } else {
+        // Ansonsten Mapping von einem anderen Prozess uebernehmen
+        struct shm_process* first = list_get_element_at(shm->processes, 0);
+        ret = mmc_automap_user(&process->context,
+            &first->process->context, first->vaddr, shm->num_pages,
+            MM_USER_START, MM_USER_END, MM_FLAGS_USER_DATA);
+    }
+
+    if (ret == NULL) {
+        return NULL;
+    }
+
+    shm_proc = calloc(1, sizeof(*shm_proc));
+    shm_proc->shm = shm;
+    shm_proc->process = process;
+    shm_proc->vaddr = ret;
+    list_push(shm->processes, shm_proc);
+
+    if (process->shm == NULL) {
+        process->shm = list_create();
+        pm_register_on_destroy(process, shm_destroy_task, NULL);
+    }
+    list_push(process->shm, shm_proc);
+
+    return ret;
 }
-vaddr_t attach_task_to_shm(struct task *task, uint32_t id)
+
+/**
+ * Shared Memory schliessen. Wenn keine Prozesse den Shared Memory mehr
+ * geoeffnet haben, wird er geloescht.
+ *
+ * @param process Prozess, der den Shared Memory schliesst
+ * @param id ID des zu schliessenden Shared Memory
+ */
+void shm_detach(pm_process_t* process, uint32_t id)
 {
-    int i, j;
-    //Nach id suchen
-    for (i = 0; i < list_size(shm_table); i++) {
-        if (((shm_table_entry_t *)list_get_element_at(shm_table, i))->id == id) {
-            shm_table_entry_t *shmem = (shm_table_entry_t *)list_get_element_at(shm_table, i);
-            //Pages suchen
-            vaddr_t vaddr = find_contiguous_pages(task->cr3, shmem->pagecount,
-                USER_MEM_START, USER_MEM_END);
-            //Pages mappen
-            for (j = 0; j < shmem->pagecount; j++) {
-                map_page(task->cr3, vaddr + j * PAGE_SIZE, shmem->addresses[j],
-                    PTE_P | PTE_U | PTE_W);
-                
-            }
-            shmem->usecount++;
-            list_push(task->shmids, (void*)id);
-            list_push(task->shmaddresses, vaddr);
-            return vaddr;
+    struct shm_desc* shm = tree_search(shms, id);
+    struct shm_process* shm_proc;
+    int i;
+
+    if (shm == NULL) {
+        return;
+    }
+
+    // Aus der SHM-Liste des Prozesses austragen
+    for (i = 0; (shm_proc = list_get_element_at(process->shm, i)); i++) {
+        if (shm_proc->shm == shm) {
+            list_remove(process->shm, i);
+            break;
+        }
+    }
+
+    // Aus der Prozessliste des SHM austragen
+    for (i = 0; (shm_proc = list_get_element_at(shm->processes, i)); i++) {
+        if (shm_proc->process == process) {
+            list_remove(shm->processes, i);
+            goto found;
+        }
+    }
+
+    return;
+
+found:
+
+    // Wenn es der letzte Benutzer war, SHM loeschen
+    if (list_is_empty(shm->processes)) {
+        for (i = 0; i < shm->num_pages; i++) {
+            pmm_free(mmc_resolve(&process->context,
+                shm_proc->vaddr + (i * PAGE_SIZE)), 1);
         }
+
+        list_destroy(shm->processes);
+        shm->processes = NULL;
+        tree_remove(shms, shm);
+    }
+
+    // Virtuellen Speicher freigeben
+    mmc_unmap(&process->context, shm_proc->vaddr, shm->num_pages);
+
+
+    free(shm_proc);
+    if (shm->processes == NULL) {
+        free(shm);
     }
-    return 0;
+
+    return;
 }
-void detach_task_from_shm(struct task *task, uint32_t id)
+
+/**
+ * Gibt die Groesse des SHM-Bereichs in Bytes zurueck
+ */
+size_t shm_size(uint32_t id)
 {
-    //kprintf("Loese Task von shm %d.\n", id);
-    int i, j, k;
-    //Einträge suchen
-    for (i = 0; i < list_size(task->shmids); i++) {
-        if ((uint32_t)list_get_element_at(task->shmids, i) == id) {
-            vaddr_t vaddr = list_get_element_at(task->shmaddresses, i);
-            for (j = 0; j < list_size(shm_table); j++) {
-                if (((shm_table_entry_t *)list_get_element_at(shm_table, j))->id == id) {
-                    shm_table_entry_t *shmem = (shm_table_entry_t *)list_get_element_at(shm_table, j);
-                    //Pages des Tasks freimachen
-                    for (k = 0; k < shmem->pagecount; k++) {
-                        unmap_page(task->cr3, vaddr + k * PAGE_SIZE);
-                    }
-                    list_remove(task->shmids, i);
-                    list_remove(task->shmaddresses, i);
-                    shmem->usecount--;
-                    if (!shmem->usecount) {
-                        //kprintf("Shared Memory wird nicht mehr benoetigt.\n");
-                        //Shared Memory wird nicht mehr benötigt
-                        for (k = 0; k < shmem->pagecount; k++) {
-                            phys_mark_page_as_free(shmem->addresses[k]);
-                        }
-                        free(shmem->addresses);
-                        free(shmem);
-                        list_remove(shm_table, j);
-                    }
-                    return;
-                }
-            }
-            return;
-        }
+    struct shm_desc* shm = tree_search(shms, id);
+
+    if (shm == NULL) {
+        return 0;
     }
+
+    return shm->num_pages * PAGE_SIZE;
+}
+
+/**
+ * Schliesst alle SHM-Bereiche eines Prozesses
+ */
+static void shm_destroy_task(pm_process_t* process, void* prv)
+{
+    struct shm_process* shm_proc;
+
+    if (process->shm == NULL) {
+        return;
+    }
+
+    while ((shm_proc = list_get_element_at(process->shm, 0))) {
+        shm_detach(process, shm_proc->shm->id);
+    }
+
+    list_destroy(process->shm);
 }
diff --git a/src/kernel2/src/module.mk b/src/kernel/src/module.mk
similarity index 100%
rename from src/kernel2/src/module.mk
rename to src/kernel/src/module.mk
diff --git a/src/kernel/src/modules.c b/src/kernel/src/modules.c
deleted file mode 100644
index d05b10ba..00000000
--- a/src/kernel/src/modules.c
+++ /dev/null
@@ -1,371 +0,0 @@
-/*  
- * Copyright (c) 2006 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */  
-
-#include <stdint.h>
-
-#include "modules.h"
-#include "multiboot.h"
-#include "kprintf.h"
-#include "elf32.h"
-#include "vmm.h"
-#include "kernel.h"
-#include "string.h"
-#include "paging.h"
-#include "types.h"
-#include "intr.h"
-#include "tasks.h"
-#include "kmm.h"
-#include "paging.h"
-
-#define ELF_MAGIC 0x464C457F
-#define MODULE_ENTRY ((vaddr_t) 0x40000000)
-
-#undef DEBUG
-
-//Wird in schedule.c definiert und hier verwendet, um auf die Task-Struct
-// des Init-Moduls zuzugreifen
-extern struct task* first_task;
-
-//Laed ein ELF-Dateiimage (wird nur noch fuer init verwendet)
-void load_single_module(Elf32_Ehdr* elf_header, const char* cmdline);
-
-
-
-
-/**
- * Laed nur das erste Modul, das in der Multiboot-Modulliste eingetragen
- * ist, das Init-Modul. Es wird im Moment nur ELF 
- * unterstuetzt.
- *
- * @param elf_header Pointer auf den ELF-Header
- */
-void load_init_module(struct multiboot_info * multiboot_info)
-{
-    struct multiboot_module * multiboot_module;
-    
-    //Ueberpruefen, ob ueberhaupt module in der Liste sind
-    if (multiboot_info->mi_mods_count == 0)
-    {
-        panic("Keine Multiboot-Module zu laden.");
-    }
-    
-    
-    //Multiboot-Modulliste in den Kerneladressraum mappen
-    multiboot_module = map_phys_addr((paddr_t)multiboot_info->mi_mods_addr, sizeof(multiboot_module));
-    if (multiboot_module == NULL)    
-    {
-        panic("Konnte Multiboot-Modulliste nicht in den Kernelspeicher mappen.");
-    }
-    
-    //Befehlszeile des Moduls mappen
-    char* cmdline = map_phys_addr((paddr_t) multiboot_module->cmdline, 4096);
-
-    //Das Modul dem ELF-Loader uebergeben
-    void* elf_image = map_phys_addr((paddr_t) multiboot_module->start,
-        multiboot_module->end - multiboot_module->start);
-    load_single_module(elf_image, cmdline);
-    free_phys_addr(elf_image, multiboot_module->end - multiboot_module->start);
-    
-    //Modulbefehlszeile wieder freigeben
-    free_phys_addr(cmdline, 4096);
-
-    //Multiboot-Modulliste wieder aus dem Kerneladressraum freigeben
-    free_phys_addr((vaddr_t)multiboot_module, sizeof(multiboot_module));
-    
-    //In der Multiboot Struct den Pointer und die anzahl der Module anpassen,
-    // da Init nun geladen ist.
-    multiboot_info->mi_mods_addr++;
-    multiboot_info->mi_mods_count--;
-}
-
-
-/**
- * Hier werden die anderen Module Module an Init weiter geleitet
-  *
- * @param elf_header Pointer auf den ELF-Header
- */
-void load_multiboot_modules(struct multiboot_info * multiboot_info)
-{
-    int i;
-    struct multiboot_module * multiboot_module_phys;
-    struct multiboot_module * multiboot_module;
-    
-    //Ueberpruefen, ausser dem 
-    if (multiboot_info->mi_mods_count == 0)
-    {
-        //Ist hier ein Panic wirklich das richtige?
-        panic("Keine Multiboot-Module zu laden.");
-    }
-    else
-    {
-        multiboot_module_phys = multiboot_info->mi_mods_addr;
-        
-        // Speicher f�r die Modulparameter
-        paddr_t mod_cmdline_page_phys = phys_alloc_page();
-        void* mod_cmdline_task = find_contiguous_pages((page_directory_t)first_task->cr3, 1, USER_MEM_START, USER_MEM_END);
-        map_page((page_directory_t)first_task->cr3, mod_cmdline_task, mod_cmdline_page_phys, PTE_P | PTE_U | PTE_W);
-        
-        char* mod_cmdline_page = map_phys_addr(mod_cmdline_page_phys, PAGE_SIZE);
-        char* mod_cmdline = mod_cmdline_page;
-        size_t mod_cmdline_free = PAGE_SIZE;
-
-        //Speicher f�r die Modulliste allokieren und 
-        void* mod_list_task = find_contiguous_pages((page_directory_t)first_task->cr3, 1, USER_MEM_START, USER_MEM_END);
-        paddr_t mod_list_phys = phys_alloc_page();
-        map_page((page_directory_t)first_task->cr3, mod_list_task, mod_list_phys, PTE_P | PTE_U | PTE_W);
-        
-        
-        //Stack von Init mappen um ein Pointer auf die Modulliste zu uebergeben
-        uint32_t* stack = (uint32_t*) ((uint32_t)map_phys_addr(resolve_vaddr((page_directory_t)first_task->cr3, first_task->user_stack_bottom), 0x1000) - 0);
-        stack[255] = (uint32_t)mod_list_task;
-        free_phys_addr((vaddr_t)stack, 0x1000);
-        
-        //Modulliste temporaer mappen
-        uint32_t* modulelist = (uint32_t*) map_phys_addr(mod_list_phys, 0x1000);
-        
-        //Das unterste dword auf der Page mit der Liste beinhaltet die Anzahl der Module
-        modulelist[0] = multiboot_info->mi_mods_count;
-        
-        //Module in den Adressraum von Init mapen
-        for (i = 0; i < multiboot_info->mi_mods_count; i++)
-        {
-            //Die multiboot_module Struct des aktuellen Moduls mappen
-            multiboot_module = map_phys_addr((paddr_t)multiboot_module_phys, sizeof(multiboot_module));
-            
-            //Anzahl der benoetigten Pages berechnen
-            size_t pages = (PAGE_ALIGN_ROUND_UP((uint32_t)multiboot_module->end) -PAGE_ALIGN_ROUND_DOWN((uint32_t)multiboot_module->start)) / 0x1000;
-            
-            //Freie virtuelle Adresse suchen um das Modul dort hin zu mappen.
-            void* dest = find_contiguous_pages((page_directory_t)first_task->cr3, pages, USER_MEM_START, USER_MEM_END);
-            map_page_range((page_directory_t)first_task->cr3, dest, (paddr_t) multiboot_module->start, PTE_P | PTE_U | PTE_W, pages);
-            first_task->memory_used += pages * 0x1000;
-
-            //TODO: Den Speicher aus dem Kerneladressraum unmappen
-           
-            //Die Adresse in die Modulliste von Init schreiben
-            modulelist[1 + (3*i)] = (uint32_t) dest;
-            modulelist[2 + (3*i)] = multiboot_module->end - multiboot_module->start;
-            modulelist[3 + (3*i)] = (uint32_t) mod_cmdline_task + (mod_cmdline - mod_cmdline_page);
-
-            // Modellbefehlszeile kopieren
-            char* cmdline = map_phys_addr((paddr_t) multiboot_module->cmdline, 4096);
-            size_t length = strlen(cmdline);
-            if (mod_cmdline_free > length) {
-                strncpy(mod_cmdline, cmdline, length);
-                mod_cmdline[length] = '\0';
-                mod_cmdline += (length + 1);
-                mod_cmdline_free -= (length + 1);
-            }
-            free_phys_addr(cmdline, 4096);
-            
-            //multiboot_module Struct wieder freigeben
-            free_phys_addr((vaddr_t)multiboot_module, sizeof(multiboot_module));
-            
-            //Physikalische Adresse der  multiboot_module Struct auf die naechste setzen
-            multiboot_module_phys++;
-        }
-        
-        //Die temporaer gemapte Modulliste wieder freigeben(nur hier im Kernel freigeben)
-        free_phys_addr((vaddr_t)modulelist, 0x1000);
-        free_phys_addr(mod_cmdline_page, 0x1000);
-    }
-    
-    //TODO: Muessen noch irgendwelche Multiboot-Structs physikalisch freigegeben werden?
-}  
-
-
-/**
- * Ein einzelnes ELF-Image laden und den Prozess erstellen.
- *
- * @param elf_header Pointer auf den ELF-Header. Es wird erwartet, dass das
- * gesamte ELF-Image gemappt ist.
- */
-void load_single_module(Elf32_Ehdr * elf_header, const char* cmdline) 
-{
-    Elf32_Phdr * program_header;
-    uint32_t i, j;
-    uint32_t pages;
-
-    struct task * task = NULL;
-    vaddr_t address, base, dst;
-    paddr_t phys_dst;
-
-    //kprintf("[ehdr: %x]", elf_header);
-
-    if (elf_header->e_magic == ELF_MAGIC) {
-        
-        program_header = (Elf32_Phdr *) ((uint32_t) elf_header + elf_header->e_phoff);
-
-#ifdef DEBUG
-        kprintf("    EntryCount: %d", elf_header->e_phnum);
-        kprintf("    Offset: 0x%x\n", elf_header->e_phoff);
-#endif
-
-        for (i = 0; i < elf_header->e_phnum; i++, program_header++) {
-
-#ifdef DEBUG
-            kprintf(" ph @ %x, type=%d\n", program_header, program_header->p_type);
-#endif
-            if (program_header->p_type == 1) {
-                
-              	if ((elf_header->e_entry >= program_header->p_vaddr) && (elf_header->e_entry <= program_header->p_vaddr + program_header->p_memsz)) {
-#ifdef DEBUG
-                    kprintf("Neuen Task erstellen\n");
-#endif
-                    task = create_task((vaddr_t) elf_header->e_entry, cmdline, 0);
-                } else if (task == NULL) {
-					// FIXME
-					kprintf("Kein Task: phdr->vaddr = %x, ehdr->entry = %x\nDas Modul ist entweder beschaedigt oder wird von diesem Kernel nicht unterstuetzt (Entry Point muss im ersten Program Header liegen)\n", program_header->p_vaddr, elf_header->e_entry);
-                    continue;
-                }
-                
-                // Pages erstellen
-                pages = 1 + ((program_header->p_offset + program_header->p_memsz) / 0x1000) - (program_header->p_offset / 0x1000);
-                
-#ifdef DEBUG
-                kprintf("Mapping von %d Pages\n", pages);
-#endif
-                base = (vaddr_t) PAGE_ALIGN_ROUND_DOWN(program_header->p_vaddr);
-                if (base < MODULE_ENTRY) {
-                    base = MODULE_ENTRY;
-                }
-
-                for (j = 0; j < pages; j++) {
-                    paddr_t curPage = phys_alloc_page();
-#ifdef DEBUG
-                    kprintf("  %x => %x", (vaddr_t) (base + 0x1000 * j), curPage);
-#endif
-                    map_page((page_directory_t) task->cr3, (vaddr_t) (base + 0x1000 * j), curPage, PTE_P | PTE_U | PTE_W);
-                }
-
-                // Programm kopieren
-#ifdef DEBUG
-                kprintf("Programm kopieren\n");
-#endif
-                pages = 1 + ((program_header->p_offset + program_header->p_filesz) / 0x1000) - (program_header->p_offset / 0x1000);
-#ifdef DEBUG
-                kprintf("%d Pages zu kopieren\n", pages);
-#endif
-                
-                
-                uint32_t bytes_on_first_page;
-                if (program_header->p_filesz > 0x1000 - (program_header->p_vaddr % 0x1000)) {
-                    bytes_on_first_page = 0x1000 - (program_header->p_vaddr % 0x1000);
-                } else {
-                    bytes_on_first_page = program_header->p_filesz;
-                }
-
-                uint32_t zero_bytes_on_last_page = 0x1000 - (
-                    (program_header->p_offset + program_header->p_filesz) 
-                    % 0x1000);
-
-#ifdef DEBUG
-                kprintf("bytes_on_first_page: 0x%x\n", bytes_on_first_page);
-                kprintf("zero_bytes_on_last_page: 0x%x\n", zero_bytes_on_last_page);
-#endif
-
-                // Erste Page kopieren (m�glicherweise fangen die Daten mitten in der
-                // Page an)
-                address = (vaddr_t) ((uint32_t) elf_header + program_header->p_offset);
-                phys_dst = resolve_vaddr((page_directory_t) task->cr3, (vaddr_t) program_header->p_vaddr);
-                dst = map_phys_addr(phys_dst, bytes_on_first_page);
-#ifdef DEBUG
-                kprintf("  Kopiere 0x%x Bytes nach %x von %x [1]\n", bytes_on_first_page, program_header->p_vaddr, address);
-#endif
-                memcpy(dst, address, bytes_on_first_page);
-                free_phys_addr(dst, bytes_on_first_page);
-
-
-                address += bytes_on_first_page;
-                for (j = 1; j < pages; j++) {
-                    //address = map_phys_addr(phys_address, 0x1000);
-
-                    phys_dst = resolve_vaddr((page_directory_t) task->cr3, (vaddr_t) (base + 0x1000 * j));
-                    dst = map_phys_addr(phys_dst, 0x1000);
-#ifdef DEBUG
-                    kprintf("  Kopiere 4K nach %x von %x\n", (base + 0x1000 * j), address);
-#endif
-                    memcpy(dst, address, 0x1000);
-
-                    free_phys_addr(dst, 0x1000);
-                    //free_phys_addr(address, 0x1000);
-
-                    address += 0x1000;                
-                }
-
-                if (zero_bytes_on_last_page) {
-                    // Es ist ein Teilst�ck einer Page �brig, das mit Nullen gef�llt wird
-#ifdef DEBUG
-                    kprintf("  Setze Nullen in 0x%x (0x%x Stueck)\n", 
-                            (vaddr_t) (base + 0x1000 * (j - 1)) + (0x1000 - zero_bytes_on_last_page), 
-                            zero_bytes_on_last_page);
-#endif
-
-                    phys_dst = resolve_vaddr(
-                        (page_directory_t) task->cr3, 
-                        (vaddr_t) (base + 0x1000 * (j - 1)) + (0x1000 - zero_bytes_on_last_page)
-                    ) /*(bytes_on_last_page)*/;
-
-                    dst = map_phys_addr(phys_dst, zero_bytes_on_last_page);
-                    memset(dst, 0, zero_bytes_on_last_page);
-                    free_phys_addr(dst, zero_bytes_on_last_page);
-                }
-                
-                // Wenn memsz > filesz. mu� mit Nullen aufgef�llt werden
-                pages = program_header->p_memsz / 0x1000;
-                if (program_header->p_memsz % 0x1000) {
-                    pages++;
-                }
-                for (; j < pages; j++) {
-                    phys_dst = resolve_vaddr((page_directory_t) task->cr3, (vaddr_t) (base + 0x1000 * j));
-                    dst = map_phys_addr(phys_dst, 0x1000);
-
-#ifdef DEBUG
-                    kprintf("  Setze Nullen in %x\n", (base + 0x1000 * j));
-#endif
-                    memset(dst, 0, 0x1000);
-
-                    free_phys_addr((vaddr_t)phys_dst, 0x1000);
-                }
-                
-#ifdef DEBUG
-                kprintf("    Modul geladen.\n");
-#endif
-            }
-        }
-    } else {
-        kprintf("ELF-Magic ungueltig (0x%x)\n",elf_header->e_magic);
-    }
-}
diff --git a/src/kernel2/src/notifier.c b/src/kernel/src/notifier.c
similarity index 100%
rename from src/kernel2/src/notifier.c
rename to src/kernel/src/notifier.c
diff --git a/src/kernel/src/rpc.c b/src/kernel/src/rpc.c
deleted file mode 100644
index 45887e13..00000000
--- a/src/kernel/src/rpc.c
+++ /dev/null
@@ -1,343 +0,0 @@
-/*  
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */  
-
-#include <stdint.h>
-
-#include "rpc.h"
-#include "tasks.h"
-#include "paging.h"
-#include "vmm.h"
-#include "kmm.h"
-#include "intr.h"
-#include "string.h"
-#include "stdlib.h"
-#include "debug.h"
-
-typedef struct {
-    uint32_t   old_eip;
-    uint32_t   old_esp;
-    uint32_t   eflags;
-    uint32_t   eax;
-
-    uint32_t   reenable_irq;
-
-    struct task* caller;
-} rpc_t;
-
-/**
- * F�hrt einen RPC durch.
- *
- * Der Aufruf einer RPC-Funktion besteht im allgemeinen aus Metadaten (z.B.
- * die Funktionsnummer der aufzurufenden Funktion, Nachrichten-ID usw.)
- * und Nutzdaten.
- *
- * Die Daten werden dem aufgerufenen Task so auf den Stack gelegt, da� von
- * esp bis esp + metadata_size die Metadaten liegen, von esp + metadata_size
- * bis esp + metadata_size + data_size die Nutzdaten. Daraus ergibt sich
- * insbesondere, da� sich die Grenze zwischen Metadaten und Daten beliebig 
- * ziehen l��t, wie sie f�r den Aufrufer am g�nstigsten ist. Unter anderem ist
- * es m�glich, alle Daten an einem Ort zu �bergeben und metadata_size = 0 zu
- * setzen.
- *
- * Im Allgemeinen liegen allerdings die Metadaten auf dem Stack des Aufrufers,
- * w�hrend die Nutzdaten oft ein Pointer in den Heap des Aufrufers sind.
- *
- * Zur Durchf�hrung eines RPC werden zun�chst einige Register des aufgerufenen
- * Tasks gesichtert (eax, eip, esp, eflags; die �brigen Register hat der
- * aufgerufene Task selbst zu sichern). Anschlie�end werden die Daten auf den
- * Stack des aufgerufenen Tasks gelegt, eip auf den RPc-Handler gesetzt und der
- * Scheduler angewiesen, zum aufgerufenen Task umzuschalten.
- *
- * Der RPC-Handler mu� als letzte Aktion den Syscall FASTRPC_RET aufrufen, der
- * die Register wiederherstellt und dadurch den R�cksprung vornimmt.
- *
- * @param callee        Aufzurufender Task
- * @param metadata_size L�nge der Metadaten in Bytes
- * @param metadata      Pointer auf die Metadaten
- * @param data_size     L�nger der Daten in Bytes
- * @param data          Pointer auf die Daten
- *
- * @return true, wenn der Aufruf erfolgreich durchgef�hrt wurde, false
- * sonst. Bei false als R�ckgabe sollte der aufrufende Task den RPC-Syscall
- * wiederholen.
- */
-bool fastrpc(struct task * callee, uint32_t metadata_size, void* metadata,
-    uint32_t data_size, void* data)
-{
-    int i;
-
-    //kprintf("[%d => %d, 0x%x + 0x%x]\n", current_task->pid, callee->pid, 
-    //    metadata_size, data_size);
-    //kprintf("<%08x = %08x %08x>\n", metadata, 0, 0);
-    
-    if (!callee) {
-        abort_task("RPC zu nicht vorhandenem Prozess");
-        return false;
-    }
-
-    if (metadata_size + data_size > 9 * PAGE_SIZE) {
-        abort_task("RPC-Datenblock zu gross: %d Bytes", data_size);
-        return false;
-    }
-    
-    if (callee->rpc_handler == NULL) {
-        return false;
-    }
-
-    // Gesamtgr��e, um die der Stack des aufgerufenen Prozesses vergr��ert
-    // wird (zus�tzlich 4 Bytes f�r die R�cksprungadresse)
-    uint32_t total_data_size = metadata_size + data_size
-        + sizeof(data_size) + sizeof(pid_t);
-    
-    // Datengr��e auf ganze vier Bytes aufrunden
-    uint32_t rounded_data_size = (total_data_size + 3) & ~0x3;
-
-    // Wenn es sich um eine Antwort im Rahmen von asynchronem RPC handelt,
-    // durchlassen, auch wenn der Proze� nicht blockiert werden kann
-    bool ignore_blocked = false;
-    if ((callee->status == TS_WAIT_FOR_RPC) && (
-                ((metadata_size >= 4) 
-            &&  (((uint32_t*)metadata)[0] == 513))
-
-        ||      ((metadata_size == 0) 
-            &&  (data_size >= 4) 
-            &&  (((uint32_t*)data)[0] == 513))
-        ))
-    {
-        ignore_blocked = true;
-    }
-
-    // W�hrend wir am Stack rumbasteln, sollte niemand dazwischenfunken und
-    // erst recht nicht der Task weiterlaufen (momentan unn�tig, da im Kernel
-    // keine Interrupts erlaubt sind). Au�erdem wird damit sichergestellt, da�
-    // ein Task, der p() aufgerufen hat, keinen RPC bekommt.
-    //
-    // Wenn der Task nicht blockiert werden kann, soll der Aufrufer es sp�ter
-    // nochmal versuchen.
-    if (!ignore_blocked && 
-        ((callee->blocked_by_pid) || !block_task(callee, current_task->pid)))
-    {
-        //kprintf("Task %d ist blockiert.\n", callee->pid);
-        return false;
-    }
-    
-    // Falls der Stack nicht ausreicht, vergr��ern
-    paddr_t callee_isf_phys = 
-        resolve_vaddr((page_directory_t) callee->cr3, (vaddr_t) callee->esp);
-
-    struct int_stack_frame* callee_isf = (struct int_stack_frame*) 
-        map_phys_addr(callee_isf_phys, sizeof(callee_isf));
-    
-    uint32_t pages_count = ((rounded_data_size + PAGE_SIZE - 1) / PAGE_SIZE);
-    if ((rounded_data_size % PAGE_SIZE) > (callee_isf->esp % PAGE_SIZE)) {
-        pages_count++;
-    }
-
-	if(resolve_vaddr((page_directory_t) callee->cr3,
-        (vaddr_t) callee_isf->esp - rounded_data_size) == (paddr_t) NULL)
-	{
-        // TODO Das k�nnte bis zu (pages_count - 1) Pages zu viel reservieren
-		increase_user_stack_size(callee, pages_count);
-	}
-    
-    // Den Stack des aufgerufenen Tasks in den Kernelspeicher mappen
-    uint32_t callee_esp_phys = (uint32_t) resolve_vaddr(
-        (page_directory_t) callee->cr3, (vaddr_t) callee_isf->esp);
-   
-    // TODO Funktion, um komplette Bereiche eines anderen Tasks zu mappen
-    vaddr_t callee_esp_kernel_pages = 
-        find_contiguous_kernel_pages(pages_count);
-
-    for (i = 0; i < pages_count; i++) {
-        map_page(
-            kernel_page_directory, 
-            (vaddr_t) ((uint32_t) callee_esp_kernel_pages + (PAGE_SIZE * i)),
-            (paddr_t) PAGE_ALIGN_ROUND_DOWN((uint32_t) resolve_vaddr(
-                (page_directory_t) callee->cr3, 
-                (vaddr_t) callee_isf->esp - (PAGE_SIZE * (pages_count - i - 1))
-            )),
-            PTE_P | PTE_W
-        );
-    }
-
-    // RPC-Backlinkinformation anlegen
-    rpc_t* rpc = malloc(sizeof(rpc_t));
-    
-    rpc->old_eip = callee_isf->eip;
-    rpc->old_esp = callee_isf->esp;
-    rpc->eax     = callee_isf->eax;
-    rpc->eflags  = callee_isf->eflags;
-    rpc->caller  = current_task;
-
-    rpc->reenable_irq = 0;
-
-    list_push(callee->rpcs, rpc);
-    
-    // Adresse des neuen Stackendes im Kernelspeicher berechnen. Diese Adresse
-    // liegt irgendwo in der Mitte der ersten gemappten Stackpage. Das Offset
-    // von der Pagegrenze ist also in der Rechnung zu ber�cksichtigen.
-    //
-    // Auf den Stack kommen neue Daten der Gr��e rounded_data_size.
-    vaddr_t callee_esp = callee_esp_kernel_pages
-        + (callee_esp_phys % PAGE_SIZE) + ((pages_count - 1) * PAGE_SIZE);
-
-    callee_esp -= rounded_data_size;
-
-    // Kopieren der Datengr��e, der Aufrufer-PID und der Daten auf den Stack
-    *((uint32_t *) callee_esp) = data_size + metadata_size;
-    *((uint32_t *) (callee_esp + 4)) = current_task->pid;
-    memcpy(callee_esp + 8, metadata, metadata_size);
-    memcpy(callee_esp + 8 + metadata_size, data, data_size);
-    
-    // Den Stackpointer des aufgerufenen Tasks anpassen, so da� er auf den 
-    // Anfang der kopierten Daten zeigt, und in den RPC-Handler springen
-    callee_isf->esp -= rounded_data_size;
-    callee_isf->eip = (uint32_t) callee->rpc_handler;
-
-    // Gemappte Seiten wieder freigeben
-    for (i = 0; i < pages_count; i++) {
-        unmap_page(kernel_page_directory, 
-            (vaddr_t) ((uint32_t) callee_esp_kernel_pages + (PAGE_SIZE * i)));
-    }
-
-    unmap_page(kernel_page_directory, 
-        (vaddr_t) PAGE_ALIGN_ROUND_DOWN((uint32_t) callee_isf));
-   
-    // Der Task darf wieder laufen
-    if (callee->status == TS_WAIT_FOR_RPC) {
-        callee->status = TS_RUNNING;
-    }
-
-    if (!ignore_blocked) {
-        //kprintf("PID %d darf wieder laufen.\n", callee->pid);
-        unblock_task(callee, current_task->pid);
-    }
-
-    return true;
-}
-
-/**
- * F�hrt einen RPC zur Behandlung eines IRQ durch. Der IRQ wird dabei
- * deaktiviert, solange der Handler arbeitet und erst anschlie�end 
- * wieder freigegeben. Im sonstigen Verhalten gleicht diese Funktion
- * fastrpc.
- *
- * @see fastrpc
- */
-bool fastrpc_irq(struct task * callee, uint32_t metadata_size, void* metadata,
-    uint32_t data_size, void* data, uint8_t irq)
-{
-    if (callee->blocked_by_pid && (callee->status != TS_WAIT_FOR_RPC)) {
-        return false;
-    }
-
-    if (fastrpc(callee, metadata_size, metadata, data_size, data)) {
-        rpc_t* rpc = list_get_element_at(current_task->rpcs, 0);
-        rpc->reenable_irq = irq;
-        return true;
-    } else {
-        return false;
-    }
-}
-
-/**
- * Wird nach der Ausf�hrung eines RPC-Handlers aufgerufen.
- *
- * Nach der R�ckkehr vom RPC-Handler wird der neueste Zustand vom RPC-Stack
- * gepopt und zur Wiederherstellung des urspr�nglichen Prozessorzustands
- * benutzt.
- *
- * Dies betrifft eip, esp, eax und eflags. Die �brigen Register sind vom
- * RPC-Handler zu sicher und vor dem Aufruf von SYSCALL_FASTRPC_RET
- * wiederherzustellen. eax ist davon ausgenommen, da es die Funktionsnummer
- * des Syscalls enthalten mu�.
- *
- * @param esp Interrupt-Stackframe des vom RPC-Handler zur�ckkehrenden Tasks
- */
-void return_from_rpc(struct int_stack_frame ** esp)
-{
-    rpc_t* rpc = list_pop(current_task->rpcs);
-    struct int_stack_frame* callee_isf = *esp;
-
-    // Wenn der Task vom RPC-Handler zur�ckkehrt, obwohl der Handler
-    // gar nicht aufgerufen wurde, l�uft was schief
-    if (rpc == NULL) {
-        if(debug_test_flag(DEBUG_FLAG_STACK_BACKTRACE)) {
-            stack_backtrace_ebp(callee_isf->ebp, callee_isf->eip);
-        }
-        abort_task("Unerwartete Rueckkehr vom RPC-Handler");
-    }
-    
-    // Wiederherstellen der Register
-    callee_isf->eip = rpc->old_eip; 
-    callee_isf->esp = rpc->old_esp;
-    callee_isf->eax = rpc->eax; 
-    callee_isf->eflags = rpc->eflags;
-
-    // Wechsel zum aufrufenden Task
-    if (rpc->caller) {
-        schedule_to_task(rpc->caller, (uint32_t*) esp);
-    }
-
-    // Wenn es ein IRQ-verarbeitender RPC war, den Interrupt jetzt
-    // wieder aktivieren
-    if (rpc->reenable_irq) {
-        //printf("reenable IRQ %d\n", rpc->reenable_irq);
-        enable_irq(rpc->reenable_irq);
-    }
-
-    free(rpc);
-}
-
-/**
- * Entfernt den gegebenen Task aus allen RPC-Backlinks.
- *
- * Diese Funktion wird benoetigt, wenn ein Task einen RPC aufruft und beendet
- * wird, bevor der RPC fertig ist. Ansonsten zeigt rpc->caller ins Leere,
- * was in return_from_rpc() zur Katastrophe f�hrt.
- */
-void rpc_destroy_task_backlinks(struct task* destroyed_task)
-{
-    struct task* task;
-    for (task = first_task; task != NULL; task = task->next_task) {
-        int i;
-        rpc_t* rpc;
-        for (i = 0; (rpc = list_get_element_at(task->rpcs, i)); i++) {
-            if (rpc->caller == destroyed_task) {
-                rpc->caller = NULL;
-            }
-        }
-    }
-}
diff --git a/src/kernel/src/schedule.c b/src/kernel/src/schedule.c
deleted file mode 100644
index 725dd9a6..00000000
--- a/src/kernel/src/schedule.c
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Burkhard Weseloh.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <lost/config.h>
-#include "types.h"
-#include "string.h"
-#include "stdlib.h"
-#include <stdint.h>
-
-#include "kernel.h"
-#include "intr.h"
-#include "tasks.h"
-#include "tss.h"
-#include "kprintf.h"
-#include "timer.h"
-
-struct task* first_task = NULL;
-struct task* current_task = NULL;
-int num_tasks;
-int current_task_num;
-
-/** Einheit: Mikrosekunden */
-uint64_t timer_ticks = 0;
-
-
-void set_io_bitmap(void);
-
-/**
- * Wird bei Kooperativem Multitasking benutzt zum handeln des Timers
- */
-void do_nothing(void) {}
-
-
-/**
- * Timer interrupt
- * @param irq IRQ-Nummer
- * @param esp Pointer auf Stackpointer
- */
-void timer_irq(int irq, uint32_t* esp)
-{
-    timer_ticks += 1000000 / CONFIG_TIMER_HZ;
-
-    //Ueberpruefen, ob der aktuelle Task alle seine Zeit verbraucht hat. Wenn
-    // ja, wird ein neuer Task ausgewaehlt
-    #ifndef CONFIG_COOPERATIVE_MULTITASKING
-    if ((current_task == NULL) ||
-        (--(current_task->schedule_ticks_left) >= 0))
-    {
-        schedule(esp);
-    }
-    #else
-    if (current_task == NULL) {
-        schedule(esp);
-    }
-    #endif
-
-
-    // Ueberpruefen, ob ein Timer abgelaufen ist.
-    // Dies muss nach dem schedule() kommen, da der Timer mit current_task ==
-    // NULL nicht zurechtkommt.
-    timer_notify(timer_ticks);
-}
-
-
-/**
- * Naechsten Task auswaehlen der ausgefuehrt werden soll
- * @param esp Pointer auf Stackpointer
- */
-void schedule(uint32_t* esp)
-{
-    if(first_task == NULL) {
-        panic("Taskliste leer!");
-    }
-
-    if (current_task != NULL) {
-        //kprintf("\nSwitch from %d", current_task->pid);
-        current_task->esp = *esp;
-    } else {
-        current_task = first_task;
-    }
-
-    struct task* old_task = current_task;
-
-    do {
-        current_task = current_task->next_task;
-        
-        if(current_task == NULL) {
-            current_task = first_task;
-        }
-
-        if (current_task == old_task) {
-            kprintf("%");
-            break;
-        }
-
-    } while(((current_task->blocked_by_pid) 
-        && (current_task->blocked_by_pid != current_task->pid))
-        || (current_task->status != TS_RUNNING)
-    );
-    
-    // Damit der Task die Zeit nicht beliebig hochspielen kann
-    if (current_task->schedule_ticks_left > current_task->schedule_ticks_max) {
-        current_task->schedule_ticks_left = current_task->schedule_ticks_max;
-    }
-
-    // Hier wird die CPU-Zeit berechnet, die der Task benutzen darf
-    // Diese wird folgendermassen berechnet:
-    // Benutzbare Ticks = Maximale Ticks + (Uebrige Ticks vom letzten Mal) / 2
-    current_task->schedule_ticks_left = current_task->schedule_ticks_max +
-        current_task->schedule_ticks_left / 2;
-
-    //kprintf("\nSwitch to %d", current_task->pid);
-    *esp = current_task->esp;
-
-    // Wenn der Task auf einen Port zugreift, fliegt ein GPF.
-    // Wir haben dann immer noch Zeit, die IO-Bitmap zu kopieren.
-    tss.io_bit_map_offset = TSS_IO_BITMAP_NOT_LOADED;
-}
-
-void schedule_to_task(struct task* target_task, uint32_t* esp)
-{
-    if ((target_task != NULL) && ((!target_task->blocked_by_pid) || (target_task->blocked_by_pid == target_task->pid))) {
-        current_task->esp = *esp;
-        current_task = target_task;
-        *esp = current_task->esp;
-        
-        tss.io_bit_map_offset = TSS_IO_BITMAP_NOT_LOADED;
-    }
-}
-
-void set_io_bitmap()
-{
-    tss.io_bit_map_offset = TSS_IO_BITMAP_OFFSET;
-
-    if (current_task->io_bitmap) {
-        memcpy(tss.io_bit_map, current_task->io_bitmap, IO_BITMAP_LENGTH / 8);
-    } else {
-        memset(tss.io_bit_map, 0xff, IO_BITMAP_LENGTH / 8);
-    }
-}
-
-/**
- * Initialisiert das Multitasking
- */
-void init_scheduler(void)
-{
-    request_irq(0, timer_irq);
-    
-    num_tasks = 0;
-    current_task = NULL;
-    first_task = NULL;
-    
-    uint16_t reload_value = 1193182 / CONFIG_TIMER_HZ;
-    // Timer umprogrammieren
-    asm(
-        "movb $0x34, %%al;"
-        "outb %%al, $0x43;"
-        "movw %0, %%ax;"
-        "outb %%al, $0x40;"
-        "movb %%ah, %%al;"
-        "outb %%al, $0x40"
-        : : "b" (reload_value) : "eax");
-}
diff --git a/src/kernel2/src/smp/Makefile.conf b/src/kernel/src/smp/Makefile.conf
similarity index 100%
rename from src/kernel2/src/smp/Makefile.conf
rename to src/kernel/src/smp/Makefile.conf
diff --git a/src/kernel2/src/smp/rm_trampoline.asm b/src/kernel/src/smp/rm_trampoline.asm
similarity index 100%
rename from src/kernel2/src/smp/rm_trampoline.asm
rename to src/kernel/src/smp/rm_trampoline.asm
diff --git a/src/kernel2/src/smp/smp.c b/src/kernel/src/smp/smp.c
similarity index 100%
rename from src/kernel2/src/smp/smp.c
rename to src/kernel/src/smp/smp.c
diff --git a/src/kernel/src/stubs.asm b/src/kernel/src/stubs.asm
deleted file mode 100644
index 681baee5..00000000
--- a/src/kernel/src/stubs.asm
+++ /dev/null
@@ -1,145 +0,0 @@
-;

-; Copyright (c) 2006 The tyndur Project. All rights reserved.

-;

-; This code is derived from software contributed to the tyndur Project

-; by Burkhard Weseloh.

-;

-; Redistribution and use in source and binary forms, with or without

-; modification, are permitted provided that the following conditions

-; are met:

-; 1. Redistributions of source code must retain the above copyright

-;    notice, this list of conditions and the following disclaimer.

-; 2. 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.

-; 3. All advertising materials mentioning features or use of this software

-;    must display the following acknowledgement:

-;     This product includes software developed by the tyndur Project

-;     and its contributors.

-; 4. Neither the name of the tyndur Project nor the names of its

-;    contributors may be used to endorse or promote products derived

-;    from this software without specific prior written permission.

-;

-; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

-; ``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 COPYRIGHT HOLDERS OR

-; CONTRIBUTORS 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.

-;

-

-section .text

-

-%define IRQ_BASE 0x20

-

-extern handle_int

-

-%macro exception_stub 1

-global exception_stub_%1

-exception_stub_%1:

-	push dword 0

-	push dword %1

-	jmp int_bottom

-%endmacro

-

-%macro exception_stub_error_code 1

-global exception_stub_%1

-exception_stub_%1:

-	push dword %1

-	jmp int_bottom

-%endmacro

-

-%macro irq_stub 1

-global irq_stub_%1

-irq_stub_%1:

-	push dword 0

-	push dword %1 + IRQ_BASE

-	jmp int_bottom

-%endmacro

-

-global null_handler

-null_handler:

-	push dword 0

-	push dword 0x1337

-	jmp int_bottom

-

-global syscall_stub

-syscall_stub:

-  push dword 0

-  push dword 0x30

-	jmp int_bottom

-

-exception_stub 0

-exception_stub 1

-exception_stub 2

-exception_stub 3

-exception_stub 4

-exception_stub 5

-exception_stub 6

-exception_stub 7

-exception_stub_error_code 8

-exception_stub 9

-exception_stub_error_code 10

-exception_stub_error_code 11

-exception_stub_error_code 12

-exception_stub_error_code 13

-exception_stub_error_code 14

-exception_stub 16

-exception_stub_error_code 17

-exception_stub 18

-exception_stub 19

-

-irq_stub 0

-irq_stub 1

-irq_stub 2

-irq_stub 3

-irq_stub 4

-irq_stub 5

-irq_stub 6

-irq_stub 7

-irq_stub 8

-irq_stub 9

-irq_stub 10

-irq_stub 11

-irq_stub 12

-irq_stub 13

-irq_stub 14

-irq_stub 15

-

-int_bottom:

-	; register sichern

-	pusha

-	push ds

-	push es

-	push fs

-	push gs

-

-	; ring 0 segment register laden

-	cld

-	mov ax, 0x10

-	mov ds, ax

-	mov es, ax

-

-	; c-handler aufrufen

-	push esp

-	call handle_int

-	add esp, 4

-

-	; den stack wechseln

-	mov esp, eax

-	

-	; register laden

-	pop gs

-	pop fs

-	pop es

-	pop ds

-	popa

-

-	add esp, 8 ; fehlercode und interrupt nummer �berspringen

-

-	iret

diff --git a/src/kernel/src/syscall.c b/src/kernel/src/syscall.c
index 5a69af10..f74dbebe 100644
--- a/src/kernel/src/syscall.c
+++ b/src/kernel/src/syscall.c
@@ -1,8 +1,8 @@
-/*  
- * Copyright (c) 2006 The tyndur Project. All rights reserved.
+/*
+ * Copyright (c) 2007 The tyndur Project. All rights reserved.
  *
  * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
+ * by Antoine Kaufmann.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -20,766 +20,161 @@
  *    contributors may be used to endorse or promote products derived
  *    from this software without specific prior written permission.
  *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS 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 
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */  
+ */
 
+#include <types.h>
 #include <stdint.h>
-#include <stdbool.h>
-#include <errno.h>
 
-#include "console.h"
 #include "syscall.h"
-#include "kprintf.h"
-#include "vmm.h"
-#include "paging.h"
-#include "phys.h"
-#include "kernel.h"
-#include "string.h"
-#include "kmm.h"
-#include "tasks.h"
-#include "stdlib.h"
-#include "intr.h"
-#include <lost/config.h>
-#include "rpc.h"
-#include "io.h"
-#include "debug.h"
-#include "syscall_structs.h"
-#include "timer.h"
-#include "shm.h"
-#include "vm86.h"
-
-extern void timer_irq(int irq, uint32_t* esp);
-extern uint64_t timer_ticks;
+#include "syscallno.h"
 
-extern void set_io_bitmap(void);
+#include "kernel.h"
 
-#ifdef CONFIG_DEBUG_LAST_SYSCALL
-uint32_t debug_last_syscall_no = 0;
-pid_t debug_last_syscall_pid = 0;
-uint32_t debug_last_syscall_data[DEBUG_LAST_SYSCALL_DATA_SIZE] = { 0 };
-#endif 
+syscall_t syscalls[SYSCALL_MAX];
 
-void syscall(struct int_stack_frame ** esp) 
+/**
+ * Die Syscalls initialisieren.
+ */
+void syscall_init()
 {
-    struct int_stack_frame * isf = *esp;
-
-    #ifdef CONFIG_DEBUG_LAST_SYSCALL
-    {
-        uint32_t i;
-        debug_last_syscall_no = isf->eax;
-        debug_last_syscall_pid = current_task->pid;
-        for (i = 0; i < DEBUG_LAST_SYSCALL_DATA_SIZE; i++) {
-            debug_last_syscall_data[i] = *(((uint32_t*)isf->esp) + i);
-        }
-    }
-    #endif 
-
-    
-    if (debug_test_flag(DEBUG_FLAG_SYSCALL)) {
-        kprintf("[PID %d] Syscall:%d\n", current_task->pid, isf->eax);
-        io_ports_check(current_task);
-    }
-        
-    // FIXME: Adressen, die vom aufrufenden Programm kommen, 
-    // vor der Verwendung pr�fen
-    switch (isf->eax) {
-        case SYSCALL_PUTSN:
-        {
-            unsigned int n = *((int*) isf->esp);
-            char * s = *((char**) (isf->esp + 4));
-
-            if(n == -1)
-            {
-                con_puts(s);
-            }
-            else
-            {
-                con_putsn(n, s);
-            }
-            break;
-        }
-
-        case SYSCALL_MEM_ALLOCATE:
-        {
-            uint32_t num;
-            uint32_t flags;
-
-            paddr_t paddr;
-            vaddr_t vaddr;
-
-            num = PAGE_ALIGN_ROUND_UP(*((size_t*) isf->esp)) >> 12;
-            flags = *((uint32_t*) (isf->esp + 4));
-            paddr_t* phys = *((paddr_t**) (isf->esp + 8));
-            (void) flags;
-            //kprintf("\nMEM_ALLOCATE: PID %d: alloc %d Pages, flags %x\n", current_task->pid, num, flags);
-            //stack_backtrace_ebp(isf->ebp, isf->eip);
-            
-            // TODO: Flags ber�cksichtigen
-            vaddr = find_contiguous_pages((page_directory_t) current_task->cr3, num, USER_MEM_START, USER_MEM_END);
-            isf->eax = (uint32_t) vaddr;
-            
-            current_task->memory_used += num << 12;
-
-            //DMA-Page
-            if((flags & 0x80) != 0)
-            {
-                paddr = phys_alloc_dma_page_range_64k(num);
-               
-                //Bei DMA-Pages die phys. Adresse in ebx speichern
-                *phys = paddr;
-                if (!map_page_range((page_directory_t) current_task->cr3, vaddr, paddr, PTE_P | PTE_U | PTE_W, num))
-                {
-                    panic("Fehler beim Zuweisen der reservierten DMA-Speicherseite %x", vaddr);
-                }
-
-                //kprintf("DMA-Adresse: phys 0x%08x, virt %08x\n", isf->ebx, isf->eax);
-            }
-            else
-            {
-                while(num--)
-                {
-                    paddr = phys_alloc_page();
-                    *phys = (paddr_t) NULL;
-                    
-                    if (!map_page((page_directory_t) current_task->cr3, vaddr, paddr, PTE_P | PTE_U | PTE_W))
-                    {
-                        panic("Fehler beim Zuweisen der reservierten Speicherseite %x", vaddr);
-                    }
-                    vaddr += PAGE_SIZE;
-                }
-            }
-            
-            break;
-        }
-
-        case SYSCALL_MEM_ALLOCATE_PHYSICAL:
-        {
-            uint32_t num;
-            paddr_t position;
-            uint32_t flags;
-
-            vaddr_t vaddr;
-            num = PAGE_ALIGN_ROUND_UP(*((size_t*) isf->esp)) >> 12;
-            //TODO: Position entsprechend den Pages abrunden
-            position = *((paddr_t*) (isf->esp + 4));
-            flags = *((uint32_t*) (isf->esp + 8));
-            (void) flags;
-            // Speicher an der physikalischen Position einfach an eine freie
-            // Position mappen
-            vaddr = find_contiguous_pages((page_directory_t) current_task->cr3,
-                num, USER_MEM_START, USER_MEM_END);
-            isf->eax = (uint32_t) vaddr;
-
-            current_task->memory_used += num << 12;
-            
-            //TODO: Speicher als benutzt markieren?
-            //Nur nicht freien (=unnereichbaren) Speicher benutzen?
-            if (!map_page_range((page_directory_t) current_task->cr3, vaddr,
-                position, PTE_P | PTE_U | PTE_W, num)) {
-                panic("Fehler beim Zuweisen des Speichers %x", vaddr);
-            }
-            break;
-        }
-
-        
-        case SYSCALL_MEM_FREE:
-        {
-            vaddr_t address = *((vaddr_t*) isf->esp);
-            uint32_t pages = PAGE_ALIGN_ROUND_UP(*((size_t*) (isf->esp + 4))) >> PAGE_SHIFT;
-            
-            //kprintf("\nMEM_FREE: PID %d: free  %x Pages @ 0x%x\n", current_task->pid, pages, address);
-            
-            current_task->memory_used -= pages << 12;
-
-            if((uint32_t)address % PAGE_SIZE != 0)
-            {
-                if (debug_test_flag(DEBUG_FLAG_PEDANTIC)) {
-                    abort_task("SYSCALL_MEM_FREE: Der Task versucht eine "
-                        "nicht ausgerichtete Adresse freizugeben: 0x%08x", 
-                        address);
-                }
-                isf->eax = false;
-                break;
-            }
-
-            if (!is_userspace(address, pages * PAGE_SIZE)) 
-            {
-                if (debug_test_flag(DEBUG_FLAG_PEDANTIC)) {
-                    abort_task("SYSCALL_MEM_FREE: Der Task versucht eine "
-                        "Adresse freizugeben, die nicht fuer ihn reserviert "
-                        "ist: 0x%08x (+0x%x)", address, pages * PAGE_SIZE);
-                }
-                isf->eax = false;
-                break;
-            }
-
-            for (; pages; pages--) {
-                paddr_t paddress = resolve_vaddr((page_directory_t) current_task->cr3, address);
-
-                if(unmap_page((page_directory_t) current_task->cr3, address) != true)
-                {
-                    abort_task("SYSCALL_MEM_FREE: Die Speicherseite konnte nicht freigegeben werden: 0x%08x", address);
-                }
-                else
-                {
-                    phys_mark_page_as_free(paddress);
-                }
-
-                address += PAGE_SIZE;
-            }
-
-            isf->eax = true;
-            break;
-        }
-        
-        case SYSCALL_MEM_FREE_PHYSICAL:
-        {
-            vaddr_t address = *((vaddr_t*) isf->esp);
-            uint32_t pages = PAGE_ALIGN_ROUND_UP(*((size_t*) (isf->esp + 4))) >> PAGE_SHIFT;
-            current_task->memory_used -= pages << 12;
-            if((uint32_t)address % PAGE_SIZE != 0)
-            {
-                abort_task("SYSCALL_MEM_FREE_PHYSICAL: Der Task versucht eine nicht ausgerichtete Adresse freizugeben: 0x%08x", address);
-            }
-
-            for (; pages; pages--) {
-                //paddr_t paddress = resolve_vaddr((page_directory_t) current_task->cr3, address);
-
-                if(unmap_page((page_directory_t) current_task->cr3, address) != true)
-                {
-                    abort_task("SYSCALL_MEM_FREE_PHYSICAL: Die Speicherseite konnte nicht freigegeben werden: 0x%08x", address);
-                }
-                //FIXME: Speicher freigeben?
-
-                address += PAGE_SIZE;
-            }
-
-            break;
-        }
-        
-        case SYSCALL_MEM_RESOLVE_VADDR:
-        {
-            vaddr_t address = *((vaddr_t*) isf->esp);
-            if (is_userspace(address, 1)) {
-                isf->eax = (uint32_t) resolve_vaddr(current_task->cr3, address);
-            } else {
-                isf->eax = 0;
-            }
-
-            break;
-        }
-
-        
-        case SYSCALL_MEM_INFO:
-        {
-            isf->eax = phys_count_pages() * PAGE_SIZE;
-            isf->edx = phys_count_free_pages() *PAGE_SIZE;
-
-            break;
-        }
-        
-        case SYSCALL_SHM_CREATE:
-        {
-            uint32_t size = *((uint32_t*) isf->esp);
-            isf->eax = create_shared_memory(size);
-            break;
-        }
-
-        case SYSCALL_SHM_ATTACH:
-        {
-            uint32_t id = *((uint32_t*) isf->esp);
-            isf->eax = (uint32_t)attach_task_to_shm(current_task, id);
-            break;
-        }
-
-        case SYSCALL_SHM_DETACH:
-        {
-            uint32_t id = *((uint32_t*) isf->esp);
-            detach_task_from_shm(current_task, id);
-            break;
-        }
-
-        case SYSCALL_PM_REQUEST_PORT:
-        {
-            uint32_t port = *((uint32_t*) isf->esp);
-            uint32_t length = *((uint32_t*) (isf->esp + 4));
-
-            isf->eax = io_ports_request(current_task, port, length);
-
-            set_io_bitmap();
-            break;
-        }
-
-        case SYSCALL_PM_RELEASE_PORT:
-        {
-            uint32_t port = *((uint32_t*) isf->esp);
-            uint32_t length = *((uint32_t*) (isf->esp + 4));
-
-            isf->eax = true;
-            if (!io_ports_release(current_task, port, length)) 
-            {
-                if (debug_test_flag(DEBUG_FLAG_PEDANTIC)) {
-                    abort_task("Freigab eines nicht reservierten Ports (port: 0x%x, Laenge 0x%x)", port, length);
-                }
-
-                isf->eax = false;
-            }
-
-            set_io_bitmap();
-            break;
-        }
-
-        case SYSCALL_PM_CREATE_PROCESS:
-        {
-            //TODO: Die UID irgendwie verwerten
-            //uid_t uid = *((uid_t*) isf->esp + 4);
-            
-            pid_t parent_pid = *((pid_t*)((uint32_t)isf->esp + 12));
-            void* eip = *((void**) isf->esp);
-            const char* cmdline = *((const char**) ((uint32_t)isf->esp + 8));
-
-            struct task* new_task = create_task(eip, cmdline, parent_pid);
-
-            new_task->blocked_by_pid = current_task->pid;
-            isf->eax = new_task->pid;
-            break;
-        }
-        case SYSCALL_PM_INIT_PAGE:
-        {
-            struct task* new_task = get_task(*((pid_t*) isf->esp));
-            
-            if((new_task == NULL) || (new_task->blocked_by_pid != current_task->pid)) 
-            {
-                abort_task("SYSCALL_PM_INIT_PAGE: Der Aufrufer hat eine ungueltige PID angegeben: %d", *((pid_t*) isf->esp));
-            }
-
-            int num = PAGE_ALIGN_ROUND_UP(*((size_t*) (isf->esp + 12))) >> 12;
-            vaddr_t dest = (vaddr_t) PAGE_ALIGN_ROUND_DOWN(*((size_t*) (isf->esp + 4)));
-            vaddr_t src = (vaddr_t) PAGE_ALIGN_ROUND_DOWN(*((size_t*) (isf->esp + 8)));
-            
-            if (dest == NULL) {
-                abort_task("SYSCALL_PM_INIT_PAGE: Versuchtes NULL-Mapping: src = 0x%08x", src);
-            }
-            
-            current_task->memory_used -= num * PAGE_SIZE;
-            //kprintf("Map psrc:%x    src:%x    dest:%x   size:%x\n", resolve_vaddr((page_directory_t) current_task->cr3, src), src, dest, num << 12);
-            
-            /*{
-                uint32_t i;
-                for (i = 0; i < num; i++)
-                    kprintf("[%08x %08x]\n", *((uint32_t*) (src + 0x1000*i)), *((uint32_t*) (src + 0x1000*i + 4)));
-            }*/
-
-            // Das PD-des neuen tasks mappen
-            page_directory_t new_task_pd = new_task->cr3;
-            
-            // An dieser Stelle kann kein map_page_range benutzt werden, da
-            // der Speicher nur virtuell, aber nicht unbedingt physisch
-            // zusammenh�ngend sein mu�.
-            while(num--) {
-                if (!resolve_vaddr(new_task_pd, dest)) {
-                    if (!map_page(new_task_pd, dest, resolve_vaddr((page_directory_t) current_task->cr3, src), PTE_P | PTE_U | PTE_W)) {
-                        abort_task("SYSCALL_PM_INIT_PAGE: Fehler beim Zuweisen der reservierten Speicherseite %x  =>  %x", src, dest);
-                    }
-                } else {
-                    // FIXME: Hier muss was passieren. Kopieren?
-                }
-                
-                src += 0x1000;
-                dest += 0x1000;
-            }
-            
-            //free_phys_addr((vaddr_t)new_task_pd, PAGE_DIRECTORY_LENGTH);
-            break;
-        }
-        case SYSCALL_PM_INIT_PAGE_COPY:
-        {
-            struct task* new_task = get_task(*((pid_t*) isf->esp));
-            
-            if((new_task == NULL) || (new_task->blocked_by_pid != current_task->pid)) 
-            {
-                abort_task("SYSCALL_PM_INIT_PAGE_COPY: Der Aufrufer hat eine ungueltige PID angegeben: %d", *((pid_t*) isf->esp));
-            }
-
-            int num = PAGE_ALIGN_ROUND_UP(*((size_t*) (isf->esp + 12))) >> 12;
-            vaddr_t dest = (vaddr_t) PAGE_ALIGN_ROUND_DOWN(*((size_t*) (isf->esp + 4)));
-            vaddr_t src = (vaddr_t) PAGE_ALIGN_ROUND_DOWN(*((size_t*) (isf->esp + 8)));
-            
-            if (dest == NULL) {
-                abort_task("SYSCALL_PM_INIT_PAGE_COPY: Versuchtes Kopieren nach NULL: src = 0x%08x", src);
-            }
-            
-            // Das PD-des neuen tasks mappen
-            page_directory_t new_task_pd = new_task->cr3;
-            
-            // Speicher wird kopiert, nicht gemappt.
-            while(num--) {
-                if (!resolve_vaddr(new_task_pd, dest)) {
-                    map_page(new_task_pd, dest, phys_alloc_page(), PTE_P | PTE_U | PTE_W);
-                }
-                
-                paddr_t phys_addr = resolve_vaddr(new_task_pd, dest);
-                char *destmem = find_contiguous_kernel_pages(1);
-                map_page(kernel_page_directory, destmem, phys_addr, PTE_P | PTE_W);
-                memcpy(destmem, src, 0x1000);
-                unmap_page(kernel_page_directory, destmem);
-                
-                src += 0x1000;
-                dest += 0x1000;
-            }
-            
-            break;
-        }
-        case SYSCALL_PM_EXIT_PROCESS:
-        {
-            struct task* old_task = current_task;
-            schedule((uint32_t*)esp);
-            destroy_task(old_task);
-            break;
-        }
-        
-        case SYSCALL_PM_SLEEP:
-            schedule((uint32_t*)esp);
-            break;
-        
-        case SYSCALL_PM_WAIT_FOR_RPC:
-            /*kprintf("Kernel: wait_for_rpc: PID %d an %08x\n", 
-                current_task->pid, 
-                isf->ebp >= 0x1000 ? *((uint32_t*) (isf->ebp  + 4)) : 0
-            );*/
-            current_task->status = TS_WAIT_FOR_RPC;
-            schedule((uint32_t*)esp);
-            break;
-                    
-        case SYSCALL_PM_V_AND_WAIT_FOR_RPC:
-            if(unblock_task(current_task, current_task->pid) == false)
-            {
-                abort_task("SYSCALL_PM_V_AND_WAIT_FOR_RPC: "
-                    "Der Task konnte nicht fortgesetzt werden");
-            }
-            /*kprintf("Kernel: v_and_wait_for_rpc: PID %d an %08x, blocked: %d\n",
-                current_task->pid, 
-                isf->ebp >= 0x1000 ? *((uint32_t*) (isf->ebp  + 4)) : 0,
-                current_task->blocked_count
-            );*/
-            current_task->status = TS_WAIT_FOR_RPC;
-            schedule((uint32_t*)esp);
-            break;
-
-        case SYSCALL_PM_GET_UID:
-            isf->eax = 0;
-            break;
-        
-        case SYSCALL_PM_GET_PID:
-            isf->eax = current_task->pid;
-            break;
-        
-        case SYSCALL_PM_GET_CMDLINE:
-        {   
-            vaddr_t vaddr = find_contiguous_pages((page_directory_t) current_task->cr3, 1, USER_MEM_START, USER_MEM_END);
-            paddr_t paddr = phys_alloc_page();
-            
-            if (!map_page((page_directory_t) current_task->cr3, vaddr, paddr, PTE_P | PTE_U | PTE_W))
-            {
-                panic("Fehler beim Zuweisen der reservierten Speicherseite %x", vaddr);
-            }
-
-            isf->eax = (uint32_t) vaddr;
-
-            memcpy((void*) vaddr, (void*)(current_task->cmdline), strlen(current_task->cmdline) + 1);
-            //kprintf("KERNEL return commmandline %s\n", current_task->cmdline);
-
-            break;
-        }
-
-        case SYSCALL_PM_GET_PARENT_PID:
-            // Eltern PID vom aktuellen Task
-            if (*((pid_t*) isf->esp) == 0) {
-                if (current_task->parent_task != NULL) {
-                    isf->eax = current_task->parent_task->pid;
-                } else {
-                    isf->eax = 0;
-                }
-            } else {
-                struct task* task = get_task(*((pid_t*) isf->esp));
-
-                if (task == NULL) {
-                    isf->eax = 0;
-                } else {
-                    if (task->parent_task == NULL) {
-                        isf->eax = 0;
-                    } else {
-                        isf->eax = task->parent_task->pid;
-                    }
-                }
-            }
-            break;
-        case SYSCALL_PM_ENUMERATE_TASKS:
-        {
-            // Erst werden die Tasks gezaehlt, und die Groesse der
-            // Informationen mit den Kommandozeilen wird errechnet.
-            size_t task_count = 0;
-            size_t result_size = sizeof(task_info_t);
-            struct task* task = first_task;
-            uint32_t i;
-
-            while (task != NULL) {
-                task_count++;
-                result_size += sizeof(task_info_task_t) + strlen(task->cmdline)
-                    + 1;
-                task = task->next_task;
-            }
-            
-            // Anzahl der Seiten berechnen, die die Informationen benoetigen.
-            size_t result_page_count = PAGE_ALIGN_ROUND_UP(result_size) /
-                PAGE_SIZE;
-
-            // Jetzt wird eine freie Stelle im Adressraum des Prozesses
-            // gesucht, wo die Task-Infos hingemappt werden koennen
-            task_info_t* task_info = find_contiguous_pages((page_directory_t)
-                current_task->cr3, result_page_count, USER_MEM_START,
-                USER_MEM_END);
-
-            // Ein paar Seite an die Stelle mappen
-            for (i = 0; i < result_page_count; i++) {
-                if (!map_page((page_directory_t) current_task->cr3, (void*)
-                    ((uint32_t)task_info + i * PAGE_SIZE), phys_alloc_page(), 
-                    PTE_P | PTE_U | PTE_W))
-                {
-                    panic("Fehler beim Zuweisen der reservierten "
-                        "Speicherseite %x", (uint32_t)task_info + i * PAGE_SIZE);
-                }
-            }
-            
-            // Der groessen-Eintrag ist nur da, damit der Tasks die Pages
-            // freigeben koennte.
-            task_info->info_size = result_size;
-
-            task_info->task_count = task_count;
-
-            // Dieser Pointer zeigt direkt hinter das Array mit den
-            // Task-Informationen. Dort werden die Kommandozeilen
-            // hintereinander gespeichert, und aus den Task-Strukturen wird auf
-            // sie verwiesen.
-            char* cmdlines = (char*) task_info->tasks;
-            cmdlines += task_count * sizeof(task_info_task_t);
-            
-            task = first_task;
-            // Jetzt werden die Infos eingefuellt.
-            for (i = 0; i < task_count; i++) {
-                task_info->tasks[i].pid = task->pid;
-                task_info->tasks[i].status = task->status;
-                task_info->tasks[i].eip = 
-                    ((struct int_stack_frame*) task->esp)->eip;
-
-                // Wenn der Task keinen Eltern-Task hat muessen wir aufpassen,
-                // damit wir keinen Pagefault produzieren.
-                if (task->parent_task == NULL) {
-                    task_info->tasks[i].parent_pid = 0;
-                } else {
-                    task_info->tasks[i].parent_pid = task->parent_task->pid;
-                }
-                
-                // Die Kommandozeile inklusive Nullbyte kopieren
-                size_t cmdline_size = strlen(task->cmdline) + 1;
-                memcpy(cmdlines, task->cmdline, cmdline_size);
-
-                // Den Pointer fuer die Kommandozeile setzen
-                task_info->tasks[i].cmdline = cmdlines;
-
-                // Den Zielpointer fuer die naechste Kommandozeile direkt
-                // hinter die aktuelle setzen.
-                cmdlines += cmdline_size;
-                
-                task_info->tasks[i].memory_used = task->memory_used;
-                task = task->next_task;
-            }
-            
-            // In eax wird ein Pointer auf die Daten zurueck gegeben
-            isf->eax = (uint32_t) task_info;
-
-            break;
-        }
-
-        case SYSCALL_PM_P:
-            /*kprintf("Kernel: p: PID %d an %08x => %d\n", 
-                current_task->pid, 
-                isf->ebp >= 0x1000 ? *((uint32_t*) (isf->ebp  + 4)) : 0,
-                current_task->blocked_count
-            );*/
-            if (!block_task(current_task, current_task->pid)) {
-                panic("Konnte Task nicht blockieren");
-            }
-            break;
-        
-        case SYSCALL_PM_V:
-        {
-            pid_t pid = *((pid_t*) isf->esp);
-            struct task* task_ptr = get_task(pid);
-            if(pid == 0)
-            {
-                unblock_task(current_task, current_task->pid);
-            }
-            else
-            {
-                if(task_ptr == NULL)
-                    abort_task("SYSCALL_PM_V: Der Aufrufer hat eine ungueltige PID angegeben: %d", pid);
-                
-                if(task_ptr->blocked_by_pid == current_task->pid)
-                {
-                    if(unblock_task(task_ptr, current_task->pid) == false)
-                    {
-                        panic("SYSCALL_PM_V: Der Task konnte nicht fortgesetzt werden");
-                    }
-                }
-                else
-                {
-                    abort_task("SYSCALL_PM_V: Der Aufrufer hat einen Prozess(PID=%d) angegeben, der nicht von ihm blockiert ist", pid);
-                }
-            }
-            /*kprintf("Kernel: v: PID %d an %08x => %d\n", 
-                current_task->pid, 
-                isf->ebp >= 0x1000 ? *((uint32_t*) (isf->ebp  + 4)) : 0,
-                current_task->blocked_count
-            );*/
-            break;
-        }
-
-        case SYSCALL_SET_RPC_HANDLER:
-        {
-            current_task->rpc_handler = *((vaddr_t*) isf->esp);
-            break;
-        }
-
-        case SYSCALL_FASTRPC:
-        {
-            uint32_t metadata_size = *((uint32_t*) (isf->esp + 4));
-            void* metadata = *((void**) (isf->esp + 8));
-            uint32_t data_size = *((uint32_t*) (isf->esp + 12));
-            void* data = *((void**) (isf->esp + 16));
-
-            uint32_t callee_pid = *((uint32_t*) isf->esp);
-            struct task* callee = get_task(callee_pid);
-
-            if (!callee) {
-                isf->eax = -ESRCH;
-                break;
-            }
-
-            if (!is_userspace(metadata, metadata_size)) {
-                abort_task("SYSCALL_FASTRPC: Ungueltige Metadaten (%08x)",
-                    (uint32_t) metadata);
-                break;
-            }
-            
-            if (!is_userspace(data, data_size)) {
-                abort_task("SYSCALL_FASTRPC: Ungueltige Daten (%08x)",
-                    (uint32_t) data);
-                break;
-            }
-
-            isf->eax = 0;
-            if (fastrpc(
-                callee,
-                metadata_size, metadata,
-                data_size, data    
-            )) {
-                schedule_to_task(callee, (uint32_t*) esp);
-            } else {
-                isf->eax = -EAGAIN;
-                schedule((uint32_t*)esp);
-            }
-            break;
-        }
-
-        case SYSCALL_FASTRPC_RET:
-        {
-            return_from_rpc(esp);
-            break;
-        }
-
-        case SYSCALL_ADD_INTERRUPT_HANDLER:
-        {
-            set_intr_handling_task(*((uint32_t*) isf->esp), current_task);
-            break;
-        }
-        
-        case SYSCALL_GET_TICK_COUNT:
-        {
-            isf->eax = (uint32_t)timer_ticks;
-            isf->edx = (uint32_t)(timer_ticks >> 32);
-            break;
-        }
-
-        case SYSCALL_ADD_TIMER:
-        {
-            timer_register(
-                current_task,
-                *((uint32_t*) (isf->esp)),
-                *((uint32_t*) (isf->esp + 4))
-            );
-            break;
-        }
-        
-        case SYSCALL_VM86:
-        {
-            vm86_regs_t *regs = *((vm86_regs_t **) (isf->esp));
-            uint32_t *mem = *((uint32_t **) (isf->esp + 4));
-            if (!regs) {
-                isf->eax = 0;
-                break;
-            }
-            if (create_vm86_task(0x10, regs, mem, current_task)) {
-                isf->eax = 1;
-            } else {
-                isf->eax = 0;
-            }
-            schedule((uint32_t*)esp);
-            break;
-        }
-
-        case SYSCALL_FORTY_TWO:
-        {
-            asm("int $0x20");
-            char* forty_two = malloc(61);
-            memcpy(forty_two, "\nThe Answer to Life, the Universe, and Everything is ... 42\n", 61);
-            kprintf("%s", forty_two);
-            break;
-        }
-
-        case SYSCALL_DEBUG_STACKTRACE:
-        {
-            pid_t pid = *((uint32_t*) (isf->esp));
-            struct task* task = get_task(pid);
-
-            // FIXME: Was bei einem Fehler
-            if (task != NULL) {
-                // TODO: Irgend ein Gefuehl sagt mir, dass das nicht so einfach
-                //       sein kann *g*
-                // In den Kontext dieses Tasks wechseln
-                __asm("mov %0, %%cr3" : : "r"(resolve_vaddr(kernel_page_directory, task->cr3)));            
-                struct int_stack_frame* isf = (struct int_stack_frame*) task->esp;
-                stack_backtrace_ebp(isf->ebp, isf->eip);
-
-                // Zurueck in den Kontext des aktuellen Tasks wechseln
-                __asm("mov %0, %%cr3" : : "r"(resolve_vaddr(kernel_page_directory, current_task->cr3)));
-            }
-
-            break;
-        }
+    syscall_register(SYSCALL_MEM_ALLOCATE, &syscall_mem_allocate, 3);
+    syscall_register(SYSCALL_MEM_ALLOCATE_PHYSICAL,
+            &syscall_mem_allocate_physical, 3);
+    syscall_register(SYSCALL_MEM_FREE, &syscall_mem_free, 2);
+    syscall_register(SYSCALL_MEM_FREE_PHYSICAL, &syscall_mem_free_physical, 2);
+    syscall_register(SYSCALL_MEM_INFO, &syscall_mem_info, 0);
+
+    syscall_register(SYSCALL_PM_GET_PID, (void*) &syscall_pm_get_pid, 0);
+    syscall_register(SYSCALL_PM_GET_PARENT_PID, (void*)
+        &syscall_pm_get_parent_pid, 1);
+    syscall_register(SYSCALL_PM_GET_CMDLINE, (void*) syscall_pm_get_cmdline,
+        0);
+
+    syscall_register(SYSCALL_PM_SLEEP, &syscall_pm_sleep, 0);
+    syscall_register(SYSCALL_PM_WAIT_FOR_RPC, &syscall_pm_wait_for_rpc, 0);
+
+    syscall_register(SYSCALL_PM_P, (void*) &syscall_pm_p, 0);
+    syscall_register(SYSCALL_PM_V, (void*) &syscall_pm_v, 1);
+    syscall_register(SYSCALL_PM_V_AND_WAIT_FOR_RPC, (void*)
+        &syscall_pm_v_and_wait_for_rpc, 0);
+
+    syscall_register(SYSCALL_PM_CREATE_PROCESS, &syscall_pm_create_process, 4);
+    syscall_register(SYSCALL_PM_INIT_PAGE, &syscall_init_child_page, 4);
+    syscall_register(SYSCALL_PM_INIT_PROC_PARAM_BLOCK, &syscall_init_ppb, 2);
+    syscall_register(SYSCALL_PM_EXIT_PROCESS, &syscall_pm_exit_process, 0);
+
+    syscall_register(SYSCALL_PM_ENUMERATE_TASKS,
+        &syscall_pm_enumerate_tasks, 0);
+
+#if CONFIG_ARCH == ARCH_I386
+    syscall_register(SYSCALL_PM_CREATE_THREAD, &syscall_pm_create_thread, 2);
+    syscall_register(SYSCALL_PM_GET_TID, &syscall_pm_get_tid, 0);
+    syscall_register(SYSCALL_PM_EXIT_THREAD, &syscall_pm_exit_thread, 0);
+#endif
+
+    syscall_register(SYSCALL_MUTEX_LOCK, &syscall_mutex_lock, 1);
+    syscall_register(SYSCALL_MUTEX_UNLOCK, &syscall_mutex_unlock, 1);
+
+    syscall_register(SYSCALL_SET_RPC_HANDLER, &syscall_set_rpc_handler, 1);
+#if CONFIG_ARCH == ARCH_I386
+    syscall_register(SYSCALL_FASTRPC, &syscall_fastrpc, 5);
+    syscall_register(SYSCALL_FASTRPC_RET, &syscall_fastrpc_ret, 0);
+#endif
+
+    syscall_register(SYSCALL_ADD_TIMER, &syscall_add_timer, 2);
+
+
+#if CONFIG_ARCH == ARCH_I386
+    syscall_register(SYSCALL_PM_REQUEST_PORT, syscall_io_request_port, 2);
+    syscall_register(SYSCALL_PM_RELEASE_PORT, syscall_io_release_port, 2);
+#endif
+    syscall_register(SYSCALL_ADD_INTERRUPT_HANDLER,
+        syscall_add_interrupt_handler, 1);
+
+    syscall_register(SYSCALL_PUTSN, (void*) &syscall_putsn, 2);
+    syscall_register(SYSCALL_GET_TICK_COUNT, syscall_get_tick_count, 0);
+
+    syscall_register(SYSCALL_SHM_CREATE, &syscall_shm_create, 1);
+    syscall_register(SYSCALL_SHM_ATTACH, &syscall_shm_attach, 1);
+    syscall_register(SYSCALL_SHM_DETACH, &syscall_shm_detach, 1);
+    syscall_register(SYSCALL_SHM_SIZE, &syscall_shm_size, 1);
+
+#if CONFIG_ARCH == ARCH_I386
+    syscall_register(SYSCALL_VM86, &syscall_vm86_old, 2);
+    syscall_register(SYSCALL_VM86_BIOS_INT, &syscall_vm86, 3);
+#endif
+
+    syscall_register(SYSCALL_LIO_RESOURCE, &syscall_lio_resource, 4);
+    syscall_register(SYSCALL_LIO_OPEN, &syscall_lio_open, 3);
+    syscall_register(SYSCALL_LIO_PIPE, &syscall_lio_pipe, 3);
+    syscall_register(SYSCALL_LIO_COMPOSITE_STREAM,
+                     &syscall_lio_composite_stream, 3);
+    syscall_register(SYSCALL_LIO_CLOSE, &syscall_lio_close, 1);
+    syscall_register(SYSCALL_LIO_READ, &syscall_lio_read, 6);
+    syscall_register(SYSCALL_LIO_WRITE, &syscall_lio_write, 6);
+    syscall_register(SYSCALL_LIO_SEEK, &syscall_lio_seek, 4);
+    syscall_register(SYSCALL_LIO_TRUNCATE, &syscall_lio_truncate, 2);
+    syscall_register(SYSCALL_LIO_SYNC, &syscall_lio_sync, 1);
+    syscall_register(SYSCALL_LIO_READ_DIR, &syscall_lio_read_dir, 5);
+    syscall_register(SYSCALL_LIO_MKFILE, &syscall_lio_mkfile, 4);
+    syscall_register(SYSCALL_LIO_MKDIR, &syscall_lio_mkdir, 4);
+    syscall_register(SYSCALL_LIO_MKSYMLINK, &syscall_lio_mksymlink, 6);
+    syscall_register(SYSCALL_LIO_STAT, &syscall_lio_stat, 2);
+    syscall_register(SYSCALL_LIO_UNLINK, &syscall_lio_unlink, 3);
+    syscall_register(SYSCALL_LIO_SYNC_ALL, &syscall_lio_sync_all, 0);
+    syscall_register(SYSCALL_LIO_PASS_FD, &syscall_lio_pass_fd, 2);
+    syscall_register(SYSCALL_LIO_PROBE_SERVICE, &syscall_lio_probe_service, 2);
+    syscall_register(SYSCALL_LIO_DUP, &syscall_lio_dup, 2);
+    syscall_register(SYSCALL_LIO_STREAM_ORIGIN, &syscall_lio_stream_origin, 1);
+    syscall_register(SYSCALL_LIO_IOCTL, &syscall_lio_ioctl, 2);
+
+    syscall_register(SYSCALL_LIO_SRV_SERVICE_REGISTER,
+        &syscall_lio_srv_service_register, 4);
+    syscall_register(SYSCALL_LIO_SRV_TREE_SET_RING,
+        &syscall_lio_srv_tree_set_ring, 4);
+    syscall_register(SYSCALL_LIO_SRV_RES_UPLOAD,
+        &syscall_lio_srv_res_upload, 1);
+    syscall_register(SYSCALL_LIO_SRV_NODE_ADD, &syscall_lio_srv_node_add, 4);
+    syscall_register(SYSCALL_LIO_SRV_NODE_REMOVE,
+        &syscall_lio_srv_node_remove, 3);
+    syscall_register(SYSCALL_LIO_SRV_OP_DONE, &syscall_lio_srv_op_done, 3);
+    syscall_register(SYSCALL_LIO_SRV_WAIT, &syscall_lio_srv_wait, 0);
+
+    syscalls[KERN_SYSCALL_PM_SLEEP] = (syscall_t) {
+        .handler    = &kern_syscall_pm_sleep,
+        .arg_count  = 2,
+        .privileged = true,
+    };
+}
 
-        default:
-            abort_task("Ungueltige Systemfunktion %d", isf->eax);
-            break;
+/**
+ * Einen neuen Syscall registrieren
+ *
+ * @param number Syscallnummer (syscallno.h!)
+ * @param handler Adresse der Handler-Funktion
+ * @param arg_count Anzahl der Argumente, die fuer diesen Syscall uebergeben
+ *                  werden muessen.
+ */
+void syscall_register(syscall_arg_t number, void* handler, size_t arg_count)
+{
+    // Ein Syscall mit einer zu grossen ID wuerde dazu fuehren, dass Teile von
+    // Kernel-Daten ueberschrieben wuerden
+    if (number >= SYSCALL_MAX) {
+        panic("Es wurde versucht einen Syscall mit einer Nummer groesser als"
+                "SYSCALL_MAX zu reservieren!");
     }
+    syscalls[number].handler = handler;
+    syscalls[number].arg_count = arg_count;
+    syscalls[number].privileged = false;
 }
diff --git a/src/kernel2/src/syscalls/io.c b/src/kernel/src/syscalls/io.c
similarity index 100%
rename from src/kernel2/src/syscalls/io.c
rename to src/kernel/src/syscalls/io.c
diff --git a/src/kernel2/src/syscalls/lio_server.c b/src/kernel/src/syscalls/lio_server.c
similarity index 100%
rename from src/kernel2/src/syscalls/lio_server.c
rename to src/kernel/src/syscalls/lio_server.c
diff --git a/src/kernel2/src/syscalls/lostio.c b/src/kernel/src/syscalls/lostio.c
similarity index 100%
rename from src/kernel2/src/syscalls/lostio.c
rename to src/kernel/src/syscalls/lostio.c
diff --git a/src/kernel2/src/syscalls/mem.c b/src/kernel/src/syscalls/mem.c
similarity index 100%
rename from src/kernel2/src/syscalls/mem.c
rename to src/kernel/src/syscalls/mem.c
diff --git a/src/kernel2/src/syscalls/misc.c b/src/kernel/src/syscalls/misc.c
similarity index 100%
rename from src/kernel2/src/syscalls/misc.c
rename to src/kernel/src/syscalls/misc.c
diff --git a/src/kernel2/src/syscalls/mutex.c b/src/kernel/src/syscalls/mutex.c
similarity index 100%
rename from src/kernel2/src/syscalls/mutex.c
rename to src/kernel/src/syscalls/mutex.c
diff --git a/src/kernel2/src/syscalls/pm.c b/src/kernel/src/syscalls/pm.c
similarity index 100%
rename from src/kernel2/src/syscalls/pm.c
rename to src/kernel/src/syscalls/pm.c
diff --git a/src/kernel2/src/syscalls/pv.c b/src/kernel/src/syscalls/pv.c
similarity index 100%
rename from src/kernel2/src/syscalls/pv.c
rename to src/kernel/src/syscalls/pv.c
diff --git a/src/kernel2/src/syscalls/rpc.c b/src/kernel/src/syscalls/rpc.c
similarity index 100%
rename from src/kernel2/src/syscalls/rpc.c
rename to src/kernel/src/syscalls/rpc.c
diff --git a/src/kernel2/src/syscalls/shm.c b/src/kernel/src/syscalls/shm.c
similarity index 100%
rename from src/kernel2/src/syscalls/shm.c
rename to src/kernel/src/syscalls/shm.c
diff --git a/src/kernel/src/task.c b/src/kernel/src/task.c
deleted file mode 100644
index eeca57fc..00000000
--- a/src/kernel/src/task.c
+++ /dev/null
@@ -1,422 +0,0 @@
-/*  
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */  
-
-#include <types.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <string.h>
-
-#include "vmm.h"
-#include "kmm.h"
-#include "paging.h"
-#include "kernel.h"
-#include "shm.h"
-
-#include "rpc.h"
-#include "io.h"
-
-#include "tasks.h"
-#include "timer.h"
-#include "kprintf.h"
-#include "debug.h"
-
-#define USER_STACK_VIRT 0xfffff000
-#define USER_STACK_SIZE (1024 - 4)
-
-extern uint64_t timer_ticks;
-extern struct task* first_task;
-extern int num_tasks;
-
-/**
- * Generiert eine neue eindeutige Prozess-ID
- * @return neue Prozess-ID
- */
-pid_t generate_pid()
-{
-    static pid_t next_pid = 1;
-    return next_pid++;
-}
-
-/**
- * Blockiert einen Task. Zu einem blockierten Task k�nnen keine RPC-Aufrufe
- * durchgef�hrt werden. Wenn der Task durch einen anderen Task blockiert ist,
- * wird er au�erdem vom Scheduler nicht mehr aufgerufen, bis der Task 
- * entblockt wird.
- *
- * @param task Zu blockierender Task
- * @param blocked_by PID des blockierenden Tasks
- */
-bool block_task(struct task* task, pid_t blocked_by)
-{
-    if(task->blocked_by_pid == blocked_by) {
-        task->blocked_count++;
-        return true;
-    }
-
-/*    while(task->blocked_by_pid)
-    {
-        kprintf("[block_task() => intr]\n");
-        asm("int $0x20");
-    }*/
-    if (task->blocked_by_pid) {
-        return false;
-    }
-    
-    /*if (blocked_by == 10 || blocked_by == 11) {
-        uint32_t ebp =((struct int_stack_frame*) current_task->esp)->ebp; 
-
-        kprintf("block_task PID %d durch PID %d = %d an %08x\n", 
-            task->pid, 
-            blocked_by,
-            current_task->pid,
-            ebp >= 0x1000 ? *((uint32_t*) (ebp  + 4)) : 0
-        );
-    }*/
-
-    task->blocked_by_pid = blocked_by;
-    task->blocked_count = 1;
-
-    return true;
-}
-
-/**
- * Entblockt einen blockierten Task. Dies ist nur m�glich, wenn der
- * aufrufende Task dem blockierenden Task entspricht
- *
- * @param task Zu entblockender Task
- * @param blocked_by Aufrufender Task
- *
- * @return true, wenn der Task erfolgreich entblockt wurde, false
- * im Fehlerfall.
- */
-bool unblock_task(struct task* task, pid_t blocked_by)
-{
-    if (task->blocked_by_pid == blocked_by) {
-        if(--(task->blocked_count) == 0) {
-            task->blocked_by_pid = 0;
-        }
-        return true;
-    } else {
-        kprintf("\033[41munblock_task nicht erlaubt.\n\n\n");
-        return false;
-    }
-}
-
-
-/**
- * Erstellt einen neuen Task
- *
- * @param entry Einsprungspunkt
- * @param args String der Parameter
- *
- * @return Neuer Task
- */
-struct task * create_task(void* entry, const char* args, pid_t parent_pid)
-{
-    struct task* new_task = malloc(sizeof(struct task));
-    new_task->pid = generate_pid();
-    new_task->rpcs = list_create();
-    new_task->io_bitmap = NULL;
-    new_task->status = TS_RUNNING;
-    
-    new_task->shmids = list_create();
-    new_task->shmaddresses = list_create();
-
-    new_task->vm86 = false;
-    new_task->vm86_info = NULL;
-    
-    new_task->memory_used = 0;
-    // Wenn nicht Init erstellt werden soll, wir der Task mit der PID seines
-    //  Elterntasks blockiert. Damit der Elterntask Zeit hat, die notwendigen
-    //  Pages in den Adressraum des neuen Prozesses zu mappen.
-    if (new_task->pid != 1) {
-        new_task->blocked_count = 1;
-        new_task->blocked_by_pid = parent_pid;
-    } else {
-        new_task->blocked_by_pid = 0;
-        new_task->blocked_count = 0;
-    }
-
-    
-    // Scheduling-Eigenschaften fuer den Task setzen
-    new_task->schedule_ticks_left = 0;
-    new_task->schedule_ticks_max = 50;
-
-    // Haenge den Task an die Liste an
-    // TODO Trennen der Task-Liste von der Scheduling-Liste
-    new_task->next_task = first_task;
-    first_task = new_task;
-    if (parent_pid == 0) {
-        new_task->parent_task = current_task;
-    } else {
-        new_task->parent_task = get_task(parent_pid);
-    }
-    
-    // Kopieren der Kommandozeile
-    new_task->cmdline = malloc(strlen(args) + 1);
-    memcpy((void*) (new_task->cmdline), (void*)args, strlen(args) + 1);
-
-    // Ein neues Page Directory anlegen. Das Page Directory bleibt
-    // gemappt, solange der Task l�uft.
-    //
-    // Der Kernelspeicher wird in allen Tasks gleich gemappt, der
-    // Userspace bekommt erstmal einen komplett leeren Speicher.
-    paddr_t phys_pagedir = phys_alloc_page();
-    page_directory_t pagedir = (page_directory_t) map_phys_addr(phys_pagedir, PAGE_SIZE);
-
-    memset((void*) pagedir, 0, PAGE_SIZE);
-    memcpy((void*) pagedir, kernel_page_directory, 1024);
-    pagedir[0xff] = (uint32_t) phys_pagedir | PTE_W | PTE_P;
-    new_task->cr3 = pagedir;
-
-    // Speicher fuer die Stacks allokieren
-    // Stack im PD des neuen Tasks mappen
-    paddr_t phys_kernel_stack = phys_alloc_page();
-    paddr_t phys_user_stack = phys_alloc_page();
-
-    map_page(pagedir, (vaddr_t)USER_STACK_VIRT, phys_user_stack, PTE_W | PTE_P | PTE_U);
-    new_task->user_stack_bottom = (vaddr_t) USER_STACK_VIRT;
-
-    // Den Kernelstack mappen und initialisieren
-    // Der Stack wird von oben her beschrieben, daher 4K addieren 
-    // (1024 * sizeof(uint32_t))
-    uint32_t * kernel_stack = map_phys_addr(phys_kernel_stack, PAGE_SIZE);
-    kernel_stack += 1024;
-
-    *(--kernel_stack) = 0x23; // ss
-    *(--kernel_stack) = USER_STACK_VIRT + USER_STACK_SIZE - 0x4; // esp FIXME: das + 0x8 ist gehoert hier eigentlich nicht hin, das dient dazu dem Task startparameter mit zu geben und sollte flexibler geloest werden
-    *(--kernel_stack) = 0x0202; // eflags = interrupts aktiviert und iopl = 0
-    *(--kernel_stack) = 0x1b; // cs
-    *(--kernel_stack) = (uint32_t)entry; // eip
-
-    *(--kernel_stack) = 0; // interrupt nummer
-    *(--kernel_stack) = 0; // error code
-
-    // general purpose registers
-    *(--kernel_stack) = 0;
-    *(--kernel_stack) = 0;
-    *(--kernel_stack) = 0;
-    *(--kernel_stack) = 0;
-    *(--kernel_stack) = 0;
-    *(--kernel_stack) = 0;
-    *(--kernel_stack) = 0;
-    *(--kernel_stack) = 0;
-
-    // segment registers
-    *(--kernel_stack) = 0x23;
-    *(--kernel_stack) = 0x23;
-    *(--kernel_stack) = 0x23;
-    *(--kernel_stack) = 0x23;
-    
-    new_task->esp = (uint32_t) kernel_stack;
-    new_task->kernel_stack = (uint32_t) kernel_stack;
-
-    num_tasks++;
-    
-    return new_task;
-}
-
-/**
- * Beendet einen Taks.
- *
- * @param task_ptr Zu beendender Task
- */
-void destroy_task(struct task* task_ptr)
-{
-    task_ptr->blocked_by_pid = -1;
-
-    struct task* previous_task = NULL;
-    struct task* next_task = NULL;
-
-    // Den vorherigen Task in der Liste heraussuchen
-    if(task_ptr == first_task)
-    {
-        first_task = task_ptr->next_task;
-    }
-    else
-    {
-        next_task = first_task;
-        while(next_task != task_ptr)
-        {
-            // Wenn der Task nicht gefunden wuzde verlasse die Funktion
-            if(next_task == NULL)
-                return;
-
-            previous_task = next_task;
-            next_task = next_task->next_task;
-        }
-        previous_task->next_task = task_ptr->next_task;
-    }
-
-    // Alle Kindprozesse an init weitervererben
-    for (next_task = first_task; next_task; next_task = next_task->next_task) {
-        if (next_task->parent_task == task_ptr) {
-            next_task->parent_task = get_task(1);
-        }
-    }
-
-    // Interrupthandler ausschalten
-    remove_intr_handling_task(task_ptr);
-    
-    
-    // Melde das Beenden des Tasks per RPC an init
-    char* rpc_init = "        SERV_SHD    ";
-    *((uint32_t*)rpc_init) = 512;
-    *((pid_t*)((uint32_t) rpc_init + 8 + 8))  = task_ptr->pid;
-    
-    fastrpc(get_task(1), 0, 0, strlen(rpc_init), rpc_init);
-    
-    // Timer freigeben
-    timer_cancel_all(task_ptr);
-    
-    // Alle Ports und die IO-Bitmap des Tasks freigeben
-    if (task_ptr->io_bitmap) {
-        io_ports_release_all(task_ptr);
-        free(task_ptr->io_bitmap);
-    }
-    
-    //Shared Memory-Bereiche von Task l�sen
-    while (list_size(task_ptr->shmids) > 0) {
-        uint32_t id = (uint32_t)list_get_element_at(task_ptr->shmids, list_size(task_ptr->shmids) - 1);
-        detach_task_from_shm(task_ptr, id);
-    }
-    
-    // Evtl. zusatzliche Infos von VM86-Task l�schen
-    if (task_ptr->vm86) {
-        free(task_ptr->vm86_info);
-    }
-
-    // Kommandozeilenparameter freigeben
-    if (task_ptr->cmdline) {
-        free((char*) task_ptr->cmdline);
-    }
-
-    // Wenn der zu beendende Task kurz vorher einen RPC gemacht hat,
-    // hat der aufgerufene Prozess den jetzt beendeten Task in
-    // callee->rpcs und der Ruecksprung wurde im Desaster enden.
-    rpc_destroy_task_backlinks(task_ptr);
-
-    // Pagedir des tasks mappen, um den gesamten Speicher
-    // freigeben zu k�nnen
-    page_directory_t page_dir = task_ptr->cr3;
-    page_table_t page_table;
-    
-    int i;
-    int n;
-    
-    // Alle Pages von 1 GB - 4 GB
-    //
-    // FIXME Physisch freigeben nur, wenn die Seite tats�chlich speziell f�r
-    // den Task reserviert wurde. Das ist beispielsweise bei Shared Memory oder
-    // beim Zugriff auf physischen Speicher (Framebuffer) nicht der Fall.
-    for(i=256; i < 1024; i++)
-    {
-        if(page_dir[i] & PTE_P)
-        {
-            page_table = map_phys_addr((paddr_t)(page_dir[i] & ~0xFFF), PAGE_TABLE_LENGTH);
-            
-            for(n=0; n < 1024; n++)
-            {
-                if(page_table[n] & PTE_P)
-                {
-                    phys_free_page((paddr_t) (page_table[n] & PAGE_MASK));
-                }
-            }
-            
-            free_phys_addr((vaddr_t)page_table, PAGE_TABLE_LENGTH);
-        }
-    }
-   
-    // Page Directory und den Task selbst freigeben
-    // TODO Auch die physische Seite freigeben
-    free_phys_addr((vaddr_t)page_dir, PAGE_DIRECTORY_LENGTH);
-    free(task_ptr);
-}
-
-
-/**
- * Sucht einen Task anhand der PID und gibt einen Pointer darauf zurueck:
- * 
- * @param pid PID des gesuchten Tasks
- * @return Pointer auf den Task oder NULL, falls kein Task mit der passenden
- * PID gefunden wurde
- */
-struct task * get_task(pid_t pid)
-{
-    struct task* curr_task = first_task;
-    
-    while(curr_task != NULL)
-    {
-        if(curr_task->pid == pid) {
-            return curr_task;
-        }
-        
-        curr_task = curr_task->next_task;
-    }
-    
-    return NULL;
-}
-
-/**
- * Bricht den aktuell ausgef�hrten Task mit einer Fehlermeldung ab.
- */
-void abort_task(char* format, ...)
-{
-    int * args = ((int*)&format) + 1;
-
-    kprintf("\n\033[1;37m\033[41m" // weiss auf rot
-        "Task %d beendet: %s\n", 
-        current_task->pid,
-        current_task->cmdline != NULL 
-            ? current_task->cmdline 
-            : "Unbekannter Task"
-        );
-    kaprintf(format, &args);
-    kprintf("\n\033[0;37m\033[40m");
-        
-    if(debug_test_flag(DEBUG_FLAG_STACK_BACKTRACE))
-    {
-        struct int_stack_frame* isf = (struct int_stack_frame*)
-            current_task->esp;
-        stack_backtrace_ebp(isf->ebp, isf->eip);
-    }
-
-    destroy_task(current_task);
-    
-    current_task = NULL;
-    asm("int $0x20");
-}
-
diff --git a/src/kernel2/src/tasks/modules.c b/src/kernel/src/tasks/modules.c
similarity index 100%
rename from src/kernel2/src/tasks/modules.c
rename to src/kernel/src/tasks/modules.c
diff --git a/src/kernel2/src/tasks/pm.c b/src/kernel/src/tasks/pm.c
similarity index 100%
rename from src/kernel2/src/tasks/pm.c
rename to src/kernel/src/tasks/pm.c
diff --git a/src/kernel2/src/tasks/scheduler.c b/src/kernel/src/tasks/scheduler.c
similarity index 100%
rename from src/kernel2/src/tasks/scheduler.c
rename to src/kernel/src/tasks/scheduler.c
diff --git a/src/kernel2/src/tasks/thread.c b/src/kernel/src/tasks/thread.c
similarity index 100%
rename from src/kernel2/src/tasks/thread.c
rename to src/kernel/src/tasks/thread.c
diff --git a/src/kernel/src/timer.c b/src/kernel/src/timer.c
index 685cbd1b..33d0dcb7 100644
--- a/src/kernel/src/timer.c
+++ b/src/kernel/src/timer.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.
+ * Copyright (c) 2006-2009 The tyndur Project. All rights reserved.
  *
  * This code is derived from software contributed to the tyndur Project
  * by Kevin Wolf.
@@ -33,30 +33,61 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <types.h>
+#include <stdint.h>
+#include <stdbool.h>
 #include <collections.h>
 #include <stdlib.h>
+#include <ports.h>
 
 #include "timer.h"
-#include "rpc.h"
+#include "syscall.h"
 
 extern uint64_t timer_ticks;
+extern int do_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata,
+    size_t data_size, void* data, bool syscall);
 
-
+/**
+ * Liste aller registrierten Timer
+ */
 static list_t* timers;
 
+/**
+ * Repraesentiert einen registrierten Timer. Ein Timer gehoert zun einem
+ * bestimmten Prozess und nach Ablauf der vorgegebenen Zeitspanne wird ein RPC
+ * zu diesem Prozess durchgefuehrt
+ */
 struct timeout {
-    struct task*    task;
-    uint32_t           timer_id;
-    uint64_t           timeout;
+    pm_process_t*   task;
+    uint32_t        timer_id;
+    uint64_t        timeout;
 };
 
-void timer_init()
+#define PIT_COUNTER_0       (0x0 << 6)
+#define PIT_RW_LO_BYTE      (0x1 << 4)
+#define PIT_RW_HI_BYTE      (0x2 << 4)
+#define PIT_RW_FULL         (0x3 << 4)
+#define PIT_MODE_2_RATE_GEN (0x2 << 1)
+
+/**
+ * Initialisiert die Timerverwaltung
+ */
+void timer_init(void)
 {
+    uint16_t reload_value;
+
     timers = list_create();
+
+    // PIT initialisieren
+    reload_value = 1193182 / CONFIG_TIMER_HZ;
+    outb(0x43, PIT_COUNTER_0 | PIT_RW_FULL | PIT_MODE_2_RATE_GEN);
+    outb(0x40, reload_value & 0xff);
+    outb(0x40, reload_value >> 8);
 }
 
-void timer_register(struct task* task, uint32_t timer_id, uint32_t usec)
+/**
+ * Registriert einen neuen Timer
+ */
+void timer_register(pm_process_t* task, uint32_t timer_id, uint32_t usec)
 {
     // Anlegen des Timeout-Objekts
     struct timeout* timeout = malloc(sizeof(struct timeout));
@@ -66,7 +97,7 @@ void timer_register(struct task* task, uint32_t timer_id, uint32_t usec)
     timeout->timeout    = timer_ticks + usec;
 
     // An der richtigen Stelle in der Liste einsortieren, so dass immer nur
-    // das erste Listenelement gepr�ft werden muss
+    // das erste Listenelement geprueft werden muss
     struct timeout* item;
     int i;
     for (i = 0; (item = list_get_element_at(timers, i)); i++) {
@@ -78,47 +109,55 @@ void timer_register(struct task* task, uint32_t timer_id, uint32_t usec)
     list_insert(timers, i, timeout);
 }
 
+/**
+ * Aufzurufen bei jeder Aktualisierung der Systemzeit. Fuehrt die
+ * RPC-Benachrichtigungen fuer alle faelligen Timer aus.
+ */
 void timer_notify(uint64_t microtime)
 {
     static uint64_t last_microtime = 0;
     static const uint32_t rpc_timer_function = 514;
-    
+
     struct timeout* item;
-    for (; (item = list_get_element_at(timers, 0)); free(list_pop(timers))) 
+    int i = 0;
+    while ((item = list_get_element_at(timers, i)))
     {
-        // Die Schleife soll nur so lange laufen, wie die Timeouts in der 
+        // Die Schleife soll nur so lange laufen, wie die Timeouts in der
         // Vergangenheit liegen. Da die Liste sortiert ist, kann beim ersten
         // Timeout, der in der Zukunft liegt, abgebrochen werden.
         //
-        // Overflows m�ssen abgefangen werden, da in diesem Spezialfall eine
-        // gr��ere Zahl dennoch Vergangenheit bedeutet. Wie ich grad sehe,
+        // Overflows muessen abgefangen werden, da in diesem Spezialfall eine
+        // groessere Zahl dennoch Vergangenheit bedeutet. Wie ich grad sehe,
         // reden wir von einem qword und damit von einer Uptime von ein paar
-        // hunderttausend Jahren, aber LOST ist ja stabil und wir daher
+        // hunderttausend Jahren, aber tyndur ist ja stabil und wir daher
         // optimistisch.
-        if (((item->timeout > microtime) && (microtime > last_microtime)) 
+        if (((item->timeout > microtime) && (microtime > last_microtime))
             || ((item->timeout < last_microtime) && (microtime < last_microtime)))
         {
             break;
         }
 
-        // Task per RPC informieren, dass der Timer abgelaufen ist
-        // Im Fehlerfall mit der Abarbeitung der Liste aufh�ren und es beim
-        // n�chsten Mal nochmal versuchen.
-        //
-        // FIXME Mit p(); while(1); kann ein Prozess den Timer f�r das ganze
-        // System lahmlegen
-        if (!fastrpc(item->task, 
-                4, (char*) &rpc_timer_function, 
-                4, (char*) &item->timer_id)) 
+        // Task per RPC informieren, dass der Timer abgelaufen ist.
+        // Im Fehlerfall ueberspringen und es beim naechsten Mal nochmal
+        // versuchen.
+        if (do_fastrpc(item->task->pid,
+                4, (char*) &rpc_timer_function,
+                4, (char*) &item->timer_id, false))
         {
-            break;
+            i++;
+            continue;
         }
+
+        free(list_remove(timers, i));
     }
 
     last_microtime = microtime;
 }
 
-void timer_cancel_all(struct task* task)
+/**
+ * Entfernt alle registrierten Timer eines Prozesses
+ */
+void timer_cancel_all(pm_process_t* task)
 {
     struct timeout* item;
     int i;
diff --git a/src/kernel/src/tss.c b/src/kernel/src/tss.c
deleted file mode 100644
index 8c858176..00000000
--- a/src/kernel/src/tss.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Burkhard Weseloh.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gdt.h"
-#include "tss.h"
-#include "cdefs.h"
-
-tss_t tss = { 
-    .ss0 = SYS_DATA_SEL, 
-    .io_bit_map_offset = TSS_IO_BITMAP_OFFSET,
-    .io_bit_map_end = 0xFF 
-};
diff --git a/src/kernel/src/vm86.c b/src/kernel/src/vm86.c
deleted file mode 100644
index be50e39d..00000000
--- a/src/kernel/src/vm86.c
+++ /dev/null
@@ -1,392 +0,0 @@
-/*  
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Mathias Gottschlag.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdint.h>
-#include <stdbool.h>
-
-#include "vm86.h"
-#include "string.h"
-#include "stdlib.h"
-#include "syscall_structs.h"
-#include "paging.h"
-#include "intr.h"
-#include "kprintf.h"
-#include "kmm.h"
-#include "kernel.h"
-#include <ports.h>
-
-extern int num_tasks;
-
-// Kopie der ersten 4k RAM
-struct
-{
-    uint16_t ivt[256][2];
-    uint8_t data[3072];
-} bios_data __attribute__ ((aligned (4096)));
-
-// TODO: Support f�r mehrere VM86-Tasks
-// Gibt evtl Probleme mit der Platzierung des Kernels.
-bool vm86_task_running = false;
-
-/**
- * Speichert BIOS-Daten, um sie den VM86-Tasks sp�ter bereitstellen zu k�nnen
- */
-void save_bios_data(void)
-{
-    memcpy(&bios_data, 0, 4096);
-}
-
-/**
- * Liefert ein Segment:Offset-Paar aus der IVT zur�ck
- *
- * @param interrupt Nummer des Interrupts
- *
- * @return Pointer auf Segment/Offset
- */
-uint16_t *get_ivt_entry(uint16_t interrupt)
-{
-    return bios_data.ivt[interrupt];
-}
-
-/**
- * Erstellt einen VM86-Task, der einen bestimmten RM-Interrupt aufruft
- *
- * @param interrupt Nummer des Interrupts
- * @param regs Struktur mit Registerinhalt (wird auch zur R�ckgabe der Ergebnisse
- * benutzt.
- * @param meminfo Daten �ber Speicherbereiche, die in den Task gemappt werden.
- * Die erste Zahl steht f�r die Anzahl der Eintr�ge, danach folgen je drei Zahlen
- * f�r Adresse im neuen Task, Adresse in aufrufenden Task und Gr��e.
- *
- * @return Taskstruktur des neuen Tasks oder Null bei Fehlern
- */
-
-struct task * create_vm86_task(uint16_t interrupt, vm86_regs_t *regs, uint32_t *meminfo, struct task *parent)
-{
-    // Nur einen VM86-Task starten
-    if (vm86_task_running) {
-        return 0;
-    }
-    vm86_task_running = true;
-    
-    struct task* new_task = malloc(sizeof(struct task));
-    new_task->pid = generate_pid();
-    
-    // Aufrufender Thread wird geblockt, damit sp�ter Ergebnisse zur�ckgegeben werden k�nnen
-    if (!block_task(parent, new_task->pid)) {
-        //puts("VM86: Konnte aufrufenden Task nicht blockieren!\n");
-        free(new_task);
-        return 0;
-    }
-
-    
-    new_task->rpcs = list_create();
-    new_task->io_bitmap = NULL;
-    new_task->status = TS_RUNNING;
-    new_task->shmids = list_create();
-    new_task->shmaddresses = list_create();
-    new_task->memory_used = 0;
-    // Neuer Task wird nicht geblockt, da er sofort ausgef�hrt werden kann und sollte
-    new_task->blocked_by_pid = 0;
-    new_task->blocked_count = 0;
-    // Info �ber Register/Speicher f�r R�ckgabe von Daten aufbewahren
-    new_task->vm86 = true;
-    new_task->vm86_info = malloc(sizeof(vm86_info_t));
-    new_task->vm86_info->regs = regs;
-    new_task->vm86_info->meminfo = meminfo;
-    //printf("Neuer vm86-Task mit PID %d\n", new_task->pid);
-    
-    // Name des Tasks setzen
-    new_task->cmdline = malloc(strlen("vm86") + 1);
-    memcpy((void*) (new_task->cmdline), "vm86", strlen("vm86") + 1);
-    
-    // Scheduling-Eigenschaften fuer den Task setzen
-    new_task->schedule_ticks_left = 0;
-    new_task->schedule_ticks_max = 50;
-    
-    // Haenge den Task an die Liste an
-    // TODO Trennen der Task-Liste von der Scheduling-Liste
-    new_task->next_task = first_task;
-    first_task = new_task;
-    if (parent->pid == 0) {
-        new_task->parent_task = current_task;
-    } else {
-        new_task->parent_task = get_task(parent->pid);
-    }
-    
-    // Neues Pagedirectory anlegen
-    // TODO: Die erste Pagetable sollte kopiert werden oder der Kernel etwas nach
-    // hinten verschoben werden.
-    paddr_t phys_pagedir = (paddr_t)phys_alloc_page();
-    page_directory_t pagedir = (page_directory_t) map_phys_addr(phys_pagedir, PAGE_SIZE);
-
-    memset((void*) pagedir, 0, PAGE_SIZE);
-    memcpy((void*) pagedir, kernel_page_directory, 1024);
-    new_task->cr3 = pagedir;
-    pagedir[0] |= 0x4;
-    
-    map_page_range(kernel_page_directory, (vaddr_t)0xC0000, (paddr_t)0xC0000, PTE_P | PTE_U, 0x40);
-    map_page_range(kernel_page_directory, (vaddr_t)0xA0000, (paddr_t)0xA0000, PTE_W | PTE_P | PTE_U, 0x10);
-    
-    
-    // Speicher fuer die Stacks allokieren
-    // Stack im PD des neuen Tasks mappen
-    paddr_t phys_kernel_stack = (paddr_t)phys_alloc_page();
-    paddr_t phys_user_stack = (paddr_t)phys_alloc_page();
-
-    // TODO: Dynamisch freien Speicher suchen, bin ich grad zu faul zu -.-
-    map_page(pagedir, (vaddr_t)0x90000, phys_user_stack, PTE_W | PTE_P | PTE_U);
-    new_task->user_stack_bottom = (vaddr_t) 0x90000;
-    
-    // Erste 4k mappen
-    uint32_t *page_table = (uint32_t*)find_contiguous_kernel_pages(1);
-    map_page(kernel_page_directory, page_table, (paddr_t)(pagedir[0] & ~0xFFF), PTE_P | PTE_W);
-    page_table[0] = (uint32_t)&bios_data | 0x7;
-    unmap_page(kernel_page_directory, page_table);
-    
-    // Gew�nschte Speicherbereiche reservieren
-    if (meminfo) {
-        uint32_t infosize = meminfo[0];
-        uint32_t i;
-        for (i = 0; i < infosize; i++) {
-            uint32_t addr = meminfo[1 + i * 3];
-            uint32_t src = meminfo[1 + i * 3 + 1];
-            uint32_t size = meminfo[1 + i * 3 + 2];
-            paddr_t phys_mem = (paddr_t)phys_alloc_page();
-            map_page(pagedir, (vaddr_t)(addr & ~0xFFF), phys_mem, PTE_W | PTE_P | PTE_U);
-            memcpy((void*)addr, (void*)src, size);
-        }
-    }
-    
-    // Userstack mit Nullen f�llen, um bei einem iret den Task zu beenden
-    uint32_t *user_stack = (uint32_t*)find_contiguous_kernel_pages(1);
-    map_page(kernel_page_directory, user_stack, phys_user_stack, PTE_P | PTE_W);
-    user_stack[1023] = 0x0;
-    user_stack[1022] = 0x0;
-    unmap_page(kernel_page_directory, user_stack);
-    
-    // Den Kernelstack mappen und initialisieren
-    // Der Stack wird von oben her beschrieben, daher 4K addieren 
-    // (1024 * sizeof(uint32_t))
-    uint32_t * kernel_stack = (uint32_t*)map_phys_addr(phys_kernel_stack, PAGE_SIZE);
-    kernel_stack += 1024;
-
-    *(--kernel_stack) = 0x00; // gs
-    *(--kernel_stack) = 0x00; // fs
-    *(--kernel_stack) = regs->es; // es
-    *(--kernel_stack) = regs->ds; // ds
-    *(--kernel_stack) = 0x9000; // ss
-    *(--kernel_stack) = 0 + 4096 - 6;
-    *(--kernel_stack) = 0x20202; // eflags = VM-Bit gesetzt, interrupts aktiviert und iopl = 0
-    *(--kernel_stack) = get_ivt_entry(interrupt)[1]; // cs
-    *(--kernel_stack) = get_ivt_entry(interrupt)[0]; // eip
-    //kprintf("Interrupt: %x/%x\n", get_ivt_entry(interrupt)[1], get_ivt_entry(interrupt)[0]);
-
-    *(--kernel_stack) = 0; // interrupt nummer
-    *(--kernel_stack) = 0; // error code
-
-    // general purpose registers
-    *(--kernel_stack) = regs->ax;
-    *(--kernel_stack) = regs->cx;
-    *(--kernel_stack) = regs->dx;
-    *(--kernel_stack) = regs->bx;
-    *(--kernel_stack) = 0;
-    *(--kernel_stack) = 0;
-    *(--kernel_stack) = regs->si;
-    *(--kernel_stack) = regs->di;
-
-    // segment registers
-    *(--kernel_stack) = 0x23;
-    *(--kernel_stack) = 0x23;
-    *(--kernel_stack) = 0x23;
-    *(--kernel_stack) = 0x23;
-    
-    new_task->esp = (uint32_t) kernel_stack;
-    new_task->kernel_stack = (uint32_t) kernel_stack;
-
-    num_tasks++;
-    
-    //puts("vm86-Task erstellt.\n");
-        
-    return new_task;
-
-}
-
-/**
- * Handler f�r Exceptions im VM86-Mode
- *
- * @param esp Pointer auf Stackpointer
- *
- * @return true, wenn die Exception verarbeitet wurde, false, wenn sie nicht
- * verarbeitet werden konnte und der Task beendet werden muss.
- */
-bool vm86_exception(uint32_t *esp)
-{
-    // TODO: Das hier ist noch lange nicht vollst�ndig
-    struct int_stack_frame *isf = *((struct int_stack_frame **)esp);
-    //puts("vm86 Exception.\n");
-    if (isf->interrupt_number == 13) {
-        // GPF, wurde vermutlich durch einen nicht erlaubten Befehl verursacht
-        uint8_t *ops = (uint8_t*)(isf->eip + (isf->cs << 4));
-        if (ops[0] == 0xCD) { // int
-            //kprintf("VM86: int 0x%x\n", ops[1]);
-            // Derzeitige Adresse auf den Stack pushen und neue Codeadresse setzen
-            uint16_t intno = ops[1];
-            isf->esp -= 6;
-            ((uint16_t*)(isf->esp + (isf->ss << 4)))[0] = (uint16_t)isf->eflags;
-            ((uint16_t*)(isf->esp + (isf->ss << 4)))[1] = (uint16_t)isf->cs;
-            ((uint16_t*)(isf->esp + (isf->ss << 4)))[2] = (uint16_t)isf->eip + 2;
-            isf->eip = bios_data.ivt[intno][0];
-            isf->cs = bios_data.ivt[intno][1];
-            return true;
-        } else if (ops[0] == 0xCF) { // iret
-            //puts("VM86: iret.\n");
-            // Alte Adresse von Stack holen
-            isf->eip = ((uint16_t*)(isf->esp + (isf->ss << 4)))[2];
-            isf->cs = ((uint16_t*)(isf->esp + (isf->ss << 4)))[1];
-            isf->esp += 6;
-            // Abbrechen, wenn wir das letzte iret erreicht haben
-            if ((isf->eip == 0) && (isf->cs == 0)) {
-                //puts("Breche VM86-Task ab.\n");
-                struct task *task = current_task;
-                vm86_info_t *info = task->vm86_info;
-                // Speicher kopieren
-                if (info->meminfo) {
-                    paddr_t phys_meminfo = resolve_vaddr(task->parent_task->cr3, (uint32_t*)((uint32_t)info->meminfo & ~0xFFF));
-                    uint32_t *meminfo = (uint32_t*)find_contiguous_kernel_pages(1);
-                    map_page(kernel_page_directory, meminfo, phys_meminfo, PTE_P | PTE_W);
-                    meminfo = (uint32_t*)(((uint32_t)meminfo) + ((uint32_t)info->meminfo & 0xFFF));
-                    uint32_t i;
-                    for (i = 0; i < meminfo[0]; i++) {
-                        paddr_t phys_mem = resolve_vaddr(task->parent_task->cr3, (uint32_t*)((uint32_t)meminfo[1 + i * 3 + 1] & ~0xFFF));
-                        uint32_t *mem = (uint32_t*)find_contiguous_kernel_pages(1);
-                        map_page(kernel_page_directory, mem, phys_mem, PTE_P | PTE_W);
-                        memcpy((void*)((uint32_t)mem + (meminfo[1 + i * 3 + 1] & 0xFFF)), (void*)meminfo[1 + i * 3], meminfo[1 + i * 3 + 2]);
-                        unmap_page(kernel_page_directory, mem);
-                        unmap_page(kernel_page_directory, (uint32_t*)((uint32_t)meminfo[1 + i * 3] & ~0xFFF));
-                    }
-                    unmap_page(kernel_page_directory, (uint32_t*)((uint32_t)meminfo & ~0xFFF));
-                }
-                // Register speichern
-                paddr_t phys_regs = resolve_vaddr(task->parent_task->cr3, (uint32_t*)((uint32_t)info->regs & ~0xFFF));
-                uint32_t regs = (uint32_t) map_phys_addr(phys_regs, PAGE_SIZE);
-                vm86_regs_t * vm86_regs = (vm86_regs_t *)(regs + ((uint32_t)info->regs & 0xFFF));
-                vm86_regs->ax = isf->eax;
-                vm86_regs->bx = isf->ebx;
-                vm86_regs->cx = isf->ecx;
-                vm86_regs->dx = isf->edx;
-                vm86_regs->si = isf->esi;
-                vm86_regs->di = isf->edi;
-                vm86_regs->ds = ((uint32_t*)(isf + 1))[0];
-                vm86_regs->es = ((uint32_t*)(isf + 1))[1];
-                free_phys_addr((vaddr_t) regs, PAGE_SIZE);
-                // Speicher freigeben
-                // - Stack
-                unmap_page(task->cr3, (vaddr_t)0x90000);
-                // - BIOS-Daten
-                uint32_t *page_table = (uint32_t*)find_contiguous_kernel_pages(1);
-                map_page(kernel_page_directory, page_table, (((uint32_t*)task->cr3)[0] & ~0xFFF), PTE_P | PTE_W);
-                page_table[0] = 0;
-                unmap_page(kernel_page_directory, page_table);
-                // - BIOS
-                uint32_t i;
-                for (i = 0; i < 0x40; i++) {
-                    unmap_page(task->cr3, (uint32_t*)(0xC0000 + i * 0x1000));
-                }
-                // - VGA
-                for (i = 0; i < 0x10; i++) {
-                    unmap_page(task->cr3, (uint32_t*)(0xA0000 + i * 0x1000));
-                }
-                // Task beenden
-                if (!unblock_task(task->parent_task, task->pid)) {
-                    panic("VM86: Konnte aufrufenden Task nicht wecken!");
-                }
-                schedule(esp);
-                destroy_task(task);
-                vm86_task_running = false;
-                return true;
-            }
-            return true;
-        } else if (ops[0] == 0x9C) { // pushf
-            // EFLAGS speichern
-            isf->esp -= 2;
-            ((uint16_t*)(isf->esp + (isf->ss << 4)))[0] = (uint16_t)isf->eflags;
-            isf->eip++;
-            return true;
-        } else if (ops[0] == 0x9D) { // popf
-            // So tun, als w�rden wir die EFLAGS wiederherstellen.
-            // Das hier ist wohl alles andere als korrekt, aber funzt erstmal.
-            isf->esp += 2;
-            isf->eip++;
-            return true;
-        } else if (ops[0] == 0xEF) { // outw
-            outw(isf->edx, isf->eax);
-            isf->eip++;
-            return true;
-        } else if (ops[0] == 0xEE) { // outb
-            outb(isf->edx, isf->eax);
-            isf->eip++;
-            return true;
-        } else if (ops[0] == 0xED) { // inw
-            isf->eax = inb(isf->edx);
-            isf->eip++;
-            return true;
-        } else if (ops[0] == 0xEC) { // inb
-            isf->eax = (isf->eax & 0xFF00) + inb(isf->edx);
-            isf->eip++;
-            return true;
-        } else if (ops[0] == 0xFA) { // sti
-            isf->eip++;
-            return true;
-        } else if (ops[0] == 0xFB) { // cli
-            isf->eip++;
-            return true;
-        } else if (ops[0] == 0x66) { // o32
-            // TODO
-            isf->eip++;
-            return true;
-        } else if (ops[0] == 0x67) { // a32
-            // TODO
-            isf->eip++;
-            return true;
-        } else {
-            abort_task("VM86: Unbekannter Opcode: %x\n", ops[0]);
-            return false;
-        }
-    } else {
-        return false;
-    }
-}
-
diff --git a/src/kernel2/.ignorenobuild b/src/kernel2/.ignorenobuild
deleted file mode 100644
index e69de29b..00000000
diff --git a/src/kernel2/include/console.h b/src/kernel2/include/console.h
deleted file mode 100644
index 60e7e8e6..00000000
--- a/src/kernel2/include/console.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*

- * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.

- *

- * This code is derived from software contributed to the tyndur Project

- * by Burkhard Weseloh.

- *

- * Redistribution and use in source and binary forms, with or without

- * modification, are permitted provided that the following conditions

- * are met:

- * 1. Redistributions of source code must retain the above copyright

- *    notice, this list of conditions and the following disclaimer.

- * 2. 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.

- * 3. All advertising materials mentioning features or use of this software

- *    must display the following acknowledgement:

- *     This product includes software developed by the tyndur Project

- *     and its contributors.

- * 4. Neither the name of the tyndur Project nor the names of its

- *    contributors may be used to endorse or promote products derived

- *    from this software without specific prior written permission.

- *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

- * ``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 COPYRIGHT HOLDERS OR

- * CONTRIBUTORS 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 CONSOLE_H

-#define CONSOLE_H

-

-extern void init_console(void);

-

-extern void con_putc(const char c); // Zeichen ausgeben ohne Auswertung der ANSI-Codes

-extern void con_putc_ansi(const char c); // Zeichen ausgeben mit Auswertung der ANSI-Codes

-extern void con_puts(const char * s); // Zeichenkette ausgeben mit Auswertung der ANSI-Codes

-extern void con_putsn(unsigned int n, const char * s); // wie con_puts, allerdings werden maximal n Bytes ausgewertet

-extern void con_flush_ansi_escape_code_sequence(void); // Zwischenspeicher leeren

-

-#endif /* ndef CONSOLE_H */

diff --git a/src/kernel2/include/cpu.h b/src/kernel2/include/cpu.h
deleted file mode 100644
index 97b5cdee..00000000
--- a/src/kernel2/include/cpu.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2007-2012 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Antoine Kaufmann.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS 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 _CPU_H_
-#define _CPU_H_
-
-#include <types.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-#include "tasks.h"
-#include "cpu_arch.h"
-
-extern cpu_t cpus[];
-extern size_t cpu_count;
-
-cpu_t* cpu_get_current(void);
-void cpu_dump(machine_state_t* machine_state);
-
-/**
- * Wird aufgerufen, nachdem zu einem neuen Task gewechselt wurde
- */
-void cpu_prepare_current_task(void);
-
-#endif //ifndef _CPU_H_
-
-
diff --git a/src/kernel2/include/debug.h b/src/kernel2/include/debug.h
deleted file mode 100644
index d8540b40..00000000
--- a/src/kernel2/include/debug.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*

- * Copyright (c) 2006-2008 The tyndur Project. All rights reserved.

- *

- * This code is derived from software contributed to the tyndur Project

- * by Kevin Wolf.

- *

- * Redistribution and use in source and binary forms, with or without

- * modification, are permitted provided that the following conditions

- * are met:

- * 1. Redistributions of source code must retain the above copyright

- *    notice, this list of conditions and the following disclaimer.

- * 2. 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.

- * 3. All advertising materials mentioning features or use of this software

- *    must display the following acknowledgement:

- *     This product includes software developed by the tyndur Project

- *     and its contributors.

- * 4. Neither the name of the tyndur Project nor the names of its

- *    contributors may be used to endorse or promote products derived

- *    from this software without specific prior written permission.

- *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

- * ``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 COPYRIGHT HOLDERS OR

- * CONTRIBUTORS 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 _DEBUG_H_

-#define _DEBUG_H_

-

-#include <stdint.h>

-#include <stdbool.h>

-

-/* Debug-Funktionen und Helferlein */

-

-#define DEBUG_FLAG_INIT 1

-#define DEBUG_FLAG_STACK_BACKTRACE 2

-#define DEBUG_FLAG_PEDANTIC 4

-#define DEBUG_FLAG_SYSCALL 8

-

-///Setzt die richtigen Debug-Flags anhand der Commandline vom bootloader

-void debug_parse_cmdline(char* cmdline);

-

-///Ueberprueft ob ein bestimmtes Debug-Flag gesetzt ist

-bool debug_test_flag(uint32_t flag);

-

-///Gibt die Debug-Meldung aus, wenn das Flag gesetzt ist

-void debug_print(uint32_t flag, const char* message);

-
-/*
- * Gibt einen Stack Backtrace aus, beginnend an den �bergebenen Werten
- * f�r bp und ip
- */
-void stack_backtrace(uintptr_t start_bp, uintptr_t start_ip);
-
-#endif
diff --git a/src/kernel2/include/gdt.h b/src/kernel2/include/gdt.h
deleted file mode 100644
index 426775c8..00000000
--- a/src/kernel2/include/gdt.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*

- * Copyright (c) 2007 The tyndur Project. All rights reserved.

- *

- * This code is derived from software contributed to the tyndur Project

- * by Kevin Wolf.

- *

- * Redistribution and use in source and binary forms, with or without

- * modification, are permitted provided that the following conditions

- * are met:

- * 1. Redistributions of source code must retain the above copyright

- *    notice, this list of conditions and the following disclaimer.

- * 2. 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.

- * 3. All advertising materials mentioning features or use of this software

- *    must display the following acknowledgement:

- *     This product includes software developed by the tyndur Project

- *     and its contributors.

- * 4. Neither the name of the tyndur Project nor the names of its

- *    contributors may be used to endorse or promote products derived

- *    from this software without specific prior written permission.

- *

- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

- * ``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 COPYRIGHT HOLDERS OR

- * CONTRIBUTORS 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 _GDT_H_

-#define _GDT_H_

-#include <types.h>

-

-void gdt_init(void);

-void gdt_init_local(void);

-

-#endif //ifndef _GDT_H_

-

diff --git a/src/kernel2/include/kernel.h b/src/kernel2/include/kernel.h
deleted file mode 100644
index aabbb9e5..00000000
--- a/src/kernel2/include/kernel.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Burkhard Weseloh.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS 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 _KERNEL_H_
-#define _KERNEL_H_
-
-#include <stdint.h>
-
-extern uint64_t timer_ticks;
-
-__attribute__((noreturn)) void panic(char* message, ...);
-
-#define GLUE(x,y) x ## y
-#define BUILD_ASSERT(cnt) GLUE(__cdi_build_assert, cnt)
-#define BUILD_BUG_ON(x) \
-    struct BUILD_ASSERT(__COUNTER__) { int assertion[(x) ? -1 : 1];  };
-
-#define BUG_ON(c) \
-    do { \
-        if (c) { \
-            panic("BUG: %s:%d: " #c, __FILE__, __LINE__); \
-        } \
-    } while(0)
-
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-
-#define DIV_ROUND_UP(x, align)  (((x) + (align) + 1) / (align))
-#define ROUND_UP(x, align) (DIV_ROUND_UP(x, align) * (align))
-
-#endif
diff --git a/src/kernel2/include/kprintf.h b/src/kernel2/include/kprintf.h
deleted file mode 100644
index 4b7e29ae..00000000
--- a/src/kernel2/include/kprintf.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef KPRINTF_H
-#define KPRINTF_H
-
-#include <stdint.h>
-#include <stdarg.h>
-
-void kprintf(char* format, ...) __attribute__((format(printf,1,2)));
-void kaprintf(char* format, va_list args);
-
-/// Ist nur zu Testzwecken hier
-void kputn(unsigned long long x, int radix, int pad, char padchar);
-#endif /* ndef KPRINTF_H */
diff --git a/src/kernel2/include/multiboot.h b/src/kernel2/include/multiboot.h
deleted file mode 100644
index 39f116f3..00000000
--- a/src/kernel2/include/multiboot.h
+++ /dev/null
@@ -1,188 +0,0 @@
-/*-
- * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Julio M. Merino Vidal.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *    This product includes software developed by the NetBSD
- *    Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``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 FOUNDATION OR CONTRIBUTORS
- * 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 MULTIBOOT_H
-#define MULTIBOOT_H
-
-#include <stdint.h>
-
-/* --------------------------------------------------------------------- */
-
-/*
- * Multiboot header structure.
- */
-#define MULTIBOOT_HEADER_MAGIC            0x1BADB002
-#define MULTIBOOT_HEADER_MODS_ALIGNED    0x00000001
-#define MULTIBOOT_HEADER_WANT_MEMORY    0x00000002
-#define MULTIBOOT_HEADER_HAS_VBE        0x00000004
-#define MULTIBOOT_HEADER_HAS_ADDR       0x00010000
-
-struct multiboot_header {
-    uint32_t   mh_magic;
-    uint32_t   mh_flags;
-    uint32_t   mh_checksum;
-
-    /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */
-    uint32_t   mh_header_addr;
-    uint32_t   mh_load_addr;
-    uint32_t   mh_load_end_addr;
-    uint32_t   mh_bss_end_addr;
-    uint32_t   mh_entry_addr;
-
-    /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */
-    uint32_t   mh_mode_type;
-    uint32_t   mh_width;
-    uint32_t   mh_height;
-    uint32_t   mh_depth;
-} __attribute((packed));
-
-/* --------------------------------------------------------------------- */
-
-/*
- * Multiboot information structure.
- */
-#define MULTIBOOT_INFO_MAGIC            0x2BADB002
-#define MULTIBOOT_INFO_HAS_MEMORY        0x00000001
-#define MULTIBOOT_INFO_HAS_BOOT_DEVICE    0x00000002
-#define MULTIBOOT_INFO_HAS_CMDLINE        0x00000004
-#define MULTIBOOT_INFO_HAS_MODS            0x00000008
-#define MULTIBOOT_INFO_HAS_AOUT_SYMS    0x00000010
-#define MULTIBOOT_INFO_HAS_ELF_SYMS        0x00000020
-#define MULTIBOOT_INFO_HAS_MMAP            0x00000040
-#define MULTIBOOT_INFO_HAS_DRIVES        0x00000080
-#define MULTIBOOT_INFO_HAS_CONFIG_TABLE    0x00000100
-#define MULTIBOOT_INFO_HAS_LOADER_NAME    0x00000200
-#define MULTIBOOT_INFO_HAS_APM_TABLE    0x00000400
-#define MULTIBOOT_INFO_HAS_VBE            0x00000800
-
-struct multiboot_info {
-    uint32_t    mi_flags;
-
-    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */
-    uint32_t    mi_mem_lower;
-    uint32_t    mi_mem_upper;
-
-    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */
-    uint8_t     mi_boot_device_part3;
-    uint8_t     mi_boot_device_part2;
-    uint8_t     mi_boot_device_part1;
-    uint8_t     mi_boot_device_drive;
-
-    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */
-    uint32_t    mi_cmdline;
-
-    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */
-    uint32_t    mi_mods_count;
-    uint32_t    mi_mods_addr;
-
-    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */
-    uint32_t    mi_elfshdr_num;
-    uint32_t    mi_elfshdr_size;
-    uint32_t    mi_elfshdr_addr;
-    uint32_t    mi_elfshdr_shndx;
-
-    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */
-    uint32_t    mi_mmap_length;
-    uint32_t    mi_mmap_addr;
-
-    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */
-    uint32_t    mi_drives_length;
-    uint32_t    mi_drives_addr;
-
-    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */
-    uint32_t    unused_mi_config_table;
-
-    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */
-    uint32_t    mi_loader_name;
-
-    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */
-    uint32_t    unused_mi_apm_table;
-
-    /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */
-    uint32_t    unused_mi_vbe_control_info;
-    uint32_t    unused_mi_vbe_mode_info;
-    uint32_t    unused_mi_vbe_interface_seg;
-    uint32_t    unused_mi_vbe_interface_off;
-    uint32_t    unused_mi_vbe_interface_len;
-} __attribute((packed));
-
-extern struct multiboot_info multiboot_info;
-
-/* --------------------------------------------------------------------- */
-
-/*
- * Drive information.  This describes an entry in the drives table as
- * pointed to by mi_drives_addr.
- */
-struct multiboot_drive {
-    uint32_t    md_length;
-    uint8_t     md_number;
-    uint8_t     md_mode;
-    uint16_t    md_cylinders;
-    uint8_t     md_heads;
-    uint8_t     md_sectors;
-
-    /* The variable-sized 'ports' field comes here, so this structure
-     * can be longer. */
-};
-
-/* --------------------------------------------------------------------- */
-
-/*
- * Memory mapping.  This describes an entry in the memory mappings table
- * as pointed to by mi_mmap_addr.
- *
- * Be aware that mm_size specifies the size of all other fields *except*
- * for mm_size.  In order to jump between two different entries, you
- * have to count mm_size + 4 bytes.
- */
-struct multiboot_mmap {
-    uint32_t    mm_size;
-    uint64_t    mm_base_addr;
-    uint64_t    mm_length;
-    uint32_t    mm_type;
-} __attribute((packed));
-
-
-struct multiboot_module {
-  uint32_t start;
-  uint32_t end;
-  uint32_t cmdline;
-  uint32_t reserved;
-};
-
-#endif
diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h
deleted file mode 100644
index ad941e85..00000000
--- a/src/kernel2/include/syscall.h
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Antoine Kaufmann.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS 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 _SYSCALL_H_
-#define _SYSCALL_H_
-
-#include <types.h>
-#include <stdint.h>
-#include <syscall_structs.h>
-
-#include "cpu.h"
-
-// Ist das wirklich die korrekte Definition? Dieser Typ sollte der Groesse der
-// Werte die auf dem Stack gespeichert werden entsprechen.
-// FIXME: Doppelte Definition! (modules/include/syscall.h)
-typedef uintptr_t syscall_arg_t;
-
-typedef struct {
-    /// Pointer auf den Handler des Syscalls oder NULL, falls dieser Syscall
-    /// nicht existiert.
-    void* handler;
-    
-    /// Anzahl der Argumente die der Syscall benoetigt
-    size_t arg_count;
-
-    /// true, wenn der Syscall nur aus dem Kernelspace aufgerufen werden darf
-    bool privileged;
-} syscall_t;
-
-/// In diesem Array werden alle Syscalls gespeichert.
-extern syscall_t syscalls[];
-
-
-/// Architektur-Abhaengiger Handler, der die eigentlichen Handler aufruft
-void syscall_arch(machine_state_t* isf);
-
-
-/// Einen neuen Syscall verfuegbar machen
-void syscall_register(syscall_arg_t number, void* handler, size_t arg_count);
-
-/// Syscalls initialisieren
-void syscall_init(void);
-
-// ###########################################################################
-// SYSCALLS
-// ###########################################################################
-
-// Speicherverwaltung
-/// Einen Speicherblock allokieren.
-vaddr_t syscall_mem_allocate(size_t bytes, syscall_arg_t flags, paddr_t* phys);
-
-/// Physischen Speicher mappen
-vaddr_t syscall_mem_allocate_physical(
-    size_t bytes, paddr_t position, syscall_arg_t flags);
-
-/// Einen Speicherblock freigeben
-void syscall_mem_free(vaddr_t start, size_t bytes);
-
-/// Physischen Speicher freigeben
-void syscall_mem_free_physical(vaddr_t start, size_t bytes);
-
-/// Freie Pages und Gesamtspeicher zurueckgeben
-void syscall_mem_info(uint32_t* sum_pages, uint32_t* free_pages);
-
-
-// Prozessverwaltung
-/// PID des aktuellen Prozesses abfragen
-pid_t syscall_pm_get_pid(void);
-
-/// PID des Elternprozesses ausfindig machen
-pid_t syscall_pm_get_parent_pid(pid_t pid);
-
-/// Befehlszeile des aktuellen Prozesses abfragen
-const char* syscall_pm_get_cmdline(void);
-
-/// Kritischen Abschnitt betreten
-int syscall_pm_p(void);
-
-/// Kritischen Abschnitt verlassen
-int syscall_pm_v(pid_t pid);
-
-/// Kritischen Abschnitt verlassen und auf RPC warten
-int syscall_pm_v_and_wait_for_rpc(void);
-
-/// Die Kontrolle an einen anderen Task abgeben
-void syscall_pm_sleep(void);
-
-/// Die Kontrolle an einen anderen Task abgeben
-void kern_syscall_pm_sleep(tid_t yield_to, int status);
-
-/// Warten, bis ein RPC zu bearbeiten ist
-void syscall_pm_wait_for_rpc(void);
-
-/// Prozess erstellen
-pid_t syscall_pm_create_process(vaddr_t start, uid_t uid,
-    const char* cmdline, pid_t parent_pid);
-
-/// Aktuellen Prozess beenden
-void syscall_pm_exit_process(void);
-
-/// Alle Prozesse auflisten
-void* syscall_pm_enumerate_tasks(void);
-
-
-/// Thread erstellen
-tid_t syscall_pm_create_thread(vaddr_t start, void *arg);
-
-/// ID des aktuellen Threads abfragen
-tid_t syscall_pm_get_tid(void);
-
-/// Thread beenden
-void syscall_pm_exit_thread(void);
-
-/// Mutex nehmen
-void syscall_mutex_lock(int* mutex);
-
-/// Mutex freigeben
-void syscall_mutex_unlock(int* mutex);
-
-
-/// Speicher an einen anderen Prozess uebergeben
-void syscall_init_child_page(pid_t pid, vaddr_t src, vaddr_t dest,
-    size_t size);
-
-/// Initialisiert den Prozessparameterblock eines Kindprozesses
-int syscall_init_ppb(pid_t pid, int shm_id);
-int arch_init_ppb(pm_process_t* process, int shm_id, void* ptr, size_t size);
-
-/// IO-Ports anfordern
-int syscall_io_request_port(uint32_t port, uint32_t length);
-
-/// IO-Ports freigeben
-int syscall_io_release_port(uint32_t port, uint32_t length);
-
-/// Aktuelle Zeit abfragen (Mikrosekunden seit Systemstart)
-uint64_t syscall_get_tick_count(void);
-
-
-// SHM
-/// Neuen Shared Memory reservieren
-uint32_t syscall_shm_create(size_t size);
-
-/// Bestehenden Shared Memory oeffnen
-void* syscall_shm_attach(uint32_t id);
-
-/// Shared Memory schliessen
-void syscall_shm_detach(uint32_t id);
-
-/// Größe eines Shared Memory zurückgeben
-int32_t syscall_shm_size(uint32_t id);
-
-/// Einen Timer anlegen
-void syscall_add_timer(uint32_t timer_id, uint32_t usec);
-
-// RPC
-/// RPC-Handler registrieren
-void syscall_set_rpc_handler(vaddr_t address);
-
-/// RPC durchfuehren
-int syscall_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata,
-    size_t data_size, void* data);
-
-/// Von einem RPC zurueckkehren
-void syscall_fastrpc_ret(void);
-
-/// Interrupt registrieren
-void syscall_add_interrupt_handler(uint32_t intr);
-
-
-// LIO
-/// Ressource suchen
-void syscall_lio_resource(const char* path, size_t path_len, int flags,
-    lio_usp_resource_t* res_id);
-
-/// Informationen über eine Ressource abfragen
-int syscall_lio_stat(lio_usp_resource_t* resid, struct lio_stat* sbuf);
-
-/// Ressource öffnen
-void syscall_lio_open(lio_usp_resource_t* resid, int flags,
-    lio_usp_stream_t* stream_id);
-
-/// Pipe erstellen
-int syscall_lio_pipe(lio_usp_stream_t* stream_reader,
-                     lio_usp_stream_t* stream_writer,
-                     bool bidirectional);
-
-/// Ein- und Ausgabestream zusammensetzen
-int syscall_lio_composite_stream(lio_usp_stream_t* read,
-                                 lio_usp_stream_t* write,
-                                 lio_usp_stream_t* result);
-
-/// Stream schließen
-int syscall_lio_close(lio_usp_stream_t* stream_id);
-
-/// Zusätzliche ID für Stream erstellen
-int syscall_lio_dup(lio_usp_stream_t* source, lio_usp_stream_t* dest);
-
-/// Stream an anderen Prozess weitergeben
-int syscall_lio_pass_fd(lio_usp_stream_t* stream_id, pid_t pid);
-
-/// PID des Prozesses, der den Stream dem aktuellen übergeben hat, auslesen
-int syscall_lio_stream_origin(lio_usp_stream_t* stream_id);
-
-/// Aus Stream lesen
-void syscall_lio_read(lio_usp_stream_t* stream_id, uint64_t* offset,
-    size_t bytes, void* buffer, int updatepos, ssize_t* result);
-
-/// In Stream schreiben
-void syscall_lio_write(lio_usp_stream_t* stream_id, uint64_t* offset,
-    size_t bytes, const void* buffer, int updatepos, ssize_t* result);
-
-/// Cursorposition in der Datei ändern
-void syscall_lio_seek(lio_usp_stream_t* stream_id, int64_t* offset,
-    int whence, int64_t* result);
-
-/// Dateigröße ändern
-int syscall_lio_truncate(lio_usp_stream_t* stream_id, uint64_t* size);
-
-/// Veränderte Blocks schreiben
-int syscall_lio_sync(lio_usp_stream_t* stream_id);
-
-/// Verzeichnisinhalt auslesen
-void syscall_lio_read_dir(lio_usp_resource_t* res, size_t start, size_t num,
-    struct lio_usp_dir_entry* dent, ssize_t* result);
-
-/// Ressourcenspezifischen Befehl ausführen
-int syscall_lio_ioctl(lio_usp_stream_t* stream_id, int cmd);
-
-/// Neue Datei anlegen
-void syscall_lio_mkfile(lio_usp_resource_t* parent, const char* name,
-    size_t name_len, lio_usp_resource_t* result);
-
-/// Neues Verzeichnis anlegen
-void syscall_lio_mkdir(lio_usp_resource_t* parent, const char* name,
-    size_t name_len, lio_usp_resource_t* result);
-
-/// Neuen Symlink anlegen
-void syscall_lio_mksymlink(lio_usp_resource_t* parent, const char* name,
-    size_t name_len, const char* target, size_t target_len,
-    lio_usp_resource_t* result);
-
-/// Verzeichniseintrag löschen
-int syscall_lio_unlink(lio_usp_resource_t* parent, const char* name,
-    size_t name_len);
-
-/// Alle Blocks rausschreiben, die sich im Cache befinden
-int syscall_lio_sync_all(int soft);
-
-/// Service finden, der die Ressource als Pipequelle akzeptiert
-int syscall_lio_probe_service(lio_usp_resource_t* res,
-                              struct lio_probe_service_result* probe_data);
-
-// LIO-Server
-/// Neuen lio-Service registrieren
-int syscall_lio_srv_service_register(const char* name, size_t name_len,
-    void* buffer, size_t size);
-
-/// Neuen Tree-Ring registrieren
-int syscall_lio_srv_tree_set_ring(lio_usp_tree_t* tree_id, tid_t tid,
-    void* buffer, size_t size);
-
-/// Ressource fuer Kernel bereitstellen
-int syscall_lio_srv_res_upload(struct lio_server_resource* resource);
-
-/// Neuen Knoten erstellen
-int syscall_lio_srv_node_add(lio_usp_resource_t* parent,
-    lio_usp_resource_t* resource, const char* name, size_t name_len);
-
-/// Knoten loeschen
-int syscall_lio_srv_node_remove(lio_usp_resource_t* parent, const char* name,
-    size_t name_len);
-
-/// Kernel ueber abgearbeitete Operation informieren
-void syscall_lio_srv_op_done(struct lio_op* op, int status, uint64_t* result);
-
-/// Auf LIO-Operationen fuer diesen Prozess warten
-void syscall_lio_srv_wait(void);
-
-/// Cache-Blocks mit Uebersetzungstabelle anfordern
-int syscall_lio_srv_request_translated_blocks(lio_usp_resource_t* res,
-    uint64_t* offset, size_t num, uint64_t* table);
-
-
-// Diverse
-/// Textausgabe ueber den Kernel
-void syscall_putsn(int char_count, char* source);
-
-/// -ENOSYS
-int syscall_vm86_old(void* regs, uint32_t* memory);
-
-/// BIOS-Interrupt ausfuehren
-int syscall_vm86(uint8_t intr, void* regs, uint32_t* memory);
-
-#endif //ifndef _SYSCALL_H_
-
diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h
deleted file mode 100644
index 774ca39f..00000000
--- a/src/kernel2/include/tasks.h
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Antoine Kaufmann.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS 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 _TASKS_H_
-#define _TASKS_H_
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <types.h>
-#include <collections.h>
-#include <lost/config.h>
-
-#include "mm_arch.h"
-#include "lock.h"
-#include "multiboot.h"
-
-#define PM_STATUS_READY 0
-#define PM_STATUS_BLOCKED 1
-#define PM_STATUS_RUNNING 2
-#define PM_STATUS_WAIT_FOR_RPC 3
-#define PM_STATUS_WAIT_FOR_LIO 4
-#define PM_STATUS_WAIT_FOR_IO_REQUEST 5
-#define PM_STATUS_WAIT_FOR_DATA 6
-
-typedef struct pm_process {
-    /// Die eindeutige Prozessnummer
-    pid_t pid;
-
-    /// Elternprozess
-    struct pm_process* parent;
-
-    /// Der Kontext fuer die Speicherverwaltung
-    mmc_context_t context;
-
-    /// Liste mit den Threads
-    list_t* threads;
-
-    /// Adresse, an der der naechste Thread seinen Stack ablegen soll
-    vaddr_t next_stack;
-
-    /// Kommandozeile die zum Starten des Prozesses benutzt wurde
-    char* cmdline;
-
-    /// Aktueller Status
-    uint32_t status;
-
-    /// Wird gesperrt, wenn aenderungen am Prozess vorgenommen werden
-    lock_t lock;
-
-    /// Der RPC-Handler fuer diesen Prozess
-    vaddr_t rpc_handler;
-
-    /// Die PID des Prozesses, der RPC fuer diesen Prozess abgestellt hat
-    uint32_t blocked_by_pid;
-
-    /// Die Anzahl von p()s (RPC wird erst bei 0 wieder freigegeben)
-    uint32_t blocked_count;
-
-    /// Eine Liste von RPC-Backlinks
-    list_t* rpcs;
-
-    /// Eine Liste von geoeffneten SHM-Bereichen
-    list_t* shm;
-
-#if CONFIG_ARCH == ARCH_I386
-    /// IO-Bitmap
-    void* io_bitmap;
-#elif CONFIG_ARCH == ARCH_AMD64
-#else
-#error Architektur nicht unterstuetzt
-#endif
-
-    /**
-     * Eine Liste von Eventhandlern, die beim Loeschen des Prozesses
-     * aufgerufen werden
-     */
-    list_t* on_destroy;
-
-    /// Speicherverbrauch des Prozesses
-    uintmax_t memory_used;
-
-    /// Baum aller geoeffneten LostIO-Streams
-    tree_t* lio_streams;
-} pm_process_t;
-
-typedef struct {
-    /// Adresse des Kernelstack-Pointers
-    vaddr_t kernel_stack;
-
-    /// Anfang des Stacks
-    vaddr_t kernel_stack_bottom;
-
-    /// Groesse des Kernelstacks
-    size_t kernel_stack_size;
-
-    /// Aktueller Stackframe des Userspace-Interrupts
-    vaddr_t user_isf;
-
-    /// Anfang des Usermode-Stacks
-    vaddr_t user_stack_bottom;
-
-    /// Der Prozess, dem der Thread gehoert
-    pm_process_t* process;
-
-    /// Aktueller Status
-    uint32_t status;
-
-    /// Wird gesperrt, wenn aenderungen am Thread vorgenommen werden
-    lock_t lock;
-
-    /// Gesetzt, wenn der Thread ein VM86-Thread mit allem Drum und Dran ist
-    bool vm86;
-
-    /// Eindeutige Threadnummer
-    tid_t tid;
-
-    /// Gesetzt, wenn der Thread beim Beenden den gesamten Prozess beendet
-    bool is_main_thread;
-
-    /**
-     * Eine Liste von Eventhandlern, die beim Loeschen des Threads
-     * aufgerufen werden
-     */
-    list_t* on_destroy;
-
-    /// Eine Liste der von diesem Thread angebotenen LIO-Services
-    list_t* lio_services;
-
-    /// Eine Liste aller LIO-Trees, deren Ring dieser Thread verarbeitet
-    list_t* lio_trees;
-} pm_thread_t;
-
-typedef void (*pm_process_destroy_handler)(pm_process_t* process, void* prv);
-typedef void (*pm_thread_destroy_handler)(pm_thread_t* thread, void* prv);
-
-extern list_t* process_list;
-
-/**
- * Prozessverwaltung
- */
-/// Prozessverwaltung initialisieren
-void pm_init(void);
-
-/// Prozess erstellen
-pm_process_t* pm_create(pm_process_t* parent, const char* cmdline);
-
-/// Datenstrukturen eines Prozesses freigeben (vor dem Taskwechsel)
-void pm_prepare_destroy(pm_process_t* process);
-
-/// Prozess zerstoeren
-void pm_destroy(pm_process_t* process);
-
-/// Prozess blockieren
-bool pm_block(pm_process_t* process);
-
-/// Prozess entblocken
-bool pm_unblock(pm_process_t* process);
-
-/// Prozess anhand seiner PID suchen
-pm_process_t* pm_get(pid_t pid);
-
-/// RPC-Empfang fuer einen Prozess blockieren
-bool pm_block_rpc(pm_process_t* task, pid_t blocked_by);
-
-/// RPC-Empfang fuer einen Prozess wieder freigeben
-bool pm_unblock_rpc(pm_process_t* task, pid_t blocked_by);
-
-
-/// Handler fuer das Loeschen des Prozesses registrieren
-void pm_register_on_destroy(pm_process_t* process,
-    pm_process_destroy_handler handler, void* prv);
-void pm_unregister_on_destroy(pm_process_t* process,
-    pm_process_destroy_handler handler, void* prv);
-
-/// Handler fuer das Loeschen des Threads registrieren
-void pm_thread_register_on_destroy(pm_thread_t* thread,
-    pm_thread_destroy_handler handler, void* prv);
-
-/// Entfernt den gegebenen Task aus allen RPC-Backlinks
-void rpc_destroy_task_backlinks(pm_process_t* destroyed_process);
-
-/**
- * Threadverwaltung
- */
-/// Neuen Thread erstellen
-pm_thread_t* pm_thread_create(pm_process_t* process, vaddr_t entry);
-
-/// Einen Thread zerstoeren
-void pm_thread_destroy(pm_thread_t* thread);
-
-/// Thread blockieren
-bool pm_thread_block(pm_thread_t* thread);
-
-/// Thread anhand der TID (und ggf. Prozess) suchen
-pm_thread_t* pm_thread_get(pm_process_t* process, tid_t tid);
-
-/// Thread entblocken
-bool pm_thread_unblock(pm_thread_t* thread);
-
-/// Darf der Thread einfach auf RUNNING gesetzt werden?
-bool pm_thread_runnable(pm_thread_t* thread);
-
-/**
- * Scheduling
- */
-/// Dem Scheduler einen neuen Thread hinzufuegen
-void pm_scheduler_add(pm_thread_t* thread);
-
-/// Einen Thread aus dem Scheduler entfernen
-void pm_scheduler_delete(pm_thread_t* thread);
-
-/// Die Liste im Scheduler aktualisieren
-void pm_scheduler_refresh(void);
-
-/// Einen Thread zum ausfuehren holen
-pm_thread_t* pm_scheduler_pop(void);
-
-/// Einen bestimmten Thread zum Ausfuehren holen
-void pm_scheduler_get(pm_thread_t* thread);
-
-/// Einen ausgefuerten Thread wieder zurueck an den Scheduler geben
-void pm_scheduler_push(pm_thread_t* thread);
-
-/// Kontrolle vom aktuellen Kernelthread an einen anderen Thread abgeben
-void pm_scheduler_yield(void);
-
-/// Kontrolle an einen bestimmten Thread abgeben, mit Folgezustand
-void pm_scheduler_kern_yield(tid_t tid, int status);
-
-/// Versucht einen Taskwechsel zum übergebenen Thread
-void pm_scheduler_try_switch(pm_thread_t* thread);
-
-/**
- * Initialisierung
- */
-/// Das Init-Modul laden
-void load_init_module(struct multiboot_info* multiboot_info);
-
-/// Alle weiteren Module an init uebergeben
-void load_multiboot_modules(struct multiboot_info* multiboot_info);
-
-// Kann erst hier eingebunden werden, weil es die Strukturen braucht
-#include "cpu.h"
-
-#define current_thread (cpu_get_current()->thread)
-#define current_process (cpu_get_current()->thread->process)
-
-#endif //ifndef _TASKS_H_
-
diff --git a/src/kernel2/include/timer.h b/src/kernel2/include/timer.h
deleted file mode 100644
index b4d586d7..00000000
--- a/src/kernel2/include/timer.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2006-2009 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the LOST Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the LOST Project
- *     and its contributors.
- * 4. Neither the name of the LOST Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS 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 _TIMER_H_
-#define _TIMER_H_
-
-#include <stdint.h>
-#include "tasks.h"
-
-void timer_init(void);
-void timer_register(pm_process_t* task, uint32_t timer_id, uint32_t usec);
-void timer_notify(uint64_t microtime);
-void timer_cancel_all(pm_process_t* task);
-
-#endif
diff --git a/src/kernel2/include/vm86.h b/src/kernel2/include/vm86.h
deleted file mode 100644
index 978f762f..00000000
--- a/src/kernel2/include/vm86.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2010 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS 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 _VM86_H_
-#define _VM86_H_
-
-void vm86_init(void);
-int arch_vm86(uint8_t intr, void* regs, uint32_t* memory);
-
-#endif
-
diff --git a/src/kernel2/src/console.c b/src/kernel2/src/console.c
deleted file mode 100644
index 50afd286..00000000
--- a/src/kernel2/src/console.c
+++ /dev/null
@@ -1,609 +0,0 @@
-/*
- * Copyright (c) 2006 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Burkhard Weseloh.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdint.h>
-#include <string.h>
-#include <ports.h>
-
-/*
- * Das hier ist eine sehr beschr�nkte Untermenge der ANSI Escape Codes. Alle
- * Sequenzen werden mit dem ASCII Zeichen ESC (Wert 0x1b) eingeleitet. ESC
- * soll im folgenden dieses Zeichen darstellen. Wir k�nnen folgende Escape 
- * Sequenzen behandeln:
- *
- * ESC[#A - Cursor um # Zeilen nach oben bewegen
- * ESC[#B - Cursor um # Zeilen nach unten bewegen
- * ESC[#C - Cursor um # Zeilen nach rechts bewegen
- * ESC[#D - Cursor um # Zeilen nach links bewegen
- * ESC[2J - Bildschirm leeren
- * ESC[K - Bis Zeile von der Cursor-Position zum Ende leeren
- * ESC[#m oder ESC[#;#m - Vorder- und Hintergrundfarbe �ndern, Fettschrift, Blinken
- * ESC[s - Cursor-Position speichern
- * ESC[u - Cursor-Position wiederherstellen
- *
- * Folgende Farbcodes werden bei und ESC[#m oder ESC[#;#m unterst�tzt:
- * - Attribute:
- *  0 - Normale Schrift
- *  1 - Fett
- *  5 - Blinken
- * - Vordergrundfarben:
- *  30 - Schwarz
- *  31 - Rot
- *  32 - Gr�n
- *  33 - Gelb
- *  34 - Blau
- *  35 - Magenta
- *  36 - Cyan
- *  37 - Weiss
- * - Hintergrundfarben:
- *  40 - Schwarz
- *  41 - Rot
- *  42 - Gr�n
- *  43 - Gelb
- *  44 - Blau
- *  45 - Magenta
- *  46 - Cyan
- *  47 - Weiss
- *
- * Es k�nnen nur 1 oder 2 Farbcodes pro Escape-Sequenz angewendet werden.
- *
- * Ung�ltige und nicht erkannte Sequenzen werden einfach ausgegeben.
- */
-
-#define ASCII_ESC 0x1b
-
-#define SCREEN_WIDTH 80
-#define SCREEN_HEIGHT 25
-
-void con_set_hw_cursor(void);
-
-unsigned short * vidmem = (unsigned short*)0xb8000;
-
-// Aktuelle Cursor-Position
-static unsigned int cursor_x;
-static unsigned int cursor_y;
-
-typedef enum ansi_esc_seq_status
-{
-    INVALID = 0,
-    SUCCESS,
-    NEED_MORE,
-} ansi_esc_seq_status_t;
-
-// Puffer f�r die ANSI-Sequenzen
-static char ansi_buf[16];
-static unsigned int ansi_buf_ofs = 0;
-
-// Aufschl�sselung des Attribut-Bytes vom Text Modus
-static union
-{
-    unsigned char _color;
-    struct 
-    {
-        unsigned char foreground : 3;
-        unsigned char bold : 1;
-        unsigned char background : 3;
-        unsigned char blink : 1;
-    };
-} con_color;
-
-/**
- * Setzt die Cursor-Position
- */
-static void con_set_cursor_pos(unsigned int x, unsigned int y)
-{
-    if(x >= SCREEN_WIDTH)
-    {
-        cursor_x = SCREEN_WIDTH - 1;
-    }
-    else
-    {
-        cursor_x = x;
-    }
-
-    if(y >= SCREEN_HEIGHT)
-    {
-        cursor_y = SCREEN_HEIGHT - 1;
-    }
-    else
-    {
-        cursor_y = y;
-    }
-
-    con_set_hw_cursor();
-}
-
-/**
- * Leert den Bildschirm
- */
-static void con_clear_screen(void)
-{
-    int i;
-
-    for(i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++)
-    {
-        vidmem[i] = con_color._color << 8;
-    }
-    
-    con_set_cursor_pos(0, 0);
-}
-
-/**
- * Scrollt eine Zeile nach unten
- */
-static void scroll_down(void)
-{
-    int i;
-    
-    memmove(vidmem, vidmem + SCREEN_WIDTH, SCREEN_WIDTH * (SCREEN_HEIGHT - 1) * 2);
-
-    for(i = SCREEN_WIDTH * (SCREEN_HEIGHT - 1); i < SCREEN_WIDTH * SCREEN_HEIGHT; i++)
-    {
-        vidmem[i] = con_color._color << 8;
-    }
-
-    con_set_cursor_pos(cursor_x, cursor_y - 1);
-}
-
-/**
- * Setzt die Attribute f�r die folgenden Ausgabe entsprechend der obigen Liste.
- */
-static ansi_esc_seq_status_t handle_ansi_formatting_sequence_number(int n)
-{
-    static char colors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; /* Zum Umrechnen der ANSI Farbcodes in die VGA Palette. */
-
-    switch(n)
-    {
-        case 0: // Normal
-            con_color.bold = 0;
-            con_color.blink = 0;
-            break;
-        
-        case 1: // Fett
-            con_color.bold = 1;
-            break;
-
-        case 5: // Blinken
-            con_color.blink = 1;
-            break;
-
-        case 30 ... 37: // Vordergrundfarbe
-            con_color.foreground = colors[n - 30];
-            break;
-
-        case 40 ... 47: // Hintergrundfarbe
-            con_color.background = colors[n - 40];
-            break;
-
-        default:
-            return INVALID;
-    }
-
-    return SUCCESS;
-}
-
-/**
- * L�scht den Bildschirm von der aktuellen Cursor Position bis zur
- * angegebenen Spalte
- *
- * @return Die Spalte bis zu der gel�scht wurde
- */
-static unsigned int con_clear_to(unsigned int column)
-{
-    int i;
-
-    for(i = cursor_x; i < column; i++)
-    {
-        vidmem[cursor_y * SCREEN_WIDTH + i] = con_color._color << 8;
-    }
-
-    return column;
-}
-
-/**
- * Versucht eine ANSI-Escape-Code-Sequenz zu parsen. 
- *
- * @param ansi_buf Sequenz die ausgewertet werden soll
- * @param ansi_buf_len Anzahl der auszuwertenden Bytes
- * 
- * @return INVALID, wenn die ANSI-Code-Sequenz ung�ltig ist, SUCCESS, wenn die
- *    ANSI-Code-Sequenz erfolgreich ausgewertet wurde, NEED_MORE, wenn die 
- *    Sequenz unvollst�ndig ist, und noch weitere Zeichen zur Auswertung 
- *    eingelesen werden m�ssen.
- */
-static ansi_esc_seq_status_t con_ansi_parse(const char * ansi_buf, unsigned int ansi_buf_len)
-{
-    static unsigned int save_cursor_x;
-    static unsigned int save_cursor_y;
-
-    int i;
-    int n1 = 0, n2 = 0;
-    int have_n1 = 0, have_n2 = 0, have_delimiter = 0;
-    
-    if(ansi_buf_len == 0)
-    {
-        return NEED_MORE;
-    }
-
-    if(ansi_buf[0] != ASCII_ESC)
-    {
-        return INVALID;
-    }
-
-    if(ansi_buf_len == 1)
-    {
-        return NEED_MORE;
-    }
-
-    if(ansi_buf[1] != '[')
-    {
-        return INVALID;
-    }
-
-    if(ansi_buf_len == 2)
-    {
-        return NEED_MORE;
-    }
-
-    for(i = 2; i < ansi_buf_len; i++)
-    {
-        switch(ansi_buf[i])
-        {
-            case '0' ... '9':
-                if(!have_delimiter)
-                {
-                    n1 = n1 * 10 + (ansi_buf[i] - '0');
-                    have_n1 = 1;
-                }
-                else
-                {
-                    n2 = n2 * 10 + (ansi_buf[i] - '0');
-                    have_n2 = 1;
-                }
-                break; // n�chstes Zeichen auswerten
-
-            case ';':
-                if(have_delimiter)
-                {
-                    return INVALID;
-                }
-                have_delimiter = 1;
-                break; // n�chstes Zeichen auswerten
-
-
-            case 'A': // ESC[#A - Cursor um # Zeilen nach oben bewegen
-                if(have_delimiter || !have_n1 || have_n2)
-                {
-                    return INVALID;
-                }
-                con_set_cursor_pos(cursor_x, cursor_y - n1);
-                return SUCCESS;
-
-            case 'B': // ESC[#B - Cursor um # Zeilen nach unten bewegen
-                if(have_delimiter || !have_n1 || have_n2)
-                {
-                    return INVALID;
-                }
-                con_set_cursor_pos(cursor_x, cursor_y + n1);
-                return SUCCESS;
-
-            case 'C': // ESC[#C - Cursor um # Zeilen nach rechts bewegen
-                if(have_delimiter || !have_n1 || have_n2)
-                {
-                    return INVALID;
-                }
-                con_set_cursor_pos(cursor_x + n1, cursor_y);
-                return SUCCESS;
-                
-            case 'D': // ESC[#D - Cursor um # Zeilen nach links bewegen
-                if(have_delimiter || !have_n1 || have_n2)
-                {
-                    return INVALID;
-                }
-                con_set_cursor_pos(cursor_x - n1, cursor_y);
-                return SUCCESS;
-
-            case 'H': // ESC[#;#H - Cursor zur Zeile # und Spalte # bewegen
-            case 'f':
-                if(!have_n1 || !have_n2)
-                {
-                    return INVALID;
-                }
-                
-                con_set_cursor_pos(n1, n2);
-                return SUCCESS;
-
-            case 'J': // ESC[2J - Bildschirm leeren
-                if(have_delimiter || !have_n1 || have_n2 || n1 != 2)
-                {
-                    return INVALID;
-                }
-                con_clear_screen();
-                return SUCCESS;
-
-            case 'K': // ESC[K - Bis Zeile von der Cursor Position zum Ende leeren
-                if(have_delimiter || have_n1 || have_n2)
-                {
-                    return INVALID;
-                }
-                
-                con_clear_to(SCREEN_WIDTH);
-
-                return SUCCESS;
-
-            case 'm': // ESC[#m oder ESC[#;#m - Vorder- und Hintergrundfarbe �ndern, Fettschrift, Blinken
-                if(!have_n1)
-                {
-                    return INVALID;
-                }
-                
-                if(handle_ansi_formatting_sequence_number(n1) != SUCCESS)
-                {
-                    return INVALID;
-                }
-
-                if(have_n2)
-                {
-                    if(handle_ansi_formatting_sequence_number(n2) != SUCCESS)
-                    {
-                        return INVALID;
-                    }
-                }
-
-                return SUCCESS;
-
-            case 's': // ESC[s - Cursor-Position speichern
-                if(have_delimiter || have_n1 || have_n2)
-                {
-                    return INVALID;
-                }
-                save_cursor_x = cursor_x;
-                save_cursor_y = cursor_y;
-
-                return SUCCESS;
-
-            case 'u': // ESC[u - Cursor-Position wiederherstellen
-                if(have_delimiter || have_n1 || have_n2)
-                {
-                    return INVALID;
-                }
-                cursor_x = save_cursor_x;
-                cursor_y = save_cursor_y;
-
-                return SUCCESS;
-
-            default:
-                return INVALID;
-        }
-    }
-
-    return NEED_MORE;
-}
-
-/**
- * Gibt ein Zeichen auf der Konsole aus.
- */
-void con_putc(const char c)
-{
-    static char last_char = 0;
-
-    if (c == '\n') {
-        outb(0x3f8, '\r');
-        while ((inb(0x3fd) & 0x20) == 0) asm("nop");
-    }
-    outb(0xe9, c);
-    outb(0x3f8, c);
-    while ((inb(0x3fd) & 0x20) == 0) asm("nop");
-    
-    switch(c)
-    {
-        case '\n':
-            if (last_char != '\r') {
-                con_clear_to(SCREEN_WIDTH);
-            }
-            cursor_x = 0;
-            cursor_y++;
-            break;
-        
-        case '\r':
-            cursor_x = 0;
-            break;
-        
-        case '\t':
-            cursor_x = con_clear_to((cursor_x & ~7) + 8);
-            break;
-
-        default:
-            vidmem[cursor_x + cursor_y * SCREEN_WIDTH] = c | (con_color._color << 8);
-            cursor_x++;
-            break;
-    }
-    
-    if(cursor_x >= SCREEN_WIDTH)
-    {
-        cursor_y += cursor_x / SCREEN_WIDTH;
-        cursor_x %= SCREEN_WIDTH;
-    }
-    
-
-    while(cursor_y >= SCREEN_HEIGHT)
-    {
-        scroll_down();
-    }
-    con_set_hw_cursor();
-
-    last_char = c;
-}
-
-/**
- * Gibt ein Zeichen auf der Konsole aus. Wenn das Zeichen ein Escape-Zeichen
- * ist, wird es und die folgenden Zeichen in einem Puffer zwischen gespeichert,
- * bis entweder diese Zeichenfolge erfolgreich als ANSI-Escape-Code-Sequenz
- * ausgewertet wurde, oder feststeht, dass diese Sequenz ung�ltig ist. In 
- * diesem Fall werden alle Zeichen einschlie�lich des Escape-Zeichens auf der 
- * Konsole ausgegeben.
- */
-void con_putc_ansi(const char c)
-{
-    ansi_esc_seq_status_t status;
-    int i;
-
-    if(c == ASCII_ESC || ansi_buf_ofs > 0)
-    {
-        ansi_buf[ansi_buf_ofs++] = c;
-
-        status = con_ansi_parse(ansi_buf, ansi_buf_ofs);
-
-        switch(status)
-        {
-            case NEED_MORE:
-                if(ansi_buf_ofs <= sizeof(ansi_buf))
-                {
-                    break;
-                }
-                // fall through
-
-            case INVALID:
-                for(i = 0; i < ansi_buf_ofs; i++)
-                {
-                    con_putc(ansi_buf[i]);
-                }
-                ansi_buf_ofs = 0;
-                break;
-            
-            case SUCCESS:
-                ansi_buf_ofs = 0;
-                break;
-        }
-    }
-    else
-    {
-        con_putc(c);
-    }
-}
-
-/**
- * Leert den Puffer, in dem die Zeichen einer m�glichen ANSI-Escape-Code-
- * Sequenz zwischengespeichert werden. Diese Funktion muss aufgerufen werden,
- * wenn sichergestellt werden soll, dass s�mtliche Zeichen, die via 
- * con_putc_ansi ausgegeben werden sollen, tats�chlich ausgegeben werden.
- */
-void con_flush_ansi_escape_code_sequence(void)
-{
-    int i;
-    
-    if(ansi_buf_ofs > 0)
-    {
-        for(i = 0; i < ansi_buf_ofs; i++)
-        {
-            con_putc(ansi_buf[i]);
-        }
-        ansi_buf_ofs = 0;
-    }
-}
-
-/**
- * Gibt eine Zeichenkette auf der Konsole aus. Diese Zeichenkette kann
- * ANSI-Steuercodes enthalten. 
- * Unvollst�ndige und fehlerhafte Sequenzen werden einfach ausgegeben.
- */
-void con_puts(const char * s)
-{
-    while(*s)
-    {
-        con_putc_ansi(*s);
-        s++;
-    }
-
-    con_flush_ansi_escape_code_sequence();
-}
-
-/**
- * Gibt eine Zeichenkette auf der Konsole aus. Diese Zeichenkette kann
- * ANSI-Steuercodes enthalten. Die Ausgabe terminiert bei Erreichen eines
- * Null-Bytes oder wenn n Bytes ausgewertet wurden.
- * Unvollst�ndige und fehlerhafte Sequenzen werden einfach ausgegeben.
- */
-void con_putsn(unsigned int n, const char * s)
-{
-    while(n-- && *s)
-    {
-        con_putc_ansi(*s);
-        s++;
-    }
-
-    con_flush_ansi_escape_code_sequence();
-}
-
-/**
- * Initialisiert die Console, in dem der Bildschirm geleert wird.
- */
-void init_console(void)
-{
-    con_color._color = 0x07;
-    con_clear_screen();
-    
-    /* Initialisiert die serielle Schnittstelle */
-    /* 9600 Baud, 8 Datenbits, 1 Stopbit, keine Parit�t */
-    
-    /* COM1 -> 0x3F8 */
-    outb(0x3FB, 0x83); /* DLAB = 1 */
-    outb(0x3F8, 0x0C); /* 9600 Baud */
-    outb(0x3F9, 0x00);
-    outb(0x3FB, 0x03); /* DLAB = 0 */
-    outb(0x3F9, 0x00); /* keine Interrupts ausl�sen */
-    outb(0x3FA, 0x00); /* FIFOs deaktiviert (8250, 16450) */
-    outb(0x3FC, 0x00); /* Loopback deaktivieren, Aux1 & Aux2 deaktivieren */
-}
-
-/**
- * Aktualisiert die Postition des Hardware Cursors
- */
-void con_set_hw_cursor(void)
-{
-    //Hardware Cursor verschieben
-    uint16_t hw_cursor_pos = cursor_x + cursor_y * SCREEN_WIDTH;
-    outb(0x3D4, 15);
-    outb(0x3D5, hw_cursor_pos);
-    outb(0x3D4, 14);
-    outb(0x3D5, hw_cursor_pos >> 8);
-}
-
-int puts(char * s)
-{
-    con_puts(s);
-    return 0;
-}
-
diff --git a/src/kernel2/src/debug.c b/src/kernel2/src/debug.c
deleted file mode 100644
index 28312dbe..00000000
--- a/src/kernel2/src/debug.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2006 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Burkhard Weseloh.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <elf32.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <string.h>
-
-#include <lost/config.h>
-#include "kprintf.h"
-#include "multiboot.h"
-#include "debug.h"
-
-static uint32_t debug_flags = 0;
-
-/**
- * Ueberprueft ob ein bestimmtes Debug-Flag gesetzt ist
- *
- * @param flag Flag-Nummer
- *
- * @return TRUE wenn gesetzt, FALSE sonst
- */
-bool debug_test_flag(uint32_t flag)
-{
-    return ((debug_flags & flag) != 0);
-}
-
-/**
- * Gibt die Debug-Meldung aus, wenn das Flag gesetzt ist.
- *
- * @param flag Flag-Nummer
- */
-void debug_print(uint32_t flag, const char* message)
-{
-    if (debug_test_flag(flag)) {
-        kprintf("DEBUG: %s\n", message);
-    }
-}
-
-///Setzt die richtigen Debug-Flags anhand der Commandline vom Bootloader
-void debug_parse_cmdline(char* cmdline)
-{
-    char* pos = strstr(cmdline, "debug=");
-    debug_flags = 0;
-
-    if(pos == NULL) return;
-
-    //Debug= ueberspringen
-    pos += 6;
-    while((*pos != 0) && (*pos != ' '))
-    {
-        switch(*pos)
-        {
-            case 'i':
-                debug_flags |= DEBUG_FLAG_INIT;
-                break;
-
-            case 'p':
-                debug_flags |= DEBUG_FLAG_PEDANTIC;
-                break;
-
-            case 's':
-                debug_flags |= DEBUG_FLAG_STACK_BACKTRACE;
-                break;
-
-            case 'c':
-                debug_flags |= DEBUG_FLAG_SYSCALL;
-                break;
-        }
-        pos++;
-    }
-}
-
diff --git a/src/kernel2/src/init.c b/src/kernel2/src/init.c
deleted file mode 100644
index 2a38a759..00000000
--- a/src/kernel2/src/init.c
+++ /dev/null
@@ -1,357 +0,0 @@
-/*  
- * Copyright (c) 2006 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Andreas Klebinger.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- * ``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 COPYRIGHT HOLDERS OR 
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */  
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <lost/config.h>
-#include <lock.h>
-
-#include "multiboot.h"
-#include "mm.h"
-#include "im.h"
-#include "tasks.h"
-#include "syscall.h"
-
-#include "console.h"
-#include "kprintf.h"
-#include "debug.h"
-#include "apic.h"
-#include "lock.h"
-#include "gdt.h"
-#include "timer.h"
-#include "lostio/core.h"
-
-struct multiboot_info multiboot_info;
-
-#define init_context (&init_thread.process->context)
-
-extern const void kernelstack_bottom;
-extern const void kernelstack;
-
-pm_thread_t init_thread;
-pm_process_t init_process = {
-    .cmdline = "(Kernel)",
-};
-
-lock_t init_lock = 0;
-
-void smp_init(void);
-void gdt_init(void);
-void vm86_init(void);
-void panic(char* message, ...);
-
-/**
- * Liest die Kernelkommandozeile ein
- *
- * Als erster Teilstring wird einfach irgendwas akzeptiert, weil davon
- * auszugehen ist, dass das der Kernelname ist. GRUB 2 übergibt den
- * Kernelnamen allerdings nicht, deswegen werden auch an erster Position
- * Parameter ausgewertet, wenn sie bekannt sind.
- */
-static void parse_cmdline(char* cmdline)
-{
-    char* p;
-    extern bool enable_smp;
-    bool kernel_name = true;
-
-    p = strtok(cmdline, " ");
-
-    while (p) {
-        if (!strncmp(p, "debug=", 6)) {
-            debug_parse_cmdline(p);
-        } else if (!strcmp(p, "smp")) {
-            enable_smp = true;
-        } else if (kernel_name) {
-            kernel_name = false;
-        } else {
-            kprintf("Unbekannte Option: '%s'\n", p);
-        }
-
-        p = strtok(NULL, " ");
-    }
-}
-
-/**
- * Kernel-Initialisierung erfolgt hier,
- * die Funktion init wird von header.asm aufgerufen (BSP = true) oder aus
- * smp_trampoline.asm
- *
- * @param multiboot_magic Multiboot Magic-Number
- * @param multiboot_info Pointer zur Multiboot-Info-Struct
- * @param bsp true, wenn die Funktion auf dem Bootstrap-Prozessor laeuft
- */
-void init(int multiboot_magic, struct multiboot_info *boot_info, bool bsp)
-{
-    static lock_t init_lock = LOCK_LOCKED;;
-    // Diese ersten Initialisierungen muessen nur einmal, und ganz am Anfang
-    // gemacht werden.
-    if (bsp == true) {
-        init_console();
-
-        // Multiboot-Infos sichern
-        memcpy(&multiboot_info, boot_info, sizeof(struct multiboot_info));
-
-        // Hiermit wird eine Laufende Multitasking-Umgebung simuliert. Dies ist
-        // notwendig, damit im restlichen Code keine Aenderungen notwendig sind
-        // fuer die Initialisierung.
-        init_thread = (pm_thread_t) {
-            .process                = &init_process,
-            .kernel_stack_bottom    = (vaddr_t) &kernelstack_bottom,
-            .kernel_stack_size      = (uint8_t*) &kernelstack
-                                    - (uint8_t*) &kernelstack_bottom,
-        };
-
-        cpu_get(0)->thread = &init_thread;
-
-        // Debugparameter verarbeiten, das ist aber nur moeglich, wenn eine
-        // Kernelkommandozeile existiert.
-        if ((multiboot_info.mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0) {
-            parse_cmdline((char*)(uintptr_t)multiboot_info.mi_cmdline);
-        }
-
-#if CONFIG_ARCH == ARCH_I386
-        // IVT fuer den VM86 sichern
-        vm86_init();
-#endif
-
-        debug_print(DEBUG_FLAG_INIT, "Initialisiere physische "
-            "Speicherverwaltung");
-        pmm_init(&multiboot_info);
-
-        // APIC initialisieren (Wird bei der SMP-Initialisierung genutzt
-        apic_init();
-
-        // SMP muss _direkt nach_ der physikalischen Speicherverwaltung
-        // initialisiert werden, da sonst notwendige Strukturen im Speicher
-        // dazu ueberschrieben werden koennten.
-        debug_print(DEBUG_FLAG_INIT, "Initialisiere Mehrprozessor-"
-            "Unterstuetzung");
-        smp_init();
-
-        // GDT und IDT vorbereiten
-        debug_print(DEBUG_FLAG_INIT, "gdt/idt_init");
-        gdt_init();
-        im_init();
-
-        // Eventuellen zusaetzlichen Prozessoren Mitteilen, dass sie mit der
-        // Initialisierung fortfahren duerfen.
-        unlock(&init_lock);
-    } else {
-        lock_wait(&init_lock);
-
-        // APIC initialisieren. Dies ist beim BSP bereits erledigt.
-        apic_init();
-    }
-
-    // Die IDT und die GDT wurden schon vorbereitet und muessen jetzt nur noch
-    // aktiviert werden auf diesem Prozessor.
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere Deskriptortabellen fuer einen "
-        "Prozessor");
-    gdt_init_local();
-    im_init_local();
-
-
-    // Auf dem BSP muss die ganze virtuelle Speicherverwaltung initialisiert
-    // werden. Bei den APs reicht es, wenn sie ihren Stack mappen.
-    static volatile lock_t mm_prepare_lock = LOCK_LOCKED;
-    cpu_get_current()->thread = &init_thread;
-    if (bsp == true) {
-        *init_context = mmc_create_kernel_context();
-        mmc_activate(init_context);
-
-        // Freigabe erteilen, damit die APs ihre Stacks mappen koennen.
-        unlock(&mm_prepare_lock);
-    } else {
-        // Warten, bis wir das Signal vom BSP haben, zum fortfahren
-        lock_wait(&mm_prepare_lock);
-
-        // TODO: Was tun, wenn dieses identity-Mapping schief geht?
-        // Dies ist naehmlich sher warscheinlich.
-        uintptr_t sp;
-        #if CONFIG_ARCH == ARCH_AMD64
-            asm volatile("movq %%rsp, %0" : "=r"(sp));
-        #else
-            asm volatile("movl %%esp, %0" : "=r"(sp));
-        #endif
-        mmc_map(init_context, (vaddr_t) PAGE_ALIGN_ROUND_DOWN(sp),
-            (paddr_t) PAGE_ALIGN_ROUND_DOWN(sp), MM_FLAGS_KERNEL_DATA, 1);
-    }
-
-
-    // Warten, bis alle CPUs hier angekommen sind.
-    // TODO: Timeout?
-    static volatile uint32_t cpus_arrived = 0;
-    locked_increment(&cpus_arrived);
-    while (cpus_arrived < cpu_count) asm("nop");
-
-    // SSE aktivieren
-    // Allerdings nur, wenn cpuid sagt, dass die Flags FXSR und SSE da sind,
-    // sonst rennen wir hier in Exceptions.
-    // TODO: Buildscripts fixen?
-    uint32_t edx = 0, dummy = 0;
-    asm volatile("cpuid": "=d" (edx), "=a" (dummy) : "a" (1) : "ebx", "ecx");
-    if ((edx & (1 << 24)) && (edx & (1 << 25))) {
-        #if CONFIG_ARCH == ARCH_AMD64
-            asm volatile(
-                "movq %cr0, %rax;"
-                "andq $0xfffffffffffffffb, %rax;"
-                "orq $2, %rax;"
-                "movq %rax, %cr0;"
-                "movq %cr4, %rax;"
-                "orq $0x600, %rax;"
-                "movq %rax, %cr4;"
-            );
-        #else
-            asm volatile(
-                "movl %cr0, %eax;"
-                "andl $0xfffffffb, %eax;"
-                "orl $2, %eax;"
-                "movl %eax, %cr0;"
-                "movl %cr4, %eax;"
-                "orl $0x600, %eax;"
-                "movl %eax, %cr4;"
-            );
-        #endif
-    }
-
-    static volatile lock_t vmm_lock = LOCK_LOCKED;
-    // ACHTUNG: Hier besteht ein kleines Problem: Da in vmm_init der APIC
-    // gemappt wird, kann nicht mehr darauf zugegriffen werden, bis Paging
-    // aktiviert ist. Das geht sonst schief! Genau das geschieht aber, wenn
-    // mapping-Funktionen aufgerufen werden. Darum muss alles gemappt sein,
-    // bevor vmm_init aufgerufen wird.
-    if (bsp == true) {
-        debug_print(DEBUG_FLAG_INIT, "Initialisiere virtuelle "
-            "Speicherverwaltung");
-        vmm_init(init_context);
-        unlock(&vmm_lock);
-    }
-
-    lock_wait(&vmm_lock);
-    // Hier wird je nach Architektur Paging aktiviert
-    vmm_init_local(init_context);
-
-
-    // Hier geht die initialisierung langsam dem Ende zu. Jetzt fuehrt der BSP
-    // noch ein paar notwendige Dinge durch, wartet dann auf die anderen CPUs
-    // und gibt den endgueltigen Startschuss.
-    static volatile uint32_t final_cpus_arrived = 0;
-    static volatile lock_t final_lock = LOCK_LOCKED;
-    locked_increment(&final_cpus_arrived);
-
-    if (bsp == true) {
-        debug_print(DEBUG_FLAG_INIT, "Initialisiere Kerneldienste");
-
-        // Syscalls initialisieren
-        syscall_init();
-
-        // Prozessverwaltung initialisieren
-        pm_init();
-
-        // Shared Memory initialisieren
-        shm_init();
-
-        // Timer initialisieren
-        timer_init();
-
-        // LostIO initialisieren
-        lio_init();
-
-        // Init-Modul laden
-        debug_print(DEBUG_FLAG_INIT, "Lade Module");
-        load_init_module(&multiboot_info);
-
-        // Alle weiteren Module an init uebergeben
-        load_multiboot_modules(&multiboot_info);
-
-        // Sobald alle CPUs angekommen sind, gehts los!
-        // TODO: Timeout?
-        debug_print(DEBUG_FLAG_INIT, "BSP: Warte auf andere CPUs");
-        while (final_cpus_arrived < cpu_count) asm("nop");
-        unlock(&final_lock);
-    } else {
-        // Warten, bis wir das Signal vom BSP haben, zum fortfahren
-        lock_wait(&final_lock);
-    }
-
-
-    // Ersten Thread auf dieser CPU starten
-    debug_print(DEBUG_FLAG_INIT, "Starte Ausfuehrung von init");
-    current_thread = pm_scheduler_pop();
-    interrupt_stack_frame_t* isf = im_prepare_current_thread();
-    asm volatile("jmp im_run_thread" :: "a" (isf));
-
-    // Hier kommen wir nie hin
-}
-
-__attribute__((noreturn)) void panic(char * message, ...)
-{
-    __asm__ __volatile__("cli");
-    va_list args;
-    va_start(args,message);
-
-    // XXX disable_interrupts();
-
-    kprintf("\n"
-      "\033[1;37m\033[41m" // weiss auf rot
-      "PANIC: ");
-    kaprintf(message, args);
-    kprintf("\n");
-
-    // FIXME
-    #undef CONFIG_DEBUG_LAST_SYSCALL
-    #ifdef CONFIG_DEBUG_LAST_SYSCALL
-    {
-        uint32_t i;
-
-        kprintf("Letzter Syscall: %d ", debug_last_syscall_no);
-        for (i = 0; i < DEBUG_LAST_SYSCALL_DATA_SIZE; i++) {
-            kprintf("0x%08x ", debug_last_syscall_data[i]);
-        }
-        kprintf("\n");
-    }
-    #endif
-
-    stack_backtrace(0, 0);
-
-    kprintf("\033[0;37m\033[40m");
-
-
-    while(1) {
-      cpu_halt();
-    }
-}
diff --git a/src/kernel2/src/kprintf.c b/src/kernel2/src/kprintf.c
deleted file mode 100644
index d2cea6c5..00000000
--- a/src/kernel2/src/kprintf.c
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (c) 2006 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Burkhard Weseloh.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- 
-#include <stdint.h>
-#include <stddef.h>
-#include <lost/config.h>
-
-#include "kprintf.h"
-#include "console.h"
-#include "lock.h"
-
-
-static lock_t printf_lock;
-
-/* Dividiert ein uint64 durch einen uint32 und gibt das Ergebnis zur�ck */
-unsigned long long divmod(unsigned long long dividend, unsigned int divisor, unsigned int * remainder)
-{
-#if CONFIG_ARCH == ARCH_AMD64
-    if (remainder) {
-        *remainder = dividend % divisor;
-    }
-    return dividend / divisor;
-#else
-    unsigned int highword = dividend >> 32;
-    unsigned int lowword = dividend & 0xffffffff;
-    unsigned long long quotient;
-    unsigned int rem;
-    
-    __asm__("div %%ecx\n\t"
-        "xchg %%ebx, %%eax\n\t"
-        "div %%ecx\n\t"
-        "xchg %%edx, %%ebx"
-        : "=A"(quotient), "=b"(rem)
-        : "a"(highword), "b"(lowword), "c"(divisor), "d"(0)
-        );
-
-    if (remainder) {
-        *remainder = rem;
-    }
-
-    return quotient;
-#endif
-}
-
-/* Gibt eine unsigned 64-bit Zahl mit beliebiger Basis zwischen 2 und 36 aus */
-/*static*/ void kputn(unsigned long long x, int radix, int pad, char padchar)
-{
-    char b[65];
-    char * r = b + 64; // r zeig auf das letzte Zeichen von b[]
-    char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
-    unsigned int remainder;
-
-    if(radix < 2 || radix > 36)
-    {
-        return;
-    }
-
-    *r-- = 0;
-
-    do
-    {
-        x = divmod(x, radix, &remainder);
-        *r-- = digits[remainder];
-        pad--;
-    }
-    while(x > 0);
-
-    while(pad-- > 0)
-    {
-        con_putc_ansi(padchar);
-    }
-
-    con_puts(r + 1);
-}
-
-/* Hilfsfunktion f�r kprintf() */
-void kaprintf(char* format, va_list args)
-{
-    int pad;
-    char padfill;
-    unsigned long long value = 0;
-
-    while(*format)
-    {
-        if(*format == '%')
-        {
-            format++;
-
-            pad = 0;
-            if(*format == '0')
-            {
-                padfill = '0';
-                format++;
-            }
-            else
-            {
-                padfill = ' ';
-            }
-
-            while(*format >= '0' && *format <= '9')
-            {
-                pad = pad * 10 + *format++ - '0';
-            }
-
-            if(format[0] == 'l' && format[1] == 'l' && (format[2] == 'd' || format[2] == 'i'))
-            {
-                signed long long tmp = va_arg(args, long long int);
-                if (tmp < 0) {
-                    con_putc_ansi('-');
-                    pad--;
-                    value = -tmp;
-                } else {
-                    value = tmp;
-                }
-                format += 2;
-            }
-            else if(format[0] == 'l' && format[1] == 'l' && (format[2] == 'o' || format[2] == 'u' || format[2] == 'x'))
-            {
-                value = va_arg(args, unsigned long long int);
-                format += 2;
-            }
-            else if(format[0] == 'l' && (format[1] == 'd' || format[1] == 'i'))
-            {
-                signed long int tmp = va_arg(args, long int);
-                if(tmp < 0) {
-                    con_putc_ansi('-');
-                    pad--;
-                    value = -tmp;
-                } else {
-                    value = tmp;
-                }
-                format++;
-            } else if(format[0] == 'z' && (format[1] == 'u' || format[1] == 'x')) {
-                value = va_arg(args, size_t);
-                format++;
-            }
-            else if(format[0] == 'l' && (format[1] == 'o' || format[1] == 'u' || format[1] == 'x'))
-            {
-                value = va_arg(args, unsigned long int);
-                format++;
-            }
-            else if(format[0] == 'd' || format[0] == 'i')
-            {
-                int tmp = va_arg(args, int);
-                if(tmp < 0) {
-                    con_putc_ansi('-');
-                    pad--;
-                    value = -tmp;
-                } else {
-                    value = tmp;
-                }
-            } else if(format[0] == 'u' || format[0] == 'o' || format[0] == 'x') {
-                value = va_arg(args, unsigned int);
-            } else if(format[0] == 'p') {
-                value = va_arg(args, uintptr_t);
-            }
-
-            switch(*format)
-            {
-                case 0:
-                    return;
-                case '%':
-                    con_putc_ansi('%');
-                    break;
-                case 'c':
-                    //con_putc_ansi(*(*args)++);
-                    con_putc(va_arg(args, int));
-                    break;
-                case 'd':
-                case 'i':
-                case 'u':
-                    kputn(value, 10, pad, padfill);
-                    break;
-                case 'o':
-                    kputn(value, 8, pad, padfill);
-                    break;
-                case 'p':
-                case 'x':
-                    kputn(value, 16, pad, padfill);
-                    break;
-                /* Folgendes wieder einkommentieren um das extrem coole
-                   Feature "rekursives printf" auszuprobieren */
-                /*case 'r':
-                    format2 = (char*)*(*args)++;
-                    kaprintf(format2, args);
-                    break;*/
-                case 's':
-                    //con_puts((char*)*(*args)++);
-                    con_puts(va_arg(args, char*));
-                    break;
-                default:
-                    con_putc_ansi('%');
-                    con_putc_ansi(*format);
-                    break;
-            }
-            format++;
-        }
-        else
-        {
-            con_putc_ansi(*format++);
-        }
-    }
-    
-    con_flush_ansi_escape_code_sequence();
-}
-
-/* printf für den Kernel. Nur für Testzwecke gedacht.
- Unterstützt %c, %d, %i, %o, %p, %u, %s, %x und %lld, %lli, %llo, %llu, %llx, %zu, %zx. */
-void kprintf(char* format, ...)
-{
-    lock(&printf_lock);
-    
-    va_list args;
-    
-    va_start(args,format);
-    kaprintf(format, args);
-    va_end(args);
-
-    unlock(&printf_lock);
-}
-
-int printf(const char* format, ...)
-{
-    lock(&printf_lock);
-    
-    va_list args;
-    va_start(args,format);
-    kaprintf((char*) format, args);
-    va_end(args);
-    
-    unlock(&printf_lock);
-    return 0; // TODO Korrekte printf-R�ckgabe
-}
-
diff --git a/src/kernel2/src/mm/phys.c b/src/kernel2/src/mm/phys.c
deleted file mode 100644
index c4a59ec1..00000000
--- a/src/kernel2/src/mm/phys.c
+++ /dev/null
@@ -1,615 +0,0 @@
-/*
- * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Burkhard Weseloh.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <string.h>
-
-#include "kernel.h"
-#include "multiboot.h"
-#include "mm.h"
-#include "lock.h"
-
-#define min(x,y) (((x) < (y)) ? (x) : (y))
-
-/* Diese beiden werden in kernel.ld definiert. */
-extern void kernel_phys_start(void);
-extern void kernel_phys_end(void);
-
-/** Bitmap aller physischen Seiten. Gesetztes Bit steht f�r freie Seite */
-#define PMM_BITS_PER_ELEMENT (8 * sizeof(uint_fast32_t))
-#define PMM_NUM_DMA_ELEMENTS ((16 * 1024 * 1024) / sizeof(uint_fast32_t))
-
-static uint_fast32_t* pmm_bitmap;
-
-/** Lock fuer die physikalische Speicherverwaltung */
-static lock_t pmm_lock = 0;
-
-/** 
- * Gr��e von pmm_bitmap in Elementen (= 1/8*sizeof(uint_fast32_t) der Anzahl
- * der physischen Seiten)
- *
- * @see pmm_bitmap
- */
-static size_t pmm_bitmap_length;
-
-/**
- * Gibt die Startadresse der Bitmap zur�ck
- */
-void* pmm_get_bitmap_start()
-{
-    return pmm_bitmap;
-}
-
-/**
- * Setzt die Startadresse der Bitmap. Diese Funktion ist einzig und allein dazu
- * bestimmt, den �bergang von physischen zu virtuellen Adressen beim
- * Einschalten von Paging bewerkstelligen zu k�nnen.
- */
-void pmm_set_bitmap_start(void* bitmap_start)
-{
-    pmm_bitmap = bitmap_start;
-}
-
-/**
- * Gibt die G��e der Bitmap in Bytes zur�ck
- */
-size_t pmm_get_bitmap_size()
-{
-    return pmm_bitmap_length * PMM_BITS_PER_ELEMENT / 8;
-}
-
-/**
- * Gibt die Anzahl der freien Seiten zurueck
- *
- * @return Anzahl freier Seiten
- */
-size_t pmm_count_free()
-{
-    size_t free_pages = 0;
-    size_t i, j;
-    
-    for (i = 0; i < pmm_bitmap_length; i++) {
-        for (j = 0; j < PMM_BITS_PER_ELEMENT; j++) {
-            if (pmm_bitmap[i] & (1 << j)) {
-                free_pages++;
-            }
-        }
-    }
-
-    return free_pages;
-}
-
-/**
- * Gibt die Anzahl der Pages zurueck
- */
-size_t pmm_count_pages()
-{
-    return 8 * pmm_get_bitmap_size();
-}
-
-/**
- * Markiert eine Page als frei/unbenutzt.
- *
- * @param page Zeiger auf den Anfang der Page, die als frei markiert werden 
- * soll.
- */
-
-static inline void phys_mark_page_as_free(paddr_t page)
-{
-    //lock(&pmm_lock);
-    size_t bitmap_index = (size_t) page / PAGE_SIZE / PMM_BITS_PER_ELEMENT;
-    pmm_bitmap[bitmap_index] |= 1 << (((size_t) page / PAGE_SIZE) & 
-        (PMM_BITS_PER_ELEMENT - 1));
-
-    //unlock(&pmm_lock);
-}
-
-/**
- * Markiert num Pages als frei/unbenutzt.
- *
- * @param page Zeiger auf den Anfang der ersten Page.
- * @param num Anzahl der Pages die als frei markiert werden sollen.
- */
-
-static inline void phys_mark_page_range_as_free(paddr_t page, size_t num)
-{
-    size_t i;
-
-    for(i = 0; i < num; i++) {
-        phys_mark_page_as_free(page + i * PAGE_SIZE);
-    }
-}
-
-/**
- * Markiert eine Page als benutzt.
- *
- * @param page Zeiger auf den Anfang der Page, die als benutzt markiert werden 
- * soll.
- */
-
-static inline void phys_mark_page_as_used(paddr_t page)
-{
-    //lock(&pmm_lock);
-    size_t bitmap_index = (size_t) page / PAGE_SIZE / PMM_BITS_PER_ELEMENT;
-    pmm_bitmap[bitmap_index] &= ~(1 << (((size_t) page / PAGE_SIZE) & 
-        (PMM_BITS_PER_ELEMENT - 1)));
-    //unlock(&pmm_lock);
-}
-
-/**
- * Markiert num Pages als benutzt.
- *
- * @param page Zeiger auf den Anfang der ersten Page.
- * @param num Anzahl der Pages die als benutzt markiert werden sollen.
- */
-
-static inline void phys_mark_page_range_as_used(paddr_t page, size_t num)
-{
-    size_t i;
-
-    for(i = 0; i < num; i++) {
-        phys_mark_page_as_used(page + i * PAGE_SIZE);
-    }
-}
-
-/**
- * Sucht num freie Pages und gibt einen Zeiger auf den Anfang der ersten Page 
- * zur�ck.
- *
- * @param lower_index Index der niedrigsten erlaubten Page
- * @param upper_index Index der h�chsten erlaubten Page
- * @param num Anzahl der Pages.
- *
- * @return Zeiger auf den Anfang der ersten Page.
- * @return Im Erfolgsfall wird ein Zeiger auf den Anfang der ersten 
- *      Page zur�ckgegeben (Bei Erfolg ist der R�ckgabewert immer
- *      durch PAGE_SIZE teilbar). Im Fehlerfall wird 1 zur�ckgegeben.
- */
-
-/* TODO: unbedingt testen */
-static paddr_t find_free_page_range
-    (size_t lower_index, size_t upper_index, size_t num)
-{
-    size_t i, j;
-    size_t found = 0;
-    paddr_t page = 0;
-
-    for(i = lower_index; i < upper_index; i++)
-    {
-        if(pmm_bitmap[i] == 0) {
-            found = 0;
-            continue;
-        }
-
-        if(pmm_bitmap[i] == ~0x0)
-        {
-            if(found == 0)
-            {
-                page = i * PMM_BITS_PER_ELEMENT * PAGE_SIZE;
-            }
-            found += PMM_BITS_PER_ELEMENT;
-        }
-        else
-        {
-            for(j = 0; j < PMM_BITS_PER_ELEMENT; j++)
-            {
-                if(pmm_bitmap[i] & (1 << j))
-                {
-                    if(found == 0) {
-                        page = (i * PMM_BITS_PER_ELEMENT + j) * PAGE_SIZE;
-                    }
-                    found++;
-
-                    if(found > num) {
-                        break;
-                    }
-                }
-                else
-                {
-                    found = 0;
-                }
-            }
-        }
-
-        if(found > num) {
-            return page;
-        }
-    }
-
-    return 1;
-}
-
-
-/**
- * Reserviert num Pages.
- *
- * @param lower_limit Niedrigste erlaubte Adresse (Mu� auf 32-Bit-Systemen
- * auf einer 128K-Grenze liegen. Wenn nicht, wird gerundet)
- *
- * @param upper_limit H�chste erlaubte Adresse (Mu� auf 32-Bit-Systemen
- * auf einer 128K-Grenze liegen. Wenn nicht, wird gerundet)
- *
- * @param num Anzahl der zu reservierenden Seiten
- *
- * @return Zeiger auf den Anfang der ersten Page.
- */
-paddr_t pmm_alloc_limits(paddr_t lower_limit, paddr_t upper_limit, size_t num)
-{
-    lock(&pmm_lock);
-    paddr_t page;
-    size_t lower_index = (size_t) lower_limit / PMM_BITS_PER_ELEMENT;
-    size_t upper_index = (size_t) upper_limit / PMM_BITS_PER_ELEMENT;
-
-    if (upper_index > pmm_bitmap_length) {
-        upper_index = pmm_bitmap_length;
-    }
-
-    if ((upper_index > PMM_NUM_DMA_ELEMENTS) && 
-        (lower_index < PMM_NUM_DMA_ELEMENTS))
-    {
-        page = find_free_page_range(lower_index, upper_index, num);
-    }
-    else
-    {
-        page = find_free_page_range(PMM_NUM_DMA_ELEMENTS, upper_index, num);
-    
-        if((size_t) page & (PAGE_SIZE - 1)) {
-            page = find_free_page_range(
-                lower_index, 
-                min(PMM_NUM_DMA_ELEMENTS + num, upper_index), 
-                num
-            );
-        }
-    }
-    
-    if((size_t) page & (PAGE_SIZE - 1)) {
-        unlock(&pmm_lock);
-        panic("Kein freier Speicher mehr da.");
-    } else {
-        phys_mark_page_range_as_used(page, num);
-        unlock(&pmm_lock);
-        return page;
-    }
-}
-
-/**
- * Reserviert num Pages, die beliebig im physischen Speicher liegen k�nnen.
- *
- * @see pmm_alloc_limits
- */
-paddr_t pmm_alloc(size_t num)
-{
-    paddr_t result = pmm_alloc_limits(
-        0,
-        pmm_bitmap_length * PMM_BITS_PER_ELEMENT * PAGE_SIZE,
-        num
-    );
-
-    return result;
-}
-
-
-/**
- * Gibt physisch zusammenh�ngende Speicherseiten frei
- *
- * @param start Zeiger auf das erste Byte der ersten freizugebenden Seite
- * @param count Anzahl der freizugebenden Seiten
- */
-void pmm_free(paddr_t start, size_t count)
-{
-    // TODO Pr�fen, ob die Seiten vorher auch besetzt waren, sonst Panic
-    phys_mark_page_range_as_free(start, count);
-}
-
-
-struct mem_block {
-    paddr_t start;
-    paddr_t end;
-};
-
-/**
- * Wird benutzt, um nacheinander alle vom BIOS aus freien Speicherbereiche
- * aufzuzaehlen. Dies bedeutet nicht, dass die zurueckgegebenen
- * Speicherbereiche frei benutzt werden koennen. Um festzustellen, ob nicht
- * tyndur Bereiche benoetigt (z.B. fuer Kernel oder Multiboot-Strukturen), muss
- * zusaetzlich get_reserved_block() benutzt werden.
- *
- * @param multiboot_info Pointer auf die Multiboot-Info
- * @param i Index des freien Speicherbereichs
- *
- * @return Beschreibung des freien Speicherblocks. Wenn i groesser als die
- * Anzahl der freien Blocks ist, wird ein Block mit start > end
- * zurueckgegeben.
- */
-static struct mem_block get_free_block
-    (struct multiboot_info* multiboot_info, size_t i)
-{
-    struct mem_block result;
-
-    // �berpr�fung der BIOS-Memory-Map
-    struct multiboot_mmap* mmap;
-    uintptr_t mmap_addr = multiboot_info->mi_mmap_addr;
-    uintptr_t mmap_end = mmap_addr + multiboot_info->mi_mmap_length;
-
-    for(mmap = (struct multiboot_mmap*) (mmap_addr);
-        mmap < (struct multiboot_mmap*) (mmap_end);
-        mmap++)
-    {
-        uint64_t start = mmap->mm_base_addr;
-        uint64_t end   = mmap->mm_base_addr + mmap->mm_length - 1;
-
-        if (start > UINTPTR_MAX) {
-            continue;
-        }
-        if (end > UINTPTR_MAX) {
-            end = UINTPTR_MAX;
-        }
-
-        // Typ 1 steht f�r freien Speicher
-        if (mmap->mm_type == 1) {
-            if (i-- == 0) {
-                result.start    = (paddr_t)start;
-                result.end      = (paddr_t)end;
-                return result;
-            }
-        }
-    }
-
-    result.start = (paddr_t) 0xFFFFFFFF;
-    result.end   = (paddr_t) 0;
-
-    return result;
-}
-
-/**
- * Wird benutzt, um nacheinander alle belegten Speicherbereiche aufzuzaehlen.
- * Dies sind vor allem Kernel, Module und Multiboot-Strukturen. Vom BIOS als
- * reserviert gekennzeichnete Bereiche sind hierbei nicht enthalten. Um die
- * vom BIOS aus freien Bereiche zu erhalten, muss get_free_block() benutzt
- * werdem.
- *
- * @param multiboot_info Pointer auf die Multiboot-Info
- * @param i Index des belegten Speicherbereichs
- * @param bitmap Wenn true, wird auch der Platz der Speicherbitmap als
- * reserviert gekennzeichnet. Wenn die Speicherbitmap noch nicht platziert
- * wurde, muss dieser Parameter false sein.
- *
- * @return Beschreibung des reservierten Blocks. Wenn i groesser als die
- * Anzahl der reservierten Blocks ist, wird ein Block mit start > end
- * zurueckgegeben.
- */
-static struct mem_block get_reserved_block
-    (struct multiboot_info* multiboot_info, size_t i, bool bitmap)
-{
-    struct mem_block result;
-
-    // Bitmap nur beruecksichtigen, wenn sie bereits zugewiesen ist
-    if (bitmap && (i-- == 0)) {
-        result.start = (paddr_t) pmm_bitmap;
-        result.end   = (paddr_t)
-            (pmm_bitmap + ((pmm_bitmap_length / 8) * PMM_BITS_PER_ELEMENT));
-        return result;
-    }
-
-    // Der Kernel ist besetzt
-    if (i-- == 0) {
-        result.start    = (paddr_t) kernel_phys_start;
-        result.end      = (paddr_t) kernel_phys_end;
-        return result;
-    }
-
-    // Die Module auch.
-    {
-        uint32_t j;
-        struct multiboot_module* multiboot_module;
-        multiboot_module = (struct multiboot_module*) (uintptr_t) 
-            multiboot_info->mi_mods_addr;
-
-        for (j = 0; j < multiboot_info->mi_mods_count; j++) 
-        {
-            // Die Multiboot-Info zum Modul    
-            if (i-- == 0) {
-                result.start    = (paddr_t) multiboot_module;
-                result.end      = (paddr_t) (multiboot_module + 1);
-                return result;
-            }
-
-            // Das Modul selbst
-            if (i-- == 0) {
-                result.start    = (paddr_t) multiboot_module->start;
-                result.end      = (paddr_t) multiboot_module->end;
-                return result;
-            }
-
-            // Die Kommandozeile des Moduls 
-            if (multiboot_module->cmdline) {
-                if (i-- == 0) {
-                    result.start = (paddr_t) multiboot_module->cmdline;
-                    result.end   = (paddr_t) multiboot_module->cmdline +
-                        strlen((char*) (uintptr_t) multiboot_module->cmdline);
-                    return result;
-                }
-            }
-
-            multiboot_module++;
-        }
-    }
-
-    result.start = (paddr_t) 0xFFFFFFFF;
-    result.end   = (paddr_t) 0;
-
-    return result;
-}
-
-/**
- * Suche einen Platz f�r die Bitmap
- */
-static paddr_t find_bitmap_mem
-    (struct multiboot_info* multiboot_info, size_t size)
-{
-    if (multiboot_info->mi_flags & MULTIBOOT_INFO_HAS_MMAP) {
-        size_t i, j;
-        struct mem_block free, reserved;
-        paddr_t bitmap = 0x0;
-
-        i = 0;
-        do
-        {
-            // Freien Speicherblock suchen und Bitmap an den Anfang legen
-            free = get_free_block(multiboot_info, i++);
-            if (free.start > free.end) {
-                panic("Keinen Platz fuer die Speicherbitmap gefunden");
-            }
-            bitmap = free.start;
-
-            // Probieren, ob der Speicherblock nicht doch besetzt ist und
-            // in diesem Fall ein Stueck weitergehen und nochmal von vorne
-            // durchprobieren
-            j = 0;
-            do
-            {
-                reserved = get_reserved_block(multiboot_info, j++, false);
-                if (!((reserved.start > bitmap + size)
-                    || (reserved.end <= bitmap)))
-                {
-                    j = 0;
-                    bitmap = (paddr_t)
-                        PAGE_ALIGN_ROUND_UP((uintptr_t) reserved.end);
-                }
-            }
-            while ((bitmap <= free.end) && (reserved.start < reserved.end));
-
-            // Wenn die Bitmap nach Beruecksichtigung aller besetzten Bereiche
-            // immer noch im freien Bereich liegt, dann nehmen wir die Adresse
-            if (bitmap <= free.end) {
-                return bitmap;
-            }
-        }
-        while(true);
-    } else {
-        return (paddr_t) 0x1000;
-    }
-}
-
-/**
- * Bestimmt die ben�tigte Gr��e der Bitmap in Bytes
- */
-static size_t required_bitmap_size(struct multiboot_info* multiboot_info)
-{
-    // Suche die h�chste Adresse
-    paddr_t upper_end = 0;
-    if (multiboot_info->mi_flags & MULTIBOOT_INFO_HAS_MMAP) 
-    {
-        struct multiboot_mmap* mmap =
-            (struct multiboot_mmap*) (uintptr_t) multiboot_info->mi_mmap_addr;
-
-        size_t i = 0;
-        for (i = 0; i < multiboot_info->mi_mmap_length / sizeof(*mmap); i++)
-        {
-            if (((uint32_t) (mmap[i].mm_base_addr + mmap[i].mm_length)
-                > (uint32_t) (uintptr_t) upper_end) && (mmap[i].mm_type == 1))
-            {
-                upper_end = (paddr_t)(uintptr_t) 
-                    mmap[i].mm_base_addr + mmap[i].mm_length;
-            }
-        }
-    }
-    else 
-    {
-        // Der hintere Cast verhindert Compiler-Warungen
-        upper_end = (paddr_t) (1024 * (1024 + (uintptr_t) 
-            multiboot_info->mi_mem_upper));
-    }
-
-    // Umrechnen auf ben�tigte Bytes f�r die Bitmap
-    return (size_t) upper_end / PAGE_SIZE / 8;
-}
-
-/**
- * Initialisiert den physischen Speicher.
- *
- * @param mmap_addr Adresse der Memorymap.
- * @param mmap_length L�nge der Memorymap in Bytes.
- * @param upper_mem Gr��e des upper_mem in Kilobyte, wie in der Multboot-Info
- *      �bergeben.
- */
-void pmm_init(struct multiboot_info* multiboot_info)
-{
-    // Finde einen Platz f�r die Bitmap
-    size_t bitmap_size = required_bitmap_size(multiboot_info);
-    pmm_bitmap = (void*) find_bitmap_mem(multiboot_info, bitmap_size);
-    pmm_bitmap_length = 8 * bitmap_size / PMM_BITS_PER_ELEMENT;
-
-    // Am Anfang ist alles besetzt
-    memset(pmm_bitmap, 0x0, bitmap_size);
-
-    // ...anschlie�end die BIOS-Memory-Map abarbeiten
-    size_t i = 0;
-    do
-    {
-        struct mem_block block = get_free_block(multiboot_info, i++);
-
-        // Wenn der Start nach dem Ende liegt, ist der Block ungueltig
-        // und wir sind fertig
-        if (block.start > block.end) {
-            break;
-        }
-
-        // Reservierten Block als frei markieren
-        phys_mark_page_range_as_free
-            (block.start, NUM_PAGES(block.end - block.start));
-    }
-    while(true);
-
-
-    // ...und dann Kernel usw. wieder reservieren
-    i = 0;
-    do
-    {
-        struct mem_block block = get_reserved_block(multiboot_info, i++, true);
-
-        // Wenn der Start nach dem Ende liegt, ist der Block ungueltig
-        // und wir sind fertig
-        if (block.start > block.end) {
-            break;
-        }
-
-        // Reservierten Block als besetzt markieren
-        phys_mark_page_range_as_used
-            (block.start, NUM_PAGES(block.end - block.start));
-    }
-    while(true);
-}
diff --git a/src/kernel2/src/mm/shm.c b/src/kernel2/src/mm/shm.c
deleted file mode 100644
index 6d94c52b..00000000
--- a/src/kernel2/src/mm/shm.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Copyright (c) 2008 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <collections.h>
-
-#include "mm.h"
-#include "cpu.h"
-#include "tasks.h"
-
-struct shm_desc {
-    uint64_t            id;
-    struct tree_item    tree_item;
-
-    size_t              num_pages;
-    list_t*             processes;
-};
-
-struct shm_process {
-    struct shm_desc*    shm;
-    pm_process_t*       process;
-    vaddr_t             vaddr;
-};
-
-static tree_t* shms = NULL;
-static uint32_t shm_last_id = 0;
-
-static void shm_destroy_task(pm_process_t* process, void* prv);
-
-/**
- * Initialisiert die SHM-Verwaltung
- */
-void shm_init(void)
-{
-    shms = tree_create(struct shm_desc, tree_item, id);
-}
-
-/**
- * Neuen Shared Memory reservieren
- *
- * @return ID des neu angelegten Shared Memory. Der Aufrufer muss anschliessend
- * syscall_shm_attach aufrufen, um auf den Speicher zugreifen zu koennen.
- */
-uint32_t shm_create(size_t size)
-{
-    uint32_t id = ++shm_last_id;
-    struct shm_desc* shm;
-
-    while (tree_search(shms, id)) {
-        id++;
-    }
-
-    shm = calloc(1, sizeof(*shm));
-    shm->id = id;
-    shm->num_pages = NUM_PAGES(size);
-    shm->processes = list_create();
-
-    tree_insert(shms, shm);
-
-    return id;
-}
-
-/**
- * Bestehenden Shared Memory oeffnen.
- *
- * @param process Prozess, der den Shared Memory oeffnet
- * @param id ID des zu oeffnenden Shared Memory
- * @return Virtuelle Adresse des geoeffneten Shared Memory; NULL, wenn der
- * Shared Memory mit der angegebenen ID nicht existiert.
- */
-void* shm_attach(pm_process_t* process, uint32_t id)
-{
-    struct shm_desc* shm = tree_search(shms, id);
-    void* ret;
-    struct shm_process* shm_proc;
-
-    if (shm == NULL) {
-        return NULL;
-    }
-
-    if (list_is_empty(shm->processes)) {
-        // Erster Prozess, der den SHM oeffnet: Speicher allozieren
-        ret = mmc_valloc(&process->context, shm->num_pages,
-            MM_FLAGS_USER_DATA);
-    } else {
-        // Ansonsten Mapping von einem anderen Prozess uebernehmen
-        struct shm_process* first = list_get_element_at(shm->processes, 0);
-        ret = mmc_automap_user(&process->context,
-            &first->process->context, first->vaddr, shm->num_pages,
-            MM_USER_START, MM_USER_END, MM_FLAGS_USER_DATA);
-    }
-
-    if (ret == NULL) {
-        return NULL;
-    }
-
-    shm_proc = calloc(1, sizeof(*shm_proc));
-    shm_proc->shm = shm;
-    shm_proc->process = process;
-    shm_proc->vaddr = ret;
-    list_push(shm->processes, shm_proc);
-
-    if (process->shm == NULL) {
-        process->shm = list_create();
-        pm_register_on_destroy(process, shm_destroy_task, NULL);
-    }
-    list_push(process->shm, shm_proc);
-
-    return ret;
-}
-
-/**
- * Shared Memory schliessen. Wenn keine Prozesse den Shared Memory mehr
- * geoeffnet haben, wird er geloescht.
- *
- * @param process Prozess, der den Shared Memory schliesst
- * @param id ID des zu schliessenden Shared Memory
- */
-void shm_detach(pm_process_t* process, uint32_t id)
-{
-    struct shm_desc* shm = tree_search(shms, id);
-    struct shm_process* shm_proc;
-    int i;
-
-    if (shm == NULL) {
-        return;
-    }
-
-    // Aus der SHM-Liste des Prozesses austragen
-    for (i = 0; (shm_proc = list_get_element_at(process->shm, i)); i++) {
-        if (shm_proc->shm == shm) {
-            list_remove(process->shm, i);
-            break;
-        }
-    }
-
-    // Aus der Prozessliste des SHM austragen
-    for (i = 0; (shm_proc = list_get_element_at(shm->processes, i)); i++) {
-        if (shm_proc->process == process) {
-            list_remove(shm->processes, i);
-            goto found;
-        }
-    }
-
-    return;
-
-found:
-
-    // Wenn es der letzte Benutzer war, SHM loeschen
-    if (list_is_empty(shm->processes)) {
-        for (i = 0; i < shm->num_pages; i++) {
-            pmm_free(mmc_resolve(&process->context,
-                shm_proc->vaddr + (i * PAGE_SIZE)), 1);
-        }
-
-        list_destroy(shm->processes);
-        shm->processes = NULL;
-        tree_remove(shms, shm);
-    }
-
-    // Virtuellen Speicher freigeben
-    mmc_unmap(&process->context, shm_proc->vaddr, shm->num_pages);
-
-
-    free(shm_proc);
-    if (shm->processes == NULL) {
-        free(shm);
-    }
-
-    return;
-}
-
-/**
- * Gibt die Groesse des SHM-Bereichs in Bytes zurueck
- */
-size_t shm_size(uint32_t id)
-{
-    struct shm_desc* shm = tree_search(shms, id);
-
-    if (shm == NULL) {
-        return 0;
-    }
-
-    return shm->num_pages * PAGE_SIZE;
-}
-
-/**
- * Schliesst alle SHM-Bereiche eines Prozesses
- */
-static void shm_destroy_task(pm_process_t* process, void* prv)
-{
-    struct shm_process* shm_proc;
-
-    if (process->shm == NULL) {
-        return;
-    }
-
-    while ((shm_proc = list_get_element_at(process->shm, 0))) {
-        shm_detach(process, shm_proc->shm->id);
-    }
-
-    list_destroy(process->shm);
-}
diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c
deleted file mode 100644
index f74dbebe..00000000
--- a/src/kernel2/src/syscall.c
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Antoine Kaufmann.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <types.h>
-#include <stdint.h>
-
-#include "syscall.h"
-#include "syscallno.h"
-
-#include "kernel.h"
-
-syscall_t syscalls[SYSCALL_MAX];
-
-/**
- * Die Syscalls initialisieren.
- */
-void syscall_init()
-{
-    syscall_register(SYSCALL_MEM_ALLOCATE, &syscall_mem_allocate, 3);
-    syscall_register(SYSCALL_MEM_ALLOCATE_PHYSICAL,
-            &syscall_mem_allocate_physical, 3);
-    syscall_register(SYSCALL_MEM_FREE, &syscall_mem_free, 2);
-    syscall_register(SYSCALL_MEM_FREE_PHYSICAL, &syscall_mem_free_physical, 2);
-    syscall_register(SYSCALL_MEM_INFO, &syscall_mem_info, 0);
-
-    syscall_register(SYSCALL_PM_GET_PID, (void*) &syscall_pm_get_pid, 0);
-    syscall_register(SYSCALL_PM_GET_PARENT_PID, (void*)
-        &syscall_pm_get_parent_pid, 1);
-    syscall_register(SYSCALL_PM_GET_CMDLINE, (void*) syscall_pm_get_cmdline,
-        0);
-
-    syscall_register(SYSCALL_PM_SLEEP, &syscall_pm_sleep, 0);
-    syscall_register(SYSCALL_PM_WAIT_FOR_RPC, &syscall_pm_wait_for_rpc, 0);
-
-    syscall_register(SYSCALL_PM_P, (void*) &syscall_pm_p, 0);
-    syscall_register(SYSCALL_PM_V, (void*) &syscall_pm_v, 1);
-    syscall_register(SYSCALL_PM_V_AND_WAIT_FOR_RPC, (void*)
-        &syscall_pm_v_and_wait_for_rpc, 0);
-
-    syscall_register(SYSCALL_PM_CREATE_PROCESS, &syscall_pm_create_process, 4);
-    syscall_register(SYSCALL_PM_INIT_PAGE, &syscall_init_child_page, 4);
-    syscall_register(SYSCALL_PM_INIT_PROC_PARAM_BLOCK, &syscall_init_ppb, 2);
-    syscall_register(SYSCALL_PM_EXIT_PROCESS, &syscall_pm_exit_process, 0);
-
-    syscall_register(SYSCALL_PM_ENUMERATE_TASKS,
-        &syscall_pm_enumerate_tasks, 0);
-
-#if CONFIG_ARCH == ARCH_I386
-    syscall_register(SYSCALL_PM_CREATE_THREAD, &syscall_pm_create_thread, 2);
-    syscall_register(SYSCALL_PM_GET_TID, &syscall_pm_get_tid, 0);
-    syscall_register(SYSCALL_PM_EXIT_THREAD, &syscall_pm_exit_thread, 0);
-#endif
-
-    syscall_register(SYSCALL_MUTEX_LOCK, &syscall_mutex_lock, 1);
-    syscall_register(SYSCALL_MUTEX_UNLOCK, &syscall_mutex_unlock, 1);
-
-    syscall_register(SYSCALL_SET_RPC_HANDLER, &syscall_set_rpc_handler, 1);
-#if CONFIG_ARCH == ARCH_I386
-    syscall_register(SYSCALL_FASTRPC, &syscall_fastrpc, 5);
-    syscall_register(SYSCALL_FASTRPC_RET, &syscall_fastrpc_ret, 0);
-#endif
-
-    syscall_register(SYSCALL_ADD_TIMER, &syscall_add_timer, 2);
-
-
-#if CONFIG_ARCH == ARCH_I386
-    syscall_register(SYSCALL_PM_REQUEST_PORT, syscall_io_request_port, 2);
-    syscall_register(SYSCALL_PM_RELEASE_PORT, syscall_io_release_port, 2);
-#endif
-    syscall_register(SYSCALL_ADD_INTERRUPT_HANDLER,
-        syscall_add_interrupt_handler, 1);
-
-    syscall_register(SYSCALL_PUTSN, (void*) &syscall_putsn, 2);
-    syscall_register(SYSCALL_GET_TICK_COUNT, syscall_get_tick_count, 0);
-
-    syscall_register(SYSCALL_SHM_CREATE, &syscall_shm_create, 1);
-    syscall_register(SYSCALL_SHM_ATTACH, &syscall_shm_attach, 1);
-    syscall_register(SYSCALL_SHM_DETACH, &syscall_shm_detach, 1);
-    syscall_register(SYSCALL_SHM_SIZE, &syscall_shm_size, 1);
-
-#if CONFIG_ARCH == ARCH_I386
-    syscall_register(SYSCALL_VM86, &syscall_vm86_old, 2);
-    syscall_register(SYSCALL_VM86_BIOS_INT, &syscall_vm86, 3);
-#endif
-
-    syscall_register(SYSCALL_LIO_RESOURCE, &syscall_lio_resource, 4);
-    syscall_register(SYSCALL_LIO_OPEN, &syscall_lio_open, 3);
-    syscall_register(SYSCALL_LIO_PIPE, &syscall_lio_pipe, 3);
-    syscall_register(SYSCALL_LIO_COMPOSITE_STREAM,
-                     &syscall_lio_composite_stream, 3);
-    syscall_register(SYSCALL_LIO_CLOSE, &syscall_lio_close, 1);
-    syscall_register(SYSCALL_LIO_READ, &syscall_lio_read, 6);
-    syscall_register(SYSCALL_LIO_WRITE, &syscall_lio_write, 6);
-    syscall_register(SYSCALL_LIO_SEEK, &syscall_lio_seek, 4);
-    syscall_register(SYSCALL_LIO_TRUNCATE, &syscall_lio_truncate, 2);
-    syscall_register(SYSCALL_LIO_SYNC, &syscall_lio_sync, 1);
-    syscall_register(SYSCALL_LIO_READ_DIR, &syscall_lio_read_dir, 5);
-    syscall_register(SYSCALL_LIO_MKFILE, &syscall_lio_mkfile, 4);
-    syscall_register(SYSCALL_LIO_MKDIR, &syscall_lio_mkdir, 4);
-    syscall_register(SYSCALL_LIO_MKSYMLINK, &syscall_lio_mksymlink, 6);
-    syscall_register(SYSCALL_LIO_STAT, &syscall_lio_stat, 2);
-    syscall_register(SYSCALL_LIO_UNLINK, &syscall_lio_unlink, 3);
-    syscall_register(SYSCALL_LIO_SYNC_ALL, &syscall_lio_sync_all, 0);
-    syscall_register(SYSCALL_LIO_PASS_FD, &syscall_lio_pass_fd, 2);
-    syscall_register(SYSCALL_LIO_PROBE_SERVICE, &syscall_lio_probe_service, 2);
-    syscall_register(SYSCALL_LIO_DUP, &syscall_lio_dup, 2);
-    syscall_register(SYSCALL_LIO_STREAM_ORIGIN, &syscall_lio_stream_origin, 1);
-    syscall_register(SYSCALL_LIO_IOCTL, &syscall_lio_ioctl, 2);
-
-    syscall_register(SYSCALL_LIO_SRV_SERVICE_REGISTER,
-        &syscall_lio_srv_service_register, 4);
-    syscall_register(SYSCALL_LIO_SRV_TREE_SET_RING,
-        &syscall_lio_srv_tree_set_ring, 4);
-    syscall_register(SYSCALL_LIO_SRV_RES_UPLOAD,
-        &syscall_lio_srv_res_upload, 1);
-    syscall_register(SYSCALL_LIO_SRV_NODE_ADD, &syscall_lio_srv_node_add, 4);
-    syscall_register(SYSCALL_LIO_SRV_NODE_REMOVE,
-        &syscall_lio_srv_node_remove, 3);
-    syscall_register(SYSCALL_LIO_SRV_OP_DONE, &syscall_lio_srv_op_done, 3);
-    syscall_register(SYSCALL_LIO_SRV_WAIT, &syscall_lio_srv_wait, 0);
-
-    syscalls[KERN_SYSCALL_PM_SLEEP] = (syscall_t) {
-        .handler    = &kern_syscall_pm_sleep,
-        .arg_count  = 2,
-        .privileged = true,
-    };
-}
-
-/**
- * Einen neuen Syscall registrieren
- *
- * @param number Syscallnummer (syscallno.h!)
- * @param handler Adresse der Handler-Funktion
- * @param arg_count Anzahl der Argumente, die fuer diesen Syscall uebergeben
- *                  werden muessen.
- */
-void syscall_register(syscall_arg_t number, void* handler, size_t arg_count)
-{
-    // Ein Syscall mit einer zu grossen ID wuerde dazu fuehren, dass Teile von
-    // Kernel-Daten ueberschrieben wuerden
-    if (number >= SYSCALL_MAX) {
-        panic("Es wurde versucht einen Syscall mit einer Nummer groesser als"
-                "SYSCALL_MAX zu reservieren!");
-    }
-    syscalls[number].handler = handler;
-    syscalls[number].arg_count = arg_count;
-    syscalls[number].privileged = false;
-}
diff --git a/src/kernel2/src/timer.c b/src/kernel2/src/timer.c
deleted file mode 100644
index 33d0dcb7..00000000
--- a/src/kernel2/src/timer.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright (c) 2006-2009 The tyndur Project. All rights reserved.
- *
- * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the tyndur Project
- *     and its contributors.
- * 4. Neither the name of the tyndur Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``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 COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <collections.h>
-#include <stdlib.h>
-#include <ports.h>
-
-#include "timer.h"
-#include "syscall.h"
-
-extern uint64_t timer_ticks;
-extern int do_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata,
-    size_t data_size, void* data, bool syscall);
-
-/**
- * Liste aller registrierten Timer
- */
-static list_t* timers;
-
-/**
- * Repraesentiert einen registrierten Timer. Ein Timer gehoert zun einem
- * bestimmten Prozess und nach Ablauf der vorgegebenen Zeitspanne wird ein RPC
- * zu diesem Prozess durchgefuehrt
- */
-struct timeout {
-    pm_process_t*   task;
-    uint32_t        timer_id;
-    uint64_t        timeout;
-};
-
-#define PIT_COUNTER_0       (0x0 << 6)
-#define PIT_RW_LO_BYTE      (0x1 << 4)
-#define PIT_RW_HI_BYTE      (0x2 << 4)
-#define PIT_RW_FULL         (0x3 << 4)
-#define PIT_MODE_2_RATE_GEN (0x2 << 1)
-
-/**
- * Initialisiert die Timerverwaltung
- */
-void timer_init(void)
-{
-    uint16_t reload_value;
-
-    timers = list_create();
-
-    // PIT initialisieren
-    reload_value = 1193182 / CONFIG_TIMER_HZ;
-    outb(0x43, PIT_COUNTER_0 | PIT_RW_FULL | PIT_MODE_2_RATE_GEN);
-    outb(0x40, reload_value & 0xff);
-    outb(0x40, reload_value >> 8);
-}
-
-/**
- * Registriert einen neuen Timer
- */
-void timer_register(pm_process_t* task, uint32_t timer_id, uint32_t usec)
-{
-    // Anlegen des Timeout-Objekts
-    struct timeout* timeout = malloc(sizeof(struct timeout));
-
-    timeout->task       = task;
-    timeout->timer_id   = timer_id;
-    timeout->timeout    = timer_ticks + usec;
-
-    // An der richtigen Stelle in der Liste einsortieren, so dass immer nur
-    // das erste Listenelement geprueft werden muss
-    struct timeout* item;
-    int i;
-    for (i = 0; (item = list_get_element_at(timers, i)); i++) {
-        if (item->timeout > timeout->timeout) {
-            break;
-        }
-    }
-
-    list_insert(timers, i, timeout);
-}
-
-/**
- * Aufzurufen bei jeder Aktualisierung der Systemzeit. Fuehrt die
- * RPC-Benachrichtigungen fuer alle faelligen Timer aus.
- */
-void timer_notify(uint64_t microtime)
-{
-    static uint64_t last_microtime = 0;
-    static const uint32_t rpc_timer_function = 514;
-
-    struct timeout* item;
-    int i = 0;
-    while ((item = list_get_element_at(timers, i)))
-    {
-        // Die Schleife soll nur so lange laufen, wie die Timeouts in der
-        // Vergangenheit liegen. Da die Liste sortiert ist, kann beim ersten
-        // Timeout, der in der Zukunft liegt, abgebrochen werden.
-        //
-        // Overflows muessen abgefangen werden, da in diesem Spezialfall eine
-        // groessere Zahl dennoch Vergangenheit bedeutet. Wie ich grad sehe,
-        // reden wir von einem qword und damit von einer Uptime von ein paar
-        // hunderttausend Jahren, aber tyndur ist ja stabil und wir daher
-        // optimistisch.
-        if (((item->timeout > microtime) && (microtime > last_microtime))
-            || ((item->timeout < last_microtime) && (microtime < last_microtime)))
-        {
-            break;
-        }
-
-        // Task per RPC informieren, dass der Timer abgelaufen ist.
-        // Im Fehlerfall ueberspringen und es beim naechsten Mal nochmal
-        // versuchen.
-        if (do_fastrpc(item->task->pid,
-                4, (char*) &rpc_timer_function,
-                4, (char*) &item->timer_id, false))
-        {
-            i++;
-            continue;
-        }
-
-        free(list_remove(timers, i));
-    }
-
-    last_microtime = microtime;
-}
-
-/**
- * Entfernt alle registrierten Timer eines Prozesses
- */
-void timer_cancel_all(pm_process_t* task)
-{
-    struct timeout* item;
-    int i;
-    for (i = 0; (item = list_get_element_at(timers, i)); i++) {
-        if (item->task == task) {
-            list_remove(timers, i);
-        }
-    }
-}
-- 
2.24.1