From 4ab6404b1c5798155640edf4bb207c8d1de37b5d Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Fri, 29 Oct 2021 06:42:15 +0000 Subject: [PATCH] sim: erc32: fix signedness compatibility and redefinition warnings --- sim/erc32/erc32.c | 23 +++++++++++------------ sim/erc32/exec.c | 14 +++++++------- sim/erc32/func.c | 4 +++- sim/erc32/sis.h | 11 ++++++----- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/sim/erc32/erc32.c b/sim/erc32/erc32.c index e7a816f86bf..68136e46c30 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; @@ -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; + memcpy (data, &erareg, 4); 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.30.2