Changeset 709 for soft/giet_vm/giet_common
- Timestamp:
- Oct 1, 2015, 4:20:46 PM (9 years ago)
- Location:
- soft/giet_vm/giet_common
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_common/kernel_locks.c
r632 r709 70 70 : "r" (ptr), "r" (mask) 71 71 : "$10", "$11", "$12", "memory" ); 72 } 73 74 ///////////////////////////////////////////////////// 75 unsigned int _atomic_test_and_set( unsigned int* ptr, 76 unsigned int value ) 77 { 78 unsigned int ret = 1; 79 80 asm volatile ( 81 "ori %0, $0, 1 \n" /* default : ret <= 1 */ 82 "move $10, %1 \n" /* $10 <= ptr */ 83 "move $11, %2 \n" /* $11 <= value */ 84 "ll $12, 0($10) \n" /* $12 <= *ptr */ 85 "bne $12, $0, 1515f \n" /* return 1 if non zero */ 86 "sc $11, 0($10) \n" /* *ptr <= $12 */ 87 "beqz $11, 1515f \n" /* return 1 if failure */ 88 "ori %0, $0, 0 \n" /* success : ret <= 0 */ 89 "1515: \n" 90 : "=r" (ret) 91 : "r" (ptr), "r" (value) 92 : "$10", "$11", "$12", "memory" ); 93 94 return ret; 72 95 } 73 96 -
soft/giet_vm/giet_common/kernel_locks.h
r632 r709 20 20 21 21 extern unsigned int _atomic_increment( unsigned int* ptr, 22 int increment );22 int increment ); 23 23 24 24 extern void _atomic_or( unsigned int* ptr, … … 27 27 extern void _atomic_and( unsigned int* ptr, 28 28 unsigned int mask ); 29 30 extern unsigned int _atomic_test_and_set( unsigned int* ptr, 31 unsigned int value ); 29 32 30 33 ////////////////////////////////////////////////////////////////////////////// -
soft/giet_vm/giet_common/mips32_registers.h
r399 r709 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 -
soft/giet_vm/giet_common/tty0.c
r594 r709 12 12 #include <stdarg.h> 13 13 #include <tty_driver.h> 14 #include <ctx_handler.h> 14 15 #include <utils.h> 15 16 #include <kernel_locks.h> … … 30 31 spin_lock_t _tty0_spin_lock __attribute__((aligned(64))); 31 32 32 ////////////////////////////////////////////// 33 unsigned int _tty0_write( char* buffer, 34 unsigned int nbytes ) 33 ///////////////////////////////////////////////////// 34 unsigned int _tty_channel_write( unsigned int channel, 35 char* buffer, 36 unsigned int nbytes ) 35 37 { 36 38 unsigned int n; … … 40 42 { 41 43 // test TTY_TX buffer full 42 if ( (_tty_get_register( 0, TTY_STATUS ) & 0x2) ) // buffer full44 if ( (_tty_get_register( channel , TTY_STATUS ) & 0x2) ) // buffer full 43 45 { 44 46 // retry if full 45 47 for( k = 0 ; k < 10000 ; k++ ) 46 48 { 47 if ( (_tty_get_register( 0, TTY_STATUS ) & 0x2) == 0) break;49 if ( (_tty_get_register( channel , TTY_STATUS ) & 0x2) == 0) break; 48 50 } 49 51 // return error if full after 10000 retry … … 52 54 53 55 // write one byte 54 if (buffer[n] == '\n') _tty_set_register( 0, TTY_WRITE, (unsigned int)'\r' );55 _tty_set_register( 0, TTY_WRITE, (unsigned int)buffer[n] );56 if (buffer[n] == '\n') _tty_set_register( channel, TTY_WRITE, (unsigned int)'\r' ); 57 _tty_set_register( channel, TTY_WRITE, (unsigned int)buffer[n] ); 56 58 } 57 59 return 0; … … 65 67 while ( string[n] > 0 ) n++; 66 68 67 _tty 0_write(string, n );69 _tty_channel_write( 0, string, n ); 68 70 } 69 71 … … 84 86 val = val >> 4; 85 87 } 86 _tty 0_write(buf, 10 );88 _tty_channel_write( 0, buf, 10 ); 87 89 } 88 90 … … 102 104 val = val >> 4; 103 105 } 104 _tty 0_write(buf, 18 );106 _tty_channel_write( 0, buf, 18 ); 105 107 } 106 108 … … 126 128 val /= 10; 127 129 } 128 _tty 0_write(&buf[first], 10 - first );130 _tty_channel_write( 0, &buf[first], 10 - first ); 129 131 } 130 132 … … 140 142 141 143 ////////////////////////////////////////////////////////// 142 static void _kernel_printf( char * format, va_list* args ) 144 static void _kernel_printf( unsigned int channel, 145 char * format, 146 va_list* args ) 143 147 { 144 148 … … 151 155 if (i) 152 156 { 153 if ( _tty 0_write(format, i ) ) goto return_error;157 if ( _tty_channel_write( channel, format, i ) ) goto return_error; 154 158 format += i; 155 159 } … … 188 192 { 189 193 val = -val; 190 if ( _tty 0_write("-" , 1 ) ) goto return_error;194 if ( _tty_channel_write( channel, "-" , 1 ) ) goto return_error; 191 195 } 192 196 for(i = 0; i < 10; i++) … … 214 218 { 215 219 unsigned int val = va_arg( *args , unsigned int ); 216 if ( _tty 0_write("0x" , 2 ) ) goto return_error;220 if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error; 217 221 for(i = 0; i < 8; i++) 218 222 { … … 227 231 { 228 232 unsigned int val = va_arg( *args , unsigned int ); 229 if ( _tty 0_write("0x" , 2 ) ) goto return_error;233 if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error; 230 234 for(i = 0; i < 8; i++) 231 235 { … … 240 244 { 241 245 unsigned long long val = va_arg( *args , unsigned long long ); 242 if ( _tty 0_write("0x" , 2 ) ) goto return_error;246 if ( _tty_channel_write( channel, "0x" , 2 ) ) goto return_error; 243 247 for(i = 0; i < 16; i++) 244 248 { … … 264 268 } 265 269 266 if ( _tty 0_write(pbuf, len ) ) goto return_error;270 if ( _tty_channel_write( channel, pbuf, len ) ) goto return_error; 267 271 268 272 goto printf_text; … … 284 288 _putd( lpid ); 285 289 _puts("]\n"); 286 287 290 _exit(); 288 291 } … … 294 297 va_list args; 295 298 299 // call kernel_printf 296 300 va_start( args , format ); 297 _kernel_printf( format , &args );301 _kernel_printf( 0, format , &args ); 298 302 va_end( args ); 299 303 } 304 300 305 //////////////////////////////// 301 306 void _printf( char* format, ...) … … 309 314 else _sqt_lock_acquire( &_tty0_sqt_lock ); 310 315 316 // call kernel_printf 311 317 va_start( args , format ); 312 _kernel_printf( format , &args );318 _kernel_printf( 0, format , &args ); 313 319 va_end( args ); 314 320 … … 318 324 _it_restore( &save_sr ); 319 325 } 326 327 ///////////////////////////////////// 328 void _user_printf( char* format, ...) 329 { 330 va_list args; 331 332 // get calling thread TYY channel 333 unsigned int channel = _get_context_slot( CTX_TTY_ID ); 334 if( channel >= NB_TTY_CHANNELS ) 335 { 336 _puts("\n[GIET ERROR] in _user_printf() : no TTY allocated for thread "); 337 _putx( _get_thread_trdid() ); 338 _puts("\n"); 339 _exit(); 340 } 341 342 // call kernel_printf 343 va_start( args , format ); 344 _kernel_printf( channel, format , &args ); 345 va_end( args ); 346 } 347 320 348 321 349 -
soft/giet_vm/giet_common/tty0.h
r466 r709 14 14 15 15 /////////////////////////////////////////////////////////////////////////////////// 16 // Access functions to kernel terminal TTY0 16 // Access functions to kernel terminal TTY0 (or calling thread TTY) 17 17 /////////////////////////////////////////////////////////////////////////////////// 18 18 … … 27 27 extern void _getc( char* byte ); 28 28 29 extern void _printf( char* format, ... ); 30 29 31 extern void _nolock_printf( char* format, ... ); 30 32 31 extern void _ printf( char* format, ... );33 extern void _user_printf( char* format, ... ); 32 34 33 35 #endif -
soft/giet_vm/giet_common/utils.c
r618 r709 16 16 #include <ctx_handler.h> 17 17 18 // This variable is allocated in theboot.c file or in kernel_init.c file19 extern static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX];18 // This variable is allocated in boot.c file or in kernel_init.c file 19 extern static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX]; 20 20 21 21 /////////////////////////////////////////////////////////////////////////// … … 23 23 /////////////////////////////////////////////////////////////////////////// 24 24 25 ///////////////////////// 26 unsigned int_get_sched()25 //////////////////////////////// 26 static_scheduler_t* _get_sched() 27 27 { 28 28 unsigned int ret; 29 29 asm volatile( "mfc0 %0, $4,2 \n" 30 30 : "=r"(ret) ); 31 return ret; 31 32 return (static_scheduler_t*)ret; 32 33 } 33 34 /////////////////////// … … 411 412 412 413 //////////////////////////////////////////////////////////////////////////// 413 // Scheduler and t asks context access functions414 // Scheduler and threads context access functions 414 415 //////////////////////////////////////////////////////////////////////////// 415 416 416 417 417 /////////////////////////////////// 418 unsigned int _get_current_task_id() 419 { 420 static_scheduler_t * psched = (static_scheduler_t *) _get_sched(); 421 return (unsigned int) (psched->current); 418 /////////////////////////////// 419 unsigned int _get_thread_ltid() 420 { 421 static_scheduler_t* psched = (static_scheduler_t *) _get_sched(); 422 return psched->current; 423 } 424 425 //////////////////////////////// 426 unsigned int _get_thread_trdid() 427 { 428 static_scheduler_t* psched = (static_scheduler_t *) _get_sched(); 429 unsigned int current = psched->current; 430 return psched->context[current].slot[CTX_TRDID_ID]; 431 } 432 433 ////////////////////////////////////////////// 434 unsigned int _get_thread_slot( unsigned int x, 435 unsigned int y, 436 unsigned int p, 437 unsigned int ltid, 438 unsigned int slotid ) 439 { 440 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 441 return psched->context[ltid].slot[slotid]; 442 } 443 444 ////////////////////////////////////// 445 void _set_thread_slot( unsigned int x, 446 unsigned int y, 447 unsigned int p, 448 unsigned int ltid, 449 unsigned int slotid, 450 unsigned int value ) 451 { 452 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 453 psched->context[ltid].slot[slotid] = value; 454 } 455 456 ///////////////////////////////////////////////////// 457 unsigned int _get_context_slot( unsigned int slotid ) 458 { 459 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 460 unsigned int ltid = psched->current; 461 return psched->context[ltid].slot[slotid]; 422 462 } 423 463 424 464 //////////////////////////////////////////// 425 unsigned int _get_task_slot( unsigned int x, 426 unsigned int y, 427 unsigned int p, 428 unsigned int ltid, 429 unsigned int slot ) 430 { 431 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 432 return psched->context[ltid][slot]; 433 } 434 435 //////////////////////////////////// 436 void _set_task_slot( unsigned int x, 437 unsigned int y, 438 unsigned int p, 439 unsigned int ltid, 440 unsigned int slot, 441 unsigned int value ) 442 { 443 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 444 psched->context[ltid][slot] = value; 445 } 446 447 /////////////////////////////////////////////////// 448 unsigned int _get_context_slot( unsigned int slot ) 465 void _set_context_slot( unsigned int slotid, 466 unsigned int value ) 449 467 { 450 468 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 451 unsigned int task_id = psched->current; 452 return psched->context[task_id][slot]; 453 } 454 455 /////////////////////////////////////////// 456 void _set_context_slot( unsigned int slot, 457 unsigned int value ) 458 { 459 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 460 unsigned int task_id = psched->current; 461 psched->context[task_id][slot] = value; 469 unsigned int ltid = psched->current; 470 psched->context[ltid].slot[slotid] = value; 462 471 } 463 472 … … 496 505 MAPPING_VSPACE_SIZE * header->vspaces); 497 506 } 498 ////////////////////////////////////////////////////////// 499 mapping_t ask_t * _get_task_base(mapping_header_t * header)500 { 501 return (mapping_t ask_t *) ((char *) header +507 ////////////////////////////////////////////////////////////// 508 mapping_thread_t * _get_thread_base(mapping_header_t * header) 509 { 510 return (mapping_thread_t *) ((char *) header + 502 511 MAPPING_HEADER_SIZE + 503 512 MAPPING_CLUSTER_SIZE * X_SIZE * Y_SIZE + … … 515 524 MAPPING_VSPACE_SIZE * header->vspaces + 516 525 MAPPING_VSEG_SIZE * header->vsegs + 517 MAPPING_T ASK_SIZE * header->tasks);526 MAPPING_THREAD_SIZE * header->threads); 518 527 } 519 528 /////////////////////////////////////////////////////// … … 526 535 MAPPING_VSPACE_SIZE * header->vspaces + 527 536 MAPPING_VSEG_SIZE * header->vsegs + 528 MAPPING_T ASK_SIZE * header->tasks +537 MAPPING_THREAD_SIZE * header->threads + 529 538 MAPPING_PROC_SIZE * header->procs); 530 539 } … … 538 547 MAPPING_VSPACE_SIZE * header->vspaces + 539 548 MAPPING_VSEG_SIZE * header->vsegs + 540 MAPPING_T ASK_SIZE * header->tasks +549 MAPPING_THREAD_SIZE * header->threads + 541 550 MAPPING_PROC_SIZE * header->procs + 542 551 MAPPING_IRQ_SIZE * header->irqs); -
soft/giet_vm/giet_common/utils.h
r618 r709 14 14 15 15 #include <mapping_info.h> 16 #include <ctx_handler.h> 16 17 17 18 ////////////////////////////////////////////////////////////////////////////////// … … 41 42 /////////////////////////////////////////////////////////////////////////// 42 43 43 extern unsigned int_get_sched(void);44 extern static_scheduler_t* _get_sched(void); 44 45 45 46 extern unsigned int _get_epc(void); … … 105 106 106 107 /////////////////////////////////////////////////////////////////////////// 107 // Scheduler and t askcontext access functions108 // Scheduler and thread context access functions 108 109 /////////////////////////////////////////////////////////////////////////// 109 110 110 extern unsigned int _get_ current_task_id(void);111 extern unsigned int _get_thread_ltid(void); 111 112 112 extern unsigned int _get_task_slot( unsigned int x, 113 unsigned int y, 114 unsigned int p, 115 unsigned int ltid, 116 unsigned int slot ); 113 extern unsigned int _get_thread_trdid(void); 117 114 118 extern void _set_task_slot( unsigned int x, 119 unsigned int y, 120 unsigned int p, 121 unsigned int ltid, 122 unsigned int slot, 123 unsigned int value ); 115 extern unsigned int _get_thread_slot( unsigned int x, 116 unsigned int y, 117 unsigned int p, 118 unsigned int ltid, 119 unsigned int slot ); 120 121 extern void _set_thread_slot( unsigned int x, 122 unsigned int y, 123 unsigned int p, 124 unsigned int ltid, 125 unsigned int slot, 126 unsigned int value ); 124 127 125 128 extern unsigned int _get_context_slot( unsigned int slot ); … … 136 139 extern mapping_vspace_t * _get_vspace_base(mapping_header_t* header); 137 140 extern mapping_vseg_t * _get_vseg_base(mapping_header_t* header); 138 extern mapping_t ask_t * _get_task_base(mapping_header_t* header);141 extern mapping_thread_t * _get_thread_base(mapping_header_t* header); 139 142 extern mapping_proc_t * _get_proc_base(mapping_header_t* header); 140 143 extern mapping_irq_t * _get_irq_base(mapping_header_t* header);
Note: See TracChangeset
for help on using the changeset viewer.