V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
amiwrong123
V2EX  ›  程序员

怎么理解用 TSS 恢复任务的执行,里面用到的 LDT 段选择子?

  •  
  •   amiwrong123 · 2022-12-19 20:35:18 +08:00 · 943 次点击
    这是一个创建于 486 天前的主题,其中的信息可能已经有所发展或是发生改变。

    根据书上内容,当切换到新任务,当前任务会指向一个新的 TSS ,TSS 里面会保存 恢复任务需要的东西。上图红框的这几个选择子,都依赖从当前的任务的 LDT 里,去取属于自己的段描述符。

    对于上图的 LDT segment selector ,我不是很理解,不是应该存任务的 LDTR 里面的值( 32 的基地址,和 16 的偏移地址),这样就可以直接拿这个值来装入 LDTR 寄存器里面,就可以识别到新的 LDT 了。或者说,我觉得保存 LDT 在哪里这个信息,不应该用到选择子阿

    但是现在,却是一个 LDT 的选择子,难道说 可以用这个选择子从 GDT 里面取到一个段描述符吗,并把里面的地址 作为 LDTR 的基地址?但就算是这样,他也没有保存到 LDT 的界限是多少阿!

    6 条回复    2022-12-21 12:05:33 +08:00
    amiwrong123
        1
    amiwrong123  
    OP
       2022-12-20 00:03:43 +08:00 via Android
    原来每个任务的 TCB 里面,有存 LDT 的基地址和界限。

    但还是不知道 LDT 的段选择子是用来干啥的。而且 TCB 里面也有 LDT 的段选择子,奇怪了。
    yuguorui96
        2
    yuguorui96  
       2022-12-20 08:53:54 +08:00 via iPhone
    愚以为直接存基址的话,在 32 和 64 之间就需要不同的大小来操作 ldt ,这个非常痛苦。
    所以我理解 selector 的本质作用就是替换掉变长的地址宽度。
    ihciah
        3
    ihciah  
       2022-12-20 20:24:47 +08:00
    The LDT is located in a system segment of the LDT type. The GDT must contain a segment descriptor for the LDT segment. If the system supports multiple LDTs, each must have a separate segment selector and segment descriptor in the GDT. The segment descriptor for an LDT can be located anywhere in the GDT. See Section 3.5, “System Descriptor Types”, for information on the LDT segment-descriptor type.
    An LDT is accessed with its segment selector. To eliminate address translations when accessing the LDT, the segment selector, base linear address, limit, and access rights of the LDT are stored in the LDTR register (see Section 2.4, “Memory-Management Registers”).
    From SDM Vol. 3A 3-15
    amiwrong123
        4
    amiwrong123  
    OP
       2022-12-20 21:28:36 +08:00
    @ihciah #3
    原来 LDTR 寄存器里面有三个东西,segment selector, base linear address, limit

    但好像还是不明白,这三个东西,既然已经有了 segment selector ,那还需要 base linear address, limit 干什么,毕竟一个段选择子指向一个段描述符,而一个段描述符其实就是包含了基地址和界限。
    yuguorui96
        5
    yuguorui96  
       2022-12-20 23:22:24 +08:00 via iPhone
    @amiwrong123 你再看看上个回答?谜底就在谜面上。
    stevefan1999
        6
    stevefan1999  
       2022-12-21 12:05:33 +08:00 via Android
    歷史原因
    在沒有線性地址前 DOS 就是靠交換 TSS 來獲得有限的虛擬內存支援 但並沒有內存保護
    後來有了 32-bit 就完全改成了線性地址 但是為了向下兼容就規定了只有當你轉成保護模式才可以
    你做的這是其中一步
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5372 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:03 · PVG 17:03 · LAX 02:03 · JFK 05:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.