1 /* 2 * Initialisation code for the stage 2 payload. 3 * 4 * Copyright 2009 (C) Qi Hardware Inc. 5 * Author: Wolfgang Spraul <wolfgang@sharism.cc> 6 * 7 * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> 8 * 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #include "sdram.h" 24 25 .text 26 .extern c_main 27 .extern _tlb_entry 28 .extern _exc_entry 29 .extern _irq_entry 30 .extern _end_entries 31 .extern _got_start 32 .extern _got_end 33 .extern _got_copy_start 34 .globl _start 35 .set noreorder 36 37 _start: 38 b real_start 39 nop 40 41 /* Apparently reserved region which, if used, breaks the USB Boot process. */ 42 43 .word 0x0 44 .word 0x0 45 .word 0x0 46 .word 0x0 47 .word 0x0 48 .word 0x0 49 .word 0x0 50 .word 0x0 51 52 real_start: 53 /* Initialise the stack. */ 54 55 la $sp, 0x80080000 56 57 /* Initialise the globals pointer. */ 58 59 lui $gp, %hi(_GLOBAL_OFFSET_TABLE_) 60 ori $gp, $gp, %lo(_GLOBAL_OFFSET_TABLE_) 61 62 move $k0, $ra 63 64 /* Copy TLB handling instructions. */ 65 66 la $t0, _tlb_entry /* start */ 67 li $t1, 0x80000000 68 la $t2, _exc_entry /* end */ 69 jal _copy 70 nop 71 72 /* Copy exception handling instructions. */ 73 74 la $t0, _exc_entry /* start */ 75 li $t1, 0x80000180 76 la $t2, _irq_entry /* end */ 77 jal _copy 78 nop 79 80 /* Copy IRQ handling instructions. */ 81 82 la $t0, _irq_entry /* start */ 83 li $t1, 0x80000200 84 la $t2, _end_entries /* end */ 85 jal _copy 86 nop 87 88 /* Copy the offset table for user mode programs. */ 89 90 la $t0, _got_start /* start */ 91 la $t1, _got_copy_start 92 la $t2, _got_end /* end */ 93 li $t3, 0x80000000 /* adjustment */ 94 jal _copy_adjust 95 nop 96 97 move $ra, $k0 98 99 /* Enable caching. */ 100 101 li $t0, CONFIG_CM_CACHABLE_NONCOHERENT 102 mtc0 $t0, $16 /* CP0_CONFIG */ 103 nop 104 105 /* Start the program. */ 106 107 la $t9, c_main /* load the address of the routine */ 108 j c_main 109 nop 110 111 _copy: 112 /* Copy via $t3 the region from $t0 to $t2 into $t1. */ 113 114 lw $t3, 0($t0) 115 addiu $t0, $t0, 4 116 sw $t3, 0($t1) 117 bne $t0, $t2, _copy 118 addiu $t1, $t1, 4 /* executed in delay slot before branch */ 119 jr $ra 120 nop 121 122 _copy_adjust: 123 /* Copy via $t4 the region from $t0 to $t2 into $t1, adjusting by $t3. */ 124 125 lw $t4, 0($t0) 126 addiu $t0, $t0, 4 127 subu $t4, $t4, $t3 128 sw $t4, 0($t1) 129 bne $t0, $t2, _copy_adjust 130 addiu $t1, $t1, 4 /* executed in delay slot before branch */ 131 jr $ra 132 nop 133 134 .set reorder