Remove i386_elf_emit_arch_note
[deliverable/binutils-gdb.git] / sim / arm / armos.c
index 63ca2974a392210e90ea68a6475e356cc682172e..e5c218d0c6f4069f8a89c755daf96fbc0787700f 100644 (file)
@@ -3,7 +3,7 @@
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
+    the Free Software Foundation; either version 3 of the License, or
     (at your option) any later version.
  
     This program is distributed in the hope that it will be useful,
@@ -12,8 +12,7 @@
     GNU General Public License for more details.
  
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
+    along with this program; if not, see <http://www.gnu.org/licenses/>. */
 
 /* This file contains a model of Demon, ARM Ltd's Debug Monitor,
    including all the SWI's required to support the C library. The code in
@@ -27,6 +26,7 @@
 
 #include <time.h>
 #include <errno.h>
+#include <limits.h>
 #include <string.h>
 #include "targ-vals.h"
 
 #define TARGET_O_BINARY 0
 #endif
 
-#ifdef __STDC__
-#define unlink(s) remove(s)
-#endif
-
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>            /* For SEEK_SET etc.  */
 #endif
@@ -89,6 +85,9 @@ extern ARMword  ARMul_Debug        (ARMul_State *, ARMword, ARMword);
 #define FOPEN_MAX 64
 #endif
 #define UNIQUETEMPS 256
+#ifndef PATH_MAX
+#define PATH_MAX 1024
+#endif
 
 /* OS private Information.  */
 
@@ -299,22 +298,35 @@ WriteCommandLineTo (ARMul_State * state, ARMword addr)
   while (temp != 0);
 }
 
+static int
+ReadFileName (ARMul_State * state, char *buf, ARMword src, size_t n)
+{
+  struct OSblock *OSptr = (struct OSblock *) state->OSptr;
+  char *p = buf;
+
+  while (n--)
+    if ((*p++ = ARMul_SafeReadByte (state, src++)) == '\0')
+      return 0;
+  OSptr->ErrorNo = cb_host_to_target_errno (sim_callback, ENAMETOOLONG);
+  state->Reg[0] = -1;
+  return -1;
+}
+
 static void
 SWIopen (ARMul_State * state, ARMword name, ARMword SWIflags)
 {
   struct OSblock *OSptr = (struct OSblock *) state->OSptr;
-  char dummy[2000];
+  char buf[PATH_MAX];
   int flags;
-  int i;
 
-  for (i = 0; (dummy[i] = ARMul_SafeReadByte (state, name + i)); i++)
-    ;
+  if (ReadFileName (state, buf, name, sizeof buf) == -1)
+    return;
 
   /* Now we need to decode the Demon open mode.  */
   flags = translate_open_mode[SWIflags];
 
   /* Filename ":tt" is special: it denotes stdin/out.  */
-  if (strcmp (dummy, ":tt") == 0)
+  if (strcmp (buf, ":tt") == 0)
     {
       if (flags == TARGET_O_RDONLY) /* opening tty "r" */
        state->Reg[0] = 0;      /* stdin */
@@ -323,7 +335,7 @@ SWIopen (ARMul_State * state, ARMword name, ARMword SWIflags)
     }
   else
     {
-      state->Reg[0] = sim_callback->open (sim_callback, dummy, flags);
+      state->Reg[0] = sim_callback->open (sim_callback, buf, flags);
       OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
     }
 }
@@ -388,7 +400,7 @@ SWIflen (ARMul_State * state, ARMword fh)
   struct OSblock *OSptr = (struct OSblock *) state->OSptr;
   ARMword addr;
 
-  if (fh == 0 || fh > FOPEN_MAX)
+  if (fh > FOPEN_MAX)
     {
       OSptr->ErrorNo = EBADF;
       state->Reg[0] = -1L;
@@ -403,6 +415,33 @@ SWIflen (ARMul_State * state, ARMword fh)
   OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
 }
 
+static void
+SWIremove (ARMul_State * state, ARMword path)
+{
+  char buf[PATH_MAX];
+
+  if (ReadFileName (state, buf, path, sizeof buf) != -1)
+    {
+      struct OSblock *OSptr = (struct OSblock *) state->OSptr;
+      state->Reg[0] = sim_callback->unlink (sim_callback, buf);
+      OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+    }
+}
+
+static void
+SWIrename (ARMul_State * state, ARMword old, ARMword new)
+{
+  char oldbuf[PATH_MAX], newbuf[PATH_MAX];
+
+  if (ReadFileName (state, oldbuf, old, sizeof oldbuf) != -1
+      && ReadFileName (state, newbuf, new, sizeof newbuf) != -1)
+    {
+      struct OSblock *OSptr = (struct OSblock *) state->OSptr;
+      state->Reg[0] = sim_callback->rename (sim_callback, oldbuf, newbuf);
+      OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+    }
+}
+
 /* The emulator calls this routine when a SWI instruction is encuntered.
    The parameter passed is the SWI number (lower 24 bits of the instruction).  */
 
@@ -544,6 +583,30 @@ ARMul_OSHandleSWI (ARMul_State * state, ARMword number)
       state->Emulate = FALSE;
       break;
 
+    case SWI_Remove:
+      if (swi_mask & SWI_MASK_DEMON)
+       SWIremove (state, state->Reg[0]);
+      else
+       unhandled = TRUE;
+      break;
+
+    case SWI_Rename:
+      if (swi_mask & SWI_MASK_DEMON)
+       SWIrename (state, state->Reg[0], state->Reg[1]);
+      else
+       unhandled = TRUE;
+      break;
+
+    case SWI_IsTTY:
+      if (swi_mask & SWI_MASK_DEMON)
+       {
+         state->Reg[0] = sim_callback->isatty (sim_callback, state->Reg[0]);
+         OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+       }
+      else
+       unhandled = TRUE;
+      break;
+
       /* Handle Angel SWIs as well as Demon ones.  */
     case AngelSWI_ARM:
     case AngelSWI_Thumb:
@@ -566,10 +629,7 @@ ARMul_OSHandleSWI (ARMul_State * state, ARMword number)
          
              /* Unimplemented reason codes.  */
            case AngelSWI_Reason_ReadC:
-           case AngelSWI_Reason_IsTTY:
            case AngelSWI_Reason_TmpNam:
-           case AngelSWI_Reason_Remove:
-           case AngelSWI_Reason_Rename:
            case AngelSWI_Reason_System:
            case AngelSWI_Reason_EnterSVC:
            default:
@@ -684,6 +744,21 @@ ARMul_OSHandleSWI (ARMul_State * state, ARMword number)
                        ARMul_ReadWord (state, addr + 4),
                        ARMul_ReadWord (state, addr + 8));
              break;
+
+           case AngelSWI_Reason_IsTTY:
+             state->Reg[0] = sim_callback->isatty (sim_callback,
+                                                   ARMul_ReadWord (state, addr));
+             OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+             break;
+
+           case AngelSWI_Reason_Remove:
+             SWIremove (state,
+                        ARMul_ReadWord (state, addr));
+
+           case AngelSWI_Reason_Rename:
+             SWIrename (state,
+                        ARMul_ReadWord (state, addr),
+                        ARMul_ReadWord (state, addr + 4));
            }
        }
       else
@@ -783,9 +858,26 @@ ARMul_OSHandleSWI (ARMul_State * state, ARMword number)
            case 18: /* Time.  */
              sim_callback->printf_filtered
                (sim_callback,
-                "sim: unhandled RedBoot syscall '%d' encountered - ignoring\n",
+                "sim: unhandled RedBoot syscall `%d' encountered - "
+                "returning ENOSYS\n",
                 state->Reg[0]);
-             return FALSE;
+             state->Reg[0] = -1;
+             OSptr->ErrorNo = cb_host_to_target_errno
+               (sim_callback, ENOSYS);
+             break;
+           case 1001: /* Meminfo. */
+             {
+               ARMword totmem = state->Reg[1],
+                       topmem = state->Reg[2];
+               ARMword stack = state->MemSize > 0
+                 ? state->MemSize : ADDRUSERSTACK;
+               if (totmem != 0)
+                 ARMul_WriteWord (state, totmem, stack);
+               if (topmem != 0)
+                 ARMul_WriteWord (state, topmem, stack);
+               state->Reg[0] = 0;
+               break;
+             }
 
            default:
              sim_callback->printf_filtered
This page took 0.033773 seconds and 4 git commands to generate.