Re: [PATCH] x86/boot: Do not test if AC and ID eflags are changeable on x86_64

From: Uros Bizjak
Date: Sat Mar 08 2025 - 05:13:18 EST


On Fri, Mar 7, 2025 at 3:46 PM H. Peter Anvin <hpa@xxxxxxxxx> wrote:
>
> On March 7, 2025 5:45:42 AM PST, Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
> >On Fri, Mar 7, 2025 at 2:13 PM H. Peter Anvin <hpa@xxxxxxxxx> wrote:
> >
> >> >> PUSF et al → pushf
> >> >>
> >> >> The -l and -q suffixes have been optional for a long time.
> >> >
> >> >No, not in this case. Please see the comment:
> >> >
> >> >/*
> >> >* For building the 16-bit code we want to explicitly specify 32-bit
> >> >* push/pop operations, rather than just saying 'pushf' or 'popf' and
> >> >* letting the compiler choose.
> >> >*/
> >> >
> >> >We are building 16-bit code here, and we want PUSHFL, the one with
> >> >operand size prefix 0x66.
> >> >
> >> >Please consider the following code:
> >> >
> >> > .code16
> >> > pushf
> >> > pushfl
> >> >
> >> >as -o push.o push.s
> >> >
> >> >objdump -dr -Mdata16 push.o
> >> >
> >> >0000000000000000 <.text>:
> >> > 0: 9c pushf
> >> > 1: 66 9c pushfl
> >> >
> >> >Uros.
> >> >
> >>
> >> *plonk* I should have remembered (.code16gcc is different then .code16 though.) I wrote the damned things after all...
> >
> >Please note that while "gcc -m16" emits .code16gcc, "clang -m16" emits
> >.code16, so in the latter case we don't have ‘pushf’, and ‘popf’
> >instructions default to 32-bit size. So, the only solution is to
> >decorate pushfl with operand size prefix in this specific case.
> >
> >Uros.
> >
>
> Can you please beat up the clang people who do gratuitously incompatible things like this?

:)

BTW: This patch is actually the implementation you requested at some
previous discussion [1], but I took the approach similar to the
definition of have_cpuid_p() in cpuid.h [2].

[1] https://lore.kernel.org/lkml/0A743606-067F-450C-85A5-55ECE4378E22@xxxxxxxxx/#t
[2] https://elixir.bootlin.com/linux/v6.14-rc5/source/arch/x86/include/asm/cpuid.h#L32

Uros.