@@ -293,7 +293,8 @@ static void usage(const char *execpath)
293293{
294294 fprintf (
295295 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" ,
297298 execpath );
298299}
299300
@@ -302,19 +303,21 @@ static void handle_options(int argc,
302303 char * * kernel_file ,
303304 char * * dtb_file ,
304305 char * * initrd_file ,
305- char * * disk_file )
306+ char * * disk_file ,
307+ uint32_t * cycle_limit )
306308{
307309 * kernel_file = * dtb_file = * initrd_file = * disk_file = NULL ;
308310
309311 int optidx = 0 ;
310312 struct option opts [] = {
311313 {"kernel" , 1 , NULL , 'k' }, {"dtb" , 1 , NULL , 'b' },
312314 {"initrd" , 1 , NULL , 'i' }, {"disk" , 1 , NULL , 'd' },
315+ {"max_cycles" , 1 , NULL , 'c' },
313316 {"help" , 0 , NULL , 'h' },
314317 };
315318
316319 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 ) {
318321 switch (c ) {
319322 case 'k' :
320323 * kernel_file = optarg ;
@@ -328,6 +331,14 @@ static void handle_options(int argc,
328331 case 'd' :
329332 * disk_file = optarg ;
330333 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 ;
331342 case 'h' :
332343 usage (argv [0 ]);
333344 exit (0 );
@@ -354,8 +365,9 @@ static int semu_start(int argc, char **argv)
354365 char * dtb_file ;
355366 char * initrd_file ;
356367 char * disk_file ;
368+ uint32_t cycle_limit = 0 ;
357369 handle_options (argc , argv , & kernel_file , & dtb_file , & initrd_file ,
358- & disk_file );
370+ & disk_file , & cycle_limit );
359371
360372 /* Initialize the emulator */
361373 emu_state_t emu ;
@@ -442,6 +454,7 @@ static int semu_start(int argc, char **argv)
442454 if (emu .vblk .InterruptStatus )
443455 emu_update_vblk_interrupts (& vm );
444456#endif
457+ if (cycle_limit && vm .insn_count >= cycle_limit ) exit (0 );
445458 }
446459
447460 if (vm .insn_count_hi > emu .timer_hi ||
0 commit comments