- Timestamp:
- Feb 12, 2013, 6:33:31 PM (12 years ago)
- Location:
- soft/giet_vm
- Files:
-
- 1 added
- 41 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/boot/boot_init.c
r218 r228 56 56 #include <mwmr_channel.h> 57 57 #include <barrier.h> 58 #include <memspace.h> 58 59 #include <irq_handler.h> 59 60 #include <ctx_handler.h> … … 63 64 #include <stdarg.h> 64 65 65 #if !defined(NB_CLUSTERS) 66 67 #if !defined(NB_CLUSTERS) 66 68 # error The NB_CLUSTERS value must be defined in the 'giet_config.h' file ! 67 69 #endif 68 70 69 #if !defined(NB_PROCS_MAX) 71 #if !defined(NB_PROCS_MAX) 70 72 # error The NB_PROCS_MAX value must be defined in the 'giet_config.h' file ! 71 73 #endif 72 74 73 #if !defined(GIET_NB_VSPACE_MAX) 75 #if !defined(GIET_NB_VSPACE_MAX) 74 76 # error The GIET_NB_VSPACE_MAX value must be defined in the 'giet_config.h' file ! 75 77 #endif … … 82 84 83 85 // Page table pointers array 84 page_table_t *boot_ptabs_vaddr[GIET_NB_VSPACE_MAX];85 page_table_t *boot_ptabs_paddr[GIET_NB_VSPACE_MAX];86 page_table_t * boot_ptabs_vaddr[GIET_NB_VSPACE_MAX]; 87 page_table_t * boot_ptabs_paddr[GIET_NB_VSPACE_MAX]; 86 88 87 89 // Scheduler pointers array 88 static_scheduler_t *boot_schedulers_paddr[NB_CLUSTERS * NB_PROCS_MAX];90 static_scheduler_t * boot_schedulers_paddr[NB_CLUSTERS * NB_PROCS_MAX]; 89 91 90 92 // Next free PT2 index array 91 unsigned int 92 { [0 ... GIET_NB_VSPACE_MAX-1] = 0 };93 unsigned int boot_next_free_pt2[GIET_NB_VSPACE_MAX] = 94 { [0 ... GIET_NB_VSPACE_MAX - 1] = 0 }; 93 95 94 96 // Max PT2 index 95 unsigned int 96 { [0 ... GIET_NB_VSPACE_MAX-1] = 0 };97 unsigned int boot_max_pt2[GIET_NB_VSPACE_MAX] = 98 { [0 ... GIET_NB_VSPACE_MAX - 1] = 0 }; 97 99 98 100 … … 100 102 // boot_procid() 101 103 ////////////////////////////////////////////////////////////////////////////// 102 inline unsigned int boot_procid() 103 { 104 inline unsigned int boot_procid() { 104 105 unsigned int ret; 105 asm volatile ("mfc0 %0, $15, 1" : "=r"(ret));106 asm volatile ("mfc0 %0, $15, 1":"=r" (ret)); 106 107 return (ret & 0x3FF); 107 108 } 109 110 108 111 ////////////////////////////////////////////////////////////////////////////// 109 112 // boot_proctime() 110 113 ////////////////////////////////////////////////////////////////////////////// 111 inline unsigned int boot_proctime() 112 { 114 inline unsigned int boot_proctime() { 113 115 unsigned int ret; 114 asm volatile ("mfc0 %0, $9" : "=r"(ret));116 asm volatile ("mfc0 %0, $9":"=r" (ret)); 115 117 return ret; 116 118 } 119 120 117 121 ////////////////////////////////////////////////////////////////////////////// 118 122 // boot_exit() 119 123 ////////////////////////////////////////////////////////////////////////////// 120 void boot_exit() 121 { 122 while(1) asm volatile("nop"); 123 } 124 void boot_exit() { 125 while (1) { 126 asm volatile ("nop"); 127 } 128 } 129 130 124 131 ////////////////////////////////////////////////////////////////////////////// 125 132 // boot_eret() … … 127 134 // in all task contexts (when the task has never been executed. 128 135 /////////////////////////////////"///////////////////////////////////////////// 129 void boot_eret() 130 { 131 asm volatile("eret"); 132 } 136 void boot_eret() { 137 asm volatile ("eret"); 138 } 139 140 133 141 ////////////////////////////////////////////////////////////////////////////// 134 142 // boot_scheduler_set_context() … … 140 148 // - value : value to be written 141 149 ////////////////////////////////////////////////////////////////////////////// 142 inline void boot_scheduler_set_context( unsigned int gpid, 143 unsigned int ltid, 144 unsigned int slotid, 145 unsigned int value ) 146 { 150 inline void boot_scheduler_set_context(unsigned int gpid, 151 unsigned int ltid, 152 unsigned int slotid, 153 unsigned int value) { 147 154 // get scheduler physical address 148 static_scheduler_t *psched = boot_schedulers_paddr[gpid];149 155 static_scheduler_t * psched = boot_schedulers_paddr[gpid]; 156 150 157 // get slot physical address 151 unsigned int* pslot = &(psched->context[ltid][slotid]); 152 153 asm volatile ( "li $26, 0xB \n" 154 "mtc2 $26, $1 \n" /* desactivate DTLB */ 155 "sw %1, 0(%0) \n" /* *pslot <= value */ 156 "li $26, 0xF \n" 157 "mtc2 $26, $1 \n" /* activate DTLB */ 158 : 159 : "r"(pslot), "r"(value) 160 : "$26" ); 161 } 158 unsigned int * pslot = &(psched->context[ltid][slotid]); 159 160 asm volatile ("li $26, 0xB \n" 161 "mtc2 $26, $1 \n" /* desactivate DTLB */ 162 "sw %1, 0(%0) \n" /* *pslot <= value */ 163 "li $26, 0xF \n" 164 "mtc2 $26, $1 \n" /* activate DTLB */ 165 : 166 :"r" (pslot), "r"(value) 167 :"$26"); 168 } 169 170 162 171 ////////////////////////////////////////////////////////////////////////////// 163 172 // boot_scheduler_set_itvector() … … 168 177 // - value : value to be written 169 178 ////////////////////////////////////////////////////////////////////////////// 170 inline void boot_scheduler_set_itvector( unsigned int gpid, 171 unsigned int slotid, 172 unsigned int value ) 173 { 179 inline void boot_scheduler_set_itvector(unsigned int gpid, 180 unsigned int slotid, 181 unsigned int value) { 174 182 // get scheduler physical address 175 static_scheduler_t *psched = boot_schedulers_paddr[gpid];176 183 static_scheduler_t * psched = boot_schedulers_paddr[gpid]; 184 177 185 // get slot physical address 178 unsigned int* pslot = &(psched->interrupt_vector[slotid]); 179 180 asm volatile ( "li $26, 0xB \n" 181 "mtc2 $26, $1 \n" /* desactivate DTLB */ 182 "sw %1, 0(%0) \n" /* *pslot <= value */ 183 "li $26, 0xF \n" 184 "mtc2 $26, $1 \n" /* activate DTLB */ 185 : 186 : "r"(pslot), "r"(value) 187 : "$26" ); 188 } 186 unsigned int * pslot = &(psched->interrupt_vector[slotid]); 187 188 asm volatile ("li $26, 0xB \n" 189 "mtc2 $26, $1 \n" /* desactivate DTLB */ 190 "sw %1, 0(%0) \n" /* *pslot <= value */ 191 "li $26, 0xF \n" 192 "mtc2 $26, $1 \n" /* activate DTLB */ 193 : 194 :"r" (pslot), "r"(value) 195 :"$26"); 196 } 197 189 198 190 199 ////////////////////////////////////////////////////////////////////////////// … … 196 205 // - return the content of the slot 197 206 ////////////////////////////////////////////////////////////////////////////// 198 unsigned int boot_scheduler_get_itvector( unsigned int gpid, 199 unsigned int slotid) 200 { 207 unsigned int boot_scheduler_get_itvector(unsigned int gpid, unsigned int slotid) { 201 208 unsigned int value; 202 209 203 210 // get scheduler physical address 204 static_scheduler_t *psched = boot_schedulers_paddr[gpid];205 211 static_scheduler_t * psched = boot_schedulers_paddr[gpid]; 212 206 213 // get slot physical address 207 unsigned int * pslot= &(psched->interrupt_vector[slotid]);208 209 asm volatile ( 210 "mtc2 $26, $1 \n"/* desactivate DTLB */211 "lw %0, 0(%1) \n"/* *pslot <= value */212 "li $26, 0xF \n"213 "mtc2 $26, $1 \n"/* activate DTLB */214 : "=r"(value)215 : "r"(pslot)216 : "$26");214 unsigned int * pslot = &(psched->interrupt_vector[slotid]); 215 216 asm volatile ("li $26, 0xB \n" 217 "mtc2 $26, $1 \n" /* desactivate DTLB */ 218 "lw %0, 0(%1) \n" /* *pslot <= value */ 219 "li $26, 0xF \n" 220 "mtc2 $26, $1 \n" /* activate DTLB */ 221 :"=r" (value) 222 :"r"(pslot) 223 :"$26"); 217 224 return value; 218 225 } 226 219 227 220 228 ////////////////////////////////////////////////////////////////////////////// … … 224 232 // - gpid : global processor/scheduler index 225 233 ////////////////////////////////////////////////////////////////////////////// 226 inline unsigned int boot_scheduler_get_tasks( unsigned int gpid ) 227 { 228 unsigned int ret; 234 inline unsigned int boot_scheduler_get_tasks(unsigned int gpid) { 235 unsigned int ret; 229 236 230 237 // get scheduler physical address 231 static_scheduler_t *psched = boot_schedulers_paddr[gpid];232 238 static_scheduler_t * psched = boot_schedulers_paddr[gpid]; 239 233 240 // get tasks physical address 234 unsigned int *ptasks = &(psched->tasks);235 236 asm volatile ( 237 "mtc2 $26, $1 \n"/* desactivate DTLB */238 "lw %0, 0(%1) \n"/* ret <= *ptasks */239 "li $26, 0xF \n"240 "mtc2 $26, $1 \n"/* activate DTLB */241 : "=r"(ret)242 : "r"(ptasks)243 : "$26");241 unsigned int * ptasks = &(psched->tasks); 242 243 asm volatile ("li $26, 0xB \n" 244 "mtc2 $26, $1 \n" /* desactivate DTLB */ 245 "lw %0, 0(%1) \n" /* ret <= *ptasks */ 246 "li $26, 0xF \n" 247 "mtc2 $26, $1 \n" /* activate DTLB */ 248 :"=r" (ret) 249 :"r"(ptasks) 250 :"$26"); 244 251 return ret; 245 252 } 253 254 246 255 ////////////////////////////////////////////////////////////////////////////// 247 256 // boot_scheduler_set_tasks() … … 251 260 // - value : value to be written 252 261 ////////////////////////////////////////////////////////////////////////////// 253 inline void boot_scheduler_set_tasks( unsigned int gpid, 254 unsigned int value ) 255 { 262 inline void boot_scheduler_set_tasks(unsigned int gpid, unsigned int value) { 256 263 // get scheduler physical address 257 static_scheduler_t *psched = boot_schedulers_paddr[gpid];258 264 static_scheduler_t * psched = boot_schedulers_paddr[gpid]; 265 259 266 // get tasks physical address 260 unsigned int* ptasks = &(psched->tasks); 261 262 asm volatile ( "li $26, 0xB \n" 263 "mtc2 $26, $1 \n" /* desactivate DTLB */ 264 "sw %1, 0(%0) \n" /* *ptasks <= value */ 265 "li $26, 0xF \n" 266 "mtc2 $26, $1 \n" /* activate DTLB */ 267 : 268 : "r"(ptasks), "r"(value) 269 : "$26" ); 270 } 267 unsigned int * ptasks = &(psched->tasks); 268 269 asm volatile ("li $26, 0xB \n" 270 "mtc2 $26, $1 \n" /* desactivate DTLB */ 271 "sw %1, 0(%0) \n" /* *ptasks <= value */ 272 "li $26, 0xF \n" 273 "mtc2 $26, $1 \n" /* activate DTLB */ 274 : 275 :"r" (ptasks), "r"(value) 276 :"$26"); 277 } 278 279 271 280 ////////////////////////////////////////////////////////////////////////////// 272 281 // boot_scheduler_set_current() … … 276 285 // - value : value to be written 277 286 ////////////////////////////////////////////////////////////////////////////// 278 inline void boot_scheduler_set_current( unsigned int gpid, 279 unsigned int value ) 280 { 287 inline void boot_scheduler_set_current(unsigned int gpid, unsigned int value) { 281 288 // get scheduler physical address 282 static_scheduler_t *psched = boot_schedulers_paddr[gpid];283 289 static_scheduler_t *psched = boot_schedulers_paddr[gpid]; 290 284 291 // get tasks physical address 285 unsigned int* pcur = &(psched->current); 286 287 asm volatile ( "li $26, 0xB \n" 288 "mtc2 $26, $1 \n" /* desactivate DTLB */ 289 "sw %1, 0(%0) \n" /* *pcur <= value */ 290 "li $26, 0xF \n" 291 "mtc2 $26, $1 \n" /* activate DTLB */ 292 : 293 : "r"(pcur), "r"(value) 294 : "$26" ); 295 } 292 unsigned int * pcur = &(psched->current); 293 294 asm volatile ("li $26, 0xB \n" 295 "mtc2 $26, $1 \n" /* desactivate DTLB */ 296 "sw %1, 0(%0) \n" /* *pcur <= value */ 297 "li $26, 0xF \n" 298 "mtc2 $26, $1 \n" /* activate DTLB */ 299 : 300 :"r" (pcur), "r"(value) 301 :"$26"); 302 } 303 304 296 305 ////////////////////////////////////////////////////////////////////////////// 297 306 // boot_set_mmu_ptpr() 298 307 // This function set a new value for the MMU PTPR register. 299 308 ////////////////////////////////////////////////////////////////////////////// 300 inline void boot_set_mmu_ptpr( unsigned int val )301 { 302 asm volatile("mtc2 %0, $0" : : "r"(val) ); 303 } 309 inline void boot_set_mmu_ptpr(unsigned int val) { 310 asm volatile ("mtc2 %0, $0"::"r" (val)); 311 } 312 304 313 305 314 ////////////////////////////////////////////////////////////////////////////// … … 307 316 // This function set a new value for the MMU MODE register. 308 317 ////////////////////////////////////////////////////////////////////////////// 309 inline void boot_set_mmu_mode( unsigned int val ) 310 { 311 asm volatile("mtc2 %0, $1" : : "r"(val) ); 312 } 318 inline void boot_set_mmu_mode(unsigned int val) { 319 asm volatile ("mtc2 %0, $1"::"r" (val)); 320 } 321 322 313 323 //////////////////////////////////////////////////////////////////////////// 314 324 // boot_puts() 315 325 // (it uses TTY0) 316 326 //////////////////////////////////////////////////////////////////////////// 317 void boot_puts(const char *buffer) 318 { 319 unsigned int* tty_address = (unsigned int*) &seg_tty_base; 327 void boot_puts(const char * buffer) { 328 unsigned int *tty_address = (unsigned int *) &seg_tty_base; 320 329 unsigned int n; 321 330 322 for ( n=0; n<100; n++) 323 { 324 if (buffer[n] == 0) break; 325 tty_address[TTY_WRITE] = (unsigned int)buffer[n]; 326 } 327 } 331 for (n = 0; n < 100; n++) { 332 if (buffer[n] == 0) { 333 break; 334 } 335 tty_address[TTY_WRITE] = (unsigned int) buffer[n]; 336 } 337 } 338 339 328 340 //////////////////////////////////////////////////////////////////////////// 329 341 // boot_putx() 330 342 // (it uses TTY0) 331 343 //////////////////////////////////////////////////////////////////////////// 332 void boot_putx(unsigned int val) 333 { 334 static const char HexaTab[] = "0123456789ABCDEF"; 335 char buf[11]; 336 unsigned int c; 337 338 buf[0] = '0'; 339 buf[1] = 'x'; 344 void boot_putx(unsigned int val) { 345 static const char HexaTab[] = "0123456789ABCDEF"; 346 char buf[11]; 347 unsigned int c; 348 349 buf[0] = '0'; 350 buf[1] = 'x'; 340 351 buf[10] = 0; 341 352 342 for ( c = 0 ; c < 8 ; c++ ) 343 { 344 buf[9-c] = HexaTab[val&0xF]; 353 for (c = 0; c < 8; c++) { 354 buf[9 - c] = HexaTab[val & 0xF]; 345 355 val = val >> 4; 346 356 } 347 357 boot_puts(buf); 348 358 } 359 360 349 361 //////////////////////////////////////////////////////////////////////////// 350 362 // boot_putd() 351 363 // (it uses TTY0) 352 364 //////////////////////////////////////////////////////////////////////////// 353 void boot_putd(unsigned int val) 354 { 355 static const char DecTab[] = "0123456789"; 356 char buf[11]; 357 unsigned int i; 358 unsigned int first; 365 void boot_putd(unsigned int val) { 366 static const char DecTab[] = "0123456789"; 367 char buf[11]; 368 unsigned int i; 369 unsigned int first; 359 370 360 371 buf[10] = 0; 361 372 362 for ( i = 0 ; i < 10 ; i++ ) 363 { 364 if ((val != 0) || (i == 0)) 365 { 366 buf[9-i] = DecTab[val % 10]; 367 first = 9-i; 368 } 369 else 370 { 373 for (i = 0; i < 10; i++) { 374 if ((val != 0) || (i == 0)) { 375 buf[9 - i] = DecTab[val % 10]; 376 first = 9 - i; 377 } 378 else { 371 379 break; 372 380 } 373 381 val /= 10; 374 382 } 375 boot_puts( &buf[first] ); 376 } 383 boot_puts(&buf[first]); 384 } 385 377 386 378 387 ///////////////////////////////////////////////////////////////////////////// 379 388 // mapping_info data structure access functions 380 389 ///////////////////////////////////////////////////////////////////////////// 381 inline mapping_cluster_t * boot_get_cluster_base( mapping_header_t* header )382 { 383 return (mapping_cluster_t*) ((char*)header + 384 MAPPING_HEADER_SIZE); 385 } 390 inline mapping_cluster_t *boot_get_cluster_base(mapping_header_t * header) { 391 return (mapping_cluster_t *) ((char *) header + MAPPING_HEADER_SIZE); 392 } 393 394 386 395 ///////////////////////////////////////////////////////////////////////////// 387 inline mapping_pseg_t* boot_get_pseg_base( mapping_header_t* header ) 388 { 389 return (mapping_pseg_t*) ((char*)header + 390 MAPPING_HEADER_SIZE + 391 MAPPING_CLUSTER_SIZE*header->clusters); 392 } 396 inline mapping_pseg_t *boot_get_pseg_base(mapping_header_t * header) { 397 return (mapping_pseg_t *) ((char *) header + 398 MAPPING_HEADER_SIZE + 399 MAPPING_CLUSTER_SIZE * header->clusters); 400 } 401 402 393 403 ///////////////////////////////////////////////////////////////////////////// 394 inline mapping_vspace_t* boot_get_vspace_base( mapping_header_t* header ) 395 { 396 return (mapping_vspace_t*) ((char*)header + 397 MAPPING_HEADER_SIZE + 398 MAPPING_CLUSTER_SIZE*header->clusters + 399 MAPPING_PSEG_SIZE*header->psegs); 400 } 404 inline mapping_vspace_t *boot_get_vspace_base(mapping_header_t * header) { 405 return (mapping_vspace_t *) ((char *) header + 406 MAPPING_HEADER_SIZE + 407 MAPPING_CLUSTER_SIZE * header->clusters + 408 MAPPING_PSEG_SIZE * header->psegs); 409 } 410 411 401 412 ///////////////////////////////////////////////////////////////////////////// 402 inline mapping_vseg_t* boot_get_vseg_base( mapping_header_t* header ) 403 { 404 return (mapping_vseg_t*) ((char*)header + 405 MAPPING_HEADER_SIZE + 406 MAPPING_CLUSTER_SIZE*header->clusters + 407 MAPPING_PSEG_SIZE*header->psegs + 408 MAPPING_VSPACE_SIZE*header->vspaces); 409 } 413 inline mapping_vseg_t *boot_get_vseg_base(mapping_header_t * header) { 414 return (mapping_vseg_t *) ((char *) header + 415 MAPPING_HEADER_SIZE + 416 MAPPING_CLUSTER_SIZE * header->clusters + 417 MAPPING_PSEG_SIZE * header->psegs + 418 MAPPING_VSPACE_SIZE * header->vspaces); 419 } 420 421 410 422 ///////////////////////////////////////////////////////////////////////////// 411 inline mapping_vobj_t* boot_get_vobj_base( mapping_header_t* header ) 412 { 413 return (mapping_vobj_t*) ((char*)header + 414 MAPPING_HEADER_SIZE + 415 MAPPING_CLUSTER_SIZE*header->clusters + 416 MAPPING_PSEG_SIZE*header->psegs + 417 MAPPING_VSPACE_SIZE*header->vspaces + 418 MAPPING_VSEG_SIZE*header->vsegs ); 419 } 423 inline mapping_vobj_t *boot_get_vobj_base(mapping_header_t * header) { 424 return (mapping_vobj_t *) ((char *) header + 425 MAPPING_HEADER_SIZE + 426 MAPPING_CLUSTER_SIZE * header->clusters + 427 MAPPING_PSEG_SIZE * header->psegs + 428 MAPPING_VSPACE_SIZE * header->vspaces + 429 MAPPING_VSEG_SIZE * header->vsegs); 430 } 431 432 420 433 ///////////////////////////////////////////////////////////////////////////// 421 inline mapping_task_t* boot_get_task_base( mapping_header_t* header ) 422 { 423 return (mapping_task_t*) ((char*)header + 424 MAPPING_HEADER_SIZE + 425 MAPPING_CLUSTER_SIZE*header->clusters + 426 MAPPING_PSEG_SIZE*header->psegs + 427 MAPPING_VSPACE_SIZE*header->vspaces + 428 MAPPING_VSEG_SIZE*header->vsegs + 429 MAPPING_VOBJ_SIZE*header->vobjs ); 430 } 434 inline mapping_task_t *boot_get_task_base(mapping_header_t * header) { 435 return (mapping_task_t *) ((char *) header + 436 MAPPING_HEADER_SIZE + 437 MAPPING_CLUSTER_SIZE * header->clusters + 438 MAPPING_PSEG_SIZE * header->psegs + 439 MAPPING_VSPACE_SIZE * header->vspaces + 440 MAPPING_VSEG_SIZE * header->vsegs + 441 MAPPING_VOBJ_SIZE * header->vobjs); 442 } 443 444 431 445 ///////////////////////////////////////////////////////////////////////////// 432 inline mapping_proc_t* boot_get_proc_base( mapping_header_t* header ) 433 { 434 return (mapping_proc_t*) ((char*)header + 435 MAPPING_HEADER_SIZE + 436 MAPPING_CLUSTER_SIZE*header->clusters + 437 MAPPING_PSEG_SIZE*header->psegs + 438 MAPPING_VSPACE_SIZE*header->vspaces + 439 MAPPING_VSEG_SIZE*header->vsegs + 440 MAPPING_VOBJ_SIZE*header->vobjs + 441 MAPPING_TASK_SIZE*header->tasks ); 442 } 446 inline mapping_proc_t *boot_get_proc_base(mapping_header_t * header) { 447 return (mapping_proc_t *) ((char *) header + 448 MAPPING_HEADER_SIZE + 449 MAPPING_CLUSTER_SIZE * header->clusters + 450 MAPPING_PSEG_SIZE * header->psegs + 451 MAPPING_VSPACE_SIZE * header->vspaces + 452 MAPPING_VSEG_SIZE * header->vsegs + 453 MAPPING_VOBJ_SIZE * header->vobjs + 454 MAPPING_TASK_SIZE * header->tasks); 455 } 456 457 443 458 ///////////////////////////////////////////////////////////////////////////// 444 inline mapping_irq_t* boot_get_irq_base( mapping_header_t* header ) 445 { 446 return (mapping_irq_t*) ((char*)header + 447 MAPPING_HEADER_SIZE + 448 MAPPING_CLUSTER_SIZE*header->clusters + 449 MAPPING_PSEG_SIZE*header->psegs + 450 MAPPING_VSPACE_SIZE*header->vspaces + 451 MAPPING_VSEG_SIZE*header->vsegs + 452 MAPPING_VOBJ_SIZE*header->vobjs + 453 MAPPING_TASK_SIZE*header->tasks + 454 MAPPING_PROC_SIZE*header->procs ); 455 } 459 inline mapping_irq_t *boot_get_irq_base(mapping_header_t * header) { 460 return (mapping_irq_t *) ((char *) header + 461 MAPPING_HEADER_SIZE + 462 MAPPING_CLUSTER_SIZE * header->clusters + 463 MAPPING_PSEG_SIZE * header->psegs + 464 MAPPING_VSPACE_SIZE * header->vspaces + 465 MAPPING_VSEG_SIZE * header->vsegs + 466 MAPPING_VOBJ_SIZE * header->vobjs + 467 MAPPING_TASK_SIZE * header->tasks + 468 MAPPING_PROC_SIZE * header->procs); 469 } 470 471 456 472 ///////////////////////////////////////////////////////////////////////////// 457 inline mapping_coproc_t* boot_get_coproc_base( mapping_header_t* header ) 458 { 459 return (mapping_coproc_t*) ((char*)header + 460 MAPPING_HEADER_SIZE + 461 MAPPING_CLUSTER_SIZE*header->clusters + 462 MAPPING_PSEG_SIZE*header->psegs + 463 MAPPING_VSPACE_SIZE*header->vspaces + 464 MAPPING_VOBJ_SIZE*header->vobjs + 465 MAPPING_VSEG_SIZE*header->vsegs + 466 MAPPING_TASK_SIZE*header->tasks + 467 MAPPING_PROC_SIZE*header->procs + 468 MAPPING_IRQ_SIZE*header->irqs ); 469 } 473 inline mapping_coproc_t *boot_get_coproc_base(mapping_header_t * header) { 474 return (mapping_coproc_t *) ((char *) header + 475 MAPPING_HEADER_SIZE + 476 MAPPING_CLUSTER_SIZE * header->clusters + 477 MAPPING_PSEG_SIZE * header->psegs + 478 MAPPING_VSPACE_SIZE * header->vspaces + 479 MAPPING_VOBJ_SIZE * header->vobjs + 480 MAPPING_VSEG_SIZE * header->vsegs + 481 MAPPING_TASK_SIZE * header->tasks + 482 MAPPING_PROC_SIZE * header->procs + 483 MAPPING_IRQ_SIZE * header->irqs); 484 } 485 486 470 487 /////////////////////////////////////////////////////////////////////////////////// 471 inline mapping_cp_port_t* boot_get_cp_port_base( mapping_header_t* header ) 472 { 473 return (mapping_cp_port_t*) ((char*)header + 474 MAPPING_HEADER_SIZE + 475 MAPPING_CLUSTER_SIZE*header->clusters + 476 MAPPING_PSEG_SIZE*header->psegs + 477 MAPPING_VSPACE_SIZE*header->vspaces + 478 MAPPING_VOBJ_SIZE*header->vobjs + 479 MAPPING_VSEG_SIZE*header->vsegs + 480 MAPPING_TASK_SIZE*header->tasks + 481 MAPPING_PROC_SIZE*header->procs + 482 MAPPING_IRQ_SIZE*header->irqs + 483 MAPPING_COPROC_SIZE*header->coprocs ); 484 } 488 inline mapping_cp_port_t *boot_get_cp_port_base(mapping_header_t * header) { 489 return (mapping_cp_port_t *) ((char *) header + 490 MAPPING_HEADER_SIZE + 491 MAPPING_CLUSTER_SIZE * header->clusters + 492 MAPPING_PSEG_SIZE * header->psegs + 493 MAPPING_VSPACE_SIZE * header->vspaces + 494 MAPPING_VOBJ_SIZE * header->vobjs + 495 MAPPING_VSEG_SIZE * header->vsegs + 496 MAPPING_TASK_SIZE * header->tasks + 497 MAPPING_PROC_SIZE * header->procs + 498 MAPPING_IRQ_SIZE * header->irqs + 499 MAPPING_COPROC_SIZE * header->coprocs); 500 } 501 502 485 503 /////////////////////////////////////////////////////////////////////////////////// 486 inline mapping_periph_t * boot_get_periph_base( mapping_header_t* header )487 { 488 return (mapping_periph_t*) ((char*)header+489 MAPPING_HEADER_SIZE+490 MAPPING_CLUSTER_SIZE*header->clusters +491 MAPPING_PSEG_SIZE*header->psegs +492 MAPPING_VSPACE_SIZE*header->vspaces +493 MAPPING_VOBJ_SIZE*header->vobjs +494 MAPPING_VSEG_SIZE*header->vsegs +495 MAPPING_TASK_SIZE*header->tasks +496 MAPPING_PROC_SIZE*header->procs +497 MAPPING_IRQ_SIZE*header->irqs +498 MAPPING_COPROC_SIZE*header->coprocs +499 MAPPING_CP_PORT_SIZE*header->cp_ports ); 500 } 504 inline mapping_periph_t *boot_get_periph_base(mapping_header_t * header) { 505 return (mapping_periph_t *) ((char *) header + 506 MAPPING_HEADER_SIZE + 507 MAPPING_CLUSTER_SIZE * header->clusters + 508 MAPPING_PSEG_SIZE * header->psegs + 509 MAPPING_VSPACE_SIZE * header->vspaces + 510 MAPPING_VOBJ_SIZE * header->vobjs + 511 MAPPING_VSEG_SIZE * header->vsegs + 512 MAPPING_TASK_SIZE * header->tasks + 513 MAPPING_PROC_SIZE * header->procs + 514 MAPPING_IRQ_SIZE * header->irqs + 515 MAPPING_COPROC_SIZE * header->coprocs + 516 MAPPING_CP_PORT_SIZE * header->cp_ports); 517 } 518 501 519 502 520 ////////////////////////////////////////////////////////////////////////////// … … 505 523 // identified by the pseg index. 506 524 ////////////////////////////////////////////////////////////////////////////// 507 mapping_pseg_t* boot_pseg_get( unsigned int seg_id) 508 { 509 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 510 mapping_pseg_t* pseg = boot_get_pseg_base( header ); 525 mapping_pseg_t *boot_pseg_get(unsigned int seg_id) { 526 mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; 527 mapping_pseg_t * pseg = boot_get_pseg_base(header); 511 528 512 529 // checking argument 513 if ( seg_id >= header->psegs ) 514 { 530 if (seg_id >= header->psegs) { 515 531 boot_puts("\n[BOOT ERROR] : seg_id argument too large\n"); 516 532 boot_puts(" in function boot_pseg_get()\n"); … … 518 534 } 519 535 520 return &pseg[seg_id]; 521 } // end boot_pseg_get() 536 return &pseg[seg_id]; 537 } // end boot_pseg_get() 538 522 539 523 540 ////////////////////////////////////////////////////////////////////////////// … … 532 549 // being mapped. 533 550 ////////////////////////////////////////////////////////////////////////////// 534 void boot_add_pte( unsigned int vspace_id, 535 unsigned int vpn, 536 unsigned int flags, 537 unsigned int ppn ) 538 { 539 unsigned int ix1; 540 unsigned int ix2; 541 unsigned int ptba; // PT2 base address 542 unsigned int pt2_id; // PT2 index 543 unsigned int* pt_flags; // pointer on the pte_flags = &PT2[2*ix2] 544 unsigned int* pt_ppn; // pointer on the pte_ppn = &PT2[2*ix2+1] 545 546 ix1 = vpn >> 9; // 11 bits 547 ix2 = vpn & 0x1FF; // 9 bits 551 void boot_add_pte(unsigned int vspace_id, 552 unsigned int vpn, unsigned int flags, unsigned int ppn) { 553 unsigned int ix1; 554 unsigned int ix2; 555 unsigned int ptba; // PT2 base address 556 unsigned int pt2_id; // PT2 index 557 unsigned int *pt_flags; // pointer on the pte_flags = &PT2[2*ix2] 558 unsigned int *pt_ppn; // pointer on the pte_ppn = &PT2[2*ix2+1] 559 560 ix1 = vpn >> 9; // 11 bits 561 ix2 = vpn & 0x1FF; // 9 bits 548 562 549 563 // check that the boot_max_pt2[vspace_id] has been set 550 unsigned int max_pt2 = boot_max_pt2[vspace_id]; 551 552 if(max_pt2 == 0) 553 { 564 unsigned int max_pt2 = boot_max_pt2[vspace_id]; 565 566 if (max_pt2 == 0) { 554 567 boot_puts("Unfound page table for vspace "); 555 568 boot_putd(vspace_id); … … 557 570 boot_exit(); 558 571 } 559 560 572 // get page table physical address 561 page_table_t* pt = boot_ptabs_paddr[vspace_id]; 562 563 if ( (pt->pt1[ix1] & PTE_V) == 0 ) // set a new PTD in PT1 564 { 573 page_table_t *pt = boot_ptabs_paddr[vspace_id]; 574 575 if ((pt->pt1[ix1] & PTE_V) == 0) { // set a new PTD in PT1 565 576 pt2_id = boot_next_free_pt2[vspace_id]; 566 if ( pt2_id == max_pt2 ) 567 { 577 if (pt2_id == max_pt2) { 568 578 boot_puts("\n[BOOT ERROR] in boot_add_pte() function\n"); 569 boot_puts("the length of the ptab vobj is too small\n"); 579 boot_puts("the length of the ptab vobj is too small\n"); 570 580 boot_exit(); 571 581 } 572 else 573 { 574 ptba = (unsigned int)pt + PT1_SIZE + PT2_SIZE*pt2_id; 575 pt->pt1[ix1] = PTE_V | PTE_T | (ptba >> 12); 582 else { 583 ptba = (unsigned int) pt + PT1_SIZE + PT2_SIZE * pt2_id; 584 pt->pt1[ix1] = PTE_V | PTE_T | (ptba >> 12); 576 585 boot_next_free_pt2[vspace_id] = pt2_id + 1; 577 586 } 578 587 } 579 else 580 { 588 else { 581 589 ptba = pt->pt1[ix1] << 12; 582 590 } 583 591 584 592 // set PTE2 after checking double mapping error 585 pt_flags = (unsigned int*)(ptba + 8*ix2); 586 pt_ppn = (unsigned int*)(ptba + 8*ix2 + 4); 587 588 if ( ( *pt_flags & PTE_V) != 0 ) // page already mapped 589 { 593 pt_flags = (unsigned int *) (ptba + 8 * ix2); 594 pt_ppn = (unsigned int *) (ptba + 8 * ix2 + 4); 595 596 if ((*pt_flags & PTE_V) != 0) { // page already mapped 590 597 boot_puts("\n[BOOT ERROR] double mapping in vspace "); 591 boot_putd( vspace_id);598 boot_putd(vspace_id); 592 599 boot_puts(" for vpn = "); 593 boot_putx( vpn);600 boot_putx(vpn); 594 601 boot_puts("\n"); 595 602 boot_exit(); 596 603 } 597 598 604 // set PTE2 599 605 *pt_flags = flags; 600 *pt_ppn = ppn; 601 602 } // end boot_add_pte() 603 606 *pt_ppn = ppn; 607 608 } // end boot_add_pte() 609 610 604 611 ///////////////////////////////////////////////////////////////////// 605 612 // This function build the page table for a given vspace. … … 608 615 // It initializes the MWMR channels. 609 616 ///////////////////////////////////////////////////////////////////// 610 void boot_vspace_pt_build( unsigned int vspace_id ) 611 { 612 unsigned int vseg_id; 613 unsigned int npages; 614 unsigned int ppn; 615 unsigned int vpn; 616 unsigned int flags; 617 unsigned int page_id; 618 619 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 620 mapping_vspace_t* vspace = boot_get_vspace_base( header ); 621 mapping_vseg_t* vseg = boot_get_vseg_base( header ); 622 617 void boot_vspace_pt_build(unsigned int vspace_id) { 618 unsigned int vseg_id; 619 unsigned int npages; 620 unsigned int ppn; 621 unsigned int vpn; 622 unsigned int flags; 623 unsigned int page_id; 624 625 mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; 626 mapping_vspace_t * vspace = boot_get_vspace_base(header); 627 mapping_vseg_t * vseg = boot_get_vseg_base(header); 628 623 629 // private segments 624 for ( vseg_id = vspace[vspace_id].vseg_offset ; 625 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs) ; 626 vseg_id++ ) 627 { 628 vpn = vseg[vseg_id].vbase >> 12; 629 ppn = vseg[vseg_id].pbase >> 12; 630 npages = vseg[vseg_id].length >> 12; 631 if ( (vseg[vseg_id].length & 0xFFF) != 0 ) npages++; 630 for (vseg_id = vspace[vspace_id].vseg_offset; 631 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); 632 vseg_id++) { 633 vpn = vseg[vseg_id].vbase >> 12; 634 ppn = vseg[vseg_id].pbase >> 12; 635 npages = vseg[vseg_id].length >> 12; 636 if ((vseg[vseg_id].length & 0xFFF) != 0) { 637 npages++; 638 } 632 639 633 640 flags = PTE_V; 634 if ( vseg[vseg_id].mode & C_MODE_MASK ) flags = flags | PTE_C; 635 if ( vseg[vseg_id].mode & X_MODE_MASK ) flags = flags | PTE_X; 636 if ( vseg[vseg_id].mode & W_MODE_MASK ) flags = flags | PTE_W; 637 if ( vseg[vseg_id].mode & U_MODE_MASK ) flags = flags | PTE_U; 641 if (vseg[vseg_id].mode & C_MODE_MASK) { 642 flags = flags | PTE_C; 643 } 644 if (vseg[vseg_id].mode & X_MODE_MASK) { 645 flags = flags | PTE_X; 646 } 647 if (vseg[vseg_id].mode & W_MODE_MASK) { 648 flags = flags | PTE_W; 649 } 650 if (vseg[vseg_id].mode & U_MODE_MASK) { 651 flags = flags | PTE_U; 652 } 638 653 639 654 #if BOOT_DEBUG_PT 640 boot_puts( vseg[vseg_id].name);641 boot_puts(" : flags = ");642 boot_putx( flags);643 boot_puts(" / npages = ");644 boot_putd( npages);645 boot_puts(" / pbase = ");646 boot_putx( vseg[vseg_id].pbase);647 boot_puts("\n");648 #endif 655 boot_puts(vseg[vseg_id].name); 656 boot_puts(" : flags = "); 657 boot_putx(flags); 658 boot_puts(" / npages = "); 659 boot_putd(npages); 660 boot_puts(" / pbase = "); 661 boot_putx(vseg[vseg_id].pbase); 662 boot_puts("\n"); 663 #endif 649 664 // loop on 4K pages 650 for ( page_id = 0 ; page_id < npages ; page_id++ ) 651 { 652 boot_add_pte( vspace_id, 653 vpn, 654 flags, 655 ppn ); 665 for (page_id = 0; page_id < npages; page_id++) { 666 boot_add_pte(vspace_id, vpn, flags, ppn); 656 667 vpn++; 657 668 ppn++; … … 660 671 661 672 // global segments 662 for ( vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ ) 663 { 664 vpn = vseg[vseg_id].vbase >> 12; 665 ppn = vseg[vseg_id].pbase >> 12; 666 npages = vseg[vseg_id].length >> 12; 667 if ( (vseg[vseg_id].length & 0xFFF) != 0 ) npages++; 673 for (vseg_id = 0; vseg_id < header->globals; vseg_id++) { 674 vpn = vseg[vseg_id].vbase >> 12; 675 ppn = vseg[vseg_id].pbase >> 12; 676 npages = vseg[vseg_id].length >> 12; 677 if ((vseg[vseg_id].length & 0xFFF) != 0) { 678 npages++; 679 } 668 680 669 681 flags = PTE_V; 670 if ( vseg[vseg_id].mode & C_MODE_MASK ) flags = flags | PTE_C; 671 if ( vseg[vseg_id].mode & X_MODE_MASK ) flags = flags | PTE_X; 672 if ( vseg[vseg_id].mode & W_MODE_MASK ) flags = flags | PTE_W; 673 if ( vseg[vseg_id].mode & U_MODE_MASK ) flags = flags | PTE_U; 682 if (vseg[vseg_id].mode & C_MODE_MASK) { 683 flags = flags | PTE_C; 684 } 685 if (vseg[vseg_id].mode & X_MODE_MASK) { 686 flags = flags | PTE_X; 687 } 688 if (vseg[vseg_id].mode & W_MODE_MASK) { 689 flags = flags | PTE_W; 690 } 691 if (vseg[vseg_id].mode & U_MODE_MASK) { 692 flags = flags | PTE_U; 693 } 674 694 675 695 #if BOOT_DEBUG_PT 676 boot_puts( vseg[vseg_id].name);677 boot_puts(" / flags = ");678 boot_putx( flags);679 boot_puts(" / npages = ");680 boot_putd( npages);681 boot_puts(" / pbase = ");682 boot_putx( vseg[vseg_id].pbase);683 boot_puts("\n");684 #endif 696 boot_puts(vseg[vseg_id].name); 697 boot_puts(" / flags = "); 698 boot_putx(flags); 699 boot_puts(" / npages = "); 700 boot_putd(npages); 701 boot_puts(" / pbase = "); 702 boot_putx(vseg[vseg_id].pbase); 703 boot_puts("\n"); 704 #endif 685 705 // loop on 4K pages 686 for ( page_id = 0 ; page_id < npages ; page_id++ ) 687 { 688 boot_add_pte( vspace_id, 689 vpn, 690 flags, 691 ppn ); 706 for (page_id = 0; page_id < npages; page_id++) { 707 boot_add_pte(vspace_id, vpn, flags, ppn); 692 708 vpn++; 693 709 ppn++; 694 710 } 695 711 } 696 697 } // end boot_vspace_pt_build() 712 } // end boot_vspace_pt_build() 713 698 714 699 715 /////////////////////////////////////////////////////////////////////////// … … 701 717 // alignPow2 ( the logarithme of 2 the alignement). 702 718 /////////////////////////////////////////////////////////////////////////// 703 unsigned int align_to( unsigned int toAlign, 704 unsigned int alignPow2) 705 { 706 unsigned int mask = (1 << alignPow2) - 1; 707 return ((toAlign + mask ) & ~mask ); 708 } 719 unsigned int align_to(unsigned int toAlign, unsigned int alignPow2) { 720 unsigned int mask = (1 << alignPow2) - 1; 721 return ((toAlign + mask) & ~mask); 722 } 723 709 724 710 725 /////////////////////////////////////////////////////////////////////////// … … 717 732 // It is a global vseg if vspace_id = (-1). 718 733 /////////////////////////////////////////////////////////////////////////// 719 void boot_vseg_map( mapping_vseg_t* vseg, 720 unsigned int vspace_id ) 721 { 722 unsigned int vobj_id; 723 unsigned int cur_vaddr; 724 unsigned int cur_paddr; 725 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 726 mapping_vobj_t* vobj = boot_get_vobj_base( header ); 727 734 void boot_vseg_map(mapping_vseg_t * vseg, unsigned int vspace_id) { 735 unsigned int vobj_id; 736 unsigned int cur_vaddr; 737 unsigned int cur_paddr; 738 mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; 739 mapping_vobj_t * vobj = boot_get_vobj_base(header); 740 728 741 // get physical segment pointer 729 mapping_pseg_t * pseg = boot_pseg_get( vseg->psegid);742 mapping_pseg_t *pseg = boot_pseg_get(vseg->psegid); 730 743 731 744 // compute vseg physical base address 732 if ( vseg->ident != 0 ) // identity mapping required 733 { 734 vseg->pbase = vseg->vbase; 735 } 736 else // unconstrained mapping 737 { 745 if (vseg->ident != 0) { // identity mapping required 746 vseg->pbase = vseg->vbase; 747 } 748 else { // unconstrained mapping 738 749 vseg->pbase = pseg->next_base; 739 750 740 751 // test alignment constraint 741 if ( vobj[vseg->vobj_offset].align ) 742 { 743 vseg->pbase = align_to( vseg->pbase, vobj[vseg->vobj_offset].align ); 744 } 745 } 746 752 if (vobj[vseg->vobj_offset].align) { 753 vseg->pbase = align_to(vseg->pbase, vobj[vseg->vobj_offset].align); 754 } 755 } 756 747 757 // loop on vobjs contained in vseg to : 748 758 // (1) computes the length of the vseg, … … 753 763 cur_paddr = vseg->pbase; 754 764 755 for( vobj_id = vseg->vobj_offset; 756 vobj_id < (vseg->vobj_offset + vseg->vobjs); 757 vobj_id++) 758 { 759 if ( vobj[vobj_id].align ) 760 { 765 for (vobj_id = vseg->vobj_offset; vobj_id < (vseg->vobj_offset + vseg->vobjs); vobj_id++) { 766 if (vobj[vobj_id].align) { 761 767 cur_paddr = align_to(cur_paddr, vobj[vobj_id].align); 762 768 } 763 764 769 // set vaddr/paddr for current vobj 765 vobj[vobj_id].vaddr = cur_vaddr; 766 vobj[vobj_id].paddr = cur_paddr; 767 770 vobj[vobj_id].vaddr = cur_vaddr; 771 vobj[vobj_id].paddr = cur_paddr; 772 768 773 // initialise boot_ptabs_vaddr[] if current vobj is a PTAB 769 if ( vobj[vobj_id].type == VOBJ_TYPE_PTAB ) 770 { 771 if(vspace_id == ((unsigned int) -1)) // global vseg 772 { 773 boot_puts( "\n[BOOT ERROR] in boot_vseg_map() function: " ); 774 boot_puts( "a PTAB vobj cannot be global" ); 774 if (vobj[vobj_id].type == VOBJ_TYPE_PTAB) { 775 if (vspace_id == ((unsigned int) -1)) { // global vseg 776 boot_puts("\n[BOOT ERROR] in boot_vseg_map() function: "); 777 boot_puts("a PTAB vobj cannot be global"); 775 778 boot_exit(); 776 779 } 777 778 780 // we need at least one PT2 => ( boot_max_pt2[vspace_id] >= 1) 779 if(vobj[vobj_id].length < (PT1_SIZE + PT2_SIZE) ) 780 { 781 boot_puts( "\n[BOOT ERROR] in boot_vseg_map() function, " ); 781 if (vobj[vobj_id].length < (PT1_SIZE + PT2_SIZE)) { 782 boot_puts("\n[BOOT ERROR] in boot_vseg_map() function, "); 782 783 boot_puts("PTAB too small, minumum size is: "); 783 boot_putx( 784 boot_putx(PT1_SIZE + PT2_SIZE); 784 785 boot_exit(); 785 786 } 786 787 787 // register both physical and virtual page table address 788 boot_ptabs_vaddr[vspace_id] = (page_table_t *)vobj[vobj_id].vaddr;789 boot_ptabs_paddr[vspace_id] = (page_table_t *)vobj[vobj_id].paddr;788 boot_ptabs_vaddr[vspace_id] = (page_table_t *) vobj[vobj_id].vaddr; 789 boot_ptabs_paddr[vspace_id] = (page_table_t *) vobj[vobj_id].paddr; 790 790 791 791 /* computing the number of second level page */ 792 792 boot_max_pt2[vspace_id] = (vobj[vobj_id].length - PT1_SIZE) / PT2_SIZE; 793 793 } 794 795 794 // set next vaddr/paddr 796 795 cur_vaddr += vobj[vobj_id].length; 797 cur_paddr += vobj[vobj_id].length; 796 cur_paddr += vobj[vobj_id].length; 798 797 799 798 } // end for vobjs 800 799 801 800 //set the vseg length 802 vseg->length = align_to( 801 vseg->length = align_to((cur_paddr - vseg->pbase), 12); 803 802 804 803 // checking pseg overflow 805 if ( (vseg->pbase < pseg->base) || 806 ((vseg->pbase + vseg->length) > (pseg->base + pseg->length)) ) 807 { 804 if ((vseg->pbase < pseg->base) || 805 ((vseg->pbase + vseg->length) > (pseg->base + pseg->length))) { 808 806 boot_puts("\n[BOOT ERROR] in boot_vseg_map() function\n"); 809 807 boot_puts("impossible mapping for virtual segment: "); 810 boot_puts( vseg->name );811 boot_puts("\n"); 808 boot_puts(vseg->name); 809 boot_puts("\n"); 812 810 boot_puts("vseg pbase = "); 813 boot_putx( vseg->pbase );814 boot_puts("\n"); 811 boot_putx(vseg->pbase); 812 boot_puts("\n"); 815 813 boot_puts("vseg length = "); 816 boot_putx( vseg->length );817 boot_puts("\n"); 814 boot_putx(vseg->length); 815 boot_puts("\n"); 818 816 boot_puts("pseg pbase = "); 819 boot_putx( pseg->base );820 boot_puts("\n"); 817 boot_putx(pseg->base); 818 boot_puts("\n"); 821 819 boot_puts("pseg length = "); 822 boot_putx( pseg->length );823 boot_puts("\n"); 820 boot_putx(pseg->length); 821 boot_puts("\n"); 824 822 boot_exit(); 825 823 } 826 824 827 828 825 #if BOOT_DEBUG_PT 829 boot_puts( vseg->name);830 boot_puts(" : len = ");831 boot_putx( vseg->length);832 boot_puts(" / vbase = ");833 boot_putx( vseg->vbase);834 boot_puts(" / pbase = ");835 boot_putx( vseg->pbase);836 boot_puts("\n");837 #endif 826 boot_puts(vseg->name); 827 boot_puts(" : len = "); 828 boot_putx(vseg->length); 829 boot_puts(" / vbase = "); 830 boot_putx(vseg->vbase); 831 boot_puts(" / pbase = "); 832 boot_putx(vseg->pbase); 833 boot_puts("\n"); 834 #endif 838 835 839 836 // set the next_base field in vseg 840 if ( vseg->ident == 0 && pseg->type != PSEG_TYPE_PERI )837 if (vseg->ident == 0 && pseg->type != PSEG_TYPE_PERI) { 841 838 pseg->next_base = vseg->pbase + vseg->length; 842 843 } // end boot_vseg_map() 839 } 840 841 } // end boot_vseg_map() 844 842 845 843 ///////////////////////////////////////////////////////////////////// … … 847 845 // structure (soft), and the giet_config file (hard). 848 846 ///////////////////////////////////////////////////////////////////// 849 void boot_check_mapping() 850 { 851 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 852 mapping_cluster_t* cluster = boot_get_cluster_base( header ); 853 mapping_periph_t* periph = boot_get_periph_base( header ); 847 void boot_check_mapping() { 848 mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; 849 mapping_cluster_t * cluster = boot_get_cluster_base(header); 850 mapping_periph_t * periph = boot_get_periph_base(header); 854 851 855 852 // checking mapping availability 856 if ( header->signature != IN_MAPPING_SIGNATURE ) 857 { 853 if (header->signature != IN_MAPPING_SIGNATURE) { 858 854 boot_puts("\n[BOOT ERROR] Illegal mapping signature: "); 859 855 boot_putx(header->signature); … … 861 857 boot_exit(); 862 858 } 863 864 859 // checking number of clusters 865 if ( header->clusters != NB_CLUSTERS ) 866 { 860 if (header->clusters != NB_CLUSTERS) { 867 861 boot_puts("\n[BOOT ERROR] Incoherent NB_CLUSTERS"); 868 862 boot_puts("\n - In giet_config, value = "); 869 boot_putd ( NB_CLUSTERS);863 boot_putd(NB_CLUSTERS); 870 864 boot_puts("\n - In mapping_info, value = "); 871 boot_putd ( header->clusters);865 boot_putd(header->clusters); 872 866 boot_puts("\n"); 873 867 boot_exit(); 874 868 } 875 876 869 // checking number of virtual spaces 877 if ( header->vspaces > GIET_NB_VSPACE_MAX ) 878 { 870 if (header->vspaces > GIET_NB_VSPACE_MAX) { 879 871 boot_puts("\n[BOOT ERROR] : number of vspaces > GIET_NB_VSPACE_MAX\n"); 880 872 boot_puts("\n"); 881 873 boot_exit(); 882 874 } 883 884 875 // checking hardware 885 876 unsigned int periph_id; … … 887 878 unsigned int tty_found = 0; 888 879 unsigned int nic_found = 0; 889 for ( cluster_id = 0 ; cluster_id < NB_CLUSTERS ; cluster_id++ ) 890 { 880 for (cluster_id = 0; cluster_id < NB_CLUSTERS; cluster_id++) { 891 881 // NB_PROCS_MAX 892 if ( cluster[cluster_id].procs > NB_PROCS_MAX ) 893 { 894 boot_puts("\n[BOOT ERROR] too much processors in cluster "); 895 boot_putd( cluster_id ); 882 if (cluster[cluster_id].procs > NB_PROCS_MAX) { 883 boot_puts("\n[BOOT ERROR] too many processors in cluster "); 884 boot_putd(cluster_id); 896 885 boot_puts(" : procs = "); 897 boot_putd ( cluster[cluster_id].procs);886 boot_putd(cluster[cluster_id].procs); 898 887 boot_puts("\n"); 899 888 boot_exit(); 900 889 } 901 890 902 for ( periph_id = cluster[cluster_id].periph_offset ; 903 periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs ; 904 periph_id++ ) 905 { 891 for (periph_id = cluster[cluster_id].periph_offset; 892 periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs; 893 periph_id++) { 906 894 // NB_TTYS 907 if ( periph[periph_id].type == PERIPH_TYPE_TTY ) 908 { 909 if ( tty_found ) 910 { 895 if (periph[periph_id].type == PERIPH_TYPE_TTY) { 896 if (tty_found) { 911 897 boot_puts("\n[BOOT ERROR] TTY component should not be replicated\n"); 912 898 boot_exit(); 913 899 } 914 if ( periph[periph_id].channels > NB_TTYS ) 915 { 900 if (periph[periph_id].channels > NB_TTYS) { 916 901 boot_puts("\n[BOOT ERROR] Wrong NB_TTYS in cluster "); 917 boot_putd( cluster_id);902 boot_putd(cluster_id); 918 903 boot_puts(" : ttys = "); 919 boot_putd ( periph[periph_id].channels);904 boot_putd(periph[periph_id].channels); 920 905 boot_puts("\n"); 921 906 boot_exit(); … … 924 909 } 925 910 // NB_NICS 926 if ( periph[periph_id].type == PERIPH_TYPE_NIC ) 927 { 928 if ( nic_found ) 929 { 911 if (periph[periph_id].type == PERIPH_TYPE_NIC) { 912 if (nic_found) { 930 913 boot_puts("\n[BOOT ERROR] NIC component should not be replicated\n"); 931 914 boot_exit(); 932 915 } 933 if ( periph[periph_id].channels != NB_NICS ) 934 { 916 if (periph[periph_id].channels != NB_NICS) { 935 917 boot_puts("\n[BOOT ERROR] Wrong NB_NICS in cluster "); 936 boot_putd( cluster_id);918 boot_putd(cluster_id); 937 919 boot_puts(" : nics = "); 938 boot_putd ( periph[periph_id].channels);920 boot_putd(periph[periph_id].channels); 939 921 boot_puts("\n"); 940 922 boot_exit(); … … 943 925 } 944 926 // NB_TIMERS 945 if ( periph[periph_id].type == PERIPH_TYPE_TIM ) 946 { 947 if ( periph[periph_id].channels > NB_TIMERS_MAX ) 948 { 927 if (periph[periph_id].type == PERIPH_TYPE_TIM) { 928 if (periph[periph_id].channels > NB_TIMERS_MAX) { 949 929 boot_puts("\n[BOOT ERROR] Too much user timers in cluster "); 950 boot_putd( cluster_id);930 boot_putd(cluster_id); 951 931 boot_puts(" : timers = "); 952 boot_putd ( periph[periph_id].channels);932 boot_putd(periph[periph_id].channels); 953 933 boot_puts("\n"); 954 934 boot_exit(); … … 956 936 } 957 937 // NB_DMAS 958 if ( periph[periph_id].type == PERIPH_TYPE_DMA ) 959 { 960 if ( periph[periph_id].channels != NB_DMAS_MAX ) 961 { 938 if (periph[periph_id].type == PERIPH_TYPE_DMA) { 939 if (periph[periph_id].channels != NB_DMAS_MAX) { 962 940 boot_puts("\n[BOOT ERROR] Too much DMA channels in cluster "); 963 boot_putd( cluster_id);941 boot_putd(cluster_id); 964 942 boot_puts(" : channels = "); 965 boot_putd ( periph[periph_id].channels ); 943 boot_putd(periph[periph_id].channels); 944 boot_puts(" - NB_DMAS_MAX : "); 945 boot_putd(NB_DMAS_MAX); 966 946 boot_puts("\n"); 967 947 boot_exit(); … … 971 951 } // end for clusters 972 952 } // end boot_check_mapping() 953 973 954 974 955 ///////////////////////////////////////////////////////////////////// … … 978 959 // schedulers in the first RAM pseg found (4k bytes per processor). 979 960 ///////////////////////////////////////////////////////////////////// 980 void boot_psegs_init() 981 { 982 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 983 984 mapping_cluster_t* cluster = boot_get_cluster_base( header ); 985 mapping_pseg_t* pseg = boot_get_pseg_base( header ); 961 void boot_psegs_init() { 962 mapping_header_t * header = (mapping_header_t *) &seg_mapping_base; 963 964 mapping_cluster_t * cluster = boot_get_cluster_base(header); 965 mapping_pseg_t * pseg = boot_get_pseg_base(header); 986 966 987 967 unsigned int cluster_id; … … 990 970 991 971 #if BOOT_DEBUG_PT 992 boot_puts("\n[BOOT DEBUG] ****** psegs allocators nitialisation ******\n"); 993 #endif 994 995 for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) 996 { 997 if ( cluster[cluster_id].procs > NB_PROCS_MAX ) 998 { 972 boot_puts 973 ("\n[BOOT DEBUG] ****** psegs allocators nitialisation ******\n"); 974 #endif 975 976 for (cluster_id = 0; cluster_id < header->clusters; cluster_id++) { 977 if (cluster[cluster_id].procs > NB_PROCS_MAX) { 999 978 boot_puts("\n[BOOT ERROR] The number of processors in cluster "); 1000 boot_putd( cluster_id);979 boot_putd(cluster_id); 1001 980 boot_puts(" is larger than NB_PROCS_MAX \n"); 1002 981 boot_exit(); 1003 982 } 1004 983 1005 found = 0; 1006 1007 for ( pseg_id = cluster[cluster_id].pseg_offset ; 1008 pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs ; 1009 pseg_id++ ) 1010 { 984 found = 0; 985 986 for (pseg_id = cluster[cluster_id].pseg_offset; 987 pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs; 988 pseg_id++) { 1011 989 unsigned int free = pseg[pseg_id].base; 1012 990 1013 if ( (pseg[pseg_id].type == PSEG_TYPE_RAM) && (found == 0) ) 1014 { 991 if ((pseg[pseg_id].type == PSEG_TYPE_RAM) && (found == 0)) { 1015 992 free = free + (cluster[cluster_id].procs << 12); 1016 993 found = 1; … … 1019 996 1020 997 #if BOOT_DEBUG_PT 1021 boot_puts("cluster ");1022 boot_putd(cluster_id);1023 boot_puts(" / pseg ");1024 boot_puts(pseg[pseg_id].name);1025 boot_puts(" : next_base = ");1026 boot_putx(pseg[pseg_id].next_base);1027 boot_puts("\n");998 boot_puts("cluster "); 999 boot_putd(cluster_id); 1000 boot_puts(" / pseg "); 1001 boot_puts(pseg[pseg_id].name); 1002 boot_puts(" : next_base = "); 1003 boot_putx(pseg[pseg_id].next_base); 1004 boot_puts("\n"); 1028 1005 #endif 1029 1006 } 1030 1007 } 1031 1008 } // end boot_pseg_init() 1009 1032 1010 1033 1011 ///////////////////////////////////////////////////////////////////// … … 1037 1015 // (replicated in all vspaces), and the private vsegs. 1038 1016 ///////////////////////////////////////////////////////////////////// 1039 void boot_pt_init() 1040 { 1041 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 1042 1043 mapping_vspace_t* vspace = boot_get_vspace_base( header ); 1044 mapping_vseg_t* vseg = boot_get_vseg_base( header ); 1045 1046 unsigned int vspace_id; 1047 unsigned int vseg_id; 1017 void boot_pt_init() { 1018 mapping_header_t * header = (mapping_header_t *) &seg_mapping_base; 1019 1020 mapping_vspace_t * vspace = boot_get_vspace_base(header); 1021 mapping_vseg_t * vseg = boot_get_vseg_base(header); 1022 1023 unsigned int vspace_id; 1024 unsigned int vseg_id; 1048 1025 1049 1026 #if BOOT_DEBUG_PT 1050 boot_puts("\n[BOOT DEBUG] ****** mapping global vsegs ******\n");1051 #endif 1052 1027 boot_puts("\n[BOOT DEBUG] ****** mapping global vsegs ******\n"); 1028 #endif 1029 1053 1030 // step 1 : first loop on virtual spaces to map global vsegs 1054 for ( vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ ) 1055 { 1056 boot_vseg_map( &vseg[vseg_id], ((unsigned int)(-1)) ); 1031 for (vseg_id = 0; vseg_id < header->globals; vseg_id++) { 1032 boot_vseg_map(&vseg[vseg_id], ((unsigned int) (-1))); 1057 1033 } 1058 1034 1059 1035 // step 2 : loop on virtual vspaces to map private vsegs 1060 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 1061 { 1036 for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) { 1062 1037 1063 1038 #if BOOT_DEBUG_PT 1064 boot_puts("\n[BOOT DEBUG] ****** mapping private vsegs in vspace "); 1065 boot_puts(vspace[vspace_id].name);1066 boot_puts(" ******\n");1067 #endif 1068 1069 for ( vseg_id = vspace[vspace_id].vseg_offset ; 1070 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs) ;1071 vseg_id++ )1072 {1073 boot_vseg_map( &vseg[vseg_id], vspace_id );1074 } 1075 } 1039 boot_puts 1040 ("\n[BOOT DEBUG] ****** mapping private vsegs in vspace "); 1041 boot_puts(vspace[vspace_id].name); 1042 boot_puts(" ******\n"); 1043 #endif 1044 1045 for (vseg_id = vspace[vspace_id].vseg_offset; 1046 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); 1047 vseg_id++) { 1048 boot_vseg_map(&vseg[vseg_id], vspace_id); 1049 } 1050 } 1076 1051 1077 1052 // step 3 : loop on the vspaces to build the page tables 1078 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 1079 { 1053 for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) { 1080 1054 1081 1055 #if BOOT_DEBUG_PT 1082 boot_puts("\n[BOOT DEBUG] ****** building page table for vspace ");1083 boot_puts(vspace[vspace_id].name);1084 boot_puts(" ******\n");1085 #endif 1086 1087 boot_vspace_pt_build( vspace_id);1056 boot_puts("\n[BOOT DEBUG] ****** building page table for vspace "); 1057 boot_puts(vspace[vspace_id].name); 1058 boot_puts(" ******\n"); 1059 #endif 1060 1061 boot_vspace_pt_build(vspace_id); 1088 1062 1089 1063 #if BOOT_DEBUG_PT 1090 boot_puts("\n>>> page table physical address = ");1091 boot_putx((unsigned int)boot_ptabs_paddr[vspace_id]);1092 boot_puts(", page table number of PT2 = ");1093 boot_putd((unsigned int)boot_max_pt2[vspace_id]);1094 boot_puts("\n");1095 #endif 1096 } 1064 boot_puts("\n>>> page table physical address = "); 1065 boot_putx((unsigned int) boot_ptabs_paddr[vspace_id]); 1066 boot_puts(", page table number of PT2 = "); 1067 boot_putd((unsigned int) boot_max_pt2[vspace_id]); 1068 boot_puts("\n"); 1069 #endif 1070 } 1097 1071 } // end boot_pt_init() 1072 1098 1073 1099 1074 /////////////////////////////////////////////////////////////////////////////// 1100 1075 // This function initializes all private vobjs defined in the vspaces, 1101 1076 // such as mwmr channels, barriers and locks, because these vobjs 1102 // are not known, and not initiali sed by the compiler.1077 // are not known, and not initialized by the compiler. 1103 1078 /////////////////////////////////////////////////////////////////////////////// 1104 void boot_vobjs_init() 1105 { 1106 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 1107 mapping_vspace_t* vspace = boot_get_vspace_base( header ); 1108 mapping_vobj_t* vobj = boot_get_vobj_base( header ); 1109 1110 unsigned int vspace_id; 1111 unsigned int vobj_id; 1079 void boot_vobjs_init() { 1080 mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; 1081 mapping_vspace_t * vspace = boot_get_vspace_base(header); 1082 mapping_vobj_t * vobj = boot_get_vobj_base(header); 1083 1084 unsigned int vspace_id; 1085 unsigned int vobj_id; 1112 1086 1113 1087 // loop on the vspaces 1114 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 1115 { 1088 for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) { 1116 1089 1117 1090 #if BOOT_DEBUG_VOBJS 1118 boot_puts("\n[BOOT DEBUG] ****** vobjs initialisation in vspace "); 1119 boot_puts(vspace[vspace_id].name);1120 boot_puts(" ******\n");1091 boot_puts("\n[BOOT DEBUG] ****** vobjs initialisation in vspace "); 1092 boot_puts(vspace[vspace_id].name); 1093 boot_puts(" ******\n"); 1121 1094 #endif 1122 1095 … … 1124 1097 1125 1098 // loop on the vobjs 1126 for(vobj_id= vspace[vspace_id].vobj_offset; 1127 vobj_id < (vspace[vspace_id].vobj_offset+ vspace[vspace_id].vobjs); 1128 vobj_id++) 1129 { 1130 switch( vobj[vobj_id].type ) 1131 { 1132 case VOBJ_TYPE_MWMR: // storage capacity is (vobj.length/4 - 5) words 1133 { 1134 mwmr_channel_t* mwmr = (mwmr_channel_t*)(vobj[vobj_id].paddr); 1135 mwmr->ptw = 0; 1136 mwmr->ptr = 0; 1137 mwmr->sts = 0; 1099 for (vobj_id = vspace[vspace_id].vobj_offset; 1100 vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs); 1101 vobj_id++) { 1102 switch (vobj[vobj_id].type) { 1103 case VOBJ_TYPE_MWMR: // storage capacity is (vobj.length/4 - 5) words 1104 { 1105 mwmr_channel_t * mwmr = (mwmr_channel_t *) (vobj[vobj_id].paddr); 1106 mwmr->ptw = 0; 1107 mwmr->ptr = 0; 1108 mwmr->sts = 0; 1138 1109 mwmr->width = vobj[vobj_id].init; 1139 mwmr->depth = (vobj[vobj_id].length >>2) - 6;1140 mwmr->lock 1110 mwmr->depth = (vobj[vobj_id].length >> 2) - 6; 1111 mwmr->lock = 0; 1141 1112 #if BOOT_DEBUG_VOBJS 1142 boot_puts("MWMR : ");1143 boot_puts(vobj[vobj_id].name);1144 boot_puts(" / depth = ");1145 boot_putd( mwmr->depth);1146 boot_puts(" / width = ");1147 boot_putd( mwmr->width);1148 boot_puts("\n");1113 boot_puts("MWMR : "); 1114 boot_puts(vobj[vobj_id].name); 1115 boot_puts(" / depth = "); 1116 boot_putd(mwmr->depth); 1117 boot_puts(" / width = "); 1118 boot_putd(mwmr->width); 1119 boot_puts("\n"); 1149 1120 #endif 1150 1121 break; 1151 1122 } 1152 case VOBJ_TYPE_ELF: 1123 case VOBJ_TYPE_ELF: // initialisation done by the loader 1153 1124 { 1154 1125 #if BOOT_DEBUG_VOBJS 1155 boot_puts("ELF : ");1156 boot_puts(vobj[vobj_id].name);1157 boot_puts(" / length = ");1158 boot_putx( vobj[vobj_id].length ); 1159 boot_puts("\n");1126 boot_puts("ELF : "); 1127 boot_puts(vobj[vobj_id].name); 1128 boot_puts(" / length = "); 1129 boot_putx(vobj[vobj_id].length); 1130 boot_puts("\n"); 1160 1131 #endif 1161 1132 break; 1162 1133 } 1163 case VOBJ_TYPE_BLOB: 1134 case VOBJ_TYPE_BLOB: // initialisation done by the loader 1164 1135 { 1165 1136 #if BOOT_DEBUG_VOBJS 1166 boot_puts("BLOB : ");1167 boot_puts(vobj[vobj_id].name);1168 boot_puts(" / length = ");1169 boot_putx( vobj[vobj_id].length ); 1170 boot_puts("\n");1137 boot_puts("BLOB : "); 1138 boot_puts(vobj[vobj_id].name); 1139 boot_puts(" / length = "); 1140 boot_putx(vobj[vobj_id].length); 1141 boot_puts("\n"); 1171 1142 #endif 1172 1143 break; 1173 1144 } 1174 case VOBJ_TYPE_BARRIER: 1145 case VOBJ_TYPE_BARRIER: // init is the number of participants 1175 1146 { 1176 giet_barrier_t * barrier = (giet_barrier_t*)(vobj[vobj_id].paddr);1177 barrier->count = 0;1178 barrier->init 1147 giet_barrier_t * barrier = (giet_barrier_t *) (vobj[vobj_id].paddr); 1148 barrier->count = vobj[vobj_id].init; 1149 barrier->init = vobj[vobj_id].init; 1179 1150 #if BOOT_DEBUG_VOBJS 1180 boot_puts("BARRIER : ");1181 boot_puts(vobj[vobj_id].name);1182 boot_puts(" / init_value = ");1183 boot_putd( barrier->init);1184 boot_puts("\n");1151 boot_puts("BARRIER : "); 1152 boot_puts(vobj[vobj_id].name); 1153 boot_puts(" / init_value = "); 1154 boot_putd(barrier->init); 1155 boot_puts("\n"); 1185 1156 #endif 1186 1157 break; 1187 1158 } 1188 case VOBJ_TYPE_LOCK: 1159 case VOBJ_TYPE_LOCK: // init is "not taken" 1189 1160 { 1190 unsigned int * lock = (unsigned int*)(vobj[vobj_id].paddr);1161 unsigned int * lock = (unsigned int *) (vobj[vobj_id].paddr); 1191 1162 *lock = 0; 1192 1163 #if BOOT_DEBUG_VOBJS 1193 boot_puts("LOCK : ");1194 boot_puts(vobj[vobj_id].name);1195 boot_puts("\n");1164 boot_puts("LOCK : "); 1165 boot_puts(vobj[vobj_id].name); 1166 boot_puts("\n"); 1196 1167 #endif 1197 1168 break; 1198 1169 } 1199 case VOBJ_TYPE_BUFFER: 1170 case VOBJ_TYPE_BUFFER: // nothing to initialise 1200 1171 { 1201 1172 #if BOOT_DEBUG_VOBJS 1202 boot_puts("BUFFER : "); 1203 boot_puts( vobj[vobj_id].name); 1204 boot_puts(" / length = "); 1205 boot_putx( vobj[vobj_id].length ); 1206 boot_puts("\n"); 1173 boot_puts("BUFFER : "); 1174 boot_puts(vobj[vobj_id].name); 1175 boot_puts(" / paddr = "); 1176 boot_putx(vobj[vobj_id].paddr); 1177 boot_puts(" / length = "); 1178 boot_putx(vobj[vobj_id].length); 1179 boot_puts("\n"); 1207 1180 #endif 1208 1181 break; 1209 1182 } 1210 case VOBJ_TYPE_PTAB: // nothing to initialise 1183 case VOBJ_TYPE_MEMSPACE: 1184 { 1185 giet_memspace_t * memspace = (giet_memspace_t *) vobj[vobj_id].paddr; 1186 memspace->buffer = (void *) vobj[vobj_id].vaddr + 8; 1187 memspace->size = vobj[vobj_id].length - 8; 1188 #if BOOT_DEBUG_VOBJS 1189 boot_puts("MEMSPACE : "); 1190 boot_puts(vobj[vobj_id].name); 1191 boot_puts(" / paddr = "); 1192 boot_putx(vobj[vobj_id].paddr); 1193 boot_puts(" / length = "); 1194 boot_putx(vobj[vobj_id].length); 1195 boot_puts("\n"); 1196 #endif 1197 break; 1198 } 1199 case VOBJ_TYPE_PTAB: // nothing to initialise 1211 1200 { 1212 1201 ptab_found = 1; 1213 1202 #if BOOT_DEBUG_VOBJS 1214 boot_puts("PTAB : "); 1215 boot_puts( vobj[vobj_id].name); 1216 boot_puts(" / length = "); 1217 boot_putx( vobj[vobj_id].length ); 1218 boot_puts("\n"); 1219 #endif 1203 boot_puts("PTAB : "); 1204 boot_puts(vobj[vobj_id].name); 1205 boot_puts(" / length = "); 1206 boot_putx(vobj[vobj_id].length); 1207 boot_puts("\n"); 1208 #endif 1209 break; 1210 } 1211 case VOBJ_TYPE_CONST: 1212 { 1213 #if BOOT_DEBUG_VOBJS 1214 boot_puts("CONST : "); 1215 boot_puts(vobj[vobj_id].name); 1216 boot_puts(" / Paddr :"); 1217 boot_putx(vobj[vobj_id].paddr); 1218 boot_puts(" / init = "); 1219 boot_putx(vobj[vobj_id].init); 1220 boot_puts("\n"); 1221 #endif 1222 unsigned int *addr = (unsigned int *) vobj[vobj_id].paddr; 1223 *addr = vobj[vobj_id].init; 1220 1224 break; 1221 1225 } 1222 1226 default: 1223 1227 { 1224 boot_puts("\n[INIT ERROR] illegal vobj of name "); 1225 boot_puts(vobj->name); 1226 boot_puts(" / in vspace = "); 1227 boot_puts(vobj->name); 1228 boot_puts("\n[INIT ERROR] illegal vobj type: "); 1229 boot_putd(vobj[vobj_id].type); 1228 1230 boot_puts("\n "); 1229 1231 boot_exit(); 1230 1232 } 1231 } // end switch type 1232 } // end loop on vobjs 1233 if( ptab_found == 0 ) 1234 { 1233 } // end switch type 1234 } // end loop on vobjs 1235 if (ptab_found == 0) { 1235 1236 boot_puts("\n[INIT ERROR] Missing PTAB for vspace "); 1236 boot_putd( vspace_id);1237 boot_putd(vspace_id); 1237 1238 boot_exit(); 1238 1239 } … … 1240 1241 } // end boot_vobjs_init() 1241 1242 1242 void 1243 mwmr_hw_init( void *coproc, enum mwmrPortDirection way, 1244 unsigned int no, const mwmr_channel_t *pmwmr) 1245 { 1246 volatile unsigned int *cbase = (unsigned int*) coproc; 1247 1248 cbase[MWMR_CONFIG_FIFO_WAY] = way ; 1249 cbase[MWMR_CONFIG_FIFO_NO] = no ; 1250 cbase[MWMR_CONFIG_STATUS_ADDR] = (unsigned int)pmwmr ; 1251 cbase[MWMR_CONFIG_WIDTH] = pmwmr->width ; 1243 1244 void mwmr_hw_init(void * coproc, enum mwmrPortDirection way, 1245 unsigned int no, const mwmr_channel_t * pmwmr) { 1246 volatile unsigned int *cbase = (unsigned int *) coproc; 1247 1248 cbase[MWMR_CONFIG_FIFO_WAY] = way; 1249 cbase[MWMR_CONFIG_FIFO_NO] = no; 1250 cbase[MWMR_CONFIG_STATUS_ADDR] = (unsigned int) pmwmr; 1251 cbase[MWMR_CONFIG_WIDTH] = pmwmr->width; 1252 1252 cbase[MWMR_CONFIG_DEPTH] = pmwmr->depth; 1253 cbase[MWMR_CONFIG_BUFFER_ADDR] = (unsigned int) &pmwmr->data;1254 cbase[MWMR_CONFIG_RUNNING] = 1 1253 cbase[MWMR_CONFIG_BUFFER_ADDR] = (unsigned int) &pmwmr->data; 1254 cbase[MWMR_CONFIG_RUNNING] = 1; 1255 1255 } 1256 1256 … … 1260 1260 // in the mapping_info file. 1261 1261 //////////////////////////////////////////////////////////////////////////////// 1262 void boot_peripherals_init() 1263 { 1264 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 1265 mapping_cluster_t* cluster = boot_get_cluster_base( header ); 1266 mapping_periph_t* periph = boot_get_periph_base( header ); 1267 mapping_pseg_t* pseg = boot_get_pseg_base( header ); 1268 mapping_vobj_t* vobj = boot_get_vobj_base( header ); 1269 mapping_vspace_t* vspace = boot_get_vspace_base( header ); 1270 mapping_coproc_t* coproc = boot_get_coproc_base( header ); 1271 mapping_cp_port_t* cp_port = boot_get_cp_port_base( header ); 1272 1273 unsigned int cluster_id; 1274 unsigned int periph_id; 1275 unsigned int coproc_id; 1276 unsigned int cp_port_id; 1277 unsigned int channel_id; 1278 1279 for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) 1280 { 1262 void boot_peripherals_init() { 1263 mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; 1264 mapping_cluster_t * cluster = boot_get_cluster_base(header); 1265 mapping_periph_t * periph = boot_get_periph_base(header); 1266 mapping_pseg_t * pseg = boot_get_pseg_base(header); 1267 mapping_vobj_t * vobj = boot_get_vobj_base(header); 1268 mapping_vspace_t * vspace = boot_get_vspace_base(header); 1269 mapping_coproc_t * coproc = boot_get_coproc_base(header); 1270 mapping_cp_port_t * cp_port = boot_get_cp_port_base(header); 1271 1272 unsigned int cluster_id; 1273 unsigned int periph_id; 1274 unsigned int coproc_id; 1275 unsigned int cp_port_id; 1276 unsigned int channel_id; 1277 1278 for (cluster_id = 0; cluster_id < header->clusters; cluster_id++) { 1281 1279 1282 1280 #if BOOT_DEBUG_PERI 1283 boot_puts("\n[BOOT DEBUG] ****** peripheral initialisation in cluster "); 1284 boot_putd( cluster_id);1285 boot_puts(" ******\n");1286 #endif 1287 1288 for ( periph_id = cluster[cluster_id].periph_offset ; 1289 periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs;1290 periph_id++ )1291 {1292 unsigned int type= periph[periph_id].type;1293 unsigned int channels= periph[periph_id].channels;1294 unsigned int pseg_id= periph[periph_id].psegid;1295 1296 unsigned int * pseg_base = (unsigned int*)pseg[pseg_id].base;1281 boot_puts 1282 ("\n[BOOT DEBUG] ****** peripheral initialisation in cluster "); 1283 boot_putd(cluster_id); 1284 boot_puts(" ******\n"); 1285 #endif 1286 1287 for (periph_id = cluster[cluster_id].periph_offset; 1288 periph_id < cluster[cluster_id].periph_offset + 1289 cluster[cluster_id].periphs; periph_id++) { 1290 unsigned int type = periph[periph_id].type; 1291 unsigned int channels = periph[periph_id].channels; 1292 unsigned int pseg_id = periph[periph_id].psegid; 1293 1294 unsigned int * pseg_base = (unsigned int *) pseg[pseg_id].base; 1297 1295 1298 1296 #if BOOT_DEBUG_PERI 1299 boot_puts("- peripheral type : "); 1300 boot_putd( type ); 1301 boot_puts(" / address = "); 1302 boot_putx( (unsigned int)pseg_base ); 1303 boot_puts(" / channels = "); 1304 boot_putd( channels ); 1305 boot_puts("\n"); 1306 #endif 1307 1308 switch ( type ) 1309 { 1310 case PERIPH_TYPE_IOC: // vci_block_device component 1311 pseg_base[BLOCK_DEVICE_IRQ_ENABLE] = 1; 1297 boot_puts("- peripheral type : "); 1298 boot_putd(type); 1299 boot_puts(" / address = "); 1300 boot_putx((unsigned int) pseg_base); 1301 boot_puts(" / channels = "); 1302 boot_putd(channels); 1303 boot_puts("\n"); 1304 #endif 1305 1306 switch (type) { 1307 case PERIPH_TYPE_IOC: // vci_block_device component 1308 pseg_base[BLOCK_DEVICE_IRQ_ENABLE] = 1; 1312 1309 #if BOOT_DEBUG_PERI 1313 boot_puts("- IOC initialised\n");1314 #endif 1315 break;1316 case PERIPH_TYPE_DMA: // vci_multi_dma component 1317 for ( channel_id = 0 ; channel_id < channels ; channel_id++ )1318 {1319 pseg_base[DMA_IRQ_DISABLE + channel_id *DMA_SPAN] = 0;1310 boot_puts("- IOC initialised\n"); 1311 #endif 1312 break; 1313 1314 case PERIPH_TYPE_DMA: // vci_multi_dma component 1315 for (channel_id = 0; channel_id < channels; channel_id++) { 1316 pseg_base[DMA_IRQ_DISABLE + channel_id * DMA_SPAN] = 0; 1320 1317 } 1321 1318 #if BOOT_DEBUG_PERI 1322 boot_puts("- DMA initialised\n");1323 #endif 1324 break;1325 case PERIPH_TYPE_NIC: // vci_multi_nic component 1326 for ( channel_id = 0 ; channel_id < channels ; channel_id++ )1327 {1319 boot_puts("- DMA initialised\n"); 1320 #endif 1321 break; 1322 1323 case PERIPH_TYPE_NIC: // vci_multi_nic component 1324 for (channel_id = 0; channel_id < channels; channel_id++) { 1328 1325 // TODO 1329 1326 } 1330 1327 #if BOOT_DEBUG_PERI 1331 boot_puts("- NIC initialised\n"); 1332 #endif 1333 break; 1334 case PERIPH_TYPE_TTY: // vci_multi_tty component 1328 boot_puts("- NIC initialised\n"); 1329 #endif 1330 break; 1331 1332 case PERIPH_TYPE_TTY: // vci_multi_tty component 1335 1333 #if BOOT_DEBUG_PERI 1336 boot_puts("- TTY initialised\n");1337 #endif 1338 break;1339 case PERIPH_TYPE_IOB: // vci_io_bridge component 1340 if ( IOMMU_ACTIVE )1341 {1334 boot_puts("- TTY initialised\n"); 1335 #endif 1336 break; 1337 1338 case PERIPH_TYPE_IOB: // vci_io_bridge component 1339 if (IOMMU_ACTIVE) { 1342 1340 // TODO 1343 1341 // get the iommu page table physical address … … 1349 1347 } 1350 1348 #if BOOT_DEBUG_PERI 1351 boot_puts("- IOB initialised\n");1352 #endif 1353 break;1354 } // end switch periph type1355 } // end for periphs1349 boot_puts("- IOB initialised\n"); 1350 #endif 1351 break; 1352 } // end switch periph type 1353 } // end for periphs 1356 1354 1357 1355 #if BOOT_DEBUG_PERI 1358 boot_puts("\n[BOOT DEBUG] ****** coprocessors initialisation in cluster "); 1359 boot_putd( cluster_id);1360 boot_puts(" ******\n");1361 #endif 1362 1363 for ( coproc_id = cluster[cluster_id].coproc_offset ; 1364 coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs;1365 coproc_id++ )1366 {1367 unsigned no_fifo_to = 0;//FIXME: should it be the map.xml who define the order?1356 boot_puts 1357 ("\n[BOOT DEBUG] ****** coprocessors initialisation in cluster "); 1358 boot_putd(cluster_id); 1359 boot_puts(" ******\n"); 1360 #endif 1361 1362 for (coproc_id = cluster[cluster_id].coproc_offset; 1363 coproc_id < cluster[cluster_id].coproc_offset + 1364 cluster[cluster_id].coprocs; coproc_id++) { 1365 unsigned no_fifo_to = 0; //FIXME: should it be the map.xml who define the order? 1368 1366 unsigned no_fifo_from = 0; 1369 1367 unsigned int cpseg = pseg[coproc[coproc_id].psegid].base; 1370 1368 1371 1369 #if BOOT_DEBUG_PERI 1372 boot_puts("- coprocessor name : "); 1373 boot_puts( coproc[coproc_id].name ); 1374 boot_puts(" / nb ports = "); 1375 boot_putd((unsigned int)coproc[coproc_id].ports); 1376 boot_puts("\n"); 1377 #endif 1378 1379 for ( cp_port_id = coproc[coproc_id].port_offset ; 1380 cp_port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports ; 1381 cp_port_id++ ) 1382 { 1370 boot_puts("- coprocessor name : "); 1371 boot_puts(coproc[coproc_id].name); 1372 boot_puts(" / nb ports = "); 1373 boot_putd((unsigned int) coproc[coproc_id].ports); 1374 boot_puts("\n"); 1375 #endif 1376 1377 for (cp_port_id = coproc[coproc_id].port_offset; 1378 cp_port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports; 1379 cp_port_id++) { 1383 1380 //FIXME: the vspace_id should be the same for all ports: put it in the coproc? 1384 unsigned int vspace_id = cp_port[cp_port_id].vspaceid; 1385 unsigned int vobj_id = cp_port[cp_port_id].vobjlocid + vspace[vspace_id].vobj_offset; 1386 1387 mwmr_channel_t *pmwmr = (mwmr_channel_t*)(vobj[vobj_id].paddr); 1388 1389 if( cp_port[cp_port_id].direction == PORT_TO_COPROC) 1390 { 1391 1381 unsigned int vspace_id = cp_port[cp_port_id].vspaceid; 1382 unsigned int vobj_id = cp_port[cp_port_id].vobjlocid + vspace[vspace_id].vobj_offset; 1383 1384 mwmr_channel_t * pmwmr = (mwmr_channel_t *) (vobj[vobj_id].paddr); 1385 1386 if (cp_port[cp_port_id].direction == PORT_TO_COPROC) { 1392 1387 #if BOOT_DEBUG_PERI 1393 boot_puts(" port direction: PORT_TO_COPROC");1394 #endif 1395 mwmr_hw_init((void *)cpseg, PORT_TO_COPROC, no_fifo_to, pmwmr);1388 boot_puts(" port direction: PORT_TO_COPROC"); 1389 #endif 1390 mwmr_hw_init((void *) cpseg, PORT_TO_COPROC, no_fifo_to, pmwmr); 1396 1391 no_fifo_to++; 1397 1392 } 1398 else 1399 { 1393 else { 1400 1394 #if BOOT_DEBUG_PERI 1401 boot_puts(" port direction: PORT_FROM_COPROC");1402 #endif 1403 mwmr_hw_init((void *)cpseg, PORT_FROM_COPROC, no_fifo_from, pmwmr);1395 boot_puts(" port direction: PORT_FROM_COPROC"); 1396 #endif 1397 mwmr_hw_init((void *) cpseg, PORT_FROM_COPROC, no_fifo_from, pmwmr); 1404 1398 no_fifo_from++; 1405 1399 } 1406 1400 #if BOOT_DEBUG_PERI 1407 boot_puts(", with mwmr: ");1408 boot_puts(vobj[vobj_id].name);1409 boot_puts(" of vspace: ");1410 boot_puts(vspace[vspace_id].name);1401 boot_puts(", with mwmr: "); 1402 boot_puts(vobj[vobj_id].name); 1403 boot_puts(" of vspace: "); 1404 boot_puts(vspace[vspace_id].name); 1411 1405 #endif 1412 1406 } 1413 1407 } // end for coprocs 1414 1415 1408 } // end for clusters 1416 1409 } // end boot_peripherals_init() … … 1426 1419 // channel can be allocated if required. 1427 1420 /////////////////////////////////////////////////////////////////////////////// 1428 void boot_schedulers_init() 1429 { 1430 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 1431 mapping_cluster_t* cluster = boot_get_cluster_base( header ); 1432 mapping_pseg_t* pseg = boot_get_pseg_base( header ); 1433 mapping_vspace_t* vspace = boot_get_vspace_base( header ); 1434 mapping_task_t* task = boot_get_task_base( header ); 1435 mapping_vobj_t* vobj = boot_get_vobj_base( header ); 1436 mapping_proc_t* proc = boot_get_proc_base( header ); 1437 mapping_irq_t* irq = boot_get_irq_base( header ); 1438 1439 unsigned int alloc_tty_channel; // TTY channel allocator 1440 unsigned int alloc_nic_channel; // NIC channel allocator 1441 unsigned int alloc_dma_channel[NB_CLUSTERS]; // DMA channel allocators 1442 unsigned int alloc_timer_channel[NB_CLUSTERS]; // user TIMER allocators 1443 1444 unsigned int cluster_id; // cluster global index 1445 unsigned int proc_id; // processor global index 1446 unsigned int irq_id; // irq global index 1447 unsigned int pseg_id; // pseg global index 1448 unsigned int vspace_id; // vspace global index 1449 unsigned int task_id; // task global index; 1421 void boot_schedulers_init() { 1422 mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; 1423 mapping_cluster_t * cluster = boot_get_cluster_base(header); 1424 mapping_pseg_t * pseg = boot_get_pseg_base(header); 1425 mapping_vspace_t * vspace = boot_get_vspace_base(header); 1426 mapping_task_t * task = boot_get_task_base(header); 1427 mapping_vobj_t * vobj = boot_get_vobj_base(header); 1428 mapping_proc_t * proc = boot_get_proc_base(header); 1429 mapping_irq_t * irq = boot_get_irq_base(header); 1430 1431 unsigned int alloc_tty_channel; // TTY channel allocator 1432 unsigned int alloc_nic_channel; // NIC channel allocator 1433 unsigned int alloc_dma_channel[NB_CLUSTERS]; // DMA channel allocators 1434 unsigned int alloc_timer_channel[NB_CLUSTERS]; // user TIMER allocators 1435 1436 unsigned int cluster_id; // cluster global index 1437 unsigned int proc_id; // processor global index 1438 unsigned int irq_id; // irq global index 1439 unsigned int pseg_id; // pseg global index 1440 unsigned int vspace_id; // vspace global index 1441 unsigned int task_id; // task global index; 1450 1442 1451 1443 // Step 0 : TTY, NIC, TIMERS and DMA channels allocators initialisation … … 1455 1447 // are reserved for the kernel (context switch) 1456 1448 1457 alloc_tty_channel = 1; 1449 alloc_tty_channel = 1; 1458 1450 alloc_nic_channel = 0; 1459 1451 1460 for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) 1461 { 1462 alloc_dma_channel[cluster_id] = 0; 1452 for (cluster_id = 0; cluster_id < header->clusters; cluster_id++) { 1453 alloc_dma_channel[cluster_id] = 0; 1463 1454 alloc_timer_channel[cluster_id] = 0; 1464 1455 } 1465 1456 1466 1457 // Step 1 : loop on the clusters and on the processors 1467 1458 // - initialise the boot_schedulers_paddr[] pointers array 1468 1459 // - initialise the interrupt vectors for each processor. 1469 1460 1470 for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) 1471 { 1461 for (cluster_id = 0; cluster_id < header->clusters; cluster_id++) { 1472 1462 1473 1463 #if BOOT_DEBUG_SCHED 1474 boot_puts("\n[BOOT DEBUG] Initialise schedulers / IT vector in cluster ");1475 boot_putd( cluster_id);1476 boot_puts("\n");1464 boot_puts("\n[BOOT DEBUG] Initialise schedulers / IT vector in cluster "); 1465 boot_putd(cluster_id); 1466 boot_puts("\n"); 1477 1467 #endif 1478 1468 unsigned int found = 0; 1479 unsigned int pseg_pbase; 1480 unsigned int lpid; 1469 unsigned int pseg_pbase; // pseg base address 1470 unsigned int lpid; // processor local index 1481 1471 1482 1472 // get the physical base address of the first PSEG_TYPE_RAM pseg in cluster 1483 for ( pseg_id = cluster[cluster_id].pseg_offset ; 1484 pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs ; 1485 pseg_id++ ) 1486 { 1487 if ( pseg[pseg_id].type == PSEG_TYPE_RAM ) 1488 { 1473 for (pseg_id = cluster[cluster_id].pseg_offset; 1474 pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs; 1475 pseg_id++) { 1476 if (pseg[pseg_id].type == PSEG_TYPE_RAM) { 1489 1477 pseg_pbase = pseg[pseg_id].base; 1490 1478 found = 1; … … 1493 1481 } 1494 1482 1495 if ( (cluster[cluster_id].procs > 0) && (found == 0) ) 1496 { 1483 if ((cluster[cluster_id].procs > 0) && (found == 0)) { 1497 1484 boot_puts("\n[BOOT ERROR] Missing RAM pseg in cluster "); 1498 boot_putd( cluster_id);1485 boot_putd(cluster_id); 1499 1486 boot_puts("\n"); 1500 1487 boot_exit(); 1501 1488 } 1502 1503 1489 // 4 Kbytes per scheduler 1504 for ( lpid = 0 ; lpid < cluster[cluster_id].procs ; lpid++ ) 1505 { 1506 boot_schedulers_paddr[cluster_id*NB_PROCS_MAX + lpid] = 1507 (static_scheduler_t*)( pseg_pbase + (lpid<<12) ); 1508 } 1509 1510 for ( proc_id = cluster[cluster_id].proc_offset ; 1511 proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs ; 1512 proc_id++ ) 1513 { 1490 for (lpid = 0; lpid < cluster[cluster_id].procs; lpid++) { 1491 boot_schedulers_paddr[cluster_id * NB_PROCS_MAX + lpid] = (static_scheduler_t *) (pseg_pbase + (lpid << 12)); 1492 } 1493 1494 for (proc_id = cluster[cluster_id].proc_offset; 1495 proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs; 1496 proc_id++) { 1514 1497 1515 1498 #if BOOT_DEBUG_SCHED 1516 boot_puts("\nProc ");1517 boot_putd( proc_id);1518 boot_puts(" : scheduler pbase = ");1519 boot_putx( pseg_pbase + (proc_id<<12));1520 boot_puts("\n");1499 boot_puts("\nProc "); 1500 boot_putd(proc_id); 1501 boot_puts(" : scheduler pbase = "); 1502 boot_putx(pseg_pbase + (proc_id << 12)); 1503 boot_puts("\n"); 1521 1504 #endif 1522 1505 // initialise the "tasks" variable in scheduler 1523 boot_scheduler_set_tasks( proc_id , 0);1524 1506 boot_scheduler_set_tasks(proc_id, 0); 1507 1525 1508 // initialise the interrupt_vector with ISR_DEFAULT 1526 1509 unsigned int slot; 1527 for ( slot = 0 ; slot < 32 ; slot++) 1528 { 1529 boot_scheduler_set_itvector( proc_id, slot, 0); 1510 for (slot = 0; slot < 32; slot++) { 1511 boot_scheduler_set_itvector(proc_id, slot, 0); 1530 1512 } 1531 1513 1532 1514 // scan the IRQs actually allocated to current processor 1533 for ( irq_id = proc[proc_id].irq_offset ; 1534 irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs ; 1535 irq_id++ ) 1536 { 1537 unsigned int type = irq[irq_id].type; 1538 unsigned int icu_id = irq[irq_id].icuid; 1539 unsigned int isr_id = irq[irq_id].isr; 1515 for (irq_id = proc[proc_id].irq_offset; 1516 irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs; 1517 irq_id++) { 1518 unsigned int type = irq[irq_id].type; 1519 unsigned int icu_id = irq[irq_id].icuid; 1520 unsigned int isr_id = irq[irq_id].isr; 1540 1521 unsigned int channel = irq[irq_id].channel; 1541 unsigned int value = isr_id | (type<<8) | (channel<<16);1542 boot_scheduler_set_itvector( proc_id, icu_id, value);1522 unsigned int value = isr_id | (type << 8) | (channel << 16); 1523 boot_scheduler_set_itvector(proc_id, icu_id, value); 1543 1524 1544 1525 #if BOOT_DEBUG_SCHED 1545 boot_puts("- IRQ : icu = ");1546 boot_putd( icu_id);1547 boot_puts(" / type = ");1548 boot_putd( type);1549 boot_puts(" / isr = ");1550 boot_putd( isr_id);1551 boot_puts(" / channel = ");1552 boot_putd( channel);1553 boot_puts("\n");1526 boot_puts("- IRQ : icu = "); 1527 boot_putd(icu_id); 1528 boot_puts(" / type = "); 1529 boot_putd(type); 1530 boot_puts(" / isr = "); 1531 boot_putd(isr_id); 1532 boot_puts(" / channel = "); 1533 boot_putd(channel); 1534 boot_puts("\n"); 1554 1535 #endif 1555 1536 } … … 1560 1541 // to initialise the schedulers and the task contexts. 1561 1542 1562 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 1563 { 1543 for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) { 1564 1544 1565 1545 #if BOOT_DEBUG_SCHED 1566 boot_puts("\n[BOOT DEBUG] Initialise schedulers / task contexts for vspace "); 1567 boot_puts(vspace[vspace_id].name); 1568 boot_puts("\n"); 1546 boot_puts 1547 ("\n[BOOT DEBUG] Initialise schedulers / task contexts for vspace "); 1548 boot_puts(vspace[vspace_id].name); 1549 boot_puts("\n"); 1569 1550 #endif 1570 1551 // We must set the PTPR depending on the vspace, because the start_vector 1571 1552 // and the stack address are defined in virtual space. 1572 boot_set_mmu_ptpr( (unsigned int)boot_ptabs_paddr[vspace_id] >> 13);1553 boot_set_mmu_ptpr((unsigned int) boot_ptabs_paddr[vspace_id] >> 13); 1573 1554 1574 1555 // loop on the tasks in vspace (task_id is the global index) 1575 for ( task_id = vspace[vspace_id].task_offset ; 1576 task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks) ; 1577 task_id++ ) 1578 { 1556 for (task_id = vspace[vspace_id].task_offset; 1557 task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks); 1558 task_id++) { 1579 1559 // ctx_ra : the return address is &boot_eret() 1580 unsigned int ctx_ra = (unsigned int) &boot_eret;1560 unsigned int ctx_ra = (unsigned int) &boot_eret; 1581 1561 1582 1562 // ctx_sr : value required before an eret instruction 1583 unsigned int ctx_sr = 0x0000FF13; 1563 unsigned int ctx_sr = 0x0000FF13; 1584 1564 1585 1565 // ctx_ptpr : page table physical base address (shifted by 13 bit) 1586 unsigned int ctx_ptpr = (unsigned int) boot_ptabs_paddr[vspace_id] >> 13;1566 unsigned int ctx_ptpr = (unsigned int) boot_ptabs_paddr[vspace_id] >> 13; 1587 1567 1588 1568 // compute gpid = global processor index 1589 unsigned int gpid = task[task_id].clusterid*NB_PROCS_MAX + 1590 task[task_id].proclocid; 1569 unsigned int gpid = task[task_id].clusterid * NB_PROCS_MAX + task[task_id].proclocid; 1591 1570 1592 1571 // ctx_ptab : page_table virtual base address 1593 unsigned int ctx_ptab = (unsigned int) boot_ptabs_vaddr[vspace_id];1572 unsigned int ctx_ptab = (unsigned int) boot_ptabs_vaddr[vspace_id]; 1594 1573 1595 1574 // ctx_tty : terminal global index provided by a global allocator 1596 1575 unsigned int ctx_tty = 0xFFFFFFFF; 1597 if ( task[task_id].use_tty ) 1598 { 1599 if ( alloc_tty_channel >= NB_TTYS ) 1600 { 1576 if (task[task_id].use_tty) { 1577 if (alloc_tty_channel >= NB_TTYS) { 1601 1578 boot_puts("\n[BOOT ERROR] TTY index too large for task "); 1602 boot_puts( task[task_id].name);1579 boot_puts(task[task_id].name); 1603 1580 boot_puts(" in vspace "); 1604 boot_puts( vspace[vspace_id].name);1581 boot_puts(vspace[vspace_id].name); 1605 1582 boot_puts("\n"); 1606 1583 boot_exit(); … … 1609 1586 alloc_tty_channel++; 1610 1587 } 1611 1612 1588 // ctx_nic : NIC channel global index provided by a global allocator 1613 1589 unsigned int ctx_nic = 0xFFFFFFFF; 1614 if ( task[task_id].use_nic ) 1615 { 1616 if ( alloc_nic_channel >= NB_NICS ) 1617 { 1590 if (task[task_id].use_nic) { 1591 if (alloc_nic_channel >= NB_NICS) { 1618 1592 boot_puts("\n[BOOT ERROR] NIC channel index too large for task "); 1619 boot_puts( task[task_id].name);1593 boot_puts(task[task_id].name); 1620 1594 boot_puts(" in vspace "); 1621 boot_puts( vspace[vspace_id].name);1595 boot_puts(vspace[vspace_id].name); 1622 1596 boot_puts("\n"); 1623 1597 boot_exit(); … … 1626 1600 alloc_nic_channel++; 1627 1601 } 1628 1629 1602 // ctx_timer : user TIMER global index provided by a cluster allocator 1630 1603 unsigned int ctx_timer = 0xFFFFFFFF; 1631 if ( task[task_id].use_timer ) 1632 { 1604 if (task[task_id].use_timer) { 1633 1605 unsigned int cluster_id = task[task_id].clusterid; 1634 1606 unsigned int allocated = alloc_timer_channel[cluster_id]; 1635 1607 1636 if ( allocated >= NB_TIMERS_MAX ) 1637 { 1608 if (allocated >= NB_TIMERS_MAX) { 1638 1609 boot_puts("\n[BOOT ERROR] local TIMER index too large for task "); 1639 boot_puts( task[task_id].name);1610 boot_puts(task[task_id].name); 1640 1611 boot_puts(" in vspace "); 1641 boot_puts( vspace[vspace_id].name);1612 boot_puts(vspace[vspace_id].name); 1642 1613 boot_puts("\n"); 1643 1614 boot_exit(); 1644 1615 } 1645 1646 1616 //assert(allocated >= 0); 1647 1617 char found = 0; 1648 for( irq_id = 0; irq_id < 32; irq_id++)//look at the isr_timer isr channel 1649 { 1650 unsigned int isr = boot_scheduler_get_itvector(gpid, irq_id) && 0x000000FF; 1651 if(isr == ISR_TIMER) 1652 { 1653 if(allocated == 0) 1654 { 1618 for (irq_id = 0; irq_id < 32; irq_id++) { //look at the isr_timer isr channel 1619 unsigned int isr = boot_scheduler_get_itvector(gpid, irq_id) & 0x000000FF; 1620 if (isr == ISR_TIMER) { 1621 if (allocated == 0) { 1655 1622 found = 1; 1656 1623 alloc_timer_channel[cluster_id]++; 1657 ctx_timer = cluster_id *NB_TIMERS_MAX + alloc_timer_channel[cluster_id];1624 ctx_timer = cluster_id * NB_TIMERS_MAX + alloc_timer_channel[cluster_id]; 1658 1625 break; 1659 }else 1626 } 1627 else { 1660 1628 allocated--; 1629 } 1661 1630 } 1662 1631 } 1663 1632 1664 if(!found) 1665 { 1633 if (!found) { 1666 1634 boot_puts("\n[BOOT ERROR] No user timer available for task "); 1667 boot_puts( task[task_id].name);1635 boot_puts(task[task_id].name); 1668 1636 boot_puts(" in vspace "); 1669 boot_puts( vspace[vspace_id].name);1637 boot_puts(vspace[vspace_id].name); 1670 1638 boot_puts("\n"); 1671 1639 boot_exit(); … … 1673 1641 1674 1642 } 1675 1676 1643 // ctx_dma : DMA global index provided by a cluster allocator 1677 1644 unsigned int ctx_dma = 0xFFFFFFFF; 1678 if ( task[task_id].use_fbdma || task[task_id].use_nic ) 1679 { 1645 if (task[task_id].use_fbdma || task[task_id].use_nic) { 1680 1646 unsigned int cluster_id = task[task_id].clusterid; 1681 if ( alloc_dma_channel[cluster_id] >= NB_DMAS_MAX ) 1682 { 1647 if (alloc_dma_channel[cluster_id] >= NB_DMAS_MAX) { 1683 1648 boot_puts("\n[BOOT ERROR] local DMA index too large for task "); 1684 boot_puts( task[task_id].name);1649 boot_puts(task[task_id].name); 1685 1650 boot_puts(" in vspace "); 1686 boot_puts( vspace[vspace_id].name);1651 boot_puts(vspace[vspace_id].name); 1687 1652 boot_puts("\n"); 1688 1653 boot_exit(); 1689 1654 } 1690 ctx_dma = cluster_id *NB_DMAS_MAX + alloc_dma_channel[cluster_id];1655 ctx_dma = cluster_id * NB_DMAS_MAX + alloc_dma_channel[cluster_id]; 1691 1656 alloc_dma_channel[cluster_id]++; 1692 1657 } 1693 1694 1658 // ctx_epc : Get the virtual address of the start function 1695 mapping_vobj_t* pvobj = &vobj[vspace[vspace_id].vobj_offset + 1696 vspace[vspace_id].start_offset]; 1697 unsigned int* start_vector_vbase = (unsigned int*)pvobj->vaddr; 1659 mapping_vobj_t * pvobj = &vobj[vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset]; 1660 unsigned int * start_vector_vbase = (unsigned int *) pvobj->vaddr; 1698 1661 unsigned int ctx_epc = start_vector_vbase[task[task_id].startid]; 1699 1662 … … 1707 1670 1708 1671 // get local task index in scheduler[gpid] 1709 unsigned int ltid = boot_scheduler_get_tasks( gpid ); 1710 1711 if ( ltid >= IDLE_TASK_INDEX ) 1712 { 1672 unsigned int ltid = boot_scheduler_get_tasks(gpid); 1673 1674 if (ltid >= IDLE_TASK_INDEX) { 1713 1675 boot_puts("\n[BOOT ERROR] : "); 1714 boot_putd( ltid);1676 boot_putd(ltid); 1715 1677 boot_puts(" tasks allocated to processor "); 1716 boot_putd( gpid);1678 boot_putd(gpid); 1717 1679 boot_puts(" / max is 15\n"); 1718 1680 boot_exit(); 1719 1681 } 1720 1721 1682 // update the "tasks" field in scheduler[gpid] 1722 boot_scheduler_set_tasks( 1683 boot_scheduler_set_tasks(gpid, ltid + 1); 1723 1684 1724 1685 // update the "current" field in scheduler[gpid] 1725 boot_scheduler_set_current( gpid, 0);1686 boot_scheduler_set_current(gpid, 0); 1726 1687 1727 1688 // initializes the task context in scheduler[gpid] 1728 boot_scheduler_set_context( gpid, ltid, CTX_SR_ID , ctx_sr);1729 boot_scheduler_set_context( gpid, ltid, CTX_SP_ID , ctx_sp);1730 boot_scheduler_set_context( gpid, ltid, CTX_RA_ID , ctx_ra);1731 boot_scheduler_set_context( gpid, ltid, CTX_EPC_ID , ctx_epc);1732 boot_scheduler_set_context( gpid, ltid, CTX_PTPR_ID , ctx_ptpr);1733 boot_scheduler_set_context( gpid, ltid, CTX_TTY_ID , ctx_tty);1734 boot_scheduler_set_context( gpid, ltid, CTX_DMA_ID , ctx_dma);1735 boot_scheduler_set_context( gpid, ltid, CTX_NIC_ID , ctx_nic);1736 boot_scheduler_set_context( gpid, ltid, CTX_TIMER_ID , ctx_timer);1737 boot_scheduler_set_context( gpid, ltid, CTX_PTAB_ID , ctx_ptab);1738 boot_scheduler_set_context( gpid, ltid, CTX_LTID_ID , ltid);1739 boot_scheduler_set_context( gpid, ltid, CTX_VSID_ID , vspace_id);1740 boot_scheduler_set_context( gpid, ltid, CTX_RUN_ID , 1);1741 1689 boot_scheduler_set_context(gpid, ltid, CTX_SR_ID, ctx_sr); 1690 boot_scheduler_set_context(gpid, ltid, CTX_SP_ID, ctx_sp); 1691 boot_scheduler_set_context(gpid, ltid, CTX_RA_ID, ctx_ra); 1692 boot_scheduler_set_context(gpid, ltid, CTX_EPC_ID, ctx_epc); 1693 boot_scheduler_set_context(gpid, ltid, CTX_PTPR_ID, ctx_ptpr); 1694 boot_scheduler_set_context(gpid, ltid, CTX_TTY_ID, ctx_tty); 1695 boot_scheduler_set_context(gpid, ltid, CTX_DMA_ID, ctx_dma); 1696 boot_scheduler_set_context(gpid, ltid, CTX_NIC_ID, ctx_nic); 1697 boot_scheduler_set_context(gpid, ltid, CTX_TIMER_ID, ctx_timer); 1698 boot_scheduler_set_context(gpid, ltid, CTX_PTAB_ID, ctx_ptab); 1699 boot_scheduler_set_context(gpid, ltid, CTX_LTID_ID, ltid); 1700 boot_scheduler_set_context(gpid, ltid, CTX_VSID_ID, vspace_id); 1701 boot_scheduler_set_context(gpid, ltid, CTX_RUN_ID, 1); 1702 1742 1703 #if BOOT_DEBUG_SCHED 1743 boot_puts("\nTask "); 1744 boot_puts( task[task_id].name ); 1745 boot_puts(" allocated to processor "); 1746 boot_putd( gpid ); 1747 boot_puts(" - ctx[LTID] = "); 1748 boot_putd( ltid ); 1749 boot_puts("\n"); 1750 1751 boot_puts(" - ctx[SR] = "); 1752 boot_putx( ctx_sr ); 1753 boot_puts("\n"); 1754 1755 boot_puts(" - ctx[SR] = "); 1756 boot_putx( ctx_sp ); 1757 boot_puts("\n"); 1758 1759 boot_puts(" - ctx[RA] = "); 1760 boot_putx( ctx_ra ); 1761 boot_puts("\n"); 1762 1763 boot_puts(" - ctx[EPC] = "); 1764 boot_putx( ctx_epc ); 1765 boot_puts("\n"); 1766 1767 boot_puts(" - ctx[PTPR] = "); 1768 boot_putx( ctx_ptpr ); 1769 boot_puts("\n"); 1770 1771 boot_puts(" - ctx[TTY] = "); 1772 boot_putd( ctx_tty ); 1773 boot_puts("\n"); 1774 1775 boot_puts(" - ctx[NIC] = "); 1776 boot_putd( ctx_nic ); 1777 boot_puts("\n"); 1778 1779 boot_puts(" - ctx[TIMER] = "); 1780 boot_putd( ctx_timer ); 1781 boot_puts("\n"); 1782 1783 boot_puts(" - ctx[DMA] = "); 1784 boot_putd( ctx_dma ); 1785 boot_puts("\n"); 1786 1787 boot_puts(" - ctx[PTAB] = "); 1788 boot_putx( ctx_ptab ); 1789 boot_puts("\n"); 1790 1791 boot_puts(" - ctx[VSID] = "); 1792 boot_putd( vspace_id ); 1793 boot_puts("\n"); 1704 boot_puts("\nTask "); 1705 boot_puts(task[task_id].name); 1706 boot_puts(" ("); 1707 boot_putd(task_id); 1708 boot_puts(") allocated to processor "); 1709 boot_putd(gpid); 1710 boot_puts(" - ctx[LTID] = "); 1711 boot_putd(ltid); 1712 boot_puts("\n"); 1713 1714 boot_puts(" - ctx[SR] = "); 1715 boot_putx(ctx_sr); 1716 boot_puts("\n"); 1717 1718 boot_puts(" - ctx[SR] = "); 1719 boot_putx(ctx_sp); 1720 boot_puts("\n"); 1721 1722 boot_puts(" - ctx[RA] = "); 1723 boot_putx(ctx_ra); 1724 boot_puts("\n"); 1725 1726 boot_puts(" - ctx[EPC] = "); 1727 boot_putx(ctx_epc); 1728 boot_puts("\n"); 1729 1730 boot_puts(" - ctx[PTPR] = "); 1731 boot_putx(ctx_ptpr); 1732 boot_puts("\n"); 1733 1734 boot_puts(" - ctx[TTY] = "); 1735 boot_putd(ctx_tty); 1736 boot_puts("\n"); 1737 1738 boot_puts(" - ctx[NIC] = "); 1739 boot_putd(ctx_nic); 1740 boot_puts("\n"); 1741 1742 boot_puts(" - ctx[TIMER] = "); 1743 boot_putd(ctx_timer); 1744 boot_puts("\n"); 1745 1746 boot_puts(" - ctx[DMA] = "); 1747 boot_putd(ctx_dma); 1748 boot_puts("\n"); 1749 1750 boot_puts(" - ctx[PTAB] = "); 1751 boot_putx(ctx_ptab); 1752 boot_puts("\n"); 1753 1754 boot_puts(" - ctx[VSID] = "); 1755 boot_putd(vspace_id); 1756 boot_puts("\n"); 1794 1757 1795 1758 #endif … … 1799 1762 } // end boot_schedulers_init() 1800 1763 1764 1801 1765 ////////////////////////////////////////////////////////////////////////////////// 1802 1766 // This function is executed by P[0] to wakeup all processors. 1803 1767 ////////////////////////////////////////////////////////////////////////////////// 1804 void boot_start_all_procs() 1805 { 1806 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 1768 void boot_start_all_procs() { 1769 mapping_header_t * header = (mapping_header_t *) &seg_mapping_base; 1807 1770 header->signature = OUT_MAPPING_SIGNATURE; 1808 1771 } 1772 1809 1773 1810 1774 ///////////////////////////////////////////////////////////////////// 1811 1775 // This function is the entry point of the initialisation procedure 1812 1776 ///////////////////////////////////////////////////////////////////// 1813 void boot_init() 1814 { 1777 void boot_init() { 1815 1778 // mapping_info checking 1816 1779 boot_check_mapping(); 1817 1780 1818 1781 boot_puts("\n[BOOT] Mapping check completed at cycle "); 1819 boot_putd( boot_proctime());1782 boot_putd(boot_proctime()); 1820 1783 boot_puts("\n"); 1821 1784 … … 1823 1786 boot_psegs_init(); 1824 1787 1825 boot_puts("\n[BOOT] Pseg allocators initialisation completed at cycle "); 1826 boot_putd( boot_proctime() ); 1788 boot_puts 1789 ("\n[BOOT] Pseg allocators initialisation completed at cycle "); 1790 boot_putd(boot_proctime()); 1827 1791 boot_puts("\n"); 1828 1792 … … 1831 1795 1832 1796 boot_puts("\n[BOOT] Page Tables initialisation completed at cycle "); 1833 boot_putd( boot_proctime());1797 boot_putd(boot_proctime()); 1834 1798 boot_puts("\n"); 1835 1799 … … 1838 1802 1839 1803 boot_puts("\n[BOOT] Vobjs initialisation completed at cycle : "); 1840 boot_putd( boot_proctime());1804 boot_putd(boot_proctime()); 1841 1805 boot_puts("\n"); 1842 1806 … … 1845 1809 1846 1810 boot_puts("\n[BOOT] Peripherals initialisation completed at cycle "); 1847 boot_putd( boot_proctime());1811 boot_putd(boot_proctime()); 1848 1812 boot_puts("\n"); 1849 1813 1850 1814 // mmu activation 1851 boot_set_mmu_ptpr( (unsigned int)boot_ptabs_paddr[0] >> 13);1852 boot_set_mmu_mode( 0xF);1815 boot_set_mmu_ptpr((unsigned int) boot_ptabs_paddr[0] >> 13); 1816 boot_set_mmu_mode(0xF); 1853 1817 1854 1818 boot_puts("\n[BOOT] MMU activation completed at cycle "); 1855 boot_putd( boot_proctime());1819 boot_putd(boot_proctime()); 1856 1820 boot_puts("\n"); 1857 1821 … … 1860 1824 1861 1825 boot_puts("\n[BOOT] Schedulers initialisation completed at cycle "); 1862 boot_putd( boot_proctime());1826 boot_putd(boot_proctime()); 1863 1827 boot_puts("\n"); 1864 1828 … … 1867 1831 1868 1832 } // end boot_init() 1833 1869 1834 1870 1835 // Local Variables: … … 1874 1839 // indent-tabs-mode: nil 1875 1840 // End: 1876 // vim: filetype=c pp:expandtab:shiftwidth=4:tabstop=4:softtabstop=41877 1841 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 1842 -
soft/giet_vm/libs/barrier.c
r165 r228 15 15 16 16 /////////////////////////////////////////////////////////////////////////////////// 17 // 17 // barrier_init() 18 18 // This function makes a cooperative initialisation of the barrier: 19 19 // several tasks try to initialize the barrier, but the initialisation 20 20 // is done by only one task, using LL/SC instructions. 21 21 /////////////////////////////////////////////////////////////////////////////////// 22 void barrier_init( giet_barrier_t* barrier, 23 unsigned int value ) 24 { 25 unsigned int* pinit = (unsigned int*)&barrier->init; 26 unsigned int* pcount = (unsigned int*)&barrier->count; 22 void barrier_init( giet_barrier_t * barrier, unsigned int value) { 23 unsigned int * pinit = (unsigned int *) &barrier->init; 24 unsigned int * pcount = (unsigned int *) &barrier->count; 27 25 28 26 // parallel initialisation using atomic instructions LL/SC … … 30 28 // no output 31 29 asm volatile ("_barrier_init_test: \n" 32 "ll $2, 0(%0) \n" /* read initial value */ 33 "bnez $2, _barrier_init_done \n" 34 "move $3, %2 \n" 35 "sc $3, 0(%0) \n" /* write initial value */ 36 "beqz $3, _barrier_init_test \n" 37 "move $3, %2 \n" 38 "sw $3, 0(%1) \n" /* write count */ 39 "_barrier_init_done: \n" 40 :: "r"(pinit), "r"(pcount), "r"(value) 41 : "$2", "$3"); 30 "ll $2, 0(%0) \n" /* read initial value */ 31 "bnez $2, _barrier_init_done \n" 32 "move $3, %2 \n" 33 "sc $3, 0(%0) \n" /* write initial value */ 34 "beqz $3, _barrier_init_test \n" 35 "move $3, %2 \n" 36 "sw $3, 0(%1) \n" /* write count */ 37 "_barrier_init_done: \n" 38 : 39 : "r"(pinit), "r"(pcount), "r"(value) 40 : "$2", "$3"); 42 41 } 42 43 43 44 /////////////////////////////////////////////////////////////////////////////////// 44 // 45 // barrier_wait() 45 46 // This blocking function uses LL/SC to decrement the barrier's counter. 46 47 // Then, it uses a busy_waiting mechanism if it is not the last. 47 48 // (because the GIET does not support dynamic task scheduling/descheduling) 48 49 /////////////////////////////////////////////////////////////////////////////////// 49 void barrier_wait( giet_barrier_t* barrier ) 50 { 51 unsigned int* pcount = (unsigned int*)&barrier->count; 50 void barrier_wait(giet_barrier_t * barrier) { 51 unsigned int * pcount = (unsigned int *) &barrier->count; 52 52 unsigned int maxcount = barrier->init; 53 53 unsigned int count; … … 57 57 // - output : counter value 58 58 asm volatile ("_barrier_decrement: \n" 59 60 61 62 63 64 65 59 "ll %0, 0(%1) \n" 60 "addi $3, %0, -1 \n" 61 "sc $3, 0(%1) \n" 62 "beqz $3, _barrier_decrement \n" 63 : "=&r"(count) 64 : "r"(pcount) 65 : "$2", "$3"); 66 66 67 67 // the last task re-initializes the barrier counter to the max value, 68 68 // waking up all other waiting tasks 69 69 70 if (count == 1) // last task71 {70 if (count == 1) { 71 // last task 72 72 *pcount = maxcount; 73 73 } 74 else // other tasks busy-wait75 {74 else { 75 // other tasks busy-wait 76 76 while (*pcount != maxcount) asm volatile ("nop"); 77 77 } 78 78 } 79 79 80 // Local Variables: 81 // tab-width: 4 82 // c-basic-offset: 4 83 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 84 // indent-tabs-mode: nil 85 // End: 86 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 87 -
soft/giet_vm/libs/barrier.h
r165 r228 14 14 15 15 typedef struct giet_barrier_s { 16 char name[32];// barrier name17 unsigned int init;// total number of participants18 unsigned int count;// number of not yet arrived tasks16 char name[32]; // barrier name 17 unsigned int init; // total number of participants 18 unsigned int count; // number of not yet arrived tasks 19 19 } giet_barrier_t; 20 20 … … 23 23 ////////////////////////////////////////////////////////////////////////////// 24 24 25 void barrier_init( giet_barrier_t* barrier, 26 unsigned int value ); 27 28 void barrier_wait( giet_barrier_t* barrier ); 25 void barrier_init(giet_barrier_t * barrier, unsigned int value); 26 void barrier_wait(giet_barrier_t * barrier); 29 27 30 28 #endif 31 29 30 // Local Variables: 31 // tab-width: 4 32 // c-basic-offset: 4 33 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 34 // indent-tabs-mode: nil 35 // End: 36 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 37 -
soft/giet_vm/libs/common.h
r178 r228 16 16 */ 17 17 ////////////////////////////////////////////////////////////////////////// 18 static inline void *memcpy(void *_dst, const void *_src, unsigned int size) 19 { 20 unsigned int *dst = _dst; 21 const unsigned int *src = _src; 18 static inline void * memcpy(void * _dst, const void * _src, unsigned int size) { 19 unsigned int * dst = _dst; 20 const unsigned int * src = _src; 22 21 23 22 /* if source and destination buffer are word-aligned, 24 23 * then copy word-by-word */ 25 if (!((unsigned int)dst & 3) && !((unsigned int)src & 3)) 24 if (!((unsigned int)dst & 3) && !((unsigned int)src & 3)) { 26 25 while (size > 3) { 27 26 *dst++ = *src++; 28 27 size -= 4; 29 28 } 29 } 30 30 31 unsigned char * cdst = (unsigned char*)dst;32 unsigned char * csrc = (unsigned char*)src;31 unsigned char * cdst = (unsigned char *) dst; 32 unsigned char * csrc = (unsigned char *) src; 33 33 34 34 /* byte-by-byte copy */ … … 39 39 } 40 40 41 41 42 ////////////////////////////////////////////////////////// 42 static inline void * memset(void * dst, int s, unsigned int count)43 { 44 char *a = (char *) dst; 45 while (count--) 46 *a++ = (char)s; 47 43 static inline void * memset(void * dst, int s, unsigned int count) { 44 char * a = (char *) dst; 45 while (count--) { 46 *a++ = (char) s; 47 } 48 return dst; 48 49 } 49 50 51 50 52 /** 51 52 53 */54 #define assert(expr) 55 do { 56 if ( ! (expr) ) { 53 the same as the C assert. 54 Taken from Mutekh(SRL API) 55 */ 56 #define assert(expr) \ 57 do { \ 58 if ( ! (expr) ) { \ 57 59 giet_tty_printf("assertion (%s) failed on %s:%d !\n", \ 58 #expr, __FILE__, __LINE__ );\59 __abort(); 60 } 60 #expr, __FILE__, __LINE__ ); \ 61 __abort(); \ 62 } \ 61 63 } while(0) 62 64 63 65 /** 64 @this aborts the current execution. 65 Taken from Mutekh(SRL API) 66 */ 67 static inline void __abort() 68 { 69 asm volatile ("break 0"); 70 while(1); 66 @this aborts the current execution. 67 Taken from Mutekh(SRL API) 68 */ 69 static inline void __abort() { 70 asm volatile ("break 0"); 71 while (1); 71 72 } 72 73 73 74 #endif /* _COMMON_H_ */ 75 76 77 // Local Variables: 78 // tab-width: 4 79 // c-basic-offset: 4 80 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 81 // indent-tabs-mode: nil 82 // End: 83 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 84 -
soft/giet_vm/libs/libsrl/srl_args.h
r215 r228 4 4 5 5 6 #define SRL_GET_MWMR(port) (srl_mwmr_t) APP_GET_ARG(port, VOBJ_TYPE_MWMR)7 #define SRL_GET_BARRIER(port) APP_GET_ARG(port, VOBJ_TYPE_BARRIER)8 #define SRL_GET_LOCK(port) APP_GET_ARG(port, VOBJ_TYPE_LOCK)9 //#define SRL_GET_MEMSPACE(port) APP_GET_ARG(port, VOBJ_TYPE_BUFFER) TODO 10 #define SRL_GET_MEMSPACE #error "SRL_GET_MEMSPACE is not implemented"//6 #define SRL_GET_MWMR(port) (srl_mwmr_t) APP_GET_ARG(port, VOBJ_TYPE_MWMR) 7 #define SRL_GET_BARRIER(port) (srl_barrier_t) APP_GET_ARG(port, VOBJ_TYPE_BARRIER) 8 #define SRL_GET_LOCK(port) APP_GET_ARG(port, VOBJ_TYPE_LOCK) 9 #define SRL_GET_CONST(port) APP_GET_ARG(port, VOBJ_TYPE_CONST) 10 #define SRL_GET_MEMSPACE(port) (srl_memspace_t) APP_GET_ARG(port, VOBJ_TYPE_MEMSPACE) 11 11 12 12 … … 14 14 ({ \ 15 15 unsigned int vbase; \ 16 if ( giet_vobj_get_vbase( APP_NAME , alias_##task_name.port, type, &vbase ) )\16 if (giet_vobj_get_vbase(APP_NAME , alias_##task_name.port, type, &vbase)) \ 17 17 { \ 18 srl_log_printf( NONE, "\n[ERROR] in "#task_name" task :\n");\19 srl_log_printf( NONE, " undefined port <"#port"> for channel(%s): %d\n",\20 alias_##task_name.port, vbase);\21 srl_log_printf( TRACE, "*** &"#port" = %x\n\n", vbase );\18 srl_log_printf(NONE, "\n[ERROR] in "#task_name" task :\n"); \ 19 srl_log_printf(NONE, " undefined port <"#port"> for channel \"%s\": %x\n", \ 20 alias_##task_name.port, vbase); \ 21 srl_log_printf(TRACE, "*** &"#port" = %x\n\n", vbase); \ 22 22 srl_exit(); \ 23 }else \ 24 srl_log_printf( TRACE, "%s:%d: arg of %s for %s,from %s; &"#port" = %x\n\n", \ 25 __FILE__, __LINE__, APP_NAME, #task_name,#port, vbase ); \ 26 vbase;\ 23 } \ 24 else \ 25 srl_log_printf(TRACE, "%s:%d: arg of %s for %s, from %s; &"#port" = %x\n\n", \ 26 __FILE__, __LINE__, APP_NAME, #task_name, #port, vbase); \ 27 vbase; \ 27 28 }) 28 29 -
soft/giet_vm/libs/libsrl/srl_barrier.h
r178 r228 23 23 24 24 25 typedef giet_barrier_t * srl_barrier_t;25 typedef giet_barrier_t * srl_barrier_t; 26 26 27 27 #define srl_barrier_wait(bar) barrier_wait(bar) 28 28 29 29 #endif 30 31 32 // Local Variables: 33 // tab-width: 4 34 // c-basic-offset: 4 35 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 36 // indent-tabs-mode: nil 37 // End: 38 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 39 -
soft/giet_vm/libs/libsrl/srl_endianness.h
r160 r228 5 5 6 6 /** @this reads a big endian 16 bits value */ 7 # define endian_le16(x) 7 # define endian_le16(x) (x) 8 8 /** @this reads a big endian 32 bits value */ 9 # define endian_le32(x) 9 # define endian_le32(x) (x) 10 10 /** @this reads a big endian 64 bits value */ 11 //# define endian_le64(x) 11 //# define endian_le64(x) (x) 12 12 /** @this reads a little endian 16 bits value */ 13 # define endian_be16(x) 13 # define endian_be16(x) endian_swap16(x) 14 14 /** @this reads a little endian 32 bits value */ 15 # define endian_be32(x) 15 # define endian_be32(x) endian_swap32(x) 16 16 /** @this reads a little endian 64 bits value */ 17 //# define endian_be64(x) 17 //# define endian_be64(x) endian_swap64(x) 18 18 19 19 /** @internal */ 20 static inline uint16_t endian_swap16(uint16_t x) 21 { 22 return (x >> 8) | (x << 8); 20 static inline uint16_t endian_swap16(uint16_t x) { 21 return (x >> 8) | (x << 8); 23 22 } 24 23 24 25 25 /** @internal */ 26 static inline uint32_t endian_swap32(uint32_t x) 27 { 28 return (((x >> 24) & 0x000000ff) | 29 ((x >> 8 ) & 0x0000ff00) | 30 ((x << 8 ) & 0x00ff0000) | 31 ((x << 24) & 0xff000000)); 26 static inline uint32_t endian_swap32(uint32_t x) { 27 return (((x >> 24) & 0x000000ff) | 28 ((x >> 8 ) & 0x0000ff00) | 29 ((x << 8 ) & 0x00ff0000) | 30 ((x << 24) & 0xff000000)); 32 31 } 33 32 33 34 34 /** @internal *//* 35 static inline uint64_t __endian_swap64(uint64_t x)36 {37 return (((uint64_t)endian_swap32(x ) << 32) |38 39 }*/35 static inline uint64_t __endian_swap64(uint64_t x) 36 { 37 return (((uint64_t)endian_swap32(x ) << 32) | 38 ((uint64_t)endian_swap32(x >> 32) )); 39 }*/ 40 40 41 static inline uint32_t srl_uint32_le_to_machine(uint32_t x) 42 { 43 return endian_le32(x); 41 static inline uint32_t srl_uint32_le_to_machine(uint32_t x) { 42 return endian_le32(x); 44 43 } 45 44 46 static inline uint32_t srl_uint32_machine_to_le(uint32_t x) 47 {48 45 46 static inline uint32_t srl_uint32_machine_to_le(uint32_t x) { 47 return endian_le32(x); 49 48 } 50 49 51 static inline uint32_t srl_uint32_be_to_machine(uint32_t x) 52 {53 50 51 static inline uint32_t srl_uint32_be_to_machine(uint32_t x) { 52 return endian_be32(x); 54 53 } 55 54 56 static inline uint32_t srl_uint32_machine_to_be(uint32_t x) 57 {58 55 56 static inline uint32_t srl_uint32_machine_to_be(uint32_t x) { 57 return endian_be32(x); 59 58 } 60 59 61 static inline uint16_t srl_uint16_le_to_machine(uint16_t x) 62 {63 60 61 static inline uint16_t srl_uint16_le_to_machine(uint16_t x) { 62 return endian_le16(x); 64 63 } 65 64 66 static inline uint16_t srl_uint16_machine_to_le(uint16_t x) 67 {68 65 66 static inline uint16_t srl_uint16_machine_to_le(uint16_t x) { 67 return endian_le16(x); 69 68 } 70 69 71 static inline uint16_t srl_uint16_be_to_machine(uint16_t x) 72 {73 70 71 static inline uint16_t srl_uint16_be_to_machine(uint16_t x) { 72 return endian_be16(x); 74 73 } 75 74 76 static inline uint16_t srl_uint16_machine_to_be(uint16_t x) 77 {78 75 76 static inline uint16_t srl_uint16_machine_to_be(uint16_t x) { 77 return endian_be16(x); 79 78 } 80 79 81 80 82 81 #endif 82 83 84 // Local Variables: 85 // tab-width: 4 86 // c-basic-offset: 4 87 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 88 // indent-tabs-mode: nil 89 // End: 90 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 91 -
soft/giet_vm/libs/libsrl/srl_hw_helpers.h
r178 r228 12 12 13 13 /** 14 15 */14 Standard API call, expands to nothing for this implementation. 15 */ 16 16 #define srl_busy_cycles(n) do{}while(0) 17 17 18 18 //void useless(void *pointless,...){} 19 19 /** 20 21 */20 @this flushes the cache line containing the address. 21 */ 22 22 //TODO 23 23 #define srl_dcache_flush_addr 0 24 24 25 25 /* 26 static inline cpu_dcache_invld(void *ptr){27 asm volatile ( 28 " cache %0, %1"29 : : "i" (0x11) , "R" (*(uint8_t*)(ptr))30 : "memory"31 );32 }33 */26 static inline cpu_dcache_invld(void *ptr){ 27 asm volatile ( 28 " cache %0, %1" 29 : : "i" (0x11) , "R" (*(uint8_t*)(ptr)) 30 : "memory" 31 ); 32 } 33 */ 34 34 35 35 /** 36 37 */36 @this flushes a memory zone from cache. 37 */ 38 38 //TODO 39 39 //void dcache_flush(const void * addr, size_t size) … … 41 41 42 42 /** 43 44 43 @this waits for at least the given time (in cycles). The actual 44 time spent in this call is not predictable. 45 45 46 47 */48 void srl_sleep_cycles( unsigned int time);46 @param time Number of cycles to wait for 47 */ 48 void srl_sleep_cycles(unsigned int time); 49 49 50 50 /** 51 52 51 @this returns the absolute timestamp counter from the 52 initialization of the platform. 53 53 54 @return Cycles from the initialization of the system 55 */ 56 static inline unsigned int srl_cycle_count() 57 { 58 return giet_proctime(); 54 @return Cycles from the initialization of the system 55 */ 56 static inline unsigned int srl_cycle_count() { 57 return giet_proctime(); 59 58 } 60 59 60 61 61 /** 62 @this aborts the current execution. On most systems, @this will 63 simply hang. 64 */ 65 static inline void srl_abort() 66 { 67 asm volatile ("break 0"); 68 while(1); 62 @this aborts the current execution. On most systems, @this will 63 simply hang. 64 */ 65 static inline void srl_abort() { 66 asm volatile ("break 0"); 67 while (1); 69 68 } 69 70 70 71 71 /** 72 72 * 73 73 */ 74 static inline void srl_exit() 75 { 74 static inline void srl_exit() { 76 75 giet_exit(); 77 76 } 78 77 79 78 #endif 79 80 // Local Variables: 81 // tab-width: 4 82 // c-basic-offset: 4 83 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 84 // indent-tabs-mode: nil 85 // End: 86 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 87 -
soft/giet_vm/libs/libsrl/srl_lock.h
r178 r228 23 23 #include "spin_lock.h" 24 24 25 typedef giet_lock_t * srl_lock_t;25 typedef giet_lock_t * srl_lock_t; 26 26 27 27 /** … … 49 49 50 50 #endif 51 52 53 // Local Variables: 54 // tab-width: 4 55 // c-basic-offset: 4 56 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 57 // indent-tabs-mode: nil 58 // End: 59 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 60 -
soft/giet_vm/libs/libsrl/srl_memspace.h
r178 r228 1 1 #ifndef SRL_MEMSPACE_H 2 2 #define SRL_MEMSPACE_H 3 4 #include "srl_public_types.h" 5 6 #include <memspace.h> 3 7 4 8 /** … … 12 16 The memspace abstract type. 13 17 */ 14 typedef void* srl_memspace_t; 18 19 20 typedef giet_memspace_t * srl_memspace_t; 15 21 16 22 /** … … 21 27 */ 22 28 #define SRL_MEMSPACE_SIZE(memsp) ((memsp)->size) 29 #define SRL_MEMSPACE_ADDR(memsp) ((memsp)->buffer) 30 23 31 24 32 #endif 33 34 // Local Variables: 35 // tab-width: 4 36 // c-basic-offset: 4 37 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 38 // indent-tabs-mode: nil 39 // End: 40 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 41 -
soft/giet_vm/libs/libsrl/srl_mwmr.h
r213 r228 4 4 #include "mwmr_channel.h" 5 5 6 typedef mwmr_channel_t * srl_mwmr_t;6 typedef mwmr_channel_t * srl_mwmr_t; 7 7 8 #define srl_mwmr_write(a, b, c) mwmr_write(a, (unsigned int *) b, (unsigned int)c)9 #define srl_mwmr_read(a, b, c) mwmr_read(a, (unsigned int *) b, (unsigned int)c)8 #define srl_mwmr_write(a, b, c) mwmr_write(a, (unsigned int *) b, (unsigned int) c) 9 #define srl_mwmr_read(a, b, c) mwmr_read(a, (unsigned int *) b, (unsigned int) c) 10 10 11 11 12 12 #endif //fin de SRL_MWMR_H_ 13 14 // Local Variables: 15 // tab-width: 4 16 // c-basic-offset: 4 17 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 18 // indent-tabs-mode: nil 19 // End: 20 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 21 -
soft/giet_vm/libs/libsrl/srl_private_types.c
r160 r228 1 1 2 #include "srl_private_types.h" 2 3 … … 6 7 // GCC requires this function. Taken from MutekH. 7 8 //////////////////////////////////////////////////////////////////////////////////////// 8 void *memcpy(void *_dst, const void *_src, unsigned int size) 9 { 10 unsigned int *dst = _dst; 11 const unsigned int *src = _src; 12 if ( ! ((unsigned int)dst & 3) && ! ((unsigned int)src & 3) ) 9 void * memcpy(void *_dst, const void * _src, unsigned int size) { 10 unsigned int * dst = _dst; 11 const unsigned int * src = _src; 12 if (!((unsigned int) dst & 3) && !((unsigned int) src & 3) ) 13 13 while (size > 3) { 14 14 *dst++ = *src++; … … 25 25 } 26 26 27 27 28 //////////////////////////////////////////////////////////////////////////////////////// 28 29 // mempcy() 29 30 // GCC requires this function. Taken from MutekH. 30 31 //////////////////////////////////////////////////////////////////////////////////////// 31 inline void * memset(void * dst, int s, size_t count)32 { 33 /* 34 int8_t s = _s;35 const reg_t v = (uint8_t)s * (reg_t)0x0101010101010101LL;36 int8_t *a =dst;37 reg_t *r; 32 inline void * memset(void * dst, int s, size_t count) { 33 char * a = (char *) dst; 34 while (count--){ 35 *a++ = (char)s; 36 } 37 return dst; 38 } 38 39 39 // align40 while ( ((uintptr_t *)a & reg_t_log2_m1) && count )41 count--, *a++ = s;42 40 43 size_t ucount = count & reg_t_log2_m1; 44 count &= ~reg_t_log2_m1; 41 // Local Variables: 42 // tab-width: 4 43 // c-basic-offset: 4 44 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 45 // indent-tabs-mode: nil 46 // End: 47 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 45 48 46 for (r = (reg_t*)a; count; count -= sizeof(reg_t))47 *r++ = v;48 49 for (a = (int8_t*)r; ucount; ucount--)50 *a++ = s;51 52 */53 char *a = (char *) dst;54 while (count--){55 *a++ = (char)s;56 }57 58 return dst;59 } -
soft/giet_vm/libs/libsrl/srl_sched_wait.c
r178 r228 28 28 #define DECLARE_WAIT(name, cmp) \ 29 29 \ 30 void srl_sched_wait_##name( void *addr, sint32_t val ) \ 31 { \ 32 srl_dcache_flush_addr(addr); \ 33 if ( ((sint32_t)*((unsigned int *)addr)) cmp val ) \ 34 return; \ 35 do { \ 36 srl_sched_wait_priv(100);?? \ 37 srl_dcache_flush_addr(addr); \ 38 } while (((sint32_t)*((unsigned int*)addr)) cmp val ); \ 39 } 30 void srl_sched_wait_##name(void * addr, sint32_t val) { \ 31 srl_dcache_flush_addr(addr); \ 32 if (((sint32_t) * ((unsigned int *) addr)) cmp val) \ 33 return; \ 34 do { \ 35 srl_sched_wait_priv(100);?? \ 36 srl_dcache_flush_addr(addr); \ 37 } while (((sint32_t) * ((unsigned int *) addr)) cmp val); \ 38 } 40 39 41 40 … … 53 52 DECLARE_WAIT(gt, >) 54 53 55 //TODO 56 void srl_sched_wait_priv(uint32_t date ) 57 { 58 do{ 59 context_switch(); 60 }while (srl_cycle_count() > date); 54 //TODO 55 void srl_sched_wait_priv(uint32_t date) { 56 do { 57 context_switch(); 58 } while (srl_cycle_count() > date); 61 59 } 62 60 63 void srl_sleep_cycles( uint32_t n ) 64 { 65 uint32_t next_run_to = srl_cycle_count()+n; 61 void srl_sleep_cycles(uint32_t n) { 62 uint32_t next_run_to = srl_cycle_count() + n; 66 63 67 while(srl_cycle_count() < next_run_to) 68 srl_sched_wait_priv(next_run_to); 64 while (srl_cycle_count() < next_run_to) { 65 srl_sched_wait_priv(next_run_to); 66 } 69 67 } 70 68 69 70 // Local Variables: 71 // tab-width: 4 72 // c-basic-offset: 4 73 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 74 // indent-tabs-mode: nil 75 // End: 76 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 77 -
soft/giet_vm/libs/libsrl/srl_sched_wait.h
r160 r228 35 35 36 36 37 void srl_sleep_cycles( unsigned int n);37 void srl_sleep_cycles(unsigned int n); 38 38 39 39 #endif 40 41 42 // Local Variables: 43 // tab-width: 4 44 // c-basic-offset: 4 45 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 46 // indent-tabs-mode: nil 47 // End: 48 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 49 -
soft/giet_vm/libs/mwmr_channel.c
r207 r228 19 19 // can be used to get the virtual base address of the channel from it's name. 20 20 // 21 // An MWMR transaction transfer 21 // An MWMR transaction transfer an integer number of items, and an item is 22 22 // an integer number of unsigned int (32 bits words). 23 23 // The max number of words that can be stored in a MWMR channel is defined by the … … 39 39 // If the lock is already taken a fixed delay is introduced before retry. 40 40 ////////////////////////////////////////////////////////////////////////////// 41 void mwmr_lock_acquire(unsigned int* lock_address) 42 { 43 register unsigned int* plock = lock_address; 44 register unsigned int delay = 100; 41 void mwmr_lock_acquire(unsigned int * lock_address) { 42 register unsigned int * plock = lock_address; 43 register unsigned int delay = 100; 45 44 asm volatile ( 46 "mwmr_lock_try: 47 "ll $2, 0(%0) 48 "bnez $2, mwmr_lock_delay 49 "li $3, 1 50 "sc $3, 0(%0) 51 "bnez $3, mwmr_lock_ok 52 "mwmr_lock_delay: 45 "mwmr_lock_try: \n" 46 "ll $2, 0(%0) \n" /* $2 <= lock current value */ 47 "bnez $2, mwmr_lock_delay \n" /* retry after delay if lock busy */ 48 "li $3, 1 \n" /* $3 <= argument for sc */ 49 "sc $3, 0(%0) \n" /* try to get lock */ 50 "bnez $3, mwmr_lock_ok \n" /* exit if atomic */ 51 "mwmr_lock_delay: \n" 53 52 "move $4, %1 \n" /* $4 <= delay */ 54 53 "mwmr_lock_loop: \n" 55 "beqz $4, mwmr_lock_loop 56 "addi $4, $4, -1 57 "j mwmr_lock_try 58 "nop 59 "mwmr_lock_ok: 54 "beqz $4, mwmr_lock_loop \n" /* test end delay */ 55 "addi $4, $4, -1 \n" /* $4 <= $4 - 1 */ 56 "j mwmr_lock_try \n" /* retry ll */ 57 "nop \n" 58 "mwmr_lock_ok: \n" 60 59 : 61 60 :"r"(plock), "r"(delay) 62 61 :"$2", "$3", "$4"); 63 62 } 64 ////////////////////////////////////////////////////////////////////////////// 65 // nb_mwmr_write() 63 64 65 ////////////////////////////////////////////////////////////////////////////// 66 // nb_mwmr_write() 66 67 // This is a non-blocking function. 67 68 // The nitems parameter is the number of items to be transfered. … … 72 73 // the number of read items (it can be 0). 73 74 ////////////////////////////////////////////////////////////////////////////// 74 unsigned int nb_mwmr_write( mwmr_channel_t* mwmr, 75 unsigned int* buffer, 76 unsigned int nitems ) 77 { 78 unsigned int x; 79 unsigned int spaces; // number of empty slots (in words) 80 unsigned int nwords; // requested transfer length (in words) 81 unsigned int depth; // channel depth (in words) 82 unsigned int width; // channel width (in words) 83 unsigned int sts; // channel sts 84 unsigned int ptw; // channel ptw 85 86 if(nitems == 0) return 0; 75 unsigned int nb_mwmr_write(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems) { 76 unsigned int x; 77 unsigned int spaces; // number of empty slots (in words) 78 unsigned int nwords; // requested transfer length (in words) 79 unsigned int depth; // channel depth (in words) 80 unsigned int width; // channel width (in words) 81 unsigned int sts; // channel sts 82 unsigned int ptw; // channel ptw 83 84 if (nitems == 0) { 85 return 0; 86 } 87 87 88 88 // get the lock 89 mwmr_lock_acquire( &mwmr->lock);89 mwmr_lock_acquire(&mwmr->lock); 90 90 91 91 // access fifo status 92 depth 93 width 94 sts 95 ptw 92 depth = mwmr->depth; 93 width = mwmr->width; 94 sts = mwmr->sts; 95 ptw = mwmr->ptw; 96 96 spaces = depth - sts; 97 97 nwords = width * nitems; 98 98 99 if( spaces >= nwords ) // transfer nitems, release lock and return 100 { 101 for ( x = 0 ; x < nwords ; x++ ) 102 { 99 if (spaces >= nwords) { // transfer nitems, release lock and return 100 for (x = 0; x < nwords; x++) { 103 101 mwmr->data[ptw] = buffer[x]; 104 if ( (ptw + 1) == depth ) ptw = 0; 105 else ptw = ptw + 1; 106 } 107 mwmr->sts = mwmr->sts + nwords; 108 mwmr->ptw = ptw; 102 if ((ptw + 1) == depth) { 103 ptw = 0; 104 } 105 else { 106 ptw = ptw + 1; 107 } 108 } 109 mwmr->sts = mwmr->sts + nwords; 110 mwmr->ptw = ptw; 109 111 mwmr->lock = 0; 110 112 return nitems; 111 113 } 112 113 else if ( spaces < width ) // release lock and return 114 { 114 else if (spaces < width) { 115 // release lock and return 115 116 mwmr->lock = 0; 116 117 return 0; 117 118 } 118 else // transfer as many items as possible, release lock and return 119 { 120 nwords = (spaces/width) * width; // integer number of items 121 for ( x = 0 ; x < nwords ; x++ ) 122 { 119 else { 120 // transfer as many items as possible, release lock and return 121 nwords = (spaces / width) * width; // integer number of items 122 for (x = 0; x < nwords; x++) { 123 123 mwmr->data[ptw] = buffer[x]; 124 if ( (ptw + 1) == depth ) ptw = 0; 125 else ptw = ptw + 1; 126 } 127 mwmr->sts = sts + nwords; 128 mwmr->ptw = ptw; 129 mwmr->lock = 0; 130 return (nwords/width); 124 if ((ptw + 1) == depth) { 125 ptw = 0; 126 } 127 else { 128 ptw = ptw + 1; 129 } 130 } 131 mwmr->sts = sts + nwords; 132 mwmr->ptw = ptw; 133 mwmr->lock = 0; 134 return (nwords / width); 131 135 } 132 136 } // end nb_mwmr_write() 133 137 134 ////////////////////////////////////////////////////////////////////////////// 135 // mwmr_write() 138 139 ////////////////////////////////////////////////////////////////////////////// 140 // mwmr_write() 136 141 // This blocking function returns only when the transfer is completed. 137 142 // The nitems parameter is the number of items to be transfered. … … 142 147 // after a random delay. 143 148 ////////////////////////////////////////////////////////////////////////////// 144 void mwmr_write( mwmr_channel_t* mwmr, 145 unsigned int* buffer, 146 unsigned int nitems ) 147 { 148 unsigned int x; 149 unsigned int spaces; // number of empty slots (in words) 150 unsigned int nwords; // requested transfer length (in words) 151 unsigned int depth; // channel depth (in words) 152 unsigned int width; // channel width (in words) 153 unsigned int sts; // channel sts 154 unsigned int ptw; // channel ptw 155 156 if(nitems == 0) return; 157 158 while(1) 159 { 149 void mwmr_write(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems) { 150 unsigned int x; 151 unsigned int spaces; // number of empty slots (in words) 152 unsigned int nwords; // requested transfer length (in words) 153 unsigned int depth; // channel depth (in words) 154 unsigned int width; // channel width (in words) 155 unsigned int sts; // channel sts 156 unsigned int ptw; // channel ptw 157 158 if (nitems == 0) { 159 return; 160 } 161 162 while (1) { 160 163 // get the lock 161 164 mwmr_lock_acquire(&mwmr->lock); 162 165 163 166 // compute spaces and nwords 164 depth 165 width 166 sts 167 ptw 167 depth = mwmr->depth; 168 width = mwmr->width; 169 sts = mwmr->sts; 170 ptw = mwmr->ptw; 168 171 spaces = depth - sts; 169 172 nwords = width * nitems; 170 173 171 if( spaces >= nwords ) // write nwords, release lock and return 172 { 173 for ( x = 0 ; x < nwords ; x++ ) 174 { 174 if (spaces >= nwords) { 175 // write nwords, release lock and return 176 for (x = 0; x < nwords; x++) { 175 177 mwmr->data[ptw] = buffer[x]; 176 if ( (ptw + 1) == depth ) ptw = 0; 177 else ptw = ptw + 1; 178 } 179 mwmr->ptw = ptw; 180 mwmr->sts = sts + nwords; 178 if ((ptw + 1) == depth) { 179 ptw = 0; 180 } 181 else { 182 ptw = ptw + 1; 183 } 184 } 185 mwmr->ptw = ptw; 186 mwmr->sts = sts + nwords; 181 187 mwmr->lock = 0; 182 188 return; 183 189 } 184 else if ( spaces < width ) // release lock and retry after delay 185 { 186 mwmr->lock = 0; 187 for ( x = giet_rand()>>8 ; x > 0 ; x-- ) asm volatile ( "nop" ); 188 } 189 else // write as many items as possible, release lock and retry after delay 190 { 191 nwords = (spaces/width) * width; // integer number of items 192 for ( x = 0 ; x < nwords ; x++ ) 193 { 190 else if (spaces < width) { 191 // release lock and retry after delay 192 mwmr->lock = 0; 193 } 194 else { 195 // write as many items as possible, release lock and retry after delay 196 nwords = (spaces / width) * width; // integer number of items 197 for (x = 0; x < nwords; x++) { 194 198 mwmr->data[ptw] = buffer[x]; 195 if ( (ptw + 1) == depth ) ptw = 0; 196 else ptw = ptw + 1; 197 } 198 mwmr->sts = sts + nwords; 199 mwmr->ptw = ptw; 200 buffer = buffer + nwords; 201 nitems = nitems - (nwords/width); 202 mwmr->lock = 0; 203 } 204 // random delay before retry 205 for ( x = giet_rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" ); 199 if ((ptw + 1) == depth) { 200 ptw = 0; 201 } 202 else { 203 ptw = ptw + 1; 204 } 205 } 206 mwmr->sts = sts + nwords; 207 mwmr->ptw = ptw; 208 buffer = buffer + nwords; 209 nitems = nitems - (nwords/width); 210 mwmr->lock = 0; 211 } 212 giet_context_switch(); 206 213 } 207 214 } // end mwmr_write() 208 215 209 ////////////////////////////////////////////////////////////////////////////// 210 // nb_mwmr_read() 216 217 ////////////////////////////////////////////////////////////////////////////// 218 // nb_mwmr_read() 211 219 // This is a non-blocking function. 212 220 // The nitems parameter is the number of items to be transfered. … … 217 225 // the number of read items (it can be 0). 218 226 ////////////////////////////////////////////////////////////////////////////// 219 unsigned int nb_mwmr_read( mwmr_channel_t* mwmr, 220 unsigned int* buffer, 221 unsigned int nitems ) 222 { 223 unsigned int x; 224 unsigned int nwords; // requested transfer length (in words) 225 unsigned int depth; // channel depth (in words) 226 unsigned int width; // channel width (in words) 227 unsigned int sts; // channel sts 228 unsigned int ptr; // channel ptr 229 230 if(nitems == 0) return 0; 227 unsigned int nb_mwmr_read(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems) { 228 unsigned int x; 229 unsigned int nwords; // requested transfer length (in words) 230 unsigned int depth; // channel depth (in words) 231 unsigned int width; // channel width (in words) 232 unsigned int sts; // channel sts 233 unsigned int ptr; // channel ptr 234 235 if (nitems == 0) { 236 return 0; 237 } 231 238 232 239 // get the lock 233 mwmr_lock_acquire( &mwmr->lock);240 mwmr_lock_acquire(&mwmr->lock); 234 241 235 242 // access fifo status 236 depth 237 width 238 sts 239 ptr 243 depth = mwmr->depth; 244 width = mwmr->width; 245 sts = mwmr->sts; 246 ptr = mwmr->ptr; 240 247 nwords = width * nitems; 241 248 242 if( sts >= nwords ) // transfer nitems, release lock and return 243 { 244 for ( x = 0 ; x < nwords ; x++ ) 245 { 249 if (sts >= nwords) { 250 // transfer nitems, release lock and return 251 for (x = 0; x < nwords; x++) { 246 252 buffer[x] = mwmr->data[ptr]; 247 if ( (ptr + 1) == depth ) ptr = 0; 248 else ptr = ptr + 1; 249 } 250 mwmr->sts = mwmr->sts - nwords; 251 mwmr->ptr = ptr; 253 if ((ptr + 1) == depth) { 254 ptr = 0; 255 } 256 else { 257 ptr = ptr + 1; 258 } 259 } 260 mwmr->sts = mwmr->sts - nwords; 261 mwmr->ptr = ptr; 252 262 mwmr->lock = 0; 253 263 return nitems; 254 264 } 255 256 else if ( sts < width ) // release lock and return 257 { 265 else if (sts < width) { 266 // release lock and return 258 267 mwmr->lock = 0; 259 268 return 0; 260 269 } 261 else // transfer as many items as possible, release lock and return 262 { 263 nwords = (sts/width) * width; // integer number of items 264 for ( x = 0 ; x < nwords ; x++ ) 265 { 270 else { 271 // transfer as many items as possible, release lock and return 272 nwords = (sts / width) * width; // integer number of items 273 for (x = 0 ; x < nwords ; x++) { 266 274 buffer[x] = mwmr->data[ptr]; 267 if ( (ptr + 1) == depth ) ptr = 0; 268 else ptr = ptr + 1; 269 } 270 mwmr->sts = sts - nwords; 271 mwmr->ptr = ptr; 272 mwmr->lock = 0; 273 return (nwords/width); 274 } 275 } // nb_mwmr_read() 276 277 ////////////////////////////////////////////////////////////////////////////// 278 // mwmr_read() 275 if ((ptr + 1) == depth) { 276 ptr = 0; 277 } 278 else { 279 ptr = ptr + 1; 280 } 281 } 282 mwmr->sts = sts - nwords; 283 mwmr->ptr = ptr; 284 mwmr->lock = 0; 285 return (nwords / width); 286 } 287 } // nb_mwmr_read() 288 289 290 ////////////////////////////////////////////////////////////////////////////// 291 // mwmr_read() 279 292 // This blocking function returns only when the transfer is completed. 280 293 // The nitems parameter is the number of items to be transfered. … … 285 298 // after a random delay. 286 299 ////////////////////////////////////////////////////////////////////////////// 287 void mwmr_read( mwmr_channel_t* mwmr, 288 unsigned int* buffer, 289 unsigned int nitems ) 290 { 291 unsigned int x; 292 unsigned int nwords; // requested transfer length (in words) 293 unsigned int depth; // channel depth (in words) 294 unsigned int width; // channel width (in words) 295 unsigned int sts; // channel sts 296 unsigned int ptr; // channel ptr 297 298 if(nitems == 0) return; 299 300 while(1) 301 { 300 void mwmr_read( mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems) { 301 unsigned int x; 302 unsigned int nwords; // requested transfer length (in words) 303 unsigned int depth; // channel depth (in words) 304 unsigned int width; // channel width (in words) 305 unsigned int sts; // channel sts 306 unsigned int ptr; // channel ptr 307 308 if (nitems == 0) { 309 return; 310 } 311 312 while (1) { 302 313 // get the lock 303 mwmr_lock_acquire( &mwmr->lock);314 mwmr_lock_acquire(&mwmr->lock); 304 315 305 316 // compute nwords 306 depth 307 width 308 sts 309 ptr 317 depth = mwmr->depth; 318 width = mwmr->width; 319 sts = mwmr->sts; 320 ptr = mwmr->ptr; 310 321 nwords = width * nitems; 311 322 312 if( sts >= nwords ) // read nwords, release lock and return 313 { 314 for ( x = 0 ; x < nwords ; x++ ) 315 { 323 if (sts >= nwords) { 324 // read nwords, release lock and return 325 for (x = 0; x < nwords; x++) { 316 326 buffer[x] = mwmr->data[ptr]; 317 if ( (ptr + 1) == depth ) ptr = 0; 318 else ptr = ptr + 1; 319 } 320 mwmr->sts = mwmr->sts - nwords; 321 mwmr->ptr = ptr; 327 if ((ptr + 1) == depth) { 328 ptr = 0; 329 } 330 else { 331 ptr = ptr + 1; 332 } 333 } 334 mwmr->sts = mwmr->sts - nwords; 335 mwmr->ptr = ptr; 322 336 mwmr->lock = 0; 323 337 return; 324 338 } 325 else if ( sts < width ) // release lock and retry after delay 326 { 327 mwmr->lock = 0; 328 for ( x = giet_rand()>>8 ; x > 0 ; x-- ) asm volatile ( "nop" ); 329 } 330 else // read as many items as possible, release lock and retry after delay 331 { 332 nwords = (sts/width) * width; // integer number of items 333 for ( x = 0 ; x < nwords ; x++ ) 334 { 339 else if (sts < width) { 340 // release lock and retry after delay 341 mwmr->lock = 0; 342 } 343 else { // read as many items as possible, release lock and retry after delay 344 nwords = (sts / width) * width; // integer number of items 345 for (x = 0; x < nwords; x++) { 335 346 buffer[x] = mwmr->data[ptr]; 336 if ( (ptr + 1) == depth ) ptr = 0; 337 else ptr = ptr + 1; 338 } 339 mwmr->sts = sts - nwords; 340 mwmr->ptr = ptr; 341 buffer = buffer + nwords; 342 nitems = nitems - (nwords/width); 343 mwmr->lock = 0; 344 } 345 // random delay before retry 346 for ( x = giet_rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" ); 347 if ((ptr + 1) == depth) { 348 ptr = 0; 349 } 350 else { 351 ptr = ptr + 1; 352 } 353 } 354 mwmr->sts = sts - nwords; 355 mwmr->ptr = ptr; 356 buffer = buffer + nwords; 357 nitems = nitems - (nwords/width); 358 mwmr->lock = 0; 359 } 360 giet_context_switch(); 347 361 } 348 362 } // end mwmr_read() 349 363 350 364 365 // Local Variables: 366 // tab-width: 4 367 // c-basic-offset: 4 368 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 369 // indent-tabs-mode: nil 370 // End: 371 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 372 -
soft/giet_vm/libs/mwmr_channel.h
r200 r228 16 16 17 17 typedef struct mwmr_channel_s { 18 unsigned int ptr;// index of the first valid data word19 unsigned int ptw;// index of the first empty slot20 unsigned int sts;// number of words available21 unsigned int lock;// exclusive access lock22 unsigned int depth;// max number of words in the channel23 unsigned int width; // number of words in an item24 unsigned int data[1018];// circular buffer18 unsigned int ptr; // index of the first valid data word 19 unsigned int ptw; // index of the first empty slot 20 unsigned int sts; // number of words available 21 unsigned int lock; // exclusive access lock 22 unsigned int depth; // max number of words in the channel 23 unsigned int width; // number of words in an item 24 unsigned int data[1018]; // circular buffer 25 25 } mwmr_channel_t; 26 26 … … 29 29 ////////////////////////////////////////////////////////////////////////////// 30 30 31 void mwmr_write( mwmr_channel_t* mwmr, 32 unsigned int* buffer, 33 unsigned int nitems ); 31 void mwmr_write(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems); 32 void mwmr_read(mwmr_channel_t * mwmr, unsigned int * buffer, unsigned int nitems); 34 33 35 void mwmr_read( mwmr_channel_t* mwmr,36 unsigned int* buffer,37 unsigned int nitems );38 34 #endif 39 35 36 // Local Variables: 37 // tab-width: 4 38 // c-basic-offset: 4 39 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 40 // indent-tabs-mode: nil 41 // End: 42 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 43 -
soft/giet_vm/libs/spin_lock.c
r189 r228 28 28 // If the lock is already taken a random delay is introduced before retry. 29 29 /////////////////////////////////////////////////////////////////////////////////// 30 void lock_acquire( giet_lock_t* lock ) 31 { 32 unsigned int* plock = &lock->value; 33 30 void lock_acquire(giet_lock_t * lock) { 31 unsigned int * plock = &lock->value; 32 34 33 asm volatile ( 35 "giet_lock_try: 36 "ll $2, 0(%0) 37 "bnez $2, giet_lock_delay 38 "li $3, 1 39 "sc $3, 0(%0) 40 "bnez $3, giet_lock_ok 34 "giet_lock_try: \n" 35 "ll $2, 0(%0) \n" /* $2 <= lock current value */ 36 "bnez $2, giet_lock_delay \n" /* retry if lock already taken */ 37 "li $3, 1 \n" /* $3 <= argument for sc */ 38 "sc $3, 0(%0) \n" /* try to get lock */ 39 "bnez $3, giet_lock_ok \n" /* exit if atomic */ 41 40 42 "giet_lock_delay: 43 "jal giet_rand 44 "nop 45 "andi $4, $2, 0xFF \n"/* $4 <= delay < 256 cycles */41 "giet_lock_delay: \n" 42 "jal giet_rand \n" /* giet_rand() system call */ 43 "nop \n" 44 "andi $4, $2, 0xFF \n" /* $4 <= delay < 256 cycles */ 46 45 47 "giet_lock_loop: 48 "addi $4, $4, -1 49 "beqz $4, giet_lock_loop 50 "nop 51 "j giet_lock_try 52 "nop 53 "giet_lock_ok: 46 "giet_lock_loop: \n" 47 "addi $4, $4, -1 \n" /* $4 <= $4 - 1 */ 48 "beqz $4, giet_lock_loop \n" /* test end delay */ 49 "nop \n" 50 "j giet_lock_try \n" /* retry */ 51 "nop \n" 52 "giet_lock_ok: \n" 54 53 : 55 54 :"r"(plock) 56 55 :"$2", "$3", "$4"); 57 } 56 } 57 58 58 59 59 ////////////////////////////////////////////////////////////////////////////// 60 60 // lock_release() 61 61 ////////////////////////////////////////////////////////////////////////////// 62 void lock_release( giet_lock_t* lock) 63 { 62 void lock_release(giet_lock_t * lock) { 64 63 lock->value = 0; 65 64 } 66 65 66 67 // Local Variables: 68 // tab-width: 4 69 // c-basic-offset: 4 70 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 71 // indent-tabs-mode: nil 72 // End: 73 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 74 -
soft/giet_vm/libs/spin_lock.h
r189 r228 15 15 16 16 typedef struct giet_lock_s { 17 char name[32];// lock name18 unsigned int value;// taken if value != 017 char name[32]; // lock name 18 unsigned int value; // taken if value != 0 19 19 } giet_lock_t; 20 20 … … 23 23 ////////////////////////////////////////////////////////////////////////////// 24 24 25 void lock_acquire( giet_lock_t* lock ); 26 27 void lock_release( giet_lock_t* lock ); 25 void lock_acquire(giet_lock_t * lock); 26 void lock_release(giet_lock_t * lock); 28 27 29 28 #endif 30 29 30 // Local Variables: 31 // tab-width: 4 32 // c-basic-offset: 4 33 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 34 // indent-tabs-mode: nil 35 // End: 36 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 37 -
soft/giet_vm/libs/srl.h
r200 r228 13 13 14 14 #include "libsrl/srl_public_types.h" 15 //#include "libsrl/srl_private_types.h"16 17 15 #include "libsrl/srl_lock.h" 18 16 #include "libsrl/srl_mwmr.h" … … 20 18 #include "libsrl/srl_barrier.h" 21 19 #include "libsrl/srl_memspace.h" 22 23 20 #include "libsrl/srl_hw_helpers.h" 24 25 21 #include "libsrl/srl_args.h" 26 27 //kernel use!28 //#include "libsrl/srl_mwmr_sys.h"29 22 30 23 -
soft/giet_vm/libs/stdio.c
r218 r228 21 21 #define SYSCALL_GCD_WRITE 0x06 22 22 #define SYSCALL_GCD_READ 0x07 23 #define SYSCALL_TASK_ID 0x09 23 24 #define SYSCALL_CTX_SWITCH 0x0D 24 25 #define SYSCALL_EXIT 0x0E … … 32 33 #define SYSCALL_IOC_READ 0x16 33 34 #define SYSCALL_IOC_COMPLETED 0x17 34 #define SYSCALL_VOBJ_GET_VBASE 35 #define SYSCALL_VOBJ_GET_VBASE 0x1A 35 36 #define SYSCALL_NIC_WRITE 0x1B 36 37 #define SYSCALL_NIC_READ 0x1C … … 43 44 // and tells GCC what has been modified by system call execution. 44 45 ////////////////////////////////////////////////////////////////////////////////// 45 static inline unsigned int sys_call( unsigned int call_no, 46 unsigned int arg_0, 47 unsigned int arg_1, 48 unsigned int arg_2, 49 unsigned int arg_3) 50 { 46 static inline unsigned int sys_call(unsigned int call_no, 47 unsigned int arg_0, 48 unsigned int arg_1, 49 unsigned int arg_2, 50 unsigned int arg_3) { 51 51 register unsigned int reg_no_and_output asm("v0") = call_no; 52 register unsigned int reg_a0 53 register unsigned int reg_a1 54 register unsigned int reg_a2 55 register unsigned int reg_a3 52 register unsigned int reg_a0 asm("a0") = arg_0; 53 register unsigned int reg_a1 asm("a1") = arg_1; 54 register unsigned int reg_a2 asm("a2") = arg_2; 55 register unsigned int reg_a3 asm("a3") = arg_3; 56 56 57 57 asm volatile( … … 59 59 : "=r" (reg_no_and_output) /* output argument */ 60 60 : "r" (reg_a0), /* input arguments */ 61 62 63 64 61 "r" (reg_a1), 62 "r" (reg_a2), 63 "r" (reg_a3), 64 "r" (reg_no_and_output) 65 65 : "memory", 66 66 /* These persistant registers will be saved on the stack by the … … 83 83 } 84 84 85 ///// 85 ///// MIPS32 related system calls ///// 86 86 87 87 //////////////////////////////////////////////////////////////////////////////////// … … 90 90 // This function returns the processor identifier. 91 91 //////////////////////////////////////////////////////////////////////////////////// 92 unsigned int giet_procid() 93 { 94 return sys_call(SYSCALL_PROCID, 95 0, 0, 0, 0); 96 } 92 unsigned int giet_procid() { 93 return sys_call(SYSCALL_PROCID, 0, 0, 0, 0); 94 } 95 96 97 97 //////////////////////////////////////////////////////////////////////////////////// 98 98 // giet_proctime() … … 100 100 // This function returns the local processor time (clock cycles since boot) 101 101 //////////////////////////////////////////////////////////////////////////////////// 102 unsigned int giet_proctime() 103 { 104 return sys_call(SYSCALL_PROCTIME, 105 0, 0, 0, 0); 106 } 107 108 ////// TTY device related system calls ///// 102 unsigned int giet_proctime() { 103 return sys_call(SYSCALL_PROCTIME, 0, 0, 0, 0); 104 } 105 106 107 ////// TTY device related system calls ///// 109 108 110 109 //////////////////////////////////////////////////////////////////////////////////// … … 116 115 // - Returns 1 if the character has been written, 0 otherwise. 117 116 //////////////////////////////////////////////////////////////////////////////////// 118 unsigned int giet_tty_putc(char byte) 119 { 120 return sys_call(SYSCALL_TTY_WRITE, 121 (unsigned int)(&byte), 122 1, 123 0,0); 124 } 117 unsigned int giet_tty_putc(char byte) { 118 return sys_call(SYSCALL_TTY_WRITE, (unsigned int) (&byte), 1, 0, 0); 119 } 120 121 125 122 //////////////////////////////////////////////////////////////////////////////////// 126 123 // giet_tty_puts() … … 132 129 // - Returns the number of written characters. 133 130 //////////////////////////////////////////////////////////////////////////////////// 134 unsigned int giet_tty_puts(char *buf) 135 { 131 unsigned int giet_tty_puts(char * buf) { 136 132 unsigned int length = 0; 137 while (buf[length] != 0) 138 { 133 while (buf[length] != 0) { 139 134 length++; 140 135 } 141 return sys_call(SYSCALL_TTY_WRITE, 142 (unsigned int)buf, 143 length, 144 0,0); 145 } 136 return sys_call(SYSCALL_TTY_WRITE, (unsigned int) buf, length, 0, 0); 137 } 138 139 146 140 //////////////////////////////////////////////////////////////////////////////////// 147 141 // giet_tty_putw() … … 152 146 // Returns the number of written characters (should be equal to ten). 153 147 //////////////////////////////////////////////////////////////////////////////////// 154 unsigned int giet_tty_putw(unsigned int val) 155 { 148 unsigned int giet_tty_putw(unsigned int val) { 156 149 char buf[10]; 157 150 unsigned int i; 158 for (i = 0; i < 10; i++) 159 { 160 buf[9-i] = (val % 10) + 0x30; 151 for (i = 0; i < 10; i++) { 152 buf[9 - i] = (val % 10) + 0x30; 161 153 val = val / 10; 162 154 } 163 return sys_call(SYSCALL_TTY_WRITE, 164 (unsigned int)buf, 165 10, 166 0,0); 167 } 155 return sys_call(SYSCALL_TTY_WRITE, (unsigned int) buf, 10, 0, 0); 156 } 157 158 168 159 //////////////////////////////////////////////////////////////////////////////////// 169 160 // giet_tty_getc() … … 174 165 // - Returns 0 when completed. 175 166 //////////////////////////////////////////////////////////////////////////////////// 176 unsigned int giet_tty_getc(char *byte) 177 { 167 unsigned int giet_tty_getc(char * byte) { 178 168 unsigned int ret = 0; 179 while (ret == 0) 180 { 181 ret = sys_call(SYSCALL_TTY_READ, 182 (unsigned int)byte, 183 1, 184 0,0); 169 while (ret == 0) { 170 ret = sys_call(SYSCALL_TTY_READ, (unsigned int)byte, 1, 0, 0); 185 171 } 186 172 return 0; 187 173 } 174 175 188 176 //////////////////////////////////////////////////////////////////////////////////// 189 177 // giet_tty_gets() … … 201 189 // removed from the target buffer. 202 190 //////////////////////////////////////////////////////////////////////////////////// 203 unsigned int giet_tty_gets( char* buf, 204 unsigned int bufsize ) 205 { 191 unsigned int giet_tty_gets(char * buf, unsigned int bufsize) { 206 192 unsigned int ret; 207 193 unsigned char byte; 208 194 unsigned int index = 0; 209 195 210 while (index < (bufsize - 1)) 211 { 196 while (index < (bufsize - 1)) { 212 197 do { 213 ret = sys_call(SYSCALL_TTY_READ, 214 (unsigned int)(&byte), 215 1, 216 0,0); 198 ret = sys_call(SYSCALL_TTY_READ, (unsigned int) (&byte), 1, 0, 0); 217 199 } while (ret != 1); 218 200 219 if ( byte == 0x0A )201 if (byte == 0x0A) { 220 202 break; /* LF */ 221 else if ((byte == 0x7F) && (index > 0)) 203 } 204 else if ((byte == 0x7F) && (index > 0)) { 222 205 index--; /* DEL */ 223 else224 {206 } 207 else { 225 208 buf[index] = byte; 226 209 index++; … … 230 213 return 0; 231 214 } 215 216 232 217 //////////////////////////////////////////////////////////////////////////////////// 233 218 // giet_tty_getw() … … 248 233 // bits range, the zero value is returned. 249 234 //////////////////////////////////////////////////////////////////////////////////// 250 unsigned int giet_tty_getw(unsigned int *val) 251 { 235 unsigned int giet_tty_getw(unsigned int * val) { 252 236 unsigned char buf[32]; 253 237 unsigned char byte; … … 260 244 unsigned int ret; 261 245 262 while (done == 0) 263 { 246 while (done == 0) { 264 247 do { 265 ret = sys_call(SYSCALL_TTY_READ, 266 (unsigned int)(&byte), 267 1, 268 0,0); 248 ret = sys_call(SYSCALL_TTY_READ, (unsigned int) (&byte), 1, 0, 0); 269 249 } while (ret != 1); 270 250 271 if ((byte > 0x2F) && (byte < 0x3A)) /* decimal character */272 {251 if ((byte > 0x2F) && (byte < 0x3A)) { 252 /* decimal character */ 273 253 buf[max] = byte; 274 254 max++; 275 255 giet_tty_putc(byte); 276 256 } 277 else if ((byte == 0x0A) || (byte == 0x0D)) /* LF or CR character */278 {257 else if ((byte == 0x0A) || (byte == 0x0D)) { 258 /* LF or CR character */ 279 259 done = 1; 280 260 } 281 else if (byte == 0x7F) /* DEL character */ 282 { 283 if (max > 0) 284 { 261 else if (byte == 0x7F) { 262 /* DEL character */ 263 if (max > 0) { 285 264 max--; /* cancel the character */ 286 265 giet_tty_putc(0x08); … … 289 268 } 290 269 } 291 if (max == 32) /* decimal string overflow */292 {293 for (i = 0; i < max; i++) /* cancel the string */294 {270 if (max == 32) { 271 /* decimal string overflow */ 272 for (i = 0; i < max; i++) { 273 /* cancel the string */ 295 274 giet_tty_putc(0x08); 296 275 giet_tty_putc(0x20); … … 304 283 305 284 /* string conversion */ 306 for (i = 0; i < max; i++) 307 { 285 for (i = 0; i < max; i++) { 308 286 dec = dec * 10 + (buf[i] - 0x30); 309 if (dec < save) 287 if (dec < save) { 310 288 overflow = 1; 289 } 311 290 save = dec; 312 291 } 313 292 314 293 /* check overflow */ 315 if (overflow == 0) 316 { 294 if (overflow == 0) { 317 295 *val = dec; /* return decimal value */ 318 296 } 319 else 320 { 321 for (i = 0; i < max; i++) /* cancel the string */ 322 { 297 else { 298 for (i = 0; i < max; i++) { 299 /* cancel the string */ 323 300 giet_tty_putc(0x08); 324 301 giet_tty_putc(0x20); … … 330 307 return 0; 331 308 } 309 310 332 311 //////////////////////////////////////////////////////////////////////////////////// 333 312 // giet_tty_printf() … … 344 323 // - Returns 0 if success, > 0 if error. 345 324 //////////////////////////////////////////////////////////////////////////////////// 346 unsigned int giet_tty_printf(char *format, ...) 347 { 325 unsigned int giet_tty_printf(char * format, ...) { 348 326 va_list ap; 349 327 va_start(ap, format); … … 354 332 while (*format) { 355 333 unsigned int i; 356 for (i = 0; format[i] && format[i] != '%'; i++) 357 ; 334 for (i = 0; format[i] && format[i] != '%'; i++); 358 335 if (i) { 359 ret = sys_call(SYSCALL_TTY_WRITE, 360 (unsigned int)format, 361 i, 362 0,0); 363 if (ret != i) 336 ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int) format, i, 0, 0); 337 if (ret != i) { 364 338 return 1; /* return error */ 339 } 365 340 format += i; 366 341 } … … 377 352 378 353 { 379 int 380 char 381 char *pbuf;382 unsigned int 383 static const char 384 unsigned int 354 int val = va_arg(ap, long); 355 char buf[20]; 356 char * pbuf; 357 unsigned int len = 0; 358 static const char HexaTab[] = "0123456789ABCDEF"; 359 unsigned int i; 385 360 386 361 switch (*format++) { … … 393 368 if (val < 0) { 394 369 val = -val; 395 ret = sys_call(SYSCALL_TTY_WRITE, 396 (unsigned int)"-", 397 1, 398 0,0); 399 if (ret != 1) 370 ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int)"-", 1, 0, 0); 371 if (ret != 1) { 400 372 return 1; /* return error */ 373 } 401 374 } 402 375 case ('u'): /* decimal unsigned integer */ 403 for( i=0 ; i<10 ; i++) { 404 buf[9-i] = HexaTab[val % 10]; 405 if (!(val /= 10)) break; 376 for(i = 0; i < 10; i++) { 377 buf[9 - i] = HexaTab[val % 10]; 378 if (!(val /= 10)) { 379 break; 380 } 406 381 } 407 len = i +1;408 pbuf = &buf[9 -i];382 len = i + 1; 383 pbuf = &buf[9 - i]; 409 384 break; 410 385 case ('x'): /* hexadecimal integer */ 411 ret = sys_call(SYSCALL_TTY_WRITE, 412 (unsigned int)"0x", 413 2, 414 0,0); 415 if (ret != 2) 386 ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int) "0x", 2, 0, 0); 387 if (ret != 2) { 416 388 return 1; /* return error */ 417 for( i=0 ; i<8 ; i++) {418 buf[7-i] = HexaTab[val % 16U];419 if (!(val /= 16U)) break;420 389 } 421 len = i+1; 422 pbuf = &buf[7-i]; 390 for(i = 0; i < 8; i++) { 391 buf[7 - i] = HexaTab[val % 16U]; 392 if (!(val /= 16U)) { 393 break; 394 } 395 } 396 len = i + 1; 397 pbuf = &buf[7 - i]; 423 398 break; 424 399 case ('s'): /* string */ 425 400 { 426 char *str = (char*)val; 427 while ( str[len] ) len++; 428 pbuf = (char*)val; 401 char * str = (char *) val; 402 while (str[len]) { 403 len++; 404 } 405 pbuf = (char *) val; 429 406 } 430 407 break; … … 433 410 } 434 411 435 ret = sys_call(SYSCALL_TTY_WRITE, 436 (unsigned int)pbuf, 437 len, 438 0,0); 439 if (ret != len) 412 ret = sys_call(SYSCALL_TTY_WRITE, (unsigned int) pbuf, len, 0, 0); 413 if (ret != len) { 440 414 return 1; 415 } 441 416 goto printf_text; 442 417 } … … 453 428 // - Returns 0 if success, > 0 if error. 454 429 ////////////////////////////////////////////////////////////////////////////////// 455 unsigned int giet_timer_start() 456 { 457 return sys_call(SYSCALL_TIMER_START, 458 0,0,0,0); 459 } 430 unsigned int giet_timer_start() { 431 return sys_call(SYSCALL_TIMER_START, 0, 0, 0, 0); 432 } 433 434 460 435 ////////////////////////////////////////////////////////////////////////////////// 461 436 // giet_timer_stop() … … 464 439 // - Returns 0 if success, > 0 if error. 465 440 ////////////////////////////////////////////////////////////////////////////////// 466 unsigned int giet_timer_stop() 467 { 468 return sys_call(SYSCALL_TIMER_STOP, 469 0,0,0,0); 470 } 441 unsigned int giet_timer_stop() { 442 return sys_call(SYSCALL_TIMER_STOP, 0, 0, 0, 0); 443 } 444 471 445 472 446 ///// GCD (Greatest Common Divider) related system calls … … 483 457 // - Returns 0 if success, > 0 if error. 484 458 ////////////////////////////////////////////////////////////////////////////////// 485 unsigned int giet_gcd_set_opa(unsigned int val) 486 { 487 return sys_call(SYSCALL_GCD_WRITE, 488 GCD_OPA, 489 val, 490 0, 0); 491 } 492 ////////////////////////////////////////////////////////////////////////////////// 493 // giet_gcd_set_opb() 459 unsigned int giet_gcd_set_opa(unsigned int val) { 460 return sys_call(SYSCALL_GCD_WRITE, GCD_OPA, val, 0, 0); 461 } 462 463 464 ////////////////////////////////////////////////////////////////////////////////// 465 // giet_gcd_set_opb() 494 466 ////////////////////////////////////////////////////////////////////////////////// 495 467 // This function sets operand B in the GCD coprocessor. 496 468 // - Returns 0 if success, > 0 if error. 497 469 ////////////////////////////////////////////////////////////////////////////////// 498 unsigned int giet_gcd_set_opb(unsigned int val) 499 { 500 return sys_call(SYSCALL_GCD_WRITE, 501 GCD_OPB, 502 val, 503 0, 0); 504 } 505 ////////////////////////////////////////////////////////////////////////////////// 506 // giet_gcd_start() 470 unsigned int giet_gcd_set_opb(unsigned int val) { 471 return sys_call(SYSCALL_GCD_WRITE, GCD_OPB, val, 0, 0); 472 } 473 474 475 ////////////////////////////////////////////////////////////////////////////////// 476 // giet_gcd_start() 507 477 ////////////////////////////////////////////////////////////////////////////////// 508 478 // This function starts the computation in the GCD coprocessor. 509 479 // - Returns 0 if success, > 0 if error. 510 480 ////////////////////////////////////////////////////////////////////////////////// 511 unsigned int giet_gcd_start() 512 { 513 return sys_call(SYSCALL_GCD_WRITE, 514 GCD_START, 515 0, 0, 0); 516 } 517 ////////////////////////////////////////////////////////////////////////////////// 518 // giet_gcd_get_status() 481 unsigned int giet_gcd_start() { 482 return sys_call(SYSCALL_GCD_WRITE, GCD_START, 0, 0, 0); 483 } 484 485 486 ////////////////////////////////////////////////////////////////////////////////// 487 // giet_gcd_get_status() 519 488 ////////////////////////////////////////////////////////////////////////////////// 520 489 // This function gets the status fromn the GCD coprocessor. 521 490 // - The value is 0 when the coprocessor is idle (computation completed). 522 491 ////////////////////////////////////////////////////////////////////////////////// 523 unsigned int giet_gcd_get_status(unsigned int *val) 524 { 525 return sys_call(SYSCALL_GCD_READ, 526 GCD_STATUS, 527 (unsigned int)val, 528 0, 0); 529 } 530 ////////////////////////////////////////////////////////////////////////////////// 531 // giet_gcd_get_result() 492 unsigned int giet_gcd_get_status(unsigned int * val) { 493 return sys_call(SYSCALL_GCD_READ, GCD_STATUS, (unsigned int) val, 0, 0); 494 } 495 496 497 ////////////////////////////////////////////////////////////////////////////////// 498 // giet_gcd_get_result() 532 499 ////////////////////////////////////////////////////////////////////////////////// 533 500 // This function gets the result of the computation from the GCD coprocessor. 534 501 ////////////////////////////////////////////////////////////////////////////////// 535 unsigned int giet_gcd_get_result(unsigned int *val) 536 { 537 return sys_call(SYSCALL_GCD_READ, 538 GCD_OPA, 539 (unsigned int)val, 540 0, 0); 541 } 502 unsigned int giet_gcd_get_result(unsigned int * val) { 503 return sys_call(SYSCALL_GCD_READ, GCD_OPA, (unsigned int) val, 0, 0); 504 } 505 542 506 543 507 ///// Block device related system calls ///// 544 508 545 509 ////////////////////////////////////////////////////////////////////////////////// 546 // 510 // giet_ioc_write() 547 511 ////////////////////////////////////////////////////////////////////////////////// 548 512 // Transfer data from a memory buffer to a file on the block_device. … … 552 516 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 553 517 ////////////////////////////////////////////////////////////////////////////////// 554 unsigned int giet_ioc_write( unsigned int lba, 555 void* buffer, 556 unsigned int count) 557 { 558 return sys_call(SYSCALL_IOC_WRITE, 559 lba, 560 (unsigned int)buffer, 561 count, 562 0); 563 } 518 unsigned int giet_ioc_write( unsigned int lba, void * buffer, unsigned int count) { 519 return sys_call(SYSCALL_IOC_WRITE, lba, (unsigned int) buffer, count, 0); 520 } 521 522 564 523 ////////////////////////////////////////////////////////////////////////////////// 565 524 // giet_ioc_read() … … 571 530 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 572 531 ////////////////////////////////////////////////////////////////////////////////// 573 unsigned int giet_ioc_read( unsigned int lba, 574 void* buffer, 575 unsigned int count ) 576 { 577 return sys_call(SYSCALL_IOC_READ, 578 lba, 579 (unsigned int)buffer, 580 count, 581 0); 582 } 532 unsigned int giet_ioc_read(unsigned int lba, void * buffer, unsigned int count) { 533 return sys_call(SYSCALL_IOC_READ, lba, (unsigned int) buffer, count, 0); 534 } 535 536 583 537 ////////////////////////////////////////////////////////////////////////////////// 584 538 // giet_ioc_completed() … … 587 541 // successfully completed, and returns 1 if an address error has been detected. 588 542 ////////////////////////////////////////////////////////////////////////////////// 589 unsigned int giet_ioc_completed() 590 { 591 return sys_call(SYSCALL_IOC_COMPLETED, 592 0, 0, 0, 0); 593 } 543 unsigned int giet_ioc_completed() { 544 return sys_call(SYSCALL_IOC_COMPLETED, 0, 0, 0, 0); 545 } 546 594 547 595 548 ///// Frame buffer device related system calls ///// … … 605 558 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 606 559 ////////////////////////////////////////////////////////////////////////////////// 607 unsigned int giet_fb_sync_write( unsigned int offset, 608 void* buffer, 609 unsigned int length ) 610 { 611 return sys_call(SYSCALL_FB_SYNC_WRITE, 612 offset, 613 (unsigned int)buffer, 614 length, 615 0); 616 } 560 unsigned int giet_fb_sync_write(unsigned int offset, void * buffer, unsigned int length) { 561 return sys_call(SYSCALL_FB_SYNC_WRITE, offset, (unsigned int) buffer, length, 0); 562 } 563 564 617 565 ////////////////////////////////////////////////////////////////////////////////// 618 566 // giet_fb_sync_read() … … 625 573 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 626 574 ////////////////////////////////////////////////////////////////////////////////// 627 unsigned int giet_fb_sync_read( unsigned int offset, 628 void* buffer, 629 unsigned int length ) 630 { 631 return sys_call(SYSCALL_FB_SYNC_READ, 632 offset, 633 (unsigned int)buffer, 634 length, 635 0); 636 } 575 unsigned int giet_fb_sync_read(unsigned int offset, void * buffer, unsigned int length) { 576 return sys_call(SYSCALL_FB_SYNC_READ, offset, (unsigned int) buffer, length, 0); 577 } 578 579 637 580 ////////////////////////////////////////////////////////////////////////////////// 638 581 // giet_fb_write() … … 647 590 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 648 591 ////////////////////////////////////////////////////////////////////////////////// 649 unsigned int giet_fb_write( unsigned int offset, 650 void* buffer, 651 unsigned int length ) 652 { 653 return sys_call(SYSCALL_FB_WRITE, 654 offset, 655 (unsigned int)buffer, 656 length, 657 0); 658 } 592 unsigned int giet_fb_write(unsigned int offset, void * buffer, unsigned int length) { 593 return sys_call(SYSCALL_FB_WRITE, offset, (unsigned int) buffer, length, 0); 594 } 595 596 659 597 ////////////////////////////////////////////////////////////////////////////////// 660 598 // giet_fb_read() … … 669 607 // - Returns 0 if success, > 0 if error (e.g. memory buffer not in user space). 670 608 ////////////////////////////////////////////////////////////////////////////////// 671 unsigned int giet_fb_read( unsigned int offset, 672 void* buffer, 673 unsigned int length ) 674 { 675 return sys_call(SYSCALL_FB_READ, 676 offset, 677 (unsigned int)buffer, 678 length, 679 0); 680 } 609 unsigned int giet_fb_read(unsigned int offset, void * buffer, unsigned int length) { 610 return sys_call(SYSCALL_FB_READ, offset, (unsigned int) buffer, length, 0); 611 } 612 613 681 614 ////////////////////////////////////////////////////////////////////////////////// 682 615 // giet_fb_completed() … … 685 618 // - Returns 0 if success, > 0 if error. 686 619 ////////////////////////////////////////////////////////////////////////////////// 687 unsigned int giet_fb_completed() 688 { 689 return sys_call(SYSCALL_FB_COMPLETED, 690 0, 0, 0, 0); 691 } 620 unsigned int giet_fb_completed() { 621 return sys_call(SYSCALL_FB_COMPLETED, 0, 0, 0, 0); 622 } 623 692 624 693 625 ////////////////////////////////////////////////////////////////////////////////// … … 704 636 ////////////////////////////////////////////////////////////////////////////////// 705 637 706 unsigned int giet_nic_write( unsigned int offset, 707 void* buffer, 708 unsigned int length ) 709 { 710 return sys_call(SYSCALL_NIC_WRITE, 711 offset, 712 (unsigned int)buffer, 713 length, 714 0); 715 } 638 unsigned int giet_nic_write(unsigned int offset, void * buffer, unsigned int length) { 639 return sys_call(SYSCALL_NIC_WRITE, offset, (unsigned int) buffer, length, 0); 640 } 641 716 642 717 643 ////////////////////////////////////////////////////////////////////////////////// … … 728 654 ////////////////////////////////////////////////////////////////////////////////// 729 655 730 unsigned int giet_nic_read( unsigned int offset, 731 void* buffer, 732 unsigned int length ) 733 { 734 return sys_call(SYSCALL_NIC_READ, 735 offset, 736 (unsigned int)buffer, 737 length, 738 0); 739 } 656 unsigned int giet_nic_read(unsigned int offset, void * buffer, unsigned int length) { 657 return sys_call(SYSCALL_NIC_READ, offset, (unsigned int) buffer, length, 0); 658 } 659 740 660 741 661 ////////////////////////////////////////////////////////////////////////////////// … … 745 665 // - Returns 0 if success, > 0 if error. 746 666 ////////////////////////////////////////////////////////////////////////////////// 747 unsigned int giet_nic_completed() 748 { 749 return sys_call(SYSCALL_NIC_COMPLETED, 750 0, 0, 0, 0); 751 } 667 unsigned int giet_nic_completed() { 668 return sys_call(SYSCALL_NIC_COMPLETED, 0, 0, 0, 0); 669 } 670 752 671 753 672 ///// Miscellaneous related system calls ///// … … 762 681 // - Returns the address if success, 0 if error ( not defined or wrong type ) 763 682 ////////////////////////////////////////////////////////////////////////////////// 764 unsigned int giet_vobj_get_vbase( char* vspace_name, 765 char* vobj_name, 766 unsigned int vobj_type, 767 unsigned int* vobj_vaddr ) 768 { 683 unsigned int giet_vobj_get_vbase(char * vspace_name, char * vobj_name, unsigned int vobj_type, unsigned int * vobj_vaddr) { 769 684 return sys_call(SYSCALL_VOBJ_GET_VBASE, 770 (unsigned int)vspace_name, 771 (unsigned int)vobj_name, 772 (unsigned int)vobj_type, 773 (unsigned int)vobj_vaddr); 774 } 685 (unsigned int) vspace_name, 686 (unsigned int) vobj_name, 687 (unsigned int) vobj_type, 688 (unsigned int) vobj_vaddr); 689 } 690 775 691 776 692 //////////////////////////////////////////////////////////////////////////////////// … … 781 697 // - Returns 0 if success, > 0 if error ( cluster index too large ) 782 698 //////////////////////////////////////////////////////////////////////////////////// 783 unsigned int giet_proc_number( unsigned int cluster_id, 784 unsigned int* buffer ) 785 { 786 return sys_call(SYSCALL_PROC_NUMBER, 787 cluster_id, 788 (unsigned int)buffer, 789 0, 0); 790 } 699 unsigned int giet_proc_number(unsigned int cluster_id, unsigned int * buffer) { 700 return sys_call(SYSCALL_PROC_NUMBER, cluster_id, (unsigned int) buffer, 0, 0); 701 } 702 791 703 792 704 ///// Miscellaneous system calls ///// … … 799 711 // The task is blocked, but it still consume processor cycles ... 800 712 ////////////////////////////////////////////////////////////////////////////////// 801 void giet_exit() 802 { 803 sys_call(SYSCALL_EXIT, 804 0, 0, 0, 0); 805 } 713 void giet_exit() { 714 sys_call(SYSCALL_EXIT, 0, 0, 0, 0); 715 } 716 717 806 718 /////////////////////////////////////////////////////////////////////////////////// 807 719 // giet_rand() … … 809 721 // count. This value is comprised between 0 & 65535. 810 722 /////////////////////////////////////////////////////////////////////////////////// 811 unsigned int giet_rand() 812 { 813 unsigned int x = sys_call(SYSCALL_PROCTIME, 814 0, 0, 0, 0); 815 if((x & 0xF) > 7) 723 unsigned int giet_rand() { 724 unsigned int x = sys_call(SYSCALL_PROCTIME, 0, 0, 0, 0); 725 if ((x & 0xF) > 7) { 816 726 return (x*x & 0xFFFF); 817 else 727 } 728 else { 818 729 return (x*x*x & 0xFFFF); 819 } 820 ////////////////////////////////////////////////////////////////////////////////// 821 // giet_ctx_switch() 730 } 731 } 732 733 734 ////////////////////////////////////////////////////////////////////////////////// 735 // giet_context_switch() 822 736 // The user task calling this function is descheduled and 823 737 // the processor is allocated to another task. 824 738 ////////////////////////////////////////////////////////////////////////////////// 825 unsigned int giet_ctx_switch() 826 { 827 return sys_call(SYSCALL_CTX_SWITCH, 828 0, 0, 0, 0); 829 } 830 831 739 unsigned int giet_context_switch() { 740 return sys_call(SYSCALL_CTX_SWITCH, 0, 0, 0, 0); 741 } 742 743 ////////////////////////////////////////////////////////////////////////////////// 744 // giet_get_task_id() 745 // The user task calling this function is descheduled and 746 // the processor is allocated to another task. 747 ////////////////////////////////////////////////////////////////////////////////// 748 unsigned int giet_task_id() { 749 return sys_call(SYSCALL_TASK_ID, 0, 0, 0, 0); 750 } 751 752 753 // Local Variables: 754 // tab-width: 4 755 // c-basic-offset: 4 756 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 757 // indent-tabs-mode: nil 758 // End: 759 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 760 -
soft/giet_vm/libs/stdio.h
r218 r228 15 15 /* TTY device related functions */ 16 16 unsigned int giet_tty_putc(char byte); 17 unsigned int giet_tty_puts(char * buf);17 unsigned int giet_tty_puts(char * buf); 18 18 unsigned int giet_tty_putw(unsigned int val); 19 unsigned int giet_tty_getc_no_irq(char * byte);20 unsigned int giet_tty_getc(char * byte);21 unsigned int giet_tty_gets(char * buf, unsigned int bufsize);22 unsigned int giet_tty_getw(unsigned int * val);23 unsigned int giet_tty_printf(char * format,...);19 unsigned int giet_tty_getc_no_irq(char * byte); 20 unsigned int giet_tty_getc(char * byte); 21 unsigned int giet_tty_gets(char * buf, unsigned int bufsize); 22 unsigned int giet_tty_getw(unsigned int * val); 23 unsigned int giet_tty_printf(char * format,...); 24 24 25 25 /* GCD coprocessor related functions */ … … 27 27 unsigned int giet_gcd_set_opb(unsigned int val); 28 28 unsigned int giet_gcd_start(); 29 unsigned int giet_gcd_get_result(unsigned int * val);30 unsigned int giet_gcd_get_status(unsigned int * val);29 unsigned int giet_gcd_get_result(unsigned int * val); 30 unsigned int giet_gcd_get_status(unsigned int * val); 31 31 32 32 /* Block device related functions */ 33 unsigned int giet_ioc_read( unsigned int lba, 34 void* buffer, 35 unsigned int count); 36 unsigned int giet_ioc_write(unsigned int lba, 37 void* buffer, 38 unsigned int count); 33 unsigned int giet_ioc_read(unsigned int lba, void * buffer, unsigned int count); 34 unsigned int giet_ioc_write(unsigned int lba, void * buffer, unsigned int count); 39 35 unsigned int giet_ioc_completed(); 40 36 41 37 /* Frame buffer device related functions */ 42 unsigned int giet_fb_sync_read( unsigned int offset, 43 void* buffer, 44 unsigned int length ); 45 unsigned int giet_fb_sync_write(unsigned int offset, 46 void* buffer, 47 unsigned int length ); 48 unsigned int giet_fb_read( unsigned int offset, 49 void* buffer, 50 unsigned int length ); 51 unsigned int giet_fb_write( unsigned int offset, 52 void* buffer, 53 unsigned int length ); 54 unsigned int giet_nic_write( unsigned int offset, 55 void* buffer, 56 unsigned int length ); 57 unsigned int giet_nic_read( unsigned int offset, 58 void* buffer, 59 unsigned int length ); 38 unsigned int giet_fb_sync_read(unsigned int offset, void * buffer, unsigned int length ); 39 unsigned int giet_fb_sync_write(unsigned int offset, void * buffer, unsigned int length); 40 unsigned int giet_fb_read(unsigned int offset, void * buffer, unsigned int length); 41 unsigned int giet_fb_write(unsigned int offset, void * buffer, unsigned int length); 42 unsigned int giet_nic_write(unsigned int offset, void * buffer, unsigned int length); 43 unsigned int giet_nic_read(unsigned int offset, void * buffer, unsigned int length); 60 44 unsigned int giet_fb_completed(); 61 45 unsigned int giet_nic_completed(); 62 46 63 47 /* Misc */ 64 unsigned int giet_vobj_get_vbase( char* vspace_name, 65 char* vobj_name, 66 unsigned int vobj_type, 67 unsigned int* vobj_vaddr ); 68 void giet_exit(); 48 unsigned int giet_vobj_get_vbase(char * vspace_name, char * vobj_name, unsigned int vobj_type, unsigned int * vobj_vaddr); 49 void giet_exit(); 69 50 unsigned int giet_rand(); 70 unsigned int giet_ctx_switch(); 51 unsigned int giet_context_switch(); 52 unsigned int giet_task_id(); 71 53 unsigned int giet_procnumber(); 72 54 73 55 #endif 74 56 57 // Local Variables: 58 // tab-width: 4 59 // c-basic-offset: 4 60 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 61 // indent-tabs-mode: nil 62 // End: 63 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 64 -
soft/giet_vm/libs/utils.c
r201 r228 4 4 // GCC requires this function. Taken from MutekH. 5 5 //////////////////////////////////////////////////////////////////////////////////////// 6 void *memcpy(void *_dst, const void *_src, unsigned int size) 7 { 8 unsigned int *dst = _dst; 9 const unsigned int *src = _src; 10 if ( ! ((unsigned int)dst & 3) && ! ((unsigned int)src & 3) ) 6 void * memcpy(void *_dst, const void * _src, unsigned int size) { 7 unsigned int * dst = _dst; 8 const unsigned int * src = _src; 9 if (!((unsigned int) dst & 3) && ! ((unsigned int) src & 3) ) { 11 10 while (size > 3) { 12 11 *dst++ = *src++; 13 12 size -= 4; 14 13 } 14 } 15 15 16 unsigned char * cdst = (unsigned char*)dst;17 unsigned char * csrc = (unsigned char*)src;16 unsigned char * cdst = (unsigned char *) dst; 17 unsigned char * csrc = (unsigned char *) src; 18 18 19 19 while (size--) { … … 23 23 } 24 24 25 25 26 //////////////////////////////////////////////////////////////////////////////////////// 26 27 // memset() 27 28 // GCC requires this function. Taken from MutekH. 28 29 //////////////////////////////////////////////////////////////////////////////////////// 29 void * memset(void * dst, int s, unsigned int count)30 { 31 char *a = (char *) dst; 32 while (count--) 33 *a++ = (char)s; 34 30 void * memset(void * dst, int s, unsigned int count) { 31 char * a = (char *) dst; 32 while (count--) { 33 *a++ = (char) s; 34 } 35 return dst; 35 36 } 37 38 39 // Local Variables: 40 // tab-width: 4 41 // c-basic-offset: 4 42 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 43 // indent-tabs-mode: nil 44 // End: 45 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 46 -
soft/giet_vm/libs/utils.h
r201 r228 9 9 #define _UTILS_H 10 10 11 void* memcpy( void* dst, 12 void* src, 13 unsigned int size ); 11 void * memcpy(void * dst, void * src, unsigned int size); 12 void * memset(void * dst, int s, unsigned int count); 14 13 15 void * memset( void *dst,16 int s,17 unsigned int count);18 14 #endif 19 15 16 // Local Variables: 17 // tab-width: 4 18 // c-basic-offset: 4 19 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 20 // indent-tabs-mode: nil 21 // End: 22 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 23 -
soft/giet_vm/sys/common.c
r221 r228 17 17 18 18 /////////////////////////////////////////////////////////////////////////////////// 19 // 19 // Global variables 20 20 /////////////////////////////////////////////////////////////////////////////////// 21 21 … … 23 23 24 24 // SR save (used by _it_mask() / it_restore() 25 unsigned int 26 27 /////////////////////////////////////////////////////////////////////////////////// 28 // 25 unsigned int _status_register_save; 26 27 /////////////////////////////////////////////////////////////////////////////////// 28 // _get_sched() 29 29 // Access CP0 and returns scheduler physical address. 30 30 /////////////////////////////////////////////////////////////////////////////////// 31 inline unsigned int _get_sched() 32 { 33 unsigned int ret; 34 asm volatile ( "mfc0 %0, $22" 35 : "=r"(ret) ); 36 return ret; 37 } 38 /////////////////////////////////////////////////////////////////////////////////// 39 // _get_ptpr() 31 inline unsigned int _get_sched() { 32 unsigned int ret; 33 asm volatile( 34 "mfc0 %0, $22" 35 : "=r"(ret)); 36 return ret; 37 } 38 39 40 /////////////////////////////////////////////////////////////////////////////////// 41 // _get_ptpr() 40 42 // Access CP2 and returns PTPR register. 41 43 /////////////////////////////////////////////////////////////////////////////////// 42 inline unsigned int _get_ptpr() 43 { 44 unsigned int ret; 45 asm volatile ( "mfc2 %0, $0" 46 : "=r"(ret) ); 47 return ret; 48 } 49 /////////////////////////////////////////////////////////////////////////////////// 50 // _get_epc() 44 inline unsigned int _get_ptpr() { 45 unsigned int ret; 46 asm volatile( 47 "mfc2 %0, $0" 48 : "=r"(ret)); 49 return ret; 50 } 51 52 53 /////////////////////////////////////////////////////////////////////////////////// 54 // _get_epc() 51 55 // Access CP0 and returns EPC register. 52 56 /////////////////////////////////////////////////////////////////////////////////// 53 inline unsigned int _get_epc() 54 { 55 unsigned int ret; 56 asm volatile ( "mfc0 %0, $14" 57 : "=r"(ret) ); 58 return ret; 59 } 60 /////////////////////////////////////////////////////////////////////////////////// 61 // _get_bar() 57 inline unsigned int _get_epc() { 58 unsigned int ret; 59 asm volatile("mfc0 %0, $14" 60 : "=r"(ret)); 61 return ret; 62 } 63 64 65 /////////////////////////////////////////////////////////////////////////////////// 66 // _get_bar() 62 67 // Access CP0 and returns BAR register. 63 68 /////////////////////////////////////////////////////////////////////////////////// 64 inline unsigned int _get_bvar() 65 { 66 unsigned int ret; 67 asm volatile ( "mfc0 %0, $8" 68 : "=r"(ret) ); 69 return ret; 70 } 71 /////////////////////////////////////////////////////////////////////////////////// 72 // _get_cr() 69 inline unsigned int _get_bvar() { 70 unsigned int ret; 71 asm volatile( 72 "mfc0 %0, $8" 73 : "=r"(ret)); 74 return ret; 75 } 76 77 78 /////////////////////////////////////////////////////////////////////////////////// 79 // _get_cr() 73 80 // Access CP0 and returns CR register. 74 81 /////////////////////////////////////////////////////////////////////////////////// 75 inline unsigned int _get_cause() 76 { 77 unsigned int ret; 78 asm volatile ( "mfc0 %0, $13" 79 : "=r"(ret) ); 80 return ret; 81 } 82 /////////////////////////////////////////////////////////////////////////////////// 83 // _get_sr() 82 inline unsigned int _get_cause() { 83 unsigned int ret; 84 asm volatile("mfc0 %0, $13" 85 : "=r"(ret)); 86 return ret; 87 } 88 89 90 /////////////////////////////////////////////////////////////////////////////////// 91 // _get_sr() 84 92 // Access CP0 and returns SR register. 85 93 /////////////////////////////////////////////////////////////////////////////////// 86 inline unsigned int _get_sr() 87 { 88 unsigned int ret; 89 asm volatile ( "mfc0 %0, $12" 90 : "=r"(ret) ); 91 return ret; 92 } 94 inline unsigned int _get_sr() { 95 unsigned int ret; 96 asm volatile( 97 "mfc0 %0, $12" 98 : "=r"(ret)); 99 return ret; 100 } 101 93 102 /////////////////////////////////////////////////////////////////////////////////// 94 103 // _it_mask() 95 104 // Access CP0 and mask IRQs 96 105 /////////////////////////////////////////////////////////////////////////////////// 97 inline void _it_mask() 98 { 99 unsigned int sr_value; 100 asm volatile( "li $3, 0xFFFFFFFE \n" 101 "mfc0 %0, $12 \n" 102 "and $3, $3, %0 \n" 103 "mtc0 $3, $12 \n" 104 : "=r"(sr_value) : : "$3" ); 106 inline void _it_mask() { 107 unsigned int sr_value; 108 asm volatile( 109 "li $3, 0xFFFFFFFE \n" 110 "mfc0 %0, $12 \n" 111 "and $3, $3, %0 \n" 112 "mtc0 $3, $12 \n" 113 : "=r"(sr_value) 114 : 115 : "$3"); 105 116 _status_register_save = sr_value; 106 117 } 107 /////////////////////////////////////////////////////////////////////////////////// 108 // _it_enable() 118 119 120 /////////////////////////////////////////////////////////////////////////////////// 121 // _it_restore() 109 122 // Access CP0 and enable IRQs 110 123 /////////////////////////////////////////////////////////////////////////////////// 111 inline void _it_restore() 112 { 113 unsigned int sr_value = _status_register_save; 114 asm volatile( "mtc0 %0, $12 \n" 115 : : "r"(sr_value) ); 116 } 124 inline void _it_restore() { 125 unsigned int sr_value = _status_register_save; 126 asm volatile( 127 "mtc0 %0, $12 \n" 128 : 129 : "r"(sr_value)); 130 } 131 132 117 133 //////////////////////////////////////////////////////////////////////////// 118 134 // _get_lock() … … 121 137 // (delay average value = 100 cycles) 122 138 //////////////////////////////////////////////////////////////////////////// 123 inline void _get_lock( unsigned int* plock ) 124 { 125 register unsigned int delay = ( _proctime() ^ _procid()<<4 ) & 0xFF; 139 inline void _get_lock(unsigned int * plock) { 140 register unsigned int delay = ( _proctime() ^ _procid() << 4) & 0xFF; 126 141 127 142 asm volatile ( … … 144 159 } 145 160 161 146 162 //////////////////////////////////////////////////////////////////////////// 147 163 // _release_lock() 148 164 //////////////////////////////////////////////////////////////////////////// 149 inline void _release_lock( unsigned int* plock ) 150 { 165 inline void _release_lock(unsigned int * plock) { 151 166 asm volatile ( 152 "sync\n" /* necessary because of the consistency model in tsar */153 );167 "sync\n" /* necessary because of the consistency model in tsar */ 168 ); 154 169 *plock = 0; 155 170 } 171 156 172 157 173 //////////////////////////////////////////////////////////////////////////// … … 159 175 // display a string on TTY0 / used for system code debug and log 160 176 //////////////////////////////////////////////////////////////////////////// 161 void _puts(char* buffer) 162 { 163 unsigned int* tty_address = (unsigned int*) &seg_tty_base; 177 void _puts(char * buffer) { 178 unsigned int * tty_address = (unsigned int *) &seg_tty_base; 164 179 unsigned int n; 165 180 166 for ( n=0; n<100; n++) 167 { 168 if (buffer[n] == 0) break; 169 tty_address[TTY_WRITE] = (unsigned int)buffer[n]; 181 for (n = 0; n < 100; n++) { 182 if (buffer[n] == 0) { 183 break; 184 } 185 tty_address[TTY_WRITE] = (unsigned int) buffer[n]; 170 186 } 171 187 } 188 189 172 190 //////////////////////////////////////////////////////////////////////////// 173 191 // _putx() 174 192 // display an int (hexa) on TTY0 / used for system code debug and log 175 193 //////////////////////////////////////////////////////////////////////////// 176 void _putx(unsigned int val) 177 { 178 static const char HexaTab[] = "0123456789ABCDEF"; 179 char buf[11]; 180 unsigned int c; 181 182 buf[0] = '0'; 183 buf[1] = 'x'; 194 void _putx(unsigned int val) { 195 static const char HexaTab[] = "0123456789ABCDEF"; 196 char buf[11]; 197 unsigned int c; 198 199 buf[0] = '0'; 200 buf[1] = 'x'; 184 201 buf[10] = 0; 185 202 186 for ( c = 0 ; c < 8 ; c++ ) 187 { 188 buf[9-c] = HexaTab[val&0xF]; 203 for (c = 0; c < 8; c++) { 204 buf[9 - c] = HexaTab[val & 0xF]; 189 205 val = val >> 4; 190 206 } 191 207 _puts(buf); 192 208 } 209 210 193 211 //////////////////////////////////////////////////////////////////////////// 194 212 // _putd() 195 213 // display an int (decimal) on TTY0 / used for system code debug and log 196 214 //////////////////////////////////////////////////////////////////////////// 197 void _putd(unsigned int val) 198 { 199 static const char DecTab[] = "0123456789"; 200 char buf[11]; 201 unsigned int i; 202 unsigned int first; 215 void _putd(unsigned int val) { 216 static const char DecTab[] = "0123456789"; 217 char buf[11]; 218 unsigned int i; 219 unsigned int first; 203 220 204 221 buf[10] = 0; 205 222 206 for (i = 0; i < 10; i++) 207 { 208 if ((val != 0) || (i == 0)) 209 { 210 buf[9-i] = DecTab[val % 10]; 211 first = 9-i; 223 for (i = 0; i < 10; i++) { 224 if ((val != 0) || (i == 0)) { 225 buf[9 - i] = DecTab[val % 10]; 226 first = 9 - i; 212 227 } 213 else 214 { 228 else { 215 229 break; 216 230 } 217 231 val /= 10; 218 232 } 219 _puts( &buf[first] ); 220 } 233 _puts(&buf[first]); 234 } 235 236 221 237 //////////////////////////////////////////////////////////////////////////// 222 238 // _strncmp() 223 239 // compare two strings s1 & s2 (no more than n characters) 224 240 //////////////////////////////////////////////////////////////////////////// 225 unsigned int _strncmp(const char* s1, 226 const char* s2, 227 unsigned int n) 228 { 241 unsigned int _strncmp(const char * s1, const char * s2, unsigned int n) { 229 242 unsigned int i; 230 for ( i=0 ; i<n ; i++) 231 { 232 if ( s1[i] != s2[i] ) return 1; 233 if ( s1[i] == 0 ) break; 243 for (i = 0; i < n; i++) { 244 if (s1[i] != s2[i]) { 245 return 1; 246 } 247 if (s1[i] == 0) { 248 break; 249 } 234 250 } 235 251 return 0; 236 252 } 237 //////////////////////////////////////////////////////////////////////////// 238 // _dcache_buf_invalidate() 253 254 255 //////////////////////////////////////////////////////////////////////////// 256 // _dcache_buf_invalidate() 239 257 // Invalidate all data cache lines corresponding to a memory 240 258 // buffer (identified by an address and a size). 241 259 //////////////////////////////////////////////////////////////////////////// 242 void _dcache_buf_invalidate(const void *buffer, 243 unsigned int size) 244 { 260 void _dcache_buf_invalidate(const void * buffer, unsigned int size) { 245 261 unsigned int i; 246 262 unsigned int tmp; … … 248 264 249 265 // compute data cache line size based on config register (bits 12:10) 250 asm volatile("mfc0 %0, $16, 1" : "=r" (tmp));251 tmp = ((tmp >>10) & 0x7);266 asm volatile("mfc0 %0, $16, 1" : "=r" (tmp)); 267 tmp = ((tmp >> 10) & 0x7); 252 268 line_size = 2 << tmp; 253 269 254 270 // iterate on cache lines 255 for (i = 0; i < size; i += line_size) 256 { 271 for (i = 0; i < size; i += line_size) { 257 272 asm volatile( 258 273 " cache %0, %1" 259 ::"i" (0x11), "R" (*((unsigned char*)buffer+i)) 274 : 275 :"i" (0x11), "R" (*((unsigned char *) buffer + i)) 260 276 ); 261 277 } 262 278 } 279 280 263 281 //////////////////////////////////////////////////////////////////////////// 264 282 // _physical_read_access() … … 266 284 // after a temporary DTLB desactivation. 267 285 //////////////////////////////////////////////////////////////////////////// 268 unsigned int _physical_read_access(unsigned int* paddr) 269 { 286 unsigned int _physical_read_access(unsigned int * paddr) { 270 287 unsigned int value; 271 288 272 asm volatile( "li $3, 0xFFFFFFFE \n" 273 "mfc0 $2, $12 \n" /* $2 <= SR */ 274 "and $3, $3, $2 \n" 275 "mtc0 $3, $12 \n" /* interrupt masked */ 276 "li $3, 0xB \n" 277 "mtc2 $3, $1 \n" /* DTLB off */ 278 279 "lw %0, 0(%1) \n" /* entry <= *pslot */ 280 281 "li $3, 0xF \n" 282 "mtc2 $3, $1 \n" /* DTLB on */ 283 "mtc0 $2, $12 \n" /* restore SR */ 284 : "=r"(value) 285 : "r"(paddr) 286 : "$2", "$3" ); 289 asm volatile( 290 "li $3, 0xFFFFFFFE \n" 291 "mfc0 $2, $12 \n" /* $2 <= SR */ 292 "and $3, $3, $2 \n" 293 "mtc0 $3, $12 \n" /* interrupt masked */ 294 "li $3, 0xB \n" 295 "mtc2 $3, $1 \n" /* DTLB off */ 296 297 "lw %0, 0(%1) \n" /* entry <= *pslot */ 298 299 "li $3, 0xF \n" 300 "mtc2 $3, $1 \n" /* DTLB on */ 301 "mtc0 $2, $12 \n" /* restore SR */ 302 : "=r" (value) 303 : "r" (paddr) 304 : "$2", "$3"); 287 305 return value; 288 306 } 307 308 289 309 //////////////////////////////////////////////////////////////////////////// 290 310 // _physical_write_access() … … 292 312 // after a temporary DTLB desactivation. 293 313 //////////////////////////////////////////////////////////////////////////// 294 void _physical_write_access(unsigned int* paddr, unsigned int value) 295 { 296 asm volatile( "li $3, 0xFFFFFFFE \n" 297 "mfc0 $2, $12 \n" /* $26 <= SR */ 298 "and $3, $3, $2 \n" 299 "mtc0 $3, $12 \n" /* interrupt masked */ 300 "li $3, 0xB \n" 301 "mtc2 $3, $1 \n" /* DTLB off */ 302 303 "sw %0, 0(%1) \n" /* entry <= *pslot */ 304 305 "li $3, 0xF \n" 306 "mtc2 $3, $1 \n" /* DTLB on */ 307 "mtc0 $2, $12 \n" /* restore SR */ 308 : 309 : "r"(value), "r"(paddr) 310 : "$2", "$3" ); 311 } 314 void _physical_write_access(unsigned int * paddr, unsigned int value) { 315 asm volatile( 316 "li $3, 0xFFFFFFFE \n" 317 "mfc0 $2, $12 \n" /* $26 <= SR */ 318 "and $3, $3, $2 \n" 319 "mtc0 $3, $12 \n" /* interrupt masked */ 320 "li $3, 0xB \n" 321 "mtc2 $3, $1 \n" /* DTLB off */ 322 323 "sw %0, 0(%1) \n" /* entry <= *pslot */ 324 325 "li $3, 0xF \n" 326 "mtc2 $3, $1 \n" /* DTLB on */ 327 "mtc0 $2, $12 \n" /* restore SR */ 328 : 329 : "r" (value), "r" (paddr) 330 : "$2", "$3"); 331 } 332 333 312 334 //////////////////////////////////////////////////////////////////////////// 313 335 // _get_tasks_number() 314 336 // This function returns the number of tasks allocated to processor. 315 337 //////////////////////////////////////////////////////////////////////////// 316 unsigned int _get_tasks_number() 317 { 318 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 319 return _physical_read_access( &(psched->tasks) ); 320 } 338 unsigned int _get_tasks_number() { 339 static_scheduler_t * psched = (static_scheduler_t *) _get_sched(); 340 return _physical_read_access(&(psched->tasks)); 341 } 342 343 321 344 //////////////////////////////////////////////////////////////////////////// 322 345 // _get_current_task_id() 323 346 // This function returns the index of the currently running task. 324 347 //////////////////////////////////////////////////////////////////////////// 325 unsigned int _get_current_task_id() 326 { 327 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 328 return _physical_read_access( &(psched->current) ); 329 } 348 unsigned int _get_current_task_id() { 349 static_scheduler_t * psched = (static_scheduler_t *) _get_sched(); 350 return _physical_read_access(&(psched->current)); 351 } 352 353 330 354 //////////////////////////////////////////////////////////////////////////// 331 355 // _set_current_task_id() 332 356 // This function returns the index of the currently running task. 333 357 //////////////////////////////////////////////////////////////////////////// 334 void _set_current_task_id( unsigned int value ) 335 { 336 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 337 _physical_write_access( &(psched->current), value ); 338 } 358 void _set_current_task_id(unsigned int value) { 359 static_scheduler_t * psched = (static_scheduler_t *) _get_sched(); 360 _physical_write_access(&(psched->current), value); 361 } 362 363 339 364 /////////////////////////////////////////////////////////////////////////////// 340 365 // _get_context_slot() 341 366 // This function returns a slot content for the task defined by task_id. 342 367 /////////////////////////////////////////////////////////////////////////////// 343 unsigned int _get_context_slot( unsigned int task_id,344 unsigned int slot_id )345 { 346 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 347 return _physical_read_access( &(psched->context[task_id][slot_id]) ); 348 } 368 unsigned int _get_context_slot(unsigned int task_id, unsigned int slot_id) { 369 static_scheduler_t * psched = (static_scheduler_t *) _get_sched(); 370 return _physical_read_access(&(psched->context[task_id][slot_id])); 371 } 372 373 349 374 /////////////////////////////////////////////////////////////////////////////// 350 375 // _set_context_slot() … … 352 377 /////////////////////////////////////////////////////////////////////////////// 353 378 void _set_context_slot( unsigned int task_id, 354 unsigned int slot_id, 355 unsigned int value ) 356 { 357 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 358 _physical_write_access( &(psched->context[task_id][slot_id]), value ); 359 } 379 unsigned int slot_id, 380 unsigned int value) { 381 static_scheduler_t * psched = (static_scheduler_t *) _get_sched(); 382 _physical_write_access(&(psched->context[task_id][slot_id]), value); 383 } 384 385 360 386 //////////////////////////////////////////////////////////////////////////////// 361 387 // _get_interrupt_vector_entry() 362 388 // This function returns the interrupt_vector entry defined by argument index. 363 389 //////////////////////////////////////////////////////////////////////////////// 364 unsigned int _get_interrupt_vector_entry( unsigned int index ) 390 unsigned int _get_interrupt_vector_entry(unsigned int index) { 391 static_scheduler_t * psched = (static_scheduler_t *) _get_sched(); 392 return _physical_read_access( &(psched->interrupt_vector[index])); 393 } 394 395 396 ///////////////////////////////////////////////////////////////////////////// 397 // access functions to mapping_info data structure 398 ///////////////////////////////////////////////////////////////////////////// 399 mapping_cluster_t * _get_cluster_base(mapping_header_t * header) { 400 return (mapping_cluster_t *) ((char *) header + 401 MAPPING_HEADER_SIZE); 402 } 403 404 405 ///////////////////////////////////////////////////////////////////////////// 406 mapping_pseg_t * _get_pseg_base(mapping_header_t * header) { 407 return (mapping_pseg_t *) ((char *) header + 408 MAPPING_HEADER_SIZE + 409 MAPPING_CLUSTER_SIZE * header->clusters); 410 } 411 ///////////////////////////////////////////////////////////////////////////// 412 mapping_vspace_t * _get_vspace_base(mapping_header_t * header) { 413 return (mapping_vspace_t *) ((char *) header + 414 MAPPING_HEADER_SIZE + 415 MAPPING_CLUSTER_SIZE * header->clusters + 416 MAPPING_PSEG_SIZE * header->psegs); 417 } 418 419 420 ///////////////////////////////////////////////////////////////////////////// 421 mapping_vseg_t * _get_vseg_base(mapping_header_t * header) 365 422 { 366 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 367 return _physical_read_access( &(psched->interrupt_vector[index]) ); 368 } 369 370 ///////////////////////////////////////////////////////////////////////////// 371 // access functions to mapping_info data structure 372 ///////////////////////////////////////////////////////////////////////////// 373 mapping_cluster_t* _get_cluster_base( mapping_header_t* header ) 374 { 375 return (mapping_cluster_t*) ((char*)header + 376 MAPPING_HEADER_SIZE); 377 } 378 ///////////////////////////////////////////////////////////////////////////// 379 mapping_pseg_t* _get_pseg_base( mapping_header_t* header ) 380 { 381 return (mapping_pseg_t*) ((char*)header + 382 MAPPING_HEADER_SIZE + 383 MAPPING_CLUSTER_SIZE*header->clusters); 384 } 385 ///////////////////////////////////////////////////////////////////////////// 386 mapping_vspace_t* _get_vspace_base( mapping_header_t* header ) 387 { 388 return (mapping_vspace_t*) ((char*)header + 389 MAPPING_HEADER_SIZE + 390 MAPPING_CLUSTER_SIZE*header->clusters + 391 MAPPING_PSEG_SIZE*header->psegs); 392 } 393 ///////////////////////////////////////////////////////////////////////////// 394 mapping_vseg_t* _get_vseg_base( mapping_header_t* header ) 395 { 396 return (mapping_vseg_t*) ((char*)header + 397 MAPPING_HEADER_SIZE + 398 MAPPING_CLUSTER_SIZE*header->clusters + 399 MAPPING_PSEG_SIZE*header->psegs + 400 MAPPING_VSPACE_SIZE*header->vspaces); 401 } 402 ///////////////////////////////////////////////////////////////////////////// 403 mapping_vobj_t* _get_vobj_base( mapping_header_t* header ) 404 { 405 return (mapping_vobj_t*) ((char*)header + 406 MAPPING_HEADER_SIZE + 407 MAPPING_CLUSTER_SIZE*header->clusters + 408 MAPPING_PSEG_SIZE*header->psegs + 409 MAPPING_VSPACE_SIZE*header->vspaces + 410 MAPPING_VSEG_SIZE*header->vsegs ); 411 } 412 ///////////////////////////////////////////////////////////////////////////// 413 mapping_task_t* _get_task_base( mapping_header_t* header ) 414 { 415 return (mapping_task_t*) ((char*)header + 416 MAPPING_HEADER_SIZE + 417 MAPPING_CLUSTER_SIZE*header->clusters + 418 MAPPING_PSEG_SIZE*header->psegs + 419 MAPPING_VSPACE_SIZE*header->vspaces + 420 MAPPING_VOBJ_SIZE*header->vobjs + 421 MAPPING_VSEG_SIZE*header->vsegs); 422 } 423 423 return (mapping_vseg_t *) ((char *) header + 424 MAPPING_HEADER_SIZE + 425 MAPPING_CLUSTER_SIZE * header->clusters + 426 MAPPING_PSEG_SIZE * header->psegs + 427 MAPPING_VSPACE_SIZE * header->vspaces); 428 } 429 430 431 ///////////////////////////////////////////////////////////////////////////// 432 mapping_vobj_t * _get_vobj_base(mapping_header_t * header) { 433 return (mapping_vobj_t *) ((char *) header + 434 MAPPING_HEADER_SIZE + 435 MAPPING_CLUSTER_SIZE * header->clusters + 436 MAPPING_PSEG_SIZE * header->psegs + 437 MAPPING_VSPACE_SIZE * header->vspaces + 438 MAPPING_VSEG_SIZE * header->vsegs ); 439 } 440 441 442 ///////////////////////////////////////////////////////////////////////////// 443 mapping_task_t * _get_task_base(mapping_header_t * header) { 444 return (mapping_task_t *) ((char *) header + 445 MAPPING_HEADER_SIZE + 446 MAPPING_CLUSTER_SIZE * header->clusters + 447 MAPPING_PSEG_SIZE * header->psegs + 448 MAPPING_VSPACE_SIZE * header->vspaces + 449 MAPPING_VOBJ_SIZE * header->vobjs + 450 MAPPING_VSEG_SIZE * header->vsegs); 451 } 452 453 454 // Local Variables: 455 // tab-width: 4 456 // c-basic-offset: 4 457 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 458 // indent-tabs-mode: nil 459 // End: 460 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 461 -
soft/giet_vm/sys/common.h
r218 r228 30 30 31 31 /////////////////////////////////////////////////////////////////////////////////// 32 // 32 // Prototypes of common functions 33 33 /////////////////////////////////////////////////////////////////////////////////// 34 34 35 void 36 void 37 void 35 void _puts(char *string); 36 void _putx(unsigned int val); 37 void _putd(unsigned int val); 38 38 39 unsigned int _strncmp( const char* s1, 40 const char* s2, 41 unsigned int n ); 39 unsigned int _strncmp(const char * s1, const char * s2, unsigned int n); 40 void _dcache_buf_invalidate(const void * buffer, unsigned int size); 42 41 43 void _dcache_buf_invalidate( const void *buffer,44 unsigned int size);42 void _dtlb_off(void); 43 void _dtlb_on(void); 45 44 46 void _dtlb_off(void);47 void _dtlb_on(void);45 void _it_mask(void); 46 void _it_restore(void); 48 47 49 void _it_mask(void); 50 void _it_enable(void); 48 unsigned int _get_epc(void); 49 unsigned int _get_ptpr(void); 50 unsigned int _get_bvar(void); 51 unsigned int _get_cr(void); 52 unsigned int _get_sched(void); 51 53 52 unsigned int _get_epc(void); 53 unsigned int _get_ptpr(void); 54 unsigned int _get_bvar(void); 55 unsigned int _get_cr(void); 56 unsigned int _get_sched(void); 54 unsigned int _get_context_slot(unsigned int task_id, unsigned int slot_id); 55 void _set_context_slot(unsigned int task_id, unsigned int slot_id, unsigned int value); 57 56 58 unsigned int _get_context_slot( unsigned int task_id, 59 unsigned int slot_id ); 57 unsigned int _get_interrupt_vector_entry(unsigned int index); 60 58 61 void _set_context_slot( unsigned int task_id, 62 unsigned int slot_id, 63 unsigned int value ); 59 unsigned int _get_current_task_id(void); 60 void _set_current_task_id(unsigned int value); 64 61 65 unsigned int _get_interrupt_vector_entry(unsigned int index);62 unsigned int _get_tasks_number(void); 66 63 67 unsigned int _get_current_task_id( void);68 void _set_current_task_id( unsigned int value);64 void _get_lock(unsigned int * lock); 65 void _release_lock(unsigned int * lock); 69 66 70 unsigned int _get_tasks_number(void); 71 72 73 void _get_lock(unsigned int* lock); 74 void _release_lock(unsigned int* lock); 75 76 mapping_cluster_t* _get_cluster_base( mapping_header_t* header ); 77 mapping_pseg_t* _get_pseg_base( mapping_header_t* header ); 78 mapping_vspace_t* _get_vspace_base( mapping_header_t* header ); 79 mapping_vseg_t* _get_vseg_base( mapping_header_t* header ); 80 mapping_vobj_t* _get_vobj_base( mapping_header_t* header ); 81 mapping_task_t* _get_task_base( mapping_header_t* header ); 67 mapping_cluster_t * _get_cluster_base(mapping_header_t* header); 68 mapping_pseg_t * _get_pseg_base(mapping_header_t* header); 69 mapping_vspace_t * _get_vspace_base(mapping_header_t* header); 70 mapping_vseg_t * _get_vseg_base(mapping_header_t* header); 71 mapping_vobj_t * _get_vobj_base(mapping_header_t* header); 72 mapping_task_t * _get_task_base(mapping_header_t* header); 82 73 83 74 … … 89 80 // Code taken from MutekH. 90 81 /////////////////////////////////////////////////////////////////////////////////// 91 static inline void *memcpy(void *_dst, const void *_src, unsigned int size) 92 { 93 unsigned int *dst = _dst; 94 const unsigned int *src = _src; 82 static inline void * memcpy(void * _dst, const void * _src, unsigned int size) { 83 unsigned int * dst = _dst; 84 const unsigned int * src = _src; 95 85 96 86 /* if source and destination buffer are word-aligned, 97 87 * then copy word-by-word */ 98 if (!((unsigned int) dst & 3) && !((unsigned int)src & 3))88 if (!((unsigned int) dst & 3) && !((unsigned int) src & 3)) { 99 89 while (size > 3) { 100 90 *dst++ = *src++; 101 91 size -= 4; 102 92 } 93 } 103 94 104 unsigned char * cdst = (unsigned char*)dst;105 unsigned char * csrc = (unsigned char*)src;95 unsigned char * cdst = (unsigned char *) dst; 96 unsigned char * csrc = (unsigned char *) src; 106 97 107 98 /* byte-by-byte copy */ … … 113 104 114 105 #endif 106 107 // Local Variables: 108 // tab-width: 4 109 // c-basic-offset: 4 110 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 111 // indent-tabs-mode: nil 112 // End: 113 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 114 -
soft/giet_vm/sys/ctx_handler.c
r218 r228 30 30 // - CP2 registers : PTPR 31 31 // It contains some general informations associated to the task: 32 // - TTY 33 // - FBDMA 34 // - NIC 32 // - TTY : terminal global index 33 // - FBDMA : DMA channel global index 34 // - NIC : NIC channel global index 35 35 // - TIMER : Timer global index 36 36 // - PTAB : page table virtual base address 37 // - LTID 37 // - LTID : Task local index (in scheduler) 38 38 // - VSID : Virtual space index 39 // - RUN 39 // - RUN : Task state (0 => sleeping / 1 => runable ) 40 40 // 41 41 // ctx[0]<- ***|ctx[8] <- $8 |ctx[16]<- $16|ctx[24]<- $24|ctx[32]<- EPC |ctx[40]<- TTY … … 49 49 ////////////////////////////////////////////////////////////////////////////////////////// 50 50 51 extern void _task_switch(unsigned int *, unsigned int*);51 extern void _task_switch(unsigned int *, unsigned int *); 52 52 53 53 ///////////////////////////////////////////////////////////////////////////////// 54 // 54 // _ctx_switch() 55 55 // This function performs a context switch between the running task 56 56 // and another task, using a round-robin sheduling policy between all … … 68 68 // contained in the ctx[31] slot of the next task context. 69 69 ///////////////////////////////////////////////////////////////////////////////// 70 void _ctx_switch() 71 { 70 void _ctx_switch() { 72 71 // get scheduler physical address 73 static_scheduler_t * psched = (static_scheduler_t*)_get_sched();72 static_scheduler_t * psched = (static_scheduler_t *) _get_sched(); 74 73 75 74 // get number of tasks allocated to scheduler 76 unsigned int 75 unsigned int tasks = _get_tasks_number(); 77 76 78 77 // get current task index 79 unsigned int 78 unsigned int curr_task_id = _get_current_task_id(); 80 79 81 80 // select the next task using a round-robin policy 82 unsigned int 83 unsigned int 84 unsigned int 81 unsigned int next_task_id; 82 unsigned int tid; 83 unsigned int found = 0; 85 84 86 for ( tid = curr_task_id + 1 ; 87 tid < curr_task_id + 1 + tasks ; 88 tid++ ) 89 { 85 for (tid = curr_task_id + 1; tid < curr_task_id + 1 + tasks; tid++) { 90 86 next_task_id = tid % tasks; 91 87 92 88 // test if the task is runable 93 if ( _get_context_slot( next_task_id, CTX_RUN_ID ) ) 94 { 89 if (_get_context_slot(next_task_id, CTX_RUN_ID)) { 95 90 found = 1; 96 91 break; 97 92 } 98 93 } 99 94 100 95 // launch "idle" task if no runable task 101 if ( found == 0 ) 102 { 96 if (found == 0) { 103 97 next_task_id = IDLE_TASK_INDEX; 104 98 } 105 99 106 100 // no switch if no change 107 if ( curr_task_id != next_task_id ) 108 { 109 unsigned int* curr_ctx_paddr = &(psched->context[curr_task_id][0]); 110 unsigned int* next_ctx_paddr = &(psched->context[next_task_id][0]); 101 if (curr_task_id != next_task_id) { 102 unsigned int * curr_ctx_paddr = &(psched->context[curr_task_id][0]); 103 unsigned int * next_ctx_paddr = &(psched->context[next_task_id][0]); 111 104 112 _set_current_task_id( next_task_id ); 113 _task_switch( curr_ctx_paddr, next_ctx_paddr ); 105 _set_current_task_id(next_task_id); 106 //_timer_reset_irq_cpt(cluster_id, local_id); // commented until not properly supported in soclib 107 // (the function is not yet present in drivers.c) 108 _task_switch(curr_ctx_paddr, next_ctx_paddr); 114 109 115 110 #if GIET_DEBUG_SWITCH 116 _get_lock( &_tty_put_lock);117 _puts("\n[GIET DEBUG] Context switch for processor ");118 _putd( _procid());119 _puts(" at cycle ");120 _putd( _proctime());121 _puts("\n");122 _puts(" - tasks = ");123 _putd( tasks);124 _puts("\n");125 _puts(" - curr_task_id = ");126 _putd( curr_task_id );127 _puts("\n");128 _puts(" - next_task_id = ");129 _putd( next_task_id);130 _puts("\n");131 _release_lock( &_tty_put_lock);111 _get_lock(&_tty_put_lock); 112 _puts("\n[GIET DEBUG] Context switch for processor "); 113 _putd(_procid()); 114 _puts(" at cycle "); 115 _putd(_proctime()); 116 _puts("\n"); 117 _puts(" - tasks = "); 118 _putd(tasks); 119 _puts("\n"); 120 _puts(" - curr_task_id = "); 121 _putd( curr_task_id ); 122 _puts("\n"); 123 _puts(" - next_task_id = "); 124 _putd(next_task_id); 125 _puts("\n"); 126 _release_lock( &_tty_put_lock); 132 127 #endif 133 128 … … 138 133 // This function is executed as the"idle" task when no other task can be executed 139 134 ///////////////////////////////////////////////////////////////////////////////////// 140 void _ctx_idle() 141 { 135 void _ctx_idle() { 142 136 unsigned int delay = 1000000; 143 137 144 while (1)145 {146 asm volatile("move $3, %0\n"147 "loop:\n"148 "addi $3, $3, -1\n"149 "bnez $3, loop\n"150 "nop\n"151 152 153 138 while (1) { 139 asm volatile( 140 "move $3, %0 \n" 141 "loop: \n" 142 "addi $3, $3, -1 \n" 143 "bnez $3, loop \n" 144 "nop \n" 145 : 146 : "r"(delay) 147 : "$3" ); 154 148 155 _get_lock( &_tty_put_lock);156 _puts( 157 _putd( _procid());158 _puts( 159 _putd( _proctime());149 _get_lock(&_tty_put_lock); 150 _puts("\n[GIET WARNING] Processor "); 151 _putd(_procid()); 152 _puts(" still idle at cycle "); 153 _putd(_proctime()); 160 154 _puts("\n"); 161 _release_lock( &_tty_put_lock);162 155 _release_lock(&_tty_put_lock); 156 163 157 } 164 158 } // end ctx_idle() 159 165 160 166 161 ///////////////////////////////////////////////////////////////////////////////// … … 168 163 // in the "idle" task context. 169 164 ///////////////////////////////////////////////////////////////////////////////// 170 void _ctx_eret() 171 { 165 void _ctx_eret() { 172 166 asm volatile("eret"); 173 167 } 174 168 175 169 170 // Local Variables: 171 // tab-width: 4 172 // c-basic-offset: 4 173 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 174 // indent-tabs-mode: nil 175 // End: 176 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 177 -
soft/giet_vm/sys/drivers.c
r226 r228 103 103 104 104 ////////////////////////////////////////////////////////////////////////////// 105 // 105 // Timers driver 106 106 ////////////////////////////////////////////////////////////////////////////// 107 107 // The timers can be implemented in a vci_timer component or in a vci_xicu … … 119 119 120 120 #if (NB_TIMERS_MAX > 0) 121 in_unckdata volatile unsigned char _user_timer_event[NB_CLUSTERS *NB_TIMERS_MAX]122 = { [0 ... ((NB_CLUSTERS*NB_TIMERS_MAX)-1)] = 0 };121 in_unckdata volatile unsigned char _user_timer_event[NB_CLUSTERS * NB_TIMERS_MAX] 122 = { [0 ... ((NB_CLUSTERS * NB_TIMERS_MAX) - 1)] = 0 }; 123 123 #endif 124 124 … … 131 131 // Returns 0 if success, > 0 if error. 132 132 ////////////////////////////////////////////////////////////////////////////// 133 unsigned int _timer_start( unsigned int cluster_id, 134 unsigned int local_id, 135 unsigned int period ) 136 { 133 unsigned int _timer_start(unsigned int cluster_id, unsigned int local_id, unsigned int period) { 137 134 // parameters checking 138 if ( cluster_id >= NB_CLUSTERS) return 1; 139 if ( local_id >= NB_TIMERS_MAX) return 2; 135 if (cluster_id >= NB_CLUSTERS) { 136 return 1; 137 } 138 if (local_id >= NB_TIMERS_MAX) { 139 return 2; 140 } 140 141 141 142 #if USE_XICU 142 unsigned int* timer_address = (unsigned int*)((char*)&seg_icu_base + 143 (cluster_id * CLUSTER_SIZE) ); 143 unsigned int * timer_address = (unsigned int *) ((char *) &seg_icu_base + (cluster_id * CLUSTER_SIZE)); 144 144 145 145 timer_address[XICU_REG(XICU_PTI_PER, local_id)] = period; 146 146 #else 147 unsigned int* timer_address = (unsigned int*)((char*)&seg_tim_base + 148 (cluster_id * CLUSTER_SIZE) ); 147 unsigned int* timer_address = (unsigned int *) ((char *) &seg_tim_base + (cluster_id * CLUSTER_SIZE)); 149 148 150 149 timer_address[local_id * TIMER_SPAN + TIMER_PERIOD] = period; 151 timer_address[local_id * TIMER_SPAN + TIMER_MODE] = 0x3; 152 #endif 153 154 return 0; 155 } 150 timer_address[local_id * TIMER_SPAN + TIMER_MODE] = 0x3; 151 #endif 152 return 0; 153 } 154 155 156 156 ////////////////////////////////////////////////////////////////////////////// 157 157 // _timer_stop() … … 160 160 // Returns 0 if success, > 0 if error. 161 161 ////////////////////////////////////////////////////////////////////////////// 162 unsigned int _timer_stop( unsigned int cluster_id, 163 unsigned int local_id ) 164 { 162 unsigned int _timer_stop(unsigned int cluster_id, unsigned int local_id) { 165 163 // parameters checking 166 if ( cluster_id >= NB_CLUSTERS) return 1; 167 if ( local_id >= NB_TIMERS_MAX ) return 2; 164 if (cluster_id >= NB_CLUSTERS) { 165 return 1; 166 } 167 if (local_id >= NB_TIMERS_MAX) { 168 return 2; 169 } 168 170 169 171 #if USE_XICU 170 unsigned int* timer_address = (unsigned int*)((char*)&seg_icu_base + 171 (cluster_id * CLUSTER_SIZE) ); 172 unsigned int * timer_address = (unsigned int *) ((char *) &seg_icu_base + (cluster_id * CLUSTER_SIZE)); 172 173 173 174 timer_address[XICU_REG(XICU_PTI_PER, local_id)] = 0; 174 175 #else 175 unsigned int* timer_address = (unsigned int*)((char*)&seg_tim_base + 176 (cluster_id * CLUSTER_SIZE) ); 177 176 unsigned int* timer_address = (unsigned int *) ((char *) &seg_tim_base + (cluster_id * CLUSTER_SIZE)); 178 177 timer_address[local_id * TIMER_SPAN + TIMER_MODE] = 0; 179 178 #endif 180 181 return 0; 182 } 179 return 0; 180 } 181 182 183 183 ////////////////////////////////////////////////////////////////////////////// 184 184 // _timer_reset_irq() … … 189 189 // Returns 0 if success, > 0 if error. 190 190 ////////////////////////////////////////////////////////////////////////////// 191 unsigned int _timer_reset_irq( unsigned int cluster_id, 192 unsigned int local_id ) 193 { 191 unsigned int _timer_reset_irq(unsigned int cluster_id, unsigned int local_id) { 194 192 // parameters checking 195 if ( cluster_id >= NB_CLUSTERS) return 1; 196 if ( local_id >= NB_TIMERS_MAX ) return 2; 193 if (cluster_id >= NB_CLUSTERS) { 194 return 1; 195 } 196 if (local_id >= NB_TIMERS_MAX) { 197 return 2; 198 } 197 199 198 200 #if USE_XICU 199 unsigned int * timer_address = (unsigned int*)((char*)&seg_icu_base +200 (cluster_id * (unsigned)CLUSTER_SIZE));201 unsigned int * timer_address = (unsigned int *) ((char *) &seg_icu_base + 202 (cluster_id * (unsigned) CLUSTER_SIZE)); 201 203 202 204 unsigned int bloup = timer_address[XICU_REG(XICU_PTI_ACK, local_id)]; 203 bloup++; 205 bloup++; // to avoid a warning 204 206 #else 205 unsigned int * timer_address = (unsigned int*)((char*)&seg_tim_base +206 (cluster_id * CLUSTER_SIZE));207 unsigned int * timer_address = (unsigned int *)((char *) &seg_tim_base + 208 (cluster_id * CLUSTER_SIZE)); 207 209 208 210 timer_address[local_id * TIMER_SPAN + TIMER_RESETIRQ] = 0; … … 212 214 } 213 215 216 214 217 ///////////////////////////////////////////////////////////////////////////////// 215 // 218 // VciMultiTty driver 216 219 ///////////////////////////////////////////////////////////////////////////////// 217 220 // There is only one multi_tty controler in the architecture. … … 226 229 // TTY variables 227 230 in_unckdata volatile unsigned char _tty_get_buf[NB_TTYS]; 228 in_unckdata volatile unsigned char _tty_get_full[NB_TTYS] = { [0 ... NB_TTYS -1] = 0 };229 in_unckdata unsigned int 231 in_unckdata volatile unsigned char _tty_get_full[NB_TTYS] = { [0 ... NB_TTYS - 1] = 0 }; 232 in_unckdata unsigned int _tty_put_lock = 0; // protect kernel TTY[0] 230 233 231 234 //////////////////////////////////////////////////////////////////////////////// 232 235 // _tty_error() 233 236 //////////////////////////////////////////////////////////////////////////////// 234 void _tty_error( unsigned int tty_id, unsigned int task_id ) 235 { 237 void _tty_error(unsigned int tty_id, unsigned int task_id) { 236 238 unsigned int proc_id = _procid(); 237 239 238 240 _get_lock(&_tty_put_lock); 239 if ( tty_id == 0xFFFFFFFF )241 if (tty_id == 0xFFFFFFFF) { 240 242 _puts("\n[GIET ERROR] no TTY assigned to the task "); 241 else 243 } 244 else { 242 245 _puts("\n[GIET ERROR] TTY index too large for task "); 243 _putd( task_id ); 246 } 247 _putd(task_id); 244 248 _puts(" on processor "); 245 _putd( proc_id);249 _putd(proc_id); 246 250 _puts("\n"); 247 251 _release_lock(&_tty_put_lock); 248 252 } 253 254 249 255 ///////////////////////////////////////////////////////////////////////////////// 250 256 // _tty_write() … … 256 262 // The function returns the number of characters that have been written. 257 263 ///////////////////////////////////////////////////////////////////////////////// 258 unsigned int _tty_write( const char *buffer, 259 unsigned int length) 260 { 261 unsigned int nwritten; 262 263 unsigned int task_id = _get_current_task_id(); 264 unsigned int tty_id = _get_context_slot(task_id, CTX_TTY_ID); 265 266 if ( tty_id >= NB_TTYS ) 267 { 268 _tty_error( tty_id , task_id ); 264 unsigned int _tty_write(const char * buffer, unsigned int length) { 265 unsigned int nwritten; 266 unsigned int task_id = _get_current_task_id(); 267 unsigned int tty_id = _get_context_slot(task_id, CTX_TTY_ID); 268 269 if (tty_id >= NB_TTYS) { 270 _tty_error(tty_id , task_id); 269 271 return 0; 270 272 } 271 273 272 unsigned int* tty_address = (unsigned int*) &seg_tty_base; 273 274 for (nwritten = 0; nwritten < length; nwritten++) 275 { 274 unsigned int * tty_address = (unsigned int *) &seg_tty_base; 275 276 for (nwritten = 0; nwritten < length; nwritten++) { 276 277 // check tty's status 277 if ((tty_address[tty_id *TTY_SPAN + TTY_STATUS] & 0x2) == 0x2)278 if ((tty_address[tty_id * TTY_SPAN + TTY_STATUS] & 0x2) == 0x2) { 278 279 break; 279 else 280 } 281 else { 280 282 // write character 281 tty_address[tty_id*TTY_SPAN + TTY_WRITE] = (unsigned int)buffer[nwritten]; 283 tty_address[tty_id * TTY_SPAN + TTY_WRITE] = (unsigned int) buffer[nwritten]; 284 } 282 285 } 283 286 return nwritten; 284 287 } 288 289 285 290 ////////////////////////////////////////////////////////////////////////////// 286 291 // _tty_read() … … 294 299 // Returns 0 if the kernel buffer is empty, 1 if the buffer is full. 295 300 ////////////////////////////////////////////////////////////////////////////// 296 unsigned int _tty_read( char *buffer, 297 unsigned int length) 298 { 299 unsigned int task_id = _get_current_task_id(); 300 unsigned int tty_id = _get_context_slot(task_id, CTX_TTY_ID); 301 302 if ( tty_id >= NB_TTYS ) 303 { 304 _tty_error( tty_id, task_id ); 301 unsigned int _tty_read(char * buffer, unsigned int length) { 302 unsigned int task_id = _get_current_task_id(); 303 unsigned int tty_id = _get_context_slot(task_id, CTX_TTY_ID); 304 305 if (tty_id >= NB_TTYS) { 306 _tty_error(tty_id, task_id); 305 307 return 0; 306 308 } 307 309 308 if (_tty_get_full[tty_id] == 0) 309 { 310 if (_tty_get_full[tty_id] == 0) { 310 311 return 0; 311 312 } 312 else 313 { 313 else { 314 314 *buffer = _tty_get_buf[tty_id]; 315 315 _tty_get_full[tty_id] = 0; 316 316 return 1; 317 317 } 318 } 318 } 319 320 319 321 //////////////////////////////////////////////////////////////////////////////// 320 322 // _tty_get_char() … … 324 326 // Returns 0 if success, 1 if tty_id too large. 325 327 //////////////////////////////////////////////////////////////////////////////// 326 unsigned int _tty_get_char( unsigned int tty_id, 327 unsigned char* buffer ) 328 { 328 unsigned int _tty_get_char(unsigned int tty_id, unsigned char * buffer) { 329 329 // checking argument 330 if ( tty_id >= NB_TTYS ) return 1; 330 if (tty_id >= NB_TTYS) { 331 return 1; 332 } 331 333 332 334 // compute terminal base address 333 unsigned int *tty_address = (unsigned int*) &seg_tty_base; 334 335 *buffer = (unsigned char)tty_address[tty_id*TTY_SPAN + TTY_READ]; 336 return 0; 337 } 338 339 //////////////////////////////////////////////////////////////////////////////// 340 // VciMultiIcu and VciXicu drivers 335 unsigned int * tty_address = (unsigned int *) &seg_tty_base; 336 337 *buffer = (unsigned char) tty_address[tty_id * TTY_SPAN + TTY_READ]; 338 return 0; 339 } 340 341 342 //////////////////////////////////////////////////////////////////////////////// 343 // VciMultiIcu and VciXicu drivers 341 344 //////////////////////////////////////////////////////////////////////////////// 342 345 // There is one vci_multi_icu (or vci_xicu) component per cluster, … … 352 355 // Returns 0 if success, > 0 if error. 353 356 //////////////////////////////////////////////////////////////////////////////// 354 unsigned int _icu_set_mask( unsigned int cluster_id,355 unsigned int proc_id,356 unsigned int value,357 unsigned int is_timer )358 {357 unsigned int _icu_set_mask( 358 unsigned int cluster_id, 359 unsigned int proc_id, 360 unsigned int value, 361 unsigned int is_timer) { 359 362 // parameters checking 360 if ( cluster_id >= NB_CLUSTERS) return 1; 361 if ( proc_id >= NB_PROCS_MAX ) return 1; 362 363 unsigned int* icu_address = (unsigned int*)( (char*)&seg_icu_base + 364 (cluster_id * (unsigned)CLUSTER_SIZE) ); 363 if (cluster_id >= NB_CLUSTERS) { 364 return 1; 365 } 366 if (proc_id >= NB_PROCS_MAX) { 367 return 1; 368 } 369 370 unsigned int * icu_address = (unsigned int *) ((char *) &seg_icu_base + 371 (cluster_id * (unsigned) CLUSTER_SIZE)); 365 372 #if USE_XICU 366 if ( is_timer ) icu_address[XICU_REG(XICU_MSK_PTI_ENABLE, proc_id)] = value; 367 else icu_address[XICU_REG(XICU_MSK_HWI_ENABLE, proc_id)] = value; 373 if (is_timer) { 374 icu_address[XICU_REG(XICU_MSK_PTI_ENABLE, proc_id)] = value; 375 } 376 else { 377 icu_address[XICU_REG(XICU_MSK_HWI_ENABLE, proc_id)] = value; 378 } 368 379 #else 369 380 icu_address[proc_id * ICU_SPAN + ICU_MASK_SET] = value; … … 372 383 return 0; 373 384 } 385 386 374 387 //////////////////////////////////////////////////////////////////////////////// 375 388 // _icu_get_index() … … 379 392 // Returns 0 if success, > 0 if error. 380 393 //////////////////////////////////////////////////////////////////////////////// 381 unsigned int _icu_get_index( unsigned int cluster_id, 382 unsigned int proc_id, 383 unsigned int* buffer ) 384 { 394 unsigned int _icu_get_index(unsigned int cluster_id, unsigned int proc_id, unsigned int * buffer) { 385 395 // parameters checking 386 if ( cluster_id >= NB_CLUSTERS) return 1; 387 if ( proc_id >= NB_PROCS_MAX ) return 1; 388 389 unsigned int* icu_address = (unsigned int*)( (char*)&seg_icu_base + 390 (cluster_id * (unsigned)CLUSTER_SIZE) ); 396 if (cluster_id >= NB_CLUSTERS) { 397 return 1; 398 } 399 if (proc_id >= NB_PROCS_MAX) { 400 return 1; 401 } 402 403 unsigned int * icu_address = (unsigned int *) ((char *) &seg_icu_base + 404 (cluster_id * (unsigned) CLUSTER_SIZE)); 391 405 #if USE_XICU 392 unsigned int prio 406 unsigned int prio = icu_address[XICU_REG(XICU_PRIO, proc_id)]; 393 407 unsigned int pti_ok = (prio & 0x00000001); 394 408 unsigned int hwi_ok = (prio & 0x00000002); … … 397 411 unsigned int hwi_id = (prio & 0x001F0000) >> 16; 398 412 unsigned int swi_id = (prio & 0x1F000000) >> 24; 399 if (pti_ok) *buffer = pti_id; 400 else if (hwi_ok) *buffer = hwi_id; 401 else if (swi_ok) *buffer = swi_id; 402 else *buffer = 32; 413 if (pti_ok) { 414 *buffer = pti_id; 415 } 416 else if (hwi_ok) { 417 *buffer = hwi_id; 418 } 419 else if (swi_ok) { 420 *buffer = swi_id; 421 } 422 else { 423 *buffer = 32; 424 } 403 425 #else 404 426 *buffer = icu_address[proc_id * ICU_SPAN + ICU_IT_VECTOR]; … … 408 430 } 409 431 410 //////////////////////////////////////////////////////////////////////////////// 411 // VciGcd driver 432 433 //////////////////////////////////////////////////////////////////////////////// 434 // VciGcd driver 412 435 //////////////////////////////////////////////////////////////////////////////// 413 436 // The Greater Dommon Divider is a -very- simple hardware coprocessor … … 421 444 // Returns 0 if success, > 0 if error. 422 445 //////////////////////////////////////////////////////////////////////////////// 423 unsigned int _gcd_write( unsigned int register_index, 424 unsigned int value) 425 { 446 unsigned int _gcd_write(unsigned int register_index, unsigned int value) { 426 447 // parameters checking 427 if (register_index >= GCD_END) 428 return 1; 429 430 unsigned int* gcd_address = (unsigned int*) &seg_gcd_base; 448 if (register_index >= GCD_END) { 449 return 1; 450 } 451 452 unsigned int * gcd_address = (unsigned int *) &seg_gcd_base; 431 453 432 454 gcd_address[register_index] = value; // write word 433 455 return 0; 434 456 } 457 458 435 459 //////////////////////////////////////////////////////////////////////////////// 436 460 // _gcd_read() … … 438 462 // Returns 0 if success, > 0 if error. 439 463 //////////////////////////////////////////////////////////////////////////////// 440 unsigned int _gcd_read( unsigned int register_index, 441 unsigned int *buffer) 442 { 464 unsigned int _gcd_read(unsigned int register_index, unsigned int * buffer) { 443 465 // parameters checking 444 if (register_index >= GCD_END) 445 return 1; 446 447 unsigned int* gcd_address = (unsigned int*) &seg_gcd_base; 466 if (register_index >= GCD_END) { 467 return 1; 468 } 469 470 unsigned int * gcd_address = (unsigned int *) &seg_gcd_base; 448 471 449 472 *buffer = gcd_address[register_index]; // read word … … 502 525 503 526 // IOC global variables 504 in_unckdata volatile unsigned int _ioc_status= 0;505 in_unckdata volatile unsigned int _ioc_done= 0;506 in_unckdata unsigned int _ioc_lock= 0;507 in_unckdata unsigned int _ioc_iommu_ix1= 0;508 in_unckdata unsigned int 527 in_unckdata volatile unsigned int _ioc_status= 0; 528 in_unckdata volatile unsigned int _ioc_done = 0; 529 in_unckdata unsigned int _ioc_lock = 0; 530 in_unckdata unsigned int _ioc_iommu_ix1 = 0; 531 in_unckdata unsigned int _ioc_iommu_npages; 509 532 510 533 /////////////////////////////////////////////////////////////////////////////// … … 519 542 // Returns 0 if success, > 0 if error. 520 543 /////////////////////////////////////////////////////////////////////////////// 521 unsigned int _ioc_access( unsigned int to_mem,522 unsigned int lba,523 unsigned int user_vaddr,524 unsigned int count )525 {526 unsigned int user_vpn_min;// first virtuel page index in user space527 unsigned int user_vpn_max;// last virtual page index in user space528 unsigned int vpn;// current virtual page index in user space529 unsigned int ppn;// physical page number530 unsigned int flags;// page protection flags531 unsigned int ix2;// page index in IOMMU PT1 page table532 unsigned int addr;// buffer address for IOC peripheral533 unsigned int ppn_first;// first physical page number for user buffer534 544 unsigned int _ioc_access( 545 unsigned int to_mem, 546 unsigned int lba, 547 unsigned int user_vaddr, 548 unsigned int count) { 549 unsigned int user_vpn_min; // first virtuel page index in user space 550 unsigned int user_vpn_max; // last virtual page index in user space 551 unsigned int vpn; // current virtual page index in user space 552 unsigned int ppn; // physical page number 553 unsigned int flags; // page protection flags 554 unsigned int ix2; // page index in IOMMU PT1 page table 555 unsigned int addr; // buffer address for IOC peripheral 556 unsigned int ppn_first; // first physical page number for user buffer 557 535 558 // check buffer alignment 536 if ( (unsigned int)user_vaddr & 0x3 ) return 1; 537 538 unsigned int* ioc_address = (unsigned int*) &seg_ioc_base ; 539 540 unsigned int block_size = ioc_address[BLOCK_DEVICE_BLOCK_SIZE]; 541 unsigned int length = count*block_size; 559 if ((unsigned int) user_vaddr & 0x3) { 560 return 1; 561 } 562 563 unsigned int * ioc_address = (unsigned int *) &seg_ioc_base ; 564 565 unsigned int block_size = ioc_address[BLOCK_DEVICE_BLOCK_SIZE]; 566 unsigned int length = count * block_size; 542 567 543 568 // get user space page table virtual address 544 unsigned int task_id 545 unsigned int user_pt_vbase = _get_context_slot( task_id, CTX_PTAB_ID);546 569 unsigned int task_id = _get_current_task_id(); 570 unsigned int user_pt_vbase = _get_context_slot(task_id, CTX_PTAB_ID); 571 547 572 user_vpn_min = user_vaddr >> 12; 548 573 user_vpn_max = (user_vaddr + length - 1) >> 12; 549 ix2 574 ix2 = 0; 550 575 551 576 // loop on all virtual pages covering the user buffer 552 for ( vpn = user_vpn_min ; vpn <= user_vpn_max ; vpn++ ) 553 { 577 for (vpn = user_vpn_min; vpn <= user_vpn_max; vpn++) { 554 578 // get ppn and flags for each vpn 555 unsigned int ko = _v2p_translate( (page_table_t*)user_pt_vbase, 556 vpn, 557 &ppn, 558 &flags ); 579 unsigned int ko = _v2p_translate((page_table_t *) user_pt_vbase, vpn, &ppn, &flags); 559 580 560 581 // check access rights 561 if ( ko ) return 2; // unmapped 562 if ( (flags & PTE_U) == 0 ) return 3; // not in user space 563 if ( ( (flags & PTE_W) == 0 ) && to_mem ) return 4; // not writable 582 if (ko) { 583 return 2; // unmapped 584 } 585 if ((flags & PTE_U) == 0) { 586 return 3; // not in user space 587 } 588 if (((flags & PTE_W) == 0 ) && to_mem) { 589 return 4; // not writable 590 } 564 591 565 592 // save first ppn value 566 if ( ix2 == 0 ) ppn_first = ppn; 567 568 if ( IOMMU_ACTIVE ) // the user buffer must be remapped in the I/0 space 569 { 593 if (ix2 == 0) { 594 ppn_first = ppn; 595 } 596 597 if (IOMMU_ACTIVE) { 598 // the user buffer must be remapped in the I/0 space 570 599 // check buffer length < 2 Mbytes 571 if ( ix2 > 511 ) return 2; 600 if (ix2 > 511) { 601 return 2; 602 } 572 603 573 604 // map the physical page in IOMMU page table 574 _iommu_add_pte2( _ioc_iommu_ix1, // PT1 index 575 ix2, // PT2 index 576 ppn, // Physical page number 577 flags ); // Protection flags 605 _iommu_add_pte2( 606 _ioc_iommu_ix1, // PT1 index 607 ix2, // PT2 index 608 ppn, // Physical page number 609 flags); // Protection flags 578 610 } 579 else // no IOMMU : check that physical pages are contiguous 580 { 581 if ( (ppn - ppn_first) != ix2 ) return 5; // split physical buffer 611 else { 612 // no IOMMU : check that physical pages are contiguous 613 if ((ppn - ppn_first) != ix2) { 614 return 5; // split physical buffer 615 } 582 616 } 583 617 584 618 // increment page index 585 619 ix2++; … … 590 624 591 625 // invalidate data cache in case of memory write 592 if ( to_mem ) _dcache_buf_invalidate( (void*)user_vaddr, length ); 626 if (to_mem) { 627 _dcache_buf_invalidate((void *) user_vaddr, length); 628 } 593 629 594 630 // compute buffer base address for IOC depending on IOMMU activation 595 if ( IOMMU_ACTIVE ) addr = (_ioc_iommu_ix1) << 21 | (user_vaddr & 0xFFF); 596 else addr = (ppn_first << 12) | (user_vaddr & 0xFFF); 631 if (IOMMU_ACTIVE) { 632 addr = (_ioc_iommu_ix1) << 21 | (user_vaddr & 0xFFF); 633 } 634 else { 635 addr = (ppn_first << 12) | (user_vaddr & 0xFFF); 636 } 597 637 598 638 // get the lock on ioc device 599 _get_lock( &_ioc_lock);639 _get_lock(&_ioc_lock); 600 640 601 641 // peripheral configuration 602 ioc_address[BLOCK_DEVICE_BUFFER] = addr; 603 ioc_address[BLOCK_DEVICE_COUNT] = count; 604 ioc_address[BLOCK_DEVICE_LBA] = lba; 605 if ( to_mem == 0 ) ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_WRITE; 606 else ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_READ; 607 608 return 0; 609 } 642 ioc_address[BLOCK_DEVICE_BUFFER] = addr; 643 ioc_address[BLOCK_DEVICE_COUNT] = count; 644 ioc_address[BLOCK_DEVICE_LBA] = lba; 645 if (to_mem == 0) { 646 ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_WRITE; 647 } 648 else { 649 ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_READ; 650 } 651 652 return 0; 653 } 654 655 610 656 ///////////////////////////////////////////////////////////////////////////////// 611 657 // _ioc_completed() … … 617 663 // Returns 0 if success, > 0 if error. 618 664 ///////////////////////////////////////////////////////////////////////////////// 619 unsigned int _ioc_completed() 620 { 621 unsigned int ret; 622 unsigned int ix2; 665 unsigned int _ioc_completed() { 666 unsigned int ret; 667 unsigned int ix2; 623 668 624 669 // busy waiting 625 while (_ioc_done == 0) 670 while (_ioc_done == 0) { 626 671 asm volatile("nop"); 672 } 627 673 628 674 // unmap the buffer from IOMMU page table if IOMMU is activated 629 if ( IOMMU_ACTIVE ) 630 { 631 unsigned int* iob_address = (unsigned int*) &seg_iob_base; 632 633 for ( ix2 = 0 ; ix2 < _ioc_iommu_npages ; ix2++ ) 634 { 675 if (IOMMU_ACTIVE) { 676 unsigned int * iob_address = (unsigned int *) &seg_iob_base; 677 678 for (ix2 = 0; ix2 < _ioc_iommu_npages; ix2++) { 635 679 // unmap the page in IOMMU page table 636 _iommu_inval_pte2( _ioc_iommu_ix1, // PT1 index 637 ix2 ); // PT2 index 680 _iommu_inval_pte2( 681 _ioc_iommu_ix1, // PT1 index 682 ix2 ); // PT2 index 638 683 639 684 // clear IOMMU TLB … … 644 689 // test IOC status 645 690 if ((_ioc_status != BLOCK_DEVICE_READ_SUCCESS) 646 && (_ioc_status != BLOCK_DEVICE_WRITE_SUCCESS)) ret = 1; // error 647 else ret = 0; // success 691 && (_ioc_status != BLOCK_DEVICE_WRITE_SUCCESS)) { 692 ret = 1; // error 693 } 694 else { 695 ret = 0; // success 696 } 648 697 649 698 // reset synchronization variables 650 699 _ioc_done = 0; 651 asm volatile 700 asm volatile("sync"); 652 701 _ioc_lock = 0; 653 702 654 703 return ret; 655 704 } 705 706 656 707 /////////////////////////////////////////////////////////////////////////////// 657 708 // _ioc_read() … … 662 713 // Returns 0 if success, > 0 if error. 663 714 /////////////////////////////////////////////////////////////////////////////// 664 unsigned int _ioc_read( unsigned int lba,665 void* buffer,666 unsigned int count )667 { 668 return _ioc_access( 1, // read access669 lba,670 (unsigned int)buffer, 671 count ); 672 } 715 unsigned int _ioc_read(unsigned int lba, void * buffer, unsigned int count) { 716 return _ioc_access( 717 1, // read access 718 lba, 719 (unsigned int) buffer, 720 count); 721 } 722 723 673 724 /////////////////////////////////////////////////////////////////////////////// 674 725 // _ioc_write() … … 679 730 // Returns 0 if success, > 0 if error. 680 731 /////////////////////////////////////////////////////////////////////////////// 681 unsigned int _ioc_write( unsigned int lba,682 const void* buffer,683 unsigned int count )684 { 685 return _ioc_access( 0, // write access686 lba,687 (unsigned int)buffer, 688 count ); 689 } 732 unsigned int _ioc_write(unsigned int lba, const void * buffer, unsigned int count) { 733 return _ioc_access( 734 0, // write access 735 lba, 736 (unsigned int) buffer, 737 count); 738 } 739 740 690 741 /////////////////////////////////////////////////////////////////////////////// 691 742 // _ioc_get_status() … … 693 744 // Returns 0 if success, > 0 if error. 694 745 /////////////////////////////////////////////////////////////////////////////// 695 unsigned int _ioc_get_status(unsigned int* status) 696 { 746 unsigned int _ioc_get_status(unsigned int * status) { 697 747 // get IOC base address 698 unsigned int * ioc_address = (unsigned int*) &seg_ioc_base;748 unsigned int * ioc_address = (unsigned int *) &seg_ioc_base; 699 749 700 750 *status = ioc_address[BLOCK_DEVICE_STATUS]; // read status & reset IRQ 701 751 return 0; 702 752 } 753 703 754 704 755 ////////////////////////////////////////////////////////////////////////////////// … … 719 770 720 771 #if NB_DMAS_MAX > 0 721 in_unckdata unsigned int _dma_lock[NB_DMAS_MAX * NB_CLUSTERS]722 = { [0 ... (NB_DMAS_MAX * NB_CLUSTERS)-1] = 0 };723 724 in_unckdata volatile unsigned int _dma_done[NB_DMAS_MAX * NB_CLUSTERS] 725 = { [0 ... (NB_DMAS_MAX * NB_CLUSTERS)-1] = 0 }; 726 727 in_unckdata volatile unsigned int _dma_status[NB_DMAS_MAX * NB_CLUSTERS];728 729 in_unckdata unsigned int _dma_iommu_ix1 = 1;730 731 in_unckdata unsigned int 772 in_unckdata unsigned int _dma_lock[NB_DMAS_MAX * NB_CLUSTERS] = { 773 [0 ... (NB_DMAS_MAX * NB_CLUSTERS) - 1] = 0 774 }; 775 776 in_unckdata volatile unsigned int _dma_done[NB_DMAS_MAX * NB_CLUSTERS] = { 777 [0 ... (NB_DMAS_MAX * NB_CLUSTERS) - 1] = 0 778 }; 779 780 in_unckdata volatile unsigned int _dma_status[NB_DMAS_MAX * NB_CLUSTERS]; 781 in_unckdata unsigned int _dma_iommu_ix1 = 1; 782 in_unckdata unsigned int _dma_iommu_npages[NB_DMAS_MAX * NB_CLUSTERS]; 732 783 #endif 733 784 … … 735 786 // _dma_reset_irq() 736 787 ////////////////////////////////////////////////////////////////////////////////// 737 unsigned int _dma_reset_irq( unsigned int cluster_id, 738 unsigned int channel_id ) 739 { 788 unsigned int _dma_reset_irq(unsigned int cluster_id, unsigned int channel_id) { 740 789 #if NB_DMAS_MAX > 0 741 790 // parameters checking 742 if ( cluster_id >= NB_CLUSTERS ) return 1; 743 if ( channel_id >= NB_DMAS_MAX ) return 1; 791 if (cluster_id >= NB_CLUSTERS) { 792 return 1; 793 } 794 if (channel_id >= NB_DMAS_MAX) { 795 return 1; 796 } 744 797 745 798 // compute DMA base address 746 unsigned int * dma_address = (unsigned int*)( (char*)&seg_dma_base +747 (cluster_id * (unsigned)CLUSTER_SIZE));748 749 dma_address[channel_id *DMA_SPAN + DMA_RESET] = 0;799 unsigned int * dma_address = (unsigned int *) ((char *) &seg_dma_base + 800 (cluster_id * (unsigned) CLUSTER_SIZE)); 801 802 dma_address[channel_id * DMA_SPAN + DMA_RESET] = 0; 750 803 return 0; 751 804 #else … … 754 807 } 755 808 809 756 810 ////////////////////////////////////////////////////////////////////////////////// 757 811 // _dma_get_status() 758 812 ////////////////////////////////////////////////////////////////////////////////// 759 unsigned int _dma_get_status( unsigned int cluster_id, 760 unsigned int channel_id, 761 unsigned int* status ) 762 { 813 unsigned int _dma_get_status(unsigned int cluster_id, unsigned int channel_id, unsigned int * status) { 763 814 #if NB_DMAS_MAX > 0 764 815 // parameters checking 765 if ( cluster_id >= NB_CLUSTERS ) return 1; 766 if ( channel_id >= NB_DMAS_MAX ) return 1; 816 if (cluster_id >= NB_CLUSTERS) { 817 return 1; 818 } 819 if (channel_id >= NB_DMAS_MAX) { 820 return 1; 821 } 767 822 768 823 // compute DMA base address 769 unsigned int * dma_address = (unsigned int*)( (char*)&seg_dma_base +770 (cluster_id * (unsigned)CLUSTER_SIZE));771 772 *status = dma_address[channel_id *DMA_SPAN + DMA_LEN];824 unsigned int * dma_address = (unsigned int *) ((char *) &seg_dma_base + 825 (cluster_id * (unsigned) CLUSTER_SIZE)); 826 827 *status = dma_address[channel_id * DMA_SPAN + DMA_LEN]; 773 828 return 0; 774 829 #else … … 776 831 #endif 777 832 } 833 778 834 779 835 ////////////////////////////////////////////////////////////////////////////////// … … 798 854 // Returns 0 if success, > 0 if error. 799 855 ////////////////////////////////////////////////////////////////////////////////// 800 unsigned int _dma_transfer( unsigned int dev_type,801 unsigned int to_user,802 unsigned int offset,803 unsigned int user_vaddr,804 unsigned int length )805 {856 unsigned int _dma_transfer( 857 unsigned int dev_type, 858 unsigned int to_user, 859 unsigned int offset, 860 unsigned int user_vaddr, 861 unsigned int length) { 806 862 #if NB_DMAS_MAX > 0 807 unsigned int ko;// unsuccessfull V2P translation808 unsigned int flags;// protection flags809 unsigned int ppn;// physical page number810 unsigned int user_pbase;// user buffer pbase address811 unsigned int device_pbase;// frame buffer pbase address812 unsigned int device_vaddr;// device buffer vbase address863 unsigned int ko; // unsuccessfull V2P translation 864 unsigned int flags; // protection flags 865 unsigned int ppn; // physical page number 866 unsigned int user_pbase; // user buffer pbase address 867 unsigned int device_pbase; // frame buffer pbase address 868 unsigned int device_vaddr; // device buffer vbase address 813 869 814 870 // check user buffer address and length alignment 815 if ( (user_vaddr & 0x3) || (length & 0x3) ) 816 { 871 if ((user_vaddr & 0x3) || (length & 0x3)) { 817 872 _get_lock(&_tty_put_lock); 818 873 _puts("\n[GIET ERROR] in _dma_transfer : user buffer not word aligned\n"); … … 822 877 823 878 // get DMA channel and compute DMA vbase address 824 unsigned int 825 unsigned int dma_id = _get_context_slot( task_id, CTX_DMA_ID);826 unsigned int 827 unsigned int 828 unsigned int * dma_base = (unsigned int*)( (char*)&seg_dma_base +829 (cluster_id * (unsigned)CLUSTER_SIZE));879 unsigned int task_id = _get_current_task_id(); 880 unsigned int dma_id = _get_context_slot(task_id, CTX_DMA_ID); 881 unsigned int cluster_id = dma_id / NB_DMAS_MAX; 882 unsigned int loc_id = dma_id % NB_DMAS_MAX; 883 unsigned int * dma_base = (unsigned int *) ((char *) &seg_dma_base + 884 (cluster_id * (unsigned) CLUSTER_SIZE)); 830 885 831 886 // get page table address 832 unsigned int user_ptab = _get_context_slot( task_id, CTX_PTAB_ID);887 unsigned int user_ptab = _get_context_slot( task_id, CTX_PTAB_ID); 833 888 834 889 // get peripheral buffer virtual address 835 if ( dev_type) device_vaddr = (unsigned int)&seg_nic_base + offset; 836 else device_vaddr = (unsigned int)&seg_fbf_base + offset; 890 if ( dev_type) { 891 device_vaddr = (unsigned int) &seg_nic_base + offset; 892 } 893 else { 894 device_vaddr = (unsigned int) &seg_fbf_base + offset; 895 } 837 896 838 897 // get device buffer physical address 839 ko = _v2p_translate( (page_table_t*)user_ptab, 840 (device_vaddr >> 12), 841 &ppn, 842 &flags ); 843 if ( ko ) 844 { 898 ko = _v2p_translate((page_table_t *) user_ptab, (device_vaddr >> 12), &ppn, &flags); 899 if (ko) { 845 900 _get_lock(&_tty_put_lock); 846 901 _puts("\n[GIET ERROR] in _dma_transfer : device buffer unmapped\n"); … … 851 906 852 907 // Compute user buffer physical address 853 ko = _v2p_translate( (page_table_t*)user_ptab, 854 (user_vaddr >> 12), 855 &ppn, 856 &flags ); 857 if ( ko ) 858 { 908 ko = _v2p_translate( (page_table_t*)user_ptab, (user_vaddr >> 12), &ppn, &flags); 909 if (ko) { 859 910 _get_lock(&_tty_put_lock); 860 911 _puts("\n[GIET ERROR] in _dma_transfer() : user buffer unmapped\n"); … … 862 913 return 3; 863 914 } 864 if ( (flags & PTE_U) == 0 ) 865 { 915 if ((flags & PTE_U) == 0) { 866 916 _get_lock(&_tty_put_lock); 867 917 _puts("[GIET ERROR] in _dma_transfer() : user buffer not in user space\n"); … … 869 919 return 4; 870 920 } 871 if ( ( (flags & PTE_W) == 0 ) && to_user ) 872 { 921 if (((flags & PTE_W) == 0 ) && to_user) { 873 922 _get_lock(&_tty_put_lock); 874 923 _puts("\n[GIET ERROR] in _dma_transfer() : user buffer not writable\n"); … … 878 927 user_pbase = (ppn << 12) | (user_vaddr & 0x00000FFF); 879 928 880 /* This is a draft for IOMMU support881 929 /* This is a draft for IOMMU support 930 882 931 // loop on all virtual pages covering the user buffer 883 932 unsigned int user_vpn_min = user_vaddr >> 12; … … 888 937 for ( vpn = user_vpn_min ; vpn <= user_vpn_max ; vpn++ ) 889 938 { 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 _iommu_add_pte2( ix1,// PT1 index911 ix2,// PT2 index912 ppn,// physical page number913 flags );// protection flags914 915 916 917 918 919 920 921 939 // get ppn and flags for each vpn 940 unsigned int ko = _v2p_translate( (page_table_t*)user_pt_vbase, 941 vpn, 942 &ppn, 943 &flags ); 944 945 // check access rights 946 if ( ko ) return 3; // unmapped 947 if ( (flags & PTE_U) == 0 ) return 4; // not in user space 948 if ( ( (flags & PTE_W) == 0 ) && to_user ) return 5; // not writable 949 950 // save first ppn value 951 if ( ix2 == 0 ) ppn_first = ppn; 952 953 if ( IOMMU_ACTIVE ) // the user buffer must be remapped in the I/0 space 954 { 955 // check buffer length < 2 Mbytes 956 if ( ix2 > 511 ) return 2; 957 958 // map the physical page in IOMMU page table 959 _iommu_add_pte2( ix1, // PT1 index 960 ix2, // PT2 index 961 ppn, // physical page number 962 flags ); // protection flags 963 } 964 else // no IOMMU : check that physical pages are contiguous 965 { 966 if ( (ppn - ppn_first) != ix2 ) return 6; // split physical buffer 967 } 968 969 // increment page index 970 ix2++; 922 971 } // end for vpn 923 972 … … 928 977 929 978 // invalidate data cache in case of memory write 930 if ( to_user ) _dcache_buf_invalidate( (void*)user_vaddr, length ); 931 979 if (to_user) { 980 _dcache_buf_invalidate((void *) user_vaddr, length); 981 } 982 932 983 // get the lock 933 _get_lock( &_dma_lock[dma_id]);984 _get_lock(&_dma_lock[dma_id]); 934 985 935 986 // DMA configuration 936 if ( to_user ) 937 { 938 dma_base[loc_id*DMA_SPAN + DMA_SRC] = (unsigned int)device_pbase; 939 dma_base[loc_id*DMA_SPAN + DMA_DST] = (unsigned int)user_pbase; 940 } 941 else 942 { 943 dma_base[loc_id*DMA_SPAN + DMA_SRC] = (unsigned int)user_pbase; 944 dma_base[loc_id*DMA_SPAN + DMA_DST] = (unsigned int)device_pbase; 945 } 946 dma_base[loc_id*DMA_SPAN + DMA_LEN] = (unsigned int)length; 947 948 return 0; 949 987 if (to_user) { 988 dma_base[loc_id * DMA_SPAN + DMA_SRC] = (unsigned int) device_pbase; 989 dma_base[loc_id * DMA_SPAN + DMA_DST] = (unsigned int) user_pbase; 990 } 991 else { 992 dma_base[loc_id * DMA_SPAN + DMA_SRC] = (unsigned int) user_pbase; 993 dma_base[loc_id * DMA_SPAN + DMA_DST] = (unsigned int) device_pbase; 994 } 995 dma_base[loc_id * DMA_SPAN + DMA_LEN] = (unsigned int) length; 996 997 return 0; 950 998 #else //NB_DMAS_MAX == 0 951 952 999 return -1; 953 954 1000 #endif 955 1001 } // end _dma_transfer() 1002 956 1003 957 1004 ////////////////////////////////////////////////////////////////////////////////// … … 963 1010 // (1 == read error / 2 == DMA idle error / 3 == write error) 964 1011 ////////////////////////////////////////////////////////////////////////////////// 965 unsigned int _dma_completed() 966 { 1012 unsigned int _dma_completed() { 967 1013 #if NB_DMAS_MAX > 0 968 unsigned int 969 unsigned int dma_id = _get_context_slot( task_id, CTX_DMA_ID);970 unsigned int 1014 unsigned int task_id = _get_current_task_id(); 1015 unsigned int dma_id = _get_context_slot(task_id, CTX_DMA_ID); 1016 unsigned int dma_ret; 971 1017 972 1018 // busy waiting with a pseudo random delay between bus access 973 while (_dma_done[dma_id] == 0) 974 {975 unsigned int delay = (( _proctime() ^ _procid()<<4 ) & 0x3F) + 1;976 asm volatile("move $3, %0\n"977 "loop_nic_completed:\n"978 "addi $3, $3, -1\n"979 "bnez $3, loop_nic_completed\n"980 "nop\n"981 982 : "r"(delay)983 : "$3");984 } 985 986 /* draft support for IOMMU1019 while (_dma_done[dma_id] == 0) { 1020 unsigned int delay = (( _proctime() ^ _procid() << 4) & 0x3F) + 1; 1021 asm volatile( 1022 "move $3, %0 \n" 1023 "loop_nic_completed: \n" 1024 "addi $3, $3, -1 \n" 1025 "bnez $3, loop_nic_completed \n" 1026 "nop \n" 1027 : 1028 : "r" (delay) 1029 : "$3"); 1030 } 1031 1032 /* draft support for IOMMU 987 1033 // unmap the buffer from IOMMU page table if IOMMU is activated 988 1034 if ( GIET_IOMMU_ACTIVE ) 989 1035 { 990 991 992 993 994 995 996 997 998 _iommu_inval_pte2( ix1,// PT1 index999 1000 1001 1002 1003 1004 } 1005 */1036 unsigned int* iob_address = (unsigned int*)&seg_iob_base; 1037 1038 unsigned int ix1 = _dma_iommu_ix1 + dma_id; 1039 unsigned int ix2; 1040 1041 for ( ix2 = 0 ; ix2 < _dma_iommu_npages[dma_id] ; ix2++ ) 1042 { 1043 // unmap the page in IOMMU page table 1044 _iommu_inval_pte2( ix1, // PT1 index 1045 ix2 ); // PT2 index 1046 1047 // clear IOMMU TLB 1048 iob_address[IOB_INVAL_PTE] = (ix1 << 21) | (ix2 << 12); 1049 } 1050 } 1051 */ 1006 1052 1007 1053 // reset synchronization variables … … 1019 1065 1020 1066 ////////////////////////////////////////////////////////////////////////////////// 1021 // 1067 // VciFrameBuffer driver 1022 1068 ////////////////////////////////////////////////////////////////////////////////// 1023 1069 // The vci_frame_buffer device can be accessed directly by software with memcpy(), … … 1041 1087 // - length : number of bytes to be transfered. 1042 1088 ////////////////////////////////////////////////////////////////////////////////// 1043 unsigned int _fb_sync_write( unsigned int offset, 1044 const void* buffer, 1045 unsigned int length ) 1046 { 1047 unsigned char *fb_address = (unsigned char*)&seg_fbf_base + offset; 1048 memcpy((void*)fb_address, (void*)buffer, length); 1049 return 0; 1050 } 1089 unsigned int _fb_sync_write(unsigned int offset, const void * buffer, unsigned int length) { 1090 unsigned char * fb_address = (unsigned char *) &seg_fbf_base + offset; 1091 memcpy((void *) fb_address, (void *) buffer, length); 1092 return 0; 1093 } 1094 1051 1095 1052 1096 ////////////////////////////////////////////////////////////////////////////////// … … 1057 1101 // - length : number of bytes to be transfered. 1058 1102 ////////////////////////////////////////////////////////////////////////////////// 1059 unsigned int _fb_sync_read( unsigned int offset, 1060 const void* buffer, 1061 unsigned int length ) 1062 { 1063 unsigned char *fb_address = (unsigned char*)&seg_fbf_base + offset; 1064 memcpy((void*)buffer, (void*)fb_address, length); 1065 return 0; 1066 } 1103 unsigned int _fb_sync_read(unsigned int offset, const void * buffer, unsigned int length) { 1104 unsigned char * fb_address = (unsigned char *) &seg_fbf_base + offset; 1105 memcpy((void *) buffer, (void *) fb_address, length); 1106 return 0; 1107 } 1108 1067 1109 1068 1110 ////////////////////////////////////////////////////////////////////////////////// … … 1074 1116 // Returns 0 if success, > 0 if error. 1075 1117 ////////////////////////////////////////////////////////////////////////////////// 1076 unsigned int _fb_write( unsigned int offset, 1077 const void* buffer, 1078 unsigned int length ) 1079 { 1080 return _dma_transfer( 0, // frame buffer 1081 0, // write 1082 offset, 1083 (unsigned int)buffer, 1084 length ); 1085 } 1118 unsigned int _fb_write(unsigned int offset, const void * buffer, unsigned int length) { 1119 return _dma_transfer( 1120 0, // frame buffer 1121 0, // write 1122 offset, 1123 (unsigned int) buffer, 1124 length); 1125 } 1126 1086 1127 1087 1128 ////////////////////////////////////////////////////////////////////////////////// … … 1093 1134 // Returns 0 if success, > 0 if error. 1094 1135 ////////////////////////////////////////////////////////////////////////////////// 1095 unsigned int _fb_read( unsigned int offset, 1096 const void* buffer, 1097 unsigned int length ) 1098 { 1099 return _dma_transfer( 0, // frame buffer 1100 1, // read 1101 offset, 1102 (unsigned int)buffer, 1103 length ); 1104 } 1136 unsigned int _fb_read(unsigned int offset, const void * buffer, unsigned int length) { 1137 return _dma_transfer( 1138 0, // frame buffer 1139 1, // read 1140 offset, 1141 (unsigned int) buffer, 1142 length); 1143 } 1144 1105 1145 1106 1146 ////////////////////////////////////////////////////////////////////////////////// … … 1111 1151 // (1 == read error / 2 == DMA idle error / 3 == write error) 1112 1152 ////////////////////////////////////////////////////////////////////////////////// 1113 unsigned int _fb_completed() 1114 { 1153 unsigned int _fb_completed() { 1115 1154 return _dma_completed(); 1116 1155 } 1117 1156 1118 1157 ////////////////////////////////////////////////////////////////////////////////// 1119 // 1158 // VciMultiNic driver 1120 1159 ////////////////////////////////////////////////////////////////////////////////// 1121 1160 // The VciMultiNic device can be accessed directly by software with memcpy(), … … 1139 1178 // - length : number of bytes to be transfered. 1140 1179 ////////////////////////////////////////////////////////////////////////////////// 1141 unsigned int _nic_sync_write( unsigned int offset, 1142 const void* buffer, 1143 unsigned int length ) 1144 { 1145 unsigned char *nic_address = (unsigned char*)&seg_nic_base + offset; 1146 memcpy((void*)nic_address, (void*)buffer, length); 1147 return 0; 1148 } 1180 unsigned int _nic_sync_write(unsigned int offset, const void * buffer, unsigned int length) { 1181 unsigned char * nic_address = (unsigned char *) &seg_nic_base + offset; 1182 memcpy((void *) nic_address, (void *) buffer, length); 1183 return 0; 1184 } 1185 1149 1186 1150 1187 ////////////////////////////////////////////////////////////////////////////////// … … 1155 1192 // - length : number of bytes to be transfered. 1156 1193 ////////////////////////////////////////////////////////////////////////////////// 1157 unsigned int _nic_sync_read( unsigned int offset, 1158 const void* buffer, 1159 unsigned int length ) 1160 { 1161 unsigned char *nic_address = (unsigned char*)&seg_nic_base + offset; 1162 memcpy((void*)buffer, (void*)nic_address, length); 1163 return 0; 1164 } 1194 unsigned int _nic_sync_read(unsigned int offset, const void * buffer, unsigned int length) { 1195 unsigned char *nic_address = (unsigned char *) &seg_nic_base + offset; 1196 memcpy((void *) buffer, (void *) nic_address, length); 1197 return 0; 1198 } 1199 1165 1200 1166 1201 ////////////////////////////////////////////////////////////////////////////////// … … 1172 1207 // Returns 0 if success, > 0 if error. 1173 1208 ////////////////////////////////////////////////////////////////////////////////// 1174 unsigned int _nic_write( unsigned int offset, 1175 const void* buffer, 1176 unsigned int length ) 1177 { 1178 return _dma_transfer( 1, // NIC 1179 0, // write 1180 offset, 1181 (unsigned int)buffer, 1182 length ); 1183 } 1209 unsigned int _nic_write(unsigned int offset, const void * buffer, unsigned int length) { 1210 return _dma_transfer( 1211 1, // NIC 1212 0, // write 1213 offset, 1214 (unsigned int) buffer, 1215 length ); 1216 } 1217 1184 1218 1185 1219 ////////////////////////////////////////////////////////////////////////////////// … … 1191 1225 // Returns 0 if success, > 0 if error. 1192 1226 ////////////////////////////////////////////////////////////////////////////////// 1193 unsigned int _nic_read( unsigned int offset, 1194 const void* buffer, 1195 unsigned int length ) 1196 { 1197 return _dma_transfer( 1, // NIC 1198 1, // read 1199 offset, 1200 (unsigned int)buffer, 1201 length ); 1202 } 1227 unsigned int _nic_read(unsigned int offset, const void * buffer, unsigned int length) { 1228 return _dma_transfer( 1229 1, // NIC 1230 1, // read 1231 offset, 1232 (unsigned int) buffer, 1233 length ); 1234 } 1235 1203 1236 1204 1237 ////////////////////////////////////////////////////////////////////////////////// … … 1209 1242 // (1 == read error / 2 == DMA idle error / 3 == write error) 1210 1243 ////////////////////////////////////////////////////////////////////////////////// 1211 unsigned int _nic_completed() 1212 { 1244 unsigned int _nic_completed() { 1213 1245 return _dma_completed(); 1214 1246 } 1215 1247 1248 // Local Variables: 1249 // tab-width: 4 1250 // c-basic-offset: 4 1251 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 1252 // indent-tabs-mode: nil 1253 // End: 1254 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 1255 -
soft/giet_vm/sys/drivers.h
r218 r228 16 16 extern volatile unsigned char _timer_event[]; 17 17 18 unsigned int _timer_start( unsigned int cluster_id, 19 unsigned int local_id, 20 unsigned int period ); 18 unsigned int _timer_start(unsigned int cluster_id, unsigned int local_id, unsigned int period); 19 unsigned int _timer_stop(unsigned int cluster_id, unsigned int local_id); 20 unsigned int _timer_reset_irq(unsigned int cluster_id, unsigned int local_id); 21 unsigned int _timer_reset_irq_cpt(unsigned int cluster_id, unsigned int local_id); 21 22 22 unsigned int _timer_stop( unsigned int cluster_id,23 unsigned int local_id );24 25 26 unsigned int _timer_reset_irq( unsigned int cluster_id,27 unsigned int local_id );28 23 29 24 /////////////////////////////////////////////////////////////////////////////////// … … 33 28 extern volatile unsigned char _tty_get_buf[]; 34 29 extern volatile unsigned char _tty_get_full[]; 35 extern unsigned int 30 extern unsigned int _tty_put_lock; 36 31 37 unsigned int _tty_write( const char* buffer, 38 unsigned int length); 39 40 unsigned int _tty_read( char* buffer, 41 unsigned int length); 42 43 unsigned int _tty_get_char( unsigned int tty_id, 44 unsigned char* buffer); 32 unsigned int _tty_write(const char * buffer, unsigned int length); 33 unsigned int _tty_read(char * buffer, unsigned int length); 34 unsigned int _tty_get_char(unsigned int tty_id, unsigned char * buffer); 45 35 46 36 /////////////////////////////////////////////////////////////////////////////////// … … 48 38 /////////////////////////////////////////////////////////////////////////////////// 49 39 50 unsigned int _icu_get_index(unsigned int cluster_id, 51 unsigned int proc_id, 52 unsigned int* buffer ); 53 54 unsigned int _icu_set_mask( unsigned int cluster_id, 55 unsigned int proc_id, 56 unsigned int mask, 57 unsigned int is_timer ); 40 unsigned int _icu_get_index(unsigned int cluster_id, unsigned int proc_id, unsigned int * buffer); 41 unsigned int _icu_set_mask( 42 unsigned int cluster_id, 43 unsigned int proc_id, 44 unsigned int mask, 45 unsigned int is_timer); 58 46 59 47 /////////////////////////////////////////////////////////////////////////////////// … … 61 49 /////////////////////////////////////////////////////////////////////////////////// 62 50 63 extern volatile unsigned int 64 extern volatile unsigned int 65 extern unsigned int 66 extern unsigned int 67 extern unsigned int 51 extern volatile unsigned int _ioc_status; 52 extern volatile unsigned int _ioc_done; 53 extern unsigned int _ioc_lock; 54 extern unsigned int _ioc_iommu_ix1; 55 extern unsigned int _ioc_iommu_npages; 68 56 69 57 70 unsigned int _ioc_write( unsigned int lba, 71 const void* buffer, 72 unsigned int count); 73 74 unsigned int _ioc_read( unsigned int lba, 75 void* buffer, 76 unsigned int count); 77 58 unsigned int _ioc_write(unsigned int lba, const void * buffer, unsigned int count); 59 unsigned int _ioc_read(unsigned int lba, void * buffer, unsigned int count); 78 60 unsigned int _ioc_completed(); 79 80 unsigned int _ioc_get_status( unsigned int* status); 61 unsigned int _ioc_get_status(unsigned int * status); 81 62 82 63 /////////////////////////////////////////////////////////////////////////////////// 83 // Multi DMA variables 64 // Multi DMA variables (vci_multi_dma) 84 65 /////////////////////////////////////////////////////////////////////////////////// 85 86 extern volatile unsigned int _dma_status[];87 extern volatile unsigned int _dma_done[];88 extern unsigned int _dma_lock[];89 extern unsigned int _dma_iommu_ix1;90 extern unsigned int _dma_iommu_npages[];91 66 92 unsigned int _dma_reset_irq( unsigned int cluster_id, 93 unsigned int local_id ); 67 extern volatile unsigned int _dma_status[]; 68 extern volatile unsigned int _dma_done[]; 69 extern unsigned int _dma_lock[]; 70 extern unsigned int _dma_iommu_ix1; 71 extern unsigned int _dma_iommu_npages[]; 94 72 95 unsigned int _dma_get_status( unsigned int cluster_id, 96 unsigned int local_id, 97 unsigned int* status ); 73 unsigned int _dma_reset_irq(unsigned int cluster_id, unsigned int local_id); 74 unsigned int _dma_get_status(unsigned int cluster_id, unsigned int local_id, unsigned int * status); 98 75 99 unsigned int _dma_transfer( unsigned int dev_type, 100 unsigned int to_user, 101 unsigned int offset, 102 unsigned int user_vaddr, 103 unsigned int length ); 76 unsigned int _dma_transfer( 77 unsigned int dev_type, 78 unsigned int to_user, 79 unsigned int offset, 80 unsigned int user_vaddr, 81 unsigned int length); 104 82 105 83 unsigned int _dma_completed(); … … 108 86 // Frame Buffer access functions (vci_frame_buffer) 109 87 /////////////////////////////////////////////////////////////////////////////////// 110 111 unsigned int _fb_sync_write(unsigned int offset,112 const void* buffer,113 unsigned int length);114 88 115 unsigned int _fb_sync_read( unsigned int offset, 116 const void* buffer, 117 unsigned int length); 118 119 unsigned int _fb_write( unsigned int offset, 120 const void* buffer, 121 unsigned int length); 122 123 unsigned int _fb_read( unsigned int offset, 124 const void* buffer, 125 unsigned int length); 89 unsigned int _fb_sync_write(unsigned int offset, const void * buffer, unsigned int length); 90 unsigned int _fb_sync_read( unsigned int offset, const void * buffer, unsigned int length); 91 unsigned int _fb_write( unsigned int offset, const void * buffer, unsigned int length); 92 unsigned int _fb_read( unsigned int offset, const void * buffer, unsigned int length); 126 93 127 94 unsigned int _fb_completed(); … … 131 98 /////////////////////////////////////////////////////////////////////////////////// 132 99 133 unsigned int _nic_sync_write(unsigned int offset, 134 const void* buffer, 135 unsigned int length); 136 137 unsigned int _nic_sync_read( unsigned int offset, 138 const void* buffer, 139 unsigned int length); 140 141 142 unsigned int _nic_write( unsigned int offset, 143 const void* buffer, 144 unsigned int length); 145 146 unsigned int _nic_read( unsigned int offset, 147 const void* buffer, 148 unsigned int length); 100 unsigned int _nic_sync_write(unsigned int offset, const void * buffer, unsigned int length); 101 unsigned int _nic_sync_read( unsigned int offset, const void * buffer, unsigned int length); 102 unsigned int _nic_write( unsigned int offset, const void * buffer, unsigned int length); 103 unsigned int _nic_read( unsigned int offset, const void * buffer, unsigned int length); 149 104 150 105 unsigned int _nic_completed(); … … 154 109 /////////////////////////////////////////////////////////////////////////////////// 155 110 156 unsigned int _gcd_write( unsigned int register_index, 157 unsigned int value); 158 159 unsigned int _gcd_read( unsigned int register_index, 160 unsigned int* buffer); 111 unsigned int _gcd_write(unsigned int register_index, unsigned int value); 112 unsigned int _gcd_read( unsigned int register_index, unsigned int * buffer); 161 113 162 114 163 115 #endif 164 116 117 // Local Variables: 118 // tab-width: 4 119 // c-basic-offset: 4 120 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 121 // indent-tabs-mode: nil 122 // End: 123 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 124 -
soft/giet_vm/sys/exc_handler.c
r218 r228 54 54 }; 55 55 56 static const char * exc_type[] = {56 static const char * exc_type[] = { 57 57 "strange unknown cause", 58 58 "illegal read address", … … 62 62 "breakpoint", 63 63 "reserved instruction", 64 "illegal coproc access" 64 "illegal coproc access", 65 65 "arithmetic overflow", 66 66 }; 67 67 68 static void _display_cause(unsigned int type) 69 {68 69 static void _display_cause(unsigned int type) { 70 70 _get_lock(&_tty_put_lock); 71 71 _puts("\n[GIET] Exception for task "); 72 _putd( _get_current_task_id());72 _putd(_get_current_task_id()); 73 73 _puts(" on processor "); 74 _putd( _procid());74 _putd(_procid()); 75 75 _puts(" at cycle "); 76 _putd( _proctime());76 _putd(_proctime()); 77 77 _puts("\n - type : "); 78 _puts( (char*)exc_type[type]);78 _puts((char *) exc_type[type]); 79 79 _puts("\n - EPC : "); 80 _putx( _get_epc());80 _putx(_get_epc()); 81 81 _puts("\n - BVAR : "); 82 _putx( _get_bvar());82 _putx(_get_bvar()); 83 83 _puts("\n"); 84 84 _puts("...Task desactivated\n"); … … 87 87 // goes to sleeping state 88 88 unsigned int task_id = _get_current_task_id(); 89 _set_context_slot( task_id, CTX_RUN_ID, 0 90 89 _set_context_slot( task_id, CTX_RUN_ID, 0); 90 91 91 // deschedule 92 92 _ctx_switch(); … … 103 103 static void _cause_ovf() { _display_cause(8); } 104 104 105 // Local Variables: 106 // tab-width: 4 107 // c-basic-offset: 4 108 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 109 // indent-tabs-mode: nil 110 // End: 111 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 112 -
soft/giet_vm/sys/hwr_mapping.h
r209 r228 90 90 91 91 #define XICU_REG(func, index) (((func)<<5)|(index)) 92 92 93 93 /* TIMER */ 94 94 enum TIMER_registers { … … 113 113 /* IOB */ 114 114 enum IOB_registers { 115 IOB_IOMMU_PTPR = 0, 116 IOB_IOMMU_ACTIVE = 1, 117 IOB_IOMMU_BVAR = 2, 118 IOB_IOMMU_ETR = 3, 119 IOB_IOMMU_BAD_ID = 4, 120 IOB_INVAL_PTE = 5, 121 IOB_IT_ADDR_IOMMU_LO = 6, 122 IOB_IT_ADDR_IOMMU_HI = 7, 123 IOB_IT_ADDRESS_BEGIN = 8, 115 IOB_IOMMU_PTPR = 0, /* R/W : Page Table Pointer Register */ 116 IOB_IOMMU_ACTIVE = 1, /* R/W : IOMMU activated if not 0 */ 117 IOB_IOMMU_BVAR = 2, /* R : Bad Virtual Address (unmapped) */ 118 IOB_IOMMU_ETR = 3, /* R : Error Type */ 119 IOB_IOMMU_BAD_ID = 4, /* R : Faulty Peripheral Index */ 120 IOB_INVAL_PTE = 5, /* W : Invalidate a PTE (virtual address) */ 121 IOB_IT_ADDR_IOMMU_LO = 6, /* W/R : 32 LSB bits for IOMMU IT*/ 122 IOB_IT_ADDR_IOMMU_HI = 7, /* W/R : 32 MSB bits for IOMMU IT */ 123 IOB_IT_ADDRESS_BEGIN = 8, /* R/W : Peripheral IT address (2 32 bits registers) */ 124 124 }; 125 125 … … 145 145 #endif 146 146 147 // Local Variables: 148 // tab-width: 4 149 // c-basic-offset: 4 150 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 151 // indent-tabs-mode: nil 152 // End: 153 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 154 -
soft/giet_vm/sys/irq_handler.c
r216 r228 20 20 21 21 #if NB_TIMERS_MAX 22 extern volatile unsigned char _user_timer_event[NB_CLUSTERS *NB_TIMERS_MAX] ;22 extern volatile unsigned char _user_timer_event[NB_CLUSTERS * NB_TIMERS_MAX] ; 23 23 #endif 24 24 25 25 /////////////////////////////////////////////////////////////////////////////////// 26 // 26 // _irq_demux() 27 27 // This function uses the ICU or XICU component (Interrupt Controler Unit) 28 28 // to get the interrupt vector entry. There is one ICU or XICU component per … … 40 40 // a global index : channel_id = cluster_id * NB_CHANNELS_MAX + loc_id 41 41 /////////////////////////////////////////////////////////////////////////////////// 42 void _irq_demux() 43 { 44 unsigned int pid = _procid(); 45 unsigned int irq_id; 42 void _irq_demux() { 43 unsigned int pid = _procid(); 44 unsigned int irq_id; 46 45 47 46 48 47 // get the highest priority active IRQ index 49 if ( _icu_get_index( pid / NB_PROCS_MAX, 50 pid % NB_PROCS_MAX, 51 &irq_id ) ) 52 { 48 if (_icu_get_index( pid / NB_PROCS_MAX, pid % NB_PROCS_MAX, &irq_id)) { 53 49 _get_lock(&_tty_put_lock); 54 50 _puts("\n[GIET ERROR] Strange... Wrong _icu_read in _irq_demux()\n"); … … 57 53 58 54 59 if ( irq_id < 32 ) // do nothing if no interrupt active 60 { 61 unsigned int entry = _get_interrupt_vector_entry(irq_id); 62 unsigned int isr_id = entry & 0x000000FF; 63 unsigned int channel_id = (entry>>16) & 0x0000FFFF; 64 if ( isr_id == ISR_SWITCH ) _isr_switch( channel_id ); 65 else if ( isr_id == ISR_IOC ) _isr_ioc(); 66 else if ( isr_id == ISR_DMA ) _isr_dma( channel_id ); 67 else if ( isr_id == ISR_TTY ) _isr_tty( channel_id ); 68 else if ( isr_id == ISR_TIMER ) _isr_timer( channel_id ); 69 else _isr_default(); 70 } 71 } 72 /////////////////////////////////////////////////////////////////////////////////// 73 // _isr_default() 55 if (irq_id < 32) { 56 // do nothing if no interrupt active 57 unsigned int entry = _get_interrupt_vector_entry(irq_id); 58 unsigned int isr_id = entry & 0x000000FF; 59 unsigned int channel_id = (entry >> 16) & 0x0000FFFF; 60 if ( isr_id == ISR_SWITCH) _isr_switch( channel_id); 61 else if ( isr_id == ISR_IOC ) _isr_ioc(); 62 else if ( isr_id == ISR_DMA ) _isr_dma(channel_id); 63 else if ( isr_id == ISR_TTY ) _isr_tty(channel_id); 64 else if ( isr_id == ISR_TIMER ) _isr_timer(channel_id); 65 else _isr_default(); 66 } 67 } 68 69 70 /////////////////////////////////////////////////////////////////////////////////// 71 // _isr_default() 74 72 // The default ISR is called when no specific ISR has been installed in the 75 73 // interrupt vector. It simply displays an error message on kernel TTY[0]. 76 74 /////////////////////////////////////////////////////////////////////////////////// 77 void _isr_default() 78 { 75 void _isr_default() { 79 76 _get_lock(&_tty_put_lock); 80 77 _puts("\n[GIET ERROR] Strange... Default ISR activated for processor "); … … 84 81 } 85 82 86 /////////////////////////////////////////////////////////////////////////////////// 87 // _isr_dma() 83 84 /////////////////////////////////////////////////////////////////////////////////// 85 // _isr_dma() 88 86 // This ISR handles all IRQs generated by the multi-channels DMA controlers. 89 87 // The multi_dma components can be distributed in the clusters. … … 94 92 // - it resets the synchronisation variable _dma_busy[dma_global_id]. 95 93 /////////////////////////////////////////////////////////////////////////////////// 96 void _isr_dma( unsigned int channel_id ) 97 { 94 void _isr_dma(unsigned int channel_id) { 98 95 #if NB_DMAS_MAX > 0 99 96 // compute cluster_id 100 unsigned int cluster_id = _procid() /NB_PROCS_MAX;97 unsigned int cluster_id = _procid() / NB_PROCS_MAX; 101 98 102 99 // compute dma_global_id 103 unsigned int dma_global_id = cluster_id *NB_DMAS_MAX + channel_id;100 unsigned int dma_global_id = cluster_id * NB_DMAS_MAX + channel_id; 104 101 105 102 // save DMA channel status 106 if ( _dma_get_status(cluster_id, 107 channel_id, 108 (unsigned int*)&_dma_status[dma_global_id] ) ) 109 { 103 if (_dma_get_status(cluster_id, channel_id, 104 (unsigned int *) &_dma_status[dma_global_id])) { 110 105 _get_lock(&_tty_put_lock); 111 106 _puts("[GIET ERROR] illegal DMA channel detected by _isr_dma\n"); … … 115 110 116 111 // reset DMA channel irq 117 if ( _dma_reset_irq( cluster_id, 118 channel_id) ) 119 { 112 if (_dma_reset_irq(cluster_id, channel_id)) { 120 113 _get_lock(&_tty_put_lock); 121 114 _puts("[GIET ERROR] illegal DMA channel detected by _isr_dma\n"); … … 133 126 134 127 /////////////////////////////////////////////////////////////////////////////////// 135 // 128 // _isr_ioc() 136 129 // There is only one IOC controler shared by all tasks. 137 130 // - The ISR save the status and acknowledge the IRQ. 138 131 // - It sets the _ioc_done variable to signal completion. 139 132 /////////////////////////////////////////////////////////////////////////////////// 140 void _isr_ioc() 141 { 142 // save status & reset IRQ 143 if ( _ioc_get_status( (unsigned int*)&_ioc_status ) ) 144 { 133 void _isr_ioc() { 134 // save status & reset IRQ 135 if (_ioc_get_status((unsigned int *) &_ioc_status )) { 145 136 _get_lock(&_tty_put_lock); 146 137 _puts("[GIET ERROR] bad access to IOC status detected by _isr_ioc\n"); … … 150 141 151 142 // signals completion 152 _ioc_done = 1; 153 } 154 155 /////////////////////////////////////////////////////////////////////////////////// 156 // _isr_timer() 143 _ioc_done = 1; 144 } 145 146 147 /////////////////////////////////////////////////////////////////////////////////// 148 // _isr_timer() 157 149 // This ISR handles the IRQs generated by the "user" timers (the IRQs generated 158 150 // by the "system" timers should be handled by the _isr_switch(). … … 164 156 // of the _timer_event[] array, and a log message is displayed on kernel terminal. 165 157 /////////////////////////////////////////////////////////////////////////////////// 166 void _isr_timer(unsigned int timer_id) 167 { 158 void _isr_timer(unsigned int timer_id) { 168 159 // compute cluster_id 169 unsigned int cluster_id = _procid() /NB_PROCS_MAX;160 unsigned int cluster_id = _procid() / NB_PROCS_MAX; 170 161 171 162 // aknowledge IRQ 172 if ( _timer_reset_irq( cluster_id, 173 timer_id ) ) 174 { 163 if (_timer_reset_irq( cluster_id, timer_id)) { 175 164 _get_lock(&_tty_put_lock); 176 165 _puts("[GIET ERROR] illegal timer index detected by _isr_timer\n"); … … 181 170 #if NB_TIMERS_MAX 182 171 // register the event 183 unsigned int timer_global_id = cluster_id *NB_TIMERS_MAX + timer_id;172 unsigned int timer_global_id = cluster_id * NB_TIMERS_MAX + timer_id; 184 173 _user_timer_event[timer_global_id] = 1; 185 174 #endif … … 188 177 _get_lock(&_tty_put_lock); 189 178 _puts("\n[GIET] User Timer IRQ at cycle "); 190 _putd( _proctime());179 _putd(_proctime()); 191 180 _puts("\n - cluster_id = "); 192 _putd( cluster_id);181 _putd(cluster_id); 193 182 _puts("\n - timer_id = "); 194 _putd( timer_id);183 _putd(timer_id); 195 184 _puts("\n"); 196 185 _release_lock(&_tty_put_lock); 197 186 } 187 198 188 199 189 /////////////////////////////////////////////////////////////////////////////////// … … 208 198 // A character is lost if the buffer is full when the ISR is executed. 209 199 /////////////////////////////////////////////////////////////////////////////////// 210 void _isr_tty(unsigned int tty_id) 211 { 200 void _isr_tty(unsigned int tty_id) { 212 201 // save character and reset IRQ 213 if ( _tty_get_char( tty_id, 214 (unsigned char*)&_tty_get_buf[tty_id] ) ) 215 { 202 if (_tty_get_char( tty_id, (unsigned char *) &_tty_get_buf[tty_id])) { 216 203 _get_lock(&_tty_put_lock); 217 204 _puts("[GIET ERROR] illegal tty index detected by _isr_tty\n"); … … 223 210 _tty_get_full[tty_id] = 1; 224 211 } 212 225 213 226 214 ///////////////////////////////////////////////////////////////////////////////////// … … 232 220 // The ISR acknowledges the IRQ and calls the _ctx_switch() function. 233 221 ///////////////////////////////////////////////////////////////////////////////////// 234 void _isr_switch( unsigned int timer_id) 235 { 222 void _isr_switch( unsigned int timer_id) { 236 223 // get cluster index and proc local index 237 224 unsigned int cluster_id = _procid() / NB_PROCS_MAX; 238 225 239 226 // acknowledge IRQ 240 if ( _timer_reset_irq( cluster_id, timer_id ) ) 241 { 227 if (_timer_reset_irq(cluster_id, timer_id)) { 242 228 _get_lock(&_tty_put_lock); 243 229 _puts("[GIET ERROR] illegal proc index detected by _isr_switch\n"); … … 250 236 } 251 237 238 239 // Local Variables: 240 // tab-width: 4 241 // c-basic-offset: 4 242 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 243 // indent-tabs-mode: nil 244 // End: 245 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 246 -
soft/giet_vm/sys/irq_handler.h
r189 r228 21 21 void _isr_default(); 22 22 void _isr_ioc(); 23 void _isr_timer( unsigned int channel);24 void _isr_dma( unsigned int channel);25 void _isr_tty( unsigned int channel);23 void _isr_timer(unsigned int channel); 24 void _isr_dma(unsigned int channel); 25 void _isr_tty(unsigned int channel); 26 26 void _isr_switch(); 27 27 28 28 #endif 29 30 // Local Variables: 31 // tab-width: 4 32 // c-basic-offset: 4 33 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 34 // indent-tabs-mode: nil 35 // End: 36 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 37 -
soft/giet_vm/sys/kernel_init.c
r220 r228 37 37 38 38 __attribute__((section (".kdata"))) 39 unsigned int 40 41 __attribute__((section (".kdata"))) 42 unsigned int 39 unsigned int _ptabs_paddr[GIET_NB_VSPACE_MAX]; 40 41 __attribute__((section (".kdata"))) 42 unsigned int _ptabs_vaddr[GIET_NB_VSPACE_MAX]; 43 43 44 44 /////////////////////////////////////////////////////////////////////////////////// … … 47 47 48 48 __attribute__((section (".kdata"))) 49 static_scheduler_t * _schedulers_paddr[NB_CLUSTERS*NB_PROCS_MAX];49 static_scheduler_t * _schedulers_paddr[NB_CLUSTERS * NB_PROCS_MAX]; 50 50 51 51 /////////////////////////////////////////////////////////////////////////////////// … … 54 54 55 55 __attribute__((section (".kdata"))) 56 unsigned int _idle_stack[NB_CLUSTERS*NB_PROCS_MAX*64]; 57 58 void _sys_exit() 59 { 60 while(1); 56 unsigned int _idle_stack[NB_CLUSTERS*NB_PROCS_MAX * 64]; 57 58 void _sys_exit() { 59 while (1); 61 60 } 61 62 62 63 63 ////////////////////////////////////////////////////////////////////////////////// 64 64 // This function is the entry point for the last step of the boot sequence. 65 65 ////////////////////////////////////////////////////////////////////////////////// 66 __attribute__((section (".kinit"))) void _kernel_init() 67 { 66 __attribute__((section (".kinit"))) void _kernel_init() { 68 67 // compute cluster and local processor index 69 unsigned int 70 unsigned int 71 unsigned int proc_id= global_pid % NB_PROCS_MAX;68 unsigned int global_pid = _procid(); 69 unsigned int cluster_id = global_pid / NB_PROCS_MAX; 70 unsigned int proc_id = global_pid % NB_PROCS_MAX; 72 71 73 72 // Step 0 : Compute number of tasks allocated to proc … … 76 75 77 76 #if GIET_DEBUG_INIT 78 _get_lock(&_tty_put_lock);79 _puts("\n[GIET DEBUG] step 0 for processor ");80 _putd( global_pid);81 _puts(" : tasks = ");82 _putd( tasks);83 _puts("\n");84 _release_lock(&_tty_put_lock);77 _get_lock(&_tty_put_lock); 78 _puts("\n[GIET DEBUG] step 0 for processor "); 79 _putd(global_pid); 80 _puts(" : tasks = "); 81 _putd(tasks); 82 _puts("\n"); 83 _release_lock(&_tty_put_lock); 85 84 #endif 86 85 … … 88 87 // get scheduler physical address (from CP0 register) 89 88 90 static_scheduler_t * psched = (static_scheduler_t*)_get_sched();91 _schedulers_paddr[global_pid] 92 93 #if GIET_DEBUG_INIT 94 _get_lock(&_tty_put_lock);95 _puts("\n[GIET DEBUG] step 1 for processor ");96 _putd( global_pid);97 _puts(" / scheduler pbase = ");98 _putx( (unsigned int)psched);99 _puts("\n");100 _release_lock(&_tty_put_lock);89 static_scheduler_t * psched = (static_scheduler_t *) _get_sched(); 90 _schedulers_paddr[global_pid] = psched; 91 92 #if GIET_DEBUG_INIT 93 _get_lock(&_tty_put_lock); 94 _puts("\n[GIET DEBUG] step 1 for processor "); 95 _putd(global_pid); 96 _puts(" / scheduler pbase = "); 97 _putx((unsigned int) psched); 98 _puts("\n"); 99 _release_lock(&_tty_put_lock); 101 100 #endif 102 101 … … 107 106 unsigned int ltid; 108 107 109 for ( ltid = 0 ; ltid < tasks ; ltid++ ) 110 { 111 unsigned int vspace_id = _get_context_slot( ltid , CTX_VSID_ID ); 112 unsigned int ptab_vaddr = _get_context_slot( ltid , CTX_PTAB_ID ); 113 unsigned int ptab_paddr = _get_context_slot( ltid , CTX_PTPR_ID ) << 13; 108 for (ltid = 0; ltid < tasks; ltid++) { 109 unsigned int vspace_id = _get_context_slot(ltid , CTX_VSID_ID); 110 unsigned int ptab_vaddr = _get_context_slot(ltid , CTX_PTAB_ID); 111 unsigned int ptab_paddr = _get_context_slot(ltid , CTX_PTPR_ID) << 13; 114 112 115 113 _ptabs_vaddr[vspace_id] = ptab_vaddr; … … 117 115 118 116 #if GIET_DEBUG_INIT 119 _get_lock(&_tty_put_lock);120 _puts("\n[GIET DEBUG] step 2 for processor ");121 _putd( global_pid);122 _puts(" / vspace ");123 _putd( vspace_id);124 _puts("\n- ptab vbase = ");125 _putx( ptab_vaddr);126 _puts("\n- ptab pbase = ");127 _putx( ptab_paddr);128 _puts("\n");129 _release_lock(&_tty_put_lock);130 #endif 131 132 } 133 117 _get_lock(&_tty_put_lock); 118 _puts("\n[GIET DEBUG] step 2 for processor "); 119 _putd(global_pid); 120 _puts(" / vspace "); 121 _putd(vspace_id); 122 _puts("\n- ptab vbase = "); 123 _putx(ptab_vaddr); 124 _puts("\n- ptab pbase = "); 125 _putx(ptab_paddr); 126 _puts("\n"); 127 _release_lock(&_tty_put_lock); 128 #endif 129 130 } 131 134 132 unsigned int isr_switch_channel = 0xFFFFFFFF; 135 133 … … 142 140 unsigned int pti_mask = 0; 143 141 144 for ( irq_id = 0 ; irq_id < 32 ; irq_id++ ) 145 { 146 unsigned int entry = _get_interrupt_vector_entry(irq_id); 147 unsigned int isr = entry & 0x000000FF; 148 149 if ( (isr == ISR_DMA) || (isr == ISR_IOC) || (isr == ISR_TTY) ) 150 { 151 hwi_mask = hwi_mask | 0x1<< irq_id; 152 } 153 else if ( (isr == ISR_SWITCH) ) 154 { 155 pti_mask = pti_mask | 0x1<< irq_id; 142 for (irq_id = 0; irq_id < 32; irq_id++) { 143 unsigned int entry = _get_interrupt_vector_entry(irq_id); 144 unsigned int isr = entry & 0x000000FF; 145 146 if ((isr == ISR_DMA) || (isr == ISR_IOC) || (isr == ISR_TTY)) { 147 hwi_mask = hwi_mask | 0x1 << irq_id; 148 } 149 else if ((isr == ISR_SWITCH)) { 150 pti_mask = pti_mask | 0x1 << irq_id; 156 151 isr_switch_channel = irq_id; 157 152 } 158 else if ( (isr == ISR_TIMER) ) 159 { 160 pti_mask = pti_mask | 0x1<< irq_id; 161 } 162 } 163 _icu_set_mask( cluster_id, proc_id, hwi_mask, 0 ); // set HWI_MASK 164 _icu_set_mask( cluster_id, proc_id, pti_mask, 1 ); // set PTI_MASK 165 166 #if GIET_DEBUG_INIT 167 _get_lock(&_tty_put_lock); 168 _puts("\n[GIET DEBUG] step 3 for processor "); 169 _putd( global_pid ); 170 _puts("\n - ICU HWI_MASK = "); 171 _putx( hwi_mask ); 172 _puts("\n - ICU PTI_MASK = "); 173 _putx( pti_mask ); 174 _puts("\n"); 175 _release_lock(&_tty_put_lock); 153 else if ((isr == ISR_TIMER)) { 154 pti_mask = pti_mask | 0x1 << irq_id; 155 } 156 } 157 _icu_set_mask(cluster_id, proc_id, hwi_mask, 0); // set HWI_MASK 158 _icu_set_mask(cluster_id, proc_id, pti_mask, 1); // set PTI_MASK 159 160 #if GIET_DEBUG_INIT 161 _get_lock(&_tty_put_lock); 162 _puts("\n[GIET DEBUG] step 3 for processor "); 163 _putd(global_pid); 164 _puts("\n - ICU HWI_MASK = "); 165 _putx(hwi_mask); 166 _puts("\n - ICU PTI_MASK = "); 167 _putx(pti_mask); 168 _puts("\n"); 169 _release_lock(&_tty_put_lock); 176 170 #endif 177 171 178 172 // step 4 : start TICK timer if more than one task 179 if ( tasks > 1 ) 180 { 181 if(isr_switch_channel == 0xFFFFFFFF) 182 { 173 if (tasks > 1) { 174 if (isr_switch_channel == 0xFFFFFFFF) { 183 175 _get_lock(&_tty_put_lock); 184 176 _puts("\n[GIET ERROR] ISR_SWITCH not found on proc "); 185 _putd( 177 _putd(proc_id); 186 178 _puts("\n"); 187 179 _release_lock(&_tty_put_lock); … … 189 181 } 190 182 191 if(_timer_start( cluster_id, isr_switch_channel, GIET_TICK_VALUE )) 192 { 183 if (_timer_start( cluster_id, isr_switch_channel, GIET_TICK_VALUE)) { 193 184 _get_lock(&_tty_put_lock); 194 185 _puts("\n[GIET ERROR] ISR_SWITCH init error for proc "); 195 _putd( 186 _putd(proc_id); 196 187 _puts("\n"); 197 188 _release_lock(&_tty_put_lock); 198 189 _sys_exit(); 199 190 } 200 201 #if GIET_DEBUG_INIT 202 _get_lock(&_tty_put_lock);203 _puts("\n[GIET DEBUG] Step 4 for processor ");204 _putd( global_pid);205 _puts(" / context switch activated\n");206 _release_lock(&_tty_put_lock);207 #endif 208 191 192 #if GIET_DEBUG_INIT 193 _get_lock(&_tty_put_lock); 194 _puts("\n[GIET DEBUG] Step 4 for processor "); 195 _putd(global_pid); 196 _puts(" / context switch activated\n"); 197 _release_lock(&_tty_put_lock); 198 #endif 199 209 200 } 210 201 … … 214 205 // it uses the page table of vspace[0] 215 206 // the stack size is 256 bytes 216 217 _set_context_slot( IDLE_TASK_INDEX, CTX_RUN_ID, 1);218 _set_context_slot( IDLE_TASK_INDEX, CTX_SR_ID, 0xFF03);219 _set_context_slot( IDLE_TASK_INDEX, CTX_SP_ID, (unsigned int)_idle_stack + ((global_pid+1)<<8));220 _set_context_slot( IDLE_TASK_INDEX, CTX_RA_ID, (unsigned int)&_ctx_eret);221 _set_context_slot( IDLE_TASK_INDEX, CTX_EPC_ID, (unsigned int)&_ctx_idle);222 _set_context_slot( IDLE_TASK_INDEX, CTX_LTID_ID, IDLE_TASK_INDEX 223 _set_context_slot( IDLE_TASK_INDEX, CTX_PTPR_ID, _ptabs_paddr[0] >> 13 224 225 #if GIET_DEBUG_INIT 226 _get_lock(&_tty_put_lock);227 _puts("\n[GIET DEBUG] Step 5 for processor ");228 _putd( global_pid);229 _puts(" / idle task context set\n");230 _release_lock(&_tty_put_lock);231 #endif 232 207 208 _set_context_slot( IDLE_TASK_INDEX, CTX_RUN_ID, 1); 209 _set_context_slot( IDLE_TASK_INDEX, CTX_SR_ID, 0xFF03); 210 _set_context_slot( IDLE_TASK_INDEX, CTX_SP_ID, (unsigned int) _idle_stack + ((global_pid + 1) << 8)); 211 _set_context_slot( IDLE_TASK_INDEX, CTX_RA_ID, (unsigned int) &_ctx_eret); 212 _set_context_slot( IDLE_TASK_INDEX, CTX_EPC_ID, (unsigned int) &_ctx_idle); 213 _set_context_slot( IDLE_TASK_INDEX, CTX_LTID_ID, IDLE_TASK_INDEX); 214 _set_context_slot( IDLE_TASK_INDEX, CTX_PTPR_ID, _ptabs_paddr[0] >> 13); 215 216 #if GIET_DEBUG_INIT 217 _get_lock(&_tty_put_lock); 218 _puts("\n[GIET DEBUG] Step 5 for processor "); 219 _putd(global_pid); 220 _puts(" / idle task context set\n"); 221 _release_lock(&_tty_put_lock); 222 #endif 223 233 224 // step 6 : each processor initialises SP, SR, PTPR, EPC, registers 234 225 // with the values corresponding to the first allocated task, … … 237 228 unsigned int task_id; 238 229 239 if ( tasks == 0 ) 240 { 230 if (tasks == 0) { 241 231 task_id = IDLE_TASK_INDEX; 242 232 243 _get_lock( &_tty_put_lock);233 _get_lock(&_tty_put_lock); 244 234 _puts("\n[GIET WARNING] No task allocated to processor "); 245 _putd( global_pid);235 _putd(global_pid); 246 236 _puts(" => idle\n"); 247 _release_lock ( &_tty_put_lock ); 248 } 249 else 250 { 251 task_id = 0; 252 } 253 254 unsigned int sp_value = _get_context_slot( task_id, CTX_SP_ID ); 255 unsigned int sr_value = _get_context_slot( task_id, CTX_SR_ID ); 256 unsigned int ptpr_value = _get_context_slot( task_id, CTX_PTPR_ID ); 257 unsigned int epc_value = _get_context_slot( task_id, CTX_EPC_ID ); 258 259 #if GIET_DEBUG_INIT 260 _get_lock(&_tty_put_lock); 261 _puts("\n[GIET DEBUG] step 6 for processor "); 262 _putd( global_pid ); 263 _puts(" / registers initialised \n"); 264 _puts("- sp = "); 265 _putx( sp_value ); 266 _puts("\n"); 267 _puts("- sr = "); 268 _putx( sr_value ); 269 _puts("\n"); 270 _puts("- ptpr = "); 271 _putx( ptpr_value<<13 ); 272 _puts("\n"); 273 _puts("- epc = "); 274 _putx( epc_value ); 275 _puts("\n"); 276 _release_lock(&_tty_put_lock); 237 _release_lock (&_tty_put_lock); 238 } 239 else { 240 task_id = 0; 241 } 242 243 unsigned int sp_value = _get_context_slot(task_id, CTX_SP_ID); 244 unsigned int sr_value = _get_context_slot(task_id, CTX_SR_ID); 245 unsigned int ptpr_value = _get_context_slot(task_id, CTX_PTPR_ID); 246 unsigned int epc_value = _get_context_slot(task_id, CTX_EPC_ID); 247 248 #if GIET_DEBUG_INIT 249 _get_lock(&_tty_put_lock); 250 _puts("\n[GIET DEBUG] step 6 for processor "); 251 _putd(global_pid); 252 _puts(" / registers initialised \n"); 253 _puts("- sp = "); 254 _putx(sp_value); 255 _puts("\n"); 256 _puts("- sr = "); 257 _putx(sr_value); 258 _puts("\n"); 259 _puts("- ptpr = "); 260 _putx(ptpr_value << 13); 261 _puts("\n"); 262 _puts("- epc = "); 263 _putx(epc_value); 264 _puts("\n"); 265 _release_lock(&_tty_put_lock); 277 266 #endif 278 267 279 268 // set registers and jump to user code 280 asm volatile ( "move $29, %0 \n" /* SP <= ctx[CTX_SP_ID] */ 281 "mtc0 %1, $12 \n" /* SR <= ctx[CTX_SR_ID] */ 282 "mtc2 %2, $0 \n" /* PTPR <= ctx[CTX_PTPR_ID] */ 283 "mtc0 %3, $14 \n" /* EPC <= ctx[CTX_EPC_ID] */ 284 "eret \n" /* jump to user code */ 285 "nop \n" 286 : 287 : "r"(sp_value), "r"(sr_value), "r"(ptpr_value), "r"(epc_value) ); 269 asm volatile ( 270 "move $29, %0 \n" /* SP <= ctx[CTX_SP_ID] */ 271 "mtc0 %1, $12 \n" /* SR <= ctx[CTX_SR_ID] */ 272 "mtc2 %2, $0 \n" /* PTPR <= ctx[CTX_PTPR_ID] */ 273 "mtc0 %3, $14 \n" /* EPC <= ctx[CTX_EPC_ID] */ 274 "eret \n" /* jump to user code */ 275 "nop \n" 276 : 277 : "r" (sp_value), "r" (sr_value), "r" (ptpr_value), "r" (epc_value)); 288 278 289 279 } // end _kernel_init() 280 281 // Local Variables: 282 // tab-width: 4 283 // c-basic-offset: 4 284 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 285 // indent-tabs-mode: nil 286 // End: 287 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 288 -
soft/giet_vm/sys/mips32_registers.h
r199 r228 1 1 /********************************************************************************/ 2 /* File : mips32_registers.h*/3 /* Author : Alain Greiner*/4 /* Date : 26/03/2012*/2 /* File : mips32_registers.h */ 3 /* Author : Alain Greiner */ 4 /* Date : 26/03/2012 */ 5 5 /********************************************************************************/ 6 /* We define mnemonics for MIPS32 registers*/6 /* We define mnemonics for MIPS32 registers */ 7 7 /********************************************************************************/ 8 8 9 9 #ifndef _MIPS32_REGISTER_H 10 10 #define _MIPS32_REGISTER_H … … 12 12 /* processor registers */ 13 13 14 #define zero 15 #define at 16 #define v0 17 #define v1 18 #define a0 19 #define a1 20 #define a2 21 #define a3 22 #define t0 23 #define t1 24 #define t2 25 #define t3 26 #define t4 27 #define t5 28 #define t6 29 #define t7 30 #define s0 31 #define s1 32 #define s2 33 #define s3 34 #define s4 35 #define s5 36 #define s6 37 #define s7 38 #define t8 39 #define t9 40 #define k0 41 #define k1 42 #define gp 43 #define sp 44 #define fp 45 #define ra 14 #define zero $0 15 #define at $1 16 #define v0 $2 17 #define v1 $3 18 #define a0 $4 19 #define a1 $5 20 #define a2 $6 21 #define a3 $7 22 #define t0 $8 23 #define t1 $9 24 #define t2 $10 25 #define t3 $11 26 #define t4 $12 27 #define t5 $13 28 #define t6 $14 29 #define t7 $15 30 #define s0 $16 31 #define s1 $17 32 #define s2 $18 33 #define s3 $19 34 #define s4 $20 35 #define s5 $21 36 #define s6 $22 37 #define s7 $23 38 #define t8 $24 39 #define t9 $25 40 #define k0 $26 41 #define k1 $27 42 #define gp $28 43 #define sp $29 44 #define fp $30 45 #define ra $31 46 46 47 47 /* CP0 registers */ 48 48 49 #define CP0_BVAR 50 #define CP0_TIME 51 #define CP0_SR$1252 #define CP0_CR 53 #define CP0_EPC 54 #define CP0_PROCID 55 #define CP0_SCHED 49 #define CP0_BVAR $8 50 #define CP0_TIME $9 51 #define CP0_SR $12 52 #define CP0_CR $13 53 #define CP0_EPC $14 54 #define CP0_PROCID $15,1 55 #define CP0_SCHED $22 56 56 57 57 /* CP2 registers */ 58 58 59 #define CP2_PTPR 60 #define CP2_MODE 61 #define CP2_ICACHE_FLUSH 62 #define CP2_DCACHE_FLUSH 63 #define CP2_ITLB_INVAL 64 #define CP2_DTLB_INVAL 65 #define CP2_ICACHE_INVAL 66 #define CP2_DCACHE_INVAL 67 #define CP2_ICACHE_PREFETCH 68 #define CP2_DCACHE_PREFETCH 69 #define CP2_SYNC 70 #define CP2_IETR 71 #define CP2_DETR 72 #define CP2_IBVAR 73 #define CP2_DBVAR 74 #define CP2_PARAMS 75 #define CP2_RELEASE 76 #define CP2_DATA_LO $1777 #define CP2_DATA_HI $1878 #define CP2_ICACHE_INVAL_PA $1979 #define CP2_DCACHE_INVAL_PA 59 #define CP2_PTPR $0 60 #define CP2_MODE $1 61 #define CP2_ICACHE_FLUSH $2 62 #define CP2_DCACHE_FLUSH $3 63 #define CP2_ITLB_INVAL $4 64 #define CP2_DTLB_INVAL $5 65 #define CP2_ICACHE_INVAL $6 66 #define CP2_DCACHE_INVAL $7 67 #define CP2_ICACHE_PREFETCH $8 68 #define CP2_DCACHE_PREFETCH $9 69 #define CP2_SYNC $10 70 #define CP2_IETR $11 71 #define CP2_DETR $12 72 #define CP2_IBVAR $13 73 #define CP2_DBVAR $14 74 #define CP2_PARAMS $15 75 #define CP2_RELEASE $16 76 #define CP2_DATA_LO $17 77 #define CP2_DATA_HI $18 78 #define CP2_ICACHE_INVAL_PA $19 79 #define CP2_DCACHE_INVAL_PA $20 80 80 81 81 #endif 82 83 // Local Variables: 84 // tab-width: 4 85 // c-basic-offset: 4 86 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 87 // indent-tabs-mode: nil 88 // End: 89 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 90 -
soft/giet_vm/sys/sys_handler.c
r218 r228 17 17 #include <giet_config.h> 18 18 #include <mapping_info.h> 19 20 //////////////////////////////////////////////////////////////////////////// 21 // Initialize the syscall vector with syscall handlers 22 //////////////////////////////////////////////////////////////////////////// 23 const void *_syscall_vector[32] = { 24 &_procid, /* 0x00 */ 25 &_proctime, /* 0x01 */ 26 &_tty_write, /* 0x02 */ 27 &_tty_read, /* 0x03 */ 28 &_timer_start, /* 0x04 */ 29 &_timer_stop, /* 0x05 */ 30 &_gcd_write, /* 0x06 */ 31 &_gcd_read, /* 0x07 */ 32 &_sys_ukn, /* 0x08 */ 33 &_sys_ukn, /* 0x09 */ 34 &_sys_ukn, /* 0x0A */ 35 &_sys_ukn, /* 0x0B */ 36 &_sys_ukn, /* 0x0C */ 37 &_ctx_switch, /* 0x0D */ 38 &_exit, /* 0x0E */ 39 &_procs_number, /* 0x0F */ 40 &_fb_sync_write, /* 0x10 */ 41 &_fb_sync_read, /* 0x11 */ 42 &_fb_write, /* 0x12 */ 43 &_fb_read, /* 0x13 */ 44 &_fb_completed, /* 0x14 */ 45 &_ioc_write, /* 0x15 */ 46 &_ioc_read, /* 0x16 */ 47 &_ioc_completed, /* 0x17 */ 48 &_sys_ukn, /* 0x18 */ 49 &_sys_ukn, /* 0x19 */ 50 &_vobj_get_vbase, /* 0x1A */ 51 &_nic_write, /* 0x1B */ 52 &_nic_read, /* 0x1C */ 53 &_nic_completed, /* 0x1D */ 54 &_sys_ukn, /* 0x1E */ 55 &_sys_ukn, /* 0x1F */ 19 #include <srl_memspace.h> 20 21 //////////////////////////////////////////////////////////////////////////// 22 // Initialize the syscall vector with syscall handlers 23 //////////////////////////////////////////////////////////////////////////// 24 const void * _syscall_vector[32] = { 25 &_procid, /* 0x00 */ 26 &_proctime, /* 0x01 */ 27 &_tty_write, /* 0x02 */ 28 &_tty_read, /* 0x03 */ 29 &_timer_start, /* 0x04 */ 30 &_timer_stop, /* 0x05 */ 31 &_gcd_write, /* 0x06 */ 32 &_gcd_read, /* 0x07 */ 33 &_sys_ukn, /* 0x08 */ 34 &_get_current_task_id, /* 0x09 */ 35 &_sys_ukn, /* 0x0A */ 36 &_sys_ukn, /* 0x0B */ 37 &_sys_ukn, /* 0x0C */ 38 &_context_switch, /* 0x0D */ 39 &_exit, /* 0x0E */ 40 &_procs_number, /* 0x0F */ 41 &_fb_sync_write, /* 0x10 */ 42 &_fb_sync_read, /* 0x11 */ 43 &_fb_write, /* 0x12 */ 44 &_fb_read, /* 0x13 */ 45 &_fb_completed, /* 0x14 */ 46 &_ioc_write, /* 0x15 */ 47 &_ioc_read, /* 0x16 */ 48 &_ioc_completed, /* 0x17 */ 49 &_sys_ukn, /* 0x18 */ 50 &_sys_ukn, /* 0x19 */ 51 &_vobj_get_vbase, /* 0x1A */ 52 &_nic_write, /* 0x1B */ 53 &_nic_read, /* 0x1C */ 54 &_nic_completed, /* 0x1D */ 55 &_sys_ukn, /* 0x1E */ 56 &_sys_ukn, /* 0x1F */ 56 57 }; 57 58 … … 59 60 // function executed in case of undefined syscall 60 61 ////////////////////////////////////////////////////////////////////////////// 61 void _sys_ukn() 62 { 63 unsigned int epc; 64 asm volatile("mfc0 %0, $14" : "=r"(epc)); 62 void _sys_ukn() { 63 unsigned int epc; 64 asm volatile("mfc0 %0, $14" : "=r" (epc)); 65 65 66 66 _puts("\n\n!!! Undefined System Call !!!\n"); 67 67 _puts("\nEPC = "); 68 _putx( epc);68 _putx(epc); 69 69 _exit(); 70 70 } 71 72 71 73 //////////////////////////////////////////////////////////////////////////// 72 74 // _exit() 73 75 // Task suicide... after printing a death message. 74 76 //////////////////////////////////////////////////////////////////////////// 75 void _exit() 76 { 77 unsigned int date = _proctime(); 77 void _exit() { 78 unsigned int date = _proctime(); 78 79 unsigned int proc_id = _procid(); 79 80 unsigned int task_id = _get_current_task_id(); 80 81 81 82 // print death message 82 83 _get_lock(&_tty_put_lock); 83 84 _puts("\n[GIET] Exit task "); 84 _putd( task_id);85 _putd(task_id); 85 86 _puts(" on processor "); 86 _putd( proc_id);87 _putd(proc_id); 87 88 _puts(" at cycle "); 88 _putd( date);89 _putd(date); 89 90 _puts("\n\n"); 90 91 _release_lock(&_tty_put_lock); 91 92 92 93 // goes to sleeping state 93 _set_context_slot( task_id, CTX_RUN_ID, 0 94 94 _set_context_slot( task_id, CTX_RUN_ID, 0); 95 95 96 // deschedule 96 97 _ctx_switch(); 97 98 } 99 100 98 101 ////////////////////////////////////////////////////////////////////////////// 99 102 // _procid() … … 101 104 // Max number or processors is 1024. 102 105 ////////////////////////////////////////////////////////////////////////////// 103 unsigned int _procid() 104 { 105 unsigned int ret; 106 asm volatile("mfc0 %0, $15, 1" : "=r"(ret)); 106 unsigned int _procid() { 107 unsigned int ret; 108 asm volatile("mfc0 %0, $15, 1" : "=r" (ret)); 107 109 return (ret & 0xFFF); 108 110 } 111 112 109 113 ////////////////////////////////////////////////////////////////////////////// 110 114 // _proctime() 111 115 // Access CP0 and returns current processor's elapsed clock cycles since boot. 112 116 ////////////////////////////////////////////////////////////////////////////// 113 unsigned int _proctime() 114 { 115 unsigned int ret; 116 asm volatile("mfc0 %0, $9" : "=r"(ret)); 117 unsigned int _proctime() { 118 unsigned int ret; 119 asm volatile("mfc0 %0, $9" : "=r" (ret)); 117 120 return ret; 118 121 } 122 123 119 124 ////////////////////////////////////////////////////////////////////////////// 120 125 // _procnumber() … … 122 127 // specified by the cluster_id argument. 123 128 ////////////////////////////////////////////////////////////////////////////// 124 unsigned int _procs_number( unsigned int cluster_id, 125 unsigned int* buffer) 126 { 127 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 128 mapping_cluster_t* cluster = _get_cluster_base( header ); 129 130 if ( cluster_id < header->clusters ) 131 { 129 unsigned int _procs_number(unsigned int cluster_id, unsigned int * buffer) { 130 mapping_header_t * header = (mapping_header_t *) &seg_mapping_base; 131 mapping_cluster_t * cluster = _get_cluster_base(header); 132 133 if (cluster_id < header->clusters) { 132 134 *buffer = cluster[cluster_id].procs; 133 135 return 0; 134 136 } 135 else 136 { 137 return 1; 138 } 139 } 140 141 int _get_vobj( char* vspace_name, char* vobj_name, unsigned int vobj_type, mapping_vobj_t** res_vobj) 142 { 143 mapping_header_t* header = (mapping_header_t*)&seg_mapping_base; 144 mapping_vspace_t* vspace = _get_vspace_base( header ); 145 mapping_vobj_t* vobj = _get_vobj_base( header ); 146 147 unsigned int vspace_id; 148 unsigned int vobj_id; 149 137 else { 138 return 1; 139 } 140 } 141 142 143 int _get_vobj(char * vspace_name, char * vobj_name, unsigned int vobj_type, mapping_vobj_t ** res_vobj) { 144 mapping_header_t * header = (mapping_header_t *) &seg_mapping_base; 145 mapping_vspace_t * vspace = _get_vspace_base(header); 146 mapping_vobj_t * vobj = _get_vobj_base(header); 147 148 unsigned int vspace_id; 149 unsigned int vobj_id; 150 150 151 151 152 // scan vspaces 152 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 153 { 154 if ( _strncmp( vspace[vspace_id].name, vspace_name, 31) == 0 ) 155 { 153 for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) { 154 if (_strncmp( vspace[vspace_id].name, vspace_name, 31) == 0) { 156 155 // scan vobjs 157 for (vobj_id = vspace[vspace_id].vobj_offset;156 for (vobj_id = vspace[vspace_id].vobj_offset; 158 157 vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs); 159 vobj_id++) 160 { 161 162 if ( _strncmp( vobj[vobj_id].name, vobj_name, 31) == 0 ) 163 { 164 if(vobj[vobj_id].type != vobj_type) 165 return -1; //wrong type 166 158 vobj_id++) { 159 160 if (_strncmp(vobj[vobj_id].name, vobj_name, 31) == 0) { 161 if (vobj[vobj_id].type != vobj_type) { 162 _get_lock(&_tty_put_lock); 163 _puts("*** Error in _get_obj: wrong type\n"); 164 _release_lock(&_tty_put_lock); 165 return -1; //wrong type 166 } 167 167 *res_vobj = &vobj[vobj_id]; 168 169 168 return 0; 170 169 } … … 172 171 } 173 172 } 174 return -2; //not found 175 176 } 173 _get_lock(&_tty_put_lock); 174 _puts("*** Error in _get_obj: object not found\n"); 175 _release_lock(&_tty_put_lock); 176 177 return -2; //not found 178 } 179 180 177 181 ///////////////////////////////////////////////////////////////////////////// 178 182 // _vobj_get_vbase() … … 182 186 // returns 0: success, else: failed. 183 187 ///////////////////////////////////////////////////////////////////////////// 184 unsigned int _vobj_get_vbase( char* vspace_name, 185 char* vobj_name, 186 unsigned int vobj_type, 187 unsigned int* vobj_vaddr ) 188 { 189 mapping_vobj_t* res_vobj; 190 unsigned int ret; 191 if( (ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj)) ) 192 { 188 unsigned int _vobj_get_vbase( 189 char * vspace_name, 190 char * vobj_name, 191 unsigned int vobj_type, 192 unsigned int * vobj_vaddr) { 193 mapping_vobj_t * res_vobj; 194 unsigned int ret; 195 if ((ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj))) { 193 196 return ret; 194 197 } 195 198 196 199 *vobj_vaddr = res_vobj->vaddr; 197 198 200 return 0; 199 201 } 202 200 203 201 204 ///////////////////////////////////////////////////////////////////////////// … … 206 209 // returns 0: success, else: failed. 207 210 ///////////////////////////////////////////////////////////////////////////// 208 unsigned int _vobj_get_length(char* vspace_name, 209 char* vobj_name, 210 unsigned int vobj_type, 211 unsigned int* vobj_length ) 212 { 213 214 mapping_vobj_t* res_vobj; 215 unsigned int ret; 216 if( (ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj)) ) 217 { 211 unsigned int _vobj_get_length( 212 char * vspace_name, 213 char * vobj_name, 214 unsigned int vobj_type, 215 unsigned int * vobj_length) { 216 217 mapping_vobj_t * res_vobj; 218 unsigned int ret; 219 if ((ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj))) { 218 220 return ret; 219 221 } 220 222 221 223 *vobj_length = res_vobj->length; 222 224 223 225 return 0; 224 226 } 227 228 229 //////////////////////////////////////////////////////////////// 230 // _context_switch() 231 // This functions masks interruptions before calling _ctx_switch 232 // (They are usually masked when we receive a isr_switch interrupt 233 // because we execute isrs with interrupt masked) 234 //////////////////////////////////////////////////////////////// 235 void _context_switch() { 236 _it_mask(); 237 _ctx_switch(); 238 _it_restore(); 239 } 240 241 242 // Local Variables: 243 // tab-width: 4 244 // c-basic-offset: 4 245 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 246 // indent-tabs-mode: nil 247 // End: 248 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 249 -
soft/giet_vm/sys/sys_handler.h
r160 r228 10 10 11 11 ////////////////////////////////////////////////////////////////////////////////// 12 // 12 // Syscall Vector Table (indexed by syscall index) 13 13 ////////////////////////////////////////////////////////////////////////////////// 14 14 15 extern const void * _syscall_vector[32];15 extern const void * _syscall_vector[32]; 16 16 17 17 ////////////////////////////////////////////////////////////////////////////////// … … 19 19 ////////////////////////////////////////////////////////////////////////////////// 20 20 21 void _sys_ukn(); 21 void _sys_ukn(); 22 void _exit(); 23 void _context_switch(); 24 unsigned int _procid(); 25 unsigned int _proctime(); 26 unsigned int _procs_number(unsigned int cluster_id, unsigned int * buffer ); 27 unsigned int _vobj_get_vbase(char * vspace_name, char * vobj_name, unsigned vobj_type, unsigned int * vobj_buffer); 22 28 23 void _exit(); 29 #endif 24 30 25 unsigned int _procid(); 31 // Local Variables: 32 // tab-width: 4 33 // c-basic-offset: 4 34 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 35 // indent-tabs-mode: nil 36 // End: 37 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 26 38 27 unsigned int _proctime();28 29 unsigned int _procs_number( unsigned int cluster_id,30 unsigned int* buffer );31 32 unsigned int _vobj_get_vbase( char* vspace_name, char* vobj_name,33 unsigned vobj_type, unsigned int* vobj_buffer);34 #endif -
soft/giet_vm/sys/vm_handler.c
r207 r228 20 20 21 21 ///////////////////////////////////////////////////////////////////////////// 22 // 22 // Global variable : IOMMU page table 23 23 ///////////////////////////////////////////////////////////////////////////// 24 24 25 __attribute__((section (".iommu"))) page_table_t 25 __attribute__((section (".iommu"))) page_table_t _iommu_ptab; 26 26 27 27 ////////////////////////////////////////////////////////////////////////////// 28 28 // _iommu_add_pte2() 29 29 ////////////////////////////////////////////////////////////////////////////// 30 void _iommu_add_pte2( unsigned int ix1,31 unsigned int ix2,32 unsigned int ppn,33 unsigned int flags )34 {35 unsigned int 36 unsigned int *pt_ppn;37 unsigned int *pt_flags;30 void _iommu_add_pte2( 31 unsigned int ix1, 32 unsigned int ix2, 33 unsigned int ppn, 34 unsigned int flags) { 35 unsigned int ptba; 36 unsigned int * pt_ppn; 37 unsigned int * pt_flags; 38 38 39 39 // get pointer on iommu page table 40 page_table_t * pt = &_iommu_ptab;40 page_table_t * pt = &_iommu_ptab; 41 41 42 42 // get ptba and update PT2 43 if ( (pt->pt1[ix1] & PTE_V) == 0 ) 44 { 43 if ((pt->pt1[ix1] & PTE_V) == 0) { 45 44 _puts("\n[GIET ERROR] in iommu_add_pte2 function\n"); 46 45 _puts("the IOMMU PT1 entry is not mapped / ix1 = "); … … 49 48 _exit(); 50 49 } 51 else 52 { 53 ptba = pt->pt1[ix1] << 12; 54 pt_flags = (unsigned int*)(ptba + 8*ix2); 55 pt_ppn = (unsigned int*)(ptba + 8*ix2 + 4); 50 else { 51 ptba = pt->pt1[ix1] << 12; 52 pt_flags = (unsigned int *) (ptba + 8 * ix2); 53 pt_ppn = (unsigned int *) (ptba + 8 * ix2 + 4); 56 54 *pt_flags = flags; 57 *pt_ppn 55 *pt_ppn = ppn; 58 56 } 59 57 } // end _iommu_add_pte2() 58 60 59 61 60 ////////////////////////////////////////////////////////////////////////////// 62 61 // _iommu_inval_pte2() 63 62 ////////////////////////////////////////////////////////////////////////////// 64 void _iommu_inval_pte2( unsigned int ix1, 65 unsigned int ix2 ) 66 { 67 unsigned int ptba; 68 unsigned int* pt_flags; 63 void _iommu_inval_pte2(unsigned int ix1, unsigned int ix2) { 64 unsigned int ptba; 65 unsigned int * pt_flags; 69 66 70 67 // get pointer on iommu page table 71 page_table_t * pt = &_iommu_ptab;68 page_table_t * pt = &_iommu_ptab; 72 69 73 70 // get ptba and inval PTE2 74 if ( (pt->pt1[ix1] & PTE_V) == 0 ) 75 { 71 if ((pt->pt1[ix1] & PTE_V) == 0) { 76 72 _puts("\n[GIET ERROR] in iommu_inval_pte2 function\n"); 77 73 _puts("the IOMMU PT1 entry is not mapped / ix1 = "); … … 80 76 _exit(); 81 77 } 82 else 83 { 84 ptba = pt->pt1[ix1] << 12; 85 pt_flags = (unsigned int*)(ptba + 8*ix2); 78 else { 79 ptba = pt->pt1[ix1] << 12; 80 pt_flags = (unsigned int *) (ptba + 8 * ix2); 86 81 *pt_flags = 0; 87 82 } 88 83 } // end _iommu_inval_pte2() 84 89 85 90 86 ////////////////////////////////////////////////////////////////////////////// … … 92 88 // Returns 0 if success, 1 if PTE1 or PTE2 unmapped 93 89 ////////////////////////////////////////////////////////////////////////////// 94 unsigned int _v2p_translate( page_table_t* pt, 95 unsigned int vpn, 96 unsigned int* ppn, 97 unsigned int* flags ) 98 { 99 unsigned int ptba; 90 unsigned int _v2p_translate( 91 page_table_t * pt, 92 unsigned int vpn, 93 unsigned int * ppn, 94 unsigned int * flags) { 95 unsigned int ptba; 96 register unsigned int * pte2; 97 register unsigned int flags_value; 98 register unsigned int ppn_value; 100 99 101 register unsigned int* pte2; 102 register unsigned int flags_value; 103 register unsigned int ppn_value; 104 105 unsigned int ix1 = vpn >> 9; 106 unsigned int ix2 = vpn & 0x1FF; 107 /* 108 _puts("\n\n********************** entering v2p_translate"); 109 _puts("\n - pt = "); 110 _putx( (unsigned int)pt ); 111 _puts("\n - vpn = "); 112 _putx( vpn << 12 ); 113 _puts("\n - ptba = "); 114 _putx( pt->pt1[ix1] << 12 ) ; 115 _puts("\n - &pte2 = "); 116 _putx( (pt->pt1[ix1] << 12) + 8*ix2 ); 117 _puts("\n - flags = "); 118 _putx( *(unsigned int*)((pt->pt1[ix1] << 12) + 8*ix2) ); 119 _puts("\n"); 120 */ 100 unsigned int ix1 = vpn >> 9; 101 unsigned int ix2 = vpn & 0x1FF; 102 /* 103 _puts("\n\n********************** entering v2p_translate"); 104 _puts("\n - pt = "); 105 _putx( (unsigned int)pt ); 106 _puts("\n - vpn = "); 107 _putx( vpn << 12 ); 108 _puts("\n - ptba = "); 109 _putx( pt->pt1[ix1] << 12 ) ; 110 _puts("\n - &pte2 = "); 111 _putx( (pt->pt1[ix1] << 12) + 8*ix2 ); 112 _puts("\n - flags = "); 113 _putx( *(unsigned int*)((pt->pt1[ix1] << 12) + 8*ix2) ); 114 _puts("\n"); 115 */ 121 116 // check PTE1 mapping 122 if ( (pt->pt1[ix1] & PTE_V) == 0 ) 123 { 117 if ((pt->pt1[ix1] & PTE_V) == 0) { 124 118 return 1; 125 119 } 126 else 127 { 120 else { 128 121 // get physical addresses of pte2 129 122 ptba = pt->pt1[ix1] << 12; 130 pte2 = (unsigned int *)(ptba + 8*ix2);123 pte2 = (unsigned int *) (ptba + 8 * ix2); 131 124 132 125 // gets ppn_value and flags_value, after temporary DTLB desactivation 133 asm volatile ( "li $27, 0xFFFFFFFE \n" /* Mask for IE bits */ 134 "mfc0 $26, $12 \n" /* save SR */ 135 "and $27, $26, $27 \n" 136 "mtc0 $27, $12 \n" /* disable Interrupts */ 126 asm volatile ( 127 "li $27, 0xFFFFFFFE \n" /* Mask for IE bits */ 128 "mfc0 $26, $12 \n" /* save SR */ 129 "and $27, $26, $27 \n" 130 "mtc0 $27, $12 \n" /* disable Interrupts */ 137 131 138 139 132 "li $27, 0xB \n" 133 "mtc2 $27, $1 \n" /* DTLB unactivated */ 140 134 141 142 143 135 "move $27, %2 \n" /* $27 <= pte2 */ 136 "lw %0, 0($27) \n" /* read flags */ 137 "lw %1, 4($27) \n" /* read ppn */ 144 138 145 146 139 "li $27, 0xF \n" 140 "mtc2 $27, $1 \n" /* DTLB activated */ 147 141 148 149 :"=r"(flags_value), "=r"(ppn_value)150 :"r"(pte2)151 :"$26","$27","$8");142 "mtc0 $26, $12 \n" /* restore SR */ 143 : "=r" (flags_value), "=r" (ppn_value) 144 : "r" (pte2) 145 : "$26","$27","$8"); 152 146 153 147 // check PTE2 mapping 154 if ( (flags_value & PTE_V) == 0 ) 155 { 148 if ((flags_value & PTE_V) == 0) { 156 149 return 1; 157 150 } 158 151 159 152 // set return values 160 *ppn 161 *flags 153 *ppn = ppn_value; 154 *flags = flags_value; 162 155 } 163 156 return 0; 164 } 157 } // end _v2p_translate() 165 158 166 159 // Local Variables: … … 170 163 // indent-tabs-mode: nil 171 164 // End: 165 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 172 166 173 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4174 167 -
soft/giet_vm/sys/vm_handler.h
r195 r228 6 6 /////////////////////////////////////////////////////////////////////////////////// 7 7 8 #ifndef 9 #define 8 #ifndef _VM_HANDLER_H_ 9 #define _VM_HANDLER_H_ 10 10 11 #include 12 #include 11 #include <giet_config.h> 12 #include <mapping_info.h> 13 13 14 14 ///////////////////////////////////////////////////////////////////////////////////// … … 16 16 ///////////////////////////////////////////////////////////////////////////////////// 17 17 18 #define 19 #define 18 #define PT1_SIZE 8192 19 #define PT2_SIZE 4096 20 20 21 21 ///////////////////////////////////////////////////////////////////////////////////// … … 23 23 ///////////////////////////////////////////////////////////////////////////////////// 24 24 25 #define PTE_V0x8000000026 #define PTE_T0x4000000027 #define PTE_L0x2000000028 #define PTE_R0x1000000029 #define PTE_C0x0800000030 #define PTE_W0x0400000031 #define PTE_X0x0200000032 #define PTE_U0x0100000033 #define PTE_G0x0080000034 #define PTE_D0x0040000025 #define PTE_V 0x80000000 26 #define PTE_T 0x40000000 27 #define PTE_L 0x20000000 28 #define PTE_R 0x10000000 29 #define PTE_C 0x08000000 30 #define PTE_W 0x04000000 31 #define PTE_X 0x02000000 32 #define PTE_U 0x01000000 33 #define PTE_G 0x00800000 34 #define PTE_D 0x00400000 35 35 36 36 ///////////////////////////////////////////////////////////////////////////////////// … … 38 38 ///////////////////////////////////////////////////////////////////////////////////// 39 39 40 #define MMU_ERR_PT1_UNMAPPED 0x001// Page fault on Table1 (invalid PTE)41 #define MMU_ERR_PT2_UNMAPPED 0x002// Page fault on Table 2 (invalid PTE)42 #define MMU_ERR_PRIVILEGE_VIOLATION 0x004// Protected access in user mode43 #define MMU_ERR_WRITE_VIOLATION 0x008// Write access to a non write page44 #define MMU_ERR_EXEC_VIOLATION 0x010// Exec access to a non exec page45 #define MMU_ERR_UNDEFINED_XTN 0x020// Undefined external access address46 #define MMU_ERR_PT1_ILLEGAL_ACCESS 0x040// Bus Error in Table1 access47 #define MMU_ERR_PT2_ILLEGAL_ACCESS 0x080// Bus Error in Table2 access48 #define MMU_ERR_CACHE_ILLEGAL_ACCESS 0x100// Bus Error during the cache access40 #define MMU_ERR_PT1_UNMAPPED 0x001 // Page fault on Table1 (invalid PTE) 41 #define MMU_ERR_PT2_UNMAPPED 0x002 // Page fault on Table 2 (invalid PTE) 42 #define MMU_ERR_PRIVILEGE_VIOLATION 0x004 // Protected access in user mode 43 #define MMU_ERR_WRITE_VIOLATION 0x008 // Write access to a non write page 44 #define MMU_ERR_EXEC_VIOLATION 0x010 // Exec access to a non exec page 45 #define MMU_ERR_UNDEFINED_XTN 0x020 // Undefined external access address 46 #define MMU_ERR_PT1_ILLEGAL_ACCESS 0x040 // Bus Error in Table1 access 47 #define MMU_ERR_PT2_ILLEGAL_ACCESS 0x080 // Bus Error in Table2 access 48 #define MMU_ERR_CACHE_ILLEGAL_ACCESS 0x100 // Bus Error during the cache access 49 49 50 50 ///////////////////////////////////////////////////////////////////////////////////// 51 51 // Page table structure definition 52 52 ///////////////////////////////////////////////////////////////////////////////////// 53 typedef struct PageTable 54 { 55 unsigned int pt1[PT1_SIZE/4]; // PT1 (index is ix1) 56 unsigned int pt2[1][PT2_SIZE/4]; // PT2s (index is 2*ix2) 53 typedef struct PageTable { 54 unsigned int pt1[PT1_SIZE / 4]; // PT1 (index is ix1) 55 unsigned int pt2[1][PT2_SIZE / 4]; // PT2s (index is 2*ix2) 57 56 } page_table_t; 58 57 … … 68 67 //////////////////////////////////////////////////////////////////////////////////// 69 68 70 void _iommu_add_pte2( unsigned int ix1, 71 unsigned int ix2, 72 unsigned int ppn, 73 unsigned int flags ); 74 75 void _iommu_inval_pte2( unsigned int ix1, 76 unsigned int ix2 ); 77 78 unsigned int _v2p_translate( page_table_t* pt, 79 unsigned int vpn, 80 unsigned int* ppn, 81 unsigned int* flags ); 69 void _iommu_add_pte2(unsigned int ix1, unsigned int ix2, unsigned int ppn, unsigned int flags); 70 void _iommu_inval_pte2(unsigned int ix1, unsigned int ix2); 71 unsigned int _v2p_translate(page_table_t * pt, unsigned int vpn, unsigned int * ppn, unsigned int * flags); 82 72 83 73 #endif … … 89 79 // indent-tabs-mode: nil 90 80 // End: 81 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 91 82 92 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 -
soft/giet_vm/xml/mapping_info.h
r215 r228 30 30 #define _MAPPING_INFO_H_ 31 31 32 #define MAPPING_HEADER_SIZE 33 #define MAPPING_CLUSTER_SIZE 34 #define MAPPING_VSPACE_SIZE 35 #define MAPPING_VSEG_SIZE 36 #define MAPPING_VOBJ_SIZE 37 #define MAPPING_PSEG_SIZE 38 #define MAPPING_TASK_SIZE 39 #define MAPPING_PROC_SIZE 40 #define MAPPING_IRQ_SIZE 41 #define MAPPING_COPROC_SIZE 42 #define MAPPING_CP_PORT_SIZE 43 44 #define C_MODE_MASK 0b1000// cacheable45 #define X_MODE_MASK 0b0100// executable46 #define W_MODE_MASK 0b0010// writable47 #define U_MODE_MASK 0b0001// user access32 #define MAPPING_HEADER_SIZE sizeof(mapping_header_t) 33 #define MAPPING_CLUSTER_SIZE sizeof(mapping_cluster_t) 34 #define MAPPING_VSPACE_SIZE sizeof(mapping_vspace_t) 35 #define MAPPING_VSEG_SIZE sizeof(mapping_vseg_t) 36 #define MAPPING_VOBJ_SIZE sizeof(mapping_vobj_t) 37 #define MAPPING_PSEG_SIZE sizeof(mapping_pseg_t) 38 #define MAPPING_TASK_SIZE sizeof(mapping_task_t) 39 #define MAPPING_PROC_SIZE sizeof(mapping_proc_t) 40 #define MAPPING_IRQ_SIZE sizeof(mapping_irq_t) 41 #define MAPPING_COPROC_SIZE sizeof(mapping_coproc_t) 42 #define MAPPING_CP_PORT_SIZE sizeof(mapping_cp_port_t) 43 44 #define C_MODE_MASK 0b1000 // cacheable 45 #define X_MODE_MASK 0b0100 // executable 46 #define W_MODE_MASK 0b0010 // writable 47 #define U_MODE_MASK 0b0001 // user access 48 48 49 49 #define IN_MAPPING_SIGNATURE 0xDEADBEEF 50 50 #define OUT_MAPPING_SIGNATURE 0xBABEF00D 51 51 52 enum vobjType 53 { 54 VOBJ_TYPE_ELF = 0, // loadable code/data object of elf files 55 VOBJ_TYPE_BLOB = 1, // loadable blob object 56 VOBJ_TYPE_PTAB = 2, // page table 57 VOBJ_TYPE_PERI = 3, // hardware component 58 VOBJ_TYPE_MWMR = 4, // MWMR channel 59 VOBJ_TYPE_LOCK = 5, // Lock 60 VOBJ_TYPE_BUFFER = 6, // Any "no intialiasation needed" objects (stacks...) 61 VOBJ_TYPE_BARRIER = 7, // Barrier 62 }; 63 64 enum psegType 65 { 66 PSEG_TYPE_RAM = 0, 67 PSEG_TYPE_ROM = 1, 68 PSEG_TYPE_PERI = 2, 69 }; 70 71 enum periphType 72 { 73 PERIPH_TYPE_ICU = 0, 74 PERIPH_TYPE_TIM = 1, 75 PERIPH_TYPE_XICU = 2, 76 PERIPH_TYPE_DMA = 3, 77 PERIPH_TYPE_IOC = 4, 78 PERIPH_TYPE_TTY = 5, 79 PERIPH_TYPE_FBF = 6, 80 PERIPH_TYPE_NIC = 7, 81 PERIPH_TYPE_IOB = 8, 82 }; 83 84 enum mwmrPortDirection 85 { 86 PORT_TO_COPROC = 0, // status register 87 PORT_FROM_COPROC = 1, // config register 88 }; 89 90 /////////////////////////////// 91 92 typedef struct mapping_header_s 93 { 94 unsigned int signature; // must contain MAPPING_SIGNATURE 95 unsigned int clusters; // number of clusters 96 unsigned int cluster_x; // number of cluster on the abcsisse axe 97 unsigned int cluster_y; // number of cluster on the ordinate axe 98 unsigned int globals; // number of vsegs mapped in all vspaces 99 unsigned int vspaces; // number of virtual spaces 100 101 unsigned int tty_clusterid; // index of cluster containing TTY controler 102 unsigned int ioc_clusterid; // index of cluster containing IOC controler 103 unsigned int nic_clusterid; // index of cluster containing NIC controler 104 unsigned int fbf_clusterid; // index of cluster containing FBF controler 105 106 unsigned int psegs; // total number of physical segments (for all clusters) 107 unsigned int vsegs; // total number of virtual segments (for all vspaces) 108 unsigned int vobjs; // total number of virtual objects (for all vspaces) 109 unsigned int tasks; // total number of tasks (for all vspaces) 110 unsigned int procs; // total number of procs (for all clusters) 111 unsigned int irqs; // total number of irqs (for all processors) 112 unsigned int coprocs; // total number of coprocs (for all clusters) 113 unsigned int cp_ports; // total number of cp_ports (for all coprocs) 114 unsigned int periphs; // total number of peripherals (for all clusters) 115 116 char name[32]; // mapping name 52 enum vobjType { 53 VOBJ_TYPE_ELF = 0, // loadable code/data object of elf files 54 VOBJ_TYPE_BLOB = 1, // loadable blob object 55 VOBJ_TYPE_PTAB = 2, // page table 56 VOBJ_TYPE_PERI = 3, // hardware component 57 VOBJ_TYPE_MWMR = 4, // MWMR channel 58 VOBJ_TYPE_LOCK = 5, // Lock 59 VOBJ_TYPE_BUFFER = 6, // Any "no initialization needed" objects (stacks...) 60 VOBJ_TYPE_BARRIER = 7, // Barrier 61 VOBJ_TYPE_CONST = 8, // Constant 62 VOBJ_TYPE_MEMSPACE = 9, // Memspace; different from buffer because we add infos at the beginning 63 }; 64 65 66 enum psegType { 67 PSEG_TYPE_RAM = 0, 68 PSEG_TYPE_ROM = 1, 69 PSEG_TYPE_PERI = 2, 70 }; 71 72 73 enum periphType { 74 PERIPH_TYPE_ICU = 0, 75 PERIPH_TYPE_TIM = 1, 76 PERIPH_TYPE_XICU = 2, 77 PERIPH_TYPE_DMA = 3, 78 PERIPH_TYPE_IOC = 4, 79 PERIPH_TYPE_TTY = 5, 80 PERIPH_TYPE_FBF = 6, 81 PERIPH_TYPE_NIC = 7, 82 PERIPH_TYPE_IOB = 8, 83 }; 84 85 86 enum mwmrPortDirection { 87 PORT_TO_COPROC = 0, // status register 88 PORT_FROM_COPROC = 1, // config register 89 }; 90 91 92 /////////////////////////////// 93 94 typedef struct mapping_header_s { 95 unsigned int signature; // must contain MAPPING_SIGNATURE 96 unsigned int clusters; // number of clusters 97 unsigned int cluster_x; // number of cluster on the abcsisse axe 98 unsigned int cluster_y; // number of cluster on the ordinate axe 99 unsigned int globals; // number of vsegs mapped in all vspaces 100 unsigned int vspaces; // number of virtual spaces 101 102 unsigned int tty_clusterid; // index of cluster containing TTY controler 103 unsigned int ioc_clusterid; // index of cluster containing IOC controler 104 unsigned int nic_clusterid; // index of cluster containing NIC controler 105 unsigned int fbf_clusterid; // index of cluster containing FBF controler 106 107 unsigned int psegs; // total number of physical segments (for all clusters) 108 unsigned int vsegs; // total number of virtual segments (for all vspaces) 109 unsigned int vobjs; // total number of virtual objects (for all vspaces) 110 unsigned int tasks; // total number of tasks (for all vspaces) 111 unsigned int procs; // total number of procs (for all clusters) 112 unsigned int irqs; // total number of irqs (for all processors) 113 unsigned int coprocs; // total number of coprocs (for all clusters) 114 unsigned int cp_ports; // total number of cp_ports (for all coprocs) 115 unsigned int periphs; // total number of peripherals (for all clusters) 116 117 char name[32]; // mapping name 117 118 } mapping_header_t; 118 119 120 119 121 //////////////////////////////// 120 typedef struct mapping_cluster_s 121 { 122 unsigned int psegs; // number of psegs in cluster 123 unsigned int pseg_offset; // index of first pseg in pseg set 124 125 unsigned int procs; // number of processors in cluster 126 unsigned int proc_offset; // index of first proc in proc set 127 128 unsigned int coprocs; // number of coprocessors in cluster 129 unsigned int coproc_offset; // index of first coproc in coproc set 130 131 unsigned int periphs; // number of peripherals in cluster 132 unsigned int periph_offset; // index of first coproc in coproc set 122 typedef struct mapping_cluster_s { 123 unsigned int psegs; // number of psegs in cluster 124 unsigned int pseg_offset; // index of first pseg in pseg set 125 126 unsigned int procs; // number of processors in cluster 127 unsigned int proc_offset; // index of first proc in proc set 128 129 unsigned int coprocs; // number of coprocessors in cluster 130 unsigned int coproc_offset; // index of first coproc in coproc set 131 132 unsigned int periphs; // number of peripherals in cluster 133 unsigned int periph_offset; // index of first coproc in coproc set 133 134 } mapping_cluster_t; 134 135 135 ///////////////////////////// 136 typedef struct mapping_pseg_s 137 {138 char name[32];// pseg name (unique in a cluster)139 unsigned intbase; // base address in physical space140 unsigned intlength; // size (bytes)141 unsigned int 142 unsigned int 143 unsigned int 136 137 ///////////////////////////// 138 typedef struct mapping_pseg_s { 139 char name[32]; // pseg name (unique in a cluster) 140 unsigned int base; // base address in physical space 141 unsigned int length; // size (bytes) 142 unsigned int type; // RAM / ROM / PERI 143 unsigned int cluster; // index of cluster containing pseg 144 unsigned int next_base; // first free page base address 144 145 } mapping_pseg_t; 145 146 146 /////////////////////////////// 147 typedef struct mapping_vspace_s 148 {149 char name[32];// virtual space name150 unsigned int 151 unsigned int vsegs;// number of vsegs in vspace152 unsigned int vobjs;// number of vobjs in vspace153 unsigned int tasks;// number of tasks in vspace154 unsigned int 155 unsigned int 156 unsigned int 147 148 /////////////////////////////// 149 typedef struct mapping_vspace_s { 150 char name[32]; // virtual space name 151 unsigned int start_offset; // offset of the vobj containing the start vector 152 unsigned int vsegs; // number of vsegs in vspace 153 unsigned int vobjs; // number of vobjs in vspace 154 unsigned int tasks; // number of tasks in vspace 155 unsigned int vseg_offset; // index of first vseg in vspace 156 unsigned int vobj_offset; // index of first vobjs in vspace 157 unsigned int task_offset; // index of first task in vspace 157 158 } mapping_vspace_t; 158 159 159 ///////////////////////////// 160 typedef struct mapping_vseg_s 161 {162 char name[32];// vseg name (unique in vspace)163 unsigned intvbase; // base address in virtual space (hexa)164 unsigned intpbase; // base address in physical space (hexa)165 unsigned intlength; // size (bytes)166 unsigned int psegid;// physical segment global index167 unsigned int mode;// C-X-W-U flags168 unsigned int 169 unsigned int vobjs;// number of vobjs in vseg170 unsigned int 160 161 ///////////////////////////// 162 typedef struct mapping_vseg_s { 163 char name[32]; // vseg name (unique in vspace) 164 unsigned int vbase; // base address in virtual space (hexa) 165 unsigned int pbase; // base address in physical space (hexa) 166 unsigned int length; // size (bytes) 167 unsigned int psegid; // physical segment global index 168 unsigned int mode; // C-X-W-U flags 169 unsigned int ident; // identity mapping if non zero 170 unsigned int vobjs; // number of vobjs in vseg 171 unsigned int vobj_offset; // index of first vobjs in vseg 171 172 } mapping_vseg_t; 172 173 173 ///////////////////////////// 174 typedef struct mapping_task_s 175 {176 char name[32];// task name (unique in vspace)177 unsigned int clusterid;// physical cluster index178 unsigned intproclocid; // processor local index (inside cluster)179 unsigned int 180 unsigned int 181 unsigned int 182 unsigned int 183 unsigned int 184 unsigned int 174 175 ///////////////////////////// 176 typedef struct mapping_task_s { 177 char name[32]; // task name (unique in vspace) 178 unsigned int clusterid; // physical cluster index 179 unsigned int proclocid; // processor local index (inside cluster) 180 unsigned int vobjlocid; // stack vobj index in vspace 181 unsigned int startid; // index in start_vector 182 unsigned int use_tty; // TTY terminal required (global) 183 unsigned int use_nic; // NIC channel required (global) 184 unsigned int use_timer; // user timer required (local) 185 unsigned int use_fbdma; // DMA channel to frame buffer required (local) 185 186 } mapping_task_t; 186 187 187 ///////////////////////////// 188 typedef struct mapping_vobj_s 189 {190 char name[32];// vobj name (unique in a vspace)191 char binpath[64];// path for the binary code ("*.elf")192 unsigned inttype; // type of vobj193 unsigned intlength; // size (bytes)194 unsigned intalign; // required alignement (logarithm of 2)195 unsigned intvaddr; // virtual base addresse of the vobj196 unsigned intpaddr; // physical base addresse of the vobj197 unsigned intinit; // init value (used by barrier or mwmr channel)188 189 ///////////////////////////// 190 typedef struct mapping_vobj_s { 191 char name[32]; // vobj name (unique in a vspace) 192 char binpath[64]; // path for the binary code ("*.elf") 193 unsigned int type; // type of vobj 194 unsigned int length; // size (bytes) 195 unsigned int align; // required alignement (logarithm of 2) 196 unsigned int vaddr; // virtual base addresse of the vobj 197 unsigned int paddr; // physical base addresse of the vobj 198 unsigned int init; // init value (used by barrier or mwmr channel) 198 199 } mapping_vobj_t; 199 200 200 ///////////////////////////// 201 typedef struct mapping_proc_s 202 {203 unsigned int 204 unsigned int 201 202 ///////////////////////////// 203 typedef struct mapping_proc_s { 204 unsigned int irqs; // number of IRQs allocated to processor 205 unsigned int irq_offset; // index of first IRQ allocated to processor 205 206 } mapping_proc_t; 206 207 207 ///////////////////////////// 208 typedef struct mapping_irq_s 209 {210 unsigned int 211 unsigned int 212 unsigned int 213 unsigned int 208 209 ///////////////////////////// 210 typedef struct mapping_irq_s { 211 unsigned int type; // 0 => HW_IRQ / 1 => SW_IRQ 212 unsigned int icuid; // IRQ Index for the ICU component 213 unsigned int isr; // Interrupt Service Routine Index 214 unsigned int channel; // Channel Index (for multi-cannels peripherals) 214 215 } mapping_irq_t; 215 216 216 /////////////////////////////// 217 typedef struct mapping_coproc_s 218 {219 char name[32];// coprocessor name220 unsigned int 221 unsigned int 222 unsigned int 217 218 /////////////////////////////// 219 typedef struct mapping_coproc_s { 220 char name[32]; // coprocessor name 221 unsigned int psegid; // global pseg index 222 unsigned int ports; // number of MWMR ports used by coprocessor 223 unsigned int port_offset; // index of first MWMR port used by coprocessor 223 224 } mapping_coproc_t; 224 225 226 225 227 //////////////////////////////// 226 typedef struct mapping_cp_port_s 227 { 228 unsigned int direction; // TO_COPROC == 0 / FROM_COPROC == 1 229 unsigned int vspaceid; // index of the vspace containing the MWMR channel 230 unsigned int vobjlocid; // local index of the vobj containing the MWMR channel 228 typedef struct mapping_cp_port_s { 229 unsigned int direction; // TO_COPROC == 0 / FROM_COPROC == 1 230 unsigned int vspaceid; // index of the vspace containing the MWMR channel 231 unsigned int vobjlocid; // local index of the vobj containing the MWMR channel 231 232 } mapping_cp_port_t; 232 233 233 /////////////////////////////// 234 typedef struct mapping_periph_s 235 {236 unsigned int 237 unsigned int 238 unsigned int 234 235 /////////////////////////////// 236 typedef struct mapping_periph_s { 237 unsigned int type; // IOC / TTY / TIM / DMA / FBF / NIC / IOB 238 unsigned int psegid; // pseg index in cluster 239 unsigned int channels; // number of channels 239 240 } mapping_periph_t; 240 241 … … 249 250 // End: 250 251 251 // vim: filetype=c pp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4252 252 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 253 -
soft/giet_vm/xml/xml_driver.c
r215 r228 18 18 19 19 ////////////////////////////////////////////////////// 20 void buildXml( mapping_header_t* header, FILE* fpout ) 21 { 22 const char* vobj_type[] = 20 void buildXml(mapping_header_t * header, FILE * fpout) { 21 const char * vobj_type[] = 23 22 { 24 "ELF", // binary code generated by GCC 25 "BLOB", // binary code generated by GCC 26 "PTAB", // page table 27 "PERI", // hardware component 28 "MWMR", // MWMR channel 29 "LOCK", // Spin-Lock 30 "BUFFER", // Any "no intialiasation needed" objects (stacks...) 31 "BARRIER", // Barrier 32 }; 33 34 const char* pseg_type[] = 23 "ELF", // binary code generated by GCC 24 "BLOB", // binary code generated by GCC 25 "PTAB", // page table 26 "PERI", // hardware component 27 "MWMR", // MWMR channel 28 "LOCK", // Spin-Lock 29 "BUFFER", // Any "no intialiasation needed" objects (stacks...) 30 "BARRIER", // Barrier 31 "CONST", // Constant 32 "MEMSPACE", // Memspace 33 }; 34 35 const char * pseg_type[] = 35 36 { 36 37 "RAM", … … 39 40 }; 40 41 41 const char * irq_type[] =42 const char * irq_type[] = 42 43 { 43 44 "HARD", … … 45 46 }; 46 47 47 const char * isr_type[] =48 const char * isr_type[] = 48 49 { 49 50 "ISR_DEFAULT", … … 55 56 }; 56 57 57 const char * periph_type[] =58 const char * periph_type[] = 58 59 { 59 60 "ICU", … … 68 69 }; 69 70 70 const char * port_direction[] =71 const char * port_direction[] = 71 72 { 72 73 "TO_COPROC", … … 74 75 }; 75 76 76 const char* mode_str[] = 77 { "____", 78 "___U", 79 "__W_", 80 "__WU", 81 "_X__", 82 "_X_U", 83 "_XW_", 84 "_XWU", 85 "C___", 86 "C__U", 87 "C_W_", 88 "C_WU", 89 "CX__", 90 "CX_U", 91 "CXW_", 92 "CXWU", 93 }; 94 95 unsigned int vspace_id; 96 unsigned int cluster_id; 97 unsigned int pseg_id; 98 unsigned int vseg_id; 99 unsigned int vobj_id; 100 unsigned int task_id; 101 unsigned int proc_id; 102 unsigned int irq_id; 103 unsigned int coproc_id; 104 unsigned int port_id; 105 unsigned int periph_id; 106 107 mapping_cluster_t* cluster; 108 mapping_pseg_t* pseg; 109 mapping_vspace_t* vspace; 110 mapping_vseg_t* vseg; 111 mapping_vobj_t* vobj; 112 mapping_task_t* task; 113 mapping_proc_t* proc; 114 mapping_irq_t* irq; 115 mapping_coproc_t* coproc; 116 mapping_cp_port_t* cp_port; 117 mapping_periph_t* periph; 77 const char * mode_str[] = 78 { 79 "____", 80 "___U", 81 "__W_", 82 "__WU", 83 "_X__", 84 "_X_U", 85 "_XW_", 86 "_XWU", 87 "C___", 88 "C__U", 89 "C_W_", 90 "C_WU", 91 "CX__", 92 "CX_U", 93 "CXW_", 94 "CXWU", 95 }; 96 97 unsigned int vspace_id; 98 unsigned int cluster_id; 99 unsigned int pseg_id; 100 unsigned int vseg_id; 101 unsigned int vobj_id; 102 unsigned int task_id; 103 unsigned int proc_id; 104 unsigned int irq_id; 105 unsigned int coproc_id; 106 unsigned int port_id; 107 unsigned int periph_id; 108 109 mapping_cluster_t * cluster; 110 mapping_pseg_t * pseg; 111 mapping_vspace_t * vspace; 112 mapping_vseg_t * vseg; 113 mapping_vobj_t * vobj; 114 mapping_task_t * task; 115 mapping_proc_t * proc; 116 mapping_irq_t * irq; 117 mapping_coproc_t * coproc; 118 mapping_cp_port_t * cp_port; 119 mapping_periph_t * periph; 118 120 119 121 // computes the base adresss for clusters array, 120 cluster = (mapping_cluster_t *)((char*)header +121 MAPPING_HEADER_SIZE);122 cluster = (mapping_cluster_t *)((char *) header + 123 MAPPING_HEADER_SIZE); 122 124 123 125 // computes the base adresss for psegs array, 124 pseg = (mapping_pseg_t*) ((char*)header +125 126 MAPPING_CLUSTER_SIZE*header->clusters);126 pseg = (mapping_pseg_t *) ((char *) header + 127 MAPPING_HEADER_SIZE + 128 MAPPING_CLUSTER_SIZE * header->clusters); 127 129 128 130 // computes the base adresss for vspaces array, 129 vspace = (mapping_vspace_t*) ((char*)header +130 131 MAPPING_CLUSTER_SIZE*header->clusters +132 MAPPING_PSEG_SIZE*header->psegs);131 vspace = (mapping_vspace_t *) ((char *) header + 132 MAPPING_HEADER_SIZE + 133 MAPPING_CLUSTER_SIZE * header->clusters + 134 MAPPING_PSEG_SIZE * header->psegs); 133 135 134 136 // computes the base adresss for vsegs array, 135 vseg = (mapping_vseg_t*) ((char*)header +136 137 MAPPING_CLUSTER_SIZE*header->clusters +138 MAPPING_PSEG_SIZE*header->psegs +139 MAPPING_VSPACE_SIZE*header->vspaces);137 vseg = (mapping_vseg_t *) ((char *) header + 138 MAPPING_HEADER_SIZE + 139 MAPPING_CLUSTER_SIZE * header->clusters + 140 MAPPING_PSEG_SIZE * header->psegs + 141 MAPPING_VSPACE_SIZE * header->vspaces); 140 142 141 143 // computes the base adresss for vobjs array, 142 vobj = (mapping_vobj_t*) ((char*)header +143 144 MAPPING_CLUSTER_SIZE*header->clusters +145 MAPPING_PSEG_SIZE*header->psegs +146 MAPPING_VSPACE_SIZE*header->vspaces +147 MAPPING_VSEG_SIZE*header->vsegs);144 vobj = (mapping_vobj_t *) ((char *) header + 145 MAPPING_HEADER_SIZE + 146 MAPPING_CLUSTER_SIZE * header->clusters + 147 MAPPING_PSEG_SIZE * header->psegs + 148 MAPPING_VSPACE_SIZE * header->vspaces + 149 MAPPING_VSEG_SIZE * header->vsegs); 148 150 149 151 // computes the base address for tasks array 150 task = (mapping_task_t*) ((char*)header +151 152 MAPPING_CLUSTER_SIZE*header->clusters +153 MAPPING_PSEG_SIZE*header->psegs +154 MAPPING_VSPACE_SIZE*header->vspaces +155 MAPPING_VOBJ_SIZE*header->vobjs +156 MAPPING_VSEG_SIZE*header->vsegs);152 task = (mapping_task_t *) ((char *) header + 153 MAPPING_HEADER_SIZE + 154 MAPPING_CLUSTER_SIZE * header->clusters + 155 MAPPING_PSEG_SIZE * header->psegs + 156 MAPPING_VSPACE_SIZE * header->vspaces + 157 MAPPING_VOBJ_SIZE * header->vobjs + 158 MAPPING_VSEG_SIZE * header->vsegs); 157 159 158 160 // computes the base address for procs array 159 proc = (mapping_proc_t*) ((char*)header +160 161 MAPPING_CLUSTER_SIZE*header->clusters +162 MAPPING_PSEG_SIZE*header->psegs +163 MAPPING_VSPACE_SIZE*header->vspaces +164 MAPPING_VOBJ_SIZE*header->vobjs +165 MAPPING_VSEG_SIZE*header->vsegs +166 MAPPING_TASK_SIZE*header->tasks);161 proc = (mapping_proc_t *) ((char *) header + 162 MAPPING_HEADER_SIZE + 163 MAPPING_CLUSTER_SIZE * header->clusters + 164 MAPPING_PSEG_SIZE * header->psegs + 165 MAPPING_VSPACE_SIZE * header->vspaces + 166 MAPPING_VOBJ_SIZE * header->vobjs + 167 MAPPING_VSEG_SIZE * header->vsegs + 168 MAPPING_TASK_SIZE * header->tasks); 167 169 168 170 // computes the base address for irqs array 169 irq = (mapping_irq_t*) ((char*)header +170 171 MAPPING_CLUSTER_SIZE*header->clusters +172 MAPPING_PSEG_SIZE*header->psegs +173 MAPPING_VSPACE_SIZE*header->vspaces +174 MAPPING_VOBJ_SIZE*header->vobjs +175 MAPPING_VSEG_SIZE*header->vsegs +176 MAPPING_TASK_SIZE*header->tasks +177 MAPPING_PROC_SIZE*header->procs);171 irq = (mapping_irq_t *) ((char *) header + 172 MAPPING_HEADER_SIZE + 173 MAPPING_CLUSTER_SIZE * header->clusters + 174 MAPPING_PSEG_SIZE * header->psegs + 175 MAPPING_VSPACE_SIZE * header->vspaces + 176 MAPPING_VOBJ_SIZE * header->vobjs + 177 MAPPING_VSEG_SIZE * header->vsegs + 178 MAPPING_TASK_SIZE * header->tasks + 179 MAPPING_PROC_SIZE * header->procs); 178 180 179 181 // computes the base address for coprocs array 180 coproc = (mapping_coproc_t *) ((char*)header +181 182 MAPPING_CLUSTER_SIZE*header->clusters +183 MAPPING_PSEG_SIZE*header->psegs +184 MAPPING_VSPACE_SIZE*header->vspaces +185 MAPPING_VOBJ_SIZE*header->vobjs +186 MAPPING_VSEG_SIZE*header->vsegs +187 MAPPING_TASK_SIZE*header->tasks +188 MAPPING_PROC_SIZE*header->procs +189 MAPPING_IRQ_SIZE*header->irqs);182 coproc = (mapping_coproc_t *) ((char *) header + 183 MAPPING_HEADER_SIZE + 184 MAPPING_CLUSTER_SIZE * header->clusters + 185 MAPPING_PSEG_SIZE * header->psegs + 186 MAPPING_VSPACE_SIZE * header->vspaces + 187 MAPPING_VOBJ_SIZE * header->vobjs + 188 MAPPING_VSEG_SIZE * header->vsegs + 189 MAPPING_TASK_SIZE * header->tasks + 190 MAPPING_PROC_SIZE * header->procs + 191 MAPPING_IRQ_SIZE * header->irqs); 190 192 191 193 // computes the base address for cp_ports array 192 cp_port = (mapping_cp_port_t *)((char*)header +193 194 MAPPING_CLUSTER_SIZE*header->clusters +195 MAPPING_PSEG_SIZE*header->psegs +196 MAPPING_VSPACE_SIZE*header->vspaces +197 MAPPING_VOBJ_SIZE*header->vobjs +198 MAPPING_VSEG_SIZE*header->vsegs +199 MAPPING_TASK_SIZE*header->tasks +200 MAPPING_PROC_SIZE*header->procs +201 MAPPING_IRQ_SIZE*header->irqs +202 MAPPING_COPROC_SIZE*header->coprocs);194 cp_port = (mapping_cp_port_t *) ((char *) header + 195 MAPPING_HEADER_SIZE + 196 MAPPING_CLUSTER_SIZE * header->clusters + 197 MAPPING_PSEG_SIZE * header->psegs + 198 MAPPING_VSPACE_SIZE * header->vspaces + 199 MAPPING_VOBJ_SIZE * header->vobjs + 200 MAPPING_VSEG_SIZE * header->vsegs + 201 MAPPING_TASK_SIZE * header->tasks + 202 MAPPING_PROC_SIZE * header->procs + 203 MAPPING_IRQ_SIZE * header->irqs + 204 MAPPING_COPROC_SIZE * header->coprocs); 203 205 204 206 // computes the base address for periphs array 205 periph = (mapping_periph_t *) ((char*)header +206 207 MAPPING_CLUSTER_SIZE*header->clusters +208 MAPPING_PSEG_SIZE*header->psegs +209 MAPPING_VSPACE_SIZE*header->vspaces +210 MAPPING_VOBJ_SIZE*header->vobjs +211 MAPPING_VSEG_SIZE*header->vsegs +212 MAPPING_TASK_SIZE*header->tasks +213 MAPPING_PROC_SIZE*header->procs +214 MAPPING_IRQ_SIZE*header->irqs +215 MAPPING_COPROC_SIZE*header->coprocs +216 MAPPING_CP_PORT_SIZE*header->cp_ports);207 periph = (mapping_periph_t *) ((char *) header + 208 MAPPING_HEADER_SIZE + 209 MAPPING_CLUSTER_SIZE * header->clusters + 210 MAPPING_PSEG_SIZE * header->psegs + 211 MAPPING_VSPACE_SIZE * header->vspaces + 212 MAPPING_VOBJ_SIZE * header->vobjs + 213 MAPPING_VSEG_SIZE * header->vsegs + 214 MAPPING_TASK_SIZE * header->tasks + 215 MAPPING_PROC_SIZE * header->procs + 216 MAPPING_IRQ_SIZE * header->irqs + 217 MAPPING_COPROC_SIZE * header->coprocs + 218 MAPPING_CP_PORT_SIZE * header->cp_ports); 217 219 218 220 ///////////////////////// header ///////////////////////////////////////////// 219 221 220 fprintf( 221 222 fprintf( 223 fprintf( 224 fprintf( 225 fprintf( 226 fprintf( 222 fprintf(fpout, "<?xml version = \"1.0\"?>\n\n"); 223 224 fprintf(fpout, "<mapping_info signature = \"0x%x\" ", header->signature); 225 fprintf(fpout, " name = \"%s\" ", header->name); 226 fprintf(fpout, " cluster_x = \"%d\" ", header->cluster_x); 227 fprintf(fpout, " cluster_y = \"%d\" ", header->cluster_y); 228 fprintf(fpout, " vspaces = \"%d\" >\n\n", header->vspaces); 227 229 228 230 ///////////////////// clusters /////////////////////////////////////////////// 229 231 230 fprintf( fpout, " <clusterset>\n" ); 231 for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) 232 { 233 fprintf( fpout, " <cluster index = \"%d\" >\n", cluster_id); 234 for ( pseg_id = cluster[cluster_id].pseg_offset ; 235 pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs ; 236 pseg_id++ ) 237 { 238 fprintf( fpout, " <pseg name = \"%s\" ", pseg[pseg_id].name); 239 fprintf( fpout, " type = \"%s\" ", pseg_type[pseg[pseg_id].type]); 240 fprintf( fpout, " base = \"0x%x\" ", pseg[pseg_id].base); 241 fprintf( fpout, " length = \"0x%x\" />\n", pseg[pseg_id].length); 242 } 243 244 ///////////////////// processors ///////////////////////////////////////////// 232 fprintf( fpout, " <clusterset>\n"); 233 for (cluster_id = 0; cluster_id < header->clusters; cluster_id++) { 234 fprintf(fpout, " <cluster index = \"%d\" >\n", cluster_id); 235 for (pseg_id = cluster[cluster_id].pseg_offset; 236 pseg_id < cluster[cluster_id].pseg_offset + cluster[cluster_id].psegs; 237 pseg_id++) { 238 fprintf(fpout, " <pseg name = \"%s\" ", pseg[pseg_id].name); 239 fprintf(fpout, " type = \"%s\" ", pseg_type[pseg[pseg_id].type]); 240 fprintf(fpout, " base = \"0x%x\" ", pseg[pseg_id].base); 241 fprintf(fpout, " length = \"0x%x\" />\n", pseg[pseg_id].length); 242 } 243 244 ///////////////////// processors ///////////////////////////////////////////// 245 245 246 246 unsigned int proc_index = 0; 247 for ( proc_id = cluster[cluster_id].proc_offset ; 248 proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs ; 249 proc_id++ ) 250 { 251 fprintf( fpout, " <proc index = \"%d\" >\n", proc_index); 252 for ( irq_id = proc[proc_id].irq_offset ; 253 irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs ; 254 irq_id++ ) 255 { 256 fprintf( fpout, " <irq type = \"%s\" ", irq_type[irq[irq_id].type]); 257 fprintf( fpout, " icuid = \"0x%x\" ", irq[irq_id].icuid); 258 fprintf( fpout, " isr = \"%s\" ", isr_type[irq[irq_id].isr]); 259 fprintf( fpout, " channel = \"0x%x\" />\n", irq[irq_id].channel); 247 for (proc_id = cluster[cluster_id].proc_offset; 248 proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs; 249 proc_id++) { 250 fprintf(fpout, " <proc index = \"%d\" >\n", proc_index); 251 for (irq_id = proc[proc_id].irq_offset; 252 irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs; 253 irq_id++) { 254 fprintf(fpout, " <irq type = \"%s\" ", irq_type[irq[irq_id].type]); 255 fprintf(fpout, " icuid = \"0x%x\" ", irq[irq_id].icuid); 256 fprintf(fpout, " isr = \"%s\" ", isr_type[irq[irq_id].isr]); 257 fprintf(fpout, " channel = \"0x%x\" />\n", irq[irq_id].channel); 260 258 } 261 fprintf( fpout, " </proc>\n" ); 262 } 263 264 265 ///////////////////// coprocessors /////////////////////////////////////////// 266 267 for ( coproc_id = cluster[cluster_id].coproc_offset ; 268 coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs ; 269 coproc_id++ ) 270 { 271 fprintf( fpout, " <coproc name = \"%s\" ", coproc[coproc_id].name); 272 fprintf( fpout, " psegname = \"%s\" >\n", pseg[coproc[coproc_id].psegid].name); 273 for ( port_id = coproc[coproc_id].port_offset ; 274 port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports ; 275 port_id++ ) 276 { 259 fprintf(fpout, " </proc>\n" ); 260 } 261 262 263 ///////////////////// coprocessors /////////////////////////////////////////// 264 265 for (coproc_id = cluster[cluster_id].coproc_offset; 266 coproc_id < cluster[cluster_id].coproc_offset + cluster[cluster_id].coprocs; 267 coproc_id++) { 268 fprintf(fpout, " <coproc name = \"%s\" ", coproc[coproc_id].name); 269 fprintf(fpout, " psegname = \"%s\" >\n", pseg[coproc[coproc_id].psegid].name); 270 for (port_id = coproc[coproc_id].port_offset; 271 port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports; 272 port_id++) { 277 273 unsigned int vobj_id = cp_port[port_id].vobjlocid + vspace[cp_port[port_id].vspaceid].vobj_offset; 278 fprintf( fpout, " <port direction = \"%s\" ", port_direction[cp_port[port_id].direction]);279 fprintf( 280 fprintf( 274 fprintf(fpout, " <port direction = \"%s\" ", port_direction[cp_port[port_id].direction]); 275 fprintf(fpout, " vspacename = \"%s\" ", vspace[cp_port[port_id].vspaceid].name); 276 fprintf(fpout, " vobjname = \"%s\" />\n", vobj[vobj_id].name); 281 277 } 282 fprintf( fpout, " </coproc>\n" ); 283 } 284 285 ///////////////////// periphs /////////////////////////////////////////////// 286 287 for ( periph_id = cluster[cluster_id].periph_offset ; 288 periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs ; 289 periph_id++ ) 290 { 291 fprintf( fpout, " <periph type = \"%s\" ", periph_type[periph[periph_id].type]); 292 fprintf( fpout, " psegname = \"%s\" ", pseg[periph[periph_id].psegid].name); 293 fprintf( fpout, " channels = \"%d\" />\n", periph[periph_id].channels); 294 } 295 fprintf( fpout, " </cluster>\n" ); 296 } 297 fprintf( fpout, " </clusterset>\n\n" ); 278 fprintf(fpout, " </coproc>\n" ); 279 } 280 281 ///////////////////// periphs /////////////////////////////////////////////// 282 283 for (periph_id = cluster[cluster_id].periph_offset; 284 periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs; 285 periph_id++) { 286 fprintf(fpout, " <periph type = \"%s\" ", periph_type[periph[periph_id].type]); 287 fprintf(fpout, " psegname = \"%s\" ", pseg[periph[periph_id].psegid].name); 288 fprintf(fpout, " channels = \"%d\" />\n", periph[periph_id].channels); 289 } 290 fprintf(fpout, " </cluster>\n" ); 291 } 292 fprintf(fpout, " </clusterset>\n\n" ); 298 293 299 294 /////////////////// globals ///////////////////////////////////////////////// 300 295 301 fprintf( fpout, " <globalset>\n" ); 302 for ( vseg_id = 0 ; vseg_id < header->globals ; vseg_id++ ) 303 { 296 fprintf(fpout, " <globalset>\n" ); 297 for (vseg_id = 0; vseg_id < header->globals; vseg_id++) { 304 298 unsigned int pseg_id = vseg[vseg_id].psegid; 305 299 306 fprintf( fpout, " <vseg name = \"%s\" ", vseg[vseg_id].name); 307 fprintf( fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase); 308 fprintf( fpout, "mode = \"%s\" ", mode_str[vseg[vseg_id].mode]); 309 fprintf( fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster); 310 fprintf( fpout, "psegname = \"%s\" ", pseg[pseg_id].name); 311 fprintf( fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident); 312 for ( vobj_id = vseg[vseg_id].vobj_offset; 313 vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); 314 vobj_id++ ) 315 { 316 fprintf( fpout, " <vobj name = \"%s\" ", vobj[vobj_id].name); 317 fprintf( fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]); 318 fprintf( fpout, "length = \"0x%x\" ", vobj[vobj_id].length); 319 fprintf( fpout, "align = \"%d\" ", vobj[vobj_id].align); 320 fprintf( fpout, "init = \"%d\" ", vobj[vobj_id].init); 321 fprintf( fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath); 322 } 323 fprintf( fpout, " </vseg>\n"); 324 } 325 fprintf( fpout, " </globalset>\n" ); 300 fprintf(fpout, " <vseg name = \"%s\" ", vseg[vseg_id].name); 301 fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase); 302 fprintf(fpout, "mode = \"%s\" ", mode_str[vseg[vseg_id].mode]); 303 fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster); 304 fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name); 305 fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident); 306 for (vobj_id = vseg[vseg_id].vobj_offset; 307 vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); 308 vobj_id++) { 309 fprintf(fpout, " <vobj name = \"%s\" ", vobj[vobj_id].name); 310 fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]); 311 fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length); 312 fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align); 313 fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init); 314 fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath); 315 } 316 fprintf(fpout, " </vseg>\n"); 317 } 318 fprintf(fpout, " </globalset>\n" ); 326 319 327 320 //////////////////// vspaces //////////////////////////////////////////////// 328 321 329 322 fprintf( fpout, "\n <vspaceset>\n\n" ); 330 for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) 331 { 323 for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) { 332 324 unsigned int func_id = vspace[vspace_id].vobj_offset + vspace[vspace_id].start_offset; 333 fprintf( fpout, " <vspace name = \"%s\" ", vspace[vspace_id].name); 334 fprintf( fpout, " startname = \"%s\" >\n", vobj[func_id].name); 335 336 for ( vseg_id = vspace[vspace_id].vseg_offset ; 337 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs) ; 338 vseg_id++ ) 339 { 325 fprintf(fpout, " <vspace name = \"%s\" ", vspace[vspace_id].name); 326 fprintf(fpout, " startname = \"%s\" >\n", vobj[func_id].name); 327 328 for (vseg_id = vspace[vspace_id].vseg_offset; 329 vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); 330 vseg_id++) { 340 331 unsigned int pseg_id = vseg[vseg_id].psegid; 341 332 342 fprintf( fpout, " <vseg name = \"%s\" ", vseg[vseg_id].name); 343 fprintf( fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase); 344 fprintf( fpout, "mode = \"%s\" ", mode_str[vseg[vseg_id].mode]); 345 fprintf( fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster); 346 fprintf( fpout, "psegname = \"%s\" ", pseg[pseg_id].name); 347 fprintf( fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident); 348 349 for ( vobj_id = vseg[vseg_id].vobj_offset ; 350 vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs) ; 351 vobj_id++ ) 352 { 353 fprintf( fpout, " <vobj name = \"%s\" ", vobj[vobj_id].name); 354 fprintf( fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]); 355 fprintf( fpout, "length = \"0x%x\" ", vobj[vobj_id].length); 356 fprintf( fpout, "align = \"%d\" ", vobj[vobj_id].align); 357 fprintf( fpout, "init = \"%d\" ", vobj[vobj_id].init); 358 fprintf( fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath); 333 fprintf(fpout, " <vseg name = \"%s\" ", vseg[vseg_id].name); 334 fprintf(fpout, "vbase = \"0x%x\" ", vseg[vseg_id].vbase); 335 fprintf(fpout, "mode = \"%s\" ", mode_str[vseg[vseg_id].mode]); 336 fprintf(fpout, "clusterid = \"%d\" ", pseg[pseg_id].cluster); 337 fprintf(fpout, "psegname = \"%s\" ", pseg[pseg_id].name); 338 fprintf(fpout, "ident = \"%d\" >\n", vseg[vseg_id].ident); 339 340 for (vobj_id = vseg[vseg_id].vobj_offset; 341 vobj_id < (vseg[vseg_id].vobj_offset + vseg[vseg_id].vobjs); 342 vobj_id++) { 343 fprintf(fpout, " <vobj name = \"%s\" ", vobj[vobj_id].name); 344 fprintf(fpout, "type = \"%s\" ", vobj_type[vobj[vobj_id].type]); 345 fprintf(fpout, "length = \"0x%x\" ", vobj[vobj_id].length); 346 fprintf(fpout, "align = \"%d\" ", vobj[vobj_id].align); 347 fprintf(fpout, "init = \"%d\" ", vobj[vobj_id].init); 348 fprintf(fpout, "binpath = \"%s\" />\n", vobj[vobj_id].binpath); 359 349 } 360 fprintf( fpout, " </vseg>\n\n"); 361 } 362 for ( task_id = vspace[vspace_id].task_offset ; 363 task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks) ; 364 task_id++ ) 365 { 350 fprintf(fpout, " </vseg>\n\n"); 351 } 352 for (task_id = vspace[vspace_id].task_offset; 353 task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks); 354 task_id++) { 366 355 unsigned int vobj_id = task[task_id].vobjlocid + vspace[vspace_id].vobj_offset; 367 356 368 fprintf( 369 fprintf( 370 fprintf( 371 fprintf( 372 fprintf( 373 fprintf( 374 fprintf( 375 fprintf( 376 fprintf( 377 } 378 fprintf( 379 } 380 fprintf( fpout, " </vspaceset>\n");381 fprintf( 357 fprintf(fpout, " <task name = \"%s\" ", task[task_id].name); 358 fprintf(fpout, "clusterid = \"%d\" ", task[task_id].clusterid); 359 fprintf(fpout, "proclocid = \"%d\" ", task[task_id].proclocid); 360 fprintf(fpout, "stackname = \"%s\" ", vobj[vobj_id].name); 361 fprintf(fpout, "startid = \"%d\" ", task[task_id].startid); 362 fprintf(fpout, "usetty = \"%d\" ", task[task_id].use_tty); 363 fprintf(fpout, "usenic = \"%d\" ", task[task_id].use_nic); 364 fprintf(fpout, "usetimer = \"%d\" ", task[task_id].use_timer); 365 fprintf(fpout, "usefbma = \"%d\" />\n", task[task_id].use_fbdma); 366 } 367 fprintf(fpout, " </vspace>\n\n"); 368 } 369 fprintf(fpout, " </vspaceset>\n"); 370 fprintf(fpout, "</mapping_info>\n"); 382 371 } // end buildXml() 383 372 373 384 374 ///////////////////////////////////// 385 int main ( int argc, char* argv[] ) 386 { 387 if ( argc < 2 ) 388 { 375 int main(int argc, char * argv[]) { 376 if (argc < 2) { 389 377 printf("Usage: bin2xml <input_file_path> <output_file_path>\n"); 390 378 return 1; 391 379 } 392 380 393 unsigned int bin[0x10000]; // 64 K int = 256 Kbytes 394 395 int fdin = open( argv[1], O_RDONLY ); 396 if (fdin < 0) 397 { 381 unsigned int bin[0x10000]; // 64 K int = 256 Kbytes 382 383 int fdin = open(argv[1], O_RDONLY); 384 if (fdin < 0) { 398 385 perror("open"); 399 386 exit(1); 400 387 } 401 388 402 FILE* fpout = fopen( argv[2], "w" ); 403 if (fpout == NULL) 404 { 389 FILE * fpout = fopen( argv[2], "w"); 390 if (fpout == NULL) { 405 391 perror("open"); 406 392 exit(1); … … 409 395 unsigned int length = read(fdin, bin, 0x40000); 410 396 411 if ( length <= 0 ) 412 { 397 if (length <= 0) { 413 398 perror("read"); 414 399 exit(1); 415 400 } 416 401 417 if ( bin[0] == IN_MAPPING_SIGNATURE ) 418 { 419 buildXml( (mapping_header_t*)bin, fpout ); 402 if (bin[0] == IN_MAPPING_SIGNATURE) { 403 buildXml((mapping_header_t *) bin, fpout); 420 404 } 421 else 422 { 405 else { 423 406 printf("[ERROR] Wrong file format\n"); 424 407 exit(1); … … 426 409 return 0; 427 410 } // end main() 411 412 413 414 // Local Variables: 415 // tab-width: 4 416 // c-basic-offset: 4 417 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 418 // indent-tabs-mode: nil 419 // End: 420 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 421 -
soft/giet_vm/xml/xml_parser.c
r226 r228 30 30 #include <irq_handler.h> 31 31 32 #define MAX_CLUSTERS 33 #define MAX_PSEGS 34 #define MAX_VSPACES 35 #define MAX_TASKS 36 #define MAX_MWMRS 37 #define MAX_VSEGS 38 #define MAX_VOBJS 39 #define MAX_PROCS 40 #define MAX_IRQS 41 #define MAX_COPROCS 42 #define MAX_CP_PORTS 43 #define MAX_PERIPHS 44 45 #define XML_PARSER_DEBUG 32 #define MAX_CLUSTERS 1024 33 #define MAX_PSEGS 4096 34 #define MAX_VSPACES 1024 35 #define MAX_TASKS 4096 36 #define MAX_MWMRS 4096 37 #define MAX_VSEGS 4096 38 #define MAX_VOBJS 8192 39 #define MAX_PROCS 1024 40 #define MAX_IRQS 8192 41 #define MAX_COPROCS 4096 42 #define MAX_CP_PORTS 8192 43 #define MAX_PERIPHS 8192 44 45 #define XML_PARSER_DEBUG 0 46 46 47 47 /////////////////////////////////////////////////////////////////////////////////// 48 // 48 // global variables used to store and index the data structures 49 49 /////////////////////////////////////////////////////////////////////////////////// 50 50 51 mapping_header_t *header;52 mapping_cluster_t * cluster[MAX_CLUSTERS];// cluster array53 mapping_pseg_t * pseg[MAX_PSEGS];// pseg array54 mapping_vspace_t * vspace[MAX_VSPACES];// vspace array55 mapping_vseg_t * vseg[MAX_VSEGS];// vseg array56 mapping_vobj_t * vobj[MAX_VOBJS];// vobj array57 mapping_task_t * task[MAX_TASKS];// task array58 mapping_proc_t * proc[MAX_PROCS];// proc array59 mapping_irq_t * irq[MAX_IRQS];// irq array60 mapping_coproc_t * coproc[MAX_COPROCS];// coproc array61 mapping_cp_port_t * cp_port[MAX_CP_PORTS];// coproc port array62 mapping_periph_t * periph[MAX_PERIPHS];// peripheral array51 mapping_header_t * header; 52 mapping_cluster_t * cluster[MAX_CLUSTERS]; // cluster array 53 mapping_pseg_t * pseg[MAX_PSEGS]; // pseg array 54 mapping_vspace_t * vspace[MAX_VSPACES]; // vspace array 55 mapping_vseg_t * vseg[MAX_VSEGS]; // vseg array 56 mapping_vobj_t * vobj[MAX_VOBJS]; // vobj array 57 mapping_task_t * task[MAX_TASKS]; // task array 58 mapping_proc_t * proc[MAX_PROCS]; // proc array 59 mapping_irq_t * irq[MAX_IRQS]; // irq array 60 mapping_coproc_t * coproc[MAX_COPROCS]; // coproc array 61 mapping_cp_port_t * cp_port[MAX_CP_PORTS]; // coproc port array 62 mapping_periph_t * periph[MAX_PERIPHS]; // peripheral array 63 63 64 64 // Index for the various arrays 65 65 66 unsigned int 67 unsigned int vspace_index= 0;68 unsigned int global_index= 0;69 unsigned int pseg_index = 0;70 71 unsigned int proc_index= 0;72 unsigned int 73 74 unsigned int irq_index= 0;75 unsigned int 76 77 unsigned int coproc_index= 0;78 unsigned int 79 80 unsigned int cp_port_index= 0;81 unsigned int 82 83 unsigned int periph_index= 0;84 unsigned int 85 86 unsigned int vseg_index= 0;87 unsigned int 88 89 unsigned int task_index= 0;90 unsigned int 91 92 unsigned int vobj_index= 0;93 unsigned int 94 unsigned int vobj_count= 0;66 unsigned int cluster_index = 0; 67 unsigned int vspace_index = 0; 68 unsigned int global_index = 0; 69 unsigned int pseg_index = 0; 70 71 unsigned int proc_index = 0; 72 unsigned int proc_loc_index = 0; 73 74 unsigned int irq_index = 0; 75 unsigned int irq_loc_index = 0; 76 77 unsigned int coproc_index = 0; 78 unsigned int coproc_loc_index = 0; 79 80 unsigned int cp_port_index = 0; 81 unsigned int cp_port_loc_index = 0; 82 83 unsigned int periph_index = 0; 84 unsigned int periph_loc_index = 0; 85 86 unsigned int vseg_index = 0; 87 unsigned int vseg_loc_index = 0; 88 89 unsigned int task_index = 0; 90 unsigned int task_loc_index = 0; 91 92 unsigned int vobj_index = 0; 93 unsigned int vobj_loc_index = 0; 94 unsigned int vobj_count = 0; 95 95 96 96 … … 107 107 //needed to generate map_config.ld 108 108 ////////////////////////////////// 109 unsigned int cluster_y 110 unsigned int cluster_x 111 unsigned int nb_proc_max 112 unsigned int nb_timer_channel_max 113 unsigned int nb_dma_channel_max 114 unsigned int nb_tty_channel 115 unsigned int nb_ioc_channel 116 unsigned int nb_nic_channel 117 unsigned int io_mmu_active 118 unsigned int use_xicu 109 unsigned int cluster_y = 0; 110 unsigned int cluster_x = 0; 111 unsigned int nb_proc_max = 0; // max number of processors per cluster 112 unsigned int nb_timer_channel_max = 0; // max number of user timer 113 unsigned int nb_dma_channel_max = 0; 114 unsigned int nb_tty_channel = 0; 115 unsigned int nb_ioc_channel = 0; 116 unsigned int nb_nic_channel = 0; 117 unsigned int io_mmu_active = 0; 118 unsigned int use_xicu = 0xFFFFFFFF; 119 119 120 120 … … 124 124 125 125 //kernel and boot code 126 unsigned int kernel_code_base = 0x80000000; 127 unsigned int kernel_data_base = 0x80010000; 128 unsigned int kernel_uncdata_base = 0x80080000; 129 unsigned int kernel_init_base = 0x80090000; 130 131 unsigned int boot_code_base = 0xBFC00000; 132 unsigned int boot_stack_base = 0xBFC08000; 133 unsigned int boot_mapping_base = 0xBFC0C000; 126 unsigned int kernel_code_base = 0x80000000; /* kernel code */ 127 unsigned int kernel_data_base = 0x80010000; /* system cacheable data */ 128 unsigned int kernel_uncdata_base = 0x80080000; /* system uncacheable data */ 129 unsigned int kernel_init_base = 0x80090000; /* system init entry */ 130 131 unsigned int boot_code_base = 0xBFC00000; /* boot code */ 132 unsigned int boot_stack_base = 0xBFC08000; /* boot temporary stack */ 133 unsigned int boot_mapping_base = 0xBFC0C000; /* mapping_info blob */ 134 134 135 135 //periphs … … 151 151 // once all the vspace have been parsed. 152 152 ///////////////////////////////////////////////////////////////////// 153 typedef struct vobj_ref_s 154 { 153 typedef struct vobj_ref_s { 155 154 char vspace_name[32]; 156 155 char vobj_name[32]; 157 } vobj_ref_t;158 159 vobj_ref_t * cp_port_vobj_ref[MAX_CP_PORTS];156 } vobj_ref_t; 157 158 vobj_ref_t * cp_port_vobj_ref[MAX_CP_PORTS]; 160 159 161 160 162 161 ////////////////////////////////////////////////// 163 unsigned int getIntValue( xmlTextReaderPtr reader, 164 const char* attributeName, 165 unsigned int* ok ) 166 { 167 unsigned int value = 0; 168 unsigned int i; 169 char c; 170 171 char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName); 172 173 if ( string == NULL ) // missing argument 174 { 162 unsigned int getIntValue(xmlTextReaderPtr reader, const char * attributeName, unsigned int * ok) { 163 unsigned int value = 0; 164 unsigned int i; 165 char c; 166 167 char * string = (char *) xmlTextReaderGetAttribute(reader, (const xmlChar *) attributeName); 168 169 if (string == NULL) { 170 // missing argument 175 171 *ok = 0; 176 172 return 0; 177 173 } 178 else 179 { 180 if ( (string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X')) ) // Hexa 181 { 182 for ( i = 2 ; (string[i] != 0) && (i < 10) ; i++ ) 183 { 174 else { 175 if ((string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X'))) { 176 // Hexa 177 for (i = 2 ; (string[i] != 0) && (i < 10) ; i++) { 184 178 c = string[i]; 185 if ((c >= '0') && (c <= '9')) value = (value<<4) + string[i] - 48; 186 else if ((c >= 'a') && (c <= 'f')) value = (value<<4) + string[i] - 87; 187 else if ((c >= 'A') && (c <= 'F')) value = (value<<4) + string[i] - 55; 188 else 189 { 179 if ((c >= '0') && (c <= '9')) { value = (value << 4) + string[i] - 48; } 180 else if ((c >= 'a') && (c <= 'f')) { value = (value << 4) + string[i] - 87; } 181 else if ((c >= 'A') && (c <= 'F')) { value = (value << 4) + string[i] - 55; } 182 else { 190 183 *ok = 0; 191 184 return 0; … … 193 186 } 194 187 } 195 else // Decimal 196 { 197 for ( i = 0 ; (string[i] != 0) && (i < 9) ; i++ ) 198 { 188 else { 189 // Decimal 190 for (i = 0; (string[i] != 0) && (i < 9); i++) { 199 191 c = string[i]; 200 if ((c >= '0') && (c <= '9')) value = (value*10) + string[i] - 48; 201 else 202 { 192 if ((c >= '0') && (c <= '9')) value = (value * 10) + string[i] - 48; 193 else { 203 194 *ok = 0; 204 195 return 0; … … 211 202 } // end getIntValue() 212 203 204 213 205 /////////////////////////////////////////////// 214 char* getStringValue ( xmlTextReaderPtr reader, 215 const char* attributeName, 216 unsigned int* ok ) 217 { 218 char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName); 219 220 221 if ( string == NULL ) // missing argument 222 { 206 char * getStringValue(xmlTextReaderPtr reader, const char * attributeName, unsigned int * ok) { 207 char * string = (char *) xmlTextReaderGetAttribute(reader, (const xmlChar *) attributeName); 208 209 210 if (string == NULL) { 211 // missing argument 223 212 *ok = 0; 224 213 return NULL; 225 214 } 226 else 227 { 215 else { 228 216 //we read only string smaller than 32 byte 229 if(strlen(string) > 32) 230 { 217 if (strlen(string) > 32) { 231 218 printf("[XML ERROR] all strings must be less than 32 bytes\n"); 232 219 exit(1); … … 238 225 } // end getStringValue() 239 226 227 240 228 /////////////////////////////////////// 241 int getPsegId( unsigned int cluster_id, 242 char* pseg_name ) 243 { 229 int getPsegId(unsigned int cluster_id, char * pseg_name) { 244 230 unsigned int pseg_id; 245 231 unsigned int pseg_min = cluster[cluster_id]->pseg_offset; 246 232 unsigned int pseg_max = pseg_min + cluster[cluster_id]->psegs; 247 233 248 for ( pseg_id = pseg_min ; pseg_id < pseg_max ; pseg_id++ ) 249 { 250 if ( strcmp(pseg[pseg_id]->name, pseg_name) == 0 ) 251 { 234 for (pseg_id = pseg_min; pseg_id < pseg_max; pseg_id++) { 235 if (strcmp(pseg[pseg_id]->name, pseg_name) == 0) { 252 236 return pseg_id; 253 237 } … … 256 240 } 257 241 242 258 243 //////////////////////////////////////////// 259 int getVspaceId( char* vspace_name) 260 { 244 int getVspaceId(char * vspace_name) { 261 245 unsigned int vspace_id; 262 246 263 for( vspace_id = 0; vspace_id < vspace_index ; vspace_id++) 264 { 265 if( !strcmp(vspace[vspace_id]->name, vspace_name)) 266 { 247 for (vspace_id = 0; vspace_id < vspace_index; vspace_id++) { 248 if (!strcmp(vspace[vspace_id]->name, vspace_name)) { 267 249 return vspace_id; 268 250 } … … 271 253 } 272 254 255 273 256 //////////////////////////////////////////// 274 int getVobjLocId( unsigned int vspace_id, 275 char* vobj_name, 276 unsigned int vspace_max) 277 { 257 int getVobjLocId(unsigned int vspace_id, char * vobj_name, unsigned int vspace_max) { 278 258 unsigned int vobj_id; 279 259 unsigned int vobj_min = vspace[vspace_id]->vobj_offset; 280 260 unsigned int vobj_max = vobj_min + vspace_max; 281 261 282 for ( vobj_id = vobj_min ; vobj_id < vobj_max ; vobj_id++ ) 283 { 284 if ( strcmp(vobj[vobj_id]->name, vobj_name) == 0 ) 285 { 286 return (vobj_id - vobj_min); 262 for (vobj_id = vobj_min; vobj_id < vobj_max; vobj_id++) { 263 if (strcmp(vobj[vobj_id]->name, vobj_name) == 0) { 264 return (vobj_id - vobj_min); 287 265 } 288 266 } … … 290 268 } 291 269 270 292 271 ///////////////////////////////////////// 293 void taskNode ( xmlTextReaderPtr reader ) 294 ///////////////////////////////////////// 295 { 296 unsigned int ok; 297 unsigned int value; 298 char* str; 299 300 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 301 302 if ( task_index >= MAX_TASKS ) 303 { 272 void taskNode(xmlTextReaderPtr reader) { 273 unsigned int ok; 274 unsigned int value; 275 char * str; 276 277 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 278 return; 279 } 280 281 if (task_index >= MAX_TASKS) { 304 282 printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS); 305 283 } 306 284 307 285 #if XML_PARSER_DEBUG 308 printf(" task %d\n", task_loc_index);309 #endif 310 311 task[task_index] = (mapping_task_t *)malloc(sizeof(mapping_task_t));286 printf(" task %d\n", task_loc_index); 287 #endif 288 289 task[task_index] = (mapping_task_t *) malloc(sizeof(mapping_task_t)); 312 290 313 291 ////////// get name attribute 314 292 str = getStringValue(reader, "name", &ok); 315 if ( ok ) 316 { 317 #if XML_PARSER_DEBUG 318 printf(" name = %s\n", str); 293 if (ok) { 294 #if XML_PARSER_DEBUG 295 printf(" name = %s\n", str); 319 296 #endif 320 297 strncpy( task[task_index]->name, str, 31 ); 321 298 } 322 else 323 { 299 else { 324 300 printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n", 325 vspace_index, task_loc_index);301 vspace_index, task_loc_index); 326 302 exit(1); 327 303 } 328 304 329 305 ///////// get clusterid attribute 330 value = getIntValue(reader,"clusterid", &ok); 331 if ( ok ) 332 { 333 #if XML_PARSER_DEBUG 334 printf(" clusterid = %x\n", value); 335 #endif 336 if ( value >= header->clusters ) 337 { 306 value = getIntValue(reader, "clusterid", &ok); 307 if (ok) { 308 #if XML_PARSER_DEBUG 309 printf(" clusterid = %x\n", value); 310 #endif 311 if (value >= header->clusters) { 338 312 printf("[XML ERROR] <clusterid> too large for task (%d,%d)\n", 339 vspace_index, task_loc_index);313 vspace_index, task_loc_index); 340 314 exit(1); 341 315 } 342 316 task[task_index]->clusterid = value; 343 317 } 344 else 345 { 318 else { 346 319 printf("[XML ERROR] illegal or missing <clusterid> attribute for task (%d,%d)\n", 347 vspace_index, task_loc_index);320 vspace_index, task_loc_index); 348 321 exit(1); 349 322 } 350 323 351 324 ////////// get proclocid attribute 352 value = getIntValue(reader,"proclocid", &ok); 353 if ( ok ) 354 { 355 #if XML_PARSER_DEBUG 356 printf(" proclocid = %x\n", value); 357 #endif 358 if ( value >= cluster[task[task_index]->clusterid]->procs ) 359 { 325 value = getIntValue(reader, "proclocid", &ok); 326 if (ok) { 327 #if XML_PARSER_DEBUG 328 printf(" proclocid = %x\n", value); 329 #endif 330 if (value >= cluster[task[task_index]->clusterid]->procs) { 360 331 printf("[XML ERROR] <proclocid> too large for task (%d,%d)\n", 361 vspace_index, task_loc_index);332 vspace_index, task_loc_index); 362 333 exit(1); 363 334 } 364 335 task[task_index]->proclocid = value; 365 336 } 366 else 367 { 337 else { 368 338 printf("[XML ERROR] illegal or missing <locprocid> attribute for task (%d,%d)\n", 369 339 vspace_index, task_loc_index); … … 373 343 ////////// get stackname attribute 374 344 str = getStringValue(reader, "stackname" , &ok); 375 if ( ok ) 376 { 377 int index = getVobjLocId( vspace_index, str , vobj_loc_index); 378 if ( index >= 0 ) 379 { 380 #if XML_PARSER_DEBUG 381 printf(" stackname = %s\n", str); 382 printf(" stackid = %d\n", index); 345 if (ok) { 346 int index = getVobjLocId(vspace_index, str , vobj_loc_index); 347 if (index >= 0) { 348 #if XML_PARSER_DEBUG 349 printf(" stackname = %s\n", str); 350 printf(" stackid = %d\n", index); 383 351 #endif 384 352 task[task_index]->vobjlocid = index; 385 353 } 386 else 387 { 354 else { 388 355 printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", 389 356 vspace_index, task_loc_index); … … 391 358 } 392 359 } 393 else 394 { 360 else { 395 361 printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", 396 362 vspace_index, task_loc_index); … … 399 365 400 366 ////////// get startid attribute 401 value = getIntValue(reader,"startid", &ok); 402 if ( ok ) 403 { 404 #if XML_PARSER_DEBUG 405 printf(" startid = %x\n", value); 367 value = getIntValue(reader, "startid", &ok); 368 if (ok) { 369 #if XML_PARSER_DEBUG 370 printf(" startid = %x\n", value); 406 371 #endif 407 372 task[task_index]->startid = value; 408 373 } 409 else 410 { 374 else { 411 375 printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n", 412 376 vspace_index, task_loc_index); … … 415 379 416 380 /////////// get usetty attribute (optionnal : 0 if missing) 417 value = getIntValue(reader,"usetty", &ok); 418 if ( ok ) 419 { 420 #if XML_PARSER_DEBUG 421 printf(" usetty = %x\n", value); 381 value = getIntValue(reader, "usetty", &ok); 382 if (ok) { 383 #if XML_PARSER_DEBUG 384 printf(" usetty = %x\n", value); 422 385 #endif 423 386 task[task_index]->use_tty = value; 424 387 } 425 else 426 { 388 else { 427 389 task[task_index]->use_tty = 0; 428 390 } 429 391 430 392 /////////// get usenic attribute (optionnal : 0 if missing) 431 value = getIntValue(reader,"usenic", &ok); 432 if ( ok ) 433 { 434 #if XML_PARSER_DEBUG 435 printf(" usenic = %x\n", value); 393 value = getIntValue(reader, "usenic", &ok); 394 if (ok) { 395 #if XML_PARSER_DEBUG 396 printf(" usenic = %x\n", value); 436 397 #endif 437 398 task[task_index]->use_nic = value; 438 399 } 439 else 440 { 400 else { 441 401 task[task_index]->use_nic = 0; 442 402 } 443 403 444 404 /////////// get usetimer attribute (optionnal : 0 if missing) 445 value = getIntValue(reader,"usetimer", &ok); 446 if ( ok ) 447 { 448 #if XML_PARSER_DEBUG 449 printf(" usetimer = %x\n", value); 405 value = getIntValue(reader, "usetimer", &ok); 406 if (ok) { 407 #if XML_PARSER_DEBUG 408 printf(" usetimer = %x\n", value); 450 409 #endif 451 410 task[task_index]->use_timer = value; 452 411 } 453 else 454 { 412 else { 455 413 task[task_index]->use_timer = 0; 456 414 } 457 415 458 416 /////////// get usefbdma attribute (optionnal : 0 if missing) 459 value = getIntValue(reader,"usefbdma", &ok); 460 if ( ok ) 461 { 462 #if XML_PARSER_DEBUG 463 printf(" usefbdma = %x\n", value); 417 value = getIntValue(reader, "usefbdma", &ok); 418 if (ok) { 419 #if XML_PARSER_DEBUG 420 printf(" usefbdma = %x\n", value); 464 421 #endif 465 422 task[task_index]->use_fbdma = value; 466 } 467 else 468 { 423 } 424 else { 469 425 task[task_index]->use_fbdma = 0; 470 426 } … … 474 430 } // end taskNode() 475 431 432 476 433 ////////////////////////////////////////// 477 void vobjNode ( xmlTextReaderPtr reader ) 478 ////////////////////////////////////////// 479 { 480 unsigned int ok; 481 unsigned int value; 482 char* str; 483 484 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 485 486 if ( vobj_index >= MAX_VOBJS ) 487 { 434 void vobjNode(xmlTextReaderPtr reader) { 435 unsigned int ok; 436 unsigned int value; 437 char * str; 438 439 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 440 return; 441 } 442 443 if (vobj_index >= MAX_VOBJS) { 488 444 printf("[XML ERROR] The number of vobjs is larger than %d\n", MAX_VSEGS); 489 445 exit(1); … … 491 447 492 448 #if XML_PARSER_DEBUG 493 printf(" vobj %d\n", vobj_loc_index);494 #endif 495 496 vobj[vobj_index] = (mapping_vobj_t *)malloc(sizeof(mapping_vobj_t));449 printf(" vobj %d\n", vobj_loc_index); 450 #endif 451 452 vobj[vobj_index] = (mapping_vobj_t *) malloc(sizeof(mapping_vobj_t)); 497 453 498 454 ///////// get name attribute 499 455 str = getStringValue(reader, "name", &ok); 500 if ( ok ) 501 { 502 #if XML_PARSER_DEBUG 503 printf(" name = %s\n", str); 504 #endif 505 strncpy( vobj[vobj_index]->name, str, 31); 506 } 507 else 508 { 456 if (ok) { 457 #if XML_PARSER_DEBUG 458 printf(" name = %s\n", str); 459 #endif 460 strncpy(vobj[vobj_index]->name, str, 31); 461 } 462 else { 509 463 printf("[XML ERROR] illegal or missing <name> attribute for vobj (%d,%d)\n", 510 464 vseg_index, vobj_loc_index); … … 515 469 str = getStringValue(reader, "type", &ok); 516 470 #if XML_PARSER_DEBUG 517 printf(" type = %s\n", str); 518 #endif 519 if (ok && (strcmp(str, "ELF") == 0)) 520 { 471 printf(" type = %s\n", str); 472 #endif 473 if (ok && (strcmp(str, "ELF") == 0)) { 521 474 vobj[vobj_index]->type = VOBJ_TYPE_ELF; 522 475 523 476 //check that this vobj is the first in vseg 524 if(vobj_count != 0) 525 { 477 if (vobj_count != 0) { 526 478 printf("[XML ERROR] an ELF vobj must be alone in a vseg (%d,%d)\n", 527 479 vspace_index, vobj_loc_index); … … 529 481 } 530 482 } 531 else if (ok && (strcmp(str, "BLOB") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BLOB; 532 else if (ok && (strcmp(str, "PTAB") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PTAB; 533 else if (ok && (strcmp(str, "PERI") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PERI; 534 else if (ok && (strcmp(str, "MWMR") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_MWMR; 535 else if (ok && (strcmp(str, "LOCK") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_LOCK; 536 else if (ok && (strcmp(str, "BUFFER") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BUFFER; 537 else if (ok && (strcmp(str, "BARRIER") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BARRIER; 538 else 539 { 483 else if (ok && (strcmp(str, "BLOB") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BLOB; } 484 else if (ok && (strcmp(str, "PTAB") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PTAB; } 485 else if (ok && (strcmp(str, "PERI") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_PERI; } 486 else if (ok && (strcmp(str, "MWMR") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_MWMR; } 487 else if (ok && (strcmp(str, "LOCK") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_LOCK; } 488 else if (ok && (strcmp(str, "BUFFER") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BUFFER; } 489 else if (ok && (strcmp(str, "BARRIER") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_BARRIER; } 490 else if (ok && (strcmp(str, "CONST") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_CONST; } 491 else if (ok && (strcmp(str, "MEMSPACE") == 0)) { vobj[vobj_index]->type = VOBJ_TYPE_MEMSPACE; } 492 else { 540 493 printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n", 541 494 vspace_index, vobj_loc_index); … … 544 497 545 498 ////////// get length attribute 546 value = getIntValue(reader,"length", &ok); 547 if ( ok ) 548 { 549 #if XML_PARSER_DEBUG 550 printf(" length = %d\n", value); 499 value = getIntValue(reader, "length", &ok); 500 if (ok) { 501 #if XML_PARSER_DEBUG 502 printf(" length = %d\n", value); 551 503 #endif 552 504 vobj[vobj_index]->length = value; 553 505 } 554 else 555 { 506 else { 556 507 printf("[XML ERROR] illegal or missing <length> attribute for vobj (%d,%d)\n", 557 508 vspace_index, vobj_loc_index); … … 560 511 561 512 ////////// get align attribute (optional : 0 if missing) 562 value = getIntValue(reader,"align", &ok); 563 if ( ok ) 564 { 565 #if XML_PARSER_DEBUG 566 printf(" align = %d\n", value); 513 value = getIntValue(reader, "align", &ok); 514 if (ok) { 515 #if XML_PARSER_DEBUG 516 printf(" align = %d\n", value); 567 517 #endif 568 518 vobj[vobj_index]->align = value; 569 519 } 570 else 571 { 520 else { 572 521 vobj[vobj_index]->align = 0; 573 522 } … … 575 524 ////////// get binpath attribute (optional : '\0' if missing) 576 525 str = getStringValue(reader, "binpath", &ok); 577 if ( ok ) 578 { 579 #if XML_PARSER_DEBUG 580 printf(" binpath = %s\n", str); 526 if (ok) { 527 #if XML_PARSER_DEBUG 528 printf(" binpath = %s\n", str); 581 529 #endif 582 530 strncpy(vobj[vobj_index]->binpath, str, 63); 583 531 } 584 else 585 { 532 else { 586 533 vobj[vobj_index]->binpath[0] = '\0'; 587 534 } 588 535 589 536 ////////// get init attribute (mandatory for mwmr and barrier) 590 value = getIntValue(reader,"init", &ok); 591 if ( ok ) 592 { 593 #if XML_PARSER_DEBUG 594 printf(" init = %d\n", value); 537 value = getIntValue(reader, "init", &ok); 538 if (ok) { 539 #if XML_PARSER_DEBUG 540 printf(" init = %d\n", value); 595 541 #endif 596 542 vobj[vobj_index]->init = value; 597 543 } 598 else 599 { 600 if( (vobj[vobj_index]->type == VOBJ_TYPE_MWMR) || 601 (vobj[vobj_index]->type == VOBJ_TYPE_BARRIER) ) 602 { 544 else { 545 if ((vobj[vobj_index]->type == VOBJ_TYPE_MWMR) || 546 (vobj[vobj_index]->type == VOBJ_TYPE_BARRIER) || 547 (vobj[vobj_index]->type == VOBJ_TYPE_CONST)) { 603 548 printf("[XML ERROR] illegal or missing <value> attribute for vobj (%d,%d). \ 604 549 All MWMR or BARRIER vobj must have a init value \n", 605 550 vspace_index, vobj_loc_index); 606 551 exit(1); … … 614 559 } // end vobjNode() 615 560 561 616 562 ////////////////////////////////////////// 617 void vsegNode ( xmlTextReaderPtr reader ) 618 ////////////////////////////////////////// 619 { 620 unsigned int ok; 621 unsigned int value; 622 char* str; 623 624 vobj_count = 0; 625 626 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 627 628 if ( vseg_index >= MAX_VSEGS ) 629 { 563 void vsegNode(xmlTextReaderPtr reader) { 564 unsigned int ok; 565 unsigned int value; 566 char * str; 567 568 vobj_count = 0; 569 570 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 571 return; 572 } 573 574 if (vseg_index >= MAX_VSEGS) { 630 575 printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS); 631 576 exit(1); … … 633 578 634 579 #if XML_PARSER_DEBUG 635 printf(" vseg %d\n", vseg_loc_index);636 #endif 637 638 vseg[vseg_index] = (mapping_vseg_t *)malloc(sizeof(mapping_vseg_t));639 580 printf(" vseg %d\n", vseg_loc_index); 581 #endif 582 583 vseg[vseg_index] = (mapping_vseg_t *) malloc(sizeof(mapping_vseg_t)); 584 640 585 ////////// set vobj_offset attributes 641 586 vseg[vseg_index]->vobj_offset = vobj_index; 642 587 #if XML_PARSER_DEBUG 643 printf(" vobj_offset = %d\n", vobj_index);588 printf(" vobj_offset = %d\n", vobj_index); 644 589 #endif 645 590 646 591 ///////// get name attribute 647 592 str = getStringValue(reader, "name", &ok); 648 if ( ok ) 649 { 650 #if XML_PARSER_DEBUG 651 printf(" name = %s\n", str); 593 if (ok) { 594 #if XML_PARSER_DEBUG 595 printf(" name = %s\n", str); 652 596 #endif 653 597 strncpy( vseg[vseg_index]->name, str, 31); 654 598 } 655 else 656 { 599 else { 657 600 printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", 658 601 vspace_index, vseg_loc_index); … … 661 604 662 605 ////////// get ident attribute (optional : 0 if missing) 663 value = getIntValue(reader,"ident", &ok); 664 if ( ok ) 665 { 666 #if XML_PARSER_DEBUG 667 printf(" ident = %d\n", value); 606 value = getIntValue(reader, "ident", &ok); 607 if (ok) { 608 #if XML_PARSER_DEBUG 609 printf(" ident = %d\n", value); 668 610 #endif 669 611 vseg[vseg_index]->ident = value; 670 612 } 671 else 672 { 613 else { 673 614 vseg[vseg_index]->ident = 0; 674 615 } 675 616 676 617 /////////// get vbase attribute 677 value = getIntValue(reader,"vbase", &ok); 678 if ( ok ) 679 { 680 #if XML_PARSER_DEBUG 681 printf(" vbase = 0x%x\n", value); 618 value = getIntValue(reader, "vbase", &ok); 619 if (ok) { 620 #if XML_PARSER_DEBUG 621 printf(" vbase = 0x%x\n", value); 682 622 #endif 683 623 vseg[vseg_index]->vbase = value; 684 624 } 685 else 686 { 625 else { 687 626 printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", 688 627 vspace_index, vseg_loc_index); … … 691 630 692 631 ////////// get clusterid and psegname attributes 693 value = getIntValue(reader,"clusterid", &ok); 694 if ( ok == 0 ) 695 { 632 value = getIntValue(reader, "clusterid", &ok); 633 if (ok == 0) { 696 634 printf("[XML ERROR] illegal or missing <clusterid> for vseg %d\n", 697 vseg_loc_index); 698 exit(1); 699 } 700 str = getStringValue(reader,"psegname", &ok); 701 if ( ok == 0 ) 702 { 635 vseg_loc_index); 636 exit(1); 637 } 638 str = getStringValue(reader, "psegname", &ok); 639 if (ok == 0) { 703 640 printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", 704 641 vseg_loc_index); 705 642 exit(1); 706 643 } 707 644 708 645 /////////// set psegid field 709 int index = getPsegId( value, str ); 710 if ( index >= 0 ) 711 { 712 #if XML_PARSER_DEBUG 713 printf(" clusterid = %d\n", value); 714 printf(" psegname = %s\n", str); 715 printf(" psegid = %d\n", index); 646 int index = getPsegId(value, str); 647 if (index >= 0) { 648 #if XML_PARSER_DEBUG 649 printf(" clusterid = %d\n", value); 650 printf(" psegname = %s\n", str); 651 printf(" psegid = %d\n", index); 716 652 #endif 717 653 vseg[vseg_index]->psegid = index; 718 654 } 719 else 720 { 655 else { 721 656 printf("[XML ERROR] pseg not found for vseg %d / clusterid = %d / psegname = %s\n", 722 657 vseg_loc_index, value, str ); 723 658 exit(1); 724 659 } 725 660 726 661 //////// get mode attribute 727 str = getStringValue(reader,"mode", &ok); 728 #if XML_PARSER_DEBUG 729 printf(" mode = %s\n", str); 730 #endif 731 if (ok && (strcmp(str, "CXWU") == 0)) vseg[vseg_index]->mode = 0xF; 732 else if (ok && (strcmp(str, "CXW_") == 0)) vseg[vseg_index]->mode = 0xE; 733 else if (ok && (strcmp(str, "CX_U") == 0)) vseg[vseg_index]->mode = 0xD; 734 else if (ok && (strcmp(str, "CX__") == 0)) vseg[vseg_index]->mode = 0xC; 735 else if (ok && (strcmp(str, "C_WU") == 0)) vseg[vseg_index]->mode = 0xB; 736 else if (ok && (strcmp(str, "C_W_") == 0)) vseg[vseg_index]->mode = 0xA; 737 else if (ok && (strcmp(str, "C__U") == 0)) vseg[vseg_index]->mode = 0x9; 738 else if (ok && (strcmp(str, "C___") == 0)) vseg[vseg_index]->mode = 0x8; 739 else if (ok && (strcmp(str, "_XWU") == 0)) vseg[vseg_index]->mode = 0x7; 740 else if (ok && (strcmp(str, "_XW_") == 0)) vseg[vseg_index]->mode = 0x6; 741 else if (ok && (strcmp(str, "_X_U") == 0)) vseg[vseg_index]->mode = 0x5; 742 else if (ok && (strcmp(str, "_X__") == 0)) vseg[vseg_index]->mode = 0x4; 743 else if (ok && (strcmp(str, "__WU") == 0)) vseg[vseg_index]->mode = 0x3; 744 else if (ok && (strcmp(str, "__W_") == 0)) vseg[vseg_index]->mode = 0x2; 745 else if (ok && (strcmp(str, "___U") == 0)) vseg[vseg_index]->mode = 0x1; 746 else if (ok && (strcmp(str, "____") == 0)) vseg[vseg_index]->mode = 0x0; 747 else 748 { 662 str = getStringValue(reader, "mode", &ok); 663 #if XML_PARSER_DEBUG 664 printf(" mode = %s\n", str); 665 #endif 666 if (ok && (strcmp(str, "CXWU") == 0)) { vseg[vseg_index]->mode = 0xF; } 667 else if (ok && (strcmp(str, "CXW_") == 0)) { vseg[vseg_index]->mode = 0xE; } 668 else if (ok && (strcmp(str, "CX_U") == 0)) { vseg[vseg_index]->mode = 0xD; } 669 else if (ok && (strcmp(str, "CX__") == 0)) { vseg[vseg_index]->mode = 0xC; } 670 else if (ok && (strcmp(str, "C_WU") == 0)) { vseg[vseg_index]->mode = 0xB; } 671 else if (ok && (strcmp(str, "C_W_") == 0)) { vseg[vseg_index]->mode = 0xA; } 672 else if (ok && (strcmp(str, "C__U") == 0)) { vseg[vseg_index]->mode = 0x9; } 673 else if (ok && (strcmp(str, "C___") == 0)) { vseg[vseg_index]->mode = 0x8; } 674 else if (ok && (strcmp(str, "_XWU") == 0)) { vseg[vseg_index]->mode = 0x7; } 675 else if (ok && (strcmp(str, "_XW_") == 0)) { vseg[vseg_index]->mode = 0x6; } 676 else if (ok && (strcmp(str, "_X_U") == 0)) { vseg[vseg_index]->mode = 0x5; } 677 else if (ok && (strcmp(str, "_X__") == 0)) { vseg[vseg_index]->mode = 0x4; } 678 else if (ok && (strcmp(str, "__WU") == 0)) { vseg[vseg_index]->mode = 0x3; } 679 else if (ok && (strcmp(str, "__W_") == 0)) { vseg[vseg_index]->mode = 0x2; } 680 else if (ok && (strcmp(str, "___U") == 0)) { vseg[vseg_index]->mode = 0x1; } 681 else if (ok && (strcmp(str, "____") == 0)) { vseg[vseg_index]->mode = 0x0; } 682 else { 749 683 printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", 750 684 vspace_index, vseg_loc_index); 751 685 exit(1); 752 686 } 753 687 754 688 ////////// get vobjs in vseg 755 689 int status = xmlTextReaderRead(reader); 756 while ( status == 1 )757 {758 const char* tag = (const char*)xmlTextReaderConstName(reader); 759 760 if ( strcmp(tag, "vobj") == 0 )vobjNode(reader);761 else if ( strcmp(tag, "#text" ) == 0 ) {}762 else if ( strcmp(tag, "#comment")== 0 ) { }763 else if ( strcmp(tag, "vseg") == 0 )764 {690 while (status == 1) { 691 const char * tag = (const char *) xmlTextReaderConstName(reader); 692 693 if (strcmp(tag, "vobj") == 0 ) { 694 vobjNode(reader); 695 } 696 else if (strcmp(tag, "#text" ) == 0 ) { } 697 else if (strcmp(tag, "#comment") == 0 ) { } 698 else if (strcmp(tag, "vseg") == 0 ) { 765 699 vseg[vseg_index]->vobjs = vobj_count; 766 700 vseg_index++; … … 768 702 return; 769 703 } 770 else 771 { 772 printf("[XML ERROR] Unknown tag %s",tag); 773 exit(1); 774 } 775 status = xmlTextReaderRead ( reader ); 704 else { 705 printf("[XML ERROR] Unknown tag %s", tag); 706 exit(1); 707 } 708 status = xmlTextReaderRead (reader); 776 709 } 777 710 } // end vsegNode() 778 711 712 779 713 ////////////////////////////////////////// 780 void vspaceNode( xmlTextReaderPtr reader ) 781 ////////////////////////////////////////// 782 { 783 char* str; 784 unsigned int ok; 714 void vspaceNode(xmlTextReaderPtr reader) { 715 char * str; 716 unsigned int ok; 785 717 786 718 vobj_loc_index = 0; 787 vseg_loc_index = 0; 788 task_loc_index = 0; 789 790 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 719 vseg_loc_index = 0; 720 task_loc_index = 0; 721 722 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 723 return; 724 } 791 725 792 726 // checking source file consistency 793 if ( vspace_index >= header->vspaces ) 794 { 727 if (vspace_index >= header->vspaces) { 795 728 printf("[XML ERROR] The vspace index is too large : %d\n", 796 797 exit(1); 798 } 799 800 #if XML_PARSER_DEBUG 801 printf("\n vspace %d\n", vspace_index);802 #endif 803 804 vspace[vspace_index] = (mapping_vspace_t *)malloc(sizeof(mapping_vspace_t));729 vspace_index); 730 exit(1); 731 } 732 733 #if XML_PARSER_DEBUG 734 printf("\n vspace %d\n", vspace_index); 735 #endif 736 737 vspace[vspace_index] = (mapping_vspace_t *) malloc(sizeof(mapping_vspace_t)); 805 738 806 739 ////////// get name attribute 807 740 str = getStringValue(reader, "name", &ok); 808 if ( ok ) 809 { 810 #if XML_PARSER_DEBUG 811 printf(" name = %s\n", str); 741 if (ok) { 742 #if XML_PARSER_DEBUG 743 printf(" name = %s\n", str); 812 744 #endif 813 745 strncpy(vspace[vspace_index]->name, str, 31); 814 746 } 815 else 816 { 747 else { 817 748 printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", 818 749 vspace_index); 819 750 exit(1); 820 751 } … … 824 755 vspace[vspace_index]->vobj_offset = vobj_index; 825 756 vspace[vspace_index]->task_offset = task_index; 826 827 #if XML_PARSER_DEBUG 828 printf(" vseg_offset = %d\n", vseg_index);829 printf(" vobj_offset = %d\n", vobj_index);830 printf(" task_offset = %d\n", task_index);757 758 #if XML_PARSER_DEBUG 759 printf(" vseg_offset = %d\n", vseg_index); 760 printf(" vobj_offset = %d\n", vobj_index); 761 printf(" task_offset = %d\n", task_index); 831 762 #endif 832 763 833 764 ////////// get startname attribute 834 765 str = getStringValue(reader, "startname", &ok); 835 if ( ok ) 836 { 766 if (ok) { 837 767 //used after parsing the vobjs 838 768 } 839 else 840 { 769 else { 841 770 printf("[XML ERROR] illegal or missing <startname> attribute for vspace %s\n", 842 771 vspace[vspace_index]->name); 843 772 exit(1); 844 773 } 845 774 846 775 int status = xmlTextReaderRead(reader); 847 while ( status == 1 ) 848 { 849 const char* tag = (const char*)xmlTextReaderConstName(reader); 850 851 if ( strcmp(tag, "vseg") == 0 ) vsegNode(reader); 852 else if ( strcmp(tag, "task") == 0 ) taskNode(reader); 853 else if ( strcmp(tag, "#text") == 0 ) { } 854 else if ( strcmp(tag, "#comment") == 0 ) { } 855 else if ( strcmp(tag, "vspace") == 0 ) 856 { 776 while (status == 1) { 777 const char * tag = (const char *) xmlTextReaderConstName(reader); 778 779 if (strcmp(tag, "vseg") == 0 ) { 780 vsegNode(reader); 781 } 782 else if (strcmp(tag, "task") == 0 ) { 783 taskNode(reader); 784 } 785 else if (strcmp(tag, "#text") == 0 ) { } 786 else if (strcmp(tag, "#comment") == 0 ) { } 787 else if (strcmp(tag, "vspace") == 0 ) { 857 788 vspace[vspace_index]->vobjs = vobj_loc_index; 858 789 vspace[vspace_index]->tasks = task_loc_index ; … … 860 791 861 792 // get index of the vobj containing the start vector 862 int index = getVobjLocId( vspace_index, str , vobj_loc_index ); 863 if(index == -1) 864 { 793 int index = getVobjLocId(vspace_index, str , vobj_loc_index); 794 if (index == -1) { 865 795 printf("[XML ERROR] vobj containing start vector not found in vspace %s\n", 866 796 vspace[vspace_index]->name); 867 797 exit(-1); 868 798 } 869 else 870 { 799 else { 871 800 vspace[vspace_index]->start_offset = index; 872 801 #if XML_PARSER_DEBUG 873 printf(" startname = %s\n", str);874 printf(" startid = %d\n", index);875 printf(" end vspace %d\n\n", vspace_index);802 printf(" startname = %s\n", str); 803 printf(" startid = %d\n", index); 804 printf(" end vspace %d\n\n", vspace_index); 876 805 #endif 877 806 } … … 881 810 int task_min = vspace[vspace_index]->task_offset; 882 811 int task_max = task_min + vspace[vspace_index]->tasks; 883 for ( task_id = task_min ; task_id < task_max ; task_id++ ) 884 { 885 if ( task[task_id]->startid >= vspace[vspace_index]->tasks ) 886 { 812 for (task_id = task_min; task_id < task_max; task_id++) { 813 if (task[task_id]->startid >= vspace[vspace_index]->tasks) { 887 814 printf("[XML ERROR] <startid> too large for task (%d,%d)\n", 888 vspace_index, task_id );815 vspace_index, task_id ); 889 816 exit(1); 890 817 } … … 894 821 return; 895 822 } 896 else 897 { 898 printf("[XML ERROR] Unknown tag %s",tag); 899 exit(1); 900 } 901 status = xmlTextReaderRead ( reader ); 823 else { 824 printf("[XML ERROR] Unknown tag %s", tag); 825 exit(1); 826 } 827 status = xmlTextReaderRead(reader); 902 828 } 903 829 } // end vspaceNode() 904 830 831 905 832 /////////////////////////////////////////// 906 void cpPortNode ( xmlTextReaderPtr reader ) 907 /////////////////////////////////////////// 908 { 909 char* str; 910 unsigned int ok; 911 912 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 913 914 if ( cp_port_index >= MAX_CP_PORTS ) 915 { 833 void cpPortNode(xmlTextReaderPtr reader) { 834 char * str; 835 unsigned int ok; 836 837 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 838 return; 839 } 840 841 if (cp_port_index >= MAX_CP_PORTS) { 916 842 printf("[XML ERROR] The number of ports (for coprocs) is larger than %d\n", MAX_CP_PORTS); 917 843 } 918 844 919 845 #if XML_PARSER_DEBUG 920 printf("\n port %d\n", cp_port_index);921 #endif 922 923 cp_port[cp_port_index] = (mapping_cp_port_t *)malloc(sizeof(mapping_cp_port_t));924 cp_port_vobj_ref[cp_port_index] = (vobj_ref_t *)malloc(sizeof(vobj_ref_t));925 926 927 846 printf("\n port %d\n", cp_port_index); 847 #endif 848 849 cp_port[cp_port_index] = (mapping_cp_port_t *) malloc(sizeof(mapping_cp_port_t)); 850 cp_port_vobj_ref[cp_port_index] = (vobj_ref_t *) malloc(sizeof(vobj_ref_t)); 851 852 853 928 854 ///////// get direction attribute 929 str = getStringValue( reader, "direction", &ok ); 930 if ( ok ) 931 { 932 #if XML_PARSER_DEBUG 933 printf(" direction = %s\n", str); 934 #endif 935 if ( strcmp(str, "TO_COPROC") == 0 ) cp_port[cp_port_index]->direction = PORT_TO_COPROC; 936 else if ( strcmp(str, "FROM_COPROC") == 0 ) cp_port[cp_port_index]->direction = PORT_FROM_COPROC; 937 else 938 { 855 str = getStringValue(reader, "direction", &ok); 856 if (ok) { 857 #if XML_PARSER_DEBUG 858 printf(" direction = %s\n", str); 859 #endif 860 if (strcmp(str, "TO_COPROC") == 0) { 861 cp_port[cp_port_index]->direction = PORT_TO_COPROC; 862 } 863 else if (strcmp(str, "FROM_COPROC") == 0) { 864 cp_port[cp_port_index]->direction = PORT_FROM_COPROC; 865 } 866 else { 939 867 printf("[XML ERROR] illegal <direction> for cp_port %d in cluster %d\n", 940 cp_port_index, cluster_index);868 cp_port_index, cluster_index); 941 869 exit(1); 942 870 } 943 871 } 944 else 945 { 872 else { 946 873 printf("[XML ERROR] missing <direction> for cp_port %d in cluster %d\n", 947 cp_port_index, cluster_index);948 exit(1); 949 } 950 874 cp_port_index, cluster_index); 875 exit(1); 876 } 877 951 878 /////////// get vspacename attribute 952 str = getStringValue( reader, "vspacename", &ok ); 953 #if XML_PARSER_DEBUG 954 printf(" vspacename = %s\n", str); 955 #endif 956 if ( ok ) 957 { 879 str = getStringValue(reader, "vspacename", &ok); 880 #if XML_PARSER_DEBUG 881 printf(" vspacename = %s\n", str); 882 #endif 883 if (ok) { 958 884 strncpy(cp_port_vobj_ref[cp_port_index]->vspace_name, str, 31); 959 885 } 960 else 961 { 886 else { 962 887 printf("[XML ERROR] missing <vspacename> for cp_port %d in cluster %d\n", 963 cp_port_index, cluster_index);888 cp_port_index, cluster_index); 964 889 exit(1); 965 890 } 966 891 967 892 /////////// get vobjname attribute 968 str = getStringValue( reader, "vobjname", &ok ); 969 #if XML_PARSER_DEBUG 970 printf(" vobjname = %s\n", str); 971 #endif 972 if ( ok ) 973 { 893 str = getStringValue(reader, "vobjname", &ok); 894 #if XML_PARSER_DEBUG 895 printf(" vobjname = %s\n", str); 896 #endif 897 if (ok) { 974 898 strncpy(cp_port_vobj_ref[cp_port_index]->vobj_name, str, 31); 975 899 } 976 else 977 { 900 else { 978 901 printf("[XML ERROR] missing <vobjname> for cp_port %d in cluster %d\n", 979 cp_port_index, cluster_index);980 exit(1); 981 } 982 902 cp_port_index, cluster_index); 903 exit(1); 904 } 905 983 906 cp_port_index++; 984 907 cp_port_loc_index++; … … 986 909 } // end cpPortNode() 987 910 911 988 912 /////////////////////////////////////////// 989 void periphNode ( xmlTextReaderPtr reader ) 990 /////////////////////////////////////////// 991 { 992 char* str; 993 unsigned int value; 994 unsigned int ok; 995 996 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 997 998 if ( periph_index >= MAX_PERIPHS ) 999 { 913 void periphNode(xmlTextReaderPtr reader) { 914 char * str; 915 unsigned int value; 916 unsigned int ok; 917 918 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 919 return; 920 } 921 922 if (periph_index >= MAX_PERIPHS) { 1000 923 printf("[XML ERROR] The number of periphs is larger than %d\n", MAX_PERIPHS); 1001 924 } 1002 925 1003 926 #if XML_PARSER_DEBUG 1004 printf("\n periph %d\n", periph_index);1005 #endif 1006 1007 periph[periph_index] = (mapping_periph_t *)malloc(sizeof(mapping_periph_t));927 printf("\n periph %d\n", periph_index); 928 #endif 929 930 periph[periph_index] = (mapping_periph_t *) malloc(sizeof(mapping_periph_t)); 1008 931 1009 932 1010 933 ///////// get channels attribute (optionnal : 1 if missing) 1011 value = getIntValue( reader, "channels", &ok ); 1012 if ( ok ) 1013 { 1014 #if XML_PARSER_DEBUG 1015 printf(" channels = %d\n", value); 934 value = getIntValue(reader, "channels", &ok); 935 if (ok) { 936 #if XML_PARSER_DEBUG 937 printf(" channels = %d\n", value); 1016 938 #endif 1017 939 periph[periph_index]->channels = value; 1018 940 } 1019 else 1020 { 941 else { 1021 942 periph[periph_index]->channels = 1; 1022 943 } 1023 944 1024 945 /////////// get psegname attribute 1025 str = getStringValue(reader,"psegname", &ok); 1026 if ( ok == 0 ) 1027 { 946 str = getStringValue(reader, "psegname", &ok); 947 if (ok == 0) { 1028 948 printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", 1029 949 coproc_index, cluster_index); 1030 950 exit(1); 1031 951 } 1032 952 1033 953 /////////// set psegid attribute 1034 int index = getPsegId( cluster_index, str ); 1035 if ( index >= 0 ) 1036 { 1037 #if XML_PARSER_DEBUG 1038 printf(" clusterid = %d\n", cluster_index); 1039 printf(" psegname = %s\n", str); 1040 printf(" psegid = %d\n", index); 954 int index = getPsegId(cluster_index, str); 955 if (index >= 0) { 956 #if XML_PARSER_DEBUG 957 printf(" clusterid = %d\n", cluster_index); 958 printf(" psegname = %s\n", str); 959 printf(" psegid = %d\n", index); 1041 960 #endif 1042 961 periph[periph_index]->psegid = index; 1043 962 assert(pseg[index]->type == PSEG_TYPE_PERI && 1044 "peripheral psegname attribute must refer to a pseg of type PERI" ); 1045 } 1046 else 1047 { 963 "peripheral psegname attribute must refer to a pseg of type PERI" ); 964 } 965 else { 1048 966 printf("[XML ERROR] pseg not found for periph %d / clusterid = %d / psegname = %s\n", 1049 967 periph_loc_index, cluster_index, str ); 1050 968 exit(1); 1051 969 } … … 1053 971 1054 972 /////////// get type attribute 1055 str = getStringValue( reader, "type", &ok ); 1056 if ( ok ) 1057 { 1058 #if XML_PARSER_DEBUG 1059 printf(" type = %s\n", str); 973 str = getStringValue(reader, "type", &ok); 974 if (ok) { 975 #if XML_PARSER_DEBUG 976 printf(" type = %s\n", str); 1060 977 #endif 1061 978 unsigned int error = 0; 1062 979 1063 980 // The TTY, IOC, NIC, FBF and IOB peripherals cannot be replicated 1064 981 // one per architecture 1065 if ( strcmp( str, "IOC" ) == 0 ) 1066 { 982 if (strcmp(str, "IOC") == 0) { 1067 983 periph[periph_index]->type = PERIPH_TYPE_IOC; 1068 if ( header->ioc_clusterid == 0xFFFFFFFF) header->ioc_clusterid = cluster_index; 1069 else error = 1; 1070 1071 ioc_base_offset = pseg[ periph[periph_index]->psegid ]->base; 984 if (header->ioc_clusterid == 0xFFFFFFFF) { 985 header->ioc_clusterid = cluster_index; 986 } 987 else { 988 error = 1; 989 } 990 991 ioc_base_offset = pseg[periph[periph_index]->psegid]->base; 1072 992 nb_ioc_channel = periph[periph_index]->channels; 1073 993 } 1074 else if ( strcmp( str, "TTY" ) == 0 ) 1075 { 994 else if (strcmp(str, "TTY") == 0) { 1076 995 periph[periph_index]->type = PERIPH_TYPE_TTY; 1077 if ( header->tty_clusterid == 0xFFFFFFFF) header->tty_clusterid = cluster_index; 1078 else error = 1; 1079 1080 tty_base_offset = pseg[ periph[periph_index]->psegid ]->base; 996 if (header->tty_clusterid == 0xFFFFFFFF) { 997 header->tty_clusterid = cluster_index; 998 } 999 else { 1000 error = 1; 1001 } 1002 1003 tty_base_offset = pseg[periph[periph_index]->psegid]->base; 1081 1004 nb_tty_channel = periph[periph_index]->channels; 1082 1005 } 1083 else if ( strcmp( str, "FBF" ) == 0 ) 1084 { 1006 else if (strcmp(str, "FBF") == 0) { 1085 1007 periph[periph_index]->type = PERIPH_TYPE_FBF; 1086 if ( header->fbf_clusterid == 0xFFFFFFFF) header->fbf_clusterid = cluster_index; 1087 else error = 1; 1088 1089 fbf_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1090 } 1091 else if ( strcmp( str, "NIC" ) == 0 ) 1092 { 1008 if (header->fbf_clusterid == 0xFFFFFFFF) { 1009 header->fbf_clusterid = cluster_index; 1010 } 1011 else { 1012 error = 1; 1013 } 1014 fbf_base_offset = pseg[periph[periph_index]->psegid]->base; 1015 } 1016 else if (strcmp(str, "NIC") == 0) { 1093 1017 periph[periph_index]->type = PERIPH_TYPE_NIC; 1094 if ( header->nic_clusterid == 0xFFFFFFFF) header->nic_clusterid = cluster_index; 1095 else error = 1; 1096 1097 nic_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1018 if (header->nic_clusterid == 0xFFFFFFFF) { 1019 header->nic_clusterid = cluster_index; 1020 } 1021 else { 1022 error = 1; 1023 } 1024 nic_base_offset = pseg[periph[periph_index]->psegid]->base; 1098 1025 nb_nic_channel = periph[periph_index]->channels; 1099 1026 } 1100 else if ( strcmp( str, "IOB" ) == 0 ) 1101 { 1027 else if (strcmp(str, "IOB") == 0) { 1102 1028 periph[periph_index]->type = PERIPH_TYPE_IOB; 1103 iob_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1104 1105 if(io_mmu_active) error = 1; 1029 iob_base_offset = pseg[periph[periph_index]->psegid]->base; 1030 1031 if (io_mmu_active) { 1032 error = 1; 1033 } 1106 1034 io_mmu_active = 1; 1107 1035 } 1108 1036 // The TIM, ICU, XICU, DMA and IOB peripherals can be replicated in several clusters 1109 1037 // one per cluster 1110 else if ( strcmp( str, "TIM" ) == 0 ) 1111 { 1038 else if (strcmp(str, "TIM") == 0 ) { 1112 1039 periph[periph_index]->type = PERIPH_TYPE_TIM; 1113 if(found_timer) error = 1; 1040 if (found_timer) { 1041 error = 1; 1042 } 1114 1043 found_timer = 1; 1115 1044 1116 if (tim_base_offset == 0xFFFFFFFF)1045 if (tim_base_offset == 0xFFFFFFFF) { 1117 1046 tim_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1118 1119 if(nb_timer_channel_max < periph[periph_index]->channels) 1047 } 1048 1049 if (nb_timer_channel_max < periph[periph_index]->channels) { 1120 1050 nb_timer_channel_max = periph[periph_index]->channels; 1121 }1122 else if ( strcmp( str, "ICU" ) == 0 )1123 {1051 } 1052 } 1053 else if (strcmp(str, "ICU") == 0) { 1124 1054 periph[periph_index]->type = PERIPH_TYPE_ICU; 1125 if(found_icu) error = 1; 1055 if (found_icu) { 1056 error = 1; 1057 } 1126 1058 found_icu = 1; 1127 1059 1128 if(icu_base_offset == 0xFFFFFFFF) 1060 if (icu_base_offset == 0xFFFFFFFF) { 1061 icu_base_offset = pseg[periph[periph_index]->psegid]->base; 1062 } 1063 } 1064 else if (strcmp(str, "XICU") == 0) { 1065 periph[periph_index]->type = PERIPH_TYPE_XICU; 1066 if (found_xicu) { 1067 error = 1; 1068 } 1069 found_xicu = 1; 1070 1071 //'icu' since we can't have both xicu and icu in an arch 1072 if (icu_base_offset == 0xFFFFFFFF) { 1129 1073 icu_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1130 } 1131 else if ( strcmp( str, "XICU" ) == 0 ) 1132 { 1133 periph[periph_index]->type = PERIPH_TYPE_XICU; 1134 if(found_xicu) error = 1; 1135 found_xicu = 1; 1136 1137 //'icu' since we can't have both xicu and icu in an arch 1138 if(icu_base_offset == 0xFFFFFFFF) 1139 icu_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1140 1141 if(nb_timer_channel_max == 0) 1074 } 1075 1076 if (nb_timer_channel_max == 0) { 1142 1077 nb_timer_channel_max = 32; 1143 }1144 else if ( strcmp( str, "DMA" ) == 0 )1145 {1078 } 1079 } 1080 else if (strcmp(str, "DMA") == 0) { 1146 1081 periph[periph_index]->type = PERIPH_TYPE_DMA; 1147 if(found_dma) error = 1; 1082 if (found_dma) { 1083 error = 1; 1084 } 1148 1085 found_dma = 1; 1149 1086 1150 if(dma_base_offset == 0xFFFFFFFF) 1151 dma_base_offset = pseg[ periph[periph_index]->psegid ]->base; 1152 if(nb_dma_channel_max < periph[periph_index]->channels) 1087 if (dma_base_offset == 0xFFFFFFFF) { 1088 dma_base_offset = pseg[periph[periph_index]->psegid]->base; 1089 } 1090 if (nb_dma_channel_max < periph[periph_index]->channels) { 1153 1091 nb_dma_channel_max = periph[periph_index]->channels; 1154 }1155 else1156 {1092 } 1093 } 1094 else { 1157 1095 printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n", 1158 periph_loc_index, cluster_index); 1159 exit(1); 1160 } 1161 1162 if(error) 1163 { 1096 periph_loc_index, cluster_index); 1097 exit(1); 1098 } 1099 1100 if (error) { 1164 1101 printf("[XML ERROR] illegal <type> for peripheral %d in cluster %d\n", 1165 periph_loc_index, cluster_index); 1166 exit(1); 1167 } 1168 } 1169 else 1170 { 1102 periph_loc_index, cluster_index); 1103 exit(1); 1104 } 1105 } 1106 else { 1171 1107 printf("[XML ERROR] missing <type> for peripheral %d in cluster %d\n", 1172 periph_loc_index, cluster_index);1173 exit(1); 1174 } 1175 1176 1108 periph_loc_index, cluster_index); 1109 exit(1); 1110 } 1111 1112 1177 1113 periph_index++; 1178 1114 periph_loc_index++; … … 1181 1117 } // end periphNode 1182 1118 1119 1183 1120 ///////////////////////////////////////// 1184 void coprocNode ( xmlTextReaderPtr reader ) 1185 ///////////////////////////////////////// 1186 { 1187 char* str; 1188 unsigned int ok; 1121 void coprocNode(xmlTextReaderPtr reader) { 1122 char * str; 1123 unsigned int ok; 1189 1124 1190 1125 cp_port_loc_index = 0; 1191 1126 1192 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 1193 1194 if ( coproc_index >= MAX_COPROCS ) 1195 { 1127 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1128 return; 1129 } 1130 1131 if (coproc_index >= MAX_COPROCS) { 1196 1132 printf("[XML ERROR] The number of coprocs is larger than %d\n", MAX_COPROCS); 1197 1133 } 1198 1134 1199 1135 #if XML_PARSER_DEBUG 1200 printf("\n coproc %d\n", coproc_index);1201 #endif 1202 1203 coproc[coproc_index] = (mapping_coproc_t *)malloc(sizeof(mapping_coproc_t));1136 printf("\n coproc %d\n", coproc_index); 1137 #endif 1138 1139 coproc[coproc_index] = (mapping_coproc_t *) malloc(sizeof(mapping_coproc_t)); 1204 1140 1205 1141 /////////// get name attribute 1206 str = getStringValue( reader, "name", &ok ); 1207 if ( ok ) 1208 { 1209 #if XML_PARSER_DEBUG 1210 printf(" name = %s\n", str); 1142 str = getStringValue(reader, "name", &ok); 1143 if (ok) { 1144 #if XML_PARSER_DEBUG 1145 printf(" name = %s\n", str); 1211 1146 #endif 1212 1147 strncpy(coproc[coproc_index]->name, str, 31); 1213 1148 } 1214 else 1215 { 1149 else { 1216 1150 printf("[XML ERROR] illegal or missing <name> for coproc %d in cluster %d\n", 1217 coproc_index, cluster_index);1151 coproc_index, cluster_index); 1218 1152 exit(1); 1219 1153 } 1220 1154 1221 1155 /////////// get psegname attribute 1222 str = getStringValue(reader,"psegname", &ok); 1223 if ( ok == 0 ) 1224 { 1156 str = getStringValue(reader, "psegname", &ok); 1157 if (ok == 0) { 1225 1158 printf("[XML ERROR] illegal or missing <psegname> for coproc %d in cluster %d\n", 1226 1159 coproc_index, cluster_index); 1227 1160 exit(1); 1228 1161 } 1229 1162 1230 1163 /////////// set psegid attribute 1231 int index = getPsegId( cluster_index, str ); 1232 if ( index >= 0 ) 1233 { 1234 #if XML_PARSER_DEBUG 1235 printf(" clusterid = %d\n", cluster_index); 1236 printf(" psegname = %s\n", str); 1237 printf(" psegid = %d\n", index); 1164 int index = getPsegId(cluster_index, str); 1165 if (index >= 0) { 1166 #if XML_PARSER_DEBUG 1167 printf(" clusterid = %d\n", cluster_index); 1168 printf(" psegname = %s\n", str); 1169 printf(" psegid = %d\n", index); 1238 1170 #endif 1239 1171 coproc[coproc_index]->psegid = index; 1240 1172 assert(pseg[index]->type == PSEG_TYPE_PERI && "coproc psegname attribute must refer to a pseg of type PERI" ); 1241 1173 } 1242 else 1243 { 1174 else { 1244 1175 printf("[XML ERROR] pseg not found for coproc %d / clusterid = %d / psegname = %s\n", 1245 1176 coproc_index, cluster_index, str ); 1246 1177 exit(1); 1247 1178 } … … 1251 1182 1252 1183 #if XML_PARSER_DEBUG 1253 printf(" port_offset = %d\n", cp_port_index);1184 printf(" port_offset = %d\n", cp_port_index); 1254 1185 #endif 1255 1186 1256 1187 int status = xmlTextReaderRead(reader); 1257 while ( status == 1 )1258 {1259 const char* tag = (const char*)xmlTextReaderConstName(reader); 1260 1261 if ( strcmp(tag, "port") == 0 )cpPortNode(reader);1262 else if ( strcmp(tag, "#text") == 0 ) {}1263 else if ( strcmp(tag, "#comment")== 0 ) { }1264 else if ( strcmp(tag, "coproc") == 0 )1265 {1188 while (status == 1) { 1189 const char * tag = (const char *) xmlTextReaderConstName(reader); 1190 1191 if (strcmp(tag, "port") == 0 ) { 1192 cpPortNode(reader); 1193 } 1194 else if (strcmp(tag, "#text") == 0 ) { } 1195 else if (strcmp(tag, "#comment") == 0 ) { } 1196 else if (strcmp(tag, "coproc") == 0 ) { 1266 1197 coproc[coproc_index]->ports = cp_port_loc_index; 1267 1198 cluster[cluster_index]->coprocs++; … … 1270 1201 return; 1271 1202 } 1272 else 1273 { 1274 printf("[XML ERROR] Unknown tag %s",tag); 1275 exit(1); 1276 } 1277 status = xmlTextReaderRead ( reader ); 1203 else { 1204 printf("[XML ERROR] Unknown tag %s", tag); 1205 exit(1); 1206 } 1207 status = xmlTextReaderRead(reader); 1278 1208 } 1279 1209 } // end coprocNode() 1280 1210 1211 1281 1212 /////////////////////////////////////// 1282 void irqNode( xmlTextReaderPtr reader ) 1283 /////////////////////////////////////// 1284 { 1285 unsigned int ok; 1286 unsigned int value; 1287 char* str; 1288 1289 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 1290 1291 if ( irq_index >= MAX_IRQS ) 1292 { 1213 void irqNode(xmlTextReaderPtr reader) { 1214 unsigned int ok; 1215 unsigned int value; 1216 char * str; 1217 1218 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1219 return; 1220 } 1221 1222 if (irq_index >= MAX_IRQS) { 1293 1223 printf("[XML ERROR] The number of irqs is larger than %d\n", MAX_IRQS); 1294 1224 } 1295 1225 1296 1226 #if XML_PARSER_DEBUG 1297 printf(" irq %d\n", irq_loc_index);1298 #endif 1299 1300 irq[irq_index] = (mapping_irq_t *)malloc(sizeof(mapping_irq_t));1227 printf(" irq %d\n", irq_loc_index); 1228 #endif 1229 1230 irq[irq_index] = (mapping_irq_t *) malloc(sizeof(mapping_irq_t)); 1301 1231 1302 1232 ///////// get type attribute 1303 str = getStringValue(reader,"type", &ok); 1304 if ( ok ) 1305 { 1306 #if XML_PARSER_DEBUG 1307 printf(" type = %s\n", str); 1308 #endif 1309 if ( strcmp(str, "HARD") == 0 ) irq[irq_index]->type = 0; 1310 else if ( strcmp(str, "SOFT") == 0 ) irq[irq_index]->type = 1; 1311 else 1312 { 1233 str = getStringValue(reader, "type", &ok); 1234 if (ok) { 1235 #if XML_PARSER_DEBUG 1236 printf(" type = %s\n", str); 1237 #endif 1238 if (strcmp(str, "HARD") == 0 ) { 1239 irq[irq_index]->type = 0; 1240 } 1241 else if (strcmp(str, "SOFT") == 0 ) { 1242 irq[irq_index]->type = 1; 1243 } 1244 else { 1313 1245 printf("[XML ERROR] undefined IRQ <type> for processor %d in cluster %d\n", 1314 cluster_index, proc_loc_index);1246 cluster_index, proc_loc_index); 1315 1247 exit(1); 1316 1248 } 1317 1249 } 1318 else 1319 { 1250 else { 1320 1251 printf("[XML ERROR] missing IRQ <type> for processor %d in cluster %d\n", 1321 cluster_index, proc_loc_index);1252 cluster_index, proc_loc_index); 1322 1253 exit(1); 1323 1254 } … … 1325 1256 ///////// get icuid attribute 1326 1257 value = getIntValue(reader, "icuid", &ok); 1327 if ( ok ) 1328 { 1329 #if XML_PARSER_DEBUG 1330 printf(" icuid = %d\n", value); 1258 if (ok) { 1259 #if XML_PARSER_DEBUG 1260 printf(" icuid = %d\n", value); 1331 1261 #endif 1332 1262 irq[irq_index]->icuid = value; 1333 if ( value >= 32 ) 1334 { 1263 if (value >= 32) { 1335 1264 printf("[XML ERROR] IRQ <icuid> too large for processor %d in cluster %d\n", 1336 cluster_index, proc_loc_index ); 1337 exit(1); 1338 } 1339 } 1340 else 1341 { 1265 cluster_index, proc_loc_index); 1266 exit(1); 1267 } 1268 } 1269 else { 1342 1270 printf("[XML ERROR] missing IRQ <icuid> for processor %d in cluster %d\n", 1343 cluster_index, proc_loc_index);1271 cluster_index, proc_loc_index); 1344 1272 exit(1); 1345 1273 } 1346 1274 1347 1275 ///////// get isr attribute 1348 str = getStringValue(reader,"isr", &ok); 1349 if ( ok ) 1350 { 1351 #if XML_PARSER_DEBUG 1352 printf(" isr = %s\n", str); 1353 #endif 1354 if ( strcmp(str, "ISR_SWITCH" ) == 0 ) irq[irq_index]->isr = ISR_SWITCH; 1355 else if ( strcmp(str, "ISR_IOC" ) == 0 ) irq[irq_index]->isr = ISR_IOC; 1356 else if ( strcmp(str, "ISR_DMA" ) == 0 ) irq[irq_index]->isr = ISR_DMA; 1357 else if ( strcmp(str, "ISR_TTY" ) == 0 ) irq[irq_index]->isr = ISR_TTY; 1358 else if ( strcmp(str, "ISR_TIMER" ) == 0 ) irq[irq_index]->isr = ISR_TIMER; 1359 else 1360 { 1276 str = getStringValue(reader, "isr", &ok); 1277 if (ok) { 1278 #if XML_PARSER_DEBUG 1279 printf(" isr = %s\n", str); 1280 #endif 1281 if (strcmp(str, "ISR_SWITCH" ) == 0) { irq[irq_index]->isr = ISR_SWITCH; } 1282 else if (strcmp(str, "ISR_IOC" ) == 0) { irq[irq_index]->isr = ISR_IOC; } 1283 else if (strcmp(str, "ISR_DMA" ) == 0) { irq[irq_index]->isr = ISR_DMA; } 1284 else if (strcmp(str, "ISR_TTY" ) == 0) { irq[irq_index]->isr = ISR_TTY; } 1285 else if (strcmp(str, "ISR_TIMER" ) == 0) { irq[irq_index]->isr = ISR_TIMER; } 1286 else { 1361 1287 printf("[XML ERROR] illegal IRQ <isr> for processor %d in cluster %d\n", 1362 cluster_index, proc_loc_index);1363 exit(1); 1364 } 1365 #if XML_PARSER_DEBUG 1366 printf(" isrnum = %d\n", irq[irq_index]->isr);1288 cluster_index, proc_loc_index); 1289 exit(1); 1290 } 1291 #if XML_PARSER_DEBUG 1292 printf(" isrnum = %d\n", irq[irq_index]->isr); 1367 1293 #endif 1368 1294 } 1369 else 1370 { 1295 else { 1371 1296 printf("[XML ERROR] missing IRQ <isr> for processor %d in cluster %d\n", 1372 cluster_index, proc_loc_index);1297 cluster_index, proc_loc_index); 1373 1298 exit(1); 1374 1299 } … … 1376 1301 ///////// get channel attribute (optionnal : 0 if missing) 1377 1302 value = getIntValue(reader, "channel", &ok); 1378 if ( ok ) 1379 { 1380 #if XML_PARSER_DEBUG 1381 printf(" channel = %d\n", value); 1303 if (ok) { 1304 #if XML_PARSER_DEBUG 1305 printf(" channel = %d\n", value); 1382 1306 #endif 1383 1307 irq[irq_index]->channel = value; 1384 1308 } 1385 else 1386 { 1309 else { 1387 1310 irq[irq_index]->channel = 0; 1388 1311 } … … 1393 1316 } // end irqNode 1394 1317 1318 1395 1319 ///////////////////////////////////////// 1396 void procNode ( xmlTextReaderPtr reader ) 1397 ///////////////////////////////////////// 1398 { 1399 unsigned int ok; 1400 unsigned int value; 1320 void procNode(xmlTextReaderPtr reader) { 1321 unsigned int ok; 1322 unsigned int value; 1401 1323 1402 1324 irq_loc_index = 0; 1403 1325 1404 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 1405 1406 if ( proc_index >= MAX_PROCS ) 1407 { 1326 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1327 return; 1328 } 1329 1330 if (proc_index >= MAX_PROCS) { 1408 1331 printf("[XML ERROR] The number of procs is larger than %d\n", MAX_PROCS); 1409 1332 } 1410 1333 1411 1334 #if XML_PARSER_DEBUG 1412 printf("\n proc %d\n", proc_index);1413 #endif 1414 1415 proc[proc_index] = (mapping_proc_t *)malloc(sizeof(mapping_proc_t));1335 printf("\n proc %d\n", proc_index); 1336 #endif 1337 1338 proc[proc_index] = (mapping_proc_t *) malloc(sizeof(mapping_proc_t)); 1416 1339 1417 1340 1418 1341 /////////// get index attribute (optional) 1419 value = getIntValue(reader,"index",&ok); 1420 if ( ok && (value != proc_loc_index) ) 1421 { 1422 printf("[XML ERROR] wrong proc index / expected value is %d", 1342 value = getIntValue(reader, "index", &ok); 1343 if (ok && (value != proc_loc_index)) { 1344 printf("[XML ERROR] wrong proc index / expected value is %d", 1423 1345 proc_loc_index); 1424 1346 exit(1); 1425 1347 } 1426 1348 … … 1429 1351 1430 1352 #if XML_PARSER_DEBUG 1431 printf(" irq_offset = %d\n", irq_index);1353 printf(" irq_offset = %d\n", irq_index); 1432 1354 #endif 1433 1355 1434 1356 int status = xmlTextReaderRead(reader); 1435 while ( status == 1 )1436 {1437 const char* tag = (const char*)xmlTextReaderConstName(reader); 1438 1439 if ( strcmp(tag, "irq") == 0 )irqNode(reader);1440 else if ( strcmp(tag, "#text") == 0 ) {}1441 else if ( strcmp(tag, "#comment") == 0) { }1442 else if ( strcmp(tag, "proc") == 0 )1443 {1357 while (status == 1) { 1358 const char * tag = (const char *) xmlTextReaderConstName(reader); 1359 1360 if (strcmp(tag, "irq") == 0) { 1361 irqNode(reader); 1362 } 1363 else if (strcmp(tag, "#text") == 0) { } 1364 else if (strcmp(tag, "#comment") == 0) { } 1365 else if (strcmp(tag, "proc") == 0) { 1444 1366 proc[proc_index]->irqs = irq_loc_index; 1445 1367 cluster[cluster_index]->procs++; … … 1448 1370 return; 1449 1371 } 1450 else 1451 { 1452 printf("[XML ERROR] Unknown tag %s",tag); 1453 exit(1); 1454 } 1455 status = xmlTextReaderRead ( reader ); 1372 else { 1373 printf("[XML ERROR] Unknown tag %s", tag); 1374 exit(1); 1375 } 1376 status = xmlTextReaderRead(reader); 1456 1377 } 1457 1378 } // end procNode() … … 1459 1380 1460 1381 ////////////////////////////////////////// 1461 void psegNode ( xmlTextReaderPtr reader ) 1462 ////////////////////////////////////////// 1463 { 1464 unsigned int ok; 1465 unsigned int value; 1466 char* str; 1467 1468 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 1469 1470 if ( pseg_index >= MAX_PSEGS ) 1471 { 1382 void psegNode(xmlTextReaderPtr reader) { 1383 unsigned int ok; 1384 unsigned int value; 1385 char * str; 1386 1387 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1388 return; 1389 } 1390 1391 if (pseg_index >= MAX_PSEGS) { 1472 1392 printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); 1473 1393 exit(1); … … 1475 1395 1476 1396 #if XML_PARSER_DEBUG 1477 printf(" pseg %d\n", pseg_index);1478 #endif 1479 1480 pseg[pseg_index] = (mapping_pseg_t *)malloc(sizeof(mapping_pseg_t));1397 printf(" pseg %d\n", pseg_index); 1398 #endif 1399 1400 pseg[pseg_index] = (mapping_pseg_t *) malloc(sizeof(mapping_pseg_t)); 1481 1401 1482 1402 /////// get name attribute 1483 str = getStringValue( reader, "name", &ok ); 1484 #if XML_PARSER_DEBUG 1485 printf(" name = %s\n", str); 1486 #endif 1487 if ( ok ) 1488 { 1403 str = getStringValue(reader, "name", &ok); 1404 #if XML_PARSER_DEBUG 1405 printf(" name = %s\n", str); 1406 #endif 1407 if (ok) { 1489 1408 strncpy(pseg[pseg_index]->name, str, 31); 1490 1409 } 1491 else 1492 { 1410 else { 1493 1411 printf("[XML ERROR] illegal or missing <name> for pseg %d in cluster %d\n", 1494 pseg_index, cluster_index);1412 pseg_index, cluster_index); 1495 1413 exit(1); 1496 1414 } … … 1499 1417 str = getStringValue(reader, "type", &ok); 1500 1418 #if XML_PARSER_DEBUG 1501 printf(" type = %s\n", str); 1502 #endif 1503 if (ok && (strcmp(str, "RAM" ) == 0)) pseg[pseg_index]->type = PSEG_TYPE_RAM; 1504 else if (ok && (strcmp(str, "ROM" ) == 0)) pseg[pseg_index]->type = PSEG_TYPE_ROM; 1505 else if (ok && (strcmp(str, "PERI") == 0)) pseg[pseg_index]->type = PSEG_TYPE_PERI; 1506 else 1507 { 1419 printf(" type = %s\n", str); 1420 #endif 1421 if (ok && (strcmp(str, "RAM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_RAM; } 1422 else if (ok && (strcmp(str, "ROM" ) == 0)) { pseg[pseg_index]->type = PSEG_TYPE_ROM; } 1423 else if (ok && (strcmp(str, "PERI") == 0)) { pseg[pseg_index]->type = PSEG_TYPE_PERI; } 1424 else { 1508 1425 printf("[XML ERROR] illegal or missing <type> for pseg %s in cluster %d\n", 1509 pseg[pseg_index]->name, cluster_index);1426 pseg[pseg_index]->name, cluster_index); 1510 1427 exit(1); 1511 1428 } 1512 1429 1513 1430 //////// get base attribute 1514 value = getIntValue( reader, "base", &ok ); 1515 #if XML_PARSER_DEBUG 1516 printf(" base = 0x%x\n", value); 1517 #endif 1518 if ( ok ) 1519 { 1431 value = getIntValue(reader, "base", &ok); 1432 #if XML_PARSER_DEBUG 1433 printf(" base = 0x%x\n", value); 1434 #endif 1435 if (ok) { 1520 1436 pseg[pseg_index]->base = value; 1521 1437 } 1522 else 1523 { 1438 else { 1524 1439 printf("[XML ERROR] illegal or missing <base> for pseg %s in cluster %d\n", 1525 pseg[pseg_index]->name, cluster_index);1440 pseg[pseg_index]->name, cluster_index); 1526 1441 exit(1); 1527 1442 } 1528 1443 1529 1444 //////// get length attribute 1530 value = getIntValue( reader, "length", &ok ); 1531 #if XML_PARSER_DEBUG 1532 printf(" length = 0x%x\n", value); 1533 #endif 1534 if ( ok ) 1535 { 1445 value = getIntValue(reader, "length", &ok); 1446 #if XML_PARSER_DEBUG 1447 printf(" length = 0x%x\n", value); 1448 #endif 1449 if (ok) { 1536 1450 pseg[pseg_index]->length = value; 1537 1451 } 1538 else 1539 { 1452 else { 1540 1453 printf("[XML ERROR] illegal or missing <length> for pseg %s in cluster %d\n", 1541 pseg[pseg_index]->name, cluster_index);1454 pseg[pseg_index]->name, cluster_index); 1542 1455 exit(1); 1543 1456 } … … 1550 1463 } // end psegNode() 1551 1464 1465 1552 1466 ///////////////////////////////////////////// 1553 void clusterNode ( xmlTextReaderPtr reader ) 1554 ///////////////////////////////////////////// 1555 { 1467 void clusterNode(xmlTextReaderPtr reader) { 1556 1468 unsigned int ok; 1557 1469 unsigned int value; 1558 1470 1559 cluster[cluster_index] = (mapping_cluster_t *)malloc(sizeof(mapping_cluster_t));1560 1471 cluster[cluster_index] = (mapping_cluster_t *) malloc(sizeof(mapping_cluster_t)); 1472 1561 1473 //initialise all variables 1562 1474 //they will be incremented by *Node() functions … … 1580 1492 found_dma = 0; 1581 1493 1582 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; 1494 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1495 return; 1496 } 1583 1497 1584 1498 // checking source file consistency 1585 if ( cluster_index >= header->clusters ) 1586 { 1499 if (cluster_index >= header->clusters) { 1587 1500 printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index); 1588 1501 exit(1); … … 1590 1503 1591 1504 #if XML_PARSER_DEBUG 1592 printf(" cluster %d\n", cluster_index);1505 printf(" cluster %d\n", cluster_index); 1593 1506 #endif 1594 1507 1595 1508 1596 1509 /////////// check cluster index attribute (optional) 1597 value = getIntValue(reader,"index",&ok); 1598 if ( ok && (value != cluster_index) ) 1599 { 1600 printf("[XML ERROR] wrong cluster index / expected value is %d", 1510 value = getIntValue(reader, "index", &ok); 1511 if (ok && (value != cluster_index)) { 1512 printf("[XML ERROR] wrong cluster index / expected value is %d", 1601 1513 cluster_index); 1602 1514 exit(1); 1603 1515 } 1604 1516 1605 1517 ////////// set offsets 1606 cluster[cluster_index]->pseg_offset 1607 cluster[cluster_index]->proc_offset 1518 cluster[cluster_index]->pseg_offset = pseg_index; 1519 cluster[cluster_index]->proc_offset = proc_index; 1608 1520 cluster[cluster_index]->coproc_offset = coproc_index; 1609 1521 cluster[cluster_index]->periph_offset = periph_index; 1610 1522 1611 1523 #if XML_PARSER_DEBUG 1612 printf(" pseg_offset = %d\n", pseg_index);1613 printf(" proc_offset = %d\n", proc_index);1614 printf(" coproc_offset = %d\n", coproc_index);1615 printf(" periph_offset = %d\n", coproc_index);1524 printf(" pseg_offset = %d\n", pseg_index); 1525 printf(" proc_offset = %d\n", proc_index); 1526 printf(" coproc_offset = %d\n", coproc_index); 1527 printf(" periph_offset = %d\n", coproc_index); 1616 1528 #endif 1617 1529 … … 1619 1531 int status = xmlTextReaderRead(reader); 1620 1532 1621 while ( status == 1 ) 1622 { 1623 const char* tag = (const char*)xmlTextReaderConstName(reader); 1624 1625 if ( strcmp(tag, "pseg") == 0 ) psegNode(reader); 1626 else if ( strcmp(tag, "proc") == 0 ) procNode(reader); 1627 else if ( strcmp(tag, "coproc") == 0 ) coprocNode(reader); 1628 else if ( strcmp(tag, "periph") == 0 ) periphNode(reader); 1629 else if ( strcmp(tag, "#text") == 0 ) { } 1630 else if ( strcmp(tag, "#comment") == 0 ) { } 1631 else if ( strcmp(tag, "cluster") == 0 ) 1632 { 1633 1634 if(use_xicu == 0xFFFFFFFF) 1533 while (status == 1) { 1534 const char * tag = (const char *) xmlTextReaderConstName(reader); 1535 1536 if (strcmp(tag, "pseg") == 0) psegNode(reader); 1537 else if (strcmp(tag, "proc") == 0) procNode(reader); 1538 else if (strcmp(tag, "coproc") == 0) coprocNode(reader); 1539 else if (strcmp(tag, "periph") == 0) periphNode(reader); 1540 else if (strcmp(tag, "#text") == 0) { } 1541 else if (strcmp(tag, "#comment") == 0) { } 1542 else if (strcmp(tag, "cluster") == 0) { 1543 1544 if (use_xicu == 0xFFFFFFFF) { 1635 1545 use_xicu = found_xicu; 1546 } 1636 1547 1637 1548 ////////////////// peripherals checks //////////////////// 1638 if( (found_timer && use_xicu) || (!found_timer && !use_xicu) ) 1639 { 1549 if ((found_timer && use_xicu) || (!found_timer && !use_xicu)) { 1640 1550 printf("[XML ERROR] illegal or missing timer peripheral in cluster %d\n", cluster_index); 1641 1551 exit(1); 1642 1552 } 1643 1553 1644 if( (found_icu && use_xicu) || (!found_icu && !use_xicu) ) 1645 { 1554 if ((found_icu && use_xicu) || (!found_icu && !use_xicu)) { 1646 1555 printf("[XML ERROR] illegal or missing icu peripheral in cluster %d\n", cluster_index); 1647 1556 exit(1); 1648 1557 } 1649 1558 1650 if( !found_xicu && use_xicu) 1651 { 1559 if (!found_xicu && use_xicu) { 1652 1560 printf("[XML ERROR] illegal or missing dma peripheral in cluster %d\n", cluster_index); 1653 1561 exit(1); 1654 1562 } 1655 1563 1656 if(!found_dma) 1657 { 1564 if (!found_dma) { 1658 1565 printf("[XML ERROR] illegal or missing dma peripheral in cluster %d\n", cluster_index); 1659 1566 exit(1); 1660 1567 } 1661 1568 1662 1663 if (nb_proc_max < cluster[cluster_index]->procs)1569 1570 if (nb_proc_max < cluster[cluster_index]->procs) { 1664 1571 nb_proc_max = cluster[cluster_index]->procs; 1665 1666 #if XML_PARSER_DEBUG 1667 printf(" psegs = %d\n", cluster[cluster_index]->psegs); 1668 printf(" procs = %d\n", cluster[cluster_index]->procs); 1669 printf(" coprocs = %d\n", cluster[cluster_index]->coprocs); 1670 printf(" periphs = %d\n", cluster[cluster_index]->periphs); 1671 printf(" end cluster %d\n", cluster_index); 1572 } 1573 1574 #if XML_PARSER_DEBUG 1575 printf(" psegs = %d\n", cluster[cluster_index]->psegs); 1576 printf(" procs = %d\n", cluster[cluster_index]->procs); 1577 printf(" coprocs = %d\n", cluster[cluster_index]->coprocs); 1578 printf(" periphs = %d\n", cluster[cluster_index]->periphs); 1579 printf(" end cluster %d\n", cluster_index); 1672 1580 #endif 1673 1581 cluster_index++; … … 1678 1586 } // end clusterNode() 1679 1587 1588 1680 1589 ////////////////////////////////////////////// 1681 void clusterSetNode( xmlTextReaderPtr reader )1682 ////////////////////////////////////////////// 1683 { 1684 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;1685 1686 #if XML_PARSER_DEBUG 1687 printf("\n clusters set\n");1590 void clusterSetNode(xmlTextReaderPtr reader) { 1591 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1592 return; 1593 } 1594 1595 #if XML_PARSER_DEBUG 1596 printf("\n clusters set\n"); 1688 1597 #endif 1689 1598 1690 1599 int status = xmlTextReaderRead(reader); 1691 while ( status == 1 )1692 {1693 const char* tag = (const char*)xmlTextReaderConstName(reader); 1694 1695 if ( strcmp(tag, "cluster") == 0 )clusterNode(reader);1696 else if ( strcmp(tag, "#text") == 0 ) {}1697 else if ( strcmp(tag, "#comment") == 0) { }1698 else if ( strcmp(tag, "clusterset") == 0 )1699 {1600 while (status == 1) { 1601 const char * tag = (const char *) xmlTextReaderConstName(reader); 1602 1603 if (strcmp(tag, "cluster") == 0) { 1604 clusterNode(reader); 1605 } 1606 else if (strcmp(tag, "#text") == 0) { } 1607 else if (strcmp(tag, "#comment") == 0) { } 1608 else if (strcmp(tag, "clusterset") == 0) { 1700 1609 // checking source file consistency 1701 if ( cluster_index != header->clusters ) 1702 { 1610 if (cluster_index != header->clusters) { 1703 1611 printf("[XML ERROR] Wrong number of clusters\n"); 1704 1612 exit(1); 1705 1613 } 1706 1614 1707 if(header->tty_clusterid == 0xFFFFFFFF) 1708 { 1615 if (header->tty_clusterid == 0xFFFFFFFF) { 1709 1616 printf("[XML ERROR] illegal or missing tty peripheral"); 1710 1617 exit(1); … … 1712 1619 1713 1620 #if XML_PARSER_DEBUG 1714 printf(" end cluster set\n\n");1715 #endif 1716 header->psegs 1717 header->procs 1718 header->irqs 1719 header->coprocs 1621 printf(" end cluster set\n\n"); 1622 #endif 1623 header->psegs = pseg_index; 1624 header->procs = proc_index; 1625 header->irqs = irq_index; 1626 header->coprocs = coproc_index; 1720 1627 header->cp_ports = cp_port_index; 1721 1628 return; 1722 1629 } 1723 else 1724 { 1630 else { 1725 1631 printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); 1726 1632 exit(1); … … 1730 1636 } // end clusterSetNode() 1731 1637 1638 1732 1639 ///////////////////////////////////////////// 1733 void globalSetNode( xmlTextReaderPtr reader )1734 ///////////////////////////////////////////// 1735 { 1736 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;1737 1738 #if XML_PARSER_DEBUG 1739 printf(" globals set\n");1640 void globalSetNode(xmlTextReaderPtr reader) { 1641 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1642 return; 1643 } 1644 1645 #if XML_PARSER_DEBUG 1646 printf(" globals set\n"); 1740 1647 #endif 1741 1648 1742 1649 int status = xmlTextReaderRead(reader); 1743 while ( status == 1 )1744 {1745 const char* tag = (const char*)xmlTextReaderConstName(reader); 1746 1747 if ( strcmp(tag, "vseg") == 0 )vsegNode(reader);1748 else if ( strcmp(tag, "#text" ) == 0 ) {}1749 else if ( strcmp(tag, "#comment") == 0) { }1750 else if ( strcmp(tag, "globalset") == 0 )1751 {1752 #if XML_PARSER_DEBUG 1753 printf(" end global set\n\n");1650 while (status == 1) { 1651 const char * tag = (const char *) xmlTextReaderConstName(reader); 1652 1653 if (strcmp(tag, "vseg") == 0) { 1654 vsegNode(reader); 1655 } 1656 else if (strcmp(tag, "#text") == 0) { } 1657 else if (strcmp(tag, "#comment") == 0) { } 1658 else if (strcmp(tag, "globalset") == 0) { 1659 #if XML_PARSER_DEBUG 1660 printf(" end global set\n\n"); 1754 1661 #endif 1755 1662 header->globals = vseg_index; … … 1757 1664 return; 1758 1665 } 1759 else 1760 { 1666 else { 1761 1667 printf("[XML ERROR] Unknown tag in globalset node : %s",tag); 1762 1668 exit(1); 1763 1669 } 1764 status = xmlTextReaderRead ( reader);1670 status = xmlTextReaderRead(reader); 1765 1671 } 1766 1672 } // end globalSetNode() 1767 1673 1674 1768 1675 ///////////////////////////////////////////// 1769 void vspaceSetNode( xmlTextReaderPtr reader )1770 ///////////////////////////////////////////// 1771 { 1772 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;1773 1774 #if XML_PARSER_DEBUG 1775 printf("\n vspaces set\n");1676 void vspaceSetNode(xmlTextReaderPtr reader) { 1677 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1678 return; 1679 } 1680 1681 #if XML_PARSER_DEBUG 1682 printf("\n vspaces set\n"); 1776 1683 #endif 1777 1684 1778 1685 int status = xmlTextReaderRead ( reader ); 1779 while ( status == 1 )1780 {1781 const char* tag = (const char*)xmlTextReaderConstName(reader); 1782 1783 if ( strcmp(tag, "vspace" ) == 0 )vspaceNode(reader);1784 else if ( strcmp(tag, "#text" ) == 0 ) {}1785 else if ( strcmp(tag, "#comment") == 0 ) { }1786 else if ( strcmp(tag, "vspaceset") == 0 )1787 {1686 while (status == 1) { 1687 const char * tag = (const char *) xmlTextReaderConstName(reader); 1688 1689 if (strcmp(tag, "vspace") == 0) { 1690 vspaceNode(reader); 1691 } 1692 else if (strcmp(tag, "#text" ) == 0 ) { } 1693 else if (strcmp(tag, "#comment" ) == 0 ) { } 1694 else if (strcmp(tag, "vspaceset") == 0 ) { 1788 1695 // checking source file consistency 1789 if ( vspace_index != header->vspaces ) 1790 { 1696 if (vspace_index != header->vspaces) { 1791 1697 printf("[XML ERROR] Wrong number of vspaces\n"); 1792 1698 exit(1); 1793 1699 } 1794 else 1795 { 1700 else { 1796 1701 header->vsegs = vseg_index; 1797 1702 header->vobjs = vobj_index; … … 1800 1705 } 1801 1706 } 1802 else 1803 { 1707 else { 1804 1708 printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); 1805 1709 exit(1); 1806 1710 } 1807 status = xmlTextReaderRead ( reader);1711 status = xmlTextReaderRead(reader); 1808 1712 } 1809 1713 } // end globalSetNode() 1810 1714 1715 1811 1716 ////////////////////////////////////////// 1812 void headerNode(xmlTextReaderPtr reader )1813 ////////////////////////////////////////// 1814 { 1815 char* name;1816 unsigned int value; 1817 unsigned int ok;1818 1819 if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return;1820 1821 #if XML_PARSER_DEBUG 1822 printf("mapping_info\n");1823 #endif 1824 1825 header = (mapping_header_t *)malloc(sizeof(mapping_header_t));1717 void headerNode(xmlTextReaderPtr reader) { 1718 char * name; 1719 unsigned int value; 1720 unsigned int ok; 1721 1722 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT) { 1723 return; 1724 } 1725 1726 #if XML_PARSER_DEBUG 1727 printf("mapping_info\n"); 1728 #endif 1729 1730 header = (mapping_header_t *) malloc(sizeof(mapping_header_t)); 1826 1731 1827 1732 ////////// get name attribute 1828 1733 name = getStringValue(reader, "name", &ok); 1829 if ( ok ) 1830 { 1831 #if XML_PARSER_DEBUG 1832 printf(" name = %s\n", name); 1833 #endif 1834 strncpy( header->name, name, 31); 1835 } 1836 else 1837 { 1734 if (ok) { 1735 #if XML_PARSER_DEBUG 1736 printf(" name = %s\n", name); 1737 #endif 1738 strncpy( header->name, name, 31); 1739 } 1740 else { 1838 1741 printf("[XML ERROR] illegal or missing <name> attribute in header\n"); 1839 1742 exit(1); … … 1842 1745 /////////// get cluster_x attribute 1843 1746 cluster_x = getIntValue(reader, "cluster_x", &ok); 1844 if ( ok ) 1845 { 1846 #if XML_PARSER_DEBUG 1847 printf(" cluster_x = %d\n", cluster_x); 1747 if (ok) { 1748 #if XML_PARSER_DEBUG 1749 printf(" cluster_x = %d\n", cluster_x); 1848 1750 #endif 1849 1751 header->cluster_x = cluster_x; 1850 1752 } 1851 else 1852 { 1753 else { 1853 1754 printf("[XML ERROR] illegal or missing <cluster_x> attribute in header\n"); 1854 1755 exit(1); … … 1857 1758 /////////// get cluster_y attribute 1858 1759 cluster_y = getIntValue(reader, "cluster_y", &ok); 1859 if ( ok ) 1860 { 1861 #if XML_PARSER_DEBUG 1862 printf(" cluster_y = %d\n", cluster_y); 1760 if (ok) { 1761 #if XML_PARSER_DEBUG 1762 printf(" cluster_y = %d\n", cluster_y); 1863 1763 #endif 1864 1764 header->cluster_y = cluster_y; 1865 1765 } 1866 else 1867 { 1766 else { 1868 1767 printf("[XML ERROR] illegal or missing <cluster_y> attribute in header\n"); 1869 1768 exit(1); … … 1871 1770 1872 1771 //check the number of cluster 1873 value = cluster_x*cluster_y; 1874 if ( value >= MAX_CLUSTERS ) 1875 { 1772 value = cluster_x * cluster_y; 1773 if (value >= MAX_CLUSTERS) { 1876 1774 printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); 1877 1775 exit(1); 1878 1776 } 1879 1777 1880 1778 header->clusters = value; 1881 1779 1882 1780 #if XML_PARSER_DEBUG 1883 printf(" clusters = %d\n", value);1781 printf(" clusters = %d\n", value); 1884 1782 #endif 1885 1783 1886 1784 ///////// get vspaces attribute 1887 1785 value = getIntValue(reader, "vspaces", &ok); 1888 if ( ok ) 1889 { 1890 if ( value >= MAX_VSPACES ) 1891 { 1786 if (ok) { 1787 if (value >= MAX_VSPACES) { 1892 1788 printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); 1893 1789 exit(1); 1894 1790 } 1895 1791 #if XML_PARSER_DEBUG 1896 printf(" vspaces = %d\n", value); 1897 #endif 1898 header->vspaces = value; 1899 } 1900 else 1901 { 1792 printf(" vspaces = %d\n", value); 1793 #endif 1794 header->vspaces = value; 1795 } 1796 else { 1902 1797 printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); 1903 1798 exit(1); … … 1914 1809 1915 1810 int status = xmlTextReaderRead(reader); 1916 while ( status == 1 )1917 {1918 const char* tag = (const char*)xmlTextReaderConstName(reader); 1919 1920 if ( strcmp(tag, "clusterset") == 0 )clusterSetNode(reader);1921 else if ( strcmp(tag, "globalset") == 0 ) globalSetNode(reader);1922 else if ( strcmp(tag, "vspaceset") == 0 ) vspaceSetNode(reader);1923 else if ( strcmp(tag, "#text") == 0 ) {}1924 else if ( strcmp(tag, "#comment") == 0) { }1925 else if ( strcmp(tag, "mapping_info") == 0 )1926 {1927 #if XML_PARSER_DEBUG 1928 printf("end mapping_info\n");1811 while (status == 1) { 1812 const char * tag = (const char *) xmlTextReaderConstName(reader); 1813 1814 if (strcmp(tag, "clusterset") == 0) { 1815 clusterSetNode(reader); 1816 } 1817 else if (strcmp(tag, "globalset") == 0) { globalSetNode(reader); } 1818 else if (strcmp(tag, "vspaceset") == 0) { vspaceSetNode(reader); } 1819 else if (strcmp(tag, "#text") == 0) { } 1820 else if (strcmp(tag, "#comment") == 0) { } 1821 else if (strcmp(tag, "mapping_info") == 0) { 1822 #if XML_PARSER_DEBUG 1823 printf("end mapping_info\n"); 1929 1824 #endif 1930 1825 return; 1931 1826 } 1932 else 1933 { 1827 else { 1934 1828 printf("[XML ERROR] Unknown tag in header node : %s\n",tag); 1935 1829 exit(1); … … 1938 1832 } 1939 1833 } // end headerNode() 1940 1834 1835 1941 1836 /////////////////////////////////////// 1942 void BuildTable( int fdout, 1943 const char* type, 1944 unsigned int nb_elem, 1945 unsigned int elem_size, 1946 char** table) 1947 //////////////////////////////////////// 1948 { 1837 void BuildTable(int fdout, const char * type, unsigned int nb_elem, 1838 unsigned int elem_size, char ** table) { 1949 1839 unsigned int i; 1950 1840 // write element 1951 for ( i = 0 ; i < nb_elem ; i++ ) 1952 { 1953 if(elem_size != write(fdout, table[i], elem_size)) 1954 { 1841 for (i = 0; i < nb_elem; i++) { 1842 if (elem_size != write(fdout, table[i], elem_size)) { 1955 1843 printf("function %s: %s(%d) write error \n", __FUNCTION__, type, i); 1956 1844 exit(1); … … 1958 1846 1959 1847 #if XML_PARSER_DEBUG 1960 printf("Building binary: writing %s %d\n", type, i);1848 printf("Building binary: writing %s %d\n", type, i); 1961 1849 #endif 1962 1850 } 1963 1851 } 1964 1852 1965 int open_file(const char* file_path) 1966 {1853 1854 int open_file(const char * file_path) { 1967 1855 1968 1856 //open file 1969 int fdout = open( file_path, (O_CREAT | O_RDWR | O_TRUNC), (S_IWUSR | S_IRUSR) ); 1970 if ( fdout < 0) 1971 { 1857 int fdout = open( file_path, (O_CREAT | O_RDWR), (S_IWUSR | S_IRUSR) ); 1858 if (fdout < 0) { 1972 1859 perror("open"); 1973 1860 exit(1); 1974 1861 } 1975 1862 1976 //#if XML_PARSER_DEBUG 1977 printf("%s\n",file_path); 1978 //#endif 1863 //reinitialise the file 1864 if (ftruncate(fdout, 0)) { 1865 perror("truncate"); 1866 exit(1); 1867 } 1868 1869 //#if XML_PARSER_DEBUG 1870 printf("%s\n", file_path); 1871 //#endif 1979 1872 1980 1873 return fdout; … … 1983 1876 1984 1877 /////////////////////////// 1985 void buildBin( const char* file_path ) 1986 /////////////////////////// 1987 { 1988 unsigned int length; 1878 void buildBin(const char * file_path) { 1879 unsigned int length; 1989 1880 1990 1881 int fdout = open_file(file_path); 1991 1882 1992 1883 // write header to binary file 1993 length = write(fdout, (char*)header, sizeof(mapping_header_t)); 1994 if ( length != sizeof(mapping_header_t) ) 1995 { 1884 length = write(fdout, (char *) header, sizeof(mapping_header_t)); 1885 if (length != sizeof(mapping_header_t)) { 1996 1886 printf("write header error : length = %d \n", length); 1997 1887 exit(1); … … 1999 1889 2000 1890 // write clusters 2001 BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char **) cluster);1891 BuildTable(fdout, "cluster", cluster_index, sizeof(mapping_cluster_t), (char **) cluster); 2002 1892 // write psegs 2003 BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char **) pseg);1893 BuildTable(fdout, "pseg", pseg_index, sizeof(mapping_pseg_t), (char **) pseg); 2004 1894 // write vspaces 2005 BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char **) vspace);1895 BuildTable(fdout, "vspace", vspace_index, sizeof(mapping_vspace_t), (char **) vspace); 2006 1896 // write vsegs 2007 BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char **) vseg);1897 BuildTable(fdout, "vseg", vseg_index, sizeof(mapping_vseg_t), (char **) vseg); 2008 1898 // write vobjs 2009 BuildTable(fdout, "vobj", vobj_index, sizeof(mapping_vobj_t), (char **) vobj);1899 BuildTable(fdout, "vobj", vobj_index, sizeof(mapping_vobj_t), (char **) vobj); 2010 1900 // write tasks array 2011 BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char **) task);1901 BuildTable(fdout, "task", task_index, sizeof(mapping_task_t), (char **) task); 2012 1902 //building procs array 2013 BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char **) proc);1903 BuildTable(fdout, "proc", proc_index, sizeof(mapping_proc_t), (char **) proc); 2014 1904 //building irqs array 2015 BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char **)irq);1905 BuildTable(fdout, "irq", irq_index, sizeof(mapping_irq_t), (char **) irq); 2016 1906 //building coprocs array 2017 BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char **)coproc);1907 BuildTable(fdout, "coproc", coproc_index, sizeof(mapping_coproc_t), (char **) coproc); 2018 1908 //building cp_ports array 2019 BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char **) cp_port);1909 BuildTable(fdout, "cp_port", cp_port_index, sizeof(mapping_cp_port_t),(char **) cp_port); 2020 1910 //building periphs array 2021 BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char **)periph);2022 1911 BuildTable(fdout, "periph", periph_index, sizeof(mapping_periph_t), (char **) periph); 1912 2023 1913 close(fdout); 2024 1914 2025 1915 } // end buildBin() 1916 2026 1917 2027 1918 /////////////////////////////////////////////////////////////////////// 2028 1919 // this function set the value the vobj_id fiels of all cp_ports 2029 1920 /////////////////////////////////////////////////////////////////////// 2030 void prepareBuild() 2031 { 1921 void prepareBuild() { 2032 1922 unsigned int i; 2033 1923 //asign for all cp_ports the correct vspaceid and vobjid 2034 for(i=0; i< cp_port_index; i++) 2035 { 2036 int vspace_id = getVspaceId( cp_port_vobj_ref[i]->vspace_name ); 2037 if ( vspace_id < 0 ) 2038 { 2039 printf("[XML ERROR] illegal <vspacename> for cp_port %d,\n", 2040 i); 1924 for (i = 0; i < cp_port_index; i++) { 1925 int vspace_id = getVspaceId(cp_port_vobj_ref[i]->vspace_name); 1926 if (vspace_id < 0) { 1927 printf("[XML ERROR] illegal <vspacename> for cp_port %d,\n", i); 2041 1928 exit(1); 2042 1929 } 2043 1930 cp_port[i]->vspaceid = vspace_id; 2044 2045 int vobj_id = getVobjLocId( vspace_id, 2046 cp_port_vobj_ref[i]->vobj_name, 2047 vspace[vspace_id]->vobjs ); 2048 if ( vobj_id >= 0 ) 2049 { 2050 2051 #if XML_PARSER_DEBUG 2052 printf("\ncp_port = %d\n", i); 2053 printf(" vspace_name = %s\n", cp_port_vobj_ref[i]->vspace_name); 2054 printf(" vobj_name = %s\n", cp_port_vobj_ref[i]->vobj_name); 2055 printf(" vobj_index = %d\n", vobj_id); 1931 1932 int vobj_id = getVobjLocId(vspace_id, cp_port_vobj_ref[i]->vobj_name, vspace[vspace_id]->vobjs); 1933 if (vobj_id >= 0) { 1934 1935 #if XML_PARSER_DEBUG 1936 printf("\ncp_port = %d\n", i); 1937 printf(" vspace_name = %s\n", cp_port_vobj_ref[i]->vspace_name); 1938 printf(" vobj_name = %s\n", cp_port_vobj_ref[i]->vobj_name); 1939 printf(" vobj_index = %d\n", vobj_id); 2056 1940 #endif 2057 1941 cp_port[i]->vobjlocid = vobj_id; 2058 1942 2059 1943 assert((vobj[ vspace[vspace_id]->vobj_offset + vobj_id]->type == VOBJ_TYPE_MWMR) 2060 && "coproc ports has to refere to a vobj of type MWMR"); 2061 } 2062 else 2063 { 2064 printf("[XML ERROR] illegal <vobjname> for cp_port %d,\n", 2065 i); 1944 && "coproc ports have to refer to a vobj of type MWMR"); 1945 } 1946 else { 1947 printf("[XML ERROR] illegal <vobjname> for cp_port %d,\n", i); 2066 1948 exit(1); 2067 1949 } … … 2069 1951 } 2070 1952 1953 2071 1954 ////////////////////////////////////////// 2072 void file_write(int fdout, char* towrite) 2073 { 1955 void file_write(int fdout, char * towrite) { 2074 1956 unsigned int size = strlen(towrite); 2075 if(size != write(fdout, towrite, size)) 2076 { 1957 if (size != write(fdout, towrite, size)) { 2077 1958 printf("file_write error"); 2078 1959 exit(1); … … 2080 1961 } 2081 1962 1963 2082 1964 ////////////////////////////////////////////////// 2083 void def_int_write(int fdout, char* def, int num) 2084 { 2085 char buf[64]; 1965 void def_int_write(int fdout, char * def, int num) { 1966 char buf[64]; 2086 1967 sprintf(buf, "#define\t %s %d\n", def, num); 2087 1968 file_write(fdout, buf); 2088 1969 } 2089 1970 1971 2090 1972 ///////////////////////////////////////////////// 2091 void def_hex_write(int fdout, char* def, int num) 2092 { 2093 char buf[64]; 1973 void def_hex_write(int fdout, char * def, int num) { 1974 char buf[64]; 2094 1975 sprintf(buf, "#define\t %s 0x%x\n", def, num); 2095 1976 file_write(fdout, buf); 2096 1977 } 2097 1978 1979 2098 1980 /////////////////////////////////////// 2099 void genHd( const char* file_path ) 2100 /////////////////////////////////////// 2101 { 1981 void genHd(const char * file_path) { 2102 1982 int fdout = open_file(file_path); 2103 1983 2104 char * prol = " /* Generated from the mapping_info file */\n\n#ifndef _HD_CONFIG_H\n#define _HD_CONFIG_H\n\n";1984 char * prol = " /* Generated from the mapping_info file */\n\n#ifndef _HD_CONFIG_H\n#define _HD_CONFIG_H\n\n"; 2105 1985 file_write(fdout, prol); 2106 1986 2107 def_int_write(fdout, "CLUSTER_X" 2108 def_int_write(fdout, "CLUSTER_Y" 2109 def_int_write(fdout, "NB_CLUSTERS" 2110 def_hex_write(fdout, "CLUSTER_SIZE" 2111 def_int_write(fdout, "NB_PROCS_MAX" 2112 def_int_write(fdout, "NB_TIMERS_MAX" 2113 def_int_write(fdout, "NB_DMAS_MAX" 2114 def_int_write(fdout, "NB_TTYS" 2115 def_int_write(fdout, "NB_IOCS" 2116 def_int_write(fdout, "NB_NICS" 2117 1987 def_int_write(fdout, "CLUSTER_X" , cluster_x); 1988 def_int_write(fdout, "CLUSTER_Y" , cluster_y); 1989 def_int_write(fdout, "NB_CLUSTERS" , cluster_index); 1990 def_hex_write(fdout, "CLUSTER_SIZE" , (((unsigned long long) 1) << 32) / cluster_index); 1991 def_int_write(fdout, "NB_PROCS_MAX" , nb_proc_max); 1992 def_int_write(fdout, "NB_TIMERS_MAX", nb_timer_channel_max); 1993 def_int_write(fdout, "NB_DMAS_MAX" , nb_dma_channel_max); 1994 def_int_write(fdout, "NB_TTYS" , nb_tty_channel); 1995 def_int_write(fdout, "NB_IOCS" , nb_ioc_channel); 1996 def_int_write(fdout, "NB_NICS" , nb_nic_channel); 1997 2118 1998 file_write(fdout, "\n"); 2119 def_int_write(fdout, "USE_XICU" 2120 def_int_write(fdout, "IOMMU_ACTIVE " 2121 2122 char * epil = "\n#endif //_HD_CONFIG_H";1999 def_int_write(fdout, "USE_XICU" , use_xicu); 2000 def_int_write(fdout, "IOMMU_ACTIVE ", io_mmu_active); 2001 2002 char * epil = "\n#endif //_HD_CONFIG_H"; 2123 2003 file_write(fdout, epil); 2124 2004 … … 2126 2006 } 2127 2007 2008 2128 2009 //////////////////////////////////////////////////////// 2129 void ld_write(int fdout, char* seg, unsigned int addr) 2130 { 2131 char buf[64]; 2010 void ld_write(int fdout, char * seg, unsigned int addr) { 2011 char buf[64]; 2132 2012 sprintf(buf, "%s = 0x%x;\n", seg, addr); 2133 2013 file_write(fdout, buf); … … 2135 2015 } 2136 2016 2017 2137 2018 /////////////////////////////////////// 2138 void genLd (const char * file_path) 2139 /////////////////////////////////////// 2140 { 2019 void genLd(const char * file_path) { 2141 2020 int fdout = open_file(file_path); 2142 2021 2143 char * prol = "/* Generated from the mapping_info file */\n\n";2022 char * prol = "/* Generated from the mapping_info file */\n\n"; 2144 2023 file_write(fdout, prol); 2145 2024 2146 2025 //boot 2147 ld_write(fdout, "seg_boot_code_base" 2148 ld_write(fdout, "seg_boot_stack_base" 2149 ld_write(fdout, "seg_mapping_base" 2026 ld_write(fdout, "seg_boot_code_base", boot_code_base); 2027 ld_write(fdout, "seg_boot_stack_base", boot_stack_base); 2028 ld_write(fdout, "seg_mapping_base", boot_mapping_base); 2150 2029 2151 2030 //kernel 2152 ld_write(fdout, "\nseg_kernel_code_base" ,kernel_code_base);2153 ld_write(fdout, "seg_kernel_data_base" ,kernel_data_base);2154 ld_write(fdout, "seg_kernel_uncdata_base" 2155 ld_write(fdout, "seg_kernel_init_base" ,kernel_init_base);2031 ld_write(fdout, "\nseg_kernel_code_base", kernel_code_base); 2032 ld_write(fdout, "seg_kernel_data_base", kernel_data_base); 2033 ld_write(fdout, "seg_kernel_uncdata_base", kernel_uncdata_base); 2034 ld_write(fdout, "seg_kernel_init_base", kernel_init_base); 2156 2035 2157 2036 //peripherals 2158 ld_write(fdout, "\nseg_fbf_base", 2159 ld_write(fdout, "seg_icu_base" ,icu_base_offset);2160 ld_write(fdout, "seg_ioc_base" ,ioc_base_offset);2161 ld_write(fdout, "seg_nic_base" ,nic_base_offset);2162 ld_write(fdout, "seg_tty_base" ,tty_base_offset);2163 ld_write(fdout, "seg_dma_base" ,dma_base_offset);2164 ld_write(fdout, "seg_tim_base" ,tim_base_offset);2165 ld_write(fdout, "seg_gcd_base" ,gcd_base_offset);2166 ld_write(fdout, "seg_iob_base" ,iob_base_offset);2037 ld_write(fdout, "\nseg_fbf_base", fbf_base_offset); 2038 ld_write(fdout, "seg_icu_base", icu_base_offset); 2039 ld_write(fdout, "seg_ioc_base", ioc_base_offset); 2040 ld_write(fdout, "seg_nic_base", nic_base_offset); 2041 ld_write(fdout, "seg_tty_base", tty_base_offset); 2042 ld_write(fdout, "seg_dma_base", dma_base_offset); 2043 ld_write(fdout, "seg_tim_base", tim_base_offset); 2044 ld_write(fdout, "seg_gcd_base", gcd_base_offset); 2045 ld_write(fdout, "seg_iob_base", iob_base_offset); 2167 2046 2168 2047 close(fdout); 2169 2048 } 2170 2049 2171 char * buildPath(const char * path, const char * name) 2172 {2050 2051 char * buildPath(const char * path, const char * name) { 2173 2052 char * res = calloc(strlen(path) + strlen(name) + 1, 1); 2174 2053 strcat(res, path); … … 2178 2057 } 2179 2058 2059 2180 2060 ///////////////////////////////////// 2181 int main(int argc, char * argv[]) 2182 ///////////////////////////////////// 2183 { 2184 if ( argc < 3 ) 2185 { 2061 int main(int argc, char * argv[]) { 2062 if (argc < 3) { 2186 2063 printf("Usage: xml2bin <input_file_path> <output_path>\n"); 2187 2064 return 1; … … 2189 2066 2190 2067 struct stat dir_st; 2191 if(stat( argv[2], &dir_st )) 2192 { 2068 if (stat( argv[2], &dir_st)) { 2193 2069 perror("bad path"); 2194 2070 exit(1); 2195 2071 } 2196 2072 2197 if((dir_st.st_mode & S_IFDIR) == 0) 2198 { 2073 if ((dir_st.st_mode & S_IFDIR) == 0) { 2199 2074 printf("path is not a dir: %s", argv[2] ); 2200 2075 exit(1); 2201 2076 } 2202 2077 2203 2204 char * map_path = buildPath(argv[2], "map.bin");2205 char * ld_path = buildPath(argv[2],"giet_vsegs.ld");2206 char * hd_path = buildPath(argv[2],"hard_config.h");2078 2079 char * map_path = buildPath(argv[2], "map.bin"); 2080 char * ld_path = buildPath(argv[2], "giet_vsegs.ld"); 2081 char * hd_path = buildPath(argv[2], "hard_config.h"); 2207 2082 2208 2083 LIBXML_TEST_VERSION; 2209 2084 2210 2085 int status; 2211 xmlTextReaderPtr reader = xmlReaderForFile ( argv[1], NULL, 0 ); 2212 2213 if ( reader != NULL ) 2214 { 2215 status = xmlTextReaderRead ( reader ); 2216 while ( status == 1 ) 2217 { 2218 const char* tag = (const char*)xmlTextReaderConstName(reader); 2219 2220 if ( strcmp(tag,"mapping_info") == 0 ) 2221 { 2222 headerNode( reader ); 2086 xmlTextReaderPtr reader = xmlReaderForFile(argv[1], NULL, 0); 2087 2088 if (reader != NULL) { 2089 status = xmlTextReaderRead (reader); 2090 while (status == 1) { 2091 const char * tag = (const char *) xmlTextReaderConstName(reader); 2092 2093 if (strcmp(tag, "mapping_info") == 0) { 2094 headerNode(reader); 2223 2095 prepareBuild(); 2224 buildBin( map_path);2096 buildBin(map_path); 2225 2097 genHd(hd_path); 2226 2098 genLd(ld_path); 2227 2099 } 2228 else 2229 { 2100 else { 2230 2101 printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); 2231 2102 return 1; 2232 2103 } 2233 status = xmlTextReaderRead ( reader ); 2234 } 2235 xmlFreeTextReader ( reader ); 2236 2237 if ( status != 0 ) 2238 { 2104 status = xmlTextReaderRead(reader); 2105 } 2106 xmlFreeTextReader(reader); 2107 2108 if (status != 0) { 2239 2109 printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); 2240 2110 return 1; … … 2245 2115 2246 2116 2247 2248 2117 // Local Variables: 2118 // tab-width: 4 2119 // c-basic-offset: 4 2120 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 2121 // indent-tabs-mode: nil 2122 // End: 2123 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 2124
Note: See TracChangeset
for help on using the changeset viewer.