diff options
Diffstat (limited to 'src/core/arm/interpreter/armos.cpp')
| -rw-r--r-- | src/core/arm/interpreter/armos.cpp | 742 |
1 files changed, 742 insertions, 0 deletions
diff --git a/src/core/arm/interpreter/armos.cpp b/src/core/arm/interpreter/armos.cpp new file mode 100644 index 000000000..43484ee5f --- /dev/null +++ b/src/core/arm/interpreter/armos.cpp | |||
| @@ -0,0 +1,742 @@ | |||
| 1 | /* armos.c -- ARMulator OS interface: ARM6 Instruction Emulator. | ||
| 2 | Copyright (C) 1994 Advanced RISC Machines Ltd. | ||
| 3 | |||
| 4 | This program is free software; you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation; either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program; if not, write to the Free Software | ||
| 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | ||
| 17 | |||
| 18 | /* This file contains a model of Demon, ARM Ltd's Debug Monitor, | ||
| 19 | including all the SWI's required to support the C library. The code in | ||
| 20 | it is not really for the faint-hearted (especially the abort handling | ||
| 21 | code), but it is a complete example. Defining NOOS will disable all the | ||
| 22 | fun, and definign VAILDATE will define SWI 1 to enter SVC mode, and SWI | ||
| 23 | 0x11 to halt the emulator. */ | ||
| 24 | |||
| 25 | //chy 2005-09-12 disable below line | ||
| 26 | //#include "config.h" | ||
| 27 | |||
| 28 | #include <time.h> | ||
| 29 | #include <errno.h> | ||
| 30 | #include <string.h> | ||
| 31 | #include "skyeye_defs.h" | ||
| 32 | #ifndef __USE_LARGEFILE64 | ||
| 33 | #define __USE_LARGEFILE64 /* When use 64 bit large file need define it! for stat64*/ | ||
| 34 | #endif | ||
| 35 | #include <fcntl.h> | ||
| 36 | #include <sys/stat.h> | ||
| 37 | |||
| 38 | |||
| 39 | #ifndef O_RDONLY | ||
| 40 | #define O_RDONLY 0 | ||
| 41 | #endif | ||
| 42 | #ifndef O_WRONLY | ||
| 43 | #define O_WRONLY 1 | ||
| 44 | #endif | ||
| 45 | #ifndef O_RDWR | ||
| 46 | #define O_RDWR 2 | ||
| 47 | #endif | ||
| 48 | #ifndef O_BINARY | ||
| 49 | #define O_BINARY 0 | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #ifdef __STDC__ | ||
| 53 | #define unlink(s) remove(s) | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #ifdef HAVE_UNISTD_H | ||
| 57 | #include <unistd.h> /* For SEEK_SET etc */ | ||
| 58 | #endif | ||
| 59 | |||
| 60 | #ifdef __riscos | ||
| 61 | extern int _fisatty (FILE *); | ||
| 62 | #define isatty_(f) _fisatty(f) | ||
| 63 | #else | ||
| 64 | #ifdef __ZTC__ | ||
| 65 | #include <io.h> | ||
| 66 | #define isatty_(f) isatty((f)->_file) | ||
| 67 | #else | ||
| 68 | #ifdef macintosh | ||
| 69 | #include <ioctl.h> | ||
| 70 | #define isatty_(f) (~ioctl ((f)->_file, FIOINTERACTIVE, NULL)) | ||
| 71 | #else | ||
| 72 | #define isatty_(f) isatty (fileno (f)) | ||
| 73 | #endif | ||
| 74 | #endif | ||
| 75 | #endif | ||
| 76 | |||
| 77 | #include "armdefs.h" | ||
| 78 | #include "armos.h" | ||
| 79 | #include "armemu.h" | ||
| 80 | |||
| 81 | #ifndef NOOS | ||
| 82 | #ifndef VALIDATE | ||
| 83 | /* #ifndef ASIM */ | ||
| 84 | //chy 2005-09-12 disable below line | ||
| 85 | //#include "armfpe.h" | ||
| 86 | /* #endif */ | ||
| 87 | #endif | ||
| 88 | #endif | ||
| 89 | |||
| 90 | #define DUMP_SYSCALL 0 | ||
| 91 | #define dump(...) do { if (DUMP_SYSCALL) printf(__VA_ARGS__); } while(0) | ||
| 92 | //#define debug(...) printf(__VA_ARGS__); | ||
| 93 | #define debug(...) ; | ||
| 94 | |||
| 95 | extern unsigned ARMul_OSHandleSWI (ARMul_State * state, ARMword number); | ||
| 96 | |||
| 97 | #ifndef FOPEN_MAX | ||
| 98 | #define FOPEN_MAX 64 | ||
| 99 | #endif | ||
| 100 | |||
| 101 | /***************************************************************************\ | ||
| 102 | * OS private Information * | ||
| 103 | \***************************************************************************/ | ||
| 104 | |||
| 105 | unsigned arm_dyncom_SWI(ARMul_State * state, ARMword number) | ||
| 106 | { | ||
| 107 | return ARMul_OSHandleSWI(state, number); | ||
| 108 | } | ||
| 109 | |||
| 110 | //mmap_area_t *mmap_global = NULL; | ||
| 111 | |||
| 112 | static int translate_open_mode[] = { | ||
| 113 | O_RDONLY, /* "r" */ | ||
| 114 | O_RDONLY + O_BINARY, /* "rb" */ | ||
| 115 | O_RDWR, /* "r+" */ | ||
| 116 | O_RDWR + O_BINARY, /* "r+b" */ | ||
| 117 | O_WRONLY + O_CREAT + O_TRUNC, /* "w" */ | ||
| 118 | O_WRONLY + O_BINARY + O_CREAT + O_TRUNC, /* "wb" */ | ||
| 119 | O_RDWR + O_CREAT + O_TRUNC, /* "w+" */ | ||
| 120 | O_RDWR + O_BINARY + O_CREAT + O_TRUNC, /* "w+b" */ | ||
| 121 | O_WRONLY + O_APPEND + O_CREAT, /* "a" */ | ||
| 122 | O_WRONLY + O_BINARY + O_APPEND + O_CREAT, /* "ab" */ | ||
| 123 | O_RDWR + O_APPEND + O_CREAT, /* "a+" */ | ||
| 124 | O_RDWR + O_BINARY + O_APPEND + O_CREAT /* "a+b" */ | ||
| 125 | }; | ||
| 126 | // | ||
| 127 | //static void | ||
| 128 | //SWIWrite0 (ARMul_State * state, ARMword addr) | ||
| 129 | //{ | ||
| 130 | // ARMword temp; | ||
| 131 | // | ||
| 132 | // //while ((temp = ARMul_ReadByte (state, addr++)) != 0) | ||
| 133 | // while(1){ | ||
| 134 | // mem_read(8, addr++, &temp); | ||
| 135 | // if(temp != 0) | ||
| 136 | // (void) fputc ((char) temp, stdout); | ||
| 137 | // else | ||
| 138 | // break; | ||
| 139 | // } | ||
| 140 | //} | ||
| 141 | // | ||
| 142 | //static void | ||
| 143 | //WriteCommandLineTo (ARMul_State * state, ARMword addr) | ||
| 144 | //{ | ||
| 145 | // ARMword temp; | ||
| 146 | // char *cptr = state->CommandLine; | ||
| 147 | // if (cptr == NULL) | ||
| 148 | // cptr = "\0"; | ||
| 149 | // do { | ||
| 150 | // temp = (ARMword) * cptr++; | ||
| 151 | // //ARMul_WriteByte (state, addr++, temp); | ||
| 152 | // mem_write(8, addr++, temp); | ||
| 153 | // } | ||
| 154 | // while (temp != 0); | ||
| 155 | //} | ||
| 156 | // | ||
| 157 | //static void | ||
| 158 | //SWIopen (ARMul_State * state, ARMword name, ARMword SWIflags) | ||
| 159 | //{ | ||
| 160 | // char dummy[2000]; | ||
| 161 | // int flags; | ||
| 162 | // int i; | ||
| 163 | // | ||
| 164 | // for (i = 0; (dummy[i] = ARMul_ReadByte (state, name + i)); i++); | ||
| 165 | // assert(SWIflags< (sizeof(translate_open_mode)/ sizeof(translate_open_mode[0]))); | ||
| 166 | // /* Now we need to decode the Demon open mode */ | ||
| 167 | // flags = translate_open_mode[SWIflags]; | ||
| 168 | // flags = SWIflags; | ||
| 169 | // | ||
| 170 | // /* Filename ":tt" is special: it denotes stdin/out */ | ||
| 171 | // if (strcmp (dummy, ":tt") == 0) { | ||
| 172 | // if (flags == O_RDONLY) /* opening tty "r" */ | ||
| 173 | // state->Reg[0] = 0; /* stdin */ | ||
| 174 | // else | ||
| 175 | // state->Reg[0] = 1; /* stdout */ | ||
| 176 | // } | ||
| 177 | // else { | ||
| 178 | // state->Reg[0] = (int) open (dummy, flags, 0666); | ||
| 179 | // } | ||
| 180 | //} | ||
| 181 | // | ||
| 182 | //static void | ||
| 183 | //SWIread (ARMul_State * state, ARMword f, ARMword ptr, ARMword len) | ||
| 184 | //{ | ||
| 185 | // int res; | ||
| 186 | // int i; | ||
| 187 | // char *local = (char*) malloc (len); | ||
| 188 | // | ||
| 189 | // if (local == NULL) { | ||
| 190 | // fprintf (stderr, | ||
| 191 | // "sim: Unable to read 0x%ulx bytes - out of memory\n", | ||
| 192 | // len); | ||
| 193 | // return; | ||
| 194 | // } | ||
| 195 | // | ||
| 196 | // res = read (f, local, len); | ||
| 197 | // if (res > 0) | ||
| 198 | // for (i = 0; i < res; i++) | ||
| 199 | // //ARMul_WriteByte (state, ptr + i, local[i]); | ||
| 200 | // mem_write(8, ptr + i, local[i]); | ||
| 201 | // free (local); | ||
| 202 | // //state->Reg[0] = res == -1 ? -1 : len - res; | ||
| 203 | // state->Reg[0] = res; | ||
| 204 | //} | ||
| 205 | // | ||
| 206 | //static void | ||
| 207 | //SWIwrite (ARMul_State * state, ARMword f, ARMword ptr, ARMword len) | ||
| 208 | //{ | ||
| 209 | // int res; | ||
| 210 | // ARMword i; | ||
| 211 | // char *local = malloc (len); | ||
| 212 | // | ||
| 213 | // if (local == NULL) { | ||
| 214 | // fprintf (stderr, | ||
| 215 | // "sim: Unable to write 0x%lx bytes - out of memory\n", | ||
| 216 | // (long unsigned int) len); | ||
| 217 | // return; | ||
| 218 | // } | ||
| 219 | // | ||
| 220 | // for (i = 0; i < len; i++){ | ||
| 221 | // //local[i] = ARMul_ReadByte (state, ptr + i); | ||
| 222 | // ARMword data; | ||
| 223 | // mem_read(8, ptr + i, &data); | ||
| 224 | // local[i] = data & 0xFF; | ||
| 225 | // } | ||
| 226 | // | ||
| 227 | // res = write (f, local, len); | ||
| 228 | // //state->Reg[0] = res == -1 ? -1 : len - res; | ||
| 229 | // state->Reg[0] = res; | ||
| 230 | // free (local); | ||
| 231 | //} | ||
| 232 | |||
| 233 | //static void | ||
| 234 | //SWIflen (ARMul_State * state, ARMword fh) | ||
| 235 | //{ | ||
| 236 | // ARMword addr; | ||
| 237 | // | ||
| 238 | // if (fh == 0 || fh > FOPEN_MAX) { | ||
| 239 | // state->Reg[0] = -1L; | ||
| 240 | // return; | ||
| 241 | // } | ||
| 242 | // | ||
| 243 | // addr = lseek (fh, 0, SEEK_CUR); | ||
| 244 | // | ||
| 245 | // state->Reg[0] = lseek (fh, 0L, SEEK_END); | ||
| 246 | // (void) lseek (fh, addr, SEEK_SET); | ||
| 247 | // | ||
| 248 | //} | ||
| 249 | |||
| 250 | /***************************************************************************\ | ||
| 251 | * The emulator calls this routine when a SWI instruction is encuntered. The * | ||
| 252 | * parameter passed is the SWI number (lower 24 bits of the instruction). * | ||
| 253 | \***************************************************************************/ | ||
| 254 | /* ahe-ykl information is retrieved from elf header and the starting value of | ||
| 255 | brk_static is in sky_info_t */ | ||
| 256 | |||
| 257 | /* brk static hold the value of brk */ | ||
| 258 | static uint32_t brk_static = -1; | ||
| 259 | |||
| 260 | unsigned | ||
| 261 | ARMul_OSHandleSWI (ARMul_State * state, ARMword number) | ||
| 262 | { | ||
| 263 | number &= 0xfffff; | ||
| 264 | ARMword addr, temp; | ||
| 265 | |||
| 266 | switch (number) { | ||
| 267 | // case SWI_Syscall: | ||
| 268 | // if (state->Reg[7] != 0) | ||
| 269 | // return ARMul_OSHandleSWI(state, state->Reg[7]); | ||
| 270 | // else | ||
| 271 | // return FALSE; | ||
| 272 | // case SWI_Read: | ||
| 273 | // SWIread (state, state->Reg[0], state->Reg[1], state->Reg[2]); | ||
| 274 | // return TRUE; | ||
| 275 | // | ||
| 276 | // case SWI_GetUID32: | ||
| 277 | // state->Reg[0] = getuid(); | ||
| 278 | // return TRUE; | ||
| 279 | // | ||
| 280 | // case SWI_GetGID32: | ||
| 281 | // state->Reg[0] = getgid(); | ||
| 282 | // return TRUE; | ||
| 283 | // | ||
| 284 | // case SWI_GetEUID32: | ||
| 285 | // state->Reg[0] = geteuid(); | ||
| 286 | // return TRUE; | ||
| 287 | // | ||
| 288 | // case SWI_GetEGID32: | ||
| 289 | // state->Reg[0] = getegid(); | ||
| 290 | // return TRUE; | ||
| 291 | // | ||
| 292 | // case SWI_Write: | ||
| 293 | // SWIwrite (state, state->Reg[0], state->Reg[1], state->Reg[2]); | ||
| 294 | // return TRUE; | ||
| 295 | // | ||
| 296 | // case SWI_Open: | ||
| 297 | // SWIopen (state, state->Reg[0], state->Reg[1]); | ||
| 298 | // return TRUE; | ||
| 299 | // | ||
| 300 | // case SWI_Close: | ||
| 301 | // state->Reg[0] = close (state->Reg[0]); | ||
| 302 | // return TRUE; | ||
| 303 | // | ||
| 304 | // case SWI_Seek:{ | ||
| 305 | // /* We must return non-zero for failure */ | ||
| 306 | // state->Reg[0] = | ||
| 307 | // lseek (state->Reg[0], state->Reg[1], | ||
| 308 | // SEEK_SET); | ||
| 309 | // return TRUE; | ||
| 310 | // } | ||
| 311 | // | ||
| 312 | // case SWI_ExitGroup: | ||
| 313 | // case SWI_Exit: | ||
| 314 | // { | ||
| 315 | // struct timeval tv; | ||
| 316 | // //gettimeofday(&tv,NULL); | ||
| 317 | // //printf("In %s, %d sec, %d usec\n", __FUNCTION__, tv.tv_sec, tv.tv_usec); | ||
| 318 | // printf("passed %d sec, %lld usec\n", get_clock_sec(), get_clock_us()); | ||
| 319 | // | ||
| 320 | // /* quit here */ | ||
| 321 | // run_command("quit"); | ||
| 322 | // return TRUE; | ||
| 323 | // } | ||
| 324 | // case SWI_Times:{ | ||
| 325 | // uint32_t dest = state->Reg[0]; | ||
| 326 | // struct tms now; | ||
| 327 | // struct target_tms32 nowret; | ||
| 328 | // | ||
| 329 | // uint32_t ret = times(&now); | ||
| 330 | // | ||
| 331 | // if (ret == -1){ | ||
| 332 | // debug("syscall %s error %d\n", "SWI_Times", ret); | ||
| 333 | // state->Reg[0] = ret; | ||
| 334 | // return FALSE; | ||
| 335 | // } | ||
| 336 | // | ||
| 337 | // nowret.tms_cstime = now.tms_cstime; | ||
| 338 | // nowret.tms_cutime = now.tms_cutime; | ||
| 339 | // nowret.tms_stime = now.tms_stime; | ||
| 340 | // nowret.tms_utime = now.tms_utime; | ||
| 341 | // | ||
| 342 | // uint32_t offset; | ||
| 343 | // for (offset = 0; offset < sizeof(nowret); offset++) { | ||
| 344 | // bus_write(8, dest + offset, *((uint8_t *) &nowret + offset)); | ||
| 345 | // } | ||
| 346 | // | ||
| 347 | // state->Reg[0] = ret; | ||
| 348 | // return TRUE; | ||
| 349 | // } | ||
| 350 | // | ||
| 351 | // case SWI_Gettimeofday: { | ||
| 352 | // uint32_t dest1 = state->Reg[0]; | ||
| 353 | // uint32_t dest2 = state->Reg[1]; // Unsure of this | ||
| 354 | // struct timeval val; | ||
| 355 | // struct timezone zone; | ||
| 356 | // struct target_timeval32 valret; | ||
| 357 | // struct target_timezone32 zoneret; | ||
| 358 | // | ||
| 359 | // uint32_t ret = gettimeofday(&val, &zone); | ||
| 360 | // valret.tv_sec = val.tv_sec; | ||
| 361 | // valret.tv_usec = val.tv_usec; | ||
| 362 | // zoneret.tz_dsttime = zoneret.tz_dsttime; | ||
| 363 | // zoneret.tz_minuteswest = zoneret.tz_minuteswest; | ||
| 364 | // | ||
| 365 | // if (ret == -1){ | ||
| 366 | // debug("syscall %s error %d\n", "SWI_Gettimeofday", ret); | ||
| 367 | // state->Reg[0] = ret; | ||
| 368 | // return FALSE; | ||
| 369 | // } | ||
| 370 | // | ||
| 371 | // uint32_t offset; | ||
| 372 | // if (dest1) { | ||
| 373 | // for (offset = 0; offset < sizeof(valret); offset++) { | ||
| 374 | // bus_write(8, dest1 + offset, *((uint8_t *) &valret + offset)); | ||
| 375 | // } | ||
| 376 | // state->Reg[0] = ret; | ||
| 377 | // } | ||
| 378 | // if (dest2) { | ||
| 379 | // for (offset = 0; offset < sizeof(zoneret); offset++) { | ||
| 380 | // bus_write(8, dest2 + offset, *((uint8_t *) &zoneret + offset)); | ||
| 381 | // } | ||
| 382 | // state->Reg[0] = ret; | ||
| 383 | // } | ||
| 384 | // | ||
| 385 | // return TRUE; | ||
| 386 | // } | ||
| 387 | // case SWI_Brk: | ||
| 388 | // /* initialize brk value */ | ||
| 389 | // /* suppose that brk_static doesn't reach 0xffffffff... */ | ||
| 390 | // if (brk_static == -1) { | ||
| 391 | // brk_static = (get_skyeye_pref()->info).brk; | ||
| 392 | // } | ||
| 393 | // | ||
| 394 | // /* FIXME there might be a need to do a mmap */ | ||
| 395 | // | ||
| 396 | // if(state->Reg[0]){ | ||
| 397 | // if (get_skyeye_exec_info()->mmap_access) { | ||
| 398 | // /* if new brk is greater than current brk, allocate memory */ | ||
| 399 | // if (state->Reg[0] > brk_static) { | ||
| 400 | // uint32_t ret = mmap( (void *) brk_static, state->Reg[0] - brk_static, | ||
| 401 | // PROT_WRITE, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0 ); | ||
| 402 | // if (ret != MAP_FAILED) | ||
| 403 | // brk_static = ret; | ||
| 404 | // } | ||
| 405 | // } | ||
| 406 | // brk_static = state->Reg[0]; | ||
| 407 | // //state->Reg[0] = 0; /* FIXME return value of brk set to be the address on success */ | ||
| 408 | // } else { | ||
| 409 | // state->Reg[0] = brk_static; | ||
| 410 | // } | ||
| 411 | // return TRUE; | ||
| 412 | // | ||
| 413 | // case SWI_Break: | ||
| 414 | // state->Emulate = FALSE; | ||
| 415 | // return TRUE; | ||
| 416 | // | ||
| 417 | // case SWI_Mmap:{ | ||
| 418 | // int addr = state->Reg[0]; | ||
| 419 | // int len = state->Reg[1]; | ||
| 420 | // int prot = state->Reg[2]; | ||
| 421 | // int flag = state->Reg[3]; | ||
| 422 | // int fd = state->Reg[4]; | ||
| 423 | // int offset = state->Reg[5]; | ||
| 424 | // mmap_area_t *area = new_mmap_area(addr, len); | ||
| 425 | // state->Reg[0] = area->bank.addr; | ||
| 426 | // //printf("syscall %d mmap(0x%x,%x,0x%x,0x%x,%d,0x%x) = 0x%x\n",\ | ||
| 427 | // SWI_Mmap, addr, len, prot, flag, fd, offset, state->Reg[0]); | ||
| 428 | // return TRUE; | ||
| 429 | // } | ||
| 430 | // | ||
| 431 | // case SWI_Munmap: | ||
| 432 | // state->Reg[0] = 0; | ||
| 433 | // return TRUE; | ||
| 434 | // | ||
| 435 | // case SWI_Mmap2:{ | ||
| 436 | // int addr = state->Reg[0]; | ||
| 437 | // int len = state->Reg[1]; | ||
| 438 | // int prot = state->Reg[2]; | ||
| 439 | // int flag = state->Reg[3]; | ||
| 440 | // int fd = state->Reg[4]; | ||
| 441 | // int offset = state->Reg[5] * 4096; /* page offset */ | ||
| 442 | // mmap_area_t *area = new_mmap_area(addr, len); | ||
| 443 | // state->Reg[0] = area->bank.addr; | ||
| 444 | // | ||
| 445 | // return TRUE; | ||
| 446 | // } | ||
| 447 | // | ||
| 448 | // case SWI_Breakpoint: | ||
| 449 | // //chy 2005-09-12 change below line | ||
| 450 | // //state->EndCondition = RDIError_BreakpointReached; | ||
| 451 | // //printf ("SKYEYE: in armos.c : should not come here!!!!\n"); | ||
| 452 | // state->EndCondition = 0; | ||
| 453 | // /*modified by ksh to support breakpoiont*/ | ||
| 454 | // state->Emulate = STOP; | ||
| 455 | // return (TRUE); | ||
| 456 | // case SWI_Uname: | ||
| 457 | // { | ||
| 458 | // struct utsname *uts = (uintptr_t) state->Reg[0]; /* uname should write data in this address */ | ||
| 459 | // struct utsname utsbuf; | ||
| 460 | // //printf("Uname size is %x\n", sizeof(utsbuf)); | ||
| 461 | // char *buf; | ||
| 462 | // uintptr_t sp ; /* used as a temporary address */ | ||
| 463 | // | ||
| 464 | //#define COPY_UTS_STRING(addr) \ | ||
| 465 | // buf = addr; \ | ||
| 466 | // while(*buf != NULL) { \ | ||
| 467 | // bus_write(8, sp, *buf); \ | ||
| 468 | // sp++; \ | ||
| 469 | // buf++; \ | ||
| 470 | // } | ||
| 471 | //#define COPY_UTS(field) /*printf("%s: %s at %p\n", #field, utsbuf.field, uts->field);*/ \ | ||
| 472 | // sp = (uintptr_t) uts->field; \ | ||
| 473 | // COPY_UTS_STRING((&utsbuf)->field); | ||
| 474 | // | ||
| 475 | // if (uname(&utsbuf) < 0) { | ||
| 476 | // printf("syscall uname: utsname error\n"); | ||
| 477 | // state->Reg[0] = -1; | ||
| 478 | // return FALSE; | ||
| 479 | // } | ||
| 480 | // | ||
| 481 | // /* FIXME for now, this is just the host system call | ||
| 482 | // Some data should be missing, as it depends on | ||
| 483 | // the version of utsname */ | ||
| 484 | // COPY_UTS(sysname); | ||
| 485 | // COPY_UTS(nodename); | ||
| 486 | // COPY_UTS(release); | ||
| 487 | // COPY_UTS(version); | ||
| 488 | // COPY_UTS(machine); | ||
| 489 | // | ||
| 490 | // state->Reg[0] = 0; | ||
| 491 | // return TRUE; | ||
| 492 | // } | ||
| 493 | // case SWI_Fcntl: | ||
| 494 | // { | ||
| 495 | // uint32_t fd = state->Reg[0]; | ||
| 496 | // uint32_t cmd = state->Reg[1]; | ||
| 497 | // uint32_t arg = state->Reg[2]; | ||
| 498 | // uint32_t ret; | ||
| 499 | // | ||
| 500 | // switch(cmd){ | ||
| 501 | // case (F_GETFD): | ||
| 502 | // { | ||
| 503 | // ret = fcntl(fd, cmd, arg); | ||
| 504 | // //printf("syscall fcntl for getfd not implemented, ret %d\n", ret); | ||
| 505 | // state->Reg[0] = ret; | ||
| 506 | // return FALSE; | ||
| 507 | // } | ||
| 508 | // default: | ||
| 509 | // break; | ||
| 510 | // } | ||
| 511 | // | ||
| 512 | // printf("syscall fcntl unimplemented fd %x cmd %x\n", fd, cmd); | ||
| 513 | // state->Reg[0] = -1; | ||
| 514 | // return FALSE; | ||
| 515 | // | ||
| 516 | // } | ||
| 517 | // case SWI_Fstat64: | ||
| 518 | // { | ||
| 519 | // uint32_t dest = state->Reg[1]; | ||
| 520 | // uint32_t fd = state->Reg[0]; | ||
| 521 | // struct stat64 statbuf; | ||
| 522 | // struct target_stat64 statret; | ||
| 523 | // memset(&statret, 0, sizeof(struct target_stat64)); | ||
| 524 | // uint32_t ret = fstat64(fd, &statbuf); | ||
| 525 | // | ||
| 526 | // if (ret == -1){ | ||
| 527 | // printf("syscall %s returned error\n", "SWI_Fstat"); | ||
| 528 | // state->Reg[0] = ret; | ||
| 529 | // return FALSE; | ||
| 530 | // } | ||
| 531 | // | ||
| 532 | // /* copy statbuf to the process memory space | ||
| 533 | // FIXME can't say if endian has an effect here */ | ||
| 534 | // uint32_t offset; | ||
| 535 | // //printf("Fstat system is size %x\n", sizeof(statbuf)); | ||
| 536 | // //printf("Fstat target is size %x\n", sizeof(statret)); | ||
| 537 | // | ||
| 538 | // /* we copy system structure data stat64 into arm fixed size structure target_stat64 */ | ||
| 539 | // statret.st_dev = statbuf.st_dev; | ||
| 540 | // statret.st_ino = statbuf.st_ino; | ||
| 541 | // statret.st_mode = statbuf.st_mode; | ||
| 542 | // statret.st_nlink = statbuf.st_nlink; | ||
| 543 | // statret.st_uid = statbuf.st_uid; | ||
| 544 | // statret.st_gid = statbuf.st_gid; | ||
| 545 | // statret.st_rdev = statbuf.st_rdev; | ||
| 546 | // statret.st_size = statbuf.st_size; | ||
| 547 | // statret.st_blksize = statbuf.st_blksize; | ||
| 548 | // statret.st_blocks = statbuf.st_blocks; | ||
| 549 | // statret.st32_atime = statbuf.st_atime; | ||
| 550 | // statret.st32_mtime = statbuf.st_mtime; | ||
| 551 | // statret.st32_ctime = statbuf.st_ctime; | ||
| 552 | // | ||
| 553 | // for (offset = 0; offset < sizeof(statret); offset++) { | ||
| 554 | // bus_write(8, dest + offset, *((uint8_t *) &statret + offset)); | ||
| 555 | // } | ||
| 556 | // | ||
| 557 | // state->Reg[0] = ret; | ||
| 558 | // return TRUE; | ||
| 559 | // } | ||
| 560 | // case SWI_Set_tls: | ||
| 561 | // { | ||
| 562 | // //printf("syscall set_tls unimplemented\n"); | ||
| 563 | // state->mmu.thread_uro_id = state->Reg[0]; | ||
| 564 | // state->CP15[CP15_THREAD_URO - CP15_BASE] = state->Reg[0]; | ||
| 565 | // state->Reg[0] = 0; | ||
| 566 | // return FALSE; | ||
| 567 | // } | ||
| 568 | //#if 0 | ||
| 569 | // case SWI_Clock: | ||
| 570 | // /* return number of centi-seconds... */ | ||
| 571 | // state->Reg[0] = | ||
| 572 | //#ifdef CLOCKS_PER_SEC | ||
| 573 | // (CLOCKS_PER_SEC >= 100) | ||
| 574 | // ? (ARMword) (clock () / (CLOCKS_PER_SEC / 100)) | ||
| 575 | // : (ARMword) ((clock () * 100) / CLOCKS_PER_SEC); | ||
| 576 | //#else | ||
| 577 | // /* presume unix... clock() returns microseconds */ | ||
| 578 | // (ARMword) (clock () / 10000); | ||
| 579 | //#endif | ||
| 580 | // return (TRUE); | ||
| 581 | // | ||
| 582 | // case SWI_Time: | ||
| 583 | // state->Reg[0] = (ARMword) time (NULL); | ||
| 584 | // return (TRUE); | ||
| 585 | // case SWI_Flen: | ||
| 586 | // SWIflen (state, state->Reg[0]); | ||
| 587 | // return (TRUE); | ||
| 588 | // | ||
| 589 | //#endif | ||
| 590 | default: | ||
| 591 | |||
| 592 | _dbg_assert_msg_(ARM11, false, "ImplementMe: ARMul_OSHandleSWI!"); | ||
| 593 | |||
| 594 | return (FALSE); | ||
| 595 | } | ||
| 596 | } | ||
| 597 | // | ||
| 598 | ///** | ||
| 599 | // * @brief For mmap syscall.A mmap_area is a memory bank. Get from ppc. | ||
| 600 | // */ | ||
| 601 | //static mmap_area_t* new_mmap_area(int sim_addr, int len){ | ||
| 602 | // mmap_area_t *area = (mmap_area_t *)malloc(sizeof(mmap_area_t)); | ||
| 603 | // if(area == NULL){ | ||
| 604 | // printf("error, failed %s\n",__FUNCTION__); | ||
| 605 | // exit(0); | ||
| 606 | // } | ||
| 607 | //#if FAST_MEMORY | ||
| 608 | // if (mmap_next_base == -1) | ||
| 609 | // { | ||
| 610 | // mmap_next_base = get_skyeye_exec_info()->brk; | ||
| 611 | // } | ||
| 612 | //#endif | ||
| 613 | // | ||
| 614 | // memset(area, 0x0, sizeof(mmap_area_t)); | ||
| 615 | // area->bank.addr = mmap_next_base; | ||
| 616 | // area->bank.len = len; | ||
| 617 | // area->bank.bank_write = mmap_mem_write; | ||
| 618 | // area->bank.bank_read = mmap_mem_read; | ||
| 619 | // area->bank.type = MEMTYPE_RAM; | ||
| 620 | // area->bank.objname = "mmap"; | ||
| 621 | // addr_mapping(&area->bank); | ||
| 622 | // | ||
| 623 | //#if FAST_MEMORY | ||
| 624 | // if (get_skyeye_exec_info()->mmap_access) | ||
| 625 | // { | ||
| 626 | // /* FIXME check proper flags */ | ||
| 627 | // /* FIXME we may delete the need of banks up there */ | ||
| 628 | // uint32_t ret = mmap(mmap_next_base, len, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
| 629 | // mmap_next_base = ret; | ||
| 630 | // } | ||
| 631 | // area->mmap_addr = (uint8_t*)get_dma_addr(mmap_next_base); | ||
| 632 | //#else | ||
| 633 | // area->mmap_addr = malloc(len); | ||
| 634 | // if(area->mmap_addr == NULL){ | ||
| 635 | // printf("error mmap malloc\n"); | ||
| 636 | // exit(0); | ||
| 637 | // } | ||
| 638 | // memset(area->mmap_addr, 0x0, len); | ||
| 639 | //#endif | ||
| 640 | // | ||
| 641 | // area->next = NULL; | ||
| 642 | // if(mmap_global){ | ||
| 643 | // area->next = mmap_global->next; | ||
| 644 | // mmap_global->next = area; | ||
| 645 | // }else{ | ||
| 646 | // mmap_global = area; | ||
| 647 | // } | ||
| 648 | // mmap_next_base = mmap_next_base + len; | ||
| 649 | // return area; | ||
| 650 | //} | ||
| 651 | // | ||
| 652 | //static mmap_area_t *get_mmap_area(int addr){ | ||
| 653 | // mmap_area_t *tmp = mmap_global; | ||
| 654 | // while(tmp){ | ||
| 655 | // if ((tmp->bank.addr <= addr) && (tmp->bank.addr + tmp->bank.len > addr)){ | ||
| 656 | // return tmp; | ||
| 657 | // } | ||
| 658 | // tmp = tmp->next; | ||
| 659 | // } | ||
| 660 | // printf("cannot get mmap area:addr=0x%x\n", addr); | ||
| 661 | // return NULL; | ||
| 662 | //} | ||
| 663 | // | ||
| 664 | ///** | ||
| 665 | // * @brief the mmap_area bank write function. Get from ppc. | ||
| 666 | // * | ||
| 667 | // * @param size size to write, 8/16/32 | ||
| 668 | // * @param addr address to write | ||
| 669 | // * @param value value to write | ||
| 670 | // * | ||
| 671 | // * @return sucess return 1,otherwise 0. | ||
| 672 | // */ | ||
| 673 | //static char mmap_mem_write(short size, int addr, uint32_t value){ | ||
| 674 | // mmap_area_t *area_tmp = get_mmap_area(addr); | ||
| 675 | // mem_bank_t *bank_tmp = &area_tmp->bank; | ||
| 676 | // int offset = addr - bank_tmp->addr; | ||
| 677 | // switch(size){ | ||
| 678 | // case 8:{ | ||
| 679 | // //uint8_t value_endian = value; | ||
| 680 | // uint8_t value_endian = (uint8_t)value; | ||
| 681 | // *(uint8_t *)&(((char *)area_tmp->mmap_addr)[offset]) = value_endian; | ||
| 682 | // debug("in %s,size=%d,addr=0x%x,value=0x%x\n",__FUNCTION__,size,addr,value_endian); | ||
| 683 | // break; | ||
| 684 | // } | ||
| 685 | // case 16:{ | ||
| 686 | // //uint16_t value_endian = half_to_BE((uint16_t)value); | ||
| 687 | // uint16_t value_endian = ((uint16_t)value); | ||
| 688 | // *(uint16_t *)&(((char *)area_tmp->mmap_addr)[offset]) = value_endian; | ||
| 689 | // debug("in %s,size=%d,addr=0x%x,value=0x%x\n",__FUNCTION__,size,addr,value_endian); | ||
| 690 | // break; | ||
| 691 | // } | ||
| 692 | // case 32:{ | ||
| 693 | // //uint32_t value_endian = word_to_BE((uint32_t)value); | ||
| 694 | // uint32_t value_endian = ((uint32_t)value); | ||
| 695 | // *(uint32_t *)&(((char *)area_tmp->mmap_addr)[offset]) = value_endian; | ||
| 696 | // debug("in %s,size=%d,addr=0x%x,value=0x%x\n",__FUNCTION__,size,addr,value_endian); | ||
| 697 | // break; | ||
| 698 | // } | ||
| 699 | // default: | ||
| 700 | // printf("invalid size %d\n",size); | ||
| 701 | // return 0; | ||
| 702 | // } | ||
| 703 | // return 1; | ||
| 704 | //} | ||
| 705 | // | ||
| 706 | ///** | ||
| 707 | // * @brief the mmap_area bank read function. Get from ppc. | ||
| 708 | // * | ||
| 709 | // * @param size size to read, 8/16/32 | ||
| 710 | // * @param addr address to read | ||
| 711 | // * @param value value to read | ||
| 712 | // * | ||
| 713 | // * @return sucess return 1,otherwise 0. | ||
| 714 | // */ | ||
| 715 | //static char mmap_mem_read(short size, int addr, uint32_t * value){ | ||
| 716 | // mmap_area_t *area_tmp = get_mmap_area(addr); | ||
| 717 | // mem_bank_t *bank_tmp = &area_tmp->bank; | ||
| 718 | // int offset = addr - bank_tmp->addr; | ||
| 719 | // switch(size){ | ||
| 720 | // case 8:{ | ||
| 721 | // //*(uint8_t *)value = *(uint8_t *)&(((uint8_t *)area_tmp->mmap_addr)[offset]); | ||
| 722 | // *value = *(uint8_t *)&(((uint8_t *)area_tmp->mmap_addr)[offset]); | ||
| 723 | // debug("in %s,size=%d,addr=0x%x,value=0x%x\n",__FUNCTION__,size,addr,*(uint32_t*)value); | ||
| 724 | // break; | ||
| 725 | // } | ||
| 726 | // case 16:{ | ||
| 727 | // //*(uint16_t *)value = half_from_BE(*(uint16_t *)&(((uint8_t *)area_tmp->mmap_addr)[offset])); | ||
| 728 | // *value = (*(uint16_t *)&(((uint8_t *)area_tmp->mmap_addr)[offset])); | ||
| 729 | // debug("in %s,size=%d,addr=0x%x,value=0x%x\n",__FUNCTION__,size,addr,*(uint16_t*)value); | ||
| 730 | // break; | ||
| 731 | // } | ||
| 732 | // case 32: | ||
| 733 | // //*value = (uint32_t)word_from_BE(*(uint32_t *)&(((uint8_t *)area_tmp->mmap_addr)[offset])); | ||
| 734 | // *value = (uint32_t)(*(uint32_t *)&(((uint8_t *)area_tmp->mmap_addr)[offset])); | ||
| 735 | // debug("in %s,size=%d,addr=0x%x,value=0x%x\n",__FUNCTION__,size,addr,*(uint32_t*)value); | ||
| 736 | // break; | ||
| 737 | // default: | ||
| 738 | // printf("invalid size %d\n",size); | ||
| 739 | // return 0; | ||
| 740 | // } | ||
| 741 | // return 1; | ||
| 742 | //} | ||