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 init_bss 49 .extern main 50 51 _start: 52 /* Enable caching. */ 53 54 mfc0 $v1, CP0_CONFIG 55 li $t8, ~CONFIG_K0 56 and $v1, $v1, $t8 57 ori $v1, $v1, CONFIG_K0_CACHABLE_NONCOHERENT 58 mtc0 $v1, CP0_CONFIG 59 nop 60 61 /* Get the RAM size. */ 62 63 la $v1, BMXDRMSZ 64 lw $t0, 0($v1) 65 66 /* Initialise the stack pointer. */ 67 68 li $v1, KSEG0_BASE 69 addu $sp, $t0, $v1 /* sp = KSEG0_BASE + RAM size */ 70 71 /* Initialise the globals pointer. */ 72 73 lui $gp, %hi(_GLOBAL_OFFSET_TABLE_) 74 ori $gp, $gp, %lo(_GLOBAL_OFFSET_TABLE_) 75 76 /* Clear or relocate mutable data and then jump to the main program. */ 77 78 la $t9, init_bss 79 jalr $t9 80 nop 81 82 la $t9, relocate_data 83 jalr $t9 84 nop 85 86 la $t9, main 87 jalr $t9 88 nop 89 90 _end: 91 b _end 92 nop