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 main 48 49 _start: 50 /* Enable caching. */ 51 52 mfc0 $v1, CP0_CONFIG 53 li $t8, ~CONFIG_K0 54 and $v1, $v1, $t8 55 ori $v1, $v1, CONFIG_K0_CACHABLE_NONCOHERENT 56 mtc0 $v1, CP0_CONFIG 57 nop 58 59 /* Get the RAM size. */ 60 61 la $v1, BMXDRMSZ 62 lw $t0, 0($v1) 63 64 /* Initialise the stack pointer. */ 65 66 li $v1, KSEG0_BASE 67 addu $sp, $t0, $v1 /* sp = KSEG0_BASE + RAM size */ 68 69 /* Initialise the globals pointer. */ 70 71 lui $gp, %hi(_GLOBAL_OFFSET_TABLE_) 72 ori $gp, $gp, %lo(_GLOBAL_OFFSET_TABLE_) 73 74 /* 75 Jump to the main program. Since the boot code is separate from the 76 other code, the address cannot be obtained via the GOT. 77 ("relocation truncated to fit: R_MIPS_PC16 against `main'") 78 */ 79 80 lui $t9, %hi(main) 81 ori $t9, $t9, %lo(main) 82 jr $t9 83 nop