1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup raspberrypi |
---|
5 | * |
---|
6 | * @brief Startup code. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2013 by Alan Cudmore |
---|
11 | * based on work by: |
---|
12 | * Copyright (c) 2009 |
---|
13 | * embedded brains GmbH |
---|
14 | * Obere Lagerstr. 30 |
---|
15 | * D-82178 Puchheim |
---|
16 | * Germany |
---|
17 | * <rtems@embedded-brains.de> |
---|
18 | * |
---|
19 | * The license and distribution terms for this file may be |
---|
20 | * found in the file LICENSE in this distribution or at |
---|
21 | * http://www.rtems.com/license/LICENSE |
---|
22 | */ |
---|
23 | |
---|
24 | #include <stdbool.h> |
---|
25 | |
---|
26 | #include <bspopts.h> |
---|
27 | #include <bsp/start.h> |
---|
28 | #include <bsp/raspberrypi.h> |
---|
29 | #include <bsp/mmu.h> |
---|
30 | #include <bsp/linker-symbols.h> |
---|
31 | #include <bsp/uart-output-char.h> |
---|
32 | |
---|
33 | static void BSP_START_TEXT_SECTION clear_bss(void) |
---|
34 | { |
---|
35 | const int *end = (const int *) bsp_section_bss_end; |
---|
36 | int *out = (int *) bsp_section_bss_begin; |
---|
37 | |
---|
38 | /* Clear BSS */ |
---|
39 | while (out != end) { |
---|
40 | *out = 0; |
---|
41 | ++out; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | static void BSP_START_TEXT_SECTION raspberrypi_cache_setup(void) |
---|
46 | { |
---|
47 | uint32_t ctrl = 0; |
---|
48 | |
---|
49 | /* Disable MMU and cache, basic settings */ |
---|
50 | ctrl = arm_cp15_get_control(); |
---|
51 | ctrl &= ~(ARM_CP15_CTRL_I | ARM_CP15_CTRL_R | ARM_CP15_CTRL_C |
---|
52 | | ARM_CP15_CTRL_V | ARM_CP15_CTRL_M); |
---|
53 | ctrl |= ARM_CP15_CTRL_S | ARM_CP15_CTRL_A; |
---|
54 | arm_cp15_set_control(ctrl); |
---|
55 | |
---|
56 | arm_cp15_cache_invalidate(); |
---|
57 | arm_cp15_tlb_invalidate(); |
---|
58 | |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | void BSP_START_TEXT_SECTION bsp_start_hook_0(void) |
---|
63 | { |
---|
64 | raspberrypi_cache_setup(); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | void BSP_START_TEXT_SECTION bsp_start_hook_1(void) |
---|
69 | { |
---|
70 | |
---|
71 | /* Copy .text section */ |
---|
72 | arm_cp15_instruction_cache_invalidate(); |
---|
73 | bsp_start_memcpy( |
---|
74 | (int *) bsp_section_text_begin, |
---|
75 | (const int *) bsp_section_text_load_begin, |
---|
76 | (size_t) bsp_section_text_size |
---|
77 | ); |
---|
78 | |
---|
79 | /* Copy .rodata section */ |
---|
80 | arm_cp15_instruction_cache_invalidate(); |
---|
81 | bsp_start_memcpy( |
---|
82 | (int *) bsp_section_rodata_begin, |
---|
83 | (const int *) bsp_section_rodata_load_begin, |
---|
84 | (size_t) bsp_section_rodata_size |
---|
85 | ); |
---|
86 | |
---|
87 | /* Copy .data section */ |
---|
88 | arm_cp15_instruction_cache_invalidate(); |
---|
89 | bsp_start_memcpy( |
---|
90 | (int *) bsp_section_data_begin, |
---|
91 | (const int *) bsp_section_data_load_begin, |
---|
92 | (size_t) bsp_section_data_size |
---|
93 | ); |
---|
94 | |
---|
95 | /* Copy .fast_text section */ |
---|
96 | arm_cp15_instruction_cache_invalidate(); |
---|
97 | bsp_start_memcpy( |
---|
98 | (int *) bsp_section_fast_text_begin, |
---|
99 | (const int *) bsp_section_fast_text_load_begin, |
---|
100 | (size_t) bsp_section_fast_text_size |
---|
101 | ); |
---|
102 | |
---|
103 | /* Copy .fast_data section */ |
---|
104 | arm_cp15_instruction_cache_invalidate(); |
---|
105 | bsp_start_memcpy( |
---|
106 | (int *) bsp_section_fast_data_begin, |
---|
107 | (const int *) bsp_section_fast_data_load_begin, |
---|
108 | (size_t) bsp_section_fast_data_size |
---|
109 | ); |
---|
110 | |
---|
111 | /* Clear .bss section */ |
---|
112 | clear_bss(); |
---|
113 | |
---|
114 | } |
---|