Re: [PATCH 3/3] sparc32: emulate integer divide taken as illegal_instruction

From: Magnus Lindholm

Date: Sun Sep 27 2026 - 17:26:11 EST


Hi Imre,

Great to see some activity on sparc32, thanks for taking the time to do this.

On Sun, Sep 27, 2026 at 2:59 AM Imre Kaloz <kaloz@xxxxxxxxxx> wrote:
>
> SuperSPARC and SuperSPARC-II implement a 52-bit by 32-bit integer divide
> and raise illegal_instruction for udiv and sdiv when the 64-bit dividend
> {Y, rs1} has significant bits above bit 51, as the SuperSPARC II
> Addendum documents, so whether a divide traps depends on its operands.
> gcc emits udiv under -mcpu=v8, including in libgcc's __udivdi3, so
> 64-bit division in user code on these CPUs dies with SIGILL.
>
> Complete udiv and sdiv, and their -cc forms, from
> do_illegal_instruction(), sharing the windowed-operand helpers with the
> casa emulation. A CPU that executes the instruction never reaches the
> handler, nor does a kernel-mode illegal instruction. A fault reading a
> windowed operand raises SIGSEGV, as the casa emulation does. On overflow
> the quotient saturates to 0xffffffff for udiv and to 0x7fffffff or
> 0x80000000 for sdiv, and the -cc forms set V, as the architecture
> specifies.
>
> Signed-off-by: Imre Kaloz <kaloz@xxxxxxxxxx>

I stumbled upon the same issue trying to boot Linux on my SPARCstation, and
posted a fix for it on the 24th, same diagnosis, same saturating quotient and
condition-code handling, same window-flush-then-fetch structure:

https://lore.kernel.org/sparclinux/20260924205646.870950-1-linmag7@xxxxxxxxx/

Yours factors the windowed-operand helpers into div_emu_32.c so the casa
emulation can share them; mine keeps it in traps_32.c. Either does the job, so
I'll leave it to the maintainers which they'd rather take.

Regards

Magnus