xref: /netbsd/sys/arch/hpcsh/hpcsh/kloader_machdep.c (revision bf9ec67e)
1 /*	$NetBSD: kloader_machdep.c,v 1.6 2002/05/09 12:37:59 uch Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
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  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *        This product includes software developed by the NetBSD
18  *        Foundation, Inc. and its contributors.
19  * 4. Neither the name of The NetBSD Foundation nor the names of its
20  *    contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 
39 #include <sh3/mmu.h>
40 #include <sh3/mmu_sh3.h>
41 #include <sh3/mmu_sh4.h>
42 #include <sh3/cache.h>
43 #include <sh3/cache_sh3.h>
44 #include <sh3/cache_sh4.h>
45 
46 #include <machine/kloader.h>
47 
48 /*
49  * 2nd-bootloader. Make sure that PIC and its size is lower than page size.
50  */
51 #define KLOADER_SH_BOOT(cpu, product)					\
52 void									\
53 kloader_sh ## cpu ## _boot(struct kloader_bootinfo *kbi,		\
54     struct kloader_page_tag *p)						\
55 {									\
56 	int tmp;							\
57 									\
58 	/* Disable interrupt. block exception. */			\
59 	__asm__ __volatile__(						\
60 		"stc	sr, %1;"					\
61 		"or	%0, %1;"					\
62 		"ldc	%1, sr" : : "r"(0x500000f0), "r"(tmp));		\
63 									\
64 	/* Now I run on P1, TLB flush. and disable. */			\
65 	SH ## cpu ## _TLB_DISABLE;					\
66 									\
67 	do {								\
68 		u_int32_t *dst =(u_int32_t *)p->dst;			\
69 		u_int32_t *src =(u_int32_t *)p->src;			\
70 		u_int32_t sz = p->sz / sizeof (int);			\
71 		while (sz--)						\
72 			*dst++ = *src++;				\
73 	} while ((p = (struct kloader_page_tag *)p->next) != 0);	\
74 									\
75 	SH ## product ## _CACHE_FLUSH();				\
76 									\
77 	/* jump to kernel entry. */					\
78 	__asm__ __volatile__(						\
79 		"mov	%0, r4;"					\
80 		"mov	%1, r5;"					\
81 		"jmp	@%3;"						\
82 		"mov	%2, r6;"					\
83 		: :							\
84 		"r"(kbi->argc),						\
85 		"r"(kbi->argv),						\
86 		"r"(&kbi->bootinfo),					\
87 		"r"(kbi->entry));					\
88 	/* NOTREACHED */						\
89 }
90 
91 void kloader_sh_jump(kloader_bootfunc_t *, vaddr_t,
92     struct kloader_bootinfo *, struct kloader_page_tag *);
93 kloader_bootfunc_t kloader_sh3_boot;
94 kloader_bootfunc_t kloader_sh4_boot;
95 
96 struct kloader_ops kloader_sh_ops = {
97 	.jump = kloader_sh_jump,
98 	.boot = 0
99 };
100 
101 void
102 kloader_reboot_setup(const char *filename)
103 {
104 
105 	kloader_sh_ops.boot = CPU_IS_SH3 ? kloader_sh3_boot : kloader_sh4_boot;
106 
107 	__kloader_reboot_setup(&kloader_sh_ops, filename);
108 }
109 
110 void
111 kloader_sh_jump(kloader_bootfunc_t func, vaddr_t sp,
112     struct kloader_bootinfo *info, struct kloader_page_tag *tag)
113 {
114 
115 	sh_icache_sync_all();	/* also flush d-cache */
116 
117 	__asm__ __volatile__(
118 	    	"mov	%0, r4;"
119 		"mov	%1, r5;"
120 		"jmp	@%2;"
121 		"mov	%3, sp"
122 		: : "r"(info), "r"(tag), "r"(func), "r"(sp));
123 	/* NOTREACHED */
124 }
125 
126 #ifdef SH3
127 KLOADER_SH_BOOT(3, 7709A)
128 #endif
129 #ifdef SH4
130 KLOADER_SH_BOOT(4, 7750)
131 #endif
132