xref: /netbsd-src/sys/arch/hpcarm/hpcarm/kloader_pxa2x0.S (revision 02e1daee54efd901aa57f706a577298d954b8587)
1/*	$NetBSD: kloader_pxa2x0.S,v 1.2 2021/10/11 14:29:15 rin Exp $	*/
2
3/*-
4 * Copyright (C) 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
32#define	VATOPA(reg)							\
33	bic	reg, reg, #0xff000000	/* clear upper 8 bits */	;\
34	orr	reg, reg, #0xa0000000	/* OR in physical base address */
35
36	.text
37	.align	0
38/*
39 * void
40 * kloader_pxa2x0_boot(struct kloader_bootinfo *kbi,
41 *                     struct kloader_page_tag *tag)
42 *
43 * r0: kbi, r1: tag
44 */
45	.global	_C_LABEL(kloader_pxa2x0_boot)
46_C_LABEL(kloader_pxa2x0_boot):
47	mov	lr, r0			/* lr: kbi */
48	VATOPA(lr)
49
50	/* We will go ahead and disable the MMU here. */
51	adr	r8, .Lmmuoff
52	VATOPA(r8)
53
54	mrc	p15, 0, r2, c1, c0, 0
55	bic	r2, r2, #CPU_CONTROL_MMU_ENABLE
56	bic	r2, r2, #CPU_CONTROL_DC_ENABLE
57	bic	r2, r2, #CPU_CONTROL_IC_ENABLE
58	mcr	p15, 0, r2, c1, c0, 0
59
60	nop
61	nop
62	nop
63
64	mov	pc, r8			/* Heave-ho! */
65
66	.align	0
67.Lmmuoff:
68	nop
69	nop
70	nop
71
72	/* Load kernel image */
73	mov	r4, r1		/* tag */
741:	mov	r3, r4
75	cmp	r3, #0		/* tag == NULL */
76	beq	3f
77	VATOPA(r3)
78	ldmia	r3, {r4-r7}	/* r4: next, r5: src, r6: dst, r7: sz */
79	VATOPA(r5)
80	VATOPA(r6)
81	add	r8, r6, r7	/* r8: dst + sz */
822:	ldr	r9, [r5], #4	/* copy */
83	str	r9, [r6], #4
84	cmp	r8, r6
85	bne	2b
86	b	1b
87
883:
89	/* Set temporary stack pointer */
90	ldr	sp, .Lstack_addr
91
92	/* Jump to kernel entry */
93	mov	r3, lr			/* r3: kbi */
94	ldr	lr, [r3]		/* kbi->entry */
95	VATOPA(lr)
96	ldr	r0, [r3, #4]		/* kbi->argc */
97	ldr	r1, [r3, #8]		/* kbi->argv */
98	add	r2, r3, #12		/* &kbi->bootinfo */
99
100	/* Fixup argv[] */
101	cmp	r1, #0			/* argv == NULL */
102	beq	5f
103	VATOPA(r1)
104	cmp	r0, #0			/* argc == 0 */
105	beq	5f
106
107	mov	r3, r0
108	mov	r4, r1
1094:	ldr	r5, [r4]
110	VATOPA(r5)
111	str	r5, [r4], #4
112	subs	r3, r3, #1
113	bgt	4b
114
1155:	/* Jump! */
116	mov	pc, lr
117
11899:	b	99b
119
120.Lstack_addr:
121	.word	0xa0004000
122