Changeset 534
- Timestamp:
- Mar 27, 2015, 12:24:12 PM (10 years ago)
- Location:
- soft/giet_vm/giet_common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_common/vmem.c
r495 r534 9 9 #include <utils.h> 10 10 #include <vmem.h> 11 #include <ctx_handler.h> 11 12 #include <giet_config.h> 12 13 13 ///////////////////////////////////////// 14 void _v2p_translate( page_table_t* ptab, 15 unsigned int vpn, 16 unsigned int* ppn, 17 unsigned int* flags ) 14 /////////////////////////////////////////////////////// 15 unsigned long long _v2p_translate( unsigned int vaddr, 16 unsigned int* flags ) 18 17 { 19 18 unsigned long long ptba; … … 25 24 unsigned int ppn_value; 26 25 27 unsigned int ix1 = vpn >> 9; 28 unsigned int ix2 = vpn & 0x1FF; 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; 29 32 30 unsigned int save_sr; 33 // get page table vbase address 34 page_table_t* pt = (page_table_t*)_get_context_slot(CTX_PTAB_ID); 31 35 32 36 // get PTE1 33 unsigned int pte1 = pt ab->pt1[ix1];37 unsigned int pte1 = pt->pt1[ix1]; 34 38 35 39 // check PTE1 mapping … … 37 41 { 38 42 _printf("\n[VMEM ERROR] _v2p_translate() : pte1 unmapped\n" 39 " v pn= %x / ptab = %x / pte1_vaddr = %x / pte1_value = %x\n",40 v pn , (unsigned int)ptab, &(ptab->pt1[ix1]) , pte1 );43 " vaddr = %x / ptab = %x / pte1_vaddr = %x / pte1_value = %x\n", 44 vaddr , (unsigned int)pt, &(pt->pt1[ix1]) , pte1 ); 41 45 _exit(); 42 46 } … … 45 49 if ( (pte1 & PTE_T) == 0 ) // big page 46 50 { 47 // set return values48 *ppn = ((pte1 << 9) & 0x0FFFFE00) | (vpn & 0X000001FF);49 51 *flags = pte1 & 0xFFC00000; 52 offset = offset | (ix2<<12); 53 return (((unsigned long long)(pte1 & 0x7FFFF)) << 21) | offset; 50 54 } 51 55 else // small page … … 84 88 _it_restore( &save_sr ); 85 89 86 // set return values87 *ppn = ppn_value & 0x0FFFFFFF;88 *flags = flags_value & 0xFFC00000;89 90 90 // check PTE2 mapping 91 91 if ( (flags_value & PTE_V) == 0 ) 92 92 { 93 93 _printf("\n[VMEM ERROR] _v2p_translate() : pte2 unmapped\n" 94 " v pn= %x / ptab = %x / pte1_value = %x\n"94 " vaddr = %x / ptab = %x / pte1_value = %x\n" 95 95 " pte2_paddr = %l / ppn = %x / flags = %x\n", 96 v pn , ptab, pte1 , pte2_paddr , ppn_value , flags_value );96 vaddr , pt , pte1 , pte2_paddr , ppn_value , flags_value ); 97 97 _exit(); 98 98 } 99 100 *flags = flags_value & 0xFFC00000; 101 return (((unsigned long long)(ppn_value & 0x0FFFFFFF)) << 12) | offset; 99 102 } 100 103 } // end _v2p_translate() -
soft/giet_vm/giet_common/vmem.h
r476 r534 45 45 #define PTE_D 0x00400000 46 46 47 /////////////////////////////////////////////////////////////////////////////////// //47 /////////////////////////////////////////////////////////////////////////////////// 48 48 // MMU error codes definition 49 /////////////////////////////////////////////////////////////////////////////////// //49 /////////////////////////////////////////////////////////////////////////////////// 50 50 51 51 #define MMU_ERR_PT1_UNMAPPED 0x001 // Page fault on Table1 (invalid PTE) … … 59 59 #define MMU_ERR_CACHE_ILLEGAL_ACCESS 0x100 // Bus Error during the cache access 60 60 61 /////////////////////////////////////////////////////////////////////////////////// //61 /////////////////////////////////////////////////////////////////////////////////// 62 62 // Page table structure definition 63 /////////////////////////////////////////////////////////////////////////////////// //63 /////////////////////////////////////////////////////////////////////////////////// 64 64 65 65 typedef struct PageTable … … 69 69 } page_table_t; 70 70 71 /////////////////////////////////////////////////////////////////////////////////// /71 /////////////////////////////////////////////////////////////////////////////////// 72 72 // functions prototypes 73 /////////////////////////////////////////////////////////////////////////////////// /73 /////////////////////////////////////////////////////////////////////////////////// 74 74 75 75 /////////////////////////////////////////////////////////////////////////////////// 76 // This function makes a "vpn" to "ppn" translation, from the page table 77 // defined by the virtual address "pt". The MMU is supposed to be activated. 76 // This function makes a "virtual" to "physical" address translation, 77 // using the page table of the calling task. 78 // The MMU is supposed to be activated. 78 79 // It supports both small (4 Kbytes) & big (2 Mbytes) pages. 80 // The page flags are written in the flags buffer. 79 81 // It uses the address extension mechanism for physical addressing. 80 // Return 0 if success. Return 1if PTE1 or PTE2 unmapped.82 // Returns the physical address if success, exit if PTE1 or PTE2 unmapped. 81 83 /////////////////////////////////////////////////////////////////////////////////// 82 void _v2p_translate( page_table_t* pt, 83 unsigned int vpn, 84 unsigned int* ppn, 85 unsigned int* flags ); 84 unsigned long long _v2p_translate( unsigned int vaddr, 85 unsigned int* flags ); 86 86 87 87 #endif
Note: See TracChangeset
for help on using the changeset viewer.