Delivered-To: mlmmj-tyndur-devel
Received: from sv1.famkaufmann.info [176.9.73.67]
	by a9b8c5461646 with IMAP (fetchmail-6.3.26)
	for <mlmmj@localhost> (single-drop); Thu, 03 Dec 2020 16:05:12 +0000 (GMT)
Received: from localhost ([172.29.0.7])
	by sv1.famkaufmann.info with LMTP
	id 4Ax2EJMMyV+jbgAALHnFKQ
	(envelope-from <mayerNico@outlook.de>)
	for <mlmmj-tyndur-devel>; Thu, 03 Dec 2020 16:04:35 +0000
Delivered-To: tyndur-devel@tyndur.org
Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2067.outbound.protection.outlook.com [40.92.89.67])
	by sv1.famkaufmann.info (OpenSMTPD) with ESMTPS id c31dc942 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO)
	for <tyndur-devel@tyndur.org>;
	Thu, 3 Dec 2020 16:04:34 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=JjN8itFJo6UP9gbvm8R1EDbY/zbtJGlpzbo48cKQCPuVPtd+jUF5VXBsIXLzCiNRzDabRxQJA0EjCc/fGFIeTo5Zl1tE6wwiNjrahMkU53DqWLs2JFYax4sP6nhBy0P7QqbZZhFfe1v4wmUgkjK2r/k80LW2jMvkUaYKjihmm/qChVWQa9yXyRxPXSapLX66KvETCLQ4rf8frza3/ahTttaR5zhCrxjpgK0/CHqLOhuUxMEzXHeo+ZjpVJVxl7MZX/EIeAsh2LWjGJiV6Lo9j6o6EFx0kOi+jxpYm0a3EEEoc+hdXdzEI/uIJoPsvZOfmYowwaUDuyEaFvhm5/MQaA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=gd9bUc/3cB1qbeNudfpoVvTidI+bl4kjMvEUjQ9Kjk4=;
 b=bGKlOk63/+HGDL4E9/k+HLQSc13D3v8bvmDl9Z5kybovtxaOqQU8q1ZFw/oL8R+MnUDoiDl/sVdN2AMRxz3Z/B+qJ0Ce7+7U2svSId2lbnYsLfGZ2P4Id0d2wqzpP8bQvhZSdSsr3AM8N3MvU/C9Qts1/ddf9PGExWhLQTp6WXV6xzqbtroCwiu5wjVYYCAdN3OInFGasbOzCeyvmlZtpZlIciwtMKJVDOeir7F04qkkN6ZN+U1fMDo9DmFqtL9ZQw4hhT/PAGOCaKR2oroC9LMO3d10x/FSMUdU7o9QJAA48Aeb0wZ+jyhWok7DwQw3h0dkSnYJncUOaDdnZAQEKw==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none;
 dkim=none; arc=none
Received: from DB8EUR05FT031.eop-eur05.prod.protection.outlook.com
 (2a01:111:e400:fc0f::4f) by
 DB8EUR05HT025.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc0f::405)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17; Thu, 3 Dec
 2020 16:04:29 +0000
Received: from AM8PR04MB7266.eurprd04.prod.outlook.com
 (2a01:111:e400:fc0f::42) by DB8EUR05FT031.mail.protection.outlook.com
 (2a01:111:e400:fc0f::449) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend
 Transport; Thu, 3 Dec 2020 16:04:29 +0000
X-IncomingTopHeaderMarker:
 OriginalChecksum:607C156A4645E0EC07FD54E61454E64DBBA0217402A0C7522D73A89E33715EFB;UpperCasedChecksum:6D5CF011E4D4F4A02D4FAAB462AE6D2AC12443A8459F0DACF4988770A41EE055;SizeAsReceived:8389;Count:44
Received: from AM8PR04MB7266.eurprd04.prod.outlook.com
 ([fe80::a057:fc9d:dd8d:8540]) by AM8PR04MB7266.eurprd04.prod.outlook.com
 ([fe80::a057:fc9d:dd8d:8540%6]) with mapi id 15.20.3632.018; Thu, 3 Dec 2020
 16:04:29 +0000
From: Nico Mayer <mayerNico@outlook.de>
To: tyndur-devel@tyndur.org
Subject: [PATCH] kernel: entfernen des alten kernels
Date: Thu,  3 Dec 2020 17:04:22 +0100
Message-ID:
 <AM8PR04MB7266016606E8DCD11610982ED5F20@AM8PR04MB7266.eurprd04.prod.outlook.com>
X-Mailer: git-send-email 2.28.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-TMN: [BxNi9PZSyCs8HQZtKMWIqVAtOblXfLL3]
X-ClientProxiedBy: AM8P192CA0022.EURP192.PROD.OUTLOOK.COM
 (2603:10a6:20b:21b::27) To AM8PR04MB7266.eurprd04.prod.outlook.com
 (2603:10a6:20b:1d6::20)
X-Microsoft-Original-Message-ID:
 <20201203160422.113413-1-mayerNico@outlook.de>
Errors-To: toni@tyndur.org
Precedence: list
Reply-To: tyndur-Patches <tyndur-devel@tyndur.org>
List-Id: tyndur-Patches <tyndur-devel.tyndur.org>
List-Unsubscribe: <mailto:tyndur-devel+unsubscribe@tyndur.org>
List-Post: <mailto:tyndur-devel@tyndur.org>
List-Help: <mailto:tyndur-devel+help@tyndur.org>
List-Subscribe: <mailto:tyndur-devel+subscribe@tyndur.org>
List-Owner: <mailto:toni@tyndur.org>
MIME-Version: 1.0
X-MS-Exchange-MessageSentRepresentingType: 1
Received: from localhost.localdomain (87.165.248.7) by AM8P192CA0022.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:21b::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Thu, 3 Dec 2020 16:04:28 +0000
X-MS-PublicTrafficType: Email
X-IncomingHeaderCount: 44
X-EOPAttributedMessage: 0
X-MS-Office365-Filtering-Correlation-Id: 7ed483a6-7fe6-4ce6-d52f-08d897a51cfa
X-MS-TrafficTypeDiagnostic: DB8EUR05HT025:
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info:
	NhWQr0YJEb8/nDcUT7FX31TxQr8Hi39o2FmBt3Vy/54r7Lv6dAOwawbJRJrfgk9MijGJrtql/VF0AVwWzrLH0i0VPGfehh59/CrxHh0bv8F8PSRGE9eKP3thqE6c94RX1AIt7HEaaIC0h7CW/oJFzG8rv0BmnU8mYFs21IAEKqeulWksr0yxb4Ei3JE6Ao3DXny75uf1H0dzom4INqka+w==
X-MS-Exchange-AntiSpam-MessageData:
	tWCjNXdQiXKKoZIZFVGVORoYD2oUhnXrd0mvqjt6xSA0SwWICgo7c5zo8gvtCza48izjRfbmjr9a4i9JRi05nD1IkjRy9Y4r02zAIxbSX0KCczbpRhPqefLvI3UMW+NNb3C/Rm3FWXY+qwZv0xVvlA==
X-OriginatorOrg: outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 7ed483a6-7fe6-4ce6-d52f-08d897a51cfa
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2020 16:04:29.3414
 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa
X-MS-Exchange-CrossTenant-AuthSource:
	DB8EUR05FT031.eop-eur05.prod.protection.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: Internet
X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg:
	00000000-0000-0000-0000-000000000000
X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8EUR05HT025

* Der alte kernel wird nicht mehr gebraucht und kann durch kernel2
  ersetzt werden. Dieser Commit ersetzt kernel durch kernel2 und passt
die Pfade in den Buildskripts an.

Signed-off-by: Nico Mayer <mayerNico@outlook.de>
---
 Makefile.Jidder                               |   5 +-
 buildmk.sh                                    |   2 +-
 src/{kernel2 =3D> kernel}/.ignorenobuild        |   0
 src/kernel/.nobuild                           |   0
 src/{kernel2 =3D> 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 =3D> 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 =3D> kernel}/include/lostio/core.h |   0
 .../include/lostio/userspace.h                |   0
 src/{kernel2 =3D> kernel}/include/mm.h          |   0
 src/kernel/include/modules.h                  |   9 -
 src/kernel/include/multiboot.h                | 377 ++++----
 src/{kernel2 =3D> kernel}/include/notifier.h    |   0
 src/kernel/include/paging.h                   |  24 -
 src/kernel/include/phys.h                     |  13 -
 src/{kernel2 =3D> kernel}/include/pic.h         |   0
 src/kernel/include/rpc.h                      |  17 -
 src/kernel/include/shm.h                      |  61 --
 src/{kernel2 =3D> 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 =3D> kernel}/src/arch/amd64/cpu.c  |   0
 .../src/arch/amd64/debug.c                    |   0
 src/{kernel2 =3D> 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 =3D> kernel}/src/arch/i386/cpu.c   |   0
 src/{kernel2 =3D> kernel}/src/arch/i386/debug.c |   0
 src/{kernel2 =3D> 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 =3D> 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 =3D> 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 =3D> kernel}/src/interrupts/apic.c |   0
 src/{kernel2 =3D> kernel}/src/interrupts/im.c   |   0
 src/{kernel2 =3D> 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 =3D> kernel}/src/libc_helper.c     |   0
 src/{kernel2 =3D> kernel}/src/lostio/client.c   |   0
 .../src/lostio/include/lostio_int.h           |   0
 src/{kernel2 =3D> kernel}/src/lostio/lostio.c   |   0
 .../src/lostio/modules/file.c                 |   0
 .../src/lostio/modules/tmp.c                  |   0
 src/{kernel2 =3D> kernel}/src/lostio/pipes.c    |   0
 src/{kernel2 =3D> 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/kernel/src/module.mk                      |  16 +
 src/kernel/src/modules.c                      | 371 --------
 src/{kernel2 =3D> kernel}/src/notifier.c        |   0
 src/kernel/src/rpc.c                          | 343 -------
 src/kernel/src/schedule.c                     | 195 ----
 src/{kernel2 =3D> kernel}/src/smp/Makefile.conf |   0
 .../src/smp/rm_trampoline.asm                 |   0
 src/{kernel2 =3D> kernel}/src/smp/smp.c         |   0
 src/kernel/src/stubs.asm                      | 145 ---
 src/kernel/src/syscall.c                      | 899 +++---------------
 src/{kernel2 =3D> kernel}/src/syscalls/io.c     |   0
 .../src/syscalls/lio_server.c                 |   0
 src/{kernel2 =3D> kernel}/src/syscalls/lostio.c |   0
 src/{kernel2 =3D> kernel}/src/syscalls/mem.c    |   0
 src/{kernel2 =3D> kernel}/src/syscalls/misc.c   |   0
 src/{kernel2 =3D> kernel}/src/syscalls/mutex.c  |   0
 src/{kernel2 =3D> kernel}/src/syscalls/pm.c     |   0
 src/{kernel2 =3D> kernel}/src/syscalls/pv.c     |   0
 src/{kernel2 =3D> kernel}/src/syscalls/rpc.c    |   0
 src/{kernel2 =3D> kernel}/src/syscalls/shm.c    |   0
 src/kernel/src/task.c                         | 422 --------
 src/{kernel2 =3D> kernel}/src/tasks/modules.c   |   0
 src/{kernel2 =3D> kernel}/src/tasks/pm.c        |   0
 src/{kernel2 =3D> kernel}/src/tasks/scheduler.c |   0
 src/{kernel2 =3D> 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/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/module.mk                     |  16 -
 src/kernel2/src/syscall.c                     | 180 ----
 src/kernel2/src/timer.c                       | 169 ----
 144 files changed, 2245 insertions(+), 9933 deletions(-)
 rename src/{kernel2 =3D> kernel}/.ignorenobuild (100%)
 delete mode 100644 src/kernel/.nobuild
 rename src/{kernel2 =3D> kernel}/include/apic.h (100%)
 rename src/{kernel2 =3D> kernel}/include/arch/amd64/cpu_arch.h (100%)
 rename src/{kernel2 =3D> kernel}/include/arch/amd64/mm_arch.h (100%)
 rename src/{kernel2 =3D> kernel}/include/arch/i386/cpu_arch.h (100%)
 rename src/{kernel2 =3D> kernel}/include/arch/i386/mm_arch.h (100%)
 delete mode 100644 src/kernel/include/bitops.h
 rename src/{kernel2 =3D> 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 =3D> kernel}/include/lostio/client.h (100%)
 rename src/{kernel2 =3D> kernel}/include/lostio/core.h (100%)
 rename src/{kernel2 =3D> kernel}/include/lostio/userspace.h (100%)
 rename src/{kernel2 =3D> kernel}/include/mm.h (100%)
 delete mode 100644 src/kernel/include/modules.h
 rename src/{kernel2 =3D> kernel}/include/notifier.h (100%)
 delete mode 100644 src/kernel/include/paging.h
 delete mode 100644 src/kernel/include/phys.h
 rename src/{kernel2 =3D> kernel}/include/pic.h (100%)
 delete mode 100644 src/kernel/include/rpc.h
 delete mode 100644 src/kernel/include/shm.h
 rename src/{kernel2 =3D> 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 =3D> kernel}/src/arch/amd64/Makefile.all (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/cpu.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/debug.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/gdt.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/header.S (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/im/im.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/im/int_stubs.S (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/kernel.ld (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/loader/loader.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/loader/loader.ld (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/loader/startup.S (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/mm/mm_context.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/mm/mm_virt.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/amd64/smp/trampoline.S (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/Makefile.all (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/cpu.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/debug.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/gdt.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/header.asm (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/interrupts/im.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/interrupts/int_stubs.S (100=
%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/io.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/kernel.ld (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/mm/mm_context.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/mm/virt.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/smp/trampoline.S (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/syscall.c (100%)
 rename src/{kernel2 =3D> kernel}/src/arch/i386/syscalls/vm86.c (100%)
 rename src/{kernel2 =3D> 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 =3D> kernel}/src/interrupts/apic.c (100%)
 rename src/{kernel2 =3D> kernel}/src/interrupts/im.c (100%)
 rename src/{kernel2 =3D> 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 =3D> kernel}/src/libc_helper.c (100%)
 rename src/{kernel2 =3D> kernel}/src/lostio/client.c (100%)
 rename src/{kernel2 =3D> kernel}/src/lostio/include/lostio_int.h (100%)
 rename src/{kernel2 =3D> kernel}/src/lostio/lostio.c (100%)
 rename src/{kernel2 =3D> kernel}/src/lostio/modules/file.c (100%)
 rename src/{kernel2 =3D> kernel}/src/lostio/modules/tmp.c (100%)
 rename src/{kernel2 =3D> kernel}/src/lostio/pipes.c (100%)
 rename src/{kernel2 =3D> kernel}/src/lostio/tree.c (100%)
 rename src/{kernel2 =3D> 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
 create mode 100644 src/kernel/src/module.mk
 delete mode 100644 src/kernel/src/modules.c
 rename src/{kernel2 =3D> kernel}/src/notifier.c (100%)
 delete mode 100644 src/kernel/src/rpc.c
 delete mode 100644 src/kernel/src/schedule.c
 rename src/{kernel2 =3D> kernel}/src/smp/Makefile.conf (100%)
 rename src/{kernel2 =3D> kernel}/src/smp/rm_trampoline.asm (100%)
 rename src/{kernel2 =3D> kernel}/src/smp/smp.c (100%)
 delete mode 100644 src/kernel/src/stubs.asm
 rename src/{kernel2 =3D> kernel}/src/syscalls/io.c (100%)
 rename src/{kernel2 =3D> kernel}/src/syscalls/lio_server.c (100%)
 rename src/{kernel2 =3D> kernel}/src/syscalls/lostio.c (100%)
 rename src/{kernel2 =3D> kernel}/src/syscalls/mem.c (100%)
 rename src/{kernel2 =3D> kernel}/src/syscalls/misc.c (100%)
 rename src/{kernel2 =3D> kernel}/src/syscalls/mutex.c (100%)
 rename src/{kernel2 =3D> kernel}/src/syscalls/pm.c (100%)
 rename src/{kernel2 =3D> kernel}/src/syscalls/pv.c (100%)
 rename src/{kernel2 =3D> kernel}/src/syscalls/rpc.c (100%)
 rename src/{kernel2 =3D> kernel}/src/syscalls/shm.c (100%)
 delete mode 100644 src/kernel/src/task.c
 rename src/{kernel2 =3D> kernel}/src/tasks/modules.c (100%)
 rename src/{kernel2 =3D> kernel}/src/tasks/pm.c (100%)
 rename src/{kernel2 =3D> kernel}/src/tasks/scheduler.c (100%)
 rename src/{kernel2 =3D> 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/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/module.mk
 delete mode 100644 src/kernel2/src/syscall.c
 delete mode 100644 src/kernel2/src/timer.c

diff --git a/Makefile.Jidder b/Makefile.Jidder
index a97c3bf5..3e5bcfa4 100644
--- a/Makefile.Jidder
+++ b/Makefile.Jidder
@@ -3,10 +3,9 @@
=20
 ARCH ?=3D i386
=20
-LDFLAGS_KERNEL :=3D -T src/kernel/src/kernel.ld
 LDFLAGS_MODULES :=3D -m elf_i386 -Ttext=3D0x40000000
=20
-LDFLAGS_KERNEL2 :=3D -T src/kernel2/src/arch/$(ARCH)/kernel.ld
+LDFLAGS_KERNEL :=3D -T src/kernel/src/arch/$(ARCH)/kernel.ld
=20
 CPPFLAGS +=3D -Isrc/include -Isrc/include/arch/$(ARCH)
=20
@@ -54,7 +53,7 @@ build/lost.krn: CPPFLAGS +=3D -Isrc/kernel/include
=20
 zkernel: build/lost.kgz
=20
--include src/kernel2/src/module.mk
+-include src/kernel/src/module.mk
=20
 build/%.kgz: build/%.krn
 	cp -f $< $@
diff --git a/buildmk.sh b/buildmk.sh
index 8e344785..fbdb4fe0 100644
--- a/buildmk.sh
+++ b/buildmk.sh
@@ -134,7 +134,7 @@ AS=3D\$(AS_BINARY)
 all:
 EOF
=20
-if [ "`pwd | grep '/src/kernel2'`" =3D=3D "" ]; then
+if [ "`pwd | grep '/src/kernel'`" =3D=3D "" ]; then
 cat <<EOF >> Makefile
 	\$(MAKE) --no-print-directory -s makefiles
 	\$(MAKE) --no-print-directory -s subdirs
diff --git a/src/kernel2/.ignorenobuild b/src/kernel/.ignorenobuild
similarity index 100%
rename from src/kernel2/.ignorenobuild
rename to src/kernel/.ignorenobuild
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/a=
rch/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=0D
-#define BITOPS_H=0D
-=0D
-/* Voraussetzung: Mindestens ein Bit von i muss gesetzt sein. */=0D
-static inline unsigned int bit_scan_forward(unsigned int i)=0D
-{=0D
-    unsigned int j;=0D
-#if 0=0D
-    for(j =3D 0; j < 32; j++)=0D
-    {=0D
-        if(i & (1 << j))=0D
-        {=0D
-            return j;=0D
-        }=0D
-    }=0D
-#else=0D
-    __asm__("bsfl %1, %0\n\t" : "=3Dr"(j) : "g"(i));=0D
-    return j;=0D
-#endif=0D
-}=0D
-=0D
-#endif /* ndef BITOPS_H */=0D
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 @@
+/*=0D
+ * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.=0D
+ *=0D
+ * This code is derived from software contributed to the tyndur Project=0D
+ * by Burkhard Weseloh.=0D
+ *=0D
+ * Redistribution and use in source and binary forms, with or without=0D
+ * modification, are permitted provided that the following conditions=0D
+ * are met:=0D
+ * 1. Redistributions of source code must retain the above copyright=0D
+ *    notice, this list of conditions and the following disclaimer.=0D
+ * 2. Redistributions in binary form must reproduce the above copyright=0D
+ *    notice, this list of conditions and the following disclaimer in the=
=0D
+ *    documentation and/or other materials provided with the distribution.=
=0D
+ * 3. All advertising materials mentioning features or use of this softwar=
e=0D
+ *    must display the following acknowledgement:=0D
+ *     This product includes software developed by the tyndur Project=0D
+ *     and its contributors.=0D
+ * 4. Neither the name of the tyndur Project nor the names of its=0D
+ *    contributors may be used to endorse or promote products derived=0D
+ *    from this software without specific prior written permission.=0D
+ *=0D
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=0D
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED=0D
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR=0D
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=0D
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=
=0D
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=0D
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=0D
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=0D
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=0D
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=0D
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0D
+ */=0D
+=0D
 #ifndef CONSOLE_H=0D
 #define CONSOLE_H=0D
 =0D
+extern void init_console(void);=0D
+=0D
 extern void con_putc(const char c); // Zeichen ausgeben ohne Auswertung de=
r ANSI-Codes=0D
 extern void con_putc_ansi(const char c); // Zeichen ausgeben mit Auswertun=
g der ANSI-Codes=0D
 extern void con_puts(const char * s); // Zeichenkette ausgeben mit Auswert=
ung der ANSI-Codes=0D
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=0D
-#define CPU_H=0D
-=0D
-#include <stdint.h>=0D
-=0D
-#define CR0_PE		0x00000001 // Protection Enable=0D
-#define CR0_PG		0x80000000 // Paging=0D
-=0D
-#define CR4_PSE		0x00000010 // Page Size Extensions=0D
-=0D
-// eflags register=0D
-#define FL_TF		0x00000100 // Trap Flag=0D
-#define FL_IF		0x00000200 // Interrupt Flag=0D
-#define FL_IOPL0	0x00000000 // I/O Privilege Level 0=0D
-#define FL_IOPL1	0x00001000 // I/O Privilege Level 1=0D
-#define FL_IOPL2	0x00002000 // I/O Privilege Level 2=0D
-#define FL_IOPL3	0x00003000 // I/O Privilege Level 3=0D
-#define FL_NT		0x00004000 // Nested Task=0D
-#define FL_RF		0x00010000 // Resume Flag=0D
-#define FL_VM		0x00020000 // Virtual 8086 mode=0D
-=0D
-static inline uint32_t read_cr2(void)=0D
-{=0D
-    uint32_t ret;=0D
-    __asm volatile ("mov %%cr2, %0" : "=3Dr"(ret));=0D
-    return ret;=0D
-}=0D
-=0D
-#endif /* ndef CPU_H */=0D
+/*
+ * 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 softwar=
e
+ *    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 LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * 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 PROF=
ITS;
+ * 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 @@
+/*=0D
+ * Copyright (c) 2006-2008 The tyndur Project. All rights reserved.=0D
+ *=0D
+ * This code is derived from software contributed to the tyndur Project=0D
+ * by Kevin Wolf.=0D
+ *=0D
+ * Redistribution and use in source and binary forms, with or without=0D
+ * modification, are permitted provided that the following conditions=0D
+ * are met:=0D
+ * 1. Redistributions of source code must retain the above copyright=0D
+ *    notice, this list of conditions and the following disclaimer.=0D
+ * 2. Redistributions in binary form must reproduce the above copyright=0D
+ *    notice, this list of conditions and the following disclaimer in the=
=0D
+ *    documentation and/or other materials provided with the distribution.=
=0D
+ * 3. All advertising materials mentioning features or use of this softwar=
e=0D
+ *    must display the following acknowledgement:=0D
+ *     This product includes software developed by the tyndur Project=0D
+ *     and its contributors.=0D
+ * 4. Neither the name of the tyndur Project nor the names of its=0D
+ *    contributors may be used to endorse or promote products derived=0D
+ *    from this software without specific prior written permission.=0D
+ *=0D
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=0D
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED=0D
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR=0D
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=0D
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=
=0D
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=0D
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=0D
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=0D
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=0D
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=0D
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0D
+ */=0D
+=0D
+#ifndef _DEBUG_H_=0D
+#define _DEBUG_H_=0D
+=0D
 #include <stdint.h>=0D
 #include <stdbool.h>=0D
 =0D
@@ -7,13 +45,6 @@
 #define DEBUG_FLAG_STACK_BACKTRACE 2=0D
 #define DEBUG_FLAG_PEDANTIC 4=0D
 #define DEBUG_FLAG_SYSCALL 8=0D
-#define DEBUG_FLAG_NO_KCONSOLE 16=0D
-=0D
-/* Int2Str , Wandelt signed ints in Strings um */=0D
-char* int2str(signed int value,char *result);=0D
-=0D
-/* Einfache Print-Funktion f=EF=BF=BDr grundlegende Ausgaben */=0D
-void print(char *string,const int len);=0D
 =0D
 ///Setzt die richtigen Debug-Flags anhand der Commandline vom bootloader=
=0D
 void debug_parse_cmdline(char* cmdline);=0D
@@ -23,9 +54,11 @@ bool debug_test_flag(uint32_t flag);
 =0D
 ///Gibt die Debug-Meldung aus, wenn das Flag gesetzt ist=0D
 void debug_print(uint32_t flag, const char* message);=0D
-=0D
-/* =0D
- * Gibt einen Stack Backtrace aus, beginnend an den =EF=BF=BDbergebenen We=
rten=0D
- * f=EF=BF=BDr ebp und eip=0D
- */=0D
-void stack_backtrace_ebp(uint32_t start_ebp, uint32_t start_eip);=0D
+
+/*
+ * Gibt einen Stack Backtrace aus, beginnend an den =EF=BF=BDbergebenen We=
rten
+ * f=EF=BF=BDr 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
+/*=0D
+ * Copyright (c) 2007 The tyndur Project. All rights reserved.=0D
+ *=0D
+ * This code is derived from software contributed to the tyndur Project=0D
+ * by Kevin Wolf.=0D
+ *=0D
+ * Redistribution and use in source and binary forms, with or without=0D
+ * modification, are permitted provided that the following conditions=0D
+ * are met:=0D
+ * 1. Redistributions of source code must retain the above copyright=0D
+ *    notice, this list of conditions and the following disclaimer.=0D
+ * 2. Redistributions in binary form must reproduce the above copyright=0D
+ *    notice, this list of conditions and the following disclaimer in the=
=0D
+ *    documentation and/or other materials provided with the distribution.=
=0D
+ * 3. All advertising materials mentioning features or use of this softwar=
e=0D
+ *    must display the following acknowledgement:=0D
+ *     This product includes software developed by the tyndur Project=0D
+ *     and its contributors.=0D
+ * 4. Neither the name of the tyndur Project nor the names of its=0D
+ *    contributors may be used to endorse or promote products derived=0D
+ *    from this software without specific prior written permission.=0D
+ *=0D
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=0D
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED=0D
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR=0D
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=0D
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=
=0D
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=0D
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=0D
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=0D
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=0D
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=0D
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0D
+ */=0D
+=0D
+#ifndef _GDT_H_=0D
+#define _GDT_H_=0D
+#include <types.h>=0D
+=0D
+void gdt_init(void);=0D
+void gdt_init_local(void);=0D
+=0D
+#endif //ifndef _GDT_H_=0D
+=0D
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 typ=
e);
-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 co=
de */
-
-#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 @@
-/* =20
- * 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 softwar=
e
- *    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=20
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */ =20
-
-#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=0D
-#define KERNEL_H=0D
-    =0D
-//#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 softwar=
e
+ *    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 LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * 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 PROF=
ITS;
+ * 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_
=20
 #include <stdint.h>
-#include <types.h>
=20
-__attribute__((noreturn)) void panic(char * message, ...);
+extern uint64_t timer_ticks;
+
+__attribute__((noreturn)) void panic(char* message, ...);
=20
-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];  };
=20
-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)
=20
-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))
=20
-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))
=20
-extern void kernel_start(void);
-extern void kernel_phys_start(void);
-extern void kernel_end(void);=0D
-extern void kernel_phys_end(void);=0D
-=0D
-#endif /* ndef KERNEL_H */=0D
+#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=0D
-#define KPRINTF_H=0D
-=0D
-extern void kprintf(char * format, ...);=0D
-extern void kaprintf(char * format, int ** args);=0D
-=0D
-#endif /* ndef KPRINTF_H */=0D
+#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/losti=
o/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/lo=
stio/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 @@
-/*-=0D
- * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.=0D
- * All rights reserved.=0D
- *=0D
- * This code is derived from software contributed to The NetBSD Foundation=
=0D
- * by Julio M. Merino Vidal.=0D
- *=0D
- * Redistribution and use in source and binary forms, with or without=0D
- * modification, are permitted provided that the following conditions=0D
- * are met:=0D
- * 1. Redistributions of source code must retain the above copyright=0D
- *    notice, this list of conditions and the following disclaimer.=0D
- * 2. Redistributions in binary form must reproduce the above copyright=0D
- *    notice, this list of conditions and the following disclaimer in the=
=0D
- *    documentation and/or other materials provided with the distribution.=
=0D
- * 3. All advertising materials mentioning features or use of this softwar=
e=0D
- *    must display the following acknowledgement:=0D
- *	This product includes software developed by the NetBSD=0D
- *	Foundation, Inc. and its contributors.=0D
- * 4. Neither the name of The NetBSD Foundation nor the names of its=0D
- *    contributors may be used to endorse or promote products derived=0D
- *    from this software without specific prior written permission.=0D
- *=0D
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTO=
RS=0D
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED=0D
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR=0D
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTO=
RS=0D
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR=
=0D
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF=0D
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINES=
S=0D
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN=
=0D
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)=
=0D
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF =
THE=0D
- * POSSIBILITY OF SUCH DAMAGE.=0D
- */=0D
-=0D
-=0D
-#ifndef MULTIBOOT_H=0D
-#define MULTIBOOT_H=0D
-=0D
-#include <stdint.h>=0D
-#include <types.h>=0D
-=0D
-/* --------------------------------------------------------------------- *=
/=0D
-=0D
-/*=0D
- * Multiboot header structure.=0D
- */=0D
-#define MULTIBOOT_HEADER_MAGIC		    0x1BADB002=0D
-#define MULTIBOOT_HEADER_MODS_ALIGNED	0x00000001=0D
-#define MULTIBOOT_HEADER_WANT_MEMORY	0x00000002=0D
-#define MULTIBOOT_HEADER_HAS_VBE	    0x00000004=0D
-#define MULTIBOOT_HEADER_HAS_ADDR   	0x00010000=0D
-=0D
-struct multiboot_header {=0D
-	uint32_t   mh_magic;=0D
-	uint32_t   mh_flags;=0D
-	uint32_t   mh_checksum;=0D
-=0D
-	/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */=0D
-	paddr_t mh_header_addr;=0D
-	paddr_t mh_load_addr;=0D
-	paddr_t mh_load_end_addr;=0D
-	paddr_t mh_bss_end_addr;=0D
-	paddr_t mh_entry_addr;=0D
-=0D
-	/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */=0D
-	uint32_t   mh_mode_type;=0D
-	uint32_t   mh_width;=0D
-	uint32_t   mh_height;=0D
-	uint32_t   mh_depth;=0D
-};=0D
-=0D
-/* --------------------------------------------------------------------- *=
/=0D
-=0D
-/*=0D
- * Multiboot information structure.=0D
- */=0D
-#define MULTIBOOT_INFO_MAGIC		    0x2BADB002=0D
-#define MULTIBOOT_INFO_HAS_MEMORY	    0x00000001=0D
-#define MULTIBOOT_INFO_HAS_BOOT_DEVICE	0x00000002=0D
-#define MULTIBOOT_INFO_HAS_CMDLINE	    0x00000004=0D
-#define MULTIBOOT_INFO_HAS_MODS		    0x00000008=0D
-#define MULTIBOOT_INFO_HAS_AOUT_SYMS	0x00000010=0D
-#define MULTIBOOT_INFO_HAS_ELF_SYMS	    0x00000020=0D
-#define MULTIBOOT_INFO_HAS_MMAP		    0x00000040=0D
-#define MULTIBOOT_INFO_HAS_DRIVES	    0x00000080=0D
-#define MULTIBOOT_INFO_HAS_CONFIG_TABLE	0x00000100=0D
-#define MULTIBOOT_INFO_HAS_LOADER_NAME	0x00000200=0D
-#define MULTIBOOT_INFO_HAS_APM_TABLE	0x00000400=0D
-#define MULTIBOOT_INFO_HAS_VBE		    0x00000800=0D
-=0D
-struct multiboot_info {=0D
-	uint32_t	mi_flags;=0D
-=0D
-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */=0D
-	uint32_t	mi_mem_lower;=0D
-	uint32_t	mi_mem_upper;=0D
-=0D
-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */=0D
-	uint8_t	mi_boot_device_part3;=0D
-	uint8_t	mi_boot_device_part2;=0D
-	uint8_t	mi_boot_device_part1;=0D
-	uint8_t	mi_boot_device_drive;=0D
-=0D
-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */=0D
-	char *	mi_cmdline;=0D
-=0D
-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */=0D
-	uint32_t	mi_mods_count;=0D
-	struct multiboot_module * mi_mods_addr;=0D
-=0D
-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */=0D
-	uint32_t	mi_elfshdr_num;=0D
-	uint32_t	mi_elfshdr_size;=0D
-	vaddr_t	mi_elfshdr_addr;=0D
-	uint32_t	mi_elfshdr_shndx;=0D
-=0D
-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */=0D
-	uint32_t	mi_mmap_length;=0D
-	vaddr_t	mi_mmap_addr;=0D
-=0D
-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */=0D
-	uint32_t	mi_drives_length;=0D
-	vaddr_t	mi_drives_addr;=0D
-=0D
-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */=0D
-	void *	unused_mi_config_table;=0D
-=0D
-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */=0D
-	char *	mi_loader_name;=0D
-=0D
-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */=0D
-	void *	unused_mi_apm_table;=0D
-=0D
-	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */=0D
-	void *	unused_mi_vbe_control_info;=0D
-	void *	unused_mi_vbe_mode_info;=0D
-	paddr_t	unused_mi_vbe_interface_seg;=0D
-	paddr_t	unused_mi_vbe_interface_off;=0D
-	uint32_t	unused_mi_vbe_interface_len;=0D
-};=0D
-=0D
-extern struct multiboot_info multiboot_info;=0D
-=0D
-/* --------------------------------------------------------------------- *=
/=0D
-=0D
-/*=0D
- * Drive information.  This describes an entry in the drives table as=0D
- * pointed to by mi_drives_addr.=0D
- */=0D
-struct multiboot_drive {=0D
-	uint32_t	md_length;=0D
-	uint8_t	md_number;=0D
-	uint8_t	md_mode;=0D
-	uint16_t	md_cylinders;=0D
-	uint8_t	md_heads;=0D
-	uint8_t	md_sectors;=0D
-=0D
-	/* The variable-sized 'ports' field comes here, so this structure=0D
-	 * can be longer. */=0D
-};=0D
-=0D
-/* --------------------------------------------------------------------- *=
/=0D
-=0D
-/*=0D
- * Memory mapping.  This describes an entry in the memory mappings table=
=0D
- * as pointed to by mi_mmap_addr.=0D
- *=0D
- * Be aware that mm_size specifies the size of all other fields *except*=
=0D
- * for mm_size.  In order to jump between two different entries, you=0D
- * have to count mm_size + 4 bytes.=0D
- */=0D
-struct multiboot_mmap {=0D
-	uint32_t	mm_size;=0D
-	uint64_t	mm_base_addr;=0D
-	uint64_t	mm_length;=0D
-	uint32_t	mm_type;=0D
-};=0D
-=0D
-=0D
-struct multiboot_module {=0D
-  vaddr_t start;=0D
-  vaddr_t end;=0D
-  char* cmdline;=0D
-  uint32_t reserved;=0D
-};=0D
-=0D
-#endif=0D
+/*-
+ * 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 softwar=
e
+ *    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 CONTRIBUTO=
RS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTO=
RS
+ * 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 BUSINES=
S
+ * 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 padd=
r, 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* metad=
ata,=20
-    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 @@
-/* =20
- * 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 softwar=
e
- *    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=20
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */ =20
-
-#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=C3=BCgten 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 softwar=
e
+ *    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 LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * 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 PROF=
ITS;
+ * 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.
+ */
=20
+#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 Sysca=
ll
+    /// nicht existiert.
+    void* handler;
+   =20
+    /// Anzahl der Argumente die der Syscall benoetigt
+    size_t arg_count;
+
+    /// true, wenn der Syscall nur aus dem Kernelspace aufgerufen werden d=
arf
+    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_coun=
t);
+
+/// 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* p=
hys);
+
+/// 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 siz=
e);
+
+/// 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=C3=B6=C3=9Fe eines Shared Memory zur=C3=BCckgeben
+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 =C3=BCber eine Ressource abfragen
+int syscall_lio_stat(lio_usp_resource_t* resid, struct lio_stat* sbuf);
+
+/// Ressource =C3=B6ffnen
+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=C3=9Fen
+int syscall_lio_close(lio_usp_stream_t* stream_id);
+
+/// Zus=C3=A4tzliche ID f=C3=BCr 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 =C3=BCbergeben hat, au=
slesen
+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 =C3=A4ndern
+void syscall_lio_seek(lio_usp_stream_t* stream_id, int64_t* offset,
+    int whence, int64_t* result);
+
+/// Dateigr=C3=B6=C3=9Fe =C3=A4ndern
+int syscall_lio_truncate(lio_usp_stream_t* stream_id, uint64_t* size);
+
+/// Ver=C3=A4nderte 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 nu=
m,
+    struct lio_usp_dir_entry* dent, ssize_t* result);
+
+/// Ressourcenspezifischen Befehl ausf=C3=BChren
+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=C3=B6schen
+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* na=
me,
+    size_t name_len);
+
+/// Kernel ueber abgearbeitete Operation informieren
+void syscall_lio_srv_op_done(struct lio_op* op, int status, uint64_t* resu=
lt);
+
+/// 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);
+
=20
-#include "intr.h"
-#include "syscallno.h"
-#include <lost/config.h>
+// Diverse
+/// Textausgabe ueber den Kernel
+void syscall_putsn(int char_count, char* source);
=20
-#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);
=20
-void syscall(struct int_stack_frame ** esp);
+/// BIOS-Interrupt ausfuehren
+int syscall_vm86(uint8_t intr, void* regs, uint32_t* memory);
=20
-bool syscall_rpc(uint32_t callee_pid, uint32_t data_size, char* data);
+#endif //ifndef _SYSCALL_H_
=20
-#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 softwar=
e
+ *    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 LIM=
ITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
+ * 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 PROF=
ITS;
+ * 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_
=20
-#include <types.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <types.h>
+#include <collections.h>
+#include <lost/config.h>
=20
-#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"
=20
-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
=20
-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 =3D=3D ARCH_I386
+    /// IO-Bitmap
+    void* io_bitmap;
+#elif CONFIG_ARCH =3D=3D 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;
-   =20
-    struct task* parent_task;
=20
-    const char* cmdline;
-   =20
-    void* io_bitmap;
+    /// Wird gesperrt, wenn aenderungen am Thread vorgenommen werden
+    lock_t lock;
=20
-    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;
-   =20
-    //Shared Memory
-    list_t *shmids;
-    list_t *shmaddresses;
-
-    // Benutzter speicher
-    uint32_t memory_used;
-   =20
-    // VM86-Info
+    /// Gesetzt, wenn der Thread ein VM86-Thread mit allem Drum und Dran i=
st
     bool vm86;
-    vm86_info_t *vm86_info;
-};
=20
-extern struct task* current_task;
-extern struct task* first_task;
+    /// Eindeutige Threadnummer
+    tid_t tid;
=20
-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;
=20
-// 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;
=20
+    /// Eine Liste der von diesem Thread angebotenen LIO-Services
+    list_t* lio_services;
=20
-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;
=20
-void abort_task(char* format, ...);
+typedef void (*pm_process_destroy_handler)(pm_process_t* process, void* pr=
v);
+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 =C3=BCbergebenen 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_
=20
-#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 softwar=
e
  *    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_
=20
 #include <stdint.h>
-
 #include "tasks.h"
=20
 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);
=20
 #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=0D
-#define TSS_H=0D
-=0D
-#include <stdint.h>=0D
-#include <stddef.h>=0D
-=0D
-#define IO_BITMAP_LENGTH 0xffff=0D
-=0D
-// Dieser Wert muss ausserhalb des in der GDT definierten Limits=0D
-// fuer das TSS liegen=0D
-#define TSS_IO_BITMAP_NOT_LOADED (sizeof(tss) + 0x100)=0D
-#define TSS_IO_BITMAP_OFFSET offsetof(tss_t, io_bit_map)=0D
-=0D
-typedef struct tss_s=0D
-{=0D
-	uint32_t backlink;=0D
-	uint32_t esp0;=0D
-	uint32_t ss0;=0D
-	uint32_t esp1;=0D
-	uint32_t ss1;=0D
-	uint32_t esp2;=0D
-	uint32_t ss2;=0D
-	uint32_t cr3;=0D
-	uint32_t eip;=0D
-	uint32_t eflags;=0D
-	uint32_t eax;=0D
-	uint32_t ecx;=0D
-	uint32_t edx;=0D
-	uint32_t ebx;=0D
-	uint32_t esp;=0D
-	uint32_t ebp;=0D
-	uint32_t esi;=0D
-	uint32_t edi;=0D
-	uint32_t es;=0D
-	uint32_t cs;=0D
-	uint32_t ss;=0D
-	uint32_t ds;=0D
-	uint32_t fs;=0D
-	uint32_t gs;=0D
-	uint32_t ldt;=0D
-	uint16_t trace_trap;=0D
-	uint16_t io_bit_map_offset;=0D
-    uint8_t io_bit_map[IO_BITMAP_LENGTH / 8];=0D
-    uint8_t io_bit_map_end;=0D
-} __attribute__((packed)) tss_t;=0D
-=0D
-extern tss_t tss;=0D
-=0D
-#endif /* ndef TSS_H */=0D
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 @@
-/* =20
- * 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=20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
+ * 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 PROF=
ITS;
+ * 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.
  */
=20
-#ifndef VM86_H
-#define VM86_h
+#ifndef _VM86_H_
+#define _VM86_H_
=20
-#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);
=20
 #endif
=20
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=0D
-#define VMM_H=0D
-=0D
-#define PAGE_DIRECTORY_LENGTH 1024=0D
-#define PAGE_TABLE_LENGTH 1024=0D
-=0D
-#define PAGE_SHIFT 12=0D
-#define PAGE_SIZE (1 << PAGE_SHIFT)=0D
-#define PAGE_MASK (~(PAGE_SIZE - 1))=0D
-=0D
-// Die Anzahl der Pages, die von n Bytes belegt werden.=0D
-#define NUM_PAGES(n) ((((n) + ~PAGE_MASK) & PAGE_MASK) / PAGE_SIZE)=0D
-=0D
-// Rundet eine Adresse auf das kleinste Vielfache von PAGE_SIZE > n auf=0D
-#define PAGE_ALIGN_ROUND_UP(n) (((n) + ~PAGE_MASK) & PAGE_MASK)=0D
-=0D
-// Rundet eine Adresse auf das gr=EF=BF=BD=EF=BF=BDte Vielfache von PAGE_S=
IZE < n ab=0D
-#define PAGE_ALIGN_ROUND_DOWN(n) ((n) & PAGE_MASK)=0D
-=0D
-#define PGDIR_SHIFT 22=0D
-=0D
-#define PTE_P       0x001 // present=0D
-#define PTE_W       0x002 // writable=0D
-#define PTE_U       0x004 // user=0D
-#define PTE_PWT     0x008 // write-through=0D
-#define PTE_PCT     0x010 // cache-disable=0D
-#define PTE_A       0x020 // accessed=0D
-#define PTE_D       0x040 // dirty=0D
-#define PTE_PS      0x080 // page size=0D
-=0D
-#define PTE_AVAIL1  0x200 // available for software use=0D
-#define PTE_AVAIL2  0x400 // available for software use=0D
-#define PTE_AVAIL3  0x800 // available for software use=0D
-=0D
-typedef unsigned long * page_directory_t;=0D
-typedef unsigned long * page_table_t;=0D
-=0D
-typedef enum { page_4K, page_4M } page_size_t;=0D
-=0D
-// Die Adresse, an der der Kernel-Adressraum beginnt=0D
-#define KERNEL_BASE 0x00000000=0D
-=0D
-// Die Anzahl der Page Tables, die f=EF=BF=BDr den Kerneladressraum ben=EF=
=BF=BDtigt werden=0D
-#define NUM_KERNEL_PAGE_TABLES (PAGE_DIRECTORY_LENGTH - (KERNEL_BASE >> PG=
DIR_SHIFT))=0D
-=0D
-// Alle Kernel Page Tables werden nach KERNEL_PAGE_TABLES_VADDR gemappt=0D
-#define KERNEL_PAGE_TABLES_VADDR 0x3fc00000=0D
-=0D
-=0D
-#define USER_MEM_START 0x40000000=0D
-#define USER_MEM_END   0xffffffff=0D
-=0D
-#endif /* ndef VMM_H */=0D
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/c=
pu.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/g=
dt.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/amd6=
4/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/arc=
h/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/amd=
64/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/ar=
ch/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/a=
rch/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/a=
rch/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/ar=
ch/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/a=
rch/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/i=
386/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/d=
ebug.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/i38=
6/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/arc=
h/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/arc=
h/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/ar=
ch/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/arc=
h/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/vm=
86.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 @@
  */
=20
 #include <stdint.h>
-
-#include "string.h"
-#include "ports.h"
-#include <debug.h>
+#include <string.h>
+#include <ports.h>
=20
 /*
  * Das hier ist eine sehr beschr=EF=BF=BDnkte Untermenge der ANSI Escape C=
odes. Alle
@@ -89,9 +87,9 @@
 #define SCREEN_WIDTH 80
 #define SCREEN_HEIGHT 25
=20
-static void con_set_hw_cursor(void);
+void con_set_hw_cursor(void);
=20
-static unsigned short * vidmem =3D (unsigned short*)0xb8000;
+unsigned short * vidmem =3D (unsigned short*)0xb8000;
=20
 // Aktuelle Cursor-Position
 static unsigned int cursor_x;
@@ -366,15 +364,11 @@ static ansi_esc_seq_status_t con_ansi_parse(const cha=
r * ansi_buf, unsigned int
                 return SUCCESS;
=20
             case 'm': // ESC[#m oder ESC[#;#m - Vorder- und Hintergrundfar=
be =EF=BF=BDndern, Fettschrift, Blinken
-            {
-                // Attribute sichern
-                unsigned char attr =3D con_color._color;
-
                 if(!have_n1)
                 {
                     return INVALID;
                 }
-
+               =20
                 if(handle_ansi_formatting_sequence_number(n1) !=3D SUCCESS=
)
                 {
                     return INVALID;
@@ -384,14 +378,11 @@ static ansi_esc_seq_status_t con_ansi_parse(const cha=
r * ansi_buf, unsigned int
                 {
                     if(handle_ansi_formatting_sequence_number(n2) !=3D SUC=
CESS)
                     {
-                        // Bereits uebernommene Aenderungen rueckgaengig m=
achen
-                        con_color._color =3D attr;
                         return INVALID;
                     }
                 }
=20
                 return SUCCESS;
-            }
=20
             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 =3D 0;
=20
+    if (c =3D=3D '\n') {
+        outb(0x3f8, '\r');
+        while ((inb(0x3fd) & 0x20) =3D=3D 0) asm("nop");
+    }
     outb(0xe9, c);
     outb(0x3f8, c);
     while ((inb(0x3fd) & 0x20) =3D=3D 0) asm("nop");
    =20
-    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 =3D 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.
  */
=20
+#include <elf32.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <string.h>
=20
-#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 =3D 0; // Zeiger auf den ELF-Header-Eintrag der=
 Symbol Tabelle ...
-static Elf32_Shdr * strtab =3D 0; // ... und der String Tabelle
=20
 static uint32_t debug_flags =3D 0;
=20
 /**
- * Gibt einen Zeiger auf das Symbol mit der gr=EF=BF=BD=EF=BF=BDten Adress=
e kleiner als addr=20
- * zur=EF=BF=BDck. Wenn kein Symbol bestimmt werden kann, wird 0 zur=EF=BF=
=BDck gegeben.
- */
-static Elf32_Sym * elf_find_sym(uint32_t addr)
-{
-    Elf32_Sym * sym;
-    int i;
-
-    if(symtab =3D=3D 0)
-    {
-        return 0;
-    }
-
-    sym =3D (Elf32_Sym *)symtab->sh_addr;
-
-    for(i =3D 0; i < symtab->sh_size / sizeof(Elf32_Sym); i++)
-    {
-        if(addr >=3D (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=EF=BF=
=BDck.
+ * 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 =3D=3D 0)
-    {
-        return "";
-    }
-
-    return (char*)strtab->sh_addr + index;
+    return ((debug_flags & flag) !=3D 0);
 }
=20
 /**
- * Mappt den ELF-Header, sowie die ELF-Symbol-Tabelle und die dazugeh=EF=
=BF=BDrige
- * 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 =3D (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 =3D 0; i < multiboot_info.mi_elfshdr_num; i++)
-        {
-            if(elfshdr[i].sh_type =3D=3D SHT_SYMTAB)
-            {
-                symtab =3D &elfshdr[i];
-                strtab =3D &elfshdr[symtab->sh_link];
-               =20
-                break;
-            }
-        }
-    }
-
-    if(symtab !=3D 0 && strtab !=3D 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 !=3D 0)
-    {
-        kprintf("ebp %08x eip %08x", start_ebp, start_eip);
-        if((sym =3D elf_find_sym(start_eip)))
-        {
-            kprintf(" <%s + 0x%x>", elf_get_str(sym->st_name), start_eip -=
 sym->st_value);
-        }
-        kprintf("\n");
-
-        stack_frame =3D (struct stack_frame*) start_ebp;
-    }
-    else
-    {
-        __asm volatile ("mov %%ebp, %0" : "=3Dr"(stack_frame));
-    }
-
-    for( ; is_userspace(stack_frame, sizeof(*stack_frame)) && stack_frame-=
>ebp !=3D 0; stack_frame =3D stack_frame->ebp)
-    {
-        kprintf("ebp %08x eip %08x", stack_frame->ebp, stack_frame->eip);
-
-        if((sym =3D 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);
     }
 }
=20
-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 =3D strstr(cmdline, "debug=3D");
     debug_flags =3D 0;
=20
     if(pos =3D=3D NULL) return;
-   =20
+
     //Debug=3D ueberspringen
     pos +=3D 6;
     while((*pos !=3D 0) && (*pos !=3D ' '))
@@ -207,57 +98,8 @@ void debug_parse_cmdline(char* cmdline)
             case 'c':
                 debug_flags |=3D DEBUG_FLAG_SYSCALL;
                 break;
-
-            case 'n':
-                debug_flags |=3D DEBUG_FLAG_NO_KCONSOLE;
-                break;
         }
         pos++;
     }
 }
=20
-///Ueberprueft ob ein bestimmtes Debug-Flag gesetzt ist
-bool debug_test_flag(uint32_t flag)
-{
-    return ((debug_flags & flag) !=3D 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 =3D first_task;
-    struct int_stack_frame* isf;
-
-    while (task !=3D NULL)
-    {
-        kprintf("\n\nPID %d: %s\n"
-            "Status %d, blocked_by_pid %d, blocked_count %d\n",
-            task->pid,=20
-
-            (task =3D=3D 0=20
-                ? "Kernel-Initialisierung"
-                : (task->cmdline !=3D NULL=20
-                    ? task->cmdline=20
-                    : "Unbekannter Task")),
-
-            task->status, task->blocked_by_pid, task->blocked_count);
-       =20
-        __asm("mov %0, %%cr3" : : "r"(resolve_vaddr(kernel_page_directory,=
 task->cr3)));
-       =20
-        isf =3D (struct int_stack_frame*) task->esp;
-        stack_backtrace_ebp(isf->ebp, isf->eip);
-
-        task =3D task->next_task;
-    }
-       =20
-    __asm("mov %0, %%cr3" : : "r"(resolve_vaddr(kernel_page_directory, cur=
rent_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 softwar=
e
- *    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 I=
S''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE tyndur PROJECT OR CONTRI=
BUTORS
- * 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 BUSINES=
S
- * 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=EF=BF=BDufige 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=EF=BF=BDr Ring 0 und Ring 3 und einem Deskriptor f=EF=
=BF=BDr die TSS.
- * Anschlie=EF=BF=BDend 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 =3D {
-    .size  =3D GDT_SIZE*8 - 1,
-    .base  =3D (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=EF=BF=BD=EF=BF=BDe 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   =3D size & 0xFFFF;
-  gdt[segment].size2  =3D ((size >> 16) & 0x0F) | 0xC0;
-  gdt[segment].base   =3D base & 0xFFFF;
-  gdt[segment].base2  =3D (base >> 16) & 0xFF;
-  gdt[segment].base3  =3D ((base >> 24) & 0xFF);
-  gdt[segment].access =3D access | ((dpl & 3) << 5);
-}
-
-/**
- * Setzt einen Deskriptor in der GDT, wobei die Gr=EF=BF=BD=EF=BF=BDe als =
Byteangabe
- * interpretiert wird.
- *
- * \param segment Nummer des Deskriptors
- * \param size Gr=EF=BF=BD=EF=BF=BDe 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  =3D ((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 LIMI=
TED
-; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICUL=
AR
-; 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 PROFI=
TS;
-; 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=EF=
=BF=BDr die R=EF=BF=BDcksprungadresse und den alten Stack Frame erstellen
-	push 0
-	push 0
-	mov ebp, esp
-
-	; Die vom Multiboot Loader =EF=BF=BDbergebenen Informationen auf den Stac=
k legen (init ben=EF=BF=BDtigt 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.
  */ =20
=20
- /**=20
-  * Kernel-Initialisierung erfolgt hier,
-  * die Funktion init wird von header.asm aufgerufen=20
-  */
-
+#include <string.h>
+#include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
+#include <lost/config.h>
+#include <lock.h>
=20
-#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"
=20
 struct multiboot_info multiboot_info;
=20
-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 =3D {
+    .cmdline =3D "(Kernel)",
+};
+
+lock_t init_lock =3D 0;
=20
-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 =C3=BCbergibt 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 =3D true;
+
+    p =3D strtok(cmdline, " ");
+
+    while (p) {
+        if (!strncmp(p, "debug=3D", 6)) {
+            debug_parse_cmdline(p);
+        } else if (!strcmp(p, "smp")) {
+            enable_smp =3D true;
+        } else if (kernel_name) {
+            kernel_name =3D false;
+        } else {
+            kprintf("Unbekannte Option: '%s'\n", p);
+        }
+
+        p =3D strtok(NULL, " ");
+    }
 }
=20
-void init(int multiboot_magic, struct multiboot_info *boot_info)
+/**
+ * Kernel-Initialisierung erfolgt hier,
+ * die Funktion init wird von header.asm aufgerufen (BSP =3D true) oder au=
s
+ * 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 =3D LOCK_LOCKED;;
+    // Diese ersten Initialisierungen muessen nur einmal, und ganz am Anfa=
ng
+    // gemacht werden.
+    if (bsp =3D=3D true) {
+        init_console();
=20
-    memcpy(&multiboot_info, boot_info, sizeof(struct multiboot_info));
+        // Multiboot-Infos sichern
+        memcpy(&multiboot_info, boot_info, sizeof(struct multiboot_info));
=20
-   =20
-    //Debugparameter verarbeiten
-    if((multiboot_info.mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) !=3D 0)
-    {
-        debug_parse_cmdline(multiboot_info.mi_cmdline);
+        // Hiermit wird eine Laufende Multitasking-Umgebung simuliert. Die=
s ist
+        // notwendig, damit im restlichen Code keine Aenderungen notwendig=
 sind
+        // fuer die Initialisierung.
+        init_thread =3D (pm_thread_t) {
+            .process                =3D &init_process,
+            .kernel_stack_bottom    =3D (vaddr_t) &kernelstack_bottom,
+            .kernel_stack_size      =3D (uint8_t*) &kernelstack
+                                    - (uint8_t*) &kernelstack_bottom,
+        };
+
+        cpu_get(0)->thread =3D &init_thread;
+
+        // Debugparameter verarbeiten, das ist aber nur moeglich, wenn ein=
e
+        // Kernelkommandozeile existiert.
+        if ((multiboot_info.mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) !=3D 0)=
 {
+            parse_cmdline((char*)(uintptr_t)multiboot_info.mi_cmdline);
+        }
+
+#if CONFIG_ARCH =3D=3D 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 Speiche=
r
+        // 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 d=
er
+        // Initialisierung fortfahren duerfen.
+        unlock(&init_lock);
+    } else {
+        lock_wait(&init_lock);
+
+        // APIC initialisieren. Dies ist beim BSP bereits erledigt.
+        apic_init();
     }
-   =20
-    save_bios_data();
-   =20
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere physikalische Speicherverw=
altung");
-    init_phys_mem(multiboot_info.mi_mmap_addr, multiboot_info.mi_mmap_leng=
th, 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();
-   =20
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere GDT");
-    init_gdt();
-   =20
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere Kernel Stack-Backtraces");
-    init_stack_backtrace();
-   =20
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere IDT");
-    init_idt();
-
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere Scheduler");
-    init_scheduler();
-   =20
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere Timer");
-    timer_init();
-   =20
-    debug_print(DEBUG_FLAG_INIT, "Initialisiere IO-Ports");
-    init_io_ports();
-   =20
-   =20
-    //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 I=
nit-Modul");
-    load_multiboot_modules(&multiboot_info);
-
-    request_irq(1, &keyboard_handler);
-
-   =20
-    debug_print(DEBUG_FLAG_INIT, "Aktiviere Interrupts");
-    enable_interrupts();
-
-    // An dieser Stelle sofort einen Interrupt auszuf=EF=BF=BDhren, ist au=
s zwei=20
-    // Gr=EF=BF=BDnden notwendig:
-    //
-    // 1. Kooperatives Multitasking startet sonst nicht
-    // 2. current_task sollte m=EF=BF=BDglichst schnell initialisiert werd=
en, da
-    //    es nur an wenigen Stellen auf NULL =EF=BF=BDberpr=EF=BF=BDft wir=
d
-    asm volatile ("int $0x20");  =20
-   =20
-    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 ei=
nen "
+        "Prozessor");
+    gdt_init_local();
+    im_init_local();
+
+
+    // Auf dem BSP muss die ganze virtuelle Speicherverwaltung initialisie=
rt
+    // werden. Bei den APs reicht es, wenn sie ihren Stack mappen.
+    static volatile lock_t mm_prepare_lock =3D LOCK_LOCKED;
+    cpu_get_current()->thread =3D &init_thread;
+    if (bsp =3D=3D true) {
+        *init_context =3D 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 =3D=3D ARCH_AMD64
+            asm volatile("movq %%rsp, %0" : "=3Dr"(sp));
+        #else
+            asm volatile("movl %%esp, %0" : "=3Dr"(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);
     }
-}
=20
-extern void stack_backtrace(void);
+
+    // Warten, bis alle CPUs hier angekommen sind.
+    // TODO: Timeout?
+    static volatile uint32_t cpus_arrived =3D 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 sin=
d,
+    // sonst rennen wir hier in Exceptions.
+    // TODO: Buildscripts fixen?
+    uint32_t edx =3D 0, dummy =3D 0;
+    asm volatile("cpuid": "=3Dd" (edx), "=3Da" (dummy) : "a" (1) : "ebx", =
"ecx");
+    if ((edx & (1 << 24)) && (edx & (1 << 25))) {
+        #if CONFIG_ARCH =3D=3D 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 =3D 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, wen=
n
+    // mapping-Funktionen aufgerufen werden. Darum muss alles gemappt sein=
,
+    // bevor vmm_init aufgerufen wird.
+    if (bsp =3D=3D 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 C=
PUs
+    // und gibt den endgueltigen Startschuss.
+    static volatile uint32_t final_cpus_arrived =3D 0;
+    static volatile lock_t final_lock =3D LOCK_LOCKED;
+    locked_increment(&final_cpus_arrived);
+
+    if (bsp =3D=3D 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 =3D pm_scheduler_pop();
+    interrupt_stack_frame_t* isf =3D im_prepare_current_thread();
+    asm volatile("jmp im_run_thread" :: "a" (isf));
+
+    // Hier kommen wir nie hin
+}
=20
 __attribute__((noreturn)) void panic(char * message, ...)
 {
-    int * args =3D ((int*)&message) + 1;
-    disable_interrupts();
+    __asm__ __volatile__("cli");
+    va_list args;
+    va_start(args,message);
+
+    // XXX disable_interrupts();
=20
     kprintf("\n"
       "\033[1;37m\033[41m" // weiss auf rot
       "PANIC: ");
-    kaprintf(message, &args);
+    kaprintf(message, args);
     kprintf("\n");
=20
+    // FIXME
+    #undef CONFIG_DEBUG_LAST_SYSCALL
     #ifdef CONFIG_DEBUG_LAST_SYSCALL
     {
         uint32_t i;
=20
-        kprintf("Letzter Syscall (von PID %d): %d ", debug_last_syscall_pi=
d,
-            debug_last_syscall_no);
+        kprintf("Letzter Syscall: %d ", debug_last_syscall_no);
         for (i =3D 0; i < DEBUG_LAST_SYSCALL_DATA_SIZE; i++) {
             kprintf("0x%08x ", debug_last_syscall_data[i]);
         }
         kprintf("\n");
     }
-    #endif=20
+    #endif
+
+    stack_backtrace(0, 0);
+
+    kprintf("\033[0;37m\033[40m");
=20
-    stack_backtrace();
=20
     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/p=
ic.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 @@
-/* =20
- * 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 softwar=
e
- *    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=20
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */ =20
-
-/*
- * 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] =3D { 0 };
-
-static struct task * intr_handling_task[256][MAX_INTERRUPTS] =3D { { 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 =3D (struct int_stack_frame *)esp;
-    struct task* old_task =3D current_task;
-
-//	kprintf("\nTask switch!  esp alter Task:0x%08x", isf->esp);
-=09
-	if(isf->interrupt_number <=3D 31)
-    {
-        handle_exception(&esp);
-    }
-    else if(isf->interrupt_number <=3D 47)
-    {
-        // Ein IRQ
-        handle_irq(isf->interrupt_number - IRQ_BASE, &esp);
-		isf =3D (struct int_stack_frame *)esp;
-    }
-    else if(isf->interrupt_number =3D=3D 48)
-    {
-        // Ein Syscall
-        syscall((struct int_stack_frame **) &esp);
-    }
-    else
-    {
-        // TODO: Abstuerzen, denn diese Interrupts duerften nicht aufgeruf=
en werden
-    }
-
-    send_irqs(&esp);
-    //current_task =3D schedule();
-
-   // for(;;);
-
-    if ((current_task !=3D NULL) && (old_task !=3D current_task)) {
-        //tss.esp =3D current_task->kernel_stack;
-        isf =3D (struct int_stack_frame *)esp;
-        //kprintf("  esp neuer Task:0x%08x", isf->esp);
-
-        tss.esp0 =3D current_task->kernel_stack;
-        // sicherstellen, dass der Kernel Adressraum im Page Directory des=
 Tasks korrekt gemappt ist
-        //kprintf("PID=3D%d  cr3=3D0x%08x  kernel_pd=3D0x%08x eip=3D0x%08x=
\n",=20
-        //  current_task->pid, current_task->cr3, (uint32_t)kernel_page_di=
rectory, isf->eip);
-        //memcpy((void*)current_task->cr3, kernel_page_directory, 1024);
-
-        // Aktuelles Kernel-PD kopieren, wenn noetig
-        if (kernel_pd_id !=3D current_task->pd_id) {
-            memcpy((void*) current_task->cr3, kernel_page_directory, 1020)=
;
-            current_task->pd_id =3D 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 =3D=3D TS_WAIT_FOR_RPC)) {
-        current_task->status =3D TS_RUNNING;
-    }
-
-    //kprintf("int_handler: return %08x\n", esp);
-    //kprintf("int_handler: eip=3D%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 =3D 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 =3D {
-    .size  =3D IDT_SIZE*8 - 1,
-    .base  =3D (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 typ=
e)
-{
-  idt[intr].lsb_handler =3D ((uint32_t) handler) & 0xFFFF;
-  idt[intr].msb_handler =3D (((uint32_t) handler) >> 16) & 0xFFFF;
-  idt[intr].access =3D IDT_DESC_PRESENT | ((dpl & 3) << 5) | type;
-  idt[intr].selector =3D selector;
-  idt[intr].reserved =3D 0;
-}
-
-int request_irq(int irq, void * handler)
-{
-    if(irq < 0 || irq > 15)
-    {
-        return 1;
-    }
-
-    if(irq_handlers[irq] !=3D 0)
-    {
-        return 1;
-    }
-
-    irq_handlers[irq] =3D handler;
-
-    return 0;
-}
-
-int release_irq(int irq)
-{
-    if(irq < 0 || irq > 15)
-    {
-        return 1;
-    }
-
-    irq_handlers[irq] =3D 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 =3D (irq < 8 ? PIC1 : PIC2);
-        outb(pic + 3, 0x03);
-        if ((inb(pic) & (1 << (irq % 8))) =3D=3D 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=
=20
-    // ist, ansonsten gleich wieder abbrechen.
-    if ((irq =3D=3D 7) || (irq =3D=3D 15))
-    {
-        uint8_t pic =3D (irq < 8 ? PIC1 : PIC2);
-
-        outb(pic, 0x0B);
-        if ((inb(pic) & 0x80) =3D=3D 0) {
-            kprintf("Spurious IRQ %d\n", irq);
-
-            // TODO Eigentlich sollte man hier keinen EOI brauchen, aber q=
emu
-            // scheint ihn zu brauchen
-            goto send_eoi;
-        }
-    }
-
-    for (i =3D 0; i < MAX_INTERRUPTS; i++) {
-        if (intr_handling_task[irq + IRQ_BASE][i] !=3D NULL) {
-            i =3D -1;
-            break;
-        }
-    }
-    if (i =3D=3D -1)
-    {
-        //kprintf("IRQ-Verarbeitung durch ein Modul\n");
-        for (i =3D 0; i < MAX_INTERRUPTS; i++) {
-            if (intr_handling_task[irq + IRQ_BASE][i] !=3D NULL) {
-                irqs_to_send[irq][i]++;
-            }
-        }
-
-        //printf("disable IRQ %d\n", irq);
-        disable_irq(irq);
-    }=20
-    else if (irq_handlers[irq] !=3D 0)
-    {
-        irq_handlers[irq](irq, esp);
-    }
-
-send_eoi:
-    if(irq >=3D 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, tas=
k->pid);
-    for (i =3D 0; i < MAX_INTERRUPTS; i++) {
-        if ((intr_handling_task[intr][i] =3D=3D NULL) ||
-            (i =3D=3D MAX_INTERRUPTS - 1))
-        {
-            intr_handling_task[intr][i] =3D task;
-            if (intr >=3D IRQ_BASE && intr < IRQ_BASE + 16) {
-                irqs_to_send[intr - IRQ_BASE][i] =3D 0;
-            }
-            break;
-        }
-    }
-}
-
-void remove_intr_handling_task(struct task* task)
-{
-    int i, intr;
-
-    for (intr =3D 0; intr < 256; intr++) {
-        for (i =3D 0; i < MAX_INTERRUPTS; i++) {
-            if (intr_handling_task[intr][i] =3D=3D task) {
-                intr_handling_task[intr][i] =3D NULL;
-            }
-        }
-    }
-}
-
-void handle_exception(uint32_t* esp)
-{
-    struct int_stack_frame * isf =3D *((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 versuch=
en.
-            if (tss.io_bit_map_offset =3D=3D TSS_IO_BITMAP_NOT_LOADED) {
-                set_io_bitmap();
-                return;
-            }
-            break;
-
-        case 14:
-            cr2 =3D read_cr2();
-            diff =3D (cr2 >> PAGE_SHIFT) - (isf->esp >> PAGE_SHIFT);
-            // Ueberpruefen ob der Pagefault durch einen Stackoverflow
-            // hervorgerufen wurde
-            if ((diff >=3D -2) && (diff <=3D 2)
-                && (current_task !=3D NULL)
-                && ((void*)cr2 >=3D current_task->user_stack_bottom - 0x10=
00000))
-            {
-                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 re=
agieren
-    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 n=
ur
-    // den schuldigen Task beenden.
-    if (((isf->cs & 0x03) =3D=3D 0) && !(isf->eflags & 0x20000)) {
-        kprintf("\n");
-        kprintf("\033[1;37m\033[41m"); // weiss auf rot
-        kprintf("Es wurde ein Problem festgestellt. tyndur wurde herunterg=
efahren, damit der\n"
-                "Computer nicht beschaedigt wird.\n"
-                "\n"
-                "Exception #%02d, int: #%d @ 0x%04x:0x%08x, PID %d, %s\n",=
=20
-                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=3D 0x%04x:0x%08x error code: 0x%08x\n", isf->ss, i=
sf->esp, isf->error_code);
-        kprintf("eax:0x%08x, ebx:0x%08x, ecx:0x%08x, edx:0x%08x\n", isf->e=
ax, isf->ebx, isf->ecx, isf->edx);
-        kprintf("ebp:0x%08x, esp:0x%08x, esi:0x%08x, edi:0x%08x\n", isf->e=
bp, 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 =3D 0; i < DEBUG_LAST_SYSCALL_DATA_SIZE; i++) {
-                kprintf("0x%08x ", debug_last_syscall_data[i]);
-            }
-            kprintf("\n");
-        }
-        #endif=20
-
-        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=3D 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",
-           =20
-            (current_task =3D=3D 0=20
-                ? "Kernel-Initialisierung"
-                : (current_task->cmdline !=3D NULL=20
-                    ? current_task->cmdline=20
-                    : "Unbekannter Task")),
-
-            isf->interrupt_number, isf->interrupt_number, isf->cs, isf->ei=
p,=20
-            current_task ? current_task->pid : 0,
-            isf->ss, isf->esp, isf->error_code,=20
-            isf->eax, isf->ebx, isf->ecx, isf->edx,=20
-            isf->ebp, isf->esp, isf->esi, isf->edi,=20
-            isf->eflags, isf->ds, isf->es, isf->fs, isf->gs
-        );
-
-        abort_task("Unbehandelte Ausnahme.");
-    }
-}
-
-void send_irqs(uint32_t* esp)=20
-{
-    uint32_t irq;
-    int task;
-
-    for (irq =3D 0; irq < 16; irq++)
-    {
-        uint32_t rpc_data =3D irq + IRQ_BASE;
-        for (task =3D 0; task < MAX_INTERRUPTS; task++) {
-            if (intr_handling_task[irq + IRQ_BASE][task] =3D=3D 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 =3D 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 @@
-/* =20
- * 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 softwar=
e
- *    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=20
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */ =20
-
-#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] =3D { 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=EF=BF=BDr einen Task
- *
- * @param task Task, dem der Port zugeordnet werden soll
- * @param port Nummer des zuzuordnenden IO-Ports
- *
- * @return Gibt true zur=EF=BF=BDck, wenn der Task auf den Port zugreifen =
kann
- * (erfolgreiche oder bereits vorhandene Reservierung f=EF=BF=BDr denselbe=
n Task),
- * ansonsten false.
- */
-static bool io_port_request(struct task* task, uint32_t port)
-{
-    uint32_t index =3D port / 8;
-    uint8_t bit =3D 1 << (port % 8);
-    uint8_t* io_bitmap =3D task->io_bitmap;
-
-    // Pr=EF=BF=BDfen, ob der Port =EF=BF=BDberhaupt von der Bitmap abgede=
ckt wird
-    if (port >=3D IO_BITMAP_LENGTH) {
-        return false;
-    }
-
-    // Ist der Port noch frei?
-    // Wenn der Port f=EF=BF=BDr denselben Task schon einmal reserviert wu=
rde,
-    // abbrechen, aber true zur=EF=BF=BDckgeben
-    if (global_port_bitmap[index] & bit) {
-        return (io_bitmap && ((io_bitmap[index] & bit) =3D=3D 0));
-    }
-
-    // Falls der Task noch keine zugeordnete Bitmap hat, wird es jetzt
-    // Zeit, eine anzulegen
-    if (io_bitmap =3D=3D NULL) {
-        io_bitmap =3D task->io_bitmap =3D malloc(IO_BITMAP_LENGTH / 8);
-        memset(io_bitmap, 0xFF, IO_BITMAP_LENGTH / 8);
-    }
-
-    // Die eigentliche Reservierung
-    global_port_bitmap[index] |=3D bit;
-    io_bitmap[index] &=3D ~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=EF=BF=BDr den Task reserviert war.
- */
-static bool io_port_release(struct task* task, uint32_t port)
-{
-    uint32_t index =3D port / 8;
-    uint8_t bit =3D 1 << (port % 8);
-    uint8_t* io_bitmap =3D task->io_bitmap;
-
-    // Wenn der Port gar nicht f=EF=BF=BDr den Task reserviert ist, false =
zur=EF=BF=BDckgeben
-    if ((!io_bitmap) || (io_bitmap[index] & bit)) {
-        return false;
-    }
-
-    // Wenn der Port zwar f=EF=BF=BDr den Task reserviert ist, aber in der=
 globalen
-    // Tabelle als frei markiert, haben wir einen Kernel-Bug.
-    if ((global_port_bitmap[index] & bit) =3D=3D 0) {
-        panic("IO-Port-Bitmaps sind beschaedigt (Port %d, PID %d)", port, =
task->pid);
-    }
-   =20
-    // Die eigentliche Freigabe
-    global_port_bitmap[index] &=3D ~bit;
-    io_bitmap[index] |=3D bit;
-
-    return true;
-}
-
-/**
- * Reserviert einen Bereich von IO-Ports f=EF=BF=BDr einen Task.
- * Es werden entweder alle angeforderten oder im Fehlerfall gar keine Port=
s=20
- * reserviert. Eine teilweise Reservierung tritt nicht auf.
- *
- * @param task Task, f=EF=BF=BDr 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 =3D length;
-    while (n--)=20
-    {
-        if (!io_port_request(task, port++))=20
-        {
-            // Bereits reservierte Ports wieder freigeben
-            while (++n !=3D 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=EF=BF=BDr den Task reservi=
ert),
- * wird false zur=EF=BF=BDckgegeben, die Bearbeitung allerdings nicht abge=
brochen,
- * sondern die weiteren Ports versucht freizugeben.
- */
-bool io_ports_release(struct task* task, uint32_t port, uint32_t length)
-{
-    bool success =3D true;
-
-    while (length--)=20
-    {
-        if (!io_port_release(task, port++)) {
-            success =3D 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 =3D task->io_bitmap;
-
-    if (io_bitmap =3D=3D NULL) {
-        return;
-    }
-
-    for (i =3D 0; i < IO_BITMAP_LENGTH / 8; i++)
-    {
-        if (io_bitmap[i] !=3D (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 =3D task->io_bitmap;
-    uint8_t bit;
-
-    if (io_bitmap =3D=3D NULL) {
-        return;
-    }
-
-    for (i =3D 0; i < IO_BITMAP_LENGTH / 8; i++) {
-        for (j =3D 0; j < 8; j++) {
-            bit =3D 1 << j;
-            if (((io_bitmap[i] & bit) =3D=3D 0) && ((global_port_bitmap[i]=
 & bit)
-                =3D=3D 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 =3D 0x100000;=0D
-LINK_ADDR =3D 0x100000;=0D
-VIRT_TO_PHYS =3D LINK_ADDR - LOAD_ADDR;=0D
-=0D
-ENTRY(_start)=0D
-SECTIONS=0D
-{=0D
-	. =3D LINK_ADDR;=0D
-=0D
-	kernel_start =3D .;=0D
-	kernel_phys_start =3D . - VIRT_TO_PHYS;=0D
-=0D
-	.text : AT(ADDR(.text) - VIRT_TO_PHYS)=0D
-	{=0D
-        *(multiboot)=0D
-		*(.text)=0D
-	}=0D
-	.rodata ALIGN(4096) : AT(ADDR(.rodata) - VIRT_TO_PHYS)=0D
-	{=0D
-		*(.rodata)=0D
-	}=0D
-	.data ALIGN(4096) : AT(ADDR(.data) - VIRT_TO_PHYS)=0D
-	{=0D
-		*(.data)=0D
-	}=0D
-	.bss ALIGN(4096) : AT(ADDR(.bss) - VIRT_TO_PHYS)=0D
-	{=0D
-		*(.bss)=0D
-	}=0D
-=0D
-	. =3D ALIGN(4096);=0D
-=0D
-	kernel_end =3D .;=0D
-	kernel_phys_end =3D . - VIRT_TO_PHYS;=0D
-=0D
-	kernel_size =3D kernel_end - kernel_start;=0D
-}=0D
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.
  */
 =20
+#include <stdint.h>
+#include <stddef.h>
+#include <lost/config.h>
+
+#include "kprintf.h"
 #include "console.h"
+#include "lock.h"
+
+
+static lock_t printf_lock;
=20
 /* Dividiert ein uint64 durch einen uint32 und gibt das Ergebnis zur=EF=BF=
=BDck */
 unsigned long long divmod(unsigned long long dividend, unsigned int diviso=
r, unsigned int * remainder)
 {
+#if CONFIG_ARCH =3D=3D ARCH_AMD64
+    if (remainder) {
+        *remainder =3D dividend % divisor;
+    }
+    return dividend / divisor;
+#else
     unsigned int highword =3D dividend >> 32;
     unsigned int lowword =3D dividend & 0xffffffff;
     unsigned long long quotient;
     unsigned int rem;
-
+   =20
     __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)
         );
=20
-    if(remainder)
-    {
+    if (remainder) {
         *remainder =3D rem;
     }
=20
     return quotient;
+#endif
 }
=20
 /* Gibt eine unsigned 64-bit Zahl mit beliebiger Basis zwischen 2 und 36 a=
us */
-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 padch=
ar)
 {
     char b[65];
     char * r =3D 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)
 }
=20
 /* Hilfsfunktion f=EF=BF=BDr kprintf() */
-void kaprintf(const char * format, int ** args)
+void kaprintf(char* format, va_list args)
 {
     int pad;
     char padfill;
-    signed long long value =3D 0;
+    unsigned long long value =3D 0;
=20
     while(*format)
     {
@@ -119,27 +134,57 @@ void kaprintf(const char * format, int ** args)
                 pad =3D pad * 10 + *format++ - '0';
             }
=20
-            if(format[0] =3D=3D 'l' && format[1] =3D=3D 'l' && (format[2] =
=3D=3D 'd' || format[2] =3D=3D 'i' || format[2] =3D=3D 'o' || format[2] =3D=
=3D 'u' || format[2] =3D=3D 'x'))
+            if(format[0] =3D=3D 'l' && format[1] =3D=3D 'l' && (format[2] =
=3D=3D 'd' || format[2] =3D=3D 'i'))
             {
-                value =3D *(unsigned long long*)(*args);
-                *args +=3D 2;
-
+                signed long long tmp =3D va_arg(args, long long int);
+                if (tmp < 0) {
+                    con_putc_ansi('-');
+                    pad--;
+                    value =3D -tmp;
+                } else {
+                    value =3D tmp;
+                }
+                format +=3D 2;
+            }
+            else if(format[0] =3D=3D 'l' && format[1] =3D=3D 'l' && (forma=
t[2] =3D=3D 'o' || format[2] =3D=3D 'u' || format[2] =3D=3D 'x'))
+            {
+                value =3D va_arg(args, unsigned long long int);
                 format +=3D 2;
             }
-            else if(format[0] =3D=3D 'd' || format[0] =3D=3D 'u')
+            else if(format[0] =3D=3D 'l' && (format[1] =3D=3D 'd' || forma=
t[1] =3D=3D 'i'))
             {
-                value =3D *(*args)++;
-                if(value < 0)
-                {
+                signed long int tmp =3D va_arg(args, long int);
+                if(tmp < 0) {
                     con_putc_ansi('-');
                     pad--;
-                    value =3D -value;
+                    value =3D -tmp;
+                } else {
+                    value =3D tmp;
                 }
+                format++;
+            } else if(format[0] =3D=3D 'z' && (format[1] =3D=3D 'u' || for=
mat[1] =3D=3D 'x')) {
+                value =3D va_arg(args, size_t);
+                format++;
             }
-            else if(format[0] =3D=3D 'i' || format[0] =3D=3D 'o' || format=
[0] =3D=3D 'p' || format[0] =3D=3D 'x')
+            else if(format[0] =3D=3D 'l' && (format[1] =3D=3D 'o' || forma=
t[1] =3D=3D 'u' || format[1] =3D=3D 'x'))
             {
-                value =3D *(*args)++;
-                value =3D value & 0xffffffff;
+                value =3D va_arg(args, unsigned long int);
+                format++;
+            }
+            else if(format[0] =3D=3D 'd' || format[0] =3D=3D 'i')
+            {
+                int tmp =3D va_arg(args, int);
+                if(tmp < 0) {
+                    con_putc_ansi('-');
+                    pad--;
+                    value =3D -tmp;
+                } else {
+                    value =3D tmp;
+                }
+            } else if(format[0] =3D=3D 'u' || format[0] =3D=3D 'o' || form=
at[0] =3D=3D 'x') {
+                value =3D va_arg(args, unsigned int);
+            } else if(format[0] =3D=3D 'p') {
+                value =3D va_arg(args, uintptr_t);
             }
=20
             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)
 }
=20
 /* printf f=C3=BCr den Kernel. Nur f=C3=BCr Testzwecke gedacht.
- Unterst=C3=BCtzt %c, %d, %i, %o, %p, %u, %s, %x und %lld, %lli, %llo, %ll=
u, %llx. */
-void kprintf(char * format, ...)
+ Unterst=C3=BCtzt %c, %d, %i, %o, %p, %u, %s, %x und %lld, %lli, %llo, %ll=
u, %llx, %zu, %zx. */
+void kprintf(char* format, ...)
 {
-    int * args =3D ((int*)&format) + 1;
-    kaprintf(format, &args);
+    lock(&printf_lock);
+   =20
+    va_list args;
+   =20
+    va_start(args,format);
+    kaprintf(format, args);
+    va_end(args);
+
+    unlock(&printf_lock);
 }
=20
-int printf(const char * format, ...)
+int printf(const char* format, ...)
 {
-    int * args =3D ((int*)&format) + 1;
-    kaprintf(format, &args);
-
+    lock(&printf_lock);
+   =20
+    va_list args;
+    va_start(args,format);
+    kaprintf((char*) format, args);
+    va_end(args);
+   =20
+    unlock(&printf_lock);
     return 0; // TODO Korrekte printf-R=EF=BF=BDckgabe
 }
=20
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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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/l=
ostio/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/m=
odules/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/use=
rspace.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.al=
l
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 @@
-/*=0D
- * Copyright (c) 2006 The tyndur Project. All rights reserved.=0D
- *=0D
- * This code is derived from software contributed to the tyndur Project=0D
- * by Burkhard Weseloh.=0D
- *=0D
- * Redistribution and use in source and binary forms, with or without=0D
- * modification, are permitted provided that the following conditions=0D
- * are met:=0D
- * 1. Redistributions of source code must retain the above copyright=0D
- *    notice, this list of conditions and the following disclaimer.=0D
- * 2. Redistributions in binary form must reproduce the above copyright=0D
- *    notice, this list of conditions and the following disclaimer in the=
=0D
- *    documentation and/or other materials provided with the distribution.=
=0D
- * 3. All advertising materials mentioning features or use of this softwar=
e=0D
- *    must display the following acknowledgement:=0D
- *     This product includes software developed by the tyndur Project=0D
- *     and its contributors.=0D
- * 4. Neither the name of the tyndur Project nor the names of its=0D
- *    contributors may be used to endorse or promote products derived=0D
- *    from this software without specific prior written permission.=0D
- *=0D
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=0D
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED=0D
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR=0D
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=0D
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=
=0D
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=0D
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=0D
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=0D
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=0D
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=0D
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0D
- */=0D
-=0D
-#include "kernel.h"=0D
-#include "paging.h"=0D
-#include "string.h"=0D
-#include "types.h"=0D
-=0D
-=0D
-/**=0D
- * Mappt Speicher 1:1 in den Kernel Adressraum. Kein page alignment erford=
erlich.=0D
- */=0D
-bool kernel_identity_map(paddr_t paddr, uint32_t bytes)=0D
-{=0D
-    uint32_t aligned_addr =3D (uint32_t)paddr - ((uint32_t)paddr & ~PAGE_M=
ASK);=0D
-    uint32_t aligned_bytes =3D bytes + (uint32_t)paddr -=0D
-        ((uint32_t)paddr & PAGE_MASK);=0D
-=0D
-    return map_page_range(kernel_page_directory, (vaddr_t)aligned_addr, (p=
addr_t)aligned_addr, PTE_W | PTE_P /*| PTE_U*/, NUM_PAGES(aligned_bytes));=
=0D
-}=0D
-=0D
-// Der Teil des Page Directorys, der den Kernelraum mappt und f=EF=BF=BDr =
alle Prozesse gleich ist=0D
-#define kernel_page_tables \=0D
-    ((uint32_t*)(kernel_page_directory + (KERNEL_BASE >> PGDIR_SHIFT)))=0D
-extern page_directory_t kernel_page_directory;=0D
-extern uint32_t kernel_pd_id;=0D
-=0D
-/**=0D
- * Errechnet die virtuelle Adresse der Page Table, die zur Adresse addr ge=
h=EF=BF=BDrt.=0D
- */=0D
-static page_table_t get_kernel_page_table_addr(uint32_t addr)=0D
-{=0D
-    if(addr < KERNEL_BASE)=0D
-    {=0D
-        /* TODO: Ein panic mit (einem noch zu schreibenden) BUG()-Makro k=
=EF=BF=BDnnte hier angebrachter sein */=0D
-        panic("addr(%x) < KERNEL_BASE", addr);=0D
-    }=0D
-=0D
-    return (page_table_t)(KERNEL_PAGE_TABLES_VADDR + (((addr - KERNEL_BASE=
) >> PGDIR_SHIFT) << PAGE_SHIFT));=0D
-}=0D
-=0D
-/**=0D
- * Mappt eine Page Table in die Kernel Page Tables=0D
- *=0D
- * @param pgdir_index Index in das Page Directory. Die 4 MB an der virtuel=
len=0D
- *    Adresse (pgdir_index << PGDIR_SHIFT) werden von dieser Page Table ge=
mappt.=0D
- * @param addr Physische Adresse der Page Table, die gemappt werden soll=
=0D
- */=0D
-static void map_kernel_page_table(int pgdir_index, uint32_t addr)=0D
-{=0D
-    // Da alle Page Tables mit (pgdir_index << PGDIR_SHIFT) >=3D KERNEL_BA=
SE in=0D
-    // die Gegend nach KERNEL_PAGE_TABLES_VADDR gemappt werden, m=EF=BF=BD=
ssen wir die=0D
-    // dazugeh=EF=BF=BDrige Page Table finden.=0D
-    page_table_t page_table =3D get_kernel_page_table_addr(KERNEL_PAGE_TAB=
LES_VADDR);=0D
-=0D
-    // Jede Page Table ist genau 4KB gro=EF=BF=BD, also wird sie mit genau=
 einem Eintrag=0D
-    // in der Page Table der Kernel Page Tables gemappt.=0D
-    page_table[pgdir_index] =3D (addr & PAGE_MASK) | PTE_W | PTE_P;=0D
-=0D
-    asm volatile("invlpg %0" : : "m" (*page_table));=0D
-}=0D
-=0D
-/**=0D
- * Wandelt eine virtuelle Adresse >=3D KERNEL_BASE in eine physische=0D
- * Adresse um.=0D
- */=0D
-/*static*/ paddr_t kernel_virt_to_phys(uint32_t vaddr)=0D
-{=0D
-    // Die Page Table f=EF=BF=BDr diese virtuelle Adresse ermitteln ...=0D
-    page_table_t page_table =3D get_kernel_page_table_addr(vaddr);=0D
-=0D
-    // ... und auslesen.=0D
-    return (paddr_t)(page_table[(vaddr >> PAGE_SHIFT) & 0x3ff] & PAGE_MASK=
);=0D
-}=0D
-=0D
-/**=0D
- * Gibt eine Seite (4 KBytes) im Kernel-Adressraum frei.=0D
- */=0D
-void free_kernel_page(vaddr_t page)=0D
-{=0D
-    uint32_t addr =3D (uint32_t)page;=0D
-    page_table_t page_table;=0D
-    =0D
-    if(addr < KERNEL_BASE)=0D
-    {=0D
-        /* TODO: Ein panic mit (einem noch zu schreibenden) BUG()-Makro k=
=EF=BF=BDnnte hier angebrachter sein */=0D
-        panic("Es wurde versucht eine Seite ausserhalb des Kernelraums fre=
izugeben.");=0D
-    }=0D
-=0D
-    // Die physische Seite vor der virtuellen freigeben, weil sonst kernel=
_virt_to_phys() nicht mehr funktioniert.=0D
-    phys_free_page(kernel_virt_to_phys(addr));=0D
-=0D
-    // Das Mapping aufheben, und die virtuelle Seite somit freigeben.=0D
-    page_table =3D get_kernel_page_table_addr(addr);=0D
-    page_table[(addr >> PAGE_SHIFT) & 0x3ff] =3D 0;=0D
-}=0D
-=0D
-/**=0D
- * Findet einen freien Bereich mit num freien Seiten im Kernel-Adressraum.=
=0D
- *=0D
- * @return Die erste Seite dieses Bereiches=0D
- */=0D
-vaddr_t find_contiguous_kernel_pages(int num)=0D
-{=0D
-    int i, j;=0D
-    int pgdir_index, pgtbl_index;=0D
-    int num_free_pages;=0D
-    page_table_t page_table;=0D
-    =0D
-    num_free_pages =3D 0;=0D
-    pgdir_index =3D 0;=0D
-    pgtbl_index =3D 0;=0D
-=0D
-    for(i =3D 0; i < NUM_KERNEL_PAGE_TABLES; i++)=0D
-    {=0D
-        if(num_free_pages =3D=3D 0)=0D
-        {=0D
-            // Dieser Eintrag im Page Directory w=EF=BF=BDre der erste von=
 unseren Pages=0D
-            pgdir_index =3D i;=0D
-        }=0D
-=0D
-        if(kernel_page_tables[i] & PTE_P)=0D
-        {=0D
-            // Die virtuelle Adresse der passenden Page Table errechnen=0D
-            page_table =3D (page_table_t)(KERNEL_PAGE_TABLES_VADDR + (i <<=
 PAGE_SHIFT));=0D
-           =0D
-            // Die NULL-Page bleibt grunds=EF=BF=BDtzlich ungemappt, daher=
 wird bei der ersten=0D
-            // Page Table erst beim zweiten Eintrag mit Suchen angefangen=
=0D
-            for(j =3D (i =3D=3D 0 ? 1 : 0); j < PAGE_TABLE_LENGTH; j++)=0D
-            {=0D
-                if(!(page_table[j] & PTE_P))=0D
-                {=0D
-            =0D
-                    if(num_free_pages =3D=3D 0)=0D
-                    {=0D
-                        pgtbl_index =3D j;=0D
-                    }=0D
-=0D
-                    num_free_pages++;=0D
-=0D
-                    if(num_free_pages >=3D num)=0D
-                    {=0D
-                        // Wenn wir genug freie Seiten gefunden haben, die=
 Suche beenden=0D
-                        break;=0D
-                    }=0D
-                }=0D
-                else=0D
-                {=0D
-                    // Eine belegte Page ist uns dazwischen gekommen, und =
wir m=EF=BF=BDssen mit unserer Suche von vorne anfangen=0D
-                    num_free_pages =3D 0;=0D
-                }=0D
-            }=0D
-        }=0D
-        else=0D
-        {=0D
-            // Diese Page Table ist zwar nicht vorhanden, aber wir k=EF=BF=
=BDnnen trotzdem mit ihr rechnen=0D
-=0D
-            if(i =3D=3D 0)=0D
-            {=0D
-                // Die NULL-Page wird freigehalten, daher muss hier=0D
-                // eins von der theoretischen Maximalzahl abgezogen=0D
-                // werden=0D
-                pgtbl_index =3D 1;=0D
-                num_free_pages +=3D PAGE_TABLE_LENGTH - 1;=0D
-            }=0D
-            else=0D
-            {=0D
-                if(num_free_pages =3D=3D 0)=0D
-                {=0D
-                    // Diese Page w=EF=BF=BDre die erste von unseren Pages=
.=0D
-                    pgtbl_index =3D 0;=0D
-                }=0D
-=0D
-                num_free_pages +=3D PAGE_TABLE_LENGTH;=0D
-            }=0D
-        }=0D
-=0D
-        if(num_free_pages >=3D num)=0D
-        {=0D
-            // Wenn wir genug freie Seiten gefunden haben, die Suche beend=
en=0D
-            break;=0D
-        }=0D
-    }=0D
-    =0D
-    if(num_free_pages =3D=3D 0)=0D
-    {=0D
-        panic("Nicht genug Speicher.");=0D
-    }=0D
-=0D
-    return (vaddr_t)(KERNEL_BASE + (pgdir_index << PGDIR_SHIFT) + (pgtbl_i=
ndex << PAGE_SHIFT));=0D
-}=0D
-=0D
-/**=0D
- * Allokiert num_pages Seiten im Kernel-Adressraum. =0D
- *=0D
- * @return Die Adresse der ersten Seite=0D
- */=0D
-vaddr_t alloc_kernel_pages(int num)=0D
-{=0D
-    int i, j;=0D
-    int pgdir_index, pgtbl_index;=0D
-    page_table_t page_table;=0D
-    vaddr_t vaddr;=0D
-    =0D
-    vaddr =3D find_contiguous_kernel_pages(num);=0D
-    =0D
-    pgdir_index =3D ((uint32_t)vaddr - KERNEL_BASE) >> PGDIR_SHIFT;=0D
-    pgtbl_index =3D (((uint32_t)vaddr - KERNEL_BASE) >> PAGE_SHIFT) % PAGE=
_TABLE_LENGTH;=0D
-=0D
-    for(i =3D pgdir_index; num; i++)=0D
-    {=0D
-        if(!(kernel_page_tables[i] & PTE_P))
-        {
-            // Eine neue Page Table muss angelegt werden
-            kernel_page_tables[i] =3D phys_alloc_page() | PTE_W | PTE_P;
-            map_kernel_page_table(i, kernel_page_tables[i]);
-            page_table =3D (page_table_t)(KERNEL_PAGE_TABLES_VADDR + (i <<=
 PAGE_SHIFT));
-
-            // Page Table mit Nullen initialisieren=0D
-            memset(page_table, 0, PAGE_SIZE);
-=0D
-            kernel_pd_id++;=0D
-        }=0D
-        else=0D
-        {=0D
-            // Wir verwenden eine bereits vorhandene Page Table=0D
-            page_table =3D (page_table_t)(KERNEL_PAGE_TABLES_VADDR + (i <<=
 PAGE_SHIFT)); =0D
-        }=0D
-
-        for(j =3D (i =3D=3D pgdir_index) ? pgtbl_index : 0; j < PAGE_TABLE=
_LENGTH && num; j++, num--)
-        {
-            page_table[j] =3D phys_alloc_page() | PTE_W | PTE_P;
-            asm volatile("invlpg %0"
-                : : "m" (*(char*)((i * PAGE_TABLE_LENGTH + j) * PAGE_SIZE)=
)
-                : "memory");
-        }=0D
-    }=0D
-=0D
-    return vaddr;=0D
-}=0D
-=0D
-/**=0D
- * Gibt num_pages Seiten beginnend mit der Adresse first_page im=0D
- * Kernel-Adressraum frei.=0D
- */=0D
-void free_kernel_pages(vaddr_t first_page, int num_pages)=0D
-{=0D
-    int i;=0D
-    =0D
-    for(i =3D 0; i < num_pages; i++)=0D
-    {=0D
-        free_kernel_page((vaddr_t)((uint32_t)first_page + i * PAGE_SIZE));=
=0D
-    }=0D
-}=0D
-=0D
-=0D
-/**=0D
- * Mapt den physikalische Adressbereich irgendwo hin, und gibt einen Point=
er =0D
- * darauf zurueck.=0D
- * @param addr Adresse=0D
- * @param size Groesse des Speicherbereichs=0D
- * @return Pointer auf gemapte stelle=0D
- */=0D
-vaddr_t map_phys_addr(paddr_t paddr, size_t size)=0D
-{=0D
-    // FIXME Diese Funktion sollte nicht auf kernel_page_directory arbeite=
n, =0D
-    // sondern auf dem aktuellen PD.=0D
-    uint32_t aligned_addr =3D (uint32_t)paddr - ((uint32_t)paddr & ~PAGE_M=
ASK);=0D
-    uint32_t aligned_bytes =3D size + (uint32_t)paddr -=0D
-        ((uint32_t)paddr & PAGE_MASK);=0D
-    =0D
-    vaddr_t vaddr =3D find_contiguous_kernel_pages(NUM_PAGES(aligned_bytes=
));=0D
-    if (vaddr =3D=3D NULL) {=0D
-        panic("map_phys_addr(0x%08x, 0x%x): vaddr =3D=3D NULL\n", paddr, s=
ize);=0D
-        return NULL;=0D
-    }=0D
-    =0D
-    if(!map_page_range(kernel_page_directory, vaddr, (paddr_t)aligned_addr=
, PTE_W | PTE_P /*| PTE_U*/, NUM_PAGES(aligned_bytes))) {=0D
-        panic("map_phys_addr(0x%08x, 0x%x): map_page_rang fehlgeschlagen\n=
", paddr, size);=0D
-        return NULL;=0D
-    }=0D
-    =0D
-    return (vaddr_t)((uint32_t)vaddr + ((uint32_t)paddr & ~PAGE_MASK));=0D
-}=0D
-=0D
-=0D
-/**=0D
- * Free dem physikalische Adressbereich=0D
- * @param addr Adresse=0D
- * @param size Groesse des Speicherbereichs=0D
- */=0D
-void free_phys_addr(vaddr_t vaddr, size_t size)=0D
-{=0D
-    uint32_t aligned_addr =3D (uint32_t)vaddr - ((uint32_t)vaddr & ~PAGE_M=
ASK);=0D
-    uint32_t aligned_bytes =3D size + (uint32_t)vaddr -=0D
-        ((uint32_t)vaddr & PAGE_MASK);=0D
-    =0D
-    =0D
-    map_page_range(kernel_page_directory, (vaddr_t) aligned_addr, (paddr_t=
)0, 0, NUM_PAGES(aligned_bytes));=0D
-}=0D
-=0D
-/**=0D
- * Dient nur als Wrapper fuer malloc()=0D
- */=0D
-void* mem_allocate(uint32_t size, uint32_t flags)=0D
-{=0D
-    return alloc_kernel_pages(PAGE_ALIGN_ROUND_UP(size) >> 12);=0D
-}=0D
-=0D
-/**=0D
- * Dient nur als Wrapper fuer malloc()=0D
- */=0D
-void mem_free(void* address, uint32_t size)=0D
-{=0D
-    free_kernel_pages(address, PAGE_ALIGN_ROUND_UP(size) >> 12);=0D
-}=0D
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 @@
-/* =20
- * 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 softwar=
e
- *    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=20
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */ =20
-
-#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 padd=
r, 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 =3D 0;
-
-/**
- * Wenn true, werden Page Tables nicht =EF=BF=BDber ihre virtuelle Adresse
- * angesprochen, sondern =EF=BF=BDber die physische. In diesem Fall mu=EF=
=BF=BD daf=EF=BF=BDr
- * gesorgt sein, da=EF=BF=BD die Page Table auch unter dieser Adresse zugr=
eifbar
- * 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=EF=BF=BDz=EF=BF=BDgig vergeben, das =
sollte sich
-// irgendwann noch =EF=BF=BDndern.
-   =20
-/**
- * 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 =3D true;
-
-
-    // Ein Page Directory anlegen und initialisieren
-    kernel_page_directory =3D (unsigned long*) phys_alloc_page_limit(0x100=
0);
-    memset(kernel_page_directory, 0, PAGE_SIZE);
-
-
-    /* Kernel Page Tables mappen */
-    kernel_page_directory[KERNEL_PAGE_TABLES_VADDR >> PGDIR_SHIFT] =3D=20
-        (uint32_t) kernel_page_directory | PTE_W | PTE_P;
-
-    // Den Kernel mappen
-    map_page_range(kernel_page_directory, kernel_start, (paddr_t) kernel_p=
hys_start,
-        PTE_W | PTE_P /*| PTE_U*/, ((uint32_t)kernel_end - (uint32_t)kerne=
l_start) / PAGE_SIZE);
-
-    // Videospeicher mappen
-    map_page_range(kernel_page_directory, (vaddr_t) 0xB8000, (paddr_t)0xB8=
000, PTE_W | PTE_P /*| PTE_U*/, ((25*80*2) / PAGE_SIZE) + 1);
-   =20
-    /* Das Page Directory mappen */
-    map_page(kernel_page_directory, kernel_page_directory, (paddr_t)kernel=
_page_directory, PTE_P | PTE_W);
-   =20
-    // Bitmap mit dem physischen Speicher mappen.
-    map_page_range(kernel_page_directory, phys_mmap, (paddr_t)phys_mmap, P=
TE_W | PTE_P,
-        (sizeof(uint32_t) * phys_mmap_size + PAGE_SIZE - 1) / PAGE_SIZE);
-
-    __asm__(
-       =20
-        // 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"
-       =20
-    : : "r"(kernel_page_directory) : "eax");
-   =20
-    use_phys_page_tables =3D false;
-}
-
-
-/**
- * Mappt mehrere zusammenh=EF=BF=BDngende virtuelle Seiten auf einen physi=
schen
- * Speicherbereich. Beide Adressen muessen dazu 4K-aligned sein.
- *
- * @param page_directory Page Directory, auf das sich die virtuelle=20
- *    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
- *=20
- * @return true, wenn der bereich erfolgreich gemappt werden konnte,=20
- *    false sonst
- */
-bool map_page_range(page_directory_t page_directory, vaddr_t vaddr, paddr_=
t paddr, int flags, int num_pages)=20
-{
-    int i;
-    vaddr_t va;
-    paddr_t pa;
-
-    for(i =3D 0; i < num_pages; i++)
-    {
-        va =3D (vaddr_t)((uint32_t)vaddr + i * PAGE_SIZE);
-        pa =3D (paddr_t)((uint32_t)paddr + i * PAGE_SIZE);
-
-        if(map_page(page_directory, va, pa, flags) !=3D true)
-        {
-            /* TODO: Das bereits geschehene Mapping r=EF=BF=BDckg=EF=BF=BD=
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=20
- *    Adresse bezieht
- *
- * @param vaddr Virtuelle Speicheradresse
- * @param paddr Physische Speicheradresse
- * @param flags Flags, die in der Page Table gesetzt werden sollen
- *=20
- * @return true, wenn die virtuelle Seite erfolgreich gemappt werden konnt=
e,=20
- *    false sonst
- */
-bool map_page(page_directory_t page_directory, vaddr_t vaddr, paddr_t padd=
r, int flags)=20
-{
-    page_table_t page_table;
-   =20
-    uint32_t vpage =3D (uint32_t) vaddr / PAGE_SIZE;
-
-    //kprintf("map_page %x =3D> %x\n", vaddr, paddr);
-
-    // Die NULL-Page bleibt ungemappt
-    if (vaddr =3D=3D NULL) {
-        panic("Versuchtes Mapping nach virtuell NULL");
-        return false;
-    }
- =20
-    if (flags & ~0x01F) {
-        // Boese Flags wollen die Adresse manipulieren.
-        // Fliegt das entsprechende Programm eben beim naechsten Zugriff
-        // auf die Schnauze.
-       =20
-        return false;
-    }
-
-    if (((uint32_t) vaddr | (uint32_t) paddr) & 0xfff) {
-        panic("Adressen sind nicht 4K-aligned (virt =3D %x, phys =3D %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) =3D=3D 0) {
-        page_table =3D (page_table_t) phys_alloc_page();
-       =20
-        page_directory[vpage / PAGE_TABLE_LENGTH] =3D ((uint32_t) page_tab=
le) | flags | PTE_U;
-       =20
-        if (page_directory =3D=3D kernel_page_directory) {
-            if (!use_phys_page_tables) {
-                page_table =3D (page_table_t) (KERNEL_PAGE_TABLES_VADDR + =
((sizeof(uint32_t)*vpage) & ~0xfff));
-            }
-        } else {
-            // Die Page Table geh=EF=BF=BDrt nicht zum Kernel - folglich s=
ollte man nicht direkt auf
-            // ihre Adresse zugreifen, wenn man nicht gerade einen Page Fa=
ult ausl=EF=BF=BDsen will.
-            // Die Page Table muss daher zun=EF=BF=BDchst in den Kerneladr=
essraum gemappt werden.
-            vaddr_t kernel_page_table =3D find_contiguous_kernel_pages(1);
-            map_page(kernel_page_directory, kernel_page_table, (paddr_t) p=
age_table, PTE_P | PTE_W);
-           =20
-            /*=20
-            kprintf("Mappe PT in Kerneladressraum; neue PT\n");
-            kprintf("PD =3D %x\n", page_directory);
-            kprintf("PT Kernel vaddr =3D %x, paddr =3D %x\n", kernel_page_=
table, page_table);
-            */
-
-            page_table =3D kernel_page_table;
-        }
-
-        if (vaddr < (vaddr_t) 0x40000000) {
-            kernel_pd_id++;
-        }
-       =20
-        memset(page_table, 0, PAGE_SIZE);
-       =20
-    } else if (page_directory[vpage / PAGE_TABLE_LENGTH] & PTE_PS) {
-        panic("Doppelbelegung im Page Directory.");
-    } else {
-        if (page_directory =3D=3D kernel_page_directory) {
-            if (use_phys_page_tables) {
-                page_table =3D (page_table_t) (page_directory[vpage / PAGE=
_TABLE_LENGTH] & ~0xFFF);
-            } else {
-                page_table =3D (page_table_t) (KERNEL_PAGE_TABLES_VADDR + =
((sizeof(uint32_t)*vpage) & ~0xfff));
-            }
-        } else {
-            page_table =3D (page_table_t) (page_directory[vpage / PAGE_TAB=
LE_LENGTH] & ~0xFFF);
-           =20
-            // Die Page Table geh=EF=BF=BDrt nicht zum Kernel - folglich s=
ollte man nicht direkt auf
-            // ihre Adresse zugreifen, wenn man nicht gerade einen Page Fa=
ult ausl=EF=BF=BDsen will.
-            // Die Page Table muss daher zun=EF=BF=BDchst in den Kerneladr=
essraum gemappt werden.
-           =20
-            vaddr_t kernel_page_table =3D find_contiguous_kernel_pages(1);
-            map_page(kernel_page_directory, kernel_page_table, (paddr_t) p=
age_table, PTE_P | PTE_W);
-            page_table =3D kernel_page_table;
-        }
-    }
-   =20
-    // 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=EF=BF=BD=
ber hinweggesehen
-    //
-    // Und wenn das Mapping aufgehoben werden soll, sollte man sich auch n=
icht dar=EF=BF=BDber
-    // beschweren, dass der Eintrag schon besteht.
-    if ((page_table[vpage % PAGE_TABLE_LENGTH] & PTE_P) && ((page_table[vp=
age % PAGE_TABLE_LENGTH] & ~(PTE_A | PTE_D)) !=3D (((uint32_t) paddr) | fla=
gs)) && (flags & PTE_P)) {
-        panic("Doppelbelegung in einer Page Table.");
-        return false;
-    } else {
-        page_table[vpage % PAGE_TABLE_LENGTH] =3D ((uint32_t) paddr) | fla=
gs;
-
-        if (page_directory !=3D kernel_page_directory) {
-            // Falls wir die Page Table extra in den Kerneladressraum gema=
ppt haben,
-            // den Speicher wieder freigeben
-            unmap_page(kernel_page_directory, page_table);
-        }
-        // Und falls es um das aktive Page Directory geht, w=EF=BF=BDre je=
tzt ein
-        // guter Zeitpunkt, den TLB zu invalidieren.
-        // FIXME: Im moment auch wenn es sich nicht um das aktuelle PD han=
delt,
-        // aber das sauber zu machen ist zu aufwaendig, da kernel eh erset=
zt
-        // wird.
-        __asm__ __volatile__("invlpg %0" : : "m" (* (char*) vaddr));
-
-        return true;
-    }
-   =20
-}
-
-/**
- * Entfernt das Mapping einer virtuellen Adresse.
- *
- * @param page_directory Page Directory, auf das sich die virtuelle=20
- *    Adresse bezieht
- * @param vaddr Virtuelle Speicheradresse
- *=20
- * @return true, wenn die virtuelle Seite erfolgreich ungemappt werden kon=
nte,=20
- *    false sonst
- */
-bool unmap_page(page_directory_t page_directory, vaddr_t vaddr)=20
-{
-    return map_page(page_directory, vaddr, (paddr_t) NULL, 0);
-}
-
-/**
- * Gibt den Pagetable-Eintrag zu einer gegebenen virtuellen Speicheradress=
e
- * 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;
-   =20
-    uint32_t vpage =3D (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) =3D=3D 0) {
-        return 0;
-    } else if (page_directory[vpage / PAGE_TABLE_LENGTH] & PTE_PS) {
-        return page_directory[vpage / PAGE_TABLE_LENGTH];
-    } else {
-        phys_page_table =3D (paddr_t)
-            (page_directory[vpage / PAGE_TABLE_LENGTH] & ~0xFFF);
-    }
-       =20
-    // Die Page-Table-Adresse ist eine physische Adresse. Am sichersten is=
t es,
-    // die Adresse einfach noch einmal zu mappen.
-    page_table =3D map_phys_addr(phys_page_table, PAGE_SIZE);
-   =20
-    // Adresse zusammenbasteln und fertig
-    if (page_table[vpage % PAGE_TABLE_LENGTH] & PTE_P) {
-        result =3D page_table[vpage % PAGE_TABLE_LENGTH];=20
-    } else {
-        result =3D 0;
-    }
-       =20
-    // Falls wir die Page Table extra in den Kerneladressraum gemappt habe=
n,
-    // 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 =3D get_pagetable_entry(page_directory, vaddr);
-   =20
-    if ((pte & PTE_P) =3D=3D 0) {
-        return (paddr_t) NULL;
-    }
-
-    if ((pte & PTE_PS) =3D=3D 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 ha=
t.
- */
-bool is_userspace(vaddr_t start, uint32_t len)
-{
-    vaddr_t cur;
-
-    if (start + len < start) {
-        return false;
-    }   =20
-   =20
-    for (cur =3D start;=20
-        (cur < start + len) && (cur > (vaddr_t) 0xFFF);=20
-        cur +=3D PAGE_SIZE)=20
-    {
-        uint32_t pte =3D get_pagetable_entry(current_task->cr3, cur);
-        if ((pte =3D=3D 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, ui=
nt32_t lower_limit, uint32_t upper_limit)
-{
-    uint32_t free_pages =3D 0;
-    uint32_t cur_page;
-    uint32_t cur_page_table;
-
-    // Die NULL-Page bleibt ungemappt
-    if (lower_limit < PAGE_SIZE) {
-        lower_limit =3D PAGE_SIZE;
-    }
-
-    cur_page =3D (lower_limit >> PAGE_SHIFT) % PAGE_TABLE_LENGTH;
-    cur_page_table =3D (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 =3D find_contiguous_kernel_pages(1);
-
-            map_page(kernel_page_directory, kernel_page_table, page_direct=
ory[cur_page_table] & PAGE_MASK, PTE_P | PTE_W);
-            page_table =3D kernel_page_table;
-
-            while (cur_page < PAGE_TABLE_LENGTH) {
-                if ((page_table[cur_page++] & PTE_P) =3D=3D 0) {
-                    free_pages++;
-                } else {
-                    free_pages =3D 0;
-                    lower_limit =3D (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);
-           =20
-        } else {
-            free_pages +=3D PAGE_TABLE_LENGTH;
-        }
-
-        cur_page =3D 0;
-        cur_page_table++;
-    }
-
-    if ((free_pages >=3D num) && (lower_limit + (num * PAGE_SIZE) < upper_=
limit)) {
-        return (vaddr_t) lower_limit;
-    } else {
-        return NULL;
-    }
-}
-
-
-/**
- * Vergr=EF=BF=BDssert 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 =3D 0; i < pages; i++)
-	{
-		task_ptr->user_stack_bottom -=3D PAGE_SIZE;
-		if(resolve_vaddr((page_directory_t) task_ptr->cr3, (vaddr_t) task_ptr->u=
ser_stack_bottom) !=3D (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_bo=
ttom, phys_alloc_page(), PTE_P | PTE_W | PTE_U);
-	}
-=09
-}
-
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.
  */
=20
-/*
- * 2006-23-9: malu
- * Dokumentation hinzugef=EF=BF=BDgt
- */
-
 #include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
=20
-#include "bitops.h"
 #include "kernel.h"
 #include "multiboot.h"
-#include "vmm.h"
-#include "phys.h"
-#include "string.h"
+#include "mm.h"
+#include "lock.h"
=20
-extern struct multiboot_info multiboot_info;
+#define min(x,y) (((x) < (y)) ? (x) : (y))
=20
 /* Diese beiden werden in kernel.ld definiert. */
 extern void kernel_phys_start(void);
 extern void kernel_phys_end(void);
=20
-unsigned long * phys_mmap;
-unsigned long phys_mmap_size;
-unsigned long phys_mmap_usable_pages;
+/** Bitmap aller physischen Seiten. Gesetztes Bit steht f=EF=BF=BDr 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 =3D 0;
+
+/**=20
+ * Gr=EF=BF=BD=EF=BF=BDe von pmm_bitmap in Elementen (=3D 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=EF=BF=BDck
+ */
+void* pmm_get_bitmap_start()
+{
+    return pmm_bitmap;
+}
+
+/**
+ * Setzt die Startadresse der Bitmap. Diese Funktion ist einzig und allein=
 dazu
+ * bestimmt, den =EF=BF=BDbergang von physischen zu virtuellen Adressen be=
im
+ * Einschalten von Paging bewerkstelligen zu k=EF=BF=BDnnen.
+ */
+void pmm_set_bitmap_start(void* bitmap_start)
+{
+    pmm_bitmap =3D bitmap_start;
+}
=20
 /**
- * Gibt die Anzahl der freien Pages zurueck
+ * Gibt die G=EF=BF=BD=EF=BF=BDe der Bitmap in Bytes zur=EF=BF=BDck
+ */
+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 =3D 0;
-    unsigned long i, j;
+    size_t free_pages =3D 0;
+    size_t i, j;
    =20
-    for(i =3D 0; i < phys_mmap_size; i++)
-    {
-        for(j =3D 0; j < 32; j++)
-        {
-            if((phys_mmap[i] & (1 << j)) !=3D 0)
-            {
+    for (i =3D 0; i < pmm_bitmap_length; i++) {
+        for (j =3D 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();
 }
=20
 /**
  * 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 werde=
n=20
+ * soll.
  */
=20
-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] |=3D 1 << ((page / PAGE_SIZE) & 31);
+    //lock(&pmm_lock);
+    size_t bitmap_index =3D (size_t) page / PAGE_SIZE / PMM_BITS_PER_ELEME=
NT;
+    pmm_bitmap[bitmap_index] |=3D 1 << (((size_t) page / PAGE_SIZE) &=20
+        (PMM_BITS_PER_ELEMENT - 1));
+
+    //unlock(&pmm_lock);
 }
=20
 /**
  * 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.
  */
=20
-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;
=20
-    for(i =3D 0; i < num; i++)
-    {
+    for(i =3D 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, unsig=
ned int num)
 /**
  * Markiert eine Page als benutzt.
  *
- * @param page Zeiger auf den Anfang der Page die als benutzt markiert wer=
den soll.
+ * @param page Zeiger auf den Anfang der Page, die als benutzt markiert we=
rden=20
+ * soll.
  */
=20
-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] &=3D ~(1 << ((page / PAGE_SIZE) & 31)=
);
+    //lock(&pmm_lock);
+    size_t bitmap_index =3D (size_t) page / PAGE_SIZE / PMM_BITS_PER_ELEME=
NT;
+    pmm_bitmap[bitmap_index] &=3D ~(1 << (((size_t) page / PAGE_SIZE) &=20
+        (PMM_BITS_PER_ELEMENT - 1)));
+    //unlock(&pmm_lock);
 }
=20
 /**
@@ -136,57 +176,21 @@ void phys_mark_page_as_used(paddr_t page)
  * @param num Anzahl der Pages die als benutzt markiert werden sollen.
  */
=20
-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;
=20
-    for(i =3D 0; i < num; i++)
-    {
+    for(i =3D 0; i < num; i++) {
         phys_mark_page_as_used(page + i * PAGE_SIZE);
     }
 }
=20
-/**
- * Sucht eine freie Page und gibt einen Zeiger auf den Anfang zur=EF=BF=BD=
ck.
- *
- * @param lower_limit Mindestgr=EF=BF=BD=EF=BF=BDe der Page.
- *
- * @return Im Erfolgsfall wird ein Zeiger auf den Anfang der Page=20
- *      zur=EF=BF=BDckgegeben (Bei Erfolg ist der R=EF=BF=BDckgabewert imm=
er
- *      durch PAGE_SIZE teilbar). Im Fehlerfall wird 1 zur=EF=BF=BDckgegeb=
en.
- */
-
-paddr_t find_free_page(unsigned long lower_limit)
-{
-    unsigned int i, j;
-    paddr_t page =3D 0;
-
-    i =3D lower_limit / PAGE_SIZE / 32;
-    if(phys_mmap[i] & (0xffffffff << ((lower_limit / PAGE_SIZE) % 32)))
-    {
-        j =3D bit_scan_forward(phys_mmap[i] & (0xffffffff << ((lower_limit=
 / PAGE_SIZE) % 32)));
-        page =3D (i * 32 + j) * PAGE_SIZE;
-        return page;
-    }
-
-    for(i++; i < phys_mmap_size; i++)
-    {
-        if(phys_mmap[i])
-        {
-            j =3D bit_scan_forward(phys_mmap[i]);
-            page =3D (i * 32 + j) * PAGE_SIZE;
-            return page;
-        }
-    }
-
-    return 1;
-}
-
 /**
  * Sucht num freie Pages und gibt einen Zeiger auf den Anfang der ersten P=
age=20
  * zur=EF=BF=BDck.
  *
- * @param lower_limit Mindestgr=EF=BF=BD=EF=BF=BDe jeder Page.
+ * @param lower_index Index der niedrigsten erlaubten Page
+ * @param upper_index Index der h=EF=BF=BDchsten 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)
  */
=20
 /* 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 =3D 0;
+    size_t i, j;
+    size_t found =3D 0;
     paddr_t page =3D 0;
=20
-    for(i =3D lower_limit / PAGE_SIZE / 32; i < phys_mmap_size; i++)
+    for(i =3D lower_index; i < upper_index; i++)
     {
-        if(phys_mmap[i] =3D=3D 0)
-        {
+        if(pmm_bitmap[i] =3D=3D 0) {
             found =3D 0;
             continue;
         }
=20
-        if(phys_mmap[i] =3D=3D 0xffffffff)
+        if(pmm_bitmap[i] =3D=3D ~0x0)
         {
             if(found =3D=3D 0)
             {
-                page =3D i * 32 * PAGE_SIZE;
+                page =3D i * PMM_BITS_PER_ELEMENT * PAGE_SIZE;
             }
-            found +=3D 32;
+            found +=3D PMM_BITS_PER_ELEMENT;
         }
         else
         {
-            for(j =3D 0; j < 32; j++)
+            for(j =3D 0; j < PMM_BITS_PER_ELEMENT; j++)
             {
-                if(phys_mmap[i] & (1 << j))
+                if(pmm_bitmap[i] & (1 << j))
                 {
-                    if(found =3D=3D 0)
-                    {
-                        page =3D (i * 32 + j) * PAGE_SIZE;
+                    if(found =3D=3D 0) {
+                        page =3D (i * PMM_BITS_PER_ELEMENT + j) * PAGE_SIZ=
E;
                     }
                     found++;
=20
-                    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)
             }
         }
=20
-        if(found > num)
-        {
+        if(found > num) {
             return page;
         }
     }
@@ -251,349 +252,364 @@ paddr_t find_free_page_range(unsigned long lower_li=
mit, unsigned int num)
     return 1;
 }
=20
-/**
- * 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);
-}
=20
 /**
- * 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=EF=BF=BD auf 32-Bit-=
Systemen
+ * auf einer 128K-Grenze liegen. Wenn nicht, wird gerundet)
+ *
+ * @param upper_limit H=EF=BF=BDchste erlaubte Adresse (Mu=EF=BF=BD 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 =3D (size_t) lower_limit / PMM_BITS_PER_ELEMENT;
+    size_t upper_index =3D (size_t) upper_limit / PMM_BITS_PER_ELEMENT;
=20
-/**
- * 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 =3D pmm_bitmap_length;
+    }
=20
-paddr_t phys_alloc_dma_page()
-{
-    paddr_t page =3D find_free_page(0);
-    if(page & (PAGE_SIZE - 1))
+    if ((upper_index > PMM_NUM_DMA_ELEMENTS) &&=20
+        (lower_index < PMM_NUM_DMA_ELEMENTS))
+    {
+        page =3D find_free_page_range(lower_index, upper_index, num);
+    }
+    else
     {
+        page =3D find_free_page_range(PMM_NUM_DMA_ELEMENTS, upper_index, n=
um);
+   =20
+        if((size_t) page & (PAGE_SIZE - 1)) {
+            page =3D find_free_page_range(
+                lower_index,=20
+                min(PMM_NUM_DMA_ELEMENTS + num, upper_index),=20
+                num
+            );
+        }
+    }
+   =20
+    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;
 }
=20
 /**
- * Reserviert eine Page.
+ * Reserviert num Pages, die beliebig im physischen Speicher liegen k=EF=
=BF=BDnnen.
  *
- * @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 =3D find_free_page(16 * 1024 * 1024);
-    if(page & (PAGE_SIZE - 1))
-    {
-        return phys_alloc_dma_page();
-    }
-    phys_mark_page_as_used(page);
-    return page;
-}
-  =20
-/**
- * Reserviert eine Page nicht unterhalb einer gegebenen Adresse
- */
-paddr_t phys_alloc_page_limit(uint32_t lower_limit)
-{
-    paddr_t page =3D find_free_page(16 * 1024 * 1024 > lower_limit ? 16 * =
1024 * 1024 : lower_limit);
+    paddr_t result =3D pmm_alloc_limits(
+        0,
+        pmm_bitmap_length * PMM_BITS_PER_ELEMENT * PAGE_SIZE,
+        num
+    );
=20
-    if(page & (PAGE_SIZE - 1)) {
-        page =3D 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;
 }
=20
=20
 /**
- * Reserviert num DMA-Pages.
+ * Gibt physisch zusammenh=EF=BF=BDngende 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 =3D 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=EF=BF=BDfen, ob die Seiten vorher auch besetzt waren, sonst=
 Panic
+    phys_mark_page_range_as_free(start, count);
 }
=20
-/**
- * Reserviert num Pages.
- *
- * @return Zeiger auf den Anfang der ersten Page.
- */
=20
-paddr_t phys_alloc_page_range(unsigned int num)
-{
-    paddr_t page =3D 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;
+};
=20
 /**
- * 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 nich=
t
+ * 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 =3D 0;
-    paddr_t page;
+    struct mem_block result;
+
+    // =EF=BF=BDberpr=EF=BF=BDfung der BIOS-Memory-Map
+    struct multiboot_mmap* mmap;
+    uintptr_t mmap_addr =3D multiboot_info->mi_mmap_addr;
+    uintptr_t mmap_end =3D mmap_addr + multiboot_info->mi_mmap_length;
=20
-    while(1)
+    for(mmap =3D (struct multiboot_mmap*) (mmap_addr);
+        mmap < (struct multiboot_mmap*) (mmap_end);
+        mmap++)
     {
-        page =3D find_free_page_range(pos, num);
+        uint64_t start =3D mmap->mm_base_addr;
+        uint64_t end   =3D mmap->mm_base_addr + mmap->mm_length - 1;
=20
-        if(page & (PAGE_SIZE - 1))
-        {
-            panic("Keine freier Speicher mehr da.");
+        if (start > UINTPTR_MAX) {
+            continue;
+        }
+        if (end > UINTPTR_MAX) {
+            end =3D UINTPTR_MAX;
         }
=20
-        pos =3D (uint32_t) page;
-        if ((pos % 65536) + (num * PAGE_SIZE) > 65536) {
-            //printf("Kernel: dma_64k: %x + %x ueberschreitet 64k-Grenze\n=
",
-            //    pos, num);
-            pos =3D (pos + 32 * PAGE_SIZE);
-        } else {
-            break;
+        // Typ 1 steht f=EF=BF=BDr freien Speicher
+        if (mmap->mm_type =3D=3D 1) {
+            if (i-- =3D=3D 0) {
+                result.start    =3D (paddr_t)start;
+                result.end      =3D (paddr_t)end;
+                return result;
+            }
         }
-    }=20
+    }
+
+    result.start =3D (paddr_t) 0xFFFFFFFF;
+    result.end   =3D (paddr_t) 0;
=20
-    phys_mark_page_range_as_used(page, num);
-    return page;
+    return result;
 }
=20
 /**
- * Initialisiert den physischen Speicher.
+ * Wird benutzt, um nacheinander alle belegten Speicherbereiche aufzuzaehl=
en.
+ * Dies sind vor allem Kernel, Module und Multiboot-Strukturen. Vom BIOS a=
ls
+ * reserviert gekennzeichnete Bereiche sind hierbei nicht enthalten. Um di=
e
+ * vom BIOS aus freien Bereiche zu erhalten, muss get_free_block() benutzt
+ * werdem.
  *
- * @param mmap_addr Adresse der Memorymap.
- * @param mmap_length L=EF=BF=BDnge der Memorymap.
- * @param upper_mem Gr=EF=BF=BD=EF=BF=BDe des upper_mem in Kilobyte, wie i=
n der Multboot-Info
- *      =EF=BF=BDbergeben.
+ * @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 =3D 0;
-    int i, j;
-    uint32_t upper_end =3D 0;
-    phys_mmap_usable_pages =3D 0;
-    /* Die von GRUB gelieferte memory map in unser Format umwandeln. */
-    if (mmap_length) {
-        for(mmap =3D (struct multiboot_mmap*)mmap_addr;
-            mmap < (struct multiboot_mmap*)(mmap_addr + mmap_length);
-            mmap =3D (struct multiboot_mmap*)((char*)mmap + mmap->mm_size =
+ 4))
-        {
-            if(mmap->mm_type =3D=3D 1)
-            {
-                available_memory[memblocks_count].start =3D PAGE_ALIGN_ROU=
ND_UP(mmap->mm_base_addr);
-                available_memory[memblocks_count].end =3D PAGE_ALIGN_ROUND=
_DOWN(mmap->mm_base_addr + mmap->mm_length);
-
-                phys_mmap_usable_pages +=3D (available_memory[memblocks_co=
unt].end - available_memory[memblocks_count].start) / PAGE_SIZE;
-
-                memblocks_count++;
-            }
-        }
-    }
-    else
-    {
-        // Wenn GRUB keine Memory Map =EF=BF=BDbergibt, Defaultwerte anneh=
men
-        // Dabei vertrauen wir darauf, da=EF=BF=BD zumindest upper_mem kor=
rekt
-        // gesetzt ist.
-        available_memory[0].start =3D 0x0;
-        available_memory[0].end =3D 0x9fc00;
-       =20
-        available_memory[1].start =3D 0x100000;
-        available_memory[1].end =3D 0x100000 + (1024 * upper_mem);
-       =20
-        phys_mmap_usable_pages +=3D (available_memory[0].end - available_m=
emory[0].start) / PAGE_SIZE;
-        phys_mmap_usable_pages +=3D (available_memory[1].end - available_m=
emory[1].start) / PAGE_SIZE;
-       =20
-        memblocks_count =3D 2;
+    struct mem_block result;
+
+    // Bitmap nur beruecksichtigen, wenn sie bereits zugewiesen ist
+    if (bitmap && (i-- =3D=3D 0)) {
+        result.start =3D (paddr_t) pmm_bitmap;
+        result.end   =3D (paddr_t)
+            (pmm_bitmap + ((pmm_bitmap_length / 8) * PMM_BITS_PER_ELEMENT)=
);
+        return result;
     }
=20
-    /* In der Liste der physischen Speicherbl=EF=BF=BDcke (im folgenden ei=
nfach
-       Bl=EF=BF=BDcke bzw. Block) einen Bereich, der von start und end ang=
egeben wird,
-       als nicht verf=EF=BF=BDgbar definieren.
+    // Der Kernel ist besetzt
+    if (i-- =3D=3D 0) {
+        result.start    =3D (paddr_t) kernel_phys_start;
+        result.end      =3D (paddr_t) kernel_phys_end;
+        return result;
+    }
=20
-       Diese Funktion wird durch die Annahmen vereinfacht, dass GRUB den
-       Anfang und das Ende eines Moduls immer in genau einen Speicherblock=
 l=EF=BF=BDdt.
-       Au=EF=BF=BDerdem dadurch, dass die Liste der verf=EF=BF=BDgbaren Sp=
eicherbl=EF=BF=BDcke nicht
-       sortiert sein muss.
-     */
-    void carve(uint32_t start, uint32_t end)
+    // Die Module auch.
     {
-        uint32_t i;
-
-        start =3D PAGE_ALIGN_ROUND_DOWN(start);
-        end =3D PAGE_ALIGN_ROUND_UP(end);
+        uint32_t j;
+        struct multiboot_module* multiboot_module;
+        multiboot_module =3D (struct multiboot_module*) (uintptr_t)=20
+            multiboot_info->mi_mods_addr;
=20
-        //printf("carve: %x bis %x\n", start, end);
-       =20
-        for(i =3D 0; i < memblocks_count; i++)
+        for (j =3D 0; j < multiboot_info->mi_mods_count; j++)=20
         {
-            if(start =3D=3D available_memory[i].start)
-            {
-                /* Der Bereich beginnt genau an einem Blockanfang */
+            // Die Multiboot-Info zum Modul   =20
+            if (i-- =3D=3D 0) {
+                result.start    =3D (paddr_t) multiboot_module;
+                result.end      =3D (paddr_t) (multiboot_module + 1);
+                return result;
+            }
=20
-                if(end < available_memory[i].end)
-                {
-                    /* Der Bereich endet mittem im Block */
+            // Das Modul selbst
+            if (i-- =3D=3D 0) {
+                result.start    =3D (paddr_t) multiboot_module->start;
+                result.end      =3D (paddr_t) multiboot_module->end;
+                return result;
+            }
=20
-                    /* Den Beginn des Blocks hinter den Bereich verschiebe=
n */
-                    available_memory[i].start =3D end;
-                    break;
-                }
-                else if(end =3D=3D available_memory[i].end)
-                {
-                    /* Der Bereich nimmt den ganzen Block ein */
-
-                    /* Den Block aus der Liste entfernen */
-                    memblocks_count--;
-                    for(j =3D i; j < memblocks_count; j++)
-                    {
-                        available_memory[j].start =3D available_memory[j +=
 1].start;
-                        available_memory[j].end =3D available_memory[j + 1=
].end;
-                    }
-                    break;
+            // Die Kommandozeile des Moduls=20
+            if (multiboot_module->cmdline) {
+                if (i-- =3D=3D 0) {
+                    result.start =3D (paddr_t) multiboot_module->cmdline;
+                    result.end   =3D (paddr_t) multiboot_module->cmdline +
+                        strlen((char*) (uintptr_t) multiboot_module->cmdli=
ne);
+                    return result;
                 }
             }
-            else if(start > available_memory[i].start)
-            {
-                /* Der Bereich beginnt irgendwo im Block */
=20
-                if(end < available_memory[i].end)
-                {
-                    /* Der Bereich endet irgendwo mitten im Block. Das bed=
eutet
-                       ein Block muss in der Mitte zerteilt werden. Dazu m=
uss
-                       ein weiterer Eintrag in der Liste angelegt werden. =
*/
+            multiboot_module++;
+        }
+    }
=20
-                    /* Einen neuen Eintrag am Ende anlegen */
-                    available_memory[memblocks_count].start =3D end;
-                    available_memory[memblocks_count].end =3D available_me=
mory[i].end;
+    result.start =3D (paddr_t) 0xFFFFFFFF;
+    result.end   =3D (paddr_t) 0;
=20
-                    /* Den Eintrag verkleinern */
-                    // available_memory[i].start bleibt unver=EF=BF=BDnder=
t
-                    available_memory[i].end =3D start;
+    return result;
+}
=20
-                    memblocks_count++;
-                    break;
-                }
-                else if(end =3D=3D available_memory[i].end)
-                {
-                    /* Der Bereich endet genau mit dem Block */
+/**
+ * Suche einen Platz f=EF=BF=BDr 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 =3D 0x0;
=20
-                    /* Das Ende des Bereichs auf den Anfang des Blocks set=
zen. */
-                    available_memory[i].end =3D start;
-                    break;
-                }
+        i =3D 0;
+        do
+        {
+            // Freien Speicherblock suchen und Bitmap an den Anfang legen
+            free =3D get_free_block(multiboot_info, i++);
+            if (free.start > free.end) {
+                panic("Keinen Platz fuer die Speicherbitmap gefunden");
+            }
+            bitmap =3D free.start;
=20
-                /* 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 =3D 0;
+            do
+            {
+                reserved =3D get_reserved_block(multiboot_info, j++, false=
);
+                if (!((reserved.start > bitmap + size)
+                    || (reserved.end <=3D bitmap)))
+                {
+                    j =3D 0;
+                    bitmap =3D (paddr_t)
+                        PAGE_ALIGN_ROUND_UP((uintptr_t) reserved.end);
+                }
             }
+            while ((bitmap <=3D free.end) && (reserved.start < reserved.en=
d));
=20
-            /* Wenn der start vor dem Speicherblock liegt, wird nichts gem=
acht,
-               denn wir gehen davon aus, dass GRUB kein Modul in einen Ber=
eich
-               l=EF=BF=BDdt, der kein verf=EF=BF=BDgbarer Speicher ist. */
+            // Wenn die Bitmap nach Beruecksichtigung aller besetzten Bere=
iche
+            // immer noch im freien Bereich liegt, dann nehmen wir die Adr=
esse
+            if (bitmap <=3D free.end) {
+                return bitmap;
+            }
         }
+        while(true);
+    } else {
+        return (paddr_t) 0x1000;
     }
+}
=20
-    carve((uint32_t)kernel_phys_start, (uint32_t)kernel_phys_end);
-
-    /* foreach(modul in module) { carve(modul.start, module.end); } // pse=
udocode btw ;) */   =20
+/**
+ * Bestimmt die ben=EF=BF=BDtigte Gr=EF=BF=BD=EF=BF=BDe der Bitmap in Byte=
s
+ */
+static size_t required_bitmap_size(struct multiboot_info* multiboot_info)
+{
+    // Suche die h=EF=BF=BDchste Adresse
+    paddr_t upper_end =3D 0;
+    if (multiboot_info->mi_flags & MULTIBOOT_INFO_HAS_MMAP)=20
     {
-        uint32_t i;
-        struct multiboot_module * multiboot_module;
-        multiboot_module =3D multiboot_info.mi_mods_addr;
+        struct multiboot_mmap* mmap =3D
+            (struct multiboot_mmap*) (uintptr_t) multiboot_info->mi_mmap_a=
ddr;
=20
-        for (i =3D 0; i < multiboot_info.mi_mods_count; i++) {
-            carve((uint32_t) multiboot_module, ((uint32_t) multiboot_modul=
e) + 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) mul=
tiboot_module->cmdline + strlen(multiboot_module->cmdline));
+        size_t i =3D 0;
+        for (i =3D 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 =
=3D=3D 1))
+            {
+                upper_end =3D (paddr_t)(uintptr_t)=20
+                    mmap[i].mm_base_addr + mmap[i].mm_length;
             }
-
-            multiboot_module++;
         }
     }
-
-    /* Die obere Grenze des physischen Speichers ermitteln. */
-    for(i =3D 0; i < memblocks_count; i++)
+    else=20
     {
-        if(available_memory[i].end > upper_end)
-        {
-            upper_end =3D available_memory[i].end;
-        }
+        // Der hintere Cast verhindert Compiler-Warungen
+        upper_end =3D (paddr_t) (1024 * (1024 + (uintptr_t)=20
+            multiboot_info->mi_mem_upper));
     }
-   =20
-    /* einen ort f=EF=BF=BDr die tabelle mit den physischen seiten suchen =
*/
-    phys_mmap_size =3D upper_end / PAGE_SIZE / 32;
-    for(i =3D 0; i < memblocks_count; i++)
+
+    // Umrechnen auf ben=EF=BF=BDtigte Bytes f=EF=BF=BDr die Bitmap
+    return (size_t) upper_end / PAGE_SIZE / 8;
+}
+
+/**
+ * Initialisiert den physischen Speicher.
+ *
+ * @param mmap_addr Adresse der Memorymap.
+ * @param mmap_length L=EF=BF=BDnge der Memorymap in Bytes.
+ * @param upper_mem Gr=EF=BF=BD=EF=BF=BDe des upper_mem in Kilobyte, wie i=
n der Multboot-Info
+ *      =EF=BF=BDbergeben.
+ */
+void pmm_init(struct multiboot_info* multiboot_info)
+{
+    // Finde einen Platz f=EF=BF=BDr die Bitmap
+    size_t bitmap_size =3D required_bitmap_size(multiboot_info);
+    pmm_bitmap =3D (void*) find_bitmap_mem(multiboot_info, bitmap_size);
+    pmm_bitmap_length =3D 8 * bitmap_size / PMM_BITS_PER_ELEMENT;
+
+    // Am Anfang ist alles besetzt
+    memset(pmm_bitmap, 0x0, bitmap_size);
+
+    // ...anschlie=EF=BF=BDend die BIOS-Memory-Map abarbeiten
+    size_t i =3D 0;
+    do
     {
-        if((available_memory[i].start) && (available_memory[i].start + phy=
s_mmap_size * 4 < available_memory[i].end))
-        {
-            phys_mmap =3D (unsigned long*)available_memory[i].start;
-            available_memory[i].start =3D PAGE_ALIGN_ROUND_UP(available_me=
mory[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 =3D (unsigned long*)(available_memory[i].start + PAG=
E_SIZE);
-                   =20
-            available_memory[memblocks_count].start =3D available_memory[i=
].start;
-            available_memory[memblocks_count].end =3D available_memory[i].=
start + PAGE_SIZE;
-            memblocks_count++;
-           =20
-            available_memory[i].start =3D PAGE_ALIGN_ROUND_UP(available_me=
mory[i].start + PAGE_SIZE + phys_mmap_size * 4);
+        struct mem_block block =3D 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));
     }
-   =20
-    /* alle seiten als belegt markieren */
-    phys_mark_page_range_as_used(0, upper_end / PAGE_SIZE);
+    while(true);
+
=20
-    /* freie seiten als frei markieren */
-    for(i =3D 0; i < memblocks_count; i++)
+    // ...und dann Kernel usw. wieder reservieren
+    i =3D 0;
+    do
     {
-        //kprintf("Mark as free: %x, %d Pages\n", available_memory[i].star=
t, (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 =3D 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 @@
-/* =20
- * 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=20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
+ * 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 PROF=
ITS;
+ * 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.
- */ =20
+ */
=20
 #include <stdint.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <collections.h>
=20
-#include "shm.h"
-#include "phys.h"
-#include "stdlib.h"
-#include "kernel.h"
-#include "paging.h"
+#include "mm.h"
+#include "cpu.h"
+#include "tasks.h"
=20
-list_t *shm_table =3D 0;
+struct shm_desc {
+    uint64_t            id;
+    struct tree_item    tree_item;
=20
-uint32_t lastid =3D 0;
+    size_t              num_pages;
+    list_t*             processes;
+};
=20
-void init_shared_memory(void)
+struct shm_process {
+    struct shm_desc*    shm;
+    pm_process_t*       process;
+    vaddr_t             vaddr;
+};
+
+static tree_t* shms =3D NULL;
+static uint32_t shm_last_id =3D 0;
+
+static void shm_destroy_task(pm_process_t* process, void* prv);
+
+/**
+ * Initialisiert die SHM-Verwaltung
+ */
+void shm_init(void)
 {
-	shm_table =3D list_create();
+    shms =3D tree_create(struct shm_desc, tree_item, id);
 }
=20
-uint32_t create_shared_memory(uint32_t size)
+/**
+ * Neuen Shared Memory reservieren
+ *
+ * @return ID des neu angelegten Shared Memory. Der Aufrufer muss anschlie=
ssend
+ * syscall_shm_attach aufrufen, um auf den Speicher zugreifen zu koennen.
+ */
+uint32_t shm_create(size_t size)
 {
-    shm_table_entry_t *entry =3D malloc(sizeof(shm_table_entry_t));
-   =20
-    entry->pagecount =3D size / PAGE_SIZE;
-    if (size%PAGE_SIZE) {
-        entry->pagecount++;
+    uint32_t id =3D ++shm_last_id;
+    struct shm_desc* shm;
+
+    while (tree_search(shms, id)) {
+        id++;
     }
-    entry->addresses =3D malloc(entry->pagecount * sizeof(paddr_t));
-    int i;
-    for (i =3D 0; i < entry->pagecount; i++) {
-        entry->addresses[i] =3D phys_alloc_page();
+
+    shm =3D calloc(1, sizeof(*shm));
+    shm->id =3D id;
+    shm->num_pages =3D NUM_PAGES(size);
+    shm->processes =3D 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 =3D tree_search(shms, id);
+    void* ret;
+    struct shm_process* shm_proc;
+
+    if (shm =3D=3D NULL) {
+        return NULL;
     }
-    entry->usecount =3D 0;
-    entry->id =3D ++lastid;
-    list_push(shm_table, entry);
-    return entry->id;
+
+    if (list_is_empty(shm->processes)) {
+        // Erster Prozess, der den SHM oeffnet: Speicher allozieren
+        ret =3D mmc_valloc(&process->context, shm->num_pages,
+            MM_FLAGS_USER_DATA);
+    } else {
+        // Ansonsten Mapping von einem anderen Prozess uebernehmen
+        struct shm_process* first =3D list_get_element_at(shm->processes, =
0);
+        ret =3D 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 =3D=3D NULL) {
+        return NULL;
+    }
+
+    shm_proc =3D calloc(1, sizeof(*shm_proc));
+    shm_proc->shm =3D shm;
+    shm_proc->process =3D process;
+    shm_proc->vaddr =3D ret;
+    list_push(shm->processes, shm_proc);
+
+    if (process->shm =3D=3D NULL) {
+        process->shm =3D 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 =3D 0; i < list_size(shm_table); i++) {
-        if (((shm_table_entry_t *)list_get_element_at(shm_table, i))->id =
=3D=3D id) {
-            shm_table_entry_t *shmem =3D (shm_table_entry_t *)list_get_ele=
ment_at(shm_table, i);
-            //Pages suchen
-            vaddr_t vaddr =3D find_contiguous_pages(task->cr3, shmem->page=
count,
-                USER_MEM_START, USER_MEM_END);
-            //Pages mappen
-            for (j =3D 0; j < shmem->pagecount; j++) {
-                map_page(task->cr3, vaddr + j * PAGE_SIZE, shmem->addresse=
s[j],
-                    PTE_P | PTE_U | PTE_W);
-               =20
-            }
-            shmem->usecount++;
-            list_push(task->shmids, (void*)id);
-            list_push(task->shmaddresses, vaddr);
-            return vaddr;
+    struct shm_desc* shm =3D tree_search(shms, id);
+    struct shm_process* shm_proc;
+    int i;
+
+    if (shm =3D=3D NULL) {
+        return;
+    }
+
+    // Aus der SHM-Liste des Prozesses austragen
+    for (i =3D 0; (shm_proc =3D list_get_element_at(process->shm, i)); i++=
) {
+        if (shm_proc->shm =3D=3D shm) {
+            list_remove(process->shm, i);
+            break;
+        }
+    }
+
+    // Aus der Prozessliste des SHM austragen
+    for (i =3D 0; (shm_proc =3D list_get_element_at(shm->processes, i)); i=
++) {
+        if (shm_proc->process =3D=3D 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 =3D 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 =3D NULL;
+        tree_remove(shms, shm);
+    }
+
+    // Virtuellen Speicher freigeben
+    mmc_unmap(&process->context, shm_proc->vaddr, shm->num_pages);
+
+
+    free(shm_proc);
+    if (shm->processes =3D=3D 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=C3=A4ge suchen
-    for (i =3D 0; i < list_size(task->shmids); i++) {
-        if ((uint32_t)list_get_element_at(task->shmids, i) =3D=3D id) {
-            vaddr_t vaddr =3D list_get_element_at(task->shmaddresses, i);
-            for (j =3D 0; j < list_size(shm_table); j++) {
-                if (((shm_table_entry_t *)list_get_element_at(shm_table, j=
))->id =3D=3D id) {
-                    shm_table_entry_t *shmem =3D (shm_table_entry_t *)list=
_get_element_at(shm_table, j);
-                    //Pages des Tasks freimachen
-                    for (k =3D 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=C3=B6tigt
-                        for (k =3D 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 =3D tree_search(shms, id);
+
+    if (shm =3D=3D 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 =3D=3D NULL) {
+        return;
+    }
+
+    while ((shm_proc =3D list_get_element_at(process->shm, 0))) {
+        shm_detach(process, shm_proc->shm->id);
+    }
+
+    list_destroy(process->shm);
 }
diff --git a/src/kernel/src/module.mk b/src/kernel/src/module.mk
new file mode 100644
index 00000000..8b035051
--- /dev/null
+++ b/src/kernel/src/module.mk
@@ -0,0 +1,16 @@
+### Kernel=0D
+kernel: build/lost2.krn=0D
+=0D
+KERNEL2_SRC =3D $(call SOURCE_FILES_WILDCARD,src/kernel/src/arch/$(ARCH)) =
$(call SOURCE_FILES_WILDCARD,src/kernel/src/arch/$(ARCH)/*) $(call SOURCE_F=
ILES,src/kernel/src) $(call SOURCE_FILES_WILDCARD,src/kernel/src/*)=0D
+KERNEL2_OBJS =3D $(call OBJECT_FILES,$(KERNEL2_SRC))=0D
+ALL_OBJS +=3D $(KERNEL2_OBJS)=0D
+build/lost2.krn: $(KERNEL2_OBJS) src/lib/library.a=0D
+	ld -o $@ $(LDFLAGS_KERNEL2) $^=0D
+build/lost2.krn: CPPFLAGS +=3D -Isrc/kernel/include -Isrc/kernel/include/a=
rch/$(ARCH)=0D
+=0D
+zkernel: build/lost2.kgz=0D
+=0D
+src/kernel/src/smp/rm_trampoline.o: src/kernel/src/smp/rm_trampoline.asm=
=0D
+	$(NASM) -f bin $< -o $(notdir $@)=0D
+	$(OBJCOPY) -B i386:i386 -I binary -O elf32-i386 $(notdir $@) $@=0D
+	rm $(notdir $@)=0D
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 @@
-/* =20
- * 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 softwar=
e
- *    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=20
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */ =20
-
-#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=20
- * unterstuetzt.
- *
- * @param elf_header Pointer auf den ELF-Header
- */
-void load_init_module(struct multiboot_info * multiboot_info)
-{
-    struct multiboot_module * multiboot_module;
-   =20
-    //Ueberpruefen, ob ueberhaupt module in der Liste sind
-    if (multiboot_info->mi_mods_count =3D=3D 0)
-    {
-        panic("Keine Multiboot-Module zu laden.");
-    }
-   =20
-   =20
-    //Multiboot-Modulliste in den Kerneladressraum mappen
-    multiboot_module =3D map_phys_addr((paddr_t)multiboot_info->mi_mods_ad=
dr, sizeof(multiboot_module));
-    if (multiboot_module =3D=3D NULL)   =20
-    {
-        panic("Konnte Multiboot-Modulliste nicht in den Kernelspeicher map=
pen.");
-    }
-   =20
-    //Befehlszeile des Moduls mappen
-    char* cmdline =3D map_phys_addr((paddr_t) multiboot_module->cmdline, 4=
096);
-
-    //Das Modul dem ELF-Loader uebergeben
-    void* elf_image =3D 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->st=
art);
-   =20
-    //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));
-   =20
-    //In der Multiboot Struct den Pointer und die anzahl der Module anpass=
en,
-    // 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;
-   =20
-    //Ueberpruefen, ausser dem=20
-    if (multiboot_info->mi_mods_count =3D=3D 0)
-    {
-        //Ist hier ein Panic wirklich das richtige?
-        panic("Keine Multiboot-Module zu laden.");
-    }
-    else
-    {
-        multiboot_module_phys =3D multiboot_info->mi_mods_addr;
-       =20
-        // Speicher f=EF=BF=BDr die Modulparameter
-        paddr_t mod_cmdline_page_phys =3D phys_alloc_page();
-        void* mod_cmdline_task =3D 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);
-       =20
-        char* mod_cmdline_page =3D map_phys_addr(mod_cmdline_page_phys, PA=
GE_SIZE);
-        char* mod_cmdline =3D mod_cmdline_page;
-        size_t mod_cmdline_free =3D PAGE_SIZE;
-
-        //Speicher f=EF=BF=BDr die Modulliste allokieren und=20
-        void* mod_list_task =3D find_contiguous_pages((page_directory_t)fi=
rst_task->cr3, 1, USER_MEM_START, USER_MEM_END);
-        paddr_t mod_list_phys =3D phys_alloc_page();
-        map_page((page_directory_t)first_task->cr3, mod_list_task, mod_lis=
t_phys, PTE_P | PTE_U | PTE_W);
-       =20
-       =20
-        //Stack von Init mappen um ein Pointer auf die Modulliste zu ueber=
geben
-        uint32_t* stack =3D (uint32_t*) ((uint32_t)map_phys_addr(resolve_v=
addr((page_directory_t)first_task->cr3, first_task->user_stack_bottom), 0x1=
000) - 0);
-        stack[255] =3D (uint32_t)mod_list_task;
-        free_phys_addr((vaddr_t)stack, 0x1000);
-       =20
-        //Modulliste temporaer mappen
-        uint32_t* modulelist =3D (uint32_t*) map_phys_addr(mod_list_phys, =
0x1000);
-       =20
-        //Das unterste dword auf der Page mit der Liste beinhaltet die Anz=
ahl der Module
-        modulelist[0] =3D multiboot_info->mi_mods_count;
-       =20
-        //Module in den Adressraum von Init mapen
-        for (i =3D 0; i < multiboot_info->mi_mods_count; i++)
-        {
-            //Die multiboot_module Struct des aktuellen Moduls mappen
-            multiboot_module =3D map_phys_addr((paddr_t)multiboot_module_p=
hys, sizeof(multiboot_module));
-           =20
-            //Anzahl der benoetigten Pages berechnen
-            size_t pages =3D (PAGE_ALIGN_ROUND_UP((uint32_t)multiboot_modu=
le->end) -PAGE_ALIGN_ROUND_DOWN((uint32_t)multiboot_module->start)) / 0x100=
0;
-           =20
-            //Freie virtuelle Adresse suchen um das Modul dort hin zu mapp=
en.
-            void* dest =3D find_contiguous_pages((page_directory_t)first_t=
ask->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 +=3D pages * 0x1000;
-
-            //TODO: Den Speicher aus dem Kerneladressraum unmappen
-          =20
-            //Die Adresse in die Modulliste von Init schreiben
-            modulelist[1 + (3*i)] =3D (uint32_t) dest;
-            modulelist[2 + (3*i)] =3D multiboot_module->end - multiboot_mo=
dule->start;
-            modulelist[3 + (3*i)] =3D (uint32_t) mod_cmdline_task + (mod_c=
mdline - mod_cmdline_page);
-
-            // Modellbefehlszeile kopieren
-            char* cmdline =3D map_phys_addr((paddr_t) multiboot_module->cm=
dline, 4096);
-            size_t length =3D strlen(cmdline);
-            if (mod_cmdline_free > length) {
-                strncpy(mod_cmdline, cmdline, length);
-                mod_cmdline[length] =3D '\0';
-                mod_cmdline +=3D (length + 1);
-                mod_cmdline_free -=3D (length + 1);
-            }
-            free_phys_addr(cmdline, 4096);
-           =20
-            //multiboot_module Struct wieder freigeben
-            free_phys_addr((vaddr_t)multiboot_module, sizeof(multiboot_mod=
ule));
-           =20
-            //Physikalische Adresse der  multiboot_module Struct auf die n=
aechste setzen
-            multiboot_module_phys++;
-        }
-       =20
-        //Die temporaer gemapte Modulliste wieder freigeben(nur hier im Ke=
rnel freigeben)
-        free_phys_addr((vaddr_t)modulelist, 0x1000);
-        free_phys_addr(mod_cmdline_page, 0x1000);
-    }
-   =20
-    //TODO: Muessen noch irgendwelche Multiboot-Structs physikalisch freig=
egeben werden?
-} =20
-
-
-/**
- * Ein einzelnes ELF-Image laden und den Prozess erstellen.
- *
- * @param elf_header Pointer auf den ELF-Header. Es wird erwartet, dass da=
s
- * gesamte ELF-Image gemappt ist.
- */
-void load_single_module(Elf32_Ehdr * elf_header, const char* cmdline)=20
-{
-    Elf32_Phdr * program_header;
-    uint32_t i, j;
-    uint32_t pages;
-
-    struct task * task =3D NULL;
-    vaddr_t address, base, dst;
-    paddr_t phys_dst;
-
-    //kprintf("[ehdr: %x]", elf_header);
-
-    if (elf_header->e_magic =3D=3D ELF_MAGIC) {
-       =20
-        program_header =3D (Elf32_Phdr *) ((uint32_t) elf_header + elf_hea=
der->e_phoff);
-
-#ifdef DEBUG
-        kprintf("    EntryCount: %d", elf_header->e_phnum);
-        kprintf("    Offset: 0x%x\n", elf_header->e_phoff);
-#endif
-
-        for (i =3D 0; i < elf_header->e_phnum; i++, program_header++) {
-
-#ifdef DEBUG
-            kprintf(" ph @ %x, type=3D%d\n", program_header, program_heade=
r->p_type);
-#endif
-            if (program_header->p_type =3D=3D 1) {
-               =20
-              	if ((elf_header->e_entry >=3D program_header->p_vaddr) && (=
elf_header->e_entry <=3D program_header->p_vaddr + program_header->p_memsz)=
) {
-#ifdef DEBUG
-                    kprintf("Neuen Task erstellen\n");
-#endif
-                    task =3D create_task((vaddr_t) elf_header->e_entry, cm=
dline, 0);
-                } else if (task =3D=3D NULL) {
-					// FIXME
-					kprintf("Kein Task: phdr->vaddr =3D %x, ehdr->entry =3D %x\nDas Modul=
 ist entweder beschaedigt oder wird von diesem Kernel nicht unterstuetzt (E=
ntry Point muss im ersten Program Header liegen)\n", program_header->p_vadd=
r, elf_header->e_entry);
-                    continue;
-                }
-               =20
-                // Pages erstellen
-                pages =3D 1 + ((program_header->p_offset + program_header-=
>p_memsz) / 0x1000) - (program_header->p_offset / 0x1000);
-               =20
-#ifdef DEBUG
-                kprintf("Mapping von %d Pages\n", pages);
-#endif
-                base =3D (vaddr_t) PAGE_ALIGN_ROUND_DOWN(program_header->p=
_vaddr);
-                if (base < MODULE_ENTRY) {
-                    base =3D MODULE_ENTRY;
-                }
-
-                for (j =3D 0; j < pages; j++) {
-                    paddr_t curPage =3D phys_alloc_page();
-#ifdef DEBUG
-                    kprintf("  %x =3D> %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 =3D 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
-               =20
-               =20
-                uint32_t bytes_on_first_page;
-                if (program_header->p_filesz > 0x1000 - (program_header->p=
_vaddr % 0x1000)) {
-                    bytes_on_first_page =3D 0x1000 - (program_header->p_va=
ddr % 0x1000);
-                } else {
-                    bytes_on_first_page =3D program_header->p_filesz;
-                }
-
-                uint32_t zero_bytes_on_last_page =3D 0x1000 - (
-                    (program_header->p_offset + program_header->p_filesz)=
=20
-                    % 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_l=
ast_page);
-#endif
-
-                // Erste Page kopieren (m=EF=BF=BDglicherweise fangen die =
Daten mitten in der
-                // Page an)
-                address =3D (vaddr_t) ((uint32_t) elf_header + program_hea=
der->p_offset);
-                phys_dst =3D resolve_vaddr((page_directory_t) task->cr3, (=
vaddr_t) program_header->p_vaddr);
-                dst =3D 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 +=3D bytes_on_first_page;
-                for (j =3D 1; j < pages; j++) {
-                    //address =3D map_phys_addr(phys_address, 0x1000);
-
-                    phys_dst =3D resolve_vaddr((page_directory_t) task->cr=
3, (vaddr_t) (base + 0x1000 * j));
-                    dst =3D map_phys_addr(phys_dst, 0x1000);
-#ifdef DEBUG
-                    kprintf("  Kopiere 4K nach %x von %x\n", (base + 0x100=
0 * j), address);
-#endif
-                    memcpy(dst, address, 0x1000);
-
-                    free_phys_addr(dst, 0x1000);
-                    //free_phys_addr(address, 0x1000);
-
-                    address +=3D 0x1000;               =20
-                }
-
-                if (zero_bytes_on_last_page) {
-                    // Es ist ein Teilst=EF=BF=BDck einer Page =EF=BF=BDbr=
ig, das mit Nullen gef=EF=BF=BDllt wird
-#ifdef DEBUG
-                    kprintf("  Setze Nullen in 0x%x (0x%x Stueck)\n",=20
-                            (vaddr_t) (base + 0x1000 * (j - 1)) + (0x1000 =
- zero_bytes_on_last_page),=20
-                            zero_bytes_on_last_page);
-#endif
-
-                    phys_dst =3D resolve_vaddr(
-                        (page_directory_t) task->cr3,=20
-                        (vaddr_t) (base + 0x1000 * (j - 1)) + (0x1000 - ze=
ro_bytes_on_last_page)
-                    ) /*(bytes_on_last_page)*/;
-
-                    dst =3D map_phys_addr(phys_dst, zero_bytes_on_last_pag=
e);
-                    memset(dst, 0, zero_bytes_on_last_page);
-                    free_phys_addr(dst, zero_bytes_on_last_page);
-                }
-               =20
-                // Wenn memsz > filesz. mu=EF=BF=BD mit Nullen aufgef=EF=
=BF=BDllt werden
-                pages =3D program_header->p_memsz / 0x1000;
-                if (program_header->p_memsz % 0x1000) {
-                    pages++;
-                }
-                for (; j < pages; j++) {
-                    phys_dst =3D resolve_vaddr((page_directory_t) task->cr=
3, (vaddr_t) (base + 0x1000 * j));
-                    dst =3D 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);
-                }
-               =20
-#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 @@
-/* =20
- * 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 softwar=
e
- *    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=20
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */ =20
-
-#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=EF=BF=BDhrt 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=EF=
=BF=BD von
- * esp bis esp + metadata_size die Metadaten liegen, von esp + metadata_si=
ze
- * bis esp + metadata_size + data_size die Nutzdaten. Daraus ergibt sich
- * insbesondere, da=EF=BF=BD sich die Grenze zwischen Metadaten und Daten =
beliebig=20
- * ziehen l=EF=BF=BD=EF=BF=BDt, wie sie f=EF=BF=BDr den Aufrufer am g=EF=
=BF=BDnstigsten ist. Unter anderem ist
- * es m=EF=BF=BDglich, alle Daten an einem Ort zu =EF=BF=BDbergeben und me=
tadata_size =3D 0 zu
- * setzen.
- *
- * Im Allgemeinen liegen allerdings die Metadaten auf dem Stack des Aufruf=
ers,
- * w=EF=BF=BDhrend die Nutzdaten oft ein Pointer in den Heap des Aufrufers=
 sind.
- *
- * Zur Durchf=EF=BF=BDhrung eines RPC werden zun=EF=BF=BDchst einige Regis=
ter des aufgerufenen
- * Tasks gesichtert (eax, eip, esp, eflags; die =EF=BF=BDbrigen Register h=
at der
- * aufgerufene Task selbst zu sichern). Anschlie=EF=BF=BDend werden die Da=
ten auf den
- * Stack des aufgerufenen Tasks gelegt, eip auf den RPc-Handler gesetzt un=
d der
- * Scheduler angewiesen, zum aufgerufenen Task umzuschalten.
- *
- * Der RPC-Handler mu=EF=BF=BD als letzte Aktion den Syscall FASTRPC_RET a=
ufrufen, der
- * die Register wiederherstellt und dadurch den R=EF=BF=BDcksprung vornimm=
t.
- *
- * @param callee        Aufzurufender Task
- * @param metadata_size L=EF=BF=BDnge der Metadaten in Bytes
- * @param metadata      Pointer auf die Metadaten
- * @param data_size     L=EF=BF=BDnger der Daten in Bytes
- * @param data          Pointer auf die Daten
- *
- * @return true, wenn der Aufruf erfolgreich durchgef=EF=BF=BDhrt wurde, f=
alse
- * sonst. Bei false als R=EF=BF=BDckgabe sollte der aufrufende Task den RP=
C-Syscall
- * wiederholen.
- */
-bool fastrpc(struct task * callee, uint32_t metadata_size, void* metadata,
-    uint32_t data_size, void* data)
-{
-    int i;
-
-    //kprintf("[%d =3D> %d, 0x%x + 0x%x]\n", current_task->pid, callee->pi=
d,=20
-    //    metadata_size, data_size);
-    //kprintf("<%08x =3D %08x %08x>\n", metadata, 0, 0);
-   =20
-    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;
-    }
-   =20
-    if (callee->rpc_handler =3D=3D NULL) {
-        return false;
-    }
-
-    // Gesamtgr=EF=BF=BD=EF=BF=BDe, um die der Stack des aufgerufenen Proz=
esses vergr=EF=BF=BD=EF=BF=BDert
-    // wird (zus=EF=BF=BDtzlich 4 Bytes f=EF=BF=BDr die R=EF=BF=BDcksprung=
adresse)
-    uint32_t total_data_size =3D metadata_size + data_size
-        + sizeof(data_size) + sizeof(pid_t);
-   =20
-    // Datengr=EF=BF=BD=EF=BF=BDe auf ganze vier Bytes aufrunden
-    uint32_t rounded_data_size =3D (total_data_size + 3) & ~0x3;
-
-    // Wenn es sich um eine Antwort im Rahmen von asynchronem RPC handelt,
-    // durchlassen, auch wenn der Proze=EF=BF=BD nicht blockiert werden ka=
nn
-    bool ignore_blocked =3D false;
-    if ((callee->status =3D=3D TS_WAIT_FOR_RPC) && (
-                ((metadata_size >=3D 4)=20
-            &&  (((uint32_t*)metadata)[0] =3D=3D 513))
-
-        ||      ((metadata_size =3D=3D 0)=20
-            &&  (data_size >=3D 4)=20
-            &&  (((uint32_t*)data)[0] =3D=3D 513))
-        ))
-    {
-        ignore_blocked =3D true;
-    }
-
-    // W=EF=BF=BDhrend wir am Stack rumbasteln, sollte niemand dazwischenf=
unken und
-    // erst recht nicht der Task weiterlaufen (momentan unn=EF=BF=BDtig, d=
a im Kernel
-    // keine Interrupts erlaubt sind). Au=EF=BF=BDerdem wird damit sicherg=
estellt, da=EF=BF=BD
-    // ein Task, der p() aufgerufen hat, keinen RPC bekommt.
-    //
-    // Wenn der Task nicht blockiert werden kann, soll der Aufrufer es sp=
=EF=BF=BDter
-    // nochmal versuchen.
-    if (!ignore_blocked &&=20
-        ((callee->blocked_by_pid) || !block_task(callee, current_task->pid=
)))
-    {
-        //kprintf("Task %d ist blockiert.\n", callee->pid);
-        return false;
-    }
-   =20
-    // Falls der Stack nicht ausreicht, vergr=EF=BF=BD=EF=BF=BDern
-    paddr_t callee_isf_phys =3D=20
-        resolve_vaddr((page_directory_t) callee->cr3, (vaddr_t) callee->es=
p);
-
-    struct int_stack_frame* callee_isf =3D (struct int_stack_frame*)=20
-        map_phys_addr(callee_isf_phys, sizeof(callee_isf));
-   =20
-    uint32_t pages_count =3D ((rounded_data_size + PAGE_SIZE - 1) / PAGE_S=
IZE);
-    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) =3D=3D (paddr_t) NU=
LL)
-	{
-        // TODO Das k=EF=BF=BDnnte bis zu (pages_count - 1) Pages zu viel =
reservieren
-		increase_user_stack_size(callee, pages_count);
-	}
-   =20
-    // Den Stack des aufgerufenen Tasks in den Kernelspeicher mappen
-    uint32_t callee_esp_phys =3D (uint32_t) resolve_vaddr(
-        (page_directory_t) callee->cr3, (vaddr_t) callee_isf->esp);
-  =20
-    // TODO Funktion, um komplette Bereiche eines anderen Tasks zu mappen
-    vaddr_t callee_esp_kernel_pages =3D=20
-        find_contiguous_kernel_pages(pages_count);
-
-    for (i =3D 0; i < pages_count; i++) {
-        map_page(
-            kernel_page_directory,=20
-            (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,=20
-                (vaddr_t) callee_isf->esp - (PAGE_SIZE * (pages_count - i =
- 1))
-            )),
-            PTE_P | PTE_W
-        );
-    }
-
-    // RPC-Backlinkinformation anlegen
-    rpc_t* rpc =3D malloc(sizeof(rpc_t));
-   =20
-    rpc->old_eip =3D callee_isf->eip;
-    rpc->old_esp =3D callee_isf->esp;
-    rpc->eax     =3D callee_isf->eax;
-    rpc->eflags  =3D callee_isf->eflags;
-    rpc->caller  =3D current_task;
-
-    rpc->reenable_irq =3D 0;
-
-    list_push(callee->rpcs, rpc);
-   =20
-    // Adresse des neuen Stackendes im Kernelspeicher berechnen. Diese Adr=
esse
-    // liegt irgendwo in der Mitte der ersten gemappten Stackpage. Das Off=
set
-    // von der Pagegrenze ist also in der Rechnung zu ber=EF=BF=BDcksichti=
gen.
-    //
-    // Auf den Stack kommen neue Daten der Gr=EF=BF=BD=EF=BF=BDe rounded_d=
ata_size.
-    vaddr_t callee_esp =3D callee_esp_kernel_pages
-        + (callee_esp_phys % PAGE_SIZE) + ((pages_count - 1) * PAGE_SIZE);
-
-    callee_esp -=3D rounded_data_size;
-
-    // Kopieren der Datengr=EF=BF=BD=EF=BF=BDe, der Aufrufer-PID und der D=
aten auf den Stack
-    *((uint32_t *) callee_esp) =3D data_size + metadata_size;
-    *((uint32_t *) (callee_esp + 4)) =3D current_task->pid;
-    memcpy(callee_esp + 8, metadata, metadata_size);
-    memcpy(callee_esp + 8 + metadata_size, data, data_size);
-   =20
-    // Den Stackpointer des aufgerufenen Tasks anpassen, so da=EF=BF=BD er=
 auf den=20
-    // Anfang der kopierten Daten zeigt, und in den RPC-Handler springen
-    callee_isf->esp -=3D rounded_data_size;
-    callee_isf->eip =3D (uint32_t) callee->rpc_handler;
-
-    // Gemappte Seiten wieder freigeben
-    for (i =3D 0; i < pages_count; i++) {
-        unmap_page(kernel_page_directory,=20
-            (vaddr_t) ((uint32_t) callee_esp_kernel_pages + (PAGE_SIZE * i=
)));
-    }
-
-    unmap_page(kernel_page_directory,=20
-        (vaddr_t) PAGE_ALIGN_ROUND_DOWN((uint32_t) callee_isf));
-  =20
-    // Der Task darf wieder laufen
-    if (callee->status =3D=3D TS_WAIT_FOR_RPC) {
-        callee->status =3D TS_RUNNING;
-    }
-
-    if (!ignore_blocked) {
-        //kprintf("PID %d darf wieder laufen.\n", callee->pid);
-        unblock_task(callee, current_task->pid);
-    }
-
-    return true;
-}
-
-/**
- * F=EF=BF=BDhrt einen RPC zur Behandlung eines IRQ durch. Der IRQ wird da=
bei
- * deaktiviert, solange der Handler arbeitet und erst anschlie=EF=BF=BDend=
=20
- * wieder freigegeben. Im sonstigen Verhalten gleicht diese Funktion
- * fastrpc.
- *
- * @see fastrpc
- */
-bool fastrpc_irq(struct task * callee, uint32_t metadata_size, void* metad=
ata,
-    uint32_t data_size, void* data, uint8_t irq)
-{
-    if (callee->blocked_by_pid && (callee->status !=3D TS_WAIT_FOR_RPC)) {
-        return false;
-    }
-
-    if (fastrpc(callee, metadata_size, metadata, data_size, data)) {
-        rpc_t* rpc =3D list_get_element_at(current_task->rpcs, 0);
-        rpc->reenable_irq =3D irq;
-        return true;
-    } else {
-        return false;
-    }
-}
-
-/**
- * Wird nach der Ausf=EF=BF=BDhrung eines RPC-Handlers aufgerufen.
- *
- * Nach der R=EF=BF=BDckkehr vom RPC-Handler wird der neueste Zustand vom =
RPC-Stack
- * gepopt und zur Wiederherstellung des urspr=EF=BF=BDnglichen Prozessorzu=
stands
- * benutzt.
- *
- * Dies betrifft eip, esp, eax und eflags. Die =EF=BF=BDbrigen Register si=
nd vom
- * RPC-Handler zu sicher und vor dem Aufruf von SYSCALL_FASTRPC_RET
- * wiederherzustellen. eax ist davon ausgenommen, da es die Funktionsnumme=
r
- * des Syscalls enthalten mu=EF=BF=BD.
- *
- * @param esp Interrupt-Stackframe des vom RPC-Handler zur=EF=BF=BDckkehre=
nden Tasks
- */
-void return_from_rpc(struct int_stack_frame ** esp)
-{
-    rpc_t* rpc =3D list_pop(current_task->rpcs);
-    struct int_stack_frame* callee_isf =3D *esp;
-
-    // Wenn der Task vom RPC-Handler zur=EF=BF=BDckkehrt, obwohl der Handl=
er
-    // gar nicht aufgerufen wurde, l=EF=BF=BDuft was schief
-    if (rpc =3D=3D 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");
-    }
-   =20
-    // Wiederherstellen der Register
-    callee_isf->eip =3D rpc->old_eip;=20
-    callee_isf->esp =3D rpc->old_esp;
-    callee_isf->eax =3D rpc->eax;=20
-    callee_isf->eflags =3D 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 been=
det
- * wird, bevor der RPC fertig ist. Ansonsten zeigt rpc->caller ins Leere,
- * was in return_from_rpc() zur Katastrophe f=EF=BF=BDhrt.
- */
-void rpc_destroy_task_backlinks(struct task* destroyed_task)
-{
-    struct task* task;
-    for (task =3D first_task; task !=3D NULL; task =3D task->next_task) {
-        int i;
-        rpc_t* rpc;
-        for (i =3D 0; (rpc =3D list_get_element_at(task->rpcs, i)); i++) {
-            if (rpc->caller =3D=3D destroyed_task) {
-                rpc->caller =3D 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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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 =3D NULL;
-struct task* current_task =3D NULL;
-int num_tasks;
-int current_task_num;
-
-/** Einheit: Mikrosekunden */
-uint64_t timer_ticks =3D 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 +=3D 1000000 / CONFIG_TIMER_HZ;
-
-    //Ueberpruefen, ob der aktuelle Task alle seine Zeit verbraucht hat. W=
enn
-    // ja, wird ein neuer Task ausgewaehlt
-    #ifndef CONFIG_COOPERATIVE_MULTITASKING
-    if ((current_task =3D=3D NULL) ||
-        (--(current_task->schedule_ticks_left) >=3D 0))
-    {
-        schedule(esp);
-    }
-    #else
-    if (current_task =3D=3D NULL) {
-        schedule(esp);
-    }
-    #endif
-
-
-    // Ueberpruefen, ob ein Timer abgelaufen ist.
-    // Dies muss nach dem schedule() kommen, da der Timer mit current_task=
 =3D=3D
-    // 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 =3D=3D NULL) {
-        panic("Taskliste leer!");
-    }
-
-    if (current_task !=3D NULL) {
-        //kprintf("\nSwitch from %d", current_task->pid);
-        current_task->esp =3D *esp;
-    } else {
-        current_task =3D first_task;
-    }
-
-    struct task* old_task =3D current_task;
-
-    do {
-        current_task =3D current_task->next_task;
-       =20
-        if(current_task =3D=3D NULL) {
-            current_task =3D first_task;
-        }
-
-        if (current_task =3D=3D old_task) {
-            kprintf("%");
-            break;
-        }
-
-    } while(((current_task->blocked_by_pid)=20
-        && (current_task->blocked_by_pid !=3D current_task->pid))
-        || (current_task->status !=3D TS_RUNNING)
-    );
-   =20
-    // Damit der Task die Zeit nicht beliebig hochspielen kann
-    if (current_task->schedule_ticks_left > current_task->schedule_ticks_m=
ax) {
-        current_task->schedule_ticks_left =3D current_task->schedule_ticks=
_max;
-    }
-
-    // Hier wird die CPU-Zeit berechnet, die der Task benutzen darf
-    // Diese wird folgendermassen berechnet:
-    // Benutzbare Ticks =3D Maximale Ticks + (Uebrige Ticks vom letzten Ma=
l) / 2
-    current_task->schedule_ticks_left =3D current_task->schedule_ticks_max=
 +
-        current_task->schedule_ticks_left / 2;
-
-    //kprintf("\nSwitch to %d", current_task->pid);
-    *esp =3D 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 =3D TSS_IO_BITMAP_NOT_LOADED;
-}
-
-void schedule_to_task(struct task* target_task, uint32_t* esp)
-{
-    if ((target_task !=3D NULL) && ((!target_task->blocked_by_pid) || (tar=
get_task->blocked_by_pid =3D=3D target_task->pid))) {
-        current_task->esp =3D *esp;
-        current_task =3D target_task;
-        *esp =3D current_task->esp;
-       =20
-        tss.io_bit_map_offset =3D TSS_IO_BITMAP_NOT_LOADED;
-    }
-}
-
-void set_io_bitmap()
-{
-    tss.io_bit_map_offset =3D 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);
-   =20
-    num_tasks =3D 0;
-    current_task =3D NULL;
-    first_task =3D NULL;
-   =20
-    uint16_t reload_value =3D 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/Makefil=
e.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 @@
-;=0D
-; Copyright (c) 2006 The tyndur Project. All rights reserved.=0D
-;=0D
-; This code is derived from software contributed to the tyndur Project=0D
-; by Burkhard Weseloh.=0D
-;=0D
-; Redistribution and use in source and binary forms, with or without=0D
-; modification, are permitted provided that the following conditions=0D
-; are met:=0D
-; 1. Redistributions of source code must retain the above copyright=0D
-;    notice, this list of conditions and the following disclaimer.=0D
-; 2. Redistributions in binary form must reproduce the above copyright=0D
-;    notice, this list of conditions and the following disclaimer in the=
=0D
-;    documentation and/or other materials provided with the distribution.=
=0D
-; 3. All advertising materials mentioning features or use of this software=
=0D
-;    must display the following acknowledgement:=0D
-;     This product includes software developed by the tyndur Project=0D
-;     and its contributors.=0D
-; 4. Neither the name of the tyndur Project nor the names of its=0D
-;    contributors may be used to endorse or promote products derived=0D
-;    from this software without specific prior written permission.=0D
-;=0D
-; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=0D
-; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMI=
TED=0D
-; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICUL=
AR=0D
-; PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=0D
-; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=0D
-; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=0D
-; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFI=
TS;=0D
-; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,=
=0D
-; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=0D
-; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=0D
-; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0D
-;=0D
-=0D
-section .text=0D
-=0D
-%define IRQ_BASE 0x20=0D
-=0D
-extern handle_int=0D
-=0D
-%macro exception_stub 1=0D
-global exception_stub_%1=0D
-exception_stub_%1:=0D
-	push dword 0=0D
-	push dword %1=0D
-	jmp int_bottom=0D
-%endmacro=0D
-=0D
-%macro exception_stub_error_code 1=0D
-global exception_stub_%1=0D
-exception_stub_%1:=0D
-	push dword %1=0D
-	jmp int_bottom=0D
-%endmacro=0D
-=0D
-%macro irq_stub 1=0D
-global irq_stub_%1=0D
-irq_stub_%1:=0D
-	push dword 0=0D
-	push dword %1 + IRQ_BASE=0D
-	jmp int_bottom=0D
-%endmacro=0D
-=0D
-global null_handler=0D
-null_handler:=0D
-	push dword 0=0D
-	push dword 0x1337=0D
-	jmp int_bottom=0D
-=0D
-global syscall_stub=0D
-syscall_stub:=0D
-  push dword 0=0D
-  push dword 0x30=0D
-	jmp int_bottom=0D
-=0D
-exception_stub 0=0D
-exception_stub 1=0D
-exception_stub 2=0D
-exception_stub 3=0D
-exception_stub 4=0D
-exception_stub 5=0D
-exception_stub 6=0D
-exception_stub 7=0D
-exception_stub_error_code 8=0D
-exception_stub 9=0D
-exception_stub_error_code 10=0D
-exception_stub_error_code 11=0D
-exception_stub_error_code 12=0D
-exception_stub_error_code 13=0D
-exception_stub_error_code 14=0D
-exception_stub 16=0D
-exception_stub_error_code 17=0D
-exception_stub 18=0D
-exception_stub 19=0D
-=0D
-irq_stub 0=0D
-irq_stub 1=0D
-irq_stub 2=0D
-irq_stub 3=0D
-irq_stub 4=0D
-irq_stub 5=0D
-irq_stub 6=0D
-irq_stub 7=0D
-irq_stub 8=0D
-irq_stub 9=0D
-irq_stub 10=0D
-irq_stub 11=0D
-irq_stub 12=0D
-irq_stub 13=0D
-irq_stub 14=0D
-irq_stub 15=0D
-=0D
-int_bottom:=0D
-	; register sichern=0D
-	pusha=0D
-	push ds=0D
-	push es=0D
-	push fs=0D
-	push gs=0D
-=0D
-	; ring 0 segment register laden=0D
-	cld=0D
-	mov ax, 0x10=0D
-	mov ds, ax=0D
-	mov es, ax=0D
-=0D
-	; c-handler aufrufen=0D
-	push esp=0D
-	call handle_int=0D
-	add esp, 4=0D
-=0D
-	; den stack wechseln=0D
-	mov esp, eax=0D
-	=0D
-	; register laden=0D
-	pop gs=0D
-	pop fs=0D
-	pop es=0D
-	pop ds=0D
-	popa=0D
-=0D
-	add esp, 8 ; fehlercode und interrupt nummer =EF=BF=BDberspringen=0D
-=0D
-	iret=0D
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 @@
-/* =20
- * 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=20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
+ * 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 PROF=
ITS;
+ * 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.
- */ =20
+ */
=20
+#include <types.h>
 #include <stdint.h>
-#include <stdbool.h>
-#include <errno.h>
=20
-#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"
=20
-extern void set_io_bitmap(void);
+#include "kernel.h"
=20
-#ifdef CONFIG_DEBUG_LAST_SYSCALL
-uint32_t debug_last_syscall_no =3D 0;
-pid_t debug_last_syscall_pid =3D 0;
-uint32_t debug_last_syscall_data[DEBUG_LAST_SYSCALL_DATA_SIZE] =3D { 0 };
-#endif=20
+syscall_t syscalls[SYSCALL_MAX];
=20
-void syscall(struct int_stack_frame ** esp)=20
+/**
+ * Die Syscalls initialisieren.
+ */
+void syscall_init()
 {
-    struct int_stack_frame * isf =3D *esp;
-
-    #ifdef CONFIG_DEBUG_LAST_SYSCALL
-    {
-        uint32_t i;
-        debug_last_syscall_no =3D isf->eax;
-        debug_last_syscall_pid =3D current_task->pid;
-        for (i =3D 0; i < DEBUG_LAST_SYSCALL_DATA_SIZE; i++) {
-            debug_last_syscall_data[i] =3D *(((uint32_t*)isf->esp) + i);
-        }
-    }
-    #endif=20
-
-   =20
-    if (debug_test_flag(DEBUG_FLAG_SYSCALL)) {
-        kprintf("[PID %d] Syscall:%d\n", current_task->pid, isf->eax);
-        io_ports_check(current_task);
-    }
-       =20
-    // FIXME: Adressen, die vom aufrufenden Programm kommen,=20
-    // vor der Verwendung pr=EF=BF=BDfen
-    switch (isf->eax) {
-        case SYSCALL_PUTSN:
-        {
-            unsigned int n =3D *((int*) isf->esp);
-            char * s =3D *((char**) (isf->esp + 4));
-
-            if(n =3D=3D -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 =3D PAGE_ALIGN_ROUND_UP(*((size_t*) isf->esp)) >> 12;
-            flags =3D *((uint32_t*) (isf->esp + 4));
-            paddr_t* phys =3D *((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);
-           =20
-            // TODO: Flags ber=EF=BF=BDcksichtigen
-            vaddr =3D find_contiguous_pages((page_directory_t) current_tas=
k->cr3, num, USER_MEM_START, USER_MEM_END);
-            isf->eax =3D (uint32_t) vaddr;
-           =20
-            current_task->memory_used +=3D num << 12;
-
-            //DMA-Page
-            if((flags & 0x80) !=3D 0)
-            {
-                paddr =3D phys_alloc_dma_page_range_64k(num);
-              =20
-                //Bei DMA-Pages die phys. Adresse in ebx speichern
-                *phys =3D 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-Speic=
herseite %x", vaddr);
-                }
-
-                //kprintf("DMA-Adresse: phys 0x%08x, virt %08x\n", isf->eb=
x, isf->eax);
-            }
-            else
-            {
-                while(num--)
-                {
-                    paddr =3D phys_alloc_page();
-                    *phys =3D (paddr_t) NULL;
-                   =20
-                    if (!map_page((page_directory_t) current_task->cr3, va=
ddr, paddr, PTE_P | PTE_U | PTE_W))
-                    {
-                        panic("Fehler beim Zuweisen der reservierten Speic=
herseite %x", vaddr);
-                    }
-                    vaddr +=3D PAGE_SIZE;
-                }
-            }
-           =20
-            break;
-        }
-
-        case SYSCALL_MEM_ALLOCATE_PHYSICAL:
-        {
-            uint32_t num;
-            paddr_t position;
-            uint32_t flags;
-
-            vaddr_t vaddr;
-            num =3D PAGE_ALIGN_ROUND_UP(*((size_t*) isf->esp)) >> 12;
-            //TODO: Position entsprechend den Pages abrunden
-            position =3D *((paddr_t*) (isf->esp + 4));
-            flags =3D *((uint32_t*) (isf->esp + 8));
-            (void) flags;
-            // Speicher an der physikalischen Position einfach an eine fre=
ie
-            // Position mappen
-            vaddr =3D find_contiguous_pages((page_directory_t) current_tas=
k->cr3,
-                num, USER_MEM_START, USER_MEM_END);
-            isf->eax =3D (uint32_t) vaddr;
-
-            current_task->memory_used +=3D num << 12;
-           =20
-            //TODO: Speicher als benutzt markieren?
-            //Nur nicht freien (=3Dunnereichbaren) Speicher benutzen?
-            if (!map_page_range((page_directory_t) current_task->cr3, vadd=
r,
-                position, PTE_P | PTE_U | PTE_W, num)) {
-                panic("Fehler beim Zuweisen des Speichers %x", vaddr);
-            }
-            break;
-        }
-
-       =20
-        case SYSCALL_MEM_FREE:
-        {
-            vaddr_t address =3D *((vaddr_t*) isf->esp);
-            uint32_t pages =3D PAGE_ALIGN_ROUND_UP(*((size_t*) (isf->esp +=
 4))) >> PAGE_SHIFT;
-           =20
-            //kprintf("\nMEM_FREE: PID %d: free  %x Pages @ 0x%x\n", curre=
nt_task->pid, pages, address);
-           =20
-            current_task->memory_used -=3D pages << 12;
-
-            if((uint32_t)address % PAGE_SIZE !=3D 0)
-            {
-                if (debug_test_flag(DEBUG_FLAG_PEDANTIC)) {
-                    abort_task("SYSCALL_MEM_FREE: Der Task versucht eine "
-                        "nicht ausgerichtete Adresse freizugeben: 0x%08x",=
=20
-                        address);
-                }
-                isf->eax =3D false;
-                break;
-            }
-
-            if (!is_userspace(address, pages * PAGE_SIZE))=20
-            {
-                if (debug_test_flag(DEBUG_FLAG_PEDANTIC)) {
-                    abort_task("SYSCALL_MEM_FREE: Der Task versucht eine "
-                        "Adresse freizugeben, die nicht fuer ihn reservier=
t "
-                        "ist: 0x%08x (+0x%x)", address, pages * PAGE_SIZE)=
;
-                }
-                isf->eax =3D false;
-                break;
-            }
-
-            for (; pages; pages--) {
-                paddr_t paddress =3D resolve_vaddr((page_directory_t) curr=
ent_task->cr3, address);
-
-                if(unmap_page((page_directory_t) current_task->cr3, addres=
s) !=3D true)
-                {
-                    abort_task("SYSCALL_MEM_FREE: Die Speicherseite konnte=
 nicht freigegeben werden: 0x%08x", address);
-                }
-                else
-                {
-                    phys_mark_page_as_free(paddress);
-                }
-
-                address +=3D PAGE_SIZE;
-            }
-
-            isf->eax =3D true;
-            break;
-        }
-       =20
-        case SYSCALL_MEM_FREE_PHYSICAL:
-        {
-            vaddr_t address =3D *((vaddr_t*) isf->esp);
-            uint32_t pages =3D PAGE_ALIGN_ROUND_UP(*((size_t*) (isf->esp +=
 4))) >> PAGE_SHIFT;
-            current_task->memory_used -=3D pages << 12;
-            if((uint32_t)address % PAGE_SIZE !=3D 0)
-            {
-                abort_task("SYSCALL_MEM_FREE_PHYSICAL: Der Task versucht e=
ine nicht ausgerichtete Adresse freizugeben: 0x%08x", address);
-            }
-
-            for (; pages; pages--) {
-                //paddr_t paddress =3D resolve_vaddr((page_directory_t) cu=
rrent_task->cr3, address);
-
-                if(unmap_page((page_directory_t) current_task->cr3, addres=
s) !=3D true)
-                {
-                    abort_task("SYSCALL_MEM_FREE_PHYSICAL: Die Speichersei=
te konnte nicht freigegeben werden: 0x%08x", address);
-                }
-                //FIXME: Speicher freigeben?
-
-                address +=3D PAGE_SIZE;
-            }
-
-            break;
-        }
-       =20
-        case SYSCALL_MEM_RESOLVE_VADDR:
-        {
-            vaddr_t address =3D *((vaddr_t*) isf->esp);
-            if (is_userspace(address, 1)) {
-                isf->eax =3D (uint32_t) resolve_vaddr(current_task->cr3, a=
ddress);
-            } else {
-                isf->eax =3D 0;
-            }
-
-            break;
-        }
-
-       =20
-        case SYSCALL_MEM_INFO:
-        {
-            isf->eax =3D phys_count_pages() * PAGE_SIZE;
-            isf->edx =3D phys_count_free_pages() *PAGE_SIZE;
-
-            break;
-        }
-       =20
-        case SYSCALL_SHM_CREATE:
-        {
-            uint32_t size =3D *((uint32_t*) isf->esp);
-            isf->eax =3D create_shared_memory(size);
-            break;
-        }
-
-        case SYSCALL_SHM_ATTACH:
-        {
-            uint32_t id =3D *((uint32_t*) isf->esp);
-            isf->eax =3D (uint32_t)attach_task_to_shm(current_task, id);
-            break;
-        }
-
-        case SYSCALL_SHM_DETACH:
-        {
-            uint32_t id =3D *((uint32_t*) isf->esp);
-            detach_task_from_shm(current_task, id);
-            break;
-        }
-
-        case SYSCALL_PM_REQUEST_PORT:
-        {
-            uint32_t port =3D *((uint32_t*) isf->esp);
-            uint32_t length =3D *((uint32_t*) (isf->esp + 4));
-
-            isf->eax =3D io_ports_request(current_task, port, length);
-
-            set_io_bitmap();
-            break;
-        }
-
-        case SYSCALL_PM_RELEASE_PORT:
-        {
-            uint32_t port =3D *((uint32_t*) isf->esp);
-            uint32_t length =3D *((uint32_t*) (isf->esp + 4));
-
-            isf->eax =3D true;
-            if (!io_ports_release(current_task, port, length))=20
-            {
-                if (debug_test_flag(DEBUG_FLAG_PEDANTIC)) {
-                    abort_task("Freigab eines nicht reservierten Ports (po=
rt: 0x%x, Laenge 0x%x)", port, length);
-                }
-
-                isf->eax =3D false;
-            }
-
-            set_io_bitmap();
-            break;
-        }
-
-        case SYSCALL_PM_CREATE_PROCESS:
-        {
-            //TODO: Die UID irgendwie verwerten
-            //uid_t uid =3D *((uid_t*) isf->esp + 4);
-           =20
-            pid_t parent_pid =3D *((pid_t*)((uint32_t)isf->esp + 12));
-            void* eip =3D *((void**) isf->esp);
-            const char* cmdline =3D *((const char**) ((uint32_t)isf->esp +=
 8));
-
-            struct task* new_task =3D create_task(eip, cmdline, parent_pid=
);
-
-            new_task->blocked_by_pid =3D current_task->pid;
-            isf->eax =3D new_task->pid;
-            break;
-        }
-        case SYSCALL_PM_INIT_PAGE:
-        {
-            struct task* new_task =3D get_task(*((pid_t*) isf->esp));
-           =20
-            if((new_task =3D=3D NULL) || (new_task->blocked_by_pid !=3D cu=
rrent_task->pid))=20
-            {
-                abort_task("SYSCALL_PM_INIT_PAGE: Der Aufrufer hat eine un=
gueltige PID angegeben: %d", *((pid_t*) isf->esp));
-            }
-
-            int num =3D PAGE_ALIGN_ROUND_UP(*((size_t*) (isf->esp + 12))) =
>> 12;
-            vaddr_t dest =3D (vaddr_t) PAGE_ALIGN_ROUND_DOWN(*((size_t*) (=
isf->esp + 4)));
-            vaddr_t src =3D (vaddr_t) PAGE_ALIGN_ROUND_DOWN(*((size_t*) (i=
sf->esp + 8)));
-           =20
-            if (dest =3D=3D NULL) {
-                abort_task("SYSCALL_PM_INIT_PAGE: Versuchtes NULL-Mapping:=
 src =3D 0x%08x", src);
-            }
-           =20
-            current_task->memory_used -=3D num * PAGE_SIZE;
-            //kprintf("Map psrc:%x    src:%x    dest:%x   size:%x\n", reso=
lve_vaddr((page_directory_t) current_task->cr3, src), src, dest, num << 12)=
;
-           =20
-            /*{
-                uint32_t i;
-                for (i =3D 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 =3D new_task->cr3;
-           =20
-            // An dieser Stelle kann kein map_page_range benutzt werden, d=
a
-            // der Speicher nur virtuell, aber nicht unbedingt physisch
-            // zusammenh=EF=BF=BDngend sein mu=EF=BF=BD.
-            while(num--) {
-                if (!resolve_vaddr(new_task_pd, dest)) {
-                    if (!map_page(new_task_pd, dest, resolve_vaddr((page_d=
irectory_t) current_task->cr3, src), PTE_P | PTE_U | PTE_W)) {
-                        abort_task("SYSCALL_PM_INIT_PAGE: Fehler beim Zuwe=
isen der reservierten Speicherseite %x  =3D>  %x", src, dest);
-                    }
-                } else {
-                    // FIXME: Hier muss was passieren. Kopieren?
-                }
-               =20
-                src +=3D 0x1000;
-                dest +=3D 0x1000;
-            }
-           =20
-            //free_phys_addr((vaddr_t)new_task_pd, PAGE_DIRECTORY_LENGTH);
-            break;
-        }
-        case SYSCALL_PM_INIT_PAGE_COPY:
-        {
-            struct task* new_task =3D get_task(*((pid_t*) isf->esp));
-           =20
-            if((new_task =3D=3D NULL) || (new_task->blocked_by_pid !=3D cu=
rrent_task->pid))=20
-            {
-                abort_task("SYSCALL_PM_INIT_PAGE_COPY: Der Aufrufer hat ei=
ne ungueltige PID angegeben: %d", *((pid_t*) isf->esp));
-            }
-
-            int num =3D PAGE_ALIGN_ROUND_UP(*((size_t*) (isf->esp + 12))) =
>> 12;
-            vaddr_t dest =3D (vaddr_t) PAGE_ALIGN_ROUND_DOWN(*((size_t*) (=
isf->esp + 4)));
-            vaddr_t src =3D (vaddr_t) PAGE_ALIGN_ROUND_DOWN(*((size_t*) (i=
sf->esp + 8)));
-           =20
-            if (dest =3D=3D NULL) {
-                abort_task("SYSCALL_PM_INIT_PAGE_COPY: Versuchtes Kopieren=
 nach NULL: src =3D 0x%08x", src);
-            }
-           =20
-            // Das PD-des neuen tasks mappen
-            page_directory_t new_task_pd =3D new_task->cr3;
-           =20
-            // 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);
-                }
-               =20
-                paddr_t phys_addr =3D resolve_vaddr(new_task_pd, dest);
-                char *destmem =3D 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);
-               =20
-                src +=3D 0x1000;
-                dest +=3D 0x1000;
-            }
-           =20
-            break;
-        }
-        case SYSCALL_PM_EXIT_PROCESS:
-        {
-            struct task* old_task =3D current_task;
-            schedule((uint32_t*)esp);
-            destroy_task(old_task);
-            break;
-        }
-       =20
-        case SYSCALL_PM_SLEEP:
-            schedule((uint32_t*)esp);
-            break;
-       =20
-        case SYSCALL_PM_WAIT_FOR_RPC:
-            /*kprintf("Kernel: wait_for_rpc: PID %d an %08x\n",=20
-                current_task->pid,=20
-                isf->ebp >=3D 0x1000 ? *((uint32_t*) (isf->ebp  + 4)) : 0
-            );*/
-            current_task->status =3D TS_WAIT_FOR_RPC;
-            schedule((uint32_t*)esp);
-            break;
-                   =20
-        case SYSCALL_PM_V_AND_WAIT_FOR_RPC:
-            if(unblock_task(current_task, current_task->pid) =3D=3D 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,=20
-                isf->ebp >=3D 0x1000 ? *((uint32_t*) (isf->ebp  + 4)) : 0,
-                current_task->blocked_count
-            );*/
-            current_task->status =3D TS_WAIT_FOR_RPC;
-            schedule((uint32_t*)esp);
-            break;
-
-        case SYSCALL_PM_GET_UID:
-            isf->eax =3D 0;
-            break;
-       =20
-        case SYSCALL_PM_GET_PID:
-            isf->eax =3D current_task->pid;
-            break;
-       =20
-        case SYSCALL_PM_GET_CMDLINE:
-        {  =20
-            vaddr_t vaddr =3D find_contiguous_pages((page_directory_t) cur=
rent_task->cr3, 1, USER_MEM_START, USER_MEM_END);
-            paddr_t paddr =3D phys_alloc_page();
-           =20
-            if (!map_page((page_directory_t) current_task->cr3, vaddr, pad=
dr, PTE_P | PTE_U | PTE_W))
-            {
-                panic("Fehler beim Zuweisen der reservierten Speicherseite=
 %x", vaddr);
-            }
-
-            isf->eax =3D (uint32_t) vaddr;
-
-            memcpy((void*) vaddr, (void*)(current_task->cmdline), strlen(c=
urrent_task->cmdline) + 1);
-            //kprintf("KERNEL return commmandline %s\n", current_task->cmd=
line);
-
-            break;
-        }
-
-        case SYSCALL_PM_GET_PARENT_PID:
-            // Eltern PID vom aktuellen Task
-            if (*((pid_t*) isf->esp) =3D=3D 0) {
-                if (current_task->parent_task !=3D NULL) {
-                    isf->eax =3D current_task->parent_task->pid;
-                } else {
-                    isf->eax =3D 0;
-                }
-            } else {
-                struct task* task =3D get_task(*((pid_t*) isf->esp));
-
-                if (task =3D=3D NULL) {
-                    isf->eax =3D 0;
-                } else {
-                    if (task->parent_task =3D=3D NULL) {
-                        isf->eax =3D 0;
-                    } else {
-                        isf->eax =3D 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 =3D 0;
-            size_t result_size =3D sizeof(task_info_t);
-            struct task* task =3D first_task;
-            uint32_t i;
-
-            while (task !=3D NULL) {
-                task_count++;
-                result_size +=3D sizeof(task_info_task_t) + strlen(task->c=
mdline)
-                    + 1;
-                task =3D task->next_task;
-            }
-           =20
-            // Anzahl der Seiten berechnen, die die Informationen benoetig=
en.
-            size_t result_page_count =3D 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 =3D find_contiguous_pages((page_directo=
ry_t)
-                current_task->cr3, result_page_count, USER_MEM_START,
-                USER_MEM_END);
-
-            // Ein paar Seite an die Stelle mappen
-            for (i =3D 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=
(),=20
-                    PTE_P | PTE_U | PTE_W))
-                {
-                    panic("Fehler beim Zuweisen der reservierten "
-                        "Speicherseite %x", (uint32_t)task_info + i * PAGE=
_SIZE);
-                }
-            }
-           =20
-            // Der groessen-Eintrag ist nur da, damit der Tasks die Pages
-            // freigeben koennte.
-            task_info->info_size =3D result_size;
-
-            task_info->task_count =3D task_count;
-
-            // Dieser Pointer zeigt direkt hinter das Array mit den
-            // Task-Informationen. Dort werden die Kommandozeilen
-            // hintereinander gespeichert, und aus den Task-Strukturen wir=
d auf
-            // sie verwiesen.
-            char* cmdlines =3D (char*) task_info->tasks;
-            cmdlines +=3D task_count * sizeof(task_info_task_t);
-           =20
-            task =3D first_task;
-            // Jetzt werden die Infos eingefuellt.
-            for (i =3D 0; i < task_count; i++) {
-                task_info->tasks[i].pid =3D task->pid;
-                task_info->tasks[i].status =3D task->status;
-                task_info->tasks[i].eip =3D=20
-                    ((struct int_stack_frame*) task->esp)->eip;
-
-                // Wenn der Task keinen Eltern-Task hat muessen wir aufpas=
sen,
-                // damit wir keinen Pagefault produzieren.
-                if (task->parent_task =3D=3D NULL) {
-                    task_info->tasks[i].parent_pid =3D 0;
-                } else {
-                    task_info->tasks[i].parent_pid =3D task->parent_task->=
pid;
-                }
-               =20
-                // Die Kommandozeile inklusive Nullbyte kopieren
-                size_t cmdline_size =3D strlen(task->cmdline) + 1;
-                memcpy(cmdlines, task->cmdline, cmdline_size);
-
-                // Den Pointer fuer die Kommandozeile setzen
-                task_info->tasks[i].cmdline =3D cmdlines;
-
-                // Den Zielpointer fuer die naechste Kommandozeile direkt
-                // hinter die aktuelle setzen.
-                cmdlines +=3D cmdline_size;
-               =20
-                task_info->tasks[i].memory_used =3D task->memory_used;
-                task =3D task->next_task;
-            }
-           =20
-            // In eax wird ein Pointer auf die Daten zurueck gegeben
-            isf->eax =3D (uint32_t) task_info;
-
-            break;
-        }
-
-        case SYSCALL_PM_P:
-            /*kprintf("Kernel: p: PID %d an %08x =3D> %d\n",=20
-                current_task->pid,=20
-                isf->ebp >=3D 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;
-       =20
-        case SYSCALL_PM_V:
-        {
-            pid_t pid =3D *((pid_t*) isf->esp);
-            struct task* task_ptr =3D get_task(pid);
-            if(pid =3D=3D 0)
-            {
-                unblock_task(current_task, current_task->pid);
-            }
-            else
-            {
-                if(task_ptr =3D=3D NULL)
-                    abort_task("SYSCALL_PM_V: Der Aufrufer hat eine unguel=
tige PID angegeben: %d", pid);
-               =20
-                if(task_ptr->blocked_by_pid =3D=3D current_task->pid)
-                {
-                    if(unblock_task(task_ptr, current_task->pid) =3D=3D fa=
lse)
-                    {
-                        panic("SYSCALL_PM_V: Der Task konnte nicht fortges=
etzt werden");
-                    }
-                }
-                else
-                {
-                    abort_task("SYSCALL_PM_V: Der Aufrufer hat einen Proze=
ss(PID=3D%d) angegeben, der nicht von ihm blockiert ist", pid);
-                }
-            }
-            /*kprintf("Kernel: v: PID %d an %08x =3D> %d\n",=20
-                current_task->pid,=20
-                isf->ebp >=3D 0x1000 ? *((uint32_t*) (isf->ebp  + 4)) : 0,
-                current_task->blocked_count
-            );*/
-            break;
-        }
-
-        case SYSCALL_SET_RPC_HANDLER:
-        {
-            current_task->rpc_handler =3D *((vaddr_t*) isf->esp);
-            break;
-        }
-
-        case SYSCALL_FASTRPC:
-        {
-            uint32_t metadata_size =3D *((uint32_t*) (isf->esp + 4));
-            void* metadata =3D *((void**) (isf->esp + 8));
-            uint32_t data_size =3D *((uint32_t*) (isf->esp + 12));
-            void* data =3D *((void**) (isf->esp + 16));
-
-            uint32_t callee_pid =3D *((uint32_t*) isf->esp);
-            struct task* callee =3D get_task(callee_pid);
-
-            if (!callee) {
-                isf->eax =3D -ESRCH;
-                break;
-            }
-
-            if (!is_userspace(metadata, metadata_size)) {
-                abort_task("SYSCALL_FASTRPC: Ungueltige Metadaten (%08x)",
-                    (uint32_t) metadata);
-                break;
-            }
-           =20
-            if (!is_userspace(data, data_size)) {
-                abort_task("SYSCALL_FASTRPC: Ungueltige Daten (%08x)",
-                    (uint32_t) data);
-                break;
-            }
-
-            isf->eax =3D 0;
-            if (fastrpc(
-                callee,
-                metadata_size, metadata,
-                data_size, data   =20
-            )) {
-                schedule_to_task(callee, (uint32_t*) esp);
-            } else {
-                isf->eax =3D -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;
-        }
-       =20
-        case SYSCALL_GET_TICK_COUNT:
-        {
-            isf->eax =3D (uint32_t)timer_ticks;
-            isf->edx =3D (uint32_t)(timer_ticks >> 32);
-            break;
-        }
-
-        case SYSCALL_ADD_TIMER:
-        {
-            timer_register(
-                current_task,
-                *((uint32_t*) (isf->esp)),
-                *((uint32_t*) (isf->esp + 4))
-            );
-            break;
-        }
-       =20
-        case SYSCALL_VM86:
-        {
-            vm86_regs_t *regs =3D *((vm86_regs_t **) (isf->esp));
-            uint32_t *mem =3D *((uint32_t **) (isf->esp + 4));
-            if (!regs) {
-                isf->eax =3D 0;
-                break;
-            }
-            if (create_vm86_task(0x10, regs, mem, current_task)) {
-                isf->eax =3D 1;
-            } else {
-                isf->eax =3D 0;
-            }
-            schedule((uint32_t*)esp);
-            break;
-        }
-
-        case SYSCALL_FORTY_TWO:
-        {
-            asm("int $0x20");
-            char* forty_two =3D malloc(61);
-            memcpy(forty_two, "\nThe Answer to Life, the Universe, and Eve=
rything is ... 42\n", 61);
-            kprintf("%s", forty_two);
-            break;
-        }
-
-        case SYSCALL_DEBUG_STACKTRACE:
-        {
-            pid_t pid =3D *((uint32_t*) (isf->esp));
-            struct task* task =3D get_task(pid);
-
-            // FIXME: Was bei einem Fehler
-            if (task !=3D NULL) {
-                // TODO: Irgend ein Gefuehl sagt mir, dass das nicht so ei=
nfach
-                //       sein kann *g*
-                // In den Kontext dieses Tasks wechseln
-                __asm("mov %0, %%cr3" : : "r"(resolve_vaddr(kernel_page_di=
rectory, task->cr3)));           =20
-                struct int_stack_frame* isf =3D (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_di=
rectory, 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_cmdlin=
e,
+        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 =3D=3D 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 =3D=3D 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 =3D=3D 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 =3D=3D 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] =3D (syscall_t) {
+        .handler    =3D &kern_syscall_pm_sleep,
+        .arg_count  =3D 2,
+        .privileged =3D true,
+    };
+}
=20
-        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 uebergeb=
en
+ *                  werden muessen.
+ */
+void syscall_register(syscall_arg_t number, void* handler, size_t arg_coun=
t)
+{
+    // Ein Syscall mit einer zu grossen ID wuerde dazu fuehren, dass Teile=
 von
+    // Kernel-Daten ueberschrieben wuerden
+    if (number >=3D SYSCALL_MAX) {
+        panic("Es wurde versucht einen Syscall mit einer Nummer groesser a=
ls"
+                "SYSCALL_MAX zu reservieren!");
     }
+    syscalls[number].handler =3D handler;
+    syscalls[number].arg_count =3D arg_count;
+    syscalls[number].privileged =3D 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/syscall=
s/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/lo=
stio.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/mut=
ex.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 @@
-/* =20
- * 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 softwar=
e
- *    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=20
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */ =20
-
-#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 =3D 1;
-    return next_pid++;
-}
-
-/**
- * Blockiert einen Task. Zu einem blockierten Task k=EF=BF=BDnnen keine RP=
C-Aufrufe
- * durchgef=EF=BF=BDhrt werden. Wenn der Task durch einen anderen Task blo=
ckiert ist,
- * wird er au=EF=BF=BDerdem vom Scheduler nicht mehr aufgerufen, bis der T=
ask=20
- * 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 =3D=3D blocked_by) {
-        task->blocked_count++;
-        return true;
-    }
-
-/*    while(task->blocked_by_pid)
-    {
-        kprintf("[block_task() =3D> intr]\n");
-        asm("int $0x20");
-    }*/
-    if (task->blocked_by_pid) {
-        return false;
-    }
-   =20
-    /*if (blocked_by =3D=3D 10 || blocked_by =3D=3D 11) {
-        uint32_t ebp =3D((struct int_stack_frame*) current_task->esp)->ebp=
;=20
-
-        kprintf("block_task PID %d durch PID %d =3D %d an %08x\n",=20
-            task->pid,=20
-            blocked_by,
-            current_task->pid,
-            ebp >=3D 0x1000 ? *((uint32_t*) (ebp  + 4)) : 0
-        );
-    }*/
-
-    task->blocked_by_pid =3D blocked_by;
-    task->blocked_count =3D 1;
-
-    return true;
-}
-
-/**
- * Entblockt einen blockierten Task. Dies ist nur m=EF=BF=BDglich, wenn de=
r
- * 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 =3D=3D blocked_by) {
-        if(--(task->blocked_count) =3D=3D 0) {
-            task->blocked_by_pid =3D 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 =3D malloc(sizeof(struct task));
-    new_task->pid =3D generate_pid();
-    new_task->rpcs =3D list_create();
-    new_task->io_bitmap =3D NULL;
-    new_task->status =3D TS_RUNNING;
-   =20
-    new_task->shmids =3D list_create();
-    new_task->shmaddresses =3D list_create();
-
-    new_task->vm86 =3D false;
-    new_task->vm86_info =3D NULL;
-   =20
-    new_task->memory_used =3D 0;
-    // Wenn nicht Init erstellt werden soll, wir der Task mit der PID sein=
es
-    //  Elterntasks blockiert. Damit der Elterntask Zeit hat, die notwendi=
gen
-    //  Pages in den Adressraum des neuen Prozesses zu mappen.
-    if (new_task->pid !=3D 1) {
-        new_task->blocked_count =3D 1;
-        new_task->blocked_by_pid =3D parent_pid;
-    } else {
-        new_task->blocked_by_pid =3D 0;
-        new_task->blocked_count =3D 0;
-    }
-
-   =20
-    // Scheduling-Eigenschaften fuer den Task setzen
-    new_task->schedule_ticks_left =3D 0;
-    new_task->schedule_ticks_max =3D 50;
-
-    // Haenge den Task an die Liste an
-    // TODO Trennen der Task-Liste von der Scheduling-Liste
-    new_task->next_task =3D first_task;
-    first_task =3D new_task;
-    if (parent_pid =3D=3D 0) {
-        new_task->parent_task =3D current_task;
-    } else {
-        new_task->parent_task =3D get_task(parent_pid);
-    }
-   =20
-    // Kopieren der Kommandozeile
-    new_task->cmdline =3D 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=EF=BF=BDuft.
-    //
-    // Der Kernelspeicher wird in allen Tasks gleich gemappt, der
-    // Userspace bekommt erstmal einen komplett leeren Speicher.
-    paddr_t phys_pagedir =3D phys_alloc_page();
-    page_directory_t pagedir =3D (page_directory_t) map_phys_addr(phys_pag=
edir, PAGE_SIZE);
-
-    memset((void*) pagedir, 0, PAGE_SIZE);
-    memcpy((void*) pagedir, kernel_page_directory, 1024);
-    pagedir[0xff] =3D (uint32_t) phys_pagedir | PTE_W | PTE_P;
-    new_task->cr3 =3D pagedir;
-
-    // Speicher fuer die Stacks allokieren
-    // Stack im PD des neuen Tasks mappen
-    paddr_t phys_kernel_stack =3D phys_alloc_page();
-    paddr_t phys_user_stack =3D phys_alloc_page();
-
-    map_page(pagedir, (vaddr_t)USER_STACK_VIRT, phys_user_stack, PTE_W | P=
TE_P | PTE_U);
-    new_task->user_stack_bottom =3D (vaddr_t) USER_STACK_VIRT;
-
-    // Den Kernelstack mappen und initialisieren
-    // Der Stack wird von oben her beschrieben, daher 4K addieren=20
-    // (1024 * sizeof(uint32_t))
-    uint32_t * kernel_stack =3D map_phys_addr(phys_kernel_stack, PAGE_SIZE=
);
-    kernel_stack +=3D 1024;
-
-    *(--kernel_stack) =3D 0x23; // ss
-    *(--kernel_stack) =3D 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) =3D 0x0202; // eflags =3D interrupts aktiviert und i=
opl =3D 0
-    *(--kernel_stack) =3D 0x1b; // cs
-    *(--kernel_stack) =3D (uint32_t)entry; // eip
-
-    *(--kernel_stack) =3D 0; // interrupt nummer
-    *(--kernel_stack) =3D 0; // error code
-
-    // general purpose registers
-    *(--kernel_stack) =3D 0;
-    *(--kernel_stack) =3D 0;
-    *(--kernel_stack) =3D 0;
-    *(--kernel_stack) =3D 0;
-    *(--kernel_stack) =3D 0;
-    *(--kernel_stack) =3D 0;
-    *(--kernel_stack) =3D 0;
-    *(--kernel_stack) =3D 0;
-
-    // segment registers
-    *(--kernel_stack) =3D 0x23;
-    *(--kernel_stack) =3D 0x23;
-    *(--kernel_stack) =3D 0x23;
-    *(--kernel_stack) =3D 0x23;
-   =20
-    new_task->esp =3D (uint32_t) kernel_stack;
-    new_task->kernel_stack =3D (uint32_t) kernel_stack;
-
-    num_tasks++;
-   =20
-    return new_task;
-}
-
-/**
- * Beendet einen Taks.
- *
- * @param task_ptr Zu beendender Task
- */
-void destroy_task(struct task* task_ptr)
-{
-    task_ptr->blocked_by_pid =3D -1;
-
-    struct task* previous_task =3D NULL;
-    struct task* next_task =3D NULL;
-
-    // Den vorherigen Task in der Liste heraussuchen
-    if(task_ptr =3D=3D first_task)
-    {
-        first_task =3D task_ptr->next_task;
-    }
-    else
-    {
-        next_task =3D first_task;
-        while(next_task !=3D task_ptr)
-        {
-            // Wenn der Task nicht gefunden wuzde verlasse die Funktion
-            if(next_task =3D=3D NULL)
-                return;
-
-            previous_task =3D next_task;
-            next_task =3D next_task->next_task;
-        }
-        previous_task->next_task =3D task_ptr->next_task;
-    }
-
-    // Alle Kindprozesse an init weitervererben
-    for (next_task =3D first_task; next_task; next_task =3D next_task->nex=
t_task) {
-        if (next_task->parent_task =3D=3D task_ptr) {
-            next_task->parent_task =3D get_task(1);
-        }
-    }
-
-    // Interrupthandler ausschalten
-    remove_intr_handling_task(task_ptr);
-   =20
-   =20
-    // Melde das Beenden des Tasks per RPC an init
-    char* rpc_init =3D "        SERV_SHD    ";
-    *((uint32_t*)rpc_init) =3D 512;
-    *((pid_t*)((uint32_t) rpc_init + 8 + 8))  =3D task_ptr->pid;
-   =20
-    fastrpc(get_task(1), 0, 0, strlen(rpc_init), rpc_init);
-   =20
-    // Timer freigeben
-    timer_cancel_all(task_ptr);
-   =20
-    // 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);
-    }
-   =20
-    //Shared Memory-Bereiche von Task l=EF=BF=BDsen
-    while (list_size(task_ptr->shmids) > 0) {
-        uint32_t id =3D (uint32_t)list_get_element_at(task_ptr->shmids, li=
st_size(task_ptr->shmids) - 1);
-        detach_task_from_shm(task_ptr, id);
-    }
-   =20
-    // Evtl. zusatzliche Infos von VM86-Task l=EF=BF=BDschen
-    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=EF=BF=BDnnen
-    page_directory_t page_dir =3D task_ptr->cr3;
-    page_table_t page_table;
-   =20
-    int i;
-    int n;
-   =20
-    // Alle Pages von 1 GB - 4 GB
-    //
-    // FIXME Physisch freigeben nur, wenn die Seite tats=EF=BF=BDchlich sp=
eziell f=EF=BF=BDr
-    // den Task reserviert wurde. Das ist beispielsweise bei Shared Memory=
 oder
-    // beim Zugriff auf physischen Speicher (Framebuffer) nicht der Fall.
-    for(i=3D256; i < 1024; i++)
-    {
-        if(page_dir[i] & PTE_P)
-        {
-            page_table =3D map_phys_addr((paddr_t)(page_dir[i] & ~0xFFF), =
PAGE_TABLE_LENGTH);
-           =20
-            for(n=3D0; n < 1024; n++)
-            {
-                if(page_table[n] & PTE_P)
-                {
-                    phys_free_page((paddr_t) (page_table[n] & PAGE_MASK));
-                }
-            }
-           =20
-            free_phys_addr((vaddr_t)page_table, PAGE_TABLE_LENGTH);
-        }
-    }
-  =20
-    // 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:
- *=20
- * @param pid PID des gesuchten Tasks
- * @return Pointer auf den Task oder NULL, falls kein Task mit der passend=
en
- * PID gefunden wurde
- */
-struct task * get_task(pid_t pid)
-{
-    struct task* curr_task =3D first_task;
-   =20
-    while(curr_task !=3D NULL)
-    {
-        if(curr_task->pid =3D=3D pid) {
-            return curr_task;
-        }
-       =20
-        curr_task =3D curr_task->next_task;
-    }
-   =20
-    return NULL;
-}
-
-/**
- * Bricht den aktuell ausgef=EF=BF=BDhrten Task mit einer Fehlermeldung ab=
.
- */
-void abort_task(char* format, ...)
-{
-    int * args =3D ((int*)&format) + 1;
-
-    kprintf("\n\033[1;37m\033[41m" // weiss auf rot
-        "Task %d beendet: %s\n",=20
-        current_task->pid,
-        current_task->cmdline !=3D NULL=20
-            ? current_task->cmdline=20
-            : "Unbekannter Task"
-        );
-    kaprintf(format, &args);
-    kprintf("\n\033[0;37m\033[40m");
-       =20
-    if(debug_test_flag(DEBUG_FLAG_STACK_BACKTRACE))
-    {
-        struct int_stack_frame* isf =3D (struct int_stack_frame*)
-            current_task->esp;
-        stack_backtrace_ebp(isf->ebp, isf->eip);
-    }
-
-    destroy_task(current_task);
-   =20
-    current_task =3D 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/sched=
uler.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.
  */
=20
-#include <types.h>
+#include <stdint.h>
+#include <stdbool.h>
 #include <collections.h>
 #include <stdlib.h>
+#include <ports.h>
=20
 #include "timer.h"
-#include "rpc.h"
+#include "syscall.h"
=20
 extern uint64_t timer_ticks;
+extern int do_fastrpc(pid_t callee_pid, size_t metadata_size, void* metada=
ta,
+    size_t data_size, void* data, bool syscall);
=20
-
+/**
+ * Liste aller registrierten Timer
+ */
 static list_t* timers;
=20
+/**
+ * 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;
 };
=20
-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 =3D list_create();
+
+    // PIT initialisieren
+    reload_value =3D 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);
 }
=20
-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 =3D malloc(sizeof(struct timeout));
@@ -66,7 +97,7 @@ void timer_register(struct task* task, uint32_t timer_id,=
 uint32_t usec)
     timeout->timeout    =3D timer_ticks + usec;
=20
     // An der richtigen Stelle in der Liste einsortieren, so dass immer nu=
r
-    // das erste Listenelement gepr=EF=BF=BDft werden muss
+    // das erste Listenelement geprueft werden muss
     struct timeout* item;
     int i;
     for (i =3D 0; (item =3D 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);
 }
=20
+/**
+ * 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 =3D 0;
     static const uint32_t rpc_timer_function =3D 514;
-   =20
+
     struct timeout* item;
-    for (; (item =3D list_get_element_at(timers, 0)); free(list_pop(timers=
)))=20
+    int i =3D 0;
+    while ((item =3D list_get_element_at(timers, i)))
     {
-        // Die Schleife soll nur so lange laufen, wie die Timeouts in der=
=20
+        // Die Schleife soll nur so lange laufen, wie die Timeouts in der
         // Vergangenheit liegen. Da die Liste sortiert ist, kann beim erst=
en
         // Timeout, der in der Zukunft liegt, abgebrochen werden.
         //
-        // Overflows m=EF=BF=BDssen abgefangen werden, da in diesem Spezia=
lfall eine
-        // gr=EF=BF=BD=EF=BF=BDere Zahl dennoch Vergangenheit bedeutet. Wi=
e ich grad sehe,
+        // Overflows muessen abgefangen werden, da in diesem Spezialfall e=
ine
+        // groessere Zahl dennoch Vergangenheit bedeutet. Wie ich grad seh=
e,
         // reden wir von einem qword und damit von einer Uptime von ein pa=
ar
-        // 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))=
=20
+        if (((item->timeout > microtime) && (microtime > last_microtime))
             || ((item->timeout < last_microtime) && (microtime < last_micr=
otime)))
         {
             break;
         }
=20
-        // Task per RPC informieren, dass der Timer abgelaufen ist
-        // Im Fehlerfall mit der Abarbeitung der Liste aufh=EF=BF=BDren un=
d es beim
-        // n=EF=BF=BDchsten Mal nochmal versuchen.
-        //
-        // FIXME Mit p(); while(1); kann ein Prozess den Timer f=EF=BF=BDr=
 das ganze
-        // System lahmlegen
-        if (!fastrpc(item->task,=20
-                4, (char*) &rpc_timer_function,=20
-                4, (char*) &item->timer_id))=20
+        // 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));
     }
=20
     last_microtime =3D microtime;
 }
=20
-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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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 =3D {=20
-    .ss0 =3D SYS_DATA_SEL,=20
-    .io_bit_map_offset =3D TSS_IO_BITMAP_OFFSET,
-    .io_bit_map_end =3D 0xFF=20
-};
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 @@
-/* =20
- * 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 softwar=
e
- *    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=20
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
- * 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=EF=BF=BDr mehrere VM86-Tasks
-// Gibt evtl Probleme mit der Platzierung des Kernels.
-bool vm86_task_running =3D false;
-
-/**
- * Speichert BIOS-Daten, um sie den VM86-Tasks sp=EF=BF=BDter bereitstelle=
n zu k=EF=BF=BDnnen
- */
-void save_bios_data(void)
-{
-    memcpy(&bios_data, 0, 4096);
-}
-
-/**
- * Liefert ein Segment:Offset-Paar aus der IVT zur=EF=BF=BDck
- *
- * @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=EF=BF=BDckgabe=
 der Ergebnisse
- * benutzt.
- * @param meminfo Daten =EF=BF=BDber Speicherbereiche, die in den Task gem=
appt werden.
- * Die erste Zahl steht f=EF=BF=BDr die Anzahl der Eintr=EF=BF=BDge, danac=
h folgen je drei Zahlen
- * f=EF=BF=BDr Adresse im neuen Task, Adresse in aufrufenden Task und Gr=
=EF=BF=BD=EF=BF=BDe.
- *
- * @return Taskstruktur des neuen Tasks oder Null bei Fehlern
- */
-
-struct task * create_vm86_task(uint16_t interrupt, vm86_regs_t *regs, uint=
32_t *meminfo, struct task *parent)
-{
-    // Nur einen VM86-Task starten
-    if (vm86_task_running) {
-        return 0;
-    }
-    vm86_task_running =3D true;
-   =20
-    struct task* new_task =3D malloc(sizeof(struct task));
-    new_task->pid =3D generate_pid();
-   =20
-    // Aufrufender Thread wird geblockt, damit sp=EF=BF=BDter Ergebnisse z=
ur=EF=BF=BDckgegeben werden k=EF=BF=BDnnen
-    if (!block_task(parent, new_task->pid)) {
-        //puts("VM86: Konnte aufrufenden Task nicht blockieren!\n");
-        free(new_task);
-        return 0;
-    }
-
-   =20
-    new_task->rpcs =3D list_create();
-    new_task->io_bitmap =3D NULL;
-    new_task->status =3D TS_RUNNING;
-    new_task->shmids =3D list_create();
-    new_task->shmaddresses =3D list_create();
-    new_task->memory_used =3D 0;
-    // Neuer Task wird nicht geblockt, da er sofort ausgef=EF=BF=BDhrt wer=
den kann und sollte
-    new_task->blocked_by_pid =3D 0;
-    new_task->blocked_count =3D 0;
-    // Info =EF=BF=BDber Register/Speicher f=EF=BF=BDr R=EF=BF=BDckgabe vo=
n Daten aufbewahren
-    new_task->vm86 =3D true;
-    new_task->vm86_info =3D malloc(sizeof(vm86_info_t));
-    new_task->vm86_info->regs =3D regs;
-    new_task->vm86_info->meminfo =3D meminfo;
-    //printf("Neuer vm86-Task mit PID %d\n", new_task->pid);
-   =20
-    // Name des Tasks setzen
-    new_task->cmdline =3D malloc(strlen("vm86") + 1);
-    memcpy((void*) (new_task->cmdline), "vm86", strlen("vm86") + 1);
-   =20
-    // Scheduling-Eigenschaften fuer den Task setzen
-    new_task->schedule_ticks_left =3D 0;
-    new_task->schedule_ticks_max =3D 50;
-   =20
-    // Haenge den Task an die Liste an
-    // TODO Trennen der Task-Liste von der Scheduling-Liste
-    new_task->next_task =3D first_task;
-    first_task =3D new_task;
-    if (parent->pid =3D=3D 0) {
-        new_task->parent_task =3D current_task;
-    } else {
-        new_task->parent_task =3D get_task(parent->pid);
-    }
-   =20
-    // Neues Pagedirectory anlegen
-    // TODO: Die erste Pagetable sollte kopiert werden oder der Kernel etw=
as nach
-    // hinten verschoben werden.
-    paddr_t phys_pagedir =3D (paddr_t)phys_alloc_page();
-    page_directory_t pagedir =3D (page_directory_t) map_phys_addr(phys_pag=
edir, PAGE_SIZE);
-
-    memset((void*) pagedir, 0, PAGE_SIZE);
-    memcpy((void*) pagedir, kernel_page_directory, 1024);
-    new_task->cr3 =3D pagedir;
-    pagedir[0] |=3D 0x4;
-   =20
-    map_page_range(kernel_page_directory, (vaddr_t)0xC0000, (paddr_t)0xC00=
00, PTE_P | PTE_U, 0x40);
-    map_page_range(kernel_page_directory, (vaddr_t)0xA0000, (paddr_t)0xA00=
00, PTE_W | PTE_P | PTE_U, 0x10);
-   =20
-   =20
-    // Speicher fuer die Stacks allokieren
-    // Stack im PD des neuen Tasks mappen
-    paddr_t phys_kernel_stack =3D (paddr_t)phys_alloc_page();
-    paddr_t phys_user_stack =3D (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 | P=
TE_U);
-    new_task->user_stack_bottom =3D (vaddr_t) 0x90000;
-   =20
-    // Erste 4k mappen
-    uint32_t *page_table =3D (uint32_t*)find_contiguous_kernel_pages(1);
-    map_page(kernel_page_directory, page_table, (paddr_t)(pagedir[0] & ~0x=
FFF), PTE_P | PTE_W);
-    page_table[0] =3D (uint32_t)&bios_data | 0x7;
-    unmap_page(kernel_page_directory, page_table);
-   =20
-    // Gew=EF=BF=BDnschte Speicherbereiche reservieren
-    if (meminfo) {
-        uint32_t infosize =3D meminfo[0];
-        uint32_t i;
-        for (i =3D 0; i < infosize; i++) {
-            uint32_t addr =3D meminfo[1 + i * 3];
-            uint32_t src =3D meminfo[1 + i * 3 + 1];
-            uint32_t size =3D meminfo[1 + i * 3 + 2];
-            paddr_t phys_mem =3D (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);
-        }
-    }
-   =20
-    // Userstack mit Nullen f=EF=BF=BDllen, um bei einem iret den Task zu =
beenden
-    uint32_t *user_stack =3D (uint32_t*)find_contiguous_kernel_pages(1);
-    map_page(kernel_page_directory, user_stack, phys_user_stack, PTE_P | P=
TE_W);
-    user_stack[1023] =3D 0x0;
-    user_stack[1022] =3D 0x0;
-    unmap_page(kernel_page_directory, user_stack);
-   =20
-    // Den Kernelstack mappen und initialisieren
-    // Der Stack wird von oben her beschrieben, daher 4K addieren=20
-    // (1024 * sizeof(uint32_t))
-    uint32_t * kernel_stack =3D (uint32_t*)map_phys_addr(phys_kernel_stack=
, PAGE_SIZE);
-    kernel_stack +=3D 1024;
-
-    *(--kernel_stack) =3D 0x00; // gs
-    *(--kernel_stack) =3D 0x00; // fs
-    *(--kernel_stack) =3D regs->es; // es
-    *(--kernel_stack) =3D regs->ds; // ds
-    *(--kernel_stack) =3D 0x9000; // ss
-    *(--kernel_stack) =3D 0 + 4096 - 6;
-    *(--kernel_stack) =3D 0x20202; // eflags =3D VM-Bit gesetzt, interrupt=
s aktiviert und iopl =3D 0
-    *(--kernel_stack) =3D get_ivt_entry(interrupt)[1]; // cs
-    *(--kernel_stack) =3D get_ivt_entry(interrupt)[0]; // eip
-    //kprintf("Interrupt: %x/%x\n", get_ivt_entry(interrupt)[1], get_ivt_e=
ntry(interrupt)[0]);
-
-    *(--kernel_stack) =3D 0; // interrupt nummer
-    *(--kernel_stack) =3D 0; // error code
-
-    // general purpose registers
-    *(--kernel_stack) =3D regs->ax;
-    *(--kernel_stack) =3D regs->cx;
-    *(--kernel_stack) =3D regs->dx;
-    *(--kernel_stack) =3D regs->bx;
-    *(--kernel_stack) =3D 0;
-    *(--kernel_stack) =3D 0;
-    *(--kernel_stack) =3D regs->si;
-    *(--kernel_stack) =3D regs->di;
-
-    // segment registers
-    *(--kernel_stack) =3D 0x23;
-    *(--kernel_stack) =3D 0x23;
-    *(--kernel_stack) =3D 0x23;
-    *(--kernel_stack) =3D 0x23;
-   =20
-    new_task->esp =3D (uint32_t) kernel_stack;
-    new_task->kernel_stack =3D (uint32_t) kernel_stack;
-
-    num_tasks++;
-   =20
-    //puts("vm86-Task erstellt.\n");
-       =20
-    return new_task;
-
-}
-
-/**
- * Handler f=EF=BF=BDr Exceptions im VM86-Mode
- *
- * @param esp Pointer auf Stackpointer
- *
- * @return true, wenn die Exception verarbeitet wurde, false, wenn sie nic=
ht
- * verarbeitet werden konnte und der Task beendet werden muss.
- */
-bool vm86_exception(uint32_t *esp)
-{
-    // TODO: Das hier ist noch lange nicht vollst=EF=BF=BDndig
-    struct int_stack_frame *isf =3D *((struct int_stack_frame **)esp);
-    //puts("vm86 Exception.\n");
-    if (isf->interrupt_number =3D=3D 13) {
-        // GPF, wurde vermutlich durch einen nicht erlaubten Befehl verurs=
acht
-        uint8_t *ops =3D (uint8_t*)(isf->eip + (isf->cs << 4));
-        if (ops[0] =3D=3D 0xCD) { // int
-            //kprintf("VM86: int 0x%x\n", ops[1]);
-            // Derzeitige Adresse auf den Stack pushen und neue Codeadress=
e setzen
-            uint16_t intno =3D ops[1];
-            isf->esp -=3D 6;
-            ((uint16_t*)(isf->esp + (isf->ss << 4)))[0] =3D (uint16_t)isf-=
>eflags;
-            ((uint16_t*)(isf->esp + (isf->ss << 4)))[1] =3D (uint16_t)isf-=
>cs;
-            ((uint16_t*)(isf->esp + (isf->ss << 4)))[2] =3D (uint16_t)isf-=
>eip + 2;
-            isf->eip =3D bios_data.ivt[intno][0];
-            isf->cs =3D bios_data.ivt[intno][1];
-            return true;
-        } else if (ops[0] =3D=3D 0xCF) { // iret
-            //puts("VM86: iret.\n");
-            // Alte Adresse von Stack holen
-            isf->eip =3D ((uint16_t*)(isf->esp + (isf->ss << 4)))[2];
-            isf->cs =3D ((uint16_t*)(isf->esp + (isf->ss << 4)))[1];
-            isf->esp +=3D 6;
-            // Abbrechen, wenn wir das letzte iret erreicht haben
-            if ((isf->eip =3D=3D 0) && (isf->cs =3D=3D 0)) {
-                //puts("Breche VM86-Task ab.\n");
-                struct task *task =3D current_task;
-                vm86_info_t *info =3D task->vm86_info;
-                // Speicher kopieren
-                if (info->meminfo) {
-                    paddr_t phys_meminfo =3D resolve_vaddr(task->parent_ta=
sk->cr3, (uint32_t*)((uint32_t)info->meminfo & ~0xFFF));
-                    uint32_t *meminfo =3D (uint32_t*)find_contiguous_kerne=
l_pages(1);
-                    map_page(kernel_page_directory, meminfo, phys_meminfo,=
 PTE_P | PTE_W);
-                    meminfo =3D (uint32_t*)(((uint32_t)meminfo) + ((uint32=
_t)info->meminfo & 0xFFF));
-                    uint32_t i;
-                    for (i =3D 0; i < meminfo[0]; i++) {
-                        paddr_t phys_mem =3D resolve_vaddr(task->parent_ta=
sk->cr3, (uint32_t*)((uint32_t)meminfo[1 + i * 3 + 1] & ~0xFFF));
-                        uint32_t *mem =3D (uint32_t*)find_contiguous_kerne=
l_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*)((uin=
t32_t)meminfo[1 + i * 3] & ~0xFFF));
-                    }
-                    unmap_page(kernel_page_directory, (uint32_t*)((uint32_=
t)meminfo & ~0xFFF));
-                }
-                // Register speichern
-                paddr_t phys_regs =3D resolve_vaddr(task->parent_task->cr3=
, (uint32_t*)((uint32_t)info->regs & ~0xFFF));
-                uint32_t regs =3D (uint32_t) map_phys_addr(phys_regs, PAGE=
_SIZE);
-                vm86_regs_t * vm86_regs =3D (vm86_regs_t *)(regs + ((uint3=
2_t)info->regs & 0xFFF));
-                vm86_regs->ax =3D isf->eax;
-                vm86_regs->bx =3D isf->ebx;
-                vm86_regs->cx =3D isf->ecx;
-                vm86_regs->dx =3D isf->edx;
-                vm86_regs->si =3D isf->esi;
-                vm86_regs->di =3D isf->edi;
-                vm86_regs->ds =3D ((uint32_t*)(isf + 1))[0];
-                vm86_regs->es =3D ((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 =3D (uint32_t*)find_contiguous_kernel=
_pages(1);
-                map_page(kernel_page_directory, page_table, (((uint32_t*)t=
ask->cr3)[0] & ~0xFFF), PTE_P | PTE_W);
-                page_table[0] =3D 0;
-                unmap_page(kernel_page_directory, page_table);
-                // - BIOS
-                uint32_t i;
-                for (i =3D 0; i < 0x40; i++) {
-                    unmap_page(task->cr3, (uint32_t*)(0xC0000 + i * 0x1000=
));
-                }
-                // - VGA
-                for (i =3D 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 =3D false;
-                return true;
-            }
-            return true;
-        } else if (ops[0] =3D=3D 0x9C) { // pushf
-            // EFLAGS speichern
-            isf->esp -=3D 2;
-            ((uint16_t*)(isf->esp + (isf->ss << 4)))[0] =3D (uint16_t)isf-=
>eflags;
-            isf->eip++;
-            return true;
-        } else if (ops[0] =3D=3D 0x9D) { // popf
-            // So tun, als w=EF=BF=BDrden wir die EFLAGS wiederherstellen.
-            // Das hier ist wohl alles andere als korrekt, aber funzt erst=
mal.
-            isf->esp +=3D 2;
-            isf->eip++;
-            return true;
-        } else if (ops[0] =3D=3D 0xEF) { // outw
-            outw(isf->edx, isf->eax);
-            isf->eip++;
-            return true;
-        } else if (ops[0] =3D=3D 0xEE) { // outb
-            outb(isf->edx, isf->eax);
-            isf->eip++;
-            return true;
-        } else if (ops[0] =3D=3D 0xED) { // inw
-            isf->eax =3D inb(isf->edx);
-            isf->eip++;
-            return true;
-        } else if (ops[0] =3D=3D 0xEC) { // inb
-            isf->eax =3D (isf->eax & 0xFF00) + inb(isf->edx);
-            isf->eip++;
-            return true;
-        } else if (ops[0] =3D=3D 0xFA) { // sti
-            isf->eip++;
-            return true;
-        } else if (ops[0] =3D=3D 0xFB) { // cli
-            isf->eip++;
-            return true;
-        } else if (ops[0] =3D=3D 0x66) { // o32
-            // TODO
-            isf->eip++;
-            return true;
-        } else if (ops[0] =3D=3D 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/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 @@
-/*=0D
- * Copyright (c) 2006-2007 The tyndur Project. All rights reserved.=0D
- *=0D
- * This code is derived from software contributed to the tyndur Project=0D
- * by Burkhard Weseloh.=0D
- *=0D
- * Redistribution and use in source and binary forms, with or without=0D
- * modification, are permitted provided that the following conditions=0D
- * are met:=0D
- * 1. Redistributions of source code must retain the above copyright=0D
- *    notice, this list of conditions and the following disclaimer.=0D
- * 2. Redistributions in binary form must reproduce the above copyright=0D
- *    notice, this list of conditions and the following disclaimer in the=
=0D
- *    documentation and/or other materials provided with the distribution.=
=0D
- * 3. All advertising materials mentioning features or use of this softwar=
e=0D
- *    must display the following acknowledgement:=0D
- *     This product includes software developed by the tyndur Project=0D
- *     and its contributors.=0D
- * 4. Neither the name of the tyndur Project nor the names of its=0D
- *    contributors may be used to endorse or promote products derived=0D
- *    from this software without specific prior written permission.=0D
- *=0D
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=0D
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED=0D
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR=0D
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=0D
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=
=0D
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=0D
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=0D
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=0D
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=0D
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=0D
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0D
- */=0D
-=0D
-#ifndef CONSOLE_H=0D
-#define CONSOLE_H=0D
-=0D
-extern void init_console(void);=0D
-=0D
-extern void con_putc(const char c); // Zeichen ausgeben ohne Auswertung de=
r ANSI-Codes=0D
-extern void con_putc_ansi(const char c); // Zeichen ausgeben mit Auswertun=
g der ANSI-Codes=0D
-extern void con_puts(const char * s); // Zeichenkette ausgeben mit Auswert=
ung der ANSI-Codes=0D
-extern void con_putsn(unsigned int n, const char * s); // wie con_puts, al=
lerdings werden maximal n Bytes ausgewertet=0D
-extern void con_flush_ansi_escape_code_sequence(void); // Zwischenspeicher=
 leeren=0D
-=0D
-#endif /* ndef CONSOLE_H */=0D
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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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 @@
-/*=0D
- * Copyright (c) 2006-2008 The tyndur Project. All rights reserved.=0D
- *=0D
- * This code is derived from software contributed to the tyndur Project=0D
- * by Kevin Wolf.=0D
- *=0D
- * Redistribution and use in source and binary forms, with or without=0D
- * modification, are permitted provided that the following conditions=0D
- * are met:=0D
- * 1. Redistributions of source code must retain the above copyright=0D
- *    notice, this list of conditions and the following disclaimer.=0D
- * 2. Redistributions in binary form must reproduce the above copyright=0D
- *    notice, this list of conditions and the following disclaimer in the=
=0D
- *    documentation and/or other materials provided with the distribution.=
=0D
- * 3. All advertising materials mentioning features or use of this softwar=
e=0D
- *    must display the following acknowledgement:=0D
- *     This product includes software developed by the tyndur Project=0D
- *     and its contributors.=0D
- * 4. Neither the name of the tyndur Project nor the names of its=0D
- *    contributors may be used to endorse or promote products derived=0D
- *    from this software without specific prior written permission.=0D
- *=0D
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=0D
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED=0D
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR=0D
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=0D
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=
=0D
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=0D
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=0D
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=0D
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=0D
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=0D
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0D
- */=0D
-=0D
-#ifndef _DEBUG_H_=0D
-#define _DEBUG_H_=0D
-=0D
-#include <stdint.h>=0D
-#include <stdbool.h>=0D
-=0D
-/* Debug-Funktionen und Helferlein */=0D
-=0D
-#define DEBUG_FLAG_INIT 1=0D
-#define DEBUG_FLAG_STACK_BACKTRACE 2=0D
-#define DEBUG_FLAG_PEDANTIC 4=0D
-#define DEBUG_FLAG_SYSCALL 8=0D
-=0D
-///Setzt die richtigen Debug-Flags anhand der Commandline vom bootloader=
=0D
-void debug_parse_cmdline(char* cmdline);=0D
-=0D
-///Ueberprueft ob ein bestimmtes Debug-Flag gesetzt ist=0D
-bool debug_test_flag(uint32_t flag);=0D
-=0D
-///Gibt die Debug-Meldung aus, wenn das Flag gesetzt ist=0D
-void debug_print(uint32_t flag, const char* message);=0D
-
-/*
- * Gibt einen Stack Backtrace aus, beginnend an den =EF=BF=BDbergebenen We=
rten
- * f=EF=BF=BDr 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 @@
-/*=0D
- * Copyright (c) 2007 The tyndur Project. All rights reserved.=0D
- *=0D
- * This code is derived from software contributed to the tyndur Project=0D
- * by Kevin Wolf.=0D
- *=0D
- * Redistribution and use in source and binary forms, with or without=0D
- * modification, are permitted provided that the following conditions=0D
- * are met:=0D
- * 1. Redistributions of source code must retain the above copyright=0D
- *    notice, this list of conditions and the following disclaimer.=0D
- * 2. Redistributions in binary form must reproduce the above copyright=0D
- *    notice, this list of conditions and the following disclaimer in the=
=0D
- *    documentation and/or other materials provided with the distribution.=
=0D
- * 3. All advertising materials mentioning features or use of this softwar=
e=0D
- *    must display the following acknowledgement:=0D
- *     This product includes software developed by the tyndur Project=0D
- *     and its contributors.=0D
- * 4. Neither the name of the tyndur Project nor the names of its=0D
- *    contributors may be used to endorse or promote products derived=0D
- *    from this software without specific prior written permission.=0D
- *=0D
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=0D
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED=0D
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR=0D
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=0D
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=
=0D
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=0D
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=0D
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=0D
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=0D
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=0D
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0D
- */=0D
-=0D
-#ifndef _GDT_H_=0D
-#define _GDT_H_=0D
-#include <types.h>=0D
-=0D
-void gdt_init(void);=0D
-void gdt_init_local(void);=0D
-=0D
-#endif //ifndef _GDT_H_=0D
-=0D
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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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/multiboo=
t.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 softwar=
e
- *    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 CONTRIBUTO=
RS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTO=
RS
- * 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 BUSINES=
S
- * 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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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 Sysca=
ll
-    /// nicht existiert.
-    void* handler;
-   =20
-    /// Anzahl der Argumente die der Syscall benoetigt
-    size_t arg_count;
-
-    /// true, wenn der Syscall nur aus dem Kernelspace aufgerufen werden d=
arf
-    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_coun=
t);
-
-/// 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* p=
hys);
-
-/// 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 siz=
e);
-
-/// 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=C3=B6=C3=9Fe eines Shared Memory zur=C3=BCckgeben
-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 =C3=BCber eine Ressource abfragen
-int syscall_lio_stat(lio_usp_resource_t* resid, struct lio_stat* sbuf);
-
-/// Ressource =C3=B6ffnen
-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=C3=9Fen
-int syscall_lio_close(lio_usp_stream_t* stream_id);
-
-/// Zus=C3=A4tzliche ID f=C3=BCr 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 =C3=BCbergeben hat, au=
slesen
-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 =C3=A4ndern
-void syscall_lio_seek(lio_usp_stream_t* stream_id, int64_t* offset,
-    int whence, int64_t* result);
-
-/// Dateigr=C3=B6=C3=9Fe =C3=A4ndern
-int syscall_lio_truncate(lio_usp_stream_t* stream_id, uint64_t* size);
-
-/// Ver=C3=A4nderte 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 nu=
m,
-    struct lio_usp_dir_entry* dent, ssize_t* result);
-
-/// Ressourcenspezifischen Befehl ausf=C3=BChren
-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=C3=B6schen
-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* na=
me,
-    size_t name_len);
-
-/// Kernel ueber abgearbeitete Operation informieren
-void syscall_lio_srv_op_done(struct lio_op* op, int status, uint64_t* resu=
lt);
-
-/// 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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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 =3D=3D ARCH_I386
-    /// IO-Bitmap
-    void* io_bitmap;
-#elif CONFIG_ARCH =3D=3D 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 i=
st
-    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* pr=
v);
-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 =C3=BCbergebenen 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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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=EF=BF=BDnkte Untermenge der ANSI Escape C=
odes. Alle
- * Sequenzen werden mit dem ASCII Zeichen ESC (Wert 0x1b) eingeleitet. ESC
- * soll im folgenden dieses Zeichen darstellen. Wir k=EF=BF=BDnnen folgend=
e Escape=20
- * 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 =EF=BF=BDndern, Fet=
tschrift, Blinken
- * ESC[s - Cursor-Position speichern
- * ESC[u - Cursor-Position wiederherstellen
- *
- * Folgende Farbcodes werden bei und ESC[#m oder ESC[#;#m unterst=EF=BF=BD=
tzt:
- * - Attribute:
- *  0 - Normale Schrift
- *  1 - Fett
- *  5 - Blinken
- * - Vordergrundfarben:
- *  30 - Schwarz
- *  31 - Rot
- *  32 - Gr=EF=BF=BDn
- *  33 - Gelb
- *  34 - Blau
- *  35 - Magenta
- *  36 - Cyan
- *  37 - Weiss
- * - Hintergrundfarben:
- *  40 - Schwarz
- *  41 - Rot
- *  42 - Gr=EF=BF=BDn
- *  43 - Gelb
- *  44 - Blau
- *  45 - Magenta
- *  46 - Cyan
- *  47 - Weiss
- *
- * Es k=EF=BF=BDnnen nur 1 oder 2 Farbcodes pro Escape-Sequenz angewendet =
werden.
- *
- * Ung=EF=BF=BDltige und nicht erkannte Sequenzen werden einfach ausgegebe=
n.
- */
-
-#define ASCII_ESC 0x1b
-
-#define SCREEN_WIDTH 80
-#define SCREEN_HEIGHT 25
-
-void con_set_hw_cursor(void);
-
-unsigned short * vidmem =3D (unsigned short*)0xb8000;
-
-// Aktuelle Cursor-Position
-static unsigned int cursor_x;
-static unsigned int cursor_y;
-
-typedef enum ansi_esc_seq_status
-{
-    INVALID =3D 0,
-    SUCCESS,
-    NEED_MORE,
-} ansi_esc_seq_status_t;
-
-// Puffer f=EF=BF=BDr die ANSI-Sequenzen
-static char ansi_buf[16];
-static unsigned int ansi_buf_ofs =3D 0;
-
-// Aufschl=EF=BF=BDsselung des Attribut-Bytes vom Text Modus
-static union
-{
-    unsigned char _color;
-    struct=20
-    {
-        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 >=3D SCREEN_WIDTH)
-    {
-        cursor_x =3D SCREEN_WIDTH - 1;
-    }
-    else
-    {
-        cursor_x =3D x;
-    }
-
-    if(y >=3D SCREEN_HEIGHT)
-    {
-        cursor_y =3D SCREEN_HEIGHT - 1;
-    }
-    else
-    {
-        cursor_y =3D y;
-    }
-
-    con_set_hw_cursor();
-}
-
-/**
- * Leert den Bildschirm
- */
-static void con_clear_screen(void)
-{
-    int i;
-
-    for(i =3D 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++)
-    {
-        vidmem[i] =3D con_color._color << 8;
-    }
-   =20
-    con_set_cursor_pos(0, 0);
-}
-
-/**
- * Scrollt eine Zeile nach unten
- */
-static void scroll_down(void)
-{
-    int i;
-   =20
-    memmove(vidmem, vidmem + SCREEN_WIDTH, SCREEN_WIDTH * (SCREEN_HEIGHT -=
 1) * 2);
-
-    for(i =3D SCREEN_WIDTH * (SCREEN_HEIGHT - 1); i < SCREEN_WIDTH * SCREE=
N_HEIGHT; i++)
-    {
-        vidmem[i] =3D con_color._color << 8;
-    }
-
-    con_set_cursor_pos(cursor_x, cursor_y - 1);
-}
-
-/**
- * Setzt die Attribute f=EF=BF=BDr die folgenden Ausgabe entsprechend der =
obigen Liste.
- */
-static ansi_esc_seq_status_t handle_ansi_formatting_sequence_number(int n)
-{
-    static char colors[8] =3D { 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 =3D 0;
-            con_color.blink =3D 0;
-            break;
-       =20
-        case 1: // Fett
-            con_color.bold =3D 1;
-            break;
-
-        case 5: // Blinken
-            con_color.blink =3D 1;
-            break;
-
-        case 30 ... 37: // Vordergrundfarbe
-            con_color.foreground =3D colors[n - 30];
-            break;
-
-        case 40 ... 47: // Hintergrundfarbe
-            con_color.background =3D colors[n - 40];
-            break;
-
-        default:
-            return INVALID;
-    }
-
-    return SUCCESS;
-}
-
-/**
- * L=EF=BF=BDscht den Bildschirm von der aktuellen Cursor Position bis zur
- * angegebenen Spalte
- *
- * @return Die Spalte bis zu der gel=EF=BF=BDscht wurde
- */
-static unsigned int con_clear_to(unsigned int column)
-{
-    int i;
-
-    for(i =3D cursor_x; i < column; i++)
-    {
-        vidmem[cursor_y * SCREEN_WIDTH + i] =3D con_color._color << 8;
-    }
-
-    return column;
-}
-
-/**
- * Versucht eine ANSI-Escape-Code-Sequenz zu parsen.=20
- *
- * @param ansi_buf Sequenz die ausgewertet werden soll
- * @param ansi_buf_len Anzahl der auszuwertenden Bytes
- *=20
- * @return INVALID, wenn die ANSI-Code-Sequenz ung=EF=BF=BDltig ist, SUCCE=
SS, wenn die
- *    ANSI-Code-Sequenz erfolgreich ausgewertet wurde, NEED_MORE, wenn die=
=20
- *    Sequenz unvollst=EF=BF=BDndig ist, und noch weitere Zeichen zur Ausw=
ertung=20
- *    eingelesen werden m=EF=BF=BDssen.
- */
-static ansi_esc_seq_status_t con_ansi_parse(const char * ansi_buf, unsigne=
d int ansi_buf_len)
-{
-    static unsigned int save_cursor_x;
-    static unsigned int save_cursor_y;
-
-    int i;
-    int n1 =3D 0, n2 =3D 0;
-    int have_n1 =3D 0, have_n2 =3D 0, have_delimiter =3D 0;
-   =20
-    if(ansi_buf_len =3D=3D 0)
-    {
-        return NEED_MORE;
-    }
-
-    if(ansi_buf[0] !=3D ASCII_ESC)
-    {
-        return INVALID;
-    }
-
-    if(ansi_buf_len =3D=3D 1)
-    {
-        return NEED_MORE;
-    }
-
-    if(ansi_buf[1] !=3D '[')
-    {
-        return INVALID;
-    }
-
-    if(ansi_buf_len =3D=3D 2)
-    {
-        return NEED_MORE;
-    }
-
-    for(i =3D 2; i < ansi_buf_len; i++)
-    {
-        switch(ansi_buf[i])
-        {
-            case '0' ... '9':
-                if(!have_delimiter)
-                {
-                    n1 =3D n1 * 10 + (ansi_buf[i] - '0');
-                    have_n1 =3D 1;
-                }
-                else
-                {
-                    n2 =3D n2 * 10 + (ansi_buf[i] - '0');
-                    have_n2 =3D 1;
-                }
-                break; // n=EF=BF=BDchstes Zeichen auswerten
-
-            case ';':
-                if(have_delimiter)
-                {
-                    return INVALID;
-                }
-                have_delimiter =3D 1;
-                break; // n=EF=BF=BDchstes 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;
-               =20
-            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 # bewege=
n
-            case 'f':
-                if(!have_n1 || !have_n2)
-                {
-                    return INVALID;
-                }
-               =20
-                con_set_cursor_pos(n1, n2);
-                return SUCCESS;
-
-            case 'J': // ESC[2J - Bildschirm leeren
-                if(have_delimiter || !have_n1 || have_n2 || n1 !=3D 2)
-                {
-                    return INVALID;
-                }
-                con_clear_screen();
-                return SUCCESS;
-
-            case 'K': // ESC[K - Bis Zeile von der Cursor Position zum End=
e leeren
-                if(have_delimiter || have_n1 || have_n2)
-                {
-                    return INVALID;
-                }
-               =20
-                con_clear_to(SCREEN_WIDTH);
-
-                return SUCCESS;
-
-            case 'm': // ESC[#m oder ESC[#;#m - Vorder- und Hintergrundfar=
be =EF=BF=BDndern, Fettschrift, Blinken
-                if(!have_n1)
-                {
-                    return INVALID;
-                }
-               =20
-                if(handle_ansi_formatting_sequence_number(n1) !=3D SUCCESS=
)
-                {
-                    return INVALID;
-                }
-
-                if(have_n2)
-                {
-                    if(handle_ansi_formatting_sequence_number(n2) !=3D SUC=
CESS)
-                    {
-                        return INVALID;
-                    }
-                }
-
-                return SUCCESS;
-
-            case 's': // ESC[s - Cursor-Position speichern
-                if(have_delimiter || have_n1 || have_n2)
-                {
-                    return INVALID;
-                }
-                save_cursor_x =3D cursor_x;
-                save_cursor_y =3D cursor_y;
-
-                return SUCCESS;
-
-            case 'u': // ESC[u - Cursor-Position wiederherstellen
-                if(have_delimiter || have_n1 || have_n2)
-                {
-                    return INVALID;
-                }
-                cursor_x =3D save_cursor_x;
-                cursor_y =3D 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 =3D 0;
-
-    if (c =3D=3D '\n') {
-        outb(0x3f8, '\r');
-        while ((inb(0x3fd) & 0x20) =3D=3D 0) asm("nop");
-    }
-    outb(0xe9, c);
-    outb(0x3f8, c);
-    while ((inb(0x3fd) & 0x20) =3D=3D 0) asm("nop");
-   =20
-    switch(c)
-    {
-        case '\n':
-            if (last_char !=3D '\r') {
-                con_clear_to(SCREEN_WIDTH);
-            }
-            cursor_x =3D 0;
-            cursor_y++;
-            break;
-       =20
-        case '\r':
-            cursor_x =3D 0;
-            break;
-       =20
-        case '\t':
-            cursor_x =3D con_clear_to((cursor_x & ~7) + 8);
-            break;
-
-        default:
-            vidmem[cursor_x + cursor_y * SCREEN_WIDTH] =3D c | (con_color.=
_color << 8);
-            cursor_x++;
-            break;
-    }
-   =20
-    if(cursor_x >=3D SCREEN_WIDTH)
-    {
-        cursor_y +=3D cursor_x / SCREEN_WIDTH;
-        cursor_x %=3D SCREEN_WIDTH;
-    }
-   =20
-
-    while(cursor_y >=3D SCREEN_HEIGHT)
-    {
-        scroll_down();
-    }
-    con_set_hw_cursor();
-
-    last_char =3D c;
-}
-
-/**
- * Gibt ein Zeichen auf der Konsole aus. Wenn das Zeichen ein Escape-Zeich=
en
- * ist, wird es und die folgenden Zeichen in einem Puffer zwischen gespeic=
hert,
- * bis entweder diese Zeichenfolge erfolgreich als ANSI-Escape-Code-Sequen=
z
- * ausgewertet wurde, oder feststeht, dass diese Sequenz ung=EF=BF=BDltig =
ist. In=20
- * diesem Fall werden alle Zeichen einschlie=EF=BF=BDlich des Escape-Zeich=
ens auf der=20
- * Konsole ausgegeben.
- */
-void con_putc_ansi(const char c)
-{
-    ansi_esc_seq_status_t status;
-    int i;
-
-    if(c =3D=3D ASCII_ESC || ansi_buf_ofs > 0)
-    {
-        ansi_buf[ansi_buf_ofs++] =3D c;
-
-        status =3D con_ansi_parse(ansi_buf, ansi_buf_ofs);
-
-        switch(status)
-        {
-            case NEED_MORE:
-                if(ansi_buf_ofs <=3D sizeof(ansi_buf))
-                {
-                    break;
-                }
-                // fall through
-
-            case INVALID:
-                for(i =3D 0; i < ansi_buf_ofs; i++)
-                {
-                    con_putc(ansi_buf[i]);
-                }
-                ansi_buf_ofs =3D 0;
-                break;
-           =20
-            case SUCCESS:
-                ansi_buf_ofs =3D 0;
-                break;
-        }
-    }
-    else
-    {
-        con_putc(c);
-    }
-}
-
-/**
- * Leert den Puffer, in dem die Zeichen einer m=EF=BF=BDglichen ANSI-Escap=
e-Code-
- * Sequenz zwischengespeichert werden. Diese Funktion muss aufgerufen werd=
en,
- * wenn sichergestellt werden soll, dass s=EF=BF=BDmtliche Zeichen, die vi=
a=20
- * con_putc_ansi ausgegeben werden sollen, tats=EF=BF=BDchlich ausgegeben =
werden.
- */
-void con_flush_ansi_escape_code_sequence(void)
-{
-    int i;
-   =20
-    if(ansi_buf_ofs > 0)
-    {
-        for(i =3D 0; i < ansi_buf_ofs; i++)
-        {
-            con_putc(ansi_buf[i]);
-        }
-        ansi_buf_ofs =3D 0;
-    }
-}
-
-/**
- * Gibt eine Zeichenkette auf der Konsole aus. Diese Zeichenkette kann
- * ANSI-Steuercodes enthalten.=20
- * Unvollst=EF=BF=BDndige und fehlerhafte Sequenzen werden einfach ausgege=
ben.
- */
-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=EF=BF=BDndige und fehlerhafte Sequenzen werden einfach ausgege=
ben.
- */
-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 =3D 0x07;
-    con_clear_screen();
-   =20
-    /* Initialisiert die serielle Schnittstelle */
-    /* 9600 Baud, 8 Datenbits, 1 Stopbit, keine Parit=EF=BF=BDt */
-   =20
-    /* COM1 -> 0x3F8 */
-    outb(0x3FB, 0x83); /* DLAB =3D 1 */
-    outb(0x3F8, 0x0C); /* 9600 Baud */
-    outb(0x3F9, 0x00);
-    outb(0x3FB, 0x03); /* DLAB =3D 0 */
-    outb(0x3F9, 0x00); /* keine Interrupts ausl=EF=BF=BDsen */
-    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 =3D 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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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 =3D 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) !=3D 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 =3D strstr(cmdline, "debug=3D");
-    debug_flags =3D 0;
-
-    if(pos =3D=3D NULL) return;
-
-    //Debug=3D ueberspringen
-    pos +=3D 6;
-    while((*pos !=3D 0) && (*pos !=3D ' '))
-    {
-        switch(*pos)
-        {
-            case 'i':
-                debug_flags |=3D DEBUG_FLAG_INIT;
-                break;
-
-            case 'p':
-                debug_flags |=3D DEBUG_FLAG_PEDANTIC;
-                break;
-
-            case 's':
-                debug_flags |=3D DEBUG_FLAG_STACK_BACKTRACE;
-                break;
-
-            case 'c':
-                debug_flags |=3D 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 @@
-/* =20
- * 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 softwar=
e
- *    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=20
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR=20
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,=20
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,=20
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF=
ITS;=20
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY=
,=20
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=
=20
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF=
=20
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */ =20
-
-#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 =3D {
-    .cmdline =3D "(Kernel)",
-};
-
-lock_t init_lock =3D 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 =C3=BCbergibt 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 =3D true;
-
-    p =3D strtok(cmdline, " ");
-
-    while (p) {
-        if (!strncmp(p, "debug=3D", 6)) {
-            debug_parse_cmdline(p);
-        } else if (!strcmp(p, "smp")) {
-            enable_smp =3D true;
-        } else if (kernel_name) {
-            kernel_name =3D false;
-        } else {
-            kprintf("Unbekannte Option: '%s'\n", p);
-        }
-
-        p =3D strtok(NULL, " ");
-    }
-}
-
-/**
- * Kernel-Initialisierung erfolgt hier,
- * die Funktion init wird von header.asm aufgerufen (BSP =3D true) oder au=
s
- * 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 =3D LOCK_LOCKED;;
-    // Diese ersten Initialisierungen muessen nur einmal, und ganz am Anfa=
ng
-    // gemacht werden.
-    if (bsp =3D=3D true) {
-        init_console();
-
-        // Multiboot-Infos sichern
-        memcpy(&multiboot_info, boot_info, sizeof(struct multiboot_info));
-
-        // Hiermit wird eine Laufende Multitasking-Umgebung simuliert. Die=
s ist
-        // notwendig, damit im restlichen Code keine Aenderungen notwendig=
 sind
-        // fuer die Initialisierung.
-        init_thread =3D (pm_thread_t) {
-            .process                =3D &init_process,
-            .kernel_stack_bottom    =3D (vaddr_t) &kernelstack_bottom,
-            .kernel_stack_size      =3D (uint8_t*) &kernelstack
-                                    - (uint8_t*) &kernelstack_bottom,
-        };
-
-        cpu_get(0)->thread =3D &init_thread;
-
-        // Debugparameter verarbeiten, das ist aber nur moeglich, wenn ein=
e
-        // Kernelkommandozeile existiert.
-        if ((multiboot_info.mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) !=3D 0)=
 {
-            parse_cmdline((char*)(uintptr_t)multiboot_info.mi_cmdline);
-        }
-
-#if CONFIG_ARCH =3D=3D 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 Speiche=
r
-        // 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 d=
er
-        // 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 ei=
nen "
-        "Prozessor");
-    gdt_init_local();
-    im_init_local();
-
-
-    // Auf dem BSP muss die ganze virtuelle Speicherverwaltung initialisie=
rt
-    // werden. Bei den APs reicht es, wenn sie ihren Stack mappen.
-    static volatile lock_t mm_prepare_lock =3D LOCK_LOCKED;
-    cpu_get_current()->thread =3D &init_thread;
-    if (bsp =3D=3D true) {
-        *init_context =3D 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 =3D=3D ARCH_AMD64
-            asm volatile("movq %%rsp, %0" : "=3Dr"(sp));
-        #else
-            asm volatile("movl %%esp, %0" : "=3Dr"(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 =3D 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 sin=
d,
-    // sonst rennen wir hier in Exceptions.
-    // TODO: Buildscripts fixen?
-    uint32_t edx =3D 0, dummy =3D 0;
-    asm volatile("cpuid": "=3Dd" (edx), "=3Da" (dummy) : "a" (1) : "ebx", =
"ecx");
-    if ((edx & (1 << 24)) && (edx & (1 << 25))) {
-        #if CONFIG_ARCH =3D=3D 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 =3D 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, wen=
n
-    // mapping-Funktionen aufgerufen werden. Darum muss alles gemappt sein=
,
-    // bevor vmm_init aufgerufen wird.
-    if (bsp =3D=3D 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 C=
PUs
-    // und gibt den endgueltigen Startschuss.
-    static volatile uint32_t final_cpus_arrived =3D 0;
-    static volatile lock_t final_lock =3D LOCK_LOCKED;
-    locked_increment(&final_cpus_arrived);
-
-    if (bsp =3D=3D 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 =3D pm_scheduler_pop();
-    interrupt_stack_frame_t* isf =3D 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 =3D 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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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.
- */
-=20
-#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=EF=BF=
=BDck */
-unsigned long long divmod(unsigned long long dividend, unsigned int diviso=
r, unsigned int * remainder)
-{
-#if CONFIG_ARCH =3D=3D ARCH_AMD64
-    if (remainder) {
-        *remainder =3D dividend % divisor;
-    }
-    return dividend / divisor;
-#else
-    unsigned int highword =3D dividend >> 32;
-    unsigned int lowword =3D dividend & 0xffffffff;
-    unsigned long long quotient;
-    unsigned int rem;
-   =20
-    __asm__("div %%ecx\n\t"
-        "xchg %%ebx, %%eax\n\t"
-        "div %%ecx\n\t"
-        "xchg %%edx, %%ebx"
-        : "=3DA"(quotient), "=3Db"(rem)
-        : "a"(highword), "b"(lowword), "c"(divisor), "d"(0)
-        );
-
-    if (remainder) {
-        *remainder =3D rem;
-    }
-
-    return quotient;
-#endif
-}
-
-/* Gibt eine unsigned 64-bit Zahl mit beliebiger Basis zwischen 2 und 36 a=
us */
-/*static*/ void kputn(unsigned long long x, int radix, int pad, char padch=
ar)
-{
-    char b[65];
-    char * r =3D b + 64; // r zeig auf das letzte Zeichen von b[]
-    char digits[] =3D "0123456789abcdefghijklmnopqrstuvwxyz";
-    unsigned int remainder;
-
-    if(radix < 2 || radix > 36)
-    {
-        return;
-    }
-
-    *r-- =3D 0;
-
-    do
-    {
-        x =3D divmod(x, radix, &remainder);
-        *r-- =3D digits[remainder];
-        pad--;
-    }
-    while(x > 0);
-
-    while(pad-- > 0)
-    {
-        con_putc_ansi(padchar);
-    }
-
-    con_puts(r + 1);
-}
-
-/* Hilfsfunktion f=EF=BF=BDr kprintf() */
-void kaprintf(char* format, va_list args)
-{
-    int pad;
-    char padfill;
-    unsigned long long value =3D 0;
-
-    while(*format)
-    {
-        if(*format =3D=3D '%')
-        {
-            format++;
-
-            pad =3D 0;
-            if(*format =3D=3D '0')
-            {
-                padfill =3D '0';
-                format++;
-            }
-            else
-            {
-                padfill =3D ' ';
-            }
-
-            while(*format >=3D '0' && *format <=3D '9')
-            {
-                pad =3D pad * 10 + *format++ - '0';
-            }
-
-            if(format[0] =3D=3D 'l' && format[1] =3D=3D 'l' && (format[2] =
=3D=3D 'd' || format[2] =3D=3D 'i'))
-            {
-                signed long long tmp =3D va_arg(args, long long int);
-                if (tmp < 0) {
-                    con_putc_ansi('-');
-                    pad--;
-                    value =3D -tmp;
-                } else {
-                    value =3D tmp;
-                }
-                format +=3D 2;
-            }
-            else if(format[0] =3D=3D 'l' && format[1] =3D=3D 'l' && (forma=
t[2] =3D=3D 'o' || format[2] =3D=3D 'u' || format[2] =3D=3D 'x'))
-            {
-                value =3D va_arg(args, unsigned long long int);
-                format +=3D 2;
-            }
-            else if(format[0] =3D=3D 'l' && (format[1] =3D=3D 'd' || forma=
t[1] =3D=3D 'i'))
-            {
-                signed long int tmp =3D va_arg(args, long int);
-                if(tmp < 0) {
-                    con_putc_ansi('-');
-                    pad--;
-                    value =3D -tmp;
-                } else {
-                    value =3D tmp;
-                }
-                format++;
-            } else if(format[0] =3D=3D 'z' && (format[1] =3D=3D 'u' || for=
mat[1] =3D=3D 'x')) {
-                value =3D va_arg(args, size_t);
-                format++;
-            }
-            else if(format[0] =3D=3D 'l' && (format[1] =3D=3D 'o' || forma=
t[1] =3D=3D 'u' || format[1] =3D=3D 'x'))
-            {
-                value =3D va_arg(args, unsigned long int);
-                format++;
-            }
-            else if(format[0] =3D=3D 'd' || format[0] =3D=3D 'i')
-            {
-                int tmp =3D va_arg(args, int);
-                if(tmp < 0) {
-                    con_putc_ansi('-');
-                    pad--;
-                    value =3D -tmp;
-                } else {
-                    value =3D tmp;
-                }
-            } else if(format[0] =3D=3D 'u' || format[0] =3D=3D 'o' || form=
at[0] =3D=3D 'x') {
-                value =3D va_arg(args, unsigned int);
-            } else if(format[0] =3D=3D 'p') {
-                value =3D 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 =3D (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++);
-        }
-    }
-   =20
-    con_flush_ansi_escape_code_sequence();
-}
-
-/* printf f=C3=BCr den Kernel. Nur f=C3=BCr Testzwecke gedacht.
- Unterst=C3=BCtzt %c, %d, %i, %o, %p, %u, %s, %x und %lld, %lli, %llo, %ll=
u, %llx, %zu, %zx. */
-void kprintf(char* format, ...)
-{
-    lock(&printf_lock);
-   =20
-    va_list args;
-   =20
-    va_start(args,format);
-    kaprintf(format, args);
-    va_end(args);
-
-    unlock(&printf_lock);
-}
-
-int printf(const char* format, ...)
-{
-    lock(&printf_lock);
-   =20
-    va_list args;
-    va_start(args,format);
-    kaprintf((char*) format, args);
-    va_end(args);
-   =20
-    unlock(&printf_lock);
-    return 0; // TODO Korrekte printf-R=EF=BF=BDckgabe
-}
-
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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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=EF=BF=BDr 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 =3D 0;
-
-/**=20
- * Gr=EF=BF=BD=EF=BF=BDe von pmm_bitmap in Elementen (=3D 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=EF=BF=BDck
- */
-void* pmm_get_bitmap_start()
-{
-    return pmm_bitmap;
-}
-
-/**
- * Setzt die Startadresse der Bitmap. Diese Funktion ist einzig und allein=
 dazu
- * bestimmt, den =EF=BF=BDbergang von physischen zu virtuellen Adressen be=
im
- * Einschalten von Paging bewerkstelligen zu k=EF=BF=BDnnen.
- */
-void pmm_set_bitmap_start(void* bitmap_start)
-{
-    pmm_bitmap =3D bitmap_start;
-}
-
-/**
- * Gibt die G=EF=BF=BD=EF=BF=BDe der Bitmap in Bytes zur=EF=BF=BDck
- */
-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 =3D 0;
-    size_t i, j;
-   =20
-    for (i =3D 0; i < pmm_bitmap_length; i++) {
-        for (j =3D 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 werde=
n=20
- * soll.
- */
-
-static inline void phys_mark_page_as_free(paddr_t page)
-{
-    //lock(&pmm_lock);
-    size_t bitmap_index =3D (size_t) page / PAGE_SIZE / PMM_BITS_PER_ELEME=
NT;
-    pmm_bitmap[bitmap_index] |=3D 1 << (((size_t) page / PAGE_SIZE) &=20
-        (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 =3D 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 we=
rden=20
- * soll.
- */
-
-static inline void phys_mark_page_as_used(paddr_t page)
-{
-    //lock(&pmm_lock);
-    size_t bitmap_index =3D (size_t) page / PAGE_SIZE / PMM_BITS_PER_ELEME=
NT;
-    pmm_bitmap[bitmap_index] &=3D ~(1 << (((size_t) page / PAGE_SIZE) &=20
-        (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 =3D 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 P=
age=20
- * zur=EF=BF=BDck.
- *
- * @param lower_index Index der niedrigsten erlaubten Page
- * @param upper_index Index der h=EF=BF=BDchsten 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=20
- *      Page zur=EF=BF=BDckgegeben (Bei Erfolg ist der R=EF=BF=BDckgabewer=
t immer
- *      durch PAGE_SIZE teilbar). Im Fehlerfall wird 1 zur=EF=BF=BDckgegeb=
en.
- */
-
-/* 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 =3D 0;
-    paddr_t page =3D 0;
-
-    for(i =3D lower_index; i < upper_index; i++)
-    {
-        if(pmm_bitmap[i] =3D=3D 0) {
-            found =3D 0;
-            continue;
-        }
-
-        if(pmm_bitmap[i] =3D=3D ~0x0)
-        {
-            if(found =3D=3D 0)
-            {
-                page =3D i * PMM_BITS_PER_ELEMENT * PAGE_SIZE;
-            }
-            found +=3D PMM_BITS_PER_ELEMENT;
-        }
-        else
-        {
-            for(j =3D 0; j < PMM_BITS_PER_ELEMENT; j++)
-            {
-                if(pmm_bitmap[i] & (1 << j))
-                {
-                    if(found =3D=3D 0) {
-                        page =3D (i * PMM_BITS_PER_ELEMENT + j) * PAGE_SIZ=
E;
-                    }
-                    found++;
-
-                    if(found > num) {
-                        break;
-                    }
-                }
-                else
-                {
-                    found =3D 0;
-                }
-            }
-        }
-
-        if(found > num) {
-            return page;
-        }
-    }
-
-    return 1;
-}
-
-
-/**
- * Reserviert num Pages.
- *
- * @param lower_limit Niedrigste erlaubte Adresse (Mu=EF=BF=BD auf 32-Bit-=
Systemen
- * auf einer 128K-Grenze liegen. Wenn nicht, wird gerundet)
- *
- * @param upper_limit H=EF=BF=BDchste erlaubte Adresse (Mu=EF=BF=BD 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 =3D (size_t) lower_limit / PMM_BITS_PER_ELEMENT;
-    size_t upper_index =3D (size_t) upper_limit / PMM_BITS_PER_ELEMENT;
-
-    if (upper_index > pmm_bitmap_length) {
-        upper_index =3D pmm_bitmap_length;
-    }
-
-    if ((upper_index > PMM_NUM_DMA_ELEMENTS) &&=20
-        (lower_index < PMM_NUM_DMA_ELEMENTS))
-    {
-        page =3D find_free_page_range(lower_index, upper_index, num);
-    }
-    else
-    {
-        page =3D find_free_page_range(PMM_NUM_DMA_ELEMENTS, upper_index, n=
um);
-   =20
-        if((size_t) page & (PAGE_SIZE - 1)) {
-            page =3D find_free_page_range(
-                lower_index,=20
-                min(PMM_NUM_DMA_ELEMENTS + num, upper_index),=20
-                num
-            );
-        }
-    }
-   =20
-    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=EF=
=BF=BDnnen.
- *
- * @see pmm_alloc_limits
- */
-paddr_t pmm_alloc(size_t num)
-{
-    paddr_t result =3D pmm_alloc_limits(
-        0,
-        pmm_bitmap_length * PMM_BITS_PER_ELEMENT * PAGE_SIZE,
-        num
-    );
-
-    return result;
-}
-
-
-/**
- * Gibt physisch zusammenh=EF=BF=BDngende 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=EF=BF=BDfen, 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 nich=
t
- * 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;
-
-    // =EF=BF=BDberpr=EF=BF=BDfung der BIOS-Memory-Map
-    struct multiboot_mmap* mmap;
-    uintptr_t mmap_addr =3D multiboot_info->mi_mmap_addr;
-    uintptr_t mmap_end =3D mmap_addr + multiboot_info->mi_mmap_length;
-
-    for(mmap =3D (struct multiboot_mmap*) (mmap_addr);
-        mmap < (struct multiboot_mmap*) (mmap_end);
-        mmap++)
-    {
-        uint64_t start =3D mmap->mm_base_addr;
-        uint64_t end   =3D mmap->mm_base_addr + mmap->mm_length - 1;
-
-        if (start > UINTPTR_MAX) {
-            continue;
-        }
-        if (end > UINTPTR_MAX) {
-            end =3D UINTPTR_MAX;
-        }
-
-        // Typ 1 steht f=EF=BF=BDr freien Speicher
-        if (mmap->mm_type =3D=3D 1) {
-            if (i-- =3D=3D 0) {
-                result.start    =3D (paddr_t)start;
-                result.end      =3D (paddr_t)end;
-                return result;
-            }
-        }
-    }
-
-    result.start =3D (paddr_t) 0xFFFFFFFF;
-    result.end   =3D (paddr_t) 0;
-
-    return result;
-}
-
-/**
- * Wird benutzt, um nacheinander alle belegten Speicherbereiche aufzuzaehl=
en.
- * Dies sind vor allem Kernel, Module und Multiboot-Strukturen. Vom BIOS a=
ls
- * reserviert gekennzeichnete Bereiche sind hierbei nicht enthalten. Um di=
e
- * 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-- =3D=3D 0)) {
-        result.start =3D (paddr_t) pmm_bitmap;
-        result.end   =3D (paddr_t)
-            (pmm_bitmap + ((pmm_bitmap_length / 8) * PMM_BITS_PER_ELEMENT)=
);
-        return result;
-    }
-
-    // Der Kernel ist besetzt
-    if (i-- =3D=3D 0) {
-        result.start    =3D (paddr_t) kernel_phys_start;
-        result.end      =3D (paddr_t) kernel_phys_end;
-        return result;
-    }
-
-    // Die Module auch.
-    {
-        uint32_t j;
-        struct multiboot_module* multiboot_module;
-        multiboot_module =3D (struct multiboot_module*) (uintptr_t)=20
-            multiboot_info->mi_mods_addr;
-
-        for (j =3D 0; j < multiboot_info->mi_mods_count; j++)=20
-        {
-            // Die Multiboot-Info zum Modul   =20
-            if (i-- =3D=3D 0) {
-                result.start    =3D (paddr_t) multiboot_module;
-                result.end      =3D (paddr_t) (multiboot_module + 1);
-                return result;
-            }
-
-            // Das Modul selbst
-            if (i-- =3D=3D 0) {
-                result.start    =3D (paddr_t) multiboot_module->start;
-                result.end      =3D (paddr_t) multiboot_module->end;
-                return result;
-            }
-
-            // Die Kommandozeile des Moduls=20
-            if (multiboot_module->cmdline) {
-                if (i-- =3D=3D 0) {
-                    result.start =3D (paddr_t) multiboot_module->cmdline;
-                    result.end   =3D (paddr_t) multiboot_module->cmdline +
-                        strlen((char*) (uintptr_t) multiboot_module->cmdli=
ne);
-                    return result;
-                }
-            }
-
-            multiboot_module++;
-        }
-    }
-
-    result.start =3D (paddr_t) 0xFFFFFFFF;
-    result.end   =3D (paddr_t) 0;
-
-    return result;
-}
-
-/**
- * Suche einen Platz f=EF=BF=BDr 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 =3D 0x0;
-
-        i =3D 0;
-        do
-        {
-            // Freien Speicherblock suchen und Bitmap an den Anfang legen
-            free =3D get_free_block(multiboot_info, i++);
-            if (free.start > free.end) {
-                panic("Keinen Platz fuer die Speicherbitmap gefunden");
-            }
-            bitmap =3D free.start;
-
-            // Probieren, ob der Speicherblock nicht doch besetzt ist und
-            // in diesem Fall ein Stueck weitergehen und nochmal von vorne
-            // durchprobieren
-            j =3D 0;
-            do
-            {
-                reserved =3D get_reserved_block(multiboot_info, j++, false=
);
-                if (!((reserved.start > bitmap + size)
-                    || (reserved.end <=3D bitmap)))
-                {
-                    j =3D 0;
-                    bitmap =3D (paddr_t)
-                        PAGE_ALIGN_ROUND_UP((uintptr_t) reserved.end);
-                }
-            }
-            while ((bitmap <=3D free.end) && (reserved.start < reserved.en=
d));
-
-            // Wenn die Bitmap nach Beruecksichtigung aller besetzten Bere=
iche
-            // immer noch im freien Bereich liegt, dann nehmen wir die Adr=
esse
-            if (bitmap <=3D free.end) {
-                return bitmap;
-            }
-        }
-        while(true);
-    } else {
-        return (paddr_t) 0x1000;
-    }
-}
-
-/**
- * Bestimmt die ben=EF=BF=BDtigte Gr=EF=BF=BD=EF=BF=BDe der Bitmap in Byte=
s
- */
-static size_t required_bitmap_size(struct multiboot_info* multiboot_info)
-{
-    // Suche die h=EF=BF=BDchste Adresse
-    paddr_t upper_end =3D 0;
-    if (multiboot_info->mi_flags & MULTIBOOT_INFO_HAS_MMAP)=20
-    {
-        struct multiboot_mmap* mmap =3D
-            (struct multiboot_mmap*) (uintptr_t) multiboot_info->mi_mmap_a=
ddr;
-
-        size_t i =3D 0;
-        for (i =3D 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 =
=3D=3D 1))
-            {
-                upper_end =3D (paddr_t)(uintptr_t)=20
-                    mmap[i].mm_base_addr + mmap[i].mm_length;
-            }
-        }
-    }
-    else=20
-    {
-        // Der hintere Cast verhindert Compiler-Warungen
-        upper_end =3D (paddr_t) (1024 * (1024 + (uintptr_t)=20
-            multiboot_info->mi_mem_upper));
-    }
-
-    // Umrechnen auf ben=EF=BF=BDtigte Bytes f=EF=BF=BDr die Bitmap
-    return (size_t) upper_end / PAGE_SIZE / 8;
-}
-
-/**
- * Initialisiert den physischen Speicher.
- *
- * @param mmap_addr Adresse der Memorymap.
- * @param mmap_length L=EF=BF=BDnge der Memorymap in Bytes.
- * @param upper_mem Gr=EF=BF=BD=EF=BF=BDe des upper_mem in Kilobyte, wie i=
n der Multboot-Info
- *      =EF=BF=BDbergeben.
- */
-void pmm_init(struct multiboot_info* multiboot_info)
-{
-    // Finde einen Platz f=EF=BF=BDr die Bitmap
-    size_t bitmap_size =3D required_bitmap_size(multiboot_info);
-    pmm_bitmap =3D (void*) find_bitmap_mem(multiboot_info, bitmap_size);
-    pmm_bitmap_length =3D 8 * bitmap_size / PMM_BITS_PER_ELEMENT;
-
-    // Am Anfang ist alles besetzt
-    memset(pmm_bitmap, 0x0, bitmap_size);
-
-    // ...anschlie=EF=BF=BDend die BIOS-Memory-Map abarbeiten
-    size_t i =3D 0;
-    do
-    {
-        struct mem_block block =3D 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 =3D 0;
-    do
-    {
-        struct mem_block block =3D 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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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 =3D NULL;
-static uint32_t shm_last_id =3D 0;
-
-static void shm_destroy_task(pm_process_t* process, void* prv);
-
-/**
- * Initialisiert die SHM-Verwaltung
- */
-void shm_init(void)
-{
-    shms =3D tree_create(struct shm_desc, tree_item, id);
-}
-
-/**
- * Neuen Shared Memory reservieren
- *
- * @return ID des neu angelegten Shared Memory. Der Aufrufer muss anschlie=
ssend
- * syscall_shm_attach aufrufen, um auf den Speicher zugreifen zu koennen.
- */
-uint32_t shm_create(size_t size)
-{
-    uint32_t id =3D ++shm_last_id;
-    struct shm_desc* shm;
-
-    while (tree_search(shms, id)) {
-        id++;
-    }
-
-    shm =3D calloc(1, sizeof(*shm));
-    shm->id =3D id;
-    shm->num_pages =3D NUM_PAGES(size);
-    shm->processes =3D 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 =3D tree_search(shms, id);
-    void* ret;
-    struct shm_process* shm_proc;
-
-    if (shm =3D=3D NULL) {
-        return NULL;
-    }
-
-    if (list_is_empty(shm->processes)) {
-        // Erster Prozess, der den SHM oeffnet: Speicher allozieren
-        ret =3D mmc_valloc(&process->context, shm->num_pages,
-            MM_FLAGS_USER_DATA);
-    } else {
-        // Ansonsten Mapping von einem anderen Prozess uebernehmen
-        struct shm_process* first =3D list_get_element_at(shm->processes, =
0);
-        ret =3D 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 =3D=3D NULL) {
-        return NULL;
-    }
-
-    shm_proc =3D calloc(1, sizeof(*shm_proc));
-    shm_proc->shm =3D shm;
-    shm_proc->process =3D process;
-    shm_proc->vaddr =3D ret;
-    list_push(shm->processes, shm_proc);
-
-    if (process->shm =3D=3D NULL) {
-        process->shm =3D 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 =3D tree_search(shms, id);
-    struct shm_process* shm_proc;
-    int i;
-
-    if (shm =3D=3D NULL) {
-        return;
-    }
-
-    // Aus der SHM-Liste des Prozesses austragen
-    for (i =3D 0; (shm_proc =3D list_get_element_at(process->shm, i)); i++=
) {
-        if (shm_proc->shm =3D=3D shm) {
-            list_remove(process->shm, i);
-            break;
-        }
-    }
-
-    // Aus der Prozessliste des SHM austragen
-    for (i =3D 0; (shm_proc =3D list_get_element_at(shm->processes, i)); i=
++) {
-        if (shm_proc->process =3D=3D 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 =3D 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 =3D NULL;
-        tree_remove(shms, shm);
-    }
-
-    // Virtuellen Speicher freigeben
-    mmc_unmap(&process->context, shm_proc->vaddr, shm->num_pages);
-
-
-    free(shm_proc);
-    if (shm->processes =3D=3D NULL) {
-        free(shm);
-    }
-
-    return;
-}
-
-/**
- * Gibt die Groesse des SHM-Bereichs in Bytes zurueck
- */
-size_t shm_size(uint32_t id)
-{
-    struct shm_desc* shm =3D tree_search(shms, id);
-
-    if (shm =3D=3D 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 =3D=3D NULL) {
-        return;
-    }
-
-    while ((shm_proc =3D 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/kernel2/src/module.mk
deleted file mode 100644
index 53124c2a..00000000
--- a/src/kernel2/src/module.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-### Kernel 2=0D
-kernel2: build/lost2.krn=0D
-=0D
-KERNEL2_SRC =3D $(call SOURCE_FILES_WILDCARD,src/kernel2/src/arch/$(ARCH))=
 $(call SOURCE_FILES_WILDCARD,src/kernel2/src/arch/$(ARCH)/*) $(call SOURCE=
_FILES,src/kernel2/src) $(call SOURCE_FILES_WILDCARD,src/kernel2/src/*)=0D
-KERNEL2_OBJS =3D $(call OBJECT_FILES,$(KERNEL2_SRC))=0D
-ALL_OBJS +=3D $(KERNEL2_OBJS)=0D
-build/lost2.krn: $(KERNEL2_OBJS) src/lib/library.a=0D
-	ld -o $@ $(LDFLAGS_KERNEL2) $^=0D
-build/lost2.krn: CPPFLAGS +=3D -Isrc/kernel2/include -Isrc/kernel2/include=
/arch/$(ARCH)=0D
-=0D
-zkernel2: build/lost2.kgz=0D
-=0D
-src/kernel2/src/smp/rm_trampoline.o: src/kernel2/src/smp/rm_trampoline.asm=
=0D
-	$(NASM) -f bin $< -o $(notdir $@)=0D
-	$(OBJCOPY) -B i386:i386 -I binary -O elf32-i386 $(notdir $@) $@=0D
-	rm $(notdir $@)=0D
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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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_cmdlin=
e,
-        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 =3D=3D 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 =3D=3D 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 =3D=3D 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 =3D=3D 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] =3D (syscall_t) {
-        .handler    =3D &kern_syscall_pm_sleep,
-        .arg_count  =3D 2,
-        .privileged =3D 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 uebergeb=
en
- *                  werden muessen.
- */
-void syscall_register(syscall_arg_t number, void* handler, size_t arg_coun=
t)
-{
-    // Ein Syscall mit einer zu grossen ID wuerde dazu fuehren, dass Teile=
 von
-    // Kernel-Daten ueberschrieben wuerden
-    if (number >=3D SYSCALL_MAX) {
-        panic("Es wurde versucht einen Syscall mit einer Nummer groesser a=
ls"
-                "SYSCALL_MAX zu reservieren!");
-    }
-    syscalls[number].handler =3D handler;
-    syscalls[number].arg_count =3D arg_count;
-    syscalls[number].privileged =3D 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 softwar=
e
- *    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 LIM=
ITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICU=
LAR
- * 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 PROF=
ITS;
- * 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* metada=
ta,
-    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 =3D list_create();
-
-    // PIT initialisieren
-    reload_value =3D 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 =3D malloc(sizeof(struct timeout));
-
-    timeout->task       =3D task;
-    timeout->timer_id   =3D timer_id;
-    timeout->timeout    =3D timer_ticks + usec;
-
-    // An der richtigen Stelle in der Liste einsortieren, so dass immer nu=
r
-    // das erste Listenelement geprueft werden muss
-    struct timeout* item;
-    int i;
-    for (i =3D 0; (item =3D 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 =3D 0;
-    static const uint32_t rpc_timer_function =3D 514;
-
-    struct timeout* item;
-    int i =3D 0;
-    while ((item =3D 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 erst=
en
-        // Timeout, der in der Zukunft liegt, abgebrochen werden.
-        //
-        // Overflows muessen abgefangen werden, da in diesem Spezialfall e=
ine
-        // groessere Zahl dennoch Vergangenheit bedeutet. Wie ich grad seh=
e,
-        // reden wir von einem qword und damit von einer Uptime von ein pa=
ar
-        // hunderttausend Jahren, aber tyndur ist ja stabil und wir daher
-        // optimistisch.
-        if (((item->timeout > microtime) && (microtime > last_microtime))
-            || ((item->timeout < last_microtime) && (microtime < last_micr=
otime)))
-        {
-            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 =3D microtime;
-}
-
-/**
- * Entfernt alle registrierten Timer eines Prozesses
- */
-void timer_cancel_all(pm_process_t* task)
-{
-    struct timeout* item;
-    int i;
-    for (i =3D 0; (item =3D list_get_element_at(timers, i)); i++) {
-        if (item->task =3D=3D task) {
-            list_remove(timers, i);
-        }
-    }
-}
--=20
2.28.0

