Build issue "Error: operands mismatch -- statement `movec %d2,%caar' ignored" on m68k
Hello,
While trying to build the multi_defconfig, from Linux 6.12.5, for a 68040 system, the build fails with:
{standard input}: Assembler messages:
{standard input}:104: Error: operands mismatch -- statement `movec %d2,%caar' ignored make[5]: *** [scripts/Makefile.build:229: arch/m68k/kernel/sys_m68k.o] Error 1
It seems like the 68020/68030 code:
if (CPU_IS_020_OR_030) {
if (scope == FLUSH_SCOPE_LINE && len < 256) {
unsigned long cacr;
__asm__ ("movec %%cacr, %0" : "=r" (cacr));
if (cache & FLUSH_CACHE_INSN)
cacr |= 4;
if (cache & FLUSH_CACHE_DATA)
cacr |= 0x400;
len >>= 2;
while (len--) {
__asm__ __volatile__ ("movec %1, %%caar\n\t"
"movec %0, %%cacr"
: /* no outputs */
: "r" (cacr), "r" (addr));
addr += 4;
}
} else {
/* Flush the whole cache, even if page granularity requested. */
unsigned long cacr;
__asm__ ("movec %%cacr, %0" : "=r" (cacr));
if (cache & FLUSH_CACHE_INSN)
cacr |= 8;
if (cache & FLUSH_CACHE_DATA)
cacr |= 0x800;
__asm__ __volatile__ ("movec %0, %%cacr" : : "r" (cacr));
}
ret = 0;
goto out_unlock;gets compiled in, and binutils isn't happy about it.
The issue can trivially be reproduced by building the following Buildroot configuration:
BR2_m68k=y
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y
Quick recipe:
$ git clone https://gitlab.com/buildroot.org/buildroot.git $ cd buildroot/ $ cat >.config <<EOF BR2_m68k=y BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y EOF $ make olddefconfig $ make
Is this expected?
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com
Hi Thomas,
Quoted 6 lines · Thomas Petazzoni
While trying to build the
multi_defconfig, from Linux 6.12.5, for a 68040 system, the build fails with:{standard input}: Assembler messages:
{standard input}:104: Error: operands mismatch -- statement `movec %d2,%caar' ignored make[5]: *** [scripts/Makefile.build:229:arch/m68k/kernel/sys_m68k.o] Error 1
That's not the only error:
{standard input}: Assembler messages:
{standard input}:17: Error: invalid instruction for this architecture; needs M68K mmu (68020 [68k, 68ec020], 68030 [68ec030], 68040 [68ec040], 68060 [68ec060]) -- statement `pflusha' ignored make[5]: *** [scripts/Makefile.build:229: arch/m68k/mm/kmap.o] Error 1
There are more like the above, but at least these tell you what's the underlying problem: the cross-compiler does not seem to support real m68k CPUs. Interestingly, it was built with --with-cpu=68040...
Also:
cat > /tmp/a.s <<EOF
movec %d2,%caar
EOF
output/host/bin/m68k-buildroot-linux-gnu-as /tmp/a.sdoes build.
output/host/bin/m68k-buildroot-linux-gnu-gcc -c /tmp/a.s
does not.
With plain m68k-linux-gnu-{as,gcc} (Ubuntu 13.3.0-6ubuntu2~24.04, which is also 13.3.0, just like the buildroot toolchain), both work.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 8 lines · Geert Uytterhoeven
output/host/bin/m68k-buildroot-linux-gnu-as
/tmp/a.sdoes build.
output/host/bin/m68k-buildroot-linux-gnu-gcc -c
/tmp/a.sdoes not.
You may want to try,
$ output/host/bin/m68k-buildroot-linux-gnu-gcc -v -c /tmp/a.s
As that will print the full assembler command line, among other things. E.g.
.../usr/libexec/gcc/m68k-unknown-linux-musl/as -v -mcpu=68020 --pcrel -o a.o a.s
Hi Finn,
Quoted 9 lines · Finn Thain
You may want to try,
$ output/host/bin/m68k-buildroot-linux-gnu-gcc -v -c /tmp/a.sAs that will print the full assembler command line, among other things. E.g.
...
/usr/libexec/gcc/m68k-unknown-linux-musl/as-v -mcpu=68020 --pcrel -o a.o a.s
Thanks, so it fails when -mcpu=68040 is passed to the assembler.
Oh, I misread "caar" as "cacr". The latter exists on MC68040, the former does not. However, that doesn't explain the failures for pflusha, which is supported on 68040.
After disabling CONFIG_680[236]0 in the kernel config, I can build it fine using the buildroot toolchain.
Conclusion: make sure your toolchain supports (a superset of) the CPUs supported by your kernel config.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Hello Geert,
Quoted 8 lines · On Mon, 30 Dec 2024 09:53:29 +0100 Geert Uytterhoeven <[email protected]>…
Quoted 1 line
/usr/libexec/gcc/m68k-unknown-linux-musl/as-v -mcpu=68020 --pcrel -o a.o a.sThanks, so it fails when -mcpu=68040 is passed to the assembler.
Oh, I misread "caar" as "cacr". The latter exists on MC68040, the former does not. However, that doesn't explain the failures for pflusha, which is supported on 68040.
Quoted 5 lines
After disabling CONFIG_680[236]0 in the kernel config, I can build it fine using the buildroot toolchain.
Conclusion: make sure your toolchain supports (a superset of) the CPUs supported by your kernel config.
Thanks for the investigation. How should the toolchain be configured to s upport multiple m68k CPUs? My understanding was that when you configure gcc with --with-cpu=<something>, it means gcc will by default emit code for <something>, but it can always be overridden when running gcc using -mcpu=<somethingelse>.
How can one build this kernel/sys_m68k.c file if it uses instructions that are mutually incompatible on different m68k cores?
Thomas
Signature · 3 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com
Hi Thomas,
Quoted 14 lines · Thomas Petazzoni
Quoted 11 lines · On Mon, 30 Dec 2024 09:53:29 +0100 Geert Uytterhoeven <[email protected]>…
Quoted 1 line
/usr/libexec/gcc/m68k-unknown-linux-musl/as-v -mcpu=68020 --pcrel -o a.o a.sThanks, so it fails when -mcpu=68040 is passed to the assembler.
Oh, I misread "caar" as "cacr". The latter exists on MC68040, the former does not. However, that doesn't explain the failures for pflusha, which is supported on 68040.
After disabling CONFIG_680[236]0 in the kernel config, I can build it fine using the buildroot toolchain.
Quoted 8 lines
Quoted 2 lines
Conclusion: make sure your toolchain supports (a superset of) the CPUs supported by your kernel config.
Thanks for the investigation. How should the toolchain be configured to s upport multiple m68k CPUs? My understanding was that when you configure gcc with --with-cpu=<something>, it means gcc will by default emit code for <something>, but it can always be overridden when running gcc using -mcpu=<somethingelse>.
Sorry, it's been ages since I built my own cross-compiler. IIRC, I always used the default, which gives a compiler targeting all (non-Coldfire) variants.
The GCC documentation seems to be ambiguous
(https://gcc.gnu.org/install/configure.html):
Example 1: to configure a compiler for SH4A only, but supporting
both endians, with little endian being the default:
--with-cpu=sh4a --with-endian=little,big --with-multilib-list=
vs.
--with-cpu=cpu
--with-cpu-32=cpu
--with-cpu-64=cpu
Specify which cpu variant the compiler should generate codefor by default
Quoted 2 lines
How can one build this
kernel/sys_m68k.cfile if it uses instructions that are mutually incompatible on different m68k cores?
Each of the CPU-specific sections depends on CPU_IS_*(), which expand to compile-time and/or run-time checks for the CPU type, depending on which CONFIG_680*0 kernel config options are set.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 2 lines · Geert Uytterhoeven
Conclusion: make sure your toolchain supports (a superset of) the CPUs supported by your kernel config.
Conclusion: always use .chip directives.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."