Changeset 345 for soft/giet_vm/giet_libs
- Timestamp:
- Jun 25, 2014, 2:19:37 PM (11 years ago)
- Location:
- soft/giet_vm/giet_libs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/barrier.c
r295 r345 20 20 unsigned int value ) 21 21 { 22 barrier->init = value; 23 barrier->count = value; 22 barrier->init = (volatile unsigned int)value; 23 barrier->count = (volatile unsigned int)value; 24 asm volatile ("sync" ::: "memory"); 24 25 } 25 26 … … 31 32 void barrier_wait( giet_barrier_t* barrier ) 32 33 { 33 unsigned int * pcount= (unsigned int *) &barrier->count;34 unsigned int maxcount = barrier->init;35 unsigned int count;34 volatile unsigned int * pcount = (unsigned int *) &barrier->count; 35 volatile unsigned int maxcount = barrier->init; 36 volatile unsigned int count; 36 37 37 38 // parallel decrement barrier counter using atomic instructions LL/SC 38 39 // - input : pointer on the barrier counter 39 40 // - output : counter value 40 asm volatile ("_barrier_decrement: \n" 41 "ll %0, 0(%1) \n" 42 "addi $3, %0, -1 \n" 43 "sc $3, 0(%1) \n" 44 "beqz $3, _barrier_decrement \n" 45 : "=&r"(count) 41 asm volatile ( 42 "_barrier_decrement: \n" 43 "ll %0, 0(%1) \n" 44 "addi $3, %0, -1 \n" 45 "sc $3, 0(%1) \n" 46 "beqz $3, _barrier_decrement \n" 47 : "+r"(count) 46 48 : "r"(pcount) 47 : "$ 2", "$3");49 : "$3", "memory"); 48 50 49 51 // the last task re-initializes the barrier counter to the max value, … … 57 59 else { 58 60 // other tasks busy-wait 59 while (*pcount != maxcount) asm volatile ("nop");61 while (*pcount != maxcount); 60 62 } 63 64 asm volatile ("sync" ::: "memory"); 61 65 } 62 66 -
soft/giet_vm/giet_libs/mwmr_channel.c
r258 r345 43 43 register unsigned int delay = 100; 44 44 asm volatile ( 45 " mwmr_lock_try:\n"45 "1: \n" 46 46 "ll $2, 0(%0) \n" /* $2 <= lock current value */ 47 "bnez $2, mwmr_lock_delay\n" /* retry after delay if lock busy */47 "bnez $2, 2f \n" /* retry after delay if lock busy */ 48 48 "li $3, 1 \n" /* $3 <= argument for sc */ 49 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"52 "move $4, %1 \n" /* $4 <= delay */53 " mwmr_lock_loop:\n"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"50 "bnez $3, 3f \n" /* exit if atomic */ 51 "2: \n" 52 "move $4, %1 \n" /* $4 <= delay */ 53 "4: \n" 54 "beqz $4, 4b \n" /* test end delay */ 55 "addi $4, $4, -1 \n" /* $4 <= $4 - 1 */ 56 "j 1b \n" /* retry ll */ 57 "nop \n" 58 "3: \n" 59 59 : 60 60 :"r"(plock), "r"(delay) -
soft/giet_vm/giet_libs/stdio.c
r331 r345 23 23 24 24 //////////////////////////////////////// 25 void giet_tty_printf( char* format, ...) 26 { 27 va_list args; 28 va_start( args, format ); 29 30 int ret; // return value from the syscalls 31 unsigned int channel = 0xFFFFFFFF; // channel defined in task context 25 static int __printf( char* format, unsigned int channel, va_list* args) 26 { 27 int ret; // return value from the syscalls 32 28 33 29 printf_text: … … 56 52 } 57 53 58 va_end( args ); 59 return; 54 return 0; 60 55 61 56 printf_arguments: … … 72 67 case ('c'): /* char conversion */ 73 68 { 74 int val = va_arg( args, int );69 int val = va_arg( *args, int ); 75 70 len = 1; 76 71 buf[0] = val; … … 80 75 case ('d'): /* 32 bits decimal signed integer */ 81 76 { 82 int val = va_arg( args, int );77 int val = va_arg( *args, int ); 83 78 if (val < 0) 84 79 { … … 102 97 case ('u'): /* 32 bits decimal unsigned integer */ 103 98 { 104 unsigned int val = va_arg( args, unsigned int );99 unsigned int val = va_arg( *args, unsigned int ); 105 100 for(i = 0; i < 10; i++) 106 101 { … … 114 109 case ('x'): /* 32 bits hexadecimal integer */ 115 110 { 116 unsigned int val = va_arg( args, unsigned int );111 unsigned int val = va_arg( *args, unsigned int ); 117 112 ret = sys_call(SYSCALL_TTY_WRITE, 118 113 (unsigned int)"0x", … … 132 127 case ('l'): /* 64 bits hexadecimal unsigned */ 133 128 { 134 unsigned long long val = va_arg( args, unsigned long long );129 unsigned long long val = va_arg( *args, unsigned long long ); 135 130 ret = sys_call(SYSCALL_TTY_WRITE, 136 131 (unsigned int)"0x", … … 150 145 case ('s'): /* string */ 151 146 { 152 char* str = va_arg( args, char* );147 char* str = va_arg( *args, char* ); 153 148 while (str[len]) 154 149 { … … 173 168 174 169 return_error: 175 170 return 1; 171 } // end __printf() 172 173 174 //////////////////////////////////////// 175 void giet_tty_printf( char* format, ...) 176 { 177 va_list args; 178 179 va_start( args, format ); 180 int ret = __printf(format, 0xFFFFFFFF, &args); 176 181 va_end( args ); 177 giet_exit("error in giet_tty_printf()"); 182 183 if (ret) 184 { 185 giet_exit("error in giet_tty_printf()"); 186 } 178 187 } // end giet_tty_printf() 179 188 … … 182 191 { 183 192 va_list args; 184 va_start( args, format ); 185 186 int ret; // return value from the syscalls 187 unsigned int channel = 0; 188 unsigned int sr_save; 193 const int channel = 0; 194 volatile unsigned int sr_save; 189 195 190 196 sys_call( SYSCALL_TTY_GET_LOCK, … … 193 199 0, 0 ); 194 200 195 printf_text: 196 197 while (*format) 198 { 199 unsigned int i; 200 for (i = 0 ; format[i] && (format[i] != '%') ; i++); 201 if (i) 202 { 203 ret = sys_call(SYSCALL_TTY_WRITE, 204 (unsigned int)format, 205 i, 206 channel, 207 0); 208 209 if (ret != i) goto return_error; 210 211 format += i; 212 } 213 if (*format == '%') 214 { 215 format++; 216 goto printf_arguments; 217 } 218 } 201 va_start( args, format ); 202 int ret = __printf(format, channel, &args); 203 va_end( args ); 219 204 220 205 sys_call( SYSCALL_TTY_RELEASE_LOCK, … … 222 207 (unsigned int)&sr_save, 223 208 0, 0 ); 224 225 va_end( args ); 226 return; 227 228 printf_arguments: 229 230 { 231 char buf[20]; 232 char * pbuf; 233 unsigned int len = 0; 234 static const char HexaTab[] = "0123456789ABCDEF"; 235 unsigned int i; 236 237 switch (*format++) 238 { 239 case ('c'): /* char conversion */ 240 { 241 int val = va_arg( args, int ); 242 len = 1; 243 buf[0] = val; 244 pbuf = &buf[0]; 245 break; 246 } 247 case ('d'): /* 32 bits decimal signed integer */ 248 { 249 int val = va_arg( args, int ); 250 if (val < 0) 251 { 252 val = -val; 253 ret = sys_call(SYSCALL_TTY_WRITE, 254 (unsigned int)"-", 255 1, 256 channel, 257 0); 258 if (ret != 1) goto return_error; 259 } 260 for(i = 0; i < 10; i++) 261 { 262 buf[9 - i] = HexaTab[val % 10]; 263 if (!(val /= 10)) break; 264 } 265 len = i + 1; 266 pbuf = &buf[9 - i]; 267 break; 268 } 269 case ('u'): /* 32 bits decimal unsigned integer */ 270 { 271 unsigned int val = va_arg( args, unsigned int ); 272 for(i = 0; i < 10; i++) 273 { 274 buf[9 - i] = HexaTab[val % 10]; 275 if (!(val /= 10)) break; 276 } 277 len = i + 1; 278 pbuf = &buf[9 - i]; 279 break; 280 } 281 case ('x'): /* 32 bits hexadecimal integer */ 282 { 283 unsigned int val = va_arg( args, unsigned int ); 284 ret = sys_call(SYSCALL_TTY_WRITE, 285 (unsigned int)"0x", 286 2, 287 channel, 288 0); 289 if (ret != 2) goto return_error; 290 for(i = 0; i < 8; i++) 291 { 292 buf[7 - i] = HexaTab[val % 16]; 293 if (!(val /= 16)) break; 294 } 295 len = i + 1; 296 pbuf = &buf[7 - i]; 297 break; 298 } 299 case ('l'): /* 64 bits hexadecimal unsigned */ 300 { 301 unsigned long long val = va_arg( args, unsigned long long ); 302 ret = sys_call(SYSCALL_TTY_WRITE, 303 (unsigned int)"0x", 304 2, 305 channel, 306 0); 307 if (ret != 2) goto return_error; 308 for(i = 0; i < 16; i++) 309 { 310 buf[15 - i] = HexaTab[val % 16]; 311 if (!(val /= 16)) break; 312 } 313 len = i + 1; 314 pbuf = &buf[15 - i]; 315 break; 316 } 317 case ('s'): /* string */ 318 { 319 char* str = va_arg( args, char* ); 320 while (str[len]) 321 { 322 len++; 323 } 324 pbuf = str; 325 break; 326 } 327 default: 328 goto return_error; 329 } 330 331 ret = sys_call(SYSCALL_TTY_WRITE, 332 (unsigned int)pbuf, 333 len, 334 channel, 335 0); 336 if (ret != len) goto return_error; 337 338 goto printf_text; 339 } 340 341 return_error: 342 343 sys_call( SYSCALL_TTY_RELEASE_LOCK, 344 channel, 345 (unsigned int)&sr_save, 346 0, 0 ); 347 348 va_end( args ); 349 giet_exit("error in giet_shr_printf()"); 350 } // end giet_shr_printf() 351 209 210 if (ret) 211 { 212 giet_exit("error in giet_shr_printf()"); 213 } 214 } // end giet_shr_printf() 352 215 353 216 ///////////////////////////////// -
soft/giet_vm/giet_libs/stdio.h
r295 r345 72 72 asm volatile( 73 73 "syscall" 74 : "=r" (reg_no_and_output) /* output argument */ 75 : "r" (reg_a0), /* input arguments */ 76 "r" (reg_a1), 77 "r" (reg_a2), 78 "r" (reg_a3), 79 "r" (reg_no_and_output) 74 : "+r" (reg_no_and_output), /* input/output argument */ 75 "+r" (reg_a0), 76 "+r" (reg_a1), 77 "+r" (reg_a2), 78 "+r" (reg_a3), 79 "+r" (reg_no_and_output) 80 : /* input arguments */ 80 81 : "memory", 81 82 /* These persistant registers will be saved on the stack by the … … 95 96 "t9" 96 97 ); 97 return reg_no_and_output;98 return (volatile int)reg_no_and_output; 98 99 } 99 100
Note: See TracChangeset
for help on using the changeset viewer.