1 struct _subtable_data {
4 typedef struct _subtable_data subtable_data;
7 subtable_data subtable[64];
9 typedef struct _table_data table_data;
10 struct _addrspace_data {
14 typedef struct _addrspace_data addrspace_data;
16 addrspace_data space[3];
18 static struct _cpu_data cpudata[8];
19 static void install_mem_handler(addrspace_data * space, int iswrite,
20 int databits, int ismatchmask,
21 unsigned int start, unsigned int end,
22 unsigned int mask, unsigned int mirror,
23 void **handler, int isfixed,
24 const char *handler_name);
25 static void reallocate_subtable(table_data * tabledata, unsigned char subentry);
26 static void release_subtable(table_data * tabledata, unsigned char subentry);
27 void *_memory_install_read_handler(int cpunum, int spacenum, unsigned int start,
28 unsigned int end, unsigned int mask,
29 unsigned int mirror, int handler,
30 const char *handler_name)
32 addrspace_data *space = &cpudata[cpunum].space[spacenum];
33 install_mem_handler(space, 0, 8, 0, start, end, mask, mirror,
34 (void **)handler, 0, handler_name);
36 static void install_mem_handler(addrspace_data * space, int iswrite,
37 int databits, int ismatchmask,
38 unsigned int start, unsigned int end,
39 unsigned int mask, unsigned int mirror,
40 void **handler, int isfixed,
41 const char *handler_name)
43 unsigned int lmirrorbit[18], lmirrorbits, hmirrorbit[(32 - 18)],
44 hmirrorbits, lmirrorcount, hmirrorcount;
45 table_data *tabledata = iswrite ? &space->write : &space->read;
46 unsigned char idx, prev_entry = 0;
47 int cur_index, prev_index = 0;
49 for (i = (32 - 18); hmirrorcount < (1 << hmirrorbits); hmirrorcount++) {
50 unsigned int hmirrorbase = 0;
51 if (cur_index == ((end + hmirrorbase) >> (32 - 18))) {
53 && prev_entry == tabledata->table[cur_index]) {
54 if (tabledata->table[cur_index] >= (256 - 64))
55 release_subtable(tabledata,
58 if (tabledata->table[prev_index] >= (256 - 64))
59 reallocate_subtable(tabledata,
63 prev_entry = tabledata->table[cur_index];
65 for (lmirrorcount = 0;
66 lmirrorcount < (1 << lmirrorbits); lmirrorcount++) {
70 static void reallocate_subtable(table_data * tabledata, unsigned char subentry)
72 unsigned char subindex = subentry - (256 - 64);
73 if (tabledata->subtable[subindex].usecount <= 0)
76 static void release_subtable(table_data * tabledata, unsigned char subentry)
78 unsigned char subindex = subentry - (256 - 64);
79 if (tabledata->subtable[subindex].usecount <= 0)