* [Qemu-devel] [PATCH] substitute structure dump with discrete dump in eeprom_save/load @ 2009-02-22 22:58 Andre Przywara 2009-02-22 23:02 ` [Qemu-devel] [PATCH] support 93xx EEPROMs with more than 255 words Andre Przywara 2009-03-28 23:14 ` [Qemu-devel] [PATCH] substitute structure dump with discrete dump in eeprom_save/load Aurelien Jarno 0 siblings, 2 replies; 4+ messages in thread From: Andre Przywara @ 2009-02-22 22:58 UTC (permalink / raw) To: qemu-devel; +Cc: Andre Przywara The EEPROM 93xx device used to dump a C structure to the migration stream. This structure includes mixed 8 and 16bit variables and is thus subject to compiler dependent padding. Replace this with discrete dumps of each member (and add a padding byte to ensure compatibility, a version update is included in the following patch). Signed-off-by: Andre Przywara <andre.przywara@amd.com> --- hw/eeprom93xx.c | 30 ++++++++++++++++++++++++++++-- 1 files changed, 28 insertions(+), 2 deletions(-) diff --git a/hw/eeprom93xx.c b/hw/eeprom93xx.c index 896cffd..527fdf7 100644 --- a/hw/eeprom93xx.c +++ b/hw/eeprom93xx.c @@ -95,7 +95,19 @@ static void eeprom_save(QEMUFile *f, void *opaque) /* Save EEPROM data. */ unsigned address; eeprom_t *eeprom = (eeprom_t *)opaque; - qemu_put_buffer(f, (uint8_t *)eeprom, sizeof(*eeprom) - 2); + + qemu_put_byte(f, eeprom->tick); + qemu_put_byte(f, eeprom->address); + qemu_put_byte(f, eeprom->command); + qemu_put_byte(f, eeprom->writeable); + + qemu_put_byte(f, eeprom->eecs); + qemu_put_byte(f, eeprom->eesk); + qemu_put_byte(f, eeprom->eedo); + + qemu_put_byte(f, eeprom->addrbits); + qemu_put_byte(f, eeprom->size); + qemu_put_byte(f, 0); /* padding for compatiblity */ qemu_put_be16(f, eeprom->data); for (address = 0; address < eeprom->size; address++) { qemu_put_be16(f, eeprom->contents[address]); @@ -111,7 +123,20 @@ static int eeprom_load(QEMUFile *f, void *opaque, int version_id) if (version_id == eeprom_version) { unsigned address; uint8_t size = eeprom->size; - qemu_get_buffer(f, (uint8_t *)eeprom, sizeof(*eeprom) - 2); + + eeprom->tick = qemu_get_byte(f); + eeprom->address = qemu_get_byte(f); + eeprom->command = qemu_get_byte(f); + eeprom->writeable = qemu_get_byte(f); + + eeprom->eecs = qemu_get_byte(f); + eeprom->eesk = qemu_get_byte(f); + eeprom->eedo = qemu_get_byte(f); + + eeprom->addrbits = qemu_get_byte(f); + eeprom->size = qemu_get_byte(f); + qemu_get_byte(f); /* skip padding byte */ + if (eeprom->size == size) { eeprom->data = qemu_get_be16(f); for (address = 0; address < eeprom->size; address++) { -- 1.5.2.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH] support 93xx EEPROMs with more than 255 words 2009-02-22 22:58 [Qemu-devel] [PATCH] substitute structure dump with discrete dump in eeprom_save/load Andre Przywara @ 2009-02-22 23:02 ` Andre Przywara 2009-03-28 23:14 ` Aurelien Jarno 2009-03-28 23:14 ` [Qemu-devel] [PATCH] substitute structure dump with discrete dump in eeprom_save/load Aurelien Jarno 1 sibling, 1 reply; 4+ messages in thread From: Andre Przywara @ 2009-02-22 23:02 UTC (permalink / raw) To: qemu-devel; +Cc: Andre Przywara In the head of eeprom93xx.c we promise to support chips with 256 words, but store the size in an unsigned byte. This patch replaces this with an 16 bit variable and changes the load/store code accordingly (introducing a new version). Signed-off-by: Andre Przywara <andre.przywara@amd.com> --- hw/eeprom93xx.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hw/eeprom93xx.c b/hw/eeprom93xx.c index 527fdf7..e791894 100644 --- a/hw/eeprom93xx.c +++ b/hw/eeprom93xx.c @@ -49,8 +49,9 @@ #define logout(fmt, args...) ((void)0) #endif -static int eeprom_instance = 0; -static const int eeprom_version = 20061112; +#define EEPROM_INSTANCE 0 +#define OLD_EEPROM_VERSION 20061112 +#define EEPROM_VERSION (OLD_EEPROM_VERSION + 1) #if 0 typedef enum { @@ -83,7 +84,7 @@ struct _eeprom_t { uint8_t eedo; uint8_t addrbits; - uint8_t size; + uint16_t size; uint16_t data; uint16_t contents[0]; }; @@ -106,8 +107,7 @@ static void eeprom_save(QEMUFile *f, void *opaque) qemu_put_byte(f, eeprom->eedo); qemu_put_byte(f, eeprom->addrbits); - qemu_put_byte(f, eeprom->size); - qemu_put_byte(f, 0); /* padding for compatiblity */ + qemu_put_be16(f, eeprom->size); qemu_put_be16(f, eeprom->data); for (address = 0; address < eeprom->size; address++) { qemu_put_be16(f, eeprom->contents[address]); @@ -120,9 +120,9 @@ static int eeprom_load(QEMUFile *f, void *opaque, int version_id) of data and current EEPROM are identical. */ eeprom_t *eeprom = (eeprom_t *)opaque; int result = -EINVAL; - if (version_id == eeprom_version) { + if (version_id >= OLD_EEPROM_VERSION) { unsigned address; - uint8_t size = eeprom->size; + int size = eeprom->size; eeprom->tick = qemu_get_byte(f); eeprom->address = qemu_get_byte(f); @@ -134,8 +134,12 @@ static int eeprom_load(QEMUFile *f, void *opaque, int version_id) eeprom->eedo = qemu_get_byte(f); eeprom->addrbits = qemu_get_byte(f); - eeprom->size = qemu_get_byte(f); - qemu_get_byte(f); /* skip padding byte */ + if (version_id == OLD_EEPROM_VERSION) { + eeprom->size = qemu_get_byte(f); + dummy = qemu_get_byte(f); + } else { + eeprom->size = qemu_get_be16(f); + } if (eeprom->size == size) { eeprom->data = qemu_get_be16(f); @@ -317,7 +321,7 @@ eeprom_t *eeprom93xx_new(uint16_t nwords) /* Output DO is tristate, read results in 1. */ eeprom->eedo = 1; logout("eeprom = 0x%p, nwords = %u\n", eeprom, nwords); - register_savevm("eeprom", eeprom_instance, eeprom_version, + register_savevm("eeprom", EEPROM_INSTANCE, EEPROM_VERSION, eeprom_save, eeprom_load, eeprom); return eeprom; } -- 1.5.2.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] support 93xx EEPROMs with more than 255 words 2009-02-22 23:02 ` [Qemu-devel] [PATCH] support 93xx EEPROMs with more than 255 words Andre Przywara @ 2009-03-28 23:14 ` Aurelien Jarno 0 siblings, 0 replies; 4+ messages in thread From: Aurelien Jarno @ 2009-03-28 23:14 UTC (permalink / raw) To: qemu-devel; +Cc: Andre Przywara On Mon, Feb 23, 2009 at 12:02:12AM +0100, Andre Przywara wrote: > In the head of eeprom93xx.c we promise to support chips with 256 words, > but store the size in an unsigned byte. This patch replaces this with an > 16 bit variable and changes the load/store code accordingly (introducing a > new version). > > Signed-off-by: Andre Przywara <andre.przywara@amd.com> Thanks, applied. > --- > hw/eeprom93xx.c | 24 ++++++++++++++---------- > 1 files changed, 14 insertions(+), 10 deletions(-) > > diff --git a/hw/eeprom93xx.c b/hw/eeprom93xx.c > index 527fdf7..e791894 100644 > --- a/hw/eeprom93xx.c > +++ b/hw/eeprom93xx.c > @@ -49,8 +49,9 @@ > #define logout(fmt, args...) ((void)0) > #endif > > -static int eeprom_instance = 0; > -static const int eeprom_version = 20061112; > +#define EEPROM_INSTANCE 0 > +#define OLD_EEPROM_VERSION 20061112 > +#define EEPROM_VERSION (OLD_EEPROM_VERSION + 1) > > #if 0 > typedef enum { > @@ -83,7 +84,7 @@ struct _eeprom_t { > uint8_t eedo; > > uint8_t addrbits; > - uint8_t size; > + uint16_t size; > uint16_t data; > uint16_t contents[0]; > }; > @@ -106,8 +107,7 @@ static void eeprom_save(QEMUFile *f, void *opaque) > qemu_put_byte(f, eeprom->eedo); > > qemu_put_byte(f, eeprom->addrbits); > - qemu_put_byte(f, eeprom->size); > - qemu_put_byte(f, 0); /* padding for compatiblity */ > + qemu_put_be16(f, eeprom->size); > qemu_put_be16(f, eeprom->data); > for (address = 0; address < eeprom->size; address++) { > qemu_put_be16(f, eeprom->contents[address]); > @@ -120,9 +120,9 @@ static int eeprom_load(QEMUFile *f, void *opaque, int version_id) > of data and current EEPROM are identical. */ > eeprom_t *eeprom = (eeprom_t *)opaque; > int result = -EINVAL; > - if (version_id == eeprom_version) { > + if (version_id >= OLD_EEPROM_VERSION) { > unsigned address; > - uint8_t size = eeprom->size; > + int size = eeprom->size; > > eeprom->tick = qemu_get_byte(f); > eeprom->address = qemu_get_byte(f); > @@ -134,8 +134,12 @@ static int eeprom_load(QEMUFile *f, void *opaque, int version_id) > eeprom->eedo = qemu_get_byte(f); > > eeprom->addrbits = qemu_get_byte(f); > - eeprom->size = qemu_get_byte(f); > - qemu_get_byte(f); /* skip padding byte */ > + if (version_id == OLD_EEPROM_VERSION) { > + eeprom->size = qemu_get_byte(f); > + dummy = qemu_get_byte(f); > + } else { > + eeprom->size = qemu_get_be16(f); > + } > > if (eeprom->size == size) { > eeprom->data = qemu_get_be16(f); > @@ -317,7 +321,7 @@ eeprom_t *eeprom93xx_new(uint16_t nwords) > /* Output DO is tristate, read results in 1. */ > eeprom->eedo = 1; > logout("eeprom = 0x%p, nwords = %u\n", eeprom, nwords); > - register_savevm("eeprom", eeprom_instance, eeprom_version, > + register_savevm("eeprom", EEPROM_INSTANCE, EEPROM_VERSION, > eeprom_save, eeprom_load, eeprom); > return eeprom; > } > -- > 1.5.2.2 > > > > > -- Aurelien Jarno GPG: 1024D/F1BCDB73 aurelien@aurel32.net http://www.aurel32.net ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] substitute structure dump with discrete dump in eeprom_save/load 2009-02-22 22:58 [Qemu-devel] [PATCH] substitute structure dump with discrete dump in eeprom_save/load Andre Przywara 2009-02-22 23:02 ` [Qemu-devel] [PATCH] support 93xx EEPROMs with more than 255 words Andre Przywara @ 2009-03-28 23:14 ` Aurelien Jarno 1 sibling, 0 replies; 4+ messages in thread From: Aurelien Jarno @ 2009-03-28 23:14 UTC (permalink / raw) To: qemu-devel; +Cc: Andre Przywara On Sun, Feb 22, 2009 at 11:58:47PM +0100, Andre Przywara wrote: > The EEPROM 93xx device used to dump a C structure to the migration stream. > This structure includes mixed 8 and 16bit variables and is thus subject to > compiler dependent padding. Replace this with discrete dumps of each member > (and add a padding byte to ensure compatibility, a version update is > included in the following patch). > > Signed-off-by: Andre Przywara <andre.przywara@amd.com> Thanks, applied. > --- > hw/eeprom93xx.c | 30 ++++++++++++++++++++++++++++-- > 1 files changed, 28 insertions(+), 2 deletions(-) > > diff --git a/hw/eeprom93xx.c b/hw/eeprom93xx.c > index 896cffd..527fdf7 100644 > --- a/hw/eeprom93xx.c > +++ b/hw/eeprom93xx.c > @@ -95,7 +95,19 @@ static void eeprom_save(QEMUFile *f, void *opaque) > /* Save EEPROM data. */ > unsigned address; > eeprom_t *eeprom = (eeprom_t *)opaque; > - qemu_put_buffer(f, (uint8_t *)eeprom, sizeof(*eeprom) - 2); > + > + qemu_put_byte(f, eeprom->tick); > + qemu_put_byte(f, eeprom->address); > + qemu_put_byte(f, eeprom->command); > + qemu_put_byte(f, eeprom->writeable); > + > + qemu_put_byte(f, eeprom->eecs); > + qemu_put_byte(f, eeprom->eesk); > + qemu_put_byte(f, eeprom->eedo); > + > + qemu_put_byte(f, eeprom->addrbits); > + qemu_put_byte(f, eeprom->size); > + qemu_put_byte(f, 0); /* padding for compatiblity */ > qemu_put_be16(f, eeprom->data); > for (address = 0; address < eeprom->size; address++) { > qemu_put_be16(f, eeprom->contents[address]); > @@ -111,7 +123,20 @@ static int eeprom_load(QEMUFile *f, void *opaque, int version_id) > if (version_id == eeprom_version) { > unsigned address; > uint8_t size = eeprom->size; > - qemu_get_buffer(f, (uint8_t *)eeprom, sizeof(*eeprom) - 2); > + > + eeprom->tick = qemu_get_byte(f); > + eeprom->address = qemu_get_byte(f); > + eeprom->command = qemu_get_byte(f); > + eeprom->writeable = qemu_get_byte(f); > + > + eeprom->eecs = qemu_get_byte(f); > + eeprom->eesk = qemu_get_byte(f); > + eeprom->eedo = qemu_get_byte(f); > + > + eeprom->addrbits = qemu_get_byte(f); > + eeprom->size = qemu_get_byte(f); > + qemu_get_byte(f); /* skip padding byte */ > + > if (eeprom->size == size) { > eeprom->data = qemu_get_be16(f); > for (address = 0; address < eeprom->size; address++) { > -- > 1.5.2.2 > > > > > -- Aurelien Jarno GPG: 1024D/F1BCDB73 aurelien@aurel32.net http://www.aurel32.net ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-03-28 23:14 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-02-22 22:58 [Qemu-devel] [PATCH] substitute structure dump with discrete dump in eeprom_save/load Andre Przywara 2009-02-22 23:02 ` [Qemu-devel] [PATCH] support 93xx EEPROMs with more than 255 words Andre Przywara 2009-03-28 23:14 ` Aurelien Jarno 2009-03-28 23:14 ` [Qemu-devel] [PATCH] substitute structure dump with discrete dump in eeprom_save/load Aurelien Jarno
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).