Changeset 167 for soft/giet_vm/sys
- Timestamp:
- Jul 16, 2012, 10:26:27 AM (12 years ago)
- Location:
- soft/giet_vm/sys
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/sys/ctx_handler.c
r165 r167 15 15 // It contains copies of processor registers, when the task is not running, 16 16 // and some general informations associated to the task. 17 // 17 18 // - It contains GPR[i], generally stored in slot (i). $0, *26 & $27 are not saved. 18 19 // - It contains HI & LO registers. 19 20 // - It contains CP0 registers: EPC, SR, CR. 20 21 // - It contains CP2 registers : PTPR and MODE. 21 // - It contains the TTY index for the terminal allocated to the task. 22 // ctx[0] <- SR ctx[8] <- $8 ctx[16]<- $16 ctx[24]<- $24 ctx[32]<- EPC 23 // ctx[1] <- $1 ctx[9] <- $9 ctx[17]<- $17 ctx[25]<- $25 ctx[33]<- CR 24 // ctx[2] <- $2 ctx[10]<- $10 ctx[18]<- $18 ctx[26]<- LO ctx[34]<- TTY 25 // ctx[3] <- $3 ctx[11]<- $11 ctx[19]<- $19 ctx[27]<- HI ctx[35]<- PTPR 26 // ctx[4] <- $4 ctx[12]<- $12 ctx[20]<- $20 ctx[28]<- $28 ctx[36]<- MODE 27 // ctx[5] <- $5 ctx[13]<- $13 ctx[21]<- $21 ctx[29]<- $29 ctx[37]<- FBDMA 28 // ctx[6] <- $6 ctx[14]<- $14 ctx[22]<- $22 ctx[30]<- $30 ctx[38]<- reserved 29 // ctx[7] <- $7 ctx[15]<- $15 ctx[23]<- $23 ctx[31]<- $31 ctx[39]<- reserved 22 // - It contains the TTY global index, the FBDMA global index, the virtual base 23 // address of the page table (PTAB), and the task global index (TASK). 24 // 25 // ctx[0]<- SR|ctx[8] <- $8 |ctx[16]<- $16|ctx[24]<- $24|ctx[32]<- EPC |ctx[40]<- TTY 26 // ctx[1]<- $1|ctx[9] <- $9 |ctx[17]<- $17|ctx[25]<- $25|ctx[33]<- CR |ctx[41]<- FBDMA 27 // ctx[2]<- $2|ctx[10]<- $10|ctx[18]<- $18|ctx[26]<- LO |ctx[34]<- *** |ctx[42]<- PTAB 28 // ctx[3]<- $3|ctx[11]<- $11|ctx[19]<- $19|ctx[27]<- HI |ctx[35]<- PTPR|ctx[43]<- TASK 29 // ctx[4]<- $4|ctx[12]<- $12|ctx[20]<- $20|ctx[28]<- $28|ctx[36]<- MODE|ctx[44]<- *** 30 // ctx[5]<- $5|ctx[13]<- $13|ctx[21]<- $21|ctx[29]<- SP |ctx[37]<- *** |ctx[45]<- *** 31 // ctx[6]<- $6|ctx[14]<- $14|ctx[22]<- $22|ctx[30]<- $30|ctx[38]<- *** |ctx[46]<- *** 32 // ctx[7]<- $7|ctx[15]<- $15|ctx[23]<- $23|ctx[31]<- RA |ctx[39]<- *** |ctx[47]<- *** 30 33 ///////////////////////////////////////////////////////////////////////////////////// 31 34 … … 40 43 41 44 ///////////////////////////////////////////////////////////////////////////////// 42 // Global variables 45 // Global variables : array of schedulers (one scheduler per processor) 43 46 ///////////////////////////////////////////////////////////////////////////////// 44 47 45 static_scheduler_t _scheduler[NB_CLUSTERS * NB_PROCS];48 __attribute__((section (".kdata"))) static_scheduler_t _scheduler[NB_CLUSTERS * NB_PROCS]; 46 49 47 50 ///////////////////////////////////////////////////////////////////////////////// … … 64 67 unsigned int *next_context; 65 68 66 unsigned int pid = _procid(); 67 unsigned int time = _proctime(); 68 unsigned int tasks = _scheduler[pid].tasks; 69 unsigned int proc_id = _procid(); 70 unsigned int tasks = _scheduler[proc_id].tasks; 69 71 70 72 // return if only one task */ … … 72 74 73 75 // compute the task context base address for the current task 74 curr_task_id = _scheduler[p id].current;75 curr_context = &(_scheduler[p id].context[curr_task_id][0]);76 curr_task_id = _scheduler[proc_id].current; 77 curr_context = &(_scheduler[proc_id].context[curr_task_id][0]); 76 78 77 79 // select the next task using a round-robin scheduling policy … … 79 81 80 82 // compute the task context base address for the next task 81 next_context = &(_scheduler[p id].context[next_task_id][0]);83 next_context = &(_scheduler[proc_id].context[next_task_id][0]); 82 84 83 85 #if GIET_DEBUG_SWITCH 84 86 _get_lock( &_tty_put_lock ); 85 87 _puts( "\n[GIET] Context switch for processor "); 86 _putw( p id );88 _putw( proc_id ); 87 89 _puts( " at cycle "); 88 _putw( time);90 _putw( _proctime() ); 89 91 _puts("\n"); 90 92 _puts( " - tasks = "); … … 101 103 102 104 // update the scheduler state, and makes the task switch 103 _scheduler[p id].current = next_task_id;105 _scheduler[proc_id].current = next_task_id; 104 106 _task_switch( curr_context, next_context ); 105 107 -
soft/giet_vm/sys/ctx_handler.h
r165 r167 15 15 } static_scheduler_t; 16 16 17 ///////////////////////////////////////////////////////////////////////////////// 18 // Definition of the task context slots indexes 19 ///////////////////////////////////////////////////////////////////////////////// 20 21 #define CTX_SR_ID 0 22 #define CTX_SP_ID 29 23 #define CTX_RA_ID 31 24 25 #define CTX_EPC_ID 32 26 #define CTX_CR_ID 33 27 #define CTX_PTPR_ID 35 28 #define CTX_MODE_ID 36 29 30 #define CTX_TTY_ID 40 31 #define CTX_FBDMA_ID 41 32 #define CTX_PTAB_ID 42 33 #define CTX_TASK_ID 43 34 35 17 36 ////////////////////////////////////////////////////////////////////////////////// 18 37 // Prototype of the context switch function -
soft/giet_vm/sys/drivers.c
r166 r167 491 491 unsigned int count ) 492 492 { 493 unsigned int user_vpn_min; 494 unsigned int user_vpn_max; 495 unsigned int vpn; // virtual page number in user space 496 unsigned int ppn; // physical page number 497 unsigned int flags; // page protection flags 498 unsigned int ix2; // Page index (for IOMMU page table) 499 unsigned int addr; // buffer address for IOC 500 page_table_t* user_ptp; // user page table pointer 501 unsigned int ko; // bool returned by _v2p_translate() 502 unsigned int ppn_first; // first physical page number for user buffer 493 unsigned int user_vpn_min; // first virtuel page index in user space 494 unsigned int user_vpn_max; // last virtual page index in user space 495 unsigned int vpn; // current virtual page index in user space 496 unsigned int ppn; // physical page number 497 unsigned int flags; // page protection flags 498 unsigned int ix2; // page index in IOMMU PT1 page table 499 unsigned int addr; // buffer address for IOC peripheral 500 unsigned int user_ptp; // page table pointer in user space 501 unsigned int ko; // bool returned by _v2p_translate() 502 unsigned int ppn_first; // first physical page number for user buffer 503 unsigned int ltid; // current task local index 504 static_scheduler_t* psched; // pointer on the current task scheduler 503 505 504 506 // check buffer alignment … … 509 511 unsigned int length = count*block_size; 510 512 511 // get user space page table base address 512 user_ptp = (page_table_t*)(_get_ptpr() << 13); 513 // get user space page table virtual address 514 psched = &_scheduler[_procid()]; 515 ltid = psched->current; 516 user_ptp = psched->context[ltid][CTX_PTAB_ID]; 513 517 514 518 user_vpn_min = user_vaddr >> 12; … … 520 524 { 521 525 // get ppn and flags for each vpn 522 ko = _v2p_translate( user_ptp, // user page table pointer523 vpn, // virtual page number524 &ppn, // physical page number525 &flags ); // protection flags526 ko = _v2p_translate( (page_table_t*)user_ptp, 527 vpn, 528 &ppn, 529 &flags ); 526 530 527 531 // check access rights … … 543 547 ppn, // Physical page number 544 548 flags ); // Protection flags 545 546 // buffer base address for IOC with IOMMU547 549 } 548 550 else // no IOMMU : check that physical pages are contiguous … … 563 565 // compute buffer base address for IOC depending on IOMMU activation 564 566 if ( GIET_IOMMU_ACTIVE ) addr = (_ioc_iommu_ix1) << 21 | (user_vaddr & 0xFFF); 565 else addr = ppn_first| (user_vaddr & 0xFFF);567 else addr = (ppn_first << 12) | (user_vaddr & 0xFFF); 566 568 567 569 // get the lock on ioc device -
soft/giet_vm/sys/irq_handler.c
r165 r167 23 23 /////////////////////////////////////////////////////////////////////////////////// 24 24 25 _isr_func_t _interrupt_vector[32] = { [0 ... 31] = &_isr_default }; 25 __attribute__((section (".kdata"))) _isr_func_t _interrupt_vector[32] = 26 { [0 ... 31] = &_isr_default }; 26 27 27 28 /////////////////////////////////////////////////////////////////////////////////// -
soft/giet_vm/sys/kernel_init.c
r166 r167 31 31 32 32 /////////////////////////////////////////////////////////////////////////////////// 33 // array of pointers on the page tables 34 // (both physical and virtual addresses) 35 /////////////////////////////////////////////////////////////////////////////////// 36 37 __attribute__((section (".kdata"))) unsigned int _kernel_ptabs_paddr[GIET_NB_VSPACE_MAX]; 38 __attribute__((section (".kdata"))) unsigned int _kernel_ptabs_vaddr[GIET_NB_VSPACE_MAX]; 39 40 /////////////////////////////////////////////////////////////////////////////////// 33 41 // declarations required to avoid forward references 34 42 /////////////////////////////////////////////////////////////////////////////////// 35 43 36 void _kernel_vobjs_init( unsigned int*);37 void _kernel_tasks_init( unsigned int*);44 void _kernel_vobjs_init(void); 45 void _kernel_tasks_init(void); 38 46 void _kernel_peripherals_init(void); 39 47 void _kernel_interrupt_vector_init(void); … … 45 53 in_kinit void _kernel_init() 46 54 { 47 // array of pointers on the page tables (used for task context initialisation)48 unsigned int kernel_ptabs[GIET_NB_VSPACE_MAX];49 50 55 // values to be written in registers 51 56 unsigned int sp_value; … … 59 64 if ( pid == 0 ) 60 65 { 61 _kernel_vobjs_init( kernel_ptabs);62 _kernel_tasks_init( kernel_ptabs);66 _kernel_vobjs_init(); 67 _kernel_tasks_init(); 63 68 _kernel_interrupt_vector_init(); 64 69 _kernel_peripherals_init(); … … 163 168 // - ptpr page table base address / 8K 164 169 // - mode mmu_mode = 0xF (TLBs and caches activated) 170 // - ptab page table virtual address 165 171 //////////////////////////////////////////////////////////////////////////////// 166 172 in_kinit void _task_map( unsigned int task_id, // global index 167 173 unsigned int vspace_id, // global index 168 174 unsigned int tty_id, // TTY index 169 unsigned int fb_id, // FB index 170 unsigned int pt_base ) // page table base adddress 175 unsigned int fbdma_id ) // FBDMA index 171 176 { 172 177 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; … … 176 181 mapping_vobj_t* vobj = _get_vobj_base( header ); 177 182 183 178 184 // values to be initialised in task context 179 unsigned int ra = (unsigned int)&_eret;185 unsigned int ra = (unsigned int)&_eret; 180 186 unsigned int sr = 0x0000FF13; 181 187 unsigned int tty = tty_id; 182 unsigned int fb = fb_id; 183 unsigned int ptpr = pt_base >> 13; 188 unsigned int fb = fbdma_id; 189 unsigned int ptpr = _kernel_ptabs_paddr[vspace_id] >> 13; 190 unsigned int ptab = _kernel_ptabs_vaddr[vspace_id]; 184 191 unsigned int mode = 0xF; 185 192 unsigned int sp; 186 193 unsigned int epc; 187 194 188 // compute epc value 189 // Get the (virtual) base address of the start_vector that 190 // contains the start addresses for all tasks defined in a vspace. 195 // EPC : Get the (virtual) base address of the start_vector containing 196 // the start addresses for all tasks defined in a vspace. 191 197 mapping_vobj_t* vobj_data = &vobj[vspace[vspace_id].vobj_offset + 192 198 vspace[vspace_id].start_offset]; … … 194 200 epc = start_vector[task[task_id].startid]; 195 201 196 // compute sp value 197 // Get the vobj containing the stack 202 // SP : Get the vobj containing the stack 198 203 unsigned int vobj_id = task[task_id].vobjlocid + vspace[vspace_id].vobj_offset; 199 204 sp = vobj[vobj_id].vaddr + vobj[vobj_id].length; … … 220 225 _scheduler[proc_id].context[ltid][CTX_RA_ID] = ra; 221 226 _scheduler[proc_id].context[ltid][CTX_EPC_ID] = epc; 227 _scheduler[proc_id].context[ltid][CTX_PTPR_ID] = ptpr; 228 _scheduler[proc_id].context[ltid][CTX_MODE_ID] = mode; 222 229 _scheduler[proc_id].context[ltid][CTX_TTY_ID] = tty; 223 230 _scheduler[proc_id].context[ltid][CTX_FBDMA_ID] = fb; 224 _scheduler[proc_id].context[ltid][CTX_PTPR_ID] = ptpr; 225 _scheduler[proc_id].context[ltid][CTX_MODE_ID] = mode; 231 _scheduler[proc_id].context[ltid][CTX_PTAB_ID] = ptab; 226 232 _scheduler[proc_id].context[ltid][CTX_TASK_ID] = task_id; 227 233 228 #if INIT_DEBUG 234 #if INIT_DEBUG_CTX 229 235 _puts("Task "); 230 236 _puts( task[task_id].name ); … … 259 265 _puts("\n"); 260 266 267 _puts(" - PTPR = "); 268 _putw( ptpr<<13 ); 269 _puts(" saved at "); 270 _putw( (unsigned int)&_scheduler[proc_id].context[ltid][CTX_PTPR_ID] ); 271 _puts("\n"); 272 261 273 _puts(" - TTY = "); 262 274 _putw( tty ); … … 271 283 _puts("\n"); 272 284 273 _puts(" - PT PR= ");274 _putw( pt pr<<13);275 _puts(" saved at "); 276 _putw( (unsigned int)&_scheduler[proc_id].context[ltid][CTX_PT PR_ID] );285 _puts(" - PTAB = "); 286 _putw( ptab ); 287 _puts(" saved at "); 288 _putw( (unsigned int)&_scheduler[proc_id].context[ltid][CTX_PTAB_ID] ); 277 289 _puts("\n"); 278 290 #endif … … 284 296 // such as mwmr channels, barriers and locks, depending on the vobj type. 285 297 // (Most of the vobjs are not known, and not initialised by the compiler). 286 // This function initialises the kernel_ptabs[] array indexed by the vspace_id,287 // and containin tthe base addresses of all page tables.288 // This kernel_ptabs[] array is used to initialise the task contexts.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. 289 301 /////////////////////////////////////////////////////////////////////////////// 290 in_kinit void _kernel_vobjs_init( unsigned int* kernel_ptabs)302 in_kinit void _kernel_vobjs_init() 291 303 { 292 304 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; … … 302 314 char ptab_found = 0; 303 315 304 #if INIT_DEBUG 316 #if INIT_DEBUG_CTX 305 317 _puts("[INIT] --- vobjs initialisation in vspace "); 306 318 _puts(vspace[vspace_id].name); … … 317 329 { 318 330 ptab_found = 1; 319 kernel_ptabs[vspace_id] = vobj[vobj_id].paddr; 320 321 #if INIT_DEBUG 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_CTX 322 335 _puts("[INIT] PTAB address = "); 323 _putw( kernel_ptabs[vspace_id]);336 _putw(_kernel_ptabs_paddr[vspace_id]); 324 337 _puts("\n"); 325 338 #endif … … 334 347 mwmr->depth = (vobj[vobj_id].length>>2) - 5; 335 348 mwmr->lock = 0; 336 #if INIT_DEBUG 349 #if INIT_DEBUG_CTX 337 350 _puts("[INIT] MWMR channel "); 338 351 _puts( vobj->name); … … 346 359 { 347 360 348 #if INIT_DEBUG 361 #if INIT_DEBUG_CTX 349 362 _puts("[INIT] ELF section "); 350 363 _puts( vobj->name); … … 360 373 barrier->count = 0; 361 374 barrier->init = vobj[vobj_id].init; 362 #if INIT_DEBUG 375 #if INIT_DEBUG_CTX 363 376 _puts(" BARRIER "); 364 377 _puts( vobj->name); … … 373 386 unsigned int* lock = (unsigned int*)(vobj[vobj_id].vaddr); 374 387 *lock = 0; 375 #if INIT_DEBUG 388 #if INIT_DEBUG_CTX 376 389 _puts(" LOCK "); 377 390 _puts( vobj->name); … … 383 396 { 384 397 385 #if INIT_DEBUG 398 #if INIT_DEBUG_CTX 386 399 _puts(" BUFFER "); 387 400 _puts( vobj->name); … … 425 438 // TTY[0] is reserved for the kernel. 426 439 /////////////////////////////////////////////////////////////////////////////// 427 in_kinit void _kernel_tasks_init( unsigned int* ptabs)440 in_kinit void _kernel_tasks_init() 428 441 { 429 442 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; … … 461 474 { 462 475 463 #if INIT_DEBUG 476 #if INIT_DEBUG_CTX 464 477 _puts("\n[INIT] mapping tasks in vspace "); 465 478 _puts(vspace[vspace_id].name); … … 486 499 vspace_id, // vspace index 487 500 tty_id, // global tty index 488 fb_id, // global fbdma index 489 ptabs[vspace_id] ); // page table pointer 501 fb_id ); // global fbdma index 490 502 } // end loop on tasks 491 503 } // end oop on vspaces … … 495 507 _puts("\n"); 496 508 497 #if INIT_DEBUG 509 #if INIT_DEBUG_CTX 498 510 for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) 499 511 { … … 540 552 { 541 553 unsigned int* iob_address = (unsigned int*)&seg_iob_base; 542 unsigned int icu_address = (unsigned int)&seg_icu_base;543 554 544 555 // define IPI address mapping the IOC interrupt ...TODO... -
soft/giet_vm/sys/mips32_registers.h
r165 r167 78 78 #define CP2_DCACHE_INVAL_PA $20 79 79 80 /* Context index */81 82 #define CTX_SR_ID 083 #define CTX_SP_ID 2984 #define CTX_RA_ID 3185 #define CTX_EPC_ID 3286 #define CTX_TTY_ID 3487 #define CTX_PTPR_ID 3588 #define CTX_MODE_ID 3689 #define CTX_FBDMA_ID 3790 #define CTX_TASK_ID 6391 92 93 80 #endif -
soft/giet_vm/sys/sys.ld
r166 r167 3 3 *****************************************************************************/ 4 4 5 /* The vsegs used by the system are replicated in all virtual spaces5 /* The vsegs used by the system are mapped in all virtual spaces 6 6 They can be identity mapping... or not */ 7 7 8 8 seg_kernel_code_base = 0x80000000; /* system code */ 9 9 seg_kernel_data_base = 0x80010000; /* system cacheable data */ 10 seg_kernel_uncdata_base = 0x800 20000; /* system uncacheable data */11 seg_kernel_init_base = 0x800 30000; /* system page table */10 seg_kernel_uncdata_base = 0x80080000; /* system uncacheable data */ 11 seg_kernel_init_base = 0x80090000; /* system page table */ 12 12 seg_mapping_base = 0xBFC0C000; /* boot mapping_info */ 13 13 … … 16 16 must be defined, even if the peripherals are not used in the architecture */ 17 17 18 seg_tty_base = 0x90000000; /* TTY device */19 seg_timer_base = 0x91000000; /* Timer device */20 seg_ioc_base = 0x92000000; /* Block device */21 seg_dma_base = 0x93000000; /* DMA device */22 seg_gcd_base = 0x95000000; /* GCD device */23 seg_fb_base = 0x96000000; /* FrameBuffer device */24 seg_i cu_base = 0x9F000000; /* ICU or XICUdevice */25 seg_i ob_base = 0x9E000000; /* IOBdevice */18 seg_tty_base = 0x90000000; /* TTY device */ 19 seg_timer_base = 0x91000000; /* Timer device */ 20 seg_ioc_base = 0x92000000; /* Block device */ 21 seg_dma_base = 0x93000000; /* DMA device */ 22 seg_gcd_base = 0x95000000; /* GCD device */ 23 seg_fb_base = 0x96000000; /* FrameBuffer device */ 24 seg_iob_base = 0x9E000000; /* IOB device */ 25 seg_icu_base = 0x9F000000; /* ICU or XICU device */ 26 26 27 27 /* … … 40 40 seg_kernel_data : 41 41 { 42 *(.iommu) 43 *(.kdata) 42 44 *(.rodata) 43 /* . = ALIGN(4); */44 45 *(.rodata.*) 45 /* . = ALIGN(4); */46 46 *(.data) 47 /* . = ALIGN(4); */48 47 *(.lit8) 49 48 *(.lit4) 50 49 *(.sdata) 51 /* . = ALIGN(4); */52 50 *(.bss) 53 51 *(COMMON) -
soft/giet_vm/sys/sys_handler.c
r165 r167 75 75 void _exit() 76 76 { 77 unsigned int date = _proctime(); 77 78 unsigned int proc_id = _procid(); 78 79 unsigned int task_id = _scheduler[proc_id].current; … … 83 84 _puts(" on processor "); 84 85 _putw( proc_id ); 86 _puts(" at cycle "); 87 _putw( date ); 85 88 _puts("\n\n"); 86 89
Note: See TracChangeset
for help on using the changeset viewer.