Logical Address virtual address physical address bus address difference, logical Bus

Source: Internet
Author: User

Logical Address virtual address physical address bus address difference, logical Bus

1. Logical Address

Logical Address is the most vague concept.

The explanation in understanding the linux kernel is related to virtual addresses. Based on the concept of hardware MMU and Software Memory Management, you can refer to the second chapter of UTLK memory addressing, I have a very detailed explanation.

However, the MIPS architecture processor used in the work is different. In the MIPS architecture perspective, the logical address is irrelevant to MMU, And the MIPS address space is divided, there is an offset between the Kseg0 Kseg1 address space and the actual physical address, that is, there is a linear relationship. It is a simple relationship without translation.

The same memory is linearly mapped to the two address spaces, regardless of whether the processor has MMU units, the two address spaces are divided (the difference between the two addresses is whether the cache is enabled by default ).

The logic address division of the MIPS processor must be handled by its internal logic circuit, without MMU.


2. Virtual Address

As a programmer, virtual addresses are the most widely heard. for programming in linux or windows, the addresses operated by the program are all virtual addresses.

Virtual Address is a combination of hardware MMU and Software Memory Management to facilitate more efficient use of RAM. Memory Management is a big article. I will not talk about details here. For details, refer to the memory addressing chapter of UTLK.


Logical Address virtual address can be operated by software developers Based on System Programming and bare coding.


3. physical address

For embedded development, the physical address must be clear,The physical address refers to the address that the processor chip sends to address space addressing. It corresponds to the electrical signal sent from the processor address pin.

UTLK is used for memory chip-level unit addressing. In a real development environment, this is not the case because the processor needs other peripherals besides RAM, such as nand, spi, serial (of course refers to the controller of these peripherals.

The physical address is the address that the processor actually sends to its address bus. Who should the address access? Nand controller ?), This depends on the system bus arbitration of the device, that is, bus arbitration. Currently, common bus arbitration includes axi ahba.

These bus schedulers are used to plan the physical address space of the processor.

Most processor manuals provide their address map, that is, the distribution of peripherals (registers) in the processor address space.


For the processor, the virtual address logical address is an input source. The processor converts these addresses (such as MMU) to physical addresses. The actual processor sends a physical address.


4 BUS address

BUS address is the most difficult concept to understand.

All the addresses can be called Bus addresses, because all devices in the development environment are connected to the bus, such as the AXI bus, APB bus, and PCI bus I2C bus SPI bus. There will be many types of address space.


In most cases, the BUS address = physical address. Why? The physical address is the address sent by the processor on the system bus, therefore, the physical address sent by the processor can be understood as the BUS address of the processor address space, which must be equal.

Most program operations use the processor as the master device, which sends out addresses and reads and writes data according to commands. BUS address = physical address

In one case, the main device is not the processor, and the DMA controller does not need to pass through the processor to operate RAM. This is because the DMA controller is also attached to the system bus, that is, the address space of the processor.

The address issued by the DMA controller is also a physical address.

In a special case, the BUS address is different from the physical address, that is, the PCI bus.

Because the PCI bus has address ing, this is because the PCI Controller has a bridge circuit, which maps I/O addresses to different physical addresses.

As you can imagine, the PCI Controller is attached to the processor's system bus, while the PCI bus at the other end expands some PCI devices.

If a PCI device has DMA capability and needs to operate RAM, then the RAM address displayed by the device should be the BUS address mapped from the system bus to the PCI bus.

The PCI ing is configured in the PCI Controller address window, which is generally an offset, therefore, the BUS address mapped to the PCI bus is not the physical address (also known as the system BUS address) of the RAM in the processor system address space.

So the bus address! = Physical address.

Of course, the PCI Controller address window can be configured as a flat ing, and the bus address is the same as the physical address.


At this time, I will also think of a problem, that is, whether the I2C bus SPI bus will also have such a problem. In fact, I have to worry about this problem because the PCI bus supports the device as the master device, perform DMA.

The I2C SPI bus does not have such capabilities, but they still have their own address space, therefore, when operating the I2C SPI bus, we need to send an address to lock the device on its data line based on the protocol. This address is not the processor address space, but the address space of the corresponding bus.



After the above explanation, we can see that there are many address bus (axi pci I2C SPI) in any development environment, and there is a lot of address space.


The physical address is also the BUS address, just the processor system BUS address (such as axi ahba.




What is the difference between a logical address and a physical address?

A Logical Address is a segment-related offset generated by a program. For example, you can read the value (& operation) of the pointer variable in the C language pointer programming. In fact, this value is the logical address, which is relative to the address of the Data Segment of your current process, it is not related to an absolute physical address. The logical address is equal to the physical address only in Intel real mode (because the real mode does not have a segmentation or paging mechanism, the Cpu does not perform automatic address translation ); the logic is the offset address within the limit of the code segment executed by the program in Intel protection mode (assuming that the code segment and data segment are exactly the same ). Application programmers only need to deal with logical addresses, while the segmentation and paging mechanisms are completely transparent to you and are only involved by system programmers. Although the application programmer can directly operate the memory, it can only operate on the memory segment allocated to you by the operating system.

Linear Address is the intermediate layer between Logical Address and physical Address transformation. The program code will generate a logical address, or an offset address in the segment. A linear address is generated by adding the base address of the corresponding segment. If the paging mechanism is enabled, linear addresses can be transformed to generate a physical address. If the paging mechanism is not enabled, linear addresses are physical addresses. Intel 80386 linear address space is 4 GB (2 to the power of 32 address bus addressing ).

Physical Address refers to the Address signal indicating the addressing Physical memory on the CPU external Address bus. It is the final result Address of Address transformation. If the paging mechanism is enabled, linear addresses are converted to physical addresses using the items in the page Directory and page table. If the paging mechanism is not enabled, the linear address directly becomes a physical address.

Virtual Memory refers to the amount of Memory displayed on a computer that is much larger than the actual Memory. Therefore, it allows programmers to compile and run programs with much larger memory than the actual system. This allows many large projects to be implemented on systems with limited memory resources. An appropriate analogy is that you don't need a long track to drive a train from Shanghai to Beijing. You only need enough rails (for example, 3 kilometers) to complete this task. The train tracks are immediately placed in front of the train. As long as your operations are fast enough to meet the requirements, the train can run on a complete track. This is the task to be completed for virtual memory management. In the Linux 0.11 kernel, each program (process) is divided into 64 MB virtual memory space. Therefore, the logical address range of the program is 0x0000000 to 0x4000000.

Sometimes we call logical addresses as virtual addresses. Similar to the concept of virtual memory space, the logical address is not related to the actual physical memory capacity.
The difference between a logical address and a physical address is 0xC0000000, because the ing between a virtual address and a linear address is exactly the same. This value is specified by the operating system.

What is a linear address? What is the difference from a physical address?

In the 386 architecture, the cpu can be in the real mode and protection mode.
In real mode, the address accessed by the cpu command is the physical address, in the form of segment register: Offset
In protection mode, the cpu can use the segmentation and paging mechanisms.
The address used in the segmentation mechanism is the logical address, in the form of: Segment Selection Sub-: Offset
The address used in the paging mechanism is a linear address in the form of 0 xXXXXXXXX
Both logical and linear addresses are mapped to physical addresses by the cpu.
The multipart mechanism must be used in protection mode. On this basis, the paging mechanism can be used.
The logical address is converted to a linear address. If the paging mechanism is used, the linear address is mapped to a physical address through the paging mechanism. If the paging mechanism is not used, the linear address is the physical address.
Physical addresses in real mode can only access less than 1 MB of space, while physical addresses in protected mode can access all 32-bit space. Note that the physical memory space is only a part of the physical address space.
There is also a concept of "BUS address", which is from the perspective of bus devices.
In linux, for cpu, the first address of physical memory starts from 0xc0000000. For a bus device, the first address of the physical memory may start from the BUS address 0x00000000, or start from another bus address, which varies with the system. This is also why vir_to_phy and vir_to_bus conversion often exist in the kernel.

And ~~~

The differences between physical addresses, linear addresses, and virtual addresses can only be explained by my understanding, which may be inaccurate. When the physical address exists, but after the paging technology and virtual memory technology are used, it is difficult to determine where the physical address is located, therefore, we recommend that you use physical addresses and linear addresses in the real mode. At this time, physical addresses and linear addresses are actually the same. For example, the address after the computer is started is 0xfff0: 0000, which loads the BIOS and transfers it to 0x07C0: 0000. Therefore, you can always set a physical breakpoint 0x7C00 to start debugging your bootloader.

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.