Exemple #1
0
int pread_bin_int(int fd, off_t pos, char **ret_ptr)
{
   char *bufptr, *bufptr_rest;
   char prefix;
   int buf_len;
   uint32_t chunk_len;
   int skip = 0;
   buf_len = raw_read(fd, &pos, 2*SIZE_BLOCK - (pos % SIZE_BLOCK), &bufptr);
   //buf_len = raw_read(fd, &pos, 10, &bufptr);
   if(buf_len == -1)
   {
       buf_len = raw_read(fd, &pos, 4, &bufptr);
       if(buf_len == -1)
       {
           goto fail;
       }
   }

   prefix = bufptr[0] & 0x80;
   memcpy(&chunk_len, bufptr, 4);
   chunk_len = ntohl(chunk_len) & 0x7FFFFFFF;
   skip += 4;
   if(prefix)
   {
       //Just skip over the md5.. for now.
       skip += 16;
   }

   buf_len -= skip;
   memmove(bufptr, bufptr+skip, buf_len);
   if(chunk_len <= buf_len)
   {
       bufptr = (char*) realloc(bufptr, chunk_len);
       *ret_ptr = bufptr;
       return chunk_len;
   }
   else
   {
       int rest_len = raw_read(fd, &pos, chunk_len - buf_len, &bufptr_rest);
       if(rest_len == -1)
       {
           free(bufptr);
           goto fail;
       }
       bufptr = (char*) realloc(bufptr, buf_len + rest_len);
       memcpy(bufptr + buf_len, bufptr_rest, rest_len);
       free(bufptr_rest);
       *ret_ptr = bufptr;
       return chunk_len;
   }

fail:
   return -1;
}
Exemple #2
0
std::istream& OggPage::read(std::istream& from, bool read_body)
{
	raw_read(from, capture_pattern);
	raw_read(from, version);
	raw_read(from, header_type);
	raw_read(from, absolute_granule_position);
	raw_read(from, stream_serial_number);
	raw_read(from, page_sequence_no);
	raw_read(from, page_checksum);
	raw_read(from, page_segments);

	segment_table.resize(page_segments);
	from.read(reinterpret_cast<char*>(segment_table.data()), page_segments);

	const std::size_t bsz = body_size();
	if(read_body)
	{
		body.resize(bsz);
		from.read(reinterpret_cast<char*>(body.data()), bsz);
	}
	else
	{
		body.clear();
		from.ignore(bsz);
	}

	return from;
}
Exemple #3
0
/* Load in a rawfile. */
void
ft_loadfile(char *file)
{
    struct plot *pl, *np, *pp;

    fprintf(cp_out, "Loading raw data file (\"%s\") . . . ", file);
    pl = raw_read(file);
    if (pl)
        fprintf(cp_out, "done.\n");
    else
        fprintf(cp_out, "no data read.\n");

    /* This is a minor annoyance -- we should reverse the plot list so
     * they get numbered in the correct order.
     */
    for (pp = pl, pl = NULL; pp; pp = np) {
        np = pp->pl_next;
        pp->pl_next = pl;
        pl = pp;
    }
    for (; pl; pl = np) {
        np = pl->pl_next;
        plot_add(pl);
        /* Don't want to get too many "plot not written" messages. */
        pl->pl_written = TRUE;
    }
    plot_num++;
    plotl_changed = TRUE;
}
Exemple #4
0
Uint32 test_raw_read()
{
    Uint32 test_failures = 0;

    VFSStatus read_status;
    Uint32 buffer_size = 110;
    char buf[buffer_size];
    char filename[] = "/ext2_tests/indirect_block_file";
    Uint32 bytes_read;
    Uint32 offset = 10;

    buf[0] = '\0';
    read_status =
        raw_read (filename, buf, &bytes_read, offset, buffer_size-1);

    if( read_status )
    {
        serial_printf( "Failed to read '%s', error #%d\n\r",
                       filename, read_status );
        test_failures++;
    }

    buf[bytes_read] = '\0';
    serial_string ( "\n\r" );
    serial_string( buf );
    serial_string ( "\n\r" );

    return test_failures;
}
Exemple #5
0
int
sio_fill (struct siobuf *sio)
{
  assert (sio != NULL);


  if (sio->decode_cb != NULL) {
    /* Rules for the decode callback.

       The output variables (here buf and len) may be set to the
       read_buffer iff the decoding can be performed in place and
       the result is shorter than the original data.  Otherwise the
       callback must maintain its own buffer which must persist until
       the next call in the same thread.  The secarg argument may be
       used to maintain this buffer.
       
       Decode callback gets at most twice for each buffer: first time
       with buflen == 0 to decode whatever is in the internal decode
       buffer. If that call returns 0, actual data read is performed
       and decode is given the second shot, when it isupposed to
       return nonzero.
       length value 0 means error.
    */
    while ((*sio->decode_cb) (&sio->read_position, &sio->read_unread,
                               sio->read_buffer, sio->read_unread,
                               sio->secarg) == 0) {
      sio->read_unread = raw_read (sio, sio->read_buffer, sio->buffer_size);
      if (sio->read_unread <= 0)
        break;
    }
    sio->read_buffer_start = sio->read_position;
    if (sio->read_unread <= 0)
      return 0;
  } else {
    sio->read_unread = raw_read (sio, sio->read_buffer, sio->buffer_size);
    if (sio->read_unread <= 0)
      return 0;
    sio->read_position = sio->read_buffer;
    sio->read_buffer_start = sio->read_position;
 }

  if (sio->monitor_cb != NULL && sio->read_unread > 0)
    (*sio->monitor_cb) (sio->read_position, sio->read_unread,
			0, sio->cbarg);
  return sio->read_unread > 0;
}
Exemple #6
0
struct plot *
DBread( char *fileName )
{
  struct plot *plot;

  plot = raw_read( fileName );

  return(plot);
}
Exemple #7
0
int MsApiChunkHeader_Init(void)
{
    U32 u32ChunkHeaderOffset = 0;
    int ret = -1;

    UBOOT_TRACE("IN\n");
    raw_io_config_push();
    ret = mboot_raw_io_Config();
    if(ret != 0)
    {
        UBOOT_ERROR("raw_io_config setting fail!\n");
        raw_io_config_pop();
        return ret;
    }

    if(get_raw_status()==E_RAW_DATA_IN_SPI)
    {
        if(IsHouseKeepingBootingMode()==FALSE){
             u32ChunkHeaderOffset = 0x30000;
        }
        else
        {
            #if(CONFIG_MSTAR_RT_PM_IN_SPI==1)
                u32ChunkHeaderOffset = 0x30000;
            #else
#if defined(CONFIG_PM_SIZE_KB_FORCED) && (0!=CONFIG_PM_SIZE_KB_FORCED)
                u32ChunkHeaderOffset = 0x10000+(CONFIG_PM_SIZE_KB_FORCED*0x400);
#else
                u32ChunkHeaderOffset = 0x20000;
#endif
            #endif
        }

        #if(ENABLE_MSTAR_PUMABOOT)
        u32ChunkHeaderOffset = u32ChunkHeaderOffset + CONFIG_PUMABOOT_SIZE;
        #endif
    }
    else
    {
         u32ChunkHeaderOffset = 0;
    }
    ret = raw_read((U32)gu32ChunkHeader,u32ChunkHeaderOffset,(CH_ITEM_LAST+1)*4);
    
    raw_io_config_pop();
 
    if(ret != 0)
    {
         UBOOT_ERROR("raw_read gu8ChunkHeader fail\n");
         return -1;
    }
    
    ChunkHeaderReady = TRUE; 
    UBOOT_TRACE("OK\n");
    return 0;    
}
Exemple #8
0
static int /* gz_avail */
fill_in_buffer(FILE_F state)
{
	if (state->err)
		return -1;
	if (state->eof == 0) {
		if (raw_read(state, state->in, state->size, &(state->avail_in)) == -1)
			return -1;
		state->next_in = state->in;
	}
	return 0;
}
Exemple #9
0
/**
 * Reads all the streams that are in the FD_SET.  The data is put into buff,
 * but the intention is for buff to be just temporary storage, and that the
 * contents of the received data are completely irrelevant.
 * @param rfd The fd_set containing all streams that can be read
 * @param c2s_conns An array of all possible connections that could be read
 * @param c2s_conn_length The length of the array
 * @param buff A pointer to the buffer to put the read data
 * @param buff_size The size of the buffer
 * @param bytes_read An outparam which tracks the total number of bytes read
 * @return 0 on success, an error code otherwise.
 */
int read_ready_streams(fd_set *rfd, Connection *c2s_conns, int c2s_conn_length,
                       char *buff, size_t buff_size, double *bytes_read) {
  int i;
  int error;
  ssize_t current_bytes_read;
  for (i = 0; i < c2s_conn_length; i++) {
    if (FD_ISSET(c2s_conns[i].socket, rfd)) {
      error = raw_read(&c2s_conns[i], buff, buff_size, &current_bytes_read);
      if (error != 0) return error;
      *bytes_read += current_bytes_read;
    }
  }
  return 0;
}
Exemple #10
0
int mdio_read(int phyadr, int reg)
{
	int r;
	
	CSR_MINIMAC_MDIO = MINIMAC_MDIO_OE;
	raw_write(0xffffffff, 32); /* < sync */
	raw_write(0x06, 4); /* < start + read */
	raw_write(phyadr, 5);
	raw_write(reg, 5);
	raw_turnaround();
	r = raw_read();
	raw_turnaround();
	
	return r;
}
Exemple #11
0
int MsApiChunkHeader_Init(void)
{
    U32 u32ChunkHeaderOffset = 0;
    int ret = -1;

    UBOOT_TRACE("IN\n");
    raw_io_config_push();
    ret = mboot_raw_io_Config();
    if(ret != 0)
    {
        UBOOT_ERROR("raw_io_config setting fail!\n");
        raw_io_config_pop();
        return ret;
    }

    if(get_raw_status()==E_RAW_DATA_IN_SPI)
    {
        if(IsHouseKeepingBootingMode()==FALSE){
             u32ChunkHeaderOffset = 0x30000;
        }
        else
        {
            #if(ENABLE_MSTAR_STR_ENABLE==1 ||ENABLE_MSTAR_PM_SWIR==1 )
                u32ChunkHeaderOffset = 0x30000;
            #else
                u32ChunkHeaderOffset = 0x20000;
            #endif
        }
    }
    else
    {
         u32ChunkHeaderOffset = 0;
    }
    ret = raw_read((U32)gu32ChunkHeader,u32ChunkHeaderOffset,(CH_ITEM_LAST+1)*4);
    
    raw_io_config_pop();
 
    if(ret != 0)
    {
         UBOOT_ERROR("raw_read gu8ChunkHeader fail\n");
         return -1;
    }
    
    ChunkHeaderReady = TRUE; 
    UBOOT_TRACE("OK\n");
    return 0;    
}
Exemple #12
0
static int
bbsnet_read(int fd, char *buf, int len)
{
    int rc;
    time_t now;

    rc = raw_read(fd, buf, len);
    if (rc > 0) {
        now = time(NULL);
        if (now - last_refresh > 60) {
            uinfo.freshtime = now;
            UPDATE_UTMP(freshtime, uinfo);
            last_refresh = now;
        }
    }
    return rc;
}
Exemple #13
0
P1(PUBLIC pascal trap, OSErr, DIVerify, INTEGER, dn)
{
  int i;
  char buf[N_TRACK_BYTES];
  LONGINT length;
  OSErr err;
  our_file_info_t oi;

  err = get_vref_dref (dn, &oi.vref, &oi.dref);
  oi.pos = 0;
  if (err == noErr)
    {
      for (i = 0, err = noErr; err == noErr && i < FLOPPY_TRACKS_PER_SIDE; ++i)
	{
	  length = sizeof(buf);
	  err = raw_read (&oi, &length, buf);
	  if (err == noErr && length != sizeof(buf))
	    err = ioErr;
	}
    }

  return err;
}
Exemple #14
0
int SignatureLoad(SECURITY_INFO *pBufferAddr)
{
    int ret = -1;
    int flag1=0, flag2=0;    
    unsigned int u32SigOffset = 0;
    unsigned int u32SigBkOffset = 0;     
    unsigned int u32SecuritySize= 0;
    UBOOT_TRACE("IN\n");

    //Here, we check the CRC of SECUREITY_INFO, and the check range include "pBufferAddr->data" and "pBufferAddr->data_interleave"
    u32SecuritySize = sizeof(_SECURITY_INFO_DATA) * NUMBER_OF_SECURE_INFO;

    if(pBufferAddr==NULL)
    {
        UBOOT_ERROR("The input parameter pBufferAddr' is a null pointer\n");
        return -1;
    }

    ret = raw_io_config(FLASH_DEFAULT_TARGET,FLASH_DEFAULT_PARTITION,FLASH_DEFAULT_VOLUME);
    if(ret != 0)
    {
        UBOOT_ERROR("raw_io_config setting fail!\n");
        return -1;
    }

    ret = get_signature_offset(&u32SigOffset,&u32SigBkOffset);
    if(ret != 0)
    {
        UBOOT_ERROR("get_signature_offset fail!\n");
        return -1;
    }
   
    ret = raw_read((unsigned int)pBufferAddr,u32SigOffset,sizeof(SECURITY_INFO));
    
    if( (EN_SUCCESS == ret) && (pBufferAddr->crc == crc32(0, (unsigned char const *)&pBufferAddr->data,u32SecuritySize)) )
        flag1=1;
    
    ret = raw_read((unsigned int)pBufferAddr,u32SigBkOffset,sizeof(SECURITY_INFO));
    
    if( (EN_SUCCESS == ret) && (pBufferAddr->crc == crc32(0, (unsigned char const *)&pBufferAddr->data,u32SecuritySize)) )
        flag2=1;

    if( (flag2==0) && (flag1!=0) )
    {
        ret = raw_read((unsigned int)pBufferAddr,u32SigOffset,sizeof(SECURITY_INFO));
        if( (EN_SUCCESS == ret) && (pBufferAddr->crc == crc32(0, (unsigned char const *)&pBufferAddr->data,u32SecuritySize)))
        {
            ret = raw_write((unsigned int)pBufferAddr,u32SigBkOffset,sizeof(SECURITY_INFO));
        }
        else
        {
            UBOOT_ERROR("raw_read fail or caculate crc fail!\n");
            return -1;
        }
    }

    if((flag1==0)&&(flag2!=0))
    {
        ret = raw_write((unsigned int)pBufferAddr,u32SigOffset,sizeof(SECURITY_INFO));
    }

   if(EN_SUCCESS == ret)
   {
       ret=0;
       UBOOT_TRACE("OK\n");
   }
   else
   {
       ret=-1;
       UBOOT_ERROR("SignatureLoad fail\n");
   }

   return ret;
}
Exemple #15
0
int do_draw_jpg (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
    U32 u32LogoAddr=0;
    U32 u32LogoSize=0;
    U32 JPD_InputADDR=0;
    U32 JPD_OUTADDR=0;
    char *PhotoPath=NULL;
    BltConfigParams stConfig;
    UBOOT_TRACE("IN\n");

    get_addr_from_mmap("E_MMAP_ID_JPD_READ", &JPD_InputADDR);
    get_addr_from_mmap("E_MMAP_ID_JPD_WRITE", &JPD_OUTADDR);

	if(JPD_InputADDR==0xFFFF || JPD_OUTADDR==0xFFFF)
	{
		UBOOT_ERROR("Get Mmap for JPD Fail Skip JPD Decode !!! \n");
		return -1;

	}
    if(argc < 6)
    {
#if (CONFIG_BINARY_RELEASE == 1)
    stConfig.u16DispX = DEFAULT_OSD_STRING_X;
    stConfig.u16DispY = DEFAULT_OSD_STRING_Y;
    stConfig.u16DispW = DEFAULT_OSD_LAYER_WIDTH;
    stConfig.u16DispH = DEFAULT_OSD_LAYER_HEIGHT; 
#else
        cmd_usage(cmdtp);
        return 1;
#endif
    }
    else
    {
        stConfig.u16DispX = simple_strtoul(argv[2], NULL, 10);
        stConfig.u16DispY = simple_strtoul(argv[3], NULL, 10);
        stConfig.u16DispW = simple_strtoul(argv[4], NULL, 10);
        stConfig.u16DispH = simple_strtoul(argv[5], NULL, 10);       
    }
    if(IsPanelReady()!=0)
    {
         UBOOT_ERROR("Panle is not ready\n");
        return -1;
    }


    UBOOT_DEBUG("u16DispX=0x%x,u16DispY=0x%x,u16DispW=0x%x,u16DispH=0x%x\n",stConfig.u16DispX,stConfig.u16DispY,stConfig.u16DispW,stConfig.u16DispH);

    if(strncmp(argv[1], "-fs", 3)==0) // jpd from filesystem
    {
        PhotoPath = argv[6];
        UBOOT_DEBUG("PhotoPath=%s\n",PhotoPath);
        u32LogoSize = LoadJpg2Dram(PhotoPath, JPD_InputADDR);
        UBOOT_DEBUG("u32LogoSize : 0x%x \n",u32LogoSize);
        if(u32LogoSize == 0)
        {
            UBOOT_ERROR("Fail: Load_Photo2Dram return size is 0 !!\n");
            return -1;
        }
    }
    else if(strncmp(argv[1], "-s", 2)==0)
    {
        mboot_raw_io_Config();
        u32LogoAddr= simple_strtoul(argv[6],NULL,16);
        u32LogoSize= simple_strtoul(argv[7],NULL,16);;
        raw_read(PA2NVA(JPD_InputADDR),u32LogoAddr,u32LogoSize);
    }
    else
    {
#if (CONFIG_BINARY_RELEASE == 1)
        PhotoPath = DEFAULT_OSD_BACKGROUND_PATH;
        UBOOT_DEBUG("PhotoPath=%s\n",PhotoPath);
        u32LogoSize = LoadJpg2Dram(PhotoPath,LOGO_JPG_DRAM_ADDR);
        UBOOT_DEBUG("u32LogoSize : 0x%x \n",u32LogoSize);
        if(u32LogoSize == 0)
        {
            UBOOT_ERROR("Fail: Load_Photo2Dram return size is 0 !!\n");
            return -1;
        }
#else
        cmd_usage(cmdtp);
        return -1;
#endif
    }    
    MsApi_JPD_Decode(JPD_InputADDR, u32LogoSize);
    draw_jpg(stConfig,JPD_OUTADDR);
    UBOOT_TRACE("OK\n");
    return 0;
}
Exemple #16
0
int main(int argc,char *argv[]) {

  unsigned char help=0;
  unsigned char option=0;


  int arg=0;

  struct rawfp *rawfpA=NULL;
  struct rawfp *rawfpB=NULL;
  
  int sA,sB;
  int c,x;

  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);
 
  arg=OptionProcess(1,argc,argv,&opt,NULL);  

  if (help==1) {
    OptionPrintInfo(stdout,hlpstr);
    exit(0);
  }

  if (option==1) {
    OptionDump(stdout,&opt);
    exit(0);
  }


  if (argc-arg<2) {
    OptionPrintInfo(stderr,errstr);
    exit(-1);
  }


  rawfpA=raw_open(argv[arg],NULL);
  rawfpB=raw_open(argv[arg+1],NULL);

  while (1) {
    sA=raw_read(rawfpA,&rawA);
    sB=raw_read(rawfpB,&rawB);
    if ((sA==-1) || (sB==-1)) break;
  
    fprintf(stdout,
    "%.4d-%.2d-%.2d %.2d:%.2d:%.2d\t%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n",
	    rawA.PARMS.YEAR,rawA.PARMS.MONTH,rawA.PARMS.DAY,
            rawA.PARMS.HOUR,rawA.PARMS.MINUT,rawA.PARMS.SEC,
            rawB.PARMS.YEAR,rawB.PARMS.MONTH,rawB.PARMS.DAY,
            rawB.PARMS.HOUR,rawB.PARMS.MINUT,rawB.PARMS.SEC);
    
    if (rawA.PARMS.REV.MAJOR !=rawB.PARMS.REV.MAJOR) fprintf(stdout,"raw.PARMS.REV.MAJOR: %d !=%d \n",rawA.PARMS.REV.MAJOR,rawB.PARMS.REV.MAJOR);


    if (rawA.PARMS.REV.MINOR !=rawB.PARMS.REV.MINOR) fprintf(stdout,"raw.PARMS.REV.MINOR: %d !=%d \n",rawA.PARMS.REV.MINOR,rawB.PARMS.REV.MINOR);

    if (rawA.PARMS.NPARM !=rawB.PARMS.NPARM) fprintf(stdout,"raw.PARMS.NPARM: %d !=%d \n",rawA.PARMS.NPARM,rawB.PARMS.NPARM);

   if (rawA.PARMS.ST_ID !=rawB.PARMS.ST_ID) fprintf(stdout,"raw.PARMS.ST_ID: %d !=%d \n",rawA.PARMS.ST_ID,rawB.PARMS.ST_ID);

   if (rawA.PARMS.YEAR !=rawB.PARMS.YEAR) fprintf(stdout,"raw.PARMS.YEAR: %d !=%d \n",rawA.PARMS.YEAR,rawB.PARMS.YEAR);

   if (rawA.PARMS.MONTH !=rawB.PARMS.MONTH) fprintf(stdout,"raw.PARMS.MONTH: %d !=%d \n",rawA.PARMS.MONTH,rawB.PARMS.MONTH);

   if (rawA.PARMS.DAY !=rawB.PARMS.DAY) fprintf(stdout,"raw.PARMS.DAY: %d !=%d \n",rawA.PARMS.DAY,rawB.PARMS.DAY);

   if (rawA.PARMS.HOUR !=rawB.PARMS.HOUR) fprintf(stdout,"raw.PARMS.HOUR: %d !=%d \n",rawA.PARMS.HOUR,rawB.PARMS.HOUR);

   if (rawA.PARMS.MINUT !=rawB.PARMS.MINUT) fprintf(stdout,"raw.PARMS.MINUT: %d !=%d \n",rawA.PARMS.MINUT,rawB.PARMS.MINUT);

   if (rawA.PARMS.SEC !=rawB.PARMS.SEC) fprintf(stdout,"raw.PARMS.SEC: %d !=%d \n",rawA.PARMS.SEC,rawB.PARMS.SEC);

   if (rawA.PARMS.TXPOW !=rawB.PARMS.TXPOW) fprintf(stdout,"raw.PARMS.TXPOW: %d !=%d \n",rawA.PARMS.TXPOW,rawB.PARMS.TXPOW);

   if (rawA.PARMS.NAVE !=rawB.PARMS.NAVE) fprintf(stdout,"raw.PARMS.NAVE: %d !=%d \n",rawA.PARMS.NAVE,rawB.PARMS.NAVE);

   if (rawA.PARMS.ATTEN !=rawB.PARMS.ATTEN) fprintf(stdout,"raw.PARMS.ATTEN: %d !=%d \n",rawA.PARMS.ATTEN,rawB.PARMS.ATTEN);

   if (rawA.PARMS.LAGFR !=rawB.PARMS.LAGFR) fprintf(stdout,"raw.PARMS.LAGFR: %d !=%d \n",rawA.PARMS.LAGFR,rawB.PARMS.LAGFR); 

   if (rawA.PARMS.SMSEP !=rawB.PARMS.SMSEP) fprintf(stdout,"raw.PARMS.SMSEP: %d !=%d \n",rawA.PARMS.SMSEP,rawB.PARMS.SMSEP);


   if (rawA.PARMS.ERCOD !=rawB.PARMS.ERCOD) fprintf(stdout,"raw.PARMS.ERCOD: %d !=%d \n",rawA.PARMS.ERCOD,rawB.PARMS.ERCOD);

   if (rawA.PARMS.AGC_STAT !=rawB.PARMS.AGC_STAT) fprintf(stdout,"raw.PARMS.AGC_STAT: %d !=%d \n",rawA.PARMS.AGC_STAT,rawB.PARMS.AGC_STAT);

   if (rawA.PARMS.LOPWR_STAT !=rawB.PARMS.LOPWR_STAT) fprintf(stdout,"raw.PARMS.LOPWR_STAT: %d !=%d \n",rawA.PARMS.LOPWR_STAT,rawB.PARMS.LOPWR_STAT);

   if (rawA.PARMS.NBAUD !=rawB.PARMS.NBAUD) fprintf(stdout,"raw.PARMS.NBAUD: %d !=%d \n",rawA.PARMS.NBAUD,rawB.PARMS.NBAUD);

   if (rawA.PARMS.NOISE !=rawB.PARMS.NOISE) fprintf(stdout,"raw.PARMS.NOISE: %d !=%d \n",rawA.PARMS.NOISE,rawB.PARMS.NOISE);

   if (rawA.PARMS.NOISE_MEAN !=rawB.PARMS.NOISE_MEAN) fprintf(stdout,"raw.PARMS.NOISE_MEAN: %d !=%d \n",rawA.PARMS.NOISE_MEAN,rawB.PARMS.NOISE_MEAN);

   if (rawA.PARMS.CHANNEL !=rawB.PARMS.CHANNEL) fprintf(stdout,"raw.PARMS.CHANNEL: %d !=%d \n",rawA.PARMS.CHANNEL,rawB.PARMS.CHANNEL);


   if (rawA.PARMS.RXRISE !=rawB.PARMS.RXRISE) fprintf(stdout,"raw.PARMS.RXRISE: %d !=%d \n",rawA.PARMS.RXRISE,rawB.PARMS.RXRISE);


   if (rawA.PARMS.INTT !=rawB.PARMS.INTT) fprintf(stdout,"raw.PARMS.INTT: %d !=%d \n",rawA.PARMS.INTT,rawB.PARMS.INTT);


   if (rawA.PARMS.TXPL !=rawB.PARMS.TXPL) fprintf(stdout,"raw.PARMS.TXPL: %d !=%d \n",rawA.PARMS.TXPL,rawB.PARMS.TXPL);


   if (rawA.PARMS.MPINC !=rawB.PARMS.MPINC) fprintf(stdout,"raw.PARMS.MPINC: %d !=%d \n",rawA.PARMS.MPINC,rawB.PARMS.MPINC);




   if (rawA.PARMS.MPPUL !=rawB.PARMS.MPPUL) fprintf(stdout,"raw.PARMS.MPPUL: %d !=%d \n",rawA.PARMS.MPPUL,rawB.PARMS.MPPUL);


   if (rawA.PARMS.MPLGS !=rawB.PARMS.MPLGS) fprintf(stdout,"raw.PARMS.MPLGS: %d !=%d \n",rawA.PARMS.MPLGS,rawB.PARMS.MPLGS);


   if (rawA.PARMS.NRANG !=rawB.PARMS.NRANG) fprintf(stdout,"raw.PARMS.NRANG: %d !=%d \n",rawA.PARMS.NRANG,rawB.PARMS.NRANG);


   if (rawA.PARMS.FRANG !=rawB.PARMS.FRANG) fprintf(stdout,"raw.PARMS.FRANG: %d !=%d \n",rawA.PARMS.FRANG,rawB.PARMS.FRANG);


   if (rawA.PARMS.RSEP !=rawB.PARMS.RSEP) fprintf(stdout,"raw.PARMS.RSEP: %d !=%d \n",rawA.PARMS.RSEP,rawB.PARMS.RSEP);

   if (rawA.PARMS.BMNUM !=rawB.PARMS.BMNUM) fprintf(stdout,"raw.PARMS.BMNUM: %d !=%d \n",rawA.PARMS.BMNUM,rawB.PARMS.BMNUM);


   if (rawA.PARMS.XCF !=rawB.PARMS.XCF) fprintf(stdout,"raw.PARMS.XCF: %d !=%d \n",rawA.PARMS.XCF,rawB.PARMS.XCF);

 
   if (rawA.PARMS.TFREQ !=rawB.PARMS.TFREQ) fprintf(stdout,"raw.PARMS.TFREQ: %d !=%d \n",rawA.PARMS.TFREQ,rawB.PARMS.TFREQ);

   if (rawA.PARMS.SCAN !=rawB.PARMS.SCAN) fprintf(stdout,"raw.PARMS.SCAN: %d !=%d \n",rawA.PARMS.SCAN,rawB.PARMS.SCAN);

   if (rawA.PARMS.MXPWR !=rawB.PARMS.MXPWR) fprintf(stdout,"raw.PARMS.MXPWR: %d !=%d \n",rawA.PARMS.MXPWR,rawB.PARMS.MXPWR);


   if (rawA.PARMS.LVMAX !=rawB.PARMS.LVMAX) fprintf(stdout,"raw.PARMS.LVMAX: %d !=%d \n",rawA.PARMS.LVMAX,rawB.PARMS.LVMAX);


   if (rawA.PARMS.CP !=rawB.PARMS.CP) fprintf(stdout,"raw.PARMS.CP: %d !=%d \n",rawA.PARMS.CP,rawB.PARMS.CP);

   if (strcmp(rawA.COMBF,rawB.COMBF) !=0)  fprintf(stdout,"raw.combf: %s !=%s \n",rawA.COMBF,rawB.COMBF);

   for (c=0;c<rawA.PARMS.MPPUL;c++) if (rawA.PULSE_PATTERN[c] !=rawB.PULSE_PATTERN[c]) break;
   if (c !=rawA.PARMS.MPPUL) fprintf(stdout,"Pulse pattern does not match\n");

   for (c=0;c<rawA.PARMS.MPLGS;c++) {
     if (rawA.LAG_TABLE[0][c] !=rawB.LAG_TABLE[0][c]) break;
     if (rawA.LAG_TABLE[1][c] !=rawB.LAG_TABLE[1][c]) break;

   }
   if (c !=rawA.PARMS.MPLGS) fprintf(stdout,"Lag table does not match\n");

 
   for (c=0;c<rawA.PARMS.NRANG;c++) {
     if (rawA.pwr0[c] !=rawB.pwr0[c]) {
       fprintf(stdout,"pwr0[%d]: %g != %g\n",c,rawA.pwr0[c],rawB.pwr0[c]);
     }
   }

   if (c !=rawA.PARMS.NRANG) fprintf(stdout,"Lag-zero power does not match\n");

   for (c=0;c<rawA.PARMS.NRANG;c++) {
     for (x=0;x<rawA.PARMS.MPLGS;x++) {
     
       if (rawA.acfd[c][x][0] !=rawB.acfd[c][x][0]) {
         fprintf(stdout,"acfd[%d][%d][0]: %g != %g\n",c,x,rawA.acfd[c][x][0],
	         rawB.acfd[c][x][0]);
       }

       if (rawA.acfd[c][x][1] !=rawB.acfd[c][x][1]) {
         fprintf(stdout,"acfd[%d][%d][1]: %g != %g\n",c,x,rawA.acfd[c][x][1],
	       rawB.acfd[c][x][1]);
       }
     }
   }

   if (rawA.PARMS.XCF) {

     for (c=0;c<rawA.PARMS.NRANG;c++) {
       for (x=0;x<rawA.PARMS.MPLGS;x++) {
     
         if (rawA.acfd[c][x][0] !=rawB.acfd[c][x][0]) {
           fprintf(stdout,"acfd[%d][%d][0]: %g != %g\n",c,x,rawA.acfd[c][x][0],
	         rawB.acfd[c][x][0]);
         }

         if (rawA.acfd[c][x][1] !=rawB.acfd[c][x][1]) {
           fprintf(stdout,"acfd[%d][%d][1]: %g != %g\n",c,x,rawA.acfd[c][x][1],
	         rawB.acfd[c][x][1]);
         }
       }
     }

   }


   if (c !=rawA.PARMS.NRANG) fprintf(stdout,"Data does not match\n");

  }
  return 0;
}
Exemple #17
0
static void dispatch_out(void) {
    //  update latest serial received
    if (out_packet_ptr) {
        in_packet[0] = out_packet[0];
        if (in_packet_ptr == 0) {
            in_packet_ptr = 1;
        }
    }
    unsigned char ptr = 1;
    while (ptr < out_packet_ptr) {
        unsigned char code = out_packet[ptr];
        ++ptr;
        unsigned char sz = code & 0xf;
        if (sz == 15) {
            if (ptr == out_packet_ptr) {
                goto too_big;
            }
            sz = out_packet[ptr];
            ++ptr;
        }
        if (ptr + sz > out_packet_ptr || ptr + sz < ptr) {
too_big:
            MY_Failure("Too big recv", ptr + sz, out_packet_ptr);
        }
        unsigned char code_ix = (code & 0xf0) >> 4;
        if (code_ix >= sizeof(min_size)) {
unknown_op:
            MY_Failure("Unknown op", code & 0xf0, sz);
        }
        unsigned char msz = 0;
        memcpy_P(&msz, &min_size[code_ix], 1);
        if (sz < msz) {
            MY_Failure("Too small data", sz, code);
        }
        unsigned char *base = &out_packet[ptr];
        switch (code & 0xf0) {
        case OpSetStatus:
            set_status(base[0], sz-1, base+1);
            break;
        case OpGetStatus:
            get_status(base[0]);
            break;
        case OpWriteServo:
            write_servo(base[0], base[1], sz-2, base+2);
            break;
        case OpReadServo:
            read_servo(base[0], base[1], base[2]);
            break; 
        case OpOutText:
            out_text(sz, base);
            break;
        case OpRawWrite:
            raw_write(sz, base);
            break;
        case OpRawRead:
            raw_read(base[0]);
            break;
        default:
            goto unknown_op;
        }
        ptr += sz;
    }
}
int
main(int ac, char **av)
{
    char *sf, *af;
    char buf[BSIZE_SP];
    char t, f;
    struct plot *pl;
    size_t n;
    char *infile = NULL;
    char *outfile = NULL;
    FILE *fp;
    cp_in = stdin;
    cp_out = stdout;
    cp_err = stderr;
    cp_curin = stdin;
    cp_curout = stdout;
    cp_curerr = stderr;

    switch (ac) {
        case 5: 
            sf = av[2];
            af = av[4];
            f = *av[1];
            t = *av[3];
            break;

        case 3:
            f = *av[1];
            t = *av[2];
            /* This is a pain, but there is no choice */
            sf = infile = smktemp("scin");
            af = outfile = smktemp("scout");
            if (!(fp = fopen(infile, "w"))) {
                perror(infile);
                exit(EXIT_BAD);
            }
            while ((n = fread(buf, 1, sizeof(buf), stdin)) != 0)
                (void) fwrite(buf, 1, n, fp);
            (void) fclose(fp);
            break;

        case 1: printf("Input file: ");
            (void) fflush(stdout);
            (void) fgets(buf, BSIZE_SP, stdin);
            sf = copy(buf);
            printf("Input type: ");
            (void) fflush(stdout);
            (void) fgets(buf, BSIZE_SP, stdin);
            f = buf[0];
            printf("Output file: ");
            (void) fflush(stdout);
            (void) fgets(buf, BSIZE_SP, stdin);
            af = copy(buf);
            printf("Output type: ");
            (void) fflush(stdout);
            (void) fgets(buf, BSIZE_SP, stdin);
            t = buf[0];
            break;
        default:
            fprintf(cp_err, 
                "Usage: %s fromtype fromfile totype tofile,\n",
                cp_program);
            fprintf(cp_err, "\twhere types are o, b, or a\n");
            fprintf(cp_err, 
                "\tor, %s fromtype totype, used as a filter.\n",
                cp_program);
            exit(EXIT_BAD);
    }
    switch(f) {
        case 'o' :
        pl = oldread(sf);
        break;

        case 'b' :
        case 'a' :
        pl = raw_read(sf);
        break;

        default:
        fprintf(cp_err, "Types are o, a, or b\n");
        exit(EXIT_BAD);
    }
    if (!pl)
        exit(EXIT_BAD);

    switch(t) {
        case 'o' :
        oldwrite(af, FALSE, pl);
        break;

        case 'b' :
        raw_write(af, pl, FALSE, TRUE);
        break;

        case 'a' :
        raw_write(af, pl, FALSE, FALSE);
        break;

        default:
        fprintf(cp_err, "Types are o, a, or b\n");
        exit(EXIT_BAD);
    }
    if (ac == 3) {
        /* Gotta finish this stuff up */
        if (!(fp = fopen(outfile, "r"))) {
            perror(outfile);
            exit(EXIT_BAD);
        }
        while ((n = fread(buf, 1, sizeof(buf), fp)) != 0)
            (void) fwrite(buf, 1, n, stdout);
        (void) fclose(fp);
        (void) unlink(infile);
        (void) unlink(outfile);
    }
    exit(EXIT_NORMAL);
}
Exemple #19
0
int vmeio_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
		unsigned long arg)
{
	void *arb;		/* Argument buffer area */

	struct vmeio_device *dev;

	int iodr;		/* Io Direction */
	int iosz;		/* Io Size in bytes */
	int cc = 0;		/* erro return code */

	long minor;

	iodr = _IOC_DIR(cmd);
	iosz = _IOC_SIZE(cmd);

	minor = MINOR(inode->i_rdev);
	if (!minor_ok(minor))
		return -EACCES;
	dev = filp->private_data;

	if ((arb = kmalloc(iosz, GFP_KERNEL)) == NULL)
		return -ENOMEM;

	if ((iodr & _IOC_WRITE) && copy_from_user(arb, (void *)arg, iosz)) {
		cc = -EACCES;
		goto out;
	}
	debug_ioctl(_IOC_NR(cmd), iodr, iosz, arb, minor, dev->debug);

	if (!dev) {
		cc = -EACCES;
		goto out;
	}

	switch (cmd) {

	case VMEIO_SET_DEBUG:
		vmeio_set_debug(dev, arb);
		break;

	case VMEIO_GET_DEBUG:
		vmeio_get_debug(dev, arb);
		break;

	case VMEIO_GET_VERSION:
		vmeio_get_version(arb);
		break;

	case VMEIO_SET_TIMEOUT:
		vmeio_set_timeout(dev, arb);
		break;

	case VMEIO_GET_TIMEOUT:
		vmeio_get_timeout(dev, arb);
		break;

	case VMEIO_RAW_READ_DMA:
		cc = raw_dma(dev, arb, VME_DMA_FROM_DEVICE);
		if (cc < 0)
			goto out;
		break;

	case VMEIO_RAW_WRITE_DMA:
		cc = raw_dma(dev, arb, VME_DMA_TO_DEVICE);
		if (cc < 0)
			goto out;
		break;

	case VMEIO_READ_DMA:
	case VMEIO_WRITE_DMA:
		cc = do_raw_dma(arb);
		if (cc < 0)
			goto out;
		break;

	case VMEIO_RAW_READ:
		cc = raw_read(dev, arb);
		if (cc < 0)
			goto out;
		break;

	case VMEIO_RAW_WRITE:
		cc = raw_write(dev, arb);
		if (cc < 0)
			goto out;
		break;

	case VMEIO_GET_MAPPING:
		cc = get_mapping(dev, arb);
		if (cc < 0)
			goto out;
		break;

#ifdef ENCORE_DAL
	case VMEIO_GET_NREGS:
		get_nregs(arb);
		break;
	case VMEIO_GET_REGINFO:
		cc = get_reginfo(arb);
		break;
#else
	case VMEIO_GET_NREGS:
	case VMEIO_GET_REGINFO:
		cc = -ENOENT;
		break;
#endif

	default:
		cc = -ENOENT;
		goto out;
		break;
	}

	if ((iodr & _IOC_READ) && copy_to_user((void *)arg, arb, iosz)) {
			cc = -EACCES;
			goto out;
	}
out:	kfree(arb);
	return cc;
}
Exemple #20
0
main()
{
long t1, told, rec_offset;
long indrec[2];
short int indata[8192];
int rind_file;
RAW_FILE *raw_file;
size_t iostat;
struct rawdata *raddat;
short int etst;
long int ltemp;
int i;

char raw_name[80], rind_name[80], filename[80];

raddat = (struct rawdata *) calloc(1, sizeof(struct rawdata));

rec_offset = 0;		/* initialize the byte number */
told = 0;

printf("Ready to create an index file to the raw RADOPS 386 radar data\n");
printf("\nEnter the file name (no extension) of the raw data file: ");
scanf("%s",raw_name);
getchar();	/* get rid of the <cr> at the end */

strcpy(filename,raw_name);
strcat(rind_name,raw_name);

if ((raw_file = rawropen(filename)) == 0)
	{
	printf("Unable to open raw data file\n");
	exit(ENOENT);
	}

/* Now open the index file for output */

strcat(rind_name,".rin");
rind_file = open(rind_name,O_RDWR|O_CREAT|O_TRUNC,0664);
if(rind_file <= 0) 
	{
	printf("Unable to open output file %s, fp=%x\n",rind_name,rind_file);
	exit(ENOENT);	
	}
else 
{
    printf("The index file will be created in the current directory\n");
}

/*	now start reading the raw data file and filing in the index */

while (1)
	{
	rec_offset = raw_file->raw_offset;
	iostat = raw_read(raw_file, 0, raddat);
	if (iostat == EOF)
		{
		close(rind_file);
		raw_close(raw_file);
		exit(0);
		}
	t1 = cnv_mdhms_sec(&(raddat->PARMS.YEAR),
			&(raddat->PARMS.MONTH),
			&(raddat->PARMS.DAY),
			&(raddat->PARMS.HOUR),
			&(raddat->PARMS.MINUT),
			&(raddat->PARMS.SEC));
	indrec[0]=t1;
	indrec[1]=rec_offset;
	
	if (endian(&etst) == 0) {
	  for (i=0; i < 2; ++i) {
	    ltemp = indrec[i];
	    swab_dword(&indrec[i],&ltemp);
	  }
	}
	write(rind_file, indrec, sizeof(indrec[0])*2);
	if (t1-told > 900)
		{
		printf("%d  %d\n",t1,rec_offset);
		told = t1;
		}
	}
}
Exemple #21
0
static void __attribute__((constructor)) startup(void)
{
#else
#define RETURN_VALUE 0
static void *ignore_ud2_addr;
// scratch test code
int main(void)
{
#endif

	char *debug_level_str = getenv("TRAP_SYSCALLS_DEBUG");
	char *footprint_fd_str = getenv("TRAP_SYSCALLS_FOOTPRINT_FD");
	char *trace_fd_str = getenv("TRAP_SYSCALLS_TRACE_FD");
	char *sleep_for_seconds_str = getenv("TRAP_SYSCALLS_SLEEP_FOR_SECONDS");
	char *stop_self_str = getenv("TRAP_SYSCALLS_STOP_SELF");
	stop_self = (stop_self_str != NULL);
	footprints_spec_filename = getenv("TRAP_SYSCALLS_FOOTPRINT_SPEC_FILENAME");
	struct timespec one_second = { /* seconds */ 1, /* nanoseconds */ 0 };
	if (debug_level_str) debug_level = atoi(debug_level_str);
	if (trace_fd_str) trace_fd = atoi(trace_fd_str);
	if (footprint_fd_str) footprint_fd = atoi(footprint_fd_str);
	if (sleep_for_seconds_str) sleep_for_seconds = atoi(sleep_for_seconds_str);
	debug_printf(0, "Debug level is %s=%d.\n", debug_level_str, debug_level);
	if (stop_self) {
		self_pid = raw_getpid();
		debug_printf(0, "TRAP_SYSCALLS_STOP_SELF is set, sending SIGSTOP to self (pid %d)\n", self_pid);
		raw_kill(self_pid, SIGSTOP);
	}
	debug_printf(0, "TRAP_SYSCALLS_SLEEP_FOR_SECONDS is %s, pausing for %d seconds", sleep_for_seconds_str, sleep_for_seconds);
	for (int i = 0; i < sleep_for_seconds; i++) {
		raw_nanosleep(&one_second, NULL);
		debug_printf(0, ".");
	}
	debug_printf(0, "\n");

	/* Is fd open? If so, it's the input fd for our sanity check info
	 * from systemtap. */
	debug_printf(0, "TRAP_SYSCALLS_FOOTPRINT_FD is %s, ", footprint_fd_str);
	if (footprint_fd > 2)
	{
		struct stat buf;
		int stat_ret = raw_fstat(footprint_fd, &buf);
		if (stat_ret == 0) {
			debug_printf(0, "fd %d is open; outputting systemtap cross-check info.\n", footprint_fd);
			/* PROBLEM: ideally we'd read in the stap script's output ourselves, and process
			 * it at every system call. But by reading in stuff from stap, we're doing more
			 * copying to/from userspace, so creating a feedback loop which would blow up.
			 *
			 * Instead we write out what we think we touched, and do a diff outside the process.
			 * This also adds noise to stap's output, but without the feedback cycle: we ourselves
			 * won't read the extra output, hence won't write() more stuff in response.
			 */
			__write_footprints = 1;
			footprints_out = fdopen(footprint_fd, "a");
			if (!footprints_out)
				{
					debug_printf(0, "Could not open footprints output stream for writing!\n");
				}

			if (footprints_spec_filename) {

				 footprints = parse_footprints_from_file(footprints_spec_filename, &footprints_env);
				 
			} else {
				 debug_printf(0, "no footprints spec filename provided\n", footprints_spec_filename);
			}

			
		} else {
			debug_printf(0, "fd %d is closed; skipping systemtap cross-check info.\n", footprint_fd);
		}

	}
	else
	{
		debug_printf(0, "skipping systemtap cross-check info\n");
	}

	debug_printf(0, "TRAP_SYSCALLS_TRACE_FD is %s, ", trace_fd_str);
	if (!trace_fd_str || trace_fd == 2) {
		debug_printf(0, "dup'ing stderr, ");
		trace_fd = dup(2);
	}
	
	if (trace_fd >= 0) {
		struct stat buf;
		int stat_ret = raw_fstat(trace_fd, &buf);
		if (stat_ret == 0) {
			debug_printf(0, "fd %d is open; outputting traces there.\n", trace_fd);
			__write_traces = 1;
			traces_out = fdopen(trace_fd, "a");
			if (!traces_out)
				{
					debug_printf(0, "Could not open traces output stream for writing!\n");
				}
		} else {
			debug_printf(0, "fd %d is closed; not outputting traces.\n", trace_fd);
		}
	} else {
		debug_printf(0, "not outputting traces.\n");
	}

	int fd = raw_open("/proc/self/maps", O_RDONLY);

	if (fd != -1)
	{
		// we use a simple buffer and a read loop
		char buf[8192];
		unsigned int ret;
		char *buf_pos = &buf[0]; // the next position to fill in the buffer
		char *entry_start_pos = &buf[0]; // the position
		size_t size_requested;
		do
		{
			// read some stuff, perhaps filling up the buffer
			size_requested = sizeof buf - (buf_pos - buf);
			ret = raw_read(fd, buf_pos, size_requested);
			char *buf_limit = buf_pos + ret;
			assert(buf_limit <= &buf[sizeof buf]);

			// we have zero or more complete entries in the buffer; iterate over them
			char *seek_pos;
			while (1)
			{
				seek_pos = entry_start_pos;
				// search forward for a newline
				while (seek_pos != buf_limit && *seek_pos != '\n')
				{ ++seek_pos; }

				// did we find one?
				if (seek_pos == buf_limit)
				{
					// no!
					// but we have a partial entry in the buffer
					// between entry_start_pos and seek_pos;
					// copy it to the start, re-set and continue
					__builtin_memmove(&buf[0], entry_start_pos, seek_pos - entry_start_pos);
					buf_pos = &buf[seek_pos - entry_start_pos];
					entry_start_pos = &buf[0];
					break;
				}
				else
				{
					assert(*seek_pos == '\n');
					// we have a complete entry; read it and advance entry_start_pos
					char debug_buf1[seek_pos - entry_start_pos + 1];
					strncpy(debug_buf1, entry_start_pos, seek_pos - entry_start_pos);
					debug_buf1[sizeof debug_buf1 - 1] = '\0';
					debug_printf(1, "DEBUG: entry is: %s\n", debug_buf1);
					char debug_buf2[buf_pos - buf];
					strncpy(debug_buf2, buf, buf_pos - buf);
					debug_buf2[sizeof debug_buf2 - 1] = '\0';
					debug_printf(1, "DEBUG: buffer is: %s", debug_buf2);
					saw_mapping(entry_start_pos, seek_pos);
					entry_start_pos = seek_pos + 1;
					// if the newline was the last in the buffer, break and read more
					if (entry_start_pos == buf_pos + sizeof buf)
					{ buf_pos = entry_start_pos = &buf[0]; break; }

					// else we might have another entry; go round again
					continue;
				}
			}
		} while (ret > 0);
		raw_close(fd);
	}

	/* Install our SIGILL (was SIGTRAP, but that interferes with gdb) handler.
	 * Linux seems to require us to provide a restorer; the code is in restore_rt. */
	struct sigaction action = {
		//.sa_sigaction = &handle_sigtrap,
		.sa_handler = &handle_sigill,
		.sa_mask = 0,
		.sa_flags = /*SA_SIGINFO |*/ 0x04000000u /* SA_RESTORER */ | /*SA_RESTART |*/ SA_NODEFER,
		.sa_restorer = restore_rt
	};
	struct sigaction oldaction;
	raw_rt_sigaction(SIGILL, &action, &oldaction);

	/* Un-executablize our own code, except for the signal handler and the remainder of
	 * this function and those afterwards.
	 *
	 * For this, we need our load address. How can we get this? We've already seen it! */
	// long int len = &&exit_and_return - our_text_begin_address;
	// long int ret;
	// long int longprot = PROT_NONE;
	// long int op = SYS_mprotect;

	//	__asm__ (".align 4096");
exit_and_return:
	//__asm__ volatile ("movq %0, %%rdi      # \n\
	//		   movq %1, %%rsi      # \n\
	//		   movq %2, %%rdx      # \n\
	//		  "FIX_STACK_ALIGNMENT " \n\
	//		   movq %3, %%rax      # \n\
	//		   syscall	     # do the syscall \n\
	//		  "UNFIX_STACK_ALIGNMENT " \n"
	//  : /* no output*/ : "rm"(our_text_begin_address), "rm"(len), "rm"(longprot), "rm"(op) :  "%rax", "r12", SYSCALL_CLOBBER_LIST);

#ifdef EXECUTABLE
	// HACK for testing: do a ud2 right now!
	ignore_ud2_addr = &&ud2_addr;
ud2_addr:
	__asm__ ("ud2\n");

	// we must also exit without running any libdl exit handlers,
	// because we're an executable so our csu/startfiles include some cleanup
	// that will now cause traps (this isn't necessary in the shared library case)
	raw_exit(0);
#endif
	return RETURN_VALUE;
}

// For debug printing inside handle_sigill we have to know
// that it's our own debug printing in order to filter it
// out of the footprints, hence this noinline function
// rather than using the normal macro
__attribute__ ((noinline)) static void _handle_sigill_debug_printf(int level, const char *fmt, ...) {
	 va_list vl;
	 va_start(vl, fmt);
	 if ((level) <= debug_level) {
		  vfprintf(*p_err_stream, fmt, vl);
		  fflush(*p_err_stream);
	 }
	 va_end(vl);
}
Exemple #22
0
char *STORAGE::DynamicMemoryMappedFile::readHeader() {
	char *header = raw_read(0, HEADER_SIZE, 0);
	return header;
}
Exemple #23
0
main(int argc, char *argv[]) {

RAW_FILE *fp;
struct rawdata dt, *raddat;
char filename[80];
int i,j;
long t1, t2, tstart, t;
short syr, smo, sday, shr, smin, ssec;
short eyr, emo, eday, ehr, emin, esec;
long status, offset;
FILE *outfile;
char ofile[80], line[80];

short int badlag[50];

raddat = &dt;

if (argc > 1) strcpy (filename, argv[1]);
else {
  printf("Enter the filename with no extension: ");
  scanf("%s",filename);
}

if (argc > 2) {
  strcpy (ofile, argv[2]);
  outfile = fopen(ofile,"w");
}
else outfile = stdout;

fp = rawropen(filename);

if (fp == 0) {
  printf("file: %s NOT FOUND\n",filename);
  errno = ENOENT;
  perror("testread: ");
  exit(ENOENT);
}

t1 = -1;  t2 = -1;

while (t1 < 0) {
  printf("Enter start time (yr, mo, day, hr, min, sec): ");
  sscanf(strcrep(fgets(line, sizeof(line), stdin),",/:",' '),
	"%hd%hd%hd%hd%hd%hd",&syr,&smo,&sday,&shr,&smin,&ssec);
  t1 = cnv_mdhms_sec(&syr, &smo, &sday, &shr, &smin, &ssec);
}

while (t2 < 0) {
  printf("Enter stop time (yr, mo, day, hr, min, sec): ");
  sscanf(strcrep(fgets(line, sizeof(line), stdin),",/:",' '),
	 "%hd%hd%hd%hd%hd%hd",&eyr,&emo,&eday,&ehr,&emin,&esec);
  t2 = cnv_mdhms_sec(&eyr, &emo, &eday, &ehr, &emin, &esec);
}

offset = find_raw_rec(t1, &tstart, fp);

if (offset < 0) {
  errno = EIO;
  perror("Invalid offset returned from find_raw_rec\n");
  exit(EIO);
}
else printf("offset from find_raw_rec = %d\n",offset);

/* mod for badlags */
status = raw_read(fp, offset, raddat);
do {
  status = raw_read(fp, 0, raddat);
} while ( (dt.PARMS.MPPUL != 9) && (dt.PARMS.MPINC != 1500));
for (i=0; i<dt.PARMS.NRANG; ++i) {
  dt.pwr0[i]= 0;
}
for (i=0; i<dt.PARMS.NRANG; ++i) {
  status= ckrng(i, badlag, raddat);
}

status = raw_read(fp, offset, raddat);
if (status == EOF) {
  errno = EIO;
  perror ("Bad status returned from first read operation\n");
  exit (EIO);
}

/* printf("status from first raw_read = %d\n",status); */

while (t <= t2 && status != EOF) {
  t = cnv_mdhms_sec(&dt.PARMS.YEAR, &dt.PARMS.MONTH, &dt.PARMS.DAY,
		    &dt.PARMS.HOUR, &dt.PARMS.MINUT, &dt.PARMS.SEC);
  fprintf(outfile,"%d = %4hd/%2hd/%2hd %2hd:%2hd:%2hd  bmnum: %2hd\n",
	  t,dt.PARMS.YEAR,dt.PARMS.MONTH,dt.PARMS.DAY,dt.PARMS.HOUR,
	  dt.PARMS.MINUT,dt.PARMS.SEC,dt.PARMS.BMNUM);
  fprintf(outfile,"FRANGE = %4hd, RSEP = %3hd, NOISE = %d\n",
	  dt.PARMS.FRANG, dt.PARMS.RSEP, dt.PARMS.NOISE);
  fprintf(outfile,"Lag-0 power:\n");
  for (i=0; i<dt.PARMS.NRANG; ++i) 
    fprintf(outfile,"%3d  %8d\n",i+1,dt.pwr0[i]);
  for (i=0; i<dt.PARMS.NRANG; ++i) {
    if (dt.acfd[i][0][0] == 0) continue;
    fprintf(outfile,"\nACF for range %d\n",i+1);
    for (j=0; j < dt.PARMS.MPLGS; ++j) {
      if (j % 3 == 0) fprintf(outfile,"\n");
      fprintf(outfile,"%2hd (%8d,%8d)     ",
	      dt.LAG_TABLE[1][j]-dt.LAG_TABLE[0][j],
	     dt.acfd[i][j][0],dt.acfd[i][j][1]);
    }
  }
  fprintf(outfile,"\n");
  status = raw_read(fp, 0, raddat);
}
printf("END OF TIME or END OF FILE\n");
}
Exemple #24
0
Status _elf_load_from_file(Pcb* pcb, const char* file_name)
{
	// Need to copy the file_name into kernel land...because we're killing userland!
	const char* temp = file_name;
	file_name = (const char *)__kmalloc(_kstrlen(temp) + 1);
	_kmemcpy((void *)file_name, (void *)temp, _kstrlen(temp)+1); // Copy the null terminator as well

	serial_printf("---Elf: attempting to open: %s\n", file_name);
	if (pcb == NULL || file_name == NULL) 
	{
		return BAD_PARAM;
	}

	// Try to open the file
	Elf32_Ehdr* elf32_hdr = (Elf32_Ehdr *)__kmalloc(sizeof(Elf32_Ehdr));

	serial_printf("ELF header location: %x\n", elf32_hdr);

	Uint bytes_read = 0;
	VFSStatus vfs_status =
		raw_read(file_name, (void *)elf32_hdr, &bytes_read, 0, sizeof(Elf32_Ehdr));

	if (vfs_status != FS_E_OK /* Couldn't read the file */
		   || bytes_read < sizeof(Elf32_Ehdr) /* Clearly not an ELF file */
		   || elf32_hdr->e_magic != ELF_MAGIC_NUM /* Need the magic number! */
		   || elf32_hdr->e_type != ET_EXEC /* Don't support relocatable or dynamic files yet */
		   || elf32_hdr->e_machine != EM_386 /* Make sure it's for our architecture */
		   || elf32_hdr->e_entry == 0x0 /* Need an entry point */
		   || elf32_hdr->e_version != EV_CURRENT /* We don't support extensions right now */
		   || elf32_hdr->e_phoff == 0 /* If there are no program headers, what do we load? */
		   || elf32_hdr->e_phnum == 0) /* ... */
		// || elf32_hdr->e_ehsize != sizeof(Elf32_Ehdr)) /* The header size should match our struct */
	{
		if (vfs_status != FS_E_OK) { serial_printf("RETURN VALUE: %x\n", vfs_status); _kpanic("ELF", "Failed to open file successfully\n", 0); }
		if (bytes_read < sizeof(Elf32_Ehdr)) _kpanic("ELF", "Read too small of a file!\n", 0);
		if (elf32_hdr->e_magic != ELF_MAGIC_NUM) _kpanic("ELF", "Bad magic number!\n", 0);
		if (elf32_hdr->e_type != ET_EXEC) _kpanic("ELF", "Not an executable ELF!\n", 0);
		if (elf32_hdr->e_machine != EM_386) _kpanic("ELF", "Not a i386 ELF!\n", 0);
		if (elf32_hdr->e_entry == 0x0) _kpanic("ELF", "Bad entry point!\n", 0);
		if (elf32_hdr->e_version != EV_CURRENT) _kpanic("ELF", "Don't support non-current versions!\n", 0);
		if (elf32_hdr->e_phoff == 0) _kpanic("ELF", "No program headers found!\n", 0);
		if (elf32_hdr->e_phnum == 0) _kpanic("ELF", "Zero program headers!\n", 0);

		_kpanic("ELF", "Couldn't open file!\n", 0);
		// Problem opening the file
		__kfree(elf32_hdr);
		return BAD_PARAM;
	}

	if (sizeof(Elf32_Phdr) != elf32_hdr->e_phentsize)
	{
		_kpanic("ELF", "program header size is different!\n", 0);
	}

	/* Okay lets start reading in and setting up the ELF file */	
	// We need a new buffer of size of (e_phentsize * e_phnum)
	Uint32 pheader_tbl_size = sizeof(Elf32_Phdr) * elf32_hdr->e_phnum;
	Elf32_Phdr* pheaders = (Elf32_Phdr *)__kmalloc(pheader_tbl_size);

	serial_printf("---ELF: program headers location: %x\n", pheaders);

	serial_printf("ELF: Reading program headers\n");
	vfs_status = raw_read(file_name, (void *)pheaders, &bytes_read,
			elf32_hdr->e_phoff, pheader_tbl_size);

	if (vfs_status != FS_E_OK 
			|| bytes_read < pheader_tbl_size)
	{
		_kpanic("ELF", "error reading file!\n", 0);
		__kfree(pheaders);
		__kfree(elf32_hdr);
		return BAD_PARAM;
	}

	serial_printf("ELF: resetting page directory\n");
	// Cleanup the old processes page directory, we're replacing everything
	__virt_reset_page_directory();

	serial_printf("ELF: About to read the program sections\n");
	/* We need to load all of the program sections now */
	for (Int32 i = 0; i < elf32_hdr->e_phnum; ++i)
	{
		Elf32_Phdr* cur_phdr = &(pheaders[i]);	

		if (cur_phdr->p_type == PT_LOAD)
		{
			if (cur_phdr->p_vaddr >= KERNEL_LINK_ADDR || cur_phdr->p_vaddr < 0x100000)
			{
				_kpanic("ELF", "An ELF with bad addresses loaded", 0);
			}

			serial_printf("\tELF: loading program section: %d at %x size: %x\n", i, cur_phdr->p_vaddr, cur_phdr->p_memsz);
			if (cur_phdr->p_memsz == 0)
			{
				serial_printf("\tELF: empty section, skipping\n");
				continue;
			}
			// This is a loadable section
			//if (cur_phdr->p_align > 1)
			//	_kpanic("ELF", "ELF loader doesn't support aligned program segments\n", 0);

			// Map these pages into memory!
			void* start_address = (void *)cur_phdr->p_vaddr;
			void* end_address   = (void *)(start_address + cur_phdr->p_memsz);
			for (; start_address < end_address; start_address += PAGE_SIZE)
			{
				Uint32 flags = PG_USER;
				if ((cur_phdr->p_flags & PF_WRITE) > 0)
				{
					flags |= PG_READ_WRITE;	
				}

				serial_printf("Checking address: %x\n", __virt_get_phys_addr(start_address));
				serial_printf("Start address: %x\n", start_address);
				if (__virt_get_phys_addr(start_address) == (void *)0xFFFFFFFF)
				{
					serial_printf("ELF: Mapping page: %x - flags: %x\n", start_address, flags);
					__virt_map_page(__phys_get_free_4k(), start_address, flags);
					serial_printf("ELF: Done mapping page\n");
				} else {
					serial_printf("Address: %x already mapped\n", start_address);
				}
			}

			serial_printf("ELF: about to memcpy program section: %x of size %d\n", cur_phdr->p_vaddr, cur_phdr->p_memsz);
			// Lets zero it out, we only need to zero the remaining bytes, p_filesz
			// may be zero for data sections, in this case the memory should be zeroed
			_kmemclr((void *)(cur_phdr->p_vaddr + (cur_phdr->p_memsz - cur_phdr->p_filesz)), 
					cur_phdr->p_memsz - cur_phdr->p_filesz);

			serial_printf("ELF: done memory copying: %s\n", file_name);

			// Now we have to read it in from the file
			if (cur_phdr->p_filesz > 0)
			{
				serial_printf("\tAt offset: %x\n", cur_phdr->p_offset);

				vfs_status = raw_read(file_name, (void *)cur_phdr->p_vaddr,
						&bytes_read, cur_phdr->p_offset, cur_phdr->p_filesz);
						
				serial_printf("Read: %d - File size: %d\n", bytes_read, cur_phdr->p_filesz);
				
				if (bytes_read != cur_phdr->p_filesz)
				{
					_kpanic("ELF", "Failed to read data from the filesystem", 0);
				}

				if (vfs_status != FS_E_OK)
				{
					// TODO - cleanup if error
					_kpanic("ELF", "failed to read program section\n", 0);
				}

				//asm volatile("hlt");
			}
		} else {
			serial_printf("\tELF: Non-loadable section: %d at %x size: %x type: %d\n", i, cur_phdr->p_vaddr, cur_phdr->p_memsz, cur_phdr->p_type);
		}
	}

	// Setup the PCB information

	// Allocate a stack and map some pages for it
#define USER_STACK_LOCATION 0x2000000
#define USER_STACK_SIZE 0x4000 /* 16 KiB */
	serial_printf("ELF: Allocating stack\n");
	void* stack_start = (void *)USER_STACK_LOCATION;
	void* stack_end   = (void *)(USER_STACK_LOCATION + USER_STACK_SIZE);
	for (; stack_start < stack_end; stack_start += PAGE_SIZE)
	{
		__virt_map_page(__phys_get_free_4k(), stack_start, PG_READ_WRITE | PG_USER);
	}
	_kmemclr((void *)USER_STACK_LOCATION, USER_STACK_SIZE);

	// Throw exit as the return address as a safe guard
	serial_printf("ELF: setting up context\n");
	// Setup the context
	Context* context = ((Context *)(USER_STACK_LOCATION+USER_STACK_SIZE-4)) - 1;
	serial_printf("Context location: %x\n", context);
	pcb->context = context;

	context->esp = (Uint32)(((Uint32 *)context) - 1);
	context->ebp = (USER_STACK_LOCATION+USER_STACK_SIZE)-4;
	context->cs = GDT_CODE;
	context->ss = GDT_STACK;
	context->ds = GDT_DATA;
	context->es = GDT_DATA;
	context->fs = GDT_DATA;
	context->gs = GDT_DATA;

	serial_printf("ELF: setting entry point: %x\n", elf32_hdr->e_entry);
 	// Entry point
	context->eip = elf32_hdr->e_entry;

	// Setup the rest of the PCB
	pcb->context->eflags = DEFAULT_EFLAGS;

	serial_printf("ELF: about to return\n");
	__kfree(pheaders);
	__kfree(elf32_hdr);
	__kfree((void *)file_name);
	return SUCCESS;
}
Exemple #25
0
/**
 * @ingroup midi
 *
 */
static bool parse(void) {
	uint8_t serial_data;
    if (!raw_read(&serial_data)) {
        // No data available.
        return false;
	}

#if 0
    console_putc('|'); console_puthex(serial_data); console_putc('|');
    return false;
#endif

	if (pending_message_index == (uint8_t) 0) {
		// Start a new pending message
		pending_message[0] = serial_data;

		// Check for running status first
		if (is_channel_message(get_type_from_status_byte(running_status_rx))) {
			// Only these types allow Running Status
			// If the status byte is not received, prepend it
			// to the pending message
			if (serial_data < 0x80) {
				pending_message[0] = running_status_rx;
				pending_message[1] = serial_data;
				pending_message_index = (uint8_t) 1;
			}
			// Else: well, we received another status byte,
			// so the running status does not apply here.
			// It will be updated upon completion of this message.
		}

		switch (get_type_from_status_byte(pending_message[0])) {
		// 1 byte messages
		case MIDI_TYPES_START:
		case MIDI_TYPES_CONTINUE:
		case MIDI_TYPES_STOP:
		case MIDI_TYPES_CLOCK:
		case MIDI_TYPES_ACTIVE_SENSING:
		case MIDI_TYPES_SYSTEM_RESET:
		case MIDI_TYPES_TUNE_REQUEST:
			// Handle the message type directly here.
			midi_message.type = get_type_from_status_byte(pending_message[0]);
			midi_message.channel = (uint8_t) 0;
			midi_message.data1 = (uint8_t) 0;
			midi_message.data2 = (uint8_t) 0;
			midi_message.bytes_count = (uint8_t) 1;
			//midi_message.valid = true;
			// \fix Running Status broken when receiving Clock messages.
			// Do not reset all input attributes, Running Status must remain unchanged.
			//resetInput();
			// We still need to reset these
			pending_message_index = (uint8_t) 0;
			pending_message_expected_lenght = (uint8_t) 0;
			return true;
			break;
		// 2 bytes messages
		case MIDI_TYPES_PROGRAM_CHANGE:
		case MIDI_TYPES_AFTER_TOUCH_CHANNEL:
		case MIDI_TYPES_TIME_CODE_QUARTER_FRAME:
		case MIDI_TYPES_SONG_SELECT:
			pending_message_expected_lenght = (uint8_t) 2;
			break;
		// 3 bytes messages
		case MIDI_TYPES_NOTE_ON:
		case MIDI_TYPES_NOTE_OFF:
		case MIDI_TYPES_CONTROL_CHANGE:
		case MIDI_TYPES_PITCH_BEND:
		case MIDI_TYPES_AFTER_TOUCH_POLY:
		case MIDI_TYPES_SONG_POSITION:
			pending_message_expected_lenght = (uint8_t) 3;
			break;
		case MIDI_TYPES_SYSTEM_EXCLUSIVE:
			// The message can be any lenght
			// between 3 and MIDI_SYSTEM_EXCLUSIVE_INDEX_ENTRIES
			pending_message_expected_lenght = MIDI_SYSTEM_EXCLUSIVE_INDEX_ENTRIES;
			running_status_rx = MIDI_TYPES_INVALIDE_TYPE;
			midi_message.system_exclusive[0] = MIDI_TYPES_SYSTEM_EXCLUSIVE;
			break;
		case MIDI_TYPES_INVALIDE_TYPE:
		default:
			// This is obviously wrong. Let's get the hell out'a here.
			reset_input();
			return false;
			break;
		}

		if (pending_message_index >= (pending_message_expected_lenght - (uint8_t) 1)) {
			// Reception complete
			midi_message.type = get_type_from_status_byte(pending_message[0]);
			midi_message.channel = get_channel_from_status_byte(pending_message[0]);
			midi_message.data1 = pending_message[1];

			// Save data2 only if applicable
			if (pending_message_expected_lenght == (uint8_t) 3) {
				midi_message.data2 = pending_message[2];
				midi_message.bytes_count = (uint8_t) 3;
			} else {
				midi_message.data2 = (uint8_t) 0;
				midi_message.bytes_count = (uint8_t) 2;
			}
			pending_message_index = (uint8_t) 0;
			pending_message_expected_lenght = (uint8_t) 0;
			//midi_message.valid = true;
			return true;
		} else {
			// Waiting for more data
			pending_message_index++;
		}

		if (USE_1_BYTE_PARSING) {
			// Message is not complete.
			return false;
		} else {
			// Call the parser recursively
			// to parse the rest of the message.
			return parse();
		}
	} else {
		// First, test if this is a status byte
		if (serial_data >= 0x80) {
			// Reception of status bytes in the middle of an uncompleted message
			// are allowed only for interleaved Real Time message or EOX
			switch (serial_data) {
			case MIDI_TYPES_CLOCK:
			case MIDI_TYPES_START:
			case MIDI_TYPES_CONTINUE:
			case MIDI_TYPES_STOP:
			case MIDI_TYPES_ACTIVE_SENSING:
			case MIDI_TYPES_SYSTEM_RESET:
				// Here we will have to extract the one-byte message,
				// pass it to the structure for being read outside
				// the MIDI class, and recompose the message it was
				// interleaved into. Oh, and without killing the running status..
				// This is done by leaving the pending message as is,
				// it will be completed on next calls.
				midi_message.type = serial_data;
				midi_message.data1 = 0;
				midi_message.data2 = 0;
				midi_message.channel = 0;
				midi_message.bytes_count = (uint8_t) 1;
				//midi_message.valid = true;
				return true;

				break;
				// End of Exclusive
			case 0xF7:
				if (midi_message.system_exclusive[0]
						== MIDI_TYPES_SYSTEM_EXCLUSIVE) {
					// Store the last byte (EOX)
					midi_message.system_exclusive[pending_message_index++] = 0xF7;
					midi_message.type = MIDI_TYPES_SYSTEM_EXCLUSIVE;
					// Get length
					midi_message.data1 = pending_message_index & 0xFF; // LSB
					midi_message.data2 = pending_message_index >> 8;   // MSB
					midi_message.channel = 0;
					midi_message.bytes_count = (uint8_t) 3;
					//midi_message.valid = true;

					reset_input();
					return true;
				} else {
					// Well well well.. error.
					reset_input();
					return false;
				}
				break;
			default:
				break;
			}
		}