深入理解linux内核-ch02

2.1 内存编址

我们通过 memory address 来得到内存的内容,对于8086处理器,需要区分三种地址:
1. 逻辑地址:每个逻辑地址包含一个 段 和一个 偏移
2. 线性地址:又称虚地址:一个32位的无符号整数,4G
3. 物理地址:

内存管理单元,Memory Management Unit - MMU,通过一个被称为段单元的硬件电路,将逻辑地址转换为线性地址,页单元 将线性地址转换为物理地址。(可参考操作系统书籍,内存管理部分)

Memory arbiter 被插在 bus 和每个 RAM芯片之间,用于同步,当芯片忙时让请求等待。

2.2 段机制-硬件

Intel的处理器,分为实模式和保护模式。Real mode exists mostly to maintain processor compatibility with older models and to allow the operating system to bootstrap

2.2.1 段选择器和段寄存器

一个逻辑地址包含一个 segment identifier 和一个 偏移,segment identifier是一个16位的段选择器

这里写图片描述

为了更方便地得到段选择器,处理器指定来一些段寄存器来保存它。
cs, ss, ds, es, fs, gs
cs: 代码段 code segment, 包含了2-bit的CPL,current privilege level当前优先级等级,0代表最高级,内核态kernel mode,3代表最低,用户态
ss: stack segment
ds: data segment

2.2.2 段描述符

每个段都用一个8-bit的段描述符,它被保存在 GDT 全局描述符表,LDT local

The address and size of the GDT in main memory are contained in the gdtr control register, while the address and size of the currently used LDT are contained in the ldtr control register

这里写图片描述

2.2.3 Fast Access to Segment Descriptors

这里写图片描述

2.2.4 Segmentation Unit

这里写图片描述

根据段选择器段 TI 来判断哪个 描述符表 存储了 段描述符,根据段选择器 的 index 计算出段描述符的地址,(乘8 再加上 gdtr or ldtr ),段描述符的 base 加上逻辑地址的 offset 得到线性地址。

2.3 Segmentation in Linux

linux的段机制

segmentation can assign a different linear address space to each process, while paging can map the same linear address space into different physical address spaces.

所有的用户态的进程,使用相同的段来寻址,内核态一样

All Linux processes running in User Mode use the same pair of segments to address instructions and data. These segments are called user code segment and user data segment , respectively. Similarly, all Linux processes running in Kernel Mode use the same pair of segments to address instructions and data: they are called kernel code segment and kernel data segment , respectively. Table 2-3 shows the values of the Segment Descriptor fields for these four crucial segments.

这里写图片描述

对应的段选择器定义为 __USER_CS, __USER_DS, __KERNEL_CS, __KERNEL_DS,例如为来得到 kernel code segment,只需要取出 __KERNEL_CS 的值到 cs 段寄存器中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值