x86 は Intel の 16 ビット 8086 から始まりました。80286 はプロテクトモードを導入し、 IA-32 は 32 ビットプログラミングモデルとページングを確立し、AMD64 はアーキテクチャ を 64 ビット実行へ拡張しました。Intel は統合アーキテクチャを Intel 64 と IA-32 と 呼び、AMD の文書では AMD64 を使います。ベンダー名だけではすべての機能は決まらない ため、ソフトウェアは拡張機能を明示的に検出する必要があります。
バイト順序とオペランドサイズ #
x86 はメモリをバイト単位でアドレス指定し、複数バイト整数をリトルエンディアンで
格納します。最下位バイトが最も低いアドレスを占めます。アドレス p から始まる
32 ビット値 0x12345678 のメモリ内容は次のとおりです。
address p p+1 p+2 p+3
byte 78 56 34 12アーキテクチャ用語では、16 ビット値を word、32 ビット値を doubleword、 64 ビット値を quadword、128 ビット値を double quadword と呼びます。これらの 名称は C 実装の型サイズとは独立しています。
命令オペランドサイズは、実行モード、プレフィックス、オペコード、REX、VEX、EVEX
フィールドに依存します。64 ビットモードでも、多くの整数命令は 32 ビットオペランド
がデフォルトで、対応している場合は REX.W エンコーディングが 64 ビットを選択します。
アドレスサイズは独立した属性で、実効アドレス計算を制御します。
通常の整数ロードとストアは非アラインメントのアドレスを許可しますが、キャッシュ ラインやページ境界をまたぐとレイテンシーやフォールト動作が増えることがあります。 アトミック性の保証はアラインメント、幅、メモリ型、命令に依存するため、共有データは アーキテクチャの明示的な要件を満たす必要があります。
実行モード #
リセット後、x86 プロセッサーはリアルアドレスモードで開始します。ファームウェアが 後続モードに必要なテーブルと制御レジスターを設定します。
- リアルアドレスモード は、プロテクトモードの特権強制なしに 8086 形式のセグメントモデルを使います。
- プロテクトモード は 16 または 32 ビットのコード・データセグメント、ディスクリプター検査、 4 段階の特権レベル、オプションのページングをサポートします。
- Virtual-8086 モード は、オペレーティングシステムの制御下で、リアルモード形式の 8086 ソフトウェアをプロテクトモードタスクとして実行します。
- ロングモード は 64 ビットモードと互換モードを含みます。互換モードは 64 ビット オペレーティングシステム上でプロテクトされた 16 または 32 ビットコードを実行します。
- システム管理モード は、アプリケーション実行モードではなく、システム管理割り込みで 入る独立したファームウェア環境です。
In 64-bit mode, ordinary address generation treats CS, DS, ES, and SS
bases as zero and does not enforce their legacy limits. FS and GS retain
usable bases, commonly for thread-local and per-CPU state. Descriptor types and
privilege checks remain relevant even though flat addressing removes most
segment arithmetic.
論理、線形、仮想、物理アドレス #
Intel の用語では、セグメントセレクターとオフセットの組み合わせを 論理アドレス と呼びます。セグメンテーションがアクセスを検証してセグメントベースを加え、 線形アドレス を生成します。ページングが無効な場合、線形アドレスはアーキテクチャ の幅とプラットフォーム動作に従って物理アドレスへ直接対応します。ページングが有効 な場合、ページテーブルが線形アドレスを 物理アドレス に変換します。
オペレーティングシステムの文書では、プロセスから見える線形アドレスを 仮想アドレス と呼ぶことがよくあります。そのためページング境界では「線形」と「仮想」が同じ数値 アドレスを指すことがありますが、異なるモデルを強調します。仮想化されたゲストでは、 ゲスト物理メモリからホスト物理メモリへの別の変換が加わることがあります。
命令はベースレジスター、インデックスレジスター、スケール、ディスプレースメント から実効オフセットを形成します。64 ビットモードでは、線形アドレスは有効なアドレス 幅に対して canonical でなければなりません。非 canonical アドレスは通常のページ 変換前にフォールトになります。その後ページテーブルが present、書き込み可能、 user/supervisor、実行禁止などの権限を適用します。
Exceptions, Interrupts, and Control Transfer #
The interrupt descriptor table maps vectors to gates. Processor-detected exceptions, software interrupt instructions, and external interrupts use those vectors, although interrupt-controller routing is platform-specific.
Exceptions are conventionally grouped as:
- A fault reports before architectural completion and can often restart the instruction after correction, as with a page-not-present fault.
- A trap reports after the triggering instruction, as with a breakpoint.
- An abort reports a condition for which reliable restart is not generally available.
The vector determines whether the processor pushes an error code and what saved
state is available. A privilege-changing gate also switches stacks according to
the task-state segment. Return uses IRET or a system-call-specific return
instruction after software validates the destination state.
Near branches change the instruction pointer within the current code segment.
Far transfers and gates can load a new code segment and perform additional
checks. SYSCALL/SYSRET and SYSENTER/SYSEXIT provide faster configured
paths, but their register convention belongs to an operating-system ABI.
Extension and Operating-System Discovery #
CPUID reports vendor identification, topology information, address widths,
cache parameters, and feature bits through numbered leaves and subleaves.
Software must first determine the maximum supported leaf and then test every
feature it intends to use. A family or model number can select an optimization
after correctness has been established through feature bits.
Some features require operating-system management in addition to processor
support. For AVX-family state, software checks CPUID for XSAVE and OSXSAVE,
then uses XGETBV to confirm that the operating system enabled the required
XCR0 components. AVX-512 and newer state can require additional bits. Similar
principles apply to supervisor features, where a user-visible CPUID bit does not
grant privilege.
Feature use must also account for ABI and deployment policy. A compiler’s baseline target can differ from the machine running the build, so portable binaries use a conservative baseline, function multiversioning, or runtime dispatch.
Related articles cover instruction encoding, instruction families, registers, memory organization, and protected-mode privilege.
コメント
GitHub で閲覧・コメントする(投稿にはログインが必要です)