Re: [tip: x86/cleanups] x86/segment: Use MOVL when reading segment registers

From: H. Peter Anvin

Date: Thu Mar 12 2026 - 15:36:07 EST


Note: I personally *hate* the savesegment() syntax. For one thing, I would
much rather see a more C-like syntax, even if that means making a bunch of
inline functions. Replacing the macro with something that is actually
type-safe would be a bloody good thing, too.

Something like:

/* Generates register operation */
static inline unsigned int ds(void)
{
unsigned int v;
asm volatile("mov %%ds,%0" : "=r" (v));
return v;
}

/* Generates memory operation */
static inline void save_ds(u16 *dst)
{
asm volatile("mov %%ds,%0" : "=m" (dst));
}

Generating those inlines can be macroized if we really feel the need to, of
course...

-hpa