Index: boot/arch/sparc32/src/ambapp.c
===================================================================
--- boot/arch/sparc32/src/ambapp.c	(revision b6b02c0fa1670aace09bf1d3f51ce99017e6230e)
+++ boot/arch/sparc32/src/ambapp.c	(revision b6b02c0fa1670aace09bf1d3f51ce99017e6230e)
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2013 Jakub Klama
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup sparc32boot
+ * @{
+ */
+/** @file
+ * @brief Bootstrap.
+ */
+
+#include <arch/asm.h>
+#include <arch/common.h>
+#include <arch/arch.h>
+#include <arch/ambapp.h>
+#include <arch/mm.h>
+#include <arch/main.h>
+#include <arch/_components.h>
+#include <halt.h>
+#include <printf.h>
+#include <memstr.h>
+#include <version.h>
+#include <macros.h>
+#include <align.h>
+#include <str.h>
+#include <errno.h>
+
+static void ambapp_scan_area(uintptr_t, int);
+
+void ambapp_scan()
+{
+	/* Scan for AHB masters & slaves */
+	ambapp_scan_area(AMBAPP_AHBMASTER_AREA, 64);
+	ambapp_scan_area(AMBAPP_AHBSLAVE_AREA, 63);
+
+	/* Scan for APB slaves on APBMST */
+	amba_device_t *apbmst = ambapp_lookup_first(GAISLER, GAISLER_APBMST);
+	if (apbmst != NULL)
+		ambapp_scan_area(apbmst->bars[0].start, 16);
+
+	/* If we found nothing, fake device entries */
+	ambapp_qemu_fake_scan();
+}
+
+static void ambapp_scan_area(uintptr_t master_bar, int max_entries)
+{
+	ambapp_entry_t *entry = (ambapp_entry_t *) (master_bar | AMBAPP_CONF_AREA);
+
+	for (int i = 0; i < max_entries; i++) {
+		if (amba_devices_found == AMBAPP_MAX_DEVICES)
+			return;
+
+		if (entry->vendor_id == 0xff)
+			continue;
+
+		amba_device_t *device = &amba_devices[amba_devices_found];
+		device->vendor_id = (amba_vendor_id_t)entry->vendor_id;
+		device->device_id = (amba_device_id_t)entry->device_id;
+		device->version = entry->version;
+		device->irq = entry->irq;
+	
+		for (int bar = 0; bar < 4; bar++) {
+			device->bars[bar].start = entry->bar[bar].addr << 20;
+			device->bars[bar].size = entry->bar[bar].mask;
+			device->bars[bar].prefetchable = (bool)entry->bar[bar].prefetchable;
+			device->bars[bar].cacheable = (bool)entry->bar[bar].cacheable;
+		}
+
+		amba_devices_found++;
+	}
+}
+
+void ambapp_qemu_fake_scan()
+{
+	/* UART */
+	amba_devices[0].vendor_id = GAISLER;
+	amba_devices[0].device_id = GAISLER_APBUART;
+	amba_devices[0].version = 1;
+	amba_devices[0].irq = 2;
+	amba_devices[0].bars[0].start = 0x80000100;
+	amba_devices[0].bars[0].size = 0x100;
+
+	/* IRQMP */
+	amba_devices[1].vendor_id = GAISLER;
+	amba_devices[1].device_id = GAISLER_IRQMP;
+	amba_devices[1].version = 1;
+	amba_devices[1].irq = -1;
+	amba_devices[1].bars[0].start = 0x80000200;
+	amba_devices[1].bars[0].size = 0x100;
+
+	/* GPTIMER */
+	amba_devices[2].vendor_id = GAISLER;
+	amba_devices[2].device_id = GAISLER_GPTIMER;
+	amba_devices[2].version = 1;
+	amba_devices[2].irq = 8;
+	amba_devices[2].bars[0].start = 0x80000300;
+	amba_devices[2].bars[0].size = 0x100;
+
+	amba_devices_found = 3;
+}
+
+void ambapp_print_devices()
+{
+	printf("ABMA devices:\n");
+
+	for (int i = 0; i < amba_devices_found; i++) {
+		amba_device_t *dev = &amba_devices[i];
+		printf("<%1x:%03x> at 0x%08x, irq %d\n", dev->vendor_id, dev->device_id, dev->bars[0].start, dev->irq);
+	}
+}
+
+amba_device_t *ambapp_lookup_first(amba_vendor_id_t vendor, amba_device_id_t device)
+{
+	for (int i = 0; i < amba_devices_found; i++) {
+		if (amba_devices[i].vendor_id == vendor &&
+		    amba_devices[i].device_id == device)
+			return &amba_devices[i];
+	}
+
+	return NULL;
+}
Index: boot/arch/sparc32/src/asm.S
===================================================================
--- boot/arch/sparc32/src/asm.S	(revision b6b02c0fa1670aace09bf1d3f51ce99017e6230e)
+++ boot/arch/sparc32/src/asm.S	(revision b6b02c0fa1670aace09bf1d3f51ce99017e6230e)
@@ -0,0 +1,56 @@
+#
+# Copyright (c) 2007 Michal Kebrt
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#include <arch/arch.h>
+
+.section BOOTSTRAP
+
+.global start
+.global boot_pt
+.global boot_ctx_table
+.global boot_stack
+.global jump_to_kernel
+
+start:
+	b bootstrap
+	nop
+
+.section BOOTPT
+.align 4096
+boot_pt:
+	.space PTL0_ENTRIES * PTL0_ENTRY_SIZE
+boot_ctx_table:
+	.space 4
+.section BOOTSTACK
+	.space 4096
+boot_stack:
+
+jump_to_kernel:
+	set 0x80a00000, %l0
+	jmp %l0
+	nop
Index: boot/arch/sparc32/src/main.c
===================================================================
--- boot/arch/sparc32/src/main.c	(revision b6b02c0fa1670aace09bf1d3f51ce99017e6230e)
+++ boot/arch/sparc32/src/main.c	(revision b6b02c0fa1670aace09bf1d3f51ce99017e6230e)
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2013 Jakub Klama
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup sparc32boot
+ * @{
+ */
+/** @file
+ * @brief Bootstrap.
+ */
+
+#include <arch/asm.h>
+#include <arch/common.h>
+#include <arch/arch.h>
+#include <arch/ambapp.h>
+#include <arch/mm.h>
+#include <arch/main.h>
+#include <arch/_components.h>
+#include <halt.h>
+#include <printf.h>
+#include <memstr.h>
+#include <version.h>
+#include <macros.h>
+#include <align.h>
+#include <str.h>
+#include <errno.h>
+#include <inflate.h>
+
+#define TOP2ADDR(top)  (((void *) PA2KA(BOOT_OFFSET)) + (top))
+static bootinfo_t bootinfo;
+
+void bootstrap(void)
+{
+	/* Initialize AMBA P&P device list */
+	ambapp_scan();
+
+	/* Look up for UART */
+	amba_device_t *uart = ambapp_lookup_first(GAISLER, GAISLER_APBUART);
+	amba_uart_base = uart->bars[0].start;
+
+	/* Standard output is now initialized */
+	version_print();
+
+	for (size_t i = 0; i < COMPONENTS; i++) {
+		printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].start,
+		    components[i].start, components[i].name, components[i].inflated,
+		    components[i].size);
+	}
+
+	ambapp_print_devices();
+
+	mmu_init();
+
+	void *dest[COMPONENTS];
+	size_t top = 0;
+	size_t cnt = 0;
+	bootinfo.cnt = 0;
+	for (size_t i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
+		top = ALIGN_UP(top, PAGE_SIZE);
+		
+		if (i > 0) {
+			bootinfo.tasks[bootinfo.cnt].addr = TOP2ADDR(top);
+			bootinfo.tasks[bootinfo.cnt].size = components[i].inflated;
+			
+			str_cpy(bootinfo.tasks[bootinfo.cnt].name,
+			    BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
+			
+			bootinfo.cnt++;
+		}
+		
+		dest[i] = TOP2ADDR(top);
+
+		top += components[i].inflated;
+		cnt++;
+	}
+	
+	printf("\nInflating components ... ");
+	
+	for (size_t i = cnt; i > 0; i--) {
+		void *tail = components[i - 1].start + components[i - 1].size;
+		if (tail >= dest[i - 1]) {
+			printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
+			    components[i].name, tail, dest[i - 1]);
+			for (;;);
+		}
+		
+		printf("%s ", components[i - 1].name);
+		
+		int err = inflate(components[i - 1].start, components[i - 1].size,
+		    dest[i - 1], components[i - 1].inflated);
+		if (err != EOK) {
+			printf("\n%s: Inflating error %d\n", components[i - 1].name, err);
+			for (;;);
+		}
+	}
+
+	printf("Booting the kernel ... \n");
+	jump_to_kernel((void *) PA2KA(BOOT_OFFSET));
+}
+
+/** @}
+ */
Index: boot/arch/sparc32/src/mm.c
===================================================================
--- boot/arch/sparc32/src/mm.c	(revision b6b02c0fa1670aace09bf1d3f51ce99017e6230e)
+++ boot/arch/sparc32/src/mm.c	(revision b6b02c0fa1670aace09bf1d3f51ce99017e6230e)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2013 Jakub Klama
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup sparc32boot
+ * @{
+ */
+/** @file
+ * @brief Bootstrap.
+ */
+
+#include <arch/asm.h>
+#include <arch/common.h>
+#include <arch/arch.h>
+#include <arch/mm.h>
+#include <arch/main.h>
+#include <arch/_components.h>
+#include <halt.h>
+#include <printf.h>
+#include <memstr.h>
+#include <version.h>
+#include <macros.h>
+#include <align.h>
+#include <str.h>
+#include <errno.h>
+#include <inflate.h>
+
+#define	OFF2SEC(_addr)	((_addr) >> PTL0_SHIFT)
+#define	SEC2OFF(_sec)	((_sec) << PTL0_SHIFT)
+
+static section_mapping_t mappings[] = {
+	{ 0x40000000, 0x3fffffff, 0x40000000, 1 },
+	{ 0x40000000, 0x2fffffff, 0x80000000, 1 },
+	{ 0x80000000, 0x0fffffff, 0xb0000000, 0 },
+	{ 0, 0, 0, 0 },
+};
+
+extern uintptr_t boot_ctx_table;
+
+static void mmu_enable()
+{
+	boot_ctx_table = ((uintptr_t)&boot_pt[0] >> 4) | PTE_ET_DESCRIPTOR;
+
+	/* Set Context Table Pointer register */
+	asi_u32_write(ASI_MMUREGS, 0x100, ((uint32_t)&boot_ctx_table) >> 4);
+
+	/* Select context 0 */
+	asi_u32_write(ASI_MMUREGS, 0x200, 0);
+
+	/* Enable MMU */
+	uint32_t cr = asi_u32_read(ASI_MMUREGS, 0x000);
+	cr |= 1;
+	asi_u32_write(ASI_MMUREGS, 0x000, cr);
+}
+
+static void mmu_disable()
+{
+	uint32_t cr = asi_u32_read(ASI_MMUREGS, 0x000);
+	cr &= ~1;
+	asi_u32_write(ASI_MMUREGS, 0x000, cr);
+}
+
+void mmu_init()
+{
+	mmu_disable();
+
+	for (int i = 0; mappings[i].size != 0; i++) {
+		int ptr = 0;
+		for (uint32_t sec = OFF2SEC(mappings[i].va); 
+		     sec < OFF2SEC(mappings[i].va + mappings[i].size);
+		     sec++) {
+			boot_pt[sec].ppn = ((mappings[i].pa + SEC2OFF(ptr++)) >> 12) & 0xffffff;
+			boot_pt[sec].cacheable = mappings[i].cacheable;
+			boot_pt[sec].acc = PTE_ACC_RWX;
+			boot_pt[sec].et = PTE_ET_ENTRY;
+		}
+	}
+
+	mmu_enable();
+}
Index: boot/arch/sparc32/src/putchar.c
===================================================================
--- boot/arch/sparc32/src/putchar.c	(revision b6b02c0fa1670aace09bf1d3f51ce99017e6230e)
+++ boot/arch/sparc32/src/putchar.c	(revision b6b02c0fa1670aace09bf1d3f51ce99017e6230e)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2007 Michal Kebrt
+ * Copyright (c) 2009 Vineeth Pillai
+ * Copyright (c) 2010 Jiri Svoboda
+ * Copyright (c) 2013 Jakub Klama
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup sparc32boot
+ * @{
+ */
+/** @file
+ * @brief bootloader output logic
+ */
+
+#include <typedefs.h>
+#include <arch/asm.h>
+#include <arch/arch.h>
+#include <arch/main.h>
+#include <arch/mm.h>
+#include <putchar.h>
+#include <str.h>
+
+/** Send a byte to the LEON3 serial console.
+ *
+ * @param byte		Byte to send.
+ */
+static void scons_sendb(uint8_t byte)
+{
+	asi_u32_write(ASI_MMUBYPASS, APBUART_SCONS_THR, byte);
+}
+
+/** Display a character
+ *
+ * @param ch	Character to display
+ */
+void putchar(const wchar_t ch)
+{
+	if (ch == '\n')
+		scons_sendb('\r');
+
+	if (ascii_check(ch))
+		scons_sendb((uint8_t) ch);
+	else
+		scons_sendb(U_SPECIAL);
+}
+
+/** @}
+ */
