/* personal notes of renzo diomedi */

~ 00010101 ~

AMD64 Features

• Register Extensions :
- 8 additional general-purpose registers (GPRs).
- All 16 GPRs are 64 bits wide.
- 8 additional YMM/XMM registers.
- Uniform byte-register addressing for all GPRs.
- An instruction prefix (REX) accesses the extended registers.

• Long Mode :
- Up to 64 bits of virtual address.
- 64-bit instruction pointer (RIP).
- Instruction-pointer-relative data-addressing mode.
- Flat address space.

1. Gray-shaded entries indicate differences between the modes. These differences (except stack-width difference) are the AMD64 architecture’s register extensions.
2. GPRs are listed using their full-width names. In legacy and compatibility modes,16-bit and 8-bit mappings of the registers are also accessible. In 64-bit mode, 32-bit, 16-bit, and 8-bit mappings of the registers are accessible.
3. The XMM registers overlay the lower octword of the YMM registers.
4. The MMX0–MMX7 registers are mapped onto the FPR0–FPR7 physical registers,
The x87 stack registers, ST(0)–ST(7), are the logical mappings of the FPR0–FPR7 physical registers

Long Mode Long mode is an extension of legacy protected mode. Long mode consists of two submodes: 64-bit mode and compatibility mode. 64-bit mode supports all of the features and register extensions of the AMD64 architecture. Compatibility mode supports binary compatibility with existing 16-bit and 32- bit applications. Long mode does not support legacy real mode or legacy virtual-8086 mode, and it does not support hardware task switching. Throughout this document, references to long mode refer to both 64-bit mode and compatibility mode. If a function is specific to either of these submodes, then the name of the specific submode is used instead of the name long mode.

Bit Mode 64-bit mode—a submode of long mode—supports the full range of 64-bit virtual-addressing and register-extension features. This mode is enabled by the operating system on an individual codesegment basis. Because 64-bit mode supports a 64-bit virtual-address space, it requires a 64-bit operating system and tool chain. Existing application binaries can run without recompilation in compatibility mode, under an operating system that runs in 64-bit mode, or the applications can also be recompiled to run in 64-bit mode. Addressing features include a 64-bit instruction pointer (RIP) and an RIP-relative data-addressing mode. This mode accommodates modern operating systems by supporting only a flat address space, with single code, data, and stack space. Register Extensions. 64-bit mode implements register extensions through a group of instruction prefixes, called REX prefixes. These extensions add eight GPRs (R8–R15), widen all GPRs to 64 bits, and add eight YMM/XMM registers (YMM/XMM8–15). The REX instruction prefixes also provide a byte-register capability that makes the low byte of any of the sixteen GPRs available for byte operations. This results in a uniform set of byte, word, doubleword, and quadword registers that is better suited to compiler register-allocation. 64-Bit Addresses and Operands. In 64-bit mode, the default virtual-address size is 64 bits (implementations can have fewer). The default operand size for most instructions is 32 bits. For most instructions, these defaults can be overridden on an instruction-by-instruction basis using instruction prefixes. REX prefixes specify the 64-bit operand size and register extensions. RIP-Relative Data Addressing. 64-bit mode supports data addressing relative to the 64-bit instruction pointer (RIP). The legacy x86 architecture supports IP-relative addressing only in control transfer instructions. RIP-relative addressing improves the efficiency of position-independent code and code that addresses global data. Opcodes. A few instruction opcodes and prefix bytes are redefined to allow register extensions and 64-bit addressing.

Compatibility Mode
Compatibility mode—the second submode of long mode—allows 64-bit operating systems to run existing 16-bit and 32-bit x86 applications. These legacy applications run in compatibility mode without recompilation.
Applications running in compatibility mode use 32-bit or 16-bit addressing and can access the first 4GB of virtual-address space. Legacy x86 instruction prefixes toggle between 16-bit and 32-bit address and operand sizes.
As with 64-bit mode, compatibility mode is enabled by the operating system on an individual codesegment basis. Unlike 64-bit mode, however, x86 segmentation functions the same as in the legacy x86 architecture, using 16-bit or 32-bit protected-mode semantics. From the application viewpoint, compatibility mode looks like the legacy x86 protected-mode environment. From the operatingsystem viewpoint, however, address translation, interrupt and exception handling, and system data structures use the 64-bit long-mode mechanisms.

Legacy Mode
Legacy mode preserves binary compatibility not only with existing 16-bit and 32-bit applications but also with existing 16-bit and 32-bit operating systems. Legacy mode consists of the following three submodes:
• Protected Mode—Protected mode supports 16-bit and 32-bit programs with memory segmentation, optional paging, and privilege-checking. Programs running in protected mode can access up to 4GB of memory space.
• Virtual-8086 Mode—Virtual-8086 mode supports 16-bit real-mode programs running as tasks under protected mode. It uses a simple form of memory segmentation, optional paging, and limited protection-checking. Programs running in virtual-8086 mode can access up to 1MB of memory space.
• Real Mode—Real mode supports 16-bit programs using simple register-based memory segmentation. It does not support paging or protection-checking. Programs running in real mode can access up to 1MB of memory space.
Legacy mode is compatible with existing 32-bit processor implementations of the x86 architecture. Processors that implement the AMD64 architecture boot in legacy real mode, just like processors that implement the legacy x86 architecture.
Throughout this document, references to legacy mode refer to all three submodes—protected mode, virtual-8086 mode, and real mode. If a function is specific to either of these submodes, then the name of the specific submode is used instead of the name legacy mode.

Virtual Memory
Virtual memory consists of the entire address space available to programs. It is a large linear-address space that is translated by a combination of hardware and operating-system software to a smaller physical-address space, parts of which are located in memory and parts on disk or other external storage media.
the figure below shows how the virtual-memory space is treated in the two submodes of long mode:

• 64-bit mode—This mode uses a flat segmentation model of virtual memory. The 64-bit virtualmemory space is treated as a single, flat (unsegmented) address space. Program addresses access locations that can be anywhere in the linear 64-bit address space. The operating system can use separate selectors for code, stack, and data segments for memory-protection purposes, but the base address of all these segments is always 0.
• Compatibility mode—This mode uses a protected, multi-segment model of virtual memory, just as in legacy protected mode. The 32-bit virtual-memory space is treated as a segmented set of address spaces for code, stack, and data segments, each with its own base address and protection parameters. A segmented space is specified by adding a segment selector to an address.

Home Page