1 | /** |
---|
2 | * @file bspstart.c |
---|
3 | * |
---|
4 | * This file contains the GBA BSP startup package. |
---|
5 | * It includes application, board, and monitor specific initialization and |
---|
6 | * configuration. The generic CPU dependent initialization has been |
---|
7 | * performed before this routine is invoked. |
---|
8 | */ |
---|
9 | /* |
---|
10 | * RTEMS GBA BSP |
---|
11 | * |
---|
12 | * Copyright (c) 2004 Markku Puro <markku.puro@kopteri.net> |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.com/license/LICENSE. |
---|
17 | * |
---|
18 | * $Id$ |
---|
19 | */ |
---|
20 | |
---|
21 | #include <stdio.h> |
---|
22 | #include <bsp.h> |
---|
23 | #include <rtems/bspIo.h> |
---|
24 | #include <rtems/libio.h> |
---|
25 | #include <rtems/libcsupport.h> |
---|
26 | #include <gba.h> |
---|
27 | #include <conio.h> |
---|
28 | |
---|
29 | #define BSP_DEBUG 0 |
---|
30 | |
---|
31 | /* Global Variables, Defined in 'linkcmds' */ |
---|
32 | extern void _end; |
---|
33 | extern void _stack_size; |
---|
34 | extern void _irq_max_vector; |
---|
35 | extern void __heap_limit; |
---|
36 | extern void __ro_start; |
---|
37 | extern void __ro_end; |
---|
38 | extern void __data_start; |
---|
39 | extern void __data_end; |
---|
40 | extern void __load_start_data; |
---|
41 | extern void __load_stop_data; |
---|
42 | extern void __ewram_start; |
---|
43 | extern void __ewram_end; |
---|
44 | extern void __load_start_ewram; |
---|
45 | extern void __load_stop_ewram; |
---|
46 | extern void __iwram_start; |
---|
47 | extern void __iwram_end; |
---|
48 | extern void __load_start_iwram; |
---|
49 | extern void __load_stop_iwram; |
---|
50 | extern void __bss_start; |
---|
51 | extern void __bss_end; |
---|
52 | |
---|
53 | /* External Prototypes */ |
---|
54 | extern void bsp_cleanup( void ); |
---|
55 | extern void rtems_irq_mngt_init(void); |
---|
56 | extern void bsp_libc_init( void *, uint32_t, int ); |
---|
57 | |
---|
58 | /** Chip registers */ |
---|
59 | volatile unsigned int *Regs = (unsigned int *)GBA_IO_REGS_ADDR; |
---|
60 | |
---|
61 | /** |
---|
62 | * Size of heap if it is 0 it will be dynamically defined by memory size, |
---|
63 | * otherwise the value should be changed by binary patch |
---|
64 | */ |
---|
65 | uint32_t _heap_size = 0; |
---|
66 | |
---|
67 | /** Address of start of free memory - should be updated after creating new partitions or regions.*/ |
---|
68 | uint32_t rtemsFreeMemStart; |
---|
69 | |
---|
70 | /** |
---|
71 | * @brief BSP pretasking hook. |
---|
72 | * |
---|
73 | * Called just before drivers are initialized. |
---|
74 | * Used to setup libc and install any BSP extensions. |
---|
75 | * |
---|
76 | * NOTE: Must not use libc (to do io) from here, since drivers are not yet initialized. |
---|
77 | * |
---|
78 | * @param None |
---|
79 | * @return None |
---|
80 | */ |
---|
81 | void bsp_pretasking_hook(void) |
---|
82 | { |
---|
83 | |
---|
84 | if (_heap_size == 0) { |
---|
85 | _heap_size = (uint32_t)&__heap_limit - rtemsFreeMemStart; |
---|
86 | } |
---|
87 | |
---|
88 | bsp_libc_init((void *)rtemsFreeMemStart, _heap_size, 0); |
---|
89 | |
---|
90 | rtemsFreeMemStart += _heap_size; |
---|
91 | |
---|
92 | |
---|
93 | #ifdef RTEMS_DEBUG |
---|
94 | rtems_debug_enable(RTEMS_DEBUG_ALL_MASK); |
---|
95 | #endif /* RTEMS_DEBUG */ |
---|
96 | |
---|
97 | #if BSP_DEBUG |
---|
98 | /* The following information is very useful when debugging. */ |
---|
99 | printk("[bsp_pretasking_hook]\n"); |
---|
100 | printk("_heap_size = 0x%x\n", _heap_size); |
---|
101 | printk("_stack_size = 0x%x\n", (uint32_t)&_stack_size); |
---|
102 | printk("_irq_max_vector = 0x%x\n", (uint32_t)&_irq_max_vector); |
---|
103 | printk("__ro_start = 0x%x : __ro_end = 0x%x\n", (uint32_t)&__ro_start, (uint32_t)&__ro_end); |
---|
104 | printk("__ewram_start = 0x%x : __ewram_end = 0x%x\n", (uint32_t)&__ewram_start, (uint32_t)&__ewram_end); |
---|
105 | printk("__data_start = 0x%x : __data_end = 0x%x\n", (uint32_t)&__data_start, (uint32_t)&__data_end); |
---|
106 | printk("__bss_start = 0x%x : __bss_end = 0x%x\n", (uint32_t)&__bss_start,(uint32_t)&__bss_end); |
---|
107 | printk("__iwram_start = 0x%x : __iwram_end = 0x%x\n", (uint32_t)&__iwram_start,(uint32_t)&__iwram_end); |
---|
108 | printk("__load_start_iwram = 0x%x\n", (uint32_t)&__load_start_iwram); |
---|
109 | printk("__load_stop_iwram = 0x%x\n", (uint32_t)&__load_stop_iwram); |
---|
110 | printk("__load_start_ewram = 0x%x\n", (uint32_t)&__load_start_ewram); |
---|
111 | printk("__load_stop_ewram = 0x%x\n", (uint32_t)&__load_stop_ewram); |
---|
112 | printk("__load_start_data = 0x%x\n", (uint32_t)&__load_start_data); |
---|
113 | printk("__load_stop_data = 0x%x\n", (uint32_t)&__load_stop_data); |
---|
114 | #endif |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | /** |
---|
119 | * @brief BSP Start |
---|
120 | * |
---|
121 | * Called before main is invoked. |
---|
122 | * |
---|
123 | * @param None |
---|
124 | * @return None |
---|
125 | */ |
---|
126 | void bsp_start_default( void ) |
---|
127 | { |
---|
128 | /* set the value of start of free memory. */ |
---|
129 | rtemsFreeMemStart = (uint32_t)&_end; |
---|
130 | |
---|
131 | /* Place RTEMS workspace at beginning of free memory. */ |
---|
132 | Configuration.work_space_start = (void *)rtemsFreeMemStart; |
---|
133 | rtemsFreeMemStart += rtems_configuration_get_work_space_size(); |
---|
134 | |
---|
135 | /* Init conio */ |
---|
136 | gba_textmode(CO60); |
---|
137 | |
---|
138 | /* Init rtems exceptions management */ |
---|
139 | /*!!!!!GBA - Can't use exception vectors in GBA because they are already in GBA ROM BIOS */ |
---|
140 | /* rtems_exception_init_mngt(); */ |
---|
141 | |
---|
142 | /* Init rtems interrupt management */ |
---|
143 | rtems_irq_mngt_init(); |
---|
144 | |
---|
145 | #if BSP_DEBUG |
---|
146 | /* The following information is very useful when debugging. */ |
---|
147 | printk("[bsp_start]\n"); |
---|
148 | printk("rtemsFreeMemStart= 0x%x\n", rtemsFreeMemStart); |
---|
149 | printk("__heap_limit = 0x%x\n", (uint32_t)&__heap_limit); |
---|
150 | printk("work_space_start = 0x%x size = 0x%x\n", |
---|
151 | Configuration.work_space_start, |
---|
152 | rtems_configuration_get_work_space_size()); |
---|
153 | printk("microseconds_per_tick = 0x%x\n", |
---|
154 | rtems_configuration_get_microseconds_per_tick()); |
---|
155 | printk("ticks_per_timeslice = 0x%x\n", |
---|
156 | rtems_configuration_get_ticks_per_timeslice()); |
---|
157 | #endif |
---|
158 | |
---|
159 | /* Do we have enough memory */ |
---|
160 | if ((uint32_t)&__heap_limit < rtemsFreeMemStart) { |
---|
161 | printk("\nFatal Error: Memory overflow[0x%x]!\n",rtemsFreeMemStart); |
---|
162 | bsp_cleanup(); |
---|
163 | } |
---|
164 | |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | /** |
---|
169 | * @brief weak alias for bsp_start_default |
---|
170 | * |
---|
171 | * By making this a weak alias for bsp_start_default, a brave soul |
---|
172 | * can override the actual bsp_start routine used. |
---|
173 | */ |
---|
174 | void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default"))); |
---|