Revision 86f25c7c hw/ds1225y.c

b/hw/ds1225y.c
33 33
    uint32_t chip_size;
34 34
    QEMUFile *file;
35 35
    uint8_t *contents;
36
    uint8_t protection;
37 36
} ds1225y_t;
38 37

  
39 38

  
......
98 97
    nvram_writeb(opaque, addr + 3, (val >> 24) & 0xff);
99 98
}
100 99

  
101
static void nvram_writeb_protected (void *opaque, target_phys_addr_t addr, uint32_t val)
102
{
103
    ds1225y_t *s = opaque;
104

  
105
    if (s->protection != 7) {
106
#ifdef DEBUG_NVRAM
107
    printf("nvram: prevent write of 0x%x at " TARGET_FMT_lx "\n", val, addr);
108
#endif
109
        return;
110
    }
111

  
112
    nvram_writeb(opaque, addr, val);
113
}
114

  
115
static void nvram_writew_protected (void *opaque, target_phys_addr_t addr, uint32_t val)
116
{
117
    nvram_writeb_protected(opaque, addr, val & 0xff);
118
    nvram_writeb_protected(opaque, addr + 1, (val >> 8) & 0xff);
119
}
120

  
121
static void nvram_writel_protected (void *opaque, target_phys_addr_t addr, uint32_t val)
122
{
123
    nvram_writeb_protected(opaque, addr, val & 0xff);
124
    nvram_writeb_protected(opaque, addr + 1, (val >> 8) & 0xff);
125
    nvram_writeb_protected(opaque, addr + 2, (val >> 16) & 0xff);
126
    nvram_writeb_protected(opaque, addr + 3, (val >> 24) & 0xff);
127
}
128

  
129 100
static CPUReadMemoryFunc * const nvram_read[] = {
130 101
    &nvram_readb,
131 102
    &nvram_readw,
......
138 109
    &nvram_writel,
139 110
};
140 111

  
141
static CPUWriteMemoryFunc * const nvram_write_protected[] = {
142
    &nvram_writeb_protected,
143
    &nvram_writew_protected,
144
    &nvram_writel_protected,
145
};
146

  
147 112
/* Initialisation routine */
148 113
void *ds1225y_init(target_phys_addr_t mem_base, const char *filename)
149 114
{
150 115
    ds1225y_t *s;
151
    int mem_indexRW, mem_indexRP;
116
    int mem_indexRW;
152 117
    QEMUFile *file;
153 118

  
154 119
    s = qemu_mallocz(sizeof(ds1225y_t));
155 120
    s->chip_size = 0x2000; /* Fixed for ds1225y chip: 8 KiB */
156 121
    s->contents = qemu_mallocz(s->chip_size);
157
    s->protection = 7;
158 122

  
159 123
    /* Read current file */
160 124
    file = qemu_fopen(filename, "rb");
......
174 138
    mem_indexRW = cpu_register_io_memory(nvram_read, nvram_write, s,
175 139
                                         DEVICE_NATIVE_ENDIAN);
176 140
    cpu_register_physical_memory(mem_base, s->chip_size, mem_indexRW);
177
    /* Read/write protected memory */
178
    mem_indexRP = cpu_register_io_memory(nvram_read, nvram_write_protected, s,
179
                                         DEVICE_NATIVE_ENDIAN);
180
    cpu_register_physical_memory(mem_base + s->chip_size, s->chip_size, mem_indexRP);
181 141
    return s;
182 142
}

Also available in: Unified diff