void itlb_miss_handler(void)
{
unsigned int vaddr, paddr;
// unsigned int vaddr;
unsigned int EA;
unsigned int PSW;
asm volatile("mv %0, ea": "=r"(EA) :: );
asm volatile("rcsr %0, itlbma" : "=r"(vaddr) :: );
// If the following line is commented, then EA == itlb_miss_handler and upon eret we are doomed. If it is un-commented, then EA has a correct value and everything goes fine !
// asm volatile("rcsr %0, PSW" : "=r"(PSW) :: );
printf("ea == 0x%08X\n", EA);
// printf("Address 0x%08X caused an ITLB page fault\n", vaddr);
// printf("PSW == 0x%08X\n", PSW);
// asm volatile("mv EA, %0" :: "r"(vaddr) : );
paddr = get_mmu_mapping_for(vaddr);
if (paddr == A_BAD_ADDR)
{
puts("No such mapping !");
puts("Unrecoverable ITLB page fault !");
panic();
}
if (!is_itlb_mapping(vaddr))
{
puts("Mapping not in ITLB");
panic();
}
// printf("Refilling ITLB with mapping 0x%08X->0x%08X\n", vaddr, paddr);
mmu_itlb_map(vaddr, paddr);
}
With "asm volatile("rcsr %0, PSW" : "=r"(PSW) :: );" un-commented:
yann@debian:~/dev/milkymist-mmu/tools$ ./flterm --port /dev/ttyUSB0
[FLTERM] Starting...
BIOS> itlbtest
stack == 0x47FFFEE8
f() is located at 0x00865a80
Mapping f() into virtual memory at 0x44004000 [physical == 0x44005000]
mapping 0x00860000->0x00860000 in slot 29 [0x446617d8]
mapping 0x00861000->0x00861000 in slot 28 [0x446617cc]
mapping 0x00862000->0x00862000 in slot 27 [0x446617c0]
mapping 0x00863000->0x00863000 in slot 26 [0x446617b4]
mapping 0x00864000->0x00864000 in slot 25 [0x446617a8]
mapping 0x00865000->0x00865000 in slot 24 [0x4466179c]
mapping 0x00866000->0x00866000 in slot 23 [0x44661790]
mapping 0x00867000->0x00867000 in slot 22 [0x44661784]
mapping 0x00868000->0x00868000 in slot 21 [0x44661778]
mapping 0x00869000->0x00869000 in slot 20 [0x4466176c]
mapping 0x0086A000->0x0086A000 in slot 19 [0x44661760]
mapping 0x0086B000->0x0086B000 in slot 18 [0x44661754]
mapping 0x0086C000->0x0086C000 in slot 17 [0x44661748]
mapping 0x0086D000->0x0086D000 in slot 16 [0x4466173c]
mapping 0x0086E000->0x0086E000 in slot 15 [0x44661730]
mapping 0x0086F000->0x0086F000 in slot 14 [0x44661724]
mapping 0x00870000->0x00870000 in slot 13 [0x44661718]
mapping 0x00871000->0x00871000 in slot 12 [0x4466170c]
mapping 0x00872000->0x00872000 in slot 11 [0x44661700]
mapping 0x00873000->0x00873000 in slot 10 [0x446616f4]
mapping 0x00874000->0x00874000 in slot 9 [0x446616e8]
mapping 0x47FFF000->0x47FFF000 in slot 8 [0x446616dc]
Already mapped, updating metadata !
Mapping DONE
Printing MMU mappings :
[8] 0x47FFF000 -> 0x47FFF000: DTLB
[9] 0x00874000 -> 0x00874000: ITLB DTLB
[10] 0x00873000 -> 0x00873000: ITLB DTLB
[11] 0x00872000 -> 0x00872000: ITLB DTLB
[12] 0x00871000 -> 0x00871000: ITLB DTLB
[13] 0x00870000 -> 0x00870000: ITLB DTLB
[14] 0x0086F000 -> 0x0086F000: ITLB DTLB
[15] 0x0086E000 -> 0x0086E000: ITLB DTLB
[16] 0x0086D000 -> 0x0086D000: ITLB DTLB
[17] 0x0086C000 -> 0x0086C000: ITLB DTLB
[18] 0x0086B000 -> 0x0086B000: ITLB DTLB
[19] 0x0086A000 -> 0x0086A000: ITLB DTLB
[20] 0x00869000 -> 0x00869000: ITLB DTLB
[21] 0x00868000 -> 0x00868000: ITLB DTLB
[22] 0x00867000 -> 0x00867000: ITLB DTLB
[23] 0x00866000 -> 0x00866000: ITLB DTLB
[24] 0x00865000 -> 0x00865000: ITLB DTLB
[25] 0x00864000 -> 0x00864000: ITLB DTLB
[26] 0x00863000 -> 0x00863000: ITLB DTLB
[27] 0x00862000 -> 0x00862000: ITLB DTLB
[28] 0x00861000 -> 0x00861000: ITLB DTLB
[29] 0x00860000 -> 0x00860000: ITLB DTLB
Instruction and Data caches have been invalidated
ea == 0x00865A80
@ea == 0x00866FE8
ea == 0x00866FF8
ea == 0x0086830C
totolol
test 5 � abcd
Call DONE
BIOS>
It works nicely.
With "asm volatile("rcsr %0, PSW" : "=r"(PSW) :: );" commented:
BIOS> itlbtest
stack == 0x47FFFEE8
f() is located at 0x00865a7c
Mapping f() into virtual memory at 0x44004000 [physical == 0x44005000]
mapping 0x00860000->0x00860000 in slot 29 [0x446617d8]
mapping 0x00861000->0x00861000 in slot 28 [0x446617cc]
mapping 0x00862000->0x00862000 in slot 27 [0x446617c0]
mapping 0x00863000->0x00863000 in slot 26 [0x446617b4]
mapping 0x00864000->0x00864000 in slot 25 [0x446617a8]
mapping 0x00865000->0x00865000 in slot 24 [0x4466179c]
mapping 0x00866000->0x00866000 in slot 23 [0x44661790]
mapping 0x00867000->0x00867000 in slot 22 [0x44661784]
mapping 0x00868000->0x00868000 in slot 21 [0x44661778]
mapping 0x00869000->0x00869000 in slot 20 [0x4466176c]
mapping 0x0086A000->0x0086A000 in slot 19 [0x44661760]
mapping 0x0086B000->0x0086B000 in slot 18 [0x44661754]
mapping 0x0086C000->0x0086C000 in slot 17 [0x44661748]
mapping 0x0086D000->0x0086D000 in slot 16 [0x4466173c]
mapping 0x0086E000->0x0086E000 in slot 15 [0x44661730]
mapping 0x0086F000->0x0086F000 in slot 14 [0x44661724]
mapping 0x00870000->0x00870000 in slot 13 [0x44661718]
mapping 0x00871000->0x00871000 in slot 12 [0x4466170c]
mapping 0x00872000->0x00872000 in slot 11 [0x44661700]
mapping 0x00873000->0x00873000 in slot 10 [0x446616f4]
mapping 0x00874000->0x00874000 in slot 9 [0x446616e8]
mapping 0x47FFF000->0x47FFF000 in slot 8 [0x446616dc]
Already mapped, updating metadata !
Mapping DONE
Printing MMU mappings :
[8] 0x47FFF000 -> 0x47FFF000: DTLB
[9] 0x00874000 -> 0x00874000: ITLB DTLB
[10] 0x00873000 -> 0x00873000: ITLB DTLB
[11] 0x00872000 -> 0x00872000: ITLB DTLB
[12] 0x00871000 -> 0x00871000: ITLB DTLB
[13] 0x00870000 -> 0x00870000: ITLB DTLB
[14] 0x0086F000 -> 0x0086F000: ITLB DTLB
[15] 0x0086E000 -> 0x0086E000: ITLB DTLB
[16] 0x0086D000 -> 0x0086D000: ITLB DTLB
[17] 0x0086C000 -> 0x0086C000: ITLB DTLB
[18] 0x0086B000 -> 0x0086B000: ITLB DTLB
[19] 0x0086A000 -> 0x0086A000: ITLB DTLB
[20] 0x00869000 -> 0x00869000: ITLB DTLB
[21] 0x00868000 -> 0x00868000: ITLB DTLB
[22] 0x00867000 -> 0x00867000: ITLB DTLB
[23] 0x00866000 -> 0x00866000: ITLB DTLB
[24] 0x00865000 -> 0x00865000: ITLB DTLB
[25] 0x00864000 -> 0x00864000: ITLB DTLB
[26] 0x00863000 -> 0x00863000: ITLB DTLB
[27] 0x00862000 -> 0x00862000: ITLB DTLB
[28] 0x00861000 -> 0x00861000: ITLB DTLB
[29] 0x00860000 -> 0x00860000: ITLB DTLB
Instruction and Data caches have been invalidated
ea == 0x00865A7C
@ea == 0x00866FE4
ea == 0x00860120
ea == 0x00860120
ea == 0x00860120
ea == 0x00860120
ea == 0x00860120
ea == 0x00860120
ea == 0x00860120
ea == 0x00860120
ea == 0x00860120
ea == 0x00860120
ea == 0x00860120
ea == 0x00860120