Skip to content

Commit 55bf643

Browse files
committed
Facilitate PRIV macro
1 parent 71c3746 commit 55bf643

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

main.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
#include "riscv.h"
1313
#include "riscv_private.h"
1414

15+
#define PRIV(x) ((emu_state_t *) x->priv)
16+
1517
/* Define fetch separately since it is simpler (fixed width, already checked
1618
* alignment, only main RAM is executable).
1719
*/
1820
static void mem_fetch(vm_t *vm, uint32_t n_pages, uint32_t **page_addr)
1921
{
20-
emu_state_t *data = (emu_state_t *) vm->priv;
22+
emu_state_t *data = PRIV(vm);
2123
if (unlikely(n_pages >= RAM_SIZE / RV_PAGE_SIZE)) {
2224
/* TODO: check for other regions */
2325
vm_set_exception(vm, RV_EXC_FETCH_FAULT, vm->exc_val);
@@ -29,15 +31,15 @@ static void mem_fetch(vm_t *vm, uint32_t n_pages, uint32_t **page_addr)
2931
/* Similarly, only main memory pages can be used as page tables. */
3032
static uint32_t *mem_page_table(const vm_t *vm, uint32_t ppn)
3133
{
32-
emu_state_t *data = (emu_state_t *) vm->priv;
34+
emu_state_t *data = PRIV(vm);
3335
if (ppn < (RAM_SIZE / RV_PAGE_SIZE))
3436
return &data->ram[ppn << (RV_PAGE_SHIFT - 2)];
3537
return NULL;
3638
}
3739

3840
static void emu_update_uart_interrupts(vm_t *vm)
3941
{
40-
emu_state_t *data = (emu_state_t *) vm->priv;
42+
emu_state_t *data = PRIV(vm);
4143
u8250_update_interrupts(&data->uart);
4244
if (data->uart.pending_ints)
4345
data->plic.active |= IRQ_UART_BIT;
@@ -49,7 +51,7 @@ static void emu_update_uart_interrupts(vm_t *vm)
4951
#if SEMU_HAS(VIRTIONET)
5052
static void emu_update_vnet_interrupts(vm_t *vm)
5153
{
52-
emu_state_t *data = (emu_state_t *) vm->priv;
54+
emu_state_t *data = PRIV(vm);
5355
if (data->vnet.InterruptStatus)
5456
data->plic.active |= IRQ_VNET_BIT;
5557
else
@@ -61,7 +63,7 @@ static void emu_update_vnet_interrupts(vm_t *vm)
6163
#if SEMU_HAS(VIRTIOBLK)
6264
static void emu_update_vblk_interrupts(vm_t *vm)
6365
{
64-
emu_state_t *data = (emu_state_t *) vm->priv;
66+
emu_state_t *data = PRIV(vm);
6567
if (data->vblk.InterruptStatus)
6668
data->plic.active |= IRQ_VBLK_BIT;
6769
else
@@ -72,8 +74,7 @@ static void emu_update_vblk_interrupts(vm_t *vm)
7274

7375
static void mem_load(vm_t *vm, uint32_t addr, uint8_t width, uint32_t *value)
7476
{
75-
emu_state_t *data = (emu_state_t *) vm->priv;
76-
77+
emu_state_t *data = PRIV(vm);
7778
/* RAM at 0x00000000 + RAM_SIZE */
7879
if (addr < RAM_SIZE) {
7980
ram_read(vm, data->ram, addr, width, value);
@@ -111,8 +112,7 @@ static void mem_load(vm_t *vm, uint32_t addr, uint8_t width, uint32_t *value)
111112

112113
static void mem_store(vm_t *vm, uint32_t addr, uint8_t width, uint32_t value)
113114
{
114-
emu_state_t *data = (emu_state_t *) vm->priv;
115-
115+
emu_state_t *data = PRIV(vm);
116116
/* RAM at 0x00000000 + RAM_SIZE */
117117
if (addr < RAM_SIZE) {
118118
ram_write(vm, data->ram, addr, width, value);
@@ -159,7 +159,7 @@ typedef struct {
159159

160160
static inline sbi_ret_t handle_sbi_ecall_TIMER(vm_t *vm, int32_t fid)
161161
{
162-
emu_state_t *data = (emu_state_t *) vm->priv;
162+
emu_state_t *data = PRIV(vm);
163163
switch (fid) {
164164
case SBI_TIMER__SET_TIMER:
165165
data->timer = (((uint64_t) vm->x_regs[RV_R_A1]) << 32) |
@@ -172,7 +172,7 @@ static inline sbi_ret_t handle_sbi_ecall_TIMER(vm_t *vm, int32_t fid)
172172

173173
static inline sbi_ret_t handle_sbi_ecall_RST(vm_t *vm, int32_t fid)
174174
{
175-
emu_state_t *data = (emu_state_t *) vm->priv;
175+
emu_state_t *data = PRIV(vm);
176176
switch (fid) {
177177
case SBI_RST__SYSTEM_RESET:
178178
fprintf(stderr, "system reset: type=%u, reason=%u\n",

0 commit comments

Comments
 (0)