13.07.2015 Views

Volume 3: General-Purpose and System Instructions - Stanford ...

Volume 3: General-Purpose and System Instructions - Stanford ...

Volume 3: General-Purpose and System Instructions - Stanford ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

24594 Rev. 3.10 February 2005 AMD64 TechnologySYSRETFast <strong>System</strong> ReturnReturns from the operating system to an application. It is a low-latency system returninstruction designed for use by system <strong>and</strong> application software implementing a flatsegmentation memory model.The SYSCALL <strong>and</strong> SYSRET instructions are low-latency system call <strong>and</strong> returncontrol-transfer instructions that assume that the operating system implements a flatsegmentmemory model. By eliminating unneeded checks, <strong>and</strong> by loading predeterminedvalues into the CS <strong>and</strong> SS segment registers (both visible <strong>and</strong> hiddenportions), calls to <strong>and</strong> returns from the operating system are greatly simplified. Theseinstructions can be used in protected mode <strong>and</strong> are particularly well-suited for use in64-bit mode, which requires implementation of a paged, flat-segment memory model.This instruction has been optimized by reducing the number of checks <strong>and</strong> memoryreferences that are normally made so that a call or return takes substantially fewerinternal clock cycles when compared to the CALL/RET instruction method.It is assumed that the base, limit, <strong>and</strong> attributes of the Code Segment will remain flatfor all processes <strong>and</strong> for the operating system, <strong>and</strong> that only the current privilege levelfor the selector of the calling process should be changed from a current privilege levelof 0 to a new privilege level of 3. It is also assumed (but not checked) that the RPL ofthe SYSCALL <strong>and</strong> SYSRET target selectors are set to 0 <strong>and</strong> 3, respectively.SYSRET sets the CPL to 3, regardless of the values of bits 49–48 of the star register.SYSRET can only be executed in protected mode at CPL 0. SYSCALL <strong>and</strong> SYSRETmust be enabled by setting EFER.SCE to 1.It is the responsibility of the operating system to keep the descriptors in memory thatcorrespond to the CS <strong>and</strong> SS selectors loaded by the SYSCALL <strong>and</strong> SYSRETinstructions consistent with the segment base, limit, <strong>and</strong> attribute values forced bythese instructions.When a system procedure performs a SYSRET back to application software, the CSselector is updated from bits 63–50 of the STAR register (STAR.SYSRET_CS) asfollows:• If the return is to 32-bit mode (legacy or compatibility), CS is updated with thevalue of STAR.SYSRET_CS.• If the return is to 64-bit mode, CS is updated with the value of STAR.SYSRET_CS+ 16.SYSRET 363

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!