Index: kernel/arch/ppc32/Makefile.inc
===================================================================
--- kernel/arch/ppc32/Makefile.inc	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/Makefile.inc	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,88 @@
+#
+# Copyright (C) 2005 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+## Toolchain configuration
+#
+
+BFD_NAME = elf32-powerpc
+BFD_ARCH = powerpc:common
+BFD = binary
+TARGET = ppc-linux-gnu
+TOOLCHAIN_DIR = /usr/local/ppc/bin
+
+## Make some default assumptions
+#
+
+CFLAGS += -mcpu=powerpc -msoft-float -m32
+AFLAGS += -a32
+LFLAGS += -no-check-sections -N
+
+DEFS += -D__32_BITS__
+
+## Own configuration directives
+#
+
+CONFIG_FB = y
+
+## Compile with hierarchical page tables support.
+#
+
+CONFIG_PAGE_PT = y
+DEFS += -DCONFIG_PAGE_PT
+
+## Compile with support for address space identifiers.
+#
+
+CONFIG_ASID = y
+CONFIG_ASID_FIFO = y
+
+## Compile with support for software integer division.
+#
+
+CONFIG_SOFTINT = y
+
+ARCH_SOURCES = \
+	arch/$(ARCH)/src/context.S \
+	arch/$(ARCH)/src/debug/panic.s \
+	arch/$(ARCH)/src/fpu_context.S \
+	arch/$(ARCH)/src/boot/boot.S \
+	arch/$(ARCH)/src/ppc32.c \
+	arch/$(ARCH)/src/dummy.s \
+	arch/$(ARCH)/src/exception.S \
+	arch/$(ARCH)/src/interrupt.c \
+	arch/$(ARCH)/src/asm.S \
+	arch/$(ARCH)/src/cpu/cpu.c \
+	arch/$(ARCH)/src/proc/scheduler.c \
+	arch/$(ARCH)/src/ddi/ddi.c \
+	arch/$(ARCH)/src/drivers/cuda.c \
+	arch/$(ARCH)/src/mm/as.c \
+	arch/$(ARCH)/src/mm/frame.c \
+	arch/$(ARCH)/src/mm/memory_init.c \
+	arch/$(ARCH)/src/mm/page.c \
+	arch/$(ARCH)/src/mm/tlb.c \
+	arch/$(ARCH)/src/drivers/pic.c
Index: kernel/arch/ppc32/_link.ld.in
===================================================================
--- kernel/arch/ppc32/_link.ld.in	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/_link.ld.in	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,59 @@
+/** PPC32 linker script
+ *
+ * umapped section:
+ * 	kernel text
+ * 	kernel data
+ * mapped section:
+ *	kernel text
+ *	kernel data 
+ *
+ */
+
+#define __ASM__
+#include <arch/boot/boot.h>
+#include <arch/mm/page.h>
+
+ENTRY(kernel_image_start)
+OUTPUT_FORMAT("elf32-powerpc")
+OUTPUT_ARCH("powerpc:common")
+
+SECTIONS {
+	.unmapped 0: AT (0) {
+		unmapped_ktext_start = .;
+		*(K_UNMAPPED_TEXT_START);
+		unmapped_ktext_end = .;
+		
+		unmapped_kdata_start = .;
+		*(K_UNMAPPED_DATA_START);
+		unmapped_kdata_start = .;
+	}
+	
+	.mapped PA2KA(BOOT_OFFSET): AT (BOOT_OFFSET) { 
+		ktext_start = .;
+		*(K_TEXT_START);
+		*(.text);
+		ktext_end = .;
+		
+		kdata_start = .;
+		*(K_DATA_START);
+		*(.rodata);
+		*(.rodata.*);
+		*(.data);		/* initialized data */
+		*(.sdata);
+		*(.sdata2);
+		*(.sbss);
+		hardcoded_ktext_size = .;
+		LONG(ktext_end - ktext_start);	
+		hardcoded_kdata_size = .;
+		LONG(kdata_end - kdata_start);
+		hardcoded_load_address = .;
+		LONG(PA2KA(BOOT_OFFSET));
+		*(.bss);		/* uninitialized static variables */	
+		*(COMMON); 		/* global variables */
+
+		symbol_table = .;
+		*(symtab.*);            /* Symbol table, must be LAST symbol!*/
+
+		kdata_end = .;
+	}
+}
Index: kernel/arch/ppc32/include/arch.h
===================================================================
--- kernel/arch/ppc32/include/arch.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/arch.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_ARCH_H__
+#define __ppc32_ARCH_H__
+
+#include <arch/drivers/cuda.h>
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/arg.h
===================================================================
--- kernel/arch/ppc32/include/arg.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/arg.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_ARG_H__
+#define __ppc32_ARG_H__
+
+#include <stdarg.h>
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/asm.h
===================================================================
--- kernel/arch/ppc32/include/asm.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/asm.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_ASM_H__
+#define __ppc32_ASM_H__
+
+#include <arch/types.h>
+#include <config.h>
+
+/** Enable interrupts.
+ *
+ * Enable interrupts and return previous
+ * value of EE.
+ *
+ * @return Old interrupt priority level.
+ */
+static inline ipl_t interrupts_enable(void)
+{
+	ipl_t v;
+	ipl_t tmp;
+	
+	asm volatile (
+		"mfmsr %0\n"
+		"mfmsr %1\n"
+		"ori %1, %1, 1 << 15\n"
+		"mtmsr %1\n"
+		: "=r" (v), "=r" (tmp)
+	);
+	return v;
+}
+
+/** Disable interrupts.
+ *
+ * Disable interrupts and return previous
+ * value of EE.
+ *
+ * @return Old interrupt priority level.
+ */
+static inline ipl_t interrupts_disable(void)
+{
+	ipl_t v;
+	ipl_t tmp;
+	
+	asm volatile (
+		"mfmsr %0\n"
+		"mfmsr %1\n"
+		"rlwinm %1, %1, 0, 17, 15\n"
+		"mtmsr %1\n"
+		: "=r" (v), "=r" (tmp)
+	);
+	return v;
+}
+
+/** Restore interrupt priority level.
+ *
+ * Restore EE.
+ *
+ * @param ipl Saved interrupt priority level.
+ */
+static inline void interrupts_restore(ipl_t ipl)
+{
+	ipl_t tmp;
+	
+	asm volatile (
+		"mfmsr %1\n"
+		"rlwimi  %0, %1, 0, 17, 15\n"
+		"cmpw 0, %0, %1\n"
+		"beq 0f\n"
+		"mtmsr %0\n"
+		"0:\n"
+		: "=r" (ipl), "=r" (tmp)
+		: "0" (ipl)
+		: "cr0"
+	);
+}
+
+/** Return interrupt priority level.
+ *
+ * Return EE.
+ *
+ * @return Current interrupt priority level.
+ */
+static inline ipl_t interrupts_read(void)
+{
+	ipl_t v;
+	
+	asm volatile (
+		"mfmsr %0\n"
+		: "=r" (v)
+	);
+	return v;
+}
+
+/** Return base address of current stack.
+ *
+ * Return the base address of the current stack.
+ * The stack is assumed to be STACK_SIZE bytes long.
+ * The stack must start on page boundary.
+ */
+static inline uintptr_t get_stack_base(void)
+{
+	uintptr_t v;
+	
+	asm volatile (
+		"and %0, %%sp, %1\n"
+		: "=r" (v)
+		: "r" (~(STACK_SIZE - 1))
+	);
+	return v;
+}
+
+static inline void cpu_sleep(void)
+{
+}
+
+void cpu_halt(void);
+void asm_delay_loop(uint32_t t);
+
+extern void userspace_asm(uintptr_t uspace_uarg, uintptr_t stack, uintptr_t entry);
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/asm/regname.h
===================================================================
--- kernel/arch/ppc32/include/asm/regname.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/asm/regname.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,231 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_REGNAME_H__
+#define __ppc32_REGNAME_H__
+
+/* Condition Register Bit Fields */
+#define	cr0	0
+#define	cr1	1
+#define	cr2	2
+#define	cr3	3
+#define	cr4	4
+#define	cr5	5
+#define	cr6	6
+#define	cr7	7
+
+/* General Purpose Registers (GPRs) */
+#define	r0	0
+#define	r1	1
+#define	r2	2
+#define	r3	3
+#define	r4	4
+#define	r5	5
+#define	r6	6
+#define	r7	7
+#define	r8	8
+#define	r9	9
+#define	r10	10
+#define	r11	11
+#define	r12	12
+#define	r13	13
+#define	r14	14
+#define	r15	15
+#define	r16	16
+#define	r17	17
+#define	r18	18
+#define	r19	19
+#define	r20	20
+#define	r21	21
+#define	r22	22
+#define	r23	23
+#define	r24	24
+#define	r25	25
+#define	r26	26
+#define	r27	27
+#define	r28	28
+#define	r29	29
+#define	r30	30
+#define	r31	31
+
+/* GPR Aliases */
+#define	sp	1
+
+/* Floating Point Registers (FPRs) */
+#define	fr0		0
+#define	fr1		1
+#define	fr2		2
+#define	fr3		3
+#define	fr4		4
+#define	fr5		5
+#define	fr6		6
+#define	fr7		7
+#define	fr8		8
+#define	fr9		9
+#define	fr10	10
+#define	fr11	11
+#define	fr12	12
+#define	fr13	13
+#define	fr14	14
+#define	fr15	15
+#define	fr16	16
+#define	fr17	17
+#define	fr18	18
+#define	fr19	19
+#define	fr20	20
+#define	fr21	21
+#define	fr22	22
+#define	fr23	23
+#define	fr24	24
+#define	fr25	25
+#define	fr26	26
+#define	fr27	27
+#define	fr28	28
+#define	fr29	29
+#define	fr30	30
+#define	fr31	31
+
+#define	vr0		0
+#define	vr1		1
+#define	vr2		2
+#define	vr3		3
+#define	vr4		4
+#define	vr5		5
+#define	vr6		6
+#define	vr7		7
+#define	vr8		8
+#define	vr9		9
+#define	vr10	10
+#define	vr11	11
+#define	vr12	12
+#define	vr13	13
+#define	vr14	14
+#define	vr15	15
+#define	vr16	16
+#define	vr17	17
+#define	vr18	18
+#define	vr19	19
+#define	vr20	20
+#define	vr21	21
+#define	vr22	22
+#define	vr23	23
+#define	vr24	24
+#define	vr25	25
+#define	vr26	26
+#define	vr27	27
+#define	vr28	28
+#define	vr29	29
+#define	vr30	30
+#define	vr31	31
+
+#define	evr0	0
+#define	evr1	1
+#define	evr2	2
+#define	evr3	3
+#define	evr4	4
+#define	evr5	5
+#define	evr6	6
+#define	evr7	7
+#define	evr8	8
+#define	evr9	9
+#define	evr10	10
+#define	evr11	11
+#define	evr12	12
+#define	evr13	13
+#define	evr14	14
+#define	evr15	15
+#define	evr16	16
+#define	evr17	17
+#define	evr18	18
+#define	evr19	19
+#define	evr20	20
+#define	evr21	21
+#define	evr22	22
+#define	evr23	23
+#define	evr24	24
+#define	evr25	25
+#define	evr26	26
+#define	evr27	27
+#define	evr28	28
+#define	evr29	29
+#define	evr30	30
+#define	evr31	31
+
+/* Special Purpose Registers (SPRs) */
+#define	xer		1
+#define lr		8
+#define ctr		9
+#define	dec		22
+#define	sdr1	25
+#define	srr0	26
+#define srr1	27
+#define	sprg0	272
+#define	sprg1	273
+#define	sprg2	274
+#define	sprg3	275
+#define	prv		287
+#define ibat0u	528
+#define ibat0l	529
+#define ibat1u	530
+#define ibat1l	531
+#define ibat2u	532
+#define ibat2l	533
+#define ibat3u	534
+#define ibat3l	535
+#define dbat0u	536
+#define dbat0l	537
+#define dbat1u	538
+#define dbat1l	539
+#define dbat2u	540
+#define dbat2l	541
+#define dbat3u	542
+#define dbat3l	543
+#define hid0	1008
+
+/* MSR bits */
+#define msr_ir	(1 << 4)
+#define msr_dr	(1 << 5)
+#define msr_pr	(1 << 14)
+#define msr_ee	(1 << 15)
+
+/* HID0 bits */
+#define hid0_ice	(1 << 15)
+#define hid0_dce	(1 << 14)
+#define hid0_icfi	(1 << 11)
+#define hid0_dci	(1 << 10)
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/atomic.h
===================================================================
--- kernel/arch/ppc32/include/atomic.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/atomic.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_ATOMIC_H__
+#define __ppc32_ATOMIC_H__
+
+static inline void atomic_inc(atomic_t *val)
+{
+	long tmp;
+
+	asm volatile (
+		"1:\n"
+		"lwarx %0, 0, %2\n"
+		"addic %0, %0, 1\n"
+		"stwcx. %0, 0, %2\n"
+		"bne- 1b"
+		: "=&r" (tmp), "=m" (val->count)
+		: "r" (&val->count), "m" (val->count)
+		: "cc"
+	);
+}
+
+static inline void atomic_dec(atomic_t *val)
+{
+	long tmp;
+
+	asm volatile (
+		"1:\n"
+		"lwarx %0, 0, %2\n"
+		"addic %0, %0, -1\n"
+		"stwcx.	%0, 0, %2\n"
+		"bne- 1b"
+		: "=&r" (tmp), "=m" (val->count)
+		: "r" (&val->count), "m" (val->count)
+		: "cc"
+	);
+}
+
+static inline long atomic_postinc(atomic_t *val)
+{
+	atomic_inc(val);
+	return val->count - 1;
+}
+
+static inline long atomic_postdec(atomic_t *val)
+{
+	atomic_dec(val);
+	return val->count + 1;
+}
+
+static inline long atomic_preinc(atomic_t *val)
+{
+	atomic_inc(val);
+	return val->count;
+}
+
+static inline long atomic_predec(atomic_t *val)
+{
+	atomic_dec(val);
+	return val->count;
+}
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/barrier.h
===================================================================
--- kernel/arch/ppc32/include/barrier.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/barrier.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_BARRIER_H__
+#define __ppc32_BARRIER_H__
+
+#define CS_ENTER_BARRIER()	asm volatile ("" ::: "memory")
+#define CS_LEAVE_BARRIER()	asm volatile ("" ::: "memory")
+
+#define memory_barrier() asm volatile ("sync" ::: "memory")
+#define read_barrier() asm volatile ("sync" ::: "memory")
+#define write_barrier() asm volatile ("eieio" ::: "memory")
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/boot/boot.h
===================================================================
--- kernel/arch/ppc32/include/boot/boot.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/boot/boot.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2006 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_BOOT_H__
+#define __ppc32_BOOT_H__
+
+#define BOOT_OFFSET		0x8000
+
+/* Temporary stack size for boot process */
+#define TEMP_STACK_SIZE 0x100
+
+#define TASKMAP_MAX_RECORDS 32
+#define MEMMAP_MAX_RECORDS 32
+
+#ifndef __ASM__
+
+#include <arch/types.h>
+
+typedef struct {
+	uintptr_t addr;
+	uint32_t size;
+} utask_t;
+
+typedef struct {
+	uint32_t count;
+	utask_t tasks[TASKMAP_MAX_RECORDS];
+} taskmap_t;
+
+typedef struct {
+	uintptr_t start;
+	uint32_t size;
+} memzone_t;
+
+typedef struct {
+	uint32_t total;
+	uint32_t count;
+	memzone_t zones[MEMMAP_MAX_RECORDS];
+} memmap_t;
+
+typedef struct {
+	uintptr_t addr;
+	unsigned int width;
+	unsigned int height;
+	unsigned int bpp;
+	unsigned int scanline;
+} screen_t;
+
+typedef struct {
+	uintptr_t addr;
+	unsigned int size;
+} keyboard_t;
+
+typedef struct {
+	memmap_t memmap;
+	taskmap_t taskmap;
+	screen_t screen;
+	keyboard_t keyboard;
+} bootinfo_t;
+
+extern bootinfo_t bootinfo;
+
+#endif
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/byteorder.h
===================================================================
--- kernel/arch/ppc32/include/byteorder.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/byteorder.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2005 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_BYTEORDER_H__
+#define __ppc32_BYTEORDER_H__
+
+#include <arch/types.h>
+#include <byteorder.h>
+
+#define BIG_ENDIAN
+
+static inline uint64_t uint64_t_le2host(uint64_t n)
+{
+	return uint64_t_byteorder_swap(n);
+}
+
+
+/** Convert little-endian unative_t to host unative_t
+ *
+ * Convert little-endian unative_t parameter to host endianess.
+ *
+ * @param n Little-endian unative_t argument.
+ *
+ * @return Result in host endianess.
+ *
+ */
+static inline unative_t unative_t_le2host(unative_t n)
+{
+	uintptr_t v;
+	
+	asm volatile (
+		"lwbrx %0, %1, %2\n"
+		: "=r" (v)
+		: "i" (0), "r" (&n)
+	);
+	return v;
+}
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/context.h
===================================================================
--- kernel/arch/ppc32/include/context.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/context.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_CONTEXT_H__
+#define __ppc32_CONTEXT_H__
+
+#ifndef __ppc32_TYPES_H__
+# include <arch/types.h>
+#endif
+
+#define SP_DELTA	16
+
+struct context {
+	uintptr_t sp;
+	uintptr_t pc;
+	
+	uint32_t r2;
+	uint32_t r13;
+	uint32_t r14;
+	uint32_t r15;
+	uint32_t r16;
+	uint32_t r17;
+	uint32_t r18;
+	uint32_t r19;
+	uint32_t r20;
+	uint32_t r21;
+	uint32_t r22;
+	uint32_t r23;
+	uint32_t r24;
+	uint32_t r25;
+	uint32_t r26;
+	uint32_t r27;
+	uint32_t r28;
+	uint32_t r29;
+	uint32_t r30;
+	uint32_t r31;
+	
+	uint32_t cr;
+	
+	ipl_t ipl;
+} __attribute__ ((packed));
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/context_offset.h
===================================================================
--- kernel/arch/ppc32/include/context_offset.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/context_offset.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,49 @@
+/* This file is automatically generated by gencontext.c. */
+/* struct context */
+#define OFFSET_SP    0x0
+#define OFFSET_PC    0x4
+#define OFFSET_R2    0x8
+#define OFFSET_R13   0xc
+#define OFFSET_R14   0x10
+#define OFFSET_R15   0x14
+#define OFFSET_R16   0x18
+#define OFFSET_R17   0x1c
+#define OFFSET_R18   0x20
+#define OFFSET_R19   0x24
+#define OFFSET_R20   0x28
+#define OFFSET_R21   0x2c
+#define OFFSET_R22   0x30
+#define OFFSET_R23   0x34
+#define OFFSET_R24   0x38
+#define OFFSET_R25   0x3c
+#define OFFSET_R26   0x40
+#define OFFSET_R27   0x44
+#define OFFSET_R28   0x48
+#define OFFSET_R29   0x4c
+#define OFFSET_R30   0x50
+#define OFFSET_R31   0x54
+#define OFFSET_CR    0x58
+
+#define OFFSET_FR14  0x0
+#define OFFSET_FR15  0x8
+#define OFFSET_FR16  0x10
+#define OFFSET_FR17  0x18
+#define OFFSET_FR18  0x20
+#define OFFSET_FR19  0x28
+#define OFFSET_FR20  0x30
+#define OFFSET_FR21  0x38
+#define OFFSET_FR22  0x40
+#define OFFSET_FR23  0x48
+#define OFFSET_FR24  0x50
+#define OFFSET_FR25  0x58
+#define OFFSET_FR26  0x60
+#define OFFSET_FR27  0x68
+#define OFFSET_FR28  0x70
+#define OFFSET_FR29  0x78
+#define OFFSET_FR30  0x80
+#define OFFSET_FR31  0x88
+#define OFFSET_FPSCR 0x90
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/cpu.h
===================================================================
--- kernel/arch/ppc32/include/cpu.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/cpu.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_CPU_H__
+#define __ppc32_CPU_H__
+
+#include <typedefs.h>
+
+struct cpu_arch {
+	int version;
+	int revision;
+};
+	
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/cpuid.h
===================================================================
--- kernel/arch/ppc32/include/cpuid.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/cpuid.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2006 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_CPUID_H__
+#define __ppc32_CPUID_H__
+
+#include <arch/types.h>
+
+struct cpu_info {
+	uint16_t version;
+	uint16_t revision;
+} __attribute__ ((packed));
+
+static inline void cpu_version(struct cpu_info *info)
+{
+	asm volatile (
+		"mfpvr %0\n"
+		: "=r" (*info)
+	);
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/debug.h
===================================================================
--- kernel/arch/ppc32/include/debug.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/debug.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2005 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32debug
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_DEBUG_H__
+#define __ppc32_DEBUG_H__
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/drivers/cuda.h
===================================================================
--- kernel/arch/ppc32/include/drivers/cuda.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/drivers/cuda.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2006 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __CUDA_H__
+#define __CUDA_H__
+
+#include <arch/types.h>
+#include <typedefs.h>
+
+#define CUDA_IRQ 10
+
+extern void cuda_init(uintptr_t base, size_t size);
+extern int cuda_get_scancode(void);
+extern void cuda_grab(void);
+extern void cuda_release(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/drivers/pic.h
===================================================================
--- kernel/arch/ppc32/include/drivers/pic.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/drivers/pic.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2006 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __PIC_H_
+#define __PIC_H_
+
+#define PIC_PENDING_LOW    8
+#define PIC_PENDING_HIGH   4
+#define PIC_MASK_LOW       9
+#define PIC_MASK_HIGH      5
+#define PIC_ACK_LOW        10
+#define PIC_ACK_HIGH       6
+
+void pic_init(uintptr_t base, size_t size);
+void pic_enable_interrupt(int intnum);
+void pic_disable_interrupt(int intnum);
+void pic_ack_interrupt(int intnum);
+int pic_get_pending(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/elf.h
===================================================================
--- kernel/arch/ppc32/include/elf.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/elf.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2006 Sergey Bondari
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_ELF_H__
+#define __ppc32_ELF_H__
+
+#define	ELF_MACHINE		EM_PPC
+#define ELF_DATA_ENCODING	ELFDATA2MSB
+#define ELF_CLASS		ELFCLASS32
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/exception.h
===================================================================
--- kernel/arch/ppc32/include/exception.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/exception.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2006 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_EXCEPTION_H__
+#define __ppc32_EXCEPTION_H__
+
+#ifndef __ppc32_TYPES_H__
+#  include <arch/types.h>
+#endif
+
+#include <typedefs.h>
+
+struct istate {
+	uint32_t r0;
+	uint32_t r2;
+	uint32_t r3;
+	uint32_t r4;
+	uint32_t r5;
+	uint32_t r6;
+	uint32_t r7;
+	uint32_t r8;
+	uint32_t r9;
+	uint32_t r10;
+	uint32_t r11;
+	uint32_t r13;
+	uint32_t r14;
+	uint32_t r15;
+	uint32_t r16;
+	uint32_t r17;
+	uint32_t r18;
+	uint32_t r19;
+	uint32_t r20;
+	uint32_t r21;
+	uint32_t r22;
+	uint32_t r23;
+	uint32_t r24;
+	uint32_t r25;
+	uint32_t r26;
+	uint32_t r27;
+	uint32_t r28;
+	uint32_t r29;
+	uint32_t r30;
+	uint32_t r31;
+	uint32_t cr;
+	uint32_t pc;
+	uint32_t srr1;
+	uint32_t lr;
+	uint32_t ctr;
+	uint32_t xer;
+	uint32_t r12;
+	uint32_t sp;
+};
+
+static inline void istate_set_retaddr(istate_t *istate, uintptr_t retaddr)
+{
+	istate->pc = retaddr;
+}
+/** Return true if exception happened while in userspace */
+#include <panic.h>
+static inline int istate_from_uspace(istate_t *istate)
+{
+	panic("istate_from_uspace not yet implemented");
+	return 0;
+}
+static inline unative_t istate_get_pc(istate_t *istate)
+{
+	return istate->pc;
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/faddr.h
===================================================================
--- kernel/arch/ppc32/include/faddr.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/faddr.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_FADDR_H__
+#define __ppc32_FADDR_H__
+
+#include <arch/types.h>
+
+#define FADDR(fptr)		((uintptr_t) (fptr))
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/fpu_context.h
===================================================================
--- kernel/arch/ppc32/include/fpu_context.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/fpu_context.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_FPU_CONTEXT_H__
+#define __ppc32_FPU_CONTEXT_H__
+
+#ifndef __ppc32_TYPES_H__
+# include <arch/types.h>
+#endif
+
+struct fpu_context {
+	uint64_t fr14;
+	uint64_t fr15;
+	uint64_t fr16;
+	uint64_t fr17;
+	uint64_t fr18;
+	uint64_t fr19;
+	uint64_t fr20;
+	uint64_t fr21;
+	uint64_t fr22;
+	uint64_t fr23;
+	uint64_t fr24;
+	uint64_t fr25;
+	uint64_t fr26;
+	uint64_t fr27;
+	uint64_t fr28;
+	uint64_t fr29;
+	uint64_t fr30;
+	uint64_t fr31;
+	uint32_t fpscr;
+} __attribute__ ((packed));
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/interrupt.h
===================================================================
--- kernel/arch/ppc32/include/interrupt.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/interrupt.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32interrupt
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_INTERRUPT_H__
+#define __ppc32_INTERRUPT_H__
+
+#include <arch/exception.h>
+
+#define IRQ_COUNT	64
+
+
+#define IVT_ITEMS   (16 + IRQ_COUNT)
+#define INT_OFFSET  16
+
+#define int_register(it, name, handler) exc_register(((it) + INT_OFFSET), name, handler)
+
+#define VECTOR_DATA_STORAGE 2
+#define VECTOR_INSTRUCTION_STORAGE 3
+#define VECTOR_EXTERNAL 4
+#define VECTOR_DECREMENTER 8
+
+extern void start_decrementer(void);
+extern void interrupt_init(void);
+extern void extint_handler(int n, istate_t *istate);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/memstr.h
===================================================================
--- kernel/arch/ppc32/include/memstr.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/memstr.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2005 Sergey Bondari
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_MEMSTR_H__
+#define __ppc32_MEMSTR_H__
+
+#define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
+
+extern void memsetw(uintptr_t dst, size_t cnt, uint16_t x);
+extern void memsetb(uintptr_t dst, size_t cnt, uint8_t x);
+
+extern int memcmp(uintptr_t src, uintptr_t dst, int cnt);
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/mm/as.h
===================================================================
--- kernel/arch/ppc32/include/mm/as.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/mm/as.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32mm	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_AS_H__
+#define __ppc32_AS_H__
+
+#define KERNEL_ADDRESS_SPACE_SHADOWED_ARCH	0
+
+#define KERNEL_ADDRESS_SPACE_START_ARCH		((unsigned long) 0x80000000)
+#define KERNEL_ADDRESS_SPACE_END_ARCH		((unsigned long) 0xffffffff)
+#define USER_ADDRESS_SPACE_START_ARCH		((unsigned long) 0x00000000)
+#define USER_ADDRESS_SPACE_END_ARCH		((unsigned long) 0x7fffffff)
+
+#define USTACK_ADDRESS_ARCH	(0x7fffffff-(PAGE_SIZE-1))
+
+extern void as_arch_init(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/mm/asid.h
===================================================================
--- kernel/arch/ppc32/include/mm/asid.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/mm/asid.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2005 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32mm	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_ASID_H__
+#define __ppc32_ASID_H__
+
+#include <arch/types.h>
+
+#define ASID_MAX_ARCH		4096
+
+typedef uint32_t asid_t;
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/mm/frame.h
===================================================================
--- kernel/arch/ppc32/include/mm/frame.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/mm/frame.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32mm	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_FRAME_H__
+#define __ppc32_FRAME_H__
+
+#define FRAME_WIDTH		12	/* 4K */
+#define FRAME_SIZE		(1 << FRAME_WIDTH)
+
+#ifdef KERNEL
+#ifndef __ASM__
+
+#include <arch/types.h> 
+
+extern uintptr_t last_frame;
+
+extern void frame_arch_init(void);
+
+#endif /* __ASM__ */
+#endif /* KERNEL */
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/mm/memory_init.h
===================================================================
--- kernel/arch/ppc32/include/mm/memory_init.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/mm/memory_init.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32mm	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_MEMORY_INIT_H__
+#define __ppc32_MEMORY_INIT_H__
+
+#include <typedefs.h>
+
+size_t get_memory_size(void);
+
+void memory_print_map(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/mm/page.h
===================================================================
--- kernel/arch/ppc32/include/mm/page.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/mm/page.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32mm	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_PAGE_H__
+#define __ppc32_PAGE_H__
+
+#include <arch/mm/frame.h>
+
+#define PAGE_WIDTH	FRAME_WIDTH
+#define PAGE_SIZE	FRAME_SIZE
+
+#ifdef KERNEL
+
+#ifndef __ASM__
+#	define KA2PA(x)	(((uintptr_t) (x)) - 0x80000000)
+#	define PA2KA(x)	(((uintptr_t) (x)) + 0x80000000)
+#else
+#	define KA2PA(x)	((x) - 0x80000000)
+#	define PA2KA(x)	((x) + 0x80000000)
+#endif
+
+/*
+ * Implementation of generic 4-level page table interface,
+ * the hardware Page Hash Table is used as cache.
+ *
+ * Page table layout:
+ * - 32-bit virtual addressess
+ * - Offset is 12 bits => pages are 4K long
+ * - PTL0 has 1024 entries (10 bits)
+ * - PTL1 is not used
+ * - PTL2 is not used
+ * - PLT3 has 1024 entries (10 bits)
+ */
+
+#define PTL0_ENTRIES_ARCH	1024
+#define PTL1_ENTRIES_ARCH	0
+#define PTL2_ENTRIES_ARCH	0
+#define PTL3_ENTRIES_ARCH	1024
+
+#define PTL0_INDEX_ARCH(vaddr)	(((vaddr) >> 22) & 0x3ff)
+#define PTL1_INDEX_ARCH(vaddr)	0
+#define PTL2_INDEX_ARCH(vaddr)	0
+#define PTL3_INDEX_ARCH(vaddr)	(((vaddr) >> 12) & 0x3ff)
+
+#define GET_PTL1_ADDRESS_ARCH(ptl0, i)		(((pte_t *) (ptl0))[(i)].pfn << 12)
+#define GET_PTL2_ADDRESS_ARCH(ptl1, i)		(ptl1)
+#define GET_PTL3_ADDRESS_ARCH(ptl2, i)		(ptl2)
+#define GET_FRAME_ADDRESS_ARCH(ptl3, i)		(((pte_t *) (ptl3))[(i)].pfn << 12)
+
+#define SET_PTL0_ADDRESS_ARCH(ptl0)
+#define SET_PTL1_ADDRESS_ARCH(ptl0, i, a)	(((pte_t *) (ptl0))[(i)].pfn = (a) >> 12)
+#define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)
+#define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)
+#define SET_FRAME_ADDRESS_ARCH(ptl3, i, a)	(((pte_t *) (ptl3))[(i)].pfn = (a) >> 12)
+
+#define GET_PTL1_FLAGS_ARCH(ptl0, i)		get_pt_flags((pte_t *) (ptl0), (index_t) (i))
+#define GET_PTL2_FLAGS_ARCH(ptl1, i)		PAGE_PRESENT
+#define GET_PTL3_FLAGS_ARCH(ptl2, i)		PAGE_PRESENT
+#define GET_FRAME_FLAGS_ARCH(ptl3, i)		get_pt_flags((pte_t *) (ptl3), (index_t) (i))
+
+#define SET_PTL1_FLAGS_ARCH(ptl0, i, x)		set_pt_flags((pte_t *) (ptl0), (index_t) (i), (x))
+#define SET_PTL2_FLAGS_ARCH(ptl1, i, x)
+#define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
+#define SET_FRAME_FLAGS_ARCH(ptl3, i, x)	set_pt_flags((pte_t *) (ptl3), (index_t) (i), (x))
+
+#define PTE_VALID_ARCH(pte)			(*((uint32_t *) (pte)) != 0)
+#define PTE_PRESENT_ARCH(pte)			((pte)->p != 0)
+#define PTE_GET_FRAME_ARCH(pte)			((pte)->pfn << 12)
+#define PTE_WRITABLE_ARCH(pte)			1
+#define PTE_EXECUTABLE_ARCH(pte)		1
+
+#ifndef __ASM__
+
+#include <mm/page.h>
+#include <arch/mm/frame.h>
+#include <arch/types.h>
+
+static inline int get_pt_flags(pte_t *pt, index_t i)
+{
+	pte_t *p = &pt[i];
+	
+	return (
+		(1 << PAGE_CACHEABLE_SHIFT) |
+		((!p->p) << PAGE_PRESENT_SHIFT) |
+		(1 << PAGE_USER_SHIFT) |
+		(1 << PAGE_READ_SHIFT) |
+		(1 << PAGE_WRITE_SHIFT) |
+		(1 << PAGE_EXEC_SHIFT) |
+		(p->g << PAGE_GLOBAL_SHIFT)
+	);
+}
+
+static inline void set_pt_flags(pte_t *pt, index_t i, int flags)
+{
+	pte_t *p = &pt[i];
+	
+	p->p = !(flags & PAGE_NOT_PRESENT);
+	p->g = (flags & PAGE_GLOBAL) != 0;
+	p->valid = 1;
+}
+
+extern void page_arch_init(void);
+
+#endif /* __ASM__ */
+
+#endif /* KERNEL */
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/mm/tlb.h
===================================================================
--- kernel/arch/ppc32/include/mm/tlb.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/mm/tlb.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2006 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32mm	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_TLB_H__
+#define __ppc32_TLB_H__
+
+typedef struct {
+	unsigned v : 1;          /**< Valid */
+	unsigned vsid : 24;      /**< Virtual Segment ID */
+	unsigned h : 1;          /**< Primary/secondary hash */
+	unsigned api : 6;        /**< Abbreviated Page Index */
+	unsigned rpn : 20;       /**< Real Page Number */
+	unsigned reserved0 : 3;
+	unsigned r : 1;          /**< Reference */
+	unsigned c : 1;          /**< Change */
+	unsigned wimg : 4;       /**< Access control */
+	unsigned reserved1 : 1;
+	unsigned pp : 2;         /**< Page protection */
+} phte_t;
+
+extern void pht_refill(int n, istate_t *istate);
+extern bool pht_real_refill(int n, istate_t *istate) __attribute__ ((section("K_UNMAPPED_TEXT_START")));
+extern void pht_init(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/proc/task.h
===================================================================
--- kernel/arch/ppc32/include/proc/task.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/proc/task.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2006 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32proc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_TASK_H__
+#define __ppc32_TASK_H__
+
+typedef struct {
+} task_arch_t;
+
+#define task_create_arch(t)
+#define task_destroy_arch(t)
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/proc/thread.h
===================================================================
--- kernel/arch/ppc32/include/proc/thread.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/proc/thread.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32proc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_THREAD_H__
+#define __ppc32_THREAD_H__
+
+typedef struct {
+} thread_arch_t;
+
+#define thread_create_arch(t)
+
+#endif
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/include/types.h
===================================================================
--- kernel/arch/ppc32/include/types.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/include/types.h	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __ppc32_TYPES_H__
+#define __ppc32_TYPES_H__
+
+#define NULL 0
+
+typedef signed char int8_t;
+typedef signed short int16_t;
+typedef signed int int32_t;
+typedef signed long long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef uint32_t uintptr_t;
+typedef uint32_t pfn_t;
+
+typedef uint32_t ipl_t;
+
+typedef uint32_t unative_t;
+
+/** Page Table Entry. */
+typedef struct {
+	unsigned p : 1;       /**< Present bit. */
+	unsigned a : 1;       /**< Accessed bit. */
+	unsigned g : 1;       /**< Global bit. */
+	unsigned valid : 1;   /**< Valid content even if not present. */
+	unsigned pfn : 20;    /**< Physical frame number. */
+} pte_t;
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/asm.S
===================================================================
--- kernel/arch/ppc32/src/asm.S	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/asm.S	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,311 @@
+#
+# Copyright (C) 2005 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#include <arch/asm/regname.h>
+
+.text
+
+.global userspace_asm
+.global iret
+.global iret_syscall
+.global memsetb
+.global memcpy
+.global memcpy_from_uspace
+.global memcpy_to_uspace
+.global memcpy_from_uspace_failover_address
+.global memcpy_to_uspace_failover_address
+
+userspace_asm:
+
+	# r3 = uspace_uarg
+	# r4 = stack
+	# r5 = entry
+	
+	# disable interrupts
+
+	mfmsr r31
+	rlwinm r31, r31, 0, 17, 15
+	mtmsr r31
+	
+	# set entry point
+	
+	mtsrr0 r5
+	
+	# set problem state, enable interrupts
+	
+	ori r31, r31, msr_pr
+	ori r31, r31, msr_ee
+	mtsrr1 r31
+	
+	# set stack
+	
+	mr sp, r4
+	
+	# jump to userspace
+	
+	rfi
+
+iret:
+	
+	# disable interrupts
+	
+	mfmsr r31
+	rlwinm r31, r31, 0, 17, 15
+	mtmsr r31
+	
+	lwz r0, 8(sp)
+	lwz r2, 12(sp)
+	lwz r3, 16(sp)
+	lwz r4, 20(sp)
+	lwz r5, 24(sp)
+	lwz r6, 28(sp)
+	lwz r7, 32(sp)
+	lwz r8, 36(sp)
+	lwz r9, 40(sp)
+	lwz r10, 44(sp)
+	lwz r11, 48(sp)
+	lwz r13, 52(sp)
+	lwz r14, 56(sp)
+	lwz r15, 60(sp)
+	lwz r16, 64(sp)
+	lwz r17, 68(sp)
+	lwz r18, 72(sp)
+	lwz r19, 76(sp)
+	lwz r20, 80(sp)
+	lwz r21, 84(sp)
+	lwz r22, 88(sp)
+	lwz r23, 92(sp)
+	lwz r24, 96(sp)
+	lwz r25, 100(sp)
+	lwz r26, 104(sp)
+	lwz r27, 108(sp)
+	lwz r28, 112(sp)
+	lwz r29, 116(sp)
+	lwz r30, 120(sp)
+	lwz r31, 124(sp)
+	
+	lwz r12, 128(sp)
+	mtcr r12
+	
+	lwz r12, 132(sp)
+	mtsrr0 r12
+	
+	lwz r12, 136(sp)
+	mtsrr1 r12
+	
+	lwz r12, 140(sp)
+	mtlr r12
+	
+	lwz r12, 144(sp)
+	mtctr r12
+	
+	lwz r12, 148(sp)
+	mtxer r12
+	
+	lwz r12, 152(sp)
+	lwz sp, 156(sp)
+	
+	rfi
+
+iret_syscall:
+	
+	# reset decrementer
+
+	li r31, 1000
+	mtdec r31
+	
+	# disable interrupts
+	
+	mfmsr r31
+	rlwinm r31, r31, 0, 17, 15
+	mtmsr r31
+	
+	lwz r0, 8(sp)
+	lwz r2, 12(sp)
+	lwz r4, 20(sp)
+	lwz r5, 24(sp)
+	lwz r6, 28(sp)
+	lwz r7, 32(sp)
+	lwz r8, 36(sp)
+	lwz r9, 40(sp)
+	lwz r10, 44(sp)
+	lwz r11, 48(sp)
+	lwz r13, 52(sp)
+	lwz r14, 56(sp)
+	lwz r15, 60(sp)
+	lwz r16, 64(sp)
+	lwz r17, 68(sp)
+	lwz r18, 72(sp)
+	lwz r19, 76(sp)
+	lwz r20, 80(sp)
+	lwz r21, 84(sp)
+	lwz r22, 88(sp)
+	lwz r23, 92(sp)
+	lwz r24, 96(sp)
+	lwz r25, 100(sp)
+	lwz r26, 104(sp)
+	lwz r27, 108(sp)
+	lwz r28, 112(sp)
+	lwz r29, 116(sp)
+	lwz r30, 120(sp)
+	lwz r31, 124(sp)
+	
+	lwz r12, 128(sp)
+	mtcr r12
+	
+	lwz r12, 132(sp)
+	mtsrr0 r12
+	
+	lwz r12, 136(sp)
+	mtsrr1 r12
+	
+	lwz r12, 140(sp)
+	mtlr r12
+	
+	lwz r12, 144(sp)
+	mtctr r12
+	
+	lwz r12, 148(sp)
+	mtxer r12
+	
+	lwz r12, 152(sp)
+	lwz sp, 156(sp)
+
+	rfi
+	
+memsetb:
+	rlwimi r5, r5, 8, 16, 23
+	rlwimi r5, r5, 16, 0, 15
+	
+	addi r14, r3, -4
+	
+	cmplwi 0, r4, 4
+	blt 7f
+	
+	stwu r5, 4(r14)
+	beqlr
+	
+	andi. r15, r14, 3
+	add r4, r15, r4
+	subf r14, r15, r14
+	srwi r15, r4, 2
+	mtctr r15
+	
+	bdz 6f
+	
+	1:
+		stwu r5, 4(r14)
+		bdnz 1b
+	
+	6:
+	
+	andi. r4, r4, 3
+	
+	7:
+	
+	cmpwi 0, r4, 0
+	beqlr
+	
+	mtctr r4
+	addi r6, r6, 3
+	
+	8:
+	
+	stbu r5, 1(r14)
+	bdnz 8b
+	
+	blr
+
+memcpy:
+memcpy_from_uspace:
+memcpy_to_uspace:
+
+	srwi. r7, r5, 3
+	addi r6, r3, -4
+	addi r4, r4, -4
+	beq	2f
+	
+	andi. r0, r6, 3
+	mtctr r7
+	bne 5f
+	
+	1:
+	
+	lwz r7, 4(r4)
+	lwzu r8, 8(r4)
+	stw r7, 4(r6)
+	stwu r8, 8(r6)
+	bdnz 1b
+	
+	andi. r5, r5, 7
+	
+	2:
+	
+	cmplwi 0, r5, 4
+	blt 3f
+	
+	lwzu r0, 4(r4)
+	addi r5, r5, -4
+	stwu r0, 4(r6)
+	
+	3:
+	
+	cmpwi 0, r5, 0
+	beqlr
+	mtctr r5
+	addi r4, r4, 3
+	addi r6, r6, 3
+	
+	4:
+	
+	lbzu r0, 1(r4)
+	stbu r0, 1(r6)
+	bdnz 4b
+	blr
+	
+	5:
+	
+	subfic r0, r0, 4
+	mtctr r0
+	
+	6:
+	
+	lbz r7, 4(r4)
+	addi r4, r4, 1
+	stb r7, 4(r6)
+	addi r6, r6, 1
+	bdnz 6b
+	subf r5, r0, r5
+	rlwinm. r7, r5, 32-3, 3, 31
+	beq 2b
+	mtctr r7
+	b 1b
+
+memcpy_from_uspace_failover_address:
+memcpy_to_uspace_failover_address:
+	b memcpy_from_uspace_failover_address
Index: kernel/arch/ppc32/src/boot/boot.S
===================================================================
--- kernel/arch/ppc32/src/boot/boot.S	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/boot/boot.S	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,81 @@
+#
+# Copyright (C) 2005 Jakub Jermar
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#include <arch/asm/regname.h>
+#include <arch/boot/boot.h>
+
+.section K_TEXT_START, "ax"
+
+.global kernel_image_start
+kernel_image_start:
+
+	# load temporal kernel stack
+	
+	lis sp, kernel_stack@ha
+	addi sp, sp, kernel_stack@l
+	
+	# set kernel stack for interrupt handling
+	
+	mr r31, sp
+	subis r31, r31, 0x8000
+	mtsprg0 r31
+	
+	# r3 contains physical address of bootinfo_t
+	# r4 contains size of bootinfo_t
+	
+	cmpwi r4, 0
+	beq bootinfo_end
+	
+	addis r3, r3, 0x8000
+
+	lis r31, bootinfo@ha
+	addi r31, r31, bootinfo@l  # r31 = bootinfo
+	
+	bootinfo_loop:
+		
+		lwz r30, 0(r3)
+		stw r30, 0(r31)
+		
+		addi r3, r3, 4
+		addi r31, r31, 4
+		subi r4, r4, 4
+		
+		cmpwi r4, 0
+		bgt bootinfo_loop
+		
+	bootinfo_end:
+	
+	bl arch_pre_main
+	b main_bsp
+
+.section K_DATA_START, "aw", @progbits
+
+.align 12
+kernel_stack_bottom:
+	.space TEMP_STACK_SIZE
+kernel_stack:
Index: kernel/arch/ppc32/src/context.S
===================================================================
--- kernel/arch/ppc32/src/context.S	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/context.S	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,109 @@
+#
+# Copyright (C) 2005 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#include <arch/asm/regname.h>
+#include <arch/context_offset.h>
+
+.text   
+
+.global context_save_arch
+.global context_restore_arch
+
+.macro CONTEXT_STORE r
+	stw sp, OFFSET_SP(\r)
+	stw r2, OFFSET_R2(\r)
+	stw r13, OFFSET_R13(\r)
+	stw r14, OFFSET_R14(\r)
+	stw r15, OFFSET_R15(\r)
+	stw r16, OFFSET_R16(\r)
+	stw r17, OFFSET_R17(\r)
+	stw r18, OFFSET_R18(\r)
+	stw r19, OFFSET_R19(\r)
+	stw r20, OFFSET_R20(\r)
+	stw r21, OFFSET_R21(\r)
+	stw r22, OFFSET_R22(\r)
+	stw r23, OFFSET_R23(\r)
+	stw r24, OFFSET_R24(\r)
+	stw r25, OFFSET_R25(\r)
+	stw r26, OFFSET_R26(\r)
+	stw r27, OFFSET_R27(\r)
+	stw r28, OFFSET_R28(\r)
+	stw r29, OFFSET_R29(\r)
+	stw r30, OFFSET_R30(\r)
+	stw r31, OFFSET_R31(\r)
+.endm
+
+.macro CONTEXT_LOAD r
+	lwz sp, OFFSET_SP(\r)
+	lwz r2, OFFSET_R2(\r)
+	lwz r13, OFFSET_R13(\r)
+	lwz r14, OFFSET_R14(\r)
+	lwz r15, OFFSET_R15(\r)
+	lwz r16, OFFSET_R16(\r)
+	lwz r17, OFFSET_R17(\r)
+	lwz r18, OFFSET_R18(\r)
+	lwz r19, OFFSET_R19(\r)
+	lwz r20, OFFSET_R20(\r)
+	lwz r21, OFFSET_R21(\r)
+	lwz r22, OFFSET_R22(\r)
+	lwz r23, OFFSET_R23(\r)
+	lwz r24, OFFSET_R24(\r)
+	lwz r25, OFFSET_R25(\r)
+	lwz r26, OFFSET_R26(\r)
+	lwz r27, OFFSET_R27(\r)
+	lwz r28, OFFSET_R28(\r)
+	lwz r29, OFFSET_R29(\r)
+	lwz r30, OFFSET_R30(\r)
+	lwz r31, OFFSET_R31(\r)
+.endm
+
+context_save_arch:
+	CONTEXT_STORE r3
+	
+	mflr r4
+	stw r4, OFFSET_PC(r3)
+	
+	mfcr r4
+	stw r4, OFFSET_CR(r3)
+	
+	# context_save returns 1
+	li r3, 1
+	blr
+	
+context_restore_arch:
+	CONTEXT_LOAD r3
+	
+	lwz r4, OFFSET_CR(r3)
+	mtcr r4
+	
+	lwz r4, OFFSET_PC(r3)
+	mtlr r4
+	
+	# context_restore returns 0
+	li r3, 0
+	blr
Index: kernel/arch/ppc32/src/cpu/cpu.c
===================================================================
--- kernel/arch/ppc32/src/cpu/cpu.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/cpu/cpu.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32
+ * @{
+ */
+/** @file
+ */
+
+#include <arch/cpu.h>
+#include <arch/cpuid.h>
+#include <cpu.h>
+
+#include <arch.h>
+
+#include <typedefs.h>
+#include <print.h>
+
+void cpu_arch_init(void)
+{
+}
+
+void cpu_identify(void)
+{
+	cpu_info_t info;
+	
+	cpu_version(&info);
+	CPU->arch.version = info.version;
+	CPU->arch.revision = info.revision;
+}
+
+void cpu_print_report(cpu_t *m)
+{
+	char *name;
+	
+	switch (m->arch.version) {
+		case 8:
+			name = " (PowerPC 750)";
+			break;
+		case 9:
+			name = " (PowerPC 604e)";
+			break;
+		case 0x81:
+			name = " (PowerPC 8260)";
+			break;
+		case 0x8081:
+			name = " (PowerPC 826xA)";
+			break;
+		default:
+			name = "";
+	}
+	
+	printf("cpu%d: version=%d%s, revision=%d\n", m->id, m->arch.version, name, m->arch.revision);
+}
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/ddi/ddi.c
===================================================================
--- kernel/arch/ppc32/src/ddi/ddi.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/ddi/ddi.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2006 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32ddi
+ * @{
+ */
+/** @file
+ */
+
+#include <ddi/ddi.h>
+#include <proc/task.h>
+#include <arch/types.h>
+#include <typedefs.h>
+
+/** Enable I/O space range for task.
+ *
+ * Interrupts are disabled and task is locked.
+ *
+ * @param task Task.
+ * @param ioaddr Startign I/O space address.
+ * @param size Size of the enabled I/O range.
+ *
+ * @return 0 on success or an error code from errno.h.
+ */
+int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
+{
+	return 0;
+}
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/src/debug/panic.s
===================================================================
--- kernel/arch/ppc32/src/debug/panic.s	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/debug/panic.s	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,38 @@
+#
+# Copyright (C) 2005 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#include <arch/asm/macro.h>
+
+.text
+.global panic_printf
+
+panic_printf:
+	lis %r14, halt@ha
+	addi %r14, %r14, halt@l
+	mtlr %r14	# fake stack to make printf return to halt
+	b printf
Index: kernel/arch/ppc32/src/drivers/cuda.c
===================================================================
--- kernel/arch/ppc32/src/drivers/cuda.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/drivers/cuda.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,327 @@
+/*
+ * Copyright (C) 2006 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+#include <arch/drivers/cuda.h>
+#include <arch/asm.h>
+#include <console/console.h>
+#include <console/chardev.h>
+#include <arch/drivers/pic.h>
+#include <sysinfo/sysinfo.h>
+#include <interrupt.h>
+#include <stdarg.h>
+
+#define SPECIAL		'?'
+
+#define PACKET_ADB  0x00
+#define PACKET_CUDA 0x01
+
+#define CUDA_POWERDOWN 0x0a
+
+#define RS 0x200
+#define B (0 * RS)
+#define A (1 * RS)
+#define SR (10 * RS)
+#define ACR (11 * RS)
+
+#define SR_OUT 0x10
+#define TACK 0x10
+#define TIP 0x20
+
+
+static volatile uint8_t *cuda = NULL;
+static iroutine vector;
+
+
+static char lchars[0x80] = {
+	'a',
+	's',
+	'd',
+	'f',
+	'h',
+	'g',
+	'z',
+	'x',
+	'c',
+	'v', 
+	SPECIAL,
+	'b',
+	'q',
+	'w',
+	'e',
+	'r',
+	'y',
+	't',
+	'1',
+	'2',
+	'3',
+	'4',
+	'6',
+	'5',
+	'=',
+	'9',
+	'7',
+	'-',
+	'8',
+	'0',
+	']',
+	'o',
+	'u',
+	'[',
+	'i', 
+	'p',
+	'\n',    /* Enter */
+	'l',
+	'j',
+	'\'',
+	'k',
+	';',
+	'\\',
+	',',
+	'/',
+	'n',
+	'm',
+	'.',
+	'\t',    /* Tab */
+	' ',
+	'`',
+	'\b',    /* Backspace */
+	SPECIAL,
+	SPECIAL, /* Escape */
+	SPECIAL, /* Ctrl */
+	SPECIAL, /* Alt */
+	SPECIAL, /* Shift */
+	SPECIAL, /* Caps-Lock */
+	SPECIAL, /* RAlt */
+	SPECIAL, /* Left */
+	SPECIAL, /* Right */
+	SPECIAL, /* Down */
+	SPECIAL, /* Up */
+	SPECIAL, 
+	SPECIAL,
+	'.',     /* Keypad . */
+	SPECIAL, 
+	'*',     /* Keypad * */
+	SPECIAL,
+	'+',     /* Keypad + */
+	SPECIAL,
+	SPECIAL, /* NumLock */
+	SPECIAL,
+	SPECIAL,
+	SPECIAL,
+	'/',     /* Keypad / */
+	'\n',    /* Keypad Enter */
+	SPECIAL,
+	'-',     /* Keypad - */
+	SPECIAL,
+	SPECIAL,
+	SPECIAL,
+	'0',     /* Keypad 0 */
+	'1',     /* Keypad 1 */
+	'2',     /* Keypad 2 */
+	'3',     /* Keypad 3 */
+	'4',     /* Keypad 4 */
+	'5',     /* Keypad 5 */
+	'6',     /* Keypad 6 */
+	'7',     /* Keypad 7 */
+	SPECIAL,
+	'8',     /* Keypad 8 */
+	'9',     /* Keypad 9 */
+	SPECIAL,
+	SPECIAL,
+	SPECIAL,
+	SPECIAL, /* F5 */
+	SPECIAL, /* F6 */
+	SPECIAL, /* F7 */
+	SPECIAL, /* F3 */
+	SPECIAL, /* F8 */
+	SPECIAL, /* F9 */
+	SPECIAL,
+	SPECIAL, /* F11 */
+	SPECIAL,
+	SPECIAL, /* F13 */
+	SPECIAL,
+	SPECIAL, /* ScrollLock */
+	SPECIAL,
+	SPECIAL, /* F10 */
+	SPECIAL,
+	SPECIAL, /* F12 */
+	SPECIAL,
+	SPECIAL, /* Pause */
+	SPECIAL, /* Insert */
+	SPECIAL, /* Home */
+	SPECIAL, /* PageUp */
+	SPECIAL, /* Delete */
+	SPECIAL, /* F4 */
+	SPECIAL, /* End */
+	SPECIAL, /* F2 */
+	SPECIAL, /* PageDown */
+	SPECIAL  /* F1 */
+};
+
+
+void send_packet(const uint8_t kind, index_t count, ...);
+
+
+static void receive_packet(uint8_t *kind, index_t count, uint8_t data[])
+{
+	cuda[B] = cuda[B] & ~TIP;
+	*kind = cuda[SR];
+	
+	index_t i;
+	for (i = 0; i < count; i++)
+		data[i] = cuda[SR];
+	
+	cuda[B] = cuda[B] | TIP;
+}
+
+
+/* Called from getc(). */
+static void cuda_resume(chardev_t *d)
+{
+}
+
+
+/* Called from getc(). */
+static void cuda_suspend(chardev_t *d)
+{
+}
+
+
+static char key_read(chardev_t *d)
+{
+	char ch;
+	
+	ch = 0;
+	return ch;
+}
+
+
+static chardev_t kbrd;
+static chardev_operations_t ops = {
+	.suspend = cuda_suspend,
+	.resume = cuda_resume,
+	.read = key_read
+};
+
+
+int cuda_get_scancode(void)
+{
+	uint8_t kind;
+	uint8_t data[4];
+	
+	receive_packet(&kind, 4, data);
+	
+	if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c))
+		return data[2];
+	
+	return -1;
+}
+
+static void cuda_irq(int n, istate_t *istate)
+{
+	int scan_code = cuda_get_scancode();
+	
+	if (scan_code != -1) {
+		uint8_t scancode = (uint8_t) scan_code;
+		if ((scancode & 0x80) != 0x80)
+			chardev_push_character(&kbrd, lchars[scancode & 0x7f]);
+	}
+}
+
+
+/** Initialize keyboard and service interrupts using kernel routine */
+void cuda_grab(void)
+{
+	vector = int_register(CUDA_IRQ, "cuda", cuda_irq);
+}
+
+
+/** Resume the former interrupt vector */
+void cuda_release(void)
+{
+	if (vector)
+		int_register(CUDA_IRQ, "user_interrupt", vector);
+}
+
+
+void cuda_init(uintptr_t base, size_t size)
+{
+	cuda = (uint8_t *) hw_map(base, size);
+	
+	int_register(CUDA_IRQ, "cuda", cuda_irq);
+	pic_enable_interrupt(CUDA_IRQ);
+	
+	chardev_initialize("cuda_kbd", &kbrd, &ops);
+	stdin = &kbrd;
+	
+	sysinfo_set_item_val("cuda", NULL, true);
+	sysinfo_set_item_val("cuda.irq", NULL, CUDA_IRQ);
+}
+
+
+void send_packet(const uint8_t kind, index_t count, ...)
+{
+	index_t i;
+	va_list va;
+	
+	cuda[B] = cuda[B] | TIP;
+	cuda[ACR] = cuda[ACR] | SR_OUT;
+	cuda[SR] = kind;
+	cuda[B] = cuda[B] & ~TIP;
+	
+	va_start(va, count);
+	
+	for (i = 0; i < count; i++) {
+		cuda[ACR] = cuda[ACR] | SR_OUT;
+		cuda[SR] = va_arg(va, int);
+		cuda[B] = cuda[B] | TACK;
+	}
+	
+	va_end(va);
+	
+	cuda[B] = cuda[B] | TIP;
+}
+
+
+void cpu_halt(void) {
+#ifdef CONFIG_POWEROFF
+	send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN);
+#endif
+	asm volatile (
+		"b 0\n"
+	);
+}
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/drivers/pic.c
===================================================================
--- kernel/arch/ppc32/src/drivers/pic.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/drivers/pic.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2006 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup ppc32	
+ * @{
+ */
+/** @file
+ */
+
+
+#include <arch/asm.h>
+#include <arch/drivers/pic.h>
+#include <byteorder.h>
+#include <bitops.h>
+
+static volatile uint32_t *pic;
+
+void pic_init(uintptr_t base, size_t size)
+{
+	pic = (uint32_t *) hw_map(base, size);
+}
+
+
+
+void pic_enable_interrupt(int intnum)
+{
+	if (intnum < 32) {
+		pic[PIC_MASK_LOW] = pic[PIC_MASK_LOW] | (1 << intnum);
+	} else {
+		pic[PIC_MASK_HIGH] = pic[PIC_MASK_HIGH] | (1 << (intnum - 32));
+	}
+	
+}
+
+void pic_disable_interrupt(int intnum)
+{
+	if (intnum < 32) {
+		pic[PIC_MASK_LOW] = pic[PIC_MASK_LOW] & (~(1 << intnum));
+	} else {
+		pic[PIC_MASK_HIGH] = pic[PIC_MASK_HIGH] & (~(1 << (intnum - 32)));
+	}
+}
+
+void pic_ack_interrupt(int intnum)
+{
+	if (intnum < 32) 
+		pic[PIC_ACK_LOW] = 1 << intnum;
+	else 
+		pic[PIC_ACK_HIGH] = 1 << (intnum - 32);
+}
+
+/** Return number of pending interrupt */
+int pic_get_pending(void)
+{
+	int pending;
+
+	pending = pic[PIC_PENDING_LOW];
+	if (pending) {
+		return fnzb32(pending);
+	}
+	pending = pic[PIC_PENDING_HIGH];
+	if (pending) {
+		return fnzb32(pending) + 32;
+	}
+	return -1;
+}
+
+ /** @}
+ */
+
Index: kernel/arch/ppc32/src/dummy.s
===================================================================
--- kernel/arch/ppc32/src/dummy.s	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/dummy.s	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,38 @@
+#
+# Copyright (C) 2005 Jakub Jermar
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+
+.global asm_delay_loop
+.global sys_tls_set
+
+sys_tls_set:
+	b sys_tls_set
+
+asm_delay_loop:
+	blr
Index: kernel/arch/ppc32/src/exception.S
===================================================================
--- kernel/arch/ppc32/src/exception.S	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/exception.S	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,328 @@
+#
+# Copyright (C) 2006 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#include <arch/asm/regname.h>
+#include <arch/mm/page.h>
+
+.section K_UNMAPPED_TEXT_START, "ax"
+
+.macro CONTEXT_STORE
+	
+	# save R12 in SPRG1, backup CR in R12
+	# save SP in SPRG2
+
+	mtsprg1 r12
+	mfcr r12
+	mtsprg2 sp
+	
+	# check whether SP is in kernel
+	
+	andis. sp, sp, 0x8000
+	bne 1f
+	
+		# stack is in user-space
+		
+		mfsprg0 sp
+	
+	b 2f
+	
+	1:
+	
+		# stack is in kernel
+		
+		mfsprg2 sp
+		subis sp, sp, 0x8000
+	
+	2:
+	
+	subi sp, sp, 160
+	stw r0, 8(sp)
+	stw r2, 12(sp)
+	stw r3, 16(sp)
+	stw r4, 20(sp)
+	stw r5, 24(sp)
+	stw r6, 28(sp)
+	stw r7, 32(sp)
+	stw r8, 36(sp)
+	stw r9, 40(sp)
+	stw r10, 44(sp)
+	stw r11, 48(sp)
+	stw r13, 52(sp)
+	stw r14, 56(sp)
+	stw r15, 60(sp)
+	stw r16, 64(sp)
+	stw r17, 68(sp)
+	stw r18, 72(sp)
+	stw r19, 76(sp)
+	stw r20, 80(sp)
+	stw r21, 84(sp)
+	stw r22, 88(sp)
+	stw r23, 92(sp)
+	stw r24, 96(sp)
+	stw r25, 100(sp)
+	stw r26, 104(sp)
+	stw r27, 108(sp)
+	stw r28, 112(sp)
+	stw r29, 116(sp)
+	stw r30, 120(sp)
+	stw r31, 124(sp)
+	
+	stw r12, 128(sp)
+	
+	mfsrr0 r12
+	stw r12, 132(sp)
+	
+	mfsrr1 r12
+	stw r12, 136(sp)
+	
+	mflr r12
+	stw r12, 140(sp)
+	
+	mfctr r12
+	stw r12, 144(sp)
+	
+	mfxer r12
+	stw r12, 148(sp)
+	
+	mfsprg1 r12
+	stw r12, 152(sp)
+	
+	mfsprg2 r12
+	stw r12, 156(sp)
+.endm
+
+.org 0x100
+.global exc_system_reset
+exc_system_reset:
+	CONTEXT_STORE
+	
+	li r3, 0
+	b jump_to_kernel
+
+.org 0x200
+.global exc_machine_check
+exc_machine_check:
+	CONTEXT_STORE
+	
+	li r3, 1
+	b jump_to_kernel
+
+.org 0x300
+.global exc_data_storage
+exc_data_storage:
+	CONTEXT_STORE
+	
+	li r3, 2
+	mr r4, sp
+	addi r4, r4, 8
+	bl pht_real_refill
+	
+	cmpwi r3, 0
+	bne iret_real
+	
+	li r3, 2
+	b jump_to_kernel
+
+.org 0x400
+.global exc_instruction_storage
+exc_instruction_storage:
+	CONTEXT_STORE
+	
+	li r3, 3
+	mr r4, sp
+	addi r4, r4, 8
+	bl pht_real_refill
+	
+	cmpwi r3, 0
+	bne iret_real
+
+	li r3, 3
+	b jump_to_kernel
+
+.org 0x500
+.global exc_external
+exc_external:
+	CONTEXT_STORE
+	
+	li r3, 4
+	b jump_to_kernel
+
+.org 0x600
+.global exc_alignment
+exc_alignment:
+	CONTEXT_STORE
+	
+	li r3, 5
+	b jump_to_kernel
+
+.org 0x700
+.global exc_program
+exc_program:
+	CONTEXT_STORE
+	
+	li r3, 6
+	b jump_to_kernel
+
+.org 0x800
+.global exc_fp_unavailable
+exc_fp_unavailable:
+	CONTEXT_STORE
+	
+	li r3, 7
+	b jump_to_kernel
+
+.org 0x900
+.global exc_decrementer
+exc_decrementer:
+	CONTEXT_STORE
+	
+	li r3, 8
+	b jump_to_kernel
+
+.org 0xa00
+.global exc_reserved0
+exc_reserved0:
+	CONTEXT_STORE
+	
+	li r3, 9
+	b jump_to_kernel
+
+.org 0xb00
+.global exc_reserved1
+exc_reserved1:
+	CONTEXT_STORE
+	
+	li r3, 10
+	b jump_to_kernel
+
+.org 0xc00
+.global exc_syscall
+exc_syscall:
+	CONTEXT_STORE	
+	
+	b jump_to_kernel_syscall
+
+.org 0xd00
+.global exc_trace
+exc_trace:
+	CONTEXT_STORE
+	
+	li r3, 12
+	b jump_to_kernel
+
+.org 0x4000
+jump_to_kernel:
+	lis r12, iret@ha
+	addi r12, r12, iret@l
+	mtlr r12
+	
+	lis r12, exc_dispatch@ha
+	addi r12, r12, exc_dispatch@l
+	mtsrr0 r12
+	
+	mfmsr r12
+	ori r12, r12, (msr_ir | msr_dr)@l
+	mtsrr1 r12
+	
+	addis sp, sp, 0x8000
+	mr r4, sp
+	addi r4, r4, 8
+	
+	rfi
+
+jump_to_kernel_syscall:
+	lis r12, syscall_handler@ha
+	addi r12, r12, syscall_handler@l
+	mtsrr0 r12
+	
+	lis r12, iret_syscall@ha
+	addi r12, r12, iret_syscall@l
+	mtlr r12
+	
+	mfmsr r12
+	ori r12, r12, (msr_ir | msr_dr)@l
+	mtsrr1 r12
+	
+	addis sp, sp, 0x8000
+	rfi
+
+iret_real:
+	
+	lwz r0, 8(sp)
+	lwz r2, 12(sp)
+	lwz r3, 16(sp)
+	lwz r4, 20(sp)
+	lwz r5, 24(sp)
+	lwz r6, 28(sp)
+	lwz r7, 32(sp)
+	lwz r8, 36(sp)
+	lwz r9, 40(sp)
+	lwz r10, 44(sp)
+	lwz r11, 48(sp)
+	lwz r13, 52(sp)
+	lwz r14, 56(sp)
+	lwz r15, 60(sp)
+	lwz r16, 64(sp)
+	lwz r17, 68(sp)
+	lwz r18, 72(sp)
+	lwz r19, 76(sp)
+	lwz r20, 80(sp)
+	lwz r21, 84(sp)
+	lwz r22, 88(sp)
+	lwz r23, 92(sp)
+	lwz r24, 96(sp)
+	lwz r25, 100(sp)
+	lwz r26, 104(sp)
+	lwz r27, 108(sp)
+	lwz r28, 112(sp)
+	lwz r29, 116(sp)
+	lwz r30, 120(sp)
+	lwz r31, 124(sp)
+	
+	lwz r12, 128(sp)
+	mtcr r12
+	
+	lwz r12, 132(sp)
+	mtsrr0 r12
+	
+	lwz r12, 136(sp)
+	mtsrr1 r12
+	
+	lwz r12, 140(sp)
+	mtlr r12
+	
+	lwz r12, 144(sp)
+	mtctr r12
+	
+	lwz r12, 148(sp)
+	mtxer r12
+	
+	lwz r12, 152(sp)
+	lwz sp, 156(sp)
+	
+	rfi
Index: kernel/arch/ppc32/src/fpu_context.S
===================================================================
--- kernel/arch/ppc32/src/fpu_context.S	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/fpu_context.S	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,105 @@
+#
+# Copyright (C) 2006 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#include <arch/asm/regname.h>
+#include <arch/context_offset.h>
+
+.text   
+
+.global fpu_context_save
+.global fpu_context_restore
+.global fpu_init
+.global fpu_enable
+.global fpu_disable
+
+.macro FPU_CONTEXT_STORE r
+	stfd fr14, OFFSET_FR14(\r)
+	stfd fr15, OFFSET_FR15(\r)
+	stfd fr16, OFFSET_FR16(\r)
+	stfd fr17, OFFSET_FR17(\r)
+	stfd fr18, OFFSET_FR18(\r)
+	stfd fr19, OFFSET_FR19(\r)
+	stfd fr20, OFFSET_FR20(\r)
+	stfd fr21, OFFSET_FR21(\r)
+	stfd fr22, OFFSET_FR22(\r)
+	stfd fr23, OFFSET_FR23(\r)
+	stfd fr24, OFFSET_FR24(\r)
+	stfd fr25, OFFSET_FR25(\r)
+	stfd fr26, OFFSET_FR26(\r)
+	stfd fr27, OFFSET_FR27(\r)
+	stfd fr28, OFFSET_FR28(\r)
+	stfd fr29, OFFSET_FR29(\r)
+	stfd fr30, OFFSET_FR30(\r)
+	stfd fr31, OFFSET_FR31(\r)
+.endm
+
+.macro FPU_CONTEXT_LOAD r
+	lfd fr14, OFFSET_FR14(\r)
+	lfd fr15, OFFSET_FR15(\r)
+	lfd fr16, OFFSET_FR16(\r)
+	lfd fr17, OFFSET_FR17(\r)
+	lfd fr18, OFFSET_FR18(\r)
+	lfd fr19, OFFSET_FR19(\r)
+	lfd fr20, OFFSET_FR20(\r)
+	lfd fr21, OFFSET_FR21(\r)
+	lfd fr22, OFFSET_FR22(\r)
+	lfd fr23, OFFSET_FR23(\r)
+	lfd fr24, OFFSET_FR24(\r)
+	lfd fr25, OFFSET_FR25(\r)
+	lfd fr26, OFFSET_FR26(\r)
+	lfd fr27, OFFSET_FR27(\r)
+	lfd fr28, OFFSET_FR28(\r)
+	lfd fr29, OFFSET_FR29(\r)
+	lfd fr30, OFFSET_FR30(\r)
+	lfd fr31, OFFSET_FR31(\r)
+.endm
+
+fpu_context_save:
+//	FPU_CONTEXT_STORE r3
+//	
+//	mffs fr0
+//	stfd fr0, OFFSET_FPSCR(r3)
+	
+	blr
+	
+fpu_context_restore:
+//	FPU_CONTEXT_LOAD r3
+//	
+//	lfd fr0, OFFSET_FPSCR(r3)
+//	mtfsf 7, fr0
+	
+	blr
+
+fpu_init:
+	blr
+
+fpu_enable:
+	blr
+
+fpu_disable:
+	blr
Index: kernel/arch/ppc32/src/interrupt.c
===================================================================
--- kernel/arch/ppc32/src/interrupt.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/interrupt.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2006 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32interrupt
+ * @{
+ */
+/** @file
+ */
+
+#include <interrupt.h>
+#include <arch/interrupt.h>
+#include <arch/types.h>
+#include <arch.h>
+#include <time/clock.h>
+#include <ipc/sysipc.h>
+#include <arch/drivers/pic.h>
+#include <arch/mm/tlb.h>
+
+
+void start_decrementer(void)
+{
+	asm volatile (
+		"mtdec %0\n"
+		:
+		: "r" (1000)
+	);
+}
+
+
+/** Handler of external interrupts */
+static void exception_external(int n, istate_t *istate)
+{
+	int inum;
+
+	while ((inum = pic_get_pending()) != -1) {
+		exc_dispatch(inum + INT_OFFSET, istate);
+		pic_ack_interrupt(inum);
+	}
+}
+
+
+static void exception_decrementer(int n, istate_t *istate)
+{
+	clock();
+	start_decrementer();
+}
+
+
+/* Initialize basic tables for exception dispatching */
+void interrupt_init(void)
+{
+	exc_register(VECTOR_DATA_STORAGE, "data_storage", pht_refill);
+	exc_register(VECTOR_INSTRUCTION_STORAGE, "instruction_storage", pht_refill);
+	exc_register(VECTOR_EXTERNAL, "external", exception_external);
+	exc_register(VECTOR_DECREMENTER, "timer", exception_decrementer);
+}
+
+
+static void ipc_int(int n, istate_t *istate)
+{
+	ipc_irq_send_notif(n - INT_OFFSET);
+}
+
+
+/* Reregister irq to be IPC-ready */
+void irq_ipc_bind_arch(unative_t irq)
+{
+	int_register(irq, "ipc_int", ipc_int);
+}
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/mm/as.c
===================================================================
--- kernel/arch/ppc32/src/mm/as.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/mm/as.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2006 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32mm
+ * @{
+ */
+/** @file
+ */
+
+#include <arch/mm/as.h>
+#include <genarch/mm/as_pt.h>
+#include <genarch/mm/asid_fifo.h>
+#include <arch.h>
+
+/** Architecture dependent address space init. */
+void as_arch_init(void)
+{
+	as_operations = &as_pt_operations;
+	asid_fifo_init();
+}
+
+/** Install address space.
+ *
+ * Install ASID.
+ *
+ * @param as Address space structure.
+ *
+ */
+void as_install_arch(as_t *as)
+{
+	asid_t asid;
+	ipl_t ipl;
+	uint32_t sr;
+
+	ipl = interrupts_disable();
+	spinlock_lock(&as->lock);
+	
+	asid = as->asid;
+	
+	/* Lower 2 GB, user and supervisor access */
+	for (sr = 0; sr < 8; sr++) {
+		asm volatile (
+			"mtsrin %0, %1\n"
+			:
+			: "r" ((0x6000 << 16) + (asid << 4) + sr), "r" (sr << 28)
+		);
+	}
+	
+	/* Upper 2 GB, only supervisor access */
+	for (sr = 8; sr < 16; sr++) {
+		asm volatile (
+			"mtsrin %0, %1\n"
+			:
+			: "r" ((0x4000 << 16) + (asid << 4) + sr), "r" (sr << 28)
+		);
+	}
+	
+	spinlock_unlock(&as->lock);
+	interrupts_restore(ipl);
+}
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/mm/frame.c
===================================================================
--- kernel/arch/ppc32/src/mm/frame.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/mm/frame.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32mm	
+ * @{
+ */
+/** @file
+ */
+
+#include <arch/boot/boot.h>
+#include <arch/mm/frame.h>
+#include <arch/mm/memory_init.h>
+#include <mm/frame.h>
+#include <align.h>
+#include <macros.h>
+
+uintptr_t last_frame = 0;
+
+void frame_arch_init(void)
+{
+	pfn_t minconf = 2;
+	count_t i;
+	pfn_t start, conf;
+	size_t size;
+	
+	for (i = 0; i < bootinfo.memmap.count; i++) {
+		start = ADDR2PFN(ALIGN_UP(bootinfo.memmap.zones[i].start, FRAME_SIZE));
+		size = SIZE2FRAMES(ALIGN_DOWN(bootinfo.memmap.zones[i].size, FRAME_SIZE));
+		
+		if ((minconf < start) || (minconf >= start + size))
+			conf = start;
+		else
+			conf = minconf;
+		
+		zone_create(start, size, conf, 0);
+		if (last_frame < ALIGN_UP(bootinfo.memmap.zones[i].start + bootinfo.memmap.zones[i].size, FRAME_SIZE))
+			last_frame = ALIGN_UP(bootinfo.memmap.zones[i].start + bootinfo.memmap.zones[i].size, FRAME_SIZE);
+	}
+
+	/* First is exception vector, second is 'implementation specific',
+	   third and fourth is reserved, other contain real mode code */
+	frame_mark_unavailable(0, 8);
+	
+	/* Mark the Page Hash Table frames as unavailable */
+	uint32_t sdr1;
+	asm volatile (
+		"mfsdr1 %0\n"
+		: "=r" (sdr1)
+	);
+	frame_mark_unavailable(ADDR2PFN(sdr1 & 0xffff000), 16); // FIXME
+}
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/mm/memory_init.c
===================================================================
--- kernel/arch/ppc32/src/mm/memory_init.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/mm/memory_init.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32mm	
+ * @{
+ */
+/** @file
+ */
+
+#include <arch/boot/boot.h>
+#include <arch/mm/memory_init.h>
+#include <typedefs.h>
+#include <print.h>
+
+
+size_t get_memory_size(void) 
+{
+	return bootinfo.memmap.total;
+}
+
+
+void memory_print_map(void)
+{
+	count_t i;
+	
+	for (i = 0; i < bootinfo.memmap.count; i++)
+		printf("base: %.*p size: %#x\n", sizeof(bootinfo.memmap.zones[i].start) * 2, bootinfo.memmap.zones[i].start, bootinfo.memmap.zones[i].size);
+}
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/mm/page.c
===================================================================
--- kernel/arch/ppc32/src/mm/page.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/mm/page.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32mm	
+ * @{
+ */
+/** @file
+ */
+
+#include <genarch/mm/page_pt.h>
+#include <mm/frame.h>
+#include <mm/as.h>
+#include <align.h>
+#include <config.h>
+
+void page_arch_init(void)
+{
+	if (config.cpu_active == 1)
+		page_mapping_operations = &pt_mapping_operations;
+}
+
+
+uintptr_t hw_map(uintptr_t physaddr, size_t size)
+{
+	if (last_frame + ALIGN_UP(size, PAGE_SIZE) > KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH))
+		panic("Unable to map physical memory %p (%d bytes)", physaddr, size)
+	
+	uintptr_t virtaddr = PA2KA(last_frame);
+	pfn_t i;
+	for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++)
+		page_mapping_insert(AS_KERNEL, virtaddr + PFN2ADDR(i), physaddr + PFN2ADDR(i), PAGE_NOT_CACHEABLE);
+	
+	last_frame = ALIGN_UP(last_frame + size, FRAME_SIZE);
+	
+	return virtaddr;
+}
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/mm/tlb.c
===================================================================
--- kernel/arch/ppc32/src/mm/tlb.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/mm/tlb.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,444 @@
+/*
+ * Copyright (C) 2006 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32mm	
+ * @{
+ */
+/** @file
+ */
+
+#include <mm/tlb.h>
+#include <arch/mm/tlb.h>
+#include <arch/interrupt.h>
+#include <mm/as.h>
+#include <arch.h>
+#include <print.h>
+#include <symtab.h>
+
+
+/** Try to find PTE for faulting address
+ *
+ * Try to find PTE for faulting address.
+ * The as->lock must be held on entry to this function
+ * if lock is true.
+ *
+ * @param as       Address space.
+ * @param lock     Lock/unlock the address space.
+ * @param badvaddr Faulting virtual address.
+ * @param access   Access mode that caused the fault.
+ * @param istate   Pointer to interrupted state.
+ * @param pfrc     Pointer to variable where as_page_fault() return code will be stored.
+ * @return         PTE on success, NULL otherwise.
+ *
+ */
+static pte_t *find_mapping_and_check(as_t *as, bool lock, uintptr_t badvaddr, int access, istate_t *istate, int *pfrc)
+{
+	/*
+	 * Check if the mapping exists in page tables.
+	 */	
+	pte_t *pte = page_mapping_find(as, badvaddr);
+	if ((pte) && (pte->p)) {
+		/*
+		 * Mapping found in page tables.
+		 * Immediately succeed.
+		 */
+		return pte;
+	} else {
+		int rc;
+	
+		/*
+		 * Mapping not found in page tables.
+		 * Resort to higher-level page fault handler.
+		 */
+		page_table_unlock(as, lock);
+		switch (rc = as_page_fault(badvaddr, access, istate)) {
+			case AS_PF_OK:
+				/*
+				 * The higher-level page fault handler succeeded,
+				 * The mapping ought to be in place.
+				 */
+				page_table_lock(as, lock);
+				pte = page_mapping_find(as, badvaddr);
+				ASSERT((pte) && (pte->p));
+				*pfrc = 0;
+				return pte;
+			case AS_PF_DEFER:
+				page_table_lock(as, lock);
+				*pfrc = rc;
+				return NULL;
+			case AS_PF_FAULT:
+				page_table_lock(as, lock);
+				printf("Page fault.\n");
+				*pfrc = rc;
+				return NULL;
+			default:
+				panic("unexpected rc (%d)\n", rc);
+		}	
+	}
+}
+
+
+static void pht_refill_fail(uintptr_t badvaddr, istate_t *istate)
+{
+	char *symbol = "";
+	char *sym2 = "";
+
+	char *s = get_symtab_entry(istate->pc);
+	if (s)
+		symbol = s;
+	s = get_symtab_entry(istate->lr);
+	if (s)
+		sym2 = s;
+	panic("%p: PHT Refill Exception at %p (%s<-%s)\n", badvaddr, istate->pc, symbol, sym2);
+}
+
+
+static void pht_insert(const uintptr_t vaddr, const pfn_t pfn)
+{
+	uint32_t page = (vaddr >> 12) & 0xffff;
+	uint32_t api = (vaddr >> 22) & 0x3f;
+	
+	uint32_t vsid;
+	asm volatile (
+		"mfsrin %0, %1\n"
+		: "=r" (vsid)
+		: "r" (vaddr)
+	);
+	
+	uint32_t sdr1;
+	asm volatile (
+		"mfsdr1 %0\n"
+		: "=r" (sdr1)
+	);
+	phte_t *phte = (phte_t *) PA2KA(sdr1 & 0xffff0000);
+	
+	/* Primary hash (xor) */
+	uint32_t h = 0;
+	uint32_t hash = vsid ^ page;
+	uint32_t base = (hash & 0x3ff) << 3;
+	uint32_t i;
+	bool found = false;
+	
+	/* Find unused or colliding
+	   PTE in PTEG */
+	for (i = 0; i < 8; i++) {
+		if ((!phte[base + i].v) || ((phte[base + i].vsid == vsid) && (phte[base + i].api == api))) {
+			found = true;
+			break;
+		}
+	}
+	
+	if (!found) {
+		/* Secondary hash (not) */
+		uint32_t base2 = (~hash & 0x3ff) << 3;
+		
+		/* Find unused or colliding
+		   PTE in PTEG */
+		for (i = 0; i < 8; i++) {
+			if ((!phte[base2 + i].v) || ((phte[base2 + i].vsid == vsid) && (phte[base2 + i].api == api))) {
+				found = true;
+				base = base2;
+				h = 1;
+				break;
+			}
+		}
+		
+		if (!found) {
+			// TODO: A/C precedence groups
+			i = page % 8;
+		}
+	}
+	
+	phte[base + i].v = 1;
+	phte[base + i].vsid = vsid;
+	phte[base + i].h = h;
+	phte[base + i].api = api;
+	phte[base + i].rpn = pfn;
+	phte[base + i].r = 0;
+	phte[base + i].c = 0;
+	phte[base + i].pp = 2; // FIXME
+}
+
+
+static void pht_real_insert(const uintptr_t vaddr, const pfn_t pfn)
+{
+	uint32_t page = (vaddr >> 12) & 0xffff;
+	uint32_t api = (vaddr >> 22) & 0x3f;
+	
+	uint32_t vsid;
+	asm volatile (
+		"mfsrin %0, %1\n"
+		: "=r" (vsid)
+		: "r" (vaddr)
+	);
+	
+	uint32_t sdr1;
+	asm volatile (
+		"mfsdr1 %0\n"
+		: "=r" (sdr1)
+	);
+	phte_t *phte_physical = (phte_t *) (sdr1 & 0xffff0000);
+	
+	/* Primary hash (xor) */
+	uint32_t h = 0;
+	uint32_t hash = vsid ^ page;
+	uint32_t base = (hash & 0x3ff) << 3;
+	uint32_t i;
+	bool found = false;
+	
+	/* Find unused or colliding
+	   PTE in PTEG */
+	for (i = 0; i < 8; i++) {
+		if ((!phte_physical[base + i].v) || ((phte_physical[base + i].vsid == vsid) && (phte_physical[base + i].api == api))) {
+			found = true;
+			break;
+		}
+	}
+	
+	if (!found) {
+		/* Secondary hash (not) */
+		uint32_t base2 = (~hash & 0x3ff) << 3;
+		
+		/* Find unused or colliding
+		   PTE in PTEG */
+		for (i = 0; i < 8; i++) {
+			if ((!phte_physical[base2 + i].v) || ((phte_physical[base2 + i].vsid == vsid) && (phte_physical[base2 + i].api == api))) {
+				found = true;
+				base = base2;
+				h = 1;
+				break;
+			}
+		}
+		
+		if (!found) {
+			// TODO: A/C precedence groups
+			i = page % 8;
+		}
+	}
+	
+	phte_physical[base + i].v = 1;
+	phte_physical[base + i].vsid = vsid;
+	phte_physical[base + i].h = h;
+	phte_physical[base + i].api = api;
+	phte_physical[base + i].rpn = pfn;
+	phte_physical[base + i].r = 0;
+	phte_physical[base + i].c = 0;
+	phte_physical[base + i].pp = 2; // FIXME
+}
+
+
+/** Process Instruction/Data Storage Interrupt
+ *
+ * @param n Interrupt vector number.
+ * @param istate Interrupted register context.
+ *
+ */
+void pht_refill(int n, istate_t *istate)
+{
+	uintptr_t badvaddr;
+	pte_t *pte;
+	int pfrc;
+	as_t *as;
+	bool lock;
+	
+	if (AS == NULL) {
+		as = AS_KERNEL;
+		lock = false;
+	} else {
+		as = AS;
+		lock = true;
+	}
+	
+	if (n == VECTOR_DATA_STORAGE) {
+		asm volatile (
+			"mfdar %0\n"
+			: "=r" (badvaddr)
+		);
+	} else
+		badvaddr = istate->pc;
+		
+	page_table_lock(as, lock);
+	
+	pte = find_mapping_and_check(as, lock, badvaddr, PF_ACCESS_READ /* FIXME */, istate, &pfrc);
+	if (!pte) {
+		switch (pfrc) {
+			case AS_PF_FAULT:
+				goto fail;
+				break;
+			case AS_PF_DEFER:
+				/*
+		 		 * The page fault came during copy_from_uspace()
+				 * or copy_to_uspace().
+				 */
+				page_table_unlock(as, lock);
+				return;
+			default:
+				panic("Unexpected pfrc (%d)\n", pfrc);
+		}
+	}
+	
+	pte->a = 1; /* Record access to PTE */
+	pht_insert(badvaddr, pte->pfn);
+	
+	page_table_unlock(as, lock);
+	return;
+	
+fail:
+	page_table_unlock(as, lock);
+	pht_refill_fail(badvaddr, istate);
+}
+
+
+/** Process Instruction/Data Storage Interrupt in Real Mode
+ *
+ * @param n Interrupt vector number.
+ * @param istate Interrupted register context.
+ *
+ */
+bool pht_real_refill(int n, istate_t *istate)
+{
+	uintptr_t badvaddr;
+	
+	if (n == VECTOR_DATA_STORAGE) {
+		asm volatile (
+			"mfdar %0\n"
+			: "=r" (badvaddr)
+		);
+	} else
+		badvaddr = istate->pc;
+	
+	uint32_t physmem;
+	asm volatile (
+		"mfsprg3 %0\n"
+		: "=r" (physmem)
+	);
+	
+	if ((badvaddr >= PA2KA(0)) && (badvaddr < PA2KA(physmem))) {
+		pht_real_insert(badvaddr, KA2PA(badvaddr) >> 12);
+		return true;
+	}
+	
+	return false;
+}
+
+
+void tlb_arch_init(void)
+{
+	tlb_invalidate_all();
+}
+
+
+void tlb_invalidate_all(void)
+{
+	asm volatile (
+		"tlbia\n"
+		"tlbsync\n"
+	);
+}
+
+
+void tlb_invalidate_asid(asid_t asid)
+{
+	uint32_t sdr1;
+	asm volatile (
+		"mfsdr1 %0\n"
+		: "=r" (sdr1)
+	);
+	phte_t *phte = (phte_t *) PA2KA(sdr1 & 0xffff0000);
+	
+	uint32_t i;
+	for (i = 0; i < 8192; i++) {
+		if ((phte[i].v) && (phte[i].vsid >= (asid << 4)) && (phte[i].vsid < ((asid << 4) + 16)))
+			phte[i].v = 0;
+	}
+	tlb_invalidate_all();
+}
+
+
+void tlb_invalidate_pages(asid_t asid, uintptr_t page, count_t cnt)
+{
+	// TODO
+	tlb_invalidate_all();
+}
+
+
+#define PRINT_BAT(name, ureg, lreg) \
+	asm volatile ( \
+		"mfspr %0," #ureg "\n" \
+		"mfspr %1," #lreg "\n" \
+		: "=r" (upper), "=r" (lower) \
+	); \
+	mask = (upper & 0x1ffc) >> 2; \
+	if (upper & 3) { \
+		uint32_t tmp = mask; \
+		length = 128; \
+		while (tmp) { \
+			if ((tmp & 1) == 0) { \
+				printf("ibat[0]: error in mask\n"); \
+				break; \
+			} \
+			length <<= 1; \
+			tmp >>= 1; \
+		} \
+	} else \
+		length = 0; \
+	printf(name ": page=%.*p frame=%.*p length=%d KB (mask=%#x)%s%s\n", sizeof(upper) * 2, upper & 0xffff0000, sizeof(lower) * 2, lower & 0xffff0000, length, mask, ((upper >> 1) & 1) ? " supervisor" : "", (upper & 1) ? " user" : "");
+
+
+void tlb_print(void)
+{
+	uint32_t sr;
+	
+	for (sr = 0; sr < 16; sr++) {
+		uint32_t vsid;
+		asm volatile (
+			"mfsrin %0, %1\n"
+			: "=r" (vsid)
+			: "r" (sr << 28)
+		);
+		printf("vsid[%d]: VSID=%.*p (ASID=%d)%s%s\n", sr, sizeof(vsid) * 2, vsid & 0xffffff, (vsid & 0xffffff) >> 4, ((vsid >> 30) & 1) ? " supervisor" : "", ((vsid >> 29) & 1) ? " user" : "");
+	}
+	
+	uint32_t upper;
+	uint32_t lower;
+	uint32_t mask;
+	uint32_t length;
+	
+	PRINT_BAT("ibat[0]", 528, 529);
+	PRINT_BAT("ibat[1]", 530, 531);
+	PRINT_BAT("ibat[2]", 532, 533);
+	PRINT_BAT("ibat[3]", 534, 535);
+	
+	PRINT_BAT("dbat[0]", 536, 537);
+	PRINT_BAT("dbat[1]", 538, 539);
+	PRINT_BAT("dbat[2]", 540, 541);
+	PRINT_BAT("dbat[3]", 542, 543);
+}
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/ppc32.c
===================================================================
--- kernel/arch/ppc32/src/ppc32.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/ppc32.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32
+ * @{
+ */
+/** @file
+ */
+
+#include <arch.h>
+#include <arch/boot/boot.h>
+#include <arch/drivers/cuda.h>
+#include <arch/mm/memory_init.h>
+#include <arch/interrupt.h>
+#include <genarch/fb/fb.h>
+#include <userspace.h>
+#include <proc/uarg.h>
+#include <console/console.h>
+#include <arch/drivers/pic.h>
+
+bootinfo_t bootinfo;
+
+void arch_pre_main(void)
+{
+	/* Setup usermode */
+	init.cnt = bootinfo.taskmap.count;
+	
+	uint32_t i;
+	
+	for (i = 0; i < bootinfo.taskmap.count; i++) {
+		init.tasks[i].addr = PA2KA(bootinfo.taskmap.tasks[i].addr);
+		init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
+	}
+}
+
+void arch_pre_mm_init(void)
+{
+	/* Initialize dispatch table */
+	interrupt_init();
+
+	/* Start decrementer */
+	start_decrementer();
+}
+
+void arch_post_mm_init(void)
+{
+	if (config.cpu_active == 1) {
+		fb_init(bootinfo.screen.addr, bootinfo.screen.width, bootinfo.screen.height, bootinfo.screen.bpp, bootinfo.screen.scanline);	
+	
+		/* Initialize PIC */
+		pic_init(bootinfo.keyboard.addr, PAGE_SIZE);
+		
+		cuda_init(bootinfo.keyboard.addr + 0x16000, 2 * PAGE_SIZE);
+		
+		/* Merge all zones to 1 big zone */
+		zone_merge_all();
+	}
+}
+
+void arch_pre_smp_init(void)
+{
+	memory_print_map();
+}
+
+void arch_post_smp_init(void)
+{
+}
+
+void calibrate_delay_loop(void)
+{
+}
+
+void userspace(uspace_arg_t *kernel_uarg)
+{
+	userspace_asm((uintptr_t) kernel_uarg->uspace_uarg, (uintptr_t) kernel_uarg->uspace_stack + THREAD_STACK_SIZE - SP_DELTA, (uintptr_t) kernel_uarg->uspace_entry);
+	
+	/* Unreachable */
+	for (;;)
+		;
+}
+
+/** Acquire console back for kernel
+ *
+ */
+void arch_grab_console(void)
+{
+	cuda_grab();
+}
+
+/** Return console to userspace
+ *
+ */
+void arch_release_console(void)
+{
+	cuda_release();
+}
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/proc/scheduler.c
===================================================================
--- kernel/arch/ppc32/src/proc/scheduler.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
+++ kernel/arch/ppc32/src/proc/scheduler.c	(revision 1167520724b9b526c27b67f2d4bc447ef626240c)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2006 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32proc
+ * @{
+ */
+/** @file
+ */
+
+#include <arch/mm/page.h>
+#include <arch/boot/boot.h>
+#include <proc/scheduler.h>
+#include <proc/thread.h>
+#include <arch.h>
+
+/** Perform ppc32 specific tasks needed before the new task is run. */
+void before_task_runs_arch(void)
+{
+}
+
+/** Perform ppc32 specific tasks needed before the new thread is scheduled. */
+void before_thread_runs_arch(void)
+{
+	tlb_invalidate_all();
+	asm volatile (
+		"mtsprg0 %0\n"
+		:
+		: "r" (KA2PA(&THREAD->kstack[THREAD_STACK_SIZE - SP_DELTA]))
+	);
+}
+
+void after_thread_ran_arch(void)
+{
+}
+
+/** @}
+ */
