Skip to content

Commit bbd065d

Browse files
committed
lib: sbi: Detect Zicntr extension only based on traps
OpenSBI uses time CSR if Zicntr extension present which causes it to crash on an older QEMU because QEMU generates Zicntr in the ISA string for unleashed machine which only has CYCLE and INSTRET counters. Fixes: 776770d ("lib: sbi: Using one array to define the name of extensions") Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Anup Patel <[email protected]>
1 parent ba29293 commit bbd065d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Diff for: lib/sbi/sbi_hart.c

+8
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ static int hart_detect_features(struct sbi_scratch *scratch)
748748
struct sbi_hart_features *hfeatures =
749749
sbi_scratch_offset_ptr(scratch, hart_features_offset);
750750
unsigned long val, oldval;
751+
bool has_zicntr = false;
751752
int rc;
752753

753754
/* If hart features already detected then do nothing */
@@ -900,12 +901,19 @@ static int hart_detect_features(struct sbi_scratch *scratch)
900901

901902
#undef __check_ext_csr
902903

904+
/* Save trap based detection of Zicntr */
905+
has_zicntr = sbi_hart_has_extension(scratch, SBI_HART_EXT_ZICNTR);
906+
903907
/* Let platform populate extensions */
904908
rc = sbi_platform_extensions_init(sbi_platform_thishart_ptr(),
905909
hfeatures);
906910
if (rc)
907911
return rc;
908912

913+
/* Zicntr should only be detected using traps */
914+
__sbi_hart_update_extension(hfeatures, SBI_HART_EXT_ZICNTR,
915+
has_zicntr);
916+
909917
/* Extensions implied by other extensions and features */
910918
if (hfeatures->mhpm_mask)
911919
__sbi_hart_update_extension(hfeatures,

0 commit comments

Comments
 (0)