blob: e12982faca669ec167659388a6e1fc1ea60e4963 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2015 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <trace.h>
24#include <debug.h>
25#include <stdint.h>
26#include <bits.h>
27#include <arch/mips.h>
28#include <platform.h>
29
30#define LOCAL_TRACE 0
31
32void arch_early_init(void)
33{
34 LTRACE;
35
36 /* configure the vector table */
37 uint32_t temp = mips_read_c0_status();
38 temp &= ~(1<<22); /* unset BEV, which moves vectors to 0x80000000 */
39 temp &= ~(1<<2); /* clear ERL */
40
41 /* mask all of the irq handlers */
42 temp &= ~(1<<8); // IM0
43 temp &= ~(1<<9); // IM1
44 temp &= ~(1<<10); // IM2
45 temp &= ~(1<<11); // IM3
46 temp &= ~(1<<12); // IM4
47 temp &= ~(1<<13); // IM5
48 temp &= ~(1<<14); // IM6
49 temp &= ~(1<<15); // IM7
50 temp &= ~(1<<16); // IM8
51 temp &= ~(1<<18); // IM9 (note the bit gap)
52
53 mips_write_c0_status(temp);
54
55 /* set ebase */
56 mips_write_c0_ebase(MEMBASE);
57
58 /* make sure we take exceptions in 32bit mips mode */
59 mips_write_c0_config3(mips_read_c0_config3() & ~(1<<16));
60
61 /* set vectored mode */
62 temp = mips_read_c0_intctl();
63 temp &= ~(0b1111 << 5);
64 temp |= 1 << 5; /* 32 byte spacing */
65 STATIC_ASSERT(VECTORED_OFFSET_SHIFT == 32);
66
67 mips_write_c0_intctl(temp);
68
69 temp = mips_read_c0_cause();
70 temp |= (1<<23); /* IV vectored mode */
71 mips_write_c0_cause(temp);
72}
73
74void arch_init(void)
75{
76 LTRACE;
77
78 printf("MIPS registers:\n");
79 printf("\tPRId 0x%x\n", mips_read_c0_prid());
80 printf("\tconfig 0x%x\n", mips_read_c0_config());
81 printf("\tconfig1 0x%x\n", mips_read_c0_config1());
82 printf("\tconfig2 0x%x\n", mips_read_c0_config2());
83 printf("\tconfig3 0x%x\n", mips_read_c0_config3());
84 printf("\tconfig4 0x%x\n", mips_read_c0_config4());
85 printf("\tconfig5 0x%x\n", mips_read_c0_config5());
86 printf("\tconfig6 0x%x\n", mips_read_c0_config6());
87 printf("\tconfig7 0x%x\n", mips_read_c0_config7());
88 printf("\tstatus 0x%x\n", mips_read_c0_status());
89 uint32_t intctl = mips_read_c0_intctl();
90 printf("\tintctl 0x%x\n", intctl);
91 printf("\t\tIPTI 0x%lx\n", BITS_SHIFT(intctl, 31, 29));
92 printf("\t\tIPPCI 0x%lx\n", BITS_SHIFT(intctl, 28, 26));
93 printf("\t\tIPFDC 0x%lx\n", BITS_SHIFT(intctl, 25, 23));
94 printf("\tsrsctl 0x%x\n", mips_read_c0_srsctl());
95 printf("\tebase 0x%x\n", mips_read_c0_ebase());
96 printf("\tcount 0x%x\n", mips_read_c0_count());
97 printf("\tcompare 0x%x\n", mips_read_c0_compare());
98
99 __asm__ volatile("syscall");
100
101 LTRACE_EXIT;
102}
103
104void arch_idle(void)
105{
106 asm volatile("wait");
107}
108
109void arch_chain_load(void *entry, ulong arg0, ulong arg1, ulong arg2, ulong arg3)
110{
111 PANIC_UNIMPLEMENTED;
112}
113
114void mips_enable_irq(uint num)
115{
116 uint32_t temp = mips_read_c0_status();
117 if (num < 9) {
118 temp |= (1 << (num + 8));
119 } else if (num == 9) {
120 temp |= (1 << 18);
121 }
122 mips_write_c0_status(temp);
123}
124
125void mips_disable_irq(uint num)
126{
127 uint32_t temp = mips_read_c0_status();
128 if (num < 9) {
129 temp &= ~(1 << (num + 8));
130 } else if (num == 9) {
131 temp &= ~(1 << 18);
132 }
133 mips_write_c0_status(temp);
134}
135
136/* unimplemented cache operations */
137void arch_disable_cache(uint flags) { PANIC_UNIMPLEMENTED; }
138void arch_enable_cache(uint flags) { PANIC_UNIMPLEMENTED; }
139
140void arch_clean_cache_range(addr_t start, size_t len) { PANIC_UNIMPLEMENTED; }
141void arch_clean_invalidate_cache_range(addr_t start, size_t len) { PANIC_UNIMPLEMENTED; }
142void arch_invalidate_cache_range(addr_t start, size_t len) { PANIC_UNIMPLEMENTED; }
143void arch_sync_cache_range(addr_t start, size_t len) { PANIC_UNIMPLEMENTED; }