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 <ctx_handler.h> |
---|
12 | #include <giet_config.h> |
---|
13 | |
---|
14 | /////////////////////////////////////////////////////// |
---|
15 | unsigned long long _v2p_translate( unsigned int vaddr, |
---|
16 | unsigned int* flags ) |
---|
17 | { |
---|
18 | unsigned long long ptba; |
---|
19 | unsigned long long pte2_paddr; |
---|
20 | |
---|
21 | unsigned int pte2_msb; |
---|
22 | unsigned int pte2_lsb; |
---|
23 | unsigned int flags_value; |
---|
24 | unsigned int ppn_value; |
---|
25 | |
---|
26 | unsigned int save_sr; |
---|
27 | |
---|
28 | // decode the vaddr fields |
---|
29 | unsigned int offset = vaddr & 0xFFF; |
---|
30 | unsigned int ix1 = (vaddr >> 21) & 0x7FF; |
---|
31 | unsigned int ix2 = (vaddr >> 12) & 0x1FF; |
---|
32 | |
---|
33 | // get page table vbase address |
---|
34 | page_table_t* pt = (page_table_t*)_get_context_slot(CTX_PTAB_ID); |
---|
35 | |
---|
36 | // get PTE1 |
---|
37 | unsigned int pte1 = pt->pt1[ix1]; |
---|
38 | |
---|
39 | // check PTE1 mapping |
---|
40 | if ( (pte1 & PTE_V) == 0 ) |
---|
41 | { |
---|
42 | _printf("\n[VMEM ERROR] _v2p_translate() : pte1 unmapped\n" |
---|
43 | " vaddr = %x / ptab = %x / pte1_vaddr = %x / pte1_value = %x\n", |
---|
44 | vaddr , (unsigned int)pt, &(pt->pt1[ix1]) , pte1 ); |
---|
45 | _exit(); |
---|
46 | } |
---|
47 | |
---|
48 | // test big/small page |
---|
49 | if ( (pte1 & PTE_T) == 0 ) // big page |
---|
50 | { |
---|
51 | *flags = pte1 & 0xFFC00000; |
---|
52 | offset = offset | (ix2<<12); |
---|
53 | return (((unsigned long long)(pte1 & 0x7FFFF)) << 21) | offset; |
---|
54 | } |
---|
55 | else // small page |
---|
56 | { |
---|
57 | |
---|
58 | // get physical addresses of pte2 |
---|
59 | ptba = ((unsigned long long)(pte1 & 0x0FFFFFFF)) << 12; |
---|
60 | pte2_paddr = ptba + 8*ix2; |
---|
61 | |
---|
62 | // split physical address in two 32 bits words |
---|
63 | pte2_lsb = (unsigned int) pte2_paddr; |
---|
64 | pte2_msb = (unsigned int) (pte2_paddr >> 32); |
---|
65 | |
---|
66 | // disable interrupts and save status register |
---|
67 | _it_disable( &save_sr ); |
---|
68 | |
---|
69 | // get ppn_value and flags_value, using a physical read |
---|
70 | // after temporary DTLB desactivation |
---|
71 | asm volatile ( |
---|
72 | "mfc2 $2, $1 \n" /* $2 <= MMU_MODE */ |
---|
73 | "andi $3, $2, 0xb \n" |
---|
74 | "mtc2 $3, $1 \n" /* DTLB off */ |
---|
75 | |
---|
76 | "move $4, %3 \n" /* $4 <= pte_lsb */ |
---|
77 | "mtc2 %2, $24 \n" /* PADDR_EXT <= pte_msb */ |
---|
78 | "lw %0, 0($4) \n" /* read flags */ |
---|
79 | "lw %1, 4($4) \n" /* read ppn */ |
---|
80 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
81 | |
---|
82 | "mtc2 $2, $1 \n" /* restore MMU_MODE */ |
---|
83 | : "=r" (flags_value), "=r" (ppn_value) |
---|
84 | : "r" (pte2_msb) , "r" (pte2_lsb) |
---|
85 | : "$2", "$3", "$4" ); |
---|
86 | |
---|
87 | // restore saved status register |
---|
88 | _it_restore( &save_sr ); |
---|
89 | |
---|
90 | // check PTE2 mapping |
---|
91 | if ( (flags_value & PTE_V) == 0 ) |
---|
92 | { |
---|
93 | _printf("\n[VMEM ERROR] _v2p_translate() : pte2 unmapped\n" |
---|
94 | " vaddr = %x / ptab = %x / pte1_value = %x\n" |
---|
95 | " pte2_paddr = %l / ppn = %x / flags = %x\n", |
---|
96 | vaddr , pt , pte1 , pte2_paddr , ppn_value , flags_value ); |
---|
97 | _exit(); |
---|
98 | } |
---|
99 | |
---|
100 | *flags = flags_value & 0xFFC00000; |
---|
101 | return (((unsigned long long)(ppn_value & 0x0FFFFFFF)) << 12) | offset; |
---|
102 | } |
---|
103 | } // end _v2p_translate() |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | // Local Variables: |
---|
108 | // tab-width: 4 |
---|
109 | // c-basic-offset: 4 |
---|
110 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
111 | // indent-tabs-mode: nil |
---|
112 | // End: |
---|
113 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
114 | |
---|
115 | |
---|