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