From 2390d779430a64350be827929a0ebf73155f4fd7 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 18 Apr 2021 22:24:37 -0400 Subject: [PATCH] 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 :). --- sim/common/ChangeLog | 5 +++++ sim/common/gennltvals.py | 1 + sim/common/nltvals.def | 32 ++++++++++++++++++++++++++++++++ sim/iq2000/ChangeLog | 7 +++++++ sim/iq2000/Makefile.in | 3 +++ sim/iq2000/iq2000.c | 38 ++++++++------------------------------ 6 files changed, 56 insertions(+), 30 deletions(-) diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index b1af152930a..2d5934ad064 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,8 @@ +2021-04-18 Mike Frysinger + + * gennltvals.py (TARGETS): Add iq2000. + * nltvals.def: Regenerate. + 2021-04-18 Mike Frysinger * syscall.c (cb_syscall): Implement CB_SYS_getpid. diff --git a/sim/common/gennltvals.py b/sim/common/gennltvals.py index 23b218728c2..a246977fbf8 100755 --- a/sim/common/gennltvals.py +++ b/sim/common/gennltvals.py @@ -60,6 +60,7 @@ TARGETS = { 'fr30', 'frv', 'i960', + 'iq2000', 'lm32', 'm32r', 'mcore', diff --git a/sim/common/nltvals.def b/sim/common/nltvals.def index 6f93316ea02..4aaeff8a446 100644 --- a/sim/common/nltvals.def +++ b/sim/common/nltvals.def @@ -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 }, diff --git a/sim/iq2000/ChangeLog b/sim/iq2000/ChangeLog index c6fc38c18c1..cb67450fd7a 100644 --- a/sim/iq2000/ChangeLog +++ b/sim/iq2000/ChangeLog @@ -1,3 +1,10 @@ +2021-04-18 Mike Frysinger + + * 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 * configure: Regenerate. diff --git a/sim/iq2000/Makefile.in b/sim/iq2000/Makefile.in index f3ab6351b25..baf49dd3330 100644 --- a/sim/iq2000/Makefile.in +++ b/sim/iq2000/Makefile.in @@ -15,6 +15,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# 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 diff --git a/sim/iq2000/iq2000.c b/sim/iq2000/iq2000.c index e03c47919fd..66d7b47dfb4 100644 --- a/sim/iq2000/iq2000.c +++ b/sim/iq2000/iq2000.c @@ -23,6 +23,7 @@ #include "sim-main.h" #include "cgen-mem.h" #include "cgen-ops.h" +#include "targ-vals.h" #include 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; -- 2.30.2