Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

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