glibc/sysdeps/unix/sysv/linux/or1k/setcontext-common.S
Stafford Horne 643d9d38d5 or1k: Add hard float support
This patch adds hardware floating point support to OpenRISC.  Hardware
floating point toolchain builds are enabled by passing the machine
specific argument -mhard-float to gcc via CFLAGS.  With this enabled GCC
generates floating point instructions for single-precision operations
and exports __or1k_hard_float__.

There are 2 main parts to this patch.

 - Implement fenv functions to update the FPCSR flags keeping it in sync
   with sfp (software floating point).
 - Update machine context functions to store and restore the FPCSR
   state.

*On mcontext_t ABI*

This patch adds __fpcsr to mcontext_t.  This is an ABI change, but also
an ABI fix.  The Linux kernel has always defined padding in mcontext_t
that space was missing from the glibc ABI.  In Linux this unused space
has now been re-purposed for storing the FPCSR.  This patch brings
OpenRISC glibc in line with the Linux kernel and other libc
implementation (musl).

Compatibility getcontext, setcontext, etc symbols have been added to
allow for binaries expecting the old ABI to continue to work.

*Hard float ABI*

The calling conventions and types do not change with OpenRISC hard-float
so glibc hard-float builds continue to use dynamic linker
/lib/ld-linux-or1k.so.1.

*Testing*

I have tested this patch both with hard-float and soft-float builds and
the test results look fine to me.  Results are as follows:

Hard Float

    # failures
    FAIL: elf/tst-sprof-basic		(Haven't figured out yet, not related to hard-float)
    FAIL: gmon/tst-gmon-pie		(PIE bug in or1k toolchain)
    FAIL: gmon/tst-gmon-pie-gprof	(PIE bug in or1k toolchain)
    FAIL: iconvdata/iconv-test		(timeout, passed when run manually)
    FAIL: nptl/tst-cond24		(Timeout)
    FAIL: nptl/tst-mutex10		(Timeout)

    # summary
	  6 FAIL
       4289 PASS
	 86 UNSUPPORTED
	 16 XFAIL
	  2 XPASS

    # versions
    Toolchain: or1k-smhfpu-linux-gnu
    Compiler:  gcc version 14.0.1 20240324 (experimental) [master r14-9649-gbb04a11418f] (GCC)
    Binutils:  GNU assembler version 2.42.0 (or1k-smhfpu-linux-gnu) using BFD version (GNU Binutils) 2.42.0.20240324
    Linux:     Linux buildroot 6.9.0-rc1-00008-g4dc70e1aadfa #112 SMP Sat Apr 27 06:43:11 BST 2024 openrisc GNU/Linux
    Tester:    shorne
    Glibc:     2024-04-25 b62928f907 Florian Weimer   x86: In ld.so, diagnose missing APX support in APX-only builds  (origin/master, origin/HEAD)

Soft Float

    # failures
    FAIL: elf/tst-sprof-basic
    FAIL: gmon/tst-gmon-pie
    FAIL: gmon/tst-gmon-pie-gprof
    FAIL: nptl/tst-cond24
    FAIL: nptl/tst-mutex10

    # summary
	  5 FAIL
       4295 PASS
	 81 UNSUPPORTED
	 16 XFAIL
	  2 XPASS

    # versions
    Toolchain: or1k-smh-linux-gnu
    Compiler:  gcc version 14.0.1 20240324 (experimental) [master r14-9649-gbb04a11418f] (GCC)
    Binutils:  GNU assembler version 2.42.0 (or1k-smh-linux-gnu) using BFD version (GNU Binutils) 2.42.0.20240324
    Linux:     Linux buildroot 6.9.0-rc1-00008-g4dc70e1aadfa #112 SMP Sat Apr 27 06:43:11 BST 2024 openrisc GNU/Linux
    Tester:    shorne
    Glibc:     2024-04-25 b62928f907 Florian Weimer   x86: In ld.so, diagnose missing APX support in APX-only builds  (origin/master, origin/HEAD)

Documentation: https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.4-rev0.pdf
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2024-05-03 18:28:18 +01:00

120 lines
3.8 KiB
ArmAsm

/* Set current context. OpenRISC common version.
Copyright (C) 2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
/* This common setcontext and startcontext template helps define
different implementations using control macros. Before including
this file in another file define the following:
__CONTEXT_FUNC_NAME
__CONTEXT_ENABLE_FPCSR
__CONTEXT_SIGMASK_OFFSET
__STARTCONTEXT_FUNC_NAME
*/
/* int setcontext (const ucontext_t *ucp) */
.text
ENTRY(__CONTEXT_FUNC_NAME)
l.ori r30, r3, 0
/* Restore signal mask. */
/* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
l.ori r6, r0, _NSIG8
l.ori r5, r0, 0
l.addi r4, r3, __CONTEXT_SIGMASK_OFFSET
l.ori r3, r0, SIG_SETMASK
l.ori r11, r0, SYS_ify (rt_sigprocmask)
/* Do the syscall. */
l.sys 1
l.nop
/* if -4096 < ret < 0 holds, it's an error */
l.sfgeui r11, 0xf001
l.bf 1f
l.nop
#ifdef __CONTEXT_ENABLE_FPCSR
# ifdef __or1k_hard_float__
/* Restore the floating point state. */
l.lwz r28, (MCONTEXT_FPCSR)(r30)
l.mtspr r0, r28, 20
# endif /* __or1k_hard_float__ */
#endif /* __CONTEXT_ENABLE_FPCSR */
/* Restore argument registers, for the makecontext case. */
l.lwz r3, (UCONTEXT_MCONTEXT + 3*4)(r30)
l.lwz r4, (UCONTEXT_MCONTEXT + 4*4)(r30)
l.lwz r5, (UCONTEXT_MCONTEXT + 5*4)(r30)
l.lwz r6, (UCONTEXT_MCONTEXT + 6*4)(r30)
l.lwz r7, (UCONTEXT_MCONTEXT + 7*4)(r30)
l.lwz r8, (UCONTEXT_MCONTEXT + 8*4)(r30)
/* Restore registers stored in getcontext. */
l.lwz r1, (UCONTEXT_MCONTEXT + 1*4)(r30)
l.lwz r2, (UCONTEXT_MCONTEXT + 2*4)(r30)
l.lwz r9, (UCONTEXT_MCONTEXT + 9*4)(r30)
l.lwz r10, (UCONTEXT_MCONTEXT + 10*4)(r30)
l.lwz r11, (UCONTEXT_MCONTEXT + 11*4)(r30)
/* Restore r14-r30 even, callee saved registers. */
l.lwz r14, (UCONTEXT_MCONTEXT + 14*4)(r30)
l.lwz r16, (UCONTEXT_MCONTEXT + 16*4)(r30)
l.lwz r18, (UCONTEXT_MCONTEXT + 18*4)(r30)
l.lwz r20, (UCONTEXT_MCONTEXT + 20*4)(r30)
l.lwz r22, (UCONTEXT_MCONTEXT + 22*4)(r30)
l.lwz r24, (UCONTEXT_MCONTEXT + 24*4)(r30)
l.lwz r26, (UCONTEXT_MCONTEXT + 26*4)(r30)
l.lwz r28, (UCONTEXT_MCONTEXT + 28*4)(r30)
l.lwz r30, (UCONTEXT_MCONTEXT + 30*4)(r30)
l.jr r11
l.ori r11, r0, 0
1: l.j __syscall_error
l.ori r3, r11, 0
END (__CONTEXT_FUNC_NAME)
/* We add a NOP here because when the unwinder is looking for the
enclosing function of the link register (r9) address FDE lookup will
use '$r9 - 1' finding setcontext which is wrong. This is because in
makecontext we have set r9 to the start of &__startcontext.
If this NOP did not exist the unwinder would repeatedly find
__setcontext's FDE in an infinite loop. Modifying/deleting the below
__startcontext's FDE has no help on this. */
l.nop
ENTRY(__STARTCONTEXT_FUNC_NAME)
l.ori r3, r14, 0
l.sfeq r3, r0
/* If uc_link is not 0 resume there, otherwise exit. */
l.bnf __CONTEXT_FUNC_NAME
l.nop
#ifdef SHARED
/* Obtain a pointer to .got in r16 */
l.jal 0x8
l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
l.add r16, r16, r9
l.lwz r16, got(exit)(r16)
l.jr r16
#else
l.j exit
#endif
l.nop
END(__STARTCONTEXT_FUNC_NAME)