4 * Copyright (c) 2005 NONAKA Kimihiro
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <machine/asm.h>
30 #include <sys/bootblock.h>
33 #define MBR_AFTERBPB 90 /* BPB size in FAT32 partition BR */
35 #define MBR_AFTERBPB 62 /* BPB size in floppy master BR */
40 .byte 0x11 /* 0x4e11: cmp/pz r14... */
43 . = _C_LABEL(start) + MBR_BPB_OFFSET /* move to start of BPB */
45 . = _C_LABEL(start) + MBR_AFTERBPB /* skip BPB */
50 mov r0, r11 /* r11: own loaded address */
52 mov.w stack_offset, r1
54 mov r0, r15 /* r15: stack pointer */
55 mov r0, r10 /* r10: load address */
57 /* enable/flush cache */
62 /* Read from start of disk */
63 mov #0x40, r4 /* LBA */
64 mov #0, r5 /* LBA #0 */
65 mov r10, r6 /* buffer address */
67 mov #BOOTXX_SECTORS, r7 /* number of sectors */
73 mov #0, r9 /* r9: sector # */
75 /* Search bootable partition */
76 mov.w part_offset, r12
77 add r10, r12 /* r12: pointer to partition entry */
78 mov #MBR_PART_COUNT, r8 /* r8: partition loop counter */
82 cmp/eq #MBR_PTYPE_FAT12, r0
84 cmp/eq #MBR_PTYPE_FAT16S, r0
86 cmp/eq #MBR_PTYPE_FAT16B, r0
88 cmp/eq #MBR_PTYPE_FAT32, r0
90 cmp/eq #MBR_PTYPE_FAT32L, r0
92 cmp/eq #MBR_PTYPE_FAT16L, r0
95 cmp/eq #MBR_PTYPE_NETBSD, r0
100 /* found boot partition */
108 bt next_part /* start LBA == 0 ? */
119 /* Not found NetBSD partition */
133 mova ERR_NO_BOOTXX, r0
154 mov #0x40, r4 /* LBA */
155 mov r9, r5 /* LBA # */
156 mov r10, r6 /* buffer address */
158 mov #BOOTXX_SECTORS, r7 /* number of sectors */
161 mov.l .L.bootxx_magic1, r1
162 mov.l .L.bootxx_magic, r2
172 mov.l .L.bootxx_start, r13
173 jmp @r13 /* jump to bootxx */
174 mov r9, r4 /* pass sector address to bootxx */
178 mbr_size: .word mbr_end - _C_LABEL(start)
180 stack_offset: .word 0x1000
182 part_offset: .word MBR_PART_OFFSET
184 magic_offset: .word MBR_MAGIC_OFFSET
188 .long LANDISK_BOOT_MAGIC_1
190 .long _C_LABEL(bootxx_magic)
192 .long _C_LABEL(bootxx_start)
198 ERR_READ: .asciz "Disk read"
200 ERR_NO_BOOTXX: .asciz "Not a bootxx image"
202 ERR_PTN: .asciz "No NetBSD partition"
205 /* space for mbr_dsn */
206 . = _C_LABEL(start) + MBR_DSN_OFFSET
209 /* mbr_bootsel_magic */
210 . = _C_LABEL(start) + MBR_BS_MAGIC_OFFSET
214 * MBR partition table
216 . = _C_LABEL(start) + MBR_PART_OFFSET
218 .byte 0, 0, 0, 0, 0, 0, 0, 0
219 .byte 0, 0, 0, 0, 0, 0, 0, 0
221 .byte 0, 0, 0, 0, 0, 0, 0, 0
222 .byte 0, 0, 0, 0, 0, 0, 0, 0
224 .byte 0, 0, 0, 0, 0, 0, 0, 0
225 .byte 0, 0, 0, 0, 0, 0, 0, 0
227 .byte 0, 0, 0, 0, 0, 0, 0, 0
228 .byte 0, 0, 0, 0, 0, 0, 0, 0
230 . = _C_LABEL(start) + MBR_MAGIC_OFFSET