0001-modify-and-merge-sifive-patches-to-support-V.patch 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. From d8b1bc0917a815fdb55457ad8e1eb14d0042f469 Mon Sep 17 00:00:00 2001
  2. From: "max.ma" <max.ma@starfivetech.com>
  3. Date: Mon, 5 Sep 2022 22:03:01 -0700
  4. Subject: [PATCH 01/19] modify &and merge sifive patches to support V
  5. ---
  6. sysdeps/riscv/Makefile | 5 +++
  7. .../unix/sysv/linux/riscv/bits/sigcontext.h | 31 --------------
  8. sysdeps/unix/sysv/linux/riscv/getcontext.S | 24 ++++++++++-
  9. sysdeps/unix/sysv/linux/riscv/setcontext.S | 22 ++++++++++
  10. sysdeps/unix/sysv/linux/riscv/swapcontext.S | 41 +++++++++++++++++++
  11. sysdeps/unix/sysv/linux/riscv/sys/ucontext.h | 2 +
  12. sysdeps/unix/sysv/linux/riscv/sysdep.h | 1 +
  13. sysdeps/unix/sysv/linux/riscv/ucontext_i.sym | 5 +++
  14. 8 files changed, 98 insertions(+), 33 deletions(-)
  15. delete mode 100644 sysdeps/unix/sysv/linux/riscv/bits/sigcontext.h
  16. diff --git a/sysdeps/riscv/Makefile b/sysdeps/riscv/Makefile
  17. index 8fb10b164f..e2d84640d4 100644
  18. --- a/sysdeps/riscv/Makefile
  19. +++ b/sysdeps/riscv/Makefile
  20. @@ -2,6 +2,11 @@ ifeq ($(subdir),misc)
  21. sysdep_headers += sys/asm.h
  22. endif
  23. +ifeq ($(subdir),csu)
  24. +# get offset to rtld_global._dl_hwcap and rtld_global._dl_hwcap2.
  25. +gen-as-const-headers += rtld-global-offsets.sym
  26. +endif
  27. +
  28. # RISC-V's assembler also needs to know about PIC as it changes the definition
  29. # of some assembler macros.
  30. ASFLAGS-.os += $(pic-ccflag)
  31. diff --git a/sysdeps/unix/sysv/linux/riscv/bits/sigcontext.h b/sysdeps/unix/sysv/linux/riscv/bits/sigcontext.h
  32. deleted file mode 100644
  33. index b6e15b5f62..0000000000
  34. --- a/sysdeps/unix/sysv/linux/riscv/bits/sigcontext.h
  35. +++ /dev/null
  36. @@ -1,31 +0,0 @@
  37. -/* Machine-dependent signal context structure for Linux. RISC-V version.
  38. - Copyright (C) 1996-2022 Free Software Foundation, Inc. This file is part of the GNU C Library.
  39. -
  40. - The GNU C Library is free software; you can redistribute it and/or
  41. - modify it under the terms of the GNU Lesser General Public
  42. - License as published by the Free Software Foundation; either
  43. - version 2.1 of the License, or (at your option) any later version.
  44. -
  45. - The GNU C Library is distributed in the hope that it will be useful,
  46. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  47. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  48. - Lesser General Public License for more details.
  49. -
  50. - You should have received a copy of the GNU Lesser General Public
  51. - License along with the GNU C Library. If not, see
  52. - <https://www.gnu.org/licenses/>. */
  53. -
  54. -#ifndef _BITS_SIGCONTEXT_H
  55. -#define _BITS_SIGCONTEXT_H 1
  56. -
  57. -#if !defined _SIGNAL_H && !defined _SYS_UCONTEXT_H
  58. -# error "Never use <bits/sigcontext.h> directly; include <signal.h> instead."
  59. -#endif
  60. -
  61. -struct sigcontext {
  62. - /* gregs[0] holds the program counter. */
  63. - unsigned long int gregs[32];
  64. - unsigned long long int fpregs[66] __attribute__ ((__aligned__ (16)));
  65. -};
  66. -
  67. -#endif
  68. diff --git a/sysdeps/unix/sysv/linux/riscv/getcontext.S b/sysdeps/unix/sysv/linux/riscv/getcontext.S
  69. index 499f70b65d..371ebd52a7 100644
  70. --- a/sysdeps/unix/sysv/linux/riscv/getcontext.S
  71. +++ b/sysdeps/unix/sysv/linux/riscv/getcontext.S
  72. @@ -16,6 +16,8 @@
  73. License along with the GNU C Library. If not, see
  74. <https://www.gnu.org/licenses/>. */
  75. +#include <sysdep.h>
  76. +#include <rtld-global-offsets.h>
  77. #include "ucontext-macros.h"
  78. /* int getcontext (ucontext_t *ucp) */
  79. @@ -39,6 +41,25 @@ LEAF (__getcontext)
  80. SAVE_INT_REG (s10, 26, a0)
  81. SAVE_INT_REG (s11, 27, a0)
  82. +#ifdef __riscv_vector
  83. +# ifdef SHARED
  84. + la t1, _rtld_global_ro
  85. + REG_L t1, RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(t1)
  86. +# else
  87. + la t1, _dl_hwcap
  88. + REG_L t1, (t1)
  89. +# endif
  90. + li t2, HWCAP_ISA_V
  91. + and t2, t1, t2
  92. + beqz t2, 1f
  93. + addi t2, a0, MCONTEXT_EXTENSION
  94. + li t1, RVV_MAGIC
  95. + sw t1, (t2)
  96. + csrr t1, vcsr
  97. + REG_S t1, VCSR_OFFSET(t2)
  98. +1:
  99. +#endif
  100. +
  101. #ifndef __riscv_float_abi_soft
  102. frsr a1
  103. @@ -73,5 +94,4 @@ LEAF (__getcontext)
  104. 99: j __syscall_error
  105. PSEUDO_END (__getcontext)
  106. -
  107. -weak_alias (__getcontext, getcontext)
  108. +weak_alias (__getcontext, getcontext)
  109. \ No newline at end of file
  110. diff --git a/sysdeps/unix/sysv/linux/riscv/setcontext.S b/sysdeps/unix/sysv/linux/riscv/setcontext.S
  111. index e3bc84a2e6..423d94df27 100644
  112. --- a/sysdeps/unix/sysv/linux/riscv/setcontext.S
  113. +++ b/sysdeps/unix/sysv/linux/riscv/setcontext.S
  114. @@ -16,6 +16,8 @@
  115. License along with the GNU C Library. If not, see
  116. <https://www.gnu.org/licenses/>. */
  117. +#include <sysdep.h>
  118. +#include <rtld-global-offsets.h>
  119. #include "ucontext-macros.h"
  120. /* int __setcontext (const ucontext_t *ucp)
  121. @@ -64,6 +66,26 @@ LEAF (__setcontext)
  122. fssr t1
  123. #endif /* __riscv_float_abi_soft */
  124. +#ifdef __riscv_vector
  125. +#ifdef SHARED
  126. + la t1, _rtld_global_ro
  127. + REG_L t1, RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(t1)
  128. +#else
  129. + la t1, _dl_hwcap
  130. + REG_L t1, (t1)
  131. +#endif
  132. + li t2, HWCAP_ISA_V
  133. + and t2, t1, t2
  134. + beqz t2, 1f
  135. + li t1, RVV_MAGIC
  136. + addi t2, t0, MCONTEXT_EXTENSION
  137. + lw a1, (t2)
  138. + bne a1, t1, 1f
  139. + REG_L t1, VCSR_OFFSET(t2)
  140. + csrw vcsr, t1
  141. +1:
  142. +#endif
  143. +
  144. /* Note the contents of argument registers will be random
  145. unless makecontext() has been called. */
  146. RESTORE_INT_REG (t1, 0, t0)
  147. diff --git a/sysdeps/unix/sysv/linux/riscv/swapcontext.S b/sysdeps/unix/sysv/linux/riscv/swapcontext.S
  148. index 4da615f6d4..16600f78df 100644
  149. --- a/sysdeps/unix/sysv/linux/riscv/swapcontext.S
  150. +++ b/sysdeps/unix/sysv/linux/riscv/swapcontext.S
  151. @@ -16,6 +16,8 @@
  152. License along with the GNU C Library. If not, see
  153. <https://www.gnu.org/licenses/>. */
  154. +#include <sysdep.h>
  155. +#include <rtld-global-offsets.h>
  156. #include "ucontext-macros.h"
  157. /* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
  158. @@ -40,6 +42,25 @@ LEAF (__swapcontext)
  159. SAVE_INT_REG (s10, 26, a0)
  160. SAVE_INT_REG (s11, 27, a0)
  161. +#ifdef __riscv_vector
  162. +#ifdef SHARED
  163. + la t1, _rtld_global_ro
  164. + REG_L t1, RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(t1)
  165. +#else
  166. + la t1, _dl_hwcap
  167. + REG_L t1, (t1)
  168. +#endif
  169. + li t2, HWCAP_ISA_V
  170. + and t2, t1, t2
  171. + beqz t2, 1f
  172. + addi t2, a0, MCONTEXT_EXTENSION
  173. + li t1, RVV_MAGIC
  174. + sw t1, (t2)
  175. + csrr t1, vcsr
  176. + REG_S t1, VCSR_OFFSET(t2)
  177. +1:
  178. +#endif
  179. +
  180. #ifndef __riscv_float_abi_soft
  181. frsr a1
  182. @@ -89,6 +110,26 @@ LEAF (__swapcontext)
  183. fssr t1
  184. #endif /* __riscv_float_abi_soft */
  185. +#ifdef __riscv_vector
  186. +#ifdef SHARED
  187. + la t1, _rtld_global_ro
  188. + REG_L t1, RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(t1)
  189. +#else
  190. + la t1, _dl_hwcap
  191. + REG_L t1, (t1)
  192. +#endif
  193. + li t2, HWCAP_ISA_V
  194. + and t2, t1, t2
  195. + beqz t2, 1f
  196. + li t1, RVV_MAGIC
  197. + addi t2, t0, MCONTEXT_EXTENSION
  198. + lw a1, (t2)
  199. + bne a1, t1, 1f
  200. + REG_L t1, VCSR_OFFSET(t2)
  201. + csrw vcsr, t1
  202. +1:
  203. +#endif
  204. +
  205. /* Note the contents of argument registers will be random
  206. unless makecontext() has been called. */
  207. RESTORE_INT_REG (t1, 0, t0)
  208. diff --git a/sysdeps/unix/sysv/linux/riscv/sys/ucontext.h b/sysdeps/unix/sysv/linux/riscv/sys/ucontext.h
  209. index e226ee85ee..1b370f0f45 100644
  210. --- a/sysdeps/unix/sysv/linux/riscv/sys/ucontext.h
  211. +++ b/sysdeps/unix/sysv/linux/riscv/sys/ucontext.h
  212. @@ -82,6 +82,8 @@ typedef struct mcontext_t
  213. {
  214. __riscv_mc_gp_state __gregs;
  215. union __riscv_mc_fp_state __fpregs;
  216. + /* 5K + 256 reserved for vector state and future expansion. */
  217. + unsigned char __reserved[5376] __attribute__ ((__aligned__ (16)));
  218. } mcontext_t;
  219. /* Userlevel context. */
  220. diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h
  221. index 37ff07a0d7..c9f8fd8236 100644
  222. --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h
  223. +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h
  224. @@ -50,6 +50,7 @@
  225. #ifdef __ASSEMBLER__
  226. +# include <bits/hwcap.h>
  227. # include <sys/asm.h>
  228. # define ENTRY(name) LEAF(name)
  229. diff --git a/sysdeps/unix/sysv/linux/riscv/ucontext_i.sym b/sysdeps/unix/sysv/linux/riscv/ucontext_i.sym
  230. index be55b26310..b91945a080 100644
  231. --- a/sysdeps/unix/sysv/linux/riscv/ucontext_i.sym
  232. +++ b/sysdeps/unix/sysv/linux/riscv/ucontext_i.sym
  233. @@ -2,6 +2,7 @@
  234. #include <signal.h>
  235. #include <stddef.h>
  236. #include <sys/ucontext.h>
  237. +#include <asm/sigcontext.h>
  238. -- Constants used by the rt_sigprocmask call.
  239. @@ -27,5 +28,9 @@ STACK_FLAGS stack (ss_flags)
  240. MCONTEXT_GREGS mcontext (__gregs)
  241. MCONTEXT_FPREGS mcontext (__fpregs)
  242. +MCONTEXT_EXTENSION mcontext (__reserved)
  243. UCONTEXT_SIZE sizeof (ucontext_t)
  244. +VCSR_OFFSET offsetof (struct __riscv_v_state, vcsr)
  245. +
  246. +RVV_MAGIC
  247. --
  248. 2.25.1