View difference between Paste ID: YbzcP8AQ and eUB1GkaB
SHOW: | | - or go back to the newest paste.
1
/*
2
 * Milkymist SoC (Software)
3
 * Copyright (C) 2012 Yann Sionneau <yann.sionneau@gmail.com>
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, version 3 of the License.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
#include <hal/mmu.h>
19
#include <base/mmu.h>
20
#include <base/stdio.h>
21
22
#ifdef __ASSEMBLER__
23
#define MMPTR(x) x
24
#else
25
#define MMPTR(x) (*((volatile unsigned int *)(x)))
26
#endif
27
#define CSR_UART_RXTX 		MMPTR(0xe0000000)
28
29
void f(void) {
30
	char c = '@';
31
	CSR_UART_RXTX = c;
32
//	asm volatile("bi f" ::: ); // We intinitely loop to f()
33
	asm volatile("xor r0, r0, r0\n\t"
34
		     "xor r0, r0, r0" ::: );
35
}
36
37
void itlbtest(void) {
38
	register unsigned int stack, f_addr;
39
	unsigned int *p;
40
	unsigned int *pdest;
41
	unsigned int addr;
42
43
	asm volatile("mv %0, sp" : "=r"(stack) :: );
44
	printf("stack == 0x%08X\n", stack);
45
46
	printf("f() is located at 0x%p\n", f);
47
48
	f_addr = 0x44004000;
49
	printf("Mapping f() into virtual memory at 0x%08X [physical == 0x%08X]\n", f_addr, f_addr+0x1000);
50
51
//	for (addr = 0x00860000 ; addr <= 0x00874000 ; addr += 0x1000)
52
//		mmu_map(addr, addr, DTLB_MAPPING | MAPPING_CAN_READ);
53
54
	mmu_map(stack, stack, DTLB_MAPPING | MAPPING_CAN_READ | MAPPING_CAN_WRITE);
55
	mmu_map(f_addr, f_addr + 0x1000, ITLB_MAPPING | MAPPING_CAN_READ);
56
	mmu_map(itlbtest, itlbtest, ITLB_MAPPING | MAPPING_CAN_READ);
57
	mmu_map(call_function_with_itlb_enabled, call_function_with_itlb_enabled, ITLB_MAPPING | MAPPING_CAN_READ);
58
	puts("Mapping DONE");
59
60
//	mmu_itlb_invalidate_line(f_addr);
61
62
	// We copy f's code to 0x44005000
63
	for (p = f, pdest = 0x44005000 ; p < f + 0x1000 ; p++, pdest++)
64
		*pdest = *p;
65
	puts("Copy DONE");
66
67
	asm volatile("wcsr DCC, r0\n\t"
68
		     "xor r0, r0, r0\n\t"
69
		     "xor r0, r0, r0\n\t"
70
		     "xor r0, r0, r0\n\t"
71
		     "xor r0, r0, r0");
72
	asm volatile("wcsr ICC, r0\n\t"
73
		     "xor r0, r0, r0");
74
	puts("Instruction and Data caches have been invalidated");
75
76
	call_function_with_itlb_enabled(f_addr);
77
	disable_dtlb();
78
	disable_itlb();
79
	puts("Call DONE");
80-
}
80+
81
82
00865a44 <f>:
83
  865a44:	34 02 00 40 	mvi r2,64
84
  865a48:	78 01 e0 00 	mvhi r1,0xe000
85
  865a4c:	58 22 00 00 	sw (r1+0),r2
86
  865a50:	98 00 00 00 	xor r0,r0,r0
87
  865a54:	98 00 00 00 	xor r0,r0,r0
88
  865a58:	c3 a0 00 00 	ret