1 /* 2 * PIC32 microcontroller initialisation code. 3 * 4 * Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "mips.h" 21 #include "pic32.h" 22 23 /* Application-specific configuration. */ 24 25 #include "devconfig.h" 26 27 /* Disable JTAG functionality on pins. */ 28 29 .section .devcfg0, "a" 30 .word 0xfffffffb /* DEVCFG0<2> = JTAGEN = 0 */ 31 32 /* Select oscillator, pin usage, watchdog timer and peripheral clock divider. */ 33 34 .section .devcfg1, "a" 35 .word (DEVCFG1_UNUSED | DEVCFG1_CONFIG) 36 37 /* Set clock dividers and multiplier. */ 38 39 .section .devcfg2, "a" 40 .word (DEVCFG2_UNUSED | DEVCFG2_CONFIG) 41 42 /* The start routine is placed at the boot location. */ 43 44 .section .boot, "a" 45 46 .globl _start 47 .extern relocate_data 48 .extern main 49 50 _start: 51 /* Enable caching. */ 52 53 mfc0 $v1, CP0_CONFIG 54 li $t8, ~CONFIG_K0 55 and $v1, $v1, $t8 56 ori $v1, $v1, CONFIG_K0_CACHABLE_NONCOHERENT 57 mtc0 $v1, CP0_CONFIG 58 nop 59 60 /* Get the RAM size. */ 61 62 la $v1, BMXDRMSZ 63 lw $t0, 0($v1) 64 65 /* Initialise the stack pointer. */ 66 67 li $v1, KSEG0_BASE 68 addu $sp, $t0, $v1 /* sp = KSEG0_BASE + RAM size */ 69 70 /* Initialise the globals pointer. */ 71 72 lui $gp, %hi(_GLOBAL_OFFSET_TABLE_) 73 ori $gp, $gp, %lo(_GLOBAL_OFFSET_TABLE_) 74 75 /* Relocate mutable data and then jump to the main program. */ 76 77 la $t9, relocate_data 78 jal $t9 79 nop 80 81 la $t9, main 82 jr $t9 83 nop