diff options
-rw-r--r-- | hw/e1000.c | 14 | ||||
-rw-r--r-- | hw/esp.c | 4 | ||||
-rw-r--r-- | hw/hw.h | 121 | ||||
-rw-r--r-- | hw/pcnet.c | 24 | ||||
-rw-r--r-- | hw/ptimer.c | 12 | ||||
-rw-r--r-- | hw/pxa2xx.c | 12 | ||||
-rw-r--r-- | hw/pxa2xx_timer.c | 8 | ||||
-rw-r--r-- | hw/tcx.c | 18 | ||||
-rw-r--r-- | hw/tmp105.c | 12 | ||||
-rw-r--r-- | hw/tsc210x.c | 8 | ||||
-rw-r--r-- | target-i386/machine.c | 4 | ||||
-rw-r--r-- | vl.c | 24 |
12 files changed, 183 insertions, 78 deletions
@@ -102,8 +102,8 @@ typedef struct E1000State_st { uint32_t paylen; uint16_t tso_frames; char tse; - char ip; - char tcp; + int8_t ip; + int8_t tcp; char cptse; // current packet tse bit } tx; @@ -824,8 +824,8 @@ nic_save(QEMUFile *f, void *opaque) qemu_put_be16s(f, &s->tx.size); qemu_put_be16s(f, &s->tx.tso_frames); qemu_put_8s(f, &s->tx.sum_needed); - qemu_put_8s(f, &s->tx.ip); - qemu_put_8s(f, &s->tx.tcp); + qemu_put_s8s(f, &s->tx.ip); + qemu_put_s8s(f, &s->tx.tcp); qemu_put_buffer(f, s->tx.header, sizeof s->tx.header); qemu_put_buffer(f, s->tx.data, sizeof s->tx.data); for (i = 0; i < 64; i++) @@ -849,7 +849,7 @@ nic_load(QEMUFile *f, void *opaque, int version_id) if ((ret = pci_device_load(&s->dev, f)) < 0) return ret; if (version_id == 1) - qemu_get_be32s(f, &i); /* once some unused instance id */ + qemu_get_sbe32s(f, &i); /* once some unused instance id */ qemu_get_be32s(f, &s->mmio_base); qemu_get_be32s(f, &s->rxbuf_size); qemu_get_be32s(f, &s->rxbuf_min_shift); @@ -870,8 +870,8 @@ nic_load(QEMUFile *f, void *opaque, int version_id) qemu_get_be16s(f, &s->tx.size); qemu_get_be16s(f, &s->tx.tso_frames); qemu_get_8s(f, &s->tx.sum_needed); - qemu_get_8s(f, &s->tx.ip); - qemu_get_8s(f, &s->tx.tcp); + qemu_get_s8s(f, &s->tx.ip); + qemu_get_s8s(f, &s->tx.tcp); qemu_get_buffer(f, s->tx.header, sizeof s->tx.header); qemu_get_buffer(f, s->tx.data, sizeof s->tx.data); for (i = 0; i < 64; i++) @@ -578,7 +578,7 @@ static void esp_save(QEMUFile *f, void *opaque) qemu_put_buffer(f, s->rregs, ESP_REGS); qemu_put_buffer(f, s->wregs, ESP_REGS); - qemu_put_be32s(f, (uint32_t *)&s->ti_size); + qemu_put_sbe32s(f, &s->ti_size); qemu_put_be32s(f, &s->ti_rptr); qemu_put_be32s(f, &s->ti_wptr); qemu_put_buffer(f, s->ti_buf, TI_BUFSZ); @@ -600,7 +600,7 @@ static int esp_load(QEMUFile *f, void *opaque, int version_id) qemu_get_buffer(f, s->rregs, ESP_REGS); qemu_get_buffer(f, s->wregs, ESP_REGS); - qemu_get_be32s(f, (uint32_t *)&s->ti_size); + qemu_get_sbe32s(f, &s->ti_size); qemu_get_be32s(f, &s->ti_rptr); qemu_get_be32s(f, &s->ti_wptr); qemu_get_buffer(f, s->ti_buf, TI_BUFSZ); @@ -10,15 +10,31 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode); void qemu_fflush(QEMUFile *f); void qemu_fclose(QEMUFile *f); -void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); -void qemu_put_byte(QEMUFile *f, int v); -void qemu_put_be16(QEMUFile *f, unsigned int v); -void qemu_put_be32(QEMUFile *f, unsigned int v); +void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size); +void qemu_put_byte(QEMUFile *f, int8_t v); + +static inline void qemu_put_ubyte(QEMUFile *f, uint8_t v) +{ + qemu_put_byte(f, (int8_t)v); +} + +#define qemu_put_sbyte qemu_put_byte + +void qemu_put_be16(QEMUFile *f, uint16_t v); +void qemu_put_be32(QEMUFile *f, uint32_t v); void qemu_put_be64(QEMUFile *f, uint64_t v); -int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size); -int qemu_get_byte(QEMUFile *f); -unsigned int qemu_get_be16(QEMUFile *f); -unsigned int qemu_get_be32(QEMUFile *f); +size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size); +int8_t qemu_get_byte(QEMUFile *f); + +static inline uint8_t qemu_get_ubyte(QEMUFile *f) +{ + return (uint8_t)qemu_get_byte(f); +} + +#define qemu_get_sbyte qemu_get_byte + +uint16_t qemu_get_be16(QEMUFile *f); +uint32_t qemu_get_be32(QEMUFile *f); uint64_t qemu_get_be64(QEMUFile *f); static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv) @@ -61,17 +77,106 @@ static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv) *pv = qemu_get_byte(f); } +// Signed versions for type safety +static inline void qemu_put_sbuffer(QEMUFile *f, const int8_t *buf, size_t size) +{ + qemu_put_buffer(f, (const uint8_t *)buf, size); +} + +static inline void qemu_put_sbe16(QEMUFile *f, int16_t v) +{ + qemu_put_be16(f, (uint16_t)v); +} + +static inline void qemu_put_sbe32(QEMUFile *f, int32_t v) +{ + qemu_put_be32(f, (uint32_t)v); +} + +static inline void qemu_put_sbe64(QEMUFile *f, int64_t v) +{ + qemu_put_be64(f, (uint64_t)v); +} + +static inline size_t qemu_get_sbuffer(QEMUFile *f, int8_t *buf, size_t size) +{ + return qemu_get_buffer(f, (uint8_t *)buf, size); +} + +static inline int16_t qemu_get_sbe16(QEMUFile *f) +{ + return (int16_t)qemu_get_be16(f); +} + +static inline int32_t qemu_get_sbe32(QEMUFile *f) +{ + return (int32_t)qemu_get_be32(f); +} + +static inline int64_t qemu_get_sbe64(QEMUFile *f) +{ + return (int64_t)qemu_get_be64(f); +} + +static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv) +{ + qemu_put_8s(f, (const uint8_t *)pv); +} + +static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv) +{ + qemu_put_be16s(f, (const uint16_t *)pv); +} + +static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv) +{ + qemu_put_be32s(f, (const uint32_t *)pv); +} + +static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv) +{ + qemu_put_be64s(f, (const uint64_t *)pv); +} + +static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv) +{ + qemu_get_8s(f, (uint8_t *)pv); +} + +static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv) +{ + qemu_get_be16s(f, (uint16_t *)pv); +} + +static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv) +{ + qemu_get_be32s(f, (uint32_t *)pv); +} + +static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv) +{ + qemu_get_be64s(f, (uint64_t *)pv); +} + #ifdef NEED_CPU_H #if TARGET_LONG_BITS == 64 #define qemu_put_betl qemu_put_be64 #define qemu_get_betl qemu_get_be64 #define qemu_put_betls qemu_put_be64s #define qemu_get_betls qemu_get_be64s +#define qemu_put_sbetl qemu_put_sbe64 +#define qemu_get_sbetl qemu_get_sbe64 +#define qemu_put_sbetls qemu_put_sbe64s +#define qemu_get_sbetls qemu_get_sbe64s #else #define qemu_put_betl qemu_put_be32 #define qemu_get_betl qemu_get_be32 #define qemu_put_betls qemu_put_be32s #define qemu_get_betls qemu_get_be32s +#define qemu_put_sbetl qemu_put_sbe32 +#define qemu_get_sbetl qemu_get_sbe32 +#define qemu_put_sbetls qemu_put_sbe32s +#define qemu_get_sbetls qemu_get_sbe32s #endif #endif @@ -1877,9 +1877,9 @@ static void pcnet_save(QEMUFile *f, void *opaque) if (s->pci_dev) pci_device_save(s->pci_dev, f); - qemu_put_be32(f, s->rap); - qemu_put_be32(f, s->isr); - qemu_put_be32(f, s->lnkst); + qemu_put_sbe32(f, s->rap); + qemu_put_sbe32(f, s->isr); + qemu_put_sbe32(f, s->lnkst); qemu_put_be32s(f, &s->rdra); qemu_put_be32s(f, &s->tdra); qemu_put_buffer(f, s->prom, 16); @@ -1888,10 +1888,10 @@ static void pcnet_save(QEMUFile *f, void *opaque) for (i = 0; i < 32; i++) qemu_put_be16s(f, &s->bcr[i]); qemu_put_be64s(f, &s->timer); - qemu_put_be32(f, s->xmit_pos); - qemu_put_be32(f, s->recv_pos); + qemu_put_sbe32(f, s->xmit_pos); + qemu_put_sbe32(f, s->recv_pos); qemu_put_buffer(f, s->buffer, 4096); - qemu_put_be32(f, s->tx_busy); + qemu_put_sbe32(f, s->tx_busy); qemu_put_timer(f, s->poll_timer); } @@ -1909,9 +1909,9 @@ static int pcnet_load(QEMUFile *f, void *opaque, int version_id) return ret; } - qemu_get_be32s(f, (uint32_t*)&s->rap); - qemu_get_be32s(f, (uint32_t*)&s->isr); - qemu_get_be32s(f, (uint32_t*)&s->lnkst); + qemu_get_sbe32s(f, &s->rap); + qemu_get_sbe32s(f, &s->isr); + qemu_get_sbe32s(f, &s->lnkst); qemu_get_be32s(f, &s->rdra); qemu_get_be32s(f, &s->tdra); qemu_get_buffer(f, s->prom, 16); @@ -1920,10 +1920,10 @@ static int pcnet_load(QEMUFile *f, void *opaque, int version_id) for (i = 0; i < 32; i++) qemu_get_be16s(f, &s->bcr[i]); qemu_get_be64s(f, &s->timer); - qemu_get_be32s(f, (uint32_t*)&s->xmit_pos); - qemu_get_be32s(f, (uint32_t*)&s->recv_pos); + qemu_get_sbe32s(f, &s->xmit_pos); + qemu_get_sbe32s(f, &s->recv_pos); qemu_get_buffer(f, s->buffer, 4096); - qemu_get_be32s(f, (uint32_t*)&s->tx_busy); + qemu_get_sbe32s(f, &s->tx_busy); qemu_get_timer(f, s->poll_timer); return 0; diff --git a/hw/ptimer.c b/hw/ptimer.c index 356fad7..b772ca2 100644 --- a/hw/ptimer.c +++ b/hw/ptimer.c @@ -165,9 +165,9 @@ void qemu_put_ptimer(QEMUFile *f, ptimer_state *s) qemu_put_be64s(f, &s->limit); qemu_put_be64s(f, &s->delta); qemu_put_be32s(f, &s->period_frac); - qemu_put_be64s(f, &s->period); - qemu_put_be64s(f, &s->last_event); - qemu_put_be64s(f, &s->next_event); + qemu_put_sbe64s(f, &s->period); + qemu_put_sbe64s(f, &s->last_event); + qemu_put_sbe64s(f, &s->next_event); qemu_put_timer(f, s->timer); } @@ -177,9 +177,9 @@ void qemu_get_ptimer(QEMUFile *f, ptimer_state *s) qemu_get_be64s(f, &s->limit); qemu_get_be64s(f, &s->delta); qemu_get_be32s(f, &s->period_frac); - qemu_get_be64s(f, &s->period); - qemu_get_be64s(f, &s->last_event); - qemu_get_be64s(f, &s->next_event); + qemu_get_sbe64s(f, &s->period); + qemu_get_sbe64s(f, &s->last_event); + qemu_get_sbe64s(f, &s->next_event); qemu_get_timer(f, s->timer); } diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c index fd663d9..2c838e5 100644 --- a/hw/pxa2xx.c +++ b/hw/pxa2xx.c @@ -1233,9 +1233,9 @@ static void pxa2xx_rtc_save(QEMUFile *f, void *opaque) qemu_put_be32s(f, &s->last_rycr); qemu_put_be32s(f, &s->last_swcr); qemu_put_be32s(f, &s->last_rtcpicr); - qemu_put_be64s(f, (uint64_t *) &s->last_hz); - qemu_put_be64s(f, (uint64_t *) &s->last_sw); - qemu_put_be64s(f, (uint64_t *) &s->last_pi); + qemu_put_sbe64s(f, &s->last_hz); + qemu_put_sbe64s(f, &s->last_sw); + qemu_put_sbe64s(f, &s->last_pi); } static int pxa2xx_rtc_load(QEMUFile *f, void *opaque, int version_id) @@ -1257,9 +1257,9 @@ static int pxa2xx_rtc_load(QEMUFile *f, void *opaque, int version_id) qemu_get_be32s(f, &s->last_rycr); qemu_get_be32s(f, &s->last_swcr); qemu_get_be32s(f, &s->last_rtcpicr); - qemu_get_be64s(f, (uint64_t *) &s->last_hz); - qemu_get_be64s(f, (uint64_t *) &s->last_sw); - qemu_get_be64s(f, (uint64_t *) &s->last_pi); + qemu_get_sbe64s(f, &s->last_hz); + qemu_get_sbe64s(f, &s->last_sw); + qemu_get_sbe64s(f, &s->last_pi); pxa2xx_rtc_alarm_update(s, s->rtsr); diff --git a/hw/pxa2xx_timer.c b/hw/pxa2xx_timer.c index 7e1504a..01cfc4f 100644 --- a/hw/pxa2xx_timer.c +++ b/hw/pxa2xx_timer.c @@ -384,8 +384,8 @@ static void pxa2xx_timer_save(QEMUFile *f, void *opaque) for (i = 0; i < 8; i ++) { qemu_put_be32s(f, &s->tm4[i].tm.value); qemu_put_be32(f, s->tm4[i].tm.level); - qemu_put_be32s(f, (uint32_t *) &s->tm4[i].oldclock); - qemu_put_be32s(f, (uint32_t *) &s->tm4[i].clock); + qemu_put_sbe32s(f, &s->tm4[i].oldclock); + qemu_put_sbe32s(f, &s->tm4[i].clock); qemu_put_be64s(f, &s->tm4[i].lastload); qemu_put_be32s(f, &s->tm4[i].freq); qemu_put_be32s(f, &s->tm4[i].control); @@ -418,8 +418,8 @@ static int pxa2xx_timer_load(QEMUFile *f, void *opaque, int version_id) for (i = 0; i < 8; i ++) { qemu_get_be32s(f, &s->tm4[i].tm.value); s->tm4[i].tm.level = qemu_get_be32(f); - qemu_get_be32s(f, (uint32_t *) &s->tm4[i].oldclock); - qemu_get_be32s(f, (uint32_t *) &s->tm4[i].clock); + qemu_get_sbe32s(f, &s->tm4[i].oldclock); + qemu_get_sbe32s(f, &s->tm4[i].clock); qemu_get_be64s(f, &s->tm4[i].lastload); qemu_get_be32s(f, &s->tm4[i].freq); qemu_get_be32s(f, &s->tm4[i].control); @@ -372,9 +372,9 @@ static void tcx_save(QEMUFile *f, void *opaque) { TCXState *s = opaque; - qemu_put_be16s(f, (uint16_t *)&s->height); - qemu_put_be16s(f, (uint16_t *)&s->width); - qemu_put_be16s(f, (uint16_t *)&s->depth); + qemu_put_be16s(f, &s->height); + qemu_put_be16s(f, &s->width); + qemu_put_be16s(f, &s->depth); qemu_put_buffer(f, s->r, 256); qemu_put_buffer(f, s->g, 256); qemu_put_buffer(f, s->b, 256); @@ -391,13 +391,13 @@ static int tcx_load(QEMUFile *f, void *opaque, int version_id) return -EINVAL; if (version_id == 3) { - qemu_get_be32s(f, (uint32_t *)&dummy); - qemu_get_be32s(f, (uint32_t *)&dummy); - qemu_get_be32s(f, (uint32_t *)&dummy); + qemu_get_be32s(f, &dummy); + qemu_get_be32s(f, &dummy); + qemu_get_be32s(f, &dummy); } - qemu_get_be16s(f, (uint16_t *)&s->height); - qemu_get_be16s(f, (uint16_t *)&s->width); - qemu_get_be16s(f, (uint16_t *)&s->depth); + qemu_get_be16s(f, &s->height); + qemu_get_be16s(f, &s->width); + qemu_get_be16s(f, &s->depth); qemu_get_buffer(f, s->r, 256); qemu_get_buffer(f, s->g, 256); qemu_get_buffer(f, s->b, 256); diff --git a/hw/tmp105.c b/hw/tmp105.c index a4a0103..aa2bff5 100644 --- a/hw/tmp105.c +++ b/hw/tmp105.c @@ -185,9 +185,9 @@ static void tmp105_save(QEMUFile *f, void *opaque) qemu_put_8s(f, &s->pointer); qemu_put_8s(f, &s->config); - qemu_put_be16s(f, (uint16_t *) &s->temperature); - qemu_put_be16s(f, (uint16_t *) &s->limit[0]); - qemu_put_be16s(f, (uint16_t *) &s->limit[1]); + qemu_put_sbe16s(f, &s->temperature); + qemu_put_sbe16s(f, &s->limit[0]); + qemu_put_sbe16s(f, &s->limit[1]); qemu_put_byte(f, s->alarm); s->faults = tmp105_faultq[(s->config >> 3) & 3]; /* F */ @@ -204,9 +204,9 @@ static int tmp105_load(QEMUFile *f, void *opaque, int version_id) qemu_get_8s(f, &s->pointer); qemu_get_8s(f, &s->config); - qemu_get_be16s(f, (uint16_t *) &s->temperature); - qemu_get_be16s(f, (uint16_t *) &s->limit[0]); - qemu_get_be16s(f, (uint16_t *) &s->limit[1]); + qemu_get_sbe16s(f, &s->temperature); + qemu_get_sbe16s(f, &s->limit[0]); + qemu_get_sbe16s(f, &s->limit[1]); s->alarm = qemu_get_byte(f); tmp105_interrupt_update(s); diff --git a/hw/tsc210x.c b/hw/tsc210x.c index 97c21ef..61e101d 100644 --- a/hw/tsc210x.c +++ b/hw/tsc210x.c @@ -1046,8 +1046,8 @@ static void tsc210x_save(QEMUFile *f, void *opaque) qemu_put_be16s(f, &s->pll[0]); qemu_put_be16s(f, &s->pll[1]); qemu_put_be16s(f, &s->volume); - qemu_put_be64(f, (uint64_t) (s->volume_change - now)); - qemu_put_be64(f, (uint64_t) (s->powerdown - now)); + qemu_put_sbe64(f, (s->volume_change - now)); + qemu_put_sbe64(f, (s->powerdown - now)); qemu_put_byte(f, s->softstep); qemu_put_be16s(f, &s->dac_power); @@ -1092,8 +1092,8 @@ static int tsc210x_load(QEMUFile *f, void *opaque, int version_id) qemu_get_be16s(f, &s->pll[0]); qemu_get_be16s(f, &s->pll[1]); qemu_get_be16s(f, &s->volume); - s->volume_change = (int64_t) qemu_get_be64(f) + now; - s->powerdown = (int64_t) qemu_get_be64(f) + now; + s->volume_change = qemu_get_sbe64(f) + now; + s->powerdown = qemu_get_sbe64(f) + now; s->softstep = qemu_get_byte(f); qemu_get_be16s(f, &s->dac_power); diff --git a/target-i386/machine.c b/target-i386/machine.c index 91dbd55..34a0d76 100644 --- a/target-i386/machine.c +++ b/target-i386/machine.c @@ -102,7 +102,7 @@ void cpu_save(QEMUFile *f, void *opaque) /* MMU */ a20_mask = (int32_t) env->a20_mask; - qemu_put_be32s(f, &a20_mask); + qemu_put_sbe32s(f, &a20_mask); /* XMM */ qemu_put_be32s(f, &env->mxcsr); @@ -256,7 +256,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) qemu_get_betls(f, &env->dr[i]); /* MMU */ - qemu_get_be32s(f, &a20_mask); + qemu_get_sbe32s(f, &a20_mask); env->a20_mask = a20_mask; qemu_get_be32s(f, &env->mxcsr); @@ -6247,9 +6247,9 @@ void qemu_fclose(QEMUFile *f) qemu_free(f); } -void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) +void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size) { - int l; + size_t l; while (size > 0) { l = IO_BUF_SIZE - f->buf_index; if (l > size) @@ -6263,16 +6263,16 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) } } -void qemu_put_byte(QEMUFile *f, int v) +void qemu_put_byte(QEMUFile *f, int8_t v) { f->buf[f->buf_index++] = v; if (f->buf_index >= IO_BUF_SIZE) qemu_fflush(f); } -int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size1) +size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size1) { - int size, l; + size_t size, l; size = size1; while (size > 0) { @@ -6293,7 +6293,7 @@ int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size1) return size1 - size; } -int qemu_get_byte(QEMUFile *f) +int8_t qemu_get_byte(QEMUFile *f) { if (f->buf_index >= f->buf_size) { qemu_fill_buffer(f); @@ -6329,13 +6329,13 @@ int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence) return pos; } -void qemu_put_be16(QEMUFile *f, unsigned int v) +void qemu_put_be16(QEMUFile *f, uint16_t v) { qemu_put_byte(f, v >> 8); qemu_put_byte(f, v); } -void qemu_put_be32(QEMUFile *f, unsigned int v) +void qemu_put_be32(QEMUFile *f, uint32_t v) { qemu_put_byte(f, v >> 24); qemu_put_byte(f, v >> 16); @@ -6349,17 +6349,17 @@ void qemu_put_be64(QEMUFile *f, uint64_t v) qemu_put_be32(f, v); } -unsigned int qemu_get_be16(QEMUFile *f) +uint16_t qemu_get_be16(QEMUFile *f) { - unsigned int v; + uint16_t v; v = qemu_get_byte(f) << 8; v |= qemu_get_byte(f); return v; } -unsigned int qemu_get_be32(QEMUFile *f) +uint32_t qemu_get_be32(QEMUFile *f) { - unsigned int v; + uint32_t v; v = qemu_get_byte(f) << 24; v |= qemu_get_byte(f) << 16; v |= qemu_get_byte(f) << 8; |