Index: boot/arch/ppc64/Makefile.inc
===================================================================
--- boot/arch/ppc64/Makefile.inc	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/arch/ppc64/Makefile.inc	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
@@ -0,0 +1,39 @@
+#
+# 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.
+#
+
+build: image.boot
+
+image.boot: kernel uspace
+	make -C arch/$(ARCH)/loader COMPILER=$(COMPILER) KERNELDIR=../../../$(KERNELDIR) USPACEDIR=../../../$(USPACEDIR)
+	cp arch/$(ARCH)/loader/image.boot image.boot
+
+clean: clean_boot_gen clean_kernel clean_uspace
+	make -C arch/$(ARCH)/loader clean KERNELDIR=../../../$(KERNELDIR) USPACEDIR=../../../$(USPACEDIR)
+	-rm -f image.boot
+
+arch_distclean: distclean_kernel distclean_uspace
Index: boot/arch/ppc64/loader/Makefile
===================================================================
--- boot/arch/ppc64/loader/Makefile	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/arch/ppc64/loader/Makefile	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
@@ -0,0 +1,90 @@
+#
+# 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.
+#
+
+## Toolchain configuration
+#
+
+TARGET = ppc64-linux-gnu
+TOOLCHAIN_DIR = /usr/local/ppc64/bin
+
+ifeq ($(COMPILER),native)
+	CC = gcc
+	AS = as
+	LD = ld
+	OBJCOPY = objcopy
+	OBJDUMP = objdump
+else
+	CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc
+	AS = $(TOOLCHAIN_DIR)/$(TARGET)-as
+	LD = $(TOOLCHAIN_DIR)/$(TARGET)-ld
+	OBJCOPY = $(TOOLCHAIN_DIR)/$(TARGET)-objcopy
+	OBJDUMP = $(TOOLCHAIN_DIR)/$(TARGET)-objdump
+endif
+
+CFLAGS = -I. -I../../../generic -I../../../genarch -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mcpu=powerpc64 -msoft-float -m64
+DEFS = 
+
+SOURCES = \
+	main.c \
+	../../../genarch/ofw.c \
+	../../../generic/printf.c \
+	asm.S \
+	boot.S
+
+COMPONENTS = \
+	$(KERNELDIR)/kernel.bin \
+	$(USPACEDIR)/ns/ns \
+	$(USPACEDIR)/init/init \
+	$(USPACEDIR)/fb/fb
+
+OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
+COMPONENT_OBJECTS := $(addsuffix .o,$(basename $(notdir $(COMPONENTS))))
+
+.PHONY: all clean depend
+
+all: image.boot
+
+-include Makefile.depend
+
+image.boot: depend _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) kernel.o 
+	$(LD) -no-check-sections -N -T _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) -o $@
+
+depend:
+	-makedepend $(DEFS) $(CFLAGS) -f - $(SOURCES) > Makefile.depend 2> /dev/null
+
+clean:
+	-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
+
+_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
+	./pack $(OBJCOPY) $(COMPONENTS)
+
+%.o: %.S
+	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
+
+%.o: %.c
+	$(CC) $(DEFS) $(CFLAGS) -c $< -o $@
Index: boot/arch/ppc64/loader/asm.S
===================================================================
--- boot/arch/ppc64/loader/asm.S	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/arch/ppc64/loader/asm.S	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
@@ -0,0 +1,215 @@
+#
+# 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 "asm.h"
+#include "regname.h"
+
+.text
+
+.global halt
+.global memcpy
+.global jump_to_kernel
+
+halt:
+	b halt
+
+memcpy:
+	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
+
+
+jump_to_kernel:
+	
+	# r3 = bootinfo (pa)
+	# r4 = bootinfo_size
+	# r5 = trans (pa)
+	# r6 = bytes to copy
+	# r7 = real_mode (pa)
+	
+	# disable interrupts
+	
+	mfmsr r31
+	rlwinm r31, r31, 0, 17, 15
+	mtmsr r31
+	
+	# set real_mode meeting point address
+	
+	mtspr srr0, r7
+	
+	# jumps to real_mode
+	
+	mfmsr r31
+	lis r30, ~0@h
+	ori r30, r30, ~(msr_ir | msr_dr)@l
+	and r31, r31, r30
+	mtspr srr1, r31
+	
+	sync
+	isync
+	rfid
+
+.section REALMODE, "ax"
+.align PAGE_WIDTH
+.global real_mode
+
+real_mode:
+	
+	# copy kernel to proper location
+	#
+	# r5 = trans (pa)
+	# r6 = bytes to copy
+	
+	li r31, PAGE_SIZE >> 2
+	li r30, 0
+	
+	page_copy:
+		
+		cmpwi r6, 0
+		beq copy_end
+		
+		# copy page
+		
+		mtctr r31
+		lwz r29, 0(r5)
+		
+		copy_loop:
+			
+			lwz r28, 0(r29)
+			stw r28, 0(r30)
+			
+			addi r29, r29, 4
+			addi r30, r30, 4
+			subi r6, r6, 4
+			
+			cmpwi r6, 0
+			beq copy_end
+			
+			bdnz copy_loop
+		
+		addi r5, r5, 4
+		b page_copy
+	
+	copy_end:
+	
+	# initially fill segment registers
+
+	li r31, 16
+	mtctr r31
+	li r31, 0
+	li r30, 0x2000
+
+	seg_fill:
+	
+		mtsrin r30, r31
+		addi r30, r30, 0x111
+		addis r31, r31, 0x1000    # move to next SR
+		
+		bdnz seg_fill
+	
+	tlbia
+	tlbsync
+	
+	# start the kernel
+	#
+	# r3 = bootinfo (pa)
+	
+	lis r31, KERNEL_START_ADDR@ha
+	addi r31, r31, KERNEL_START_ADDR@l
+	
+	mtspr srr0, r31
+	
+	mfmsr r31
+	ori r31, r31, (msr_ir | msr_dr)@l
+	mtspr srr1, r31
+	
+	sync
+	isync
+	rfid
+
+.align PAGE_WIDTH
+.global trans
+trans:
+	.space (TRANS_SIZE * TRANS_ITEM_SIZE)
Index: boot/arch/ppc64/loader/asm.h
===================================================================
--- boot/arch/ppc64/loader/asm.h	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/arch/ppc64/loader/asm.h	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+#ifndef __ASM_H__
+#define __ASM_H__
+
+#define PAGE_SIZE 4096
+#define PAGE_WIDTH 12
+
+#define TRANS_SIZE 1024
+#define TRANS_ITEM_SIZE 8
+
+#define KERNEL_START_ADDR 0x80004000
+
+#ifndef __ASM__
+
+#define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
+
+extern void *trans[TRANS_SIZE];
+
+extern void halt();
+extern void jump_to_kernel(void *bootinfo, unsigned long bootinfo_size, void *trans, unsigned long kernel_size, void *real_mode) __attribute__((noreturn));
+extern void real_mode();
+
+#endif
+
+#endif
Index: boot/arch/ppc64/loader/boot.S
===================================================================
--- boot/arch/ppc64/loader/boot.S	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/arch/ppc64/loader/boot.S	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
@@ -0,0 +1,42 @@
+#
+# 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 "regname.h"
+
+.section BOOTSTRAP, "ax"
+
+.global start
+
+start:
+	lis r4, ofw_cif@ha
+	addi r4, r4, ofw_cif@l
+	stw r5, 0(r4)
+	
+	bl init
+	
+	b bootstrap
Index: boot/arch/ppc64/loader/main.c
===================================================================
--- boot/arch/ppc64/loader/main.c	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/arch/ppc64/loader/main.c	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
@@ -0,0 +1,154 @@
+/*
+ * 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 "main.h" 
+#include <printf.h>
+#include "asm.h"
+#include "_components.h"
+
+#define HEAP_GAP 1024000
+
+bootinfo_t bootinfo;
+
+
+static void check_align(const void *addr, const char *desc)
+{
+	if ((unsigned long) addr % PAGE_SIZE != 0) {
+		printf("Error: %s not on page boundary, halting.\n", desc);
+		halt();
+	}
+}
+
+
+static void fix_overlap(void *va, void **pa, const char *desc, unsigned long *top)
+{
+	if ((unsigned long) *pa + PAGE_SIZE < *top) {
+		printf("Warning: %s overlaps kernel physical area\n", desc);
+		
+		void *new_va = (void *) (ALIGN_UP((unsigned long) KERNEL_END + HEAP_GAP, PAGE_SIZE) + *top);
+		void *new_pa = (void *) (HEAP_GAP + *top);
+		*top += PAGE_SIZE;
+		
+		if (ofw_map(new_pa, new_va, PAGE_SIZE, 0) != 0) {
+			printf("Error: Unable to map page aligned memory at %L (physical %L), halting.\n", new_va, new_pa);
+			halt();
+		}
+		
+		if ((unsigned long) new_pa + PAGE_SIZE < KERNEL_SIZE) {
+			printf("Error: %s cannot be relocated, halting.\n", desc);
+			halt();	
+		}
+		
+		printf("Relocating %L -> %L (physical %L -> %L)\n", va, new_va, *pa, new_pa);
+		*pa = new_pa;
+		memcpy(new_va, va, PAGE_SIZE);
+	}
+}
+
+
+void bootstrap(void)
+{
+	printf("\nHelenOS PPC Bootloader\n");
+	
+	init_components();
+	
+	unsigned int i;
+	
+	for (i = 0; i < COMPONENTS; i++)
+		check_align(components[i].start, components[i].name);
+	
+	check_align(&real_mode, "bootstrap trampoline");
+	check_align(&trans, "translation table");
+	
+	if (!ofw_memmap(&bootinfo.memmap)) {
+		printf("Error: unable to get memory map, halting.\n");
+		halt();
+	}
+	
+	if (bootinfo.memmap.total == 0) {
+		printf("Error: no memory detected, halting.\n");
+		halt();
+	}
+	
+	if (!ofw_screen(&bootinfo.screen)) {
+		printf("Error: unable to get screen properties, halting.\n");
+		halt();
+	}
+	
+	printf("\nDevice statistics\n");
+	printf(" screen at %L, resolution %dx%d, %d bpp (scanline %d bytes)\n", bootinfo.screen.addr, bootinfo.screen.width, bootinfo.screen.height, bootinfo.screen.bpp, bootinfo.screen.scanline);
+	
+	void *real_mode_pa = ofw_translate(&real_mode);
+	void *trans_pa = ofw_translate(&trans);
+	void *bootinfo_pa = ofw_translate(&bootinfo);
+	
+	printf("\nMemory statistics (total %d MB)\n", bootinfo.memmap.total >> 20);
+	printf(" %L: boot info structure (physical %L)\n", &bootinfo, bootinfo_pa);
+	printf(" %L: bootstrap trampoline (physical %L)\n", &real_mode, real_mode_pa);
+	printf(" %L: translation table (physical %L)\n", &trans, trans_pa);
+	for (i = 0; i < COMPONENTS; i++)
+		printf(" %L: %s image (size %d bytes)\n", components[i].start, components[i].name, components[i].size);
+	
+	unsigned long top = 0;
+	for (i = 0; i < COMPONENTS; i++)
+		top += ALIGN_UP(components[i].size, PAGE_SIZE);
+	
+	unsigned long pages = ALIGN_UP(KERNEL_SIZE, PAGE_SIZE) >> PAGE_WIDTH;
+	
+	for (i = 0; i < pages; i++) {
+		void *pa = ofw_translate(KERNEL_START + (i << PAGE_WIDTH));
+		fix_overlap(KERNEL_START + (i << PAGE_WIDTH), &pa, "kernel", &top);
+		trans[i] = pa;
+	}
+	
+	bootinfo.taskmap.count = 0;
+	for (i = 1; i < COMPONENTS; i++) {
+		unsigned long component_pages = ALIGN_UP(components[i].size, PAGE_SIZE) >> PAGE_WIDTH;
+		unsigned long j;
+		
+		for (j = 0; j < component_pages; j++) {
+			void *pa = ofw_translate(components[i].start + (j << PAGE_WIDTH));
+			fix_overlap(components[i].start + (j << PAGE_WIDTH), &pa, components[i].name, &top);
+			trans[pages + j] = pa;
+			if (j == 0) {
+				bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = (void *) (pages << PAGE_WIDTH);
+				bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = components[i].size;
+				bootinfo.taskmap.count++;
+			}
+		}
+		
+		pages += component_pages;
+	}
+	
+	fix_overlap(&real_mode, &real_mode_pa, "bootstrap trampoline", &top);
+	fix_overlap(&trans, &trans_pa, "translation table", &top);
+	fix_overlap(&bootinfo, &bootinfo_pa, "boot info", &top);
+	
+	printf("\nBooting the kernel...\n");
+	jump_to_kernel(bootinfo_pa, sizeof(bootinfo), trans_pa, pages << PAGE_WIDTH, real_mode_pa);
+}
Index: boot/arch/ppc64/loader/main.h
===================================================================
--- boot/arch/ppc64/loader/main.h	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/arch/ppc64/loader/main.h	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
@@ -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.
+ */
+
+#ifndef __MAIN_H__
+#define __MAIN_H__
+
+#include "ofw.h"
+
+/** Align to the nearest higher address.
+ *
+ * @param addr  Address or size to be aligned.
+ * @param align Size of alignment, must be power of 2.
+ */
+#define ALIGN_UP(addr, align) (((addr) + ((align) - 1)) & ~((align) - 1))
+
+#define TASKMAP_MAX_RECORDS 32
+
+typedef struct {
+	void *addr;
+	unsigned long size;
+} task_t;
+
+typedef struct {
+	unsigned int count;
+	task_t tasks[TASKMAP_MAX_RECORDS];
+} taskmap_t;
+
+typedef struct {
+	taskmap_t taskmap;
+	memmap_t memmap;
+	screen_t screen;
+} bootinfo_t;
+
+extern void start(void);
+extern void bootstrap(void);
+
+extern memmap_t memmap;
+
+#endif
Index: boot/arch/ppc64/loader/ofw.c
===================================================================
--- boot/arch/ppc64/loader/ofw.c	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/arch/ppc64/loader/ofw.c	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
@@ -0,0 +1,67 @@
+/*
+ * 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 <ofw.h>
+#include <printf.h>
+
+typedef int (* ofw_entry_t)(ofw_args_t *args);
+
+int ofw(ofw_args_t *args)
+{
+	return ((ofw_entry_t) ofw_cif)(args);
+}
+
+void write(const char *str, const int len)
+{
+	ofw_write(str, len);
+}
+
+int ofw_keyboard(keyboard_t *keyboard)
+{
+	char device_name[BUF_SIZE];
+	
+	if (ofw_get_property(ofw_aliases, "macio", device_name, sizeof(device_name)) <= 0)
+		return false;
+				
+	phandle device = ofw_find_device(device_name);
+	if (device == -1)
+		return false;
+								
+	pci_reg_t macio;
+	if (ofw_get_property(device, "assigned-addresses", &macio, sizeof(macio)) <= 0)
+		return false;
+	keyboard->addr = (void *) macio.addr.addr_lo;
+	keyboard->size = macio.size_lo;
+
+	return true;
+}
+
+int ofw_translate_failed(ofw_arg_t flag)
+{
+	return 0;
+}
Index: boot/arch/ppc64/loader/pack
===================================================================
--- boot/arch/ppc64/loader/pack	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/arch/ppc64/loader/pack	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
@@ -0,0 +1,124 @@
+#! /bin/sh
+
+#
+# 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.
+#
+
+[ "$#" -lt 1 ] && exit 1
+
+OBJCOPY="$1"
+LINK="_link.ld"
+HEADER="_components.h"
+
+shift
+
+echo 'OUTPUT_FORMAT("elf64-powerpc")
+OUTPUT_ARCH(powerpc:common64)
+ENTRY(start)
+
+SECTIONS {
+	.boot 0x0000000010000000: AT (0) { 
+		*(BOOTSTRAP);
+		*(REALMODE);
+		*(.text);
+		*(.toc);
+		
+		*(.opd);
+		*(.rodata);
+		*(.rodata.*);
+		*(.data);		/* initialized data */
+		*(.sdata);
+		*(.sdata2);
+		*(.sbss);
+		*(.bss);		/* uninitialized static variables */	
+		*(COMMON); 		/* global variables */
+		
+		. = ALIGN(4096);
+		*(.kernel_image);' > "$LINK"
+
+echo '#ifndef ___COMPONENTS_H__
+#define ___COMPONENTS_H__
+
+typedef struct {
+	char *name;
+	
+	void *start;
+	void *end;
+	unsigned long size;
+} component_t;' > "$HEADER"
+
+COUNT="0"
+DATA=""
+
+for TASK in "$@" ; do
+	BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`"
+	OBJECT="${BASENAME}.o"
+	SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`"
+	MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`"
+	echo "$TASK -> $OBJECT"
+	
+	echo "
+		. = ALIGN(4096);
+		*(.${BASENAME}_image);" >> "$LINK"
+	
+	echo "
+extern int ${SYMBOL}_start;
+extern int ${SYMBOL}_end;
+
+#define ${MACRO}_START ((void *) &${SYMBOL}_start)
+#define ${MACRO}_END ((void *) &${SYMBOL}_end)
+#define ${MACRO}_SIZE ((unsigned long) ${MACRO}_END - (unsigned long) ${MACRO}_START)" >> "$HEADER"
+	
+	"$OBJCOPY" -I binary -O elf64-powerpc -B powerpc:common64 --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT"
+		
+	DATA="${DATA}
+	components[$COUNT].name = \"${BASENAME}\";
+	components[$COUNT].start = ${MACRO}_START;
+	components[$COUNT].end = ${MACRO}_END;
+	components[$COUNT].size = ${MACRO}_SIZE;";
+	COUNT="`expr "$COUNT" + 1`"
+done
+
+echo '}
+
+	/DISCARD/ : {
+		*(*);
+	}
+}' >> "$LINK"
+
+echo "
+#define COMPONENTS $COUNT
+
+component_t components[COMPONENTS]; 
+
+static void init_components(void)
+{
+$DATA
+}
+
+#endif
+" >> "$HEADER"
Index: boot/arch/ppc64/loader/regname.h
===================================================================
--- boot/arch/ppc64/loader/regname.h	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/arch/ppc64/loader/regname.h	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
@@ -0,0 +1,204 @@
+/*
+ * 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.
+ */
+
+#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 hid0	1008
+
+/* MSR bits */
+#define msr_ir	(1 << 4)
+#define msr_dr	(1 << 5)
+
+/* HID0 bits */
+#define hid0_ice	(1 << 15)
+#define hid0_dce	(1 << 14)
+#define hid0_icfi	(1 << 11)
+#define hid0_dci	(1 << 10)
+
+#endif
Index: boot/arch/ppc64/loader/types.h
===================================================================
--- boot/arch/ppc64/loader/types.h	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
+++ boot/arch/ppc64/loader/types.h	(revision fb0e6f03f428e14b816f7a37cb110f0b908727d5)
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+#ifndef TYPES_H__
+#define TYPES_H__
+
+#include <gentypes.h>
+
+typedef signed char int8_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long  uint64_t;
+
+typedef uint64_t uintptr_t;
+typedef uint64_t unative_t;
+
+#endif
