1 |
1026 |
ivang |
@c
|
2 |
|
|
@c COPYRIGHT (c) 1988-2002.
|
3 |
|
|
@c On-Line Applications Research Corporation (OAR).
|
4 |
|
|
@c All rights reserved.
|
5 |
|
|
@c
|
6 |
|
|
@c cpuinit.t,v 1.5 2002/01/17 21:47:45 joel Exp
|
7 |
|
|
@c
|
8 |
|
|
|
9 |
|
|
@chapter CPU Initialization
|
10 |
|
|
|
11 |
|
|
This section describes the general CPU and system initialization sequence
|
12 |
|
|
as it pertains to the CPU dependent code.
|
13 |
|
|
|
14 |
|
|
@section Introduction
|
15 |
|
|
|
16 |
|
|
XXX general startup sequence description rewritten to make it more
|
17 |
|
|
applicable to CPU depdent code in executive
|
18 |
|
|
|
19 |
|
|
@section CPU Dependent Configuration Table
|
20 |
|
|
|
21 |
|
|
The CPU Dependent Configuration Table contains information which tailors
|
22 |
|
|
the behavior of RTEMS base Some of the fields in this table are required
|
23 |
|
|
to be present in all ports of RTEMS. These fields appear at the beginning
|
24 |
|
|
of the data structure. Fields past this point may be CPU family and CPU
|
25 |
|
|
model dependent. For example, a port may add a field to specify the
|
26 |
|
|
default value for an interrupt mask register on the CPU. This table is
|
27 |
|
|
initialized by the Board Support Package and passed to the
|
28 |
|
|
rtems_initialize_executive or rtems_initialize_executive_early directive.
|
29 |
|
|
|
30 |
|
|
@example
|
31 |
|
|
typedef struct @{
|
32 |
|
|
void (*pretasking_hook)( void );
|
33 |
|
|
void (*predriver_hook)( void );
|
34 |
|
|
void (*postdriver_hook)( void );
|
35 |
|
|
void (*idle_task)( void );
|
36 |
|
|
boolean do_zero_of_workspace;
|
37 |
|
|
unsigned32 idle_task_stack_size;
|
38 |
|
|
unsigned32 interrupt_stack_size;
|
39 |
|
|
unsigned32 extra_mpci_receive_server_stack;
|
40 |
|
|
void * (*stack_allocate_hook)( unsigned32 );
|
41 |
|
|
void (*stack_free_hook)( void* );
|
42 |
|
|
/* end of fields required on all CPUs */
|
43 |
|
|
|
44 |
|
|
unsigned32 some_other_cpu_dependent_info;
|
45 |
|
|
@} rtems_cpu_table;
|
46 |
|
|
@end example
|
47 |
|
|
|
48 |
|
|
@table @code
|
49 |
|
|
@item pretasking_hook
|
50 |
|
|
is the address of the user provided routine which is invoked
|
51 |
|
|
once RTEMS APIs are initialized. This routine will be invoked
|
52 |
|
|
before any system tasks are created. Interrupts are disabled.
|
53 |
|
|
This field may be NULL to indicate that the hook is not utilized.
|
54 |
|
|
|
55 |
|
|
@item predriver_hook
|
56 |
|
|
is the address of the user provided
|
57 |
|
|
routine that is invoked immediately before the
|
58 |
|
|
the device drivers and MPCI are initialized. RTEMS
|
59 |
|
|
initialization is complete but interrupts and tasking are disabled.
|
60 |
|
|
This field may be NULL to indicate that the hook is not utilized.
|
61 |
|
|
|
62 |
|
|
@item postdriver_hook
|
63 |
|
|
is the address of the user provided
|
64 |
|
|
routine that is invoked immediately after the
|
65 |
|
|
the device drivers and MPCI are initialized. RTEMS
|
66 |
|
|
initialization is complete but interrupts and tasking are disabled.
|
67 |
|
|
This field may be NULL to indicate that the hook is not utilized.
|
68 |
|
|
|
69 |
|
|
@item idle_task
|
70 |
|
|
is the address of the optional user
|
71 |
|
|
provided routine which is used as the system's IDLE task. If
|
72 |
|
|
this field is not NULL, then the RTEMS default IDLE task is not
|
73 |
|
|
used. This field may be NULL to indicate that the default IDLE
|
74 |
|
|
is to be used.
|
75 |
|
|
|
76 |
|
|
@item do_zero_of_workspace
|
77 |
|
|
indicates whether RTEMS should
|
78 |
|
|
zero the Workspace as part of its initialization. If set to
|
79 |
|
|
TRUE, the Workspace is zeroed. Otherwise, it is not.
|
80 |
|
|
|
81 |
|
|
@item idle_task_stack_size
|
82 |
|
|
is the size of the RTEMS idle task stack in bytes.
|
83 |
|
|
If this number is less than MINIMUM_STACK_SIZE, then the
|
84 |
|
|
idle task's stack will be MINIMUM_STACK_SIZE in byte.
|
85 |
|
|
|
86 |
|
|
@item interrupt_stack_size
|
87 |
|
|
is the size of the RTEMS allocated interrupt stack in bytes.
|
88 |
|
|
This value must be at least as large as MINIMUM_STACK_SIZE.
|
89 |
|
|
|
90 |
|
|
@item extra_mpci_receive_server_stack
|
91 |
|
|
is the extra stack space allocated for the RTEMS MPCI receive server task
|
92 |
|
|
in bytes. The MPCI receive server may invoke nearly all directives and
|
93 |
|
|
may require extra stack space on some targets.
|
94 |
|
|
|
95 |
|
|
@item stack_allocate_hook
|
96 |
|
|
is the address of the optional user provided routine which allocates
|
97 |
|
|
memory for task stacks. If this hook is not NULL, then a stack_free_hook
|
98 |
|
|
must be provided as well.
|
99 |
|
|
|
100 |
|
|
@item stack_free_hook
|
101 |
|
|
is the address of the optional user provided routine which frees
|
102 |
|
|
memory for task stacks. If this hook is not NULL, then a stack_allocate_hook
|
103 |
|
|
must be provided as well.
|
104 |
|
|
|
105 |
|
|
@end table
|
106 |
|
|
|
107 |
|
|
@section Initializing the CPU
|
108 |
|
|
|
109 |
|
|
The _CPU_Initialize routine performs processor dependent initialization.
|
110 |
|
|
|
111 |
|
|
@example
|
112 |
|
|
void _CPU_Initialize(
|
113 |
|
|
rtems_cpu_table *cpu_table,
|
114 |
|
|
void (*thread_dispatch) /* may be ignored */
|
115 |
|
|
)
|
116 |
|
|
@end example
|
117 |
|
|
|
118 |
|
|
The thread_dispatch argument is the address of the entry point for the
|
119 |
|
|
routine called at the end of an ISR once it has been decided a context
|
120 |
|
|
switch is necessary. On some compilation systems it is difficult to call
|
121 |
|
|
a high-level language routine from assembly. Providing the address of the
|
122 |
|
|
_Thread_ISR_Dispatch routine allows the porter an easy way to obtain this
|
123 |
|
|
critical address and thus provides an easy way to work around this
|
124 |
|
|
limitation on these systems.
|
125 |
|
|
|
126 |
|
|
If you encounter this problem save the entry point in a CPU dependent
|
127 |
|
|
variable as shown below:
|
128 |
|
|
|
129 |
|
|
@example
|
130 |
|
|
_CPU_Thread_dispatch_pointer = thread_dispatch;
|
131 |
|
|
@end example
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
During the initialization of the context for tasks with floating point,
|
135 |
|
|
the CPU dependent code is responsible for initializing the floating point
|
136 |
|
|
context. If there is not an easy way to initialize the FP context during
|
137 |
|
|
Context_Initialize, then it is usually easier to save an "uninitialized"
|
138 |
|
|
FP context here and copy it to the task's during Context_Initialize. If
|
139 |
|
|
this technique is used to initialize the FP contexts, then it is important
|
140 |
|
|
to ensure that the state of the floating point unit is in a coherent,
|
141 |
|
|
initialized state.
|
142 |
|
|
|
143 |
|
|
Finally, this routine is responsible for copying the application's CPU
|
144 |
|
|
Table into a locally accessible and modifiable area. This is shown below:
|
145 |
|
|
|
146 |
|
|
@example
|
147 |
|
|
_CPU_Table = *cpu_table;
|
148 |
|
|
@end example
|
149 |
|
|
|
150 |
|
|
|