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