| 1 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // File : stdio.c |
|---|
| 3 | // Date : 01/04/2010 |
|---|
| 4 | // Author : alain greiner & Joel Porquet |
|---|
| 5 | // Copyright (c) UPMC-LIP6 |
|---|
| 6 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 7 | |
|---|
| 8 | #include <stdarg.h> |
|---|
| 9 | #include <stdio.h> |
|---|
| 10 | #include <giet_config.h> |
|---|
| 11 | |
|---|
| 12 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 13 | // MIPS32 related system calls |
|---|
| 14 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 15 | |
|---|
| 16 | //////////////////////////////////////////// |
|---|
| 17 | void giet_proc_xyp( unsigned int* cluster_x, |
|---|
| 18 | unsigned int* cluster_y, |
|---|
| 19 | unsigned int* lpid ) |
|---|
| 20 | { |
|---|
| 21 | sys_call( SYSCALL_PROC_XYP, |
|---|
| 22 | (unsigned int)cluster_x, |
|---|
| 23 | (unsigned int)cluster_y, |
|---|
| 24 | (unsigned int)lpid, |
|---|
| 25 | 0 ); |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | //////////////////////////// |
|---|
| 29 | unsigned int giet_proctime() |
|---|
| 30 | { |
|---|
| 31 | return (unsigned int)sys_call( SYSCALL_PROC_TIME, |
|---|
| 32 | 0, 0, 0, 0 ); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | //////////////////////// |
|---|
| 36 | unsigned int giet_rand() |
|---|
| 37 | { |
|---|
| 38 | unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME, |
|---|
| 39 | 0, 0, 0, 0); |
|---|
| 40 | if ((x & 0xF) > 7) |
|---|
| 41 | { |
|---|
| 42 | return (x*x & 0xFFFF); |
|---|
| 43 | } |
|---|
| 44 | else |
|---|
| 45 | { |
|---|
| 46 | return (x*x*x & 0xFFFF); |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 51 | // Threads related system calls |
|---|
| 52 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 53 | |
|---|
| 54 | #define THREAD_CMD_PAUSE 0 |
|---|
| 55 | #define THREAD_CMD_RESUME 1 |
|---|
| 56 | #define THREAD_CMD_CONTEXT 2 |
|---|
| 57 | |
|---|
| 58 | ////////////////////////////////////////////////////////// |
|---|
| 59 | int giet_pthread_create( pthread_t* buffer, |
|---|
| 60 | pthread_attr_t* attr, |
|---|
| 61 | void* function, |
|---|
| 62 | void* arg ) |
|---|
| 63 | { |
|---|
| 64 | return sys_call( SYSCALL_PTHREAD_CREATE, |
|---|
| 65 | (unsigned int)buffer, |
|---|
| 66 | (unsigned int)attr, |
|---|
| 67 | (unsigned int)function, |
|---|
| 68 | (unsigned int)arg ); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | ////////////////////////////////////// |
|---|
| 72 | void giet_pthread_exit( void* string ) |
|---|
| 73 | { |
|---|
| 74 | sys_call( SYSCALL_PTHREAD_EXIT, |
|---|
| 75 | (unsigned int)string, |
|---|
| 76 | 0, 0, 0 ); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | //////////////////////////////////////// |
|---|
| 80 | int giet_pthread_join( pthread_t trdid, |
|---|
| 81 | void** ptr ) |
|---|
| 82 | { |
|---|
| 83 | return sys_call( SYSCALL_PTHREAD_JOIN, |
|---|
| 84 | trdid, |
|---|
| 85 | (unsigned int)ptr, |
|---|
| 86 | 0, 0 ); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | /////////////////////////////////////// |
|---|
| 90 | int giet_pthread_kill( pthread_t trdid, |
|---|
| 91 | int signal ) |
|---|
| 92 | { |
|---|
| 93 | return sys_call( SYSCALL_PTHREAD_KILL, |
|---|
| 94 | trdid, |
|---|
| 95 | signal, |
|---|
| 96 | 0, 0 ); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | ///////////////////////// |
|---|
| 100 | void giet_pthread_yield() |
|---|
| 101 | { |
|---|
| 102 | sys_call( SYSCALL_PTHREAD_YIELD, |
|---|
| 103 | 0, 0, 0, 0 ); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | ///////////////////////////////////////////////// |
|---|
| 107 | void giet_pthread_assert( unsigned int condition, |
|---|
| 108 | char* string ) |
|---|
| 109 | { |
|---|
| 110 | if ( condition == 0 ) giet_pthread_exit( string ); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | //////////////////////////////////////////////// |
|---|
| 114 | void giet_pthread_control( unsigned int command, |
|---|
| 115 | char* vspace_name, |
|---|
| 116 | char* thread_name ) |
|---|
| 117 | { |
|---|
| 118 | int ret = sys_call( SYSCALL_PTHREAD_CONTROL, |
|---|
| 119 | command, |
|---|
| 120 | (unsigned int) vspace_name, |
|---|
| 121 | (unsigned int) thread_name, |
|---|
| 122 | 0 ); |
|---|
| 123 | |
|---|
| 124 | if ( ret == SYSCALL_VSPACE_NOT_FOUND ) |
|---|
| 125 | { |
|---|
| 126 | giet_tty_printf(" ERROR in PTHREAD_CONTROL : " |
|---|
| 127 | "vspace %s not found\n", vspace_name ); |
|---|
| 128 | } |
|---|
| 129 | if ( ret == SYSCALL_THREAD_NOT_FOUND ) |
|---|
| 130 | { |
|---|
| 131 | giet_tty_printf(" ERROR in PTHREAD_CONTROL : " |
|---|
| 132 | "thread %s not found\n", thread_name ); |
|---|
| 133 | } |
|---|
| 134 | if ( ret == SYSCALL_UNCOHERENT_THREAD_CONTEXT ) |
|---|
| 135 | { |
|---|
| 136 | giet_tty_printf(" ERROR in PTHREAD_CONTROL : " |
|---|
| 137 | "uncoherent context for thread %s\n", thread_name ); |
|---|
| 138 | } |
|---|
| 139 | if ( ret == SYSCALL_ILLEGAL_THREAD_COMMAND_TYPE ) |
|---|
| 140 | { |
|---|
| 141 | giet_tty_printf(" ERROR in PTHREAD_CONTROL : " |
|---|
| 142 | "illegal command type %d\n", command ); |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 148 | // Applications related system calls |
|---|
| 149 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 150 | |
|---|
| 151 | /////////////////////////////////////// |
|---|
| 152 | int giet_kill_application( char* name ) |
|---|
| 153 | { |
|---|
| 154 | return ( sys_call( SYSCALL_KILL_APP, |
|---|
| 155 | (unsigned int)name, |
|---|
| 156 | 0, 0, 0 ) ); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | /////////////////////////////////////// |
|---|
| 160 | int giet_exec_application( char* name ) |
|---|
| 161 | { |
|---|
| 162 | return ( sys_call( SYSCALL_EXEC_APP, |
|---|
| 163 | (unsigned int)name, |
|---|
| 164 | 0, 0, 0 ) ); |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | /////////////////////////////////////////// |
|---|
| 168 | void giet_applications_status( char* name ) |
|---|
| 169 | { |
|---|
| 170 | sys_call( SYSCALL_APPS_STATUS, |
|---|
| 171 | (unsigned int)name, |
|---|
| 172 | 0, 0, 0 ); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 176 | // Coprocessors related system calls |
|---|
| 177 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 178 | |
|---|
| 179 | /////////////////////////////////////////////////// |
|---|
| 180 | void giet_coproc_alloc( unsigned int coproc_type, |
|---|
| 181 | unsigned int* coproc_info ) |
|---|
| 182 | { |
|---|
| 183 | if ( sys_call( SYSCALL_COPROC_ALLOC, |
|---|
| 184 | coproc_type, |
|---|
| 185 | (unsigned int)coproc_info, |
|---|
| 186 | 0, 0 ) ) |
|---|
| 187 | giet_pthread_exit("error in giet_coproc_alloc()"); |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | ///////////////////////////////////////////////////////// |
|---|
| 191 | void giet_coproc_release( unsigned int coproc_reg_index ) |
|---|
| 192 | { |
|---|
| 193 | if ( sys_call( SYSCALL_COPROC_RELEASE, |
|---|
| 194 | coproc_reg_index, |
|---|
| 195 | 0, 0, 0 ) ) |
|---|
| 196 | giet_pthread_exit("error in giet_coproc_release()"); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | ////////////////////////////////////////////////////////////////// |
|---|
| 200 | void giet_coproc_channel_init( unsigned int channel, |
|---|
| 201 | giet_coproc_channel_t* desc ) |
|---|
| 202 | { |
|---|
| 203 | if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT, |
|---|
| 204 | channel, |
|---|
| 205 | (unsigned int)desc, |
|---|
| 206 | 0, 0 ) ) |
|---|
| 207 | giet_pthread_exit("error in giet_coproc_channel_init()"); |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | ///////////////////////////////////////////////////// |
|---|
| 211 | void giet_coproc_run( unsigned int coproc_reg_index ) |
|---|
| 212 | { |
|---|
| 213 | if ( sys_call( SYSCALL_COPROC_RUN, |
|---|
| 214 | coproc_reg_index, |
|---|
| 215 | 0, 0, 0 ) ) |
|---|
| 216 | giet_pthread_exit("error in giet_coproc_run()"); |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | //////////////////////////// |
|---|
| 220 | void giet_coproc_completed() |
|---|
| 221 | { |
|---|
| 222 | if ( sys_call( SYSCALL_COPROC_COMPLETED, |
|---|
| 223 | 0, 0, 0, 0 ) ) |
|---|
| 224 | giet_pthread_exit("error in giet_coproc_completed"); |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 229 | // TTY device related system calls |
|---|
| 230 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 231 | |
|---|
| 232 | ////////////////////////////////////////// |
|---|
| 233 | void giet_tty_alloc( unsigned int shared ) |
|---|
| 234 | { |
|---|
| 235 | if ( sys_call( SYSCALL_TTY_ALLOC, |
|---|
| 236 | shared, |
|---|
| 237 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_tty_alloc()"); |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | //////////////////////////////////////////////////////////////////////// |
|---|
| 241 | static int __printf( char* format, unsigned int channel, va_list* args) |
|---|
| 242 | { |
|---|
| 243 | int ret; // return value from the syscall |
|---|
| 244 | enum TModifiers {NO_MOD, L_MOD, LL_MOD} modifiers; |
|---|
| 245 | |
|---|
| 246 | printf_text: |
|---|
| 247 | |
|---|
| 248 | while (*format) |
|---|
| 249 | { |
|---|
| 250 | unsigned int i; |
|---|
| 251 | for (i = 0 ; format[i] && (format[i] != '%') ; i++); |
|---|
| 252 | if (i) |
|---|
| 253 | { |
|---|
| 254 | ret = sys_call(SYSCALL_TTY_WRITE, |
|---|
| 255 | (unsigned int)format, |
|---|
| 256 | i, |
|---|
| 257 | channel, |
|---|
| 258 | 0); |
|---|
| 259 | |
|---|
| 260 | if (ret != i) goto return_error; |
|---|
| 261 | |
|---|
| 262 | format += i; |
|---|
| 263 | } |
|---|
| 264 | if (*format == '%') |
|---|
| 265 | { |
|---|
| 266 | format++; |
|---|
| 267 | modifiers = NO_MOD; |
|---|
| 268 | goto printf_arguments; |
|---|
| 269 | } |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | return 0; |
|---|
| 273 | |
|---|
| 274 | printf_arguments: |
|---|
| 275 | |
|---|
| 276 | { |
|---|
| 277 | char buf[30]; |
|---|
| 278 | char * pbuf; |
|---|
| 279 | unsigned int len = 0; |
|---|
| 280 | static const char HexaTab[] = "0123456789ABCDEF"; |
|---|
| 281 | unsigned int i; |
|---|
| 282 | |
|---|
| 283 | /* Ignored fields : width and precision */ |
|---|
| 284 | for (; *format >= '0' && *format <= '9'; format++); |
|---|
| 285 | |
|---|
| 286 | switch (*format++) |
|---|
| 287 | { |
|---|
| 288 | case ('%'): |
|---|
| 289 | { |
|---|
| 290 | len = 1; |
|---|
| 291 | pbuf = "%"; |
|---|
| 292 | break; |
|---|
| 293 | } |
|---|
| 294 | case ('c'): /* char conversion */ |
|---|
| 295 | { |
|---|
| 296 | int val = va_arg( *args, int ); |
|---|
| 297 | if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning |
|---|
| 298 | |
|---|
| 299 | len = 1; |
|---|
| 300 | buf[0] = val; |
|---|
| 301 | pbuf = &buf[0]; |
|---|
| 302 | break; |
|---|
| 303 | } |
|---|
| 304 | case ('d'): /* decimal signed integer */ |
|---|
| 305 | { |
|---|
| 306 | int val = va_arg( *args, int ); |
|---|
| 307 | |
|---|
| 308 | if (modifiers == LL_MOD) goto return_error; // 64 bits not supported |
|---|
| 309 | |
|---|
| 310 | if (val < 0) |
|---|
| 311 | { |
|---|
| 312 | val = -val; |
|---|
| 313 | ret = sys_call(SYSCALL_TTY_WRITE, |
|---|
| 314 | (unsigned int)"-", |
|---|
| 315 | 1, |
|---|
| 316 | channel, |
|---|
| 317 | 0); |
|---|
| 318 | if (ret != 1) goto return_error; |
|---|
| 319 | } |
|---|
| 320 | for(i = 0; i < 10; i++) |
|---|
| 321 | { |
|---|
| 322 | buf[9 - i] = HexaTab[val % 10]; |
|---|
| 323 | if (!(val /= 10)) break; |
|---|
| 324 | } |
|---|
| 325 | len = i + 1; |
|---|
| 326 | pbuf = &buf[9 - i]; |
|---|
| 327 | break; |
|---|
| 328 | } |
|---|
| 329 | case ('u'): /* decimal unsigned integer */ |
|---|
| 330 | { |
|---|
| 331 | if (modifiers != LL_MOD) //32 bits integer |
|---|
| 332 | { |
|---|
| 333 | unsigned int val = va_arg( *args, unsigned int ); |
|---|
| 334 | for(i = 0; i < 10; i++) |
|---|
| 335 | { |
|---|
| 336 | buf[9 - i] = HexaTab[val % 10]; |
|---|
| 337 | if (!(val /= 10)) break; |
|---|
| 338 | } |
|---|
| 339 | len = i + 1; |
|---|
| 340 | pbuf = &buf[9 - i]; |
|---|
| 341 | break; |
|---|
| 342 | } |
|---|
| 343 | //64 bits : base 10 unsupported : continue to hexa |
|---|
| 344 | } |
|---|
| 345 | case ('x'): |
|---|
| 346 | case ('X'): /* hexadecimal integer */ |
|---|
| 347 | { |
|---|
| 348 | unsigned long long val; |
|---|
| 349 | int imax; |
|---|
| 350 | |
|---|
| 351 | if (modifiers == LL_MOD) // 64 bits |
|---|
| 352 | { |
|---|
| 353 | val = va_arg( *args, unsigned long long); |
|---|
| 354 | |
|---|
| 355 | // if asked to print in base 10, can do only if it fits in 32 bits |
|---|
| 356 | if (*(format-1) == 'u' && (!(val & 0xFFFFFFFF00000000ULL))) |
|---|
| 357 | { |
|---|
| 358 | unsigned int uintv = (unsigned int) val; |
|---|
| 359 | |
|---|
| 360 | for(i = 0; i < 10; i++) |
|---|
| 361 | { |
|---|
| 362 | buf[9 - i] = HexaTab[uintv % 10]; |
|---|
| 363 | if (!(uintv /= 10)) break; |
|---|
| 364 | } |
|---|
| 365 | len = i + 1; |
|---|
| 366 | pbuf = &buf[9 - i]; |
|---|
| 367 | break; |
|---|
| 368 | } |
|---|
| 369 | |
|---|
| 370 | imax = 16; |
|---|
| 371 | } |
|---|
| 372 | else //32 bits |
|---|
| 373 | { |
|---|
| 374 | val = va_arg( *args, unsigned int); |
|---|
| 375 | imax = 8; |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | ret = sys_call(SYSCALL_TTY_WRITE, |
|---|
| 379 | (unsigned int)"0x", |
|---|
| 380 | 2, |
|---|
| 381 | channel, |
|---|
| 382 | 0); |
|---|
| 383 | if (ret != 2) goto return_error; |
|---|
| 384 | |
|---|
| 385 | for(i = 0; i < imax; i++) |
|---|
| 386 | { |
|---|
| 387 | buf[(imax-1) - i] = HexaTab[val % 16]; |
|---|
| 388 | if (!(val /= 16)) break; |
|---|
| 389 | } |
|---|
| 390 | len = i + 1; |
|---|
| 391 | pbuf = &buf[(imax-1) - i]; |
|---|
| 392 | break; |
|---|
| 393 | } |
|---|
| 394 | case ('s'): /* string */ |
|---|
| 395 | { |
|---|
| 396 | char* str = va_arg( *args, char* ); |
|---|
| 397 | |
|---|
| 398 | if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning |
|---|
| 399 | |
|---|
| 400 | while (str[len]) |
|---|
| 401 | { |
|---|
| 402 | len++; |
|---|
| 403 | } |
|---|
| 404 | pbuf = str; |
|---|
| 405 | break; |
|---|
| 406 | } |
|---|
| 407 | case ('e'): |
|---|
| 408 | case ('f'): |
|---|
| 409 | case ('g'): /* IEEE754 64 bits */ |
|---|
| 410 | { |
|---|
| 411 | union |
|---|
| 412 | { |
|---|
| 413 | double d; |
|---|
| 414 | unsigned long long ull; |
|---|
| 415 | } val; |
|---|
| 416 | |
|---|
| 417 | val.d = va_arg( *args, double ); |
|---|
| 418 | |
|---|
| 419 | unsigned long long digits = val.ull & 0xFFFFFFFFFFFFFULL; //get mantissa |
|---|
| 420 | |
|---|
| 421 | unsigned int |
|---|
| 422 | base = (unsigned int)((val.ull & 0x7FF0000000000000ULL) >> 52), //get exposant |
|---|
| 423 | intp = (unsigned int)val.d, //get integer part of the float |
|---|
| 424 | decp; |
|---|
| 425 | |
|---|
| 426 | int isvalue = 0; |
|---|
| 427 | |
|---|
| 428 | if (base == 0x7FF) //special value |
|---|
| 429 | { |
|---|
| 430 | if (digits & 0xFFFFFFFFFFFFFULL) |
|---|
| 431 | { |
|---|
| 432 | /* Not a Number */ |
|---|
| 433 | buf[0] = 'N'; |
|---|
| 434 | buf[1] = 'a'; |
|---|
| 435 | buf[2] = 'N'; |
|---|
| 436 | len = 3; |
|---|
| 437 | pbuf = buf; |
|---|
| 438 | } |
|---|
| 439 | else |
|---|
| 440 | { |
|---|
| 441 | /* inf */ |
|---|
| 442 | buf[0] = (val.ull & 0x8000000000000000ULL) ? '-' : '+'; |
|---|
| 443 | buf[1] = 'i'; |
|---|
| 444 | buf[2] = 'n'; |
|---|
| 445 | buf[3] = 'f'; |
|---|
| 446 | len = 4; |
|---|
| 447 | pbuf = buf; |
|---|
| 448 | } |
|---|
| 449 | break; |
|---|
| 450 | } |
|---|
| 451 | |
|---|
| 452 | if (val.ull & 0x8000000000000000ULL) |
|---|
| 453 | { |
|---|
| 454 | /* negative */ |
|---|
| 455 | ret = sys_call(SYSCALL_TTY_WRITE, |
|---|
| 456 | (unsigned int)"-", |
|---|
| 457 | 1, |
|---|
| 458 | channel, |
|---|
| 459 | 0); |
|---|
| 460 | if (ret != 1) goto return_error; |
|---|
| 461 | val.d = val.d * -1; |
|---|
| 462 | } |
|---|
| 463 | else |
|---|
| 464 | { |
|---|
| 465 | /* positive */ |
|---|
| 466 | ret = sys_call(SYSCALL_TTY_WRITE, |
|---|
| 467 | (unsigned int)"+", |
|---|
| 468 | 1, |
|---|
| 469 | channel, |
|---|
| 470 | 0); |
|---|
| 471 | if (ret != 1) goto return_error; |
|---|
| 472 | } |
|---|
| 473 | |
|---|
| 474 | if (val.d > 0xFFFFFFFF) |
|---|
| 475 | { |
|---|
| 476 | /* overflow */ |
|---|
| 477 | buf[0] = 'B'; |
|---|
| 478 | buf[1] = 'I'; |
|---|
| 479 | buf[2] = 'G'; |
|---|
| 480 | len = 3; |
|---|
| 481 | pbuf = buf; |
|---|
| 482 | break; |
|---|
| 483 | } |
|---|
| 484 | |
|---|
| 485 | val.d -= (double)intp; |
|---|
| 486 | decp = (unsigned int)(val.d * 1000000000); |
|---|
| 487 | |
|---|
| 488 | for(i = 0; i < 10; i++) |
|---|
| 489 | { |
|---|
| 490 | if ((!isvalue) && (intp % 10)) isvalue = 1; |
|---|
| 491 | buf[9 - i] = HexaTab[intp % 10]; |
|---|
| 492 | if (!(intp /= 10)) break; |
|---|
| 493 | } |
|---|
| 494 | pbuf = &buf[9 - i]; |
|---|
| 495 | len = i+11; |
|---|
| 496 | buf[10] = '.'; |
|---|
| 497 | |
|---|
| 498 | for(i = 0; i < 9; i++) |
|---|
| 499 | { |
|---|
| 500 | if ((!isvalue) && (decp % 10)) isvalue = 1; |
|---|
| 501 | buf[19 - i] = HexaTab[decp % 10]; |
|---|
| 502 | decp /= 10; |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | if (!isvalue) |
|---|
| 506 | { |
|---|
| 507 | if (val.d != 0) |
|---|
| 508 | { |
|---|
| 509 | /* underflow */ |
|---|
| 510 | buf[0] = 'T'; |
|---|
| 511 | buf[1] = 'I'; |
|---|
| 512 | buf[2] = 'N'; |
|---|
| 513 | buf[3] = 'Y'; |
|---|
| 514 | len = 4; |
|---|
| 515 | pbuf = buf; |
|---|
| 516 | } |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | break; |
|---|
| 520 | } |
|---|
| 521 | case ('l'): |
|---|
| 522 | switch (modifiers) |
|---|
| 523 | { |
|---|
| 524 | case NO_MOD: |
|---|
| 525 | modifiers = L_MOD; |
|---|
| 526 | goto printf_arguments; |
|---|
| 527 | |
|---|
| 528 | case L_MOD: |
|---|
| 529 | modifiers = LL_MOD; |
|---|
| 530 | goto printf_arguments; |
|---|
| 531 | |
|---|
| 532 | default: |
|---|
| 533 | goto return_error; |
|---|
| 534 | } |
|---|
| 535 | |
|---|
| 536 | /* Ignored fields : width and precision */ |
|---|
| 537 | case ('.'): goto printf_arguments; |
|---|
| 538 | |
|---|
| 539 | default: |
|---|
| 540 | goto return_error; |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | ret = sys_call(SYSCALL_TTY_WRITE, |
|---|
| 544 | (unsigned int)pbuf, |
|---|
| 545 | len, |
|---|
| 546 | channel, |
|---|
| 547 | 0); |
|---|
| 548 | if (ret != len) goto return_error; |
|---|
| 549 | |
|---|
| 550 | goto printf_text; |
|---|
| 551 | } |
|---|
| 552 | |
|---|
| 553 | return_error: |
|---|
| 554 | return 1; |
|---|
| 555 | } // end __printf() |
|---|
| 556 | |
|---|
| 557 | |
|---|
| 558 | //////////////////////////////////////// |
|---|
| 559 | void giet_tty_printf( char* format, ...) |
|---|
| 560 | { |
|---|
| 561 | va_list args; |
|---|
| 562 | |
|---|
| 563 | va_start( args, format ); |
|---|
| 564 | int ret = __printf(format, 0xFFFFFFFF, &args); |
|---|
| 565 | va_end( args ); |
|---|
| 566 | |
|---|
| 567 | if (ret) |
|---|
| 568 | { |
|---|
| 569 | giet_pthread_exit("error in giet_tty_printf()"); |
|---|
| 570 | } |
|---|
| 571 | } // end giet_tty_printf() |
|---|
| 572 | |
|---|
| 573 | ///////////////////////////////// |
|---|
| 574 | void giet_tty_getc( char * byte ) |
|---|
| 575 | { |
|---|
| 576 | int ret; |
|---|
| 577 | |
|---|
| 578 | do |
|---|
| 579 | { |
|---|
| 580 | ret = sys_call(SYSCALL_TTY_READ, |
|---|
| 581 | (unsigned int)byte, // buffer address |
|---|
| 582 | 1, // number of characters |
|---|
| 583 | 0xFFFFFFFF, // channel index from task context |
|---|
| 584 | 0); |
|---|
| 585 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getc()"); |
|---|
| 586 | } |
|---|
| 587 | while (ret != 1); |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | ///////////////////////////////////// |
|---|
| 591 | void giet_tty_gets( char* buf, |
|---|
| 592 | unsigned int bufsize ) |
|---|
| 593 | { |
|---|
| 594 | int ret; // return value from syscalls |
|---|
| 595 | unsigned char byte; |
|---|
| 596 | unsigned int index = 0; |
|---|
| 597 | unsigned int string_cancel = 0x00082008; // string containing BS/SPACE/BS |
|---|
| 598 | |
|---|
| 599 | while (index < (bufsize - 1)) |
|---|
| 600 | { |
|---|
| 601 | // get one character |
|---|
| 602 | do |
|---|
| 603 | { |
|---|
| 604 | ret = sys_call(SYSCALL_TTY_READ, |
|---|
| 605 | (unsigned int)(&byte), |
|---|
| 606 | 1, |
|---|
| 607 | 0xFFFFFFFF, // channel index from task context |
|---|
| 608 | 0); |
|---|
| 609 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()"); |
|---|
| 610 | } |
|---|
| 611 | while (ret != 1); |
|---|
| 612 | |
|---|
| 613 | // analyse character |
|---|
| 614 | if (byte == 0x0A) // LF special character |
|---|
| 615 | { |
|---|
| 616 | break; |
|---|
| 617 | } |
|---|
| 618 | else if ( (byte == 0x7F) || // DEL special character |
|---|
| 619 | (byte == 0x08) ) // BS special character |
|---|
| 620 | { |
|---|
| 621 | if ( index > 0 ) |
|---|
| 622 | { |
|---|
| 623 | index--; |
|---|
| 624 | |
|---|
| 625 | // cancel character |
|---|
| 626 | ret = sys_call( SYSCALL_TTY_WRITE, |
|---|
| 627 | (unsigned int)(&string_cancel), |
|---|
| 628 | 3, |
|---|
| 629 | 0XFFFFFFFF, // channel index from task context |
|---|
| 630 | 0 ); |
|---|
| 631 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()"); |
|---|
| 632 | } |
|---|
| 633 | } |
|---|
| 634 | else if ( (byte < 0x20) || (byte > 0x7F) ) // non printable characters |
|---|
| 635 | { |
|---|
| 636 | } |
|---|
| 637 | else // take all other characters |
|---|
| 638 | { |
|---|
| 639 | buf[index] = byte; |
|---|
| 640 | index++; |
|---|
| 641 | |
|---|
| 642 | // echo |
|---|
| 643 | ret = sys_call( SYSCALL_TTY_WRITE, |
|---|
| 644 | (unsigned int)(&byte), |
|---|
| 645 | 1, |
|---|
| 646 | 0XFFFFFFFF, // channel index from task context |
|---|
| 647 | 0 ); |
|---|
| 648 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()"); |
|---|
| 649 | |
|---|
| 650 | } |
|---|
| 651 | } |
|---|
| 652 | buf[index] = 0; |
|---|
| 653 | |
|---|
| 654 | } // end giet_tty_gets() |
|---|
| 655 | |
|---|
| 656 | /////////////////////////////////////// |
|---|
| 657 | void giet_tty_getw( unsigned int* val ) |
|---|
| 658 | { |
|---|
| 659 | unsigned char buf[32]; |
|---|
| 660 | unsigned int string_byte = 0x00000000; // string containing one single byte |
|---|
| 661 | unsigned int string_cancel = 0x00082008; // string containing BS/SPACE/BS |
|---|
| 662 | unsigned int save = 0; |
|---|
| 663 | unsigned int dec = 0; |
|---|
| 664 | unsigned int done = 0; |
|---|
| 665 | unsigned int overflow = 0; |
|---|
| 666 | unsigned int length = 0; |
|---|
| 667 | unsigned int i; |
|---|
| 668 | int ret; // return value from syscalls |
|---|
| 669 | |
|---|
| 670 | // get characters |
|---|
| 671 | while (done == 0) |
|---|
| 672 | { |
|---|
| 673 | // read one character |
|---|
| 674 | do |
|---|
| 675 | { |
|---|
| 676 | ret = sys_call( SYSCALL_TTY_READ, |
|---|
| 677 | (unsigned int)(&string_byte), |
|---|
| 678 | 1, |
|---|
| 679 | 0xFFFFFFFF, // channel index from task context |
|---|
| 680 | 0); |
|---|
| 681 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
|---|
| 682 | } |
|---|
| 683 | while (ret != 1); |
|---|
| 684 | |
|---|
| 685 | // analyse character |
|---|
| 686 | if ((string_byte > 0x2F) && (string_byte < 0x3A)) // decimal character |
|---|
| 687 | { |
|---|
| 688 | buf[length] = (unsigned char)string_byte; |
|---|
| 689 | length++; |
|---|
| 690 | |
|---|
| 691 | // echo |
|---|
| 692 | ret = sys_call( SYSCALL_TTY_WRITE, |
|---|
| 693 | (unsigned int)(&string_byte), |
|---|
| 694 | 1, |
|---|
| 695 | 0xFFFFFFFF, // channel index from task context |
|---|
| 696 | 0 ); |
|---|
| 697 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
|---|
| 698 | } |
|---|
| 699 | else if (string_byte == 0x0A) // LF character |
|---|
| 700 | { |
|---|
| 701 | done = 1; |
|---|
| 702 | } |
|---|
| 703 | else if ( (string_byte == 0x7F) || // DEL character |
|---|
| 704 | (string_byte == 0x08) ) // BS character |
|---|
| 705 | { |
|---|
| 706 | if ( length > 0 ) |
|---|
| 707 | { |
|---|
| 708 | length--; // cancel the character |
|---|
| 709 | |
|---|
| 710 | ret = sys_call( SYSCALL_TTY_WRITE, |
|---|
| 711 | (unsigned int)(&string_cancel), |
|---|
| 712 | 3, |
|---|
| 713 | 0xFFFFFFFF, // channel index from task context |
|---|
| 714 | 0 ); |
|---|
| 715 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
|---|
| 716 | } |
|---|
| 717 | } |
|---|
| 718 | |
|---|
| 719 | // test buffer overflow |
|---|
| 720 | if ( length >= 32 ) |
|---|
| 721 | { |
|---|
| 722 | overflow = 1; |
|---|
| 723 | done = 1; |
|---|
| 724 | } |
|---|
| 725 | } // end while characters |
|---|
| 726 | |
|---|
| 727 | // string to int conversion with overflow detection |
|---|
| 728 | if ( overflow == 0 ) |
|---|
| 729 | { |
|---|
| 730 | for (i = 0; (i < length) && (overflow == 0) ; i++) |
|---|
| 731 | { |
|---|
| 732 | dec = dec * 10 + (buf[i] - 0x30); |
|---|
| 733 | if (dec < save) overflow = 1; |
|---|
| 734 | save = dec; |
|---|
| 735 | } |
|---|
| 736 | } |
|---|
| 737 | |
|---|
| 738 | // final evaluation |
|---|
| 739 | if ( overflow == 0 ) |
|---|
| 740 | { |
|---|
| 741 | // return value |
|---|
| 742 | *val = dec; |
|---|
| 743 | } |
|---|
| 744 | else |
|---|
| 745 | { |
|---|
| 746 | // cancel all echo characters |
|---|
| 747 | for (i = 0; i < length ; i++) |
|---|
| 748 | { |
|---|
| 749 | ret = sys_call( SYSCALL_TTY_WRITE, |
|---|
| 750 | (unsigned int)(&string_cancel), |
|---|
| 751 | 3, |
|---|
| 752 | 0xFFFFFFFF, // channel index from task context |
|---|
| 753 | 0 ); |
|---|
| 754 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
|---|
| 755 | } |
|---|
| 756 | // echo character '0' |
|---|
| 757 | string_byte = 0x30; |
|---|
| 758 | ret = sys_call( SYSCALL_TTY_WRITE, |
|---|
| 759 | (unsigned int)(&string_byte), |
|---|
| 760 | 1, |
|---|
| 761 | 0xFFFFFFFF, // channel index from task context |
|---|
| 762 | 0 ); |
|---|
| 763 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
|---|
| 764 | |
|---|
| 765 | // return 0 value |
|---|
| 766 | *val = 0; |
|---|
| 767 | } |
|---|
| 768 | } // end giet_tty_getw() |
|---|
| 769 | |
|---|
| 770 | |
|---|
| 771 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 772 | // TIMER related system calls |
|---|
| 773 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 774 | |
|---|
| 775 | /////////////////////// |
|---|
| 776 | void giet_timer_alloc() |
|---|
| 777 | { |
|---|
| 778 | if ( sys_call( SYSCALL_TIM_ALLOC, |
|---|
| 779 | 0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_ALLOC"); |
|---|
| 780 | } |
|---|
| 781 | |
|---|
| 782 | //////////////////////////////////////////// |
|---|
| 783 | void giet_timer_start( unsigned int period ) |
|---|
| 784 | { |
|---|
| 785 | if ( sys_call( SYSCALL_TIM_START, |
|---|
| 786 | period, |
|---|
| 787 | 0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_START"); |
|---|
| 788 | } |
|---|
| 789 | |
|---|
| 790 | ////////////////////// |
|---|
| 791 | void giet_timer_stop() |
|---|
| 792 | { |
|---|
| 793 | if ( sys_call( SYSCALL_TIM_STOP, |
|---|
| 794 | 0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in TIMER_STOP"); |
|---|
| 795 | } |
|---|
| 796 | |
|---|
| 797 | |
|---|
| 798 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 799 | // Frame buffer related system calls |
|---|
| 800 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 801 | |
|---|
| 802 | //////////////////////////////////////// |
|---|
| 803 | void giet_fbf_size( unsigned int* width, |
|---|
| 804 | unsigned int* height ) |
|---|
| 805 | { |
|---|
| 806 | sys_call( SYSCALL_FBF_SIZE, |
|---|
| 807 | (unsigned int)width, |
|---|
| 808 | (unsigned int)height, |
|---|
| 809 | 0, 0 ); |
|---|
| 810 | } |
|---|
| 811 | |
|---|
| 812 | ///////////////////// |
|---|
| 813 | void giet_fbf_alloc() |
|---|
| 814 | { |
|---|
| 815 | if ( sys_call( SYSCALL_FBF_ALLOC, |
|---|
| 816 | 0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_ALLOC"); |
|---|
| 817 | } |
|---|
| 818 | |
|---|
| 819 | //////////////////////////////////////////// |
|---|
| 820 | void giet_fbf_cma_alloc( unsigned int nbufs ) |
|---|
| 821 | { |
|---|
| 822 | if ( sys_call( SYSCALL_FBF_CMA_ALLOC, |
|---|
| 823 | nbufs, |
|---|
| 824 | 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_ALLOC"); |
|---|
| 825 | } |
|---|
| 826 | |
|---|
| 827 | /////////////////////////////////////////////// |
|---|
| 828 | void giet_fbf_cma_init_buf( unsigned int index, |
|---|
| 829 | void* buf_vaddr, |
|---|
| 830 | void* sts_vaddr ) |
|---|
| 831 | { |
|---|
| 832 | if ( sys_call( SYSCALL_FBF_CMA_INIT_BUF, |
|---|
| 833 | index, |
|---|
| 834 | (unsigned int)buf_vaddr, |
|---|
| 835 | (unsigned int)sts_vaddr, |
|---|
| 836 | 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_INIT_BUF"); |
|---|
| 837 | } |
|---|
| 838 | |
|---|
| 839 | ///////////////////////// |
|---|
| 840 | void giet_fbf_cma_start() |
|---|
| 841 | { |
|---|
| 842 | if ( sys_call( SYSCALL_FBF_CMA_START, |
|---|
| 843 | 0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_START"); |
|---|
| 844 | } |
|---|
| 845 | |
|---|
| 846 | /////////////////////////////////////////////// |
|---|
| 847 | void giet_fbf_cma_display( unsigned int index ) |
|---|
| 848 | { |
|---|
| 849 | if ( sys_call( SYSCALL_FBF_CMA_DISPLAY, |
|---|
| 850 | index, |
|---|
| 851 | 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_DISPLAY"); |
|---|
| 852 | } |
|---|
| 853 | |
|---|
| 854 | ///////////////////////////////////////////// |
|---|
| 855 | void giet_fbf_cma_check( unsigned int index ) |
|---|
| 856 | { |
|---|
| 857 | if ( sys_call( SYSCALL_FBF_CMA_CHECK, |
|---|
| 858 | index, |
|---|
| 859 | 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_CHECK"); |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | //////////////////////// |
|---|
| 863 | void giet_fbf_cma_stop() |
|---|
| 864 | { |
|---|
| 865 | if ( sys_call( SYSCALL_FBF_CMA_STOP, |
|---|
| 866 | 0, 0, 0, 0 ) ) giet_pthread_exit("ERROR in FBF_CMA_STOP"); |
|---|
| 867 | } |
|---|
| 868 | |
|---|
| 869 | ////////////////////////////////////////////// |
|---|
| 870 | void giet_fbf_sync_write( unsigned int offset, |
|---|
| 871 | void * buffer, |
|---|
| 872 | unsigned int length ) |
|---|
| 873 | { |
|---|
| 874 | if ( sys_call( SYSCALL_FBF_SYNC_WRITE, |
|---|
| 875 | offset, |
|---|
| 876 | (unsigned int)buffer, |
|---|
| 877 | length, |
|---|
| 878 | 0 ) ) giet_pthread_exit("ERROR in FBF_SYNC_WRITE"); |
|---|
| 879 | } |
|---|
| 880 | |
|---|
| 881 | ///////////////////////////////////////////// |
|---|
| 882 | void giet_fbf_sync_read( unsigned int offset, |
|---|
| 883 | void * buffer, |
|---|
| 884 | unsigned int length ) |
|---|
| 885 | { |
|---|
| 886 | if ( sys_call( SYSCALL_FBF_SYNC_READ, |
|---|
| 887 | offset, |
|---|
| 888 | (unsigned int)buffer, |
|---|
| 889 | length, |
|---|
| 890 | 0 ) ) giet_pthread_exit("ERROR in FBF_SYNC_READ"); |
|---|
| 891 | } |
|---|
| 892 | |
|---|
| 893 | |
|---|
| 894 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 895 | // NIC related system calls |
|---|
| 896 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 897 | |
|---|
| 898 | ////////////////////////////////////////// |
|---|
| 899 | void giet_nic_rx_alloc( unsigned int xmax, |
|---|
| 900 | unsigned int ymax ) |
|---|
| 901 | { |
|---|
| 902 | if ( sys_call( SYSCALL_NIC_ALLOC, |
|---|
| 903 | 1, // RX |
|---|
| 904 | xmax, |
|---|
| 905 | ymax, |
|---|
| 906 | 0 ) ) giet_pthread_exit("error in giet_nic_rx_alloc()"); |
|---|
| 907 | } |
|---|
| 908 | |
|---|
| 909 | ////////////////////////////////////////// |
|---|
| 910 | void giet_nic_tx_alloc( unsigned int xmax, |
|---|
| 911 | unsigned int ymax ) |
|---|
| 912 | { |
|---|
| 913 | if ( sys_call( SYSCALL_NIC_ALLOC, |
|---|
| 914 | 0, // TX |
|---|
| 915 | xmax, |
|---|
| 916 | ymax, |
|---|
| 917 | 0 ) ) giet_pthread_exit("error in giet_nic_tx_alloc()"); |
|---|
| 918 | } |
|---|
| 919 | |
|---|
| 920 | //////////////////////// |
|---|
| 921 | void giet_nic_rx_start() |
|---|
| 922 | { |
|---|
| 923 | if ( sys_call( SYSCALL_NIC_START, |
|---|
| 924 | 1, // RX |
|---|
| 925 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_start()"); |
|---|
| 926 | } |
|---|
| 927 | |
|---|
| 928 | //////////////////////// |
|---|
| 929 | void giet_nic_tx_start() |
|---|
| 930 | { |
|---|
| 931 | if ( sys_call( SYSCALL_NIC_START, |
|---|
| 932 | 0, // TX |
|---|
| 933 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_start()"); |
|---|
| 934 | } |
|---|
| 935 | |
|---|
| 936 | ///////////////////////////////////// |
|---|
| 937 | void giet_nic_rx_move( void* buffer ) |
|---|
| 938 | { |
|---|
| 939 | if ( sys_call( SYSCALL_NIC_MOVE, |
|---|
| 940 | 1, // RX |
|---|
| 941 | (unsigned int)buffer, |
|---|
| 942 | 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_move()"); |
|---|
| 943 | } |
|---|
| 944 | |
|---|
| 945 | ///////////////////////////////////// |
|---|
| 946 | void giet_nic_tx_move( void* buffer ) |
|---|
| 947 | { |
|---|
| 948 | if ( sys_call( SYSCALL_NIC_MOVE, |
|---|
| 949 | 0, // TX |
|---|
| 950 | (unsigned int)buffer, |
|---|
| 951 | 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_move()"); |
|---|
| 952 | } |
|---|
| 953 | |
|---|
| 954 | /////////////////////// |
|---|
| 955 | void giet_nic_rx_stop() |
|---|
| 956 | { |
|---|
| 957 | if ( sys_call( SYSCALL_NIC_STOP, |
|---|
| 958 | 1, // RX |
|---|
| 959 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stop()"); |
|---|
| 960 | } |
|---|
| 961 | |
|---|
| 962 | /////////////////////// |
|---|
| 963 | void giet_nic_tx_stop() |
|---|
| 964 | { |
|---|
| 965 | if ( sys_call( SYSCALL_NIC_STOP, |
|---|
| 966 | 0, // TX |
|---|
| 967 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stop()"); |
|---|
| 968 | } |
|---|
| 969 | |
|---|
| 970 | //////////////////////// |
|---|
| 971 | void giet_nic_rx_stats() |
|---|
| 972 | { |
|---|
| 973 | if ( sys_call( SYSCALL_NIC_STATS, |
|---|
| 974 | 1, // RX |
|---|
| 975 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stats()"); |
|---|
| 976 | } |
|---|
| 977 | |
|---|
| 978 | //////////////////////// |
|---|
| 979 | void giet_nic_tx_stats() |
|---|
| 980 | { |
|---|
| 981 | if ( sys_call( SYSCALL_NIC_STATS, |
|---|
| 982 | 0, // TX |
|---|
| 983 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stats()"); |
|---|
| 984 | } |
|---|
| 985 | |
|---|
| 986 | //////////////////////// |
|---|
| 987 | void giet_nic_rx_clear() |
|---|
| 988 | { |
|---|
| 989 | if ( sys_call( SYSCALL_NIC_CLEAR, |
|---|
| 990 | 1, // RX |
|---|
| 991 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_clear()"); |
|---|
| 992 | } |
|---|
| 993 | |
|---|
| 994 | //////////////////////// |
|---|
| 995 | void giet_nic_tx_clear() |
|---|
| 996 | { |
|---|
| 997 | if ( sys_call( SYSCALL_NIC_CLEAR, |
|---|
| 998 | 0, // TX |
|---|
| 999 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_clear()"); |
|---|
| 1000 | } |
|---|
| 1001 | |
|---|
| 1002 | |
|---|
| 1003 | |
|---|
| 1004 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 1005 | // FAT related system calls |
|---|
| 1006 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 1007 | |
|---|
| 1008 | ///////////////////////////////////////// |
|---|
| 1009 | int giet_fat_open( char* pathname, |
|---|
| 1010 | unsigned int flags ) |
|---|
| 1011 | { |
|---|
| 1012 | return sys_call( SYSCALL_FAT_OPEN, |
|---|
| 1013 | (unsigned int)pathname, |
|---|
| 1014 | flags, |
|---|
| 1015 | 0, 0 ); |
|---|
| 1016 | } |
|---|
| 1017 | |
|---|
| 1018 | ///////////////////////////////////////// |
|---|
| 1019 | int giet_fat_close( unsigned int fd_id ) |
|---|
| 1020 | { |
|---|
| 1021 | return sys_call( SYSCALL_FAT_CLOSE, |
|---|
| 1022 | fd_id, |
|---|
| 1023 | 0, 0, 0 ); |
|---|
| 1024 | } |
|---|
| 1025 | |
|---|
| 1026 | ///////////////////////////////////////////// |
|---|
| 1027 | int giet_fat_file_info( unsigned int fd_id, |
|---|
| 1028 | struct fat_file_info_s* info ) |
|---|
| 1029 | { |
|---|
| 1030 | return sys_call( SYSCALL_FAT_FINFO, |
|---|
| 1031 | fd_id, |
|---|
| 1032 | (unsigned int)info, |
|---|
| 1033 | 0, 0 ); |
|---|
| 1034 | } |
|---|
| 1035 | |
|---|
| 1036 | /////////////////////////////////////// |
|---|
| 1037 | int giet_fat_read( unsigned int fd_id, |
|---|
| 1038 | void* buffer, |
|---|
| 1039 | unsigned int count ) |
|---|
| 1040 | { |
|---|
| 1041 | return sys_call( SYSCALL_FAT_READ, |
|---|
| 1042 | fd_id, |
|---|
| 1043 | (unsigned int)buffer, |
|---|
| 1044 | count, |
|---|
| 1045 | 0 ); // no physical addressing required |
|---|
| 1046 | } |
|---|
| 1047 | |
|---|
| 1048 | //////////////////////////////////////// |
|---|
| 1049 | int giet_fat_write( unsigned int fd_id, |
|---|
| 1050 | void* buffer, |
|---|
| 1051 | unsigned int count ) |
|---|
| 1052 | { |
|---|
| 1053 | return sys_call( SYSCALL_FAT_WRITE, |
|---|
| 1054 | fd_id, |
|---|
| 1055 | (unsigned int)buffer, |
|---|
| 1056 | count, |
|---|
| 1057 | 0 ); // no physical addressing required |
|---|
| 1058 | } |
|---|
| 1059 | |
|---|
| 1060 | //////////////////////////////////////// |
|---|
| 1061 | int giet_fat_lseek( unsigned int fd_id, |
|---|
| 1062 | unsigned int offset, |
|---|
| 1063 | unsigned int whence ) |
|---|
| 1064 | { |
|---|
| 1065 | return sys_call( SYSCALL_FAT_LSEEK, |
|---|
| 1066 | fd_id, |
|---|
| 1067 | offset, |
|---|
| 1068 | whence, |
|---|
| 1069 | 0 ); |
|---|
| 1070 | } |
|---|
| 1071 | |
|---|
| 1072 | //////////////////////////////////////////// |
|---|
| 1073 | int giet_fat_remove( char* pathname, |
|---|
| 1074 | unsigned int should_be_dir ) |
|---|
| 1075 | { |
|---|
| 1076 | return sys_call( SYSCALL_FAT_REMOVE, |
|---|
| 1077 | (unsigned int)pathname, |
|---|
| 1078 | should_be_dir, |
|---|
| 1079 | 0, 0 ); |
|---|
| 1080 | } |
|---|
| 1081 | |
|---|
| 1082 | ///////////////////////////////////// |
|---|
| 1083 | int giet_fat_rename( char* old_path, |
|---|
| 1084 | char* new_path ) |
|---|
| 1085 | { |
|---|
| 1086 | return sys_call( SYSCALL_FAT_RENAME, |
|---|
| 1087 | (unsigned int)old_path, |
|---|
| 1088 | (unsigned int)new_path, |
|---|
| 1089 | 0, 0 ); |
|---|
| 1090 | } |
|---|
| 1091 | |
|---|
| 1092 | //////////////////////////////////// |
|---|
| 1093 | int giet_fat_mkdir( char* pathname ) |
|---|
| 1094 | { |
|---|
| 1095 | return sys_call( SYSCALL_FAT_MKDIR, |
|---|
| 1096 | (unsigned int)pathname, |
|---|
| 1097 | 0, 0, 0 ); |
|---|
| 1098 | } |
|---|
| 1099 | |
|---|
| 1100 | //////////////////////////////////// |
|---|
| 1101 | int giet_fat_opendir( char* pathname ) |
|---|
| 1102 | { |
|---|
| 1103 | return sys_call( SYSCALL_FAT_OPENDIR, |
|---|
| 1104 | (unsigned int)pathname, |
|---|
| 1105 | 0, 0, 0 ); |
|---|
| 1106 | } |
|---|
| 1107 | |
|---|
| 1108 | //////////////////////////////////// |
|---|
| 1109 | int giet_fat_closedir( unsigned int fd_id ) |
|---|
| 1110 | { |
|---|
| 1111 | return sys_call( SYSCALL_FAT_CLOSEDIR, |
|---|
| 1112 | (unsigned int)fd_id, |
|---|
| 1113 | 0, 0, 0 ); |
|---|
| 1114 | } |
|---|
| 1115 | |
|---|
| 1116 | //////////////////////////////////// |
|---|
| 1117 | int giet_fat_readdir( unsigned int fd_id, |
|---|
| 1118 | fat_dirent_t* entry ) |
|---|
| 1119 | { |
|---|
| 1120 | return sys_call( SYSCALL_FAT_READDIR, |
|---|
| 1121 | (unsigned int)fd_id, |
|---|
| 1122 | (unsigned int)entry, |
|---|
| 1123 | 0, 0 ); |
|---|
| 1124 | } |
|---|
| 1125 | |
|---|
| 1126 | |
|---|
| 1127 | |
|---|
| 1128 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 1129 | // Miscellaneous system calls |
|---|
| 1130 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 1131 | |
|---|
| 1132 | ///////////////////////////////////////////////// |
|---|
| 1133 | void giet_procs_number( unsigned int* x_size, |
|---|
| 1134 | unsigned int* y_size, |
|---|
| 1135 | unsigned int* nprocs ) |
|---|
| 1136 | { |
|---|
| 1137 | if ( sys_call( SYSCALL_PROCS_NUMBER, |
|---|
| 1138 | (unsigned int)x_size, |
|---|
| 1139 | (unsigned int)y_size, |
|---|
| 1140 | (unsigned int)nprocs, |
|---|
| 1141 | 0 ) ) giet_pthread_exit("error in giet_procs_number()"); |
|---|
| 1142 | } |
|---|
| 1143 | |
|---|
| 1144 | //////////////////////////////////////////////////// |
|---|
| 1145 | void giet_vobj_get_vbase( char* vspace_name, |
|---|
| 1146 | char* vobj_name, |
|---|
| 1147 | unsigned int* vbase ) |
|---|
| 1148 | { |
|---|
| 1149 | if ( sys_call( SYSCALL_VOBJ_GET_VBASE, |
|---|
| 1150 | (unsigned int) vspace_name, |
|---|
| 1151 | (unsigned int) vobj_name, |
|---|
| 1152 | (unsigned int) vbase, |
|---|
| 1153 | 0 ) ) giet_pthread_exit("error in giet_vobj_get_vbase()"); |
|---|
| 1154 | } |
|---|
| 1155 | |
|---|
| 1156 | //////////////////////////////////////////////////// |
|---|
| 1157 | void giet_vobj_get_length( char* vspace_name, |
|---|
| 1158 | char* vobj_name, |
|---|
| 1159 | unsigned int* length ) |
|---|
| 1160 | { |
|---|
| 1161 | if ( sys_call( SYSCALL_VOBJ_GET_LENGTH, |
|---|
| 1162 | (unsigned int) vspace_name, |
|---|
| 1163 | (unsigned int) vobj_name, |
|---|
| 1164 | (unsigned int) length, |
|---|
| 1165 | 0 ) ) giet_pthread_exit("error in giet_vobj_get_length()"); |
|---|
| 1166 | } |
|---|
| 1167 | |
|---|
| 1168 | ///////////////////////////////////////// |
|---|
| 1169 | void giet_heap_info( unsigned int* vaddr, |
|---|
| 1170 | unsigned int* length, |
|---|
| 1171 | unsigned int x, |
|---|
| 1172 | unsigned int y ) |
|---|
| 1173 | { |
|---|
| 1174 | sys_call( SYSCALL_HEAP_INFO, |
|---|
| 1175 | (unsigned int)vaddr, |
|---|
| 1176 | (unsigned int)length, |
|---|
| 1177 | x, |
|---|
| 1178 | y ); |
|---|
| 1179 | } |
|---|
| 1180 | |
|---|
| 1181 | ///////////////////////////////////////// |
|---|
| 1182 | void giet_get_xy( void* ptr, |
|---|
| 1183 | unsigned int* px, |
|---|
| 1184 | unsigned int* py ) |
|---|
| 1185 | { |
|---|
| 1186 | if ( sys_call( SYSCALL_GET_XY, |
|---|
| 1187 | (unsigned int)ptr, |
|---|
| 1188 | (unsigned int)px, |
|---|
| 1189 | (unsigned int)py, |
|---|
| 1190 | 0 ) ) giet_pthread_exit("error in giet_get_xy()"); |
|---|
| 1191 | } |
|---|
| 1192 | |
|---|
| 1193 | // Local Variables: |
|---|
| 1194 | // tab-width: 4 |
|---|
| 1195 | // c-basic-offset: 4 |
|---|
| 1196 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 1197 | // indent-tabs-mode: nil |
|---|
| 1198 | // End: |
|---|
| 1199 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 1200 | |
|---|