]> git.wh0rd.org - ICEs.git/blob - bfin-asm-math/memory.i.2
add bfin ice
[ICEs.git] / bfin-asm-math / memory.i.2
1 typedef unsigned char UINT8;
2 typedef unsigned int UINT32;
3 typedef void genf(void);
4 typedef UINT32 offs_t;
5 struct _subtable_data {
6 UINT32 usecount;
7 };
8 typedef struct _subtable_data subtable_data;
9 struct _table_data {
10 UINT8 *table;
11 subtable_data subtable[64];
12 };
13 typedef struct _table_data table_data;
14 struct _addrspace_data {
15 table_data read;
16 table_data write;
17 };
18 typedef struct _addrspace_data addrspace_data;
19 struct _cpu_data {
20 addrspace_data space[3];
21 };
22 typedef struct _cpu_data cpu_data;
23 static cpu_data cpudata[8];
24 static void install_mem_handler(addrspace_data * space, int iswrite,
25 int databits, int ismatchmask, offs_t start,
26 offs_t end, offs_t mask, offs_t mirror,
27 genf * handler, int isfixed,
28 const char *handler_name);
29 static void reallocate_subtable(table_data * tabledata, UINT8 subentry);
30 static void release_subtable(table_data * tabledata, UINT8 subentry);
31 void *_memory_install_read_handler(int cpunum, int spacenum, offs_t start,
32 offs_t end, offs_t mask, offs_t mirror,
33 int handler, const char *handler_name)
34 {
35 addrspace_data *space = &cpudata[cpunum].space[spacenum];
36 install_mem_handler(space, 0, 8, 0, start, end, mask, mirror,
37 (genf *) handler, 0, handler_name);
38 }
39 static void install_mem_handler(addrspace_data * space, int iswrite,
40 int databits, int ismatchmask, offs_t start,
41 offs_t end, offs_t mask, offs_t mirror,
42 genf * handler, int isfixed,
43 const char *handler_name)
44 {
45 offs_t lmirrorbit[18], lmirrorbits, hmirrorbit[(32 - 18)], hmirrorbits,
46 lmirrorcount, hmirrorcount;
47 table_data *tabledata = iswrite ? &space->write : &space->read;
48 UINT8 idx, prev_entry = 0;
49 int cur_index, prev_index = 0;
50 int i;
51 for (i = (32 - 18); hmirrorcount < (1 << hmirrorbits); hmirrorcount++) {
52 offs_t hmirrorbase = 0;
53 if (cur_index == ((end + hmirrorbase) >> (32 - 18))) {
54 if (hmirrorcount != 0
55 && prev_entry == tabledata->table[cur_index]) {
56 if (tabledata->table[cur_index] >= (256 - 64))
57 release_subtable(tabledata,
58 tabledata->
59 table[cur_index]);
60 if (tabledata->table[prev_index] >= (256 - 64))
61 reallocate_subtable(tabledata,
62 tabledata->
63 table[prev_index]);
64 }
65 prev_entry = tabledata->table[cur_index];
66 }
67 for (lmirrorcount = 0;
68 lmirrorcount < (1 << lmirrorbits); lmirrorcount++) {
69 offs_t lmirrorbase = hmirrorbase;
70 for (i = 0; i < lmirrorbits; i++)
71 if (lmirrorcount & (1 << i))
72 lmirrorbase |= lmirrorbit[i];
73 }
74 }
75 }
76 static void reallocate_subtable(table_data * tabledata, UINT8 subentry)
77 {
78 UINT8 subindex = subentry - (256 - 64);
79 if (tabledata->subtable[subindex].usecount <= 0)
80 osd_die
81 ("Called reallocate_subtable on a table with a usecount of 0\n");
82 }
83 static void release_subtable(table_data * tabledata, UINT8 subentry)
84 {
85 UINT8 subindex = subentry - (256 - 64);
86 if (tabledata->subtable[subindex].usecount <= 0)
87 osd_die
88 ("Called release_subtable on a table with a usecount of 0\n");
89 }