sim: iq2000: switch syscalls to common nltvals

Rather than hand duplicate the syscall table, switch to the common
nltvals framework.  We have to tweak the constant names, but we get
everything else for free.  I made sure the constants have the same
values before & after too :).
This commit is contained in:
Mike Frysinger 2021-04-18 22:24:37 -04:00
parent 37e9f18266
commit 2390d77943
6 changed files with 56 additions and 30 deletions

View File

@ -1,3 +1,8 @@
2021-04-18 Mike Frysinger <vapier@gentoo.org>
* gennltvals.py (TARGETS): Add iq2000.
* nltvals.def: Regenerate.
2021-04-18 Mike Frysinger <vapier@gentoo.org>
* syscall.c (cb_syscall): Implement CB_SYS_getpid.

View File

@ -60,6 +60,7 @@ TARGETS = {
'fr30',
'frv',
'i960',
'iq2000',
'lm32',
'm32r',
'mcore',

View File

@ -342,6 +342,37 @@
/* end i960 sys target macros */
#endif
#endif
#ifdef NL_TARGET_iq2000
#ifdef sys_defs
/* from syscall.h */
/* begin iq2000 sys target macros */
{ "SYS_argc", 22 },
{ "SYS_argn", 24 },
{ "SYS_argnlen", 23 },
{ "SYS_argv", 13 },
{ "SYS_argvlen", 12 },
{ "SYS_chdir", 14 },
{ "SYS_chmod", 16 },
{ "SYS_close", 3 },
{ "SYS_exit", 1 },
{ "SYS_fstat", 10 },
{ "SYS_getpid", 8 },
{ "SYS_gettimeofday", 19 },
{ "SYS_kill", 9 },
{ "SYS_link", 21 },
{ "SYS_lseek", 6 },
{ "SYS_open", 2 },
{ "SYS_read", 4 },
{ "SYS_reconfig", 25 },
{ "SYS_stat", 15 },
{ "SYS_time", 18 },
{ "SYS_times", 20 },
{ "SYS_unlink", 7 },
{ "SYS_utime", 17 },
{ "SYS_write", 5 },
/* end iq2000 sys target macros */
#endif
#endif
#ifdef NL_TARGET_lm32
#ifdef sys_defs
/* from syscall.h */
@ -553,6 +584,7 @@
{ "SYS_access", 1033 },
{ "SYS_brk", 214 },
{ "SYS_chdir", 49 },
{ "SYS_clock_gettime64", 403 },
{ "SYS_close", 57 },
{ "SYS_dup", 23 },
{ "SYS_exit", 93 },

View File

@ -1,3 +1,10 @@
2021-04-18 Mike Frysinger <vapier@gentoo.org>
* Makefile.in (NL_TARGET): Define.
* iq2000.c: Include targ-vals.h.
(libgloss_syscall): Delete.
(do_syscall): Add TARGET_ prefix to all SYS_ constants.
2021-04-18 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.

View File

@ -15,6 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This selects the newlib/libgloss syscall definitions.
NL_TARGET = -DNL_TARGET_iq2000
## COMMON_PRE_CONFIG_FRAG
IQ2000_OBJS = iq2000.o cpu.o decode.o sem.o model.o mloop.o

View File

@ -23,6 +23,7 @@
#include "sim-main.h"
#include "cgen-mem.h"
#include "cgen-ops.h"
#include "targ-vals.h"
#include <stdlib.h>
enum
@ -32,29 +33,6 @@ enum
PC_REGNUM = 32
};
enum libgloss_syscall
{
SYS_exit = 1,
SYS_open = 2,
SYS_close = 3,
SYS_read = 4,
SYS_write = 5,
SYS_lseek = 6,
SYS_unlink = 7,
SYS_getpid = 8,
SYS_kill = 9,
SYS_fstat = 10,
SYS_argvlen = 12,
SYS_argv = 13,
SYS_chdir = 14,
SYS_stat = 15,
SYS_chmod = 16,
SYS_utime = 17,
SYS_time = 18,
SYS_gettimeofday = 19,
SYS_times = 20
};
/* Read a null terminated string from memory, return in a buffer */
static char *
fetch_str (SIM_CPU *current_cpu, PCADDR pc, DI addr)
@ -98,7 +76,7 @@ do_syscall (SIM_CPU *current_cpu, PCADDR pc)
exit (1);
}
case SYS_write:
case TARGET_SYS_write:
buf = zalloc (PARM3);
sim_read (CPU_STATE (current_cpu), CPU2DATA(PARM2), buf, PARM3);
SET_H_GR (ret_reg,
@ -107,18 +85,18 @@ do_syscall (SIM_CPU *current_cpu, PCADDR pc)
free (buf);
break;
case SYS_lseek:
case TARGET_SYS_lseek:
SET_H_GR (ret_reg,
sim_io_lseek (CPU_STATE (current_cpu),
PARM1, PARM2, PARM3));
break;
case SYS_exit:
case TARGET_SYS_exit:
sim_engine_halt (CPU_STATE (current_cpu), current_cpu,
NULL, pc, sim_exited, PARM1);
break;
case SYS_read:
case TARGET_SYS_read:
buf = zalloc (PARM3);
SET_H_GR (ret_reg,
sim_io_read (CPU_STATE (current_cpu),
@ -127,7 +105,7 @@ do_syscall (SIM_CPU *current_cpu, PCADDR pc)
free (buf);
break;
case SYS_open:
case TARGET_SYS_open:
buf = fetch_str (current_cpu, pc, PARM1);
SET_H_GR (ret_reg,
sim_io_open (CPU_STATE (current_cpu),
@ -135,12 +113,12 @@ do_syscall (SIM_CPU *current_cpu, PCADDR pc)
free (buf);
break;
case SYS_close:
case TARGET_SYS_close:
SET_H_GR (ret_reg,
sim_io_close (CPU_STATE (current_cpu), PARM1));
break;
case SYS_time:
case TARGET_SYS_time:
SET_H_GR (ret_reg, time (0));
break;