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