| 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 | |
|---|
| 145 | printf_text: |
|---|
| 146 | |
|---|
| 147 | while (*format) |
|---|
| 148 | { |
|---|
| 149 | unsigned int i; |
|---|
| 150 | for (i = 0 ; format[i] && (format[i] != '%') ; i++); |
|---|
| 151 | if (i) |
|---|
| 152 | { |
|---|
| 153 | ret = sys_call(SYSCALL_TTY_WRITE, |
|---|
| 154 | (unsigned int)format, |
|---|
| 155 | i, |
|---|
| 156 | channel, |
|---|
| 157 | 0); |
|---|
| 158 | |
|---|
| 159 | if (ret != i) goto return_error; |
|---|
| 160 | |
|---|
| 161 | format += i; |
|---|
| 162 | } |
|---|
| 163 | if (*format == '%') |
|---|
| 164 | { |
|---|
| 165 | format++; |
|---|
| 166 | goto printf_arguments; |
|---|
| 167 | } |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | return 0; |
|---|
| 171 | |
|---|
| 172 | printf_arguments: |
|---|
| 173 | |
|---|
| 174 | { |
|---|
| 175 | char buf[20]; |
|---|
| 176 | char * pbuf; |
|---|
| 177 | unsigned int len = 0; |
|---|
| 178 | static const char HexaTab[] = "0123456789ABCDEF"; |
|---|
| 179 | unsigned int i; |
|---|
| 180 | |
|---|
| 181 | switch (*format++) |
|---|
| 182 | { |
|---|
| 183 | case ('c'): /* char conversion */ |
|---|
| 184 | { |
|---|
| 185 | int val = va_arg( *args, int ); |
|---|
| 186 | len = 1; |
|---|
| 187 | buf[0] = val; |
|---|
| 188 | pbuf = &buf[0]; |
|---|
| 189 | break; |
|---|
| 190 | } |
|---|
| 191 | case ('d'): /* 32 bits decimal signed integer */ |
|---|
| 192 | { |
|---|
| 193 | int val = va_arg( *args, int ); |
|---|
| 194 | if (val < 0) |
|---|
| 195 | { |
|---|
| 196 | val = -val; |
|---|
| 197 | ret = sys_call(SYSCALL_TTY_WRITE, |
|---|
| 198 | (unsigned int)"-", |
|---|
| 199 | 1, |
|---|
| 200 | channel, |
|---|
| 201 | 0); |
|---|
| 202 | if (ret != 1) goto return_error; |
|---|
| 203 | } |
|---|
| 204 | for(i = 0; i < 10; i++) |
|---|
| 205 | { |
|---|
| 206 | buf[9 - i] = HexaTab[val % 10]; |
|---|
| 207 | if (!(val /= 10)) break; |
|---|
| 208 | } |
|---|
| 209 | len = i + 1; |
|---|
| 210 | pbuf = &buf[9 - i]; |
|---|
| 211 | break; |
|---|
| 212 | } |
|---|
| 213 | case ('u'): /* 32 bits decimal unsigned integer */ |
|---|
| 214 | { |
|---|
| 215 | unsigned int val = va_arg( *args, unsigned int ); |
|---|
| 216 | for(i = 0; i < 10; i++) |
|---|
| 217 | { |
|---|
| 218 | buf[9 - i] = HexaTab[val % 10]; |
|---|
| 219 | if (!(val /= 10)) break; |
|---|
| 220 | } |
|---|
| 221 | len = i + 1; |
|---|
| 222 | pbuf = &buf[9 - i]; |
|---|
| 223 | break; |
|---|
| 224 | } |
|---|
| 225 | case ('x'): /* 32 bits hexadecimal integer */ |
|---|
| 226 | { |
|---|
| 227 | unsigned int val = va_arg( *args, unsigned int ); |
|---|
| 228 | ret = sys_call(SYSCALL_TTY_WRITE, |
|---|
| 229 | (unsigned int)"0x", |
|---|
| 230 | 2, |
|---|
| 231 | channel, |
|---|
| 232 | 0); |
|---|
| 233 | if (ret != 2) goto return_error; |
|---|
| 234 | for(i = 0; i < 8; i++) |
|---|
| 235 | { |
|---|
| 236 | buf[7 - i] = HexaTab[val % 16]; |
|---|
| 237 | if (!(val /= 16)) break; |
|---|
| 238 | } |
|---|
| 239 | len = i + 1; |
|---|
| 240 | pbuf = &buf[7 - i]; |
|---|
| 241 | break; |
|---|
| 242 | } |
|---|
| 243 | case ('l'): /* 64 bits hexadecimal unsigned */ |
|---|
| 244 | { |
|---|
| 245 | unsigned long long val = va_arg( *args, unsigned long long ); |
|---|
| 246 | ret = sys_call(SYSCALL_TTY_WRITE, |
|---|
| 247 | (unsigned int)"0x", |
|---|
| 248 | 2, |
|---|
| 249 | channel, |
|---|
| 250 | 0); |
|---|
| 251 | if (ret != 2) goto return_error; |
|---|
| 252 | for(i = 0; i < 16; i++) |
|---|
| 253 | { |
|---|
| 254 | buf[15 - i] = HexaTab[val % 16]; |
|---|
| 255 | if (!(val /= 16)) break; |
|---|
| 256 | } |
|---|
| 257 | len = i + 1; |
|---|
| 258 | pbuf = &buf[15 - i]; |
|---|
| 259 | break; |
|---|
| 260 | } |
|---|
| 261 | case ('s'): /* string */ |
|---|
| 262 | { |
|---|
| 263 | char* str = va_arg( *args, char* ); |
|---|
| 264 | while (str[len]) |
|---|
| 265 | { |
|---|
| 266 | len++; |
|---|
| 267 | } |
|---|
| 268 | pbuf = str; |
|---|
| 269 | break; |
|---|
| 270 | } |
|---|
| 271 | default: |
|---|
| 272 | goto return_error; |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | ret = sys_call(SYSCALL_TTY_WRITE, |
|---|
| 276 | (unsigned int)pbuf, |
|---|
| 277 | len, |
|---|
| 278 | channel, |
|---|
| 279 | 0); |
|---|
| 280 | if (ret != len) goto return_error; |
|---|
| 281 | |
|---|
| 282 | goto printf_text; |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | return_error: |
|---|
| 286 | return 1; |
|---|
| 287 | } // end __printf() |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | //////////////////////////////////////// |
|---|
| 291 | void giet_tty_printf( char* format, ...) |
|---|
| 292 | { |
|---|
| 293 | va_list args; |
|---|
| 294 | |
|---|
| 295 | va_start( args, format ); |
|---|
| 296 | int ret = __printf(format, 0xFFFFFFFF, &args); |
|---|
| 297 | va_end( args ); |
|---|
| 298 | |
|---|
| 299 | if (ret) |
|---|
| 300 | { |
|---|
| 301 | giet_exit("ERROR in giet_tty_printf()"); |
|---|
| 302 | } |
|---|
| 303 | } // end giet_tty_printf() |
|---|
| 304 | |
|---|
| 305 | //////////////////////////////////////// |
|---|
| 306 | void giet_shr_printf( char* format, ...) |
|---|
| 307 | { |
|---|
| 308 | va_list args; |
|---|
| 309 | volatile unsigned int sr_save; |
|---|
| 310 | |
|---|
| 311 | sys_call( SYSCALL_TTY_GET_LOCK, |
|---|
| 312 | 0, |
|---|
| 313 | (unsigned int)&sr_save, |
|---|
| 314 | 0, 0 ); |
|---|
| 315 | |
|---|
| 316 | va_start( args, format ); |
|---|
| 317 | int ret = __printf(format, 0, &args); |
|---|
| 318 | va_end( args ); |
|---|
| 319 | |
|---|
| 320 | sys_call( SYSCALL_TTY_RELEASE_LOCK, |
|---|
| 321 | 0, |
|---|
| 322 | (unsigned int)&sr_save, |
|---|
| 323 | 0, 0 ); |
|---|
| 324 | |
|---|
| 325 | if (ret) |
|---|
| 326 | { |
|---|
| 327 | giet_exit("error in giet_shr_printf()"); |
|---|
| 328 | } |
|---|
| 329 | } // end giet_shr_printf() |
|---|
| 330 | |
|---|
| 331 | ///////////////////////////////// |
|---|
| 332 | void giet_tty_getc( char * byte ) |
|---|
| 333 | { |
|---|
| 334 | int ret; |
|---|
| 335 | |
|---|
| 336 | do |
|---|
| 337 | { |
|---|
| 338 | ret = sys_call(SYSCALL_TTY_READ, |
|---|
| 339 | (unsigned int)byte, // buffer address |
|---|
| 340 | 1, // number of characters |
|---|
| 341 | 0xFFFFFFFF, // channel index from task context |
|---|
| 342 | 0); |
|---|
| 343 | if ( ret < 0 ) giet_exit("error in giet_tty_getc()"); |
|---|
| 344 | } |
|---|
| 345 | while (ret != 1); |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | ///////////////////////////////////// |
|---|
| 349 | void giet_tty_gets( char* buf, |
|---|
| 350 | unsigned int bufsize ) |
|---|
| 351 | { |
|---|
| 352 | int ret; |
|---|
| 353 | unsigned char byte; |
|---|
| 354 | unsigned int index = 0; |
|---|
| 355 | |
|---|
| 356 | while (index < (bufsize - 1)) |
|---|
| 357 | { |
|---|
| 358 | do |
|---|
| 359 | { |
|---|
| 360 | ret = sys_call(SYSCALL_TTY_READ, |
|---|
| 361 | (unsigned int)(&byte), |
|---|
| 362 | 1, |
|---|
| 363 | 0xFFFFFFFF, |
|---|
| 364 | 0); |
|---|
| 365 | if ( ret < 0 ) giet_exit("error in giet_tty_gets()"); |
|---|
| 366 | } |
|---|
| 367 | while (ret != 1); |
|---|
| 368 | |
|---|
| 369 | if (byte == 0x0A) /* LF */ |
|---|
| 370 | { |
|---|
| 371 | break; |
|---|
| 372 | } |
|---|
| 373 | else if ((byte == 0x7F) && (index > 0)) /* DEL */ |
|---|
| 374 | { |
|---|
| 375 | index--; |
|---|
| 376 | } |
|---|
| 377 | else |
|---|
| 378 | { |
|---|
| 379 | buf[index] = byte; |
|---|
| 380 | index++; |
|---|
| 381 | } |
|---|
| 382 | } |
|---|
| 383 | buf[index] = 0; |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | /////////////////////////////////////// |
|---|
| 387 | void giet_tty_getw( unsigned int* val ) |
|---|
| 388 | { |
|---|
| 389 | unsigned char buf[32]; |
|---|
| 390 | unsigned int string_byte = 0x00000000; // string containing one single byte |
|---|
| 391 | unsigned int string_cancel = 0x00082008; // string containing BS/SPACE/BS |
|---|
| 392 | unsigned int save = 0; |
|---|
| 393 | unsigned int dec = 0; |
|---|
| 394 | unsigned int done = 0; |
|---|
| 395 | unsigned int overflow = 0; |
|---|
| 396 | unsigned int length = 0; |
|---|
| 397 | unsigned int i; |
|---|
| 398 | unsigned int channel = 0xFFFFFFFF; |
|---|
| 399 | int ret; // return value from syscalls |
|---|
| 400 | |
|---|
| 401 | // get characters |
|---|
| 402 | while (done == 0) |
|---|
| 403 | { |
|---|
| 404 | // read one character |
|---|
| 405 | do |
|---|
| 406 | { |
|---|
| 407 | ret = sys_call( SYSCALL_TTY_READ, |
|---|
| 408 | (unsigned int)(&string_byte), |
|---|
| 409 | 1, |
|---|
| 410 | channel, |
|---|
| 411 | 0); |
|---|
| 412 | if ( ret < 0 ) giet_exit("error in giet_tty_getw()"); |
|---|
| 413 | } |
|---|
| 414 | while (ret != 1); |
|---|
| 415 | |
|---|
| 416 | // analyse character |
|---|
| 417 | if ((string_byte > 0x2F) && (string_byte < 0x3A)) /* decimal character */ |
|---|
| 418 | { |
|---|
| 419 | buf[length] = (unsigned char)string_byte; |
|---|
| 420 | length++; |
|---|
| 421 | |
|---|
| 422 | // echo |
|---|
| 423 | ret = sys_call( SYSCALL_TTY_WRITE, |
|---|
| 424 | (unsigned int)(&string_byte), |
|---|
| 425 | 1, |
|---|
| 426 | channel, |
|---|
| 427 | 0 ); |
|---|
| 428 | if ( ret < 0 ) giet_exit("error in giet_tty_gets()"); |
|---|
| 429 | } |
|---|
| 430 | else if (string_byte == 0x0A) /* LF character */ |
|---|
| 431 | { |
|---|
| 432 | done = 1; |
|---|
| 433 | } |
|---|
| 434 | else if ( (string_byte == 0x7F) || /* DEL character */ |
|---|
| 435 | (string_byte == 0x08) ) /* BS character */ |
|---|
| 436 | { |
|---|
| 437 | if ( length > 0 ) |
|---|
| 438 | { |
|---|
| 439 | length--; // cancel the character |
|---|
| 440 | |
|---|
| 441 | ret = sys_call( SYSCALL_TTY_WRITE, |
|---|
| 442 | (unsigned int)(&string_cancel), |
|---|
| 443 | 3, |
|---|
| 444 | channel, |
|---|
| 445 | 0 ); |
|---|
| 446 | if ( ret < 0 ) giet_exit("error in giet_tty_getw()"); |
|---|
| 447 | } |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | // test buffer overflow |
|---|
| 451 | if ( length >= 32 ) |
|---|
| 452 | { |
|---|
| 453 | overflow = 1; |
|---|
| 454 | done = 1; |
|---|
| 455 | } |
|---|
| 456 | } // end while characters |
|---|
| 457 | |
|---|
| 458 | // string to int conversion with overflow detection |
|---|
| 459 | if ( overflow == 0 ) |
|---|
| 460 | { |
|---|
| 461 | for (i = 0; (i < length) && (overflow == 0) ; i++) |
|---|
| 462 | { |
|---|
| 463 | dec = dec * 10 + (buf[i] - 0x30); |
|---|
| 464 | if (dec < save) overflow = 1; |
|---|
| 465 | save = dec; |
|---|
| 466 | } |
|---|
| 467 | } |
|---|
| 468 | |
|---|
| 469 | // final evaluation |
|---|
| 470 | if ( overflow == 0 ) |
|---|
| 471 | { |
|---|
| 472 | // return value |
|---|
| 473 | *val = dec; |
|---|
| 474 | } |
|---|
| 475 | else |
|---|
| 476 | { |
|---|
| 477 | // cancel all echo characters |
|---|
| 478 | for (i = 0; i < length ; i++) |
|---|
| 479 | { |
|---|
| 480 | ret = sys_call( SYSCALL_TTY_WRITE, |
|---|
| 481 | (unsigned int)(&string_cancel), |
|---|
| 482 | 3, |
|---|
| 483 | channel, |
|---|
| 484 | 0 ); |
|---|
| 485 | if ( ret < 0 ) giet_exit("error in giet_tty_getw()"); |
|---|
| 486 | } |
|---|
| 487 | // echo character '0' |
|---|
| 488 | string_byte = 0x30; |
|---|
| 489 | ret = sys_call( SYSCALL_TTY_WRITE, |
|---|
| 490 | (unsigned int)(&string_byte), |
|---|
| 491 | 1, |
|---|
| 492 | channel, |
|---|
| 493 | 0 ); |
|---|
| 494 | if ( ret < 0 ) giet_exit("error in giet_tty_getw()"); |
|---|
| 495 | |
|---|
| 496 | // return 0 value |
|---|
| 497 | *val = 0; |
|---|
| 498 | } |
|---|
| 499 | } |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 503 | ///////////////////// TIMER related system calls //////////////////////////////// |
|---|
| 504 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 505 | |
|---|
| 506 | /////////////////////// |
|---|
| 507 | void giet_timer_alloc() |
|---|
| 508 | { |
|---|
| 509 | if ( sys_call( SYSCALL_TIM_ALLOC, |
|---|
| 510 | 0, 0, 0, 0 ) ) giet_exit("error in giet_timer_alloc()"); |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | //////////////////////////////////////////// |
|---|
| 514 | void giet_timer_start( unsigned int period ) |
|---|
| 515 | { |
|---|
| 516 | if ( sys_call( SYSCALL_TIM_START, |
|---|
| 517 | period, |
|---|
| 518 | 0, 0, 0 ) ) giet_exit("error in giet_timer_start()"); |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | ////////////////////// |
|---|
| 522 | void giet_timer_stop() |
|---|
| 523 | { |
|---|
| 524 | if ( sys_call( SYSCALL_TIM_STOP, |
|---|
| 525 | 0, 0, 0, 0 ) ) giet_exit("error in giet_timer_stop()"); |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 530 | /////////////// Frame buffer device related system calls /////////////////////// |
|---|
| 531 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 532 | |
|---|
| 533 | ///////////////////////// |
|---|
| 534 | void giet_fbf_cma_alloc() |
|---|
| 535 | { |
|---|
| 536 | if ( sys_call( SYSCALL_FBF_CMA_ALLOC, |
|---|
| 537 | 0, 0, 0, 0 ) ) giet_exit("error in giet_fbf_cma_alloc()"); |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | /////////////////////////////////////////// |
|---|
| 541 | void giet_fbf_cma_start( void * buf0, |
|---|
| 542 | void * buf1, |
|---|
| 543 | unsigned int length ) |
|---|
| 544 | { |
|---|
| 545 | if ( sys_call( SYSCALL_FBF_CMA_START, |
|---|
| 546 | (unsigned int)buf0, |
|---|
| 547 | (unsigned int)buf1, |
|---|
| 548 | length, |
|---|
| 549 | 0 ) ) giet_exit("error in giet_fbf_cma_start()"); |
|---|
| 550 | } |
|---|
| 551 | |
|---|
| 552 | //////////////////////////////////////////////// |
|---|
| 553 | void giet_fbf_cma_display( unsigned int buffer ) |
|---|
| 554 | { |
|---|
| 555 | if ( sys_call( SYSCALL_FBF_CMA_DISPLAY, |
|---|
| 556 | buffer, |
|---|
| 557 | 0, 0, 0 ) ) giet_exit("error in giet_fbf_cma_display()"); |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | //////////////////////// |
|---|
| 561 | void giet_fbf_cma_stop() |
|---|
| 562 | { |
|---|
| 563 | if ( sys_call( SYSCALL_FBF_CMA_STOP, |
|---|
| 564 | 0, 0, 0, 0 ) ) giet_exit("error in giet_fbf_cma_stop()"); |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | ////////////////////////////////////////////// |
|---|
| 568 | void giet_fbf_sync_write( unsigned int offset, |
|---|
| 569 | void * buffer, |
|---|
| 570 | unsigned int length ) |
|---|
| 571 | { |
|---|
| 572 | if ( sys_call( SYSCALL_FBF_SYNC_WRITE, |
|---|
| 573 | offset, |
|---|
| 574 | (unsigned int)buffer, |
|---|
| 575 | length, |
|---|
| 576 | 0 ) ) giet_exit("error in giet_fbf_sync_write()"); |
|---|
| 577 | } |
|---|
| 578 | |
|---|
| 579 | ///////////////////////////////////////////// |
|---|
| 580 | void giet_fbf_sync_read( unsigned int offset, |
|---|
| 581 | void * buffer, |
|---|
| 582 | unsigned int length ) |
|---|
| 583 | { |
|---|
| 584 | if ( sys_call( SYSCALL_FBF_SYNC_READ, |
|---|
| 585 | offset, |
|---|
| 586 | (unsigned int)buffer, |
|---|
| 587 | length, |
|---|
| 588 | 0 ) ) giet_exit("error in giet_fbf_sync_read()"); |
|---|
| 589 | } |
|---|
| 590 | |
|---|
| 591 | |
|---|
| 592 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 593 | /////////////////////// NIC related system calls ///////////////////////////////// |
|---|
| 594 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 595 | |
|---|
| 596 | //////////////////////////////////////////////////// |
|---|
| 597 | unsigned int giet_nic_rx_alloc( unsigned int xmax, |
|---|
| 598 | unsigned int ymax ) |
|---|
| 599 | { |
|---|
| 600 | int channel = sys_call( SYSCALL_NIC_ALLOC, |
|---|
| 601 | 1, |
|---|
| 602 | xmax, |
|---|
| 603 | ymax, |
|---|
| 604 | 0 ); |
|---|
| 605 | if ( channel < 0 ) giet_exit("error in giet_nic_rx_alloc()"); |
|---|
| 606 | |
|---|
| 607 | return (unsigned int)channel; |
|---|
| 608 | } |
|---|
| 609 | |
|---|
| 610 | //////////////////////////////////////////////////// |
|---|
| 611 | unsigned int giet_nic_tx_alloc( unsigned int xmax, |
|---|
| 612 | unsigned int ymax ) |
|---|
| 613 | { |
|---|
| 614 | int channel = sys_call( SYSCALL_NIC_ALLOC, |
|---|
| 615 | 0, |
|---|
| 616 | xmax, |
|---|
| 617 | ymax, |
|---|
| 618 | 0 ); |
|---|
| 619 | if ( channel < 0 ) giet_exit("error in giet_nic_tx_alloc()"); |
|---|
| 620 | |
|---|
| 621 | return (unsigned int)channel; |
|---|
| 622 | } |
|---|
| 623 | |
|---|
| 624 | ////////////////////////////////////////////// |
|---|
| 625 | void giet_nic_rx_start( unsigned int channel ) |
|---|
| 626 | { |
|---|
| 627 | if ( sys_call( SYSCALL_NIC_START, |
|---|
| 628 | 1, |
|---|
| 629 | channel, |
|---|
| 630 | 0, 0 ) ) giet_exit("error in giet_nic_rx_start()"); |
|---|
| 631 | } |
|---|
| 632 | |
|---|
| 633 | ////////////////////////////////////////////// |
|---|
| 634 | void giet_nic_tx_start( unsigned int channel ) |
|---|
| 635 | { |
|---|
| 636 | if ( sys_call( SYSCALL_NIC_START, |
|---|
| 637 | 0, |
|---|
| 638 | channel, |
|---|
| 639 | 0, 0 ) ) giet_exit("error in giet_nic_tx_start()"); |
|---|
| 640 | } |
|---|
| 641 | |
|---|
| 642 | /////////////////////////////////////////////////////////// |
|---|
| 643 | void giet_nic_rx_move( unsigned int channel, void* buffer ) |
|---|
| 644 | { |
|---|
| 645 | if ( sys_call( SYSCALL_NIC_MOVE, |
|---|
| 646 | 1, |
|---|
| 647 | channel, |
|---|
| 648 | (unsigned int)buffer, |
|---|
| 649 | 0 ) ) giet_exit("error in giet_nic_rx_move()"); |
|---|
| 650 | } |
|---|
| 651 | |
|---|
| 652 | /////////////////////////////////////////////////////////// |
|---|
| 653 | void giet_nic_tx_move( unsigned int channel, void* buffer ) |
|---|
| 654 | { |
|---|
| 655 | if ( sys_call( SYSCALL_NIC_MOVE, |
|---|
| 656 | 0, |
|---|
| 657 | channel, |
|---|
| 658 | (unsigned int)buffer, |
|---|
| 659 | 0 ) ) giet_exit("error in giet_nic_tx_move()"); |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | ///////////////////////////////////////////// |
|---|
| 663 | void giet_nic_rx_stop( unsigned int channel ) |
|---|
| 664 | { |
|---|
| 665 | if ( sys_call( SYSCALL_NIC_STOP, |
|---|
| 666 | 1, |
|---|
| 667 | channel, |
|---|
| 668 | 0, 0 ) ) giet_exit("error in giet_nic_rx_stop()"); |
|---|
| 669 | } |
|---|
| 670 | |
|---|
| 671 | ///////////////////////////////////////////// |
|---|
| 672 | void giet_nic_tx_stop( unsigned int channel ) |
|---|
| 673 | { |
|---|
| 674 | if ( sys_call( SYSCALL_NIC_STOP, |
|---|
| 675 | 0, |
|---|
| 676 | channel, |
|---|
| 677 | 0, 0 ) ) giet_exit("error in giet_nic_tx_stop()"); |
|---|
| 678 | } |
|---|
| 679 | |
|---|
| 680 | ////////////////////////////////////////////// |
|---|
| 681 | void giet_nic_rx_stats( unsigned int channel ) |
|---|
| 682 | { |
|---|
| 683 | if ( sys_call( SYSCALL_NIC_STATS, |
|---|
| 684 | 1, |
|---|
| 685 | channel, |
|---|
| 686 | 0, 0 ) ) giet_exit("error in giet_nic_rx_stats()"); |
|---|
| 687 | } |
|---|
| 688 | |
|---|
| 689 | ////////////////////////////////////////////// |
|---|
| 690 | void giet_nic_tx_stats( unsigned int channel ) |
|---|
| 691 | { |
|---|
| 692 | if ( sys_call( SYSCALL_NIC_STATS, |
|---|
| 693 | 0, |
|---|
| 694 | channel, |
|---|
| 695 | 0, 0 ) ) giet_exit("error in giet_nic_tx_stats()"); |
|---|
| 696 | } |
|---|
| 697 | |
|---|
| 698 | ////////////////////////////////////////////// |
|---|
| 699 | void giet_nic_rx_clear( unsigned int channel ) |
|---|
| 700 | { |
|---|
| 701 | if ( sys_call( SYSCALL_NIC_CLEAR, |
|---|
| 702 | 1, |
|---|
| 703 | channel, |
|---|
| 704 | 0, 0 ) ) giet_exit("error in giet_nic_rx_clear()"); |
|---|
| 705 | } |
|---|
| 706 | |
|---|
| 707 | ////////////////////////////////////////////// |
|---|
| 708 | void giet_nic_tx_clear( unsigned int channel ) |
|---|
| 709 | { |
|---|
| 710 | if ( sys_call( SYSCALL_NIC_CLEAR, |
|---|
| 711 | 0, |
|---|
| 712 | channel, |
|---|
| 713 | 0, 0 ) ) giet_exit("error in giet_nic_tx_clear()"); |
|---|
| 714 | } |
|---|
| 715 | |
|---|
| 716 | |
|---|
| 717 | |
|---|
| 718 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 719 | ///////////////////// FAT related system calls //////////////////////////////////// |
|---|
| 720 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 721 | |
|---|
| 722 | /////////////////////////////////////////// |
|---|
| 723 | int giet_fat_open( const char* pathname, |
|---|
| 724 | unsigned int flags ) |
|---|
| 725 | { |
|---|
| 726 | int ret = sys_call( SYSCALL_FAT_OPEN, |
|---|
| 727 | (unsigned int)pathname, |
|---|
| 728 | flags, |
|---|
| 729 | 0, 0 ); |
|---|
| 730 | if ( ret < 0 ) giet_exit("error in giet_fat_open()"); |
|---|
| 731 | return ret; |
|---|
| 732 | } |
|---|
| 733 | |
|---|
| 734 | //////////////////////////////////// |
|---|
| 735 | void giet_fat_read( unsigned int fd, |
|---|
| 736 | void* buffer, |
|---|
| 737 | unsigned int count, |
|---|
| 738 | unsigned int offset ) |
|---|
| 739 | { |
|---|
| 740 | if ( sys_call( SYSCALL_FAT_READ, |
|---|
| 741 | fd, |
|---|
| 742 | (unsigned int)buffer, |
|---|
| 743 | count, |
|---|
| 744 | offset ) != count ) giet_exit("ERROR in giet_fat_read()"); |
|---|
| 745 | } |
|---|
| 746 | |
|---|
| 747 | ///////////////////////////////////// |
|---|
| 748 | void giet_fat_write( unsigned int fd, |
|---|
| 749 | void* buffer, |
|---|
| 750 | unsigned int count, |
|---|
| 751 | unsigned int offset ) |
|---|
| 752 | { |
|---|
| 753 | if ( sys_call( SYSCALL_FAT_WRITE, |
|---|
| 754 | fd, |
|---|
| 755 | (unsigned int)buffer, |
|---|
| 756 | count, |
|---|
| 757 | offset ) != count ) giet_exit("ERROR in giet_fat_write()"); |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | /* variant implementing the UNIX spec |
|---|
| 761 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 762 | // This system call writes to a file identified by the "fd" file descriptor. |
|---|
| 763 | // - "buffer" is the source buffer virtual address (must be word aligned). |
|---|
| 764 | // - "count" is a number of bytes (must be multiple of 4). |
|---|
| 765 | // It uses the implicit "lseek" pointer in file descriptor. |
|---|
| 766 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 767 | void giet_fat_write( unsigned int fd, |
|---|
| 768 | void* buffer, |
|---|
| 769 | unsigned int count ) // number of bytes |
|---|
| 770 | { |
|---|
| 771 | return sys_call( SYSCALL_FAT_WRITE, |
|---|
| 772 | fd, |
|---|
| 773 | (unsigned int)buffer, |
|---|
| 774 | count, 0 ); |
|---|
| 775 | } |
|---|
| 776 | */ |
|---|
| 777 | |
|---|
| 778 | ///////////////////////////////////// |
|---|
| 779 | void giet_fat_lseek( unsigned int fd, |
|---|
| 780 | unsigned int offset, |
|---|
| 781 | unsigned int whence ) |
|---|
| 782 | { |
|---|
| 783 | if ( sys_call( SYSCALL_FAT_LSEEK, |
|---|
| 784 | fd, |
|---|
| 785 | offset, |
|---|
| 786 | whence, |
|---|
| 787 | 0 ) ) giet_exit("ERROR in giet_fat_lseek()"); |
|---|
| 788 | } |
|---|
| 789 | |
|---|
| 790 | ////////////////////////////////////// |
|---|
| 791 | void giet_fat_fstat( unsigned int fd ) |
|---|
| 792 | { |
|---|
| 793 | if ( sys_call( SYSCALL_FAT_FSTAT, |
|---|
| 794 | fd, |
|---|
| 795 | 0, 0, 0 ) ) giet_exit("ERROR in giet_fat_lseek()"); |
|---|
| 796 | } |
|---|
| 797 | |
|---|
| 798 | ///////////////////////////////////// |
|---|
| 799 | void giet_fat_close( unsigned int fd ) |
|---|
| 800 | { |
|---|
| 801 | if ( sys_call( SYSCALL_FAT_CLOSE, |
|---|
| 802 | fd, |
|---|
| 803 | 0, 0, 0 ) ) giet_exit("ERROR in giet_fat_close()"); |
|---|
| 804 | } |
|---|
| 805 | |
|---|
| 806 | |
|---|
| 807 | |
|---|
| 808 | |
|---|
| 809 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 810 | ///////////////////// Miscellaneous system calls ///////////////////////////////// |
|---|
| 811 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 812 | |
|---|
| 813 | ////////////////////////////// |
|---|
| 814 | void giet_exit( char* string ) |
|---|
| 815 | { |
|---|
| 816 | sys_call( SYSCALL_EXIT, |
|---|
| 817 | (unsigned int)string, |
|---|
| 818 | 0, 0, 0 ); |
|---|
| 819 | } |
|---|
| 820 | |
|---|
| 821 | ///////////////////////////////////////// |
|---|
| 822 | void giet_assert( unsigned int condition, |
|---|
| 823 | char* string ) |
|---|
| 824 | { |
|---|
| 825 | if ( condition == 0 ) giet_exit( string ); |
|---|
| 826 | } |
|---|
| 827 | |
|---|
| 828 | ////////////////////////// |
|---|
| 829 | void giet_context_switch() |
|---|
| 830 | { |
|---|
| 831 | sys_call( SYSCALL_CTX_SWITCH, |
|---|
| 832 | 0, 0, 0, 0 ); |
|---|
| 833 | } |
|---|
| 834 | |
|---|
| 835 | ///////////////////////////////////////////////// |
|---|
| 836 | void giet_procs_number( unsigned int* x_size, |
|---|
| 837 | unsigned int* y_size, |
|---|
| 838 | unsigned int* nprocs ) |
|---|
| 839 | { |
|---|
| 840 | if ( sys_call( SYSCALL_PROCS_NUMBER, |
|---|
| 841 | (unsigned int)x_size, |
|---|
| 842 | (unsigned int)y_size, |
|---|
| 843 | (unsigned int)nprocs, |
|---|
| 844 | 0 ) ) giet_exit("ERROR in giet_procs_number()"); |
|---|
| 845 | } |
|---|
| 846 | |
|---|
| 847 | //////////////////////////////////////////////////// |
|---|
| 848 | void giet_vobj_get_vbase( char* vspace_name, |
|---|
| 849 | char* vobj_name, |
|---|
| 850 | unsigned int* vbase ) |
|---|
| 851 | { |
|---|
| 852 | if ( sys_call( SYSCALL_VOBJ_GET_VBASE, |
|---|
| 853 | (unsigned int) vspace_name, |
|---|
| 854 | (unsigned int) vobj_name, |
|---|
| 855 | (unsigned int) vbase, |
|---|
| 856 | 0 ) ) giet_exit("ERROR in giet_vobj_get_vbase()"); |
|---|
| 857 | } |
|---|
| 858 | |
|---|
| 859 | //////////////////////////////////////////////////// |
|---|
| 860 | void giet_vobj_get_length( char* vspace_name, |
|---|
| 861 | char* vobj_name, |
|---|
| 862 | unsigned int* length ) |
|---|
| 863 | { |
|---|
| 864 | if ( sys_call( SYSCALL_VOBJ_GET_LENGTH, |
|---|
| 865 | (unsigned int) vspace_name, |
|---|
| 866 | (unsigned int) vobj_name, |
|---|
| 867 | (unsigned int) length, |
|---|
| 868 | 0 ) ) giet_exit("ERROR in giet_vobj_get_length()"); |
|---|
| 869 | } |
|---|
| 870 | |
|---|
| 871 | ///////////////////////////////////////// |
|---|
| 872 | void giet_heap_info( unsigned int* vaddr, |
|---|
| 873 | unsigned int* length, |
|---|
| 874 | unsigned int x, |
|---|
| 875 | unsigned int y ) |
|---|
| 876 | { |
|---|
| 877 | if ( sys_call( SYSCALL_HEAP_INFO, |
|---|
| 878 | (unsigned int)vaddr, |
|---|
| 879 | (unsigned int)length, |
|---|
| 880 | x, |
|---|
| 881 | y ) ) giet_exit("ERROR in giet_heap_info()"); |
|---|
| 882 | } |
|---|
| 883 | |
|---|
| 884 | ///////////////////////////////////////// |
|---|
| 885 | void giet_get_xy( void* ptr, |
|---|
| 886 | unsigned int* px, |
|---|
| 887 | unsigned int* py ) |
|---|
| 888 | { |
|---|
| 889 | if ( sys_call( SYSCALL_GET_XY, |
|---|
| 890 | (unsigned int)ptr, |
|---|
| 891 | (unsigned int)px, |
|---|
| 892 | (unsigned int)py, |
|---|
| 893 | 0 ) ) giet_exit("ERROR in giet_get_xy()"); |
|---|
| 894 | } |
|---|
| 895 | |
|---|
| 896 | // Local Variables: |
|---|
| 897 | // tab-width: 4 |
|---|
| 898 | // c-basic-offset: 4 |
|---|
| 899 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 900 | // indent-tabs-mode: nil |
|---|
| 901 | // End: |
|---|
| 902 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 903 | |
|---|