Add support for target specific command line switches to old-style simualtors.
authorNick Clifton <nickc@redhat.com>
Mon, 20 May 2002 14:32:50 +0000 (14:32 +0000)
committerNick Clifton <nickc@redhat.com>
Mon, 20 May 2002 14:32:50 +0000 (14:32 +0000)
Make use of this support in the ARM simulator to add a --swi-support= switch
to select whcih SWI protocols to emulate.

sim/arm/ChangeLog
sim/arm/Makefile.in
sim/arm/armos.c
sim/arm/dbg_rdi.h
sim/arm/wrapper.c
sim/common/ChangeLog
sim/common/run-sim.h [new file with mode: 0644]
sim/common/run.c

index e10ef891d140968fc01fd07a09ab62b535ce311d..f0639fe3c532dedbfc98b17ae5ef1799b1ae2d78 100644 (file)
@@ -1,3 +1,46 @@
+2002-05-20  Nick Clifton  <nickc@cambridge.redhat.com>
+
+       * Makefile.in (SWI_TARGET_SWITCHES): Define.
+       * armos.c (swi_mask): Define.  Initialise to supporting all
+       SWI emulations.
+       (ARMul_OSInit): For XScale targets, only support the ANGEL
+       SWI interface.  (This is at the request if Intel).
+       (ARMul_OSHandleSWI): Examine swi_mask to see if a particular
+        SWI call should be emulated.
+       Do not fall through from AngelSWI_Reason_WriteC.
+       Propagate exit code from RedBoot Exit SWI.
+       * rdi-dgb.h (swi_mask): Prototype.
+       (SWI_MASK_DEMON, SWI_MASK_ANGEL, SWI_MASK_REDBOOT): Define.
+       * wrapper.c: Include run-sim.h.
+       (sim_target_parse_command_line): New function.  Look for and
+       handle --swi-support switch.
+       (sim_target_parse_arg_array): New function.  Process an argv
+       array for parsing by sim_target_parse_command_line.
+       (sim_target_display_usage): New function.  Describe syntax of
+       --swi-suppoort switch.
+       (sim_open): Add call to sim_target_parse_arg_array).
+
+2002-05-17  Nick Clifton  <nickc@cambridge.redhat.com>
+
+       * Makefile.in (SWI_TARGET_SWITCHES): Define.
+       * armos.c (swi_mask): Define.  Initialise to supporting all
+       SWI emulations.
+       (ARMul_OSInit): For XScale targets, only support the ANGEL
+       SWI interface.  (This is at the request if Intel).
+       (ARMul_OSHandleSWI): Examine swi_mask to see if a particular
+        SWI call should be emulated.
+       Do not fall through from AngelSWI_Reason_WriteC.
+       Propagate exit code from RedBoot Exit SWI.
+       * rdi-dgb.h (swi_mask): Prototype.
+       (SWI_MASK_DEMON, SWI_MASK_ANGEL, SWI_MASK_REDBOOT): Define.
+       * wrapper.c (sim_target_parse_command_line): New function.
+       Look for and handle --swi-support switch.
+       (sim_target_parse_arg_array): New function.  Process an argv
+       array for parsing by sim_target_parse_command_line.
+       (sim_target_display_usage): New function.  Describe syntax of
+       --swi-suppoort switch.
+       (sim_open): Add call to sim_target_parse_arg_array).
+
 2002-05-09  Nick Clifton  <nickc@cambridge.redhat.com>
 
        * armos.c (ARMul_OSHandleSWI): Support the RedBoot SWI in ARM
index cb7c0d904816708219665b4808375bb3e236019e..79bbc88d6c392083a7068db11fb6d383bd1f7a1a 100644 (file)
@@ -18,7 +18,7 @@
 
 ## COMMON_PRE_CONFIG_FRAG
 
-SIM_EXTRA_CFLAGS = -DMODET -DNEED_UI_LOOP_HOOK
+SIM_EXTRA_CFLAGS = -DMODET -DNEED_UI_LOOP_HOOK -DSIM_TARGET_SWITCHES
 
 COPRO=@COPRO@
 
index d833665ac2d56e7868c754fe4a893ed2bab6eb13..1d4f79750996256b74960105515665972b6270f0 100644 (file)
@@ -125,6 +125,10 @@ struct OSblock
 #define FIXCRLF(t,c) c
 #endif
 
+/* Bit mask of enabled SWI implementations.  */
+unsigned int swi_mask = -1;
+
+
 static ARMword softvectorcode[] =
 {
   /* Basic: swi tidyexception + event; mov pc, lr;
@@ -226,6 +230,10 @@ ARMul_OSInit (ARMul_State * state)
 #endif /* VALIDATE */
 #endif /* NOOS */
 
+  /* Intel do not want DEMON SWI support.  */
+   if (state->is_XScale)
+    swi_mask = SWI_MASK_ANGEL;
   return TRUE;
 }
 
@@ -397,110 +405,134 @@ SWIflen (ARMul_State * state, ARMword fh)
 unsigned
 ARMul_OSHandleSWI (ARMul_State * state, ARMword number)
 {
-  ARMword          addr;
-  ARMword          temp;
-  ARMword          saved_number = 0;
   struct OSblock * OSptr = (struct OSblock *) state->OSptr;
-  
-  /* Intel do not want DEMON SWI support.  */
-  if (state->is_XScale)
-    switch (number)
-    {
-    case SWI_Read:
-    case SWI_Write:
-    case SWI_Open:
-    case SWI_Clock:
-    case SWI_Time:
-    case SWI_Close:
-    case SWI_Flen:
-    case SWI_Exit:
-    case SWI_Seek:
-    case SWI_WriteC:
-    case SWI_Write0:
-    case SWI_GetErrno:
-    case SWI_GetEnv:
-      saved_number = number;
-      number = -1;
-    default:
-      break;
-    }
-  
+  int              unhandled = FALSE;
+
   switch (number)
     {
     case SWI_Read:
-      SWIread (state, state->Reg[0], state->Reg[1], state->Reg[2]);
+      if (swi_mask & SWI_MASK_DEMON)
+       SWIread (state, state->Reg[0], state->Reg[1], state->Reg[2]);
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_Write:
-      SWIwrite (state, state->Reg[0], state->Reg[1], state->Reg[2]);
+      if (swi_mask & SWI_MASK_DEMON)
+       SWIwrite (state, state->Reg[0], state->Reg[1], state->Reg[2]);
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_Open:
-      SWIopen (state, state->Reg[0], state->Reg[1]);
+      if (swi_mask & SWI_MASK_DEMON)
+       SWIopen (state, state->Reg[0], state->Reg[1]);
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_Clock:
-      /* Return number of centi-seconds.  */
-      state->Reg[0] =
+      if (swi_mask & SWI_MASK_DEMON)
+       {
+         /* Return number of centi-seconds.  */
+         state->Reg[0] =
 #ifdef CLOCKS_PER_SEC
-       (CLOCKS_PER_SEC >= 100)
-       ? (ARMword) (clock () / (CLOCKS_PER_SEC / 100))
-       : (ARMword) ((clock () * 100) / CLOCKS_PER_SEC);
+           (CLOCKS_PER_SEC >= 100)
+           ? (ARMword) (clock () / (CLOCKS_PER_SEC / 100))
+           : (ARMword) ((clock () * 100) / CLOCKS_PER_SEC);
 #else
-       /* Presume unix... clock() returns microseconds.  */
-       (ARMword) (clock () / 10000);
+         /* Presume unix... clock() returns microseconds.  */
+         (ARMword) (clock () / 10000);
 #endif
-      OSptr->ErrorNo = errno;
+         OSptr->ErrorNo = errno;
+       }
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_Time:
-      state->Reg[0] = (ARMword) sim_callback->time (sim_callback, NULL);
-      OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+      if (swi_mask & SWI_MASK_DEMON)
+       {
+         state->Reg[0] = (ARMword) sim_callback->time (sim_callback, NULL);
+         OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+       }
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_Close:
-      state->Reg[0] = sim_callback->close (sim_callback, state->Reg[0]);
-      OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+      if (swi_mask & SWI_MASK_DEMON)
+       {
+         state->Reg[0] = sim_callback->close (sim_callback, state->Reg[0]);
+         OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+       }
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_Flen:
-      SWIflen (state, state->Reg[0]);
+      if (swi_mask & SWI_MASK_DEMON)
+       SWIflen (state, state->Reg[0]);
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_Exit:
-      state->Emulate = FALSE;
+      if (swi_mask & SWI_MASK_DEMON)
+       state->Emulate = FALSE;
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_Seek:
-      /* We must return non-zero for failure.  */
-      state->Reg[0] = -1 >= sim_callback->lseek (sim_callback, state->Reg[0], state->Reg[1], SEEK_SET);
-      OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+      if (swi_mask & SWI_MASK_DEMON)
+       {
+         /* We must return non-zero for failure.  */
+         state->Reg[0] = -1 >= sim_callback->lseek (sim_callback, state->Reg[0], state->Reg[1], SEEK_SET);
+         OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+       }
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_WriteC:
-      {
-       char tmp = state->Reg[0];
-       (void) sim_callback->write_stdout (sim_callback, &tmp, 1);
-       OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
-      }
+      if (swi_mask & SWI_MASK_DEMON)
+       {
+         char tmp = state->Reg[0];
+         (void) sim_callback->write_stdout (sim_callback, &tmp, 1);
+         OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+       }
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_Write0:
-      SWIWrite0 (state, state->Reg[0]);
+      if (swi_mask & SWI_MASK_DEMON)
+       SWIWrite0 (state, state->Reg[0]);
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_GetErrno:
-      state->Reg[0] = OSptr->ErrorNo;
+      if (swi_mask & SWI_MASK_DEMON)
+       state->Reg[0] = OSptr->ErrorNo;
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_GetEnv:
-      state->Reg[0] = ADDRCMDLINE;
-      if (state->MemSize)
-       state->Reg[1] = state->MemSize;
-      else
-       state->Reg[1] = ADDRUSERSTACK;
+      if (swi_mask & SWI_MASK_DEMON)
+       {
+         state->Reg[0] = ADDRCMDLINE;
+         if (state->MemSize)
+           state->Reg[1] = state->MemSize;
+         else
+           state->Reg[1] = ADDRUSERSTACK;
 
-      WriteCommandLineTo (state, state->Reg[0]);
+         WriteCommandLineTo (state, state->Reg[0]);
+       }
+      else
+       unhandled = TRUE;
       break;
 
     case SWI_Breakpoint:
@@ -511,132 +543,141 @@ ARMul_OSHandleSWI (ARMul_State * state, ARMword number)
       /* Handle Angel SWIs as well as Demon ones.  */
     case AngelSWI_ARM:
     case AngelSWI_Thumb:
-      /* R1 is almost always a parameter block.  */
-      addr = state->Reg[1];
-      /* R0 is a reason code.  */
-      switch (state->Reg[0])
+      if (swi_mask & SWI_MASK_ANGEL)
        {
-         /* 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:
-         state->Emulate = FALSE;
-         return FALSE;
-
-       case AngelSWI_Reason_Clock:
-         /* Return number of centi-seconds.  */
-         state->Reg[0] =
+         ARMword addr;
+         ARMword temp;
+
+         /* R1 is almost always a parameter block.  */
+         addr = state->Reg[1];
+         /* R0 is a reason code.  */
+         switch (state->Reg[0])
+           {
+             /* 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:
+             state->Emulate = FALSE;
+             return FALSE;
+
+           case AngelSWI_Reason_Clock:
+             /* Return number of centi-seconds.  */
+             state->Reg[0] =
 #ifdef CLOCKS_PER_SEC
-           (CLOCKS_PER_SEC >= 100)
-           ? (ARMword) (clock () / (CLOCKS_PER_SEC / 100))
-           : (ARMword) ((clock () * 100) / CLOCKS_PER_SEC);
+               (CLOCKS_PER_SEC >= 100)
+               ? (ARMword) (clock () / (CLOCKS_PER_SEC / 100))
+               : (ARMword) ((clock () * 100) / CLOCKS_PER_SEC);
 #else
-           /* Presume unix... clock() returns microseconds.  */
-           (ARMword) (clock () / 10000);
+             /* Presume unix... clock() returns microseconds.  */
+             (ARMword) (clock () / 10000);
 #endif
-         OSptr->ErrorNo = errno;
-         break;
-
-       case AngelSWI_Reason_Time:
-         state->Reg[0] = (ARMword) sim_callback->time (sim_callback, NULL);
-         OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
-         break;
-
-       case AngelSWI_Reason_WriteC:
-         {
-           char tmp = ARMul_SafeReadByte (state, addr);
-           (void) sim_callback->write_stdout (sim_callback, &tmp, 1);
-           OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
-         }
-         /* Fall thgrough.  */
-
-       case AngelSWI_Reason_Write0:
-         SWIWrite0 (state, addr);
-         break;
-
-       case AngelSWI_Reason_Close:
-         state->Reg[0] = sim_callback->close (sim_callback, ARMul_ReadWord (state, addr));
-         OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
-         break;
-
-       case AngelSWI_Reason_Seek:
-         state->Reg[0] = -1 >= sim_callback->lseek (sim_callback, ARMul_ReadWord (state, addr),
-                                      ARMul_ReadWord (state, addr + 4),
-                                      SEEK_SET);
-         OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
-         break;
-
-       case AngelSWI_Reason_FLen:
-         SWIflen (state, ARMul_ReadWord (state, addr));
-         break;
-
-       case AngelSWI_Reason_GetCmdLine:
-         WriteCommandLineTo (state, ARMul_ReadWord (state, addr));
-         break;
-
-       case AngelSWI_Reason_HeapInfo:
-         /* R1 is a pointer to a pointer.  */
-         addr = ARMul_ReadWord (state, addr);
-
-         /* Pick up the right memory limit.  */
-         if (state->MemSize)
-           temp = state->MemSize;
-         else
-           temp = ADDRUSERSTACK;
-
-         ARMul_WriteWord (state, addr, 0);             /* Heap base.  */
-         ARMul_WriteWord (state, addr + 4, temp);      /* Heap limit.  */
-         ARMul_WriteWord (state, addr + 8, temp);      /* Stack base.  */
-         ARMul_WriteWord (state, addr + 12, temp);     /* Stack limit.  */
-         break;
-
-       case AngelSWI_Reason_ReportException:
-         if (state->Reg[1] == ADP_Stopped_ApplicationExit)
-           state->Reg[0] = 0;
-         else
-           state->Reg[0] = -1;
-         state->Emulate = FALSE;
-         break;
-
-       case ADP_Stopped_ApplicationExit:
-         state->Reg[0] = 0;
-         state->Emulate = FALSE;
-         break;
-
-       case ADP_Stopped_RunTimeError:
-         state->Reg[0] = -1;
-         state->Emulate = FALSE;
-         break;
-
-       case AngelSWI_Reason_Errno:
-         state->Reg[0] = OSptr->ErrorNo;
-         break;
-
-       case AngelSWI_Reason_Open:
-         SWIopen (state,
-                  ARMul_ReadWord (state, addr),
-                  ARMul_ReadWord (state, addr + 4));
-         break;
-
-       case AngelSWI_Reason_Read:
-         SWIread (state,
-                  ARMul_ReadWord (state, addr),
-                  ARMul_ReadWord (state, addr + 4),
-                  ARMul_ReadWord (state, addr + 8));
-         break;
-
-       case AngelSWI_Reason_Write:
-         SWIwrite (state,
-                   ARMul_ReadWord (state, addr),
-                   ARMul_ReadWord (state, addr + 4),
-                   ARMul_ReadWord (state, addr + 8));
-         break;
+             OSptr->ErrorNo = errno;
+             break;
+
+           case AngelSWI_Reason_Time:
+             state->Reg[0] = (ARMword) sim_callback->time (sim_callback, NULL);
+             OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+             break;
+
+           case AngelSWI_Reason_WriteC:
+             {
+               char tmp = ARMul_SafeReadByte (state, addr);
+               (void) sim_callback->write_stdout (sim_callback, &tmp, 1);
+               OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+               break;
+             }
+
+           case AngelSWI_Reason_Write0:
+             SWIWrite0 (state, addr);
+             break;
+
+           case AngelSWI_Reason_Close:
+             state->Reg[0] = sim_callback->close (sim_callback, ARMul_ReadWord (state, addr));
+             OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+             break;
+
+           case AngelSWI_Reason_Seek:
+             state->Reg[0] = -1 >= sim_callback->lseek (sim_callback, ARMul_ReadWord (state, addr),
+                                                        ARMul_ReadWord (state, addr + 4),
+                                                        SEEK_SET);
+             OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+             break;
+
+           case AngelSWI_Reason_FLen:
+             SWIflen (state, ARMul_ReadWord (state, addr));
+             break;
+
+           case AngelSWI_Reason_GetCmdLine:
+             WriteCommandLineTo (state, ARMul_ReadWord (state, addr));
+             break;
+
+           case AngelSWI_Reason_HeapInfo:
+             /* R1 is a pointer to a pointer.  */
+             addr = ARMul_ReadWord (state, addr);
+
+             /* Pick up the right memory limit.  */
+             if (state->MemSize)
+               temp = state->MemSize;
+             else
+               temp = ADDRUSERSTACK;
+
+             ARMul_WriteWord (state, addr, 0);         /* Heap base.  */
+             ARMul_WriteWord (state, addr + 4, temp);  /* Heap limit.  */
+             ARMul_WriteWord (state, addr + 8, temp);  /* Stack base.  */
+             ARMul_WriteWord (state, addr + 12, temp); /* Stack limit.  */
+             break;
+
+           case AngelSWI_Reason_ReportException:
+             if (state->Reg[1] == ADP_Stopped_ApplicationExit)
+               state->Reg[0] = 0;
+             else
+               state->Reg[0] = -1;
+             state->Emulate = FALSE;
+             break;
+
+           case ADP_Stopped_ApplicationExit:
+             state->Reg[0] = 0;
+             state->Emulate = FALSE;
+             break;
+
+           case ADP_Stopped_RunTimeError:
+             state->Reg[0] = -1;
+             state->Emulate = FALSE;
+             break;
+
+           case AngelSWI_Reason_Errno:
+             state->Reg[0] = OSptr->ErrorNo;
+             break;
+
+           case AngelSWI_Reason_Open:
+             SWIopen (state,
+                      ARMul_ReadWord (state, addr),
+                      ARMul_ReadWord (state, addr + 4));
+             break;
+
+           case AngelSWI_Reason_Read:
+             SWIread (state,
+                      ARMul_ReadWord (state, addr),
+                      ARMul_ReadWord (state, addr + 4),
+                      ARMul_ReadWord (state, addr + 8));
+             break;
+
+           case AngelSWI_Reason_Write:
+             SWIwrite (state,
+                       ARMul_ReadWord (state, addr),
+                       ARMul_ReadWord (state, addr + 4),
+                       ARMul_ReadWord (state, addr + 8));
+             break;
+           }
        }
+      else
+       unhandled = TRUE;
+      break;
 
     case 0x90:
     case 0x91:
@@ -645,78 +686,84 @@ ARMul_OSHandleSWI (ARMul_State * state, ARMword number)
       break;
       
     case 0x180001: /* RedBoot's Syscall SWI in ARM mode.  */
-      switch (state->Reg[0])
+      if (swi_mask & SWI_MASK_REDBOOT)
        {
-         /* These numbers are defined in libgloss/syscall.h
-            but the simulator should not be dependend upon
-            libgloss being installed.  */
-       case 1:  /* Exit.  */
-         state->Emulate = FALSE;
-         return TRUE;
-
-       case 2:  /* Open.  */
-         SWIopen (state, state->Reg[1], state->Reg[2]);
-         return TRUE;
-
-       case 3:  /* Close.  */
-         state->Reg[0] = sim_callback->close (sim_callback, state->Reg[1]);
-         OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
-         return TRUE;
-
-       case 4:  /* Read.  */
-         SWIread (state, state->Reg[1], state->Reg[2], state->Reg[3]);
-         return TRUE;
-
-       case 5:  /* Write.  */
-         SWIwrite (state, state->Reg[1], state->Reg[2], state->Reg[3]);
-         return TRUE;
-
-       case 6:  /* Lseek.  */
-         state->Reg[0] = sim_callback->lseek (sim_callback,
-                                              state->Reg[1],
-                                              state->Reg[2],
-                                              state->Reg[3]);
-         OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
-         return TRUE;
-
-       case 17: /* Utime.  */
-         state->Reg[0] = (ARMword) sim_callback->time (sim_callback,
-                                                       (long *) state->Reg[1]);
-         OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
-         return TRUE;
-
-       case 7:  /* Unlink.  */
-       case 8:  /* Getpid.  */
-       case 9:  /* Kill.  */
-       case 10: /* Fstat.  */
-       case 11: /* Sbrk.  */
-       case 12: /* Argvlen.  */
-       case 13: /* Argv.  */
-       case 14: /* ChDir.  */
-       case 15: /* Stat.  */
-       case 16: /* Chmod.  */
-       case 18: /* Time.  */
-         sim_callback->printf_filtered
-           (sim_callback,
-            "sim: unhandled RedBoot syscall '%d' encountered - ignoring\n",
-            state->Reg[0]);
-         return FALSE;
-
-       default:
-         sim_callback->printf_filtered
-           (sim_callback,
-            "sim: unknown RedBoot syscall '%d' encountered - ignoring\n",
-            state->Reg[0]);
-         return FALSE;
+         switch (state->Reg[0])
+           {
+             /* These numbers are defined in libgloss/syscall.h
+                but the simulator should not be dependend upon
+                libgloss being installed.  */
+           case 1:  /* Exit.  */
+             state->Emulate = FALSE;
+             /* Copy exit code into r0.  */
+             state->Reg[0] = state->Reg[1];
+             break;
+
+           case 2:  /* Open.  */
+             SWIopen (state, state->Reg[1], state->Reg[2]);
+             break;
+
+           case 3:  /* Close.  */
+             state->Reg[0] = sim_callback->close (sim_callback, state->Reg[1]);
+             OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+             break;
+
+           case 4:  /* Read.  */
+             SWIread (state, state->Reg[1], state->Reg[2], state->Reg[3]);
+             break;
+
+           case 5:  /* Write.  */
+             SWIwrite (state, state->Reg[1], state->Reg[2], state->Reg[3]);
+             break;
+
+           case 6:  /* Lseek.  */
+             state->Reg[0] = sim_callback->lseek (sim_callback,
+                                                  state->Reg[1],
+                                                  state->Reg[2],
+                                                  state->Reg[3]);
+             OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+             break;
+
+           case 17: /* Utime.  */
+             state->Reg[0] = (ARMword) sim_callback->time (sim_callback,
+                                                           (long *) state->Reg[1]);
+             OSptr->ErrorNo = sim_callback->get_errno (sim_callback);
+             break;
+
+           case 7:  /* Unlink.  */
+           case 8:  /* Getpid.  */
+           case 9:  /* Kill.  */
+           case 10: /* Fstat.  */
+           case 11: /* Sbrk.  */
+           case 12: /* Argvlen.  */
+           case 13: /* Argv.  */
+           case 14: /* ChDir.  */
+           case 15: /* Stat.  */
+           case 16: /* Chmod.  */
+           case 18: /* Time.  */
+             sim_callback->printf_filtered
+               (sim_callback,
+                "sim: unhandled RedBoot syscall '%d' encountered - ignoring\n",
+                state->Reg[0]);
+             return FALSE;
+
+           default:
+             sim_callback->printf_filtered
+               (sim_callback,
+                "sim: unknown RedBoot syscall '%d' encountered - ignoring\n",
+                state->Reg[0]);
+             return FALSE;
+           }
+         break;
        }
-      return TRUE;
       
     default:
-      /* If there is a SWI vector installed use it.  */
-      if (state->is_XScale && saved_number != -1)
-       number = saved_number;
-           
-      if (SWI_vector_installed && number != SWI_Breakpoint)
+      unhandled = TRUE;
+    }
+      
+  if (unhandled)
+    {
+      if (SWI_vector_installed)
        {
          ARMword cpsr;
          ARMword i_size;
index 35924ec22670c1e643906c544499ffbe8fc2e0c7..14d9d7039162d876974ee4bf4264573a0f71882d 100644 (file)
@@ -330,3 +330,9 @@ struct RDIProcVec
 };
 
 #endif
+
+extern unsigned int swi_mask;
+
+#define SWI_MASK_DEMON         (1 << 0)
+#define SWI_MASK_ANGEL         (1 << 1)
+#define SWI_MASK_REDBOOT       (1 << 2)
index 773ef354d86a681588a84dc7b98634404e44a1b1..7493e8c9b9bce653391342ae76ce267b09ff70be 100644 (file)
@@ -35,6 +35,7 @@
 #include "dbg_rdi.h"
 #include "ansidecl.h"
 #include "sim-utils.h"
+#include "run-sim.h"
 
 host_callback *sim_callback;
 
@@ -426,6 +427,119 @@ sim_fetch_register (sd, rn, memory, length)
   return -1;
 }
 
+#ifdef SIM_TARGET_SWITCHES
+
+static void sim_target_parse_arg_array PARAMS ((char **));
+
+typedef struct
+{
+  char *       swi_option;
+  unsigned int swi_mask;
+} swi_options;
+
+#define SWI_SWITCH     "--swi-support"
+
+static swi_options options[] =
+  {
+    { "none",    0 },
+    { "demon",   SWI_MASK_DEMON },
+    { "angel",   SWI_MASK_ANGEL },
+    { "redboot", SWI_MASK_REDBOOT },
+    { "all",     -1 },
+    { "NONE",    0 },
+    { "DEMON",   SWI_MASK_DEMON },
+    { "ANGEL",   SWI_MASK_ANGEL },
+    { "REDBOOT", SWI_MASK_REDBOOT },
+    { "ALL",     -1 }
+  };
+
+
+int
+sim_target_parse_command_line (argc, argv)
+     int argc;
+     char ** argv;
+{
+  int i;
+
+  for (i = 1; i < argc; i++)
+    {
+      char * ptr = argv[i];
+      int arg;
+
+      if ((ptr == NULL) || (* ptr != '-'))
+       break;
+
+      if (strncmp (ptr, SWI_SWITCH, sizeof SWI_SWITCH - 1) != 0)
+       continue;
+
+      if (ptr[sizeof SWI_SWITCH - 1] == 0)
+       {
+         /* Remove this option from the argv array.  */
+         for (arg = i; arg < argc; arg ++)
+           argv[arg] = argv[arg + 1];
+         argc --;
+         
+         ptr = argv[i];
+       }
+      else
+       ptr += sizeof SWI_SWITCH;
+
+      swi_mask = 0;
+      
+      while (* ptr)
+       {
+         int i;
+
+         for (i = sizeof options / sizeof options[0]; i--;)
+           if (strncmp (ptr, options[i].swi_option,
+                        strlen (options[i].swi_option)) == 0)
+             {
+               swi_mask |= options[i].swi_mask;
+               ptr += strlen (options[i].swi_option);
+
+               if (* ptr == ',')
+                 ++ ptr;
+
+               break;
+             }
+
+         if (i < 0)
+           break;
+       }
+
+      if (* ptr != 0)
+       fprintf (stderr, "Ignoring swi options: %s\n", ptr);
+      
+      /* Remove this option from the argv array.  */
+      for (arg = i; arg < argc; arg ++)
+       argv[arg] = argv[arg + 1];
+      argc --;
+      i --;
+    }
+  return argc;
+}
+
+static void
+sim_target_parse_arg_array (argv)
+     char ** argv;
+{
+  int i;
+
+  for (i = 0; argv[i]; i++)
+    ;
+
+  return (void) sim_target_parse_command_line (i, argv);
+}
+
+void
+sim_target_display_usage ()
+{
+  fprintf (stderr, "%s=<list>  Comma seperated list of SWI protocols to supoport.\n\
+                This list can contain: NONE, DEMON, ANGEL, REDBOOT and/or ALL.\n",
+          SWI_SWITCH);
+}
+#endif
+
 SIM_DESC
 sim_open (kind, ptr, abfd, argv)
      SIM_OPEN_KIND kind;
@@ -438,6 +552,10 @@ sim_open (kind, ptr, abfd, argv)
   myname = (char *) xstrdup (argv[0]);
   sim_callback = ptr;
 
+#ifdef SIM_TARGET_SWITCHES
+  sim_target_parse_arg_array (argv);
+#endif
+  
   /* Decide upon the endian-ness of the processor.
      If we can, get the information from the bfd itself.
      Otherwise look to see if we have been given a command
index ee6bd719325b9e2e76f3278fbb903d60cc73d268..65aa6b165ce1905785a0d30a010b15c1ef59131a 100644 (file)
@@ -1,3 +1,13 @@
+2002-05-20  Nick Clifton  <nickc@cambridge.redhat.com>
+
+       * run-sim.h: New header.  Provide prototypes for functions used
+       between run() and libsim.a which are not used by GDB.
+       * run.c: Include run-sim.h.
+        (main): If SIM_TARGET_SWITCHES is defined call
+        sim_target_parse_command_line.
+        (usage): If SIM_TARGET_SWITCHES is defined call
+        sim_target_display_usage.
+
 2002-05-17  Andrey Volkov  <avolkov@transas.com>
 
        * run.c: Made h8300s as new target, not h8300h alias.
diff --git a/sim/common/run-sim.h b/sim/common/run-sim.h
new file mode 100644 (file)
index 0000000..7792373
--- /dev/null
@@ -0,0 +1,32 @@
+/* This file defines the part of the interface between the standalone
+   simaulator program - run - and simulator library - libsim.a - that
+   is not used by GDB.  The GDB part is described in include/remote-sim.h.
+   
+   Copyright 2002 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#ifdef SIM_TARGET_SWITCHES
+  /* Parse the command line, extracting any target specific switches
+     before the generic simulator code gets a chance to complain
+     about them.  Returns the adjusted value of argc.  */
+int sim_target_parse_command_line PARAMS ((int, char **));
+
+  /* Display a list of target specific switches supported by this
+     target.  */
+void sim_target_display_usage PARAMS ((void));
+#endif
index 6a21586bf69c4def33c229e23bdbf2efaca89f02..874f4b3bd5cbbc60f6abcc01fbccadec57bf208d 100644 (file)
@@ -1,5 +1,5 @@
 /* run front end support for all the simulators.
-   Copyright (C) 1992, 93-96, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1992, 93-96, 1997, 2002 Free Software Foundation, Inc.
 
 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
@@ -46,6 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "callback.h"
 #include "remote-sim.h"
 #include "ansidecl.h"
+#include "run-sim.h"
 
 static void usage PARAMS ((void));
 extern int optind;
@@ -111,6 +112,10 @@ main (ac, av)
   default_callback.init (&default_callback);
   sim_set_callbacks (&default_callback);
 
+#ifdef SIM_TARGET_SWITCHES
+  ac = sim_target_parse_command_line (ac, av);
+#endif
+
   /* FIXME: This is currently being rewritten to have each simulator
      do all argv processing.  */
 
@@ -338,5 +343,9 @@ usage ()
   fprintf (stderr, "\n");
   fprintf (stderr, "program args    Arguments to pass to simulated program.\n");
   fprintf (stderr, "                Note: Very few simulators support this.\n");
+#ifdef SIM_TARGET_SWITCHES
+  fprintf (stderr, "\nTarget specific options:\n");
+  sim_target_display_usage ();
+#endif
   exit (1);
 }