1// ---------------------------------------------
4// ( \/ ) /__\ ( )_( ) /__\ ( )
5// \ / /(__)\ ) _ ( /(__)\ )(__
6// (__)(__)(__)(_) (_)(__)(__)(____)
8// Yet Another HW Abstraction Library
9// Copyright (C) Andreas Terstegge
10// BSD Licensed (see file LICENSE)
12// ---------------------------------------------
14// Low-level reset code for the RP2040 Launchpad
17// - Check wether the image is a COPY_TO_xxx image, and relocates
18// the image if necessary
19// - Sets the VTOR register
20// - Jumps to the C++-part of the reset routine (Reset_Handler)
22// The following boot scenarios for the RP2040 Launchpad are supported:
24// 1.) Normal flash image
25// OpenOcd upload: Works, target is reset and enters reset_handler
26// via bootrom and boot2.
27// OpenOcd debug: Works, targer is reset and enters reset_handler
28// via bootrom and boot2.
31// 2.) Image linked with COPY_TO_RAM
32// OpenOcd upload: Works, target is reset and enters reset_handler
33// via bootrom and boot2.
34// OpenOcd debug: Works, targer is reset and enters reset_handler
35// via bootrom and boot2.
38// 3.) Images linked with LOAD_INTO_RAM
39// OpenOcd upload: Works, target is not reset and resumes at 0x20000001.
40// OpenOcd debug: Needs special debugger setup, reset is not allowed.
43#define VTOR_REG 0xe000ed08
49 .global _elf_entry_point
51 // This is a fake vector table to start the
52 // reset_handler, in case this code is put right
53 // at the beginning of the flash (0x10000000).
60 // Check if we have to relocate the image
61 ldr r0, =__image_load__
62 ldr r1, =__image_start__
67 // Copy the complete image (.text, .rodata, .data)
68 // to the runtime memory area in RAM
69 ldr r2, =__image_end__
76 // Setup stack pointer, because the C-part
77 // of the reset handler will use it!!
81 // Set the ISR vector offset register (VTOR)
82 ldr r0, =__vector_start__
86 // Finally jump to the C++-based part of
87 // the reset handler, which will initialize
88 // the system and jump to main(). Use a long
89 // jump here in case the jump target is in RAM
90 ldr r0, =Reset_Handler
94 // We should never get here, but just in case
95 // run into an endless loop
99 // If the image is entered via the _elf_entry_point,
100 // take a loop through the bootrom, to make sure the
101 // flash and other related things are initialized
104 // Set the ISR vector offset register (VTOR)
109 // r1=initial SP, r2=reset handler of bootrom
114 // We should never get here, but just in case
115 // run into an endless loop