[258] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : vmem.c |
---|
| 3 | // Date : 01/07/2012 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | |
---|
[455] | 8 | #include <tty0.h> |
---|
[258] | 9 | #include <utils.h> |
---|
| 10 | #include <vmem.h> |
---|
| 11 | #include <giet_config.h> |
---|
| 12 | |
---|
[408] | 13 | ////////////////////////////////////////////////// |
---|
[476] | 14 | void _v2p_translate( page_table_t* ptab, |
---|
| 15 | unsigned int vpn, |
---|
| 16 | unsigned int* ppn, |
---|
| 17 | unsigned int* flags ) |
---|
[258] | 18 | { |
---|
| 19 | unsigned long long ptba; |
---|
| 20 | unsigned long long pte2_paddr; |
---|
| 21 | |
---|
[351] | 22 | unsigned int pte2_msb; |
---|
| 23 | unsigned int pte2_lsb; |
---|
[345] | 24 | unsigned int flags_value; |
---|
| 25 | unsigned int ppn_value; |
---|
[258] | 26 | |
---|
| 27 | unsigned int ix1 = vpn >> 9; |
---|
| 28 | unsigned int ix2 = vpn & 0x1FF; |
---|
| 29 | |
---|
[345] | 30 | unsigned int save_sr; |
---|
| 31 | |
---|
[258] | 32 | // get PTE1 |
---|
[408] | 33 | unsigned int pte1 = ptab->pt1[ix1]; |
---|
[258] | 34 | |
---|
| 35 | // check PTE1 mapping |
---|
[408] | 36 | if ( (pte1 & PTE_V) == 0 ) |
---|
| 37 | { |
---|
[442] | 38 | _puts("\n[VMEM ERROR] _v2p_translate() : pte1 unmapped\n"); |
---|
[408] | 39 | _exit(); |
---|
| 40 | } |
---|
[258] | 41 | |
---|
[408] | 42 | // test big/small page |
---|
| 43 | if ( (pte1 & PTE_T) == 0 ) // big page |
---|
| 44 | { |
---|
| 45 | // set return values |
---|
| 46 | *ppn = ((pte1 << 9) & 0x0FFFFE00) | (vpn & 0X000001FF); |
---|
| 47 | *flags = pte1 & 0xFFC00000; |
---|
| 48 | } |
---|
| 49 | else // small page |
---|
| 50 | { |
---|
[258] | 51 | |
---|
[408] | 52 | // get physical addresses of pte2 (two 32 bits words) |
---|
| 53 | ptba = (unsigned long long) (pte1 & 0x0FFFFFFF) << 12; |
---|
| 54 | pte2_paddr = ptba + 8*ix2; |
---|
| 55 | pte2_lsb = (unsigned int) pte2_paddr; |
---|
| 56 | pte2_msb = (unsigned int) (pte2_paddr >> 32); |
---|
[345] | 57 | |
---|
[408] | 58 | // disable interrupts and save status register |
---|
| 59 | _it_disable( &save_sr ); |
---|
| 60 | |
---|
| 61 | // get ppn_value and flags_value, using a physical read |
---|
| 62 | // after temporary DTLB desactivation |
---|
| 63 | asm volatile ( |
---|
[345] | 64 | "mfc2 $2, $1 \n" /* $2 <= MMU_MODE */ |
---|
| 65 | "andi $3, $2, 0xb \n" |
---|
| 66 | "mtc2 $3, $1 \n" /* DTLB off */ |
---|
[258] | 67 | |
---|
[351] | 68 | "move $4, %3 \n" /* $4 <= pte_lsb */ |
---|
[408] | 69 | "mtc2 %2, $24 \n" /* PADDR_EXT <= pte_msb */ |
---|
[351] | 70 | "lw %0, 0($4) \n" /* read flags */ |
---|
| 71 | "lw %1, 4($4) \n" /* read ppn */ |
---|
[258] | 72 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
| 73 | |
---|
[345] | 74 | "mtc2 $2, $1 \n" /* restore MMU_MODE */ |
---|
[258] | 75 | : "=r" (flags_value), "=r" (ppn_value) |
---|
[345] | 76 | : "r" (pte2_msb) , "r" (pte2_lsb) |
---|
[351] | 77 | : "$2", "$3", "$4" ); |
---|
[258] | 78 | |
---|
[408] | 79 | // restore saved status register |
---|
| 80 | _it_restore( &save_sr ); |
---|
[345] | 81 | |
---|
[408] | 82 | // set return values |
---|
| 83 | *ppn = ppn_value & 0x0FFFFFFF; |
---|
| 84 | *flags = flags_value & 0xFFC00000; |
---|
[258] | 85 | |
---|
[408] | 86 | // check PTE2 mapping |
---|
| 87 | if ( (flags_value & PTE_V) == 0 ) |
---|
| 88 | { |
---|
[442] | 89 | _puts("\n[VMEM ERROR] _v2p_translate() : pte2 unmapped\n"); |
---|
[408] | 90 | _exit(); |
---|
| 91 | } |
---|
| 92 | } |
---|
[258] | 93 | } // end _v2p_translate() |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | // Local Variables: |
---|
| 98 | // tab-width: 4 |
---|
| 99 | // c-basic-offset: 4 |
---|
| 100 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 101 | // indent-tabs-mode: nil |
---|
| 102 | // End: |
---|
| 103 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 104 | |
---|
| 105 | |
---|