⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 psim.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
    printf_filtered("    change-media <device> [ <new-image> ]\n");  }}/* create the simulator proper from the device tree and executable */INLINE_PSIM\(psim *)psim_create(const char *file_name,	    device *root){  int cpu_nr;  const char *env;  psim *system;  os_emul *os_emulation;  int nr_cpus;  /* given this partially populated device tree, os_emul_create() uses     it and file_name to determine the selected emulation and hence     further populate the tree with any other required nodes. */  os_emulation = os_emul_create(file_name, root);  if (os_emulation == NULL)    error("psim: either file %s was not reconized or unreconized or unknown os-emulation type\n", file_name);  /* fill in the missing real number of CPU's */  nr_cpus = tree_find_integer_property(root, "/openprom/options/smp");  if (MAX_NR_PROCESSORS < nr_cpus)    error("target and configured number of cpus conflict\n");  /* fill in the missing TARGET BYTE ORDER information */  current_target_byte_order    = (tree_find_boolean_property(root, "/options/little-endian?")       ? LITTLE_ENDIAN       : BIG_ENDIAN);  if (CURRENT_TARGET_BYTE_ORDER != current_target_byte_order)    error("target and configured byte order conflict\n");  /* fill in the missing HOST BYTE ORDER information */  current_host_byte_order = (current_host_byte_order = 1,			     (*(char*)(&current_host_byte_order)			      ? LITTLE_ENDIAN			      : BIG_ENDIAN));  if (CURRENT_HOST_BYTE_ORDER != current_host_byte_order)    error("host and configured byte order conflict\n");  /* fill in the missing OEA/VEA information */  env = tree_find_string_property(root, "/openprom/options/env");  current_environment = ((strcmp(env, "user") == 0			  || strcmp(env, "uea") == 0)			 ? USER_ENVIRONMENT			 : (strcmp(env, "virtual") == 0			    || strcmp(env, "vea") == 0)			 ? VIRTUAL_ENVIRONMENT			 : (strcmp(env, "operating") == 0			    || strcmp(env, "oea") == 0)			 ? OPERATING_ENVIRONMENT			 : 0);  if (current_environment == 0)    error("unreconized /options env property\n");  if (CURRENT_ENVIRONMENT != current_environment)    error("target and configured environment conflict\n");  /* fill in the missing ALLIGNMENT information */  current_alignment    = (tree_find_boolean_property(root, "/openprom/options/strict-alignment?")       ? STRICT_ALIGNMENT       : NONSTRICT_ALIGNMENT);  if (CURRENT_ALIGNMENT != current_alignment)    error("target and configured alignment conflict\n");  /* fill in the missing FLOATING POINT information */  current_floating_point    = (tree_find_boolean_property(root, "/openprom/options/floating-point?")       ? HARD_FLOATING_POINT       : SOFT_FLOATING_POINT);  if (CURRENT_FLOATING_POINT != current_floating_point)    error("target and configured floating-point conflict\n");  /* fill in the missing STDIO information */  current_stdio    = (tree_find_boolean_property(root, "/openprom/options/use-stdio?")       ? DO_USE_STDIO       : DONT_USE_STDIO);  if (CURRENT_STDIO != current_stdio)    error("target and configured stdio interface conflict\n");  /* sort out the level of detail for issue modeling */  current_model_issue    = tree_find_integer_property(root, "/openprom/options/model-issue");  if (CURRENT_MODEL_ISSUE != current_model_issue)    error("target and configured model-issue conflict\n");  /* sort out our model architecture - wrong.     FIXME: this should be obtaining the required information from the     device tree via the "/chosen" property "cpu" which is an instance     (ihandle) for the only executing processor. By converting that     ihandle into the corresponding cpu's phandle and then querying     the "name" property, the cpu type can be determined. Ok? */  model_set(tree_find_string_property(root, "/openprom/options/model"));  /* create things */  system = ZALLOC(psim);  system->events = event_queue_create();  system->memory = core_from_device(root);  system->monitor = mon_create();  system->nr_cpus = nr_cpus;  system->os_emulation = os_emulation;  system->devices = root;  /* now all the processors attaching to each their per-cpu information */  for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++) {    system->processors[cpu_nr] = cpu_create(system,					    system->memory,					    mon_cpu(system->monitor,						    cpu_nr),					    system->os_emulation,					    cpu_nr);  }  /* dump out the contents of the device tree */  if (ppc_trace[trace_print_device_tree] || ppc_trace[trace_dump_device_tree])    tree_print(root);  if (ppc_trace[trace_dump_device_tree])    error("");  return system;}/* allow the simulation to stop/restart abnormaly */INLINE_PSIM\(void)psim_set_halt_and_restart(psim *system,			  void *halt_jmp_buf,			  void *restart_jmp_buf){  system->path_to_halt = halt_jmp_buf;  system->path_to_restart = restart_jmp_buf;}INLINE_PSIM\(void)psim_clear_halt_and_restart(psim *system){  system->path_to_halt = NULL;  system->path_to_restart = NULL;}INLINE_PSIM\(void)psim_restart(psim *system,	     int current_cpu){  ASSERT(current_cpu >= 0 && current_cpu < system->nr_cpus);  ASSERT(system->path_to_restart != NULL);  system->last_cpu = current_cpu;  longjmp(*(jmp_buf*)(system->path_to_restart), current_cpu + 1);}static voidcntrl_c_simulation(void *data){  psim *system = data;  psim_halt(system,	    psim_nr_cpus(system),	    was_continuing,	    SIGINT);}INLINE_PSIM\(void)psim_stop(psim *system){  event_queue_schedule_after_signal(psim_event_queue(system),				    0 /*NOW*/,				    cntrl_c_simulation,				    system);}INLINE_PSIM\(void)psim_halt(psim *system,	  int current_cpu,	  stop_reason reason,	  int signal){  ASSERT(current_cpu >= 0 && current_cpu <= system->nr_cpus);  ASSERT(system->path_to_halt != NULL);  system->last_cpu = current_cpu;  system->halt_status.reason = reason;  system->halt_status.signal = signal;  if (current_cpu == system->nr_cpus) {    system->halt_status.cpu_nr = 0;    system->halt_status.program_counter =      cpu_get_program_counter(system->processors[0]);  }  else {    system->halt_status.cpu_nr = current_cpu;    system->halt_status.program_counter =      cpu_get_program_counter(system->processors[current_cpu]);  }  longjmp(*(jmp_buf*)(system->path_to_halt), current_cpu + 1);}INLINE_PSIM\(int)psim_last_cpu(psim *system){  return system->last_cpu;}INLINE_PSIM\(int)psim_nr_cpus(psim *system){  return system->nr_cpus;}INLINE_PSIM\(psim_status)psim_get_status(psim *system){  return system->halt_status;}INLINE_PSIM\(cpu *)psim_cpu(psim *system,	 int cpu_nr){  if (cpu_nr < 0 || cpu_nr >= system->nr_cpus)    return NULL;  else    return system->processors[cpu_nr];}INLINE_PSIM\(device *)psim_device(psim *system,	    const char *path){  return tree_find_device(system->devices, path);}INLINE_PSIM\(event_queue *)psim_event_queue(psim *system){  return system->events;}STATIC_INLINE_PSIM\(void)psim_max_iterations_exceeded(void *data){  psim *system = data;  psim_halt(system,	    system->nr_cpus, /* halted during an event */	    was_signalled,	    -1);}INLINE_PSIM\(void)psim_init(psim *system){  int cpu_nr;  /* scrub the monitor */  mon_init(system->monitor, system->nr_cpus);  /* trash any pending events */  event_queue_init(system->events);  /* if needed, schedule a halt event.  FIXME - In the future this     will be replaced by a more generic change to psim_command().  A     new command `schedule NNN halt' being added. */  if (tree_find_property(system->devices, "/openprom/options/max-iterations")) {    event_queue_schedule(system->events,			 tree_find_integer_property(system->devices,						    "/openprom/options/max-iterations") - 2,			 psim_max_iterations_exceeded,			 system);  }  /* scrub all the cpus */  for (cpu_nr = 0; cpu_nr < system->nr_cpus; cpu_nr++)    cpu_init(system->processors[cpu_nr]);  /* init all the devices (which updates the cpus) */  tree_init(system->devices, system);  /* and the emulation (which needs an initialized device tree) */  os_emul_init(system->os_emulation, system->nr_cpus);  /* now sync each cpu against the initialized state of its registers */  for (cpu_nr = 0; cpu_nr < system->nr_cpus; cpu_nr++) {    cpu *processor = system->processors[cpu_nr];    cpu_synchronize_context(processor, cpu_get_program_counter(processor));    cpu_page_tlb_invalidate_all(processor);  }  /* force loop to start with first cpu */  system->last_cpu = -1;}INLINE_PSIM\(void)psim_stack(psim *system,	   char **argv,	   char **envp){  /* pass the stack device the argv/envp and let it work out what to     do with it */  device *stack_device = tree_find_device(system->devices,					  "/openprom/init/stack");  if (stack_device != (device*)0) {    unsigned_word stack_pointer;    ASSERT (psim_read_register(system, 0, &stack_pointer, "sp",			       cooked_transfer) > 0);    device_ioctl(stack_device,		 NULL, /*cpu*/		 0, /*cia*/		 device_ioctl_create_stack,		 stack_pointer,		 argv,		 envp);  }}/* SIMULATE INSTRUCTIONS, various different ways of achieving the same   thing */INLINE_PSIM\(void)psim_step(psim *system){  volatile int keep_running = 0;  idecode_run_until_stop(system, &keep_running,			 system->events, system->processors, system->nr_cpus);}INLINE_PSIM\(void)psim_run(psim *system){  idecode_run(system,	      system->events, system->processors, system->nr_cpus);}/* storage manipulation functions */INLINE_PSIM\(int)psim_read_register(psim *system,		   int which_cpu,		   void *buf,		   const char reg[],		   transfer_mode mode){  register_descriptions description;  char *cooked_buf;  cpu *processor;  /* find our processor */  if (which_cpu == MAX_NR_PROCESSORS) {    if (system->last_cpu == system->nr_cpus	|| system->last_cpu == -1)      which_cpu = 0;    else      which_cpu = system->last_cpu;  }  ASSERT(which_cpu >= 0 && which_cpu < system->nr_cpus);  processor = system->processors[which_cpu];  /* find the register description */  description = register_description(reg);  if (description.type == reg_invalid)    return 0;  cooked_buf = alloca (description.size);  /* get the cooked value */  switch (description.type) {  case reg_gpr:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -