@@ -293,7 +293,8 @@ static void usage(const char *execpath)
293
293
{
294
294
fprintf (
295
295
stderr ,
296
- "Usage: %s -k linux-image [-b dtb] [-i initrd-image] [-d disk-image]\n" ,
296
+ "Usage: %s -k linux-image [-b dtb] [-i initrd-image] "
297
+ "[-d disk-image] [-c max_cycles]\n" ,
297
298
execpath );
298
299
}
299
300
@@ -302,19 +303,21 @@ static void handle_options(int argc,
302
303
char * * kernel_file ,
303
304
char * * dtb_file ,
304
305
char * * initrd_file ,
305
- char * * disk_file )
306
+ char * * disk_file ,
307
+ uint32_t * cycle_limit )
306
308
{
307
309
* kernel_file = * dtb_file = * initrd_file = * disk_file = NULL ;
308
310
309
311
int optidx = 0 ;
310
312
struct option opts [] = {
311
313
{"kernel" , 1 , NULL , 'k' }, {"dtb" , 1 , NULL , 'b' },
312
314
{"initrd" , 1 , NULL , 'i' }, {"disk" , 1 , NULL , 'd' },
315
+ {"max_cycles" , 1 , NULL , 'c' },
313
316
{"help" , 0 , NULL , 'h' },
314
317
};
315
318
316
319
int c ;
317
- while ((c = getopt_long (argc , argv , "k:b:i:d:h" , opts , & optidx )) != -1 ) {
320
+ while ((c = getopt_long (argc , argv , "k:b:i:d:c: h" , opts , & optidx )) != -1 ) {
318
321
switch (c ) {
319
322
case 'k' :
320
323
* kernel_file = optarg ;
@@ -328,6 +331,14 @@ static void handle_options(int argc,
328
331
case 'd' :
329
332
* disk_file = optarg ;
330
333
break ;
334
+ case 'c' :
335
+ if (sscanf (optarg , "%u" , cycle_limit ) != 1 ) {
336
+ fprintf (stderr , "Cannot parse -c max_cycles argument '%s'.\n" ,
337
+ optarg );
338
+ usage (argv [0 ]);
339
+ exit (2 );
340
+ }
341
+ break ;
331
342
case 'h' :
332
343
usage (argv [0 ]);
333
344
exit (0 );
@@ -354,8 +365,9 @@ static int semu_start(int argc, char **argv)
354
365
char * dtb_file ;
355
366
char * initrd_file ;
356
367
char * disk_file ;
368
+ uint32_t cycle_limit = 0 ;
357
369
handle_options (argc , argv , & kernel_file , & dtb_file , & initrd_file ,
358
- & disk_file );
370
+ & disk_file , & cycle_limit );
359
371
360
372
/* Initialize the emulator */
361
373
emu_state_t emu ;
@@ -442,6 +454,7 @@ static int semu_start(int argc, char **argv)
442
454
if (emu .vblk .InterruptStatus )
443
455
emu_update_vblk_interrupts (& vm );
444
456
#endif
457
+ if (cycle_limit && vm .insn_count >= cycle_limit ) exit (0 );
445
458
}
446
459
447
460
if (vm .insn_count_hi > emu .timer_hi ||
0 commit comments