1 | /* |
---|
2 | * This set of routines 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 any of these are invoked. |
---|
6 | * |
---|
7 | * COPYRIGHT (c) 1989-2007. |
---|
8 | * On-Line Applications Research Corporation (OAR). |
---|
9 | * |
---|
10 | * Modified for LEON3 BSP. |
---|
11 | * COPYRIGHT (c) 2004. |
---|
12 | * Gaisler Research. |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.com/license/LICENSE. |
---|
17 | * |
---|
18 | * $Id$ |
---|
19 | */ |
---|
20 | |
---|
21 | /* must be identical to STACK_SIZE in start.S */ |
---|
22 | #define STACK_SIZE 16 * 1024 |
---|
23 | |
---|
24 | #include <string.h> |
---|
25 | |
---|
26 | #include <bsp.h> |
---|
27 | #include <rtems/bspIo.h> |
---|
28 | |
---|
29 | /* |
---|
30 | * The original table from the application and our copy of it with |
---|
31 | * some changes. |
---|
32 | */ |
---|
33 | |
---|
34 | extern rtems_configuration_table Configuration; |
---|
35 | rtems_configuration_table BSP_Configuration; |
---|
36 | |
---|
37 | rtems_cpu_table Cpu_table; |
---|
38 | |
---|
39 | /* |
---|
40 | * Tells us where to put the workspace in case remote debugger is present. |
---|
41 | */ |
---|
42 | |
---|
43 | extern uint32_t rdb_start; |
---|
44 | |
---|
45 | /* |
---|
46 | * Tells us if data cache snooping is available |
---|
47 | */ |
---|
48 | |
---|
49 | int CPU_SPARC_HAS_SNOOPING; |
---|
50 | |
---|
51 | void bsp_postdriver_hook(void); |
---|
52 | void bsp_libc_init( void *, uint32_t, int ); |
---|
53 | extern void bsp_spurious_initialize(); |
---|
54 | |
---|
55 | /* |
---|
56 | * set_snooping |
---|
57 | * |
---|
58 | * Read the data cache configuration register to determine if |
---|
59 | * bus snooping is available. This is needed for some drivers so |
---|
60 | * that they can select the most efficient copy routines. |
---|
61 | * |
---|
62 | */ |
---|
63 | |
---|
64 | static inline int set_snooping(void) |
---|
65 | { |
---|
66 | int tmp; |
---|
67 | asm(" lda [%1] 2, %0 " |
---|
68 | : "=r"(tmp) |
---|
69 | : "r"(0xC) |
---|
70 | ); |
---|
71 | return (tmp >> 27) & 1; |
---|
72 | } |
---|
73 | |
---|
74 | /* |
---|
75 | * bsp_pretasking_hook |
---|
76 | * |
---|
77 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
78 | * Used to setup libc and install any BSP extensions. |
---|
79 | */ |
---|
80 | |
---|
81 | void bsp_pretasking_hook(void) |
---|
82 | { |
---|
83 | extern int end; |
---|
84 | uint32_t heap_start; |
---|
85 | uint32_t heap_size; |
---|
86 | |
---|
87 | heap_start = (uint32_t) &end; |
---|
88 | if (heap_start & (CPU_ALIGNMENT-1)) |
---|
89 | heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
90 | |
---|
91 | heap_size = BSP_Configuration.work_space_start - (void *)&end - STACK_SIZE; |
---|
92 | heap_size &= 0xfffffff0; /* keep it as a multiple of 16 bytes */ |
---|
93 | |
---|
94 | bsp_libc_init((void *) heap_start, heap_size, 0); |
---|
95 | |
---|
96 | #ifdef RTEMS_DEBUG |
---|
97 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
98 | #endif |
---|
99 | |
---|
100 | bsp_spurious_initialize(); |
---|
101 | } |
---|
102 | |
---|
103 | void bsp_leon3_predriver_hook(void); |
---|
104 | |
---|
105 | /* |
---|
106 | * bsp_start |
---|
107 | * |
---|
108 | * This routine does the bulk of the system initialization. |
---|
109 | */ |
---|
110 | |
---|
111 | void bsp_start( void ) |
---|
112 | { |
---|
113 | unsigned char *work_space_start; |
---|
114 | |
---|
115 | /* |
---|
116 | * Set up our hooks |
---|
117 | * Make sure libc_init is done before drivers initialized so that |
---|
118 | * they can use atexit() |
---|
119 | */ |
---|
120 | |
---|
121 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
122 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
123 | Cpu_table.predriver_hook = bsp_leon3_predriver_hook; /* scan system bus */ |
---|
124 | |
---|
125 | /* |
---|
126 | * This should be enough interrupt stack. |
---|
127 | */ |
---|
128 | |
---|
129 | Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY; |
---|
130 | |
---|
131 | work_space_start = |
---|
132 | (unsigned char *)rdb_start - BSP_Configuration.work_space_size; |
---|
133 | |
---|
134 | if ( work_space_start <= (unsigned char *)&end ) { |
---|
135 | printk( "bspstart: Not enough RAM!!!\n" ); |
---|
136 | BSP_fatal_return(); |
---|
137 | } |
---|
138 | |
---|
139 | BSP_Configuration.work_space_start = work_space_start; |
---|
140 | |
---|
141 | CPU_SPARC_HAS_SNOOPING = set_snooping(); |
---|
142 | } |
---|