Skip to content

Commit

Permalink
Replaced CLINT with ACLINT
Browse files Browse the repository at this point in the history
- Removed the `SEMU_FEATURE_ACLINT` feature flag
  and the corresponding CLINT code
- Removed the `clint.c` file
- Removed the `scripts/gen-clint-dts.py` script
  • Loading branch information
Mes0903 committed Dec 14, 2024
1 parent ce2ebc1 commit 28c83fd
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 247 deletions.
96 changes: 0 additions & 96 deletions clint.c

This file was deleted.

25 changes: 0 additions & 25 deletions device.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ void virtio_blk_write(hart_t *vm,
uint32_t *virtio_blk_init(virtio_blk_state_t *vblk, char *disk_file);
#endif /* SEMU_HAS(VIRTIOBLK) */

#if SEMU_HAS(ACLINT)
/* ACLINT MTIMER */
typedef struct {
uint64_t mtimecmp[4095]; // Machine Timer Compare array
Expand Down Expand Up @@ -224,26 +223,6 @@ void aclint_sswi_write(hart_t *hart,
uint32_t addr,
uint8_t width,
uint32_t value);
#else
/* clint */
typedef struct {
uint32_t msip[4096];
uint64_t mtimecmp[4095];
semu_timer_t mtime;
} clint_state_t;

void clint_update_interrupts(hart_t *vm, clint_state_t *clint);
void clint_read(hart_t *vm,
clint_state_t *clint,
uint32_t addr,
uint8_t width,
uint32_t *value);
void clint_write(hart_t *vm,
clint_state_t *clint,
uint32_t addr,
uint8_t width,
uint32_t value);
#endif

/* memory mapping */
typedef struct {
Expand All @@ -258,12 +237,8 @@ typedef struct {
#if SEMU_HAS(VIRTIOBLK)
virtio_blk_state_t vblk;
#endif
#if SEMU_HAS(ACLINT)
/* ACLINT */
mtimer_state_t mtimer;
mswi_state_t mswi;
sswi_state_t sswi;
#else
clint_state_t clint;
#endif
} emu_state_t;
5 changes: 0 additions & 5 deletions feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,5 @@
#define SEMU_FEATURE_VIRTIONET 1
#endif

/* ACLINT */
#ifndef SEMU_FEATURE_ACLINT
#define SEMU_FEATURE_ACLINT 1
#endif

/* Feature test macro */
#define SEMU_HAS(x) SEMU_FEATURE_##x
47 changes: 2 additions & 45 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,16 @@ static void emu_update_timer_interrupt(hart_t *hart)
emu_state_t *data = PRIV(hart);

/* Sync global timer with local timer */
#if SEMU_HAS(ACLINT)
hart->time = data->mtimer.mtime;
aclint_mtimer_update_interrupts(hart, &data->mtimer);
#else
hart->time = data->clint.mtime;
clint_update_interrupts(hart, &data->clint);
#endif
}

#if SEMU_HAS(ACLINT)
static void emu_update_swi_interrupt(hart_t *hart)
{
emu_state_t *data = PRIV(hart);
aclint_mswi_update_interrupts(hart, &data->mswi);
aclint_sswi_update_interrupts(hart, &data->sswi);
}
#endif

static void mem_load(hart_t *hart,
uint32_t addr,
Expand Down Expand Up @@ -131,7 +124,6 @@ static void mem_load(hart_t *hart,
emu_update_vblk_interrupts(hart->vm);
return;
#endif
#if SEMU_HAS(ACLINT)
case 0x43: /* mtimer */
aclint_mtimer_read(hart, &data->mtimer, addr & 0xFFFFF, width,
value);
Expand All @@ -145,12 +137,6 @@ static void mem_load(hart_t *hart,
aclint_sswi_read(hart, &data->sswi, addr & 0xFFFFF, width, value);
aclint_sswi_update_interrupts(hart, &data->sswi);
return;
#else
case 0x43: /* clint */
clint_read(hart, &data->clint, addr & 0xFFFFF, width, value);
clint_update_interrupts(hart, &data->clint);
return;
#endif
}
}
vm_set_exception(hart, RV_EXC_LOAD_FAULT, hart->exc_val);
Expand Down Expand Up @@ -192,7 +178,6 @@ static void mem_store(hart_t *hart,
emu_update_vblk_interrupts(hart->vm);
return;
#endif
#if SEMU_HAS(ACLINT)
case 0x43: /* mtimer */
aclint_mtimer_write(hart, &data->mtimer, addr & 0xFFFFF, width,
value);
Expand All @@ -206,12 +191,6 @@ static void mem_store(hart_t *hart,
aclint_sswi_write(hart, &data->sswi, addr & 0xFFFFF, width, value);
aclint_sswi_update_interrupts(hart, &data->sswi);
return;
#else
case 0x43: /* clint */
clint_write(hart, &data->clint, addr & 0xFFFFF, width, value);
clint_update_interrupts(hart, &data->clint);
return;
#endif
}
}
vm_set_exception(hart, RV_EXC_STORE_FAULT, hart->exc_val);
Expand All @@ -231,15 +210,9 @@ static inline sbi_ret_t handle_sbi_ecall_TIMER(hart_t *hart, int32_t fid)
emu_state_t *data = PRIV(hart);
switch (fid) {
case SBI_TIMER__SET_TIMER:
#if SEMU_HAS(ACLINT)
data->mtimer.mtimecmp[hart->mhartid] =
(((uint64_t) hart->x_regs[RV_R_A1]) << 32) |
(uint64_t) (hart->x_regs[RV_R_A0]);
#else
data->clint.mtimecmp[hart->mhartid] =
(((uint64_t) hart->x_regs[RV_R_A1]) << 32) |
(uint64_t) (hart->x_regs[RV_R_A0]);
#endif
hart->sip &= ~RV_INT_STI_BIT;
return (sbi_ret_t){SBI_SUCCESS, 0};
default:
Expand Down Expand Up @@ -313,21 +286,11 @@ static inline sbi_ret_t handle_sbi_ecall_IPI(hart_t *hart, int32_t fid)
hart_mask = (uint64_t) hart->x_regs[RV_R_A0];
hart_mask_base = (uint64_t) hart->x_regs[RV_R_A1];
if (hart_mask_base == 0xFFFFFFFFFFFFFFFF) {
for (uint32_t i = 0; i < hart->vm->n_hart; i++) {
#if SEMU_HAS(ACLINT)
for (uint32_t i = 0; i < hart->vm->n_hart; i++)
data->sswi.ssip[i] = 1;
#else
data->clint.msip[i] = 1;
#endif
}
} else {
for (int i = hart_mask_base; hart_mask; hart_mask >>= 1, i++) {
#if SEMU_HAS(ACLINT)
for (int i = hart_mask_base; hart_mask; hart_mask >>= 1, i++)
data->sswi.ssip[i] = hart_mask & 1;
#else
data->clint.msip[i] = hart_mask & 1;
#endif
}
}

return (sbi_ret_t){SBI_SUCCESS, 0};
Expand Down Expand Up @@ -586,11 +549,7 @@ static int semu_start(int argc, char **argv)
/* Initialize the emulator */
emu_state_t emu;
memset(&emu, 0, sizeof(emu));
#if SEMU_HAS(ACLINT)
semu_timer_init(&emu.mtimer.mtime, CLOCK_FREQ);
#else
semu_timer_init(&emu.clint.mtime, CLOCK_FREQ);
#endif

/* Set up RAM */
emu.ram = mmap(NULL, RAM_SIZE, PROT_READ | PROT_WRITE,
Expand Down Expand Up @@ -680,9 +639,7 @@ static int semu_start(int argc, char **argv)
}

emu_update_timer_interrupt(vm.hart[i]);
#if SEMU_HAS(ACLINT)
emu_update_swi_interrupt(vm.hart[i]);
#endif

vm_step(vm.hart[i]);
if (likely(!vm.hart[i]->error))
Expand Down
4 changes: 0 additions & 4 deletions riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,11 +805,7 @@ void vm_step(hart_t *vm)
uint8_t idx = ilog2(applicable);
if (idx == 1) {
emu_state_t *data = PRIV(vm);
#if SEMU_HAS(ACLINT)
data->sswi.ssip[vm->mhartid] = 0;
#else
data->clint.msip[vm->mhartid] = 0;
#endif
}
vm->exc_cause = (1U << 31) | idx;
vm->stval = 0;
Expand Down
72 changes: 0 additions & 72 deletions scripts/gen-clint-dts.py

This file was deleted.

0 comments on commit 28c83fd

Please sign in to comment.