@@ -117,7 +117,9 @@ static void uc_common_setup(uc_engine **uc, uc_cpu_avr cpu_model,
117
117
static void test_avr_basic_alu (void )
118
118
{
119
119
uc_engine * uc = NULL ;
120
+
120
121
uint8_t r [32 ] = {0 ,};
122
+ uint32_t r_pc ;
121
123
uint16_t r_func_arg0 = 1 , r_func_arg1 = 2 , r_func_ret ;
122
124
r [24 ] = 1 ;
123
125
r [22 ] = 2 ;
@@ -129,7 +131,6 @@ static void test_avr_basic_alu(void)
129
131
const uint64_t code_start = ADDR [ADDR_test_func ] + 8 ;
130
132
OK (uc_emu_start (uc , code_start , code_start + 4 , 0 , 0 ));
131
133
132
- uint32_t r_pc ;
133
134
OK (uc_reg_read (uc , UC_AVR_REG_PC , & r_pc ));
134
135
OK (uc_reg_read (uc , UC_AVR_REG_R25 , & r [25 ]));
135
136
OK (uc_reg_read (uc , UC_AVR_REG_R24 , & r [24 ]));
@@ -185,28 +186,30 @@ static void test_avr_basic_mem(void)
185
186
uc_hook eventmem_hook ;
186
187
MEM_HOOK_RESULTS eventmem_trace = {0 };
187
188
189
+ const uint16_t DATA_BASE = ADDR [ADDR__data__ ];
190
+ const uint16_t DATA_SIZE = ADDR [ADDR__data__ + 1 ] - DATA_BASE ;
191
+ const uint8_t * const DATA = & FLASH [ADDR [ADDR__data__ ]];
192
+ uint8_t mem [DATA_SIZE ];
193
+
194
+ uint32_t r_pc ;
195
+ int i ;
196
+
188
197
uc_common_setup (& uc , 0 , FLASH , FLASH_SIZE );
189
198
OK (uc_hook_add (uc , & eventmem_hook , UC_HOOK_MEM_VALID ,
190
199
test_avr_basic_mem_cb_eventmem , & eventmem_trace , 1 , 0 ));
191
200
192
201
const uint64_t code_start = ADDR [ADDR__init__ ];
193
202
OK (uc_emu_start (uc , code_start , ADDR [ADDR__init__ + 1 ], 0 , 0 ));
194
203
195
- uint32_t r_pc ;
196
204
OK (uc_reg_read (uc , UC_AVR_REG_PC , & r_pc ));
197
205
TEST_CHECK (r_pc == ADDR [ADDR__init__ + 1 ]);
198
206
199
- const uint16_t DATA_BASE = ADDR [ADDR__data__ ];
200
- const uint16_t DATA_SIZE = ADDR [ADDR__data__ + 1 ] - DATA_BASE ;
201
- const uint8_t * const DATA = & FLASH [ADDR [ADDR__data__ ]];
202
-
203
207
// Check SRAM was correctly initialized with data from Flash program memory
204
- uint8_t mem [DATA_SIZE ];
205
208
OK (uc_mem_read (uc , MEM_BASE , mem , sizeof (mem )));
206
209
TEST_CHECK (memcmp (mem , DATA , DATA_SIZE ) == 0 );
207
210
208
211
TEST_CHECK (eventmem_trace .count == 2 * DATA_SIZE );
209
- for (unsigned i = 0 ; i < DATA_SIZE ; i ++ ) {
212
+ for (i = 0 ; i < DATA_SIZE ; i ++ ) {
210
213
const MEM_HOOK_RESULT * const mr = & eventmem_trace .results [2 * i ];
211
214
TEST_CHECK (mr -> type == UC_MEM_READ );
212
215
TEST_CHECK (mr -> address == (UC_AVR_MEM_FLASH |(DATA_BASE + i )));
@@ -227,16 +230,19 @@ static void test_avr_full_exec(void)
227
230
{
228
231
uc_engine * uc = NULL ;
229
232
233
+ uint8_t r [32 ] = {0 ,};
234
+ uint32_t r_pc ;
235
+ uint32_t r_sp ;
236
+
230
237
uc_common_setup (& uc , 0 , FLASH , FLASH_SIZE );
231
238
232
239
const uint64_t code_start = ADDR [ADDR__init__ ];
233
240
OK (uc_emu_start (uc , code_start , ADDR [ADDR__init__ + 1 ], 0 , 0 ));
234
241
235
- uint32_t r_pc ;
236
242
OK (uc_reg_read (uc , UC_AVR_REG_PC , & r_pc ));
237
243
TEST_CHECK (r_pc == ADDR [ADDR__init__ + 1 ]);
238
244
239
- uint32_t r_sp = MEM_BASE + MEM_SIZE - 1 ;
245
+ r_sp = MEM_BASE + MEM_SIZE - 1 ;
240
246
OK (uc_reg_write (uc , UC_AVR_REG_SP , & r_sp ));
241
247
242
248
const uint64_t exits [] = {
@@ -249,7 +255,6 @@ static void test_avr_full_exec(void)
249
255
const uint64_t code_main = ADDR [ADDR_main ];
250
256
OK (uc_emu_start (uc , code_main , 0 , 0 , 0 ));
251
257
252
- uint8_t r [32 ] = {0 ,};
253
258
OK (uc_reg_read (uc , UC_AVR_REG_R25 , & r [25 ]));
254
259
OK (uc_reg_read (uc , UC_AVR_REG_R24 , & r [24 ]));
255
260
TEST_CHECK (r [25 ] == 0 && r [24 ] == 0 );
0 commit comments