コード例 #1
0
ファイル: alloc.c プロジェクト: AKuHAK2/ps2sdk
int _start(int argc, char **argv)
{
    iop_sema_t sem_info;

    if (RegisterLibraryEntries(&_exp_alloc) != 0)
	return 1;

    // check arguments for a heap_size parameter.
    if (argc > 1) {
	heap_size = strtoul(argv[1], NULL, 0);
    }

    if (!(heap_start = AllocSysMemory(ALLOC_FIRST, heap_size, NULL)))
	return -1;
    heap_end = heap_start + heap_size;
    _heap_ptr = heap_start;

    sem_info.attr = 1;
    sem_info.option = 1;
    sem_info.initial = 1;
    sem_info.max = 1;

    alloc_sema = CreateSema(&sem_info);

    return 0;
}
コード例 #2
0
ファイル: fileXio_iop.c プロジェクト: AKuHAK2/ps2sdk
void fileXio_Thread(void* param)
{
	int OldState;

	printf("fileXio: fileXio RPC Server v1.00\nCopyright (c) 2003 adresd\n");
	#ifdef DEBUG
		printf("fileXio: RPC Initialize\n");
	#endif

	SifInitRpc(0);

	RWBufferSize=DEFAULT_RWSIZE;
	CpuSuspendIntr(&OldState);
	rwbuf = AllocSysMemory(ALLOC_FIRST, RWBufferSize, NULL);
	CpuResumeIntr(OldState);
	if (rwbuf == NULL)
	{
		#ifdef DEBUG
  			printf("Failed to allocate memory for RW buffer!\n");
		#endif

		SleepThread();
	}

	SifSetRpcQueue(&qd, GetThreadId());
	SifRegisterRpc(&sd0, FILEXIO_IRX, &fileXio_rpc_server, fileXio_rpc_buffer, NULL, NULL, &qd);
	SifRpcLoop(&qd);
}
コード例 #3
0
ファイル: devfs.c プロジェクト: AKuHAK2/ps2sdk
/** Creates a new device based on the node data supplied

    @param node: Pointer to a ::devfs_node_t structure

    @returns A new device structure or NULL on error.
*/
devfs_device_t *devfs_create_device(const devfs_node_t *node)

{
   devfs_device_t *dev;

   if((node == NULL) || (node->name == NULL))
   {
      return NULL;
   }

   dev = AllocSysMemory(ALLOC_FIRST, sizeof(devfs_device_t), NULL);
   if(dev == NULL)
   {
      printf("create_device: Alloc Failed\n");
      return NULL;
   }

   memset(dev, 0, sizeof(devfs_device_t));
   memcpy(&dev->node, node, sizeof(devfs_node_t));
   if(dev->node.name != NULL)
   {
      dev->node.name = AllocSysMemory(ALLOC_FIRST, strlen(node->name) + 1, NULL);
      if(dev->node.name == NULL)
      {
         FreeSysMemory(dev);
         return NULL;
      }
      memcpy(dev->node.name, node->name, strlen(node->name) + 1);
   }

   if(dev->node.desc != NULL)
   {
      dev->node.desc = AllocSysMemory(ALLOC_FIRST, strlen(node->desc) + 1, NULL);
      if(dev->node.name == NULL)
      {
         FreeSysMemory(dev->node.name);
         FreeSysMemory(dev);
         return NULL;
      }
      memcpy(dev->node.desc, node->desc, strlen(node->desc) + 1);
   }

   return dev;
}
コード例 #4
0
ファイル: sbp2_driver.c プロジェクト: scuriumk/ps2sdk
void *malloc(unsigned int NumBytes){
	int OldState;
	void *buffer;

	CpuSuspendIntr(&OldState);
	buffer=AllocSysMemory(ALLOC_FIRST, NumBytes, NULL);
	CpuResumeIntr(OldState);

	return buffer;
}
コード例 #5
0
ファイル: iLink_internal.c プロジェクト: AKuHAK/ps2sdk
void *malloc(unsigned int nBytes){
	int OldState;
	void *result;

	CpuSuspendIntr(&OldState);
	result=AllocSysMemory(ALLOC_FIRST, nBytes, NULL);
	CpuResumeIntr(OldState);

	return result;
}
コード例 #6
0
ファイル: usbhdfsd.c プロジェクト: AKuHAK2/ps2sdk
void *malloc(int size){
	void *result;
	int OldState;

	CpuSuspendIntr(&OldState);
	result = AllocSysMemory(ALLOC_FIRST, size, NULL);
	CpuResumeIntr(OldState);

	return result;
}
コード例 #7
0
ファイル: sys_arch.c プロジェクト: AKuHAK2/ps2sdk
void *malloc(unsigned int size){
	int flags;
	void *ptr;

	CpuSuspendIntr(&flags);
	ptr=AllocSysMemory(ALLOC_LAST, size, NULL);
	CpuResumeIntr(flags);

	return ptr;
}
コード例 #8
0
ファイル: misc.c プロジェクト: israfilistek/ps2sdk
void *apaAllocMem(int size)
{
	int intrStat;
	void *mem;

	CpuSuspendIntr(&intrStat);
	mem = AllocSysMemory(ALLOC_FIRST, size, NULL);
	CpuResumeIntr(intrStat);

	return mem;
}
コード例 #9
0
ファイル: misc.c プロジェクト: JoseEduardo/ps2sdk
void *allocMem(int size)
{
    int intrStat;
    void *mem;

    CpuDisableIntr(&intrStat);
    mem = AllocSysMemory(ALLOC_FIRST, size, NULL);
    CpuEnableIntr(intrStat);

    return mem;
}
コード例 #10
0
//-------------------------------------------------------------------------
void init_thread(void *args)
{
	if (!sceSifCheckInit())
		sceSifInit();

	sceSifInitRpc(0);

	cdvdfsv_buf = AllocSysMemory(ALLOC_FIRST, (CDVDFSV_BUF_SECTORS << 11)+2048, NULL);
	if (!cdvdfsv_buf)
		SleepThread();

	cdvdfsv_startrpcthreads();
}
コード例 #11
0
ファイル: ata.c プロジェクト: joshdekock/jim-ps2ware
int ata_engine_init(struct eng_args *args)
{
	iop_thread_t thread;
	int thid;

	/* DMA read thread.  */
	thread.attr = TH_C;
	thread.thread = read_thread;
	thread.stacksize = 4096;
	thread.priority = 21;
	if ((read_thid = CreateThread(&thread)) < 0)
		return read_thid;

	StartThread(read_thid, args);

	/* DMA write thread.  */
	thread.attr = TH_C;
	thread.thread = write_thread;
	thread.stacksize = 4096;
	thread.priority = 21;
	if ((write_thid = CreateThread(&thread)) < 0)
		return write_thid;

	StartThread(write_thid, args);

	/* RPC thread.  */
	thread.attr = TH_C;
	thread.thread = rpc_thread;
	thread.stacksize = 4096;
	thread.priority = 20;
	if ((thid = CreateThread(&thread)) < 0)
		return thid;

	StartThread(thid, NULL);

	/* RPC end thread.  */
	thread.attr = TH_C;
	thread.thread = rpc_end_thread;
	thread.stacksize = 1024;
	thread.priority = 20;
	if ((thid = CreateThread(&thread)) < 0)
		return thid;

	StartThread(thid, NULL);

	if (!(dma_buffer = AllocSysMemory(0, ATA_BUFFER_SIZE, NULL)))
		return -12;

	return 0;
}
コード例 #12
0
ファイル: sys_arch.c プロジェクト: AKuHAK/ps2sdk
void *calloc(size_t n, size_t size)
{
	int flags;
	void *ptr;

	CpuSuspendIntr(&flags);
	ptr=AllocSysMemory(ALLOC_LAST, n * size, NULL);
	CpuResumeIntr(flags);

	if(ptr != NULL)
		memset(ptr, 0, n * size);

	return ptr;
}
コード例 #13
0
ファイル: fileXio_iop.c プロジェクト: AKuHAK2/ps2sdk
void* filexioRpc_SetRWBufferSize(void *sbuff)
{
	int OldState;

	if(rwbuf!=NULL){
		CpuSuspendIntr(&OldState);
		FreeSysMemory(rwbuf);
		CpuResumeIntr(OldState);
	}

	RWBufferSize=((struct fxio_rwbuff*)sbuff)->size;
	CpuSuspendIntr(&OldState);
	rwbuf=AllocSysMemory(ALLOC_FIRST, RWBufferSize, NULL);
	CpuResumeIntr(OldState);

	((int*)sbuff)[0] = rwbuf!=NULL?0:-ENOMEM;
	return sbuff;
}
コード例 #14
0
ファイル: ps2cam.c プロジェクト: rickgaiser/ps2sdk
/** called after a camera is accepted */
void PS2CamInitializeNewDevice(CAMERA_DEVICE *cam)
{
	unsigned char			*temp_str;
	UsbDeviceDescriptor		*d;


	PS2CamSetDeviceConfiguration(cam,1);

	camStopStream(cam);
	PS2CamSelectInterface(cam,0,0);
	camStartStream(cam);

	PS2CamSetDeviceDefaults(cam);

/*	camStopStream(dev);
	setReg16(dev, 0x30, 384);
	camStartStream(dev);
*/
	camStopStream(cam);
	PS2CamSelectInterface(cam,0,EYETOY_ALTERNATE_SIZE_384);
	camStartStream(cam);

	cam->status = CAM_STATUS_CONNECTEDREADY;



	// connected message (alloc som mem and get device string then print it and free the mem we alloced)
	d   = UsbGetDeviceStaticDescriptor(cam->device_id, NULL, USB_DT_DEVICE);
	temp_str = AllocSysMemory(0, 128, 0);
	temp_str[0]=0x00;
	PS2CamGetDeviceSring(cam, d->iProduct,      (char *)temp_str, 128);
	printf("cam initialized(%s)\n",temp_str);
	FreeSysMemory(temp_str);



	DeleteThread(maintain_thread);

	return;

}
コード例 #15
0
ファイル: ps2kbd.c プロジェクト: EvertonSilva/ps2sdk
void usb_getstring(int endp, int index, char *desc)

{
  u8 *data;
  string_descriptor *str;
  int ret; 

  data = (u8 *) AllocSysMemory(0, sizeof(string_descriptor), NULL);
  str = (string_descriptor *) data;

  if(data != NULL)
    {
      str->desc = desc;
      ret = UsbControlTransfer(endp, 0x80, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) | index, 
			       0, sizeof(string_descriptor) - 4, data, ps2kbd_getstring_set, data);
      if(ret != USB_RC_OK)
	{
	  printf("PS2KBD: Error sending string descriptor request\n");
	  FreeSysMemory(data);
	}
    }
}
コード例 #16
0
ファイル: ps2kbd.c プロジェクト: EvertonSilva/ps2sdk
int ps2kbd_connect(int devId)

{
  /* Assume we can only get here if we have already checked the device is kosher */

  UsbDeviceDescriptor *dev;
  UsbConfigDescriptor *conf;
  UsbInterfaceDescriptor *intf;
  UsbEndpointDescriptor *endp;
  kbd_dev *currDev;
  int devLoop;

  //printf("PS2Kbd_connect devId %d\n", devId);

  dev = UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); /* Get device descriptor */
  if(!dev) 
    {
      printf("ERROR: Couldn't get device descriptor\n");
      return 1;
    }

  conf = UsbGetDeviceStaticDescriptor(devId, dev, USB_DT_CONFIG);
  if(!conf)
    {
      printf("ERROR: Couldn't get configuration descriptor\n");
      return 1;
    }
     
  intf = (UsbInterfaceDescriptor *) ((char *) conf + conf->bLength); /* Get first interface */
  endp = (UsbEndpointDescriptor *) ((char *) intf + intf->bLength);
  endp = (UsbEndpointDescriptor *) ((char *) endp + endp->bLength); /* Go to the data endpoint */

  for(devLoop = 0; devLoop < PS2KBD_MAXDEV; devLoop++)
    {
      if(devices[devLoop] == NULL)
	{
	  break;
	}
    }

  if(devLoop == PS2KBD_MAXDEV)
    {
      /* How the f*** did we end up here ??? */
      printf("ERROR: Device Weirdness!!\n");
      return 1;
    }

  currDev = (kbd_dev *) AllocSysMemory(0, sizeof(kbd_dev), NULL);
  if(!currDev)
    {
      printf("ERROR: Couldn't allocate a device point for the kbd\n");
      return 1;
    }

  devices[devLoop] = currDev;
  memset(currDev, 0, sizeof(kbd_dev));
  currDev->configEndp = UsbOpenEndpoint(devId, NULL);
  currDev->dataEndp = UsbOpenEndpoint(devId, endp);
  currDev->packetSize = endp->wMaxPacketSizeLB | ((int) endp->wMaxPacketSizeHB << 8);
  currDev->eventmask = (1 << devLoop);
  if(currDev->packetSize > sizeof(kbd_data_recv))
    {
      currDev->packetSize = sizeof(kbd_data_recv);
    }

  if(dev->iManufacturer != 0)
    {
      usb_getstring(currDev->configEndp, dev->iManufacturer, "Keyboard Manufacturer");
    }

  if(dev->iProduct != 0)
    {
      usb_getstring(currDev->configEndp, dev->iProduct, "Keyboard Product");
    }

  currDev->devId = devId;
  currDev->interfaceNo = intf->bInterfaceNumber;
  currDev->ledStatus = 0;

  UsbSetDevicePrivateData(devId, currDev); /* Set the index for the device data */

  //printf("Configuration value %d\n", conf->bConfigurationValue);
  UsbSetDeviceConfiguration(currDev->configEndp, conf->bConfigurationValue, ps2kbd_config_set, currDev);

  dev_count++; /* Increment device count */
  printf("PS2KBD: Connected device\n");

  return 0;
}
コード例 #17
0
ファイル: devfs.c プロジェクト: AKuHAK2/ps2sdk
int devfs_open(iop_file_t *file, const char *name, int mode, int unused)
#endif
{
   devfs_device_t *dev;
   int loop;
   int fn_offset = 0;

   //printf("devfs_open file=%p name=%s mode=%d\n", file, name, mode);
   if(name == NULL)
   {
      M_PRINTF("open: Name is NULL\n");
      return -1;
   }

   if((name[0] == '\\') || (name[0] == '/'))
   {
      fn_offset = 1;
   }

   dev = devfs_find_devicename(name + fn_offset);

   if(dev != NULL)
   {
      char *endp;
      int subdev;
      int name_len;

      name_len = strlen(dev->node.name);

      if(name_len == strlen(name)) /* If this is has not got a subnumber */
      {
        M_PRINTF("open: No subdevice number in filename %s\n", name);
        return -1;
      }

      subdev = strtoul(&name[name_len + fn_offset], &endp, 10);
      if(((subdev == 0) && (name[name_len + fn_offset] != '0'))
        || (subdev >= DEVFS_MAX_SUBDEVS))
         /* Invalid number */
      {
         M_PRINTF("open: Invalid subdev number %d\n", subdev);
         return -1;
      }

      if(*endp)
      /* Extra charactes after filename */
      {
         M_PRINTF("open: Invalid filename\n");
         return -1;
      }

      if(!dev->subdevs[subdev].valid)
      /* No subdev */
      {
        M_PRINTF("open: No subdev registered\n");
        return -1;
      }

      if((dev->subdevs[subdev].mode & DEVFS_MODE_EX)
        && (dev->subdevs[subdev].open_refcount > 0))
      /* Already opened in exclusive mode */
      {
         M_PRINTF("open: Exclusive subdevice already opened\n");
         return -1;
      }

      if(dev->subdevs[subdev].open_refcount == MAX_OPENFILES)
      {
         M_PRINTF("open: Reached open file limit for sub device\n");
      }

      /* Tried to open read but not allowed */
      if(((mode & O_RDONLY) || ((mode & O_RDWR) == O_RDWR))
        && !(dev->subdevs[subdev].mode & DEVFS_MODE_R))
      {
         M_PRINTF("open: Read mode requested but not permitted\n");
         return -1;
      }

      if(((mode & O_WRONLY) || ((mode & O_RDWR) == O_RDWR))
        && !(dev->subdevs[subdev].mode & DEVFS_MODE_W))
      {
         M_PRINTF("open: Write mode requested but not permitted\n");
         return -1;
      }

      file->privdata = AllocSysMemory(ALLOC_FIRST, sizeof(ioman_data_t), NULL);
      if(file->privdata == NULL)
      {
         M_PRINTF("open: Allocation failure\n");
         return -1;
      }

      ((ioman_data_t *) file->privdata)->hDev = dev->hDev;
      ((ioman_data_t *) file->privdata)->subdev = subdev;
      ((ioman_data_t *) file->privdata)->loc.loc64 = 0;
      ((ioman_data_t *) file->privdata)->dev = dev;
      ((ioman_data_t *) file->privdata)->mode = mode;

      dev->subdevs[subdev].open_refcount++;
      loop = 0;
      while((loop < MAX_OPENFILES) && (dev->subdevs[subdev].open_files[loop]))
      {
          loop++;
      }
      if(loop == MAX_OPENFILES)
      {
         FreeSysMemory(file->privdata);
         M_PRINTF("open: Inconsistency between number of open files and available slot\n");
         return -1;
      }

      dev->subdevs[subdev].open_files[loop] = file->privdata;
      dev->open_refcount++;
      M_PRINTF("open: Opened device %s subdev %d\n", dev->node.name, subdev);
   }
   else
   {
      M_PRINTF("open: Couldn't find the device\n");
      return -1;
   }

   return 0;
}