1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : vmem.c |
---|
3 | // Date : 01/07/2012 |
---|
4 | // Author : alain greiner |
---|
5 | // Copyright (c) UPMC-LIP6 |
---|
6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
7 | |
---|
8 | #include <tty0.h> |
---|
9 | #include <utils.h> |
---|
10 | #include <vmem.h> |
---|
11 | #include <giet_config.h> |
---|
12 | |
---|
13 | ////////////////////////////////////////////////// |
---|
14 | unsigned int _v2p_translate( page_table_t* ptab, |
---|
15 | unsigned int vpn, |
---|
16 | unsigned int* ppn, |
---|
17 | unsigned int* flags ) |
---|
18 | { |
---|
19 | unsigned long long ptba; |
---|
20 | unsigned long long pte2_paddr; |
---|
21 | |
---|
22 | unsigned int pte2_msb; |
---|
23 | unsigned int pte2_lsb; |
---|
24 | unsigned int flags_value; |
---|
25 | unsigned int ppn_value; |
---|
26 | |
---|
27 | unsigned int ix1 = vpn >> 9; |
---|
28 | unsigned int ix2 = vpn & 0x1FF; |
---|
29 | |
---|
30 | unsigned int save_sr; |
---|
31 | |
---|
32 | // get PTE1 |
---|
33 | unsigned int pte1 = ptab->pt1[ix1]; |
---|
34 | |
---|
35 | // check PTE1 mapping |
---|
36 | if ( (pte1 & PTE_V) == 0 ) |
---|
37 | { |
---|
38 | _puts("\n[VMEM ERROR] _v2p_translate() : pte1 unmapped\n"); |
---|
39 | _exit(); |
---|
40 | } |
---|
41 | |
---|
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 | { |
---|
51 | |
---|
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); |
---|
57 | |
---|
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 ( |
---|
64 | "mfc2 $2, $1 \n" /* $2 <= MMU_MODE */ |
---|
65 | "andi $3, $2, 0xb \n" |
---|
66 | "mtc2 $3, $1 \n" /* DTLB off */ |
---|
67 | |
---|
68 | "move $4, %3 \n" /* $4 <= pte_lsb */ |
---|
69 | "mtc2 %2, $24 \n" /* PADDR_EXT <= pte_msb */ |
---|
70 | "lw %0, 0($4) \n" /* read flags */ |
---|
71 | "lw %1, 4($4) \n" /* read ppn */ |
---|
72 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
73 | |
---|
74 | "mtc2 $2, $1 \n" /* restore MMU_MODE */ |
---|
75 | : "=r" (flags_value), "=r" (ppn_value) |
---|
76 | : "r" (pte2_msb) , "r" (pte2_lsb) |
---|
77 | : "$2", "$3", "$4" ); |
---|
78 | |
---|
79 | // restore saved status register |
---|
80 | _it_restore( &save_sr ); |
---|
81 | |
---|
82 | // set return values |
---|
83 | *ppn = ppn_value & 0x0FFFFFFF; |
---|
84 | *flags = flags_value & 0xFFC00000; |
---|
85 | |
---|
86 | // check PTE2 mapping |
---|
87 | if ( (flags_value & PTE_V) == 0 ) |
---|
88 | { |
---|
89 | _puts("\n[VMEM ERROR] _v2p_translate() : pte2 unmapped\n"); |
---|
90 | _exit(); |
---|
91 | } |
---|
92 | } |
---|
93 | return 0; |
---|
94 | } // end _v2p_translate() |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | // Local Variables: |
---|
99 | // tab-width: 4 |
---|
100 | // c-basic-offset: 4 |
---|
101 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
102 | // indent-tabs-mode: nil |
---|
103 | // End: |
---|
104 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
105 | |
---|
106 | |
---|