diff options
author | Marti Alonso <41269236+martialonso@users.noreply.github.com> | 2025-05-06 02:01:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-05 17:01:39 -0700 |
commit | f349e0801e88757edfa1be4403c452766c65333c (patch) | |
tree | 60973b1ffbd29974ce5fd969d81641b421080028 | |
parent | 6de71edb142be36319e380ce782c3d1830c65d68 (diff) | |
download | env-master.zip env-master.tar.gz env-master.tar.bz2 |
When cputchar was fixed for RV32, virtual memory was not taken into
consideration. If cputchar was called in supervisor mode, with virtual
memory enabled, the pointers given to the HTIF would have wrongfully
been virtual addresses.
Translate pointers to always be physical addresses to support cputchar
with both virtual memory enabled and disabled. Defined macro kaa2pa is
short for 'kernel any address to physical address'.
-rw-r--r-- | v/vm.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -29,6 +29,7 @@ static void do_tohost(uint64_t tohost_value) tohost = tohost_value; } +#define kaa2pa(aa) ((uintptr_t)(aa) & (uintptr_t)(~(-MEGAPAGE_SIZE)) | (uintptr_t)(DRAM_BASE)) #define pa2kva(pa) ((void*)(pa) - DRAM_BASE - MEGAPAGE_SIZE) #define uva2kva(pa) ((void*)(pa) - MEGAPAGE_SIZE) @@ -48,9 +49,9 @@ static void cputchar(int x) volatile int buff = x; syscall_struct[0] = SYS_write; syscall_struct[1] = 1; - syscall_struct[2] = (uintptr_t)&buff; + syscall_struct[2] = kaa2pa(&buff); syscall_struct[3] = 1; - do_tohost((uintptr_t)&syscall_struct); + do_tohost(kaa2pa(&syscall_struct)); // Wait for response as struct has to be read by HTIF while(!fromhost); #else |