xref: /netbsd-src/sys/arch/dreamcast/dreamcast/kloader_machdep.c (revision ce099b40997c43048fb78bd578195f81d2456523)
1 /*	$NetBSD: kloader_machdep.c,v 1.5 2008/04/28 20:23:16 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001, 2002, 2004 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  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: kloader_machdep.c,v 1.5 2008/04/28 20:23:16 martin Exp $");
31 
32 #include "debug_kloader.h"
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 
37 #include <sh3/mmu.h>
38 #include <sh3/mmu_sh4.h>
39 #include <sh3/cache.h>
40 #include <sh3/cache_sh4.h>
41 
42 #include <machine/kloader.h>
43 
44 kloader_jumpfunc_t kloader_dreamcast_jump;
45 kloader_bootfunc_t kloader_dreamcast_boot;
46 
47 struct kloader_ops kloader_dreamcast_ops = {
48 	.jump = kloader_dreamcast_jump,
49 	.boot = kloader_dreamcast_boot,
50 };
51 
52 void
kloader_reboot_setup(const char * filename)53 kloader_reboot_setup(const char *filename)
54 {
55 
56 	__kloader_reboot_setup(&kloader_dreamcast_ops, filename);
57 }
58 
59 void
kloader_dreamcast_jump(kloader_bootfunc_t func,vaddr_t sp,struct kloader_bootinfo * info,struct kloader_page_tag * tag)60 kloader_dreamcast_jump(kloader_bootfunc_t func, vaddr_t sp,
61     struct kloader_bootinfo *info, struct kloader_page_tag *tag)
62 {
63 
64 	sh_icache_sync_all();	/* also flush d-cache */
65 
66 	__asm volatile(
67 	    	"mov	%0, r4;"
68 		"mov	%1, r5;"
69 		"jmp	@%2;"
70 		"mov	%3, sp"
71 		: : "r"(info), "r"(tag), "r"(func), "r"(sp));
72 	/* NOTREACHED */
73 }
74 
75 /*
76  * 2nd-bootloader. Make sure that PIC and its size is lower than page size.
77  */
78 void
kloader_dreamcast_boot(struct kloader_bootinfo * kbi,struct kloader_page_tag * p)79 kloader_dreamcast_boot(struct kloader_bootinfo *kbi, struct kloader_page_tag *p)
80 {
81 	int tmp = 0;
82 
83 	/* Disable interrupt. block exception. */
84 	__asm volatile(
85 		"stc	sr, %1;"
86 		"or	%0, %1;"
87 		"ldc	%1, sr" : : "r"(0x500000f0), "r"(tmp));
88 
89 	/* Now I run on P1, TLB flush. and disable. */
90 	SH4_TLB_DISABLE;
91 
92 	do {
93 		uint32_t *dst =(uint32_t *)p->dst;
94 		uint32_t *src =(uint32_t *)p->src;
95 		uint32_t sz = p->sz / sizeof (int);
96 		while (sz--)
97 			*dst++ = *src++;
98 	} while ((p = (struct kloader_page_tag *)p->next) != 0);
99 
100 	SH7750_CACHE_FLUSH();
101 
102 	/* jump to kernel entry. */
103 	__asm volatile(
104 		"jmp	@%0;"
105 		"nop;"
106 		: : "r"(kbi->entry));
107 	/* NOTREACHED */
108 }
109