Statistics
| Branch: | Tag: | Revision:

amiro-blt / Target / Source / ARMCM3_STM32 / GCC / cstart.c @ 1446566f

History | View | Annotate | Download (3.987 KB)

1
/************************************************************************************//**
2
* \file         Source\ARMCM3_STM32\GCC\cstart.c
3
* \brief        Bootloader C startup source file.
4
* \ingroup      Target_ARMCM3_STM32
5
* \internal
6
*----------------------------------------------------------------------------------------
7
*                          C O P Y R I G H T
8
*----------------------------------------------------------------------------------------
9
*   Copyright (c) 2011  by Feaser    http://www.feaser.com    All rights reserved
10
*
11
*----------------------------------------------------------------------------------------
12
*                            L I C E N S E
13
*----------------------------------------------------------------------------------------
14
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
15
* modify it under the terms of the GNU General Public License as published by the Free
16
* Software Foundation, either version 3 of the License, or (at your option) any later
17
* version.
18
*
19
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
20
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21
* PURPOSE. See the GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License along with OpenBLT.
24
* If not, see <http://www.gnu.org/licenses/>.
25
*
26
* A special exception to the GPL is included to allow you to distribute a combined work 
27
* that includes OpenBLT without being obliged to provide the source code for any 
28
* proprietary components. The exception text is included at the bottom of the license
29
* file <license.html>.
30
* 
31
* \endinternal
32
****************************************************************************************/
33

    
34
/****************************************************************************************
35
* Include files
36
****************************************************************************************/
37
#include "boot.h"                                    /* bootloader generic header      */
38

    
39

    
40
/****************************************************************************************
41
* External function protoypes
42
****************************************************************************************/
43
extern int  main(void);
44

    
45

    
46
/****************************************************************************************
47
* External data declarations
48
****************************************************************************************/
49
/* these externals are declared by the linker */
50
extern blt_int32u _etext;
51
extern blt_int32u _data;
52
extern blt_int32u _edata;
53
extern blt_int32u _bss;
54
extern blt_int32u _ebss;
55
extern blt_int32u _estack;
56

    
57

    
58
/************************************************************************************//**
59
** \brief     Reset interrupt service routine. Configures the stack, initializes 
60
**            RAM and jumps to function main.
61
** \return    none.
62
**
63
****************************************************************************************/
64
void reset_handler(void)
65
{
66
  blt_int32u *pSrc, *pDest;
67

    
68
  /* disable interrupts first */
69
  __asm("    cpsid     i");
70
  /* copy the data segment initializers from flash to SRAM */
71
  pSrc = &_etext;
72
  for(pDest = &_data; pDest < &_edata; )
73
  {
74
    *pDest++ = *pSrc++;
75
  }
76
  /* zero fill the bss segment. this is done with inline assembly since this will 
77
   * clear the value of pDest if it is not kept in a register.
78
   */
79
  __asm("    ldr     r0, =_bss\n"
80
        "    ldr     r1, =_ebss\n"
81
        "    mov     r2, #0\n"
82
        "    .thumb_func\n"
83
        "zero_loop:\n"
84
        "        cmp     r0, r1\n"
85
        "        it      lt\n"
86
        "        strlt   r2, [r0], #4\n"
87
        "        blt     zero_loop");
88
  /* start the software application by calling its entry point */
89
  main();
90
} /*** end of reset_handler ***/
91

    
92

    
93
/************************************ end of cstart.c **********************************/