Linux memory management scheme (1) a logical linear address Address

Research kernel time is not long, a few days ago drew a big picture memory management, I feel too messy, ready to write something segments can be considered sort out his thoughts. Is a person blind pondering around no communication, not the right place, please point it out.

A logical linear address Address Memory address of the machine language instruction occurred, are the logical address needs to be converted into a linear address, and then through the MMU (memory management unit of the CPU) into a physical address to be able to be accessed. We write a simple hello world program, compiled with gcc, after then decompile see the following instructions:
   


  1. mov    0x80495b0, %eax
Copy the code


Here 0x80495b0 memory address is a logical address, you must add the implicit base address DS data segment in order to constitute a linear address. That 0x80495b0 is offset within the data segment DS current task.

<ignore_js_op>

in x86 protected mode, information (address segment of the baseline length, permissions, etc.) segment descriptor 8 bytes, i.e., pieces of information can not be stored directly (only 2-byte segment register) in the segment registers . Intel designed descriptor in the GDT or LDT stored centrally in the segment descriptor register stores the index value of the GDT or LDT (index).

Linux logical address equal to the linear address. Why do you say? Because all segments Linux (user code segment, a user data segment, the kernel code segment, the kernel data section) is a linear address 0x00000000 from the beginning, the length of 4G, so that the linear address 0x00000000 = + logical address, the logical address that is equal to the linear the address.

Under such circumstances Linux only used the GDT, regardless of user or kernel task task, did not use LDT. GDT and 13 and 12 of the segment descriptor is __KERNEL_CS __KERNEL_DS, 14 and 15 of the segment descriptor is __USER_CS and __USER_DS. And kernel tasks using __KERNEL_CS __KERNEL_DS, all users share tasks and __USER_CS __USER_DS, that is to say do not need to separate the segment descriptor assigned to each task. Kernel and user segment descriptors descriptor linear start address and length, although the same, but the DPL (descriptor privilege level) is not the same. __KERNEL_CS __KERNEL_DS and the DPL is 0 (most privileged), __ USER_CS __USER_DS and the DPL is 3.
When using gdb debugger, displaying the current value of the register using info reg:

  1. cs             0x73     115
  2. ss             0x7b     123
  3. ds             0x7b     123
  4. es             0x7b     123
复制代码


可以看到ds值为0x7b, 转换成二进制为 00000000 01111011,TI字段值为0,表示使用GDT,GDT索引值为 01111,即十进制15,对应的就是GDT内的__USER_DATA 用户数据段描述符。
从上面可以看到,Linux在x86的分段机制上运行,却通过一个巧妙的方式绕开了分段。Linux主要以分页的方式实现内存管理

 

转自:http://bbs.chinaunix.net/thread-2015599-1-1.html

Guess you like

Origin www.cnblogs.com/pipci/p/12392743.html