summaryrefslogtreecommitdiff
path: root/sys/arch/hpc/stand/hpcboot/mips/mips_arch.cpp
blob: 0611ac1416384d40590c7b4aa2dcea266dd55991 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* -*-C++-*-	$NetBSD: mips_arch.cpp,v 1.7 2008/04/28 20:23:20 martin Exp $	*/

/*-
 * Copyright (c) 2001 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
#undef DEBUG_KERNADDR_ACCESS
#undef DEBUG_CP0_ACCESS

#include <hpcboot.h>
#include <mips/mips_arch.h>
#include <console.h>
#include <memory.h>

MIPSArchitecture::MIPSArchitecture(Console *&cons, MemoryManager *&mem)
	: Architecture(cons, mem)
{
	/* NO-OP */
}

MIPSArchitecture::~MIPSArchitecture(void)
{
	/* NO-OP */
}

void
MIPSArchitecture::systemInfo()
{
	uint32_t r0, r1;
	Architecture::systemInfo();
	r0 = r1 = 0;

#ifdef DEBUG_CP0_ACCESS
	/* CP0 access test */
	_kmode = SetKMode(1);

	DPRINTF((TEXT("status register test\n")));
	GET_SR(r0);
	DPRINTF((TEXT("current value: 0x%08x\n"), r0));
	SET_SR(r1);
	GET_SR(r1);
	DPRINTF((TEXT("write test:    0x%08x\n"), r1));
	SET_SR(r0);

	SetKMode(_kmode);
#endif // DEBUG_CP0_ACCESS
}

BOOL
MIPSArchitecture::init()
{
	if (!_mem->init()) {
		DPRINTF((TEXT("can't initialize memory manager.\n")));
		return FALSE;
	}

	return TRUE;
}

BOOL
MIPSArchitecture::setupLoader()
{
	vaddr_t v;

#ifdef DEBUG_KERNADDR_ACCESS // kernel address access test
#define	TEST_MAGIC		0xac1dcafe
	paddr_t p;
	uint32_t r0;

	_kmode = SetKMode(1);
	_mem->getPage(v, p);
	VOLATILE_REF(ptokv(p)) = TEST_MAGIC;
	cacheFlush();
	r0 = VOLATILE_REF(v);
	DPRINTF((TEXT("kernel address access test: %S\n"),
	    r0 == TEST_MAGIC ? "OK" : "NG"));
	SetKMode(_kmode);
#endif // DEBUG_KERNADDR_ACCESS

	if (!_mem->getPage(v , _loader_addr)) {
		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
		return FALSE;
	}
	DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
	    (unsigned)v,(unsigned)_loader_addr));

	memcpy(LPVOID(v), LPVOID(_boot_func), _mem->getPageSize());
	DPRINTF((TEXT("2nd bootloader copy done.\n")));

	return TRUE;
}

void
MIPSArchitecture::jump(paddr_t info, paddr_t pvec)
{
	kaddr_t sp;
	vaddr_t v;
	paddr_t p;

	// stack for bootloader(but mips loader don't use stack)
	_mem->getPage(v, p);
	sp = ptokv(p + _mem->getPageSize() - 0x10);

	info = ptokv(info);
	pvec = ptokv(pvec);
	_loader_addr = ptokv(_loader_addr);

	// switch kernel mode.
	SetKMode(1);
	if (SetKMode(1) != 1) {
		DPRINTF((TEXT("SetKMode(1) failed.\n")));
		return;
	}
	DPRINTF((TEXT("jump to 0x%08x (info=0x%08x, pvec=0x%08x)\n"),
	    _loader_addr, info, pvec));

	// writeback whole D-cache and invalidate whole I-cache.
	// 2nd boot-loader access data via kseg0 which were writed via kuseg,
	cacheFlush();

	// jump to 2nd-loader(run kseg0)
	__asm(".set noreorder;"
	    "jr	a3;"
	    "move	sp, a2;"
	    ".set reorder", info, pvec, sp, _loader_addr);
	// NOTREACHED
}