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