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@73 | 23 | #include "sdram.h" |
paul@73 | 24 | |
paul@68 | 25 | .text |
paul@68 | 26 | .extern c_main |
paul@68 | 27 | .extern _tlb_entry |
paul@68 | 28 | .extern _exc_entry |
paul@68 | 29 | .extern _irq_entry |
paul@68 | 30 | .extern _end_entries |
paul@68 | 31 | .globl _start |
paul@68 | 32 | .set noreorder |
paul@68 | 33 | |
paul@8 | 34 | _start: |
paul@68 | 35 | /* Initialise the stack. */ |
paul@68 | 36 | |
paul@68 | 37 | la $sp, 0x80080000 |
paul@68 | 38 | |
paul@69 | 39 | /* Initialise the globals pointer. */ |
paul@69 | 40 | |
paul@69 | 41 | lui $gp, %hi(_GLOBAL_OFFSET_TABLE_) |
paul@69 | 42 | ori $gp, $gp, %lo(_GLOBAL_OFFSET_TABLE_) |
paul@69 | 43 | |
paul@75 | 44 | move $k0, $ra |
paul@75 | 45 | |
paul@68 | 46 | /* Copy TLB handling instructions. */ |
paul@68 | 47 | |
paul@69 | 48 | la $t0, _tlb_entry /* start */ |
paul@68 | 49 | li $t1, 0x80000000 |
paul@69 | 50 | la $t2, _cache_entry /* end */ |
paul@75 | 51 | jal _copy |
paul@75 | 52 | nop |
paul@68 | 53 | |
paul@69 | 54 | /* Copy cache handling instructions. */ |
paul@69 | 55 | |
paul@69 | 56 | move $t0, $t2 /* start */ |
paul@69 | 57 | li $t1, 0x80000100 |
paul@69 | 58 | la $t2, _exc_entry /* end */ |
paul@75 | 59 | jal _copy |
paul@75 | 60 | nop |
paul@69 | 61 | |
paul@68 | 62 | /* Copy exception handling instructions. */ |
paul@68 | 63 | |
paul@68 | 64 | move $t0, $t2 /* start */ |
paul@68 | 65 | li $t1, 0x80000180 |
paul@69 | 66 | la $t2, _irq_entry /* end */ |
paul@75 | 67 | jal _copy |
paul@75 | 68 | nop |
paul@68 | 69 | |
paul@68 | 70 | /* Copy IRQ handling instructions. */ |
paul@8 | 71 | |
paul@68 | 72 | move $t0, $t2 /* start */ |
paul@68 | 73 | li $t1, 0x80000200 |
paul@69 | 74 | la $t2, _end_entries /* end */ |
paul@75 | 75 | jal _copy |
paul@75 | 76 | nop |
paul@75 | 77 | |
paul@75 | 78 | move $ra, $k0 |
paul@68 | 79 | |
paul@73 | 80 | /* Enable caching. */ |
paul@68 | 81 | |
paul@73 | 82 | li $t0, CONFIG_CM_CACHABLE_NONCOHERENT |
paul@73 | 83 | mtc0 $t0, $16 /* CP0_CONFIG */ |
paul@68 | 84 | nop |
paul@68 | 85 | |
paul@68 | 86 | /* Start the program. */ |
paul@68 | 87 | |
paul@68 | 88 | j c_main |
paul@68 | 89 | nop |
paul@68 | 90 | |
paul@75 | 91 | _copy: |
paul@75 | 92 | /* Copy via $t3 the region from $t0 to $t2 into $t1. */ |
paul@75 | 93 | |
paul@75 | 94 | lw $t3, 0($t0) |
paul@75 | 95 | addiu $t0, $t0, 4 |
paul@75 | 96 | sw $t3, 0($t1) |
paul@75 | 97 | bne $t0, $t2, _copy |
paul@75 | 98 | addiu $t1, $t1, 4 /* executed in delay slot before branch */ |
paul@75 | 99 | j $ra |
paul@75 | 100 | nop |
paul@75 | 101 | |
paul@68 | 102 | .set reorder |