[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 | |
---|
[495] | 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 | { |
---|
[495] | 38 | _printf("\n[VMEM ERROR] _v2p_translate() : pte1 unmapped\n" |
---|
| 39 | " vpn = %x / ptab = %x / pte1_vaddr = %x / pte1_value = %x\n", |
---|
| 40 | vpn , (unsigned int)ptab, &(ptab->pt1[ix1]) , pte1 ); |
---|
[408] | 41 | _exit(); |
---|
| 42 | } |
---|
[258] | 43 | |
---|
[408] | 44 | // test big/small page |
---|
| 45 | if ( (pte1 & PTE_T) == 0 ) // big page |
---|
| 46 | { |
---|
| 47 | // set return values |
---|
| 48 | *ppn = ((pte1 << 9) & 0x0FFFFE00) | (vpn & 0X000001FF); |
---|
| 49 | *flags = pte1 & 0xFFC00000; |
---|
| 50 | } |
---|
| 51 | else // small page |
---|
| 52 | { |
---|
[258] | 53 | |
---|
[495] | 54 | // get physical addresses of pte2 |
---|
| 55 | ptba = ((unsigned long long)(pte1 & 0x0FFFFFFF)) << 12; |
---|
[408] | 56 | pte2_paddr = ptba + 8*ix2; |
---|
[495] | 57 | |
---|
| 58 | // split physical address in two 32 bits words |
---|
[408] | 59 | pte2_lsb = (unsigned int) pte2_paddr; |
---|
| 60 | pte2_msb = (unsigned int) (pte2_paddr >> 32); |
---|
[345] | 61 | |
---|
[408] | 62 | // disable interrupts and save status register |
---|
| 63 | _it_disable( &save_sr ); |
---|
| 64 | |
---|
| 65 | // get ppn_value and flags_value, using a physical read |
---|
| 66 | // after temporary DTLB desactivation |
---|
| 67 | asm volatile ( |
---|
[345] | 68 | "mfc2 $2, $1 \n" /* $2 <= MMU_MODE */ |
---|
| 69 | "andi $3, $2, 0xb \n" |
---|
| 70 | "mtc2 $3, $1 \n" /* DTLB off */ |
---|
[258] | 71 | |
---|
[351] | 72 | "move $4, %3 \n" /* $4 <= pte_lsb */ |
---|
[408] | 73 | "mtc2 %2, $24 \n" /* PADDR_EXT <= pte_msb */ |
---|
[351] | 74 | "lw %0, 0($4) \n" /* read flags */ |
---|
| 75 | "lw %1, 4($4) \n" /* read ppn */ |
---|
[258] | 76 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
| 77 | |
---|
[345] | 78 | "mtc2 $2, $1 \n" /* restore MMU_MODE */ |
---|
[258] | 79 | : "=r" (flags_value), "=r" (ppn_value) |
---|
[345] | 80 | : "r" (pte2_msb) , "r" (pte2_lsb) |
---|
[351] | 81 | : "$2", "$3", "$4" ); |
---|
[258] | 82 | |
---|
[408] | 83 | // restore saved status register |
---|
| 84 | _it_restore( &save_sr ); |
---|
[345] | 85 | |
---|
[408] | 86 | // set return values |
---|
| 87 | *ppn = ppn_value & 0x0FFFFFFF; |
---|
| 88 | *flags = flags_value & 0xFFC00000; |
---|
[258] | 89 | |
---|
[408] | 90 | // check PTE2 mapping |
---|
| 91 | if ( (flags_value & PTE_V) == 0 ) |
---|
| 92 | { |
---|
[495] | 93 | _printf("\n[VMEM ERROR] _v2p_translate() : pte2 unmapped\n" |
---|
| 94 | " vpn = %x / ptab = %x / pte1_value = %x\n" |
---|
| 95 | " pte2_paddr = %l / ppn = %x / flags = %x\n", |
---|
| 96 | vpn , ptab , pte1 , pte2_paddr , ppn_value , flags_value ); |
---|
[408] | 97 | _exit(); |
---|
| 98 | } |
---|
| 99 | } |
---|
[258] | 100 | } // end _v2p_translate() |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | // Local Variables: |
---|
| 105 | // tab-width: 4 |
---|
| 106 | // c-basic-offset: 4 |
---|
| 107 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 108 | // indent-tabs-mode: nil |
---|
| 109 | // End: |
---|
| 110 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 111 | |
---|
| 112 | |
---|