struct _subtable_data { unsigned int usecount; }; typedef struct _subtable_data subtable_data; struct _table_data { unsigned char *table; subtable_data subtable[64]; }; typedef struct _table_data table_data; struct _addrspace_data { table_data read; table_data write; }; typedef struct _addrspace_data addrspace_data; struct _cpu_data { addrspace_data space[3]; }; static struct _cpu_data cpudata[8]; static void install_mem_handler(addrspace_data * space, int iswrite, int databits, int ismatchmask, unsigned int start, unsigned int end, unsigned int mask, unsigned int mirror, void **handler, int isfixed, const char *handler_name); static void reallocate_subtable(table_data * tabledata, unsigned char subentry); static void release_subtable(table_data * tabledata, unsigned char subentry); void *_memory_install_read_handler(int cpunum, int spacenum, unsigned int start, unsigned int end, unsigned int mask, unsigned int mirror, int handler, const char *handler_name) { addrspace_data *space = &cpudata[cpunum].space[spacenum]; install_mem_handler(space, 0, 8, 0, start, end, mask, mirror, (void **)handler, 0, handler_name); } static void install_mem_handler(addrspace_data * space, int iswrite, int databits, int ismatchmask, unsigned int start, unsigned int end, unsigned int mask, unsigned int mirror, void **handler, int isfixed, const char *handler_name) { unsigned int lmirrorbit[18], lmirrorbits, hmirrorbit[(32 - 18)], hmirrorbits, lmirrorcount, hmirrorcount; table_data *tabledata = iswrite ? &space->write : &space->read; unsigned char idx, prev_entry = 0; int cur_index, prev_index = 0; int i; for (i = (32 - 18); hmirrorcount < (1 << hmirrorbits); hmirrorcount++) { unsigned int hmirrorbase = 0; if (cur_index == ((end + hmirrorbase) >> (32 - 18))) { if (hmirrorcount != 0 && prev_entry == tabledata->table[cur_index]) { if (tabledata->table[cur_index] >= (256 - 64)) release_subtable(tabledata, tabledata-> table[cur_index]); if (tabledata->table[prev_index] >= (256 - 64)) reallocate_subtable(tabledata, tabledata-> table[prev_index]); } prev_entry = tabledata->table[cur_index]; } for (lmirrorcount = 0; lmirrorcount < (1 << lmirrorbits); lmirrorcount++) { } } } static void reallocate_subtable(table_data * tabledata, unsigned char subentry) { unsigned char subindex = subentry - (256 - 64); if (tabledata->subtable[subindex].usecount <= 0) osd_die(); } static void release_subtable(table_data * tabledata, unsigned char subentry) { unsigned char subindex = subentry - (256 - 64); if (tabledata->subtable[subindex].usecount <= 0) osd_die(); }