Root/mips/start.S

1// Iris: micro-kernel for a capability-based operating system.
2// mips/start.S: kernel starter at high address.
3// Copyright 2009 Bas Wijnen <wijnen@debian.org>
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18// This program is a wrapper around the kernel.
19// It is position-independant and may be loaded anywhere.
20// It does not use gp. This means that li and la must not be used.
21    .globl __start
22    .set noreorder
23
24__start:
25    // Set t0 to uart0 txd
26    lui $t0, 0xb003
27
28    bal 1f
29// For some reason the disassembler considers everything
30// after __start non-code until the next label. So I add a label.
31start_hack_for_disassembler:
32    lui $a0, 0x8000
33base:
34    .word image_end - image
351:
36    // Set kseg0 to uncachable.
37    ori $t0, $zero, 2
38    mtc0 $t0, $16, 0
39
40    // Flush cache.
41    lui $v1, 0x8000
42    ori $v0, $v1, 0x8000
431:
44    // i-cache index invalidate.
45    cache 0, 0($v1)
46    // d-cache index write-back invalidate.
47    cache 1, 0($v1)
48    bne $v1, $v0, 1b
49    addiu $v1, $v1, 32
50
51    // Set a1 to start address of image.
52    addiu $a1, $ra, image - base + ADDR0 - 0x80000000
53
54    // Set a2 to end address of image.
55    lw $a2, 0($ra)
56    add $a2, $a2, $a1
57
58    // Set t9 to the entry point.
59    lui $t9, START >> 16
60    ori $t9, $t9, START & 0xffff
61
62    // Put the copying code at the end, to prevent overwriting itself.
63    // The copy goes to the start of RAM, so the target is never larger than the source.
64    jr $a2
65    nop
66
67image:
68    .incbin "iris.raw"
69image_end:
70    // Copy the image to the start of RAM.
71    // a0 is the destination: 0x80000000, counting up.
72    // a1 is the start of the image, counting up.
73    // a2 is the end of the image, not changing.
74    // a3 is the working register to do the move.
751: lw $a3, 0($a1)
76    addiu $a1, $a1, 4
77    sw $a3, 0($a0)
78    bne $a1, $a2, 1b
79    addiu $a0, $a0, 4
80    // Done copying.
81
82    // Make the jump to the new code.
83    jr $t9
84    nop
85

Archive Download this file

Branches:
master



interactive