paul@8 | 1 | /* |
paul@63 | 2 | * Initialisation code for the stage 2 payload. |
paul@63 | 3 | * |
paul@63 | 4 | * Copyright 2009 (C) Qi Hardware Inc. |
paul@63 | 5 | * Author: Wolfgang Spraul <wolfgang@sharism.cc> |
paul@63 | 6 | * |
paul@63 | 7 | * Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk> |
paul@8 | 8 | * |
paul@63 | 9 | * This program is free software: you can redistribute it and/or modify |
paul@63 | 10 | * it under the terms of the GNU General Public License as published by |
paul@63 | 11 | * the Free Software Foundation, either version 3 of the License, or |
paul@63 | 12 | * (at your option) any later version. |
paul@63 | 13 | * |
paul@63 | 14 | * This program is distributed in the hope that it will be useful, |
paul@63 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@63 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@63 | 17 | * GNU General Public License for more details. |
paul@63 | 18 | * |
paul@63 | 19 | * You should have received a copy of the GNU General Public License |
paul@63 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@8 | 21 | */ |
paul@8 | 22 | |
paul@68 | 23 | .text |
paul@68 | 24 | .extern c_main |
paul@68 | 25 | .extern _tlb_entry |
paul@68 | 26 | .extern _exc_entry |
paul@68 | 27 | .extern _irq_entry |
paul@68 | 28 | .extern _end_entries |
paul@68 | 29 | .globl _start |
paul@68 | 30 | .set noreorder |
paul@68 | 31 | |
paul@8 | 32 | _start: |
paul@68 | 33 | /* Initialise the stack. */ |
paul@68 | 34 | |
paul@68 | 35 | la $sp, 0x80080000 |
paul@68 | 36 | |
paul@68 | 37 | /* Copy TLB handling instructions. */ |
paul@68 | 38 | |
paul@68 | 39 | lui $t0, %hi(_tlb_entry) /* start */ |
paul@68 | 40 | ori $t0, $t0, %lo(_tlb_entry) |
paul@68 | 41 | li $t1, 0x80000000 |
paul@68 | 42 | lui $t2, %hi(_exc_entry) /* end */ |
paul@68 | 43 | ori $t2, $t2, %lo(_exc_entry) |
paul@68 | 44 | _tlb_copy: |
paul@68 | 45 | lw $t3, 0($t0) |
paul@68 | 46 | addiu $t0, $t0, 4 |
paul@68 | 47 | sw $t3, 0($t1) |
paul@68 | 48 | bne $t0, $t2, _tlb_copy |
paul@68 | 49 | addiu $t1, $t1, 4 /* executed in delay slot before branch */ |
paul@68 | 50 | |
paul@68 | 51 | /* Copy exception handling instructions. */ |
paul@68 | 52 | |
paul@68 | 53 | move $t0, $t2 /* start */ |
paul@68 | 54 | li $t1, 0x80000180 |
paul@68 | 55 | lui $t2, %hi(_irq_entry) /* end */ |
paul@68 | 56 | ori $t2, $t2, %lo(_irq_entry) |
paul@68 | 57 | _exc_copy: |
paul@68 | 58 | lw $t3, 0($t0) |
paul@68 | 59 | addiu $t0, $t0, 4 |
paul@68 | 60 | sw $t3, 0($t1) |
paul@68 | 61 | bne $t0, $t2, _exc_copy |
paul@68 | 62 | addiu $t1, $t1, 4 /* executed in delay slot before branch */ |
paul@68 | 63 | |
paul@68 | 64 | /* Copy IRQ handling instructions. */ |
paul@8 | 65 | |
paul@68 | 66 | move $t0, $t2 /* start */ |
paul@68 | 67 | li $t1, 0x80000200 |
paul@68 | 68 | lui $t2, %hi(_end_entries) /* end */ |
paul@68 | 69 | ori $t2, $t2, %lo(_end_entries) |
paul@68 | 70 | _irq_copy: |
paul@68 | 71 | lw $t3, 0($t0) |
paul@68 | 72 | addiu $t0, $t0, 4 |
paul@68 | 73 | sw $t3, 0($t1) |
paul@68 | 74 | bne $t0, $t2, _irq_copy |
paul@68 | 75 | addiu $t1, $t1, 4 /* executed in delay slot before branch */ |
paul@68 | 76 | |
paul@68 | 77 | /* Initialise interrupts. */ |
paul@68 | 78 | |
paul@68 | 79 | mfc0 $t3, $12 /* CP0_STATUS */ |
paul@68 | 80 | nop |
paul@68 | 81 | li $t4, 0xffbf00e0 /* BEV = 0 (not bootloader vectors); IM = disable all */ |
paul@68 | 82 | and $t3, $t3, $t4 /* ... KSU = 0 (kernel mode); ERL = 0; EXL = 0; IE = 0 */ |
paul@68 | 83 | li $t4, 0x0000ff04 /* IM = enable IM7..IM0; ERL = 1 (set by default) */ |
paul@68 | 84 | or $t3, $t3, $t4 |
paul@68 | 85 | mtc0 $t3, $12 |
paul@68 | 86 | nop |
paul@68 | 87 | |
paul@68 | 88 | li $t3, 0x00800000 /* IV = 1 (use 0x80000200 for interrupts) */ |
paul@68 | 89 | mtc0 $t3, $13 /* CP0_CAUSE */ |
paul@68 | 90 | nop |
paul@68 | 91 | |
paul@68 | 92 | mtc0 $zero, $15 /* CP0_EBASE (should be zero anyway) */ |
paul@68 | 93 | nop |
paul@68 | 94 | |
paul@68 | 95 | /* Start the program. */ |
paul@68 | 96 | |
paul@68 | 97 | j c_main |
paul@68 | 98 | nop |
paul@68 | 99 | |
paul@68 | 100 | .set reorder |