-
Notifications
You must be signed in to change notification settings - Fork 1
/
RAM.c
113 lines (77 loc) · 2.31 KB
/
RAM.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "mem.h"
#include "RAM.h"
static Boolean ramAccessF(void* userData, UInt32 pa, UInt8 size, Boolean write, void* bufP){
ArmRam* ram = userData;
UInt8* addr = (UInt8*)ram->buf;
pa -= ram->adr;
if(pa >= ram->sz) return false;
addr += pa;
if(write){
switch(size){
case 1:
*((UInt8*)addr) = *(UInt8*)bufP; //our memory system is little-endian
break;
case 2:
*((UInt16*)addr) = *(UInt16*)bufP; //our memory system is little-endian
break;
case 4:
*((UInt32*)addr) = *(UInt32*)bufP;
break;
case 8:
*((UInt32*)(addr + 0)) = ((UInt32*)bufP)[0];
*((UInt32*)(addr + 4)) = ((UInt32*)bufP)[1];
break;
default:
return false;
}
}
else{
switch(size){
case 1:
*(UInt8*)bufP = *((UInt8*)addr);
break;
case 2:
*(UInt16*)bufP = *((UInt16*)addr);
break;
case 4:
*(UInt32*)bufP = *((UInt32*)addr);
break;
case 64:
((UInt32*)bufP)[ 8] = *((UInt32*)(addr + 32));
((UInt32*)bufP)[ 9] = *((UInt32*)(addr + 36));
((UInt32*)bufP)[10] = *((UInt32*)(addr + 40));
((UInt32*)bufP)[11] = *((UInt32*)(addr + 44));
((UInt32*)bufP)[12] = *((UInt32*)(addr + 48));
((UInt32*)bufP)[13] = *((UInt32*)(addr + 52));
((UInt32*)bufP)[14] = *((UInt32*)(addr + 56));
((UInt32*)bufP)[15] = *((UInt32*)(addr + 60));
//fallthrough
case 32:
((UInt32*)bufP)[4] = *((UInt32*)(addr + 16));
((UInt32*)bufP)[5] = *((UInt32*)(addr + 20));
((UInt32*)bufP)[6] = *((UInt32*)(addr + 24));
((UInt32*)bufP)[7] = *((UInt32*)(addr + 28));
//fallthrough
case 16:
((UInt32*)bufP)[2] = *((UInt32*)(addr + 8));
((UInt32*)bufP)[3] = *((UInt32*)(addr + 12));
//fallthrough
case 8:
((UInt32*)bufP)[0] = *((UInt32*)(addr + 0));
((UInt32*)bufP)[1] = *((UInt32*)(addr + 4));
break;
default:
return false;
}
}
return true;
}
Boolean ramInit(ArmRam* ram, ArmMem* mem, UInt32 adr, UInt32 sz, UInt32* buf){
ram->adr = adr;
ram->sz = sz;
ram->buf = buf;
return memRegionAdd(mem, adr, sz, &ramAccessF, ram);
}
Boolean ramDeinit(ArmRam* ram, ArmMem* mem){
return memRegionDel(mem, ram->adr, ram->sz);
}