Blame view

RIOT/cpu/atmega2560/startup.c 1.89 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  /*
   * Copyright (C) 2014 Freie Universitรคt Berlin, Hinnerk van Bruinehsen
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @ingroup     cpu_atmega2560
   * @{
   *
   * @file
   * @brief       Startup code and interrupt vector definition
   *
   * @author     Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
   *
   * @}
   */
  
  #include <stdint.h>
  #include <avr/interrupt.h>
  #include <avr/io.h>
  
  /* For Catchall-Loop */
  #include "board.h"
  
  
  /**
   * @brief functions for initializing the board, std-lib and kernel
   */
  extern void board_init(void);
  extern void kernel_init(void);
  extern void __libc_init_array(void);
  
  /**
   * @brief This pair of functions hook circumvent the call to main
   *
   * avr-libc normally uses the .init9 section for a call to main. This call
   * seems to be not replaceable without hacking inside the library. We
   * circumvent the call to main by using section .init7 to call the function
   * reset_handler which therefore is the real entry point and  section .init8
   * which should never be reached but just in case jumps to exit.
   * This way there should be no way to call main directly.
   */
  void init7_ovr(void) __attribute__((section(".init7")));
  void init8_ovr(void) __attribute__((section(".init8")));
  
  
  __attribute__((used,naked)) void init7_ovr(void)
  {
      __asm__("call reset_handler");
  }
  
  __attribute__((used,naked)) void init8_ovr(void)
  {
      __asm__("jmp exit");
  }
  
  /**
   * @brief This function is the entry point after a system reset
   *
   * After a system reset, the following steps are necessary and carried out:
   * 1. initialize the board (sync clock, setup std-IO)
   * 2. initialize and start RIOTs kernel
   */
  __attribute__((used)) void reset_handler(void)
  {
      /* initialize the board and startup the kernel */
      board_init();
      /* startup the kernel */
      kernel_init();
  }