Index: boot/arch/arm32/loader/Makefile
===================================================================
--- boot/arch/arm32/loader/Makefile	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
+++ boot/arch/arm32/loader/Makefile	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
@@ -0,0 +1,115 @@
+#
+# 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 ../../../../version
+include ../../../../Makefile.config
+
+## Toolchain configuration
+#
+
+TARGET = arm-linux-gnu
+TOOLCHAIN_DIR = /usr/local/arm/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 = -DRELEASE=\"$(RELEASE)\" -I. -I../../../generic -I../../.. -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 
+
+ifdef REVISION
+	CFLAGS += "-DREVISION=\"$(REVISION)\""
+endif
+
+ifdef TIMESTAMP
+	CFLAGS += "-DTIMESTAMP=\"$(TIMESTAMP)\""
+endif
+
+ifdef MACHINE
+	CFLAGS += "-DMACHINE=$(MACHINE)"
+endif
+
+SOURCES = \
+	main.c \
+	boot.S \
+	asm.S \
+	mm.c \
+	../../../generic/printf.c \
+	../../../genarch/division.c
+
+ifeq ($(MACHINE), gxemul_testarm)
+	SOURCES += print/gxemul.c
+endif
+
+
+COMPONENTS = \
+	$(KERNELDIR)/kernel.bin \
+	$(USPACEDIR)/ns/ns \
+	$(USPACEDIR)/init/init \
+	$(USPACEDIR)/kbd/kbd \
+	$(USPACEDIR)/console/console \
+	$(USPACEDIR)/fb/fb \
+	$(USPACEDIR)/tester/tester \
+	$(USPACEDIR)/klog/klog \
+	$(USPACEDIR)/tetris/tetris
+
+OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
+COMPONENT_OBJECTS := $(addsuffix .o,$(basename $(notdir $(COMPONENTS))))
+
+.PHONY: all clean depend
+
+all: image.boot
+
+-include Makefile.depend
+
+image.boot: depend _components.h _link.ld $(OBJECTS) $(COMPONENT_OBJECTS)
+	$(LD) -no-check-sections -N -T _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) -o $@ 
+
+depend:
+	-makedepend $(DEFS) $(CFLAGS) -f - $(SOURCES) > Makefile.depend 2> /dev/null
+
+clean:
+	-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend 
+
+_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
+	./pack $(IMAGE) $(OBJCOPY) $(COMPONENTS)
+
+%.o: %.S
+	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
+
+%.o: %.c
+	$(CC) $(DEFS) $(CFLAGS) -c $< -o $@
Index: boot/arch/arm32/loader/asm.S
===================================================================
--- boot/arch/arm32/loader/asm.S	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
+++ boot/arch/arm32/loader/asm.S	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
@@ -0,0 +1,85 @@
+#
+# 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.
+#
+
+
+.text
+
+.global memcpy
+
+memcpy:
+	add     r3, r1, #3
+	bic     r3, r3, #3
+	cmp     r1, r3
+	stmdb   sp!, {r4, lr}
+	beq     4f
+1:
+	cmp     r2, #0
+	movne   ip, #0
+	beq     3f
+2:
+	ldrb    r3, [ip, r1]
+	strb    r3, [ip, r0]
+	add     ip, ip, #1
+	cmp     ip, r2
+	bne     2b
+3:
+	mov     r0, r1
+	ldmia   sp!, {r4, pc}
+4:
+	add     r3, r0, #3
+	bic     r3, r3, #3
+	cmp     r0, r3
+	bne     1b
+	movs    r4, r2, lsr #2
+	moveq   lr, r4
+	beq     6f
+	mov     lr, #0
+	mov     ip, lr
+5:
+	ldr     r3, [ip, r1]
+	add     lr, lr, #1
+	cmp     lr, r4
+	str     r3, [ip, r0]
+	add     ip, ip, #4
+	bne     5b
+6:
+	ands    r4, r2, #3
+	beq     3b
+	mov     r3, lr, lsl #2
+	add     r0, r3, r0
+	add     ip, r3, r1
+	mov     r2, #0
+7:
+	ldrb    r3, [r2, ip]
+	strb    r3, [r2, r0]
+	add     r2, r2, #1
+	cmp     r2, r4
+	bne     7b
+	b       3b
+
+
Index: boot/arch/arm32/loader/asm.h
===================================================================
--- boot/arch/arm32/loader/asm.h	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
+++ boot/arch/arm32/loader/asm.h	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+
+/** @addtogroup arm32boot
+ * @{
+ */
+/** @file
+ *  @brief Functions implemented in assembly.
+ */ 
+
+
+#ifndef BOOT_arm32_ASM_H
+#define BOOT_arm32_ASM_H
+
+
+/** Copies cnt bytes from dst to src.
+ * 
+ * @param dst Destination address.
+ * @param src Source address.
+ * @param cnt Count of bytes to be copied. 
+ */
+#define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt))
+
+
+/** Called when the CPU is switched on.
+ *
+ *  This function is placed to the 0x0 address where ARM CPU starts execution. 
+ *  Jumps to the #bootstrap only.
+ */
+extern void start(void);
+
+
+/** Jumps to the kernel entry point.
+ *
+ * @param entry          Kernel entry point address.
+ * @param bootinfo       Structure holding information about loaded tasks.
+ * @param bootinfo_size  Size of the bootinfo structure.
+ */
+extern void jump_to_kernel(void *entry, void *bootinfo, unsigned int bootinfo_size) __attribute__((noreturn));
+
+
+#endif
+
+
+/** @}
+ */
+
Index: boot/arch/arm32/loader/boot.S
===================================================================
--- boot/arch/arm32/loader/boot.S	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
+++ boot/arch/arm32/loader/boot.S	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
@@ -0,0 +1,52 @@
+#
+# 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 "mm.h"
+
+.section BOOTSTRAP
+
+.global start
+.global jump_to_kernel
+.global page_table
+
+start:
+	b bootstrap
+
+jump_to_kernel:
+	bx r0
+
+
+# place page_table to PT section
+.section PT
+
+# make place for PTL0 page table
+page_table:
+	.skip PTL0_ENTRIES * PTL0_ENTRY_SIZE
+
+
Index: boot/arch/arm32/loader/main.c
===================================================================
--- boot/arch/arm32/loader/main.c	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
+++ boot/arch/arm32/loader/main.c	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
@@ -0,0 +1,115 @@
+/*
+ * 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.
+ */
+
+
+/** @addtogroup arm32boot
+ * @{
+ */
+/** @file
+ *  @brief Bootstrap.
+ */ 
+
+
+#include "main.h" 
+#include "asm.h"
+#include "_components.h"
+#include <printf.h>
+
+#include "mm.h"
+
+/** Kernel entry point address. */
+#define KERNEL_VIRTUAL_ADDRESS 0x80200000
+
+
+char *release = RELEASE;
+
+#ifdef REVISION
+	char *revision = ", revision " REVISION;
+#else
+	char *revision = "";
+#endif
+
+#ifdef TIMESTAMP
+	char *timestamp = "\nBuilt on " TIMESTAMP;
+#else
+	char *timestamp = "";
+#endif
+
+
+/** Prints bootloader version information. */
+static void version_print(void)
+{
+	printf("HelenOS ARM32 Bootloader\nRelease %s%s%s\nCopyright (c) 2007 HelenOS project\n", 
+		release, revision, timestamp);
+}
+
+
+/** Copies all images (kernel + user tasks) to #KERNEL_VIRTUAL_ADDRESS and jumps there. */
+void bootstrap(void)
+{
+	mmu_start();
+	version_print();
+
+	component_t components[COMPONENTS];
+	bootinfo_t bootinfo;
+	init_components(components);
+	
+	printf("\nMemory statistics\n");
+	printf(" kernel entry point at %L\n", KERNEL_VIRTUAL_ADDRESS);
+	printf(" %L: boot info structure\n", &bootinfo);
+
+	unsigned int i, j;
+	for (i = 0; i < COMPONENTS; i++) {
+		printf(" %L: %s image (size %d bytes)\n", 
+			components[i].start, components[i].name, components[i].size);
+	}
+
+	printf("\nCopying components\n");
+
+	unsigned int top = 0;
+	bootinfo.cnt = 0;
+	for (i = 0; i < COMPONENTS; i++) {
+		printf(" %s...", components[i].name);
+		top = ALIGN_UP(top, KERNEL_PAGE_SIZE);
+		memcpy(((void *) KERNEL_VIRTUAL_ADDRESS) + top, components[i].start, components[i].size);
+		if (i > 0) {
+			bootinfo.tasks[bootinfo.cnt].addr = ((void *) KERNEL_VIRTUAL_ADDRESS) + top;
+			bootinfo.tasks[bootinfo.cnt].size = components[i].size;
+			bootinfo.cnt++;
+		}
+		top += components[i].size;
+		printf("done.\n");
+	}
+	
+	printf("\nBooting the kernel...\n");
+	jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS, &bootinfo, sizeof(bootinfo));
+}
+
+/** @}
+ */
+
Index: boot/arch/arm32/loader/main.h
===================================================================
--- boot/arch/arm32/loader/main.h	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
+++ boot/arch/arm32/loader/main.h	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+
+/** @addtogroup arm32boot
+ * @{
+ */
+/** @file
+ *  @brief Boot related declarations.
+ */ 
+
+
+#ifndef BOOT_arm32_MAIN_H
+#define BOOT_arm32_MAIN_H
+
+
+/** Aligns to the nearest higher address.
+ *
+ * @param addr  Address or number to be aligned.
+ * @param align Size of alignment, must be power of 2.
+ */
+#define ALIGN_UP(addr, align) (((addr) + ((align) - 1)) & ~((align) - 1))
+
+/** Maximum number of tasks in the #bootinfo_t struct. */
+#define TASKMAP_MAX_RECORDS 32
+
+
+/** Struct holding information about single loaded task. */
+typedef struct {
+	/** Address where the task was placed. */
+	void *addr;
+	/** Size of the task's binary. */
+	unsigned int size;
+} task_t;
+
+
+/** Struct holding information about loaded tasks. */
+typedef struct {
+	/** Number of loaded tasks. */
+	unsigned int cnt;
+	/** Array of loaded tasks. */
+	task_t tasks[TASKMAP_MAX_RECORDS];
+} bootinfo_t;
+
+
+
+extern void bootstrap(void);
+
+#endif
+
+/** @}
+ */
+
Index: boot/arch/arm32/loader/mm.c
===================================================================
--- boot/arch/arm32/loader/mm.c	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
+++ boot/arch/arm32/loader/mm.c	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2007 Pavel Jancik, 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.
+ */
+
+
+/** @addtogroup arm32boot
+ * @{
+ */
+/** @file 
+ *  @brief Memory management used while booting the kernel.
+ */ 
+
+
+#include "mm.h"
+
+
+/** Initializes "section" page table entry.
+ *
+ *  Will be readable/writable by kernel with no access from user mode.
+ *  Will belong to domain 0. No cache or buffering is enabled.
+ *  
+ *  @param pte    Section entry to initialize.
+ *  @param frame  First frame in the section (frame number).
+ *
+ *  @note         If frame is not 1MB aligned, first lower 1MB aligned frame will be used.
+ */   
+static void init_pte_level0_section(pte_level0_section_t* pte, unsigned int frame)
+{
+	pte->descriptor_type   = PTE_DESCRIPTOR_SECTION;
+	pte->bufferable        = 0;
+	pte->cacheable         = 0; 
+   	pte->impl_specific     = 0;
+	pte->domain            = 0;
+	pte->should_be_zero_1  = 0;
+	pte->access_permission = PTE_AP_USER_NO_KERNEL_RW;	
+	pte->should_be_zero_2  = 0;
+	pte->section_base_addr = frame;
+}
+
+
+/** Initializes page table used while booting the kernel. */
+static void init_page_table(void) 
+{
+	int i;
+	const unsigned int first_kernel_page = ADDR2PFN(PA2KA(0));
+
+	// create 1:1 virtual-physical mapping (in lower 2GB)
+	for (i = 0; i < first_kernel_page; i++) {
+		init_pte_level0_section(&page_table[i], i);
+	}
+
+	// create 1:1 virtual-physical mapping in kernel space (upper 2GB),
+	// physical addresses start from 0
+	for (i = first_kernel_page; i < PTL0_ENTRIES; i++) {
+		init_pte_level0_section(&page_table[i], i - first_kernel_page);
+	}
+}
+
+
+/** Starts the MMU - initializes page table and enables paging. */
+void mmu_start() {
+	init_page_table();
+	set_ptl0_address(page_table);
+	enable_paging();
+}
+
+
+/** @}
+ */
+ 
Index: boot/arch/arm32/loader/mm.h
===================================================================
--- boot/arch/arm32/loader/mm.h	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
+++ boot/arch/arm32/loader/mm.h	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2007 Pavel Jancik, 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.
+ */
+
+
+/** @addtogroup arm32boot
+ * @{
+ */
+/** @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_arm32__MM_H
+#define BOOT_arm32__MM_H
+
+
+#ifndef __ASM__
+#include "types.h"
+#endif
+
+
+/** Frame width. */
+#define FRAME_WIDTH                 20
+
+/** Frame size. */
+#define FRAME_SIZE                  (1 << FRAME_WIDTH)
+
+/** Page size in 2-level paging which is switched on later after the kernel initialization. */
+#define KERNEL_PAGE_SIZE            (1 << 12)
+
+
+#ifndef __ASM__
+/** Converts kernel address to physical address. */
+#	define KA2PA(x)                 (((uintptr_t) (x)) - 0x80000000)
+/** Converts physical address to kernel address. */
+#	define PA2KA(x)                 (((uintptr_t) (x)) + 0x80000000)
+#else
+#	define KA2PA(x)                 ((x) - 0x80000000)
+#	define PA2KA(x)                 ((x) + 0x80000000)
+#endif
+
+
+/** Number of entries in PTL0. */
+#define PTL0_ENTRIES                (1<<12)				/* 4096 */
+
+/** Size of an entry in PTL0. */
+#define PTL0_ENTRY_SIZE             4
+
+/** Returns number of frame the address belongs to. */
+#define ADDR2PFN( addr )            ( ((uintptr_t)(addr)) >> FRAME_WIDTH )
+
+/** Describes "section" page table entry (one-level paging with 1MB sized pages). */  
+#define PTE_DESCRIPTOR_SECTION      0x2
+
+/** Page table access rights: user - no access, kernel - read/write. */
+#define PTE_AP_USER_NO_KERNEL_RW    0x1
+
+
+#ifndef __ASM__
+
+
+/** Page table level 0 entry - "section" format is used (one-level paging, 1MB sized
+ * pages). Used only while booting the kernel. 
+ */
+typedef struct {
+	unsigned descriptor_type     : 2;
+	unsigned bufferable          : 1;
+	unsigned cacheable           : 1; 
+   	unsigned impl_specific       : 1;
+	unsigned domain              : 4;
+	unsigned should_be_zero_1    : 1;
+	unsigned access_permission   : 2; 	
+	unsigned should_be_zero_2    : 8;
+	unsigned section_base_addr   : 12;
+} __attribute__ ((packed)) pte_level0_section_t;
+
+
+/** Page table that holds 1:1 virtual to physical mapping used while booting the kernel. */ 
+extern pte_level0_section_t page_table[PTL0_ENTRIES];
+
+extern void mmu_start(void);
+
+
+/** Enables paging. */
+static inline void enable_paging()
+{
+	/* c3 - each two bits controls access to the one of domains (16)
+	 *      0b01 - behave as a client (user) of a domain
+	 */
+	asm volatile (
+		// behave as a client of domains
+		"ldr r0, =0x55555555       \n"
+		"mcr p15, 0, r0, c3, c0, 0 \n" 
+
+		// current settings
+		"mrc p15, 0, r0, c1, c0, 0 \n"
+
+		// mask to enable paging
+		"ldr r1, =0x00000001       \n"
+		"orr r0, r0, r1            \n"
+
+		// store settings
+		"mcr p15, 0, r0, c1, c0, 0 \n"
+		:
+		:
+		: "r0", "r1"
+	);
+}
+
+
+/** Sets the address of level 0 page table to CP15 register 2.
+ *
+ * @param pt Address of a page table to set.
+ */   
+static inline void set_ptl0_address(pte_level0_section_t* pt)
+{
+    asm volatile (
+		"mcr p15, 0, %0, c2, c0, 0 \n"
+		:
+		: "r"(pt)
+    );
+}
+
+
+#endif
+ 
+#endif
+
+/** @}
+ */
+ 
Index: boot/arch/arm32/loader/pack
===================================================================
--- boot/arch/arm32/loader/pack	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
+++ boot/arch/arm32/loader/pack	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
@@ -0,0 +1,139 @@
+#! /bin/sh
+
+#
+# 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.
+#
+
+
+OBJCOPY="$1"
+LINK="_link.ld"
+HEADER="_components.h"
+
+shift 1
+
+echo "OUTPUT_FORMAT(\"elf32-littlearm\")
+
+ENTRY(start)
+
+SECTIONS {
+	.boot 0x0: AT (0) {
+		*(BOOTSTRAP);
+		*(.text);
+		
+		*(.rodata);
+		*(.rodata.*);
+		*(.data);		/* initialized data */
+		*(.sdata);
+		*(.sdata2);
+		*(.sbss);
+		*(.scommon);
+		*(.bss);		/* uninitialized static variables */	
+		*(COMMON); 		/* global variables */
+		*(.reginfo);
+
+		. = 0x4000;
+		*(PT);			/* page table placed at 0x4000 */" > "$LINK"
+
+echo '
+/** @addtogroup arm32boot
+ * @{
+ */
+/** @file
+ *  @brief Components (kernel + tasks) related declarations.
+ *
+ *  Generated by the <code>pack</code> script. This script packs all the
+ *  components (kernel + tasks) into one image (image.boot) and generates
+ *  a code that initializes an array of #component_t structs.
+ */
+
+#ifndef ___COMPONENTS_H__
+#define ___COMPONENTS_H__
+
+/** Holds information about components packed to one image (kernel + tasks). */
+typedef struct {
+	/** Name. */
+	char *name;
+	/** Start address. */
+	void *start;
+	/** End address. */
+	void *end;
+	/** Size (in bytes). */
+	unsigned int size;
+} component_t;
+
+/** @}
+*/
+
+' > "$HEADER"
+
+COUNT="0"
+DATA=""
+
+for TASK in "$@" ; do
+	BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`"
+	OBJECT="${BASENAME}.o"
+	SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`"
+	MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`"
+	echo "$TASK -> $OBJECT"
+	
+	echo "
+		. = ALIGN(4096);
+		*(.${BASENAME}_image);" >> "$LINK"
+	
+	echo "
+extern int ${SYMBOL}_start;
+extern int ${SYMBOL}_end;
+
+#define ${MACRO}_START ((void *) &${SYMBOL}_start)
+#define ${MACRO}_END ((void *) &${SYMBOL}_end)
+#define ${MACRO}_SIZE ((unsigned int) ${MACRO}_END - (unsigned int) ${MACRO}_START)" >> "$HEADER"
+	
+	"$OBJCOPY" -I binary -O elf32-littlearm -B arm --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT"
+		
+	DATA="${DATA}
+	components[$COUNT].name = \"${BASENAME}\";
+	components[$COUNT].start = ${MACRO}_START;
+	components[$COUNT].end = ${MACRO}_END;
+	components[$COUNT].size = ${MACRO}_SIZE;";
+	COUNT="`expr "$COUNT" + 1`"
+done
+
+echo '	}
+}' >> "$LINK"
+
+echo "
+#define COMPONENTS $COUNT
+
+/** Initializes array of components. */
+static void init_components(component_t components[])
+{
+$DATA
+}
+
+#endif
+
+" >> "$HEADER"
Index: boot/arch/arm32/loader/print/gxemul.c
===================================================================
--- boot/arch/arm32/loader/print/gxemul.c	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
+++ boot/arch/arm32/loader/print/gxemul.c	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+
+
+/** @addtogroup arm32boot
+ * @{
+ */
+/** @file
+ *  @brief GXemul specific code.
+ */ 
+
+
+#include <printf.h>
+
+
+/** Address where characters to be printed are expected. */
+#define PUTC_ADDRESS	0x10000000
+
+
+/** Prints a character to the console.
+ *
+ * @param ch Character to be printed.
+ */
+static void putc(char ch)
+{
+	*((volatile char *)PUTC_ADDRESS) = ch;
+}
+
+
+/** Prints a string to the console.
+ *
+ * @param str String to be printed.
+ * @param len Number of characters to be printed.
+ */
+void write(const char *str, const int len)
+{
+	int i;
+	for (i = 0; i < len; ++i) {
+		putc(str[i]);
+	}
+}
+
+/** @}
+ */
+
Index: boot/arch/arm32/loader/types.h
===================================================================
--- boot/arch/arm32/loader/types.h	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
+++ boot/arch/arm32/loader/types.h	(revision 6b781c0c856d94b3114ccd6375bc6667a19e9bfe)
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+
+/** @addtogroup arm32boot
+ * @{
+ */
+/** @file 
+ *  @brief Definitions of basic types like #uintptr_t.
+ */ 
+
+
+#ifndef BOOT_arm32_TYPES_H
+#define BOOT_arm32_TYPES_H
+
+
+#include <gentypes.h>
+
+typedef signed char int8_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef uint32_t uintptr_t;
+typedef uint32_t unative_t;
+
+
+#endif
+
+
+/** @}
+ */
+
