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