summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>2008-10-02 19:14:17 +0000
committerblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>2008-10-02 19:14:17 +0000
commitb6c4f71f508977fedc11f5c822642a5bb1c899a3 (patch)
treec15fe04b63c822a16d62af197d12450286f6f390 /hw
parent09bc878a13c1ca1c5d2400db5657ea7d04fe26bc (diff)
downloadqemu-b6c4f71f508977fedc11f5c822642a5bb1c899a3.tar.gz
qemu-b6c4f71f508977fedc11f5c822642a5bb1c899a3.tar.bz2
qemu-b6c4f71f508977fedc11f5c822642a5bb1c899a3.zip
Resurrect the safe part of r5274
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5401 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'hw')
-rw-r--r--hw/e1000.c14
-rw-r--r--hw/esp.c4
-rw-r--r--hw/hw.h105
-rw-r--r--hw/pcnet.c24
-rw-r--r--hw/ptimer.c12
-rw-r--r--hw/pxa2xx.c12
-rw-r--r--hw/pxa2xx_timer.c8
-rw-r--r--hw/tcx.c18
-rw-r--r--hw/tmp105.c12
-rw-r--r--hw/tsc210x.c8
10 files changed, 161 insertions, 56 deletions
diff --git a/hw/e1000.c b/hw/e1000.c
index 265bd0dc35..b351119b41 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -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++)
diff --git a/hw/esp.c b/hw/esp.c
index c63f9936c7..6b16cf4688 100644
--- a/hw/esp.c
+++ b/hw/esp.c
@@ -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);
diff --git a/hw/hw.h b/hw/hw.h
index 45cc0b5461..c9390c1725 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -39,11 +39,27 @@ void qemu_fflush(QEMUFile *f);
int qemu_fclose(QEMUFile *f);
void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
void qemu_put_byte(QEMUFile *f, int v);
+
+static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v)
+{
+ qemu_put_byte(f, (int)v);
+}
+
+#define qemu_put_sbyte qemu_put_byte
+
void qemu_put_be16(QEMUFile *f, unsigned int v);
void qemu_put_be32(QEMUFile *f, unsigned int 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);
+
+static inline unsigned int qemu_get_ubyte(QEMUFile *f)
+{
+ return (unsigned int)qemu_get_byte(f);
+}
+
+#define qemu_get_sbyte qemu_get_byte
+
unsigned int qemu_get_be16(QEMUFile *f);
unsigned int qemu_get_be32(QEMUFile *f);
uint64_t qemu_get_be64(QEMUFile *f);
@@ -94,17 +110,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, int size)
+{
+ qemu_put_buffer(f, (const uint8_t *)buf, size);
+}
+
+static inline void qemu_put_sbe16(QEMUFile *f, int v)
+{
+ qemu_put_be16(f, (unsigned int)v);
+}
+
+static inline void qemu_put_sbe32(QEMUFile *f, int v)
+{
+ qemu_put_be32(f, (unsigned int)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, int size)
+{
+ return qemu_get_buffer(f, (uint8_t *)buf, size);
+}
+
+static inline int qemu_get_sbe16(QEMUFile *f)
+{
+ return (int)qemu_get_be16(f);
+}
+
+static inline int qemu_get_sbe32(QEMUFile *f)
+{
+ return (int)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
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 2e7f80c134..188e5ffd3b 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -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 356fad7b6f..b772ca2987 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 fd663d9da1..2c838e5e9d 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 7e1504acc1..01cfc4fab9 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);
diff --git a/hw/tcx.c b/hw/tcx.c
index 52a56c2c33..260635a5fc 100644
--- a/hw/tcx.c
+++ b/hw/tcx.c
@@ -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 a4a0103d7b..aa2bff5609 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 97c21ef026..61e101d628 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);