From the kernel function void launch (DWORD dwlaunchaddr), check the function parameter transfer of assembly and C.

Source: Internet
Author: User
Tags prefetch

Author: wogoyixikexie @ gliet

 

Void launch (DWORD dwlaunchaddr) is implemented in smdk2440a/src/bootloader/eboot/util. S (32 ).
; **************************************** **************************************

Include kxarm. h

Phy_ram_start equ 0x30000000
Vir_ram_start equ 0x80000000

Textarea

Leaf_entry launch

LDR R2, = physicalstart
LDR R3, = (vir_ram_start-phy_ram_start)

Sub R2, R2, R3

MoV R1, #0x0070; Disable MMU
MCR P15, 0, R1, C1, C0, 0
NOP
MoV PC, R2; jump to pstart
NOP

; MMU & caches now disabled.

Physicalstart

MoV R2, #0
MCR P15, 0, R2, C8, C7, 0; flush the TLB
MoV PC, R0; jump to program we are launching.
According to the void launch (DWORD dwlaunchaddr) in C language, there is only one parameter and the parameter passing rules for C and assembler function calls.
This DWORD dwlaunchaddr should be passed to R0 in the Assembly.
But I cannot figure out how this was started. In addition, this startup method is very different from that of youlong.
According to the settings in config. bib, the physical address starting with this kernel should be) 0x30200000
The Assembly segment physicalstart should be run directly, but how can the following code be inserted in front of it?
LDR R2, = physicalstart
LDR R3, = (vir_ram_start-phy_ram_start)

Sub R2, R2, R3

MoV R1, #0x0070; Disable MMU
MCR P15, 0, R1, C1, C0, 0
NOP
MoV PC, R2; jump to pstart

Another question is, why does eboot enable MMU after nboot, but disable MMU when the kernel is started?
What are the benefits of doing so?
========================================================== ======================================

Reply by referencing hzdysymbol on the first floor:

The launch function only refers to the PC pointer and jumps to the corresponding address for running.
You must access the virtual address in eboot.
After turning it off, jump to the image because the image will perform another initialization action. If the initialization is removed from the starting part of the image, you can disable MMU.

I understand what you said. I mean, I am confused about his practice.
I think this is confusing.
LDR R2, = physicalstart
LDR R3, = (vir_ram_start-phy_ram_start) // Why?
Sub R2, R2, R3
Can I directly put 0x30200000 on the PC?

------------------------------------------------
You can directly jump to the corresponding memory physical address to run
It won't be as vague as above.

C/C ++ code
   // ================================================ ==================/// Youlong bootloader loads the NK running entry function: the method of using the function pointer, // pretty clever, the program is more readable than the eboot of Samsung. ================================= void call_linux (u32 A0, u32 A1, u32 A2) {void (* goto_start) (u32, u32); rintmsk = bit_allmsk; cache_clean_invalidate (); tlb_invalidate (); _ ASM {// mov r0, a0 // % 0 // mov R1, A1 // % 1 // mov R2, a2 // % 2 mov IP, #0 MCR P15, 0, IP, C13, c0, 0/* zero PID */MCR P15, 0, IP, C7, C7, 0/* invalidate I, d caches */MCR P15, 0, IP, C7, c10, 4/* drain write buffer */MCR P15, 0, IP, C8, C7, 0/* invalidate I, d tlbs */MRC P15, 0, IP, C1, c0, 0/* Get control register */bic ip, IP, #0x0001/* disable MMU */MCR P15, 0, IP, C1, C0, 0/* write control register * // mov PC, R2 // NOP/* No outpus * //: "R" (A0 ), "R" (A1), "R" (A2)} // setclockdivider (1, 1); // setsysfclk (fclk_200m); // start kernel, use 200 m // set_if (); goto_start = (void (*) (u32, u32) A2; // This a2 = 0x30200000, passed in when calling (* goto_start) (A0, A1 );}
----------------------------------------------------------------------------
The key to the problem is that the mov PC operation must be performed in two commands after disable MMU; otherwise, the program will run
However, before you actually jump to the NK address, you also need to perform operations such as flush cache.
Therefore, you need to jump to physicalstart first, and then to the NK entry after completing other operations.
-----------------------------------------------------------------------------
The key to the problem is that the mov PC operation must be performed in two commands after disable MMU; otherwise, the program will run
Where can I introduce this? I was the first to hear that I learned this.

However, before you actually jump to the NK address, you still need to perform flush cache and other operations, so you need to jump to physicalstart first, and then to the NK entry after completing other operations.
Yes, indeed.

My doubts are:
LDR R2, = physicalstart
LDR R3, = (vir_ram_start-phy_ram_start) // find the difference between the virtual address and the physical address. In fact, this is the principle of virtual and physical address translation.

Sub R2, R2, R3 // This is equivalent to the difference between the (-) virtual address and the physical address of physicalstart.

MoV R1, #0x0070; Disable MMU
MCR P15, 0, R1, C1, C0, 0
NOP
MoV PC, R2; jump to pstart will this jump to physicalstart for execution? According to his program, it will.
Does the program convert the virtual address of physicalstart to a physical address?
Physicalstart (Virtual Address)-difference between virtual address and physical address
Is there a physical address or virtual address that the compiler compiles?
Is that true? I think this is a reasonable explanation.
The reason why you didn't use (vir_ram_start-phy_ram_start) is that it has disabled MMU in the bootloader stage and there is no need to do so.

Dear Elders, I do not know whether this understanding is correct. Please advise.
----------------------------------------------------------------------------
Reference the reply from wohuazhen on the 14th floor:
Is there a physical address or virtual address that the compiler compiles?
In my opinion, LDR r0, = physicalstart in physicalstart, the compiler gives the physical address. However, when MMU is enabled, this code will be converted to a virtual address by the processor when it is loaded to the CPU.


No, the address identified by this label indicates the virtual address when MMU is enabled. When MMU is disabled, it is the physical address, this code has run to the memory when MMU is enabled, so we need to manually change it back to the physical address, that is, the following code
LDR R2, = physicalstart
LDR R3, = (vir_ram_start-phy_ram_start)

Sub R2, R2, R3

MoV R1, #0x0070; Disable MMU
MCR P15, 0, R1, C1, C0, 0
NOP
MoV PC, R2; jump to pstart

-- This code is very clever. It was not reflected at the beginning.
----------------------------------------------------------------------------
Why is MMU enabled for eboot, but why is it disabled for youlong's ads bootloader,
I think you must be as curious as you are.
-- In fact, this is because eboot needs to call the FMD driver and some Microsoft functions. These functions run in virtual memory. eboot can only be used to satisfy her, this is the case if you want to launch MMU in streaking mode! Haha.
Youlong bootloader is naturally not in touch with the above. Naturally, there is no need to open it.

So it will lead to a big difference in starting the NK function.

Haha. You can solve the problem yourself.
----------------------------------------------------------------------------
   
    Reference the reply from the 17-floor hhyh612:
    
The compiler does not distinguish between virtual and real addresses, except boot. the ramimage address in bib is 80000000 (so-called virtual address), so the value of physicalstart is the virtual address of 8xxxxxxx. After MMU is disabled, it must be converted to a physical address 3 xxxxxxx

Why must the mov PC be used in the last two commands of disable MMU?
The reason is that when MCR P15, 0, R1, C1, C0, 0 is executed, the PC is a virtual address 8 xxxxxxx
After MMU is executed, the 8xxxxxxx does not exist. Therefore, you need to change the PC address to the actual address 3 xxxxxxx immediately.

The MMU is shut down because of the arm assembly line. However, the two commands after MCR are prefetch when the PC is a virtual address, so no error is reported.

If there are no mov PC to 3 xxxxxxx in the two commands, the prefetch abort is required .. -- I fully understand. Thank you.


Thank you, hhyh612. All the puzzles have been solved.
   
    Reference the reply from gooogleman on the 15th floor:
    
Reference the reply from wohuazhen on the 14th floor:
Is there a physical address or virtual address that the compiler compiles?
In my opinion, LDR r0, = physicalstart in physicalstart, the compiler gives the physical address. However, when MMU is enabled, this code will be converted to a virtual address by the processor when it is loaded to the CPU.


No, the address identified by this label indicates the virtual address when MMU is enabled. When MMU is disabled, it is the physical address, this code has been run to the memory when MMU is enabled, so we need to manually change it back to the physical location...

For program-related labels, I checked the book "ARM Series Processor Application full technical manual" and explained it, this label is processed as a PC value during assembly plus or minus a numerical constant. I think this is why "the address identified by this label is a virtual address when MMU is opened, and it is a physical address when MMU is disabled.
In addition, I learned a reasonable explanation of "Two commands are for the reason of the arm assembly line.
==================================================================
   
    Reference the reply from the 17-floor hhyh612:
    
The compiler does not distinguish between virtual and real addresses, except boot. the ramimage address in bib is 80000000 (so-called virtual address), so the value of physicalstart is the virtual address of 8xxxxxxx. After MMU is disabled, it must be converted to a physical address 3 xxxxxxx

Why must the mov PC be used in the last two commands of disable MMU?
The reason is that when MCR P15, 0, R1, C1, C0, 0 is executed, the PC is a virtual address 8 xxxxxxx
After MMU is executed, the 8xxxxxxx does not exist. Therefore, you need to change the PC address to the actual address 3 xxxxxxx immediately.

The MMU is shut down because of the arm assembly line. However, the two commands after MCR are prefetch when the PC is a virtual address, so no error is reported.

If there are no mov PC to 3 xxxxxxx in the two commands, the prefetch abort is required .. -- I fully understand. Thank you.


Thank you, hhyh612. All the puzzles have been solved.
=========================================================================
   
    Reference the reply from wohuazhen on the 19th floor:
    
Reference the reply from gooogleman on the 15th floor:
Reference the reply from wohuazhen on the 14th floor:
Is there a physical address or virtual address that the compiler compiles?
In my opinion, LDR r0, = physicalstart in physicalstart, the compiler gives the physical address. However, when MMU is enabled, this code will be converted to a virtual address by the processor when it is loaded to the CPU.


No, the address identified by this label indicates the virtual address when MMU is enabled. When MMU is disabled, it is the physical address, this code has been run to the memory when MMU is enabled...


No, the value of the label will not become
If mov PC is used, it must use an absolute address, and it has nothing to do with PC.
If the B command is used, the relative address of the PC is used.
=============================================================================
Finally, we need to remind you that assembly and C Mixed Programming use r0, R1, R2, and R3 In arm to pass parameters, while x86 uses stacks to pass parameters.
 
For more information about assembly and function parameter transfer in C language, see this post.
http://linux.chinaunix.net/techdoc/develop/2008/06/28/1013691.shtml
http://topic.csdn.net/u/20071128/16/d7c16f51-b70c-4b2f-a65b-f4c90c519d00.html
Reprinted Please note: the author wogoyixikexie @ gliet. Guilin University of electronic science and technology, a Department of Science and Technology Association. If any error occurs, you can leave a message to indicate it.
 
Related Article

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.