Skip to content

Commit

Permalink
lib: sbi: Fix 32/64 bits variable compatibility
Browse files Browse the repository at this point in the history
On RV64,"unsigned long" is 64bit and "unsigned int" is 32bit. So in
function "pmp_get" and "pmp_set", if "pmpcfg_shift >= 32", "0xff << pmpcfg_shift"
will go beyond "unsigned int" width. This patch tries to fix this issue.

In function 'pmp_get':
	cfgmask = (0xff << pmpcfg_shift);
			-->
	cfgmask = (0xffUL << pmpcfg_shift);
In function 'pmp_set':
	cfgmask = ~(0xff << pmpcfg_shift);
			-->
	cfgmask = ~(0xffUL << pmpcfg_shift);

Signed-off-by: Liush <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
  • Loading branch information
damon-liush authored and avpatel committed Jun 20, 2020
1 parent db56ef3 commit 9bd5f8f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/sbi/riscv_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,

/* encode PMP config */
prot |= (log2len == PMP_SHIFT) ? PMP_A_NA4 : PMP_A_NAPOT;
cfgmask = ~(0xff << pmpcfg_shift);
cfgmask = ~(0xffUL << pmpcfg_shift);
pmpcfg = (csr_read_num(pmpcfg_csr) & cfgmask);
pmpcfg |= ((prot << pmpcfg_shift) & ~cfgmask);

Expand Down Expand Up @@ -320,7 +320,7 @@ int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
return SBI_ENOTSUPP;

/* decode PMP config */
cfgmask = (0xff << pmpcfg_shift);
cfgmask = (0xffUL << pmpcfg_shift);
pmpcfg = csr_read_num(pmpcfg_csr) & cfgmask;
prot = pmpcfg >> pmpcfg_shift;

Expand Down

0 comments on commit 9bd5f8f

Please sign in to comment.