target-ppc: fix PowerMAC NVRAM emulation

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6132 c046a42c-6fe2-441c-8c8c-71466251a162
diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index 773f2d8..6bf666f 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -40,7 +40,7 @@
 struct MacIONVRAMState {
     target_phys_addr_t size;
     int mem_index;
-    uint8_t data[0x2000];
+    uint8_t *data;
 };
 
 /* Direct access to NVRAM */
@@ -49,7 +49,7 @@
     MacIONVRAMState *s = opaque;
     uint32_t ret;
 
-    if (addr < 0x2000)
+    if (addr < s->size)
         ret = s->data[addr];
     else
         ret = -1;
@@ -63,7 +63,7 @@
     MacIONVRAMState *s = opaque;
 
     NVR_DPRINTF("write addr %04x val %x\n", addr, val);
-    if (addr < 0x2000)
+    if (addr < s->size)
         s->data[addr] = val;
 }
 
@@ -73,7 +73,7 @@
 {
     MacIONVRAMState *s = opaque;
 
-    addr = (addr >> 4) & 0x1fff;
+    addr = (addr >> 4) & (s->size - 1);
     s->data[addr] = value;
     NVR_DPRINTF("writeb addr %04x val %x\n", (int)addr, value);
 }
@@ -83,7 +83,7 @@
     MacIONVRAMState *s = opaque;
     uint32_t value;
 
-    addr = (addr >> 4) & 0x1fff;
+    addr = (addr >> 4) & (s->size - 1);
     value = s->data[addr];
     NVR_DPRINTF("readb addr %04x val %x\n", (int)addr, value);
 
@@ -109,7 +109,13 @@
     s = qemu_mallocz(sizeof(MacIONVRAMState));
     if (!s)
         return NULL;
+    s->data = qemu_mallocz(size);
+    if (!s->data) {
+        qemu_free(s);
+	return NULL;
+    }
     s->size = size;
+
     s->mem_index = cpu_register_io_memory(0, nvram_read, nvram_write, s);
     *mem_index = s->mem_index;
 
@@ -121,7 +127,7 @@
     MacIONVRAMState *s;
 
     s = opaque;
-    cpu_register_physical_memory(mem_base, s->size, s->mem_index);
+    cpu_register_physical_memory(mem_base, s->size << 4, s->mem_index);
 }
 
 /* Set up a system OpenBIOS NVRAM partition */