1 | /* |
---|
2 | * This routine starts the application. It includes application, |
---|
3 | * board, and monitor specific initialization and configuration. |
---|
4 | * The generic CPU dependent initialization has been performed |
---|
5 | * before this routine is invoked. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Author: Thomas Doerfler <td@imd.m.isar.de> |
---|
10 | * IMD Ingenieurbuero fuer Microcomputertechnik |
---|
11 | * |
---|
12 | * COPYRIGHT (c) 1998 by IMD |
---|
13 | * |
---|
14 | * Changes from IMD are covered by the original distributions terms. |
---|
15 | * This file has been derived from the papyrus BSP: |
---|
16 | * |
---|
17 | * Author: Andrew Bray <andy@i-cubed.co.uk> |
---|
18 | * |
---|
19 | * COPYRIGHT (c) 1995 by i-cubed ltd. |
---|
20 | * |
---|
21 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
22 | * without any express or implied warranty: |
---|
23 | * permission to use, copy, modify, and distribute this file |
---|
24 | * for any purpose is hereby granted without fee, provided that |
---|
25 | * the above copyright notice and this notice appears in all |
---|
26 | * copies, and that the name of i-cubed limited not be used in |
---|
27 | * advertising or publicity pertaining to distribution of the |
---|
28 | * software without specific, written prior permission. |
---|
29 | * i-cubed limited makes no representations about the suitability |
---|
30 | * of this software for any purpose. |
---|
31 | * |
---|
32 | * Modifications for spooling console driver and control of memory layout |
---|
33 | * with linker command file by |
---|
34 | * Thomas Doerfler <td@imd.m.isar.de> |
---|
35 | * for these modifications: |
---|
36 | * COPYRIGHT (c) 1997 by IMD, Puchheim, Germany. |
---|
37 | * |
---|
38 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
39 | * without any express or implied warranty: |
---|
40 | * permission to use, copy, modify, and distribute this file |
---|
41 | * for any purpose is hereby granted without fee, provided that |
---|
42 | * the above copyright notice and this notice appears in all |
---|
43 | * copies. IMD makes no representations about the suitability |
---|
44 | * of this software for any purpose. |
---|
45 | * |
---|
46 | * Derived from c/src/lib/libbsp/no_cpu/no_bsp/startup/bspstart.c: |
---|
47 | * |
---|
48 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
49 | * On-Line Applications Research Corporation (OAR). |
---|
50 | * |
---|
51 | * Modifications for PPC405GP by Dennis Ehlin |
---|
52 | * Modifications for Virtex4 by Richard Claus <claus@slac.stanford.edu> |
---|
53 | */ |
---|
54 | #include <rtems.h> |
---|
55 | #include <rtems/config.h> |
---|
56 | #include <rtems/bspIo.h> |
---|
57 | #include <rtems/counter.h> |
---|
58 | #include <rtems/libio.h> |
---|
59 | #include <rtems/libcsupport.h> |
---|
60 | #include <rtems/sysinit.h> |
---|
61 | |
---|
62 | #include <libcpu/cpuIdent.h> |
---|
63 | #include <libcpu/spr.h> |
---|
64 | |
---|
65 | #include <bsp.h> |
---|
66 | #include <bsp/vectors.h> |
---|
67 | #include <bsp/bootcard.h> |
---|
68 | #include <bsp/irq.h> |
---|
69 | |
---|
70 | #include <string.h> |
---|
71 | #include <fcntl.h> |
---|
72 | #include <inttypes.h> |
---|
73 | |
---|
74 | #define DO_DOWN_ALIGN(x,a) ((x) & ~((a)-1)) |
---|
75 | |
---|
76 | #define DO_UP_ALIGN(x,a) DO_DOWN_ALIGN(((x) + (a) - 1 ),a) |
---|
77 | |
---|
78 | #define CPU_DOWN_ALIGN(x) DO_DOWN_ALIGN(x, CPU_ALIGNMENT) |
---|
79 | #define CPU_UP_ALIGN(x) DO_UP_ALIGN(x, CPU_ALIGNMENT) |
---|
80 | |
---|
81 | |
---|
82 | /* Defined in linkcmds linker script */ |
---|
83 | LINKER_SYMBOL(RamBase); |
---|
84 | LINKER_SYMBOL(RamSize); |
---|
85 | LINKER_SYMBOL(__bsp_ram_start); |
---|
86 | LINKER_SYMBOL(__bsp_ram_end); |
---|
87 | LINKER_SYMBOL(__rtems_end); |
---|
88 | LINKER_SYMBOL(WorkAreaBase); |
---|
89 | LINKER_SYMBOL(MsgAreaBase); |
---|
90 | LINKER_SYMBOL(MsgAreaSize); |
---|
91 | LINKER_SYMBOL(__phy_ram_end); |
---|
92 | LINKER_SYMBOL(bsp_exc_vector_base); |
---|
93 | |
---|
94 | |
---|
95 | /* Expected by clock.c */ |
---|
96 | uint32_t bsp_clicks_per_usec; |
---|
97 | |
---|
98 | |
---|
99 | /* |
---|
100 | * Provide weak aliases so that RTEMS distribution builds |
---|
101 | */ |
---|
102 | static void _noopfun(void) {} |
---|
103 | |
---|
104 | |
---|
105 | void app_bsp_start(void) |
---|
106 | __attribute__(( weak, alias("_noopfun") )); |
---|
107 | |
---|
108 | void app_bsp_predriver_hook(void) |
---|
109 | __attribute__(( weak, alias("_noopfun") )); |
---|
110 | |
---|
111 | |
---|
112 | static char* bspMsgBuffer = (char*)MsgAreaBase; |
---|
113 | |
---|
114 | static void __bsp_outchar_to_memory(char c) |
---|
115 | { |
---|
116 | static char* msgBuffer = (char*)MsgAreaBase; |
---|
117 | *msgBuffer++ = c; |
---|
118 | if (msgBuffer >= &bspMsgBuffer[(int)MsgAreaSize]) msgBuffer = bspMsgBuffer; |
---|
119 | *msgBuffer = 0x00; /* Overwrite next location to show EOM */ |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | void BSP_ask_for_reset(void) |
---|
124 | { |
---|
125 | printk("\nSystem stopped, issue RESET"); |
---|
126 | |
---|
127 | for(;;); |
---|
128 | } |
---|
129 | |
---|
130 | uint32_t _CPU_Counter_frequency(void) |
---|
131 | { |
---|
132 | return bsp_clicks_per_usec * 1000000; |
---|
133 | } |
---|
134 | |
---|
135 | /*===================================================================*/ |
---|
136 | |
---|
137 | /* |
---|
138 | * BSP start routine. Called by boot_card(). |
---|
139 | * |
---|
140 | * This routine does the bulk of the system initialization. |
---|
141 | */ |
---|
142 | void bsp_start(void) |
---|
143 | { |
---|
144 | ppc_cpu_id_t myCpu; |
---|
145 | ppc_cpu_revision_t myCpuRevision; |
---|
146 | |
---|
147 | /* Set the character output function; The application may override this */ |
---|
148 | BSP_output_char = __bsp_outchar_to_memory; |
---|
149 | |
---|
150 | printk("RTEMS %s\n", rtems_get_version_string()); |
---|
151 | |
---|
152 | /* |
---|
153 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() |
---|
154 | * function stores the result in global variables so that it can be used later... |
---|
155 | */ |
---|
156 | myCpu = get_ppc_cpu_type(); |
---|
157 | myCpuRevision = get_ppc_cpu_revision(); |
---|
158 | printk("CPU: 0x%04x, Revision: 0x%04x = %d, Name: %s\n", |
---|
159 | myCpu, myCpuRevision, myCpuRevision, get_ppc_cpu_type_name(myCpu)); |
---|
160 | |
---|
161 | /* |
---|
162 | * Initialize the device driver parameters |
---|
163 | */ |
---|
164 | |
---|
165 | /* Timebase register ticks/microsecond; The application may override these */ |
---|
166 | bsp_clicks_per_usec = 350; |
---|
167 | |
---|
168 | ppc_exc_initialize(); |
---|
169 | |
---|
170 | /* Let the user know what parameters we were compiled with */ |
---|
171 | printk(" Base/Start End Size\n" |
---|
172 | "RAM: %p %p\n" |
---|
173 | "RTEMS: %p\n" |
---|
174 | "Workspace: %p %p\n" |
---|
175 | "MsgArea: %p %p\n" |
---|
176 | "Physical RAM %p\n", |
---|
177 | RamBase, RamSize, |
---|
178 | __rtems_end, |
---|
179 | WorkAreaBase, __bsp_ram_end, |
---|
180 | MsgAreaBase, MsgAreaSize, |
---|
181 | __phy_ram_end); |
---|
182 | |
---|
183 | /* |
---|
184 | * Initialize RTEMS IRQ system |
---|
185 | */ |
---|
186 | BSP_rtems_irq_mngt_init(0); |
---|
187 | |
---|
188 | /* Continue with application-specific initialization */ |
---|
189 | app_bsp_start(); |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | /* |
---|
194 | * BSP predriver hook. Called by boot_card() just before drivers are |
---|
195 | * initialized. Clear out any stale interrupts here. |
---|
196 | */ |
---|
197 | static void virtex4_pre_driver_hook(void) |
---|
198 | { |
---|
199 | app_bsp_predriver_hook(); |
---|
200 | } |
---|
201 | |
---|
202 | RTEMS_SYSINIT_ITEM( |
---|
203 | virtex4_pre_driver_hook, |
---|
204 | RTEMS_SYSINIT_BSP_PRE_DRIVERS, |
---|
205 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
206 | ); |
---|