#include <stdio.h>
#include <errno.h>
#include <signal.h>
-#ifdef HAVE_UNISTD_H
#include <unistd.h>
-#endif
#ifdef HAVE_MMAP
#include <sys/mman.h>
# ifndef MAP_FAILED
#include "bfd.h"
#include "sim/callback.h"
#include "sim/sim.h"
-#include "gdb/sim-sh.h"
+#include "sim/sim-sh.h"
#include "sim-main.h"
#include "sim-base.h"
#include "sim-options.h"
-#include "targ-vals.h"
+#include "target-newlib-syscall.h"
+
+#include "sh-sim.h"
#include <math.h>
{
#if !defined(__GO32__) && !defined(_WIN32)
- case TARGET_SYS_fork:
+ case TARGET_NEWLIB_SH_SYS_fork:
regs[0] = fork ();
break;
/* This would work only if endianness matched between host and target.
Besides, it's quite dangerous. */
#if 0
- case TARGET_SYS_execve:
+ case TARGET_NEWLIB_SH_SYS_execve:
regs[0] = execve (ptr (regs[5]), (char **) ptr (regs[6]),
(char **) ptr (regs[7]));
break;
- case TARGET_SYS_execv:
+ case TARGET_NEWLIB_SH_SYS_execv:
regs[0] = execve (ptr (regs[5]), (char **) ptr (regs[6]), 0);
break;
#endif
- case TARGET_SYS_pipe:
+ case TARGET_NEWLIB_SH_SYS_pipe:
{
regs[0] = (BUSERROR (regs[5], maskl)
? -EINVAL
}
break;
- case TARGET_SYS_wait:
+ case TARGET_NEWLIB_SH_SYS_wait:
regs[0] = wait ((int *) ptr (regs[5]));
break;
#endif /* !defined(__GO32__) && !defined(_WIN32) */
- case TARGET_SYS_read:
+ case TARGET_NEWLIB_SH_SYS_read:
strnswap (regs[6], regs[7]);
regs[0]
= callback->read (callback, regs[5], ptr (regs[6]), regs[7]);
strnswap (regs[6], regs[7]);
break;
- case TARGET_SYS_write:
+ case TARGET_NEWLIB_SH_SYS_write:
strnswap (regs[6], regs[7]);
if (regs[5] == 1)
regs[0] = (int) callback->write_stdout (callback,
ptr (regs[6]), regs[7]);
strnswap (regs[6], regs[7]);
break;
- case TARGET_SYS_lseek:
+ case TARGET_NEWLIB_SH_SYS_lseek:
regs[0] = callback->lseek (callback,regs[5], regs[6], regs[7]);
break;
- case TARGET_SYS_close:
+ case TARGET_NEWLIB_SH_SYS_close:
regs[0] = callback->close (callback,regs[5]);
break;
- case TARGET_SYS_open:
+ case TARGET_NEWLIB_SH_SYS_open:
{
int len = strswaplen (regs[5]);
strnswap (regs[5], len);
strnswap (regs[5], len);
break;
}
- case TARGET_SYS_exit:
+ case TARGET_NEWLIB_SH_SYS_exit:
/* EXIT - caller can look in r5 to work out the reason */
raise_exception (SIGQUIT);
regs[0] = regs[5];
break;
- case TARGET_SYS_stat: /* added at hmsi */
+ case TARGET_NEWLIB_SH_SYS_stat: /* added at hmsi */
/* stat system call */
{
struct stat host_stat;
break;
#ifndef _WIN32
- case TARGET_SYS_chown:
+ case TARGET_NEWLIB_SH_SYS_chown:
{
int len = strswaplen (regs[5]);
break;
}
#endif /* _WIN32 */
- case TARGET_SYS_chmod:
+ case TARGET_NEWLIB_SH_SYS_chmod:
{
int len = strswaplen (regs[5]);
strnswap (regs[5], len);
break;
}
- case TARGET_SYS_utime:
+ case TARGET_NEWLIB_SH_SYS_utime:
{
/* Cast the second argument to void *, to avoid type mismatch
if a prototype is present. */
strnswap (regs[5], len);
break;
}
- case TARGET_SYS_argc:
+ case TARGET_NEWLIB_SH_SYS_argc:
regs[0] = countargv (prog_argv);
break;
- case TARGET_SYS_argnlen:
+ case TARGET_NEWLIB_SH_SYS_argnlen:
if (regs[5] < countargv (prog_argv))
regs[0] = strlen (prog_argv[regs[5]]);
else
regs[0] = -1;
break;
- case TARGET_SYS_argn:
+ case TARGET_NEWLIB_SH_SYS_argn:
if (regs[5] < countargv (prog_argv))
{
/* Include the termination byte. */
int i = strlen (prog_argv[regs[5]]) + 1;
- regs[0] = sim_write (0, regs[6], (void *) prog_argv[regs[5]], i);
+ regs[0] = sim_write (0, regs[6], prog_argv[regs[5]], i);
}
else
regs[0] = -1;
break;
- case TARGET_SYS_time:
+ case TARGET_NEWLIB_SH_SYS_time:
regs[0] = get_now ();
break;
- case TARGET_SYS_ftruncate:
+ case TARGET_NEWLIB_SH_SYS_ftruncate:
regs[0] = callback->ftruncate (callback, regs[5], regs[6]);
break;
- case TARGET_SYS_truncate:
+ case TARGET_NEWLIB_SH_SYS_truncate:
{
int len = strswaplen (regs[5]);
strnswap (regs[5], len);
lower = result - error;
frac = frexp (lower, &exp);
lower = ldexp (ceil (ldexp (frac, 24)), exp - 24);
- return abs (upper - result) >= abs (lower - result) ? upper : lower;
+ return fabs (upper - result) >= fabs (lower - result) ? upper : lower;
}
static float
return loop;
}
-static void ppi_insn ();
-
#include "ppi.c"
/* Provide calloc / free versions that use an anonymous mmap. This can
signal (SIGFPE, prev_fpe);
}
-int
-sim_write (SIM_DESC sd, SIM_ADDR addr, const unsigned char *buffer, int size)
+uint64_t
+sim_write (SIM_DESC sd, uint64_t addr, const void *buffer, uint64_t size)
{
int i;
+ const unsigned char *data = buffer;
init_pointers ();
for (i = 0; i < size; i++)
{
- saved_state.asregs.memory[(MMASKB & (addr + i)) ^ endianb] = buffer[i];
+ saved_state.asregs.memory[(MMASKB & (addr + i)) ^ endianb] = data[i];
}
return size;
}
-int
-sim_read (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size)
+uint64_t
+sim_read (SIM_DESC sd, uint64_t addr, void *buffer, uint64_t size)
{
int i;
+ unsigned char *data = buffer;
init_pointers ();
for (i = 0; i < size; i++)
{
- buffer[i] = saved_state.asregs.memory[(MMASKB & (addr + i)) ^ endianb];
+ data[i] = saved_state.asregs.memory[(MMASKB & (addr + i)) ^ endianb];
}
return size;
}
};
static int
-sh_reg_store (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
+sh_reg_store (SIM_CPU *cpu, int rn, const void *memory, int length)
{
unsigned val;
}
static int
-sh_reg_fetch (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
+sh_reg_fetch (SIM_CPU *cpu, int rn, void *memory, int length)
{
int val;
/* Set default options before parsing user options. */
current_alignment = STRICT_ALIGNMENT;
+ cb->syscall_map = cb_sh_syscall_map;
/* The cpu data is kept in a separately allocated chunk of memory. */
- if (sim_cpu_alloc_all (sd, 1) != SIM_RC_OK)
+ if (sim_cpu_alloc_all (sd, 0) != SIM_RC_OK)
{
free_state (sd);
return 0;
}
/* Check for/establish the a reference program image. */
- if (sim_analyze_program (sd,
- (STATE_PROG_ARGV (sd) != NULL
- ? *STATE_PROG_ARGV (sd)
- : NULL), abfd) != SIM_RC_OK)
+ if (sim_analyze_program (sd, STATE_PROG_FILE (sd), abfd) != SIM_RC_OK)
{
free_state (sd);
return 0;