Changeset 709 for soft/giet_vm/giet_kernel/kernel_init.c
- Timestamp:
- Oct 1, 2015, 4:20:46 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/kernel_init.c
r688 r709 23 23 #include <bdv_driver.h> 24 24 #include <mmc_driver.h> 25 #include <tty_driver.h> 25 26 #include <ctx_handler.h> 26 27 #include <irq_handler.h> 28 #include <sys_handler.h> 27 29 #include <mapping_info.h> 28 30 #include <mips32_registers.h> … … 60 62 #endif 61 63 62 #if !defined(IDLE_T ASK_INDEX)63 # error: You must define IDLE_T ASK_INDEX in the ctx_handler.h file64 #if !defined(IDLE_THREAD_INDEX) 65 # error: You must define IDLE_THREAD_INDEX in the ctx_handler.h file 64 66 #endif 65 67 … … 109 111 volatile unsigned int _kernel_init_done = 0; 110 112 111 // Kernel uses sqt_lock to protect TTY0113 // Kernel uses a sqt_lock to protect TTY0 112 114 __attribute__((section(".kdata"))) 113 115 unsigned int _tty0_boot_mode = 0; 114 116 115 // Kernel uses sqt_lock to protect command allocator in HBA117 // Kernel uses a sqt_lock to protect command allocator in HBA 116 118 __attribute__((section(".kdata"))) 117 119 unsigned int _hba_boot_mode = 0; … … 125 127 //////////////////////////////////////////////////////////////////////////////// 126 128 127 // this variable is defined in tty0.c file129 // this variable is allocated in tty0.c file 128 130 extern sqt_lock_t _tty0_sqt_lock; 129 131 130 // this variable is allocated in mmc_ kernel.c132 // this variable is allocated in mmc_driver.c file 131 133 extern unsigned int _mmc_boot_mode; 132 134 133 //////////////////////////////////////////////////////////////////////////////// 134 // This kernel_init() function completes the kernel initialisation in 6 steps: 135 // this variable is allocated in sys_handler.c file 136 extern unsigned int _tty_channel_alloc[NB_TTY_CHANNELS]; 137 138 //////////////////////////////////////////////////////////////////////////////// 139 // This kernel_init() function completes the kernel initialisation in 5 steps: 135 140 // Step 0 is done by processor[0,0,0]. Steps 1 to 4 are executed in parallel 136 141 // by all processors. … … 138 143 // - step 1 : Each processor initialises scheduler pointers array. 139 144 // - step 2 : Each processor initialises PTAB pointers arrays. 140 // - step 3 : Each processor initialise idle t askand starts TICK timer.145 // - step 3 : Each processor initialise idle thread and starts TICK timer. 141 146 // - step 4 : Each processor set sp, sr, ptpr, epc registers values. 142 147 //////////////////////////////////////////////////////////////////////////////// … … 165 170 _nolock_printf("\n[DEBUG KINIT] P[%d,%d,%d] completes kernel heap init\n", x, y, p ); 166 171 #endif 167 ////// distributed lock for MMC172 ////// distributed locks for MMC 168 173 _mmc_boot_mode = 0; 169 174 _mmc_init_locks(); 170 175 171 176 #if GIET_DEBUG_INIT 172 _nolock_printf("\n[DEBUG KINIT] P[%d,%d,%d] completes MMC distributed lock init\n", x , y , p );177 _nolock_printf("\n[DEBUG KINIT] P[%d,%d,%d] completes MMC distributed locks init\n", x , y , p ); 173 178 #endif 174 179 ////// distributed lock for TTY0 175 180 _sqt_lock_init( &_tty0_sqt_lock ); 181 _tty_channel_alloc[0] = 1; 176 182 177 183 #if GIET_DEBUG_INIT … … 183 189 #if GIET_DEBUG_INIT 184 190 _nolock_printf("\n[DEBUG KINIT] P[%d,%d,%d] completes barrier init\n", x , y , p ); 191 #endif 192 193 ////// TTY fifos initialisation 194 unsigned int tty_id; 195 for ( tty_id = 0 ; tty_id < NB_TTY_CHANNELS ; tty_id++) _tty_init( tty_id ); 196 197 #if GIET_DEBUG_INIT 198 _nolock_printf("\n[DEBUG KINIT] P[%d,%d,%d] completes TTY fifos init\n", x , y , p ); 185 199 #endif 186 200 … … 245 259 246 260 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 247 unsigned int t asks = psched->tasks;261 unsigned int threads = psched->threads; 248 262 249 263 _schedulers[x][y][p] = psched; … … 252 266 _printf("\n[DEBUG KINIT] P[%d,%d,%d] initialises SCHED array\n" 253 267 " - scheduler vbase = %x\n" 254 " - t asks= %d\n",255 x, y, p, (unsigned int)psched, t asks );268 " - threads = %d\n", 269 x, y, p, (unsigned int)psched, threads ); 256 270 #endif 257 271 … … 261 275 262 276 //////////////////////////////////////////////////////////////////////////// 263 // step 2 : each processor that is allocated at least one t askloops264 // on its allocated t asks:265 // - contributes to _ptabs_vaddr [][][] & _ptabs_ptprs[][][]266 // initialisation, from values stored in the t asks contexts.277 // step 2 : each processor that is allocated at least one thread loops 278 // on its allocated threads: 279 // - contributes to _ptabs_vaddr & _ptabs_ptprs arrays 280 // initialisation, from values stored in the threads contexts. 267 281 // - set CTX_RA slot with the kernel _ctx_eret() virtual address. 268 // - set CTX_ENTRY slot that must contain the task entry point,269 // and contain only at this point the virtual address of the270 // memory word containing this entry point.282 // - set CTX_ENTRY & CTX_EPC slots that must contain the thread 283 // entry point. The CTX_ENTRY slot contain only at this point 284 // a pointer on the memory word containing this entry point. 271 285 //////////////////////////////////////////////////////////////////////////// 272 286 273 287 unsigned int ltid; 274 288 275 for (ltid = 0; ltid < t asks; ltid++)289 for (ltid = 0; ltid < threads; ltid++) 276 290 { 277 unsigned int vsid = _get_t ask_slot( x, y, p, ltid , CTX_VSID_ID );278 unsigned int ptab = _get_t ask_slot( x, y, p, ltid , CTX_PTAB_ID );279 unsigned int ptpr = _get_t ask_slot( x, y, p, ltid , CTX_PTPR_ID );291 unsigned int vsid = _get_thread_slot( x, y, p, ltid , CTX_VSID_ID ); 292 unsigned int ptab = _get_thread_slot( x, y, p, ltid , CTX_PTAB_ID ); 293 unsigned int ptpr = _get_thread_slot( x, y, p, ltid , CTX_PTPR_ID ); 280 294 281 295 // initialize PTABS arrays … … 289 303 // set CTX_RA slot 290 304 unsigned int ctx_ra = (unsigned int)(&_ctx_eret); 291 _set_t ask_slot( x, y, p, ltid, CTX_RA_ID, ctx_ra );292 293 // set CTX_ENTRY slot294 unsigned int* ptr = (unsigned int*)_get_t ask_slot(x , y , p , ltid , CTX_ENTRY_ID);305 _set_thread_slot( x, y, p, ltid, CTX_RA_ID, ctx_ra ); 306 307 // set CTX_ENTRY and CTX_EPC slots 308 unsigned int* ptr = (unsigned int*)_get_thread_slot(x , y , p , ltid , CTX_ENTRY_ID); 295 309 unsigned int ctx_entry = *ptr; 296 _set_task_slot( x , y , p , ltid , CTX_ENTRY_ID , ctx_entry ); 310 _set_thread_slot( x , y , p , ltid , CTX_ENTRY_ID , ctx_entry ); 311 _set_thread_slot( x , y , p , ltid , CTX_EPC_ID , ctx_entry ); 297 312 298 313 #if GIET_DEBUG_INIT 299 314 _printf("\n[DEBUG KINIT] P[%d,%d,%d] initialises PTABS arrays" 300 " and context for t ask%d \n"315 " and context for thread %d \n" 301 316 " - ptabs_vaddr[%d][%d][%d] = %x\n" 302 317 " - ptabs_paddr[%d][%d][%d] = %l\n" … … 309 324 #endif 310 325 311 } // end for t asks326 } // end for threads 312 327 313 328 ///////////////////////////////////////// … … 316 331 317 332 //////////////////////////////////////////////////////////////////////////// 318 // step 3 : - Each processor complete idle t askcontext initialisation.333 // step 3 : - Each processor complete idle thread context initialisation. 319 334 // Only CTX_SP, CTX_RA, CTX_EPC, CTX_ENTRY slots, because other 320 335 // slots have been initialised in boot code) 321 336 // The 4 Kbytes idle stack is implemented in the scheduler itself. 322 // - Each processor starts TICK timer, if at least one t ask.337 // - Each processor starts TICK timer, if at least one thread. 323 338 // - P[0,0,0] initialises FAT (not done before, because it must 324 339 // be done after the _ptabs_vaddr[v][x][y] array initialisation, … … 328 343 unsigned int sp = ((unsigned int)psched) + 0x2000; 329 344 unsigned int ra = (unsigned int)(&_ctx_eret); 330 unsigned int entry = (unsigned int)(&_idle_t ask);331 332 _set_t ask_slot( x , y , p , IDLE_TASK_INDEX , CTX_SP_ID , sp );333 _set_t ask_slot( x , y , p , IDLE_TASK_INDEX , CTX_RA_ID , ra );334 _set_t ask_slot( x , y , p , IDLE_TASK_INDEX , CTX_EPC_ID , entry );335 _set_t ask_slot( x , y , p , IDLE_TASK_INDEX , CTX_ENTRY_ID , entry );336 337 if (t asks > 0) _xcu_timer_start( cluster_xy, p, GIET_TICK_VALUE );338 339 #if GIET_DEBUG_INIT 340 _printf("\n[DEBUG KINIT] P[%d,%d,%d] initializes idle_t askand starts TICK\n",345 unsigned int entry = (unsigned int)(&_idle_thread); 346 347 _set_thread_slot( x , y , p , IDLE_THREAD_INDEX , CTX_SP_ID , sp ); 348 _set_thread_slot( x , y , p , IDLE_THREAD_INDEX , CTX_RA_ID , ra ); 349 _set_thread_slot( x , y , p , IDLE_THREAD_INDEX , CTX_EPC_ID , entry ); 350 _set_thread_slot( x , y , p , IDLE_THREAD_INDEX , CTX_ENTRY_ID , entry ); 351 352 if (threads > 0) _xcu_timer_start( cluster_xy, p, GIET_TICK_VALUE ); 353 354 #if GIET_DEBUG_INIT 355 _printf("\n[DEBUG KINIT] P[%d,%d,%d] initializes idle_thread and starts TICK\n", 341 356 x, y, p ); 342 357 #endif … … 358 373 359 374 //////////////////////////////////////////////////////////////////////////// 360 // step 4 : Each processor computes the t askindex (ltid), and the values375 // step 4 : Each processor computes the thread index (ltid), and the values 361 376 // to initialize the SP, SR, PTPR, EPC registers. 362 // It jumps to a runable t ask if possible, and jumps to IDLE-TASK363 // if no task allocated or no runable task.364 //////////////////////////////////////////////////////////////////////////// 365 366 if (t asks == 0) _printf("\n[GIET WARNING] No taskallocated to P[%d,%d,%d]\n",377 // It jumps to a runable thread if possible, 378 // or jumps to IDLE-THREAD if no runable thread. 379 //////////////////////////////////////////////////////////////////////////// 380 381 if (threads == 0) _printf("\n[GIET WARNING] No thread allocated to P[%d,%d,%d]\n", 367 382 x, y, p ); 368 383 369 384 // default value for ltid 370 ltid = IDLE_T ASK_INDEX;371 372 // scan allocated t asks to find a runable task373 unsigned int t ask_id;374 for ( t ask_id = 0 ; task_id < tasks ; task_id++ )385 ltid = IDLE_THREAD_INDEX; 386 387 // scan allocated threads to find a runable thread 388 unsigned int thread_id; 389 for ( thread_id = 0 ; thread_id < threads ; thread_id++ ) 375 390 { 376 if ( _get_t ask_slot( x, y, p, task_id, CTX_NORUN_ID ) == 0 )391 if ( _get_thread_slot( x, y, p, thread_id, CTX_NORUN_ID ) == 0 ) 377 392 { 378 ltid = t ask_id;393 ltid = thread_id; 379 394 break; 380 395 } … … 384 399 psched->current = ltid; 385 400 386 // get values from selected t askcontext387 unsigned int sp_value = _get_t ask_slot( x, y, p, ltid, CTX_SP_ID);388 unsigned int sr_value = _get_t ask_slot( x, y, p, ltid, CTX_SR_ID);389 unsigned int ptpr_value = _get_t ask_slot( x, y, p, ltid, CTX_PTPR_ID);390 unsigned int epc_value = _get_t ask_slot( x, y, p, ltid, CTX_ENTRY_ID);401 // get values from selected thread context 402 unsigned int sp_value = _get_thread_slot( x, y, p, ltid, CTX_SP_ID); 403 unsigned int sr_value = _get_thread_slot( x, y, p, ltid, CTX_SR_ID); 404 unsigned int ptpr_value = _get_thread_slot( x, y, p, ltid, CTX_PTPR_ID); 405 unsigned int epc_value = _get_thread_slot( x, y, p, ltid, CTX_ENTRY_ID); 391 406 392 407 #if GIET_DEBUG_INIT
Note: See TracChangeset
for help on using the changeset viewer.