Skip to content

Commit eb64e58

Browse files
miguelafsilva5DavidMCerdeira
authored andcommitted
fix: Remove implicit type and sign casts
With the additional compiler flags, most implicit casts are not allowed. This commit achieves this by forcing explicit casts, refactoring some variable types and fixing literal values. Signed-off-by: Miguel Silva <[email protected]>
1 parent dea07f2 commit eb64e58

File tree

61 files changed

+447
-436
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+447
-436
lines changed

src/arch/armv8/aarch32/inc/arch/subarch/sysregs.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
} \
5656
static inline void sysreg_##reg##_write(unsigned long long val) \
5757
{ \
58-
sysreg_##reg1##_write(val); \
59-
sysreg_##reg2##_write(val >> 32); \
58+
sysreg_##reg1##_write((unsigned long)val); \
59+
sysreg_##reg2##_write((unsigned long)(val >> 32)); \
6060
}
6161

6262
/**
@@ -83,8 +83,9 @@ SYSREG_GEN_ACCESSORS(cptr_el2, 4, c1, c1, 2) // hcptr
8383
SYSREG_GEN_ACCESSORS(vtcr_el2, 4, c2, c1, 2)
8484
SYSREG_GEN_ACCESSORS_64(vttbr_el2, 6, c2)
8585
SYSREG_GEN_ACCESSORS(tpidr_el2, 4, c13, c0, 2) // htpidr
86-
SYSREG_GEN_ACCESSORS(ccsidr_el1, 1, c0, c0, 0)
86+
SYSREG_GEN_ACCESSORS(ccsidr, 1, c0, c0, 0)
8787
SYSREG_GEN_ACCESSORS(ccsidr2, 1, c0, c0, 2)
88+
SYSREG_GEN_ACCESSORS_MERGE(ccsidr_el1, ccsidr, ccsidr2)
8889
SYSREG_GEN_ACCESSORS(hmair0, 4, c10, c2, 0)
8990
SYSREG_GEN_ACCESSORS(hmair1, 4, c10, c2, 1)
9091
SYSREG_GEN_ACCESSORS_MERGE(mair_el2, hmair0, hmair1)

src/arch/armv8/aborts.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void aborts_data_lower(unsigned long iss, unsigned long far, unsigned long il, u
2222
ERROR("no information to handle data abort (0x%x)", far);
2323
}
2424

25-
unsigned long DSFC = bit64_extract(iss, ESR_ISS_DA_DSFC_OFF, ESR_ISS_DA_DSFC_LEN) & (0xf << 2);
25+
unsigned long DSFC = bit_extract(iss, ESR_ISS_DA_DSFC_OFF, ESR_ISS_DA_DSFC_LEN) & (0xf << 2);
2626

2727
if (DSFC != ESR_ISS_DA_DSFC_TRNSLT && DSFC != ESR_ISS_DA_DSFC_PERMIS) {
2828
ERROR("data abort is not translation fault - cant deal with it");
@@ -33,11 +33,11 @@ void aborts_data_lower(unsigned long iss, unsigned long far, unsigned long il, u
3333
if (handler != NULL) {
3434
struct emul_access emul;
3535
emul.addr = addr;
36-
emul.width = (1 << bit64_extract(iss, ESR_ISS_DA_SAS_OFF, ESR_ISS_DA_SAS_LEN));
36+
emul.width = (1U << bit_extract(iss, ESR_ISS_DA_SAS_OFF, ESR_ISS_DA_SAS_LEN));
3737
emul.write = iss & ESR_ISS_DA_WnR_BIT ? true : false;
38-
emul.reg = bit64_extract(iss, ESR_ISS_DA_SRT_OFF, ESR_ISS_DA_SRT_LEN);
39-
emul.reg_width = 4 + (4 * bit64_extract(iss, ESR_ISS_DA_SF_OFF, ESR_ISS_DA_SF_LEN));
40-
emul.sign_ext = bit64_extract(iss, ESR_ISS_DA_SSE_OFF, ESR_ISS_DA_SSE_LEN);
38+
emul.reg = bit_extract(iss, ESR_ISS_DA_SRT_OFF, ESR_ISS_DA_SRT_LEN);
39+
emul.reg_width = 4 + (4 * bit_extract(iss, ESR_ISS_DA_SF_OFF, ESR_ISS_DA_SF_LEN));
40+
emul.sign_ext = bit_extract(iss, ESR_ISS_DA_SSE_OFF, ESR_ISS_DA_SSE_LEN);
4141

4242
// TODO: check if the access is aligned. If not, inject an exception in the vm
4343

@@ -56,15 +56,15 @@ long int standard_service_call(unsigned long _fn_num)
5656
{
5757
UNUSED_ARG(_fn_num);
5858

59-
int64_t ret = -1;
59+
long int ret = -1;
6060

6161
unsigned long smc_fid = vcpu_readreg(cpu()->vcpu, 0);
6262
unsigned long x1 = vcpu_readreg(cpu()->vcpu, 1);
6363
unsigned long x2 = vcpu_readreg(cpu()->vcpu, 2);
6464
unsigned long x3 = vcpu_readreg(cpu()->vcpu, 3);
6565

6666
if (is_psci_fid(smc_fid)) {
67-
ret = psci_smc_handler(smc_fid, x1, x2, x3);
67+
ret = psci_smc_handler((uint32_t)smc_fid, x1, x2, x3);
6868
} else {
6969
INFO("unknown smc_fid 0x%lx", smc_fid);
7070
}
@@ -96,7 +96,7 @@ static inline void syscall_handler(unsigned long iss, unsigned long far, unsigne
9696
WARNING("Unknown system call fid 0x%x", fid);
9797
}
9898

99-
vcpu_writereg(cpu()->vcpu, 0, ret);
99+
vcpu_writereg(cpu()->vcpu, 0, (unsigned long)ret);
100100
}
101101

102102
void hvc_handler(unsigned long iss, unsigned long far, unsigned long il, unsigned long ec)
@@ -145,8 +145,8 @@ void sysreg_handler(unsigned long iss, unsigned long far, unsigned long il, unsi
145145
emul.addr = reg_addr;
146146
emul.width = 8;
147147
emul.write = iss & ESR_ISS_SYSREG_DIR ? false : true;
148-
emul.reg = bit64_extract(iss, ESR_ISS_SYSREG_REG_OFF, ESR_ISS_SYSREG_REG_LEN);
149-
emul.reg_high = bit64_extract(iss, ESR_ISS_SYSREG_REG2_OFF, ESR_ISS_SYSREG_REG2_LEN);
148+
emul.reg = bit_extract(iss, ESR_ISS_SYSREG_REG_OFF, ESR_ISS_SYSREG_REG_LEN);
149+
emul.reg_high = bit_extract(iss, ESR_ISS_SYSREG_REG2_OFF, ESR_ISS_SYSREG_REG2_LEN);
150150
emul.reg_width = 8;
151151
emul.multi_reg = (ec == ESR_EC_RG_64) ? true : false;
152152
emul.sign_ext = false;
@@ -187,9 +187,9 @@ void aborts_sync_handler()
187187
ipa_fault_addr = far;
188188
}
189189

190-
unsigned long ec = bit64_extract(esr, ESR_EC_OFF, ESR_EC_LEN);
191-
unsigned long il = bit64_extract(esr, ESR_IL_OFF, ESR_IL_LEN);
192-
unsigned long iss = bit64_extract(esr, ESR_ISS_OFF, ESR_ISS_LEN);
190+
unsigned long ec = bit_extract(esr, ESR_EC_OFF, ESR_EC_LEN);
191+
unsigned long il = bit_extract(esr, ESR_IL_OFF, ESR_IL_LEN);
192+
unsigned long iss = bit_extract(esr, ESR_ISS_OFF, ESR_ISS_LEN);
193193

194194
abort_handler_t handler = abort_handlers[ec];
195195
if (handler) {

src/arch/armv8/armv8-a/aarch32/vmm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void vmm_arch_init_tcr()
1616

1717
cpu_sync_barrier(&cpu_glb_sync);
1818

19-
uint64_t vtcr = VTCR_RES1 | VTCR_ORGN0_WB_RA_WA | VTCR_IRGN0_WB_RA_WA | VTCR_T0SZ(0) |
19+
unsigned long vtcr = VTCR_RES1 | VTCR_ORGN0_WB_RA_WA | VTCR_IRGN0_WB_RA_WA | VTCR_T0SZ(0) |
2020
VTCR_SH0_IS | VTCR_SL0_12;
2121

2222
sysreg_vtcr_el2_write(vtcr);

src/arch/armv8/armv8-a/inc/arch/iommu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
struct iommu_vm_arch {
1313
streamid_t global_mask;
14-
size_t ctx_id;
14+
ssize_t ctx_id;
1515
};
1616

1717
#endif

src/arch/armv8/armv8-a/inc/arch/smmuv2.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88

99
#include <bao.h>
1010

11-
#define SMMUV2_CR0_GFRE (0x1 << 1)
12-
#define SMMUV2_CR0_GFIE (0x1 << 2)
13-
#define SMMUV2_CR0_GCFGFRE (0x1 << 4)
14-
#define SMMUV2_CR0_GCFGFIE (0x1 << 5)
15-
#define SMMUV2_CR0_USFCFG (0x1 << 10)
16-
#define SMMUV2_CR0_SMCFCFG (0x1 << 21)
17-
#define SMMUV2_CR0_CLIENTPD (0x1 << 0)
11+
#define SMMUV2_CR0_GFRE (0x1U << 1)
12+
#define SMMUV2_CR0_GFIE (0x1U << 2)
13+
#define SMMUV2_CR0_GCFGFRE (0x1U << 4)
14+
#define SMMUV2_CR0_GCFGFIE (0x1U << 5)
15+
#define SMMUV2_CR0_USFCFG (0x1U << 10)
16+
#define SMMUV2_CR0_SMCFCFG (0x1U << 21)
17+
#define SMMUV2_CR0_CLIENTPD (0x1U << 0)
1818

19-
#define SMMUV2_CR0_CLEAR(cr0) (cr0 & (0x3 << 30 | 0x1 << 11))
19+
#define SMMUV2_CR0_CLEAR(cr0) (cr0 & (0x3U << 30 | 0x1U << 11))
2020

2121
#define SMMUV2_IDR0_MASK (0xFF)
2222
#define SMMUV2_IDR0_S2TS_BIT (0x1 << 30)
2323
#define SMMUV2_IDR0_SMS_BIT (0x1 << 27)
2424
#define SMMUV2_IDR0_CTTW_BIT (0x1 << 14)
2525
#define SMMUV2_IDR0_BTM_BIT (0x1 << 13)
2626

27-
#define SMMUV2_IDR1_PAGESIZE_BIT (0x1 << 31)
27+
#define SMMUV2_IDR1_PAGESIZE_BIT (0x1U << 31)
2828
#define SMMUV2_IDR1_NUMCB_OFF (0)
2929
#define SMMUV2_IDR1_NUMCB_LEN (8)
3030
#define SMMUV2_IDR1_NUMPAGEDXB_OFF (28)
@@ -49,7 +49,7 @@
4949
#define SMMU_SMR_MASK_LEN 15
5050
#define SMMU_SMR_MASK(smr) bit32_extract(smr, SMMU_SMR_MASK_OFF, SMMU_SMR_MASK_LEN)
5151

52-
#define SMMUV2_SMR_VALID (0x1 << 31)
52+
#define SMMUV2_SMR_VALID (0x1U << 31)
5353

5454
#define S2CR_IMPL_OFF (30)
5555
#define S2CR_IMPL_LEN (2)
@@ -282,7 +282,7 @@ struct smmu_glbl_rs1_hw {
282282
#define SMMUV2_SCTLR_BSU_OSH (0x2 << 14)
283283
#define SMMUV2_SCTLR_BSU_SYS (0x3 << 14)
284284

285-
#define SMMUV2_SCTLR_CLEAR(sctlr) (sctlr & (0xF << 28 | 0x1 << 20 | 0xF << 9 | 0x1 << 11))
285+
#define SMMUV2_SCTLR_CLEAR(sctlr) (sctlr & (0xFU << 28 | 0x1U << 20 | 0xFU << 9 | 0x1U << 11))
286286

287287
#define SMMUV2_SCTLR_DEFAULT (SMMUV2_SCTLR_CFCFG | SMMUV2_SCTLR_M)
288288

src/arch/armv8/armv8-a/iommu.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ bool iommu_arch_init()
2121

2222
static ssize_t iommu_vm_arch_init_ctx(struct vm* vm)
2323
{
24-
ssize_t ctx_id = vm->io.prot.mmu.ctx_id;
24+
ssize_t ctx_id = (ssize_t)vm->io.prot.mmu.ctx_id;
2525
if (ctx_id < 0) {
2626
/* Set up ctx bank to vm address space in an available ctx. */
2727
ctx_id = smmu_alloc_ctxbnk();
2828
if (ctx_id >= 0) {
2929
paddr_t rootpt;
3030
mem_translate(&cpu()->as, (vaddr_t)vm->as.pt.root, &rootpt);
31-
smmu_write_ctxbnk(ctx_id, rootpt, vm->id);
31+
smmu_write_ctxbnk((size_t)ctx_id, rootpt, vm->id);
3232
vm->io.prot.mmu.ctx_id = ctx_id;
3333
} else {
3434
INFO("iommu: smmuv2 could not allocate ctx for vm: %d", vm->id);
@@ -51,14 +51,14 @@ static bool iommu_vm_arch_add(struct vm* vm, streamid_t mask, streamid_t id)
5151
return false;
5252
}
5353

54-
if (!smmu_compatible_sme_exists(prep_mask, prep_id, vm_ctx, group)) {
54+
if (!smmu_compatible_sme_exists(prep_mask, prep_id, (size_t)vm_ctx, group)) {
5555
ssize_t sme = smmu_alloc_sme();
5656
if (sme < 0) {
5757
INFO("iommu: smmuv2 no more free sme available.");
5858
return false;
5959
}
60-
smmu_write_sme(sme, prep_mask, prep_id, group);
61-
smmu_write_s2c(sme, vm_ctx);
60+
smmu_write_sme((size_t)sme, prep_mask, prep_id, group);
61+
smmu_write_s2c((size_t)sme, (size_t)vm_ctx);
6262
}
6363

6464
return true;

src/arch/armv8/armv8-a/page_table.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ pte_t* pt_get_pte(struct page_table* pt, size_t lvl, vaddr_t va)
7474

7575
size_t rec_ind_off = cpu_pt->dscr->lvl_off[cpu_pt->dscr->lvls - lvl - 1];
7676
size_t rec_ind_len = cpu_pt->dscr->lvl_wdt[cpu_pt->dscr->lvls - lvl - 1];
77-
uintptr_t rec_ind_mask = PTE_MASK(rec_ind_off, rec_ind_len - rec_ind_off);
78-
uintptr_t addr = cpu_pt->arch.rec_mask & ~PTE_MASK(0, rec_ind_len);
77+
uintptr_t rec_ind_mask = (uintptr_t)PTE_MASK(rec_ind_off, rec_ind_len - rec_ind_off);
78+
uintptr_t addr = (uintptr_t)(cpu_pt->arch.rec_mask & ~PTE_MASK(0, rec_ind_len));
7979
addr |= (pt->arch.rec_ind << rec_ind_off) & rec_ind_mask;
80-
addr |= (va >> pt->dscr->lvl_off[lvl]) * sizeof(pte_t) & PTE_MASK(0, rec_ind_off);
80+
addr |= (uintptr_t)((va >> pt->dscr->lvl_off[lvl]) * sizeof(pte_t) & PTE_MASK(0, rec_ind_off));
8181

8282
return (pte_t*)addr;
8383
}

src/arch/armv8/armv8-a/psci.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ int32_t psci_power_down(enum wakeup_reason reason)
105105

106106
int32_t psci_cpu_suspend(uint32_t power_state, unsigned long entrypoint, unsigned long context_id)
107107
{
108-
return smc_call(PSCI_CPU_SUSPEND, power_state, entrypoint, context_id, NULL);
108+
return (int32_t)smc_call(PSCI_CPU_SUSPEND, power_state, entrypoint, context_id, NULL);
109109
}
110110

111111
int32_t psci_cpu_on(unsigned long target_cpu, unsigned long entrypoint, unsigned long context_id)
112112
{
113-
return smc_call(PSCI_CPU_ON, target_cpu, entrypoint, context_id, NULL);
113+
return (int32_t)smc_call(PSCI_CPU_ON, target_cpu, entrypoint, context_id, NULL);
114114
}

src/arch/armv8/armv8-a/smmuv2.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ void smmu_init()
129129
smmu.hw.glbl_rs0 = (struct smmu_glbl_rs0_hw*)smmu_glbl_rs0;
130130

131131
size_t pg_size = smmu.hw.glbl_rs0->IDR1 & SMMUV2_IDR1_PAGESIZE_BIT ? 0x10000 : 0x1000;
132-
size_t num_page = 1ULL << (bit32_extract(smmu.hw.glbl_rs0->IDR1, SMMUV2_IDR1_NUMPAGEDXB_OFF,
133-
SMMUV2_IDR1_NUMPAGEDXB_LEN) +
132+
size_t num_page = 1UL << (bit32_extract(smmu.hw.glbl_rs0->IDR1, SMMUV2_IDR1_NUMPAGEDXB_OFF,
133+
SMMUV2_IDR1_NUMPAGEDXB_LEN) +
134134
1);
135135
size_t ctx_bank_num =
136136
bit32_extract(smmu.hw.glbl_rs0->IDR1, SMMUV2_IDR1_NUMCB_OFF, SMMUV2_IDR1_NUMCB_LEN);
@@ -167,7 +167,7 @@ void smmu_init()
167167

168168
for (size_t i = 0; i < smmu.ctx_num; i++) {
169169
smmu.hw.cntxt[i].SCTLR = 0;
170-
smmu.hw.cntxt[i].FSR = -1;
170+
smmu.hw.cntxt[i].FSR = ~0U;
171171
}
172172

173173
/* Enable IOMMU. */
@@ -184,7 +184,7 @@ ssize_t smmu_alloc_ctxbnk()
184184
/* Find a free context bank. */
185185
ssize_t nth = bitmap_find_nth(smmu.ctxbank_bitmap, smmu.ctx_num, 1, 0, false);
186186
if (nth >= 0) {
187-
bitmap_set(smmu.ctxbank_bitmap, nth);
187+
bitmap_set(smmu.ctxbank_bitmap, (size_t)nth);
188188
}
189189
spin_unlock(&smmu.ctx_lock);
190190

@@ -249,7 +249,7 @@ ssize_t smmu_alloc_sme()
249249
/* Find a free sme. */
250250
ssize_t nth = bitmap_find_nth(smmu.sme_bitmap, smmu.sme_num, 1, 0, false);
251251
if (nth >= 0) {
252-
bitmap_set(smmu.sme_bitmap, nth);
252+
bitmap_set(smmu.sme_bitmap, (size_t)nth);
253253
}
254254
spin_unlock(&smmu.sme_lock);
255255

src/arch/armv8/armv8-r/mpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static inline void mpu_entry_set_perms(struct mp_region* mpr, struct mpu_perms m
116116
bool el1_priv = mpu_perms.el1 != PERM_NONE;
117117
perms_t perms = mpu_perms.el1 | mpu_perms.el2;
118118

119-
mpr->mem_flags.prbar &= ~(PRBAR_PERMS_FLAGS_MSK);
119+
mpr->mem_flags.prbar &= (uint16_t) ~(PRBAR_PERMS_FLAGS_MSK);
120120
if (perms & PERM_W) {
121121
mpr->mem_flags.prbar |= PRBAR_AP_RW_EL2;
122122
} else {

0 commit comments

Comments
 (0)