initial import
[ICEs.git] / bfin-asm-math / memory.i.3
1 struct _subtable_data {
2 unsigned int usecount;
3 };
4 typedef struct _subtable_data subtable_data;
5 struct _table_data {
6 unsigned char *table;
7 subtable_data subtable[64];
8 };
9 typedef struct _table_data table_data;
10 struct _addrspace_data {
11 table_data read;
12 table_data write;
13 };
14 typedef struct _addrspace_data addrspace_data;
15 struct _cpu_data {
16 addrspace_data space[3];
17 };
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)
31 {
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);
35 }
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)
42 {
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;
48 int i;
49 for (i = (32 - 18); hmirrorcount < (1 << hmirrorbits); hmirrorcount++) {
50 unsigned int hmirrorbase = 0;
51 if (cur_index == ((end + hmirrorbase) >> (32 - 18))) {
52 if (hmirrorcount != 0
53 && prev_entry == tabledata->table[cur_index]) {
54 if (tabledata->table[cur_index] >= (256 - 64))
55 release_subtable(tabledata,
56 tabledata->
57 table[cur_index]);
58 if (tabledata->table[prev_index] >= (256 - 64))
59 reallocate_subtable(tabledata,
60 tabledata->
61 table[prev_index]);
62 }
63 prev_entry = tabledata->table[cur_index];
64 }
65 for (lmirrorcount = 0;
66 lmirrorcount < (1 << lmirrorbits); lmirrorcount++) {
67 }
68 }
69 }
70 static void reallocate_subtable(table_data * tabledata, unsigned char subentry)
71 {
72 unsigned char subindex = subentry - (256 - 64);
73 if (tabledata->subtable[subindex].usecount <= 0)
74 osd_die();
75 }
76 static void release_subtable(table_data * tabledata, unsigned char subentry)
77 {
78 unsigned char subindex = subentry - (256 - 64);
79 if (tabledata->subtable[subindex].usecount <= 0)
80 osd_die();
81 }