[521] | 1 | ////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 2 | // File : stdio.c |
---|
| 3 | // Date : 01/04/2010 |
---|
| 4 | // Author : alain greiner & Joel Porquet |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
[521] | 6 | ////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 7 | |
---|
| 8 | #include <stdarg.h> |
---|
| 9 | #include <stdio.h> |
---|
[267] | 10 | #include <giet_config.h> |
---|
[258] | 11 | |
---|
[521] | 12 | ////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 13 | // MIPS32 related system calls |
---|
[521] | 14 | ////////////////////////////////////////////////////////////////////////////// |
---|
[390] | 15 | |
---|
[438] | 16 | //////////////////////////////////////////// |
---|
[431] | 17 | void giet_proc_xyp( unsigned int* cluster_x, |
---|
| 18 | unsigned int* cluster_y, |
---|
| 19 | unsigned int* lpid ) |
---|
[390] | 20 | { |
---|
[438] | 21 | sys_call( SYSCALL_PROC_XYP, |
---|
[431] | 22 | (unsigned int)cluster_x, |
---|
| 23 | (unsigned int)cluster_y, |
---|
| 24 | (unsigned int)lpid, |
---|
| 25 | 0 ); |
---|
[390] | 26 | } |
---|
| 27 | |
---|
[438] | 28 | //////////////////////////// |
---|
| 29 | unsigned int giet_proctime() |
---|
[390] | 30 | { |
---|
[438] | 31 | return (unsigned int)sys_call( SYSCALL_PROC_TIME, |
---|
| 32 | 0, 0, 0, 0 ); |
---|
[390] | 33 | } |
---|
| 34 | |
---|
[438] | 35 | //////////////////////// |
---|
| 36 | unsigned int giet_rand() |
---|
[390] | 37 | { |
---|
[438] | 38 | unsigned int x = (unsigned int)sys_call( SYSCALL_PROC_TIME, |
---|
| 39 | 0, 0, 0, 0); |
---|
[390] | 40 | if ((x & 0xF) > 7) |
---|
| 41 | { |
---|
| 42 | return (x*x & 0xFFFF); |
---|
| 43 | } |
---|
| 44 | else |
---|
| 45 | { |
---|
| 46 | return (x*x*x & 0xFFFF); |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
[521] | 50 | ////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 51 | // Threads related system calls |
---|
[521] | 52 | ////////////////////////////////////////////////////////////////////////////// |
---|
[438] | 53 | |
---|
[709] | 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 ) |
---|
[438] | 63 | { |
---|
[709] | 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 ); |
---|
[438] | 77 | } |
---|
| 78 | |
---|
[709] | 79 | //////////////////////////////////////// |
---|
| 80 | int giet_pthread_join( pthread_t trdid, |
---|
| 81 | void** ptr ) |
---|
[438] | 82 | { |
---|
[709] | 83 | return sys_call( SYSCALL_PTHREAD_JOIN, |
---|
| 84 | trdid, |
---|
| 85 | (unsigned int)ptr, |
---|
| 86 | 0, 0 ); |
---|
[438] | 87 | } |
---|
| 88 | |
---|
[709] | 89 | /////////////////////////////////////// |
---|
| 90 | int giet_pthread_kill( pthread_t trdid, |
---|
| 91 | int signal ) |
---|
[438] | 92 | { |
---|
[709] | 93 | return sys_call( SYSCALL_PTHREAD_KILL, |
---|
| 94 | trdid, |
---|
| 95 | signal, |
---|
| 96 | 0, 0 ); |
---|
[438] | 97 | } |
---|
| 98 | |
---|
[709] | 99 | ///////////////////////// |
---|
| 100 | void giet_pthread_yield() |
---|
[647] | 101 | { |
---|
[709] | 102 | sys_call( SYSCALL_PTHREAD_YIELD, |
---|
| 103 | 0, 0, 0, 0 ); |
---|
[647] | 104 | } |
---|
[438] | 105 | |
---|
[709] | 106 | ///////////////////////////////////////////////// |
---|
| 107 | void giet_pthread_assert( unsigned int condition, |
---|
| 108 | char* string ) |
---|
[647] | 109 | { |
---|
[709] | 110 | if ( condition == 0 ) giet_pthread_exit( string ); |
---|
[647] | 111 | } |
---|
| 112 | |
---|
[709] | 113 | ////////////////////////////////////////////// |
---|
| 114 | int giet_pthread_pause( char* vspace_name, |
---|
| 115 | char* thread_name ) |
---|
[647] | 116 | { |
---|
[709] | 117 | return sys_call( SYSCALL_PTHREAD_CONTROL, |
---|
| 118 | THREAD_CMD_PAUSE, |
---|
| 119 | (unsigned int) vspace_name, |
---|
| 120 | (unsigned int) thread_name, |
---|
| 121 | 0 ); |
---|
[647] | 122 | } |
---|
| 123 | |
---|
[709] | 124 | /////////////////////////////////////////////// |
---|
| 125 | int giet_pthread_resume( char* vspace_name, |
---|
| 126 | char* thread_name ) |
---|
[689] | 127 | { |
---|
[709] | 128 | return sys_call( SYSCALL_PTHREAD_CONTROL, |
---|
| 129 | THREAD_CMD_RESUME, |
---|
| 130 | (unsigned int) vspace_name, |
---|
| 131 | (unsigned int) thread_name, |
---|
| 132 | 0 ); |
---|
[689] | 133 | } |
---|
| 134 | |
---|
[709] | 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 | |
---|
[521] | 147 | ////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 148 | // Applications related system calls |
---|
[647] | 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 | |
---|
[709] | 167 | /////////////////////////////// |
---|
| 168 | void giet_applications_status() |
---|
| 169 | { |
---|
| 170 | sys_call( SYSCALL_APPS_STATUS, |
---|
| 171 | 0, 0, 0, 0 ); |
---|
| 172 | } |
---|
| 173 | |
---|
[647] | 174 | ////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 175 | // Coprocessors related system calls |
---|
[521] | 176 | ////////////////////////////////////////////////////////////////////////////// |
---|
[295] | 177 | |
---|
[521] | 178 | /////////////////////////////////////////////////// |
---|
| 179 | void giet_coproc_alloc( unsigned int coproc_type, |
---|
[558] | 180 | unsigned int* coproc_info ) |
---|
[521] | 181 | { |
---|
| 182 | if ( sys_call( SYSCALL_COPROC_ALLOC, |
---|
| 183 | coproc_type, |
---|
| 184 | (unsigned int)coproc_info, |
---|
[558] | 185 | 0, 0 ) ) |
---|
[709] | 186 | giet_pthread_exit("error in giet_coproc_alloc()"); |
---|
[521] | 187 | } |
---|
| 188 | |
---|
[558] | 189 | ///////////////////////////////////////////////////////// |
---|
| 190 | void giet_coproc_release( unsigned int coproc_reg_index ) |
---|
[521] | 191 | { |
---|
| 192 | if ( sys_call( SYSCALL_COPROC_RELEASE, |
---|
[558] | 193 | coproc_reg_index, |
---|
[521] | 194 | 0, 0, 0 ) ) |
---|
[709] | 195 | giet_pthread_exit("error in giet_coproc_release()"); |
---|
[521] | 196 | } |
---|
| 197 | |
---|
| 198 | ////////////////////////////////////////////////////////////////// |
---|
[558] | 199 | void giet_coproc_channel_init( unsigned int channel, |
---|
[521] | 200 | giet_coproc_channel_t* desc ) |
---|
| 201 | { |
---|
| 202 | if ( sys_call( SYSCALL_COPROC_CHANNEL_INIT, |
---|
| 203 | channel, |
---|
| 204 | (unsigned int)desc, |
---|
| 205 | 0, 0 ) ) |
---|
[709] | 206 | giet_pthread_exit("error in giet_coproc_channel_init()"); |
---|
[521] | 207 | } |
---|
| 208 | |
---|
[558] | 209 | ///////////////////////////////////////////////////// |
---|
| 210 | void giet_coproc_run( unsigned int coproc_reg_index ) |
---|
[521] | 211 | { |
---|
[558] | 212 | if ( sys_call( SYSCALL_COPROC_RUN, |
---|
| 213 | coproc_reg_index, |
---|
| 214 | 0, 0, 0 ) ) |
---|
[709] | 215 | giet_pthread_exit("error in giet_coproc_run()"); |
---|
[521] | 216 | } |
---|
| 217 | |
---|
[558] | 218 | //////////////////////////// |
---|
| 219 | void giet_coproc_completed() |
---|
[521] | 220 | { |
---|
| 221 | if ( sys_call( SYSCALL_COPROC_COMPLETED, |
---|
[558] | 222 | 0, 0, 0, 0 ) ) |
---|
[709] | 223 | giet_pthread_exit("error in giet_coproc_completed"); |
---|
[521] | 224 | } |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | ////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 228 | // TTY device related system calls |
---|
[521] | 229 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 230 | |
---|
[671] | 231 | ////////////////////////////////////////// |
---|
| 232 | void giet_tty_alloc( unsigned int shared ) |
---|
[258] | 233 | { |
---|
[521] | 234 | if ( sys_call( SYSCALL_TTY_ALLOC, |
---|
[671] | 235 | shared, |
---|
[709] | 236 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_tty_alloc()"); |
---|
[438] | 237 | } |
---|
[258] | 238 | |
---|
[438] | 239 | //////////////////////////////////////////////////////////////////////// |
---|
| 240 | static int __printf( char* format, unsigned int channel, va_list* args) |
---|
| 241 | { |
---|
| 242 | int ret; // return value from the syscall |
---|
[580] | 243 | enum TModifiers {NO_MOD, L_MOD, LL_MOD} modifiers; |
---|
[438] | 244 | |
---|
[295] | 245 | printf_text: |
---|
[258] | 246 | |
---|
[295] | 247 | while (*format) |
---|
[258] | 248 | { |
---|
[295] | 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, |
---|
[258] | 257 | 0); |
---|
| 258 | |
---|
[295] | 259 | if (ret != i) goto return_error; |
---|
| 260 | |
---|
| 261 | format += i; |
---|
[258] | 262 | } |
---|
[295] | 263 | if (*format == '%') |
---|
[258] | 264 | { |
---|
[295] | 265 | format++; |
---|
[580] | 266 | modifiers = NO_MOD; |
---|
[295] | 267 | goto printf_arguments; |
---|
[258] | 268 | } |
---|
| 269 | } |
---|
| 270 | |
---|
[345] | 271 | return 0; |
---|
[295] | 272 | |
---|
| 273 | printf_arguments: |
---|
| 274 | |
---|
[258] | 275 | { |
---|
[628] | 276 | char buf[30]; |
---|
| 277 | char * pbuf; |
---|
| 278 | unsigned int len = 0; |
---|
[295] | 279 | static const char HexaTab[] = "0123456789ABCDEF"; |
---|
[628] | 280 | unsigned int i; |
---|
[580] | 281 | |
---|
| 282 | /* Ignored fields : width and precision */ |
---|
| 283 | for (; *format >= '0' && *format <= '9'; format++); |
---|
[258] | 284 | |
---|
[295] | 285 | switch (*format++) |
---|
[258] | 286 | { |
---|
[580] | 287 | case ('%'): |
---|
[641] | 288 | { |
---|
| 289 | len = 1; |
---|
| 290 | pbuf = "%"; |
---|
| 291 | break; |
---|
| 292 | } |
---|
[295] | 293 | case ('c'): /* char conversion */ |
---|
[258] | 294 | { |
---|
[345] | 295 | int val = va_arg( *args, int ); |
---|
[588] | 296 | if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning |
---|
[580] | 297 | |
---|
[295] | 298 | len = 1; |
---|
| 299 | buf[0] = val; |
---|
| 300 | pbuf = &buf[0]; |
---|
| 301 | break; |
---|
[258] | 302 | } |
---|
[580] | 303 | case ('d'): /* decimal signed integer */ |
---|
[258] | 304 | { |
---|
[345] | 305 | int val = va_arg( *args, int ); |
---|
[580] | 306 | |
---|
[588] | 307 | if (modifiers == LL_MOD) goto return_error; // 64 bits not supported |
---|
[580] | 308 | |
---|
[295] | 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; |
---|
[258] | 327 | } |
---|
[580] | 328 | case ('u'): /* decimal unsigned integer */ |
---|
[295] | 329 | { |
---|
[580] | 330 | if (modifiers != LL_MOD) //32 bits integer |
---|
[295] | 331 | { |
---|
[580] | 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; |
---|
[295] | 341 | } |
---|
[580] | 342 | //64 bits : base 10 unsupported : continue to hexa |
---|
[295] | 343 | } |
---|
[580] | 344 | case ('x'): |
---|
| 345 | case ('X'): /* hexadecimal integer */ |
---|
[295] | 346 | { |
---|
[580] | 347 | unsigned long long val; |
---|
| 348 | int imax; |
---|
| 349 | |
---|
[628] | 350 | if (modifiers == LL_MOD) // 64 bits |
---|
[295] | 351 | { |
---|
[580] | 352 | val = va_arg( *args, unsigned long long); |
---|
| 353 | |
---|
[628] | 354 | // if asked to print in base 10, can do only if it fits in 32 bits |
---|
| 355 | if (*(format-1) == 'u' && (!(val & 0xFFFFFFFF00000000ULL))) |
---|
[580] | 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; |
---|
[295] | 370 | } |
---|
[580] | 371 | else //32 bits |
---|
| 372 | { |
---|
| 373 | val = va_arg( *args, unsigned int); |
---|
| 374 | imax = 8; |
---|
| 375 | } |
---|
| 376 | |
---|
[295] | 377 | ret = sys_call(SYSCALL_TTY_WRITE, |
---|
| 378 | (unsigned int)"0x", |
---|
| 379 | 2, |
---|
| 380 | channel, |
---|
| 381 | 0); |
---|
| 382 | if (ret != 2) goto return_error; |
---|
[580] | 383 | |
---|
| 384 | for(i = 0; i < imax; i++) |
---|
[295] | 385 | { |
---|
[580] | 386 | buf[(imax-1) - i] = HexaTab[val % 16]; |
---|
[295] | 387 | if (!(val /= 16)) break; |
---|
| 388 | } |
---|
| 389 | len = i + 1; |
---|
[580] | 390 | pbuf = &buf[(imax-1) - i]; |
---|
[295] | 391 | break; |
---|
| 392 | } |
---|
| 393 | case ('s'): /* string */ |
---|
| 394 | { |
---|
[345] | 395 | char* str = va_arg( *args, char* ); |
---|
[580] | 396 | |
---|
[588] | 397 | if (modifiers != NO_MOD) goto return_error; // Modifiers have no meaning |
---|
[580] | 398 | |
---|
[295] | 399 | while (str[len]) |
---|
| 400 | { |
---|
| 401 | len++; |
---|
| 402 | } |
---|
| 403 | pbuf = str; |
---|
| 404 | break; |
---|
| 405 | } |
---|
[580] | 406 | case ('e'): |
---|
| 407 | case ('f'): |
---|
| 408 | case ('g'): /* IEEE754 64 bits */ |
---|
| 409 | { |
---|
[666] | 410 | union |
---|
| 411 | { |
---|
| 412 | double d; |
---|
| 413 | unsigned long long ull; |
---|
| 414 | } val; |
---|
[580] | 415 | |
---|
[666] | 416 | val.d = va_arg( *args, double ); |
---|
[580] | 417 | |
---|
[666] | 418 | unsigned long long digits = val.ull & 0xFFFFFFFFFFFFFULL; //get mantissa |
---|
[580] | 419 | |
---|
| 420 | unsigned int |
---|
[666] | 421 | base = (unsigned int)((val.ull & 0x7FF0000000000000ULL) >> 52), //get exposant |
---|
| 422 | intp = (unsigned int)val.d, //get integer part of the float |
---|
[580] | 423 | decp; |
---|
| 424 | |
---|
| 425 | int isvalue = 0; |
---|
| 426 | |
---|
| 427 | if (base == 0x7FF) //special value |
---|
| 428 | { |
---|
[628] | 429 | if (digits & 0xFFFFFFFFFFFFFULL) |
---|
[580] | 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 */ |
---|
[666] | 441 | buf[0] = (val.ull & 0x8000000000000000ULL) ? '-' : '+'; |
---|
[580] | 442 | buf[1] = 'i'; |
---|
| 443 | buf[2] = 'n'; |
---|
| 444 | buf[3] = 'f'; |
---|
| 445 | len = 4; |
---|
| 446 | pbuf = buf; |
---|
| 447 | } |
---|
| 448 | break; |
---|
| 449 | } |
---|
| 450 | |
---|
[666] | 451 | if (val.ull & 0x8000000000000000ULL) |
---|
[580] | 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; |
---|
[666] | 460 | val.d = val.d * -1; |
---|
[580] | 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 | |
---|
[666] | 473 | if (val.d > 0xFFFFFFFF) |
---|
[580] | 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 | |
---|
[666] | 484 | val.d -= (double)intp; |
---|
| 485 | decp = (unsigned int)(val.d * 1000000000); |
---|
[580] | 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 | { |
---|
[666] | 506 | if (val.d != 0) |
---|
[580] | 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 | |
---|
[295] | 538 | default: |
---|
| 539 | goto return_error; |
---|
[258] | 540 | } |
---|
| 541 | |
---|
[295] | 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; |
---|
[258] | 550 | } |
---|
| 551 | |
---|
[295] | 552 | return_error: |
---|
[345] | 553 | return 1; |
---|
| 554 | } // end __printf() |
---|
[295] | 555 | |
---|
[345] | 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); |
---|
[295] | 564 | va_end( args ); |
---|
[345] | 565 | |
---|
| 566 | if (ret) |
---|
| 567 | { |
---|
[709] | 568 | giet_pthread_exit("error in giet_tty_printf()"); |
---|
[345] | 569 | } |
---|
[295] | 570 | } // end giet_tty_printf() |
---|
| 571 | |
---|
| 572 | ///////////////////////////////// |
---|
| 573 | void giet_tty_getc( char * byte ) |
---|
| 574 | { |
---|
| 575 | int ret; |
---|
| 576 | |
---|
| 577 | do |
---|
[267] | 578 | { |
---|
[295] | 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); |
---|
[709] | 584 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getc()"); |
---|
[267] | 585 | } |
---|
[295] | 586 | while (ret != 1); |
---|
| 587 | } |
---|
[267] | 588 | |
---|
[295] | 589 | ///////////////////////////////////// |
---|
| 590 | void giet_tty_gets( char* buf, |
---|
| 591 | unsigned int bufsize ) |
---|
| 592 | { |
---|
[647] | 593 | int ret; // return value from syscalls |
---|
[295] | 594 | unsigned char byte; |
---|
| 595 | unsigned int index = 0; |
---|
[647] | 596 | unsigned int string_cancel = 0x00082008; // string containing BS/SPACE/BS |
---|
[295] | 597 | |
---|
| 598 | while (index < (bufsize - 1)) |
---|
| 599 | { |
---|
[647] | 600 | // get one character |
---|
[295] | 601 | do |
---|
| 602 | { |
---|
| 603 | ret = sys_call(SYSCALL_TTY_READ, |
---|
| 604 | (unsigned int)(&byte), |
---|
| 605 | 1, |
---|
[647] | 606 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 607 | 0); |
---|
[709] | 608 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()"); |
---|
[295] | 609 | } |
---|
| 610 | while (ret != 1); |
---|
| 611 | |
---|
[647] | 612 | // analyse character |
---|
| 613 | if (byte == 0x0A) // LF special character |
---|
[295] | 614 | { |
---|
| 615 | break; |
---|
| 616 | } |
---|
[647] | 617 | else if ( (byte == 0x7F) || // DEL special character |
---|
| 618 | (byte == 0x08) ) // BS special character |
---|
[295] | 619 | { |
---|
[647] | 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 ); |
---|
[709] | 630 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()"); |
---|
[647] | 631 | } |
---|
[295] | 632 | } |
---|
[647] | 633 | else if ( (byte < 0x20) || (byte > 0x7F) ) // non printable characters |
---|
[295] | 634 | { |
---|
[647] | 635 | } |
---|
| 636 | else // take all other characters |
---|
| 637 | { |
---|
[295] | 638 | buf[index] = byte; |
---|
| 639 | index++; |
---|
[647] | 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 ); |
---|
[709] | 647 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()"); |
---|
[647] | 648 | |
---|
[295] | 649 | } |
---|
| 650 | } |
---|
| 651 | buf[index] = 0; |
---|
[258] | 652 | |
---|
[647] | 653 | } // end giet_tty_gets() |
---|
| 654 | |
---|
[295] | 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, |
---|
[647] | 678 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 679 | 0); |
---|
[709] | 680 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
---|
[295] | 681 | } |
---|
| 682 | while (ret != 1); |
---|
[258] | 683 | |
---|
[295] | 684 | // analyse character |
---|
[647] | 685 | if ((string_byte > 0x2F) && (string_byte < 0x3A)) // decimal character |
---|
[295] | 686 | { |
---|
| 687 | buf[length] = (unsigned char)string_byte; |
---|
| 688 | length++; |
---|
[258] | 689 | |
---|
[295] | 690 | // echo |
---|
| 691 | ret = sys_call( SYSCALL_TTY_WRITE, |
---|
| 692 | (unsigned int)(&string_byte), |
---|
| 693 | 1, |
---|
[647] | 694 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 695 | 0 ); |
---|
[709] | 696 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
---|
[295] | 697 | } |
---|
[647] | 698 | else if (string_byte == 0x0A) // LF character |
---|
[295] | 699 | { |
---|
| 700 | done = 1; |
---|
| 701 | } |
---|
[647] | 702 | else if ( (string_byte == 0x7F) || // DEL character |
---|
| 703 | (string_byte == 0x08) ) // BS character |
---|
[295] | 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, |
---|
[647] | 712 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 713 | 0 ); |
---|
[709] | 714 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
---|
[295] | 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, |
---|
[647] | 751 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 752 | 0 ); |
---|
[709] | 753 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
---|
[295] | 754 | } |
---|
| 755 | // echo character '0' |
---|
| 756 | string_byte = 0x30; |
---|
| 757 | ret = sys_call( SYSCALL_TTY_WRITE, |
---|
| 758 | (unsigned int)(&string_byte), |
---|
| 759 | 1, |
---|
[647] | 760 | 0xFFFFFFFF, // channel index from task context |
---|
[295] | 761 | 0 ); |
---|
[709] | 762 | if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()"); |
---|
[295] | 763 | |
---|
| 764 | // return 0 value |
---|
| 765 | *val = 0; |
---|
| 766 | } |
---|
[647] | 767 | } // end giet_tty_getw() |
---|
[295] | 768 | |
---|
| 769 | |
---|
[258] | 770 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 771 | // TIMER related system calls |
---|
[258] | 772 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 773 | |
---|
[295] | 774 | /////////////////////// |
---|
[438] | 775 | void giet_timer_alloc() |
---|
[258] | 776 | { |
---|
[438] | 777 | if ( sys_call( SYSCALL_TIM_ALLOC, |
---|
[709] | 778 | 0, 0, 0, 0 ) ) giet_pthread_exit("error in giet_timer_alloc()"); |
---|
[258] | 779 | } |
---|
[295] | 780 | |
---|
[438] | 781 | //////////////////////////////////////////// |
---|
| 782 | void giet_timer_start( unsigned int period ) |
---|
| 783 | { |
---|
| 784 | if ( sys_call( SYSCALL_TIM_START, |
---|
| 785 | period, |
---|
[709] | 786 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_timer_start()"); |
---|
[438] | 787 | } |
---|
| 788 | |
---|
[295] | 789 | ////////////////////// |
---|
| 790 | void giet_timer_stop() |
---|
[258] | 791 | { |
---|
[438] | 792 | if ( sys_call( SYSCALL_TIM_STOP, |
---|
[709] | 793 | 0, 0, 0, 0 ) ) giet_pthread_exit("error in giet_timer_stop()"); |
---|
[258] | 794 | } |
---|
| 795 | |
---|
| 796 | |
---|
| 797 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 798 | // Frame buffer related system calls |
---|
[258] | 799 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 800 | |
---|
[438] | 801 | ///////////////////////// |
---|
| 802 | void giet_fbf_cma_alloc() |
---|
[258] | 803 | { |
---|
[438] | 804 | if ( sys_call( SYSCALL_FBF_CMA_ALLOC, |
---|
[709] | 805 | 0, 0, 0, 0 ) ) giet_pthread_exit("error in giet_fbf_cma_alloc()"); |
---|
[258] | 806 | } |
---|
[295] | 807 | |
---|
| 808 | /////////////////////////////////////////// |
---|
[614] | 809 | void giet_fbf_cma_init_buf( void* buf0_vbase, |
---|
| 810 | void* buf1_vbase, |
---|
| 811 | void* sts0_vaddr, |
---|
| 812 | void* sts1_vaddr ) |
---|
[258] | 813 | { |
---|
[614] | 814 | if ( sys_call( SYSCALL_FBF_CMA_INIT_BUF, |
---|
| 815 | (unsigned int)buf0_vbase, |
---|
| 816 | (unsigned int)buf1_vbase, |
---|
| 817 | (unsigned int)sts0_vaddr, |
---|
[709] | 818 | (unsigned int)sts1_vaddr ) ) giet_pthread_exit("error in giet_fbf_cma_init_buf()"); |
---|
[614] | 819 | } |
---|
| 820 | |
---|
| 821 | /////////////////////////////////////////// |
---|
| 822 | void giet_fbf_cma_start( unsigned int length ) |
---|
| 823 | { |
---|
[438] | 824 | if ( sys_call( SYSCALL_FBF_CMA_START, |
---|
[614] | 825 | length, |
---|
[709] | 826 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_fbf_cma_start()"); |
---|
[258] | 827 | } |
---|
[295] | 828 | |
---|
[438] | 829 | //////////////////////////////////////////////// |
---|
| 830 | void giet_fbf_cma_display( unsigned int buffer ) |
---|
[258] | 831 | { |
---|
[438] | 832 | if ( sys_call( SYSCALL_FBF_CMA_DISPLAY, |
---|
| 833 | buffer, |
---|
[709] | 834 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_fbf_cma_display()"); |
---|
[258] | 835 | } |
---|
[295] | 836 | |
---|
| 837 | //////////////////////// |
---|
[438] | 838 | void giet_fbf_cma_stop() |
---|
[258] | 839 | { |
---|
[438] | 840 | if ( sys_call( SYSCALL_FBF_CMA_STOP, |
---|
[709] | 841 | 0, 0, 0, 0 ) ) giet_pthread_exit("error in giet_fbf_cma_stop()"); |
---|
[258] | 842 | } |
---|
| 843 | |
---|
[438] | 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, |
---|
[709] | 853 | 0 ) ) giet_pthread_exit("error in giet_fbf_sync_write()"); |
---|
[438] | 854 | } |
---|
[258] | 855 | |
---|
[438] | 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, |
---|
[709] | 865 | 0 ) ) giet_pthread_exit("error in giet_fbf_sync_read()"); |
---|
[438] | 866 | } |
---|
| 867 | |
---|
| 868 | |
---|
[258] | 869 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 870 | // NIC related system calls |
---|
[258] | 871 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 872 | |
---|
[709] | 873 | ////////////////////////////////////////// |
---|
| 874 | void giet_nic_rx_alloc( unsigned int xmax, |
---|
| 875 | unsigned int ymax ) |
---|
[258] | 876 | { |
---|
[709] | 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()"); |
---|
[258] | 882 | } |
---|
[295] | 883 | |
---|
[709] | 884 | ////////////////////////////////////////// |
---|
| 885 | void giet_nic_tx_alloc( unsigned int xmax, |
---|
| 886 | unsigned int ymax ) |
---|
[258] | 887 | { |
---|
[709] | 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()"); |
---|
[450] | 893 | } |
---|
| 894 | |
---|
[709] | 895 | //////////////////////// |
---|
| 896 | void giet_nic_rx_start() |
---|
[450] | 897 | { |
---|
[461] | 898 | if ( sys_call( SYSCALL_NIC_START, |
---|
[709] | 899 | 1, // RX |
---|
| 900 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_start()"); |
---|
[450] | 901 | } |
---|
| 902 | |
---|
[709] | 903 | //////////////////////// |
---|
| 904 | void giet_nic_tx_start() |
---|
[450] | 905 | { |
---|
[461] | 906 | if ( sys_call( SYSCALL_NIC_START, |
---|
[709] | 907 | 0, // TX |
---|
| 908 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_start()"); |
---|
[450] | 909 | } |
---|
| 910 | |
---|
[709] | 911 | ///////////////////////////////////// |
---|
| 912 | void giet_nic_rx_move( void* buffer ) |
---|
[450] | 913 | { |
---|
[461] | 914 | if ( sys_call( SYSCALL_NIC_MOVE, |
---|
[709] | 915 | 1, // RX |
---|
[438] | 916 | (unsigned int)buffer, |
---|
[709] | 917 | 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_move()"); |
---|
[258] | 918 | } |
---|
| 919 | |
---|
[709] | 920 | ///////////////////////////////////// |
---|
| 921 | void giet_nic_tx_move( void* buffer ) |
---|
[438] | 922 | { |
---|
[461] | 923 | if ( sys_call( SYSCALL_NIC_MOVE, |
---|
[709] | 924 | 0, // TX |
---|
[438] | 925 | (unsigned int)buffer, |
---|
[709] | 926 | 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_move()"); |
---|
[438] | 927 | } |
---|
| 928 | |
---|
[709] | 929 | /////////////////////// |
---|
| 930 | void giet_nic_rx_stop() |
---|
[450] | 931 | { |
---|
[461] | 932 | if ( sys_call( SYSCALL_NIC_STOP, |
---|
[709] | 933 | 1, // RX |
---|
| 934 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stop()"); |
---|
[450] | 935 | } |
---|
| 936 | |
---|
[709] | 937 | /////////////////////// |
---|
| 938 | void giet_nic_tx_stop() |
---|
[450] | 939 | { |
---|
[461] | 940 | if ( sys_call( SYSCALL_NIC_STOP, |
---|
[709] | 941 | 0, // TX |
---|
| 942 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stop()"); |
---|
[450] | 943 | } |
---|
| 944 | |
---|
[709] | 945 | //////////////////////// |
---|
| 946 | void giet_nic_rx_stats() |
---|
[461] | 947 | { |
---|
| 948 | if ( sys_call( SYSCALL_NIC_STATS, |
---|
[709] | 949 | 1, // RX |
---|
| 950 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stats()"); |
---|
[461] | 951 | } |
---|
[450] | 952 | |
---|
[709] | 953 | //////////////////////// |
---|
| 954 | void giet_nic_tx_stats() |
---|
[461] | 955 | { |
---|
| 956 | if ( sys_call( SYSCALL_NIC_STATS, |
---|
[709] | 957 | 0, // TX |
---|
| 958 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stats()"); |
---|
[461] | 959 | } |
---|
| 960 | |
---|
[709] | 961 | //////////////////////// |
---|
| 962 | void giet_nic_rx_clear() |
---|
[461] | 963 | { |
---|
| 964 | if ( sys_call( SYSCALL_NIC_CLEAR, |
---|
[709] | 965 | 1, // RX |
---|
| 966 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_clear()"); |
---|
[461] | 967 | } |
---|
| 968 | |
---|
[709] | 969 | //////////////////////// |
---|
| 970 | void giet_nic_tx_clear() |
---|
[461] | 971 | { |
---|
| 972 | if ( sys_call( SYSCALL_NIC_CLEAR, |
---|
[709] | 973 | 0, // TX |
---|
| 974 | 0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_clear()"); |
---|
[461] | 975 | } |
---|
| 976 | |
---|
| 977 | |
---|
| 978 | |
---|
[295] | 979 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 980 | // FAT related system calls |
---|
[295] | 981 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 982 | |
---|
[588] | 983 | ///////////////////////////////////////// |
---|
| 984 | int giet_fat_open( char* pathname, |
---|
| 985 | unsigned int flags ) |
---|
[295] | 986 | { |
---|
[588] | 987 | return sys_call( SYSCALL_FAT_OPEN, |
---|
| 988 | (unsigned int)pathname, |
---|
| 989 | flags, |
---|
| 990 | 0, 0 ); |
---|
[295] | 991 | } |
---|
[258] | 992 | |
---|
[588] | 993 | ///////////////////////////////////////// |
---|
| 994 | int giet_fat_close( unsigned int fd_id ) |
---|
[295] | 995 | { |
---|
[588] | 996 | return sys_call( SYSCALL_FAT_CLOSE, |
---|
| 997 | fd_id, |
---|
| 998 | 0, 0, 0 ); |
---|
[295] | 999 | } |
---|
| 1000 | |
---|
[588] | 1001 | ///////////////////////////////////////////// |
---|
[623] | 1002 | int giet_fat_file_info( unsigned int fd_id, |
---|
| 1003 | struct fat_file_info_s* info ) |
---|
[295] | 1004 | { |
---|
[588] | 1005 | return sys_call( SYSCALL_FAT_FINFO, |
---|
| 1006 | fd_id, |
---|
[623] | 1007 | (unsigned int)info, |
---|
| 1008 | 0, 0 ); |
---|
[295] | 1009 | } |
---|
| 1010 | |
---|
[588] | 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, |
---|
[709] | 1020 | 0 ); // no physical addressing required |
---|
[588] | 1021 | } |
---|
| 1022 | |
---|
| 1023 | //////////////////////////////////////// |
---|
| 1024 | int giet_fat_write( unsigned int fd_id, |
---|
[295] | 1025 | void* buffer, |
---|
[588] | 1026 | unsigned int count ) |
---|
[258] | 1027 | { |
---|
[295] | 1028 | return sys_call( SYSCALL_FAT_WRITE, |
---|
[588] | 1029 | fd_id, |
---|
[295] | 1030 | (unsigned int)buffer, |
---|
[588] | 1031 | count, |
---|
[709] | 1032 | 0 ); // no physical addressing required |
---|
[258] | 1033 | } |
---|
[295] | 1034 | |
---|
[588] | 1035 | //////////////////////////////////////// |
---|
| 1036 | int giet_fat_lseek( unsigned int fd_id, |
---|
[295] | 1037 | unsigned int offset, |
---|
| 1038 | unsigned int whence ) |
---|
[258] | 1039 | { |
---|
[588] | 1040 | return sys_call( SYSCALL_FAT_LSEEK, |
---|
| 1041 | fd_id, |
---|
| 1042 | offset, |
---|
| 1043 | whence, |
---|
| 1044 | 0 ); |
---|
[258] | 1045 | } |
---|
[295] | 1046 | |
---|
[588] | 1047 | //////////////////////////////////////////// |
---|
| 1048 | int giet_fat_remove( char* pathname, |
---|
| 1049 | unsigned int should_be_dir ) |
---|
[258] | 1050 | { |
---|
[588] | 1051 | return sys_call( SYSCALL_FAT_REMOVE, |
---|
| 1052 | (unsigned int)pathname, |
---|
| 1053 | should_be_dir, |
---|
| 1054 | 0, 0 ); |
---|
[258] | 1055 | } |
---|
[295] | 1056 | |
---|
| 1057 | ///////////////////////////////////// |
---|
[588] | 1058 | int giet_fat_rename( char* old_path, |
---|
| 1059 | char* new_path ) |
---|
[258] | 1060 | { |
---|
[588] | 1061 | return sys_call( SYSCALL_FAT_RENAME, |
---|
| 1062 | (unsigned int)old_path, |
---|
| 1063 | (unsigned int)new_path, |
---|
| 1064 | 0, 0 ); |
---|
[258] | 1065 | } |
---|
[295] | 1066 | |
---|
[588] | 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 | } |
---|
[295] | 1074 | |
---|
[659] | 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 | |
---|
[295] | 1101 | |
---|
| 1102 | |
---|
[390] | 1103 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 1104 | // Miscellaneous system calls |
---|
[390] | 1105 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 1106 | |
---|
[501] | 1107 | ///////////////////////////////////////////////// |
---|
| 1108 | void giet_procs_number( unsigned int* x_size, |
---|
| 1109 | unsigned int* y_size, |
---|
| 1110 | unsigned int* nprocs ) |
---|
[438] | 1111 | { |
---|
[501] | 1112 | if ( sys_call( SYSCALL_PROCS_NUMBER, |
---|
| 1113 | (unsigned int)x_size, |
---|
| 1114 | (unsigned int)y_size, |
---|
| 1115 | (unsigned int)nprocs, |
---|
[709] | 1116 | 0 ) ) giet_pthread_exit("error in giet_procs_number()"); |
---|
[438] | 1117 | } |
---|
| 1118 | |
---|
[295] | 1119 | //////////////////////////////////////////////////// |
---|
| 1120 | void giet_vobj_get_vbase( char* vspace_name, |
---|
| 1121 | char* vobj_name, |
---|
[438] | 1122 | unsigned int* vbase ) |
---|
[258] | 1123 | { |
---|
[295] | 1124 | if ( sys_call( SYSCALL_VOBJ_GET_VBASE, |
---|
| 1125 | (unsigned int) vspace_name, |
---|
| 1126 | (unsigned int) vobj_name, |
---|
[438] | 1127 | (unsigned int) vbase, |
---|
[709] | 1128 | 0 ) ) giet_pthread_exit("error in giet_vobj_get_vbase()"); |
---|
[258] | 1129 | } |
---|
[260] | 1130 | |
---|
[438] | 1131 | //////////////////////////////////////////////////// |
---|
| 1132 | void giet_vobj_get_length( char* vspace_name, |
---|
| 1133 | char* vobj_name, |
---|
| 1134 | unsigned int* length ) |
---|
[260] | 1135 | { |
---|
[438] | 1136 | if ( sys_call( SYSCALL_VOBJ_GET_LENGTH, |
---|
| 1137 | (unsigned int) vspace_name, |
---|
| 1138 | (unsigned int) vobj_name, |
---|
| 1139 | (unsigned int) length, |
---|
[709] | 1140 | 0 ) ) giet_pthread_exit("error in giet_vobj_get_length()"); |
---|
[260] | 1141 | } |
---|
| 1142 | |
---|
[295] | 1143 | ///////////////////////////////////////// |
---|
| 1144 | void giet_heap_info( unsigned int* vaddr, |
---|
[368] | 1145 | unsigned int* length, |
---|
| 1146 | unsigned int x, |
---|
| 1147 | unsigned int y ) |
---|
[258] | 1148 | { |
---|
[709] | 1149 | sys_call( SYSCALL_HEAP_INFO, |
---|
| 1150 | (unsigned int)vaddr, |
---|
| 1151 | (unsigned int)length, |
---|
| 1152 | x, |
---|
| 1153 | y ); |
---|
[258] | 1154 | } |
---|
| 1155 | |
---|
[390] | 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, |
---|
[709] | 1165 | 0 ) ) giet_pthread_exit("error in giet_get_xy()"); |
---|
[390] | 1166 | } |
---|
| 1167 | |
---|
[258] | 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 | |
---|