@@ -33,7 +33,7 @@ file, You can obtain one at https://mozilla.org/MPL/2.0/.
33
33
#define RVVM_TLB_MASK (RVVM_TLB_SIZE - 1)
34
34
35
35
BUILD_ASSERT (RVVM_TLB_SIZE );
36
- BUILD_ASSERT (!(( RVVM_TLB_SIZE - 1 ) & RVVM_TLB_SIZE ));
36
+ BUILD_ASSERT (!(RVVM_TLB_SIZE & RVVM_TLB_MASK ));
37
37
38
38
#define RISCV_REG_ZERO 0
39
39
#define RISCV_REG_X0 0
@@ -116,16 +116,14 @@ typedef int32_t rvvm_sxlen_t;
116
116
#endif
117
117
118
118
/*
119
- * Address translation cache
120
- * In future, it would be nice to verify if cache-line alignment
121
- * gives any profit (entries scattered between cachelines waste L1)
119
+ * Address translation cache (TLB)
122
120
*/
123
121
124
- typedef struct {
122
+ typedef randomized_struct align_type ( 32 ) {
125
123
// Pointer to page (With vaddr subtracted, for faster TLB translation)
126
124
size_t ptr ;
127
- #if ! defined(HOST_64BIT )
128
- // Make entry size a power of 2 (32 bytes)
125
+ #if defined(HOST_32BIT )
126
+ // Make structure size a power of 2 (32 bytes) regardless of align_type() support
129
127
size_t align ;
130
128
#endif
131
129
// Virtual page number per each op type (vaddr >> 12)
@@ -136,16 +134,19 @@ typedef struct {
136
134
137
135
#ifdef USE_JIT
138
136
139
- typedef struct {
137
+ typedef randomized_struct align_type ( 16 ) {
140
138
// Pointer to code block
141
139
rvjit_func_t block ;
142
- #if !defined(HOST_64BIT )
140
+ #if defined(HOST_32BIT )
141
+ // Make structure size a power of 2 (16 bytes) regardless of align_type() support
143
142
size_t align ;
144
143
#endif
145
144
// Virtual PC of this entry
146
145
rvvm_addr_t pc ;
147
146
} rvvm_jit_tlb_entry_t ;
148
147
148
+ // Those structure sizes are mandatory if we are going to use JIT
149
+ // For pure interpreter this doesn't matter, so obscure architectures are fine
149
150
BUILD_ASSERT (sizeof (rvvm_tlb_entry_t ) == 32 );
150
151
BUILD_ASSERT (sizeof (rvvm_jit_tlb_entry_t ) == 16 );
151
152
@@ -155,7 +156,7 @@ BUILD_ASSERT(sizeof(rvvm_jit_tlb_entry_t) == 16);
155
156
* Physical RAM region
156
157
*/
157
158
158
- typedef struct {
159
+ typedef randomized_struct {
159
160
rvvm_addr_t addr ; // Physical memory base address (Should be page-aligned)
160
161
size_t size ; // Physical memory amount (Should be page-aligned)
161
162
void * data ; // Pointer to memory data (Preferably page-aligned)
@@ -169,7 +170,7 @@ typedef struct {
169
170
#define RVVM_AIA_IRQ_LIMIT 256
170
171
#define RVVM_AIA_ARR_LEN (RVVM_AIA_IRQ_LIMIT >> 5)
171
172
172
- typedef struct {
173
+ typedef randomized_struct {
173
174
uint32_t eidelivery ;
174
175
uint32_t eithreshold ;
175
176
uint32_t eip [RVVM_AIA_ARR_LEN ];
@@ -180,7 +181,7 @@ typedef struct {
180
181
* Hart structure
181
182
*/
182
183
183
- struct rvvm_hart_t {
184
+ struct align_cacheline rvvm_hart_t {
184
185
uint32_t running ;
185
186
186
187
rvvm_uxlen_t registers [RISCV_REGS_MAX ];
@@ -195,6 +196,8 @@ struct rvvm_hart_t {
195
196
#endif
196
197
197
198
// Everything below here isn't accessed by JIT
199
+ randomized_fields_start
200
+
198
201
rvvm_ram_t mem ;
199
202
rvvm_machine_t * machine ;
200
203
rvvm_addr_t root_page_table ;
@@ -211,7 +214,7 @@ struct rvvm_hart_t {
211
214
rvvm_uxlen_t lrsc_addr ;
212
215
rvvm_uxlen_t lrsc_cas ;
213
216
214
- struct {
217
+ randomized_struct {
215
218
uint32_t fcsr ;
216
219
uint32_t hartid ;
217
220
@@ -257,11 +260,10 @@ struct rvvm_hart_t {
257
260
uint32_t pending_events ;
258
261
uint32_t preempt_ms ;
259
262
260
- // Cacheline alignment
261
- uint8_t align [64 ];
263
+ randomized_fields_end
262
264
};
263
265
264
- struct rvvm_machine_t {
266
+ randomized_struct rvvm_machine_t {
265
267
rvvm_ram_t mem ;
266
268
vector_t (rvvm_hart_t * ) harts ;
267
269
vector_t (rvvm_mmio_dev_t * ) mmio_devs ;
0 commit comments