5
5
#include "tcg/tcg.h"
6
6
#include "qemu-common.h"
7
7
#include "exec/memory.h"
8
+ #include "exec/cpu_ldst.h"
8
9
9
10
// This header define common patterns/codes that will be included in all arch-sepcific
10
11
// codes for unicorns purposes.
@@ -28,6 +29,40 @@ static inline bool cpu_physical_mem_write(AddressSpace *as, hwaddr addr,
28
29
return cpu_physical_memory_rw (as , addr , (void * )buf , len , 1 );
29
30
}
30
31
32
+ static bool cpu_virtual_mem_read (struct uc_struct * uc , vaddr addr , uc_prot prot , uint8_t * buf , int len )
33
+ {
34
+ MMUAccessType access_type ;
35
+ void * hostptr ;
36
+ int mmu_idx = cpu_mmu_index (uc -> cpu -> env_ptr , false);
37
+
38
+ /*
39
+ * Only page aligned access is allowed,
40
+ * because tlb_fill() might change the mappings
41
+ */
42
+ assert ((addr & TARGET_PAGE_MASK ) == ((addr + len ) & TARGET_PAGE_MASK ));
43
+
44
+ switch (prot ) {
45
+ case UC_PROT_READ :
46
+ access_type = MMU_DATA_LOAD ;
47
+ break ;
48
+ case UC_PROT_WRITE :
49
+ access_type = MMU_DATA_STORE ;
50
+ break ;
51
+ case UC_PROT_EXEC :
52
+ access_type = MMU_INST_FETCH ;
53
+ break ;
54
+ default :
55
+ return false;
56
+ }
57
+
58
+ hostptr = tlb_vaddr_to_host (uc -> cpu -> env_ptr , addr , access_type , mmu_idx );
59
+ if (!hostptr ) {
60
+ return false;
61
+ }
62
+ memcpy (buf , hostptr , len );
63
+ return true;
64
+ }
65
+
31
66
void tb_cleanup (struct uc_struct * uc );
32
67
void free_code_gen_buffer (struct uc_struct * uc );
33
68
@@ -126,6 +161,7 @@ static inline void uc_common_init(struct uc_struct* uc)
126
161
{
127
162
uc -> write_mem = cpu_physical_mem_write ;
128
163
uc -> read_mem = cpu_physical_mem_read ;
164
+ uc -> read_mem_virtual = cpu_virtual_mem_read ;
129
165
uc -> tcg_exec_init = tcg_exec_init ;
130
166
uc -> cpu_exec_init_all = cpu_exec_init_all ;
131
167
uc -> vm_start = vm_start ;
0 commit comments