xref: /netbsd/sys/arch/zaurus/zaurus/kloader_zaurus.S (revision 1ebb3968)
1/*	$NetBSD: kloader_zaurus.S,v 1.3 2012/01/21 18:56:52 nonaka Exp $	*/
2
3/*-
4 * Copyright (C) 2009-2012 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
30#include <arm/armreg.h>
31#include <arm/arm32/pte.h>
32#include <arm/arm32/pmap.h>		/* for PMAP_DOMAIN_KERNEL */
33
34/*
35 * CPWAIT -- Canonical method to wait for CP15 update.
36 * NOTE: Clobbers the specified temp reg.
37 * copied from arm/arm/cpufunc_asm_xscale.S
38 * XXX: better be in a common header file.
39 */
40#define	CPWAIT_BRANCH							 \
41	sub	pc, pc, #4
42
43#define	CPWAIT(tmp)							 \
44	mrc	p15, 0, tmp, c2, c0, 0	/* arbitrary read of CP15 */	;\
45	mov	tmp, tmp		/* wait for it to complete */	;\
46	CPWAIT_BRANCH			/* branch to next insn */
47
48	.text
49/*
50 * void
51 * kloader_zaurus_boot(struct kloader_bootinfo *kbi,
52 *                     struct kloader_page_tag *tag)
53 *
54 * r0: kbi, r1: tag
55 */
56	.global	_C_LABEL(kloader_zaurus_boot)
57_C_LABEL(kloader_zaurus_boot):
58	mov	sp, r0			/* sp: kbi */
59	bic	sp, sp, #0xff000000	/* clear upper 8 bits */
60	orr	sp, sp, #0xa0000000	/* OR in physical base address */
61
62	/* We will go ahead and disable the MMU here. */
63	adr	r8, .Lmmuoff
64	bic	r8, r8, #0xff000000	/* clear upper 8 bits */
65	orr	r8, r8, #0xa0000000	/* OR in physical base address */
66
67	mrc	p15, 0, r2, c1, c0, 0
68	bic	r2, r2, #CPU_CONTROL_MMU_ENABLE
69	bic	r2, r2, #CPU_CONTROL_DC_ENABLE
70	bic	r2, r2, #CPU_CONTROL_IC_ENABLE
71	mcr	p15, 0, r2, c1, c0, 0
72
73	nop
74	nop
75	nop
76
77	mov	pc, r8			/* Heave-ho! */
78
79.Lmmuoff:
80
81	/* Load kernel image */
82	mov	r4, r1		/* tag */
831:	mov	r3, r4
84	cmp	r3, #0		/* tag == NULL */
85	beq	3f
86	bic	r3, r3, #0xff000000
87	orr	r3, r3, #0xa0000000
88	ldmia	r3, {r4-r7}	/* r4: next, r5: src, r6: dst, r7: sz */
89	bic	r5, r5, #0xff000000
90	orr	r5, r5, #0xa0000000
91	bic	r6, r6, #0xff000000
92	orr	r6, r6, #0xa0000000
93	add	r8, r6, r7	/* r8: dst + sz */
942:	ldr	r9, [r5], #4	/* copy */
95	str	r9, [r6], #4
96	cmp	r8, r6
97	bne	2b
98#ifdef PROGRESS
99	bl	.Lprogress
100#endif
101	b	1b
1023:
103#ifdef PROGRESS
104	bl	.Lputcrlf
105#endif
106
107	/* Set kernel entry */
108	ldr	r0, [sp]
109
110	/* Set temporary stack pointer */
111	ldr	sp, .Lstack_addr
112
113	/* Jump to kernel entry */
114	mov	pc, r0
115
11699:	b	99b
117
118.Lstack_addr:
119	.word	0xa0004000
120
121#ifdef PROGRESS
122.Lprogress:
123	mov	r0, #0x2e /*'.'*/
124	b	.Lputchar
125
126.Lputchar:
127	ldr	r2, .Lffuart_txdata
128	ldr	r1, .Lffuart_txbusy
1291:
130	ldr	r9, [r1]
131	tst	r9, #0x20
132	beq	1b
133	str	r0, [r2]
134	mov	pc, lr
135
136.Lhexprint:
137	ldr	r2, .Lffuart_txdata
138	ldr	r1, .Lffuart_txbusy
139	mov	r10, #32
1401:	sub	r10, r10, #4
141	mov	r11, r0, lsr r10
142	and	r11, r11, #0xf
1432:	ldr	r9, [r1]
144	tst	r9, #0x20
145	beq	2b
146	adr	r12, .Lhextable
147	ldrb	r9, [r12, r11]
148	str	r9, [r2]
149	cmp	r10, #0
150	bne	1b
1513:	ldr	r9, [r1]
152	tst	r9, #0x20
153	beq	3b
154	mov	r9, #0x0d
155	str	r9, [r2]
1564:	ldr	r9, [r1]
157	tst	r9, #0x20
158	beq	4b
159	mov	r9, #0x0a
160	str	r9, [r2]
161	mov	pc, lr
162
163.Lputcrlf:
164	ldr	r2, .Lffuart_txdata
165	ldr	r1, .Lffuart_txbusy
166	b	3b
167
168	.align 2
169
170.Lffuart_txdata:
171	.word	0x40100000
172.Lffuart_txbusy:
173	.word	0x40100014
174
175.Lhextable:
176	.asciz	"0123456789abcdef"
177#endif
178