source: rtems/cpukit/score/src/threadinitialize.c @ ca7858bb

4.104.114.84.95
Last change on this file since ca7858bb was ca7858bb, checked in by Joel Sherrill <joel.sherrill@…>, on 07/26/00 at 19:28:11

Port of RTEMS to the Texas Instruments C3x/C4x DSP families including
a BSP (c4xsim) supporting the simulator included with gdb. This port
was done by Joel Sherrill and Jennifer Averett of OAR Corporation.
Also included with this port is a space/time optimization to eliminate
FP context switch management on CPUs without hardware or software FP.

An issue with this port was that sizeof(unsigned32) = sizeof(unsigned8)
on this CPU. This required addressing alignment checks and assumptions
as well as fixing code that assumed sizeof(unsigned32) == 4.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <rtems/system.h>
16#include <rtems/score/apiext.h>
17#include <rtems/score/context.h>
18#include <rtems/score/interr.h>
19#include <rtems/score/isr.h>
20#include <rtems/score/object.h>
21#include <rtems/score/priority.h>
22#include <rtems/score/states.h>
23#include <rtems/score/sysstate.h>
24#include <rtems/score/thread.h>
25#include <rtems/score/threadq.h>
26#include <rtems/score/userext.h>
27#include <rtems/score/wkspace.h>
28
29/*PAGE
30 *
31 *  _Thread_Initialize
32 *
33 *  This routine initializes the specified the thread.  It allocates
34 *  all memory associated with this thread.  It completes by adding
35 *  the thread to the local object table so operations on this
36 *  thread id are allowed.
37 */
38
39boolean _Thread_Initialize(
40  Objects_Information                  *information,
41  Thread_Control                       *the_thread,
42  void                                 *stack_area,
43  unsigned32                            stack_size,
44  boolean                               is_fp,
45  Priority_Control                      priority,
46  boolean                               is_preemptible,
47  Thread_CPU_budget_algorithms          budget_algorithm,
48  Thread_CPU_budget_algorithm_callout   budget_callout,
49  unsigned32                            isr_level,
50  Objects_Name                          name
51)
52{
53  unsigned32           actual_stack_size = 0;
54  void                *stack = NULL;
55  void                *fp_area;
56  void                *extensions_area;
57
58  /*
59   *  Initialize the Ada self pointer
60   */
61
62  the_thread->rtems_ada_self = NULL;
63
64  /*
65   *  Allocate and Initialize the stack for this thread.
66   */
67
68
69  if ( !stack_area ) {
70    if ( !_Stack_Is_enough( stack_size ) )
71      actual_stack_size = STACK_MINIMUM_SIZE;
72    else
73      actual_stack_size = stack_size;
74
75    actual_stack_size = _Thread_Stack_Allocate( the_thread, actual_stack_size );
76 
77    if ( !actual_stack_size )
78      return FALSE;                     /* stack allocation failed */
79
80    stack = the_thread->Start.stack;
81    the_thread->Start.core_allocated_stack = TRUE;
82  } else {
83    stack = stack_area;
84    actual_stack_size = stack_size;
85    the_thread->Start.core_allocated_stack = FALSE;
86  }
87
88  _Stack_Initialize(
89     &the_thread->Start.Initial_stack,
90     stack,
91     actual_stack_size
92  );
93
94  /*
95   *  Allocate the floating point area for this thread
96   */
97 
98#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
99  if ( is_fp ) {
100
101    fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
102    if ( !fp_area ) {
103      _Thread_Stack_Free( the_thread );
104      return FALSE;
105    }
106    fp_area = _Context_Fp_start( fp_area, 0 );
107
108  } else
109    fp_area = NULL;
110
111  the_thread->fp_context       = fp_area;
112  the_thread->Start.fp_context = fp_area;
113#endif
114
115  /*
116   *  Allocate the extensions area for this thread
117   */
118
119  if ( _Thread_Maximum_extensions ) {
120    extensions_area = _Workspace_Allocate(
121      (_Thread_Maximum_extensions + 1) * sizeof( void * )
122    );
123
124    if ( !extensions_area ) {
125      if ( fp_area )
126        (void) _Workspace_Free( fp_area );
127
128      _Thread_Stack_Free( the_thread );
129
130      return FALSE;
131    }
132  } else
133    extensions_area = NULL;
134 
135  the_thread->extensions = (void **) extensions_area;
136
137  /*
138   *  General initialization
139   */
140
141  the_thread->Start.is_preemptible   = is_preemptible;
142  the_thread->Start.budget_algorithm = budget_algorithm;
143  the_thread->Start.budget_callout   = budget_callout;
144
145  switch ( budget_algorithm ) {
146    case THREAD_CPU_BUDGET_ALGORITHM_NONE:
147    case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
148      break;
149    case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:
150      the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
151      break;
152    case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT:
153      break;
154  }
155
156  the_thread->Start.isr_level        = isr_level;
157
158  the_thread->current_state          = STATES_DORMANT;
159  the_thread->resource_count         = 0;
160  the_thread->suspend_count          = 0;
161  the_thread->real_priority          = priority;
162  the_thread->Start.initial_priority = priority;
163  the_thread->ticks_executed         = 0;
164 
165  _Thread_Set_priority( the_thread, priority );
166
167  /*
168   *  Open the object
169   */
170
171  _Objects_Open( information, &the_thread->Object, name );
172
173  /*
174   *  Invoke create extensions
175   */
176
177  if ( !_User_extensions_Thread_create( the_thread ) ) {
178
179    if ( extensions_area )
180      (void) _Workspace_Free( extensions_area );
181
182    if ( fp_area )
183      (void) _Workspace_Free( fp_area );
184
185    _Thread_Stack_Free( the_thread );
186
187    return FALSE;
188  }
189
190  return TRUE;
191   
192}
Note: See TracBrowser for help on using the repository browser.