1/*	$NetBSD: bootxx.S,v 1.1 2006/09/01 21:26:19 uwe Exp $	*/
2
3/*-
4 * Copyright (C) 2005 NONAKA Kimihiro <nonaka@netbsd.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <machine/asm.h>
29#include <sys/bootblock.h>
30
31ENTRY(bootxx_start)
32	bra	bootxx_start1
33	 nop
34	.balign 4
35ENTRY(bootxx_magic)
36	.long	LANDISK_BOOT_MAGIC_1
37boot_params:
38	.long	1f - boot_params
39#include <boot_params.S>
40
41	. = bootxx_start + 0x80
42bootxx_start1:
43	mov.l	.L._end, r0		/* zero bss */
44	mov.l	.L.__bss_start, r1
45	sub	r1, r0
46	shlr2	r0			/* _end and __bss_start are aligned */
47	mov	#0, r2
481:	mov.l	r2, @r1
49	dt	r0
50	bf/s	1b
51	 add	#4, r1
52
53	mov.l	.L.2nd_loadaddr, r15	/* new stack pointer */
54	mov.l	r4, @-r15
55	mov.l	.L.boot1, r0
56	jsr	@r0
57	 mov	r15, r4
58
59	tst	r0, r0
60	bf/s	boot_fail
61	 mov.l	@r15+, r5		/* pass boot sector to boot */
62
63	/* flush cache */
64	mov	#0, r4
65	mov	#6, r0
66	trapa	#0x3f
67
68	mov.l	.L.2nd_loadaddr, r0
69	mov.l	.L.boot_params, r4
70	jmp	@r0
71	 nop
72
73boot_fail:
74	mov	r0, r1
75	mova	.L.errtxt, r0
76	mov	r0, r4
77	mov	#32, r0
78	trapa	#0x3f
79	mov	r1, r4
80	mov	#32, r0
81	trapa	#0x3f
82	mova	.L.crlf, r0
83	mov	r0, r4
84	mov	#32, r0
85	trapa	#0x3f
8699:	bra	99b
87	 nop
88
89
90	.align	2
91.L._end:
92	.long	_end
93.L.__bss_start:
94	.long	__bss_start
95.L.boot1:
96	.long	_C_LABEL(boot1)
97.L.2nd_loadaddr:
98	.long	SECONDARY_LOAD_ADDRESS
99.L.boot_params:
100	.long	boot_params
101
102	.align	2
103.L.errtxt:	.asciz	"Error: "
104	.align	2
105.L.crlf:	.asciz	"\r\n"
106
107
108	/*
109	 * Vector the fs calls through here so we can support multiple
110	 * file system types with one copy of the library code and
111	 * multiple copies of this file.
112	 */
113ENTRY(xxfs_open)
114	mov.l	1f, r0
115	jmp	@r0
116	 nop
117	.align	2
1181:	.long	_C_LABEL(XXfs_open)
119
120ENTRY(xxfs_close)
121	mov.l	1f, r0
122	jmp	@r0
123	 nop
124	.align	2
1251:	.long	_C_LABEL(XXfs_close)
126
127ENTRY(xxfs_read)
128	mov.l	1f, r0
129	jmp	@r0
130	 nop
131	.align	2
1321:	.long	_C_LABEL(XXfs_read)
133
134ENTRY(xxfs_stat)
135	mov.l	1f, r0
136	jmp	@r0
137	 nop
138	.align	2
1391:	.long	_C_LABEL(XXfs_stat)
140
141
142
143/*
144 * int readsects(int dev, uint32_t lba, void *buf, size_t size);
145 */
146ENTRY(readsects)
147	mov	#2, r0
148	trapa	#0x3f
149	rts
150	 nop
151argerror:
152	rts
153	 mov	#-1, r0
154
155/*
156 * void putstr(const char *str);
157 */
158ENTRY(putstr)
159	mov	#32, r0
160	trapa	#0x3f
161	rts
162	 nop
163