Index: boot/arch/sparc32/Makefile.inc
===================================================================
--- boot/arch/sparc32/Makefile.inc	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/Makefile.inc	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -0,0 +1,58 @@
+#
+# 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.
+#
+
+ifeq ($(MACHINE), leon3)
+	BOOT_OUTPUT = image.boot
+	POST_OUTPUT = $(ROOT_PATH)/uImage.bin
+	LADDR = 0x40000000
+	SADDR = 0x40000000
+	POSTBUILD = Makefile.uboot
+endif
+
+BFD_NAME = elf32-sparc
+BFD_OUTPUT = $(BFD_NAME)
+BFD_ARCH = sparc
+
+BITS = 32
+ENDIANESS = LE
+
+SOURCES = \
+	arch/$(BARCH)/src/asm.S \
+	arch/$(BARCH)/src/ambapp.c \
+	arch/$(BARCH)/src/main.c \
+	arch/$(BARCH)/src/mm.c \
+	arch/$(BARCH)/src/putchar.c \
+	$(COMPS_C) \
+	genarch/src/division.c \
+	generic/src/memstr.c \
+	generic/src/printf_core.c \
+	generic/src/vprintf.c \
+	generic/src/printf.c \
+	generic/src/str.c \
+	generic/src/version.c \
+	generic/src/inflate.c
Index: boot/arch/sparc32/_link.ld.in
===================================================================
--- boot/arch/sparc32/_link.ld.in	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/_link.ld.in	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -0,0 +1,37 @@
+#include <arch/arch.h>
+
+ENTRY(start)
+
+SECTIONS {
+	. = BOOT_BASE;
+	.text : {
+		*(BOOTSTRAP);
+		*(.text);
+	}
+	. = BOOT_BASE + 0x8000;
+	.data : {
+		bdata_start = .;
+		*(BOOTPT);      /* bootstrap page table */
+		*(BOOTSTACK);   /* bootstrap stack */
+		*(.data);       /* initialized data */
+		*(.rodata);
+		*(.rodata.*);
+		*(.sdata);
+		*(.reginfo);
+		*(.sbss);
+		*(.scommon);
+		*(.bss);        /* uninitialized static variables */
+		*(COMMON);      /* global variables */
+[[COMPONENTS]]
+	}
+	bdata_end = .;
+
+	/DISCARD/ : {
+		*(.gnu.*);
+		*(.ARM.*);
+		*(.mdebug*);
+		*(.pdr);
+		*(.comment);
+		*(.note.*);
+	}
+}
Index: boot/arch/sparc32/include/ambapp.h
===================================================================
--- boot/arch/sparc32/include/ambapp.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/include/ambapp.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -0,0 +1,166 @@
+/*
+ * 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 Definitions of structures and addresses of AMBA Plug&Play interface
+ */
+
+#ifndef BOOT_sparc32_AMBAPP_H
+#define BOOT_sparc32_AMBAPP_H
+
+#define	AMBAPP_MAX_DEVICES	64
+#define	AMBAPP_AHBMASTER_AREA	0xfffff000
+#define	AMBAPP_AHBSLAVE_AREA	0xfffff800
+#define	AMBAPP_CONF_AREA	0xff000
+
+typedef enum {
+	GAISLER			= 1,
+	ESA			= 4
+} amba_vendor_id_t;
+
+typedef enum {
+	GAISLER_LEON3    	= 0x003,
+	GAISLER_LEON3DSU 	= 0x004,
+	GAISLER_ETHAHB   	= 0x005,
+	GAISLER_APBMST   	= 0x006,
+	GAISLER_AHBUART  	= 0x007,
+	GAISLER_SRCTRL   	= 0x008,
+	GAISLER_SDCTRL   	= 0x009,
+	GAISLER_APBUART  	= 0x00C,
+	GAISLER_IRQMP    	= 0x00D,
+	GAISLER_AHBRAM   	= 0x00E,
+	GAISLER_GPTIMER  	= 0x011,
+	GAISLER_PCITRG   	= 0x012,
+	GAISLER_PCISBRG  	= 0x013,
+	GAISLER_PCIFBRG  	= 0x014,
+	GAISLER_PCITRACE 	= 0x015,
+	GAISLER_PCIDMA   	= 0x016,
+	GAISLER_AHBTRACE 	= 0x017,
+	GAISLER_ETHDSU   	= 0x018,
+	GAISLER_PIOPORT  	= 0x01A,
+	GAISLER_AHBJTAG  	= 0x01c,
+	GAISLER_SPW      	= 0x01f,
+	GAISLER_ATACTRL  	= 0x024,
+	GAISLER_VGA      	= 0x061,
+	GAISLER_KBD      	= 0x060,
+	GAISLER_ETHMAC   	= 0x01D,
+	GAISLER_DDRSPA   	= 0x025,
+	GAISLER_EHCI     	= 0x026,
+	GAISLER_UHCI     	= 0x027,
+	GAISLER_SPW2     	= 0x029,
+	GAISLER_DDR2SPA  	= 0x02E,
+	GAISLER_AHBSTAT  	= 0x052,
+	GAISLER_FTMCTRL  	= 0x054,
+	ESA_MCTRL		= 0x00F,
+} amba_device_id_t;
+
+typedef struct {
+	/* Primary serial port location */
+	uintptr_t uart_base;
+	size_t uart_size;
+	int uart_irq;
+	/* Timers location */
+	uintptr_t timer_base;
+	size_t timer_size;
+	int timer_irq;
+} amba_info_t;
+
+typedef struct {
+	amba_vendor_id_t vendor_id;
+	amba_device_id_t device_id;
+	int irq;
+	int version;
+	uint32_t args[3];
+	struct {
+		uintptr_t start;
+		uintptr_t size;
+		bool prefetchable;
+		bool cacheable;
+	} bars[4];
+} amba_device_t;
+
+typedef struct {
+	unsigned int addr: 12;
+	unsigned int reserved: 2;
+	unsigned int prefetchable: 1;
+	unsigned int cacheable: 1;
+	unsigned int mask: 12;
+	unsigned int type: 4;
+} __attribute__((packed)) ambapp_bar_t;
+
+typedef struct {
+	unsigned int vendor_id: 8;
+	unsigned int device_id: 24;
+	unsigned int reserved: 2;
+	unsigned int version: 5;
+	unsigned int irq: 5;
+	uint32_t user_defined[3];
+	ambapp_bar_t bar[4];
+} __attribute__((packed)) ambapp_entry_t;
+
+typedef struct {
+	unsigned int ram_read_ws: 1;
+	unsigned int ram_write_ws: 1;
+	unsigned int ram_width: 2;
+	unsigned int rmw: 1;
+	unsigned int rbrdy: 1;
+	unsigned int : 1;
+	unsigned int bank_size: 4;
+	unsigned int si: 1;
+	unsigned int se: 1;
+	unsigned int : 1;
+	unsigned int ms: 1;
+	unsigned int : 1;
+	unsigned int d64: 1;
+	unsigned int sdram_cmd: 2;
+	unsigned int sdram_colsz: 2;
+	unsigned int sdram_banksz: 3;
+	unsigned int tcas: 1;
+	unsigned int trfc: 3;
+	unsigned int trp: 1;
+	unsigned int sdrf: 1;
+} __attribute__((packed)) mctrl_mcfg2_t;
+
+amba_device_t amba_devices[AMBAPP_MAX_DEVICES];
+int amba_devices_found;
+bool amba_fake;
+uintptr_t amba_uart_base;
+
+void ambapp_scan(void);
+bool ambapp_fake(void);
+void ambapp_qemu_fake_scan(void);
+void ambapp_print_devices(void);
+amba_device_t *ambapp_lookup_first(amba_vendor_id_t, amba_device_id_t);
+
+#endif
+
+/** @}
+ */
Index: boot/arch/sparc32/include/arch.h
===================================================================
--- boot/arch/sparc32/include/arch.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/include/arch.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+#ifndef BOOT_sparc32_ARCH_H
+#define BOOT_sparc32_ARCH_H
+
+#define	PTL0_ENTRIES	256
+#define	PTL0_SHIFT	24
+#define	PTL0_SIZE	(1 << 24)
+#define	PTL0_ENTRY_SIZE	4
+
+/* ASI assignments: */
+#define	ASI_CACHEMISS	0x01
+#define	ASI_CACHECTRL	0x02
+#define	ASI_MMUREGS	0x19
+#define	ASI_MMUBYPASS	0x1c
+
+/*
+ * Address where the boot stage image starts (beginning of usable physical
+ * memory).
+ */
+#define BOOT_BASE	0x40000000
+#define BOOT_OFFSET	(BOOT_BASE + 0xa00000)
+
+#define PA_OFFSET 0x40000000
+
+#ifndef __ASM__
+	#define PA2KA(addr)  (((uintptr_t) (addr)) + PA_OFFSET)
+#else
+	#define PA2KA(addr)  ((addr) + PA_OFFSET)
+#endif
+
+
+#endif
+
+/** @}
+ */
Index: boot/arch/sparc32/include/asm.h
===================================================================
--- boot/arch/sparc32/include/asm.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/include/asm.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+#ifndef BOOT_sparc32_ASM_H_
+#define BOOT_sparc32_ASM_H_
+
+#include <typedefs.h>
+
+static inline uint32_t asi_u32_read(int asi, uintptr_t va)
+{
+	uint32_t v;
+
+	asm volatile (
+		"lda [%[va]] %[asi], %[v]\n"
+		: [v] "=r" (v)
+		: [va] "r" (va),
+		  [asi] "i" ((unsigned int) asi)
+	);
+	
+	return v;
+}
+
+static inline void asi_u32_write(int asi, uintptr_t va, uint32_t v)
+{
+	asm volatile (
+		"sta %[v], [%[va]] %[asi]\n"
+		:: [v] "r" (v),
+		   [va] "r" (va),
+		   [asi] "i" ((unsigned int) asi)
+		: "memory"
+	);
+}
+
+extern void jump_to_kernel(void *entry, bootinfo_t *bootinfo);
+
+#endif
Index: boot/arch/sparc32/include/main.h
===================================================================
--- boot/arch/sparc32/include/main.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/include/main.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -0,0 +1,48 @@
+/*
+ * 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 Boot related declarations.
+ */
+
+#ifndef BOOT_sparc32_MAIN_H
+#define BOOT_sparc2_MAIN_H
+
+/** Address where characters to be printed are expected. */
+#define	APBUART_SCONS_THR	0x80000100
+#define	APBUART_SCONS_THR_MMU	0xb0000100
+
+extern void bootstrap(void);
+
+#endif
+
+/** @}
+ */
Index: boot/arch/sparc32/include/mm.h
===================================================================
--- boot/arch/sparc32/include/mm.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/include/mm.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -0,0 +1,76 @@
+/*
+ * 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 Memory management used while booting the kernel.
+ *
+ * So called "section" paging is used while booting the kernel. The term
+ * "section" comes from the ARM architecture specification and stands for the
+ * following: one-level paging, 1MB sized pages, 4096 entries in the page
+ * table.
+ */
+
+#ifndef BOOT_sparc32__MM_H
+#define BOOT_sparc32__MM_H
+
+#include <typedefs.h>
+
+#define	PAGE_SIZE	(1 << 12)
+
+typedef struct {
+	uint32_t pa;
+	uint32_t size;
+	uint32_t va;
+	uint32_t cacheable;
+} section_mapping_t;
+
+typedef struct {
+	unsigned int ppn: 24;
+	unsigned int cacheable: 1;
+	unsigned int modified: 1;
+	unsigned int referenced: 1;
+	unsigned int acc: 3;
+	unsigned int et: 2;
+} __attribute__((packed)) pte_t;
+
+extern pte_t boot_pt[PTL0_ENTRIES];
+
+void mmu_init(void);
+
+#define	PTE_ET_DESCRIPTOR	1
+#define	PTE_ET_ENTRY		2
+#define	PTE_ACC_RWX		3
+#define	MMU_CONTROL_EN		(1 << 0)
+
+#endif
+
+/** @}
+ */
Index: boot/arch/sparc32/include/types.h
===================================================================
--- boot/arch/sparc32/include/types.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/include/types.h	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2006 Martin Decky
+ * 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 Definitions of basic types like #uintptr_t.
+ */
+
+#ifndef BOOT_sparc32_TYPES_H
+#define BOOT_sparc32_TYPES_H
+
+#define TASKMAP_MAX_RECORDS        32
+#define BOOTINFO_TASK_NAME_BUFLEN  32
+
+typedef uint32_t size_t;
+typedef uint32_t uintptr_t;
+
+typedef uint32_t pfn_t;
+
+typedef struct {
+	/** Address where the task was placed. */
+	void *addr;
+	/** Size of the task's binary. */
+	size_t size;
+	/** Task name. */
+	char name[BOOTINFO_TASK_NAME_BUFLEN];
+} task_t;
+
+typedef struct {
+	size_t cnt;
+	task_t tasks[TASKMAP_MAX_RECORDS];
+	/* Fields below are LEON-specific */
+	uintptr_t uart_base;
+	uintptr_t intc_base;
+	uintptr_t timer_base;
+	int uart_irq;
+	int timer_irq;
+	uint32_t memsize;
+} bootinfo_t;
+
+#endif
+
+/** @}
+ */
Index: boot/arch/sparc32/src/ambapp.c
===================================================================
--- boot/arch/sparc32/src/ambapp.c	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/src/ambapp.c	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -0,0 +1,158 @@
+/*
+ * 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()
+{
+	amba_fake = false;
+
+	/* 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 */
+	if (amba_devices_found == 0)
+		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_fake = true;
+	amba_devices_found = 3;
+}
+
+bool ambapp_fake()
+{
+	return amba_fake;
+}
+
+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 ", dev->vendor_id, dev->device_id, dev->bars[0].start);
+		if (dev->irq == -1)
+			printf("\n");
+		else
+			printf("irq %d\n", 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 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/src/asm.S	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -0,0 +1,57 @@
+#
+# 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
+	mov %i1, %o0
+	jmp %l0
+	nop
Index: boot/arch/sparc32/src/main.c
===================================================================
--- boot/arch/sparc32/src/main.c	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/src/main.c	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -0,0 +1,148 @@
+/*
+ * 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;
+	bootinfo.uart_base = amba_uart_base;
+	bootinfo.uart_irq = uart->irq;
+
+	/* Look up for IRQMP */
+	amba_device_t *irqmp = ambapp_lookup_first(GAISLER, GAISLER_IRQMP);
+	bootinfo.intc_base = irqmp->bars[0].start;
+
+	/* Look up for timer */
+	amba_device_t *timer = ambapp_lookup_first(GAISLER, GAISLER_GPTIMER);
+	bootinfo.timer_base = timer->bars[0].start;
+	bootinfo.timer_irq = timer->irq;
+	
+	/* Lookp up for memory controller and obtain memory size */
+	if (ambapp_fake()) {
+		bootinfo.memsize = 64 * 1024 * 1024; // 64MB
+	} else {
+		amba_device_t *mctrl = ambapp_lookup_first(ESA, ESA_MCTRL);
+		volatile mctrl_mcfg2_t *mcfg2 = (volatile mctrl_mcfg2_t *)(mctrl->bars[0].start + 0x4);
+		bootinfo.memsize = (1 << (13 + mcfg2->bank_size));
+	}
+	
+	/* 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();
+
+	printf("Memory size: %dMB\n", bootinfo.memsize >> 20);
+
+	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), &bootinfo);
+}
+
+/** @}
+ */
Index: boot/arch/sparc32/src/mm.c
===================================================================
--- boot/arch/sparc32/src/mm.c	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/src/mm.c	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -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 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
+++ boot/arch/sparc32/src/putchar.c	(revision 7a98cef11fb8f3d08a03c92aae4d500d0a75a5d0)
@@ -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);
+}
+
+/** @}
+ */
