Instruction
ERETU
Returns from a FRED event handler in ring 0 to ring 3, restoring the user context from the stack and swapping the GS base with IA32_KERNEL_GS_BASE.
- Extensions
- Forms
- 1 (1 Legacy)
- Data
- Intel XED v2026.08.23
ERETU is the way back to user mode when FRED is enabled. It expects RSP to point at the frame that FRED event delivery pushed, skips the error code, and restores RIP, CS, RFLAGS, RSP and SS from it, loading CS and SS for ring 3 based on IA32_STAR. It also swaps the GS base with IA32_KERNEL_GS_BASE, undoing the swap made on entry.
It works only at privilege level 0 with FRED enabled (#UD otherwise), and only at stack level 0 (#GP otherwise). With supervisor shadow stacks enabled it also checks the shadow-stack pointers. ERETS is the counterpart for events that happened in the kernel: it returns within ring 0 and leaves CS, SS and GS alone.
Forms
| Instruction | Encoding | Requires |
|---|---|---|
ERETU 64-bit mode only
ERETU | F3 0F 01 CA | FRED |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
if not cr4 >> 32 & 1 or CPL > 0:
fault(UD) # FRED off, or CPL 3: #UD, not #GP
if msr[0x1D4] & 3:
fault(GP, 0) # from stack level 0 only
t = load(rsp + 8, 64) # RIP; the error code is skipped
c = load(rsp + 16, 64) # CS
f = load(rsp + 24, 64) # RFLAGS
p = load(rsp + 32, 64) # RSP
s = load(rsp + 40, 64) # SS, bits 18:16 event state
if c & 0xFFFFFFFFFFFF0003 != 3:
fault(GP, 0) # to CPL 3, no other bits
if f & 0xFFFFFFFFFFC2B02A != 2:
fault(GP, 0) # bit 1 set; IOPL, VM and reserved
# bits clear
if s & 0xFFF80003 != 3:
fault(GP, 0)
u = star >> 48 # STAR[63:48], SYSRET's selectors
c &= 0xFFFF
s &= 0xFFFF
if c == u + 16 and s == u + 8:
wide = 1 # 64-bit code, flat, as SYSRET has it
elif c == u and s == u + 8:
wide = 0 # 32-bit code, flat
else:
d = descriptor(c) # any other: both descriptors read
wide = d >> 53 & 1 # and checked as IRET checks them
if wide and not canonical(t):
fault(GP, 0)
if not wide:
t &= 0xFFFFFFFF # to compatibility mode: 32 bits,
p &= 0xFFFFFFFF # within CS's limit
rip = t
rsp = p
cs = c # CPL 3
ss = s
cf = f & 1
pf = f >> 2 & 1
af = f >> 4 & 1
zf = f >> 6 & 1
sf = f >> 7 & 1
tf = f >> 8 & 1
if_ = f >> 9 & 1
df = f >> 10 & 1
of = f >> 11 & 1
iopl = f >> 12 & 3 # 0, as checked
nt = f >> 14 & 1
rf = f >> 16 & 1 # RF may come back set
vm = f >> 17 & 1 # 0, as checked
ac = f >> 18 & 1
vif = f >> 19 & 1
vip = f >> 20 & 1
id = f >> 21 & 1
k = kernel_gs_base # GS's base swapped, as SWAPGS does
kernel_gs_base = gsbase
gsbase = k
# SS bit 17: a pending single-step #DB, if TF is set; bit 18: NMIs
# unblocked. With shadow stacks, SSP comes from IA32_PL3_SSPNot run on a processor: the Zen 5 guest that ran the probe does not report FRED in CPUID.
Operands
| Operand | Kind | Action |
|---|---|---|
ERETU 64-bit mode only | ||
stack | implicit | read |
rSP | implicit | read, write |
CS | implicit | write |
SS | implicit | write |
RIP | implicit | write |
RSP | implicit | write |
GS base | implicit | write |
IA32_KERNEL_GS_BASE | implicit | write |
RFLAGS | implicit | write |
Flags
| OF | SF | ZF | AF | PF | CF | DF | IF | TF | AC | IOPL | NT | RF | VM | VIF | VIP | ID |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| All forms | ||||||||||||||||
| P | P | P | P | P | P | P | P | P | P | P | P | P | P | P | P | P |
Attributes
What else XED records about the forms. How to read.
- All forms
- privileged: CPL 0 only; may abort a TSX transaction
CPUID and processors
Each form belongs to an XED ISA set. A form can be used when the processor reports every CPUID bit of one of its ISA set's alternatives.
| ISA set | CPUID | Processors |
|---|---|---|
FRED | FRED | Panther Lake, Nova Lake, Diamond Rapids, Zen 6 |
More FRED instructions
Sources
- Intel XED v2026.08.23 (commit
0bcb6237345c): forms, encodings, operands, flags, exception classes, attributes, ISA sets, CPUID bits and chip model. - The CPU data of x86-64.net: Zen 3 to Zen 6, from GCC’s
-marchfeature sets and AMD’s Processor Programming References, which the page of each processor cites. - Flexible Return and Event Delivery (FRED) Specification (346446-009)
- Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2A, page 3-301 (ERETU)
- Linux kernel documentation: Flexible Return and Event Delivery (FRED)
The tables are derived from Intel XED, Copyright Intel Corporation, licensed under the Apache License 2.0; x86-64.net converted and reformatted them. The text is our own.