public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/6] sim: mips: fix format warnings when setting up memory
@ 2021-06-15  5:11 Mike Frysinger
  2021-06-15  5:11 ` [PATCH 2/6] sim: mips: add casts to fpu conversions Mike Frysinger
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Mike Frysinger @ 2021-06-15  5:11 UTC (permalink / raw)
  To: gdb-patches

The majority of these inputs are not long's, so don't use %lx.
This fixes compiler warnings about type mismatches.
---
 sim/mips/interp.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/sim/mips/interp.c b/sim/mips/interp.c
index 93bbc5c846c0..bccc4c76ed8b 100644
--- a/sim/mips/interp.c
+++ b/sim/mips/interp.c
@@ -436,7 +436,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb,
 	  if (mem_size > K1SIZE)
 	    mem_size = K1SIZE;
 	  /* memory alias K1BASE@1,K1SIZE%MEMSIZE,K0BASE */
-	  sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx%%0x%lx,0x%0x",
+	  sim_do_commandf (sd, "memory alias 0x%x@1,0x%x%%0x%lx,0x%0x",
 			   K1BASE, K1SIZE, (long)mem_size, K0BASE);
 	  if (WITH_TARGET_WORD_BITSIZE == 64)
 	    sim_do_commandf (sd, "memory alias 0x%x,0x%" PRIxTW ",0x%" PRIxTA,
@@ -453,13 +453,13 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb,
       STATE_ENVIRONMENT (sd) = OPERATING_ENVIRONMENT;
 
       /* ROM: 0x9FC0_0000 - 0x9FFF_FFFF and 0xBFC0_0000 - 0xBFFF_FFFF */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x,0x%0x",
 		       0x9FC00000, 
 		       4 * 1024 * 1024, /* 4 MB */
 		       0xBFC00000);
 
       /* SRAM: 0x8000_0000 - 0x803F_FFFF and 0xA000_0000 - 0xA03F_FFFF */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x,0x%0x",
 		       0x80000000, 
 		       4 * 1024 * 1024, /* 4 MB */
 		       0xA0000000);
@@ -468,7 +468,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb,
       for (i=0; i<8; i++) /* 32 MB total */
 	{
 	  unsigned size = 4 * 1024 * 1024;  /* 4 MB */
-	  sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",
+	  sim_do_commandf (sd, "memory alias 0x%x@1,0x%x,0x%0x",
 			   0x88000000 + (i * size), 
 			   size, 
 			   0xA8000000 + (i * size));
@@ -499,13 +499,13 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb,
       /* --- memory --- */
 
       /* ROM: 0x9FC0_0000 - 0x9FFF_FFFF and 0xBFC0_0000 - 0xBFFF_FFFF */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x,0x%0x",
 		       0x9FC00000, 
 		       4 * 1024 * 1024, /* 4 MB */
 		       0xBFC00000);
 
       /* SRAM: 0x8000_0000 - 0x803F_FFFF and 0xA000_0000 - 0xA03F_FFFF */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x,0x%0x",
 		       0x80000000, 
 		       4 * 1024 * 1024, /* 4 MB */
 		       0xA0000000);
@@ -514,7 +514,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb,
       for (i=0; i<8; i++) /* 32 MB total */
 	{
 	  unsigned size = 4 * 1024 * 1024;  /* 4 MB */
-	  sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",
+	  sim_do_commandf (sd, "memory alias 0x%x@1,0x%x,0x%0x",
 			   0x88000000 + (i * size), 
 			   size, 
 			   0xA8000000 + (i * size));
@@ -522,15 +522,15 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb,
 
       /* Dummy memory regions for unsimulated devices - sorted by address */
 
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xB1000000, 0x400); /* ISA I/O */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xB2100000, 0x004); /* ISA ctl */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xB2500000, 0x004); /* LED/switch */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xB2700000, 0x004); /* RTC */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xB3C00000, 0x004); /* RTC */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xFFFF8000, 0x900); /* DRAMC */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xFFFF9000, 0x200); /* EBIF */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xFFFFE000, 0x01c); /* EBIF */
-      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xFFFFF500, 0x300); /* PIO */
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x", 0xB1000000, 0x400); /* ISA I/O */
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x", 0xB2100000, 0x004); /* ISA ctl */
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x", 0xB2500000, 0x004); /* LED/switch */
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x", 0xB2700000, 0x004); /* RTC */
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x", 0xB3C00000, 0x004); /* RTC */
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x", 0xFFFF8000, 0x900); /* DRAMC */
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x", 0xFFFF9000, 0x200); /* EBIF */
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x", 0xFFFFE000, 0x01c); /* EBIF */
+      sim_do_commandf (sd, "memory alias 0x%x@1,0x%x", 0xFFFFF500, 0x300); /* PIO */
 
 
       /* --- simulated devices --- */
@@ -711,7 +711,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb,
 			 idt_monitor_base, idt_monitor_size,
 			 EXTENDED (idt_monitor_base));
       else
-	sim_do_commandf (sd, "memory region 0x%x,0x%x",
+	sim_do_commandf (sd, "memory region 0x%x,0x%" PRIxTA,
 			 idt_monitor_base, idt_monitor_size);
 
       /* Entry into the IDT monitor is via fixed address vectors, and
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/6] sim: mips: add casts to fpu conversions
  2021-06-15  5:11 [PATCH 1/6] sim: mips: fix format warnings when setting up memory Mike Frysinger
@ 2021-06-15  5:11 ` Mike Frysinger
  2021-06-15  5:11 ` [PATCH 3/6] sim: mips: fix uninitialized register use Mike Frysinger
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2021-06-15  5:11 UTC (permalink / raw)
  To: gdb-patches

These funcs expect signed int pointers, but the code uses unsigned.
---
 sim/mips/cp1.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sim/mips/cp1.c b/sim/mips/cp1.c
index 03ed0c0558ff..b9c7a4b8074f 100644
--- a/sim/mips/cp1.c
+++ b/sim/mips/cp1.c
@@ -1422,11 +1422,11 @@ convert (sim_cpu *cpu,
       sim_fpu_to64 (&result64, &wop);
       break;
     case fmt_word:
-      status |= sim_fpu_to32i (&result32, &wop, round);
+      status |= sim_fpu_to32i ((void*)&result32, &wop, round);
       result64 = result32;
       break;
     case fmt_long:
-      status |= sim_fpu_to64i (&result64, &wop, round);
+      status |= sim_fpu_to64i ((void*)&result64, &wop, round);
       break;
     default:
       result64 = 0;
@@ -1525,8 +1525,8 @@ convert_ps (sim_cpu *cpu,
   switch (to)
     {
     case fmt_word:   /* fmt_pw */
-      status_u |= sim_fpu_to32i (&res_u, &wop_u, round);
-      status_l |= sim_fpu_to32i (&res_l, &wop_l, round);
+      status_u |= sim_fpu_to32i ((void*)&res_u, &wop_u, round);
+      status_l |= sim_fpu_to32i ((void*)&res_l, &wop_l, round);
       result = (((unsigned64)res_u) << 32) | (unsigned64)res_l;
       break;
     case fmt_ps:
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/6] sim: mips: fix uninitialized register use
  2021-06-15  5:11 [PATCH 1/6] sim: mips: fix format warnings when setting up memory Mike Frysinger
  2021-06-15  5:11 ` [PATCH 2/6] sim: mips: add casts to fpu conversions Mike Frysinger
@ 2021-06-15  5:11 ` Mike Frysinger
  2021-06-15  5:11 ` [PATCH 4/6] sim: mips: tweak buffer sign Mike Frysinger
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2021-06-15  5:11 UTC (permalink / raw)
  To: gdb-patches

In the default case, this code will read from this variable before
it is initialized as a dummy access.  Set it to 0 to fix the compiler
warning.
---
 sim/mips/dv-tx3904irc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sim/mips/dv-tx3904irc.c b/sim/mips/dv-tx3904irc.c
index 0896b0fabb0b..6fbe61c7f548 100644
--- a/sim/mips/dv-tx3904irc.c
+++ b/sim/mips/dv-tx3904irc.c
@@ -381,7 +381,7 @@ tx3904irc_io_write_buffer (struct hw *me,
       int reg_number = (address - controller->base_address) / 4;
       int reg_offset = (address - controller->base_address) % 4;
       unsigned_4* register_ptr;
-      unsigned_4 register_value;
+      unsigned_4 register_value = 0;
 
       /* fill in entire register_value word */
       switch (reg_number)
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/6] sim: mips: tweak buffer sign
  2021-06-15  5:11 [PATCH 1/6] sim: mips: fix format warnings when setting up memory Mike Frysinger
  2021-06-15  5:11 ` [PATCH 2/6] sim: mips: add casts to fpu conversions Mike Frysinger
  2021-06-15  5:11 ` [PATCH 3/6] sim: mips: fix uninitialized register use Mike Frysinger
@ 2021-06-15  5:11 ` Mike Frysinger
  2021-06-15  5:11 ` [PATCH 5/6] sim: mips: rework dynamic printf logic to avoid compiler warnings Mike Frysinger
  2021-06-15  5:11 ` [PATCH 6/6] sim: mips: add printf attribute to trace func Mike Frysinger
  4 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2021-06-15  5:11 UTC (permalink / raw)
  To: gdb-patches

This model uses unsigned char buffers, but this temporary pointer is
declared as signed.  Switch it to unsigned since it's just a temporary
variable to hold the new pointer.
---
 sim/mips/dv-tx3904sio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sim/mips/dv-tx3904sio.c b/sim/mips/dv-tx3904sio.c
index c81b2dd3a5e7..d447014014cc 100644
--- a/sim/mips/dv-tx3904sio.c
+++ b/sim/mips/dv-tx3904sio.c
@@ -582,7 +582,7 @@ tx3904sio_fifo_push(struct hw* me, struct tx3904sio_fifo* fifo, char it)
   if(fifo->size == fifo->used) /* full */
     {
       int next_size = fifo->size * 2 + 16;
-      char* next_buf = zalloc(next_size);
+      unsigned_1* next_buf = zalloc(next_size);
       memcpy(next_buf, fifo->buffer, fifo->used);
 
       if(fifo->buffer != NULL) free(fifo->buffer);
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 5/6] sim: mips: rework dynamic printf logic to avoid compiler warnings
  2021-06-15  5:11 [PATCH 1/6] sim: mips: fix format warnings when setting up memory Mike Frysinger
                   ` (2 preceding siblings ...)
  2021-06-15  5:11 ` [PATCH 4/6] sim: mips: tweak buffer sign Mike Frysinger
@ 2021-06-15  5:11 ` Mike Frysinger
  2021-06-15  5:11 ` [PATCH 6/6] sim: mips: add printf attribute to trace func Mike Frysinger
  4 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2021-06-15  5:11 UTC (permalink / raw)
  To: gdb-patches

The compiler doesn't like passing non-constant strings to printf
functions, so tweak the code to always pass one in.  This code is
a little more verbose, but it's probably the same performance.
---
 sim/mips/interp.c | 41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/sim/mips/interp.c b/sim/mips/interp.c
index bccc4c76ed8b..fc7b00324ffb 100644
--- a/sim/mips/interp.c
+++ b/sim/mips/interp.c
@@ -1388,7 +1388,7 @@ sim_monitor (SIM_DESC sd,
       {
 	address_word s = A0;
 	unsigned char c;
-	signed_word *ap = &A1; /* 1st argument */
+	address_word *ap = &A1; /* 1st argument */
         /* This isn't the quickest way, since we call the host print
            routine for every character almost. But it does avoid
            having to allocate and manage a temporary string buffer. */
@@ -1471,18 +1471,43 @@ sim_monitor (SIM_DESC sd,
 			  sim_io_printf(sd,"<binary not supported>");
 			else
 			  {
-			    sprintf (tmp, "%%%s%c", longlong ? "ll" : "", c);
-			    if (longlong)
-			      sim_io_printf(sd, tmp, lv);
-			    else
-			      sim_io_printf(sd, tmp, (int)lv);
+#define _P(c, fmt64, fmt32) \
+  case c: \
+    if (longlong) \
+      sim_io_printf (sd, "%" fmt64, lv); \
+    else \
+      sim_io_printf (sd, "%" fmt32, (int)lv); \
+    break;
+#define P(c, fmtc) _P(c, PRI##fmtc##64, PRI##fmtc##32)
+			    switch (c)
+			      {
+			      P('d', d)
+			      P('o', o)
+			      P('x', x)
+			      P('X', X)
+			      P('u', u)
+			      }
 			  }
+#undef P
+#undef _P
 		      }
 		    else if (strchr ("eEfgG", c))
 		      {
 			double dbl = *(double*)(ap++);
-			sprintf (tmp, "%%%d.%d%c", width, trunc, c);
-			sim_io_printf (sd, tmp, dbl);
+
+#define P(c, fmtc) \
+  case c: \
+    sim_io_printf (sd, "%*.*" #fmtc, width, trunc, dbl); \
+    break;
+			switch (c)
+			  {
+			  P('e', e)
+			  P('E', E)
+			  P('f', f)
+			  P('g', g)
+			  P('G', G)
+			  }
+#undef P
 			trunc = 0;
 		      }
 		  }
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 6/6] sim: mips: add printf attribute to trace func
  2021-06-15  5:11 [PATCH 1/6] sim: mips: fix format warnings when setting up memory Mike Frysinger
                   ` (3 preceding siblings ...)
  2021-06-15  5:11 ` [PATCH 5/6] sim: mips: rework dynamic printf logic to avoid compiler warnings Mike Frysinger
@ 2021-06-15  5:11 ` Mike Frysinger
  4 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2021-06-15  5:11 UTC (permalink / raw)
  To: gdb-patches

This helps catch format errors in code, although they're all clean
at this point already.
---
 sim/mips/interp.c   | 2 +-
 sim/mips/sim-main.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sim/mips/interp.c b/sim/mips/interp.c
index fc7b00324ffb..64e6d28dd52f 100644
--- a/sim/mips/interp.c
+++ b/sim/mips/interp.c
@@ -1722,7 +1722,7 @@ dotrace (SIM_DESC sd,
 	 int type,
 	 SIM_ADDR address,
 	 int width,
-	 char *comment,...)
+	 const char *comment, ...)
 {
   if (STATE & simTRACE) {
     va_list ap;
diff --git a/sim/mips/sim-main.h b/sim/mips/sim-main.h
index 8c9abfa0b0b3..990573996bb9 100644
--- a/sim/mips/sim-main.h
+++ b/sim/mips/sim-main.h
@@ -965,7 +965,7 @@ address_word micromips_instruction_decode (SIM_DESC sd, sim_cpu * cpu,
 					   int instruction_size);
 
 #if WITH_TRACE_ANY_P
-void dotrace (SIM_DESC sd, sim_cpu *cpu, FILE *tracefh, int type, SIM_ADDR address, int width, char *comment, ...);
+void dotrace (SIM_DESC sd, sim_cpu *cpu, FILE *tracefh, int type, SIM_ADDR address, int width, const char *comment, ...) ATTRIBUTE_PRINTF (7, 8);
 extern FILE *tracefh;
 #else
 #define dotrace(sd, cpu, tracefh, type, address, width, comment, ...)
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-15  5:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15  5:11 [PATCH 1/6] sim: mips: fix format warnings when setting up memory Mike Frysinger
2021-06-15  5:11 ` [PATCH 2/6] sim: mips: add casts to fpu conversions Mike Frysinger
2021-06-15  5:11 ` [PATCH 3/6] sim: mips: fix uninitialized register use Mike Frysinger
2021-06-15  5:11 ` [PATCH 4/6] sim: mips: tweak buffer sign Mike Frysinger
2021-06-15  5:11 ` [PATCH 5/6] sim: mips: rework dynamic printf logic to avoid compiler warnings Mike Frysinger
2021-06-15  5:11 ` [PATCH 6/6] sim: mips: add printf attribute to trace func Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).