ブートローダと NetBSD on uARM のカーネルをでっち上げてみましたが動きませんでした

Linux on an 8-bit micro? - Dmitry Grinberg簡潔なARMエミュレータ実装として面白そうな「uARM」というのを見て、正直ブートローダと言えないようなブートローダを書いて PXA250 なカーネルコンフィグを適当にでっち上げて試してみたところ見事動きませんでした。残念。

ブートローダもどき

これの後に objcopy で binary に変換したカーネルなどのファイルをくっつけたファイルを作って、uARM に喰わせるとつっくけたファイルが起動します。
ブートローダもどきの .Lkernel_secsize にくっつけたファイルのサイズ÷512 を指定しましょう。ファイルサイズ以上のセクタを読みに行くとエラーが表示されます。まあエラーが表示されるだけなんでファイルサイズが小さい場合はいじらなくてもいいけど。

/*	$NetBSD$	*/

/*-
 * Copyright (C) 2013 NONAKA Kimihiro <nonaka@netbsd.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. 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.
 *
 * 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 <machine/asm.h>
#include <arm/armreg.h>

#define	HYPERCALL	0xF7BBBBBB
#define	SECSIZE		512

	.text

	.thumb
        .global _C_LABEL(_start)
_C_LABEL(_start):
	adr	r0, .Lstart
	bx	r0

	.align 4
	.code 32
.Lstart:
	/* banner */
	mov	r0, #'H'
	bl	.Lputchar
	mov	r0, #'e'
	bl	.Lputchar
	mov	r0, #'l'
	bl	.Lputchar
	mov	r0, #'l'
	bl	.Lputchar
	mov	r0, #'o'
	bl	.Lputchar
	mov	r0, #','
	bl	.Lputchar
	mov	r0, #' '
	bl	.Lputchar
	mov	r0, #'N'
	bl	.Lputchar
	mov	r0, #'e'
	bl	.Lputchar
	mov	r0, #'t'
	bl	.Lputchar
	mov	r0, #'B'
	bl	.Lputchar
	mov	r0, #'S'
	bl	.Lputchar
	mov	r0, #'D'
	bl	.Lputchar
	mov	r0, #'!'
	bl	.Lputchar
	mov	r0, #'\r'
	bl	.Lputchar
	mov	r0, #'\n'
	bl	.Lputchar

	/* load kernel */
	ldr	r8, .Lkernel_text
	mov	r9, #1
	ldr	r10, .Lkernel_secsize
1:
	mov	r0, r8
	mov	r1, r9
	bl	.Lreadsec
	mov	r0, #'.'
	bl	.Lputchar
	add	r8, r8, #SECSIZE
	add	r9, r9, #1
	subs	r10, r10, #1
	bgt	1b

	/* banner */
	mov	r0, #'B'
	bl	.Lputchar
	mov	r0, #'o'
	bl	.Lputchar
	mov	r0, #'o'
	bl	.Lputchar
	mov	r0, #'t'
	bl	.Lputchar
	mov	r0, #'\r'
	bl	.Lputchar
	mov	r0, #'\n'
	bl	.Lputchar

	/* jump into kernel */
	ldr	r0, .Lkernel_text
	bx	r0

	mov	r12, #0
	.word	HYPERCALL
99:	b	99b

.Lkernel_text:
	.word	0xa0200000
.Lkernel_secsize:
	.word	5053

	/* r0: char */
.Lputchar:
			/* r0: char */
	mov	r12, #2
	.word	HYPERCALL
	mov	pc, lr

	/* r0: buffer address */
	/* r1: sector */
.Lreadsec:
	mov	r3, r0
	/* read from disk */
	mov	r0, #1	/* r0: 0:size, 1:read, 2:write */
			/* r1: sector */
	mov	r12, #4
	.word	HYPERCALL

	/* read from buffer */
	mov	r4, #0
	mov	r5, #SECSIZE
1:
	mov	r1, r4
	mov	r2, #0
	mov	r12, #5
	.word	HYPERCALL
	str	r0, [r3], #4
	add	r4, r4, #1
	subs	r5, r5, #4
	bgt	1b
	mov	pc,lr


	.align 1
/*
 * MBR partition table
 */
	. = _C_LABEL(_start) + MBR_PART_OFFSET
_pbr_part0:
	.byte	0, 0, 0, 0, 0, 0, 0, 0
	.byte	0, 0, 0, 0, 0, 0, 0, 0
_pbr_part1:
	.byte	0, 0, 0, 0, 0, 0, 0, 0
	.byte	0, 0, 0, 0, 0, 0, 0, 0
_pbr_part2:
	.byte	0, 0, 0, 0, 0, 0, 0, 0
	.byte	0, 0, 0, 0, 0, 0, 0, 0
_pbr_part3:
	.byte	0, 0, 0, 0, 0, 0, 0, 0
	.byte	0, 0, 0, 0, 0, 0, 0, 0

	. = _C_LABEL(_start) + MBR_MAGIC_OFFSET
magic:
	.short	MBR_MAGIC

ブートログ

nonaka@koharu$ ./uARM nbsdboot
Hello, NetBSD!
.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................Boot

NetBSD/evbarm (uARM) booting ...
initarm: Configuring system ...
physmemory: 4096 pages at 0xa0000000 -> 0xa0ffffff
Allocating page tables
freestart = 0xa0009000, free_pages = 503 (0x000001f7)
IRQ stack: p0xa01f1000 v0xc01f1000
ABT stack: p0xa01f0000 v0xc01f0000
UND stack: p0xa01ef000 v0xc01ef000
SVC stack: p0xa01ed000 v0xc01ed000
minidataclean: p0xa01ec000 v0xc01ec000, size = 2048
Creating L1 page table at 0xa01fc000
Mapping kernel
pmap_map_chunk: pa=0xa0200000 va=0xc0200000 size=0x1a2000 resid=0x1a2000 prot=0x3 cache=1
SLLLLLLLLLLPP
pmap_map_chunk: pa=0xa03a2000 va=0xc03a2000 size=0xea000 resid=0xea000 prot=0x3 cache=1
PPPPPPPPPPPPPPLLLLLLLLLLLLLPPPPPPPPPPPP
Constructing L2 page tables
pmap_map_chunk: pa=0xa01f1000 va=0xc01f1000 size=0x1000 resid=0x1000 prot=0x3 cache=1
P
pmap_map_chunk: pa=0xa01f0000 va=0xc01f0000 size=0x1000 resid=0x1000 prot=0x3 cache=1
P
pmap_map_chunk: pa=0xa01ef000 va=0xc01ef000 size=0x1000 resid=0x1000 prot=0x3 cache=1
P
pmap_map_chunk: pa=0xa01ed000 va=0xc01ed000 size=0x2000 resid=0x2000 prot=0x3 cache=1
PP
pmap_map_chunk: pa=0xa01fc000 va=0xc01fc000 size=0x4000 resid=0x4000 prot=0x3 cache=2
PPPP
pmap_map_chunk: pa=0xa01fb000 va=0xc01fb000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0xa01fa000 va=0xc01fa000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0xa01f9000 va=0xc01f9000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0xa01f8000 va=0xc01f8000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0xa01f7000 va=0xc01f7000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0xa01f6000 va=0xc01f6000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0xa01f5000 va=0xc01f5000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0xa01f4000 va=0xc01f4000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
pmap_map_chunk: pa=0xa01f3000 va=0xc01f3000 size=0x1000 resid=0x1000 prot=0x3 cache=2
P
devmap: 40e00000 -> 40efffff @ fd000000
pmap_map_chunk: pa=0x40e00000 va=0xfd000000 size=0x100000 resid=0x100000 prot=0x3 cache=0
S
devmap: 41300000 -> 413fffff @ fd100000
pmap_map_chunk: pa=0x41300000 va=0xfd100000 size=0x100000 resid=0x100000 prot=0x3 cache=0
S
devmap: 40d00000 -> 40dfffff @ fd200000
pmap_map_chunk: pa=0x40d00000 va=0xfd200000 size=0x100000 resid=0x100000 prot=0x3 cache=0
S
devmap: 40100000 -> 401fffff @ fd300000
pmap_map_chunk: pa=0x40100000 va=0xfd300000 size=0x100000 resid=0x100000 prot=0x3 cache=0
S
freestart = 0xa048c000, free_pages = 2932 (0xb74)
switching to new L1 page table  @0xa01fc000...bootstrap done.
init subsystems: stacks vectors undefined page pmap
[ Kernel symbol table missing! ]

uvm_fault(0xc0489434, e59ff000, 1) -> e
Fatal kernel mode data abort: 'Translation Fault (S)'
trapframe: 0xc01eed30
FSR=00000005, FAR=e59ff114, spsr=000000d3
r0 =e59ff114, r1 =00001000, r2 =00000001, r3 =00000000
r4 =00000000, r5 =00001000, r6 =c0473ae0, r7 =c047fc9c
r8 =c01ed000, r9 =00001000, r10=00000001, r11=c01eeda8
r12=c01eedac, ssp=c01eed80, slr=c0295538, pc =c026d27c

Stopped in pid 0.1 (system) at  c026d27c:       ldr     r3, [r0]
db>