Skip to content

Commit

Permalink
Facilitate PRIV macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jserv committed Jan 18, 2024
1 parent 71c3746 commit 55bf643
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
#include "riscv.h"
#include "riscv_private.h"

#define PRIV(x) ((emu_state_t *) x->priv)

/* Define fetch separately since it is simpler (fixed width, already checked
* alignment, only main RAM is executable).
*/
static void mem_fetch(vm_t *vm, uint32_t n_pages, uint32_t **page_addr)
{
emu_state_t *data = (emu_state_t *) vm->priv;
emu_state_t *data = PRIV(vm);
if (unlikely(n_pages >= RAM_SIZE / RV_PAGE_SIZE)) {
/* TODO: check for other regions */
vm_set_exception(vm, RV_EXC_FETCH_FAULT, vm->exc_val);
Expand All @@ -29,15 +31,15 @@ static void mem_fetch(vm_t *vm, uint32_t n_pages, uint32_t **page_addr)
/* Similarly, only main memory pages can be used as page tables. */
static uint32_t *mem_page_table(const vm_t *vm, uint32_t ppn)
{
emu_state_t *data = (emu_state_t *) vm->priv;
emu_state_t *data = PRIV(vm);
if (ppn < (RAM_SIZE / RV_PAGE_SIZE))
return &data->ram[ppn << (RV_PAGE_SHIFT - 2)];
return NULL;
}

static void emu_update_uart_interrupts(vm_t *vm)
{
emu_state_t *data = (emu_state_t *) vm->priv;
emu_state_t *data = PRIV(vm);
u8250_update_interrupts(&data->uart);
if (data->uart.pending_ints)
data->plic.active |= IRQ_UART_BIT;
Expand All @@ -49,7 +51,7 @@ static void emu_update_uart_interrupts(vm_t *vm)
#if SEMU_HAS(VIRTIONET)
static void emu_update_vnet_interrupts(vm_t *vm)
{
emu_state_t *data = (emu_state_t *) vm->priv;
emu_state_t *data = PRIV(vm);
if (data->vnet.InterruptStatus)
data->plic.active |= IRQ_VNET_BIT;
else
Expand All @@ -61,7 +63,7 @@ static void emu_update_vnet_interrupts(vm_t *vm)
#if SEMU_HAS(VIRTIOBLK)
static void emu_update_vblk_interrupts(vm_t *vm)
{
emu_state_t *data = (emu_state_t *) vm->priv;
emu_state_t *data = PRIV(vm);
if (data->vblk.InterruptStatus)
data->plic.active |= IRQ_VBLK_BIT;
else
Expand All @@ -72,8 +74,7 @@ static void emu_update_vblk_interrupts(vm_t *vm)

static void mem_load(vm_t *vm, uint32_t addr, uint8_t width, uint32_t *value)
{
emu_state_t *data = (emu_state_t *) vm->priv;

emu_state_t *data = PRIV(vm);
/* RAM at 0x00000000 + RAM_SIZE */
if (addr < RAM_SIZE) {
ram_read(vm, data->ram, addr, width, value);
Expand Down Expand Up @@ -111,8 +112,7 @@ static void mem_load(vm_t *vm, uint32_t addr, uint8_t width, uint32_t *value)

static void mem_store(vm_t *vm, uint32_t addr, uint8_t width, uint32_t value)
{
emu_state_t *data = (emu_state_t *) vm->priv;

emu_state_t *data = PRIV(vm);
/* RAM at 0x00000000 + RAM_SIZE */
if (addr < RAM_SIZE) {
ram_write(vm, data->ram, addr, width, value);
Expand Down Expand Up @@ -159,7 +159,7 @@ typedef struct {

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

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

0 comments on commit 55bf643

Please sign in to comment.