x86段寄存器在现代CPU和OS上是否具有特殊含义/用途? [英] Do the x86 segment registers have special meaning/usage on modern CPUs and OSes?

查看:136
本文介绍了x86段寄存器在现代CPU和OS上是否具有特殊含义/用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

x86 CPU经历了从16位到32位再到64位的各种棘手的模式和内存分段.

x86 CPUs have had all kinds of tricky modes and memory segmentation over the generations from 16-bit to 32-bit to 64-bit.

这些天来,现代操作系统在现代操作模式下使用现代CPU时,您不必担心内存段的问题,但是您仍然可以在现代CPU的旧版OS上运行旧版应用程序,在这种情况下,我认为CPU可以在一种特殊的传统模式(保护模式,实模式等).

These days with modern OSes using modern CPUs in modern operating modes you don't have to worry about memory segments, but you can still run legacy apps on legacy OSes on the modern CPUs, in which case I presume the CPUs run in a special legacy mode (protected mode, real mode, etc).

显然,段寄存器是出于向后兼容的原因而存在的,但这是唯一的原因吗?

So obviously the segment registers exist for reasons of backward compatibility, but is that the only reason?

段寄存器也有现代用途吗?还是这些天它们只是成为通用的寄存器,而其名称仅反映了它们的历史功能?

Are there modern uses for the segment registers too? Or have they just become general purpose registers these days that merely have names reflecting their historic functions?

这个问题的灵感来自对此旧堆栈溢出线程的评论:为什么必须以这种方式使用mov指令?

This question was inspired by comments on this old Stack Overflow thread: Why does the mov instruction have to be used this way?

推荐答案

在2002年,Linux内核黑客Ingo Molnar在实施

In 2002, Linux kernel hacker Ingo Molnar used segmentation when implementing Exec Shield, a form of data execution prevention, on 32 bit x86 systems. This is one modern use of segmentation that I'm aware of but mostly in a get the most mileage out of hardware mechanisms you can't change way. Segmentation is not used to implement data execution prevention on x86-64 CPUs with NX support.

FS GS 段寄存器仍在x86-64上使用: 在64位模式下,通常(但不是完全)禁止分段,从而创建了平坦的64位线性地址空间.处理器将CS,DS,ES,SS的分段基数视为零,从而创建了一个线性地址, FS和GS段是例外,这些段寄存器(保存段基)可以用作线性地址计算中的附加基寄存器,它们有助于寻址本地数据和某些操作系统数据结构. " (摘自《英特尔系统编程指南》第3.2.4章)

The FS and GS segment registers are still used on x86-64: "In 64-bit mode, segmentation is generally (but not completely) disabled, creating a flat 64-bit linear-address space. The processor treats the segment base of CS, DS, ES, SS as zero, creating a linear address that is equal to the effective address. The FS and GS segments are exceptions. These segment registers (which hold the segment base) can be used as an additional base registers in linear address calculations. They facilitate addressing local data and certain operating system data structures." (from Intel System Programming Guide, Chapter 3.2.4)

在x86-64上,Linux使用 FS 用于线程本地存储,并使用 GS 用于每个CPU数据的内核空间.参见在Linux AMD64中如何使用fs/gs寄存器?有关Linux x86 64中MSR_GS_BASE的详细信息

On x86-64, Linux uses FS for thread local storage and GS for kernel space per cpu data. See How are the fs/gs registers used in Linux AMD64? and Detail about MSR_GS_BASE in linux x86 64

这篇关于x86段寄存器在现代CPU和OS上是否具有特殊含义/用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆