]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - sim/bfin/interp.c
sim: watchpoints: use common sim_pc_get
[thirdparty/binutils-gdb.git] / sim / bfin / interp.c
index 2da70b50b62bbb888cdbed268d2e28f4a76643e5..ceb5939f4e6b10281a6c426d8020d1ad294f3545 100644 (file)
@@ -1,6 +1,6 @@
 /* Simulator for Analog Devices Blackfin processors.
 
-   Copyright (C) 2005-2015 Free Software Foundation, Inc.
+   Copyright (C) 2005-2021 Free Software Foundation, Inc.
    Contributed by Analog Devices, Inc.
 
    This file is part of simulators.
@@ -112,20 +112,6 @@ static const char cb_libgloss_stat_map_32[] =
 "space,4:st_blksize,4:st_blocks,4:space,8";
 static const char *stat_map_32, *stat_map_64;
 
-/* Count the number of arguments in an argv.  */
-static int
-count_argc (const char * const *argv)
-{
-  int i;
-
-  if (! argv)
-    return -1;
-
-  for (i = 0; argv[i] != NULL; ++i)
-    continue;
-  return i;
-}
-
 /* Simulate a monitor trap, put the result into r0 and errno into r1
    return offset by which to adjust pc.  */
 
@@ -133,7 +119,7 @@ void
 bfin_syscall (SIM_CPU *cpu)
 {
   SIM_DESC sd = CPU_STATE (cpu);
-  const char * const *argv = (void *)STATE_PROG_ARGV (sd);
+  char * const *argv = (void *)STATE_PROG_ARGV (sd);
   host_callback *cb = STATE_CALLBACK (sd);
   bu32 args[6];
   CB_SYSCALL sc;
@@ -180,12 +166,12 @@ bfin_syscall (SIM_CPU *cpu)
 #ifdef CB_SYS_argc
     case CB_SYS_argc:
       tbuf += sprintf (tbuf, "argc()");
-      sc.result = count_argc (argv);
+      sc.result = countargv ((char **)argv);
       break;
     case CB_SYS_argnlen:
       {
       tbuf += sprintf (tbuf, "argnlen(%u)", args[0]);
-       if (sc.arg1 < count_argc (argv))
+       if (sc.arg1 < countargv ((char **)argv))
          sc.result = strlen (argv[sc.arg1]);
        else
          sc.result = -1;
@@ -194,7 +180,7 @@ bfin_syscall (SIM_CPU *cpu)
     case CB_SYS_argn:
       {
        tbuf += sprintf (tbuf, "argn(%u)", args[0]);
-       if (sc.arg1 < count_argc (argv))
+       if (sc.arg1 < countargv ((char **)argv))
          {
            const char *argn = argv[sc.arg1];
            int len = strlen (argn);
@@ -303,7 +289,7 @@ bfin_syscall (SIM_CPU *cpu)
        sc.result = heap;
        heap += sc.arg2;
        /* Keep it page aligned.  */
-       heap = ALIGN (heap, 4096);
+       heap = align_up (heap, 4096);
 
        break;
       }
@@ -620,6 +606,8 @@ step_once (SIM_CPU *cpu)
     trace_prefix (sd, cpu, NULL_CIA, oldpc, TRACE_LINENUM_P (cpu),
                  NULL, 0, " "); /* Use a space for gcc warnings.  */
 
+  TRACE_DISASM (cpu, oldpc);
+
   /* Handle hardware single stepping when lower than EVT3, and when SYSCFG
      has already had the SSSTEP bit enabled.  */
   ssstep = false;
@@ -728,7 +716,7 @@ bfin_initialize_cpu (SIM_DESC sd, SIM_CPU *cpu)
 
 SIM_DESC
 sim_open (SIM_OPEN_KIND kind, host_callback *callback,
-         struct bfd *abfd, char **argv)
+         struct bfd *abfd, char * const *argv)
 {
   char c;
   int i;
@@ -741,13 +729,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback,
       return 0;
     }
 
-  {
-    /* XXX: Only first core gets profiled ?  */
-    SIM_CPU *cpu = STATE_CPU (sd, 0);
-    STATE_WATCHPOINTS (sd)->pc = &PCREG;
-    STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (PCREG);
-  }
-
   if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
     {
       free_state (sd);
@@ -769,9 +750,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback,
   e_sim_add_option_table (sd, bfin_mmu_options);
   e_sim_add_option_table (sd, bfin_mach_options);
 
-  /* getopt will print the error message so we just have to exit if this fails.
-     FIXME: Hmmm...  in the case of gdb we need getopt to call
-     print_filtered.  */
+  /* The parser will print an error message for us, so we silently return.  */
   if (sim_parse_args (sd, argv) != SIM_RC_OK)
     {
       free_state (sd);
@@ -821,7 +800,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback,
 }
 
 /* Some utils don't like having a NULL environ.  */
-static const char * const simple_env[] = { "HOME=/", "PATH=/bin", NULL };
+static char * const simple_env[] = { "HOME=/", "PATH=/bin", NULL };
 
 static bu32 fdpic_load_offset;
 
@@ -931,7 +910,7 @@ bfin_fdpic_load (SIM_DESC sd, SIM_CPU *cpu, struct bfd *abfd, bu32 *sp,
 
        free (data);
 
-       max_load_addr = MAX (paddr + memsz, max_load_addr);
+       max_load_addr = max (paddr + memsz, max_load_addr);
 
        *sp -= 12;
        sim_write (sd, *sp+0, (void *)&paddr, 4); /* loadseg.addr  */
@@ -962,7 +941,8 @@ bfin_fdpic_load (SIM_DESC sd, SIM_CPU *cpu, struct bfd *abfd, bu32 *sp,
       }
 
   /* Update the load offset with a few extra pages.  */
-  fdpic_load_offset = ALIGN (MAX (max_load_addr, fdpic_load_offset), 0x10000);
+  fdpic_load_offset = align_up (max (max_load_addr, fdpic_load_offset),
+                               0x10000);
   fdpic_load_offset += 0x10000;
 
   /* Push the summary loadmap info onto the stack last.  */
@@ -979,7 +959,7 @@ bfin_fdpic_load (SIM_DESC sd, SIM_CPU *cpu, struct bfd *abfd, bu32 *sp,
 
 static void
 bfin_user_init (SIM_DESC sd, SIM_CPU *cpu, struct bfd *abfd,
-               const char * const *argv, const char * const *env)
+               char * const *argv, char * const *env)
 {
   /* XXX: Missing host -> target endian ...  */
   /* Linux starts the user app with the stack:
@@ -1073,7 +1053,7 @@ bfin_user_init (SIM_DESC sd, SIM_CPU *cpu, struct bfd *abfd,
   sim_pc_set (cpu, elf_addrs[0]);
 
   /* Figure out how much storage the argv/env strings need.  */
-  argc = count_argc (argv);
+  argc = countargv ((char **)argv);
   if (argc == -1)
     argc = 0;
   argv_flat = argc; /* NUL bytes  */
@@ -1082,13 +1062,13 @@ bfin_user_init (SIM_DESC sd, SIM_CPU *cpu, struct bfd *abfd,
 
   if (!env)
     env = simple_env;
-  envc = count_argc (env);
+  envc = countargv ((char **)env);
   env_flat = envc; /* NUL bytes  */
   for (i = 0; i < envc; ++i)
     env_flat += strlen (env[i]);
 
   /* Push the Auxiliary Vector Table between argv/env and actual strings.  */
-  sp_flat = sp = ALIGN (SPREG - argv_flat - env_flat - 4, 4);
+  sp_flat = sp = align_up (SPREG - argv_flat - env_flat - 4, 4);
   if (auxvt)
     {
 # define AT_PUSH(at, val) \
@@ -1161,7 +1141,7 @@ bfin_user_init (SIM_DESC sd, SIM_CPU *cpu, struct bfd *abfd,
 }
 
 static void
-bfin_os_init (SIM_DESC sd, SIM_CPU *cpu, const char * const *argv)
+bfin_os_init (SIM_DESC sd, SIM_CPU *cpu, char * const *argv)
 {
   /* Pass the command line via a string in R0 like Linux expects.  */
   int i;
@@ -1198,7 +1178,7 @@ bfin_virtual_init (SIM_DESC sd, SIM_CPU *cpu)
 
 SIM_RC
 sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
-                    char **argv, char **env)
+                    char * const *argv, char * const *env)
 {
   SIM_CPU *cpu = STATE_CPU (sd, 0);
   SIM_ADDR addr;
@@ -1223,10 +1203,10 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
   switch (STATE_ENVIRONMENT (sd))
     {
     case USER_ENVIRONMENT:
-      bfin_user_init (sd, cpu, abfd, (void *)argv, (void *)env);
+      bfin_user_init (sd, cpu, abfd, argv, env);
       break;
     case OPERATING_ENVIRONMENT:
-      bfin_os_init (sd, cpu, (void *)argv);
+      bfin_os_init (sd, cpu, argv);
       break;
     default:
       bfin_virtual_init (sd, cpu);