Changeset 165 for soft/giet_vm/boot
- Timestamp:
- Jul 4, 2012, 2:51:18 PM (12 years ago)
- Location:
- soft/giet_vm/boot
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/boot/boot_handler.c
r163 r165 6 6 /////////////////////////////////////////////////////////////////////////////////// 7 7 // The boot_handler.h and boot_handler.c files are part of the GIET nano-kernel. 8 // This code can be used in the boot phase to build all the pages tables then jumps9 // in tothe seg_kernel_init segment with an activated MMU.8 // This code is executed in the boot phase by proc0 to build all the pages tables, 9 // then jump in the seg_kernel_init segment with an activated MMU. 10 10 // 11 // It uses the SoCLib generic MMU (paged virtual memory) to provide two services: 12 // 11 // The SoCLib generic MMU (paged virtual memory) provides two services: 13 12 // 1) classical memory protection, when several independant applications compiled 14 13 // in different virtual spaces are executing on the same hardware platform. … … 16 15 // of the software objects (virtual segments) on the physical memory banks. 17 16 // 18 // It uses the MAPPING_INFO binary data structures, that must be pre-loaded in the19 // boot ROM inthe seg_boot_mapping segment (at address seg_mapping_base).17 // The boot code uses the MAPPING_INFO binary data structures, that must be pre-loaded 18 // in the the seg_boot_mapping segment (at address seg_mapping_base). 20 19 // This MAPPING_INFO data structure defines both the hardware architecture, 21 20 // and the mapping: … … 32 31 // As most applications use only a limited number of segments, the number of PT2s 33 32 // actually used by a given virtual space is generally smaller than 2048, and is 34 // defined in the MAPPING_INFO_BINARY data structure (using the length field).35 // The value is calculated and put in _max_pt e2 indexed by the vspace_id.33 // defined in the MAPPING_INFO_BINARY data structure (using the length field). 34 // The value is calculated and put in _max_pt2 indexed by the vspace_id. 36 35 // The physical alignment constraints, is ensured by the align flag in the MAPPING_INFO 37 36 // structure. … … 41 40 // - a first 8K aligned PT1[2148] array, indexed by the (ix1) field of VPN. 42 41 // The PT1 contains 2048 PTD of 4 bytes => 8K bytes. 43 // - an aray of array PT2[1024][_max_pt e2[vspace_id]], indexed by42 // - an aray of array PT2[1024][_max_pt2[vspace_id]], indexed by 44 43 // the (ix2) field of the VPN, and by the PT2 index (pt2_id). 45 // Each PT2 contains 512 PTE2 of 8bytes => 4Kbytes * _max_pt e2[vspace_id]46 // The size of each page table is 8K + (_max_pt e2[vspace_id])*4K bytes.44 // Each PT2 contains 512 PTE2 of 8bytes => 4Kbytes * _max_pt2[vspace_id] 45 // The size of each page table is 8K + (_max_pt2[vspace_id])*4K bytes. 47 46 // All page tables must be stored in the seg_kernel_pt segment (at address 48 47 // seg_kernel_pt_base) 49 48 //////////////////////////////////////////////////////////////////////////////////// 50 49 51 #include <mips32_registers.h>50 #include "../sys/mips32_registers.h" 52 51 #include <boot_handler.h> 53 52 #include <mapping_info.h> 54 #include <mwmr .h>53 #include <mwmr_channel.h> 55 54 56 55 #include <stdarg.h> … … 62 61 63 62 //////////////////////////////////////////////////////////////////////////// 64 // Global variables63 // Page Tables global variables 65 64 //////////////////////////////////////////////////////////////////////////// 66 65 67 // Page Tables 68 // Next free PT2 index 66 // Next free PT2 index array 69 67 unsigned int _next_free_pt2[GIET_NB_VSPACE_MAX] = 70 68 { [0 ... GIET_NB_VSPACE_MAX-1] = 0 }; 71 69 72 // Max PT2 index73 unsigned int _max_pt e2[GIET_NB_VSPACE_MAX] =70 // Max number of PT2 array 71 unsigned int _max_pt2[GIET_NB_VSPACE_MAX] = 74 72 { [0 ... GIET_NB_VSPACE_MAX-1] = 0 }; 75 73 76 // Page table pointers 74 // Page table pointers array 77 75 page_table_t* _ptabs[GIET_NB_VSPACE_MAX]; 78 76 … … 107 105 108 106 //////////////////////////////////////////////////////////////////////////// 109 // boot_ tty_puts()107 // boot_puts() 110 108 // (it uses TTY0) 111 109 //////////////////////////////////////////////////////////////////////////// 112 void boot_ tty_puts(const char *buffer)110 void boot_puts(const char *buffer) 113 111 { 114 112 unsigned int* tty_address = (unsigned int*)&seg_tty_base; … … 124 122 125 123 //////////////////////////////////////////////////////////////////////////// 126 // boot_ tty_putw()124 // boot_putw() 127 125 // (it uses TTY0) 128 126 //////////////////////////////////////////////////////////////////////////// 129 void boot_ tty_putw(unsigned int val)127 void boot_putw(unsigned int val) 130 128 { 131 129 static const char HexaTab[] = "0123456789ABCDEF"; … … 142 140 val = val >> 4; 143 141 } 144 boot_ tty_puts(buf);142 boot_puts(buf); 145 143 } 146 144 … … 219 217 mapping_vseg_t* vseg = boot_get_vseg_base ( header ); 220 218 mapping_task_t* task = boot_get_task_base ( header );; 221 mapping_vobj_t* vobj= boot_get_vobj_base( header );219 mapping_vobj_t* vobj = boot_get_vobj_base( header ); 222 220 223 221 // header 224 boot_tty_puts("mapping_info"); 225 226 boot_tty_puts("\n - signature = "); 227 boot_tty_putw(header->signature); 228 boot_tty_puts("\n - name = "); 229 boot_tty_puts(header->name); 230 boot_tty_puts("\n - clusters = "); 231 boot_tty_putw(header->clusters); 232 boot_tty_puts("\n - psegs = "); 233 boot_tty_putw(header->psegs); 234 boot_tty_puts("\n - ttys = "); 235 boot_tty_putw(header->ttys); 236 boot_tty_puts("\n - vspaces = "); 237 boot_tty_putw(header->vspaces); 238 boot_tty_puts("\n - globals = "); 239 boot_tty_putw(header->globals); 240 boot_tty_puts("\n - vsegs = "); 241 boot_tty_putw(header->vsegs); 242 boot_tty_puts("\n - tasks = "); 243 boot_tty_putw(header->tasks); 244 boot_tty_puts("\n\n"); 222 boot_puts("mapping_info"); 223 224 boot_puts("\n - signature = "); 225 boot_putw(header->signature); 226 boot_puts("\n - name = "); 227 boot_puts(header->name); 228 boot_puts("\n - clusters = "); 229 boot_putw(header->clusters); 230 boot_puts("\n - psegs = "); 231 boot_putw(header->psegs); 232 boot_puts("\n - ttys = "); 233 boot_putw(header->ttys); 234 boot_puts("\n - fbs = "); 235 boot_putw(header->fbs); 236 boot_puts("\n - vspaces = "); 237 boot_putw(header->vspaces); 238 boot_puts("\n - globals = "); 239 boot_putw(header->globals); 240 boot_puts("\n - vsegs = "); 241 boot_putw(header->vsegs); 242 boot_puts("\n - vobjs = "); 243 boot_putw(header->vobjs); 244 boot_puts("\n - tasks = "); 245 boot_putw(header->tasks); 246 boot_puts("\n\n"); 245 247 246 248 // clusters 247 249 for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) 248 250 { 249 boot_tty_puts("cluster "); 250 boot_tty_putw(cluster_id); 251 252 boot_tty_puts("\n - procs = "); 253 boot_tty_putw(cluster[cluster_id].procs); 254 boot_tty_puts("\n - timers = "); 255 boot_tty_putw(cluster[cluster_id].timers); 256 boot_tty_puts("\n - dmas = "); 257 boot_tty_putw(cluster[cluster_id].dmas); 258 boot_tty_puts("\n\n"); 251 boot_puts("cluster "); 252 boot_putw(cluster_id); 253 254 boot_puts("\n - procs = "); 255 boot_putw(cluster[cluster_id].procs); 256 boot_puts("\n\n"); 259 257 } 260 258 … … 262 260 for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) 263 261 { 264 boot_ tty_puts("pseg ");265 boot_ tty_putw(pseg_id);266 267 boot_ tty_puts("\n - name = ");268 boot_ tty_puts( pseg[pseg_id].name );269 boot_ tty_puts("\n - base = ");270 boot_ tty_putw( pseg[pseg_id].base );271 boot_ tty_puts("\n - length = ");272 boot_ tty_putw( pseg[pseg_id].length );273 boot_ tty_puts("\n\n");262 boot_puts("pseg "); 263 boot_putw(pseg_id); 264 265 boot_puts("\n - name = "); 266 boot_puts( pseg[pseg_id].name ); 267 boot_puts("\n - base = "); 268 boot_putw( pseg[pseg_id].base ); 269 boot_puts("\n - length = "); 270 boot_putw( pseg[pseg_id].length ); 271 boot_puts("\n\n"); 274 272 } 275 273 … … 277 275 for ( vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ ) 278 276 { 279 boot_tty_puts("global vseg "); 280 boot_tty_putw(vseg_id); 281 282 boot_tty_puts("\n - name = "); 283 boot_tty_puts( vseg[vseg_id].name ); 284 boot_tty_puts("\n - vbase = "); 285 boot_tty_putw( vseg[vseg_id].vbase ); 286 boot_tty_puts("\n - length = "); 287 boot_tty_putw( vseg[vseg_id].length ); 288 boot_tty_puts("\n - mode = "); 289 boot_tty_putw( vseg[vseg_id].mode ); 290 boot_tty_puts("\n - ident = "); 291 boot_tty_putw( vseg[vseg_id].ident ); 292 boot_tty_puts("\n - psegname = "); 293 boot_tty_puts( pseg[vseg[vseg_id].psegid].name ); 294 boot_tty_puts("\n"); 295 for ( vobj_id = vseg[vseg_id].vobj_offset ; vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; vobj_id++ ) 296 { 297 boot_tty_puts("vobjs: \n"); 298 boot_tty_putw( vobj[vobj_id].name); 299 boot_tty_puts("\n"); 300 boot_tty_puts("\t name = "); 301 boot_tty_putw( vobj[vobj_id].name); 302 boot_tty_puts("\n"); 303 boot_tty_puts("\t type = "); 304 boot_tty_putw( vobj[vobj_id].type); 305 boot_tty_puts("\n"); 306 boot_tty_puts("\t length = "); 307 boot_tty_putw( vobj[vobj_id].length); 308 boot_tty_puts("\n"); 309 boot_tty_puts("\t align = "); 310 boot_tty_putw( vobj[vobj_id].align); 311 boot_tty_puts("\n"); 312 boot_tty_puts("\t binpath = "); 313 boot_tty_putw( vobj[vobj_id].binpath); 314 boot_tty_puts("\n\n"); 277 boot_puts("global vseg "); 278 boot_putw(vseg_id); 279 280 boot_puts("\n - name = "); 281 boot_puts( vseg[vseg_id].name ); 282 boot_puts("\n - vbase = "); 283 boot_putw( vseg[vseg_id].vbase ); 284 boot_puts("\n - length = "); 285 boot_putw( vseg[vseg_id].length ); 286 boot_puts("\n - mode = "); 287 boot_putw( vseg[vseg_id].mode ); 288 boot_puts("\n - ident = "); 289 boot_putw( vseg[vseg_id].ident ); 290 boot_puts("\n - psegname = "); 291 boot_puts( pseg[vseg[vseg_id].psegid].name ); 292 boot_puts("\n - vobjs = "); 293 boot_putw( vseg[vseg_id].vobjs ); 294 boot_puts("\n - vobj_offset = "); 295 boot_putw( vseg[vseg_id].vobj_offset ); 296 boot_puts("\n"); 297 for ( vobj_id = vseg[vseg_id].vobj_offset ; 298 vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; 299 vobj_id++ ) 300 { 301 boot_puts("\n\t vobj "); 302 boot_puts( vobj[vobj_id].name); 303 boot_puts("\n\t type = "); 304 boot_putw( vobj[vobj_id].type); 305 boot_puts("\n\t length = "); 306 boot_putw( vobj[vobj_id].length); 307 boot_puts("\n\t align = "); 308 boot_putw( vobj[vobj_id].align); 309 boot_puts("\n\t binpath = "); 310 boot_puts( vobj[vobj_id].binpath); 311 boot_puts("\n\n"); 315 312 } 316 313 } … … 319 316 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 320 317 { 321 unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].funcs_offset; 322 boot_tty_puts("vspace "); 323 boot_tty_putw(vspace_id); 324 325 boot_tty_puts("\n - name = "); 326 boot_tty_puts( vspace[vspace_id].name ); 327 boot_tty_puts("\n - funcs = "); 328 boot_tty_puts( vobj[func_id].name ); 329 boot_tty_puts( vspace[vspace_id].name ); 330 boot_tty_puts("\n - ttys = "); 331 boot_tty_putw( vspace[vspace_id].ttys ); 332 boot_tty_puts("\n\n"); 318 unsigned int start_id = vspace[vspace_id].vobj_offset + 319 vspace[vspace_id].start_offset; 320 321 boot_puts("vspace "); 322 boot_putw(vspace_id); 323 324 boot_puts("\n - name = "); 325 boot_puts( vspace[vspace_id].name ); 326 boot_puts("\n - start_vobj = "); 327 boot_puts( vobj[start_id].name ); 328 boot_puts("\n - vsegs = "); 329 boot_putw( vspace[vspace_id].vsegs ); 330 boot_puts("\n - vobjs = "); 331 boot_putw( vspace[vspace_id].vobjs ); 332 boot_puts("\n - tasks = "); 333 boot_putw( vspace[vspace_id].tasks ); 334 boot_puts("\n - vseg_offset = "); 335 boot_putw( vspace[vspace_id].vseg_offset ); 336 boot_puts("\n - vobj_offset = "); 337 boot_putw( vspace[vspace_id].vobj_offset ); 338 boot_puts("\n - task_offset = "); 339 boot_putw( vspace[vspace_id].task_offset ); 340 boot_puts("\n\n"); 333 341 334 342 for ( vseg_id = vspace[vspace_id].vseg_offset ; … … 336 344 vseg_id++ ) 337 345 { 338 boot_tty_puts(" private vseg "); 339 boot_tty_putw( vseg_id ); 340 341 boot_tty_puts("\n - name = "); 342 boot_tty_puts( vseg[vseg_id].name ); 343 boot_tty_puts("\n - vbase = "); 344 boot_tty_putw( vseg[vseg_id].vbase ); 345 boot_tty_puts("\n - length = "); 346 boot_tty_putw( vseg[vseg_id].length ); 347 boot_tty_puts("\n - mode = "); 348 boot_tty_putw( vseg[vseg_id].mode ); 349 boot_tty_puts("\n - ident = "); 350 boot_tty_putw( vseg[vseg_id].ident ); 351 boot_tty_puts("\n - psegname = "); 352 boot_tty_puts( pseg[vseg[vseg_id].psegid].name ); 353 boot_tty_puts("\n"); 354 for ( vobj_id = vseg[vseg_id].vobj_offset ; vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; vobj_id++ ) 346 boot_puts(" private vseg "); 347 boot_putw( vseg_id ); 348 349 boot_puts("\n - name = "); 350 boot_puts( vseg[vseg_id].name ); 351 boot_puts("\n - vbase = "); 352 boot_putw( vseg[vseg_id].vbase ); 353 boot_puts("\n - length = "); 354 boot_putw( vseg[vseg_id].length ); 355 boot_puts("\n - mode = "); 356 boot_putw( vseg[vseg_id].mode ); 357 boot_puts("\n - ident = "); 358 boot_putw( vseg[vseg_id].ident ); 359 boot_puts("\n - psegname = "); 360 boot_puts( pseg[vseg[vseg_id].psegid].name ); 361 boot_puts("\n - vobjs = "); 362 boot_putw( vseg[vseg_id].vobjs ); 363 boot_puts("\n - vobj_offset = "); 364 boot_putw( vseg[vseg_id].vobj_offset ); 365 boot_puts("\n"); 366 367 for ( vobj_id = vseg[vseg_id].vobj_offset ; 368 vobj_id < vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs ; 369 vobj_id++ ) 355 370 { 356 boot_tty_puts("\t\t vobjs = "); 357 boot_tty_putw( vobj[vobj_id].name); 358 boot_tty_puts("\n"); 359 boot_tty_puts("\t\t name = "); 360 boot_tty_putw( vobj[vobj_id].name); 361 boot_tty_puts("\n"); 362 boot_tty_puts("\t\t type = "); 363 boot_tty_putw( vobj[vobj_id].type); 364 boot_tty_puts("\n"); 365 boot_tty_puts("\t\t length = "); 366 boot_tty_putw( vobj[vobj_id].length); 367 boot_tty_puts("\n"); 368 boot_tty_puts("\t\t align = "); 369 boot_tty_putw( vobj[vobj_id].align); 370 boot_tty_puts("\n"); 371 boot_tty_puts("\t\t binpath = "); 372 boot_tty_putw( vobj[vobj_id].binpath); 373 boot_tty_puts("\n"); 371 boot_puts("\n\t\t vobj "); 372 boot_puts( vobj[vobj_id].name); 373 boot_puts("\n\t\t type = "); 374 boot_putw( vobj[vobj_id].type); 375 boot_puts("\n\t\t length = "); 376 boot_putw( vobj[vobj_id].length); 377 boot_puts("\n\t\t align = "); 378 boot_putw( vobj[vobj_id].align); 379 boot_puts("\n\t\t binpath = "); 380 boot_puts( vobj[vobj_id].binpath); 381 boot_puts("\n\n"); 374 382 } 375 383 } … … 379 387 task_id++ ) 380 388 { 381 boot_tty_puts(" task"); 382 boot_tty_putw( task_id ); 383 384 boot_tty_puts("\n - name = "); 385 boot_tty_puts( task[task_id].name ); 386 boot_tty_puts("\n - clusterid = "); 387 boot_tty_putw( task[task_id].clusterid ); 388 boot_tty_puts("\n - proclocid = "); 389 boot_tty_putw( task[task_id].proclocid ); 390 boot_tty_puts("\n - vobjlocid = "); 391 boot_tty_putw( task[task_id].vobjlocid ); 392 boot_tty_puts("\n - startid = "); 393 boot_tty_putw( task[task_id].startid ); 394 boot_tty_puts("\n - ttylocid = "); 395 boot_tty_putw( task[task_id].ttylocid ); 396 boot_tty_puts("\n\n"); 389 boot_puts(" task"); 390 boot_putw( task_id ); 391 392 boot_puts("\n - name = "); 393 boot_puts( task[task_id].name ); 394 boot_puts("\n - clusterid = "); 395 boot_putw( task[task_id].clusterid ); 396 boot_puts("\n - proclocid = "); 397 boot_putw( task[task_id].proclocid ); 398 boot_puts("\n - vobjlocid = "); 399 boot_putw( task[task_id].vobjlocid ); 400 boot_puts("\n - startid = "); 401 boot_putw( task[task_id].startid ); 402 boot_puts("\n - use_tty = "); 403 boot_putw( task[task_id].use_tty ); 404 boot_puts("\n - use_fb = "); 405 boot_putw( task[task_id].use_fb ); 406 boot_puts("\n\n"); 397 407 } 398 408 } … … 403 413 // boot_pseg_get() 404 414 // This function returns the pointer on a physical segment 405 // identified by the segmentindex.415 // identified by the pseg index. 406 416 ////////////////////////////////////////////////////////////////////////////// 407 417 mapping_pseg_t* boot_pseg_get( unsigned int seg_id) … … 413 423 if ( seg_id >= header->psegs ) 414 424 { 415 boot_ tty_puts("\n[BOOT ERROR] : seg_id argument too large\n");416 boot_ tty_puts(" in function boot_pseg_get()\n");425 boot_puts("\n[BOOT ERROR] : seg_id argument too large\n"); 426 boot_puts(" in function boot_pseg_get()\n"); 417 427 boot_exit(); 418 428 } … … 420 430 return &pseg[seg_id]; 421 431 } // end boot_pseg_get() 422 423 432 424 433 ////////////////////////////////////////////////////////////////////////////// … … 450 459 451 460 452 unsigned int max_pt e2 = _max_pte2[vspace_id];453 if(max_pt e2 == 0)454 { 455 boot_ tty_puts("Unfound page table for vspace ");456 boot_ tty_putw(vspace_id);457 boot_ tty_puts("\n");461 unsigned int max_pt2 = _max_pt2[vspace_id]; 462 if(max_pt2 == 0) 463 { 464 boot_puts("Unfound page table for vspace "); 465 boot_putw(vspace_id); 466 boot_puts("\n"); 458 467 boot_exit(); 459 468 } … … 463 472 { 464 473 pt2_id = _next_free_pt2[vspace_id]; 465 if ( pt2_id == max_pt e2 )466 { 467 boot_ tty_puts("\n[BOOT ERROR] in boot_add_pte() function\n");468 boot_ tty_puts("the length of the ptab vobj is too small\n");474 if ( pt2_id == max_pt2 ) 475 { 476 boot_puts("\n[BOOT ERROR] in boot_add_pte() function\n"); 477 boot_puts("the length of the ptab vobj is too small\n"); 469 478 boot_exit(); 470 479 } … … 487 496 if ( ( *pt_flags & PTE_V) != 0 ) // page already mapped 488 497 { 489 if(global) 490 { 491 boot_tty_puts("\n[BOOT ERROR] in boot_add_pte() function\n"); 492 boot_tty_puts("page already mapped\n"); 493 boot_exit(); 494 }else 495 { 496 /** 497 * The case where a global vseg is already mapped as private vseg of a 498 * vspace_id. Typically used when a vseg is being replicated. 499 */ 500 boot_tty_puts("\n[BOOT] global PTE for vspace "); 501 boot_tty_putw(vspace_id); 502 boot_tty_puts(" already mapped, vpn = "); 503 boot_tty_putw(vpn); 504 boot_tty_puts("\n"); 505 return; 506 } 498 boot_puts("\n[BOOT ERROR] in boot_add_pte() function\n"); 499 boot_puts("page already mapped\n"); 500 boot_exit(); 507 501 } 508 502 … … 549 543 550 544 #if BOOT_DEBUG_PT 551 boot_tty_puts("- vseg "); 552 boot_tty_puts( vseg[vseg_id].name ); 553 boot_tty_puts(" / flags = "); 554 boot_tty_putw( flags ); 555 boot_tty_puts("\n"); 545 boot_puts("- vseg "); 546 boot_puts( vseg[vseg_id].name ); 547 boot_puts(" / flags = "); 548 boot_putw( flags ); 549 boot_puts(" / npages = "); 550 boot_putw( npages ); 551 boot_puts("\n"); 556 552 #endif 557 553 // loop on 4K pages … … 583 579 584 580 #if BOOT_DEBUG_PT 585 boot_ tty_puts("- vseg ");586 boot_ tty_puts( vseg[vseg_id].name );587 boot_ tty_puts(" / flags = ");588 boot_ tty_putw( flags );589 boot_ tty_puts(" / npages = ");590 boot_ tty_putw( npages );591 boot_ tty_puts("\n");581 boot_puts("- vseg "); 582 boot_puts( vseg[vseg_id].name ); 583 boot_puts(" / flags = "); 584 boot_putw( flags ); 585 boot_puts(" / npages = "); 586 boot_putw( npages ); 587 boot_puts("\n"); 592 588 #endif 593 589 // loop on 4K pages … … 606 602 } // end boot_vspace_pt_build() 607 603 608 609 604 /////////////////////////////////////////////////////////////////////////// 610 605 // Align the value "toAlign" to the required alignement indicated by 611 606 // alignPow2 ( the logarithme of 2 the alignement). 612 607 /////////////////////////////////////////////////////////////////////////// 613 unsigned int align_to( unsigned toAlign, unsigned alignPow2) 614 { 615 unsigned mask = (1 << alignPow2) - 1; 616 return ((toAlign + mask ) & ~mask );//page aligned 617 } 618 619 /////////////////////////////////////////////////////////////////////////// 620 // Initialise vobjs 621 // For now only one type is initialised the: PTAB 622 // 623 // param: 624 // vobj: the vobj to initialise 625 // region_id: the vspace in wich the vobj is located or the global space(-1). 626 /////////////////////////////////////////////////////////////////////////// 627 void initailise_vobj(mapping_vobj_t* vobj, unsigned int region_id) 628 { 629 if(vobj->type == PTAB) 630 { 631 if(region_id == ((unsigned int) -1)) 632 { 633 boot_tty_puts( "No PTAB vobjs are allowed in the global region" ); 634 boot_exit(); 635 } 636 if(vobj->length < (PT1_SIZE + PT2_SIZE) ) //at least one pt2 => ( max_pt2 >= 1) 637 { 638 boot_tty_puts("PTAB too small, minumum size is "); 639 boot_tty_putw( PT1_SIZE + PT2_SIZE); 640 boot_exit(); 641 } 642 643 _ptabs[region_id] = (page_table_t*) vobj->paddr; 644 _max_pte2[region_id] = (vobj->length - PT1_SIZE) / PT2_SIZE; 645 646 #if BOOT_DEBUG_VIEW 647 boot_tty_puts("ptabs for vspace "); 648 boot_tty_putw(region_id); 649 boot_tty_puts(" address: "); 650 boot_tty_putw((unsigned)_ptabs[region_id]); 651 boot_tty_puts("\n"); 652 #endif 653 } 608 unsigned int align_to( unsigned int toAlign, 609 unsigned int alignPow2) 610 { 611 unsigned int mask = (1 << alignPow2) - 1; 612 return ((toAlign + mask ) & ~mask ); 654 613 } 655 614 … … 660 619 // It updates the page allocator (nextfreepage field of the pseg), 661 620 // and checks a possible pseg overflow. 662 // region_id: the vspace in wich the vseg is located or the global space(-1).621 // It is a global vseg if vspace_id = (-1) 663 622 /////////////////////////////////////////////////////////////////////////// 664 void boot_vseg_map( mapping_vseg_t* vseg, unsigned int region_id ) 665 { 666 unsigned pages; 667 unsigned vobj_id; 668 unsigned cur_vaddr; 669 unsigned cur_paddr; 623 void boot_vseg_map( mapping_vseg_t* vseg, 624 unsigned int vspace_id ) 625 { 626 unsigned int pages; 627 unsigned int vobj_id; 628 unsigned int cur_vaddr; 629 unsigned int cur_paddr; 670 630 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 671 631 mapping_vobj_t* vobj = boot_get_vobj_base( header ); … … 677 637 if ( vseg->ident != 0 ) // identity mapping required 678 638 { 679 // check physical segment overflow 680 if ( (vseg->vbase < pseg->base) || 681 ((vseg->vbase + vseg->length) > (pseg->base + pseg->length)) ) 682 { 683 boot_tty_puts("\n[BOOT ERROR] in boot_vseg_map() function\n"); 684 boot_tty_puts("impossible identity mapping for virtual segment: "); 685 boot_tty_puts( vseg->name ); 686 boot_tty_puts("\n"); 687 boot_exit(); 688 } 689 vseg->pbase = vseg->vbase; 639 vseg->pbase = vseg->vbase; 690 640 } 691 641 else // unconstrained mapping 692 642 { 693 // check physical segment overflow694 if ( (vseg->vbase + vseg->length) > (pseg->base + pseg->length) )695 {696 boot_tty_puts("\n[BOOT ERROR] in boot_vseg_map() function\n");697 boot_tty_puts("physical segment ");698 boot_tty_puts( pseg->name );699 boot_tty_puts(" is too small to map virtual segment");700 boot_tty_puts( vseg->name );701 boot_tty_puts("\n");702 boot_exit();703 }704 643 vseg->pbase = pseg->base + (pseg->next_free_page<<12); 705 644 } 706 645 707 708 //loop on vobj: 709 // + to computes the length of the current vseg 710 // + Align vobjs 711 // + Initialise the vobj 646 // loop on vobjs to computes the length of the vseg, 647 // initialise the vaddr and paddr fields of all vobjs, 648 // and initialise the page table pointers array 712 649 cur_vaddr = vseg->vbase; 713 650 cur_paddr = vseg->pbase; 714 for(vobj_id= vseg->vobj_offset; vobj_id < (vseg->vobj_offset + vseg->vobjs); vobj_id++) 715 { 716 if(vobj[vobj_id].align) 651 652 for( vobj_id = vseg->vobj_offset; 653 vobj_id < (vseg->vobj_offset + vseg->vobjs); 654 vobj_id++) 655 { 656 if ( vobj[vobj_id].align ) 717 657 { 718 658 cur_paddr = align_to(cur_paddr, vobj[vobj_id].align); 719 659 } 720 660 721 // set vaddr/paddr661 // set vaddr/paddr 722 662 vobj[vobj_id].vaddr = cur_vaddr; 723 663 vobj[vobj_id].paddr = cur_paddr; 724 664 725 // set next vaddr/paddr665 // set next vaddr/paddr 726 666 cur_vaddr += vobj[vobj_id].length; 727 667 cur_paddr += vobj[vobj_id].length; 728 initailise_vobj(&vobj[vobj_id], region_id); 668 669 // initialise _ptabs[] and _max_pt2[] 670 if ( vobj[vobj_id].type == VOBJ_TYPE_PTAB ) 671 { 672 if(vobj[vobj_id].length < (PT1_SIZE + PT2_SIZE) ) // max_pt2 >= 1 673 { 674 boot_puts( "\n[BOOT ERROR] in boot_vseg_map() function: " ); 675 boot_puts("PTAB vobj is too small in vspace "); 676 boot_putw(vspace_id); 677 boot_puts("\n"); 678 boot_exit(); 679 } 680 if(vspace_id == ((unsigned int) -1)) // global vseg 681 { 682 boot_puts( "\n[BOOT ERROR] in boot_vseg_map() function: " ); 683 boot_puts( "a PTAB vobj cannot be global" ); 684 boot_exit(); 685 } 686 _ptabs[vspace_id] = (page_table_t*)vobj[vobj_id].paddr; 687 _max_pt2[vspace_id] = (vobj[vobj_id].length - PT1_SIZE) / PT2_SIZE; 688 } 729 689 } 730 690 731 //set the length 732 vseg->length = align_to((cur_paddr - vseg->pbase), 12); 691 //set the vseg length 692 unsigned int plength = pseg->length; 693 unsigned int vlength = cur_paddr - vseg->pbase; 694 vseg->length = align_to(vlength, 12); 695 696 // checking pseg overflow 697 if ( (vseg->pbase < pseg->base) || 698 ((vseg->pbase + vlength) > (pseg->base + plength)) ) 699 { 700 boot_puts("\n[BOOT ERROR] in boot_vseg_map() function\n"); 701 boot_puts("impossible identity mapping for virtual segment: "); 702 boot_puts( vseg->name ); 703 boot_puts("\n"); 704 boot_puts("vseg pbase = "); 705 boot_putw( vseg->pbase ); 706 boot_puts("\n"); 707 boot_puts("vseg length = "); 708 boot_putw( vseg->length ); 709 boot_puts("\n"); 710 boot_puts("pseg pbase = "); 711 boot_putw( pseg->base ); 712 boot_puts("\n"); 713 boot_puts("pseg length = "); 714 boot_putw( pseg->length ); 715 boot_puts("\n"); 716 boot_exit(); 717 } 733 718 734 719 // computes number of pages … … 743 728 744 729 #if BOOT_DEBUG_PT 745 boot_ tty_puts("- vseg ");746 boot_ tty_puts( vseg->name );747 boot_ tty_puts(" : vbase = ");748 boot_ tty_putw( vseg->vbase );749 boot_ tty_puts(" / pbase = ");750 boot_ tty_putw( vseg->pbase );751 boot_ tty_puts("\n");730 boot_puts("- vseg "); 731 boot_puts( vseg->name ); 732 boot_puts(" : vbase = "); 733 boot_putw( vseg->vbase ); 734 boot_puts(" / pbase = "); 735 boot_putw( vseg->pbase ); 736 boot_puts("\n"); 752 737 #endif 753 738 … … 755 740 756 741 ///////////////////////////////////////////////////////////////////// 757 // This function che ks the mapping_info data structure742 // This function checks the mapping_info data structure 758 743 ///////////////////////////////////////////////////////////////////// 759 744 void boot_check_mapping() … … 764 749 if ( header->signature != IN_MAPPING_SIGNATURE ) 765 750 { 766 boot_ tty_puts("\n[BOOT ERROR] Illegal mapping signature: ");767 boot_ tty_putw(header->signature);768 boot_ tty_puts("\n");751 boot_puts("\n[BOOT ERROR] Illegal mapping signature: "); 752 boot_putw(header->signature); 753 boot_puts("\n"); 769 754 boot_exit(); 770 755 } … … 777 762 if ( header->clusters != NB_CLUSTERS ) 778 763 { 779 boot_ tty_puts("\n[BOOT ERROR] Incoherent NB_CLUSTERS");780 boot_ tty_puts("\n - In giet_config, value = ");781 boot_ tty_putw ( NB_CLUSTERS );782 boot_ tty_puts("\n - In mapping_info, value = ");783 boot_ tty_putw ( header->clusters );784 boot_ tty_puts("\n");764 boot_puts("\n[BOOT ERROR] Incoherent NB_CLUSTERS"); 765 boot_puts("\n - In giet_config, value = "); 766 boot_putw ( NB_CLUSTERS ); 767 boot_puts("\n - In mapping_info, value = "); 768 boot_putw ( header->clusters ); 769 boot_puts("\n"); 785 770 boot_exit(); 786 771 } … … 789 774 if ( header->ttys != NB_TTYS ) 790 775 { 791 boot_ tty_puts("\n[BOOT ERROR] Incoherent NB_TTYS");792 boot_ tty_puts("\n - In giet_config, value = ");793 boot_ tty_putw ( NB_TTYS );794 boot_ tty_puts("\n - In mapping_info, value = ");795 boot_ tty_putw ( header->ttys );796 boot_ tty_puts("\n");776 boot_puts("\n[BOOT ERROR] Incoherent NB_TTYS"); 777 boot_puts("\n - In giet_config, value = "); 778 boot_putw ( NB_TTYS ); 779 boot_puts("\n - In mapping_info, value = "); 780 boot_putw ( header->ttys ); 781 boot_puts("\n"); 797 782 boot_exit(); 798 783 } … … 801 786 if ( header->vspaces > GIET_NB_VSPACE_MAX ) 802 787 { 803 boot_ tty_puts("\n[BOOT ERROR] : number of vspaces > GIET_NB_VSPACE_MAX\n");804 boot_ tty_puts("\n");788 boot_puts("\n[BOOT ERROR] : number of vspaces > GIET_NB_VSPACE_MAX\n"); 789 boot_puts("\n"); 805 790 boot_exit(); 806 791 } … … 825 810 unsigned int pseg_id; 826 811 827 // first loop on virtual spaces to map global vsegs 812 // checking mapping_info 813 boot_check_mapping(); 814 815 // physical page allocators must be initialised 816 for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) 817 { 818 pseg[pseg_id].next_free_page = 0; 819 } 828 820 829 821 #if BOOT_DEBUG_PT 830 boot_ tty_puts("\n******* mapping global vsegs ********");822 boot_puts("\n******* mapping global vsegs ********\n"); 831 823 #endif 832 824 833 // physical page allocators must be initialised ??? 834 for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) 835 { 836 pseg[pseg_id].next_free_page = 0; 837 } 838 825 // step 1 : first loop on virtual spaces to map global vsegs 839 826 for ( vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ ) 840 827 { … … 842 829 } 843 830 844 // loop on virtual vspaces to map private vsegs831 // step 2 : loop on virtual vspaces to map private vsegs 845 832 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 846 833 { 847 834 848 835 #if BOOT_DEBUG_PT 849 boot_ tty_puts("\n******* mapping private vsegs in vspace ");850 boot_ tty_puts(vspace[vspace_id].name);851 boot_ tty_puts(" ********\n");836 boot_puts("\n******* mapping private vsegs in vspace "); 837 boot_puts(vspace[vspace_id].name); 838 boot_puts(" ********\n"); 852 839 #endif 853 840 … … 860 847 } 861 848 862 // loop on the vspaces to build the page tables849 // step 3 : loop on the vspaces to build the page tables 863 850 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 864 851 { 865 852 866 853 #if BOOT_DEBUG_PT 867 boot_ tty_puts("\n******* building page table for vspace ");868 boot_ tty_puts(vspace[vspace_id].name);869 boot_ tty_puts(" ********\n");854 boot_puts("\n******* building page table for vspace "); 855 boot_puts(vspace[vspace_id].name); 856 boot_puts(" ********\n"); 870 857 #endif 871 858 872 859 boot_vspace_pt_build( vspace_id ); 860 861 #if BOOT_DEBUG_PT 862 boot_puts(">>> page table physical address = "); 863 boot_putw((unsigned)_ptabs[vspace_id]); 864 boot_puts("\n"); 865 #endif 873 866 } 867 868 boot_puts("\n[BOOT] Page Tables initialisation completed at cycle "); 869 boot_putw( boot_time() ); 870 boot_puts("\n"); 871 874 872 } // end boot_pt_init() 875 876 877 878 ////////////////////////////////////////////////////////////////////////////////////879 // boot_init()880 // This function is executed by one single processor to initialize the page881 // tables, the tasks contexts and the peripherals, for all applications.882 ////////////////////////////////////////////////////////////////////////////////////883 void boot_init()884 {885 // checking mapping_info886 boot_check_mapping();887 888 // building page tables889 boot_pt_init();890 boot_tty_puts("\n[BOOT] Page Tables completed at cycle ");891 boot_tty_putw( boot_time() );892 boot_tty_puts("\n");893 894 } // end boot_init()895 873 896 874 // Local Variables: -
soft/giet_vm/boot/reset.S
r162 r165 1 1 /********************************************************************************/ 2 /* File : reset.S 3 /* Author : Alain Greiner & Mohamed karaoui 4 /* Date : 03/06/2012 */2 /* File : reset.S */ 3 /* Author : Alain Greiner & Mohamed karaoui */ 4 /* Date : 03/06/2012 */ 5 5 /********************************************************************************/ 6 6 /* This boot code is for a multi-cluster, multi-processor architecture, */ 7 /* running one or several multi-tasks software application(s) defined in the*/7 /* running one or several multi-tasks software application(s) defined in */ 8 8 /* the mapping_info data-structure. */ 9 /* It uses the mapping_info data structure to build the page tables.*/10 /* Processor 0 is in charge of building all pages tables.*/9 /* Procesor 0 uses the mapping_info data structure to build all page tables */ 10 /* before jumping to the kernel_init code. */ 11 11 /* Other processors are waiting until the mapping_info signature has been */ 12 12 /* modified by processor 0 (done while executing kernel_init code). */ 13 /* Implementation note: */ 13 14 /* The entry point is 0xbfc00000, but the actual boot code starts at address */ 14 15 /* 0xbfc00500, and a minimal boot exception handler is implemented at address */ … … 17 18 18 19 #include <giet_config.h> 19 #include <mips32_registers.h>20 #include "../sys/mips32_registers.h" 20 21 21 22 #define EXCEP_ORG 0x380 … … 44 45 boot_excep: 45 46 la a0, boot_error_string 46 jal boot_ tty_puts47 jal boot_puts 47 48 nop 48 49 mfc0 a0, CP0_TIME 49 jal boot_ tty_putw50 jal boot_putw 50 51 nop 51 52 la a0, boot_lf_string 52 jal boot_tty_puts 53 jal boot_puts 54 nop 55 56 la a0, boot_pid_string 57 jal boot_puts 58 nop 59 mfc0 k0, CP0_PROCID 60 andi a0, k0, 0xFFF 61 jal boot_putw 62 nop 63 la a0, boot_lf_string 64 jal boot_puts 53 65 nop 54 66 55 67 la a0, boot_epc_string 56 jal boot_ tty_puts68 jal boot_puts 57 69 nop 58 70 mfc0 a0, CP0_EPC 59 60 jal boot_tty_putw 71 jal boot_putw 61 72 nop 62 73 la a0, boot_lf_string 63 jal boot_ tty_puts74 jal boot_puts 64 75 nop 65 76 66 77 la a0, boot_cr_string 67 jal boot_ tty_puts78 jal boot_puts 68 79 nop 69 80 mfc0 a0, CP0_CR 70 jal boot_ tty_putw81 jal boot_putw 71 82 nop 72 83 la a0, boot_lf_string 73 jal boot_ tty_puts84 jal boot_puts 74 85 nop 75 86 76 87 la a0, boot_sr_string 77 jal boot_ tty_puts88 jal boot_puts 78 89 nop 79 90 mfc0 a0, CP0_SR 80 jal boot_ tty_putw91 jal boot_putw 81 92 nop 82 93 la a0, boot_lf_string 83 jal boot_ tty_puts94 jal boot_puts 84 95 nop 85 96 86 97 la a0, boot_bar_string 87 jal boot_ tty_puts98 jal boot_puts 88 99 nop 89 100 mfc0 a0, CP0_BAR 90 jal boot_ tty_putw101 jal boot_putw 91 102 nop 92 103 la a0, boot_lf_string 93 jal boot_ tty_puts104 jal boot_puts 94 105 nop 95 106 … … 101 112 /*******************************************/ 102 113 .align 2 103 114 .org START_ORG 104 115 105 116 boot_start: 106 117 /* get the procid */ 107 118 mfc0 k0, CP0_PROCID 108 andi k0, k0, 0x3FF /* no more than 1024processors... */119 andi k0, k0, 0xFFF /* no more than 4096 processors... */ 109 120 110 111 121 /* Only processor 0 does init */ 122 bne k0, zero, boot_wait_signature 112 123 nop 113 124 114 /* temporary stack for procesor 0 : 16K*/115 116 addiu sp, sp, 0x4000 125 /* Processor 0 get a temporary stack */ 126 la sp, seg_boot_stack_base 127 addiu sp, sp, 0x3000 /* SP <= seg_boot_stack + 12K */ 117 128 118 /* plat-form initialisation*/119 jal boot_init129 /* Processor 0 initialises all Page Tables */ 130 jal boot_pt_init 120 131 nop 121 j to_kinit 132 133 /* jump to kernel_init */ 134 j boot_to_kernel_init 122 135 nop 123 136 124 137 boot_wait_signature: 138 139 /* all other processors are waiting signature change */ 125 140 la k0, seg_mapping_base 126 cache 0x11, 0(k0) 127 lw k0, 0(k0) /* k0 <= mapping_info[0]*/141 cache 0x11, 0(k0) /* invalidate local cache copy */ 142 lw k0, 0(k0) /* k0 <= mapping_info[0] */ 128 143 li k1, OUT_MAPPING_SIGNATURE 129 144 bne k1, k0, boot_wait_signature 130 145 nop 131 146 132 to_kinit: 133 /* All processors initialize PTPR / MODE */ 134 /* and jump to kernel_init code. */ 147 /* all other processors get a temporary stack of 256 bytes */ 148 la sp, seg_boot_stack_base 149 addiu sp, sp, 0x3100 150 mfc0 k0, CP0_PROCID 151 andi k0, k0, 0xFFF 152 sll k0, k0, 8 153 addu sp, sp, k0 /* SP <= seg_boot_stack_base + 12K + (pid+1)*256 */ 135 154 136 /* get the procid */ 137 mfc0 s0, CP0_PROCID 138 andi s0, s0, 0x3FF /* no more than 1024 processors... TOFIX*/ 155 boot_to_kernel_init: 139 156 140 /* load a PTPR*/141 157 /* all processors initialize PTPR with PTAB[0] */ 158 la k1, _ptabs 142 159 lw k1, 0(k1) 143 160 srl k1, k1, 13 144 mtc2 k1, CP2_PTPR /* ptpr<= _ptabs[0] */161 mtc2 k1, CP2_PTPR /* PTPR <= _ptabs[0] */ 145 162 146 /* a ctivatesMMU */147 lik1, 0xF148 mtc2 k1, CP2_MODE /* loadMODE register */163 /* all processors activate MMU */ 164 li k1, 0xF 165 mtc2 k1, CP2_MODE /* MODE register */ 149 166 150 167 /* jump to kernel_init */ 151 168 la k0, seg_kernel_init_base 152 169 j k0 153 170 nop 154 171 155 156 boot_ error_string: .asciiz "\n[BOOT] Fatal Error at cycle"172 boot_error_string: .asciiz "\n[BOOT] Fatal Error in reset.S at cycle " 173 boot_pid_string: .asciiz " PID = " 157 174 boot_sr_string: .asciiz " SR = " 158 175 boot_cr_string: .asciiz " CR = "
Note: See TracChangeset
for help on using the changeset viewer.