You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Nuclei CPU IP design defines the value of the mhartid csr, which includes the cluster id and hartid. The cluster id and hartid are either 32 bits (rv32) or 64 bits (rv64), and the number of bits occupied by the hartid varies with the number of hart. For instance, if some cluster has 4 harts, then the hartid in this cluster occupies 2 bits. By default, the Nuclei linux sdk on the Nuclei Evalsoc platform occupies 8 bits for hartid. You need to modify the source code in the linux sdk that involve hartid values based on your hardware system. mhartid csr can only be accessed in M mode. Therefore, code running in M mode that uses mhartid csr may need to be modified, such as freeloader, opensbi, uboot spl, etc. If the S mode can use the shartid nuclei customized csr, you can also refer to this document.
Note
This doc assumes that linux is running on only one cluster
You can grep hartid in all the related source code, and then take care of the changes.
1. freeloader hartid patch
Define the value of MHARTID_MASK based on the number of bits occupied by the hardware hartid. For example, if your hartid is 4, then hartid occupies 2 bits. Define the following macro:
#define MHARTID_MASK 0x3
The following code does not define MHARTID_MASK macro,your need to define it based on real hardware solution,otherwise,an error will be reported when compiling. In addition, we define GET_MASKED_HARTID macro to obtain hartid value.
Define the value of MHARTID_MASK based on the number of bits occupied by the hardware hartid. For example, if your hartid is 4, then hartid occupies 2 bits. Define the following macro:
#define MHARTID_MASK 0x3
The following code does not define MHARTID_MASK macro,your need to define it based on real hardware solution,otherwise,an error will be reported when compiling. In addition, we define GET_MASKED_HARTID macro to obtain hartid value.
diff--gita/firmware/fw_base.Sb/firmware/fw_base.Sindexb947423..205e795100644---a/firmware/fw_base.S+++b/firmware/fw_base.S
@@ -42,6+42,12 @@
999:
.endm+.macroGET_MASKED_HARTIDresult_reg+# Read hartid into result register
+csrr \result_reg, mhartid+and \result_reg, \result_reg, HARTID_MASK+.endm+
.section .entry, "ax", %progbits
.align3
.globl_start
@@ -456,7+462,7 @@ _start_warm:
REG_Ls9, SBI_PLATFORM_HART_INDEX2ID_OFFSET(a4)
/* Find HART id */-csrrs6, CSR_MHARTID+GET_MASKED_HARTIDs6/* Find HART index */beqzs9, 3fdiff--gita/include/sbi/riscv_asm.hb/include/sbi/riscv_asm.hindex1ff36de..2342535100644---a/include/sbi/riscv_asm.h+++b/include/sbi/riscv_asm.h
@@ -162,8+162,15 @@ voidcsr_write_num(intcsr_num, unsigned longval);
__asm__ __volatile__("ebreak" ::: "memory"); \
} while (0)
+/* define hartid mask bits */+#ifndefMHARTID_MASK+#error "MHARTID_MASK is not defined!"
+#else+#defineHARTID_MASK MHARTID_MASK
+#endif+/* Get current HART id */-#definecurrent_hartid() ((unsigned int)csr_read(CSR_MHARTID))
+#definecurrent_hartid() ((unsigned int)csr_read(CSR_MHARTID) &HARTID_MASK)
3. uboot spl hartid patch
Define the value of MHARTID_MASK based on the number of bits occupied by the hardware hartid. For example, if your hartid is 4, then hartid occupies 2 bits. Define the following macro:
#define MHARTID_MASK 0x3
The following code does not define MHARTID_MASK macro,your need to define it based on real hardware solution,otherwise,an error will be reported when compiling. In addition, we define GET_MASKED_HARTID macro to obtain hartid value.
Perhaps you use shartid csr to read hartid in supervisor mode. you need to modify code like above. The following example
is optee os may use shartid.
Define the value of SHARTID_MASK based on the number of bits occupied by the hardware hartid. For example, if your hartid is 4, then hartid occupies 2 bits. Define the following macro:
#define SHARTID_MASK 0x3
The following code does not define SHARTID_MASK macro,your need to define it based on real hardware solution.
Nuclei CPU IP design defines the value of the mhartid csr, which includes the
cluster idandhartid. The cluster id and hartid are either 32 bits (rv32) or 64 bits (rv64), and the number of bits occupied by the hartid varies with the number of hart. For instance, if some cluster has 4 harts, then the hartid in this cluster occupies 2 bits. By default, the Nuclei linux sdk on the Nuclei Evalsoc platform occupies 8 bits for hartid. You need to modify the source code in the linux sdk that involve hartid values based on your hardware system. mhartid csr can only be accessed in M mode. Therefore, code running in M mode that uses mhartid csr may need to be modified, such as freeloader, opensbi, uboot spl, etc. If the S mode can use the shartid nuclei customized csr, you can also refer to this document.Note
hartidin all the related source code, and then take care of the changes.1. freeloader hartid patch
Define the value of MHARTID_MASK based on the number of bits occupied by the hardware hartid. For example, if your hartid is 4, then hartid occupies 2 bits. Define the following macro:
#define MHARTID_MASK 0x3The following code does not define
MHARTID_MASKmacro,your need to define it based on real hardware solution,otherwise,an error will be reported when compiling. In addition, we defineGET_MASKED_HARTIDmacro to obtain hartid value.2. opensbi hartid patch
Define the value of
MHARTID_MASKbased on the number of bits occupied by the hardware hartid. For example, if your hartid is 4, then hartid occupies 2 bits. Define the following macro:#define MHARTID_MASK 0x3The following code does not define
MHARTID_MASKmacro,your need to define it based on real hardware solution,otherwise,an error will be reported when compiling. In addition, we defineGET_MASKED_HARTIDmacro to obtain hartid value.3. uboot spl hartid patch
Define the value of
MHARTID_MASKbased on the number of bits occupied by the hardware hartid. For example, if your hartid is 4, then hartid occupies 2 bits. Define the following macro:#define MHARTID_MASK 0x3The following code does not define
MHARTID_MASKmacro,your need to define it based on real hardware solution,otherwise,an error will be reported when compiling. In addition, we defineGET_MASKED_HARTIDmacro to obtain hartid value.4. optee os shartid patch
Perhaps you use shartid csr to read hartid in supervisor mode. you need to modify code like above. The following example
is optee os may use shartid.
Define the value of
SHARTID_MASKbased on the number of bits occupied by the hardware hartid. For example, if your hartid is 4, then hartid occupies 2 bits. Define the following macro:#define SHARTID_MASK 0x3The following code does not define
SHARTID_MASKmacro,your need to define it based on real hardware solution.