Makefile.am |
24 | 24 | junk = mdebug.abi32 reginfo comment pdr note.gnu.build-id |
25 | 25 | objcopyflags = -S $(addprefix --remove-section=.,$(junk)) |
26 | 26 | |
27 | | start_load = 0x80400000 |
| 27 | start_load = 0x80003000 |
28 | 28 | load = 0x80000000 |
29 | 29 | |
30 | 30 | noinst_DATA = iris.raw mips/start.raw mips/start-hack.S mips/nanonote/sdram-setup.raw |
... | ... | |
38 | 38 | boot_threads = udc |
39 | 39 | else |
40 | 40 | if UNBRICK |
41 | | boot_threads = nand sdmmc usbmassstorage |
| 41 | boot_threads = sdmmc usbmassstorage |
42 | 42 | else |
43 | 43 | boot_threads = sdmmc partition fat |
| 44 | noinst_DATA += iris.tar.gz |
44 | 45 | endif |
45 | 46 | endif |
46 | 47 | |
... | ... | |
67 | 68 | mips_nanonote_sdram_setup_elf_SOURCES = mips/nanonote/sdram-setup.cc |
68 | 69 | |
69 | 70 | program_targets = \ |
| 71 | source/alarm.elf \ |
| 72 | source/ball.elf \ |
| 73 | source/boot.elf \ |
| 74 | source/booter.elf \ |
| 75 | source/bootinit.elf \ |
| 76 | source/bsquare.elf \ |
| 77 | source/buzzer.elf \ |
| 78 | source/elfrun.elf \ |
| 79 | source/fat.elf \ |
| 80 | source/font.elf \ |
| 81 | source/gpio.elf \ |
| 82 | source/gui.elf \ |
| 83 | source/init.elf \ |
| 84 | source/lcd.elf \ |
| 85 | source/metronome.elf \ |
| 86 | source/nand.elf \ |
| 87 | source/partition.elf \ |
| 88 | source/rtc.elf \ |
| 89 | source/sdmmc.elf \ |
| 90 | source/test.elf \ |
| 91 | source/udc.elf \ |
| 92 | source/usbmassstorage.elf |
| 93 | |
| 94 | fs_targets = \ |
70 | 95 | fs/alarm.elf \ |
71 | 96 | fs/ball.elf \ |
72 | 97 | fs/boot.elf \ |
... | ... | |
91 | 116 | fs/usbmassstorage.elf |
92 | 117 | |
93 | 118 | noinst_PROGRAMS += $(program_targets) |
| 119 | noinst_DATA += $(fs_targets) |
94 | 120 | AM_CPPFLAGS = -O5 -fno-inline -I. -I./mips -I./mips/nanonote -Wa,-mips32 -DNANONOTE |
95 | 121 | AM_CXXFLAGS = -Wno-unused-parameter -fno-strict-aliasing -fno-builtin -ggdb3 |
96 | 122 | AM_LDFLAGS = -nostdlib |
... | ... | |
113 | 139 | fs/%: % |
114 | 140 | ln -s ../$< $@ |
115 | 141 | |
116 | | fs_alarm_elf_SOURCES = source/crt0.cc source/alarm.cc ${headers} |
117 | | fs_ball_elf_SOURCES = source/crt0.cc source/ball.cc ${headers} |
118 | | fs_boot_elf_SOURCES = source/crt0.cc source/boot.cc ${headers} |
119 | | fs_booter_elf_SOURCES = source/crt0.cc source/booter.cc ${headers} |
120 | | fs_bootinit_elf_SOURCES = source/crt0.cc source/bootinit.cc ${headers} |
121 | | fs_bsquare_elf_SOURCES = source/crt0.cc source/bsquare.cc ${headers} |
122 | | fs_buzzer_elf_SOURCES = source/crt0.cc source/buzzer.cc ${headers} |
123 | | fs_elfrun_elf_SOURCES = source/crt0.cc source/elfrun.cc ${headers} |
124 | | fs_fat_elf_SOURCES = source/crt0.cc source/fat.cc ${headers} |
125 | | fs_font_elf_SOURCES = source/crt0.cc source/font.cc ${headers} |
126 | | fs_gpio_elf_SOURCES = source/crt0.cc source/gpio.cc ${headers} |
127 | | fs_gui_elf_SOURCES = source/crt0.cc source/gui.cc ${headers} |
128 | | fs_init_elf_SOURCES = source/crt0.cc source/init.cc ${headers} |
129 | | fs_lcd_elf_SOURCES = source/crt0.cc source/lcd.cc ${headers} |
130 | | fs_metronome_elf_SOURCES = source/crt0.cc source/metronome.cc ${headers} |
131 | | fs_nand_elf_SOURCES = source/crt0.cc source/nand.cc ${headers} |
132 | | fs_partition_elf_SOURCES = source/crt0.cc source/partition.cc ${headers} |
133 | | fs_rtc_elf_SOURCES = source/crt0.cc source/rtc.cc ${headers} |
134 | | fs_sdmmc_elf_SOURCES = source/crt0.cc source/sdmmc.cc ${headers} |
135 | | fs_test_elf_SOURCES = source/crt0.cc source/test.cc ${headers} |
136 | | fs_udc_elf_SOURCES = source/crt0.cc source/udc.cc ${headers} |
137 | | fs_usbmassstorage_elf_SOURCES = source/crt0.cc source/usbmassstorage.cc ${headers} |
| 142 | fs/%.elf: source/%.elf |
| 143 | $(OBJCOPY) -S $< $@ |
| 144 | |
| 145 | source_alarm_elf_SOURCES = source/crt0.cc source/alarm.cc ${headers} |
| 146 | source_ball_elf_SOURCES = source/crt0.cc source/ball.cc ${headers} |
| 147 | source_boot_elf_SOURCES = source/crt0.cc source/boot.cc ${headers} |
| 148 | source_booter_elf_SOURCES = source/crt0.cc source/booter.cc ${headers} |
| 149 | source_bootinit_elf_SOURCES = source/crt0.cc source/bootinit.cc ${headers} |
| 150 | source_bsquare_elf_SOURCES = source/crt0.cc source/bsquare.cc ${headers} |
| 151 | source_buzzer_elf_SOURCES = source/crt0.cc source/buzzer.cc ${headers} |
| 152 | source_elfrun_elf_SOURCES = source/crt0.cc source/elfrun.cc ${headers} |
| 153 | source_fat_elf_SOURCES = source/crt0.cc source/fat.cc ${headers} |
| 154 | source_font_elf_SOURCES = source/crt0.cc source/font.cc ${headers} |
| 155 | source_gpio_elf_SOURCES = source/crt0.cc source/gpio.cc ${headers} |
| 156 | source_gui_elf_SOURCES = source/crt0.cc source/gui.cc ${headers} |
| 157 | source_init_elf_SOURCES = source/crt0.cc source/init.cc ${headers} |
| 158 | source_lcd_elf_SOURCES = source/crt0.cc source/lcd.cc ${headers} |
| 159 | source_metronome_elf_SOURCES = source/crt0.cc source/metronome.cc ${headers} |
| 160 | source_nand_elf_SOURCES = source/crt0.cc source/nand.cc ${headers} |
| 161 | source_partition_elf_SOURCES = source/crt0.cc source/partition.cc ${headers} |
| 162 | source_rtc_elf_SOURCES = source/crt0.cc source/rtc.cc ${headers} |
| 163 | source_sdmmc_elf_SOURCES = source/crt0.cc source/sdmmc.cc ${headers} |
| 164 | source_test_elf_SOURCES = source/crt0.cc source/test.cc ${headers} |
| 165 | source_udc_elf_SOURCES = source/crt0.cc source/udc.cc ${headers} |
| 166 | source_usbmassstorage_elf_SOURCES = source/crt0.cc source/usbmassstorage.cc ${headers} |
138 | 167 | |
139 | 168 | server: |
140 | 169 | test -e native/Makefile || native/autogen.sh |
... | ... | |
146 | 175 | native/usb-server |
147 | 176 | echo 'reboot $(start_load) 0x$(shell /bin/sh -c '$(OBJDUMP) -t mips/start.elf | grep __start$$ | cut -b1-8') mips/start.raw' | nc localhost 5050 |
148 | 177 | |
| 178 | # SD boot stuff |
| 179 | iris.tar.gz: mips/start.raw.gz mips/start.elf $(fs_targets) fs/init.config fs/font.dat |
| 180 | test -d fs/boot || mkdir fs/boot |
| 181 | mkimage -A mips -T kernel -a $(start_load) -e $(shell /bin/sh -c '$(OBJDUMP) -t mips/start.elf | grep __start$$ | cut -b1-8') -n Iris -d mips/start.raw.gz fs/boot/uImage | sed -e 's/:/;/g' |
| 182 | cd fs && tar czvf ../$@ --dereference * |
| 183 | %.gz: % |
| 184 | gzip < $< > $@ |
| 185 | |
149 | 186 | sources = \ |
150 | 187 | source/alarm.cc \ |
151 | 188 | source/ball.cc \ |
... | ... | |
170 | 207 | source/udc.cc \ |
171 | 208 | source/usbmassstorage.cc |
172 | 209 | |
| 210 | debug: |
| 211 | stty -F $(SERIAL) 57600 raw |
| 212 | cat $(SERIAL) |
| 213 | |
173 | 214 | autoclean: maintainer-clean |
174 | 215 | $(MAKE) -C native autoclean |
175 | 216 | rm -rf aclocal.m4 configure depcomp fs install-sh iris.raw iris-sd.tar Makefile.in missing $(iris_sources) $(boot_sources) $(sources) $(headers) mips/start-hack.S mips/start.raw |
mips/entry.S |
32 | 32 | addr_000: |
33 | 33 | #if 0 |
34 | 34 | // TLB refill |
35 | | bne $zero, $k1, slow_refill |
36 | | nop |
37 | | bne $zero, $k0, slow_refill |
38 | | lw $k1, -0xd94($zero) |
| 35 | lui $k0, 0x8000 |
| 36 | lw $k1, 0x174($k0) // directory |
39 | 37 | mfc0 $k0, $CP0_ENTRY_HI |
40 | 38 | srl $k0, $k0, 19 |
41 | | and $k0, $k0, 0x3fc |
| 39 | and $k0, $k0, 0xffc |
42 | 40 | addu $k0, $k0, $k1 |
43 | 41 | beq $zero, $k0, zero_refill |
44 | 42 | lw $k0, 0($k0) |
45 | 43 | mfc0 $k1, $CP0_ENTRY_HI |
46 | 44 | srl $k1, $k1, 10 |
47 | | and $k1, $k1, 0x1f8 |
| 45 | and $k1, $k1, 0xff8 |
48 | 46 | add $k0, $k0, $k1 |
49 | 47 | lw $k1, 0($k0) |
50 | 48 | mtc0 $k1, $CP0_ENTRY_LO0 |
51 | 49 | lw $k1, 4($k0) |
52 | 50 | mtc0 $k1, $CP0_ENTRY_LO1 |
53 | 51 | 1: tlbwr |
54 | | move $zero, $k0 |
55 | | move $zero, $k1 |
| 52 | move $k0, $zero |
| 53 | move $k1, $zero |
56 | 54 | eret |
57 | 55 | |
58 | 56 | zero_refill: |
59 | | mtc0 $zero, $CP_ENTRY_LO0 |
| 57 | mtc0 $zero, $CP0_ENTRY_LO0 |
60 | 58 | b 1b |
61 | | mtc0 $zero, $CP_ENTRY_LO1 |
62 | | |
63 | | slow_refill: |
64 | | move $k1, $zero |
65 | | #endif |
66 | | sw $ra, -0xd88($zero) |
| 59 | mtc0 $zero, $CP0_ENTRY_LO1 |
| 60 | #else |
| 61 | // Slow refill: use C code (which calls kdebug etc) |
| 62 | move $k1, $ra |
67 | 63 | bal save_regs |
68 | 64 | nop |
69 | 65 | la $t9, tlb_refill |
70 | 66 | jr $t9 |
71 | 67 | nop |
| 68 | #endif |
72 | 69 | .fill 0x100 - (. - addr_000) |
73 | 70 | addr_100: |
74 | 71 | // Cache error |
75 | | sw $ra, -0xd88($zero) |
| 72 | move $k1, $ra |
76 | 73 | bal save_regs |
77 | 74 | nop |
78 | 75 | la $t9, cache_error |
79 | 76 | jr $t9 |
80 | 77 | nop |
81 | | .fill 0x180 - (. - addr_000) |
| 78 | .fill 0x180 - (. - addr_000) - 3 * 4 |
| 79 | |
| 80 | directory: // 0x174 |
| 81 | .word 0 |
| 82 | current: // 0x178 |
| 83 | .word idle |
| 84 | // 0x17c |
| 85 | .word _gp |
| 86 | |
82 | 87 | addr_180: |
83 | 88 | // General exception |
84 | | sw $ra, -0xd88($zero) |
| 89 | move $k1, $ra |
85 | 90 | bal save_regs |
86 | 91 | nop |
87 | 92 | la $t9, exception |
88 | 93 | jr $t9 |
89 | 94 | nop |
90 | | .fill 0x200 - (. - addr_000) - 8 |
91 | | .word 0x0000001e // 1f8 EntryLo data for idle page. |
| 95 | // This is annoying; it must fill it up so addr_200 is right. For some |
| 96 | // reason .fill 0x200 - (. - addr_000) - 2 * 4 doesn't work here. |
| 97 | .fill 0x60 |
| 98 | .word 0x00000012 // 1f8 EntryLo data for idle page. |
92 | 99 | .word 0x80000000 // 1fc A pointer to the current page. |
93 | 100 | addr_200: |
94 | 101 | // Interrupt |
95 | | sw $ra, -0xd88($zero) |
| 102 | move $k1, $ra |
96 | 103 | bal save_regs |
97 | 104 | nop |
98 | 105 | la $t9, interrupt |
99 | 106 | jr $t9 |
100 | 107 | nop |
101 | | .fill 0x280 - (. - addr_000) - 20 |
102 | | |
103 | | directory: |
104 | | .word 0 // -d94 == directory |
105 | | // space for save_regs |
106 | | .word 0 // -d90 == k0 |
107 | | .word idle // -d8c == current |
108 | | .word 0 // -d88 == ra |
109 | | .word _gp // -d84 == gp |
| 108 | .fill 0x280 - (. - addr_000) |
110 | 109 | |
111 | 110 | start_idle: // 280 |
112 | 111 | // Wait for the next interrupt, then the first thread will be scheduled. |
... | ... | |
118 | 117 | |
119 | 118 | // TODO: save only fragile registers now, the rest on task switch. |
120 | 119 | kernel_exit: |
| 120 | move $k0, $v0 |
| 121 | lui $k1, 0x8000 |
| 122 | sw $v0, 0x178($k1) // current |
| 123 | lw $k1, SAVE_PC($k0) |
| 124 | mtc0 $k1, $CP0_EPC |
| 125 | lw $k1, SAVE_LO($k0) |
| 126 | mtlo $k1 |
| 127 | lw $k1, SAVE_HI($k0) |
| 128 | mthi $k1 |
| 129 | lw $v0, SAVE_V + 0 * 4($k0) |
| 130 | lw $v1, SAVE_V + 1 * 4($k0) |
| 131 | lw $a0, SAVE_A + 0 * 4($k0) |
| 132 | lw $a1, SAVE_A + 1 * 4($k0) |
| 133 | lw $a2, SAVE_A + 2 * 4($k0) |
| 134 | lw $a3, SAVE_A + 3 * 4($k0) |
| 135 | lw $t0, SAVE_T + 0 * 4($k0) |
| 136 | lw $t1, SAVE_T + 1 * 4($k0) |
| 137 | lw $t2, SAVE_T + 2 * 4($k0) |
| 138 | lw $t3, SAVE_T + 3 * 4($k0) |
| 139 | lw $t4, SAVE_T + 4 * 4($k0) |
| 140 | lw $t5, SAVE_T + 5 * 4($k0) |
| 141 | lw $t6, SAVE_T + 6 * 4($k0) |
| 142 | lw $t7, SAVE_T + 7 * 4($k0) |
| 143 | lw $t8, SAVE_T + 8 * 4($k0) |
| 144 | lw $t9, SAVE_T + 9 * 4($k0) |
| 145 | lw $s0, SAVE_S + 0 * 4($k0) |
| 146 | lw $s1, SAVE_S + 1 * 4($k0) |
| 147 | lw $s2, SAVE_S + 2 * 4($k0) |
| 148 | lw $s3, SAVE_S + 3 * 4($k0) |
| 149 | lw $s4, SAVE_S + 4 * 4($k0) |
| 150 | lw $s5, SAVE_S + 5 * 4($k0) |
| 151 | lw $s6, SAVE_S + 6 * 4($k0) |
| 152 | lw $s7, SAVE_S + 7 * 4($k0) |
| 153 | lw $fp, SAVE_FP($k0) |
| 154 | lw $at, SAVE_AT($k0) |
| 155 | lw $sp, SAVE_SP($k0) |
| 156 | lw $gp, SAVE_GP($k0) |
| 157 | lw $ra, SAVE_RA($k0) |
121 | 158 | #ifndef NDEBUG |
122 | 159 | // Exceptions were enabled in the kernel; set them to usermode setting again. |
123 | | mfc0 $k0, $CP0_STATUS |
124 | | ori $k0, $k0, 0xff13 |
125 | | mtc0 $k0, $CP0_STATUS |
| 160 | mfc0 $k1, $CP0_STATUS |
| 161 | ori $k1, $k1, 0xff13 |
| 162 | mtc0 $k1, $CP0_STATUS |
126 | 163 | #endif |
127 | | sw $v0, -0xd8c($zero) |
128 | | lw $k0, SAVE_PC($v0) |
129 | | mtc0 $k0, $CP0_EPC |
130 | | lw $k0, SAVE_LO($v0) |
131 | | lw $k1, SAVE_HI($v0) |
132 | | mtlo $k0 |
133 | | mthi $k1 |
134 | | lw $v1, SAVE_V + 1 * 4($v0) |
135 | | lw $a0, SAVE_A + 0 * 4($v0) |
136 | | lw $a1, SAVE_A + 1 * 4($v0) |
137 | | lw $a2, SAVE_A + 2 * 4($v0) |
138 | | lw $a3, SAVE_A + 3 * 4($v0) |
139 | | lw $t0, SAVE_T + 0 * 4($v0) |
140 | | lw $t1, SAVE_T + 1 * 4($v0) |
141 | | lw $t2, SAVE_T + 2 * 4($v0) |
142 | | lw $t3, SAVE_T + 3 * 4($v0) |
143 | | lw $t4, SAVE_T + 4 * 4($v0) |
144 | | lw $t5, SAVE_T + 5 * 4($v0) |
145 | | lw $t6, SAVE_T + 6 * 4($v0) |
146 | | lw $t7, SAVE_T + 7 * 4($v0) |
147 | | lw $t8, SAVE_T + 8 * 4($v0) |
148 | | lw $t9, SAVE_T + 9 * 4($v0) |
149 | | lw $s0, SAVE_S + 0 * 4($v0) |
150 | | lw $s1, SAVE_S + 1 * 4($v0) |
151 | | lw $s2, SAVE_S + 2 * 4($v0) |
152 | | lw $s3, SAVE_S + 3 * 4($v0) |
153 | | lw $s4, SAVE_S + 4 * 4($v0) |
154 | | lw $s5, SAVE_S + 5 * 4($v0) |
155 | | lw $s6, SAVE_S + 6 * 4($v0) |
156 | | lw $s7, SAVE_S + 7 * 4($v0) |
157 | | lw $fp, SAVE_FP($v0) |
158 | | lw $ra, SAVE_RA($v0) |
159 | | lw $at, SAVE_AT($v0) |
160 | | lw $k0, SAVE_K + 0 * 4($v0) |
161 | | lw $k1, SAVE_V + 0 * 4($v0) |
162 | | sw $k1, -0xd90($zero) |
163 | | lw $k1, SAVE_K + 1 * 4($v0) |
164 | | lw $sp, SAVE_SP($v0) |
165 | | lw $gp, SAVE_GP($v0) |
166 | | lw $v0, -0xd90($zero) |
| 164 | move $k0, $zero |
| 165 | move $k1, $zero |
167 | 166 | eret |
168 | 167 | |
169 | 168 | save_regs: |
170 | | sw $k0, -0xd90($zero) |
171 | | lw $k0, -0xd8c($zero) |
| 169 | lui $k0, 0x8000 |
| 170 | lw $k0, 0x178($k0) // current |
172 | 171 | |
173 | | sw $at, SAVE_AT($k0) |
| 172 | sw $k1, SAVE_RA($k0) |
174 | 173 | sw $gp, SAVE_GP($k0) |
175 | 174 | sw $sp, SAVE_SP($k0) |
| 175 | sw $at, SAVE_AT($k0) |
176 | 176 | sw $fp, SAVE_FP($k0) |
177 | | |
178 | | sw $k1, SAVE_K + 4($k0) |
179 | | lw $k1, -0xd90($zero) |
180 | | sw $k1, SAVE_K + 0($k0) |
181 | | |
182 | | lw $k1, -0xd88($zero) |
183 | | sw $k1, SAVE_RA($k0) |
184 | | sw $v0, SAVE_V + 0 * 4($k0) |
185 | | sw $v1, SAVE_V + 1 * 4($k0) |
186 | | sw $a0, SAVE_A + 0 * 4($k0) |
187 | | sw $a1, SAVE_A + 1 * 4($k0) |
188 | | sw $a2, SAVE_A + 2 * 4($k0) |
189 | | sw $a3, SAVE_A + 3 * 4($k0) |
190 | | sw $t0, SAVE_T + 0 * 4($k0) |
191 | | sw $t1, SAVE_T + 1 * 4($k0) |
192 | | sw $t2, SAVE_T + 2 * 4($k0) |
193 | | sw $t3, SAVE_T + 3 * 4($k0) |
194 | | sw $t4, SAVE_T + 4 * 4($k0) |
195 | | sw $t5, SAVE_T + 5 * 4($k0) |
196 | | sw $t6, SAVE_T + 6 * 4($k0) |
197 | | sw $t7, SAVE_T + 7 * 4($k0) |
198 | | sw $t8, SAVE_T + 8 * 4($k0) |
199 | | sw $t9, SAVE_T + 9 * 4($k0) |
200 | | sw $s0, SAVE_S + 0 * 4($k0) |
201 | | sw $s1, SAVE_S + 1 * 4($k0) |
202 | | sw $s2, SAVE_S + 2 * 4($k0) |
203 | | sw $s3, SAVE_S + 3 * 4($k0) |
204 | | sw $s4, SAVE_S + 4 * 4($k0) |
205 | | sw $s5, SAVE_S + 5 * 4($k0) |
206 | | sw $s6, SAVE_S + 6 * 4($k0) |
207 | 177 | sw $s7, SAVE_S + 7 * 4($k0) |
208 | | mfhi $v0 |
209 | | mflo $v1 |
210 | | sw $v0, SAVE_HI($k0) |
211 | | sw $v1, SAVE_LO($k0) |
| 178 | sw $s6, SAVE_S + 6 * 4($k0) |
| 179 | sw $s5, SAVE_S + 5 * 4($k0) |
| 180 | sw $s4, SAVE_S + 4 * 4($k0) |
| 181 | sw $s3, SAVE_S + 3 * 4($k0) |
| 182 | sw $s2, SAVE_S + 2 * 4($k0) |
| 183 | sw $s1, SAVE_S + 1 * 4($k0) |
| 184 | sw $s0, SAVE_S + 0 * 4($k0) |
| 185 | sw $t9, SAVE_T + 9 * 4($k0) |
| 186 | sw $t8, SAVE_T + 8 * 4($k0) |
| 187 | sw $t7, SAVE_T + 7 * 4($k0) |
| 188 | sw $t6, SAVE_T + 6 * 4($k0) |
| 189 | sw $t5, SAVE_T + 5 * 4($k0) |
| 190 | sw $t4, SAVE_T + 4 * 4($k0) |
| 191 | sw $t3, SAVE_T + 3 * 4($k0) |
| 192 | sw $t2, SAVE_T + 2 * 4($k0) |
| 193 | sw $t1, SAVE_T + 1 * 4($k0) |
| 194 | sw $t0, SAVE_T + 0 * 4($k0) |
| 195 | sw $a3, SAVE_A + 3 * 4($k0) |
| 196 | sw $a2, SAVE_A + 2 * 4($k0) |
| 197 | sw $a1, SAVE_A + 1 * 4($k0) |
| 198 | sw $a0, SAVE_A + 0 * 4($k0) |
| 199 | sw $v1, SAVE_V + 1 * 4($k0) |
| 200 | sw $v0, SAVE_V + 0 * 4($k0) |
| 201 | mfhi $k1 |
| 202 | sw $k1, SAVE_HI($k0) |
| 203 | mflo $k1 |
| 204 | sw $k1, SAVE_LO($k0) |
212 | 205 | mfc0 $k1, $CP0_EPC |
213 | 206 | sw $k1, SAVE_PC($k0) |
214 | 207 | |
215 | | lw $gp, -0xd84($zero) |
216 | | la $sp, kernel_stack + KERNEL_STACK_SIZE |
217 | | |
218 | 208 | #ifndef NDEBUG |
219 | 209 | // Allow kernel bugs to set EPC and friends. |
220 | 210 | mfc0 $k0, $CP0_STATUS |
221 | | li $k1, 0x10000000 |
| 211 | lui $k1, 0x1000 |
222 | 212 | and $k0, $k0, $k1 |
223 | 213 | mtc0 $k0, $CP0_STATUS |
224 | 214 | #endif |
225 | 215 | |
| 216 | lui $k0, 0x8000 |
| 217 | lw $gp, 0x17c($k0) |
| 218 | la $sp, kernel_stack + KERNEL_STACK_SIZE |
| 219 | |
226 | 220 | move $t9, $ra |
227 | 221 | la $ra, kernel_exit |
228 | 222 | jr $t9 |
mips/init.ccp |
1 | 1 | #pypp 0 |
| 2 | // vim: set filetype=cpp : // |
2 | 3 | // Iris: micro-kernel for a capability-based operating system. |
3 | 4 | // mips/init.ccp: mips-specific boot code. |
4 | 5 | // Copyright 2009 Bas Wijnen <wijnen@debian.org> |
... | ... | |
73 | 74 | // Use non-vectored interrupts. |
74 | 75 | cp0_set0 (CP0_INT_CTL) |
75 | 76 | |
76 | | // clear the tlb, hardwire page 0 to 0xffffffff |
77 | | // and soft-wire it to (0x294 << 20) + (0x290 << 10) |
78 | | // (for the idle task). |
79 | | |
80 | | cp0_set (CP0_WIRED, 1) |
81 | | cp0_set0 (CP0_PAGE_MASK) |
82 | | cp0_set0 (CP0_ENTRY_LO0) |
83 | | cp0_set0 (CP0_ENTRY_LO1) |
84 | 77 | // Get number of tlb entries (is 31). |
85 | 78 | unsigned num |
86 | 79 | cp0_get (CP0_CONFIG1, num) |
87 | 80 | num >>= 25 |
88 | 81 | num &= 0x3f |
89 | 82 | // Clear the tlb. |
90 | | for unsigned i = 1; i <= num; ++i: |
| 83 | cp0_set (CP0_WIRED, 0) |
| 84 | cp0_set0 (CP0_PAGE_MASK) |
| 85 | cp0_set0 (CP0_ENTRY_LO0) |
| 86 | cp0_set0 (CP0_ENTRY_LO1) |
| 87 | for unsigned i = 0; i <= num; ++i: |
91 | 88 | // with asid 0, no page faults will be triggered, so it's safe to map memory anywhere. |
92 | | cp0_set (CP0_ENTRY_HI, 0x2000 * i) |
| 89 | // And it's set to invalid anyway. |
| 90 | cp0_set (CP0_ENTRY_HI, 0x2000 * (i + 1)) |
93 | 91 | cp0_set (CP0_INDEX, i) |
94 | 92 | // write the data. |
95 | 93 | __asm__ volatile ("tlbwi") |
96 | | // Fill the upper page in kseg3. |
97 | | cp0_set (CP0_ENTRY_HI, 0xffffe000) |
98 | | cp0_set (CP0_ENTRY_LO0, 0x1d) |
99 | | cp0_set (CP0_ENTRY_LO1, 0x1f) |
100 | | cp0_set0 (CP0_INDEX) |
101 | | __asm__ volatile ("tlbwi") |
102 | 94 | // Fill the idle task's page in useg. Set it to non-cachable. |
103 | 95 | // its directory entry is at 1fc, so it's number 7f (0fe00000). |
104 | 96 | // its table entry is at 1f8, so it's number 7e (0007e000). |
105 | 97 | // its address is 280 (00000280), used below for EPC. |
106 | 98 | unsigned const idle_entry_hi = 0x0fe7e000 |
107 | 99 | cp0_set (CP0_ENTRY_HI, idle_entry_hi) |
108 | | cp0_set (CP0_ENTRY_LO0, 0x16) |
109 | | cp0_set (CP0_ENTRY_LO1, 0x14) |
| 100 | cp0_set (CP0_ENTRY_LO0, 0x00000012) |
| 101 | // The following value doesn't make much sense, but it is what is |
| 102 | // filled in at run-time. So for robustness it's used here as well. |
| 103 | cp0_set (CP0_ENTRY_LO1, 0x80000000) |
110 | 104 | __asm__ volatile ("tlbwr") |
111 | 105 | // Allow eret to be used to jump to the idle task. |
112 | 106 | cp0_set (CP0_EPC, (idle_entry_hi & PAGE_MASK) | 0x280) |
... | ... | |
318 | 312 | // All interrupts enter the CPU through the interrupt controller at IP2, so enable that. |
319 | 313 | cp0_set (CP0_STATUS, 0x1000ff13) |
320 | 314 | |
| 315 | kdebug ("entering idle task\n") |
321 | 316 | // Done; return to user space (the idle task). |
322 | 317 | __asm__ volatile ("eret") |