/* 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.
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 <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
+#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
+#endif
+#ifdef HAVE_TERMIOS_H
#include <termios.h>
+#endif
#include "mem.h"
#include "cpu.h"
static unsigned char **pt[L1_LEN];
+#ifdef HAVE_TERMIOS_H
int m32c_console_ifd = 0;
+#endif
int m32c_console_ofd = 1;
+#ifdef HAVE_TERMIOS_H
+int m32c_use_raw_console = 0;
+#endif
#ifdef TIMER_A
Timer_A timer_a;
}
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);
}
void
-mem_usage_stats ()
+mem_usage_stats (void)
{
int i, j;
int rstart = 0;
#define S(d) if (trace) s(address, d)
static void
-e ()
+e (void)
{
if (!trace)
return;
extern int m32c_disassemble;
-void
+static void
mem_put_byte (int address, unsigned char value)
{
unsigned char *m;
}
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--)
- mem_put_byte (address++, *(unsigned char *) bufptr++);
+ mem_put_byte (address++, *(const unsigned char *) bufptr++);
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;
}
+#ifdef HAVE_TERMIOS_H
static int console_raw = 0;
static struct termios oattr;
static int
-stdin_ready ()
+stdin_ready (void)
{
fd_set ifd;
int n;
}
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;
}
+#endif
static unsigned char
mem_get_byte (int address)
m = mem_ptr (address);
switch (address)
{
+#ifdef HAVE_TERMIOS_H
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. */
console_raw = 1;
atexit (m32c_sim_restore_console);
}
-#endif
if (stdin_ready ())
return 0x02; /* tx empty and rx full */
}
return c;
}
+#endif
#ifdef TIMER_A
case 0x346: /* TA0low */
return timer_a.count;
#endif
+ default:
+ /* In case both cases above are not included. */
+ ;
}
S ("=>");
#if TIMER_A
void
-update_timer_a ()
+update_timer_a (void)
{
if (timer_a.bsr & 1)
{