Exemple #1
0
parse_size(device *current,
	   device *bus,
	   const char *chp,
	   device_unit *size)
{
  int i;
  int nr;
  const char *curr = chp;
  memset(size, 0, sizeof(*size));
  /* parse the numeric list */
  size->nr_cells = device_nr_size_cells(bus);
  nr = 0;
  ASSERT(size->nr_cells > 0);
  while (1) {
    char *next;
    size->cells[nr] = strtoul(curr, &next, 0);
    if (curr == next)
      device_error(current, "Problem parsing <size> %s", chp);
    nr += 1;
    if (next[0] != ',')
      break;
    if (nr == size->nr_cells)
      device_error(current, "Too many values in <size> %s", chp);
    curr = next + 1;
  }
  ASSERT(nr > 0 && nr <= size->nr_cells);
  /* right align the numbers */
  for (i = 1; i <= size->nr_cells; i++) {
    if (i <= nr)
      size->cells[size->nr_cells - i] = size->cells[nr - i];
    else
      size->cells[size->nr_cells - i] = 0;
  }
  return skip_token(chp);
}
Exemple #2
0
static int
hw_disk_ioctl(device *me,
	      cpu *processor,
	      unsigned_word cia,
	      device_ioctl_request request,
	      va_list ap)
{
  switch (request) {
  case device_ioctl_change_media:
    {
      hw_disk_device *disk = device_data(me);
      const char *name = va_arg(ap, const char *);
      if (name != NULL) {
	disk->name_index = -1;
      }
      else {
	disk->name_index = (disk->name_index + 1) % disk->nr_names;
	if (!device_find_string_array_property(me, "file",
					       disk->name_index, &name))
	  device_error(me, "invalid file property");
      }
      open_disk_image(me, disk, name);
    }
    break;
  default:
    device_error(me, "insupported ioctl request");
    break;
  }
  return 0;
}
Exemple #3
0
parse_integer_property(device *current,
		       const char *property_name,
		       const char *property_value)
{
  int nr_entries;
  unsigned_cell words[1024];
  /* integer or integer array? */
  nr_entries = 0;
  while (1) {
    char *end;
    words[nr_entries] = strtoul(property_value, &end, 0);
    if (property_value == end)
      break;
    nr_entries += 1;
    if (nr_entries * sizeof(words[0]) >= sizeof(words))
      device_error(current, "buffer overflow");
    property_value = end;
  }
  if (nr_entries == 0)
    device_error(current, "error parsing integer property %s (%s)",
                 property_name, property_value);
  else if (nr_entries == 1)
    device_add_integer_property(current, property_name, words[0]);
  else {
    int i;
    for (i = 0; i < nr_entries; i++) {
      H2BE(words[i]);
    }
    /* perhaps integer array property is better */
    device_add_array_property(current, property_name, words,
                              sizeof(words[0]) * nr_entries);
  }
}
Exemple #4
0
static void
hw_binary_init_data_callback(device *me)
{
  /* get the file name */
  const char *file_name = device_find_string_property(me, "file-name");
  bfd *image;

  /* open the file */
  image = bfd_openr(file_name, NULL);
  if (image == NULL) {
    bfd_perror("binary");
    device_error(me, "Failed to open file %s\n", file_name);
  }

  /* check it is valid */
  if (!bfd_check_format(image, bfd_object)) {
    bfd_close(image);
    device_error(me, "The file %s has an invalid binary format\n", file_name);
  }

  /* and the data sections */
  bfd_map_over_sections(image,
			update_for_binary_section,
			(PTR)me);

  bfd_close(image);
}
static void
hw_iobus_attach_address_callback(device *me,
				 attach_type type,
				 int space,
				 unsigned_word addr,
				 unsigned nr_bytes,
				 access_type access,
				 device *client) /*callback/default*/
{
  int attach_space;
  unsigned_word attach_address;
  /* sanity check */
  if (space != 0)
    device_error(me, "invalid space (%d) specified by %s",
		 space, device_path(client));
  /* get the bus address */
  device_address_to_attach_address(device_parent(me),
				   device_unit_address(me),
				   &attach_space,
				   &attach_address,
				   me);
  if (addr < attach_address)
    device_error(me, "Invalid attach address 0x%lx", (unsigned long)addr);
  device_attach_address(device_parent(me),
			type,
			attach_space,
			addr,
			nr_bytes,
			access,
			client);
}
Exemple #6
0
Fichier : hw_shm.c Projet : 5kg/gdb
static void
hw_shm_init_data(device *me)
{
  hw_shm_device *shm = (hw_shm_device*)device_data(me);
  const device_unit *d;
  reg_property_spec reg;
  int i;

  /* Obtain the Key Value */
  if (device_find_property(me, "key") == NULL)
    error("shm_init_data() required key property is missing\n");

  shm->key = (key_t) device_find_integer_property(me, "key");
  DTRACE(shm, ("shm key (0x%08x)\n", shm->key) );
  
  /* Figure out where this memory is in address space and how long it is */
  if ( !device_find_reg_array_property(me, "reg", 0, &reg) )
    error("hw_shm_init_data() no address registered\n");

  /* Determine the address and length being as paranoid as possible */
  shm->physical_address = 0xffffffff;
  shm->sizeof_memory = 0xffffffff;

  for ( i=0 ; i<reg.address.nr_cells; i++ ) {
    if (reg.address.cells[0] == 0 && reg.size.cells[0] == 0)
      continue;

    if ( shm->physical_address != 0xffffffff )
      device_error(me, "Only single celled address ranges supported\n");

    shm->physical_address = reg.address.cells[i];
    DTRACE(shm, ("shm physical_address=0x%x\n", shm->physical_address));

    shm->sizeof_memory = reg.size.cells[i];
    DTRACE(shm, ("shm length=0x%x\n", shm->sizeof_memory));
  }

  if ( shm->physical_address == 0xffffffff )
    device_error(me, "Address not specified\n" );

  if ( shm->sizeof_memory == 0xffffffff )
    device_error(me, "Length not specified\n" );

  /* Now actually attach to or create the shared memory area */
  shm->id = shmget(shm->key, shm->sizeof_memory, IPC_CREAT | 0660);
  if (shm->id == -1)
    error("hw_shm_init_data() shmget failed\n");

  shm->shm_address = shmat(shm->id, (char *)0, SHM_RND);
  if (shm->shm_address == (void *)-1)
    error("hw_shm_init_data() shmat failed\n");
}
Exemple #7
0
static void
hw_nvram_init_address(device *me)
{
  hw_nvram_device *nvram = (hw_nvram_device*)device_data(me);
  
  /* use the generic init code to attach this device to its parent bus */
  generic_device_init_address(me);

  /* find the first non zero reg property and use that as the device
     size */
  if (nvram->sizeof_memory == 0) {
    reg_property_spec reg;
    int reg_nr;
    for (reg_nr = 0;
	 device_find_reg_array_property(me, "reg", reg_nr, &reg);
	 reg_nr++) {
      unsigned attach_size;
      if (device_size_to_attach_size(device_parent(me),
				     &reg.size, &attach_size,
				     me)) {
	nvram->sizeof_memory = attach_size;
	break;
      }
    }
    if (nvram->sizeof_memory == 0)
      device_error(me, "reg property must contain a non-zero phys-addr:size tupple");
    if (nvram->sizeof_memory < 8)
      device_error(me, "NVRAM must be at least 8 bytes in size");
  }

  /* initialize the hw_nvram */
  if (nvram->memory == NULL) {
    nvram->memory = zalloc(nvram->sizeof_memory);
  }
  else
    memset(nvram->memory, 0, nvram->sizeof_memory);
  
  if (device_find_property(me, "timezone") == NULL)
    nvram->timezone = 0;
  else
    nvram->timezone = device_find_integer_property(me, "timezone");
  
  nvram->addr_year = nvram->sizeof_memory - 1;
  nvram->addr_month = nvram->sizeof_memory - 2;
  nvram->addr_date = nvram->sizeof_memory - 3;
  nvram->addr_day = nvram->sizeof_memory - 4;
  nvram->addr_hour = nvram->sizeof_memory - 5;
  nvram->addr_minutes = nvram->sizeof_memory - 6;
  nvram->addr_seconds = nvram->sizeof_memory - 7;
  nvram->addr_control = nvram->sizeof_memory - 8;
  
}
Exemple #8
0
Fichier : hw_com.c Projet : 5kg/gdb
static void
hw_com_device_init_data(device *me)
{
  hw_com_device *com = (hw_com_device*)device_data(me);
  /* clean up */
  if (com->output.file != NULL)
    fclose(com->output.file);
  if (com->input.file != NULL)
    fclose(com->input.file);
  memset(com, 0, sizeof(hw_com_device));

  /* the fifo speed */
  com->output.delay = (device_find_property(me, "output-delay") != NULL
		       ? device_find_integer_property(me, "output-delay")
		       : 0);
  com->input.delay = (device_find_property(me, "input-delay") != NULL
		      ? device_find_integer_property(me, "input-delay")
		      : 0);

  /* the data source/sink */
  if (device_find_property(me, "input-file") != NULL) {
    const char *input_file = device_find_string_property(me, "input-file");
    com->input.file = fopen(input_file, "r");
    if (com->input.file == NULL)
      device_error(me, "Problem opening input file %s\n", input_file);
    if (device_find_property(me, "input-buffering") != NULL) {
      const char *buffering = device_find_string_property(me, "input-buffering");
      if (strcmp(buffering, "unbuffered") == 0)
	setbuf(com->input.file, NULL);
    }
  }
  if (device_find_property(me, "output-file") != NULL) {
    const char *output_file = device_find_string_property(me, "output-file");
    com->output.file = fopen(output_file, "w");
    if (com->output.file == NULL)
      device_error(me, "Problem opening output file %s\n", output_file);
    if (device_find_property(me, "output-buffering") != NULL) {
      const char *buffering = device_find_string_property(me, "output-buffering");
      if (strcmp(buffering, "unbuffered") == 0)
	setbuf(com->output.file, NULL);
    }
  }

  /* ready from the start */
  com->input.ready = 1;
  com->modem.carrier = 1;
  com->output.ready = 1;
}
Exemple #9
0
static int
hw_disk_max_transfer(device_instance *instance,
		     int n_stack_args,
		     unsigned32 stack_args[/*n_stack_args*/],
		     int n_stack_returns,
		     unsigned32 stack_returns[/*n_stack_returns*/])
{
  device *me = device_instance_device(instance);
  if ((n_stack_args != 0)
      || (n_stack_returns != 1)) {
    device_error(me, "Incorrect number of arguments for max-transfer method\n");
    return -1;
  }
  else {
    unsigned_cell max_transfer;
    if (device_find_property(me, "max-transfer"))
      max_transfer = device_find_integer_property(me, "max-transfer");
    else
      max_transfer = 512;
    DITRACE(disk, ("max-transfer - instance=%ld max-transfer=%ld\n",
		   (unsigned long)device_instance_to_external(instance),
		   (long int)max_transfer));
    stack_returns[0] = max_transfer;
    return 0;
  }
}
Exemple #10
0
static unsigned
hw_disk_io_write_buffer(device *me,
			const void *source,
			int space,
			unsigned_word addr,
			unsigned nr_bytes,
			cpu *processor,
			unsigned_word cia)
{
  hw_disk_device *disk = device_data(me);
  unsigned nr_bytes_written;
  if (space != 0)
    device_error(me, "write - extended disk addressing unimplemented");
  if (disk->read_only)
    nr_bytes_written = 0;
  else if (nr_bytes == 0)
    nr_bytes_written = 0;
  else if (fseek(disk->image, addr, SEEK_SET) < 0)
    nr_bytes_written = 0;
  else if (fwrite(source, nr_bytes, 1, disk->image) != 1)
    nr_bytes_written = 0;
  else
    nr_bytes_written = nr_bytes;
  DTRACE(disk, ("io-write - address 0x%lx, nr-bytes-written %d, requested %d\n",
                (unsigned long) addr, (int)nr_bytes_written, (int)nr_bytes));
  return nr_bytes_written;
}
Exemple #11
0
static unsigned
hw_disk_io_read_buffer(device *me,
		       void *dest,
		       int space,
		       unsigned_word addr,
		       unsigned nr_bytes,
		       cpu *processor,
		       unsigned_word cia)
{
  hw_disk_device *disk = device_data(me);
  unsigned nr_bytes_read;
  if (space != 0)
    device_error(me, "read - extended disk addressing unimplemented");
  if (nr_bytes == 0)
    nr_bytes_read = 0;
  else if (fseek(disk->image, addr, SEEK_SET) < 0)
    nr_bytes_read = 0;
  else if (fread(dest, nr_bytes, 1, disk->image) != 1)
    nr_bytes_read = 0;
  else
    nr_bytes_read = nr_bytes;
  DTRACE(disk, ("io-read - address 0x%lx, nr-bytes-read %d, requested %d\n",
                (unsigned long) addr, (int)nr_bytes_read, (int)nr_bytes));
  return nr_bytes_read;
}
Exemple #12
0
static void
hw_disk_init_address(device *me)
{
  hw_disk_device *disk = device_data(me);
  unsigned_word address;
  int space;
  const char *name;

  /* attach to the parent. Since the bus is logical, attach using just
     the unit-address (size must be zero) */
  device_address_to_attach_address(device_parent(me), device_unit_address(me),
				   &space, &address, me);
  device_attach_address(device_parent(me), attach_callback,
			space, address, 0/*size*/, access_read_write_exec,
			me);

  /* Tell the world we are a disk.  */
  device_add_string_property(me, "device_type", "block");

  /* get the name of the file specifying the disk image */
  disk->name_index = 0;
  disk->nr_names = device_find_string_array_property(me, "file",
						     disk->name_index, &name);
  if (!disk->nr_names)
    device_error(me, "invalid file property");

  /* is it a RO device? */
  disk->read_only =
    (strcmp(device_name(me), "disk") != 0
     && strcmp(device_name(me), "floppy") != 0
     && device_find_property(me, "read-only") == NULL);

  /* now open it */
  open_disk_image(me, disk, name);
}
static void
decode_address(device *me,
	       address_decoder *decoder,
	       int space,
	       unsigned_word address,
	       int *controller,
	       int *reg,
	       io_direction direction)
{
  int i;
  for (i = 0; i < nr_address_blocks; i++) {
    if (space == decoder->block[i].space
	&& address >= decoder->block[i].base_addr
	&& address <= decoder->block[i].bound_addr) {
      *controller = decoder->block[i].controller;
      *reg = (address
	      - decoder->block[i].base_addr
	      + decoder->block[i].base_reg);
      if (direction == is_write) {
	switch (*reg) {
	case ide_error_reg: *reg = ide_feature_reg; break;
	case ide_status_reg: *reg = ide_command_reg; break;
	case ide_alternate_status_reg: *reg = ide_control_reg; break;
	default: break;
	}
      }
      return;
    }
  }
  device_error(me, "address %d:0x%lx invalid",
	       space, (unsigned long)address);
}
Exemple #14
0
static int
hw_disk_block_size(device_instance *instance,
		   int n_stack_args,
		   unsigned32 stack_args[/*n_stack_args*/],
		   int n_stack_returns,
		   unsigned32 stack_returns[/*n_stack_returns*/])
{
  device *me = device_instance_device(instance);
  if ((n_stack_args != 0)
      || (n_stack_returns != 1)) {
    device_error(me, "Incorrect number of arguments for block-size method\n");
    return -1;
  }
  else {
    unsigned_cell block_size;
    if (device_find_property(me, "block-size"))
      block_size = device_find_integer_property(me, "block-size");
    else
      block_size = 512;
    DITRACE(disk, ("block-size - instance=%ld block-size=%ld\n",
		   (unsigned long)device_instance_to_external(instance),
		   (long int)block_size));
    stack_returns[0] = block_size;
    return 0;
  }
}
Exemple #15
0
static int
hw_disk_nr_blocks(device_instance *instance,
		  int n_stack_args,
		  unsigned32 stack_args[/*n_stack_args*/],
		  int n_stack_returns,
		  unsigned32 stack_returns[/*n_stack_returns*/])
{
  device *me = device_instance_device(instance);
  if ((n_stack_args != 0)
      || (n_stack_returns != 1)) {
    device_error(me, "Incorrect number of arguments for block-size method\n");
    return -1;
  }
  else {
    unsigned_word nr_blocks;
    if (device_find_property(me, "#blocks"))
      nr_blocks = device_find_integer_property(me, "#blocks");
    else
      nr_blocks = -1;
    DITRACE(disk, ("#blocks - instance=%ld #blocks=%ld\n",
		   (unsigned long)device_instance_to_external(instance),
		   (long int)nr_blocks));
    stack_returns[0] = nr_blocks;
    return 0;
  }
}
adv_error device_check(const char* option, const char* arg, const adv_driver** driver_map, unsigned driver_mac, const char* driver_ignore)
{
	char buffer[DEVICE_NAME_MAX];
	const char* tag_one;
	unsigned i, j;

	/* check the validity of every item on the argument */
	sncpy(buffer, sizeof(buffer), arg);
	tag_one = strtok(buffer, " \t");
	while (tag_one) {
		if (strcmp("auto", tag_one)!=0 && strstr(driver_ignore, tag_one)==0) {
			for(i=0;i<driver_mac;++i) {
				if (strcmp(driver_map[i]->name, tag_one)==0)
					break;
				for(j=0;driver_map[i]->device_map[j].name;++j) {
					char cat_buffer[DEVICE_NAME_MAX];
					snprintf(cat_buffer, sizeof(cat_buffer), "%s/%s", driver_map[i]->name, driver_map[i]->device_map[j].name);
					if (strcmp(cat_buffer, tag_one)==0)
						break;
				}
				if (driver_map[i]->device_map[j].name)
					break;
			}
			if (i == driver_mac) {
				device_error(option, tag_one, driver_map, driver_mac);
				return -1;
			}
		}
		tag_one = strtok(NULL, " \t");
	}

	return 0;
}
Exemple #17
0
Fichier : hw_vm.c Projet : 5kg/gdb
static int
hw_vm_ioctl(device *me,
	    cpu *processor,
	    unsigned_word cia,
	    device_ioctl_request request,
	    va_list ap)
{
  /* While the caller is notified that the heap has grown by the
     requested amount, the heap is actually extended out to a page
     boundary. */
  hw_vm_device *vm = (hw_vm_device*)device_data(me);
  switch (request) {
  case device_ioctl_break:
    {
      unsigned_word requested_break = va_arg(ap, unsigned_word);
      unsigned_word new_break = ALIGN_8(requested_break);
      unsigned_word old_break = vm->heap_bound;
      signed_word delta = new_break - old_break;
      if (delta > 0)
	vm->heap_bound = ALIGN_PAGE(new_break);
      break;
    }
  default:
    device_error(me, "Unsupported ioctl request");
    break;
  }
  return 0;
    
}
Exemple #18
0
adv_error mouseb_load(adv_conf* context)
{
	unsigned i;
	int at_least_one;

	if (mouseb_state.driver_mac == 0) {
		error_set("No mouse driver was compiled in.");
		return -1;
	}

	mouseb_state.is_initialized_flag = 1;
	sncpy(mouseb_state.name, DEVICE_NAME_MAX, conf_string_get_default(context, "device_mouse"));

	/* load specific driver options */
	at_least_one = 0;
	for (i = 0; i < mouseb_state.driver_mac; ++i) {
		const adv_device* dev;

		dev = device_match(mouseb_state.name, (adv_driver*)mouseb_state.driver_map[i], 0);

		if (dev)
			at_least_one = 1;

		if (mouseb_state.driver_map[i]->load(context) != 0)
			return -1;
	}

	if (!at_least_one) {
		device_error("device_mouse", mouseb_state.name, (const adv_driver**)mouseb_state.driver_map, mouseb_state.driver_mac);
		return -1;
	}

	return 0;
}
Exemple #19
0
static void
create_ppc_aix_stack_frame(device *me,
			   unsigned_word bottom_of_stack,
			   char **argv,
			   char **envp)
{
  unsigned_word core_envp;
  unsigned_word core_argv;
  unsigned_word core_argc;
  unsigned_word core_aux;
  unsigned_word top_of_stack;

  /* cheat - create an elf stack frame */
  create_ppc_elf_stack_frame(me, bottom_of_stack, argv, envp);
  
  /* extract argument addresses from registers */
  psim_read_register(device_system(me), 0,
		     &top_of_stack, "r1", cooked_transfer);
  psim_read_register(device_system(me), 0,
		     &core_argc, "r3", cooked_transfer);
  psim_read_register(device_system(me), 0,
		     &core_argv, "r4", cooked_transfer);
  psim_read_register(device_system(me), 0,
		     &core_envp, "r5", cooked_transfer);
  psim_read_register(device_system(me), 0,
		     &core_aux, "r6", cooked_transfer);

  /* extract arguments from registers */
  device_error(me, "Unfinished procedure create_ppc_aix_stack_frame\n");
}
Exemple #20
0
tree_find_string_property(device *root,
			  const char *path_to_property)
{
  name_specifier spec;
  if (!split_property_specifier(root, path_to_property, &spec))
    device_error(root, "Invalid property path %s", path_to_property);
  root = split_find_device(root, &spec);
  return device_find_string_property(root, spec.property);
}
Exemple #21
0
static void
hw_data_init_data_callback(device *me)
{
  unsigned_word addr = device_find_integer_property(me, "real-address");
  const device_property *data = device_find_property(me, "data");
  const char *instance_spec = (device_find_property(me, "instance") != NULL
			       ? device_find_string_property(me, "instance")
			       : NULL);
  device_instance *instance = NULL;
  if (data == NULL)
    device_error(me, "missing property <data>\n");
  if (instance_spec != NULL)
    instance = tree_instance(me, instance_spec);
  switch (data->type) {
  case integer_property:
    {
      unsigned_cell buf = device_find_integer_property(me, "data");
      H2T(buf);
      if (instance == NULL) {
	if (device_dma_write_buffer(device_parent(me),
				    &buf,
				    0 /*address-space*/,
				    addr,
				    sizeof(buf), /*nr-bytes*/
				    1 /*violate ro*/) != sizeof(buf))
	  device_error(me, "Problem storing integer 0x%x at 0x%lx\n",
		       (unsigned)buf, (unsigned long)addr);
      }
      else {
	if (device_instance_seek(instance, 0, addr) < 0
	    || device_instance_write(instance, &buf, sizeof(buf)) != sizeof(buf))
	  device_error(me, "Problem storing integer 0x%x at 0x%lx of instance %s\n",
		       (unsigned)buf, (unsigned long)addr, instance_spec);
      }
    }
    break;
  default:
    device_error(me, "Write of this data is not yet implemented\n");
    break;
  }
  if (instance != NULL)
    device_instance_delete(instance);
}
Exemple #22
0
parse_address(device *current,
	      device *bus,
	      const char *chp,
	      device_unit *address)
{
  ASSERT(device_nr_address_cells(bus) > 0);
  if (device_decode_unit(bus, chp, address) < 0)
    device_error(current, "invalid unit address in %s", chp);
  return skip_token(chp);
}
Exemple #23
0
Pillow::HttpClient::HttpClient(QObject *parent)
	: QObject(parent), _responsePending(false), _error(NoError), _keepAliveTimeout(-1), _contentDecoder(0)
{
	_device = new QTcpSocket(this);
	connect(_device, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(device_error(QAbstractSocket::SocketError)));
	connect(_device, SIGNAL(connected()), this, SLOT(device_connected()));
	connect(_device, SIGNAL(readyRead()), this, SLOT(device_readyRead()));
	_requestWriter.setDevice(_device);
	_keepAliveTimeoutTimer.invalidate();
}
Exemple #24
0
static void
hw_file_init_data_callback(device *me)
{
  int count;
  const char *file_name = device_find_string_property(me, "file-name");
  unsigned_word addr = device_find_integer_property(me, "real-address");
  /* load the file */
  count = dma_file(me, file_name, addr);
  if (count < 0)
    device_error(me, "Problem loading file %s\n", file_name);
}
static void
schedule_ready_event(device *me,
		     ide_controller *controller)
{
  if (controller->event_tag != 0)
    device_error(me, "controller %d - attempting to schedule multiple events",
		 controller->nr);
  controller->event_tag = 
    device_event_queue_schedule(me, controller->ready_delay,
				do_event, controller);
}
static void
do_fifo_write(device *me,
	      ide_controller *controller,
	      const void *source,
	      int nr_bytes)
{
  if (controller->state != loading_state)
    device_error(me, "controller %d - writing fifo when not ready (%s)",
		 controller->nr,
		 ide_state_name(controller->state));
  if (controller->fifo_pos + nr_bytes > controller->fifo_size)
    device_error(me, "controller %d - fifo overflow", controller->nr);
  if (nr_bytes > 0) {
    memcpy(&controller->fifo[controller->fifo_pos], source, nr_bytes);
    controller->fifo_pos += nr_bytes;
  }
  if (controller->fifo_pos == controller->fifo_size) {
    if (controller->current_transfer > 0
	&& controller->current_drive != NULL) {
      DTRACE(ide, ("controller %d:%d - writing %d byte block at 0x%x\n",
		   controller->nr,
		   controller->current_drive->nr,
		   controller->fifo_size,
		   controller->current_byte));
      if (device_io_write_buffer(controller->current_drive->device,
				 controller->fifo,
				 0, controller->current_byte,
				 controller->fifo_size,
				 NULL, 0)
	  != controller->fifo_size)
	device_error(me, "controller %d - disk %s io write error",
		     controller->nr,
		     device_path(controller->current_drive->device));
    }
    controller->current_transfer -= 1;
    controller->fifo_pos = 0;
    controller->current_byte += controller->fifo_size;
    controller->state = busy_loaded_state;
    schedule_ready_event(me, controller);
  }
}
Exemple #27
0
static int
hw_eeprom_instance_seek(device_instance *instance,
		      unsigned_word pos_hi,
		      unsigned_word pos_lo)
{
  hw_eeprom_instance *data = device_instance_data(instance);
  if (pos_lo >= data->eeprom->sizeof_memory)
    device_error(data->me, "seek value 0x%lx out of range\n",
		 (unsigned long)pos_lo);
  data->pos = pos_lo;
  return 0;
}
Exemple #28
0
static int
hw_stack_ioctl(device *me,
	       cpu *processor,
	       unsigned_word cia,
	       device_ioctl_request request,
	       va_list ap)
{
  switch (request) {
  case device_ioctl_create_stack:
    {
      unsigned_word stack_pointer = va_arg(ap, unsigned_word);
      char **argv = va_arg(ap, char **);
      char **envp = va_arg(ap, char **);
      const char *stack_type;
      DTRACE(stack,
	     ("stack_ioctl_callback(me=0x%lx:%s processor=0x%lx cia=0x%lx argv=0x%lx envp=0x%lx)\n",
	      (long)me, device_name(me),
	      (long)processor,
	      (long)cia,
	      (long)argv,
	      (long)envp));
      stack_type = device_find_string_property(me, "stack-type");
      if (strcmp(stack_type, "ppc-elf") == 0)
	create_ppc_elf_stack_frame(me, stack_pointer, argv, envp);
      else if (strcmp(stack_type, "ppc-xcoff") == 0)
	create_ppc_aix_stack_frame(me, stack_pointer, argv, envp);
      else if (strcmp(stack_type, "chirp") == 0)
	create_ppc_chirp_bootargs(me, argv);
      else if (strcmp(stack_type, "none") != 0)
	device_error(me, "Unknown initial stack frame type %s", stack_type);
      DTRACE(stack, 
	     ("stack_ioctl_callback() = void\n"));
      break;
    }
  default:
    device_error(me, "Unsupported ioctl requested");
    break;
  }
  return 0;
}
Exemple #29
0
static void
write_stack_arguments(device *me,
		      char **arg,
		      unsigned_word start_block,
		      unsigned_word end_block,
		      unsigned_word start_arg,
		      unsigned_word end_arg)
{
  DTRACE(stack,
	("write_stack_arguments(device=%s, arg=0x%lx, start_block=0x%lx, end_block=0x%lx, start_arg=0x%lx, end_arg=0x%lx)\n",
	 device_name(me), (long)arg, (long)start_block, (long)end_block, (long)start_arg, (long)end_arg));
  if (arg == NULL)
    device_error(me, "Attempt to write a null array onto the stack\n");
  /* only copy in arguments, memory is already zero */
  for (; *arg != NULL; arg++) {
    int len = strlen(*arg)+1;
    unsigned_word target_start_block;
    DTRACE(stack,
	  ("write_stack_arguments() write %s=%s at %s=0x%lx %s=0x%lx %s=0x%lx\n",
	   "**arg", *arg, "start_block", (long)start_block,
	   "len", (long)len, "start_arg", (long)start_arg));
    if (psim_write_memory(device_system(me), 0, *arg,
			  start_block, len,
			  0/*violate_readonly*/) != len)
      device_error(me, "Write of **arg (%s) at 0x%lx of stack failed\n",
		   *arg, (unsigned long)start_block);
    target_start_block = H2T_word(start_block);
    if (psim_write_memory(device_system(me), 0, &target_start_block,
			  start_arg, sizeof(target_start_block),
			  0) != sizeof(target_start_block))
      device_error(me, "Write of *arg onto stack failed\n");
    start_block += ALIGN_8(len);
    start_arg += sizeof(start_block);
  }
  start_arg += sizeof(start_block); /*the null at the end*/
  if (start_block != end_block
      || ALIGN_8(start_arg) != end_arg)
    device_error(me, "Probable corrpution of stack arguments\n");
  DTRACE(stack, ("write_stack_arguments() = void\n"));
}
static unsigned
hw_ide_io_write_buffer(device *me,
		       const void *source,
		       int space,
		       unsigned_word addr,
		       unsigned nr_bytes,
		       cpu *processor,
		       unsigned_word cia)
{
  hw_ide_device *ide = (hw_ide_device *)device_data(me);
  int control_nr;
  int reg;
  ide_controller *controller;

  /* find the interface */
  decode_address(me, &ide->decoder, space, addr, &control_nr, &reg, is_write);
  controller = &ide->controller[control_nr];

  /* process the access */
  switch (reg) {
  case ide_data_reg:
    do_fifo_write(me, controller, source, nr_bytes);
    break;
  case ide_command_reg:
    do_command(me, controller, *(unsigned8*)source);
    break;
  case ide_control_reg:
    controller->reg[reg] = *(unsigned8*)source;
    /* possibly cancel interrupts */
    if ((controller->reg[reg] & 0x02) == 0x02)
      clear_interrupt(me, controller);
    break;
  case ide_feature_reg:
  case ide_sector_count_reg:
  case ide_sector_number_reg:
  case ide_cylinder_reg0:
  case ide_cylinder_reg1:
  case ide_drive_head_reg:
  case ide_dma_command_reg:
  case ide_dma_status_reg:
  case ide_dma_prd_table_address_reg0:
  case ide_dma_prd_table_address_reg1:
  case ide_dma_prd_table_address_reg2:
  case ide_dma_prd_table_address_reg3:
    controller->reg[reg] = *(unsigned8*)source;
    break;
  default:
    device_error(me, "bus-error at 0x%lx", addr);
    break;
  }
  return nr_bytes;
}