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