From patchwork Fri Dec 23 00:43:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 62306 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 999CE385B50F for ; Fri, 23 Dec 2022 00:44:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 999CE385B50F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1671756263; bh=n53P3AAdeGU6kOFcn4NKLcwYorXv5TJuO1Rh48/t4tQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WnNZaY66pZ/18HXA6b2rZtPyIzNQoh8NgtxaqQmL6jV/652Kb07PWRkxtJnI9EZw9 hcAecR2UBdGAIShiuxMLYmwmQqqQrzYMeXfipw1EhpMZGxdknyoe1mroZlSnsFKg6K xmT4+NKlTM4tM+8N9wTQWapnhv9w8B0BVSNkeP8o= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id 1D8183858D1E for ; Fri, 23 Dec 2022 00:43:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1D8183858D1E Received: by smtp.gentoo.org (Postfix, from userid 559) id A5F4A34127D; Fri, 23 Dec 2022 00:43:35 +0000 (UTC) To: gdb-patches@sourceware.org Subject: [PATCH] sim: switch sim_{read, write} APIs to 64-bit all the time [PR sim/7504] Date: Thu, 22 Dec 2022 19:43:32 -0500 Message-Id: <20221223004332.18190-1-vapier@gentoo.org> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-Patchwork-Original-From: Mike Frysinger via Gdb-patches From: Mike Frysinger Reply-To: Mike Frysinger Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" We've been using SIM_ADDR which has always been 32-bit. This means the upper 32-bit address range in 64-bit sims is inaccessible. Use 64-bit addresses all the time since we want the APIs to be stable regardless of the active arch backend (which can be 32 or 64-bit). The length is also 64-bit because it's completely feasible to have a program that is larger than 4 GiB in size/image/runtime. Forcing the caller to manually chunk those accesses up into 4 GiB at a time doesn't seem useful to anyone. Bug: https://sourceware.org/PR7504 --- include/sim/sim.h | 6 ++++-- sim/arm/wrapper.c | 16 ++++++++-------- sim/avr/interp.c | 8 ++++---- sim/common/sim-hrw.c | 8 ++++---- sim/common/sim-utils.h | 4 ++-- sim/cris/sim-if.c | 4 ++-- sim/d10v/interp.c | 12 ++++++------ sim/erc32/interf.c | 8 ++++---- sim/h8300/compile.c | 8 ++++---- sim/m32c/gdb-if.c | 8 ++++---- sim/ppc/sim_calls.c | 18 ++++++++++-------- sim/rl78/gdb-if.c | 8 ++++---- sim/rx/gdb-if.c | 8 ++++---- sim/sh/interp.c | 8 ++++---- 14 files changed, 64 insertions(+), 60 deletions(-) diff --git a/include/sim/sim.h b/include/sim/sim.h index 20a667cab7d3..468a63bbc201 100644 --- a/include/sim/sim.h +++ b/include/sim/sim.h @@ -20,6 +20,8 @@ #ifndef SIM_SIM_H #define SIM_SIM_H 1 +#include + #ifdef __cplusplus extern "C" { #endif @@ -163,14 +165,14 @@ SIM_RC sim_create_inferior (SIM_DESC sd, struct bfd *abfd, at virtual address MEM and store in BUF. Result is number of bytes read, or zero if error. */ -int sim_read (SIM_DESC sd, SIM_ADDR mem, void *buf, int length); +uint64_t sim_read (SIM_DESC sd, uint64_t mem, void *buf, uint64_t length); /* Store LENGTH bytes from BUF into the simulated program's memory. Store bytes starting at virtual address MEM. Result is number of bytes write, or zero if error. */ -int sim_write (SIM_DESC sd, SIM_ADDR mem, const void *buf, int length); +uint64_t sim_write (SIM_DESC sd, uint64_t mem, const void *buf, uint64_t length); /* Fetch register REGNO storing its raw (target endian) value in the diff --git a/sim/arm/wrapper.c b/sim/arm/wrapper.c index 2c5253fc7466..7b1153298f1d 100644 --- a/sim/arm/wrapper.c +++ b/sim/arm/wrapper.c @@ -150,13 +150,13 @@ ARMul_ConsolePrint (ARMul_State * state, } } -int +uint64_t sim_write (SIM_DESC sd ATTRIBUTE_UNUSED, - SIM_ADDR addr, + uint64_t addr, const void * buffer, - int size) + uint64_t size) { - int i; + uint64_t i; const unsigned char * data = buffer; init (); @@ -167,13 +167,13 @@ sim_write (SIM_DESC sd ATTRIBUTE_UNUSED, return size; } -int +uint64_t sim_read (SIM_DESC sd ATTRIBUTE_UNUSED, - SIM_ADDR addr, + uint64_t addr, void * buffer, - int size) + uint64_t size) { - int i; + uint64_t i; unsigned char * data = buffer; init (); diff --git a/sim/avr/interp.c b/sim/avr/interp.c index 3acf09b15ada..b72da5363080 100644 --- a/sim/avr/interp.c +++ b/sim/avr/interp.c @@ -1529,8 +1529,8 @@ sim_engine_run (SIM_DESC sd, } } -int -sim_write (SIM_DESC sd, SIM_ADDR addr, const void *buffer, int size) +uint64_t +sim_write (SIM_DESC sd, uint64_t addr, const void *buffer, uint64_t size) { int osize = size; @@ -1566,8 +1566,8 @@ sim_write (SIM_DESC sd, SIM_ADDR addr, const void *buffer, int size) return 0; } -int -sim_read (SIM_DESC sd, SIM_ADDR addr, void *buffer, int size) +uint64_t +sim_read (SIM_DESC sd, uint64_t addr, void *buffer, uint64_t size) { int osize = size; diff --git a/sim/common/sim-hrw.c b/sim/common/sim-hrw.c index 2596019e6e5c..091ff5bade5b 100644 --- a/sim/common/sim-hrw.c +++ b/sim/common/sim-hrw.c @@ -26,16 +26,16 @@ along with this program. If not, see . */ /* Generic implementation of sim_read that works with simulators modeling real hardware */ -int -sim_read (SIM_DESC sd, SIM_ADDR mem, void *buffer, int length) +uint64_t +sim_read (SIM_DESC sd, uint64_t mem, void *buffer, uint64_t length) { SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); return sim_core_read_buffer (sd, NULL, read_map, buffer, mem, length); } -int -sim_write (SIM_DESC sd, SIM_ADDR mem, const void *buffer, int length) +uint64_t +sim_write (SIM_DESC sd, uint64_t mem, const void *buffer, uint64_t length) { SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); return sim_core_write_buffer (sd, NULL, write_map, diff --git a/sim/common/sim-utils.h b/sim/common/sim-utils.h index cd8aca9f4016..b34ee94236e6 100644 --- a/sim/common/sim-utils.h +++ b/sim/common/sim-utils.h @@ -63,8 +63,8 @@ SIM_RC sim_analyze_program (SIM_DESC sd, const char *prog_name, This is still accommodated for backward compatibility reasons. */ typedef struct host_callback_struct host_callback; -typedef int sim_write_fn (SIM_DESC sd, SIM_ADDR mem, - const void *buf, int length); +typedef uint64_t sim_write_fn (SIM_DESC sd, uint64_t mem, + const void *buf, uint64_t length); struct bfd *sim_load_file (SIM_DESC sd, const char *myname, host_callback *callback, const char *prog, struct bfd *prog_bfd, int verbose_p, diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c index a952a27fc520..47862edf4f5a 100644 --- a/sim/cris/sim-if.c +++ b/sim/cris/sim-if.c @@ -485,8 +485,8 @@ aux_ent_entry (struct bfd *ebfd) /* Helper for cris_handle_interpreter: like sim_write, but load at interp_load_addr offset. */ -static int -cris_write_interp (SIM_DESC sd, SIM_ADDR mem, const void *buf, int length) +static uint64_t +cris_write_interp (SIM_DESC sd, uint64_t mem, const void *buf, uint64_t length) { return sim_write (sd, mem + interp_load_addr, buf, length); } diff --git a/sim/d10v/interp.c b/sim/d10v/interp.c index f83fa6678ad3..ae8b6707ed4b 100644 --- a/sim/d10v/interp.c +++ b/sim/d10v/interp.c @@ -664,9 +664,9 @@ map_memory (SIM_DESC sd, SIM_CPU *cpu, unsigned phys_addr) static int xfer_mem (SIM_DESC sd, - SIM_ADDR virt, + address_word virt, unsigned char *buffer, - int size, + uint64_t size, int write_p) { uint8_t *memory; @@ -705,8 +705,8 @@ xfer_mem (SIM_DESC sd, } -int -sim_write (SIM_DESC sd, SIM_ADDR addr, const void *buffer, int size) +uint64_t +sim_write (SIM_DESC sd, uint64_t addr, const void *buffer, uint64_t size) { /* FIXME: this should be performing a virtual transfer */ /* FIXME: We cast the const away, but it's safe because xfer_mem only reads @@ -714,8 +714,8 @@ sim_write (SIM_DESC sd, SIM_ADDR addr, const void *buffer, int size) return xfer_mem (sd, addr, (void *) buffer, size, 1); } -int -sim_read (SIM_DESC sd, SIM_ADDR addr, void *buffer, int size) +uint64_t +sim_read (SIM_DESC sd, uint64_t addr, void *buffer, uint64_t size) { /* FIXME: this should be performing a virtual transfer */ return xfer_mem (sd, addr, buffer, size, 0); diff --git a/sim/erc32/interf.c b/sim/erc32/interf.c index e88e5ed3ab8a..fdd3f0f6b402 100644 --- a/sim/erc32/interf.c +++ b/sim/erc32/interf.c @@ -329,8 +329,8 @@ sim_fetch_register(SIM_DESC sd, int regno, void *buf, int length) return -1; } -int -sim_write (SIM_DESC sd, SIM_ADDR mem, const void *buffer, int length) +uint64_t +sim_write (SIM_DESC sd, uint64_t mem, const void *buffer, uint64_t length) { int i, len; const unsigned char *data = buffer; @@ -341,8 +341,8 @@ sim_write (SIM_DESC sd, SIM_ADDR mem, const void *buffer, int length) return length; } -int -sim_read (SIM_DESC sd, SIM_ADDR mem, void *buffer, int length) +uint64_t +sim_read (SIM_DESC sd, uint64_t mem, void *buffer, uint64_t length) { int i, len; unsigned char *data = buffer; diff --git a/sim/h8300/compile.c b/sim/h8300/compile.c index 261e904577f4..077bc6dff097 100644 --- a/sim/h8300/compile.c +++ b/sim/h8300/compile.c @@ -4340,8 +4340,8 @@ sim_engine_run (SIM_DESC sd, } } -int -sim_write (SIM_DESC sd, SIM_ADDR addr, const void *buffer, int size) +uint64_t +sim_write (SIM_DESC sd, uint64_t addr, const void *buffer, uint64_t size) { sim_cpu *cpu = STATE_CPU (sd, 0); int i; @@ -4362,8 +4362,8 @@ sim_write (SIM_DESC sd, SIM_ADDR addr, const void *buffer, int size) return i; } -int -sim_read (SIM_DESC sd, SIM_ADDR addr, void *buffer, int size) +uint64_t +sim_read (SIM_DESC sd, uint64_t addr, void *buffer, uint64_t size) { sim_cpu *cpu = STATE_CPU (sd, 0); diff --git a/sim/m32c/gdb-if.c b/sim/m32c/gdb-if.c index b065bdca5b1e..f75052bfe28d 100644 --- a/sim/m32c/gdb-if.c +++ b/sim/m32c/gdb-if.c @@ -158,8 +158,8 @@ sim_create_inferior (SIM_DESC sd, struct bfd * abfd, return SIM_RC_OK; } -int -sim_read (SIM_DESC sd, SIM_ADDR mem, void *buf, int length) +uint64_t +sim_read (SIM_DESC sd, uint64_t mem, void *buf, uint64_t length) { check_desc (sd); @@ -171,8 +171,8 @@ sim_read (SIM_DESC sd, SIM_ADDR mem, void *buf, int length) return length; } -int -sim_write (SIM_DESC sd, SIM_ADDR mem, const void *buf, int length) +uint64_t +sim_write (SIM_DESC sd, uint64_t mem, const void *buf, uint64_t length) { check_desc (sd); diff --git a/sim/ppc/sim_calls.c b/sim/ppc/sim_calls.c index 6ca6c2ce2c24..88544457c6e5 100644 --- a/sim/ppc/sim_calls.c +++ b/sim/ppc/sim_calls.c @@ -124,25 +124,27 @@ sim_load (SIM_DESC sd, const char *prog, bfd *abfd, int from_tty) } -int -sim_read (SIM_DESC sd, SIM_ADDR mem, void *buf, int length) +uint64_t +sim_read (SIM_DESC sd, uint64_t mem, void *buf, uint64_t length) { int result = psim_read_memory(simulator, MAX_NR_PROCESSORS, buf, mem, length); - TRACE(trace_gdb, ("sim_read(mem=0x%lx, buf=%p, length=%d) = %d\n", - (long)mem, buf, length, result)); + TRACE(trace_gdb, + ("sim_read(mem=0x%" PRIx64 ", buf=%p, length=%" PRIx64 ") = %d\n", + mem, buf, length, result)); return result; } -int -sim_write (SIM_DESC sd, SIM_ADDR mem, const void *buf, int length) +uint64_t +sim_write (SIM_DESC sd, uint64_t mem, const void *buf, uint64_t length) { int result = psim_write_memory(simulator, MAX_NR_PROCESSORS, buf, mem, length, 1/*violate_ro*/); - TRACE(trace_gdb, ("sim_write(mem=0x%lx, buf=%p, length=%d) = %d\n", - (long)mem, buf, length, result)); + TRACE(trace_gdb, + ("sim_write(mem=0x%" PRIx64 ", buf=%p, length=%" PRIx64 ") = %d\n", + mem, buf, length, result)); return result; } diff --git a/sim/rl78/gdb-if.c b/sim/rl78/gdb-if.c index cc76a7d91313..3b3a7ae17b91 100644 --- a/sim/rl78/gdb-if.c +++ b/sim/rl78/gdb-if.c @@ -204,8 +204,8 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, /* Read memory. */ -int -sim_read (SIM_DESC sd, SIM_ADDR mem, void *buf, int length) +uint64_t +sim_read (SIM_DESC sd, uint64_t mem, void *buf, uint64_t length) { check_desc (sd); @@ -220,8 +220,8 @@ sim_read (SIM_DESC sd, SIM_ADDR mem, void *buf, int length) /* Write memory. */ -int -sim_write (SIM_DESC sd, SIM_ADDR mem, const void *buf, int length) +uint64_t +sim_write (SIM_DESC sd, uint64_t mem, const void *buf, uint64_t length) { check_desc (sd); diff --git a/sim/rx/gdb-if.c b/sim/rx/gdb-if.c index 70f84c184bc3..caa7ddbcb325 100644 --- a/sim/rx/gdb-if.c +++ b/sim/rx/gdb-if.c @@ -225,8 +225,8 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, return SIM_RC_OK; } -int -sim_read (SIM_DESC sd, SIM_ADDR mem, void *buffer, int length) +uint64_t +sim_read (SIM_DESC sd, uint64_t mem, void *buffer, uint64_t length) { int i; unsigned char *data = buffer; @@ -251,8 +251,8 @@ sim_read (SIM_DESC sd, SIM_ADDR mem, void *buffer, int length) return length; } -int -sim_write (SIM_DESC sd, SIM_ADDR mem, const void *buffer, int length) +uint64_t +sim_write (SIM_DESC sd, uint64_t mem, const void *buffer, uint64_t length) { int i; const unsigned char *data = buffer; diff --git a/sim/sh/interp.c b/sim/sh/interp.c index e0cbc7fc6d9b..7784ca7aa40f 100644 --- a/sim/sh/interp.c +++ b/sim/sh/interp.c @@ -1873,8 +1873,8 @@ sim_resume (SIM_DESC sd, int step, int siggnal) signal (SIGFPE, prev_fpe); } -int -sim_write (SIM_DESC sd, SIM_ADDR addr, const void *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; @@ -1888,8 +1888,8 @@ sim_write (SIM_DESC sd, SIM_ADDR addr, const void *buffer, int size) return size; } -int -sim_read (SIM_DESC sd, SIM_ADDR addr, void *buffer, int size) +uint64_t +sim_read (SIM_DESC sd, uint64_t addr, void *buffer, uint64_t size) { int i; unsigned char *data = buffer;