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 "mips.h" 24 #include "sdram.h" 25 26 .text 27 .extern c_main 28 .extern _tlb_entry 29 .extern _exc_entry 30 .extern _irq_entry 31 .extern _end_entries 32 .extern _got_start 33 .extern _got_end 34 .extern _got_copy_start 35 .globl _start 36 .set noreorder 37 38 _start: 39 b real_start 40 nop 41 42 /* Apparently reserved region which, if used, breaks the USB Boot process. */ 43 44 .word 0 45 .word 0 46 .word 0 47 .word 0 48 .word 0 49 .word 0 50 .word 0 51 .word 0 52 53 real_start: 54 /* Initialise the stack. */ 55 56 la $sp, 0x80080000 57 58 /* Initialise the globals pointer. */ 59 60 lui $gp, %hi(_GLOBAL_OFFSET_TABLE_) 61 ori $gp, $gp, %lo(_GLOBAL_OFFSET_TABLE_) 62 63 move $k0, $ra 64 65 /* Copy TLB handling instructions. */ 66 67 la $t0, _tlb_entry /* start */ 68 li $t1, 0x80000000 69 la $t2, _exc_entry /* end */ 70 jal _copy 71 nop 72 73 /* Copy exception handling instructions. */ 74 75 la $t0, _exc_entry /* start */ 76 li $t1, 0x80000180 77 la $t2, _irq_entry /* end */ 78 jal _copy 79 nop 80 81 /* Copy IRQ handling instructions. */ 82 83 la $t0, _irq_entry /* start */ 84 li $t1, 0x80000200 85 la $t2, _end_entries /* end */ 86 jal _copy 87 nop 88 89 /* Copy the offset table for user mode programs. */ 90 91 la $t0, _got_start /* start */ 92 la $t1, _got_copy_start 93 la $t2, _got_end /* end */ 94 li $t3, 0x80000000 /* adjustment */ 95 jal _copy_adjust 96 nop 97 98 move $ra, $k0 99 100 /* Enable caching. */ 101 102 li $t0, CONFIG_CM_CACHABLE_NONCOHERENT 103 mtc0 $t0, CP0_CONFIG 104 nop 105 106 /* Start the program. */ 107 108 la $t9, c_main /* load the address of the routine */ 109 j c_main 110 nop 111 112 _copy: 113 /* Copy via $t3 the region from $t0 to $t2 into $t1. */ 114 115 lw $t3, 0($t0) 116 addiu $t0, $t0, 4 117 sw $t3, 0($t1) 118 bne $t0, $t2, _copy 119 addiu $t1, $t1, 4 /* executed in delay slot before branch */ 120 jr $ra 121 nop 122 123 _copy_adjust: 124 /* Copy via $t4 the region from $t0 to $t2 into $t1, adjusting by $t3. */ 125 126 lw $t4, 0($t0) 127 addiu $t0, $t0, 4 128 subu $t4, $t4, $t3 129 sw $t4, 0($t1) 130 bne $t0, $t2, _copy_adjust 131 addiu $t1, $t1, 4 /* executed in delay slot before branch */ 132 jr $ra 133 nop 134 135 .set reorder