Tiny4412mmu Memory Management

Source: Internet
Author: User

   MMU is the abbreviation for Memory Management unit, the Chinese name is the Ram Management Unit , the MMU is managed by the CP15 coprocessor in arm chip, it is responsible for the mapping of virtual memory to physical memory.

To map virtual memory to physical memory, you need to build a mapping table, so how to build this mapping table will be crucial, currently, 32-bit operating system provides virtual storage as 4G, each address accounted for 16 bits and 4 bytes, if the virtual memory and physical memory to achieve one by one corresponds, Then this table of a record will occupy 8 bytes, the size of the whole table is 32G, which is certainly not desirable; so we take another approach, we will be the first 12 of an address is 2 of the 12 square 4k as the base address, the last 20 bits as the offset, Now we only need to match the first 12 bits of the virtual address with the first 1211 of the physical address, so that each record 8 bytes, the entire table becomes 32k, significantly smaller, then we need to access the site through the base address to find the corresponding physical addresses and then add the offset (base address + offset);

So, if we need to map the virtual address 0x2ab45678 to the physical address 0x6ab45678, we can first find the base address by mapping table 0X2AB the corresponding physical addresses to 0x6ab00000, and then add an offset of 45678, You can get the actual physical address as: 0x6ab45678;

0x20000000 0x60000000
0x20100000 0x60100000
.... ...
0x2ab00000 0x6ab00000

  

  

Because we have an address when we save the mapping table, we can use the address of the mapping table: Suppose the address of the map table is 0x50000000, so we can save it this way:

0x6ab00000
..........
0x60100000
0x60000000

-->0x50000000 + (2AB * 4)

.......

-->0x500000000 + (201 * 4)

-->0x500000000 + (200 * 4)

0x50000000//The address of the map table, so that the address of our map table is only the physical address, the size of the whole table is only 16k ;

Here we implement the entire process through code:

We save a data 0x12345678 at the physical address 0x6ab45678, which can be accessed through the virtual address 0x2ab45678, which means the mapping is successful or the mapping fails.

1 /*map the virtual address 0x2ab12345 to the physical address 0x6ab12345*/2 int(*printf) (Char*, ...) =0xc3e114d8;3 voidEnable_mmu ();4 voidInit_table (unsignedLong*addr);5 6 intMain ()7 {8     //0x2ab00000-0x6ab000009UnsignedLong*virt =0x2ab45678;TenUnsignedLong*phys =0x6ab45678; One*phys =0x12345678; Aprintf"Phys%x\n", *Phys);  - Enable_mmu (); -printf"virt%x\n", *virt); the      -     return 0; - } -  + voidEnable_mmu () - { +     /*Building Tables*/ AUnsignedLongAddr =0x50000000; at init_table (addr); -     /*Open the MMU .*/ -UnsignedLongMMU =0; -MMU =1| (1<<1) | (1<<3) | (1<<8); - __asm__ __volatile__ ( -         "mov r0, #3 \ n" in         "MCR P15, 0, R0, C3, C0, 0\n"//Set as Administrator -         "MCR P15, 0,%0, C2, C0, 0\n"//set the address of the table to         "MCR P15, 0,%1, C1, C0, 0\n"//Open MMU +         :     -:"R"(addr),"R"(MMU) the         : *     ); $ Panax Notoginseng } -  the voidInit_table (unsignedLong*addr) + { AUnsignedLongVA =0; theUnsignedLongPhys =0; +  -     //0x20000000-0x60000000 $     //0x2ab00000-0x6ab00000 $      for(VA =0x20000000; VA <0x30000000; VA + =0x100000) { -Phys = va +0x40000000; -Addr[va >> -] = Phys |2; the     } -     //0x40000000-0x80000000-0x40000000-0x80000000Wuyi      for(VA =0x40000000; VA <0x80000000; VA + =0x100000) { thePhys =va; -Addr[va >> -] = Phys |2; Wu     } -  About     //0x10000000-0x14000000-0x10000000-0x140000000 $      for(VA =0x10000000; VA <0x14000000; VA + =0x100000) { -Phys =va; -Addr[va >> -] = Phys |2; -     } A              +}

The results of the operation on the Development Board are as follows:

Tiny4412mmu Memory Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.