/* * Milkymist SoC (Software) * Copyright (C) 2012 Yann Sionneau * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #ifdef __ASSEMBLER__ #define MMPTR(x) x #else #define MMPTR(x) (*((volatile unsigned int *)(x))) #endif #define CSR_UART_RXTX MMPTR(0xe0000000) void f(void) { char c = '@'; CSR_UART_RXTX = c; // asm volatile("bi f" ::: ); // We intinitely loop to f() asm volatile("xor r0, r0, r0\n\t" "xor r0, r0, r0" ::: ); } void itlbtest(void) { register unsigned int stack, f_addr; unsigned int *p; unsigned int *pdest; unsigned int addr; asm volatile("mv %0, sp" : "=r"(stack) :: ); printf("stack == 0x%08X\n", stack); printf("f() is located at 0x%p\n", f); f_addr = 0x44004000; printf("Mapping f() into virtual memory at 0x%08X [physical == 0x%08X]\n", f_addr, f_addr+0x1000); // for (addr = 0x00860000 ; addr <= 0x00874000 ; addr += 0x1000) // mmu_map(addr, addr, DTLB_MAPPING | MAPPING_CAN_READ); mmu_map(stack, stack, DTLB_MAPPING | MAPPING_CAN_READ | MAPPING_CAN_WRITE); mmu_map(f_addr, f_addr + 0x1000, ITLB_MAPPING | MAPPING_CAN_READ); mmu_map(itlbtest, itlbtest, ITLB_MAPPING | MAPPING_CAN_READ); mmu_map(call_function_with_itlb_enabled, call_function_with_itlb_enabled, ITLB_MAPPING | MAPPING_CAN_READ); puts("Mapping DONE"); // mmu_itlb_invalidate_line(f_addr); // We copy f's code to 0x44005000 for (p = f, pdest = 0x44005000 ; p < f + 0x1000 ; p++, pdest++) *pdest = *p; puts("Copy DONE"); asm volatile("wcsr DCC, r0\n\t" "xor r0, r0, r0\n\t" "xor r0, r0, r0\n\t" "xor r0, r0, r0\n\t" "xor r0, r0, r0"); asm volatile("wcsr ICC, r0\n\t" "xor r0, r0, r0"); puts("Instruction and Data caches have been invalidated"); call_function_with_itlb_enabled(f_addr); disable_dtlb(); disable_itlb(); puts("Call DONE"); }