diff options
| author | Damien Le Moal <[email protected]> | 2018-12-21 17:06:59 +0900 |
|---|---|---|
| committer | Damien Le Moal <[email protected]> | 2018-12-21 17:06:59 +0900 |
| commit | 5563a0335421c3e1d69dc62a1b58675ddf3d1e5b (patch) | |
| tree | 47c756c6e8591467636f0983236c420f9f76cf43 | |
| parent | 426adf9f6025fe70470476166db63ea7c0c1514b (diff) | |
Introduce sbi_current_hartid()
Use this helper instead of hardcoding csr_read(mhartid).
Signed-off-by: Damien Le Moal <[email protected]>
| -rw-r--r-- | include/sbi/sbi_hart.h | 2 | ||||
| -rw-r--r-- | lib/sbi_hart.c | 13 | ||||
| -rw-r--r-- | lib/sbi_init.c | 2 | ||||
| -rw-r--r-- | lib/sbi_trap.c | 2 |
4 files changed, 15 insertions, 4 deletions
diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index e369779d..70416430 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -38,4 +38,6 @@ void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid); void sbi_hart_wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid); +u32 sbi_current_hartid(void); + #endif diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index 32dcfe41..09739b92 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -17,6 +17,14 @@ #include <sbi/sbi_hart.h> #include <sbi/sbi_platform.h> +/** + * Return HART ID of the caller. + */ +unsigned int sbi_current_hartid() +{ + return (u32)csr_read(mhartid); +} + static void mstatus_init(struct sbi_scratch *scratch, u32 hartid) { struct sbi_platform *plat = sbi_platform_ptr(scratch); @@ -198,7 +206,7 @@ int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid) void __attribute__((noreturn)) sbi_hart_hang(void) { - sbi_printf("\nHang !!\n"); + sbi_printf("\nHART %u Hang !!\n\n", sbi_current_hartid()); while (1) wfi(); @@ -249,7 +257,8 @@ void __attribute__((noreturn)) sbi_hart_switch_mode(unsigned long arg0, csr_write(uie, 0); } - sbi_printf("\nSwitching to %c-mode...\n\n", mode); + sbi_printf("HART %u switching to %c-mode...\n\n", + sbi_current_hartid(), mode); register unsigned long a0 asm ("a0") = arg0; register unsigned long a1 asm ("a1") = arg1; diff --git a/lib/sbi_init.c b/lib/sbi_init.c index f8451d18..da78a7ef 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -163,7 +163,7 @@ static atomic_t coldboot_lottery = ATOMIC_INITIALIZER(0); void __attribute__((noreturn)) sbi_init(struct sbi_scratch *scratch) { bool coldboot = FALSE; - u32 hartid = csr_read(mhartid); + u32 hartid = sbi_current_hartid(); if (atomic_add_return(&coldboot_lottery, 1) == 1) coldboot = TRUE; diff --git a/lib/sbi_trap.c b/lib/sbi_trap.c index f9c70a63..284bb74f 100644 --- a/lib/sbi_trap.c +++ b/lib/sbi_trap.c @@ -68,7 +68,7 @@ void sbi_trap_handler(struct sbi_trap_regs *regs, { int rc; const char *msg; - u32 hartid = csr_read(mhartid); + u32 hartid = sbi_current_hartid(); ulong mcause = csr_read(mcause); if (mcause & (1UL << (__riscv_xlen - 1))) { |
