Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/check-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ done < <(git ls-files '*.c' '*.cxx' '*.cpp' '*.h' '*.hpp')

# Use clang-format dry-run mode with --Werror to fail on format violations
# This eliminates the need for temporary files and manual diff comparisons
clang-format-18 -n --Werror "${SOURCES[@]}"
clang-format-20 -n --Werror "${SOURCES[@]}"
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ jobs:
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-clang-format-18
key: ${{ runner.os }}-apt-clang-format-20
restore-keys: |
${{ runner.os }}-apt-
- name: Install clang-format
run: |
sudo apt-get update
sudo apt-get install -q -y clang-format-18
sudo apt-get install -q -y clang-format-20
shell: bash
timeout-minutes: 5
- name: Setup reviewdog
Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
trap cleanup_files EXIT INT TERM

# Apply clang-format in-place to generate diff
clang-format-18 -i "${SOURCES[@]}"
clang-format-20 -i "${SOURCES[@]}"

# Generate diff and pipe to reviewdog
# Note: reviewdog exit code doesn't affect cleanup due to trap
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ However, participation requires adherence to fundamental ground rules:
This variant should be considered the standard for all documentation efforts.
For instance, opt for "initialize" over "initialise" and "color" rather than "colour".

Software requirement: [clang-format](https://clang.llvm.org/docs/ClangFormat.html) version 18 or later.
Software requirement: [clang-format](https://clang.llvm.org/docs/ClangFormat.html) version 20 or later.

This repository consistently contains an up-to-date `.clang-format` file with rules that match the explained ones.
For maintaining a uniform coding style, execute the command `clang-format -i *.{c,h}`.
Expand Down
58 changes: 29 additions & 29 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ static inline sbi_ret_t handle_sbi_ecall_TIMER(hart_t *hart, int32_t fid)
(((uint64_t) hart->x_regs[RV_R_A1]) << 32) |
(uint64_t) (hart->x_regs[RV_R_A0]);
hart->sip &= ~RV_INT_STI_BIT;
return (sbi_ret_t){SBI_SUCCESS, 0};
return (sbi_ret_t) {SBI_SUCCESS, 0};
default:
return (sbi_ret_t){SBI_ERR_NOT_SUPPORTED, 0};
return (sbi_ret_t) {SBI_ERR_NOT_SUPPORTED, 0};
}
}

Expand All @@ -373,9 +373,9 @@ static inline sbi_ret_t handle_sbi_ecall_RST(hart_t *hart, int32_t fid)
fprintf(stderr, "system reset: type=%u, reason=%u\n",
hart->x_regs[RV_R_A0], hart->x_regs[RV_R_A1]);
data->stopped = true;
return (sbi_ret_t){SBI_SUCCESS, 0};
return (sbi_ret_t) {SBI_SUCCESS, 0};
default:
return (sbi_ret_t){SBI_ERR_NOT_SUPPORTED, 0};
return (sbi_ret_t) {SBI_ERR_NOT_SUPPORTED, 0};
}
}

Expand All @@ -395,13 +395,13 @@ static inline sbi_ret_t handle_sbi_ecall_HSM(hart_t *hart, int32_t fid)
vm->hart[hartid]->x_regs[RV_R_A1] = opaque;
vm->hart[hartid]->pc = start_addr;
vm->hart[hartid]->s_mode = true;
return (sbi_ret_t){SBI_SUCCESS, 0};
return (sbi_ret_t) {SBI_SUCCESS, 0};
case SBI_HSM__HART_STOP:
hart->hsm_status = SBI_HSM_STATE_STOPPED;
return (sbi_ret_t){SBI_SUCCESS, 0};
return (sbi_ret_t) {SBI_SUCCESS, 0};
case SBI_HSM__HART_GET_STATUS:
hartid = hart->x_regs[RV_R_A0];
return (sbi_ret_t){SBI_SUCCESS, vm->hart[hartid]->hsm_status};
return (sbi_ret_t) {SBI_SUCCESS, vm->hart[hartid]->hsm_status};
case SBI_HSM__HART_SUSPEND:
suspend_type = hart->x_regs[RV_R_A0];
resume_addr = hart->x_regs[RV_R_A1];
Expand All @@ -415,11 +415,11 @@ static inline sbi_ret_t handle_sbi_ecall_HSM(hart_t *hart, int32_t fid)
hart->hsm_resume_pc = resume_addr;
hart->hsm_resume_opaque = opaque;
}
return (sbi_ret_t){SBI_SUCCESS, 0};
return (sbi_ret_t) {SBI_SUCCESS, 0};
default:
return (sbi_ret_t){SBI_ERR_NOT_SUPPORTED, 0};
return (sbi_ret_t) {SBI_ERR_NOT_SUPPORTED, 0};
}
return (sbi_ret_t){SBI_ERR_FAILED, 0};
return (sbi_ret_t) {SBI_ERR_FAILED, 0};
}

static inline sbi_ret_t handle_sbi_ecall_IPI(hart_t *hart, int32_t fid)
Expand All @@ -438,10 +438,10 @@ static inline sbi_ret_t handle_sbi_ecall_IPI(hart_t *hart, int32_t fid)
data->sswi.ssip[i] = hart_mask & 1;
}

return (sbi_ret_t){SBI_SUCCESS, 0};
return (sbi_ret_t) {SBI_SUCCESS, 0};
break;
default:
return (sbi_ret_t){SBI_ERR_FAILED, 0};
return (sbi_ret_t) {SBI_ERR_FAILED, 0};
}
}

Expand All @@ -458,7 +458,7 @@ static inline sbi_ret_t handle_sbi_ecall_RFENCE(hart_t *hart, int32_t fid)
switch (fid) {
case SBI_RFENCE__I:
/* Instruction cache flush - ignored in interpreter mode */
return (sbi_ret_t){SBI_SUCCESS, 0};
return (sbi_ret_t) {SBI_SUCCESS, 0};
case SBI_RFENCE__VMA:
case SBI_RFENCE__VMA_ASID:
/* RFENCE.VMA and RFENCE.VMA.ASID both use the same parameters:
Expand All @@ -484,15 +484,15 @@ static inline sbi_ret_t handle_sbi_ecall_RFENCE(hart_t *hart, int32_t fid)
mmu_invalidate_range(hart->vm->hart[i], start_addr, size);
}
}
return (sbi_ret_t){SBI_SUCCESS, 0};
return (sbi_ret_t) {SBI_SUCCESS, 0};
case SBI_RFENCE__GVMA_VMID:
case SBI_RFENCE__GVMA:
case SBI_RFENCE__VVMA_ASID:
case SBI_RFENCE__VVMA:
/* Hypervisor-related RFENCE operations - not implemented */
return (sbi_ret_t){SBI_SUCCESS, 0};
return (sbi_ret_t) {SBI_SUCCESS, 0};
default:
return (sbi_ret_t){SBI_ERR_FAILED, 0};
return (sbi_ret_t) {SBI_ERR_FAILED, 0};
}
}

Expand All @@ -504,26 +504,26 @@ static inline sbi_ret_t handle_sbi_ecall_BASE(hart_t *hart, int32_t fid)
{
switch (fid) {
case SBI_BASE__GET_SBI_IMPL_ID:
return (sbi_ret_t){SBI_SUCCESS, SBI_IMPL_ID};
return (sbi_ret_t) {SBI_SUCCESS, SBI_IMPL_ID};
case SBI_BASE__GET_SBI_IMPL_VERSION:
return (sbi_ret_t){SBI_SUCCESS, SBI_IMPL_VERSION};
return (sbi_ret_t) {SBI_SUCCESS, SBI_IMPL_VERSION};
case SBI_BASE__GET_MVENDORID:
return (sbi_ret_t){SBI_SUCCESS, RV_MVENDORID};
return (sbi_ret_t) {SBI_SUCCESS, RV_MVENDORID};
case SBI_BASE__GET_MARCHID:
return (sbi_ret_t){SBI_SUCCESS, RV_MARCHID};
return (sbi_ret_t) {SBI_SUCCESS, RV_MARCHID};
case SBI_BASE__GET_MIMPID:
return (sbi_ret_t){SBI_SUCCESS, RV_MIMPID};
return (sbi_ret_t) {SBI_SUCCESS, RV_MIMPID};
case SBI_BASE__GET_SBI_SPEC_VERSION:
return (sbi_ret_t){SBI_SUCCESS, (2 << 24) | 0}; /* version 2.0 */
return (sbi_ret_t) {SBI_SUCCESS, (2 << 24) | 0}; /* version 2.0 */
case SBI_BASE__PROBE_EXTENSION: {
int32_t eid = (int32_t) hart->x_regs[RV_R_A0];
bool available = eid == SBI_EID_BASE || eid == SBI_EID_TIMER ||
eid == SBI_EID_RST || eid == SBI_EID_HSM ||
eid == SBI_EID_IPI || eid == SBI_EID_RFENCE;
return (sbi_ret_t){SBI_SUCCESS, available};
return (sbi_ret_t) {SBI_SUCCESS, available};
}
default:
return (sbi_ret_t){SBI_ERR_NOT_SUPPORTED, 0};
return (sbi_ret_t) {SBI_ERR_NOT_SUPPORTED, 0};
}
}

Expand Down Expand Up @@ -553,7 +553,7 @@ static void handle_sbi_ecall(hart_t *hart)
SBI_HANDLE(RFENCE);
break;
default:
ret = (sbi_ret_t){SBI_ERR_NOT_SUPPORTED, 0};
ret = (sbi_ret_t) {SBI_ERR_NOT_SUPPORTED, 0};
}
hart->x_regs[RV_R_A0] = (uint32_t) ret.error;
hart->x_regs[RV_R_A1] = (uint32_t) ret.value;
Expand Down Expand Up @@ -1249,15 +1249,15 @@ static int semu_run(emu_state_t *emu)
#ifdef __APPLE__
/* macOS: use kqueue with EVFILT_TIMER */
if (kq >= 0 && pfd_count < poll_capacity && harts_active) {
pfds[pfd_count] = (struct pollfd){kq, POLLIN, 0};
pfds[pfd_count] = (struct pollfd) {kq, POLLIN, 0};
timer_index = (int) pfd_count;
pfd_count++;
}
#else
/* Linux: use timerfd */
if (wfi_timer_fd >= 0 && pfd_count < poll_capacity &&
harts_active) {
pfds[pfd_count] = (struct pollfd){wfi_timer_fd, POLLIN, 0};
pfds[pfd_count] = (struct pollfd) {wfi_timer_fd, POLLIN, 0};
timer_index = (int) pfd_count;
pfd_count++;
}
Expand All @@ -1279,7 +1279,7 @@ static int semu_run(emu_state_t *emu)
(idle_harts == 0) || emu->uart.has_waiting_hart;
if (emu->uart.in_fd >= 0 && pfd_count < poll_capacity &&
need_uart) {
pfds[pfd_count] = (struct pollfd){emu->uart.in_fd, POLLIN, 0};
pfds[pfd_count] = (struct pollfd) {emu->uart.in_fd, POLLIN, 0};
pfd_count++;
}

Expand Down Expand Up @@ -1521,7 +1521,7 @@ static int semu_run_debug(emu_state_t *emu)

emu->curr_cpuid = 0;
if (!gdbstub_init(&gdbstub, &gdbstub_ops,
(arch_info_t){
(arch_info_t) {
.smp = vm->n_hart,
.reg_num = 33,
.target_desc = TARGET_RV32,
Expand Down
Loading
Loading