From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23639 invoked by alias); 10 Jul 2013 14:49:30 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 23628 invoked by uid 89); 10 Jul 2013 14:49:29 -0000 X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from multi.imgtec.com (HELO multi.imgtec.com) (194.200.65.239) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 10 Jul 2013 14:49:28 +0000 From: "Steve Ellcey " Date: Wed, 10 Jul 2013 14:49:00 -0000 To: Subject: [patch, sim, mips] Implement unlink, lseek, and stat for MIPS User-Agent: Heirloom mailx 12.4 7/29/08 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-ID: <77654af0-7a94-479e-98f2-35691968037f@BAMAIL02.ba.imgtec.org> X-SEF-Processed: 7_3_0_01192__2013_07_10_15_49_24 X-SW-Source: 2013-07/txt/msg00274.txt.bz2 A while back I submitted a GCC patch that allowed me to build the Fortran compiler on a newlib based cross compiler. While using the GNU simulator to test that, I found that a number of tests failed due to unimplemented system calls on the MIPS GNU simulator. This patch implements unlink, lseek, and stat in the GNU simulator for MIPS. There is a second small patch that I sent to newlib that generates the necessary functions for the simulator to see and intercept these functions like it does others that are already implemented such as open and close. OK to checkin? Steve Ellcey sellcey@mips.com Steve Ellcey * interp.c (sim_monitor): Add switch entries for unlink (13), lseek (14), and stat (15). diff --git a/sim/mips/interp.c b/sim/mips/interp.c index 032570a..766a113 100644 --- a/sim/mips/interp.c +++ b/sim/mips/interp.c @@ -47,6 +47,7 @@ code on the hardware. #include #include #include +#include #include #ifdef HAVE_STDLIB_H #include @@ -1342,6 +1343,60 @@ 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; + } + +/* We may need to swap stat data around before passing it on to the + program being run. */ +#define copy16(x) (BigEndianMem ? bswap_16(x) : (x)) +#define copy32(x) (BigEndianMem ? bswap_32(x) : (x)) + + case 15: /* int stat(const char *path, struct stat *buf); */ + { + /* We need to put the data into the type of stat structure + that MIPS uses and make sure it has the correct endianness. + We are assuming that the host and MIPS agree on what the bits + in st_mode mean. That appears to be true for x86 linux and + MIPS. */ + struct stat host_stat; + struct __attribute__ ((__packed__)) mips_stat { + short st_dev; + unsigned short st_ino; + unsigned int st_mode; + unsigned short st_nlink; + unsigned short st_uid; + unsigned short st_gid; + short st_rdev; + int st_size; + } mips_stat; + char *buf; + char *path = fetch_str (sd, A0); + buf = (char *) A1; + V0 = sim_io_stat (sd, path, &host_stat); + free (path); + mips_stat.st_dev = copy16((short) host_stat.st_dev); + mips_stat.st_ino = copy16((unsigned short) host_stat.st_ino); + mips_stat.st_mode = copy32((int) host_stat.st_mode); + mips_stat.st_nlink = copy16((unsigned short) host_stat.st_nlink); + mips_stat.st_uid = copy16((unsigned short) host_stat.st_uid); + mips_stat.st_gid = copy16((unsigned short) host_stat.st_gid); + mips_stat.st_rdev = copy16((short) host_stat.st_rdev); + mips_stat.st_size = copy32((int) host_stat.st_size); + sim_write (sd, A1, (char *) &mips_stat, 20); + break; + } + case 17: /* void _exit() */ { sim_io_eprintf (sd, "sim_monitor(17): _exit(int reason) to be coded\n");