Xen Test Framework
Memory operand and segment emulation

All memory operands operate through a segment.

Several factors control which segment is actually used.

  1. If the memory operand is encoded with a base register of %rbp or %rsp, the default segment is %ss. Otherwise, %ds is the default. (String instructions with two memory operands use %es for their second operand.)
  2. Instructions encoded with an explicit segment override prefix will use the specified segment for their operand. However, in 64bit mode with deprecated most of the segmentation model, the %es, %cs, %ss and %ds segment overrides are ignored and have no effect.

This test uses the fact that %ss can be distinguished from other segments because it yields #SS[0] on a segmentation fault, rather than #GP[0]. We construct a scenario in userspace which intends to suffer a segmentation based fault.

Tests are run for each explicit segment override prefix as well as no prefix, and for each memory operand encoding of a base register, as well as an absolute operand. The resulting fault is used to check that the expected segment is being used.

See also
tests/memop-seg/main.c