0006-RISC-V-Add-zifencei-and-prefixed-h-class-extensions.patch 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. From a091f66f69e2f7b4c029c73edd2a031045a106d8 Mon Sep 17 00:00:00 2001
  2. From: Nelson Chu <nelson.chu@sifive.com>
  3. Date: Fri, 20 Nov 2020 15:35:17 +0800
  4. Subject: [PATCH 06/48] RISC-V: Add zifencei and prefixed h class extensions.
  5. bfd/
  6. * elfxx-riscv.c (riscv_parse_std_ext): Stop parsing standard
  7. extensions when parsed h keyword.
  8. (riscv_get_prefix_class): Support prefixed h class.
  9. (riscv_std_h_ext_strtab): Likewise.
  10. (riscv_ext_h_valid_p): Likewise.
  11. (parse_config): Likewise.
  12. (riscv_std_z_ext_strtab): Add zifencei.
  13. * elfxx-riscv.h (riscv_isa_ext_class): Add RV_ISA_CLASS_H.
  14. gas/
  15. * testsuite/gas/riscv/march-fail-order-z.d: New testcase, check
  16. orders of prefixed z extensions.
  17. * testsuite/gas/riscv/march-fail-order-z.l: Likewise.
  18. * testsuite/gas/riscv/march-fail-single-char-h.d: New testcase.
  19. * testsuite/gas/riscv/march-fail-single-char.l: Updated.
  20. * testsuite/gas/riscv/march-fail-unknown-h.d: New testcase.
  21. * testsuite/gas/riscv/march-fail-unknown.l: Updated.
  22. opcodes/
  23. * riscv-opc.c (riscv_ext_version_table): Add zifencei.
  24. ---
  25. bfd/elfxx-riscv.c | 21 +++++++++++++++++--
  26. bfd/elfxx-riscv.h | 1 +
  27. gas/testsuite/gas/riscv/march-fail-order-z.d | 3 +++
  28. gas/testsuite/gas/riscv/march-fail-order-z.l | 2 ++
  29. .../gas/riscv/march-fail-single-char-h.d | 3 +++
  30. .../gas/riscv/march-fail-single-char.l | 2 +-
  31. .../gas/riscv/march-fail-unknown-h.d | 3 +++
  32. gas/testsuite/gas/riscv/march-fail-unknown.l | 2 +-
  33. opcodes/riscv-opc.c | 3 +++
  34. 9 files changed, 36 insertions(+), 4 deletions(-)
  35. create mode 100644 gas/testsuite/gas/riscv/march-fail-order-z.d
  36. create mode 100644 gas/testsuite/gas/riscv/march-fail-order-z.l
  37. create mode 100644 gas/testsuite/gas/riscv/march-fail-single-char-h.d
  38. create mode 100644 gas/testsuite/gas/riscv/march-fail-unknown-h.d
  39. diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
  40. index d29bb0375e..5a95c5cb6c 100644
  41. --- a/bfd/elfxx-riscv.c
  42. +++ b/bfd/elfxx-riscv.c
  43. @@ -1210,7 +1210,7 @@ riscv_parse_std_ext (riscv_parse_subset_t *rps,
  44. while (p != NULL && *p != '\0')
  45. {
  46. - if (*p == 'x' || *p == 's' || *p == 'z')
  47. + if (*p == 'x' || *p == 's' || *p == 'h' || *p == 'z')
  48. break;
  49. if (*p == '_')
  50. @@ -1266,6 +1266,7 @@ riscv_get_prefix_class (const char *arch)
  51. switch (*arch)
  52. {
  53. case 's': return RV_ISA_CLASS_S;
  54. + case 'h': return RV_ISA_CLASS_H;
  55. case 'x': return RV_ISA_CLASS_X;
  56. case 'z': return RV_ISA_CLASS_Z;
  57. default: return RV_ISA_CLASS_UNKNOWN;
  58. @@ -1347,6 +1348,7 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps,
  59. /* Check that the prefix extension is known.
  60. For 'x', anything goes but it cannot simply be 'x'.
  61. For 's', it must be known from a list and cannot simply be 's'.
  62. + For 'h', it must be known from a list and cannot simply be 'h'.
  63. For 'z', it must be known from a list and cannot simply be 'z'. */
  64. /* Check that the extension name is well-formed. */
  65. @@ -1417,7 +1419,7 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps,
  66. static const char * const riscv_std_z_ext_strtab[] =
  67. {
  68. - "zicsr", NULL
  69. + "zicsr", "zifencei", NULL
  70. };
  71. static const char * const riscv_std_s_ext_strtab[] =
  72. @@ -1425,6 +1427,11 @@ static const char * const riscv_std_s_ext_strtab[] =
  73. NULL
  74. };
  75. +static const char * const riscv_std_h_ext_strtab[] =
  76. +{
  77. + NULL
  78. +};
  79. +
  80. /* For the extension `ext`, search through the list of known extensions
  81. `known_exts` for a match, and return TRUE if found. */
  82. @@ -1471,12 +1478,22 @@ riscv_ext_s_valid_p (const char *arg)
  83. return riscv_multi_letter_ext_valid_p (arg, riscv_std_s_ext_strtab);
  84. }
  85. +/* Predicator function for 'h' prefixed extensions.
  86. + Only known h-extensions are permitted. */
  87. +
  88. +static bfd_boolean
  89. +riscv_ext_h_valid_p (const char *arg)
  90. +{
  91. + return riscv_multi_letter_ext_valid_p (arg, riscv_std_h_ext_strtab);
  92. +}
  93. +
  94. /* Parsing order of the prefixed extensions that is specified by
  95. the ISA spec. */
  96. static const riscv_parse_config_t parse_config[] =
  97. {
  98. {RV_ISA_CLASS_S, "s", riscv_ext_s_valid_p},
  99. + {RV_ISA_CLASS_H, "h", riscv_ext_h_valid_p},
  100. {RV_ISA_CLASS_Z, "z", riscv_ext_z_valid_p},
  101. {RV_ISA_CLASS_X, "x", riscv_ext_x_valid_p},
  102. {RV_ISA_CLASS_UNKNOWN, NULL, NULL}
  103. diff --git a/bfd/elfxx-riscv.h b/bfd/elfxx-riscv.h
  104. index b5b17d1687..6b7cc5b0bf 100644
  105. --- a/bfd/elfxx-riscv.h
  106. +++ b/bfd/elfxx-riscv.h
  107. @@ -102,6 +102,7 @@ riscv_estimate_digit (unsigned);
  108. typedef enum riscv_isa_ext_class
  109. {
  110. RV_ISA_CLASS_S,
  111. + RV_ISA_CLASS_H,
  112. RV_ISA_CLASS_Z,
  113. RV_ISA_CLASS_X,
  114. RV_ISA_CLASS_UNKNOWN
  115. diff --git a/gas/testsuite/gas/riscv/march-fail-order-z.d b/gas/testsuite/gas/riscv/march-fail-order-z.d
  116. new file mode 100644
  117. index 0000000000..dd076c6d35
  118. --- /dev/null
  119. +++ b/gas/testsuite/gas/riscv/march-fail-order-z.d
  120. @@ -0,0 +1,3 @@
  121. +#as: -march=rv32i_zifencei2p0_zicsr2p0
  122. +#source: empty.s
  123. +#error_output: march-fail-order-z.l
  124. diff --git a/gas/testsuite/gas/riscv/march-fail-order-z.l b/gas/testsuite/gas/riscv/march-fail-order-z.l
  125. new file mode 100644
  126. index 0000000000..1129219f2b
  127. --- /dev/null
  128. +++ b/gas/testsuite/gas/riscv/march-fail-order-z.l
  129. @@ -0,0 +1,2 @@
  130. +.*Assembler messages:
  131. +.*Fatal error: .*z ISA extension `zicsr' is not in alphabetical order. It must come before `zifencei'
  132. diff --git a/gas/testsuite/gas/riscv/march-fail-single-char-h.d b/gas/testsuite/gas/riscv/march-fail-single-char-h.d
  133. new file mode 100644
  134. index 0000000000..7fca9576bf
  135. --- /dev/null
  136. +++ b/gas/testsuite/gas/riscv/march-fail-single-char-h.d
  137. @@ -0,0 +1,3 @@
  138. +#as: -march=rv32ih
  139. +#source: empty.s
  140. +#error_output: march-fail-single-char.l
  141. diff --git a/gas/testsuite/gas/riscv/march-fail-single-char.l b/gas/testsuite/gas/riscv/march-fail-single-char.l
  142. index aa87a8db1a..6466e164ff 100644
  143. --- a/gas/testsuite/gas/riscv/march-fail-single-char.l
  144. +++ b/gas/testsuite/gas/riscv/march-fail-single-char.l
  145. @@ -1,2 +1,2 @@
  146. .*Assembler messages:
  147. -.*Fatal error: .*unknown (s|z|x) ISA extension `(s|z|x)'
  148. +.*Fatal error: .*unknown (s|h|z|x) ISA extension `(s|h|z|x)'
  149. diff --git a/gas/testsuite/gas/riscv/march-fail-unknown-h.d b/gas/testsuite/gas/riscv/march-fail-unknown-h.d
  150. new file mode 100644
  151. index 0000000000..b0b83231aa
  152. --- /dev/null
  153. +++ b/gas/testsuite/gas/riscv/march-fail-unknown-h.d
  154. @@ -0,0 +1,3 @@
  155. +#as: -march=rv32ihfoo2p0
  156. +#source: empty.s
  157. +#error_output: march-fail-unknown.l
  158. diff --git a/gas/testsuite/gas/riscv/march-fail-unknown.l b/gas/testsuite/gas/riscv/march-fail-unknown.l
  159. index ac22fe60eb..28a864dbb7 100644
  160. --- a/gas/testsuite/gas/riscv/march-fail-unknown.l
  161. +++ b/gas/testsuite/gas/riscv/march-fail-unknown.l
  162. @@ -1,2 +1,2 @@
  163. .*Assembler messages:
  164. -.*Fatal error: .*unknown (s|z) ISA extension `(s|z)foo'
  165. +.*Fatal error: .*unknown (s|h|z) ISA extension `(s|h|z)foo'
  166. diff --git a/opcodes/riscv-opc.c b/opcodes/riscv-opc.c
  167. index 03e3bd7c05..121f3fee41 100644
  168. --- a/opcodes/riscv-opc.c
  169. +++ b/opcodes/riscv-opc.c
  170. @@ -935,6 +935,9 @@ const struct riscv_ext_version riscv_ext_version_table[] =
  171. {"zicsr", ISA_SPEC_CLASS_20191213, 2, 0},
  172. {"zicsr", ISA_SPEC_CLASS_20190608, 2, 0},
  173. +{"zifencei", ISA_SPEC_CLASS_20191213, 2, 0},
  174. +{"zifencei", ISA_SPEC_CLASS_20190608, 2, 0},
  175. +
  176. /* Terminate the list. */
  177. {NULL, 0, 0, 0}
  178. };
  179. --
  180. 2.33.0