Index: arch/ppc32/_link.ld.in
===================================================================
--- arch/ppc32/_link.ld.in	(revision 2a46e10bda4f9665e1b831254e35ea3e01b97563)
+++ arch/ppc32/_link.ld.in	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
@@ -12,5 +12,5 @@
 
 SECTIONS {
-	.image 0x80000000: AT (0x80000000) { 
+	.image 0x800000: AT (0x800000) { 
 		ktext_start = .;
 		*(K_TEXT_START)
@@ -31,5 +31,5 @@
 		LONG(kdata_end - kdata_start);
 		hardcoded_load_address = .;
-		LONG(0x80000000);
+		LONG(0x800000);
 		*(.bss);		/* uninitialized static variables */	
 		*(COMMON); 		/* global variables */
Index: arch/ppc32/include/asm/spr.h
===================================================================
--- arch/ppc32/include/asm/spr.h	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
+++ arch/ppc32/include/asm/spr.h	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+#ifndef __ppc32_SPR_H__
+#define __ppc32_SPR_H__
+
+#define MSR_DR (1<<27)
+#define MSR_IR (1<<26)
+
+#define SPRN_SRR0  0x1a
+#define SPRN_SRR1  0x1b
+
+/* Works for PPC32 */
+#define L1_CACHE_BYTES (1 << 5)
+
+#endif
Index: arch/ppc32/include/console.h
===================================================================
--- arch/ppc32/include/console.h	(revision 2a46e10bda4f9665e1b831254e35ea3e01b97563)
+++ arch/ppc32/include/console.h	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
@@ -30,5 +30,5 @@
 #define __ppc32_CONSOLE_H__
 
-extern void ofw_ppc32_console_init(void);
+extern void ppc32_console_init(void);
 
 #endif
Index: arch/ppc32/include/mm/memory_init.h
===================================================================
--- arch/ppc32/include/mm/memory_init.h	(revision 2a46e10bda4f9665e1b831254e35ea3e01b97563)
+++ arch/ppc32/include/mm/memory_init.h	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
@@ -33,4 +33,6 @@
 
 size_t get_memory_size(void);
+void preboot_read_config(void);
+void ppc_init_zones(void);
 
 #endif
Index: arch/ppc32/include/mm/page.h
===================================================================
--- arch/ppc32/include/mm/page.h	(revision 2a46e10bda4f9665e1b831254e35ea3e01b97563)
+++ arch/ppc32/include/mm/page.h	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
@@ -37,6 +37,6 @@
 #define PAGE_SIZE	FRAME_SIZE
 
-#define KA2PA(x)	(((__address) (x)) - 0x80000000)
-#define PA2KA(x)	(((__address) (x)) + 0x80000000)
+#define KA2PA(x)	((__address)(x))
+#define PA2KA(x)	((__address)(x))
 
 #define PTL0_ENTRIES_ARCH		0
Index: arch/ppc32/src/console.c
===================================================================
--- arch/ppc32/src/console.c	(revision 2a46e10bda4f9665e1b831254e35ea3e01b97563)
+++ arch/ppc32/src/console.c	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
@@ -31,23 +31,11 @@
 #include <console/chardev.h>
 #include <console/console.h>
+#include <genarch/fb/fb.h>
 
-/** Print one character.
- *
- * @param ch Character to be printed.
- */
-static void ofw_ppc32_putchar(chardev_t *d, const char ch)
-{
-	ofw_putchar(ch);
-}
-
-static chardev_t ofw_ppc32_console;
-static chardev_operations_t ofw_ppc32_console_ops = {
-	.write = ofw_ppc32_putchar
-};
 
 /** Initialize console to use ofw output */
-void ofw_ppc32_console_init(void)
+void ppc32_console_init(void)
 {
-	chardev_initialize("ofw_out", &ofw_ppc32_console, &ofw_ppc32_console_ops);
-	stdout = &ofw_ppc32_console;
+	/* TODO: PCI detection etc. etc. - this is fine in PearPC for now */
+	fb_init(0x84000000,800,600,4);
 }
Index: arch/ppc32/src/mm/frame.c
===================================================================
--- arch/ppc32/src/mm/frame.c	(revision 2a46e10bda4f9665e1b831254e35ea3e01b97563)
+++ arch/ppc32/src/mm/frame.c	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
@@ -28,4 +28,5 @@
 
 #include <arch/mm/frame.h>
+#include <arch/mm/memory_init.h>
 #include <mm/frame.h>
 #include <config.h>
@@ -34,8 +35,6 @@
 void frame_arch_init(void)
 {
-	/* First page is exception vector, 
-	 * second is 'implementation specific', evade it too
-	 */
-	zone_create(0, SIZE2FRAMES(config.memory_size), 2, 0);
+	ppc_init_zones();
+	/* First is exception vector, second is 'implementation specific' */
 	frame_mark_unavailable(0, 2);
 }
Index: arch/ppc32/src/mm/memory_init.c
===================================================================
--- arch/ppc32/src/mm/memory_init.c	(revision 2a46e10bda4f9665e1b831254e35ea3e01b97563)
+++ arch/ppc32/src/mm/memory_init.c	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
@@ -30,4 +30,6 @@
 #include <genarch/ofw/ofw.h>
 #include <panic.h>
+#include <mm/frame.h>
+#include <align.h>
 
 #define MEMMAP_MAX_RECORDS 32
@@ -38,24 +40,51 @@
 } memmap_t;
 
-size_t get_memory_size(void) 
+static memmap_t memmap[MEMMAP_MAX_RECORDS];
+size_t total_mem = 0;
+
+static void init_memmap(void)
 {
+	int i;
+
 	phandle handle = ofw_find_device("/memory");
 	if (handle == -1)
 		panic("No RAM\n");
 	
-	memmap_t memmap[MEMMAP_MAX_RECORDS];
 	size_t ret = ofw_get_property(handle, "reg", &memmap, sizeof(memmap));
 	if (ret == -1)
 		panic("Device /memory has no reg property\n");
 	
-	size_t total = 0;
-	int i;
 	
 	for (i = 0; i < MEMMAP_MAX_RECORDS; i++) {
 		if (memmap[i].size == 0)
 			break;
-		total += memmap[i].size;
+		total_mem += memmap[i].size;
 	}
+}
 
-	return total;
+void preboot_read_config(void)
+{
+	init_memmap();
 }
+
+size_t get_memory_size(void) 
+{
+	return total_mem;
+}
+
+void ppc_init_zones(void)
+{
+	int i;
+	pfn_t confdata;
+
+	for (i = 0; i < MEMMAP_MAX_RECORDS; i++) {
+		if (memmap[i].size == 0)
+			break;
+		confdata = ADDR2PFN(memmap[i].start);
+		if (confdata == 0)
+			confdata = 2;
+		zone_create(ADDR2PFN(memmap[i].start),
+			    SIZE2FRAMES(ALIGN_DOWN(memmap[i].size,PAGE_SIZE)),
+			    confdata, 0);
+	}
+}
Index: arch/ppc32/src/ppc32.c
===================================================================
--- arch/ppc32/src/ppc32.c	(revision 2a46e10bda4f9665e1b831254e35ea3e01b97563)
+++ arch/ppc32/src/ppc32.c	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
@@ -32,5 +32,5 @@
 void arch_pre_mm_init(void)
 {
-	ofw_ppc32_console_init();
+	ppc32_console_init();
 }
 
Index: arch/ppc32/src/start.S
===================================================================
--- arch/ppc32/src/start.S	(revision 2a46e10bda4f9665e1b831254e35ea3e01b97563)
+++ arch/ppc32/src/start.S	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
@@ -28,4 +28,5 @@
 
 #include <arch/asm/macro.h>
+#include <arch/asm/spr.h>
 
 .section K_TEXT_START
@@ -33,5 +34,13 @@
 .global kernel_image_start
 
+.org 0x0
+/* 256 bytes of some data */
+/* exception table - must use 'ba' instructions for branches,
+ * because it is elsewhere than the linker thinks
+ */
+.space 4096
+
 kernel_image_start:
+	/* Initialize OFW, might be needed before relocate_kernel? */
 	lis r4, ofw@ha
 	addi r4, r4, ofw@l
@@ -39,4 +48,50 @@
 	
 	bl ofw_init
+	bl preboot_read_config
+
+	bl relocate_kernel
+__after_reloc:
+	/* Set stack to some more meaningful value */
+	/* TODO: This is hardcoded for PearPC, must be changed later */
+	lis r1, 0x70
+	b main_bsp
 	
-	b main_bsp
+relocate_kernel:
+	/* TODO: We _know_ that pearpc loads it to 8MB, and
+	 * but it should be really generic
+	 */
+	lis r4, 0x80 /* r4 is where data was loaded - 8MB */
+	
+	bl to_real_mode
+	/* Now we are in real mode, copy first block and jump to it,
+	 * we are running in the loaded kernel now
+	 * We still have in r3 physical load kernel address
+	 */
+	
+	b __after_reloc /* We know in pearpc we are ok, so return,
+	                 * otherwise we should relocate kernel
+		         * here
+	                 */
+
+	
+
+	
+/* Turn off page translation
+ * - assume that physical-loaded address is in r4
+ */
+to_real_mode:
+	mflr r0
+	
+	lis   r5, ktext_start@ha // Expected start of kernel
+	addi r5, r5, ktext_start@l
+	
+	add  r0, r4, r0  	
+	sub  r0, r0, r5         // r0 now contains physical return address
+	
+	mfmsr r3
+	andis. r3, r3, (~MSR_DR | MSR_IR) >> 16
+	mtspr SPRN_SRR0, r0
+	mtspr SPRN_SRR1, r3
+	sync 			// Really needed? RFI should do it as well?
+	RFI
+
Index: kernel.config
===================================================================
--- kernel.config	(revision 2a46e10bda4f9665e1b831254e35ea3e01b97563)
+++ kernel.config	(revision 3debedeccc1f631c9b858502a18f26ae092aab18)
@@ -46,5 +46,5 @@
 
 # Framebuffer support
-! [ARCH=mips32&MIPS_MACHINE=lgxemul] CONFIG_FB (y/n)
+! [(ARCH=mips32&MIPS_MACHINE=lgxemul)|(ARCH=mips32&MIPS_MACHINE=bgxemul)] CONFIG_FB (y/n)
 
 # Support for SMP
