Automatic date update in version.in
[deliverable/binutils-gdb.git] / sim / m32c / mem.c
index 474fc5e75f9bf97a01bb92c9240aec8d581334c5..d7e26828ebb5c287a805f9d51242104366b9ac48 100644 (file)
@@ -1,6 +1,6 @@
 /* mem.c --- memory for M32C simulator.
 
 /* mem.c --- memory for M32C simulator.
 
-Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
+Copyright (C) 2005-2020 Free Software Foundation, Inc.
 Contributed by Red Hat, Inc.
 
 This file is part of the GNU simulators.
 Contributed by Red Hat, Inc.
 
 This file is part of the GNU simulators.
@@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
+#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -26,8 +27,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <sys/time.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <unistd.h>
+#ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #include <sys/select.h>
+#endif
+#ifdef HAVE_TERMIOS_H
 #include <termios.h>
 #include <termios.h>
+#endif
 
 #include "mem.h"
 #include "cpu.h"
 
 #include "mem.h"
 #include "cpu.h"
@@ -48,8 +53,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 static unsigned char **pt[L1_LEN];
 
 
 static unsigned char **pt[L1_LEN];
 
+#ifdef HAVE_TERMIOS_H
 int m32c_console_ifd = 0;
 int m32c_console_ifd = 0;
+#endif
 int m32c_console_ofd = 1;
 int m32c_console_ofd = 1;
+#ifdef HAVE_TERMIOS_H
+int m32c_use_raw_console = 0;
+#endif
 
 #ifdef TIMER_A
 Timer_A timer_a;
 
 #ifdef TIMER_A
 Timer_A timer_a;
@@ -79,7 +89,7 @@ init_mem (void)
 }
 
 static unsigned char *
 }
 
 static unsigned char *
-mem_ptr (address)
+mem_ptr (int address)
 {
   static int recursing = 0;
   int pt1 = (address >> (L2_BITS + OFF_BITS)) & ((1 << L1_BITS) - 1);
 {
   static int recursing = 0;
   int pt1 = (address >> (L2_BITS + OFF_BITS)) & ((1 << L1_BITS) - 1);
@@ -129,7 +139,7 @@ mcs (int isput, int bytes)
 }
 
 void
 }
 
 void
-mem_usage_stats ()
+mem_usage_stats (void)
 {
   int i, j;
   int rstart = 0;
 {
   int i, j;
   int rstart = 0;
@@ -182,7 +192,7 @@ s (int address, char *dir)
 
 #define S(d) if (trace) s(address, d)
 static void
 
 #define S(d) if (trace) s(address, d)
 static void
-e ()
+e (void)
 {
   if (!trace)
     return;
 {
   if (!trace)
     return;
@@ -195,7 +205,7 @@ e ()
 
 extern int m32c_disassemble;
 
 
 extern int m32c_disassemble;
 
-void
+static void
 mem_put_byte (int address, unsigned char value)
 {
   unsigned char *m;
 mem_put_byte (int address, unsigned char value)
 {
   unsigned char *m;
@@ -355,29 +365,30 @@ mem_put_si (int address, unsigned long value)
 }
 
 void
 }
 
 void
-mem_put_blk (int address, void *bufptr, int nbytes)
+mem_put_blk (int address, const void *bufptr, int nbytes)
 {
   S ("<=");
   if (enable_counting)
     mem_counters[1][1] += nbytes;
   while (nbytes--)
 {
   S ("<=");
   if (enable_counting)
     mem_counters[1][1] += nbytes;
   while (nbytes--)
-    mem_put_byte (address++, *(unsigned char *) bufptr++);
+    mem_put_byte (address++, *(const unsigned char *) bufptr++);
   E ();
 }
 
 unsigned char
   E ();
 }
 
 unsigned char
-mem_get_pc ()
+mem_get_pc (void)
 {
   unsigned char *m = mem_ptr (regs.r_pc & membus_mask);
   COUNT (0, 0);
   return *m;
 }
 
 {
   unsigned char *m = mem_ptr (regs.r_pc & membus_mask);
   COUNT (0, 0);
   return *m;
 }
 
+#ifdef HAVE_TERMIOS_H
 static int console_raw = 0;
 static struct termios oattr;
 
 static int
 static int console_raw = 0;
 static struct termios oattr;
 
 static int
-stdin_ready ()
+stdin_ready (void)
 {
   fd_set ifd;
   int n;
 {
   fd_set ifd;
   int n;
@@ -392,11 +403,13 @@ stdin_ready ()
 }
 
 void
 }
 
 void
-m32c_sim_restore_console ()
+m32c_sim_restore_console (void)
 {
 {
-  tcsetattr (m32c_console_ifd, TCSANOW, &oattr);
+  if (console_raw)
+    tcsetattr (m32c_console_ifd, TCSANOW, &oattr);
   console_raw = 0;
 }
   console_raw = 0;
 }
+#endif
 
 static unsigned char
 mem_get_byte (int address)
 
 static unsigned char
 mem_get_byte (int address)
@@ -406,12 +419,13 @@ mem_get_byte (int address)
   m = mem_ptr (address);
   switch (address)
     {
   m = mem_ptr (address);
   switch (address)
     {
+#ifdef HAVE_TERMIOS_H
     case 0x2ed:                /* m32c uart1c1 */
     case 0x3ad:                /* m16c uart1c1 */
 
     case 0x2ed:                /* m32c uart1c1 */
     case 0x3ad:                /* m16c uart1c1 */
 
-#if 0
-      if (!console_raw)
+      if (!console_raw && m32c_use_raw_console)
        {
        {
+         struct termios attr;
          tcgetattr (m32c_console_ifd, &attr);
          tcgetattr (m32c_console_ifd, &oattr);
          /* We want each key to be sent as the user presses them.  */
          tcgetattr (m32c_console_ifd, &attr);
          tcgetattr (m32c_console_ifd, &oattr);
          /* We want each key to be sent as the user presses them.  */
@@ -420,7 +434,6 @@ mem_get_byte (int address)
          console_raw = 1;
          atexit (m32c_sim_restore_console);
        }
          console_raw = 1;
          atexit (m32c_sim_restore_console);
        }
-#endif
 
       if (stdin_ready ())
        return 0x02;            /* tx empty and rx full */
 
       if (stdin_ready ())
        return 0x02;            /* tx empty and rx full */
@@ -446,6 +459,7 @@ mem_get_byte (int address)
          }
        return c;
       }
          }
        return c;
       }
+#endif
 
 #ifdef TIMER_A
     case 0x346:                /* TA0low */
 
 #ifdef TIMER_A
     case 0x346:                /* TA0low */
@@ -456,6 +470,9 @@ mem_get_byte (int address)
       return timer_a.count;
 #endif
 
       return timer_a.count;
 #endif
 
+    default:
+      /* In case both cases above are not included.  */
+      ;
     }
 
   S ("=>");
     }
 
   S ("=>");
@@ -540,7 +557,7 @@ sign_ext (int v, int bits)
 
 #if TIMER_A
 void
 
 #if TIMER_A
 void
-update_timer_a ()
+update_timer_a (void)
 {
   if (timer_a.bsr & 1)
     {
 {
   if (timer_a.bsr & 1)
     {
This page took 0.025338 seconds and 4 git commands to generate.