NMSIS-Core  Version 1.3.1
NMSIS-Core support for Nuclei processor-based devices
core_feature_base.h
1 /*
2  * Copyright (c) 2019 Nuclei Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef __CORE_FEATURE_BASE__
20 #define __CORE_FEATURE_BASE__
21 
25 /*
26  * Core Base Feature Configuration Macro:
27  * 1. __HARTID_OFFSET: Optional, define this macro when your cpu system first hart hartid and hart index is different.
28  * eg. If your cpu system, first hart hartid is 2, hart index is 0, then set this macro to 2
29  *
30  */
31 #include <stdint.h>
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 #include "nmsis_compiler.h"
38 
45 #ifndef __RISCV_XLEN
46 
47  #ifndef __riscv_xlen
48  #define __RISCV_XLEN 32
49  #else
50  #define __RISCV_XLEN __riscv_xlen
51  #endif
52 #endif /* __RISCV_XLEN */
53 
55 typedef unsigned long rv_csr_t;
56  /* End of Doxygen Group NMSIS_Core_Registers */
68 typedef union {
69  struct {
70  rv_csr_t a:1;
71  rv_csr_t b:1;
72  rv_csr_t c:1;
73  rv_csr_t d:1;
74  rv_csr_t e:1;
75  rv_csr_t f:1;
76  rv_csr_t g:1;
77  rv_csr_t h:1;
78  rv_csr_t i:1;
79  rv_csr_t j:1;
81  rv_csr_t l:1;
82  rv_csr_t m:1;
83  rv_csr_t n:1;
85  rv_csr_t p:1;
86  rv_csr_t q:1;
88  rv_csr_t s:1;
89  rv_csr_t t:1;
90  rv_csr_t u:1;
91  rv_csr_t v:1;
93  rv_csr_t x:1;
94 #if defined(__RISCV_XLEN) && __RISCV_XLEN == 64
95  rv_csr_t _reserved5:38;
96  rv_csr_t mxl:2;
97 #else
100 #endif
101  } b;
102  rv_csr_t d;
103 } CSR_MISA_Type;
104 
108 typedef union {
109  struct {
110 #if defined(__RISCV_XLEN) && __RISCV_XLEN == 64
111  rv_csr_t _reserved0:3;
112  rv_csr_t mie:1;
113  rv_csr_t _reserved1:3;
114  rv_csr_t mpie:1;
115  rv_csr_t _reserved2:3;
116  rv_csr_t mpp:2;
117  rv_csr_t fs:2;
118  rv_csr_t xs:2;
119  rv_csr_t mprv:1;
120  rv_csr_t _reserved3:14;
121  rv_csr_t uxl:2;
122  rv_csr_t _reserved6:29;
123  rv_csr_t sd:1;
124 #else
141 #endif
142  } b;
145 
149 typedef union {
150  struct {
152 #if defined(__RISCV_XLEN) && __RISCV_XLEN == 64
153  rv_csr_t addr:58;
154 #else
156 #endif
157  } b;
160 
164 typedef union {
165  struct {
173 #if defined(__RISCV_XLEN) && __RISCV_XLEN == 64
174  rv_csr_t _reserved2:32;
175  rv_csr_t interrupt:1;
176 #else
178 #endif
179  } b;
182 
186 typedef union {
187  struct {
191 #if defined(__RISCV_XLEN) && __RISCV_XLEN == 64
192  rv_csr_t _reserved1:61;
193 #else
195 #endif
196  } b;
199 
203 typedef union {
204  struct {
208 #if defined(__RISCV_XLEN) && __RISCV_XLEN == 64
209  rv_csr_t _reserved1:54;
210 #else
212 #endif
213  } b;
216 
220 typedef union {
221  struct {
224  } b;
227 
231 typedef union {
232  struct {
246  } b;
249 
251 
255 typedef union {
256  struct {
274  } b;
277 
281 typedef union {
282  struct {
291 #if defined(__RISCV_XLEN) && __RISCV_XLEN == 64
292  rv_csr_t _reserved2:48;
293 #else
295 #endif
296  } b;
299 
303 typedef union {
304  struct {
312  } b;
315 
319 typedef union {
320  struct {
328  } b;
331 
335 typedef union {
336  struct {
360  } b;
363 
367 typedef union {
368  struct {
377  } b;
380 
384 typedef union {
385  struct {
393  } b;
396 
400 typedef union {
401  struct {
410  } b;
413 
417 typedef union {
418  struct {
423  } b;
426 
430 typedef union {
431  struct {
436  } b;
439 
443 typedef union {
444  struct {
447  } b;
450 
454 typedef union {
455  struct {
462  } b;
465  /* End of Doxygen Group NMSIS_Core_Base_Registers */
467 
468 /* ########################### Core Function Access ########################### */
482 #ifndef __ASSEMBLY__
483 
484 #ifndef __ICCRISCV__
485 
496 #define __RV_CSR_SWAP(csr, val) \
497  ({ \
498  rv_csr_t __v = (unsigned long)(val); \
499  __ASM volatile("csrrw %0, " STRINGIFY(csr) ", %1" \
500  : "=r"(__v) \
501  : "rK"(__v) \
502  : "memory"); \
503  __v; \
504  })
505 
514 #define __RV_CSR_READ(csr) \
515  ({ \
516  rv_csr_t __v; \
517  __ASM volatile("csrr %0, " STRINGIFY(csr) \
518  : "=r"(__v) \
519  : \
520  : "memory"); \
521  __v; \
522  })
523 
532 #define __RV_CSR_WRITE(csr, val) \
533  ({ \
534  rv_csr_t __v = (rv_csr_t)(val); \
535  __ASM volatile("csrw " STRINGIFY(csr) ", %0" \
536  : \
537  : "rK"(__v) \
538  : "memory"); \
539  })
540 
551 #define __RV_CSR_READ_SET(csr, val) \
552  ({ \
553  rv_csr_t __v = (rv_csr_t)(val); \
554  __ASM volatile("csrrs %0, " STRINGIFY(csr) ", %1" \
555  : "=r"(__v) \
556  : "rK"(__v) \
557  : "memory"); \
558  __v; \
559  })
560 
569 #define __RV_CSR_SET(csr, val) \
570  ({ \
571  rv_csr_t __v = (rv_csr_t)(val); \
572  __ASM volatile("csrs " STRINGIFY(csr) ", %0" \
573  : \
574  : "rK"(__v) \
575  : "memory"); \
576  })
577 
588 #define __RV_CSR_READ_CLEAR(csr, val) \
589  ({ \
590  rv_csr_t __v = (rv_csr_t)(val); \
591  __ASM volatile("csrrc %0, " STRINGIFY(csr) ", %1" \
592  : "=r"(__v) \
593  : "rK"(__v) \
594  : "memory"); \
595  __v; \
596  })
597 
606 #define __RV_CSR_CLEAR(csr, val) \
607  ({ \
608  rv_csr_t __v = (rv_csr_t)(val); \
609  __ASM volatile("csrc " STRINGIFY(csr) ", %0" \
610  : \
611  : "rK"(__v) \
612  : "memory"); \
613  })
614 #else
615 
616 #include <intrinsics.h>
617 
618 #define __RV_CSR_SWAP __write_csr
619 #define __RV_CSR_READ __read_csr
620 #define __RV_CSR_WRITE __write_csr
621 #define __RV_CSR_READ_SET __set_bits_csr
622 #define __RV_CSR_SET __set_bits_csr
623 #define __RV_CSR_READ_CLEAR __clear_bits_csr
624 #define __RV_CSR_CLEAR __clear_bits_csr
625 
626 #endif /* __ICCRISCV__ */
627 
628 #endif /* __ASSEMBLY__ */
629 
638 __STATIC_FORCEINLINE void __switch_mode(uint8_t mode, uintptr_t stack, void(*entry_point)(void))
639 {
640  unsigned long val = 0;
641 
642  /* Set MPP to the requested privilege mode */
643  val = __RV_CSR_READ(CSR_MSTATUS);
644  val = __RV_INSERT_FIELD(val, MSTATUS_MPP, mode);
645 
646  /* Set previous MIE disabled */
647  val = __RV_INSERT_FIELD(val, MSTATUS_MPIE, 0);
648 
650 
651  /* Set the entry point in MEPC */
652  __RV_CSR_WRITE(CSR_MEPC, (unsigned long)entry_point);
653 
654  /* Set the register file */
655  __ASM volatile("mv sp, %0" ::"r"(stack));
656 
657  __ASM volatile("mret");
658 }
659 
667 {
669 }
670 
678 {
680 }
681 
689 {
691 }
692 
700 {
702 }
703 
711 {
713 }
714 
722 {
724 }
725 
733 {
735 }
736 
744 {
746 }
747 
755 {
756  __RV_CSR_CLEAR(CSR_MIE, 1 << irq);
757 }
758 
766 {
767  __RV_CSR_SET(CSR_MIE, 1 << irq);
768 }
769 
777 {
778  return ((__RV_CSR_READ(CSR_MIP) >> irq) & 0x1);
779 }
780 
788 {
789  __RV_CSR_SET(CSR_MIP, 1 << irq);
790 }
791 
799 {
801 }
802 
810 {
812 }
813 
821 {
823 }
824 
832 {
834 }
835 
843 {
845 }
846 
854 {
856 }
857 
865 {
867 }
868 
876 {
878 }
879 
887 {
888  __RV_CSR_CLEAR(CSR_SIE, 1 << irq);
889 }
890 
898 {
899  __RV_CSR_SET(CSR_SIE, 1 << irq);
900 }
901 
909 {
910  return ((__RV_CSR_READ(CSR_SIP) >> irq) & 0x1);
911 }
912 
920 {
921  __RV_CSR_SET(CSR_SIP, 1 << irq);
922 }
923 
931 {
932 #if __RISCV_XLEN == 32
933  volatile uint32_t high0, low, high;
934  uint64_t full;
935 
936  high0 = __RV_CSR_READ(CSR_MCYCLEH);
937  low = __RV_CSR_READ(CSR_MCYCLE);
938  high = __RV_CSR_READ(CSR_MCYCLEH);
939  if (high0 != high) {
940  low = __RV_CSR_READ(CSR_MCYCLE);
941  }
942  full = (((uint64_t)high) << 32) | low;
943  return full;
944 #elif __RISCV_XLEN == 64
945  return (uint64_t)__RV_CSR_READ(CSR_MCYCLE);
946 #else // TODO Need cover for XLEN=128 case in future
947  return (uint64_t)__RV_CSR_READ(CSR_MCYCLE);
948 #endif
949 }
950 
957 {
958 #if __RISCV_XLEN == 32
959  __RV_CSR_WRITE(CSR_MCYCLE, 0); // prevent carry
960  __RV_CSR_WRITE(CSR_MCYCLEH, (uint32_t)(cycle >> 32));
961  __RV_CSR_WRITE(CSR_MCYCLE, (uint32_t)(cycle));
962 #elif __RISCV_XLEN == 64
963  __RV_CSR_WRITE(CSR_MCYCLE, cycle);
964 #else // TODO Need cover for XLEN=128 case in future
965 #endif
966 }
967 
975 {
976 #if __RISCV_XLEN == 32
977  volatile uint32_t high0, low, high;
978  uint64_t full;
979 
980  high0 = __RV_CSR_READ(CSR_MINSTRETH);
983  if (high0 != high) {
985  }
986  full = (((uint64_t)high) << 32) | low;
987  return full;
988 #elif __RISCV_XLEN == 64
989  return (uint64_t)__RV_CSR_READ(CSR_MINSTRET);
990 #else // TODO Need cover for XLEN=128 case in future
991  return (uint64_t)__RV_CSR_READ(CSR_MINSTRET);
992 #endif
993 }
994 
1001 {
1002 #if __RISCV_XLEN == 32
1003  __RV_CSR_WRITE(CSR_MINSTRET, 0); // prevent carry
1004  __RV_CSR_WRITE(CSR_MINSTRETH, (uint32_t)(instret >> 32));
1005  __RV_CSR_WRITE(CSR_MINSTRET, (uint32_t)(instret));
1006 #elif __RISCV_XLEN == 64
1007  __RV_CSR_WRITE(CSR_MINSTRET, instret);
1008 #else // TODO Need cover for XLEN=128 case in future
1009 #endif
1010 }
1011 
1020 {
1021 #if __RISCV_XLEN == 32
1022  volatile uint32_t high0, low, high;
1023  uint64_t full;
1024 
1025  high0 = __RV_CSR_READ(CSR_TIMEH);
1026  low = __RV_CSR_READ(CSR_TIME);
1027  high = __RV_CSR_READ(CSR_TIMEH);
1028  if (high0 != high) {
1029  low = __RV_CSR_READ(CSR_TIME);
1030  }
1031  full = (((uint64_t)high) << 32) | low;
1032  return full;
1033 #elif __RISCV_XLEN == 64
1034  return (uint64_t)__RV_CSR_READ(CSR_TIME);
1035 #else // TODO Need cover for XLEN=128 case in future
1036  return (uint64_t)__RV_CSR_READ(CSR_TIME);
1037 #endif
1038 }
1039 
1048 {
1049  unsigned long id;
1050 
1051  id = (__RV_CSR_READ(CSR_MHARTID) >> 8) & 0xFF;
1052  return id;
1053 }
1054 
1064 {
1065  unsigned long id;
1066 #ifdef __HARTID_OFFSET
1067  id = __RV_CSR_READ(CSR_MHARTID) - __HARTID_OFFSET;
1068 #else
1069  id = __RV_CSR_READ(CSR_MHARTID);
1070 #endif
1071  return id;
1072 }
1073 
1084 {
1085  unsigned long id;
1086  id = __RV_CSR_READ(CSR_MHARTID);
1087  return id;
1088 }
1089  /* End of Doxygen Group NMSIS_Core_CSR_Register_Access */
1091 
1092 /* ########################### CPU Intrinsic Functions ########################### */
1110 {
1111  __ASM volatile("nop");
1112 }
1113 
1124 {
1126  __ASM volatile("wfi");
1127 }
1128 
1137 {
1139  __ASM volatile("wfi");
1141 }
1142 
1151 {
1152  __ASM volatile("ebreak");
1153 }
1154 
1162 {
1163  __ASM volatile("ecall");
1164 }
1165 
1169 typedef enum WFI_SleepMode {
1172 } WFI_SleepMode_Type;
1173 
1181 __STATIC_FORCEINLINE void __set_wfi_sleepmode(WFI_SleepMode_Type mode)
1182 {
1184 }
1185 
1193 {
1194  __RV_CSR_SET(CSR_TXEVT, 0x1);
1195 }
1196 
1203 {
1205 }
1206 
1213 {
1215 }
1216 
1223 {
1225 }
1226 
1233 {
1235 }
1236 
1244 {
1245  __RV_CSR_CLEAR(CSR_MCOUNTINHIBIT, (1 << idx));
1246 }
1247 
1255 {
1256  __RV_CSR_SET(CSR_MCOUNTINHIBIT, (1 << idx));
1257 }
1258 
1267 {
1269 }
1270 
1279 {
1281 }
1282 
1290 {
1291  __RV_CSR_CLEAR(CSR_MCOUNTINHIBIT, 0xFFFFFFFF);
1292 }
1293 
1301 {
1302  __RV_CSR_SET(CSR_MCOUNTINHIBIT, 0xFFFFFFFF);
1303 }
1304 
1312 __STATIC_FORCEINLINE void __set_hpm_event(unsigned long idx, unsigned long event)
1313 {
1314  switch (idx) {
1315  case 3: __RV_CSR_WRITE(CSR_MHPMEVENT3, event); break;
1316  case 4: __RV_CSR_WRITE(CSR_MHPMEVENT4, event); break;
1317  case 5: __RV_CSR_WRITE(CSR_MHPMEVENT5, event); break;
1318  case 6: __RV_CSR_WRITE(CSR_MHPMEVENT6, event); break;
1319  case 7: __RV_CSR_WRITE(CSR_MHPMEVENT7, event); break;
1320  case 8: __RV_CSR_WRITE(CSR_MHPMEVENT8, event); break;
1321  case 9: __RV_CSR_WRITE(CSR_MHPMEVENT9, event); break;
1322  case 10: __RV_CSR_WRITE(CSR_MHPMEVENT10, event); break;
1323  case 11: __RV_CSR_WRITE(CSR_MHPMEVENT11, event); break;
1324  case 12: __RV_CSR_WRITE(CSR_MHPMEVENT12, event); break;
1325  case 13: __RV_CSR_WRITE(CSR_MHPMEVENT13, event); break;
1326  case 14: __RV_CSR_WRITE(CSR_MHPMEVENT14, event); break;
1327  case 15: __RV_CSR_WRITE(CSR_MHPMEVENT15, event); break;
1328  case 16: __RV_CSR_WRITE(CSR_MHPMEVENT16, event); break;
1329  case 17: __RV_CSR_WRITE(CSR_MHPMEVENT17, event); break;
1330  case 18: __RV_CSR_WRITE(CSR_MHPMEVENT18, event); break;
1331  case 19: __RV_CSR_WRITE(CSR_MHPMEVENT19, event); break;
1332  case 20: __RV_CSR_WRITE(CSR_MHPMEVENT20, event); break;
1333  case 21: __RV_CSR_WRITE(CSR_MHPMEVENT21, event); break;
1334  case 22: __RV_CSR_WRITE(CSR_MHPMEVENT22, event); break;
1335  case 23: __RV_CSR_WRITE(CSR_MHPMEVENT23, event); break;
1336  case 24: __RV_CSR_WRITE(CSR_MHPMEVENT24, event); break;
1337  case 25: __RV_CSR_WRITE(CSR_MHPMEVENT25, event); break;
1338  case 26: __RV_CSR_WRITE(CSR_MHPMEVENT26, event); break;
1339  case 27: __RV_CSR_WRITE(CSR_MHPMEVENT27, event); break;
1340  case 28: __RV_CSR_WRITE(CSR_MHPMEVENT28, event); break;
1341  case 29: __RV_CSR_WRITE(CSR_MHPMEVENT29, event); break;
1342  case 30: __RV_CSR_WRITE(CSR_MHPMEVENT30, event); break;
1343  case 31: __RV_CSR_WRITE(CSR_MHPMEVENT31, event); break;
1344  default: break;
1345  }
1346 }
1347 
1356 __STATIC_FORCEINLINE unsigned long __get_hpm_event(unsigned long idx)
1357 {
1358  switch (idx) {
1359  case 3: return __RV_CSR_READ(CSR_MHPMEVENT3);
1360  case 4: return __RV_CSR_READ(CSR_MHPMEVENT4);
1361  case 5: return __RV_CSR_READ(CSR_MHPMEVENT5);
1362  case 6: return __RV_CSR_READ(CSR_MHPMEVENT6);
1363  case 7: return __RV_CSR_READ(CSR_MHPMEVENT7);
1364  case 8: return __RV_CSR_READ(CSR_MHPMEVENT8);
1365  case 9: return __RV_CSR_READ(CSR_MHPMEVENT9);
1366  case 10: return __RV_CSR_READ(CSR_MHPMEVENT10);
1367  case 11: return __RV_CSR_READ(CSR_MHPMEVENT11);
1368  case 12: return __RV_CSR_READ(CSR_MHPMEVENT12);
1369  case 13: return __RV_CSR_READ(CSR_MHPMEVENT13);
1370  case 14: return __RV_CSR_READ(CSR_MHPMEVENT14);
1371  case 15: return __RV_CSR_READ(CSR_MHPMEVENT15);
1372  case 16: return __RV_CSR_READ(CSR_MHPMEVENT16);
1373  case 17: return __RV_CSR_READ(CSR_MHPMEVENT17);
1374  case 18: return __RV_CSR_READ(CSR_MHPMEVENT18);
1375  case 19: return __RV_CSR_READ(CSR_MHPMEVENT19);
1376  case 20: return __RV_CSR_READ(CSR_MHPMEVENT20);
1377  case 21: return __RV_CSR_READ(CSR_MHPMEVENT21);
1378  case 22: return __RV_CSR_READ(CSR_MHPMEVENT22);
1379  case 23: return __RV_CSR_READ(CSR_MHPMEVENT23);
1380  case 24: return __RV_CSR_READ(CSR_MHPMEVENT24);
1381  case 25: return __RV_CSR_READ(CSR_MHPMEVENT25);
1382  case 26: return __RV_CSR_READ(CSR_MHPMEVENT26);
1383  case 27: return __RV_CSR_READ(CSR_MHPMEVENT27);
1384  case 28: return __RV_CSR_READ(CSR_MHPMEVENT28);
1385  case 29: return __RV_CSR_READ(CSR_MHPMEVENT29);
1386  case 30: return __RV_CSR_READ(CSR_MHPMEVENT30);
1387  case 31: return __RV_CSR_READ(CSR_MHPMEVENT31);
1388  default: return 0;
1389  }
1390 }
1391 
1399 __STATIC_FORCEINLINE void __set_hpm_counter(unsigned long idx, uint64_t value)
1400 {
1401  switch (idx) {
1402 #if __RISCV_XLEN == 32
1403  case 3: __RV_CSR_WRITE(CSR_MHPMCOUNTER3, 0); // prevent carry
1404  __RV_CSR_WRITE(CSR_MHPMCOUNTER3H, (uint32_t)(value >> 32));
1405  __RV_CSR_WRITE(CSR_MHPMCOUNTER3, (uint32_t)(value)); break;
1406  case 4: __RV_CSR_WRITE(CSR_MHPMCOUNTER4, 0); // prevent carry
1407  __RV_CSR_WRITE(CSR_MHPMCOUNTER4H, (uint32_t)(value >> 32));
1408  __RV_CSR_WRITE(CSR_MHPMCOUNTER4, (uint32_t)(value)); break;
1409  case 5: __RV_CSR_WRITE(CSR_MHPMCOUNTER5, 0); // prevent carry
1410  __RV_CSR_WRITE(CSR_MHPMCOUNTER5H, (uint32_t)(value >> 32));
1411  __RV_CSR_WRITE(CSR_MHPMCOUNTER5, (uint32_t)(value)); break;
1412  case 6: __RV_CSR_WRITE(CSR_MHPMCOUNTER6, 0); // prevent carry
1413  __RV_CSR_WRITE(CSR_MHPMCOUNTER6H, (uint32_t)(value >> 32));
1414  __RV_CSR_WRITE(CSR_MHPMCOUNTER6, (uint32_t)(value)); break;
1415  case 7: __RV_CSR_WRITE(CSR_MHPMCOUNTER7, 0); // prevent carry
1416  __RV_CSR_WRITE(CSR_MHPMCOUNTER7H, (uint32_t)(value >> 32));
1417  __RV_CSR_WRITE(CSR_MHPMCOUNTER7, (uint32_t)(value)); break;
1418  case 8: __RV_CSR_WRITE(CSR_MHPMCOUNTER8, 0); // prevent carry
1419  __RV_CSR_WRITE(CSR_MHPMCOUNTER8H, (uint32_t)(value >> 32));
1420  __RV_CSR_WRITE(CSR_MHPMCOUNTER8, (uint32_t)(value)); break;
1421  case 9: __RV_CSR_WRITE(CSR_MHPMCOUNTER9, 0); // prevent carry
1422  __RV_CSR_WRITE(CSR_MHPMCOUNTER9H, (uint32_t)(value >> 32));
1423  __RV_CSR_WRITE(CSR_MHPMCOUNTER9, (uint32_t)(value)); break;
1424  case 10: __RV_CSR_WRITE(CSR_MHPMCOUNTER10, 0); // prevent carry
1425  __RV_CSR_WRITE(CSR_MHPMCOUNTER10H, (uint32_t)(value >> 32));
1426  __RV_CSR_WRITE(CSR_MHPMCOUNTER10, (uint32_t)(value)); break;
1427  case 11: __RV_CSR_WRITE(CSR_MHPMCOUNTER11, 0); // prevent carry
1428  __RV_CSR_WRITE(CSR_MHPMCOUNTER11H, (uint32_t)(value >> 32));
1429  __RV_CSR_WRITE(CSR_MHPMCOUNTER11, (uint32_t)(value)); break;
1430  case 12: __RV_CSR_WRITE(CSR_MHPMCOUNTER12, 0); // prevent carry
1431  __RV_CSR_WRITE(CSR_MHPMCOUNTER12H, (uint32_t)(value >> 32));
1432  __RV_CSR_WRITE(CSR_MHPMCOUNTER12, (uint32_t)(value)); break;
1433  case 13: __RV_CSR_WRITE(CSR_MHPMCOUNTER13, 0); // prevent carry
1434  __RV_CSR_WRITE(CSR_MHPMCOUNTER13H, (uint32_t)(value >> 32));
1435  __RV_CSR_WRITE(CSR_MHPMCOUNTER13, (uint32_t)(value)); break;
1436  case 14: __RV_CSR_WRITE(CSR_MHPMCOUNTER14, 0); // prevent carry
1437  __RV_CSR_WRITE(CSR_MHPMCOUNTER14H, (uint32_t)(value >> 32));
1438  __RV_CSR_WRITE(CSR_MHPMCOUNTER14, (uint32_t)(value)); break;
1439  case 15: __RV_CSR_WRITE(CSR_MHPMCOUNTER15, 0); // prevent carry
1440  __RV_CSR_WRITE(CSR_MHPMCOUNTER15H, (uint32_t)(value >> 32));
1441  __RV_CSR_WRITE(CSR_MHPMCOUNTER15, (uint32_t)(value)); break;
1442  case 16: __RV_CSR_WRITE(CSR_MHPMCOUNTER16, 0); // prevent carry
1443  __RV_CSR_WRITE(CSR_MHPMCOUNTER16H, (uint32_t)(value >> 32));
1444  __RV_CSR_WRITE(CSR_MHPMCOUNTER16, (uint32_t)(value)); break;
1445  case 17: __RV_CSR_WRITE(CSR_MHPMCOUNTER17, 0); // prevent carry
1446  __RV_CSR_WRITE(CSR_MHPMCOUNTER17H, (uint32_t)(value >> 32));
1447  __RV_CSR_WRITE(CSR_MHPMCOUNTER17, (uint32_t)(value)); break;
1448  case 18: __RV_CSR_WRITE(CSR_MHPMCOUNTER18, 0); // prevent carry
1449  __RV_CSR_WRITE(CSR_MHPMCOUNTER18H, (uint32_t)(value >> 32));
1450  __RV_CSR_WRITE(CSR_MHPMCOUNTER18, (uint32_t)(value)); break;
1451  case 19: __RV_CSR_WRITE(CSR_MHPMCOUNTER19, 0); // prevent carry
1452  __RV_CSR_WRITE(CSR_MHPMCOUNTER19H, (uint32_t)(value >> 32));
1453  __RV_CSR_WRITE(CSR_MHPMCOUNTER19, (uint32_t)(value)); break;
1454  case 20: __RV_CSR_WRITE(CSR_MHPMCOUNTER20, 0); // prevent carry
1455  __RV_CSR_WRITE(CSR_MHPMCOUNTER20H, (uint32_t)(value >> 32));
1456  __RV_CSR_WRITE(CSR_MHPMCOUNTER20, (uint32_t)(value)); break;
1457  case 21: __RV_CSR_WRITE(CSR_MHPMCOUNTER21, 0); // prevent carry
1458  __RV_CSR_WRITE(CSR_MHPMCOUNTER21H, (uint32_t)(value >> 32));
1459  __RV_CSR_WRITE(CSR_MHPMCOUNTER21, (uint32_t)(value)); break;
1460  case 22: __RV_CSR_WRITE(CSR_MHPMCOUNTER22, 0); // prevent carry
1461  __RV_CSR_WRITE(CSR_MHPMCOUNTER22H, (uint32_t)(value >> 32));
1462  __RV_CSR_WRITE(CSR_MHPMCOUNTER22, (uint32_t)(value)); break;
1463  case 23: __RV_CSR_WRITE(CSR_MHPMCOUNTER23, 0); // prevent carry
1464  __RV_CSR_WRITE(CSR_MHPMCOUNTER23H, (uint32_t)(value >> 32));
1465  __RV_CSR_WRITE(CSR_MHPMCOUNTER23, (uint32_t)(value)); break;
1466  case 24: __RV_CSR_WRITE(CSR_MHPMCOUNTER24, 0); // prevent carry
1467  __RV_CSR_WRITE(CSR_MHPMCOUNTER24H, (uint32_t)(value >> 32));
1468  __RV_CSR_WRITE(CSR_MHPMCOUNTER24, (uint32_t)(value)); break;
1469  case 25: __RV_CSR_WRITE(CSR_MHPMCOUNTER25, 0); // prevent carry
1470  __RV_CSR_WRITE(CSR_MHPMCOUNTER25H, (uint32_t)(value >> 32));
1471  __RV_CSR_WRITE(CSR_MHPMCOUNTER25, (uint32_t)(value)); break;
1472  case 26: __RV_CSR_WRITE(CSR_MHPMCOUNTER26, 0); // prevent carry
1473  __RV_CSR_WRITE(CSR_MHPMCOUNTER26H, (uint32_t)(value >> 32));
1474  __RV_CSR_WRITE(CSR_MHPMCOUNTER26, (uint32_t)(value)); break;
1475  case 27: __RV_CSR_WRITE(CSR_MHPMCOUNTER27, 0); // prevent carry
1476  __RV_CSR_WRITE(CSR_MHPMCOUNTER27H, (uint32_t)(value >> 32));
1477  __RV_CSR_WRITE(CSR_MHPMCOUNTER27, (uint32_t)(value)); break;
1478  case 28: __RV_CSR_WRITE(CSR_MHPMCOUNTER28, 0); // prevent carry
1479  __RV_CSR_WRITE(CSR_MHPMCOUNTER28H, (uint32_t)(value >> 32));
1480  __RV_CSR_WRITE(CSR_MHPMCOUNTER28, (uint32_t)(value)); break;
1481  case 29: __RV_CSR_WRITE(CSR_MHPMCOUNTER29, 0); // prevent carry
1482  __RV_CSR_WRITE(CSR_MHPMCOUNTER29H, (uint32_t)(value >> 32));
1483  __RV_CSR_WRITE(CSR_MHPMCOUNTER29, (uint32_t)(value)); break;
1484  case 30: __RV_CSR_WRITE(CSR_MHPMCOUNTER30, 0); // prevent carry
1485  __RV_CSR_WRITE(CSR_MHPMCOUNTER30H, (uint32_t)(value >> 32));
1486  __RV_CSR_WRITE(CSR_MHPMCOUNTER30, (uint32_t)(value)); break;
1487  case 31: __RV_CSR_WRITE(CSR_MHPMCOUNTER31, 0); // prevent carry
1488  __RV_CSR_WRITE(CSR_MHPMCOUNTER31H, (uint32_t)(value >> 32));
1489  __RV_CSR_WRITE(CSR_MHPMCOUNTER31, (uint32_t)(value)); break;
1490 
1491 #elif __RISCV_XLEN == 64
1492  case 3: __RV_CSR_WRITE(CSR_MHPMCOUNTER3, (value)); break;
1493  case 4: __RV_CSR_WRITE(CSR_MHPMCOUNTER4, (value)); break;
1494  case 5: __RV_CSR_WRITE(CSR_MHPMCOUNTER5, (value)); break;
1495  case 6: __RV_CSR_WRITE(CSR_MHPMCOUNTER6, (value)); break;
1496  case 7: __RV_CSR_WRITE(CSR_MHPMCOUNTER7, (value)); break;
1497  case 8: __RV_CSR_WRITE(CSR_MHPMCOUNTER8, (value)); break;
1498  case 9: __RV_CSR_WRITE(CSR_MHPMCOUNTER9, (value)); break;
1499  case 10: __RV_CSR_WRITE(CSR_MHPMCOUNTER10, (value)); break;
1500  case 11: __RV_CSR_WRITE(CSR_MHPMCOUNTER11, (value)); break;
1501  case 12: __RV_CSR_WRITE(CSR_MHPMCOUNTER12, (value)); break;
1502  case 13: __RV_CSR_WRITE(CSR_MHPMCOUNTER13, (value)); break;
1503  case 14: __RV_CSR_WRITE(CSR_MHPMCOUNTER14, (value)); break;
1504  case 15: __RV_CSR_WRITE(CSR_MHPMCOUNTER15, (value)); break;
1505  case 16: __RV_CSR_WRITE(CSR_MHPMCOUNTER16, (value)); break;
1506  case 17: __RV_CSR_WRITE(CSR_MHPMCOUNTER17, (value)); break;
1507  case 18: __RV_CSR_WRITE(CSR_MHPMCOUNTER18, (value)); break;
1508  case 19: __RV_CSR_WRITE(CSR_MHPMCOUNTER19, (value)); break;
1509  case 20: __RV_CSR_WRITE(CSR_MHPMCOUNTER20, (value)); break;
1510  case 21: __RV_CSR_WRITE(CSR_MHPMCOUNTER21, (value)); break;
1511  case 22: __RV_CSR_WRITE(CSR_MHPMCOUNTER22, (value)); break;
1512  case 23: __RV_CSR_WRITE(CSR_MHPMCOUNTER23, (value)); break;
1513  case 24: __RV_CSR_WRITE(CSR_MHPMCOUNTER24, (value)); break;
1514  case 25: __RV_CSR_WRITE(CSR_MHPMCOUNTER25, (value)); break;
1515  case 26: __RV_CSR_WRITE(CSR_MHPMCOUNTER26, (value)); break;
1516  case 27: __RV_CSR_WRITE(CSR_MHPMCOUNTER27, (value)); break;
1517  case 28: __RV_CSR_WRITE(CSR_MHPMCOUNTER28, (value)); break;
1518  case 29: __RV_CSR_WRITE(CSR_MHPMCOUNTER29, (value)); break;
1519  case 30: __RV_CSR_WRITE(CSR_MHPMCOUNTER30, (value)); break;
1520  case 31: __RV_CSR_WRITE(CSR_MHPMCOUNTER31, (value)); break;
1521 
1522 #else
1523 #endif
1524  default: break;
1525  }
1526 }
1527 
1536 __STATIC_FORCEINLINE unsigned long __get_hpm_counter(unsigned long idx)
1537 {
1538 #if __RISCV_XLEN == 32
1539  volatile uint32_t high0, low, high;
1540  uint64_t full;
1541 
1542  switch (idx) {
1543  case 0: return __get_rv_cycle();
1544  case 2: return __get_rv_instret();
1545  case 3: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER3H);
1548  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER3); }
1549  full = (((uint64_t)high) << 32) | low; return full;
1550  case 4: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER4H);
1553  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER4); }
1554  full = (((uint64_t)high) << 32) | low; return full;
1555  case 5: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER5H);
1558  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER5); }
1559  full = (((uint64_t)high) << 32) | low; return full;
1560  case 6: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER6H);
1563  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER6); }
1564  full = (((uint64_t)high) << 32) | low; return full;
1565  case 7: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER7H);
1568  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER7); }
1569  full = (((uint64_t)high) << 32) | low; return full;
1570  case 8: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER8H);
1573  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER8); }
1574  full = (((uint64_t)high) << 32) | low; return full;
1575  case 9: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER9H);
1578  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER9); }
1579  full = (((uint64_t)high) << 32) | low; return full;
1580  case 10: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER10H);
1583  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER10); }
1584  full = (((uint64_t)high) << 32) | low; return full;
1585  case 11: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER11H);
1588  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER11); }
1589  full = (((uint64_t)high) << 32) | low; return full;
1590  case 12: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER12H);
1593  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER12); }
1594  full = (((uint64_t)high) << 32) | low; return full;
1595  case 13: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER13H);
1598  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER13); }
1599  full = (((uint64_t)high) << 32) | low; return full;
1600  case 14: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER14H);
1603  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER14); }
1604  full = (((uint64_t)high) << 32) | low; return full;
1605  case 15: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER15H);
1608  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER15); }
1609  full = (((uint64_t)high) << 32) | low; return full;
1610  case 16: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER16H);
1613  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER16); }
1614  full = (((uint64_t)high) << 32) | low; return full;
1615  case 17: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER17H);
1618  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER17); }
1619  full = (((uint64_t)high) << 32) | low; return full;
1620  case 18: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER18H);
1623  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER18); }
1624  full = (((uint64_t)high) << 32) | low; return full;
1625  case 19: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER19H);
1628  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER19); }
1629  full = (((uint64_t)high) << 32) | low; return full;
1630  case 20: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER20H);
1633  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER20); }
1634  full = (((uint64_t)high) << 32) | low; return full;
1635  case 21: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER21H);
1638  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER21); }
1639  full = (((uint64_t)high) << 32) | low; return full;
1640  case 22: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER22H);
1643  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER22); }
1644  full = (((uint64_t)high) << 32) | low; return full;
1645  case 23: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER23H);
1648  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER23); }
1649  full = (((uint64_t)high) << 32) | low; return full;
1650  case 24: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER24H);
1653  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER24); }
1654  full = (((uint64_t)high) << 32) | low; return full;
1655  case 25: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER25H);
1658  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER25); }
1659  full = (((uint64_t)high) << 32) | low; return full;
1660  case 26: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER26H);
1663  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER26); }
1664  full = (((uint64_t)high) << 32) | low; return full;
1665  case 27: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER27H);
1668  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER27); }
1669  full = (((uint64_t)high) << 32) | low; return full;
1670  case 28: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER28H);
1673  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER28); }
1674  full = (((uint64_t)high) << 32) | low; return full;
1675  case 29: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER29H);
1678  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER29); }
1679  full = (((uint64_t)high) << 32) | low; return full;
1680  case 30: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER30H);
1683  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER30); }
1684  full = (((uint64_t)high) << 32) | low; return full;
1685  case 31: high0 = __RV_CSR_READ(CSR_MHPMCOUNTER31H);
1688  if (high0 != high) { low = __RV_CSR_READ(CSR_MHPMCOUNTER31); }
1689  full = (((uint64_t)high) << 32) | low; return full;
1690 
1691 #elif __RISCV_XLEN == 64
1692  switch (idx) {
1693  case 0: return __get_rv_cycle();
1694  case 2: return __get_rv_instret();
1695  case 3: return __RV_CSR_READ(CSR_MHPMCOUNTER3);
1696  case 4: return __RV_CSR_READ(CSR_MHPMCOUNTER4);
1697  case 5: return __RV_CSR_READ(CSR_MHPMCOUNTER5);
1698  case 6: return __RV_CSR_READ(CSR_MHPMCOUNTER6);
1699  case 7: return __RV_CSR_READ(CSR_MHPMCOUNTER7);
1700  case 8: return __RV_CSR_READ(CSR_MHPMCOUNTER8);
1701  case 9: return __RV_CSR_READ(CSR_MHPMCOUNTER9);
1702  case 10: return __RV_CSR_READ(CSR_MHPMCOUNTER10);
1703  case 11: return __RV_CSR_READ(CSR_MHPMCOUNTER11);
1704  case 12: return __RV_CSR_READ(CSR_MHPMCOUNTER12);
1705  case 13: return __RV_CSR_READ(CSR_MHPMCOUNTER13);
1706  case 14: return __RV_CSR_READ(CSR_MHPMCOUNTER14);
1707  case 15: return __RV_CSR_READ(CSR_MHPMCOUNTER15);
1708  case 16: return __RV_CSR_READ(CSR_MHPMCOUNTER16);
1709  case 17: return __RV_CSR_READ(CSR_MHPMCOUNTER17);
1710  case 18: return __RV_CSR_READ(CSR_MHPMCOUNTER18);
1711  case 19: return __RV_CSR_READ(CSR_MHPMCOUNTER19);
1712  case 20: return __RV_CSR_READ(CSR_MHPMCOUNTER20);
1713  case 21: return __RV_CSR_READ(CSR_MHPMCOUNTER21);
1714  case 22: return __RV_CSR_READ(CSR_MHPMCOUNTER22);
1715  case 23: return __RV_CSR_READ(CSR_MHPMCOUNTER23);
1716  case 24: return __RV_CSR_READ(CSR_MHPMCOUNTER24);
1717  case 25: return __RV_CSR_READ(CSR_MHPMCOUNTER25);
1718  case 26: return __RV_CSR_READ(CSR_MHPMCOUNTER26);
1719  case 27: return __RV_CSR_READ(CSR_MHPMCOUNTER27);
1720  case 28: return __RV_CSR_READ(CSR_MHPMCOUNTER28);
1721  case 29: return __RV_CSR_READ(CSR_MHPMCOUNTER29);
1722  case 30: return __RV_CSR_READ(CSR_MHPMCOUNTER30);
1723  case 31: return __RV_CSR_READ(CSR_MHPMCOUNTER31);
1724 
1725 #else
1726  switch (idx) {
1727 #endif
1728  default: return 0;
1729  }
1730 }
1731 
1739 __STATIC_FORCEINLINE void __set_medeleg(unsigned long mask)
1740 {
1741  __RV_CSR_WRITE(CSR_MEDELEG, mask);
1742 }
1743 
1754 #define __FENCE(p, s) __ASM volatile ("fence " #p "," #s : : : "memory")
1755 
1763 {
1764  __ASM volatile("fence.i");
1765 }
1766 
1768 #define __RWMB() __FENCE(iorw,iorw)
1769 
1771 #define __RMB() __FENCE(ir,ir)
1772 
1774 #define __WMB() __FENCE(ow,ow)
1775 
1777 #define __SMP_RWMB() __FENCE(rw,rw)
1778 
1780 #define __SMP_RMB() __FENCE(r,r)
1781 
1783 #define __SMP_WMB() __FENCE(w,w)
1784 
1786 #define __CPU_RELAX() __ASM volatile ("" : : : "memory")
1787 
1788 
1789 /* ===== Load/Store Operations ===== */
1796 __STATIC_FORCEINLINE uint8_t __LB(volatile void *addr)
1797 {
1798  uint8_t result;
1799 
1800  __ASM volatile ("lb %0, 0(%1)" : "=r" (result) : "r" (addr));
1801  return result;
1802 }
1803 
1810 __STATIC_FORCEINLINE uint16_t __LH(volatile void *addr)
1811 {
1812  uint16_t result;
1813 
1814  __ASM volatile ("lh %0, 0(%1)" : "=r" (result) : "r" (addr));
1815  return result;
1816 }
1817 
1824 __STATIC_FORCEINLINE uint32_t __LW(volatile void *addr)
1825 {
1826  uint32_t result;
1827 
1828  __ASM volatile ("lw %0, 0(%1)" : "=r" (result) : "r" (addr));
1829  return result;
1830 }
1831 
1832 #if __RISCV_XLEN != 32
1833 
1840 __STATIC_FORCEINLINE uint64_t __LD(volatile void *addr)
1841 {
1842  uint64_t result;
1843  __ASM volatile ("ld %0, 0(%1)" : "=r" (result) : "r" (addr));
1844  return result;
1845 }
1846 #endif
1847 
1854 __STATIC_FORCEINLINE void __SB(volatile void *addr, uint8_t val)
1855 {
1856  __ASM volatile ("sb %0, 0(%1)" : : "r" (val), "r" (addr));
1857 }
1858 
1865 __STATIC_FORCEINLINE void __SH(volatile void *addr, uint16_t val)
1866 {
1867  __ASM volatile ("sh %0, 0(%1)" : : "r" (val), "r" (addr));
1868 }
1869 
1876 __STATIC_FORCEINLINE void __SW(volatile void *addr, uint32_t val)
1877 {
1878  __ASM volatile ("sw %0, 0(%1)" : : "r" (val), "r" (addr));
1879 }
1880 
1881 #if __RISCV_XLEN != 32
1882 
1888 __STATIC_FORCEINLINE void __SD(volatile void *addr, uint64_t val)
1889 {
1890  __ASM volatile ("sd %0, 0(%1)" : : "r" (val), "r" (addr));
1891 }
1892 #endif
1893 
1905 __STATIC_FORCEINLINE uint32_t __CAS_W(volatile uint32_t *addr, uint32_t oldval, uint32_t newval)
1906 {
1907  uint32_t result;
1908  uint32_t rc;
1909 
1910  __ASM volatile ( \
1911  "0: lr.w %0, %2 \n" \
1912  " bne %0, %z3, 1f \n" \
1913  " sc.w %1, %z4, %2 \n" \
1914  " bnez %1, 0b \n" \
1915  "1:\n" \
1916  : "=&r"(result), "=&r"(rc), "+A"(*addr) \
1917  : "r"(oldval), "r"(newval) \
1918  : "memory");
1919  return result;
1920 }
1921 
1929 __STATIC_FORCEINLINE uint32_t __AMOSWAP_W(volatile uint32_t *addr, uint32_t newval)
1930 {
1931  uint32_t result;
1932 
1933  __ASM volatile ("amoswap.w %0, %2, %1" : \
1934  "=r"(result), "+A"(*addr) : "r"(newval) : "memory");
1935  return result;
1936 }
1937 
1945 __STATIC_FORCEINLINE int32_t __AMOADD_W(volatile int32_t *addr, int32_t value)
1946 {
1947  int32_t result;
1948 
1949  __ASM volatile ("amoadd.w %0, %2, %1" : \
1950  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
1951  return *addr;
1952 }
1953 
1961 __STATIC_FORCEINLINE int32_t __AMOAND_W(volatile int32_t *addr, int32_t value)
1962 {
1963  int32_t result;
1964 
1965  __ASM volatile ("amoand.w %0, %2, %1" : \
1966  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
1967  return *addr;
1968 }
1969 
1977 __STATIC_FORCEINLINE int32_t __AMOOR_W(volatile int32_t *addr, int32_t value)
1978 {
1979  int32_t result;
1980 
1981  __ASM volatile ("amoor.w %0, %2, %1" : \
1982  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
1983  return *addr;
1984 }
1985 
1993 __STATIC_FORCEINLINE int32_t __AMOXOR_W(volatile int32_t *addr, int32_t value)
1994 {
1995  int32_t result;
1996 
1997  __ASM volatile ("amoxor.w %0, %2, %1" : \
1998  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
1999  return *addr;
2000 }
2001 
2009 __STATIC_FORCEINLINE uint32_t __AMOMAXU_W(volatile uint32_t *addr, uint32_t value)
2010 {
2011  uint32_t result;
2012 
2013  __ASM volatile ("amomaxu.w %0, %2, %1" : \
2014  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2015  return *addr;
2016 }
2017 
2025 __STATIC_FORCEINLINE int32_t __AMOMAX_W(volatile int32_t *addr, int32_t value)
2026 {
2027  int32_t result;
2028 
2029  __ASM volatile ("amomax.w %0, %2, %1" : \
2030  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2031  return *addr;
2032 }
2033 
2041 __STATIC_FORCEINLINE uint32_t __AMOMINU_W(volatile uint32_t *addr, uint32_t value)
2042 {
2043  uint32_t result;
2044 
2045  __ASM volatile ("amominu.w %0, %2, %1" : \
2046  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2047  return *addr;
2048 }
2049 
2057 __STATIC_FORCEINLINE int32_t __AMOMIN_W(volatile int32_t *addr, int32_t value)
2058 {
2059  int32_t result;
2060 
2061  __ASM volatile ("amomin.w %0, %2, %1" : \
2062  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2063  return *addr;
2064 }
2065 
2066 #if __RISCV_XLEN == 64
2067 
2078 __STATIC_FORCEINLINE uint64_t __CAS_D(volatile uint64_t *addr, uint64_t oldval, uint64_t newval)
2079 {
2080  uint64_t result;
2081  uint64_t rc;
2082 
2083  __ASM volatile ( \
2084  "0: lr.d %0, %2 \n" \
2085  " bne %0, %z3, 1f \n" \
2086  " sc.d %1, %z4, %2 \n" \
2087  " bnez %1, 0b \n" \
2088  "1:\n" \
2089  : "=&r"(result), "=&r"(rc), "+A"(*addr) \
2090  : "r"(oldval), "r"(newval) \
2091  : "memory");
2092  return result;
2093 }
2094 
2102 __STATIC_FORCEINLINE uint64_t __AMOSWAP_D(volatile uint64_t *addr, uint64_t newval)
2103 {
2104  uint64_t result;
2105 
2106  __ASM volatile ("amoswap.d %0, %2, %1" : \
2107  "=r"(result), "+A"(*addr) : "r"(newval) : "memory");
2108  return result;
2109 }
2110 
2118 __STATIC_FORCEINLINE int64_t __AMOADD_D(volatile int64_t *addr, int64_t value)
2119 {
2120  int64_t result;
2121 
2122  __ASM volatile ("amoadd.d %0, %2, %1" : \
2123  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2124  return *addr;
2125 }
2126 
2134 __STATIC_FORCEINLINE int64_t __AMOAND_D(volatile int64_t *addr, int64_t value)
2135 {
2136  int64_t result;
2137 
2138  __ASM volatile ("amoand.d %0, %2, %1" : \
2139  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2140  return *addr;
2141 }
2142 
2150 __STATIC_FORCEINLINE int64_t __AMOOR_D(volatile int64_t *addr, int64_t value)
2151 {
2152  int64_t result;
2153 
2154  __ASM volatile ("amoor.d %0, %2, %1" : \
2155  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2156  return *addr;
2157 }
2158 
2166 __STATIC_FORCEINLINE int64_t __AMOXOR_D(volatile int64_t *addr, int64_t value)
2167 {
2168  int64_t result;
2169 
2170  __ASM volatile ("amoxor.d %0, %2, %1" : \
2171  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2172  return *addr;
2173 }
2174 
2182 __STATIC_FORCEINLINE uint64_t __AMOMAXU_D(volatile uint64_t *addr, uint64_t value)
2183 {
2184  uint64_t result;
2185 
2186  __ASM volatile ("amomaxu.d %0, %2, %1" : \
2187  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2188  return *addr;
2189 }
2190 
2198 __STATIC_FORCEINLINE int64_t __AMOMAX_D(volatile int64_t *addr, int64_t value)
2199 {
2200  int64_t result;
2201 
2202  __ASM volatile ("amomax.d %0, %2, %1" : \
2203  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2204  return *addr;
2205 }
2206 
2214 __STATIC_FORCEINLINE uint64_t __AMOMINU_D(volatile uint64_t *addr, uint64_t value)
2215 {
2216  uint64_t result;
2217 
2218  __ASM volatile ("amominu.d %0, %2, %1" : \
2219  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2220  return *addr;
2221 }
2222 
2230 __STATIC_FORCEINLINE int64_t __AMOMIN_D(volatile int64_t *addr, int64_t value)
2231 {
2232  int64_t result;
2233 
2234  __ASM volatile ("amomin.d %0, %2, %1" : \
2235  "=r"(result), "+A"(*addr) : "r"(value) : "memory");
2236  return *addr;
2237 }
2238 #endif /* __RISCV_XLEN == 64 */
2239  /* End of Doxygen Group NMSIS_Core_CPU_Intrinsic */
2241 
2242 #ifdef __cplusplus
2243 }
2244 #endif
2245 #endif /* __CORE_FEATURE_BASE__ */
CSR_MDCFGINFO_Type::way
rv_csr_t way
D-Cache way.
Definition: core_feature_base.h:387
CSR_MHPMCOUNTER9
#define CSR_MHPMCOUNTER9
Definition: riscv_encoding.h:718
CSR_MCFGINFO_Type::safety_mecha
rv_csr_t safety_mecha
Indicate Core's safety mechanism.
Definition: core_feature_base.h:357
MCOUNTINHIBIT_CY
#define MCOUNTINHIBIT_CY
Definition: riscv_encoding.h:208
CSR_MDCFGINFO_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:394
CSR_MSAVESTATUS_Type::mpp2
rv_csr_t mpp2
bit: 9..10 privilede mode of second level NMI/exception nestting
Definition: core_feature_base.h:288
CSR_MHPMCOUNTER15H
#define CSR_MHPMCOUNTER15H
Definition: riscv_encoding.h:865
CSR_SSTATUS
#define CSR_SSTATUS
Definition: riscv_encoding.h:531
CSR_MCACHECTL_Type::dc_ecc_chk_en
rv_csr_t dc_ecc_chk_en
D-Cache check ECC codes enable.
Definition: core_feature_base.h:272
CSR_MISA_Type::c
rv_csr_t c
bit: 2 Compressed extension
Definition: core_feature_base.h:72
__enable_ext_irq_s
__STATIC_FORCEINLINE void __enable_ext_irq_s(void)
Enable External IRQ Interrupts in supervisor mode.
Definition: core_feature_base.h:820
CSR_MHPMCOUNTER7
#define CSR_MHPMCOUNTER7
Definition: riscv_encoding.h:716
CSR_MTLBCFGINFO_Type::_reserved0
rv_csr_t _reserved0
Reserved 0.
Definition: core_feature_base.h:406
__disable_sw_irq
__STATIC_FORCEINLINE void __disable_sw_irq(void)
Disable software IRQ Interrupts.
Definition: core_feature_base.h:743
CSR_MPPICFGINFO_Type::ppi_bpa
rv_csr_t ppi_bpa
PPI base address.
Definition: core_feature_base.h:422
CSR_MPPICFGINFO_Type::_reserved1
rv_csr_t _reserved1
Reserved 0.
Definition: core_feature_base.h:421
CSR_MMISCCTRL_Type::ldspec_en
rv_csr_t ldspec_en
bit: 12 enable load speculative goes to mem interface
Definition: core_feature_base.h:242
__AMOMINU_W
__STATIC_FORCEINLINE uint32_t __AMOMINU_W(volatile uint32_t *addr, uint32_t value)
Atomic unsigned MIN with 32bit value.
Definition: core_feature_base.h:2041
__get_hart_index
__STATIC_FORCEINLINE unsigned long __get_hart_index(void)
Get hart index of current cluster.
Definition: core_feature_base.h:1063
CSR_TXEVT
#define CSR_TXEVT
Definition: riscv_encoding.h:1017
CSR_MDCFGINFO_Type::_reserved0
rv_csr_t _reserved0
Definition: core_feature_base.h:389
CSR_MHPMCOUNTER16
#define CSR_MHPMCOUNTER16
Definition: riscv_encoding.h:725
WFI_SleepMode
WFI_SleepMode
WFI Sleep Mode enumeration.
Definition: core_feature_base.h:1169
CSR_MHPMEVENT26
#define CSR_MHPMEVENT26
Definition: riscv_encoding.h:764
CSR_MCFGINFO_Type::fio
rv_csr_t fio
FIO present.
Definition: core_feature_base.h:341
CSR_MMISCCTRL_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:247
CSR_MECCCODE_Type::_reserved0
rv_csr_t _reserved0
Reserved 0.
Definition: core_feature_base.h:457
CSR_MTVEC_Type::addr
rv_csr_t addr
bit: 6..31 mtvec address
Definition: core_feature_base.h:155
CSR_MISA_Type::d
rv_csr_t d
bit: 3 Double-precision floating-point extension
Definition: core_feature_base.h:73
CSR_MISA_Type::u
rv_csr_t u
bit: 20 User mode implemented
Definition: core_feature_base.h:90
CSR_MECCCODE_Type::sramid
rv_csr_t sramid
The ID of RAM that has 1bit ECC error, software can clear these bits.
Definition: core_feature_base.h:460
CSR_MCACHECTL_Type::ic_en
rv_csr_t ic_en
I-Cache enable.
Definition: core_feature_base.h:257
CSR_MHPMCOUNTER22H
#define CSR_MHPMCOUNTER22H
Definition: riscv_encoding.h:872
SSTATUS_SIE
#define SSTATUS_SIE
Definition: riscv_encoding.h:79
CSR_MECCCODE_Type::_reserved1
rv_csr_t _reserved1
Reserved 0.
Definition: core_feature_base.h:459
CSR_MDCAUSE_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:225
CSR_MDLMCTL_Type::dlm_rwecc
rv_csr_t dlm_rwecc
Control mecc_code write to dlm, simulate error injection.
Definition: core_feature_base.h:324
__enable_mhpm_counters
__STATIC_FORCEINLINE void __enable_mhpm_counters(unsigned long mask)
Enable hardware performance counters with mask.
Definition: core_feature_base.h:1266
CSR_MPPICFGINFO_Type::ppi_size
rv_csr_t ppi_size
PPI size, need to be 2^n size.
Definition: core_feature_base.h:420
CSR_MHPMCOUNTER20H
#define CSR_MHPMCOUNTER20H
Definition: riscv_encoding.h:870
CSR_MHPMCOUNTER23H
#define CSR_MHPMCOUNTER23H
Definition: riscv_encoding.h:873
CSR_MCACHECTL_Type::dc_ecc_en
rv_csr_t dc_ecc_en
D-Cache ECC enable.
Definition: core_feature_base.h:268
CSR_MCACHECTL_Type::_reserved1
rv_csr_t _reserved1
Definition: core_feature_base.h:273
CSR_MISA_Type::s
rv_csr_t s
bit: 18 Supervisor mode implemented
Definition: core_feature_base.h:88
__disable_mcycle_counter
__STATIC_FORCEINLINE void __disable_mcycle_counter(void)
Disable MCYCLE counter.
Definition: core_feature_base.h:1212
CSR_MHPMEVENT19
#define CSR_MHPMEVENT19
Definition: riscv_encoding.h:757
__enable_timer_irq
__STATIC_FORCEINLINE void __enable_timer_irq(void)
Enable Timer IRQ Interrupts.
Definition: core_feature_base.h:710
__disable_timer_irq
__STATIC_FORCEINLINE void __disable_timer_irq(void)
Disable Timer IRQ Interrupts.
Definition: core_feature_base.h:721
CSR_MCFGINFO_Type::dcache
rv_csr_t dcache
DCache present.
Definition: core_feature_base.h:347
CSR_MSUBM_Type::typ
rv_csr_t typ
bit: 6..7 current trap type
Definition: core_feature_base.h:206
CSR_MHPMCOUNTER14
#define CSR_MHPMCOUNTER14
Definition: riscv_encoding.h:723
CSR_MICFGINFO_Type::lsize
rv_csr_t lsize
I-Cache line size.
Definition: core_feature_base.h:371
CSR_MHPMCOUNTER17H
#define CSR_MHPMCOUNTER17H
Definition: riscv_encoding.h:867
CSR_MHARTID
#define CSR_MHARTID
Definition: riscv_encoding.h:773
CSR_MHPMCOUNTER21
#define CSR_MHPMCOUNTER21
Definition: riscv_encoding.h:730
CSR_MSTATUS_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:143
CSR_MECCLOCK_Type::_reserved0
rv_csr_t _reserved0
Reserved.
Definition: core_feature_base.h:446
MIE_MTIE
#define MIE_MTIE
Definition: riscv_encoding.h:166
CSR_MSTATUS_Type::_reserved0
rv_csr_t _reserved0
bit: 0 Reserved
Definition: core_feature_base.h:125
CSR_MCACHECTL_Type::ic_ecc_excp_en
rv_csr_t ic_ecc_excp_en
I-Cache 2bit ECC error exception enable.
Definition: core_feature_base.h:260
__enable_irq_s
__STATIC_FORCEINLINE void __enable_irq_s(void)
Enable IRQ Interrupts in supervisor mode.
Definition: core_feature_base.h:798
CSR_MTLBCFGINFO_Type::set
rv_csr_t set
Main TLB sets per way.
Definition: core_feature_base.h:402
__enable_sw_irq
__STATIC_FORCEINLINE void __enable_sw_irq(void)
Enable software IRQ Interrupts.
Definition: core_feature_base.h:732
__NOP
__STATIC_FORCEINLINE void __NOP(void)
NOP Instruction.
Definition: core_feature_base.h:1109
__RV_CSR_CLEAR
#define __RV_CSR_CLEAR(csr, val)
CSR operation Macro for csrc instruction.
Definition: core_feature_base.h:606
__disable_sw_irq_s
__STATIC_FORCEINLINE void __disable_sw_irq_s(void)
Disable software IRQ Interrupts in supervisor mode.
Definition: core_feature_base.h:875
CSR_MSAVESTATUS_Type::mpie2
rv_csr_t mpie2
bit: 8 interrupt enable flag of second level NMI/exception nestting
Definition: core_feature_base.h:287
CSR_MFIOCFGINFO_Type
Union type to access MFIOCFG_INFO CSR register.
Definition: core_feature_base.h:430
CSR_MFIOCFGINFO_Type::_reserved0
rv_csr_t _reserved0
Reserved.
Definition: core_feature_base.h:432
CSR_MHPMEVENT11
#define CSR_MHPMEVENT11
Definition: riscv_encoding.h:749
CSR_MCACHECTL_Type
Union type to access MCACHE_CTL CSR register.
Definition: core_feature_base.h:255
CSR_MILMCTL_Type::ilm_en
rv_csr_t ilm_en
ILM enable.
Definition: core_feature_base.h:305
CSR_MSTATUS_Type::xs
rv_csr_t xs
bit: XS status flag
Definition: core_feature_base.h:136
CSR_MCACHECTL_Type::dc_en
rv_csr_t dc_en
DCache enable.
Definition: core_feature_base.h:267
CSR_MEDELEG
#define CSR_MEDELEG
Definition: riscv_encoding.h:598
CSR_MSAVESTATUS_Type::_reserved2
rv_csr_t _reserved2
bit: 16..31 Reserved
Definition: core_feature_base.h:294
__get_hpm_event
__STATIC_FORCEINLINE unsigned long __get_hpm_event(unsigned long idx)
Get event for selected high performance monitor event.
Definition: core_feature_base.h:1356
CSR_MTVEC_Type::mode
rv_csr_t mode
bit: 0..5 interrupt mode control
Definition: core_feature_base.h:151
CSR_MHPMEVENT6
#define CSR_MHPMEVENT6
Definition: riscv_encoding.h:744
CSR_MCAUSE_Type::_reserved1
rv_csr_t _reserved1
bit: 26..24 Reserved
Definition: core_feature_base.h:169
__ECALL
__STATIC_FORCEINLINE void __ECALL(void)
Environment Call Instruction.
Definition: core_feature_base.h:1161
CSR_MHPMCOUNTER22
#define CSR_MHPMCOUNTER22
Definition: riscv_encoding.h:731
CSR_MHPMCOUNTER31
#define CSR_MHPMCOUNTER31
Definition: riscv_encoding.h:740
CSR_MMISCCTRL_Type::misalign
rv_csr_t misalign
bit: 6 misaligned access support flag
Definition: core_feature_base.h:236
CSR_MECCCODE_Type
Union type to access MECC_CODE CSR register.
Definition: core_feature_base.h:454
CSR_MCFGINFO_Type::vpu_degree
rv_csr_t vpu_degree
Indicate the VPU degree of parallel.
Definition: core_feature_base.h:354
CSR_MILMCTL_Type::ilm_ecc_chk_en
rv_csr_t ilm_ecc_chk_en
ILM check ECC codes enable.
Definition: core_feature_base.h:309
CSR_MCOUNTINHIBIT_Type
Union type to access MCOUNTINHIBIT CSR register.
Definition: core_feature_base.h:186
CSR_MMISCCTRL_Type::core_buserr
rv_csr_t core_buserr
bit: 8 core bus error exception or interrupt
Definition: core_feature_base.h:238
CSR_MICFGINFO_Type
Union type to access MICFG_INFO CSR register.
Definition: core_feature_base.h:367
CSR_MHPMEVENT17
#define CSR_MHPMEVENT17
Definition: riscv_encoding.h:755
CSR_MCOUNTINHIBIT_Type::_reserved0
rv_csr_t _reserved0
bit: 1 Reserved
Definition: core_feature_base.h:189
CSR_MHPMCOUNTER27H
#define CSR_MHPMCOUNTER27H
Definition: riscv_encoding.h:877
CSR_MSTATUS_Type::_reserved3
rv_csr_t _reserved3
bit: Reserved
Definition: core_feature_base.h:131
CSR_MHPMCOUNTER13
#define CSR_MHPMCOUNTER13
Definition: riscv_encoding.h:722
CSR_MCFGINFO_Type::vnice
rv_csr_t vnice
VNICE present.
Definition: core_feature_base.h:358
CSR_MHPMEVENT9
#define CSR_MHPMEVENT9
Definition: riscv_encoding.h:747
__AMOAND_W
__STATIC_FORCEINLINE int32_t __AMOAND_W(volatile int32_t *addr, int32_t value)
Atomic And with 32bit value.
Definition: core_feature_base.h:1961
CSR_MSAVESTATUS_Type::ptyp1
rv_csr_t ptyp1
bit: 6..7 NMI/exception type of before first nestting
Definition: core_feature_base.h:286
CSR_MFIOCFGINFO_Type::_reserved1
rv_csr_t _reserved1
Reserved.
Definition: core_feature_base.h:434
CSR_MMISCCTRL_Type::sijump_en
rv_csr_t sijump_en
bit: 11 SIJUMP mode of trace
Definition: core_feature_base.h:241
CSR_MHPMCOUNTER10H
#define CSR_MHPMCOUNTER10H
Definition: riscv_encoding.h:860
CSR_MCFGINFO_Type
Union type to access MCFG_INFO CSR register.
Definition: core_feature_base.h:335
CSR_MHPMCOUNTER14H
#define CSR_MHPMCOUNTER14H
Definition: riscv_encoding.h:864
CSR_MSTATUS_Type::spie
rv_csr_t spie
bit: 3 Supervisor Privilede mode interrupt enable flag
Definition: core_feature_base.h:130
CSR_MTLBCFGINFO_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:411
CSR_MCFGINFO_Type::clic
rv_csr_t clic
CLIC present.
Definition: core_feature_base.h:339
__disable_ext_irq_s
__STATIC_FORCEINLINE void __disable_ext_irq_s(void)
Disable External IRQ Interrupts in supervisor mode.
Definition: core_feature_base.h:831
CSR_MHPMCOUNTER13H
#define CSR_MHPMCOUNTER13H
Definition: riscv_encoding.h:863
CSR_MTLBCFGINFO_Type::i_size
rv_csr_t i_size
ITLB size.
Definition: core_feature_base.h:407
CSR_MSAVESTATUS_Type::mpp1
rv_csr_t mpp1
bit: 1..2 privilede mode of fisrt level NMI/exception nestting
Definition: core_feature_base.h:284
__AMOXOR_W
__STATIC_FORCEINLINE int32_t __AMOXOR_W(volatile int32_t *addr, int32_t value)
Atomic XOR with 32bit value.
Definition: core_feature_base.h:1993
CSR_MSTATUS_Type::_reserved1
rv_csr_t _reserved1
bit: 2 Reserved
Definition: core_feature_base.h:127
CSR_MFIOCFGINFO_Type::fio_size
rv_csr_t fio_size
FIO size, need to be 2^n size.
Definition: core_feature_base.h:433
__AMOMAX_W
__STATIC_FORCEINLINE int32_t __AMOMAX_W(volatile int32_t *addr, int32_t value)
Atomic signed MAX with 32bit value.
Definition: core_feature_base.h:2025
CSR_MCYCLEH
#define CSR_MCYCLEH
Definition: riscv_encoding.h:851
CSR_MDCFGINFO_Type
Union type to access MDCFG_INFO CSR register.
Definition: core_feature_base.h:384
CSR_MCAUSE_Type
Union type to access MCAUSE CSR register.
Definition: core_feature_base.h:164
CSR_MICFGINFO_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:378
CSR_MCAUSE_Type::mpil
rv_csr_t mpil
bit: 23..16 Previous interrupt level
Definition: core_feature_base.h:168
CSR_MCFGINFO_Type::tee
rv_csr_t tee
TEE present.
Definition: core_feature_base.h:337
CSR_MSUBM_Type::ptyp
rv_csr_t ptyp
bit: 8..9 previous trap type
Definition: core_feature_base.h:207
CSR_MISA_Type
Union type to access MISA CSR register.
Definition: core_feature_base.h:68
CSR_MHPMCOUNTER20
#define CSR_MHPMCOUNTER20
Definition: riscv_encoding.h:729
CSR_MHPMCOUNTER4
#define CSR_MHPMCOUNTER4
Definition: riscv_encoding.h:713
__set_wfi_sleepmode
__STATIC_FORCEINLINE void __set_wfi_sleepmode(WFI_SleepMode_Type mode)
Set Sleep mode of WFI.
Definition: core_feature_base.h:1181
CSR_MHPMCOUNTER8H
#define CSR_MHPMCOUNTER8H
Definition: riscv_encoding.h:858
CSR_MMISCCTRL_Type::_reserved1
rv_csr_t _reserved1
bit: 4..5 Reserved
Definition: core_feature_base.h:235
CSR_MISA_Type::t
rv_csr_t t
bit: 19 Tentatively reserved for Transactional Memory extension
Definition: core_feature_base.h:89
CSR_MHPMCOUNTER8
#define CSR_MHPMCOUNTER8
Definition: riscv_encoding.h:717
CSR_MSAVESTATUS_Type::ptyp2
rv_csr_t ptyp2
bit: 14..15 NMI/exception type of before second nestting
Definition: core_feature_base.h:290
CSR_MISA_Type::mxl
rv_csr_t mxl
bit: 30..31 Machine XLEN
Definition: core_feature_base.h:99
CSR_MSAVESTATUS_Type::_reserved1
rv_csr_t _reserved1
bit: 11..13 Reserved
Definition: core_feature_base.h:289
MIE_MEIE
#define MIE_MEIE
Definition: riscv_encoding.h:169
__RV_CSR_WRITE
#define __RV_CSR_WRITE(csr, val)
CSR operation Macro for csrw instruction.
Definition: core_feature_base.h:532
CSR_MISA_Type::f
rv_csr_t f
bit: 5 Single-precision floating-point extension
Definition: core_feature_base.h:75
CSR_MDLMCTL_Type
Union type to access MDLM_CTL CSR register.
Definition: core_feature_base.h:319
CSR_MTLBCFGINFO_Type::_reserved1
rv_csr_t _reserved1
Reserved 0.
Definition: core_feature_base.h:409
__get_core_irq_pending
__STATIC_FORCEINLINE uint32_t __get_core_irq_pending(uint32_t irq)
Get Core IRQ Interrupt Pending status.
Definition: core_feature_base.h:776
CSR_MHPMEVENT31
#define CSR_MHPMEVENT31
Definition: riscv_encoding.h:769
CSR_MHPMEVENT14
#define CSR_MHPMEVENT14
Definition: riscv_encoding.h:752
CSR_MILMCTL_Type::ilm_bpa
rv_csr_t ilm_bpa
ILM base address.
Definition: core_feature_base.h:311
CSR_MCFGINFO_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:361
CSR_TIME
#define CSR_TIME
Definition: riscv_encoding.h:497
CSR_MHPMEVENT3
#define CSR_MHPMEVENT3
Definition: riscv_encoding.h:741
CSR_MISA_Type::j
rv_csr_t j
bit: 9 Tentatively reserved for Dynamically Translated Languages extension
Definition: core_feature_base.h:79
CSR_MINSTRET
#define CSR_MINSTRET
Definition: riscv_encoding.h:711
__set_hpm_event
__STATIC_FORCEINLINE void __set_hpm_event(unsigned long idx, unsigned long event)
Set event for selected high performance monitor event.
Definition: core_feature_base.h:1312
CSR_MICFGINFO_Type::lm_xonly
rv_csr_t lm_xonly
ILM Execute only permission.
Definition: core_feature_base.h:374
__LH
__STATIC_FORCEINLINE uint16_t __LH(volatile void *addr)
Load 16bit value from address (16 bit)
Definition: core_feature_base.h:1810
CSR_MISA_Type::g
rv_csr_t g
bit: 6 Additional standard extensions present
Definition: core_feature_base.h:76
__LW
__STATIC_FORCEINLINE uint32_t __LW(volatile void *addr)
Load 32bit value from address (32 bit)
Definition: core_feature_base.h:1824
CSR_MMISCCTL_Type
CSR_MMISCCTRL_Type CSR_MMISCCTL_Type
Definition: core_feature_base.h:250
CSR_MIE
#define CSR_MIE
Definition: riscv_encoding.h:600
CSR_MDLMCTL_Type::dlm_en
rv_csr_t dlm_en
DLM enable.
Definition: core_feature_base.h:321
__enable_timer_irq_s
__STATIC_FORCEINLINE void __enable_timer_irq_s(void)
Enable Timer IRQ Interrupts in supervisor mode.
Definition: core_feature_base.h:842
__clear_core_irq_pending
__STATIC_FORCEINLINE void __clear_core_irq_pending(uint32_t irq)
Clear Core IRQ Interrupt Pending status.
Definition: core_feature_base.h:787
CSR_MDLMCTL_Type::dlm_ecc_excp_en
rv_csr_t dlm_ecc_excp_en
DLM ECC exception enable.
Definition: core_feature_base.h:323
CSR_MSAVESTATUS_Type::mpie1
rv_csr_t mpie1
bit: 0 interrupt enable flag of fisrt level NMI/exception nestting
Definition: core_feature_base.h:283
CSR_MCAUSE_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:180
CSR_MSTATUS_Type::fs
rv_csr_t fs
bit: FS status flag
Definition: core_feature_base.h:135
CSR_MHPMCOUNTER17
#define CSR_MHPMCOUNTER17
Definition: riscv_encoding.h:726
CSR_MDCFGINFO_Type::lm_ecc
rv_csr_t lm_ecc
DLM ECC present.
Definition: core_feature_base.h:391
CSR_MMISCCTRL_Type::_reserved2
rv_csr_t _reserved2
bit: 13 Reserved
Definition: core_feature_base.h:243
__get_hart_id
__STATIC_FORCEINLINE unsigned long __get_hart_id(void)
Get hart id of current cluster.
Definition: core_feature_base.h:1083
CSR_MHPMEVENT12
#define CSR_MHPMEVENT12
Definition: riscv_encoding.h:750
CSR_MCAUSE_Type::mpie
rv_csr_t mpie
bit: 27 Interrupt enable flag before enter interrupt
Definition: core_feature_base.h:170
CSR_MCACHECTL_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:275
CSR_MSUBM_Type
Union type to access MSUBM CSR register.
Definition: core_feature_base.h:203
CSR_MHPMCOUNTER19H
#define CSR_MHPMCOUNTER19H
Definition: riscv_encoding.h:869
MSTATUS_MPIE
#define MSTATUS_MPIE
Definition: riscv_encoding.h:44
__disable_irq_s
__STATIC_FORCEINLINE void __disable_irq_s(void)
Disable IRQ Interrupts in supervisor mode.
Definition: core_feature_base.h:809
CSR_MCOUNTINHIBIT_Type::cy
rv_csr_t cy
bit: 0 1 means disable mcycle counter
Definition: core_feature_base.h:188
CSR_MISA_Type::l
rv_csr_t l
bit: 11 Tentatively reserved for Decimal Floating-Point extension
Definition: core_feature_base.h:81
CSR_MCACHECTL_Type::ic_ecc_en
rv_csr_t ic_ecc_en
I-Cache ECC enable.
Definition: core_feature_base.h:259
CSR_MTVEC_Type
Union type to access MTVEC CSR register.
Definition: core_feature_base.h:149
CSR_MDLMCTL_Type::dlm_ecc_en
rv_csr_t dlm_ecc_en
DLM ECC eanble.
Definition: core_feature_base.h:322
__set_rv_cycle
__STATIC_FORCEINLINE void __set_rv_cycle(uint64_t cycle)
Set whole 64 bits value of mcycle counter.
Definition: core_feature_base.h:956
CSR_MTLBCFGINFO_Type::d_size
rv_csr_t d_size
DTLB size.
Definition: core_feature_base.h:408
MSTATUS_MPP
#define MSTATUS_MPP
Definition: riscv_encoding.h:47
__disable_all_counter
__STATIC_FORCEINLINE void __disable_all_counter(void)
Disable all MCYCLE & MINSTRET & MHPMCOUNTER counter.
Definition: core_feature_base.h:1300
CSR_MMISCCTRL_Type
Union type to access MMISC_CTRL CSR register.
Definition: core_feature_base.h:231
CSR_MHPMCOUNTER18H
#define CSR_MHPMCOUNTER18H
Definition: riscv_encoding.h:868
__SB
__STATIC_FORCEINLINE void __SB(volatile void *addr, uint8_t val)
Write 8bit value to address (8 bit)
Definition: core_feature_base.h:1854
CSR_MCFGINFO_Type::icache
rv_csr_t icache
ICache present.
Definition: core_feature_base.h:346
__disable_mhpm_counters
__STATIC_FORCEINLINE void __disable_mhpm_counters(unsigned long mask)
Disable hardware performance counters with mask.
Definition: core_feature_base.h:1278
CSR_MSTATUS_Type::sum
rv_csr_t sum
bit: Supervisor Mode load and store protection
Definition: core_feature_base.h:138
CSR_MCFGINFO_Type::etrace
rv_csr_t etrace
Etrace present.
Definition: core_feature_base.h:356
CSR_MHPMEVENT29
#define CSR_MHPMEVENT29
Definition: riscv_encoding.h:767
CSR_MHPMCOUNTER24
#define CSR_MHPMCOUNTER24
Definition: riscv_encoding.h:733
CSR_MISA_Type::h
rv_csr_t h
bit: 7 Hypervisor extension
Definition: core_feature_base.h:77
CSR_MISA_Type::b
rv_csr_t b
bit: 1 Tentatively reserved for Bit-Manipulation extension
Definition: core_feature_base.h:71
CSR_MHPMEVENT15
#define CSR_MHPMEVENT15
Definition: riscv_encoding.h:753
CSR_MCFGINFO_Type::ilm
rv_csr_t ilm
ILM present.
Definition: core_feature_base.h:344
CSR_MDCFGINFO_Type::lm_size
rv_csr_t lm_size
DLM size, need to be 2^n size.
Definition: core_feature_base.h:390
__disable_timer_irq_s
__STATIC_FORCEINLINE void __disable_timer_irq_s(void)
Disable Timer IRQ Interrupts in supervisor mode.
Definition: core_feature_base.h:853
CSR_MCACHECTL_Type::ic_rwtecc
rv_csr_t ic_rwtecc
Control I-Cache Tag Ram ECC code injection.
Definition: core_feature_base.h:261
__enable_ext_irq
__STATIC_FORCEINLINE void __enable_ext_irq(void)
Enable External IRQ Interrupts.
Definition: core_feature_base.h:688
CSR_MCFGINFO_Type::ppi
rv_csr_t ppi
PPI present.
Definition: core_feature_base.h:342
__get_rv_time
__STATIC_FORCEINLINE uint64_t __get_rv_time(void)
Read whole 64 bits value of real-time clock.
Definition: core_feature_base.h:1019
CSR_MHPMEVENT13
#define CSR_MHPMEVENT13
Definition: riscv_encoding.h:751
CSR_MCACHECTL_Type::ic_scpd_mod
rv_csr_t ic_scpd_mod
Scratchpad mode, 0: Scratchpad as ICache Data RAM, 1: Scratchpad as ILM SRAM.
Definition: core_feature_base.h:258
CSR_TIMEH
#define CSR_TIMEH
Definition: riscv_encoding.h:784
CSR_MCAUSE_Type::minhv
rv_csr_t minhv
bit: 30 Machine interrupt vector table
Definition: core_feature_base.h:172
CSR_MHPMEVENT27
#define CSR_MHPMEVENT27
Definition: riscv_encoding.h:765
CSR_MICFGINFO_Type::lm_ecc
rv_csr_t lm_ecc
ILM ECC present.
Definition: core_feature_base.h:375
CSR_MISA_Type::_reserved1
rv_csr_t _reserved1
bit: 10 Reserved
Definition: core_feature_base.h:80
CSR_MTLBCFGINFO_Type
Union type to access MTLBCFG_INFO CSR register.
Definition: core_feature_base.h:400
WFE_WFE
#define WFE_WFE
Definition: riscv_encoding.h:203
CSR_MMISCCTRL_Type::zcmt_zcmp
rv_csr_t zcmt_zcmp
bit: 7 Zc Ext uses the cfdsp of D Ext’s encoding or not
Definition: core_feature_base.h:237
CSR_MHPMEVENT25
#define CSR_MHPMEVENT25
Definition: riscv_encoding.h:763
CSR_MHPMCOUNTER30H
#define CSR_MHPMCOUNTER30H
Definition: riscv_encoding.h:880
__AMOMAXU_W
__STATIC_FORCEINLINE uint32_t __AMOMAXU_W(volatile uint32_t *addr, uint32_t value)
Atomic unsigned MAX with 32bit value.
Definition: core_feature_base.h:2009
__enable_core_irq
__STATIC_FORCEINLINE void __enable_core_irq(uint32_t irq)
Enable Core IRQ Interrupt.
Definition: core_feature_base.h:765
__WFI
__STATIC_FORCEINLINE void __WFI(void)
Wait For Interrupt.
Definition: core_feature_base.h:1123
CSR_MHPMEVENT22
#define CSR_MHPMEVENT22
Definition: riscv_encoding.h:760
CSR_SIE
#define CSR_SIE
Definition: riscv_encoding.h:534
CSR_SIP
#define CSR_SIP
Definition: riscv_encoding.h:547
CSR_MECCCODE_Type::code
rv_csr_t code
Used to inject ECC check code.
Definition: core_feature_base.h:456
CSR_MSTATUS_Type::mpie
rv_csr_t mpie
bit: mirror of MIE flag
Definition: core_feature_base.h:132
CSR_MCFGINFO_Type::zc_xlcz
rv_csr_t zc_xlcz
Zc and xlcz extension present.
Definition: core_feature_base.h:352
CSR_MCFGINFO_Type::dsp_n2
rv_csr_t dsp_n2
DSP N2 present.
Definition: core_feature_base.h:350
MSTATUS_MIE
#define MSTATUS_MIE
Definition: riscv_encoding.h:40
CSR_MECCCODE_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:463
CSR_MCFGINFO_Type::iregion
rv_csr_t iregion
IREGION present.
Definition: core_feature_base.h:353
__enable_mcycle_counter
__STATIC_FORCEINLINE void __enable_mcycle_counter(void)
Enable MCYCLE counter.
Definition: core_feature_base.h:1202
__disable_irq
__STATIC_FORCEINLINE void __disable_irq(void)
Disable IRQ Interrupts.
Definition: core_feature_base.h:677
CSR_MILMCTL_Type::ilm_rwecc
rv_csr_t ilm_rwecc
Control mecc_code write to ilm, simulate error injection.
Definition: core_feature_base.h:308
__enable_mhpm_counter
__STATIC_FORCEINLINE void __enable_mhpm_counter(unsigned long idx)
Enable selected hardware performance monitor counter.
Definition: core_feature_base.h:1243
CSR_MILMCTL_Type::_reserved0
rv_csr_t _reserved0
Reserved.
Definition: core_feature_base.h:310
WFI_SHALLOW_SLEEP
@ WFI_SHALLOW_SLEEP
Shallow sleep mode, the core_clk will poweroff.
Definition: core_feature_base.h:1170
CSR_MHPMEVENT7
#define CSR_MHPMEVENT7
Definition: riscv_encoding.h:745
CSR_MILMCTL_Type::ilm_ecc_en
rv_csr_t ilm_ecc_en
ILM ECC eanble.
Definition: core_feature_base.h:306
CSR_MCACHECTL_Type::_reserved0
rv_csr_t _reserved0
Definition: core_feature_base.h:266
CSR_MHPMEVENT20
#define CSR_MHPMEVENT20
Definition: riscv_encoding.h:758
CSR_MECCLOCK_Type
Union type to access MECC_LOCK CSR register.
Definition: core_feature_base.h:443
CSR_MCACHECTL_Type::ic_pf_en
rv_csr_t ic_pf_en
I-Cache prefetch enable.
Definition: core_feature_base.h:263
__CAS_W
__STATIC_FORCEINLINE uint32_t __CAS_W(volatile uint32_t *addr, uint32_t oldval, uint32_t newval)
Compare and Swap 32bit value using LR and SC.
Definition: core_feature_base.h:1905
CSR_MHPMEVENT5
#define CSR_MHPMEVENT5
Definition: riscv_encoding.h:743
__get_rv_cycle
__STATIC_FORCEINLINE uint64_t __get_rv_cycle(void)
Read whole 64 bits value of mcycle counter.
Definition: core_feature_base.h:930
CSR_MHPMCOUNTER16H
#define CSR_MHPMCOUNTER16H
Definition: riscv_encoding.h:866
CSR_MECCCODE_Type::_reserved2
rv_csr_t _reserved2
Reserved 0.
Definition: core_feature_base.h:461
__switch_mode
__STATIC_FORCEINLINE void __switch_mode(uint8_t mode, uintptr_t stack, void(*entry_point)(void))
switch privilege from machine mode to others.
Definition: core_feature_base.h:638
__AMOOR_W
__STATIC_FORCEINLINE int32_t __AMOOR_W(volatile int32_t *addr, int32_t value)
Atomic OR with 32bit value.
Definition: core_feature_base.h:1977
CSR_MTVEC_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:158
CSR_MHPMEVENT16
#define CSR_MHPMEVENT16
Definition: riscv_encoding.h:754
CSR_MECCLOCK_Type::ecc_lock
rv_csr_t ecc_lock
RW permission, ECC Lock configure.
Definition: core_feature_base.h:445
CSR_MICFGINFO_Type::set
rv_csr_t set
I-Cache sets per way.
Definition: core_feature_base.h:369
__SH
__STATIC_FORCEINLINE void __SH(volatile void *addr, uint16_t val)
Write 16bit value to address (16 bit)
Definition: core_feature_base.h:1865
CSR_MCAUSE_Type::exccode
rv_csr_t exccode
bit: 11..0 exception or interrupt code
Definition: core_feature_base.h:166
CSR_MHPMCOUNTER4H
#define CSR_MHPMCOUNTER4H
Definition: riscv_encoding.h:854
CSR_MINSTRETH
#define CSR_MINSTRETH
Definition: riscv_encoding.h:852
CSR_MHPMCOUNTER12
#define CSR_MHPMCOUNTER12
Definition: riscv_encoding.h:721
CSR_MHPMCOUNTER28H
#define CSR_MHPMCOUNTER28H
Definition: riscv_encoding.h:878
CSR_MHPMCOUNTER25
#define CSR_MHPMCOUNTER25
Definition: riscv_encoding.h:734
CSR_MCOUNTINHIBIT_Type::ir
rv_csr_t ir
bit: 2 1 means disable minstret counter
Definition: core_feature_base.h:190
CSR_MTLBCFGINFO_Type::way
rv_csr_t way
Main TLB ways.
Definition: core_feature_base.h:403
CSR_MHPMEVENT10
#define CSR_MHPMEVENT10
Definition: riscv_encoding.h:748
MIE_STIE
#define MIE_STIE
Definition: riscv_encoding.h:164
CSR_MHPMEVENT30
#define CSR_MHPMEVENT30
Definition: riscv_encoding.h:768
CSR_MHPMCOUNTER9H
#define CSR_MHPMCOUNTER9H
Definition: riscv_encoding.h:859
CSR_MSTATUS_Type::mpp
rv_csr_t mpp
bit: mirror of Privilege Mode
Definition: core_feature_base.h:134
CSR_MCFGINFO_Type::_reserved1
rv_csr_t _reserved1
Definition: core_feature_base.h:359
CSR_MHPMCOUNTER11
#define CSR_MHPMCOUNTER11
Definition: riscv_encoding.h:720
CSR_MICFGINFO_Type::way
rv_csr_t way
I-Cache way.
Definition: core_feature_base.h:370
MCOUNTINHIBIT_IR
#define MCOUNTINHIBIT_IR
Definition: riscv_encoding.h:207
CSR_MHPMCOUNTER7H
#define CSR_MHPMCOUNTER7H
Definition: riscv_encoding.h:857
__enable_core_irq_s
__STATIC_FORCEINLINE void __enable_core_irq_s(uint32_t irq)
Enable Core IRQ Interrupt in supervisor mode.
Definition: core_feature_base.h:897
CSR_MDLMCTL_Type::dlm_bpa
rv_csr_t dlm_bpa
DLM base address.
Definition: core_feature_base.h:327
__enable_irq
__STATIC_FORCEINLINE void __enable_irq(void)
Enable IRQ Interrupts.
Definition: core_feature_base.h:666
CSR_MHPMCOUNTER27
#define CSR_MHPMCOUNTER27
Definition: riscv_encoding.h:736
__STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE
Define a static function that should be always inlined by the compiler.
Definition: nmsis_gcc.h:70
CSR_MCACHECTL_Type::dc_rwtecc
rv_csr_t dc_rwtecc
Control D-Cache Tag Ram ECC code injection.
Definition: core_feature_base.h:270
CSR_MCOUNTINHIBIT
#define CSR_MCOUNTINHIBIT
Definition: riscv_encoding.h:608
CSR_MHPMCOUNTER5H
#define CSR_MHPMCOUNTER5H
Definition: riscv_encoding.h:855
__get_core_irq_pending_s
__STATIC_FORCEINLINE uint32_t __get_core_irq_pending_s(uint32_t irq)
Get Core IRQ Interrupt Pending status in supervisor mode.
Definition: core_feature_base.h:908
__get_cluster_id
__STATIC_FORCEINLINE unsigned long __get_cluster_id(void)
Get cluster id of current cluster.
Definition: core_feature_base.h:1047
CSR_MCYCLE
#define CSR_MCYCLE
Definition: riscv_encoding.h:710
CSR_MCFGINFO_Type::sec_mode
rv_csr_t sec_mode
Smwg extension present.
Definition: core_feature_base.h:355
MIE_SEIE
#define MIE_SEIE
Definition: riscv_encoding.h:167
CSR_MCACHECTL_Type::dc_ecc_excp_en
rv_csr_t dc_ecc_excp_en
D-Cache 2bit ECC error exception enable.
Definition: core_feature_base.h:269
CSR_MMISCCTRL_Type::_reserved0
rv_csr_t _reserved0
bit: 0..2 Reserved
Definition: core_feature_base.h:233
CSR_MSTATUS_Type
Union type to access MSTATUS CSR register.
Definition: core_feature_base.h:108
CSR_MDLMCTL_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:329
CSR_MCOUNTINHIBIT_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:197
__TXEVT
__STATIC_FORCEINLINE void __TXEVT(void)
Send TX Event.
Definition: core_feature_base.h:1192
__EBREAK
__STATIC_FORCEINLINE void __EBREAK(void)
Breakpoint Instruction.
Definition: core_feature_base.h:1150
CSR_MHPMCOUNTER29H
#define CSR_MHPMCOUNTER29H
Definition: riscv_encoding.h:879
CSR_MHPMCOUNTER3
#define CSR_MHPMCOUNTER3
Definition: riscv_encoding.h:712
CSR_MHPMCOUNTER12H
#define CSR_MHPMCOUNTER12H
Definition: riscv_encoding.h:862
__enable_sw_irq_s
__STATIC_FORCEINLINE void __enable_sw_irq_s(void)
Enable software IRQ Interrupts in supervisor mode.
Definition: core_feature_base.h:864
CSR_MHPMEVENT8
#define CSR_MHPMEVENT8
Definition: riscv_encoding.h:746
CSR_MCACHECTL_Type::dc_rwdecc
rv_csr_t dc_rwdecc
Control D-Cache Data Ram ECC code injection.
Definition: core_feature_base.h:271
__AMOSWAP_W
__STATIC_FORCEINLINE uint32_t __AMOSWAP_W(volatile uint32_t *addr, uint32_t newval)
Atomic Swap 32bit value into memory.
Definition: core_feature_base.h:1929
CSR_MCFGINFO_Type::smp
rv_csr_t smp
SMP present.
Definition: core_feature_base.h:348
CSR_MDCAUSE_Type
Union type to access MDCAUSE CSR register.
Definition: core_feature_base.h:220
CSR_MICFGINFO_Type::_reserved1
rv_csr_t _reserved1
Definition: core_feature_base.h:376
CSR_MDCFGINFO_Type::set
rv_csr_t set
D-Cache sets per way.
Definition: core_feature_base.h:386
CSR_SLEEPVALUE
#define CSR_SLEEPVALUE
Definition: riscv_encoding.h:1016
__RV_CSR_READ
#define __RV_CSR_READ(csr)
CSR operation Macro for csrr instruction.
Definition: core_feature_base.h:514
CSR_MMISCCTRL_Type::bpu
rv_csr_t bpu
bit: 3 dynamic prediction enable flag
Definition: core_feature_base.h:234
CSR_MCACHECTL_Type::ic_ecc_chk_en
rv_csr_t ic_ecc_chk_en
I-Cache check ECC codes enable.
Definition: core_feature_base.h:265
CSR_MCFGINFO_Type::plic
rv_csr_t plic
PLIC present.
Definition: core_feature_base.h:340
__set_rv_instret
__STATIC_FORCEINLINE void __set_rv_instret(uint64_t instret)
Set whole 64 bits value of machine instruction-retired counter.
Definition: core_feature_base.h:1000
CSR_MDLMCTL_Type::_reserved0
rv_csr_t _reserved0
Reserved.
Definition: core_feature_base.h:326
CSR_MTLBCFGINFO_Type::lsize
rv_csr_t lsize
Main TLB line size.
Definition: core_feature_base.h:404
CSR_MHPMCOUNTER24H
#define CSR_MHPMCOUNTER24H
Definition: riscv_encoding.h:874
CSR_MDCAUSE_Type::mdcause
rv_csr_t mdcause
bit: 0..2 More detailed exception information as MCAUSE supplement
Definition: core_feature_base.h:222
CSR_MHPMCOUNTER5
#define CSR_MHPMCOUNTER5
Definition: riscv_encoding.h:714
__get_hpm_counter
__STATIC_FORCEINLINE unsigned long __get_hpm_counter(unsigned long idx)
Get value of selected high performance monitor couner.
Definition: core_feature_base.h:1536
CSR_MIP
#define CSR_MIP
Definition: riscv_encoding.h:614
CSR_MSTATUS_Type::_reserved4
rv_csr_t _reserved4
bit: Reserved
Definition: core_feature_base.h:133
CSR_MHPMCOUNTER3H
#define CSR_MHPMCOUNTER3H
Definition: riscv_encoding.h:853
__disable_minstret_counter
__STATIC_FORCEINLINE void __disable_minstret_counter(void)
Disable MINSTRET counter.
Definition: core_feature_base.h:1232
CSR_MHPMCOUNTER15
#define CSR_MHPMCOUNTER15
Definition: riscv_encoding.h:724
CSR_MISA_Type::a
rv_csr_t a
bit: 0 Atomic extension
Definition: core_feature_base.h:70
CSR_MHPMCOUNTER6
#define CSR_MHPMCOUNTER6
Definition: riscv_encoding.h:715
CSR_MSAVESTATUS_Type::w
rv_csr_t w
Type used for csr data access.
Definition: core_feature_base.h:297
MIE_SSIE
#define MIE_SSIE
Definition: riscv_encoding.h:161
CSR_MHPMCOUNTER19
#define CSR_MHPMCOUNTER19
Definition: riscv_encoding.h:728
__enable_all_counter
__STATIC_FORCEINLINE void __enable_all_counter(void)
Enable all MCYCLE & MINSTRET & MHPMCOUNTER counter.
Definition: core_feature_base.h:1289
CSR_MHPMEVENT24
#define CSR_MHPMEVENT24
Definition: riscv_encoding.h:762
CSR_MSTATUS_Type::mprv
rv_csr_t mprv
bit: Machine mode PMP
Definition: core_feature_base.h:137
CSR_MHPMCOUNTER11H
#define CSR_MHPMCOUNTER11H
Definition: riscv_encoding.h:861
__enable_minstret_counter
__STATIC_FORCEINLINE void __enable_minstret_counter(void)
Enable MINSTRET counter.
Definition: core_feature_base.h:1222
CSR_MHPMCOUNTER23
#define CSR_MHPMCOUNTER23
Definition: riscv_encoding.h:732
CSR_MHPMCOUNTER26H
#define CSR_MHPMCOUNTER26H
Definition: riscv_encoding.h:876
CSR_MSTATUS_Type::_reserved6
rv_csr_t _reserved6
bit: 19..30 Reserved
Definition: core_feature_base.h:139
CSR_MTLBCFGINFO_Type::ecc
rv_csr_t ecc
Main TLB supports ECC or not.
Definition: core_feature_base.h:405
CSR_MDCFGINFO_Type::_reserved1
rv_csr_t _reserved1
Definition: core_feature_base.h:392
CSR_MISA_Type::p
rv_csr_t p
bit: 15 Tentatively reserved for Packed-SIMD extension
Definition: core_feature_base.h:85
__RV_CSR_SET
#define __RV_CSR_SET(csr, val)
CSR operation Macro for csrs instruction.
Definition: core_feature_base.h:569
CSR_MHPMCOUNTER31H
#define CSR_MHPMCOUNTER31H
Definition: riscv_encoding.h:881
CSR_MHPMCOUNTER21H
#define CSR_MHPMCOUNTER21H
Definition: riscv_encoding.h:871
CSR_MCFGINFO_Type::dsp_n3
rv_csr_t dsp_n3
DSP N3 present.
Definition: core_feature_base.h:351
__WFE
__STATIC_FORCEINLINE void __WFE(void)
Wait For Event.
Definition: core_feature_base.h:1136
CSR_MHPMEVENT18
#define CSR_MHPMEVENT18
Definition: riscv_encoding.h:756
CSR_MPPICFGINFO_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:424
CSR_MISA_Type::_reserved4
rv_csr_t _reserved4
bit: 22 Reserved
Definition: core_feature_base.h:92
CSR_MHPMCOUNTER28
#define CSR_MHPMCOUNTER28
Definition: riscv_encoding.h:737
CSR_MISA_Type::m
rv_csr_t m
bit: 12 Integer Multiply/Divide extension
Definition: core_feature_base.h:82
CSR_MCAUSE_Type::_reserved0
rv_csr_t _reserved0
bit: 15..12 Reserved
Definition: core_feature_base.h:167
CSR_MHPMCOUNTER29
#define CSR_MHPMCOUNTER29
Definition: riscv_encoding.h:738
CSR_MISA_Type::_reserved5
rv_csr_t _reserved5
bit: 24..29 Reserved
Definition: core_feature_base.h:98
CSR_MFIOCFGINFO_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:437
CSR_MCACHECTL_Type::ic_cancel_en
rv_csr_t ic_cancel_en
I-Cache change flow canceling enable control.
Definition: core_feature_base.h:264
CSR_MHPMEVENT28
#define CSR_MHPMEVENT28
Definition: riscv_encoding.h:766
__AMOADD_W
__STATIC_FORCEINLINE int32_t __AMOADD_W(volatile int32_t *addr, int32_t value)
Atomic Add with 32bit value.
Definition: core_feature_base.h:1945
CSR_MSTATUS
#define CSR_MSTATUS
Definition: riscv_encoding.h:596
CSR_MFIOCFGINFO_Type::fio_bpa
rv_csr_t fio_bpa
FIO base address.
Definition: core_feature_base.h:435
__LB
__STATIC_FORCEINLINE uint8_t __LB(volatile void *addr)
Load 8bit value from address (8 bit)
Definition: core_feature_base.h:1796
CSR_MSUBM_Type::_reserved0
rv_csr_t _reserved0
bit: 0..5 Reserved
Definition: core_feature_base.h:205
CSR_MHPMCOUNTER30
#define CSR_MHPMCOUNTER30
Definition: riscv_encoding.h:739
CSR_MMISCCTRL_Type::imreturn_en
rv_csr_t imreturn_en
bit: 10 IMRETURN mode of trace
Definition: core_feature_base.h:240
CSR_MSTATUS_Type::sd
rv_csr_t sd
bit: Dirty status for XS or FS
Definition: core_feature_base.h:140
CSR_MISA_Type::_reserved2
rv_csr_t _reserved2
bit: 14 Reserved
Definition: core_feature_base.h:84
__RISCV_XLEN
#define __RISCV_XLEN
Refer to the width of an integer register in bits(either 32 or 64)
Definition: core_feature_base.h:48
CSR_MDLMCTL_Type::dlm_ecc_chk_en
rv_csr_t dlm_ecc_chk_en
DLM check ECC codes enable.
Definition: core_feature_base.h:325
__disable_ext_irq
__STATIC_FORCEINLINE void __disable_ext_irq(void)
Disable External IRQ Interrupts.
Definition: core_feature_base.h:699
CSR_MSTATUS_Type::_reserved2
rv_csr_t _reserved2
bit: 4 Reserved
Definition: core_feature_base.h:129
CSR_MISA_Type::q
rv_csr_t q
bit: 16 Quad-precision floating-point extension
Definition: core_feature_base.h:86
CSR_MSTATUS_Type::sie
rv_csr_t sie
bit: 1 supervisor interrupt enable flag
Definition: core_feature_base.h:126
CSR_MILMCTL_Type::ilm_ecc_excp_en
rv_csr_t ilm_ecc_excp_en
ILM ECC exception enable.
Definition: core_feature_base.h:307
__AMOMIN_W
__STATIC_FORCEINLINE int32_t __AMOMIN_W(volatile int32_t *addr, int32_t value)
Atomic signed MIN with 32bit value.
Definition: core_feature_base.h:2057
__disable_core_irq
__STATIC_FORCEINLINE void __disable_core_irq(uint32_t irq)
Disable Core IRQ Interrupt.
Definition: core_feature_base.h:754
CSR_MSUBM_Type::_reserved1
rv_csr_t _reserved1
bit: 10..31 Reserved
Definition: core_feature_base.h:211
CSR_MMISCCTRL_Type::_reserved3
rv_csr_t _reserved3
bit: 15..XLEN-1 Reserved
Definition: core_feature_base.h:245
__set_medeleg
__STATIC_FORCEINLINE void __set_medeleg(unsigned long mask)
Set exceptions delegation to S mode.
Definition: core_feature_base.h:1739
CSR_MCOUNTINHIBIT_Type::_reserved1
rv_csr_t _reserved1
bit: 3..31 Reserved
Definition: core_feature_base.h:194
CSR_MILMCTL_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:313
CSR_MICFGINFO_Type::_reserved0
rv_csr_t _reserved0
Definition: core_feature_base.h:372
CSR_MCFGINFO_Type::dsp_n1
rv_csr_t dsp_n1
DSP N1 present.
Definition: core_feature_base.h:349
CSR_MSAVESTATUS_Type
Union type to access MSAVESTATUS CSR register.
Definition: core_feature_base.h:281
__set_hpm_counter
__STATIC_FORCEINLINE void __set_hpm_counter(unsigned long idx, uint64_t value)
Set value for selected high performance monitor counter.
Definition: core_feature_base.h:1399
CSR_MSUBM_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:214
CSR_MISA_Type::v
rv_csr_t v
bit: 21 Tentatively reserved for Vector extension
Definition: core_feature_base.h:91
CSR_MECCLOCK_Type::d
rv_csr_t d
Type used for csr data access.
Definition: core_feature_base.h:448
CSR_MHPMEVENT4
#define CSR_MHPMEVENT4
Definition: riscv_encoding.h:742
CSR_MCFGINFO_Type::dlm
rv_csr_t dlm
DLM present.
Definition: core_feature_base.h:345
__SW
__STATIC_FORCEINLINE void __SW(volatile void *addr, uint32_t val)
Write 32bit value to address (32 bit)
Definition: core_feature_base.h:1876
CSR_MCAUSE_Type::interrupt
rv_csr_t interrupt
bit: 31 trap type.
Definition: core_feature_base.h:177
__disable_core_irq_s
__STATIC_FORCEINLINE void __disable_core_irq_s(uint32_t irq)
Disable Core IRQ Interrupt in supervisor mode.
Definition: core_feature_base.h:886
CSR_MECCCODE_Type::ramid
rv_csr_t ramid
The ID of RAM that has 2bit ECC error, software can clear these bits.
Definition: core_feature_base.h:458
CSR_MPPICFGINFO_Type
Union type to access MPPICFG_INFO CSR register.
Definition: core_feature_base.h:417
CSR_MDCAUSE_Type::_reserved0
rv_csr_t _reserved0
bit: 3..XLEN-1 Reserved
Definition: core_feature_base.h:223
CSR_MHPMCOUNTER25H
#define CSR_MHPMCOUNTER25H
Definition: riscv_encoding.h:875
__ASM
#define __ASM
Pass information from the compiler to the assembler.
Definition: nmsis_gcc.h:55
__get_rv_instret
__STATIC_FORCEINLINE uint64_t __get_rv_instret(void)
Read whole 64 bits value of machine instruction-retired counter.
Definition: core_feature_base.h:974
WFI_DEEP_SLEEP
@ WFI_DEEP_SLEEP
Deep sleep mode, the core_clk and core_ano_clk will poweroff.
Definition: core_feature_base.h:1171
CSR_MSAVESTATUS_Type::_reserved0
rv_csr_t _reserved0
bit: 3..5 Reserved
Definition: core_feature_base.h:285
CSR_MISA_Type::e
rv_csr_t e
bit: 4 RV32E base ISA
Definition: core_feature_base.h:74
CSR_MILMCTL_Type
Union type to access MILM_CTL CSR register.
Definition: core_feature_base.h:303
__FENCE_I
__STATIC_FORCEINLINE void __FENCE_I(void)
Fence.i Instruction.
Definition: core_feature_base.h:1762
CSR_MICFGINFO_Type::lm_size
rv_csr_t lm_size
ILM size, need to be 2^n size.
Definition: core_feature_base.h:373
rv_csr_t
unsigned long rv_csr_t
Type of Control and Status Register(CSR), depends on the XLEN defined in RISC-V.
Definition: core_feature_base.h:55
CSR_MCFGINFO_Type::ecc
rv_csr_t ecc
ECC present.
Definition: core_feature_base.h:338
CSR_MCFGINFO_Type::nice
rv_csr_t nice
NICE present.
Definition: core_feature_base.h:343
CSR_MHPMCOUNTER10
#define CSR_MHPMCOUNTER10
Definition: riscv_encoding.h:719
CSR_MHPMEVENT23
#define CSR_MHPMEVENT23
Definition: riscv_encoding.h:761
CSR_MHPMCOUNTER18
#define CSR_MHPMCOUNTER18
Definition: riscv_encoding.h:727
CSR_WFE
#define CSR_WFE
Definition: riscv_encoding.h:1018
CSR_MDCFGINFO_Type::lsize
rv_csr_t lsize
D-Cache line size.
Definition: core_feature_base.h:388
CSR_MCAUSE_Type::mpp
rv_csr_t mpp
bit: 29..28 Privilede mode flag before enter interrupt
Definition: core_feature_base.h:171
__disable_mhpm_counter
__STATIC_FORCEINLINE void __disable_mhpm_counter(unsigned long idx)
Disable selected hardware performance monitor counter.
Definition: core_feature_base.h:1254
__clear_core_irq_pending_s
__STATIC_FORCEINLINE void __clear_core_irq_pending_s(uint32_t irq)
Clear Core IRQ Interrupt Pending status in supervisor mode.
Definition: core_feature_base.h:919
CSR_MHPMCOUNTER6H
#define CSR_MHPMCOUNTER6H
Definition: riscv_encoding.h:856
CSR_MISA_Type::n
rv_csr_t n
bit: 13 User-level interrupts supported
Definition: core_feature_base.h:83
CSR_MPPICFGINFO_Type::_reserved0
rv_csr_t _reserved0
Reserved 1.
Definition: core_feature_base.h:419
CSR_MHPMCOUNTER26
#define CSR_MHPMCOUNTER26
Definition: riscv_encoding.h:735
CSR_MMISCCTRL_Type::nmi_cause
rv_csr_t nmi_cause
bit: 9 mnvec control and nmi mcase exccode
Definition: core_feature_base.h:239
CSR_MSTATUS_Type::mie
rv_csr_t mie
bit: 3 Machine mode interrupt enable flag
Definition: core_feature_base.h:128
CSR_MHPMEVENT21
#define CSR_MHPMEVENT21
Definition: riscv_encoding.h:759
CSR_MISA_Type::x
rv_csr_t x
bit: 23 Non-standard extensions present
Definition: core_feature_base.h:93
CSR_MCACHECTL_Type::ic_rwdecc
rv_csr_t ic_rwdecc
Control I-Cache Data Ram ECC code injection.
Definition: core_feature_base.h:262
CSR_MISA_Type::i
rv_csr_t i
bit: 8 RV32I/64I/128I base ISA
Definition: core_feature_base.h:78
MIE_MSIE
#define MIE_MSIE
Definition: riscv_encoding.h:163
CSR_MISA_Type::_resreved3
rv_csr_t _resreved3
bit: 17 Reserved
Definition: core_feature_base.h:87
CSR_MMISCCTRL_Type::dbg_sec
rv_csr_t dbg_sec
bit: 14 debug access mode
Definition: core_feature_base.h:244
CSR_MEPC
#define CSR_MEPC
Definition: riscv_encoding.h:610