Follow Wei teacher to learn Linux learning Notes (iii)-MMU

Source: Internet
Author: User

(1), MMU introduction

A, Rights management

Programs in different address spaces cannot access each other, or an error occurs.

B, Address mapping

The teacher in the video on the MMU explanation is not a lot, ask also just understand the concept of the MMU, can be reference books or the following article about the MMU

Http://www.cnblogs.com/bigbear1385/p/5325344.html

1, establish a table, is to establish a virtual address to the physical address mapping

2. Inform the MMU of the form address.

3. Start the MMU

(2), program code

First we look at the assembler code, because our main program is in the assembler code.

. Text.global _start _start:     Ldr sp, =4096                       @ Set the stack pointer, the following are C functions, need to set the stack    bl before calling  Disable_watch_dog               @ Turn off watchdog, otherwise the CPU will constantly restart    bl  memsetup                        @ Set storage controller to use SDRAM    BL  copy_2th_to_sdram               @ Copy the second part of the code to the SDRAM    BL  create_page_table               @ Setup page table    bl  mmu_init                        @ start MMU    Ldr sp, = 0xb4000000                 @ Reset stack pointer, point to SDRAM top (using virtual address)    Ldr pc, =0xb0004000                 @ jump to SDRAM to continue execution of Part II code    @ LDR pc, =main  halt_loop:    b   halt_loop

Ldr sp, =4096

BL Disable_watch_dog

BL Memsetup

These three lines of code are the same as the previous episodes, setting up stacks, shutting down the watchdog, initializing SDRAM.

Next is the copy code into the SDRAM inside, this code is not quite the same as before, need to relate to the content of the connection script.

1 firtst    0x00000000  : {head.o INIT.O}23 second    0xb0004000 : at (2048) {LEDS.O}

First the first piece of code is executed from 0x00000000, but the address of our main function code is placed at 2048, and the address is 0xb0004000 (this is the virtual address, which needs to be mapped to a physical address later).

1 void Copy_2th_to_sdram (void)2 {3Unsignedint*PDWSRC = (unsignedint*)2048;4Unsignedint*pdwdest = (unsignedint*) 0x30004000;5     6while (Pdwsrc < (unsignedint*)4096)7     {8*pdwdest = *pdwsrc;9pdwdest++;TenPdwsrc++; One     } A}

This code is to copy the second piece of code into the SDRAM, because the second code is starting from a 2048, and our internal RAM is only 4096, so we copy the code from 2048 to 4096 to 0x30004000. and set aside the 0x30000000~0x30004000 address space to hold the content of the first Level page table, the base address of the first page table is 0x30000000.

Set Page table:

1     0 ; 2     0 ; 3      - 0xfff00000) |  4                                             MMU_SECDESC_WB;

The code is to map the physical address starting at 0 to the 1M address space to the virtual address of the start address bit 0 of the 1M address space.

The goal is to still be able to run the first piece of code after opening the MMU.

Why 1M: Because we are using the page table described in paragraph.

1     0xa0000000 ; 2     0x56000000 ; 3      - 0xfff00000) |  4                                             Mmu_secdesc;

The code is to map the 1M address space of the GPIO's starting physical address to 0x56000000 to the virtual address 0xa0000000, and remember to use it later.

1VIRTULADDR =0xb0000000;2PHYSICALADDR =0x30000000;3      while(Virtuladdr <0xb4000000)4     {5* (Mmu_tlb_base + (virtuladdr >> -)) = (Physicaladdr &0xfff00000) | 6 MMU_SECDESC_WB;7Virtuladdr + =0x100000;8Physicaladdr + =0x100000;9}

Here is completely the 64M address space of the SDRAM fully mapped to the starting address for the 0xb0000000 virtual address space.

After setting up the page table, start the MMU and reset the stack pointer to the top of the SDRAM. Finally jump to the 0xb0004000 to execute the second code.

Do not know is not fully understand, or what is going on? This class listens to a daze. Well, after entering Linux and then combining the relevant content in-depth study.

Follow Wei teacher to learn Linux learning Notes (iii)-MMU

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.