Changeset 175 for soft/giet_vm/sys
- Timestamp:
- Jul 21, 2012, 10:20:47 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/sys/kernel_init.c
r169 r175 5 5 // Copyright (c) UPMC-LIP6 6 6 //////////////////////////////////////////////////////////////////////////////////// 7 // FIXME 7 8 // The kernel_init.c files is part of the GIET-VM nano-kernel. 8 9 // It contains the kernel entry point for the second phase of system initialisation: … … 42 43 /////////////////////////////////////////////////////////////////////////////////// 43 44 45 void _kernel_ptabs_init(void); 44 46 void _kernel_vobjs_init(void); 45 47 void _kernel_tasks_init(void); … … 64 66 if ( pid == 0 ) 65 67 { 68 _kernel_ptabs_init(); 69 /* must be called after the initialisation of ptabs */ 66 70 _kernel_vobjs_init(); 67 71 _kernel_tasks_init(); … … 150 154 "nop"); 151 155 } 156 157 /////////////////////////////////////////////////////////////////////////////// 158 // used to access user space 159 /////////////////////////////////////////////////////////////////////////////// 160 void _set_ptpr(unsigned int vspace_id) 161 { 162 unsigned int ptpr = ((unsigned int)_kernel_ptabs_paddr[vspace_id]) >> 13; 163 asm volatile("mtc2 %0, $0"::"r"(ptpr)); 164 } 165 166 /////////////////////////////////////////////////////////////////////////////// 167 // This function initialises the _kernel_ptabs_paddr[] array indexed by the vspace_id, 168 // and containing the base addresses of all page tables. 169 // This _kernel_ptabs_paddr[] array is used to initialise the task contexts. 170 /////////////////////////////////////////////////////////////////////////////// 171 in_kinit void _kernel_ptabs_init() 172 { 173 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 174 mapping_vspace_t* vspace = _get_vspace_base( header ); 175 mapping_vobj_t* vobj = _get_vobj_base( header ); 176 177 unsigned int vspace_id; 178 unsigned int vobj_id; 179 180 // loop on the vspaces 181 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 182 { 183 char ptab_found = 0; 184 185 #if INIT_DEBUG_CTX 186 _puts("[INIT] --- vobjs initialisation in vspace "); 187 _puts(vspace[vspace_id].name); 188 _puts("\n"); 189 #endif 190 // loop on the vobjs and get the ptpr 191 for(vobj_id= vspace[vspace_id].vobj_offset; 192 vobj_id < (vspace[vspace_id].vobj_offset+ vspace[vspace_id].vobjs); 193 vobj_id++) 194 { 195 if(vobj[vobj_id].type == VOBJ_TYPE_PTAB) 196 { 197 if( ptab_found ) 198 { 199 _puts("\n[INIT ERROR] Only one PTAB for by vspace "); 200 _putw( vspace_id ); 201 _exit(); 202 } 203 204 ptab_found = 1; 205 _kernel_ptabs_paddr[vspace_id] = vobj[vobj_id].paddr; 206 _kernel_ptabs_vaddr[vspace_id] = vobj[vobj_id].vaddr; 207 208 #if INIT_DEBUG_CTX 209 _puts("[INIT] PTAB address = "); 210 _putw(_kernel_ptabs_paddr[vspace_id]); 211 _puts("\n"); 212 #endif 213 } 214 215 } 216 217 if( !ptab_found ) 218 { 219 _puts("\n[INIT ERROR] Missing PTAB for vspace "); 220 _putw( vspace_id ); 221 _exit(); 222 } 223 } 224 225 _puts("\n[INIT] Ptabss initialisation completed at cycle : "); 226 _putw( _proctime() ); 227 _puts("\n"); 228 229 } // end kernel_ptabs_init() 230 231 /////////////////////////////////////////////////////////////////////////////// 232 // This function initializes all private vobjs defined in the vspaces, 233 // such as mwmr channels, barriers and locks, depending on the vobj type. 234 // (Most of the vobjs are not known, and not initialised by the compiler). 235 /////////////////////////////////////////////////////////////////////////////// 236 in_kinit void _kernel_vobjs_init() 237 { 238 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 239 mapping_vspace_t* vspace = _get_vspace_base( header ); 240 mapping_vobj_t* vobj = _get_vobj_base( header ); 241 242 unsigned int vspace_id; 243 unsigned int vobj_id; 244 245 // loop on the vspaces 246 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 247 { 248 char ptab_found = 0; 249 250 #if INIT_DEBUG_CTX 251 _puts("[INIT] --- vobjs initialisation in vspace "); 252 _puts(vspace[vspace_id].name); 253 _puts("\n"); 254 #endif 255 // loop on the vobjs and get the ptpr 256 for(vobj_id= vspace[vspace_id].vobj_offset; 257 vobj_id < (vspace[vspace_id].vobj_offset+ vspace[vspace_id].vobjs); 258 vobj_id++) 259 { 260 if(vobj[vobj_id].type == VOBJ_TYPE_PTAB) 261 { 262 if( ptab_found ) 263 { 264 _puts("\n[INIT ERROR] Only one PTAB for by vspace "); 265 _putw( vspace_id ); 266 _exit(); 267 } 268 269 ptab_found = 1; 270 _kernel_ptabs_paddr[vspace_id] = vobj[vobj_id].paddr; 271 _kernel_ptabs_vaddr[vspace_id] = vobj[vobj_id].vaddr; 272 273 #if INIT_DEBUG_CTX 274 _puts("[INIT] PTAB address = "); 275 _putw(_kernel_ptabs_paddr[vspace_id]); 276 _puts("\n"); 277 #endif 278 } 279 280 } 281 282 if( !ptab_found ) 283 { 284 _puts("\n[INIT ERROR] Missing PTAB for vspace "); 285 _putw( vspace_id ); 286 _exit(); 287 } 288 289 /** Set the current vspace ptpr to initialise the vobjs */ 290 _set_ptpr(vspace_id); 291 292 // loop on the vobjs and get the ptpr 293 for(vobj_id= vspace[vspace_id].vobj_offset; 294 vobj_id < (vspace[vspace_id].vobj_offset+ vspace[vspace_id].vobjs); 295 vobj_id++) 296 { 297 switch( vobj[vobj_id].type ) 298 { 299 case VOBJ_TYPE_PTAB: // initialise page table pointers array 300 { 301 break;//already handled 302 } 303 case VOBJ_TYPE_MWMR: // storage capacity is (vobj.length/4 - 5) words 304 { 305 mwmr_channel_t* mwmr = (mwmr_channel_t*)(vobj[vobj_id].vaddr); 306 mwmr->ptw = 0; 307 mwmr->ptr = 0; 308 mwmr->sts = 0; 309 mwmr->depth = (vobj[vobj_id].length>>2) - 5; 310 mwmr->width = vobj[vobj_id].init; 311 mwmr->lock = 0; 312 #if INIT_DEBUG_CTX 313 _puts("[INIT] MWMR channel "); 314 _puts( vobj->name); 315 _puts(" / depth = "); 316 _putw( mwmr->depth ); 317 _puts("\n"); 318 #endif 319 break; 320 } 321 case VOBJ_TYPE_ELF: // initialisation done by the loader 322 { 323 324 #if INIT_DEBUG_CTX 325 _puts("[INIT] ELF section "); 326 _puts( vobj->name); 327 _puts(" / length = "); 328 _putw( vobj->length ); 329 _puts("\n"); 330 #endif 331 break; 332 } 333 case VOBJ_TYPE_BARRIER: // init is the number of participants 334 { 335 giet_barrier_t* barrier = (giet_barrier_t*)(vobj[vobj_id].vaddr); 336 barrier->count = 0; 337 barrier->init = vobj[vobj_id].init; 338 #if INIT_DEBUG_CTX 339 _puts(" BARRIER "); 340 _puts( vobj->name); 341 _puts(" / init_value = "); 342 _putw( barrier->init ); 343 _puts("\n"); 344 #endif 345 break; 346 } 347 case VOBJ_TYPE_LOCK: // init is "not taken" 348 { 349 unsigned int* lock = (unsigned int*)(vobj[vobj_id].vaddr); 350 *lock = 0; 351 #if INIT_DEBUG_CTX 352 _puts(" LOCK "); 353 _puts( vobj->name); 354 _puts("\n"); 355 #endif 356 break; 357 } 358 case VOBJ_TYPE_BUFFER: // nothing to do 359 { 360 361 #if INIT_DEBUG_CTX 362 _puts(" BUFFER "); 363 _puts( vobj->name); 364 _puts(" / length = "); 365 _putw( vobj->length ); 366 _puts("\n"); 367 #endif 368 break; 369 } 370 default: 371 { 372 _puts("\n[INIT ERROR] illegal vobj of name "); 373 _puts(vobj->name); 374 _puts(" / in vspace = "); 375 _puts(vobj->name); 376 _puts("\n "); 377 _exit(); 378 } 379 } // end switch type 380 } // end loop on vobjs 381 } // end loop on vspaces 382 383 _puts("\n[INIT] Vobjs initialisation completed at cycle : "); 384 _putw( _proctime() ); 385 _puts("\n"); 386 387 } // end kernel_vobjs_init() 152 388 153 389 /////////////////////////////////////////////////////////////////////////////// … … 181 417 mapping_vobj_t* vobj = _get_vobj_base( header ); 182 418 419 /** Set the current vspace ptpr before acessing the memory */ 420 _set_ptpr(vspace_id); 183 421 184 422 // values to be initialised in task context … … 291 529 292 530 } // end _task_map() 293 294 ///////////////////////////////////////////////////////////////////////////////295 // This function initializes all private vobjs defined in the vspaces,296 // such as mwmr channels, barriers and locks, depending on the vobj type.297 // (Most of the vobjs are not known, and not initialised by the compiler).298 // This function initialises the _kernel_ptabs_paddr[] array indexed by the vspace_id,299 // and containing the base addresses of all page tables.300 // This _kernel_ptabs_paddr[] array is used to initialise the task contexts.301 ///////////////////////////////////////////////////////////////////////////////302 in_kinit void _kernel_vobjs_init()303 {304 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base;305 mapping_vspace_t* vspace = _get_vspace_base( header );306 mapping_vobj_t* vobj = _get_vobj_base( header );307 308 unsigned int vspace_id;309 unsigned int vobj_id;310 311 // loop on the vspaces312 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ )313 {314 char ptab_found = 0;315 316 #if INIT_DEBUG_CTX317 _puts("[INIT] --- vobjs initialisation in vspace ");318 _puts(vspace[vspace_id].name);319 _puts("\n");320 #endif321 // loop on the vobjs322 for(vobj_id= vspace[vspace_id].vobj_offset;323 vobj_id < (vspace[vspace_id].vobj_offset+ vspace[vspace_id].vobjs);324 vobj_id++)325 {326 switch( vobj[vobj_id].type )327 {328 case VOBJ_TYPE_PTAB: // initialise page table pointers array329 {330 ptab_found = 1;331 _kernel_ptabs_paddr[vspace_id] = vobj[vobj_id].paddr;332 _kernel_ptabs_vaddr[vspace_id] = vobj[vobj_id].vaddr;333 334 #if INIT_DEBUG_CTX335 _puts("[INIT] PTAB address = ");336 _putw(_kernel_ptabs_paddr[vspace_id]);337 _puts("\n");338 #endif339 break;340 }341 case VOBJ_TYPE_MWMR: // storage capacity is (vobj.length/4 - 5) words342 {343 mwmr_channel_t* mwmr = (mwmr_channel_t*)(vobj[vobj_id].vaddr);344 mwmr->ptw = 0;345 mwmr->ptr = 0;346 mwmr->sts = 0;347 mwmr->depth = (vobj[vobj_id].length>>2) - 5;348 mwmr->lock = 0;349 #if INIT_DEBUG_CTX350 _puts("[INIT] MWMR channel ");351 _puts( vobj->name);352 _puts(" / depth = ");353 _putw( mwmr->depth );354 _puts("\n");355 #endif356 break;357 }358 case VOBJ_TYPE_ELF: // initialisation done by the loader359 {360 361 #if INIT_DEBUG_CTX362 _puts("[INIT] ELF section ");363 _puts( vobj->name);364 _puts(" / length = ");365 _putw( vobj->length );366 _puts("\n");367 #endif368 break;369 }370 case VOBJ_TYPE_BARRIER: // init is the number of participants371 {372 giet_barrier_t* barrier = (giet_barrier_t*)(vobj[vobj_id].vaddr);373 barrier->count = 0;374 barrier->init = vobj[vobj_id].init;375 #if INIT_DEBUG_CTX376 _puts(" BARRIER ");377 _puts( vobj->name);378 _puts(" / init_value = ");379 _putw( barrier->init );380 _puts("\n");381 #endif382 break;383 }384 case VOBJ_TYPE_LOCK: // init is "not taken"385 {386 unsigned int* lock = (unsigned int*)(vobj[vobj_id].vaddr);387 *lock = 0;388 #if INIT_DEBUG_CTX389 _puts(" LOCK ");390 _puts( vobj->name);391 _puts("\n");392 #endif393 break;394 }395 case VOBJ_TYPE_BUFFER: // nothing to do396 {397 398 #if INIT_DEBUG_CTX399 _puts(" BUFFER ");400 _puts( vobj->name);401 _puts(" / length = ");402 _putw( vobj->length );403 _puts("\n");404 #endif405 break;406 }407 default:408 {409 _puts("\n[INIT ERROR] illegal vobj of name ");410 _puts(vobj->name);411 _puts(" / in vspace = ");412 _puts(vobj->name);413 _puts("\n ");414 _exit();415 }416 } // end switch type417 } // end loop on vobjs418 if( !ptab_found )419 {420 _puts("\n[INIT ERROR] Missing PTAB for vspace ");421 _putw( vspace_id );422 _exit();423 }424 } // end loop on vspaces425 426 _puts("\n[INIT] Vobjs initialisation completed at cycle : ");427 _putw( _proctime() );428 _puts("\n");429 430 } // end _vobjs_init()431 531 432 532 ///////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.