Index: arch/ppc32/loader/Makefile
===================================================================
--- arch/ppc32/loader/Makefile	(revision 38fe9d0166d9870c915576570c7fa022234a45c5)
+++ arch/ppc32/loader/Makefile	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -47,5 +47,5 @@
 endif
 
-CFLAGS = -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3
+CFLAGS = -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mcpu=powerpc
 DEFS = 
 
Index: arch/ppc32/loader/asm.S
===================================================================
--- arch/ppc32/loader/asm.S	(revision 38fe9d0166d9870c915576570c7fa022234a45c5)
+++ arch/ppc32/loader/asm.S	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -30,9 +30,4 @@
 #include "regname.h"
 
-.data
-
-flush_buffer:
-	.space (L1_CACHE_LINES * L1_CACHE_BYTES)
-
 .text
 
@@ -125,4 +120,7 @@
 	and r31, r31, r30
 	mtspr srr1, r31
+	
+	sync
+	isync
 	rfi
 
Index: arch/ppc32/loader/regname.h
===================================================================
--- arch/ppc32/loader/regname.h	(revision 38fe9d0166d9870c915576570c7fa022234a45c5)
+++ arch/ppc32/loader/regname.h	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -218,7 +218,3 @@
 #define hid0_dci	(1 << 10)
 
-/* Cache sizes */
-#define L1_CACHE_LINES (128 * 8)
-#define L1_CACHE_BYTES 5
-
 #endif
Index: arch/ppc64/Makefile.inc
===================================================================
--- arch/ppc64/Makefile.inc	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/Makefile.inc	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -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
+	make -C arch/$(ARCH)/loader COMPILER=$(COMPILER) KERNEL=../../../$(KERNELDIR)/kernel.bin
+	cp arch/$(ARCH)/loader/image.boot image.boot
+
+clean: clean_kernel
+	make -C arch/$(ARCH)/loader clean
+	-rm -f image.boot
+
+arch_distclean: distclean_kernel
Index: arch/ppc64/loader/Makefile
===================================================================
--- arch/ppc64/loader/Makefile	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/Makefile	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -0,0 +1,83 @@
+#
+# 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 = ppc-linux-gnu
+TOOLCHAIN_DIR = /usr/local/ppc/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 = -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mcpu=powerpc64
+DEFS = 
+
+SOURCES = \
+	main.c \
+	ofw.c \
+	printf.c \
+	asm.S \
+	boot.S
+
+OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
+
+.PHONY: all clean depend
+
+all: image.boot
+
+-include Makefile.depend
+
+image.boot: depend $(OBJECTS) kernel.o
+	$(LD) -no-check-sections -N -T _link.ld $(OBJECTS) kernel.o -o $@
+
+depend:
+	-makedepend $(DEFS) $(CFLAGS) -f - $(SOURCES) > Makefile.depend 2> /dev/null
+
+clean:
+	-rm -f $(OBJECTS) image.boot kernel.o Makefile.depend
+
+kernel.o: $(KERNEL)
+	$(OBJCOPY) -I binary -O elf64-powerpc -B powerpc --rename-section .data=.image $(KERNEL) $@
+
+%.o: %.S
+	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
+
+%.o: %.c
+	$(CC) $(DEFS) $(CFLAGS) -c $< -o $@
Index: arch/ppc64/loader/_link.ld
===================================================================
--- arch/ppc64/loader/_link.ld	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/_link.ld	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -0,0 +1,27 @@
+/*
+ *  PPC linker script
+ *
+ */
+
+OUTPUT_FORMAT(elf64-powerpc)
+ENTRY(start)
+
+SECTIONS {
+	.boot 0x0000000010000000: AT (0) { 
+		*(BOOTSTRAP);
+		*(REALMODE);
+		*(.text);
+		
+		*(.rodata);
+		*(.rodata.*);
+		*(.data);		/* initialized data */
+		*(.sdata);
+		*(.sdata2);
+		*(.sbss);
+		*(.bss);		/* uninitialized static variables */	
+		*(COMMON); 		/* global variables */
+		
+		. = ALIGN(4096);
+		*(.image);
+	}
+}
Index: arch/ppc64/loader/asm.S
===================================================================
--- arch/ppc64/loader/asm.S	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/asm.S	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -0,0 +1,260 @@
+#
+# 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 = kernel size
+	# r7 = framebuffer (pa)
+	# r8 = real_mode (pa)
+	
+	mtspr srr0, r8
+	
+	# jumps to real_mode
+	
+	mfmsrd 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
+.align PAGE_WIDTH
+.global real_mode
+
+real_mode:
+	
+	# copy kernel to proper location
+	#
+	# r5 = trans (pa)
+	# r6 = kernel size
+	# r7 = framebuffer (pa)
+	
+	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:
+	
+	# invalidate segment registers
+
+	li r31, 16
+	mtctr r31
+	li r31, 0
+	li r30, 0
+
+	seg_fill:
+	
+		mtsrin r30, r31
+		addis r31, r31, 0x1000    # move to next SR
+		
+		bdnz seg_fill
+	
+	# invalidate block address translation registers
+	
+	mtspr ibat0u, r30
+	mtspr ibat0l, r30
+	
+	mtspr ibat1u, r30
+	mtspr ibat1l, r30
+	
+	mtspr ibat2u, r30
+	mtspr ibat2l, r30
+	
+	mtspr ibat3u, r30
+	mtspr ibat3l, r30
+	
+	mtspr dbat0u, r30
+	mtspr dbat0l, r30
+	
+	mtspr dbat1u, r30
+	mtspr dbat1l, r30
+	
+	mtspr dbat2u, r30
+	mtspr dbat2l, r30
+	
+	mtspr dbat3u, r30
+	mtspr dbat3l, r30
+	
+	# create identity mapping
+	
+	# FIXME: map exactly the size of RAM
+	
+	lis r31, 0x8000
+	ori r31, r31, 0x0ffe
+	
+	lis r30, 0x0000
+	ori r30, r30, 0x0002
+	
+	mtspr ibat0u, r31
+	mtspr ibat0l, r30
+	
+	mtspr dbat0u, r31
+	mtspr dbat0l, r30
+	
+	# FIXME: temporal framebuffer mapping
+	
+	lis r31, 0xf000
+	ori r31, r31, 0x0ffe
+	
+	mr r30, r7
+	ori r30, r30, 0x0002
+	
+	mtspr dbat1u, r31
+	mtspr dbat1l, r30
+	
+	tlbia
+	
+	# start the kernel
+	#
+	# r3 = bootinfo (pa)
+	
+	lis r31, KERNEL_START_ADDR@ha
+	addi r31, r31, KERNEL_START_ADDR@l
+	
+	mtspr srr0, r31
+	
+	mfmsrd 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: arch/ppc64/loader/asm.h
===================================================================
--- arch/ppc64/loader/asm.h	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/asm.h	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -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 4
+
+#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 int bootinfo_size, void *trans, unsigned int kernel_size, void *framebuffer, void *real_mode) __attribute__((noreturn));
+extern void real_mode();
+
+#endif
+
+#endif
Index: arch/ppc64/loader/boot.S
===================================================================
--- arch/ppc64/loader/boot.S	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/boot.S	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -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
+
+.global start
+
+start:
+	lis r4, ofw@ha
+	addi r4, r4, ofw@l
+	stw r5, 0(r4)
+	
+	bl init
+	
+	b bootstrap
Index: arch/ppc64/loader/main.c
===================================================================
--- arch/ppc64/loader/main.c	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/main.c	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -0,0 +1,128 @@
+/*
+ * 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"
+
+#define KERNEL_START ((void *) &_binary_____________kernel_kernel_bin_start)
+#define KERNEL_END ((void *) &_binary_____________kernel_kernel_bin_end)
+#define KERNEL_SIZE ((unsigned int) KERNEL_END - (unsigned int) KERNEL_START)
+
+#define HEAP_GAP 1024000
+
+bootinfo_t bootinfo;
+
+
+static void check_align(const void *addr, const char *desc)
+{
+	if ((unsigned int) 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 int *top)
+{
+	if ((unsigned int) *pa + PAGE_SIZE < *top) {
+		printf("Warning: %s overlaps kernel physical area\n", desc);
+		
+		void *new_va = (void *) (ALIGN_UP((unsigned int) 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 int) 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 PPC64 Bootloader\n");
+	
+	check_align(KERNEL_START, "Kernel image");
+	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);
+	void *fb = (void *) (((unsigned int) bootinfo.screen.addr) & ((unsigned int) ~0 << 17));
+	
+	printf("\nMemory statistics (total %d MB)\n", bootinfo.memmap.total >> 20);
+	printf(" kernel image         at %L (size %d bytes)\n", KERNEL_START, KERNEL_SIZE);
+	printf(" boot info            at %L (physical %L)\n", &bootinfo, bootinfo_pa);
+	printf(" bootstrap trampoline at %L (physical %L)\n", &real_mode, real_mode_pa);
+	printf(" translation table    at %L (physical %L)\n", &trans, trans_pa);
+	
+	unsigned int top = ALIGN_UP(KERNEL_SIZE, PAGE_SIZE);
+	unsigned int addr;
+	for (addr = 0; addr < KERNEL_SIZE; addr += PAGE_SIZE) {
+		void *pa = ofw_translate(KERNEL_START + addr);
+		fix_overlap(KERNEL_START + addr, &pa, "Kernel image", &top);
+		trans[addr >> PAGE_WIDTH] = pa;
+	}
+	
+	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, KERNEL_SIZE, fb, real_mode_pa);
+}
Index: arch/ppc64/loader/main.h
===================================================================
--- arch/ppc64/loader/main.h	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/main.h	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -0,0 +1,53 @@
+/*
+ * 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))
+
+typedef struct {
+	memmap_t memmap;
+	screen_t screen;
+} bootinfo_t;
+
+extern int _binary_____________kernel_kernel_bin_start;
+extern int _binary_____________kernel_kernel_bin_end;
+extern void start(void);
+extern void bootstrap(void);
+
+extern memmap_t memmap;
+
+#endif
Index: arch/ppc64/loader/ofw.c
===================================================================
--- arch/ppc64/loader/ofw.c	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/ofw.c	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -0,0 +1,247 @@
+/*
+ * 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 "asm.h"
+#include "printf.h"
+
+#define MAX_OFW_ARGS	10
+#define BUF_SIZE		1024
+
+typedef unsigned int ofw_arg_t;
+typedef unsigned int ihandle;
+typedef unsigned int phandle;
+
+/** OpenFirmware command structure
+ *
+ */
+typedef struct {
+	const char *service;          /**< Command name */
+	unsigned int nargs;           /**< Number of in arguments */
+	unsigned int nret;            /**< Number of out arguments */
+	ofw_arg_t args[MAX_OFW_ARGS]; /**< List of arguments */
+} ofw_args_t;
+
+typedef void (*ofw_entry)(ofw_args_t *);
+
+
+ofw_entry ofw;
+
+phandle ofw_chosen;
+ihandle ofw_stdout;
+phandle ofw_root;
+ihandle ofw_mmu;
+phandle ofw_memory;
+phandle ofw_aliases;
+
+
+static int ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...)
+{
+	va_list list;
+	ofw_args_t args;
+	int i;
+	
+	args.service = service;
+	args.nargs = nargs;
+	args.nret = nret;
+	
+	va_start(list, rets);
+	for (i = 0; i < nargs; i++)
+		args.args[i] = va_arg(list, ofw_arg_t);
+	va_end(list);
+	
+	for (i = 0; i < nret; i++)
+		args.args[i + nargs] = 0;
+	
+	ofw(&args);
+	
+	for (i = 1; i < nret; i++)
+		rets[i - 1] = args.args[i + nargs];
+	
+	return args.args[nargs];
+}
+
+
+static phandle ofw_find_device(const char *name)
+{
+	return ofw_call("finddevice", 1, 1, NULL, name);
+}
+
+
+static int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen)
+{
+	return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen);
+}
+
+
+static unsigned int ofw_get_address_cells(const phandle device)
+{
+	unsigned int ret;
+	
+	if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0)
+		if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0)
+			ret = 1;
+	
+	return ret;
+}
+
+
+static unsigned int ofw_get_size_cells(const phandle device)
+{
+	unsigned int ret;
+	
+	if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0)
+		if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0)
+			ret = 1;
+	
+	return ret;
+}
+
+
+static ihandle ofw_open(const char *name)
+{
+	return ofw_call("open", 1, 1, NULL, name);
+}
+
+
+void init(void)
+{
+	ofw_chosen = ofw_find_device("/chosen");
+	if (ofw_chosen == -1)
+		halt();
+	
+	if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)
+		ofw_stdout = 0;
+	
+	ofw_root = ofw_find_device("/");
+	if (ofw_root == -1) {
+		puts("\r\nError: Unable to find / device, halted.\r\n");
+		halt();
+	}
+	
+	if (ofw_get_property(ofw_chosen, "mmu",  &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
+		puts("\r\nError: Unable to get mmu property, halted.\r\n");
+		halt();
+	}
+	
+	ofw_memory = ofw_find_device("/memory");
+	if (ofw_memory == -1) {
+		puts("\r\nError: Unable to find /memory device, halted.\r\n");
+		halt();
+	}
+	
+	ofw_aliases = ofw_find_device("/aliases");
+	if (ofw_aliases == -1) {
+		puts("\r\nError: Unable to find /aliases device, halted.\r\n");
+		halt();
+	}
+}
+
+
+void ofw_write(const char *str, const int len)
+{
+	if (ofw_stdout == 0)
+		return;
+	
+	ofw_call("write", 3, 1, NULL, ofw_stdout, str, len);
+}
+
+
+void *ofw_translate(const void *virt)
+{
+	ofw_arg_t result[3];
+	
+	if (ofw_call("call-method", 4, 4, result, "translate", ofw_mmu, virt, 1) != 0) {
+		puts("Error: MMU method translate() failed, halting.\n");
+		halt();
+	}
+	return (void *) result[2];
+}
+
+
+int ofw_map(const void *phys, const void *virt, const int size, const int mode)
+{
+	return ofw_call("call-method", 6, 1, NULL, "map", ofw_mmu, mode, size, virt, phys);
+}
+
+
+int ofw_memmap(memmap_t *map)
+{
+	unsigned int buf[BUF_SIZE];
+	int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(unsigned int) * BUF_SIZE);
+	if (ret <= 0)
+		return false;
+		
+	unsigned int ac = ofw_get_address_cells(ofw_memory);
+	unsigned int sc = ofw_get_size_cells(ofw_memory);
+	
+	int pos;
+	map->total = 0;
+	map->count = 0;
+	for (pos = 0; (pos < ret / sizeof(unsigned int)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
+		void * start = (void *) buf[pos + ac - 1];
+		unsigned int size = buf[pos + ac + sc - 1];
+		
+		if (size > 0) {
+			map->zones[map->count].start = start;
+			map->zones[map->count].size = size;
+			map->count++;
+			map->total += size;
+		}
+	}
+}
+
+
+int ofw_screen(screen_t *screen)
+{
+	char device_name[BUF_SIZE];
+	
+	if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(char) * BUF_SIZE) <= 0)
+		return false;
+	
+	phandle device = ofw_find_device(device_name);
+	if (device == -1)
+		return false;
+	
+	if (ofw_get_property(device, "address", &screen->addr, sizeof(screen->addr)) <= 0)
+		return false;
+	
+	if (ofw_get_property(device, "width", &screen->width, sizeof(screen->width)) <= 0)
+		return false;
+	
+	if (ofw_get_property(device, "height", &screen->height, sizeof(screen->height)) <= 0)
+		return false;
+	
+	if (ofw_get_property(device, "depth", &screen->bpp, sizeof(screen->bpp)) <= 0)
+		return false;
+	
+	if (ofw_get_property(device, "linebytes", &screen->scanline, sizeof(screen->scanline)) <= 0)
+		return false;
+	
+	return true;
+}
Index: arch/ppc64/loader/ofw.h
===================================================================
--- arch/ppc64/loader/ofw.h	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/ofw.h	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -0,0 +1,71 @@
+/*
+ * 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 __OFW_H__
+#define __OFW_H__
+
+#define NULL 0
+#define MEMMAP_MAX_RECORDS 32
+#define false 0
+#define true 1
+
+typedef __builtin_va_list va_list;
+
+#define va_start(ap, last) 		__builtin_va_start(ap, last)
+#define va_arg(ap, type) 		__builtin_va_arg(ap, type)
+#define va_end(ap)			__builtin_va_end(ap)
+
+typedef struct {
+	void *start;
+	unsigned int size;
+} memzone_t;
+
+typedef struct {
+	unsigned int total;
+	unsigned int count;
+	memzone_t zones[MEMMAP_MAX_RECORDS];
+} memmap_t;
+
+typedef struct {
+	void *addr;
+	unsigned int width;
+	unsigned int height;
+	unsigned int bpp;
+	unsigned int scanline;
+} screen_t;
+
+
+extern void init(void);
+extern void ofw_write(const char *str, const int len);
+
+extern void *ofw_translate(const void *virt);
+extern int ofw_map(const void *phys, const void *virt, const int size, const int mode);
+extern int ofw_memmap(memmap_t *map);
+extern int ofw_screen(screen_t *screen);
+
+#endif
Index: arch/ppc64/loader/printf.c
===================================================================
--- arch/ppc64/loader/printf.c	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/printf.c	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -0,0 +1,243 @@
+/*
+ * 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 "printf.h"
+#include "ofw.h"
+
+static char digits[] = "0123456789abcdef";  /**< Hexadecimal characters */
+
+
+void puts(const char *str)
+{
+	int len = 0;
+	
+	while (str[len] != 0)
+		len++;
+	
+	ofw_write(str, len);
+}
+
+
+/** Print hexadecimal digits
+ *
+ * Print fixed count of hexadecimal digits from
+ * the number num. The digits are printed in
+ * natural left-to-right order starting with
+ * the width-th digit.
+ *
+ * @param num   Number containing digits.
+ * @param width Count of digits to print.
+ *
+ */
+static void print_fixed_hex(const __u64 num, const int width)
+{
+	int i;
+    
+	for (i = width * 8 - 4; i >= 0; i -= 4)
+	    ofw_write(digits + ((num >> i) & 0xf), 1);
+}
+
+
+/** Print number in given base
+ *
+ * Print significant digits of a number in given
+ * base.
+ *
+ * @param num  Number to print.
+ * @param base Base to print the number in (should
+ *             be in range 2 .. 16).
+ *
+ */
+static void print_number(const __native num, const unsigned int base)
+{
+	int val = num;
+	char d[sizeof(__native) * 8 + 1];		/* this is good enough even for base == 2 */
+	int i = sizeof(__native) * 8 - 1;
+	
+	do {
+		d[i--] = digits[val % base];
+	} while (val /= base);
+	
+	d[sizeof(__native) * 8] = 0;	
+	puts(&d[i + 1]);
+}
+
+
+/** General formatted text print
+ *
+ * Print text formatted according the fmt parameter
+ * and variant arguments. Each formatting directive
+ * begins with \% (percentage) character and one of the
+ * following character:
+ *
+ * \%    Prints the percentage character.
+ *
+ * s    The next variant argument is treated as char*
+ *      and printed as a NULL terminated string.
+ *
+ * c    The next variant argument is treated as a single char.
+ *
+ * p    The next variant argument is treated as a maximum
+ *      bit-width integer with respect to architecture
+ *      and printed in full hexadecimal width.
+ *
+ * P    As with 'p', but '0x' is prefixed.
+ *
+ * q    The next variant argument is treated as a 64b integer
+ *      and printed in full hexadecimal width.
+ *
+ * Q    As with 'q', but '0x' is prefixed.
+ *
+ * l    The next variant argument is treated as a 32b integer
+ *      and printed in full hexadecimal width.
+ *
+ * L    As with 'l', but '0x' is prefixed.
+ *
+ * w    The next variant argument is treated as a 16b integer
+ *      and printed in full hexadecimal width.
+ *
+ * W    As with 'w', but '0x' is prefixed.
+ *
+ * b    The next variant argument is treated as a 8b integer
+ *      and printed in full hexadecimal width.
+ *
+ * B    As with 'b', but '0x' is prefixed.
+ *
+ * d    The next variant argument is treated as integer
+ *      and printed in standard decimal format (only significant
+ *      digits).
+ *
+ * x    The next variant argument is treated as integer
+ *      and printed in standard hexadecimal format (only significant
+ *      digits).
+ *
+ * X    As with 'x', but '0x' is prefixed.
+ *
+ * All other characters from fmt except the formatting directives
+ * are printed in verbatim.
+ *
+ * @param fmt Formatting NULL terminated string.
+ */
+void printf(const char *fmt, ...)
+{
+	int i = 0;
+	va_list ap;
+	char c;	
+	
+	va_start(ap, fmt);
+	
+	while ((c = fmt[i++])) {
+		switch (c) {
+			
+			/* control character */
+			case '%':
+				
+				switch (c = fmt[i++]) {
+					
+					/* percentile itself */
+					case '%':
+						break;
+					
+					/*
+					 * String and character conversions.
+					 */
+					case 's':
+						puts(va_arg(ap, char_ptr));
+						goto loop;
+					
+					case 'c':
+						c = (char) va_arg(ap, int);
+						break;
+					
+					/*
+					 * Hexadecimal conversions with fixed width.
+					 */
+					case 'P': 
+						puts("0x");
+					case 'p':
+						print_fixed_hex(va_arg(ap, __native), sizeof(__native));
+						goto loop;
+					
+					case 'Q':
+						puts("0x");
+					case 'q':
+						print_fixed_hex(va_arg(ap, __u64), INT64);
+						goto loop;
+					
+					case 'L': 
+						puts("0x");
+					case 'l':
+						print_fixed_hex(va_arg(ap, __native), INT32);
+						goto loop;
+					
+					case 'W':
+						puts("0x");
+					case 'w':
+						print_fixed_hex(va_arg(ap, __native), INT16);
+						goto loop;
+					
+					case 'B':
+						puts("0x");
+					case 'b':
+						print_fixed_hex(va_arg(ap, __native), INT8);
+						goto loop;
+					
+					/*
+					 * Decimal and hexadecimal conversions.
+					 */
+					case 'd':
+						print_number(va_arg(ap, __native), 10);
+						goto loop;
+					
+					case 'X':
+						puts("0x");
+					case 'x':
+						print_number(va_arg(ap, __native), 16);
+						goto loop;
+					
+					/*
+					 * Bad formatting.
+					 */
+					default:
+						goto out;
+			}
+			
+			default:
+				if (c == '\n')
+					ofw_write("\r", 1);
+				ofw_write(&c, 1);
+		}
+	
+loop:
+		;
+	}
+	
+out:
+	
+	va_end(ap);
+}
Index: arch/ppc64/loader/printf.h
===================================================================
--- arch/ppc64/loader/printf.h	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/printf.h	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -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 __PRINTF_H__
+#define __PRINTF_H__
+
+#define INT8	1
+#define INT16	2
+#define INT32	4
+#define INT64	8
+
+typedef signed char __s8;
+
+typedef unsigned char __u8;
+typedef unsigned short __u16;
+typedef unsigned long __u32;
+typedef long long __u64;
+
+typedef __u32 __address;
+typedef __u32 __native;
+
+typedef char *char_ptr;
+
+void puts(const char *str);
+void printf(const char *fmt, ...);
+
+#endif
Index: arch/ppc64/loader/regname.h
===================================================================
--- arch/ppc64/loader/regname.h	(revision 89343aacc404c35fa2986daccaf859a148b89275)
+++ arch/ppc64/loader/regname.h	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -0,0 +1,220 @@
+/*
+ * 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 __ppc64_REGNAME_H__
+#define __ppc64_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)
+
+/* 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.config
===================================================================
--- boot.config	(revision 38fe9d0166d9870c915576570c7fa022234a45c5)
+++ boot.config	(revision 89343aacc404c35fa2986daccaf859a148b89275)
@@ -8,4 +8,5 @@
 @ "mips32" MIPS 32-bit
 @ "ppc32" PowerPC 32-bit
+@ "ppc64" PowerPC 64-bit
 ! ARCH (choice)
 
@@ -16,4 +17,10 @@
 % [ARCH=ppc32] SAVEAS PPC32_COMPILER COMPILER
 
+# PPC64 Compiler
+@ "cross" Cross-compiler
+@ "native" Native
+! [ARCH=ppc64] PPC64_COMPILER (choice)
+% [ARCH=ppc64] SAVEAS PPC64_COMPILER COMPILER
+
 # MIPS32 Compiler
 @ "cross" Cross-compiler
