1 | /*-------------------------------------------------------------------------+ |
---|
2 | | This file contains the PC386 BSP startup package. It includes application, |
---|
3 | | board, and monitor specific initialization and configuration. The generic CPU |
---|
4 | | dependent initialization has been performed before this routine is invoked. |
---|
5 | +--------------------------------------------------------------------------+ |
---|
6 | | (C) Copyright 1997 - |
---|
7 | | - NavIST Group - Real-Time Distributed Systems and Industrial Automation |
---|
8 | | |
---|
9 | | http://pandora.ist.utl.pt |
---|
10 | | |
---|
11 | | Instituto Superior Tecnico * Lisboa * PORTUGAL |
---|
12 | +--------------------------------------------------------------------------+ |
---|
13 | | Disclaimer: |
---|
14 | | |
---|
15 | | This file is provided "AS IS" without warranty of any kind, either |
---|
16 | | expressed or implied. |
---|
17 | +--------------------------------------------------------------------------+ |
---|
18 | | This code is based on: |
---|
19 | | bspstart.c,v 1.8 1996/05/28 13:12:40 joel Exp - go32 BSP |
---|
20 | | With the following copyright notice: |
---|
21 | | ************************************************************************** |
---|
22 | | * COPYRIGHT (c) 1989-1998. |
---|
23 | | * On-Line Applications Research Corporation (OAR). |
---|
24 | | * Copyright assigned to U.S. Government, 1994. |
---|
25 | | * |
---|
26 | | * The license and distribution terms for this file may be |
---|
27 | | * found in found in the file LICENSE in this distribution or at |
---|
28 | | * http://www.OARcorp.com/rtems/license.html. |
---|
29 | | ************************************************************************** |
---|
30 | | |
---|
31 | | $Id$ |
---|
32 | +--------------------------------------------------------------------------*/ |
---|
33 | |
---|
34 | |
---|
35 | #include <bsp.h> |
---|
36 | #include <libcsupport.h> |
---|
37 | #include <rtems/libio.h> |
---|
38 | #include <libcpu/cpuModel.h> |
---|
39 | #include <pc386uart.h> |
---|
40 | |
---|
41 | /*-------------------------------------------------------------------------+ |
---|
42 | | Global Variables |
---|
43 | +--------------------------------------------------------------------------*/ |
---|
44 | extern rtems_unsigned32 _end; /* End of BSS. Defined in 'linkcmds'. */ |
---|
45 | /* |
---|
46 | * Size of heap if it is 0 it will be dynamically defined by memory size, |
---|
47 | * otherwise the value should be changed by binary patch |
---|
48 | */ |
---|
49 | rtems_unsigned32 _heap_size = 0; |
---|
50 | |
---|
51 | /* Size of stack used during initialization. Defined in 'start.s'. */ |
---|
52 | extern rtems_unsigned32 _stack_size; |
---|
53 | |
---|
54 | rtems_unsigned32 rtemsFreeMemStart; |
---|
55 | /* Address of start of free memory - should be updated |
---|
56 | after creating new partitions or regions. */ |
---|
57 | |
---|
58 | /* The original BSP configuration table from the application and our copy of it |
---|
59 | with some changes. */ |
---|
60 | |
---|
61 | extern rtems_configuration_table Configuration; |
---|
62 | rtems_configuration_table BSP_Configuration; |
---|
63 | |
---|
64 | rtems_cpu_table Cpu_table; /* CPU configuration table. */ |
---|
65 | char *rtems_progname; /* Program name - from main(). */ |
---|
66 | |
---|
67 | extern void debugPollingGetChar(); |
---|
68 | |
---|
69 | /*-------------------------------------------------------------------------+ |
---|
70 | | External Prototypes |
---|
71 | +--------------------------------------------------------------------------*/ |
---|
72 | extern void _exit(int); /* define in exit.c */ |
---|
73 | void bsp_libc_init( void *, unsigned32, int ); |
---|
74 | void bsp_postdriver_hook(void); |
---|
75 | extern void rtems_irq_mngt_init(); |
---|
76 | extern void _IBMPC_initVideo(void); |
---|
77 | |
---|
78 | /*-------------------------------------------------------------------------+ |
---|
79 | | Function: bsp_pretasking_hook |
---|
80 | | Description: BSP pretasking hook. Called just before drivers are |
---|
81 | | initialized. Used to setup libc and install any BSP |
---|
82 | | extensions. NOTE: Must not use libc (to do io) from here, |
---|
83 | | since drivers are not yet initialized. |
---|
84 | | Global Variables: None. |
---|
85 | | Arguments: None. |
---|
86 | | Returns: Nothing. |
---|
87 | +--------------------------------------------------------------------------*/ |
---|
88 | void bsp_pretasking_hook(void) |
---|
89 | { |
---|
90 | rtems_unsigned32 topAddr, val; |
---|
91 | int i; |
---|
92 | |
---|
93 | |
---|
94 | if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1)) /* not aligned => align it */ |
---|
95 | rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
96 | |
---|
97 | if(_heap_size == 0) |
---|
98 | { |
---|
99 | /* |
---|
100 | * We have to dynamically size memory. Memory size can be anything |
---|
101 | * between 2M and 2048M. |
---|
102 | * let us first write |
---|
103 | */ |
---|
104 | for(i=2048; i>=2; i--) |
---|
105 | { |
---|
106 | topAddr = i*1024*1024 - 4; |
---|
107 | *(volatile rtems_unsigned32 *)topAddr = topAddr; |
---|
108 | } |
---|
109 | |
---|
110 | printk("\n"); |
---|
111 | |
---|
112 | for(i=2; i<=2048; i++) |
---|
113 | { |
---|
114 | topAddr = i*1024*1024 - 4; |
---|
115 | val = *(rtems_unsigned32 *)topAddr; |
---|
116 | if(val != topAddr) |
---|
117 | { |
---|
118 | break; |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | topAddr = (i-1)*1024*1024 - 4; |
---|
123 | |
---|
124 | _heap_size = topAddr - rtemsFreeMemStart; |
---|
125 | } |
---|
126 | |
---|
127 | bsp_libc_init((void *)rtemsFreeMemStart, _heap_size, 0); |
---|
128 | rtemsFreeMemStart += _heap_size; /* HEAP_SIZE in KBytes */ |
---|
129 | |
---|
130 | |
---|
131 | #ifdef RTEMS_DEBUG |
---|
132 | |
---|
133 | rtems_debug_enable(RTEMS_DEBUG_ALL_MASK); |
---|
134 | |
---|
135 | #endif /* RTEMS_DEBUG */ |
---|
136 | } /* bsp_pretasking_hook */ |
---|
137 | |
---|
138 | |
---|
139 | /*-------------------------------------------------------------------------+ |
---|
140 | | Function: bsp_start |
---|
141 | | Description: Called before main is invoked. |
---|
142 | | Global Variables: None. |
---|
143 | | Arguments: None. |
---|
144 | | Returns: Nothing. |
---|
145 | +--------------------------------------------------------------------------*/ |
---|
146 | void bsp_start( void ) |
---|
147 | { |
---|
148 | |
---|
149 | /* |
---|
150 | * Calibrate variable for 1ms-loop (see timer.c) |
---|
151 | */ |
---|
152 | Calibrate_loop_1ms(); |
---|
153 | /* |
---|
154 | * Initialize printk channel |
---|
155 | */ |
---|
156 | _IBMPC_initVideo(); |
---|
157 | |
---|
158 | rtemsFreeMemStart = (rtems_unsigned32)&_end + _stack_size; |
---|
159 | /* set the value of start of free memory. */ |
---|
160 | |
---|
161 | /* If we don't have command line arguments set default program name. */ |
---|
162 | |
---|
163 | Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */ |
---|
164 | Cpu_table.predriver_hook = NULL; /* use system's */ |
---|
165 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
166 | Cpu_table.idle_task = NULL; |
---|
167 | /* do not override system IDLE task */ |
---|
168 | Cpu_table.do_zero_of_workspace = TRUE; |
---|
169 | Cpu_table.interrupt_table_segment = get_ds(); |
---|
170 | Cpu_table.interrupt_table_offset = (void *)Interrupt_descriptor_table; |
---|
171 | Cpu_table.interrupt_stack_size = 4096; |
---|
172 | Cpu_table.extra_mpci_receive_server_stack = 0; |
---|
173 | |
---|
174 | /* Place RTEMS workspace at beginning of free memory. */ |
---|
175 | |
---|
176 | if (rtemsFreeMemStart & (CPU_ALIGNMENT - 1)) /* not aligned => align it */ |
---|
177 | rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); |
---|
178 | |
---|
179 | BSP_Configuration.work_space_start = (void *)rtemsFreeMemStart; |
---|
180 | rtemsFreeMemStart += BSP_Configuration.work_space_size; |
---|
181 | |
---|
182 | console_reserve_resources(&BSP_Configuration); |
---|
183 | |
---|
184 | /* |
---|
185 | * Init rtems interrupt management |
---|
186 | */ |
---|
187 | rtems_irq_mngt_init(); |
---|
188 | /* |
---|
189 | * Init rtems exceptions management |
---|
190 | */ |
---|
191 | rtems_exception_init_mngt(); |
---|
192 | /* |
---|
193 | * The following information is very useful when debugging. |
---|
194 | */ |
---|
195 | |
---|
196 | #if 0 |
---|
197 | printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size ); |
---|
198 | printk( "maximum_extensions = 0x%x\n", BSP_Configuration.maximum_extensions ); |
---|
199 | printk( "microseconds_per_tick = 0x%x\n", |
---|
200 | BSP_Configuration.microseconds_per_tick ); |
---|
201 | printk( "ticks_per_timeslice = 0x%x\n", |
---|
202 | BSP_Configuration.ticks_per_timeslice ); |
---|
203 | printk( "maximum_devices = 0x%x\n", BSP_Configuration.maximum_devices ); |
---|
204 | printk( "number_of_device_drivers = 0x%x\n", |
---|
205 | BSP_Configuration.number_of_device_drivers ); |
---|
206 | printk( "Device_driver_table = 0x%x\n", |
---|
207 | BSP_Configuration.Device_driver_table ); |
---|
208 | |
---|
209 | printk( "_heap_size = 0x%x\n", _heap_size ); |
---|
210 | printk( "_stack_size = 0x%x\n", _stack_size ); |
---|
211 | printk( "rtemsFreeMemStart = 0x%x\n", rtemsFreeMemStart ); |
---|
212 | printk( "work_space_start = 0x%x\n", BSP_Configuration.work_space_start ); |
---|
213 | printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size ); |
---|
214 | #endif |
---|
215 | } /* bsp_start */ |
---|