summaryrefslogtreecommitdiffstats
path: root/src/core/arm/interpreter/mmu/rb.cpp
blob: 600c9d8c8bda674f6a34c4866b10cdee4114a7b8 (plain) (blame)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "core/arm/skyeye_common/armdefs.h"

/*chy 2004-06-06, fix bug found by wenye@cs.ucsb.edu*/
ARMword rb_masks[] = {
	0x0,			//RB_INVALID
	4,			//RB_1
	16,			//RB_4
	32,			//RB_8
};

/*mmu_rb_init
 * @rb_t	:rb_t to init
 * @num		:number of entry
 * */
int
mmu_rb_init (rb_s * rb_t, int num)
{
	int i;
	rb_entry_t *entrys;

	entrys = (rb_entry_t *) malloc (sizeof (*entrys) * num);
	if (entrys == NULL) {
		printf ("SKYEYE:mmu_rb_init malloc error\n");
		return -1;
	}
	for (i = 0; i < num; i++) {
		entrys[i].type = RB_INVALID;
		entrys[i].fault = NO_FAULT;
	}

	rb_t->entrys = entrys;
	rb_t->num = num;
	return 0;
}

/*mmu_rb_exit*/
void
mmu_rb_exit (rb_s * rb_t)
{
	free (rb_t->entrys);
};

/*mmu_rb_search
 * @rb_t	:rb_t to serach
 * @va		:va address to math
 *
 * $	NULL :not match
 * 		NO-NULL:
 * */
rb_entry_t *
mmu_rb_search (rb_s * rb_t, ARMword va)
{
	int i;
	rb_entry_t *rb = rb_t->entrys;

	DEBUG_LOG(ARM11, "va = %x\n", va);
	for (i = 0; i < rb_t->num; i++, rb++) {
		//2004-06-06 lyh  bug from wenye@cs.ucsb.edu
		if (rb->type) {
			if ((va >= rb->va)
			    && (va < (rb->va + rb_masks[rb->type])))
				return rb;
		}
	}
	return NULL;
};

void
mmu_rb_invalidate_entry (rb_s * rb_t, int i)
{
	rb_t->entrys[i].type = RB_INVALID;
}

void
mmu_rb_invalidate_all (rb_s * rb_t)
{
	int i;

	for (i = 0; i < rb_t->num; i++)
		mmu_rb_invalidate_entry (rb_t, i);
};

void
mmu_rb_load (ARMul_State * state, rb_s * rb_t, int i_rb, int type, ARMword va)
{
	rb_entry_t *rb;
	int i;
	ARMword max_start, min_end;
	fault_t fault;
	tlb_entry_t *tlb;

	/*align va according to type */
	va &= ~(rb_masks[type] - 1);
	/*invalidate all RB match [va, va + rb_masks[type]] */
	for (rb = rb_t->entrys, i = 0; i < rb_t->num; i++, rb++) {
		if (rb->type) {
			max_start = max (va, rb->va);
			min_end =
				min (va + rb_masks[type],
				     rb->va + rb_masks[rb->type]);
			if (max_start < min_end)
				rb->type = RB_INVALID;
		}
	}
	/*load word */
	rb = &rb_t->entrys[i_rb];
	rb->type = type;
	fault = translate (state, va, D_TLB (), &tlb);
	if (fault) {
		rb->fault = fault;
		return;
	}
	fault = check_access (state, va, tlb, 1);
	if (fault) {
		rb->fault = fault;
		return;
	}

	rb->fault = NO_FAULT;
	va = tlb_va_to_pa (tlb, va);
	//2004-06-06 lyh  bug from wenye@cs.ucsb.edu
	for (i = 0; i < (rb_masks[type] / 4); i++, va += WORD_SIZE) {
		//rb->data[i] = mem_read_word (state, va);
		bus_read(32, va, &rb->data[i]);
	};
}