From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id vIOVAvkwZWDJHQAAWB0awg (envelope-from ) for ; Wed, 31 Mar 2021 22:33:29 -0400 Received: by simark.ca (Postfix, from userid 112) id F14B41EE1B; Wed, 31 Mar 2021 22:33:28 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D128E1E590 for ; Wed, 31 Mar 2021 22:33:27 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A7253858C27; Thu, 1 Apr 2021 02:33:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A7253858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617244407; bh=Bh+Nnxk0grEr1XAEAN49V2OwF8kWYRGYz2vMfDwc7n8=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=xB0vWnrQZQJa5hvq/VhZTL+EWNOdooA0WyVqNhB7y8SIkN1wbZ/sgkbK+Y4lVkFRa Hgdl34u8GmYW+ILWOPzvQ5Gt7Ul/tJESrpMt9V8DJ/mzoKbNUYQQQz3zExgcc2LIzf 007E0dOdlmPn2yI3VnXpHBBH34fFlZTaW5EaioWE= Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 0107C3858C27 for ; Thu, 1 Apr 2021 02:33:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0107C3858C27 Received: from vapier (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 0778E33D0AF; Thu, 1 Apr 2021 02:33:22 +0000 (UTC) Date: Wed, 31 Mar 2021 22:33:22 -0400 To: Faraz Shahbazker Subject: Re: [PATCH v3] sim: mips: Add handlers to simulator monitor for unlink, lseek and stat Message-ID: Mail-Followup-To: Faraz Shahbazker , gdb-patches@sourceware.org, Chao-ying Fu , macro@orcam.me.uk References: <20210331071049.1448914-1-fshahbazker@wavecomp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210331071049.1448914-1-fshahbazker@wavecomp.com> X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mike Frysinger via Gdb-patches Reply-To: Mike Frysinger Cc: macro@orcam.me.uk, gdb-patches@sourceware.org, Chao-ying Fu Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" lgtm! not sure if Maciej wants to take a pass. -mike On 31 Mar 2021 12:40, Faraz Shahbazker wrote: > sim/mips/ChangeLog > * interp.c (sim_monitor): Add switch entries for unlink (13), > lseek (14), and stat (15). > > Derived from patch authored by Steve Ellcey > --- > > Notes: > Changes from v2: > - remove call to abort() on cb_syscall failure > - capture return value of call in V0 > > sim/mips/ChangeLog | 6 ++++ > sim/mips/interp.c | 70 +++++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 75 insertions(+), 1 deletion(-) > > diff --git a/sim/mips/ChangeLog b/sim/mips/ChangeLog > index 12347a7e3e2..56464eb6727 100644 > --- a/sim/mips/ChangeLog > +++ b/sim/mips/ChangeLog > @@ -1,3 +1,9 @@ > +2021-03-31 Steve Ellcey > + Faraz Shahbazker > + > + * interp.c (sim_monitor): Add switch entries for unlink (13), > + lseek (14), and stat (15). > + > 2021-02-28 Mike Frysinger > > * configure: Regenerate. > diff --git a/sim/mips/interp.c b/sim/mips/interp.c > index fd93a12f69a..55b089dbee9 100644 > --- a/sim/mips/interp.c > +++ b/sim/mips/interp.c > @@ -50,6 +50,7 @@ code on the hardware. > #include "elf-bfd.h" > #include "gdb/callback.h" /* GDB simulator callback interface */ > #include "gdb/remote-sim.h" /* GDB simulator interface */ > +#include "sim-syscall.h" /* Simulator system call support */ > > char* pr_addr (SIM_ADDR addr); > char* pr_uword64 (uword64 addr); > @@ -1147,6 +1148,23 @@ Recognized firmware names are: `idt', `pmon', `lsipmon', and `none'.\n", > return SIM_RC_OK; > } > > +/* stat structures from MIPS32/64. */ > +static const char stat32_map[] = > +"st_dev,2:st_ino,2:st_mode,4:st_nlink,2:st_uid,2:st_gid,2" > +":st_rdev,2:st_size,4:st_atime,4:st_spare1,4:st_mtime,4:st_spare2,4" > +":st_ctime,4:st_spare3,4:st_blksize,4:st_blocks,4:st_spare4,8"; > + > +static const char stat64_map[] = > +"st_dev,2:st_ino,2:st_mode,4:st_nlink,2:st_uid,2:st_gid,2" > +":st_rdev,2:st_size,8:st_atime,8:st_spare1,8:st_mtime,8:st_spare2,8" > +":st_ctime,8:st_spare3,8:st_blksize,8:st_blocks,8:st_spare4,16"; > + > +/* Map for calls using the host struct stat. */ > +static const CB_TARGET_DEFS_MAP CB_stat_map[] = > +{ > + { "stat", CB_SYS_stat, 15 }, > + { 0, -1, -1 } > +}; > > > /* Simple monitor interface (currently setup for the IDT and PMON monitors) */ > @@ -1167,7 +1185,7 @@ sim_monitor (SIM_DESC sd, > > /* The following callback functions are available, however the > monitor we are simulating does not make use of them: get_errno, > - isatty, lseek, rename, system, time and unlink */ > + isatty, rename, system and time. */ > switch (reason) > { > > @@ -1241,6 +1259,56 @@ sim_monitor (SIM_DESC sd, > break; > } > > + case 13: /* int unlink(const char *path) */ > + { > + char *path = fetch_str (sd, A0); > + V0 = sim_io_unlink (sd, path); > + free (path); > + break; > + } > + > + case 14: /* int lseek(int fd, int offset, int whence) */ > + { > + V0 = sim_io_lseek (sd, A0, A1, A2); > + break; > + } > + > + case 15: /* int stat(const char *path, struct stat *buf); */ > + { > + /* As long as the infrastructure doesn't cache anything > + related to the stat mapping, this trick gets us a dual > + "struct stat"-type mapping in the least error-prone way. */ > + host_callback *cb = STATE_CALLBACK (sd); > + const char *saved_map = cb->stat_map; > + CB_TARGET_DEFS_MAP *saved_syscall_map = cb->syscall_map; > + bfd *prog_bfd = STATE_PROG_BFD (sd); > + int is_elf32bit = (elf_elfheader(prog_bfd)->e_ident[EI_CLASS] == > + ELFCLASS32); > + static CB_SYSCALL s; > + CB_SYSCALL_INIT (&s); > + s.func = 15; > + /* Mask out the sign extension part for 64-bit targets because the > + MIPS simulator's memory model is still 32-bit. */ > + s.arg1 = A0 & 0xFFFFFFFF; > + s.arg2 = A1 & 0xFFFFFFFF; > + s.p1 = (PTR) sd; > + s.p2 = (PTR) cpu; > + s.read_mem = sim_syscall_read_mem; > + s.write_mem = sim_syscall_write_mem; > + > + cb->syscall_map = (CB_TARGET_DEFS_MAP *) CB_stat_map; > + cb->stat_map = is_elf32bit ? stat32_map : stat64_map; > + > + if (cb_syscall (cb, &s) != CB_RC_OK) > + sim_engine_halt (sd, cpu, NULL, mips_pc_get (cpu), > + sim_stopped, SIM_SIGILL); > + > + V0 = s.result; > + cb->stat_map = saved_map; > + cb->syscall_map = saved_syscall_map; > + break; > + } > + > case 17: /* void _exit() */ > { > sim_io_eprintf (sd, "sim_monitor(17): _exit(int reason) to be coded\n"); > -- > 2.25.1 >