From 5b94c3808140206d3b5204a3780f294d590cc458 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 26 Oct 2022 21:53:30 +0545 Subject: sim: common: change sim_read & sim_write to use void* buffers When reading/writing arbitrary data to the system's memory, the unsigned char pointer type doesn't make that much sense. Switch it to void so we align a bit with standard C library read/write functions, and to avoid having to sprinkle casts everywhere. --- sim/avr/interp.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'sim/avr/interp.c') diff --git a/sim/avr/interp.c b/sim/avr/interp.c index 8efdffa..1b147c4 100644 --- a/sim/avr/interp.c +++ b/sim/avr/interp.c @@ -1526,25 +1526,26 @@ sim_engine_run (SIM_DESC sd, } int -sim_write (SIM_DESC sd, SIM_ADDR addr, const unsigned char *buffer, int size) +sim_write (SIM_DESC sd, SIM_ADDR addr, const void *buffer, int size) { int osize = size; if (addr >= 0 && addr < SRAM_VADDR) { + const unsigned char *data = buffer; while (size > 0 && addr < (MAX_AVR_FLASH << 1)) { word val = flash[addr >> 1].op; if (addr & 1) - val = (val & 0xff) | (buffer[0] << 8); + val = (val & 0xff) | (data[0] << 8); else - val = (val & 0xff00) | buffer[0]; + val = (val & 0xff00) | data[0]; flash[addr >> 1].op = val; flash[addr >> 1].code = OP_unknown; addr++; - buffer++; + data++; size--; } return osize - size; @@ -1562,12 +1563,13 @@ sim_write (SIM_DESC sd, SIM_ADDR addr, const unsigned char *buffer, int size) } int -sim_read (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size) +sim_read (SIM_DESC sd, SIM_ADDR addr, void *buffer, int size) { int osize = size; if (addr >= 0 && addr < SRAM_VADDR) { + unsigned char *data = buffer; while (size > 0 && addr < (MAX_AVR_FLASH << 1)) { word val = flash[addr >> 1].op; @@ -1575,7 +1577,7 @@ sim_read (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size) if (addr & 1) val >>= 8; - *buffer++ = val; + *data++ = val; addr++; size--; } -- cgit v1.1