1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/lib/start.S Mon Oct 22 21:44:02 2018 +0200
1.3 @@ -0,0 +1,83 @@
1.4 +/*
1.5 + * PIC32 microcontroller initialisation code.
1.6 + *
1.7 + * Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software: you can redistribute it and/or modify
1.10 + * it under the terms of the GNU General Public License as published by
1.11 + * the Free Software Foundation, either version 3 of the License, or
1.12 + * (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1.21 + */
1.22 +
1.23 +#include "mips.h"
1.24 +#include "pic32.h"
1.25 +
1.26 +/* Application-specific configuration. */
1.27 +
1.28 +#include "devconfig.h"
1.29 +
1.30 +/* Disable JTAG functionality on pins. */
1.31 +
1.32 +.section .devcfg0, "a"
1.33 +.word 0xfffffffb /* DEVCFG0<2> = JTAGEN = 0 */
1.34 +
1.35 +/* Select oscillator, pin usage, watchdog timer and peripheral clock divider. */
1.36 +
1.37 +.section .devcfg1, "a"
1.38 +.word (DEVCFG1_UNUSED | DEVCFG1_CONFIG)
1.39 +
1.40 +/* Set clock dividers and multiplier. */
1.41 +
1.42 +.section .devcfg2, "a"
1.43 +.word (DEVCFG2_UNUSED | DEVCFG2_CONFIG)
1.44 +
1.45 +/* The start routine is placed at the boot location. */
1.46 +
1.47 +.section .boot, "a"
1.48 +
1.49 +.globl _start
1.50 +.extern main
1.51 +
1.52 +_start:
1.53 + /* Enable caching. */
1.54 +
1.55 + mfc0 $v1, CP0_CONFIG
1.56 + li $t8, ~CONFIG_K0
1.57 + and $v1, $v1, $t8
1.58 + ori $v1, $v1, CONFIG_K0_CACHABLE_NONCOHERENT
1.59 + mtc0 $v1, CP0_CONFIG
1.60 + nop
1.61 +
1.62 + /* Get the RAM size. */
1.63 +
1.64 + la $v1, BMXDRMSZ
1.65 + lw $t0, 0($v1)
1.66 +
1.67 + /* Initialise the stack pointer. */
1.68 +
1.69 + li $v1, KSEG0_BASE
1.70 + addu $sp, $t0, $v1 /* sp = KSEG0_BASE + RAM size */
1.71 +
1.72 + /* Initialise the globals pointer. */
1.73 +
1.74 + lui $gp, %hi(_GLOBAL_OFFSET_TABLE_)
1.75 + ori $gp, $gp, %lo(_GLOBAL_OFFSET_TABLE_)
1.76 +
1.77 + /*
1.78 + Jump to the main program. Since the boot code is separate from the
1.79 + other code, the address cannot be obtained via the GOT.
1.80 + ("relocation truncated to fit: R_MIPS_PC16 against `main'")
1.81 + */
1.82 +
1.83 + lui $t9, %hi(main)
1.84 + ori $t9, $t9, %lo(main)
1.85 + jr $t9
1.86 + nop