示例#1
0
/**
* monitor_event - called from monitor interrupt handler
 */
void monitor_event(void)
{
    if (monitor_connected()) {
        monitor_load();
    }
    else {
        monitor_unload();
#if !defined(CONFIG_SA1100_CONNECT_GPIO) 
        monitor_load();
#endif
    }
}
示例#2
0
文件: main.c 项目: ANSSI-FR/picon
int main (int argc, char *argv[]) {
  char buffer[128];
  int fd_client_to_monitor[2];
  int fd_monitor_to_client[2];
  int fd_loading_to_monitor[2];
  int fd_monitor_to_loading[2];

  pid_t child_pid;

  unsigned int err = 0;
  monitor_data data;

  if(getenv("LD_PRELOAD")) {
    LOG_ERROR_MONITOR("LD_PRELOAD detected, aborting\n");
    return -1;
  }

  if((getenv(ENV_FD_CLIENT_TO_MONITOR)) ||
     (getenv(ENV_FD_MONITOR_TO_CLIENT)) ||
     (getenv(ENV_FD_LOADING_TO_MONITOR)) ||
     (getenv(ENV_FD_MONITOR_TO_LOADING))) {
    LOG_ERROR_MONITOR("inception of monitored programs is not supported\n");
    return -1;
  }

  if(argc < 2) {
    LOG_ERROR_MONITOR("usage: %s prog [prog_args ...]\n", argv[0]);
    return -2;
  }

  if(getenv(ENV_SM_TRACE)) {
    LOG_DEBUG_MONITOR("%s set, so we are keeping traces\n", ENV_SM_TRACE);
    OPTION_sm_trace = 1;
  }

  if(getenv(ENV_SM_DUMP)) {
    OPTION_sm_dump = 1;
  }

  if(pipe2(fd_client_to_monitor, O_DIRECT)) {
    LOG_ERROR_MONITOR("failed to create client to monitor pipe : %s\n", strerror(errno));
    return -3;
  }

  if(pipe2(fd_monitor_to_client, O_DIRECT)) {
    LOG_ERROR_MONITOR("failed to create monitor to client pipe : %s\n", strerror(errno));
    return -3;
  }

  if(pipe2(fd_loading_to_monitor, O_DIRECT)) {
    LOG_ERROR_MONITOR("failed to create loading to monitor pipe : %s\n", strerror(errno));
    return -3;
  }

  if(pipe2(fd_monitor_to_loading, O_DIRECT)) {
    LOG_ERROR_MONITOR("failed to create monitor to loading pipe : %s\n", strerror(errno));
    return -3;
  }


  LOG_DEBUG_MONITOR("forking\n");

  if((child_pid = fork()) > 0) {
    /* monitor process */
    close(fd_client_to_monitor[1]);
    close(fd_monitor_to_client[0]);
    close(fd_loading_to_monitor[1]);
    close(fd_monitor_to_loading[0]);

    if((err = mask_sigpipe())) {
      LOG_ERROR_MONITOR("cannot mask SIGPIPE\n");
    } else if((err = monitor_load(child_pid,
                                  fd_client_to_monitor[0],
                                  fd_monitor_to_client[1],
                                  fd_loading_to_monitor[0],
                                  fd_monitor_to_loading[1],
                                  &data))) {
      LOG_ERROR_MONITOR("failed to load monitor data\n");
    } else {

      if(OPTION_nb_preload_monitor_ok_answers > 0) {
        const monitor_answer ok_resp = { .event = CFI_OK };
        unsigned int i = 0;
        LOG_DEBUG_MONITOR("preloading %u OK answers\n", OPTION_nb_preload_monitor_ok_answers);
        while((i < OPTION_nb_preload_monitor_ok_answers) && !err) {
          WRITE_MONITOR_ANSWER(data.fd_monitor_to_client, ok_resp, err);
          ++i;
        }
      }

      LOG_DEBUG_MONITOR("main loop\n");
      err = monitor_run(data);
      if(!err) {
        unsigned int i;
        unsigned int nb = 0;
        for(i = 0; i < data.nb_modules; ++i) {
          nb += data.modules[i].nb_entrypoint_finis;
        }
        i = 0;
        LOG_DEBUG_MONITOR("%u finis are expected\n", nb);
        while((i < nb) && !err) {
          err = monitor_run(data);
          ++i;
        }
      }
    }

    LOG_DEBUG_MONITOR("exits with status = %i\n", err);

    if(err) {
      LOG_DEBUG_MONITOR("killing client\n");
      kill(child_pid, SIGKILL);
    }

    monitor_data_free(&data);

    return err;

  } else if(child_pid == 0) {
示例#3
0
int os_main(int argc, char* argv[])
{
	adv_crtc_container selected;
	adv_crtc_container_iterator i;
	const char* opt_rc;
	adv_bool opt_log;
	adv_bool opt_logsync;
	int j;
	adv_error res;
	char* section_map[1];
	char buffer[1024];

	opt_rc = 0;
	opt_log = 0;
	opt_logsync = 0;
	the_advance = advance_mame;
	the_sound_flag = 1;

	the_config = conf_init();

	if (os_init(the_config)!=0) {
		target_err("Error initializing the OS support.\n");
		goto err_conf;
	}

	video_reg(the_config, 1);
	monitor_register(the_config);
	crtc_container_register(the_config);
	generate_interpolate_register(the_config);
	gtf_register(the_config);
	inputb_reg(the_config, 1);
	inputb_reg_driver_all(the_config);
	
	/* MSDOS requires a special driver sub set */
#ifndef __MSDOS__
	video_reg_driver_all(the_config);
#endif

	if (conf_input_args_load(the_config, 1, "", &argc, argv, error_callback, 0) != 0)
		goto err_os;

	for(j=1;j<argc;++j) {
		if (target_option_compare(argv[j], "rc") && j+1<argc) {
			opt_rc = argv[++j];
		} else if (target_option_compare(argv[j], "log")) {
			opt_log = 1;
		} else if (target_option_compare(argv[j], "logsync")) {
			opt_logsync = 1;
		} else if (target_option_compare(argv[j], "nosound")) {
			the_sound_flag = 0;
		} else if (target_option_compare(argv[j], "advmamev")) {
			the_advance = advance_mame;
		} else if (target_option_compare(argv[j], "advmessv")) {
			the_advance = advance_mess;
		} else if (target_option_compare(argv[j], "advpacv")) {
			the_advance = advance_pac;
		} else if (target_option_compare(argv[j], "advmenuv")) {
			the_advance = advance_menu;
#ifdef __MSDOS__
		} else if (target_option_compare(argv[j], "vgav")) {
			the_advance = advance_vga;
		} else if (target_option_compare(argv[j], "vbev")) {
			the_advance = advance_vbe;
#endif
#ifdef __WIN32__
		} else if (target_option_compare(argv[j], "videowv")) {
			the_advance = advance_videow;
#endif
		} else {
			target_err("Unknown option %s\n", argv[j]);
			goto err;
		}
	}

#ifdef __MSDOS__
	/* WARNING the MSDOS drivers are registered after the command line management. */
	/* It implyes that you cannot specify any driver options on the command line */
	msdos_rut();

	if (the_advance == advance_vga) {
		if (the_advance_vga_active) {
			target_err("The AdvanceVGA utility is active. Disable it before running vgav.\n");
			goto err;
		}
		video_reg_driver(the_config, &video_vgaline_driver);
	} else if (the_advance == advance_vbe) {
		if (the_advance_vbe_active) {
			target_err("The AdvanceVBE utility is active. Disable it before running vbev.\n");
			goto err;
		}
		video_reg_driver(the_config, &video_vbeline_driver);
		video_reg_driver(the_config, &video_vgaline_driver); /* for the text modes */
	} else {
		video_reg_driver_all(the_config);
	}
#endif

	if (!opt_rc) {
		switch (the_advance) {
			case advance_vbe : opt_rc = "vbe.rc"; break;
			case advance_vga : opt_rc = "vga.rc"; break;
			case advance_menu : opt_rc = file_config_file_home("advmenu.rc"); break;
			case advance_mame : opt_rc = file_config_file_home("advmame.rc"); break;
			case advance_mess : opt_rc = file_config_file_home("advmess.rc"); break;
			case advance_pac : opt_rc = file_config_file_home("advpac.rc"); break;
			case advance_videow : opt_rc = file_config_file_home("videow.rc"); break;
			default : opt_rc = "advv.rc"; break;
		}
	}

	if (access(opt_rc, R_OK)!=0) {
		target_err("Configuration file %s not found.\n", opt_rc);
		goto err_os;
	}

	if (conf_input_file_load_adv(the_config, 0, opt_rc, opt_rc, 1, 1, STANDARD, sizeof(STANDARD)/sizeof(STANDARD[0]), error_callback, 0) != 0)
		goto err_os;

	if (opt_log || opt_logsync) {
		const char* log = "advv.log";
		remove(log);
		log_init(log, opt_logsync);
        }

	log_std(("v: %s %s\n", __DATE__, __TIME__));

	section_map[0] = "";
	conf_section_set(the_config, section_map, 1);

	if (video_load(the_config, "") != 0) {
		target_err("Error loading the video options from the configuration file %s.\n", opt_rc);
		target_err("%s\n", error_get());
		goto err_os;
	}

	if (inputb_load(the_config) != 0) {
		target_err("%s\n", error_get());
		goto err_os;
	}

	/* NOTE: After this command all the target_err() string must */
	/* have \n\r at the end to ensure correct newline in graphics mode. */

	if (os_inner_init("AdvanceVIDEO") != 0) {
		goto err_os;
	}

	if (adv_video_init() != 0) {
		target_err("%s\n\r", error_get());
		troubleshotting();
		goto err_os_inner;
	}

	if (video_blit_init() != 0) {
		target_err("%s\n\r", error_get());
		goto err_video;
	}

	if (the_advance != advance_vbe && the_advance != advance_vga) {
		if ((video_mode_generate_driver_flags(VIDEO_DRIVER_FLAGS_MODE_GRAPH_MASK, 0) & VIDEO_DRIVER_FLAGS_PROGRAMMABLE_CLOCK) == 0) {
			target_err("No active video driver is able to program your video board.\n\r");
			troubleshotting();
			goto err_blit;
		}
	}

	if (inputb_init() != 0) {
		target_err("%s\n\r", error_get());
		goto err_blit;
	}

	if (monitor_load(the_config, &the_monitor) != 0) {
		target_err("Error loading the clock options from the configuration file %s.\n\r", opt_rc);
		target_err("%s\n\r", error_get());
		goto err_input;
	}

	monitor_print(buffer, sizeof(buffer), &the_monitor);
	log_std(("v: clock %s\n", buffer));

	/* load generate_linear config */
	res = generate_interpolate_load(the_config, &the_interpolate);
	if (res<0) {
		target_err("Error loading the format options from the configuration file %s.\n\r", opt_rc);
		target_err("%s\n\r", error_get());
		goto err_input;
	}
	if (res>0) {
		generate_default_vga(&the_interpolate.map[0].gen);
		the_interpolate.map[0].hclock = 31500;
		the_interpolate.mac = 1;
	}

	/* load generate_linear config */
	res = gtf_load(the_config, &the_gtf);
	if (res<0) {
		target_err("Error loading the gtf options from the configuration file %s.\n\r", opt_rc);
		target_err("%s\n\r", error_get());
		goto err_input;
	}
	if (res>0) {
		gtf_default_vga(&the_gtf);
	}

	/* all mode */
	crtc_container_init(&selected);

	/* insert modes */
	crtc_container_insert_default_all(&selected);

	/* sort */
	crtc_container_init(&the_modes);
	for(crtc_container_iterator_begin(&i, &selected);!crtc_container_iterator_is_end(&i);crtc_container_iterator_next(&i)) {
		adv_crtc* crtc = crtc_container_iterator_get(&i);
		crtc_container_insert_sort(&the_modes, crtc, crtc_compare);
	}
	crtc_container_done(&selected);

	/* load selected */
	crtc_container_init(&selected);

	if (crtc_container_load(the_config, &selected) != 0) {
		target_err("%s\n\r", error_get());
		goto err_input;
	}

	/* union set */
	for(crtc_container_iterator_begin(&i, &selected);!crtc_container_iterator_is_end(&i);crtc_container_iterator_next(&i)) {
		adv_crtc* crtc = crtc_container_iterator_get(&i);
		adv_bool has = crtc_container_has(&the_modes, crtc, crtc_compare) != 0;
		if (has)
			crtc_container_remove(&the_modes, crtc_select_by_compare, crtc);
		crtc->user_flags |= MODE_FLAGS_USER_BIT0;
		crtc_container_insert_sort(&the_modes, crtc, crtc_compare);
	}
	crtc_container_done(&selected);

	the_modes_modified = 0;

	if (text_init(&the_modes, &the_monitor) != 0) {
		goto err_input;
	}

	if (inputb_enable(0) != 0) {
		goto err_text;
	}

	sound_signal();

	menu_run();

	log_std(("v: shutdown\n"));

	inputb_disable();

	text_done();

	crtc_container_done(&the_modes);

	inputb_done();

	video_blit_done();

	adv_video_done();

	os_inner_done();

	log_std(("v: the end\n"));

	if (opt_log || opt_logsync) {
		log_done();
	}

	os_done();

	conf_save(the_config, 0, 0, error_callback, 0);

	conf_done(the_config);

	return EXIT_SUCCESS;

err_text:
	text_done();
err_input:
	inputb_done();
err_blit:
	video_blit_done();
err_video:
	adv_video_done();
err_os_inner:
	os_inner_done();
err_os:
	if (opt_log || opt_logsync) {
		log_done();
	}
	os_done();
err_conf:
	conf_done(the_config);
err:
	return EXIT_FAILURE;
}