[PATCH] sim/erc32: fix signedness compatiblity and redefinition warnings

Orgad Shaneh orgads@gmail.com
Thu Oct 28 07:55:40 GMT 2021


---
 sim/erc32/erc32.c | 25 ++++++++++++-------------
 sim/erc32/exec.c  | 14 +++++++-------
 sim/erc32/func.c  |  4 +++-
 sim/erc32/sis.h   | 11 ++++++-----
 4 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/sim/erc32/erc32.c b/sim/erc32/erc32.c
index e7a816f86bf..3bd2df857a7 100644
--- a/sim/erc32/erc32.c
+++ b/sim/erc32/erc32.c
@@ -292,8 +292,7 @@ static uint32	gpt_counter_read (void);
 static void	gpt_scaler_set (uint32 val);
 static void	gpt_reload_set (uint32 val);
 static void	timer_ctrl (uint32 val);
-static unsigned char *
-		get_mem_ptr (uint32 addr, uint32 size);
+static void *	get_mem_ptr (uint32 addr, uint32 size);
 static void	store_bytes (unsigned char *mem, uint32 waddr,
 			uint32 *data, int sz, int32 *ws);
 
@@ -1541,7 +1540,7 @@ store_bytes (unsigned char *mem, uint32 waddr, uint32 *data, int32 sz,
 /* Memory emulation */
 
 int
-memory_iread (uint32 addr, uint32 *data, int32 *ws)
+memory_iread (uint32 addr, uint32 *data, uint32 *ws)
 {
     uint32          asi;
     if ((addr >= mem_ramstart) && (addr < (mem_ramstart + mem_ramsz))) {
@@ -1566,7 +1565,7 @@ memory_iread (uint32 addr, uint32 *data, int32 *ws)
 }
 
 int
-memory_read(int32 asi, uint32 addr, uint32 *data, int32 sz, int32 *ws)
+memory_read(int32 asi, uint32 addr, void *data, int32 sz, int32 *ws)
 {
     int32           mexc;
 
@@ -1587,7 +1586,7 @@ memory_read(int32 asi, uint32 addr, uint32 *data, int32 sz, int32 *ws)
 	*ws = mem_ramr_ws;
 	return 0;
     } else if ((addr >= MEC_START) && (addr < MEC_END)) {
-	mexc = mec_read(addr, asi, data);
+	mexc = mec_read(addr, asi, (uint32 *)data);
 	if (mexc) {
 	    set_sfsr(MEC_ACC, addr, asi, 1);
 	    *ws = MEM_EX_WS;
@@ -1607,7 +1606,7 @@ memory_read(int32 asi, uint32 addr, uint32 *data, int32 sz, int32 *ws)
 	} else if ((addr >= 0x10000000) && 
 		   (addr < (0x10000000 + (512 << (mec_iocr & 0x0f)))) &&
 		   (mec_iocr & 0x10))  {
-	    *data = erareg;
+	    *(uint32 *)data = erareg;
 	    return 0;
 	}
 	
@@ -1739,7 +1738,7 @@ memory_write(int32 asi, uint32 addr, uint32 *data, int32 sz, int32 *ws)
     return 1;
 }
 
-static unsigned char  *
+static void  *
 get_mem_ptr(uint32 addr, uint32 size)
 {
     if ((addr + size) < ROM_SZ) {
@@ -1755,15 +1754,15 @@ get_mem_ptr(uint32 addr, uint32 size)
     }
 #endif
 
-    return (char *) -1;
+    return (void *) -1;
 }
 
 int
-sis_memory_write(uint32 addr, const unsigned char *data, uint32 length)
+sis_memory_write(uint32 addr, const void *data, uint32 length)
 {
-    char           *mem;
+    void           *mem;
 
-    if ((mem = get_mem_ptr(addr, length)) == ((char *) -1))
+    if ((mem = get_mem_ptr(addr, length)) == ((void *) -1))
 	return 0;
 
     memcpy(mem, data, length);
@@ -1771,11 +1770,11 @@ sis_memory_write(uint32 addr, const unsigned char *data, uint32 length)
 }
 
 int
-sis_memory_read(uint32 addr, char *data, uint32 length)
+sis_memory_read(uint32 addr, void *data, uint32 length)
 {
     char           *mem;
 
-    if ((mem = get_mem_ptr(addr, length)) == ((char *) -1))
+    if ((mem = get_mem_ptr(addr, length)) == ((void *) -1))
 	return 0;
 
     memcpy(data, mem, length);
diff --git a/sim/erc32/exec.c b/sim/erc32/exec.c
index d8a8c6c662b..1858813f000 100644
--- a/sim/erc32/exec.c
+++ b/sim/erc32/exec.c
@@ -395,11 +395,11 @@ dispatch_instruction(struct pstate *sregs)
 
     uint32          cwp, op, op2, op3, asi, rd, cond, rs1,
                     rs2;
-    uint32          ldep, icc;
-    int32           operand1, operand2, *rdd, result, eicc,
+    uint32          ldep, icc, data, *rdd;
+    int32           operand1, operand2, result, eicc,
                     new_cwp;
-    int32           pc, npc, data, address, ws, mexc, fcc;
-    int32	    ddata[2];
+    int32           pc, npc, address, ws, mexc, fcc;
+    uint32	    ddata[2];
 
     sregs->ninst++;
     cwp = ((sregs->psr & PSR_CWP) << 4);
@@ -1096,7 +1096,7 @@ dispatch_instruction(struct pstate *sregs)
 		    break;
 		}
 		sregs->psr = (sregs->psr & 0xff000000) |
-			(rs1 ^ operand2) & 0x00f03fff;
+			((rs1 ^ operand2) & 0x00f03fff);
 		break;
 	    case WRWIM:
 		if (!(sregs->psr & PSR_S)) {
@@ -1528,7 +1528,7 @@ dispatch_instruction(struct pstate *sregs)
 		if (sregs->frd == rd)
 		    sregs->fhold += (sregs->ftime - ebase.simtime);
 	    }
-	    mexc = memory_write(asi, address, &sregs->fsi[rd], 2, &ws);
+	    mexc = memory_write(asi, address, (uint32 *)&sregs->fsi[rd], 2, &ws);
 	    sregs->hold += ws;
 	    if (mexc) {
 		sregs->trap = TRAP_DEXC;
@@ -1548,7 +1548,7 @@ dispatch_instruction(struct pstate *sregs)
 		if ((sregs->frd == rd) || (sregs->frd + 1 == rd))
 		    sregs->fhold += (sregs->ftime - ebase.simtime);
 	    }
-	    mexc = memory_write(asi, address, &sregs->fsi[rd], 3, &ws);
+	    mexc = memory_write(asi, address, (uint32 *)&sregs->fsi[rd], 3, &ws);
 	    sregs->hold += ws;
 	    sregs->icnt = T_STD;
 #ifdef STAT
diff --git a/sim/erc32/func.c b/sim/erc32/func.c
index ff53f3bca51..d168a31b2cd 100644
--- a/sim/erc32/func.c
+++ b/sim/erc32/func.c
@@ -139,7 +139,7 @@ set_regi(struct pstate *sregs, int32 reg, uint32 rval)
 }
 
 void
-get_regi(struct pstate * sregs, int32 reg, char *buf)
+get_regi(struct pstate * sregs, int32 reg, unsigned char *buf)
 {
     uint32          cwp;
     uint32          rval = 0;
@@ -996,7 +996,9 @@ sys_halt(void)
 #include "libiberty.h"
 #include "bfd.h"
 
+#ifndef min
 #define min(A, B) (((A) < (B)) ? (A) : (B))
+#endif
 #define LOAD_ADDRESS 0
 
 int
diff --git a/sim/erc32/sis.h b/sim/erc32/sis.h
index 7f787cf1433..98cb9ccc33d 100644
--- a/sim/erc32/sis.h
+++ b/sim/erc32/sis.h
@@ -164,21 +164,22 @@ extern void	sim_halt (void);
 extern void	exit_sim (void);
 extern void	init_stdio (void);
 extern void	restore_stdio (void);
-extern int	memory_iread (uint32 addr, uint32 *data, int32 *ws);
-extern int	memory_read (int32 asi, uint32 addr, uint32 *data,
+extern int	memory_iread (uint32 addr, uint32 *data, uint32 *ws);
+extern int	memory_read (int32 asi, uint32 addr, void *data,
 			     int32 sz, int32 *ws);
 extern int	memory_write (int32 asi, uint32 addr, uint32 *data,
 			      int32 sz, int32 *ws);
 extern int	sis_memory_write (uint32 addr,
-				  const unsigned char *data, uint32 length);
-extern int	sis_memory_read (uint32 addr, char *data,
+				  const void *data, uint32 length);
+extern int	sis_memory_read (uint32 addr, void *data,
 				 uint32 length);
+extern void	boot_init (void);
 
 /* func.c */
 extern struct pstate  sregs;
 extern void	set_regi (struct pstate *sregs, int32 reg,
 			  uint32 rval);
-extern void	get_regi (struct pstate *sregs, int32 reg, char *buf);
+extern void	get_regi (struct pstate *sregs, int32 reg, unsigned char *buf);
 extern int	exec_cmd (struct pstate *sregs, const char *cmd);
 extern void	reset_stat (struct pstate  *sregs);
 extern void	show_stat (struct pstate  *sregs);
-- 
2.33.1.windows.1.1.g7e610705a5



More information about the Gdb-patches mailing list