Commit 7ab2589cbb91e07f6eadde0b5435602d75a5a72a

Authored by aurel32
1 parent d4ae799c

hw/eeprom93xx.c: support 93xx EEPROMs with more than 255 words

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>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6918 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 14 additions and 10 deletions
hw/eeprom93xx.c
... ... @@ -49,8 +49,9 @@
49 49 #define logout(fmt, args...) ((void)0)
50 50 #endif
51 51  
52   -static int eeprom_instance = 0;
53   -static const int eeprom_version = 20061112;
  52 +#define EEPROM_INSTANCE 0
  53 +#define OLD_EEPROM_VERSION 20061112
  54 +#define EEPROM_VERSION (OLD_EEPROM_VERSION + 1)
54 55  
55 56 #if 0
56 57 typedef enum {
... ... @@ -83,7 +84,7 @@ struct _eeprom_t {
83 84 uint8_t eedo;
84 85  
85 86 uint8_t addrbits;
86   - uint8_t size;
  87 + uint16_t size;
87 88 uint16_t data;
88 89 uint16_t contents[0];
89 90 };
... ... @@ -106,8 +107,7 @@ static void eeprom_save(QEMUFile *f, void *opaque)
106 107 qemu_put_byte(f, eeprom->eedo);
107 108  
108 109 qemu_put_byte(f, eeprom->addrbits);
109   - qemu_put_byte(f, eeprom->size);
110   - qemu_put_byte(f, 0); /* padding for compatiblity */
  110 + qemu_put_be16(f, eeprom->size);
111 111 qemu_put_be16(f, eeprom->data);
112 112 for (address = 0; address < eeprom->size; address++) {
113 113 qemu_put_be16(f, eeprom->contents[address]);
... ... @@ -120,9 +120,9 @@ static int eeprom_load(QEMUFile *f, void *opaque, int version_id)
120 120 of data and current EEPROM are identical. */
121 121 eeprom_t *eeprom = (eeprom_t *)opaque;
122 122 int result = -EINVAL;
123   - if (version_id == eeprom_version) {
  123 + if (version_id >= OLD_EEPROM_VERSION) {
124 124 unsigned address;
125   - uint8_t size = eeprom->size;
  125 + int size = eeprom->size;
126 126  
127 127 eeprom->tick = qemu_get_byte(f);
128 128 eeprom->address = qemu_get_byte(f);
... ... @@ -134,8 +134,12 @@ static int eeprom_load(QEMUFile *f, void *opaque, int version_id)
134 134 eeprom->eedo = qemu_get_byte(f);
135 135  
136 136 eeprom->addrbits = qemu_get_byte(f);
137   - eeprom->size = qemu_get_byte(f);
138   - qemu_get_byte(f); /* skip padding byte */
  137 + if (version_id == OLD_EEPROM_VERSION) {
  138 + eeprom->size = qemu_get_byte(f);
  139 + qemu_get_byte(f);
  140 + } else {
  141 + eeprom->size = qemu_get_be16(f);
  142 + }
139 143  
140 144 if (eeprom->size == size) {
141 145 eeprom->data = qemu_get_be16(f);
... ... @@ -317,7 +321,7 @@ eeprom_t *eeprom93xx_new(uint16_t nwords)
317 321 /* Output DO is tristate, read results in 1. */
318 322 eeprom->eedo = 1;
319 323 logout("eeprom = 0x%p, nwords = %u\n", eeprom, nwords);
320   - register_savevm("eeprom", eeprom_instance, eeprom_version,
  324 + register_savevm("eeprom", EEPROM_INSTANCE, EEPROM_VERSION,
321 325 eeprom_save, eeprom_load, eeprom);
322 326 return eeprom;
323 327 }
... ...