Skip to content

Commit

Permalink
Unify MMU translation APIs
Browse files Browse the repository at this point in the history
To enable guest OS to run SDL applications using bidirectional queues,
the VMM or system emulator must access the guest OS's virtual memory,
as the queues are defined there. This requires MMU translation.

Export rv->io.mem_trans() to perform gVA2gPA translation. Unifying
MMU translation logic by using rv->io.mem_trans(), eliminating redundant
flows: mmu_walk -> check_pg_fault -> check_signal -> get_ppn_and_offset.
Also, this interface allowing src/syscall_sdl.c to handle virtual
memory.

TODO: dTLB can be introduced in rv->io.mem_trans() to cache the gVA2gPA
translation.

See: #310, #510
  • Loading branch information
ChinYikMing committed Jan 3, 2025
1 parent 5a04f3a commit 88f83c8
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 189 deletions.
18 changes: 17 additions & 1 deletion src/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,20 @@ typedef void (*riscv_mem_write_s)(riscv_t *rv,
typedef void (*riscv_mem_write_b)(riscv_t *rv,
riscv_word_t addr,
riscv_byte_t data);
#if RV32_HAS(SYSTEM)
/*
* VA2PA handler
* The MMU walkers and fault checkers are defined in system.c
* Thus, exporting this handler through function pointer
* preserves the encapsulation of MMU translation.
*
* ifetch do not leverage this translation because basic block
* might be retranslated and the corresponding PTE is NULL.
*/
typedef riscv_word_t (*riscv_mem_trans)(riscv_t *rv,
riscv_word_t vaddr,
bool rw);
#endif

/* system instruction handlers */
typedef void (*riscv_on_ecall)(riscv_t *rv);
Expand All @@ -424,7 +438,9 @@ typedef struct {
riscv_mem_write_s mem_write_s;
riscv_mem_write_b mem_write_b;

/* TODO: add peripheral I/O interfaces */
#if RV32_HAS(SYSTEM)
riscv_mem_trans mem_trans;
#endif

/* system */
riscv_on_ecall on_ecall;
Expand Down
Loading

0 comments on commit 88f83c8

Please sign in to comment.