void gobkwd(void *par)
{
  running = 1;
  drive_goto(-256, -256);
  running = 0;
  cogstop(cogid());
}
void gofwd(void *par)
{
  running = 1;
  drive_goto(256, 256);
  running = 0;
  cogstop(cogid());
}
Ejemplo n.º 3
0
int cog_endStackTest(int *coginfo)
{
  int cog = *coginfo - 1;
  int *addr = coginfo; 
  int stacksize = 0;

  //print("\n\n---[ cog_end ]---\n\n");
  //print("Cog Address = %d, Cog Value = %d\n", (int) addr, *addr);
  //print("Stack Count Address = %d, Stack Count = %d\n\n", (int) (addr+1), *(addr+1));

  int stackInts = *(addr+1);

  int stackOverhead = sizeof(_thread_state_t) + (3 * sizeof(unsigned int));
  //print("stackOverhead = %d bytes, %d ints\n", stackOverhead, stackOverhead/sizeof(int));
  int cogRunTestOverhead = 2 * sizeof(int);
  //print("cogRunTestOverhead = %d bytes, %d ints\n", cogRunTestOverhead, cogRunTestOverhead/sizeof(int));
  int stackOther = stackInts - (stackOverhead/sizeof(int)) - (cogRunTestOverhead/sizeof(int));  
  //print("stackOther = %d ints\n\n", stackOther);
  
  srand(stackOther);
  //srand(0);

  int n = -2;
  for(int *i = addr; i < (addr + (stackInts)); i++)
  {
    //print("idx = %d, addr = %d, val = %d\n", (int)(i-addr-2), (int) i, *i);
    if((n >= 0) && (stacksize == 0))
    {
      //if(*i != n)
      if(*i != rand())
      {
        stacksize = stackOther - n;
      }         
    }    
    n++;  
  }    
  
  //print("stacksize = %d ints\n", stacksize);

  if(cog > -1)
  {
    if(cog == cogid())
    {
      free(coginfo); 
      cogstop(cog);
    }
    else
    {
      cogstop(cog);
      free(coginfo); 
    }    
  }    
  *coginfo = 0;

  if(stacksize < 0) stacksize = 0;
  return stacksize; 
}
Ejemplo n.º 4
0
void cog_end(int *coginfo)
{
  int cog = *coginfo - 1;
  if(cog > -1)
  {
    if(cog == cogid())
    {
      free(coginfo); 
      cogstop(cog);
    }
    else
    {
      cogstop(cog);
      free(coginfo); 
    }    
  }    
  *coginfo = 0;
}
Ejemplo n.º 5
0
int main(void)
{
    uint8_t *buffer = (uint8_t *)(((uint32_t)padded_buffer + 15) & ~15);
    SdLoaderInfo *info = (SdLoaderInfo *)_load_start_coguser0;
    uint32_t load_address, index_width, offset_width, addr, count;
    uint32_t tags_size, cache_size, cache_lines, cache_tags, mboxes, *sp;
    VolumeInfo vinfo;
    FileInfo finfo;
    PexeFileHdr *hdr;
    int sd_id, i;
    uint8_t *p;

    // determine the cache size and setup cache variables
    index_width = info->cache_geometry >> 8;
    offset_width = info->cache_geometry & 0xff;
    tags_size = (1 << index_width) * 4;
    cache_size = 1 << (index_width + offset_width);
    cache_lines = HUB_SIZE - cache_size;
    cache_tags = cache_lines - tags_size;
    mboxes = cache_tags - sizeof(xmem_mbox_t) * 8 - 4;
    xmem_mbox = (xmem_mbox_t *)mboxes;

    // load the external memory driver
    DPRINTF("Loading external memory driver\n");
    memset((void *)mboxes, 0, sizeof(xmem_mbox_t) * 8 + 4);
    xmem_mbox[8].hubaddr = XMEM_END;
    cognew(_load_start_coguser1, mboxes);
    
    DPRINTF("Loading SD driver\n");
    sd_mbox = (uint32_t *)mboxes - 2;
    sd_mbox[0] = 0xffffffff;
    if ((sd_id = cognew(_load_start_coguser2, sd_mbox)) < 0) {
        DPRINTF("Error loading SD driver\n");
        return 1;
    }
    while (sd_mbox[0])
        ;

    DPRINTF("Initializing SD card\n");
    if (SD_Init(sd_mbox, 5) != 0) {
        DPRINTF("SD card initialization failed\n");
        return 1;
    }
	
    DPRINTF("Mounting filesystem\n");
    if (MountFS(buffer, &vinfo) != 0) {
        DPRINTF("MountFS failed\n");
        return 1;
    }
    
    // open the .pex file
    DPRINTF("Opening 'autorun.pex'\n");
    if (FindFile(buffer, &vinfo, FILENAME, &finfo) != 0) {
        DPRINTF("FindFile '%s' failed\n", FILENAME);
        return 1;
    }

	// read the file header
	DPRINTF("Reading PEX file header\n");
	if (GetNextFileSector(&finfo, kernel_image, &count) != 0 || count < PEXE_HDR_SIZE) {
	    DPRINTF("Error reading PEX file header\n");
		return 1;
	}
		
	// verify the header
    DPRINTF("Verifying PEX file header\n");
    hdr = (PexeFileHdr *)kernel_image;
    if (strncmp(hdr->tag, PEXE_TAG, sizeof(hdr->tag)) != 0 || hdr->version != PEXE_VERSION) {
        DPRINTF("Bad PEX file header\n");
        return 1;
    }
	load_address = hdr->loadAddress;
	
	// move past the header
	memmove(kernel_image, (uint8_t *)kernel_image + PEXE_HDR_SIZE, SECTOR_SIZE - PEXE_HDR_SIZE);
	p = (uint8_t *)kernel_image + SECTOR_SIZE - PEXE_HDR_SIZE;
	
    // read the .kernel cog image
    DPRINTF("Reading kernel image\n");
    for (i = 1; i < 4; ++i) {
    	if (GetNextFileSector(&finfo, p, &count) != 0 || count < SECTOR_SIZE)
    		return 1;
        p += SECTOR_SIZE;
    }
    
    // load the image
    DPRINTF("Loading image at 0x%08x\n", load_address);
    addr = load_address;
    while (GetNextFileSector(&finfo, buffer, &count) == 0) {
        write_block(addr, buffer, XMEM_SIZE_512);
        addr += SECTOR_SIZE;
    }

    // stop the sd driver
    DPRINTF("Stopping SD driver\n");
    cogstop(sd_id);
    
    // setup the stack
    // at start stack contains xmem_mbox, cache_tags, cache_lines, cache_geometry, pc
    sp = (uint32_t *)mboxes;
    *--sp = load_address;
    *--sp = info->cache_geometry;
    *--sp = cache_lines;
    *--sp = cache_tags;
    *--sp = mboxes;

    // start the xmm kernel boot code
    DPRINTF("Starting kernel\n");
    coginit(cogid(), kernel_image, sp);

    // should never reach this
    return 0;
}