コード例 #1
0
static void kbd_int(int irq, void *dummy, struct pt_regs *regs) {
	unsigned long flags;
	unsigned char scancode = 0;
	int i;

	static int upper = 0;

	cli();
	save_flags(flags);

	scancode = read_code();

	keyboard_stop();

	if (scancode == 0xf0 || scancode == 0xe0) {
		scancode = read_code();

	/* only capslock style at the moment */
	} else if ( scancode == 0x12 || scancode == 0x59) {
		upper = upper ? 0 : 1;
	}

	if(get_ascii(scancode) &&  !is_full()) {
		buf[in] = upper ? get_ASCII(scancode) : get_ascii(scancode);
		in = (in+1) % BUFLEN;
		wake_up(&keypress_wait);
	}

	keyboard_start();
	restore_flags(flags);
}
コード例 #2
0
ファイル: geekcode.c プロジェクト: masterdriverz/geekcode
static void run_code(const char *filename, FILE *in)
{
	unsigned ret, line_count;
	ret = read_code(in, &line_count);
	if (ret) {
		fprintf(stderr, "Error '%s' in file %s, line %u\n", parse_errors[ret], filename, line_count);
		exit(1);
	}
	output_answers(stdout);
}
コード例 #3
0
/** @brief  
  * 
  * @param args contains the parsed cmd-line options & arguments.
  * @param argc number of cmd-line arguments.
  * @param argv list of cmd-line arguments
  * @param optind index of the first non-option cmd-line argument.
  * 
  * @return exit status for main() to return.
  */
int foreach_parallel(struct cmdargs *args, int argc, char *argv[], int optind) {
  int tmp_fd = -1;
  char tmp_template[] = "/usr/tmp/foreach_parallel_XXXXXX";

  int ret;

  if (optind == argc) {
    fprintf(stderr, "%s: no input values provided.\n", getenv("_"));
    return EXIT_HELP;
  }

  /* no user-specified file - read stdin and put that into a
     tmp file */
  if (!args->file) {
    FILE *out;

    tmp_fd = mkstemp(tmp_template);
    if (tmp_fd < 0) {
      warn(args->file);
      return EXIT_FILE_ERR;
    }
    args->file = tmp_template;

    if (args->verbose) {
      printf("tmp fd: %d\ntmp name: %s\n", tmp_fd, args->file);
    }

    out = fopen(args->file, "w");
    ret = read_code(stdin, out);
    fclose(out);

    if (ret < 0) {
      fprintf(stderr, "%s: out of memory\n", getenv("_"));
      return EXIT_MEM_ERR;
    } else if (ret == 0) {
      fprintf(stderr, "%s: nothing to execute.\n", getenv("_"));
      return EXIT_HELP;
    }

  }

  ret = run_in_parallel(args->file, args, argc, argv, optind);

  /* see if these are pointing at the same string.  if so, we
     created a tmp file. */
  if (args->file == tmp_template)
    unlink(args->file);

  return ret;
}
コード例 #4
0
ファイル: ata_cmd.c プロジェクト: JackYangzg/sage
void init_dev_para()
{
	u8 idata tmp8;
	if((sata.fis_rcv_content[7] & 0x0F) != (max_head_per_cylnd-1))goto init_dev_para_err;
	if(sata.fis_rcv_content[12]!=max_sec_per_head)goto init_dev_para_err;
	tmp8 = read_code(0x006A+identify_data_addr);
	//The device shall also clear bit 0 of word 53 in the IDENTIFY DEVICE data to zero
	tmp8 = tmp8 | 0x01;
	enable_code_program;
    write_code(0x006A+identify_data_addr,tmp8);
	disable_code_program;
	tx_fis_34(status_good,error_no,int_set);
	return;
init_dev_para_err:
	tmp8 = read_code(0x006A+identify_data_addr);
	//The device shall also clear bit 0 of word 53 in the IDENTIFY DEVICE data to zero
	tmp8 = tmp8 & 0xfe;
	enable_code_program;
    write_code(0x006A+identify_data_addr,tmp8);
	disable_code_program;
	tx_fis_34(status_bad,error_abort,int_set);

}
コード例 #5
0
ファイル: main.c プロジェクト: zeinabkazemi/FRP-WCET
// program flow analysis to construct control flow graphs from objective code
static void
path_analysis(char *obj_file)
{
    // read object code, decode it
    read_code(obj_file);
    // create procs and their CFGs from the decoded text
    
    build_cfgs();
    // transform the CFGs into a global CFG called tcfg (transformed-cfg)
   
    prog_tran();
    // identify loop levels as well as block-loop mapping
   
    loop_process();
}
コード例 #6
0
ファイル: lh1_decoder.c プロジェクト: kacmem/zxtune
static size_t lha_lh1_read(void *data, uint8_t *buf)
{
    LHALH1Decoder *decoder = data;
    size_t result;
    uint16_t code;

    result = 0;

    // Read the next code from the input stream.

    if (!read_code(decoder, &code)) {
        return 0;
    }

    // The code either indicates a single byte to be output, or
    // it indicates that a block should be copied from the ring
    // buffer as it is a repeat of a sequence earlier in the
    // stream.

    if (code < 0x100) {
        output_byte(decoder, buf, &result, (uint8_t) code);
    } else {
        unsigned int count, start, i, pos, offset;

        // Read the offset into the history at which to start
        // copying.

        if (!read_offset(decoder, &offset)) {
            return 0;
        }

        count = code - 0x100U + COPY_THRESHOLD;
        start = decoder->ringbuf_pos - offset + RING_BUFFER_SIZE - 1;

        // Copy from history into output buffer:

        for (i = 0; i < count; ++i) {
            pos = (start + i) % RING_BUFFER_SIZE;

            output_byte(decoder, buf, &result,
                        decoder->ringbuf[pos]);
        }
    }

    return result;
}
コード例 #7
0
ファイル: thinnx.c プロジェクト: BackupTheBerlios/freenx-svn
/* Handle session start information */  
gchar *
get_session_info (gint out, gchar *code)
{
  gchar *buffer;
  gchar *retval;

  buffer = read_code (out);
  if (!strcmp (buffer, code))
    {
      flush_buffer (buffer);
      buffer = read_line (out);
      retval = get_info_after_colon (buffer);
      g_free (buffer);
      return retval;
    }

  g_warning ("Waiting for %s, got %s\n", code, buffer);
  protocol_error ("session info!");
  return NULL;
}
コード例 #8
0
ファイル: lh_new_decoder.c プロジェクト: djdron/zxtune
static size_t lha_lh_new_read(void *data, uint8_t *buf)
{
	LHANewDecoder *decoder = data;
	size_t result;
	int code;

	// Start of new block?

	while (decoder->block_remaining == 0) {
		if (!start_new_block(decoder)) {
			return 0;
		}
	}

	--decoder->block_remaining;

	// Read next command from input stream.

	result = 0;

	code = read_code(decoder);

	if (code < 0) {
		return 0;
	}

	// The code may be either a literal byte value or a copy command.

	if (code < 256) {
		output_byte(decoder, buf, &result, (uint8_t) code);
	} else {
		copy_from_history(decoder, buf, &result,
		                  code - 256 + COPY_THRESHOLD);
	}

	return result;
}
コード例 #9
0
ファイル: ata_cmd.c プロジェクト: JackYangzg/sage
///////////////////////////////////////////////////////////////////////
//load identify data from code area to SUP 32K FIFO. 
//Then send to SATA host.
///////////////////////////////////////////////////////////////////////
void identify_device()
{
	u16 i =0;
	u8 tmp,tmp1;
	u16_t tmp2;
    
    //clear_dma_run;
    //reset_dma_engine();
        
	//prepare data, read it from code area
	SFR_ext_sram_addr = 0x0000;
	SFR_ext_sram_cntl = 0x10;	//enable auto increese of the sram address
	g_tmp_addr = identify_data_addr;
    for(i=0;i<512;i++)
    {
	    SFR_ext_sram_data = read_code(g_tmp_addr);
        g_tmp_addr ++; 
    }
    
    #ifdef SUPPORT_SECURITY
    if(security_mode == show_master)//48GB
    {
        SFR_ext_sram_addr = 0x0078;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x06;

        SFR_ext_sram_addr = 0x00C8;  //identify word 100-103
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x06;

	g_tmp_addr = identify_data_addr+0xad;//28bits or 48bits
	tmp1=read_code(g_tmp_addr);
	tmp1=tmp1&0xFB;//28bits
      SFR_ext_sram_addr = 0x00ad;
      SFR_ext_sram_data=tmp1;
    }	
	else if(security_mode == show_user) //24GB
    {
        SFR_ext_sram_addr = 0x0078;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0xEE;
        SFR_ext_sram_data = 0x02;

        SFR_ext_sram_addr = 0x00C8;  //identify word 100-103
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0xEE;
        SFR_ext_sram_data = 0x02;

	g_tmp_addr = identify_data_addr+0xad;//28bits or 48bits
	tmp1=read_code(g_tmp_addr);
	tmp1=tmp1&0xFB;//28bits
      SFR_ext_sram_addr = 0x00ad;
      SFR_ext_sram_data=tmp1;
    }	
	
    #endif

	#ifdef security_debug_chs
	g_tmp_addr = identify_data_addr+0x2;//number of logical cylinders
	tmp2.byte.h=read_code(g_tmp_addr);
	g_tmp_addr = identify_data_addr+0x3;//number of logical cylinders
	tmp2.byte.l=read_code(g_tmp_addr);
	myprintf("\ncylinders:%x%x",tmp2.byte.h,tmp2.byte.l);

	g_tmp_addr = identify_data_addr+0x6;//number of logical heads
	tmp2.byte.h=read_code(g_tmp_addr);
	g_tmp_addr = identify_data_addr+0x7;//number of logical heads
	tmp2.byte.l=read_code(g_tmp_addr);
	myprintf("\nheads:%x%x",tmp2.byte.h,tmp2.byte.l);

	g_tmp_addr = identify_data_addr+0xC;//sectors per track
	tmp2.byte.h=read_code(g_tmp_addr);
	g_tmp_addr = identify_data_addr+0xD;//sectors per track
	tmp2.byte.l=read_code(g_tmp_addr);
	myprintf("\nsectors:%x%x",tmp2.byte.h,tmp2.byte.l);
	
	#endif
		
    SFR_ext_sram_addr = 0x0104;   //siganature
    SFR_ext_sram_data = 0x53;  //S
    SFR_ext_sram_data = 0x41;  //A
    SFR_ext_sram_data = 0x47;  //G
    SFR_ext_sram_data = 0x45;  //E
	SFR_ext_sram_cntl = 0x00;	//disable auto increae of the sram address
	
	
	
	
	tmp = gen_check_sum();
	SFR_ext_sram_addr = 0x01ff;
	SFR_ext_sram_data = tmp;

	//send PIO_SETUP_FIS
	tx_fis_5f(status_drq, error_no, pm_pio_read, 0x01, 0x00, status_good);
	//burst it to sata host
	sata_burst(PIO_READ,0x01);
    if(sata_burst_abort)
    {
        tx_fis_34(status_bad,error_abort,int_set);
        reset_engine();
        #ifdef SUPPORT_SMART1
        updata_smart(smart_crc_num_addr,0x01);
        reset_engine();
        #endif
	    return;
    }
}
コード例 #10
0
ファイル: superwordprof.c プロジェクト: Jeffxz/nodeas
int main(int argc, char** argv) 
{
    int i;

    for ( i=0 ; i < INSTRCOUNT ; i++ ) {
	toplevel[i].opcode = i;
	toplevel[i].count = 0;
	toplevel[i].left_child = NULL;
	toplevel[i].right_sibling = NULL;
	jumps[i] = 0;
	operands[i] = 0;
	iname[i] = "***";
    }
    jumps[OP_throw] = 1;
    jumps[OP_ifnlt] = 1;
    jumps[OP_ifnle] = 1;
    jumps[OP_ifngt] = 1;
    jumps[OP_ifnge] = 1;
    jumps[OP_jump] = 1;
    jumps[OP_iftrue] = 1;
    jumps[OP_iffalse] = 1;
    jumps[OP_ifeq] = 1;
    jumps[OP_ifne] = 1;
    jumps[OP_iflt] = 1;
    jumps[OP_ifle] = 1;
    jumps[OP_ifgt] = 1;
    jumps[OP_ifge] = 1;
    jumps[OP_ifstricteq] = 1;
    jumps[OP_ifstrictne] = 1;
    jumps[OP_lookupswitch] = 1;
    jumps[OP_returnvoid] = 1;
    jumps[OP_returnvalue] = 1;

    /* The operand count here is not important for correctness.  0 is
     * always a safe answer, and a too high number will result in an
     * out-of-bounds reference only occasionally :-P
     *
     * Getting the operand count right makes for better analysis,
     * though.
     */
    DEF(OP_bkpt, 0);
    DEF(OP_throw, 0);
    DEF(OP_getsuper, 1);
    DEF(OP_setsuper, 1);
    DEF(OP_dxns, 1);
    DEF(OP_dxnslate, 0);
    DEF(OP_kill, 1);
    DEF(OP_ifnlt, 1);
    DEF(OP_ifnle, 1);
    DEF(OP_ifngt, 1);
    DEF(OP_ifnge, 1);
    DEF(OP_jump, 1);
    DEF(OP_iftrue, 1);
    DEF(OP_iffalse, 1);
    DEF(OP_ifeq, 1);
    DEF(OP_ifne, 1);
    DEF(OP_iflt, 1);
    DEF(OP_ifle, 1);
    DEF(OP_ifgt, 1);
    DEF(OP_ifge, 1);
    DEF(OP_ifstricteq, 1);
    DEF(OP_ifstrictne, 1);
    DEF(OP_lookupswitch, 2);
    DEF(OP_pushwith, 0);
    DEF(OP_popscope, 0);
    DEF(OP_nextname, 0);
    DEF(OP_hasnext, 0);
    DEF(OP_pushnull, 0);
    DEF(OP_pushundefined, 0);
    DEF(OP_nextvalue, 0);
    DEF(OP_pushtrue, 0);
    DEF(OP_pushfalse, 0);
    DEF(OP_pushnan, 0);
    DEF(OP_pop, 0);
    DEF(OP_dup, 0);
    DEF(OP_swap, 0);
    DEF(OP_pushstring, 1);
    DEF(OP_pushdouble, 1);
    DEF(OP_pushscope, 0);
    DEF(OP_pushnamespace, 1);
    DEF(OP_hasnext2, 2);
    DEF(OP_newfunction, 1);
    DEF(OP_call, 1);
    DEF(OP_construct, 1);
    DEF(OP_callmethod, 2);
    DEF(OP_callstatic, 2);
    DEF(OP_callsuper, 2);
    DEF(OP_callproperty, 2);
    DEF(OP_returnvoid, 0);
    DEF(OP_returnvalue, 0);
    DEF(OP_constructsuper, 1);
    DEF(OP_constructprop, 1);
    DEF(OP_callproplex, 1);
    DEF(OP_callsupervoid, 2);
    DEF(OP_callpropvoid, 2);
    DEF(OP_applytype, 1);
    DEF(OP_newobject, 1);
    DEF(OP_newarray, 1);
    DEF(OP_newactivation, 0);
    DEF(OP_newclass, 1);
    DEF(OP_getdescendants, 1);
    DEF(OP_newcatch, 1);
    DEF(OP_findpropstrict, 1);
    DEF(OP_findproperty, 1);
    DEF(OP_finddef, 1);
    DEF(OP_getlex, 1);
    DEF(OP_setproperty, 1);
    DEF(OP_getlocal, 1);
    DEF(OP_setlocal, 1);
    DEF(OP_getglobalscope, 0);
    DEF(OP_getscopeobject, 1);
    DEF(OP_getproperty, 1);
    DEF(OP_getouterscope, 1);
    DEF(OP_initproperty, 1);
    DEF(OP_deleteproperty, 1);
    DEF(OP_getslot, 1);
    DEF(OP_setslot, 1);
    DEF(OP_getglobalslot, 1);
    DEF(OP_setglobalslot, 1);
    DEF(OP_convert_s, 0);
    DEF(OP_esc_xelem, 0);
    DEF(OP_esc_xattr, 0);
    DEF(OP_convert_i, 0);
    DEF(OP_convert_u, 0);
    DEF(OP_convert_d, 0);
    DEF(OP_convert_b, 0);
    DEF(OP_convert_o, 0);
    DEF(OP_checkfilter, 0);
    DEF(OP_coerce, 1);
    DEF(OP_coerce_b, 0);
    DEF(OP_coerce_a, 0);
    DEF(OP_coerce_i, 0);
    DEF(OP_coerce_d, 0);
    DEF(OP_coerce_s, 0);
    DEF(OP_astype, 1);
    DEF(OP_astypelate, 0);
    DEF(OP_coerce_u, 0);
    DEF(OP_coerce_o, 0);
    DEF(OP_negate, 0);
    DEF(OP_increment, 0);
    DEF(OP_inclocal, 1);
    DEF(OP_decrement, 0);
    DEF(OP_declocal, 1);
    DEF(OP_typeof, 0);
    DEF(OP_not, 0);
    DEF(OP_bitnot, 0);
    DEF(OP_add, 0);
    DEF(OP_subtract, 0);
    DEF(OP_multiply, 0);
    DEF(OP_divide, 0);
    DEF(OP_modulo, 0);
    DEF(OP_lshift, 0);
    DEF(OP_rshift, 0);
    DEF(OP_urshift, 0);
    DEF(OP_bitand, 0);
    DEF(OP_bitor, 0);
    DEF(OP_bitxor, 0);
    DEF(OP_equals, 0);
    DEF(OP_strictequals, 0);
    DEF(OP_lessthan, 0);
    DEF(OP_lessequals, 0);
    DEF(OP_greaterthan, 0);
    DEF(OP_greaterequals, 0);
    DEF(OP_instanceof, 0);
    DEF(OP_istype, 1);
    DEF(OP_istypelate, 0);
    DEF(OP_in, 0);
    DEF(OP_increment_i, 0);
    DEF(OP_decrement_i, 0);
    DEF(OP_inclocal_i, 1);
    DEF(OP_declocal_i, 1);
    DEF(OP_negate_i, 0);
    DEF(OP_add_i, 0);
    DEF(OP_subtract_i, 0);
    DEF(OP_multiply_i, 0);
    DEF(OP_getlocal0, 0);
    DEF(OP_getlocal1, 0);
    DEF(OP_getlocal2, 0);
    DEF(OP_getlocal3, 0);
    DEF(OP_setlocal0, 0);
    DEF(OP_setlocal1, 0);
    DEF(OP_setlocal2, 0);
    DEF(OP_setlocal3, 0);
    DEF(OP_debugline, 1);
    DEF(OP_debugfile, 1);
    DEF(OP_bkptline, 1);
    DEF(OP_ext_pushbits, 1);
    DEF(OP_ext_push_doublebits, 2);

    progname = argv[0];

    i=1;
    while (i < argc && argv[i][0] == '-') {
	if (strcmp(argv[i], "-c") == 0) {
	    if (i+1 == argc || sscanf(argv[i+1], "%d", &cutoff_count) != 1) {
		i=argc;
		break;
	    }
	    i += 2;
	}
	else if (strcmp(argv[i], "-l") == 0) {
	    if (i+1 == argc || sscanf(argv[i+1], "%d", &cutoff_length) != 1) {
		i=argc;
		break;
	    }
	    i += 2;
	}
	else if (strcmp(argv[i], "-f") == 0) {
	    flat = 1;
	    i++;
	}
	else if (strcmp(argv[i], "-h") == 0) {
	    hierarchical = 0;
	    i++;
	}
	else if (strcmp(argv[i], "-o") == 0) {
	    operand_tracking = 1;
	    i++;
	}
	else if (strcmp(argv[i], "-v") == 0) {
	    verbose = 1;
	    i++;
	}
	else {
	    i = argc;
	    break;
	}
    }
 
    if (i > argc-2 || (argc - i) % 2 != 0) {
	fprintf(stderr, "Usage: %s [options] ( code_file sample_file ) ... \n\n", progname);
	fprintf(stderr, "Options:\n");
	fprintf(stderr, "  -c n     Set sample cutoff = n (default 100)\n");
	fprintf(stderr, "  -l n     Set length cutoff = n (default unbounded)\n");
	fprintf(stderr, "  -f       Enable flat report\n");
	fprintf(stderr, "  -h       Disable hierarchical report\n");
	fprintf(stderr, "  -o       Operand tracking\n");
	fprintf(stderr, "  -v       Verbose");
	return 1;
    }

    while (i < argc) {
	read_code(argv[i]);
	read_samples(argv[i+1]);
	i += 2;
	scale++;
    }
    extract_superwords();

    return 0;
}
コード例 #11
0
ファイル: upp.c プロジェクト: mafheldt/usbpicprog
void ProcessIO(void)
{
	char oldPGDtris;
	char PIN;
	static byte counter=0;
	int nBytes;
	unsigned long address;
	
	// When the device is plugged in, the leds give the numbers 1, 2, 3, 4, 5. 
	//After configured state, the leds are controlled by the next lines in this function
	if((usb_device_state < CONFIGURED_STATE)||(UCONbits.SUSPND==1))
	{
		BlinkUSBStatus();
		return;
	}
	

	nBytes=USBGenRead((byte*)input_buffer,64);
	if(nBytes>0)
	{
		switch(input_buffer[0])
		{
			case CMD_ERASE:
				setLeds(LEDS_ON | LEDS_WR);
				output_buffer[0]=bulk_erase(picfamily,pictype,input_buffer[1]);
				counter=1;
				setLeds(LEDS_ON);
				break;
			case CMD_READ_ID:
				setLeds(LEDS_ON | LEDS_RD);
				switch(picfamily)
				{
					case PIC24:
					case dsPIC30:
						read_code(picfamily,pictype,0xFF0000,(unsigned char*)output_buffer,2,3);
						break;
					case PIC18:
					case PIC18J:
					case PIC18K:
						read_code(picfamily,pictype,0x3FFFFE,(unsigned char*)output_buffer,2,3);  //devid is at location 0x3ffffe   for PIC18 devices
						break;
					case PIC16:
						set_vdd_vpp(picfamily, pictype, 0);
						read_code(picfamily,pictype,0x2006,(unsigned char*)output_buffer,2,3);  //devid is at location 0x2006  for PIC16 devices
						break;
				}
				counter=2;
				setLeds(LEDS_ON);
				break;
			case CMD_WRITE_CODE:
				setLeds(LEDS_ON | LEDS_WR);
				address=((unsigned long)input_buffer[2])<<16|
						((unsigned long)input_buffer[3])<<8|
						((unsigned long)input_buffer[4]);
				output_buffer[0]=write_code(picfamily,pictype,address, (unsigned char*)(input_buffer+6),input_buffer[1],input_buffer[5]);
				counter=1;
				setLeds(LEDS_ON);
				break;
			case CMD_READ_CODE:
				setLeds(LEDS_ON | LEDS_RD);
				address=((unsigned long)input_buffer[2])<<16|
						((unsigned long)input_buffer[3])<<8|
						((unsigned long)input_buffer[4]);
				PIN=read_code(picfamily,pictype,address,(unsigned char*)output_buffer,input_buffer[1],input_buffer[5]);
				if(PIN==3)output_buffer[0]=0x3;
				counter=input_buffer[1];
				setLeds(LEDS_ON);
				break;
			case CMD_WRITE_DATA:
				setLeds(LEDS_ON | LEDS_WR);
				address=((unsigned long)input_buffer[2])<<16|
						((unsigned long)input_buffer[3])<<8|
						((unsigned long)input_buffer[4]);
				output_buffer[0]=write_data(picfamily,pictype,address, (unsigned char*)(input_buffer+6),input_buffer[1],input_buffer[5]); 
				counter=1;
				setLeds(LEDS_ON);
				break;
			case CMD_READ_DATA:
				setLeds(LEDS_ON | LEDS_RD);
				address=((unsigned long)input_buffer[2])<<16|
						((unsigned long)input_buffer[3])<<8|
						((unsigned long)input_buffer[4]);
				read_data(picfamily,pictype,address,(unsigned char*)output_buffer,input_buffer[1],input_buffer[5]); 
				counter=input_buffer[1];
				setLeds(LEDS_ON);
				break;
			case CMD_WRITE_CONFIG:
				setLeds(LEDS_ON | LEDS_WR);
				address=((unsigned long)input_buffer[2])<<16|
						((unsigned long)input_buffer[3])<<8|
						((unsigned long)input_buffer[4]);
				output_buffer[0]=write_config_bits(picfamily, pictype, address, (unsigned char*)(input_buffer+6),input_buffer[1],input_buffer[5]);
				counter=1;
				setLeds(LEDS_ON);
				break;
			case CMD_SET_PICTYPE:
				output_buffer[0]=set_pictype(input_buffer+1);
				//output_buffer[0]=1; //Ok
				counter=1;
				setLeds(LEDS_ON);
				break;
			case CMD_FIRMWARE_VERSION:
				strcpypgm2ram((char*)output_buffer,(const far rom char*)upp_version);
				counter=18;
				setLeds(LEDS_ON);

				break;
			case CMD_DEBUG:
				setLeds(LEDS_ON | LEDS_WR | LEDS_RD);
				switch(input_buffer[1])
				{
					case 0:
						set_vdd_vpp(dsP30F, dsPIC30, 1);
						output_buffer[0]=1;
						counter=1;	
						break;
					case 1:
						set_vdd_vpp(dsP30F, dsPIC30, 0);
						output_buffer[0]=1;
						counter=1;	
						break;
					case 2:
						dspic_send_24_bits(((unsigned long)input_buffer[2])|
								((unsigned long)input_buffer[3])<<8|
								((unsigned long)input_buffer[4])<<16);
						output_buffer[0]=1;
						counter=1;
						break;
					case 3:
						nBytes =  dspic_read_16_bits(1);
						output_buffer[0]=(unsigned char)nBytes;
						output_buffer[1]=(unsigned char)(nBytes>>8);
						counter=2;
						break;
						
				}
				break;
			case CMD_GET_PIN_STATUS:
				switch(input_buffer[1])
				{
					case SUBCMD_PIN_PGC:
						if((!TRISPGC_LOW)&&(!PGC_LOW)) //3.3V levels
						{
							if(PGC) output_buffer[0] = PIN_STATE_3_3V;
							else output_buffer[0] = PIN_STATE_0V;
						}
						else	//5V levels
						{
							if(PGC) output_buffer[0] = PIN_STATE_5V;
							else output_buffer[0] = PIN_STATE_0V;
						}
						counter=1;
						break;
					case SUBCMD_PIN_PGD:
						if(TRISPGD)//PGD is input
						{
							if(PGD_READ) output_buffer[0] = PIN_STATE_5V;
							else output_buffer[0] = PIN_STATE_0V;
						}
						else
						{							
							if((!TRISPGD_LOW)&&(!PGD_LOW)) //3.3V levels
							{
								if(PGD) output_buffer[0] = PIN_STATE_3_3V;
								else output_buffer[0] = PIN_STATE_0V;
							}
							else	//5V levels
							{
								if(PGD) output_buffer[0] = PIN_STATE_5V;
								else output_buffer[0] = PIN_STATE_0V;
							}
						}
						counter=1;
						break;
					case SUBCMD_PIN_VDD:
						if(VDD) output_buffer[0] = PIN_STATE_FLOAT;
						else output_buffer[0] = PIN_STATE_5V;
						counter = 1;
						break;
					case SUBCMD_PIN_VPP:
						counter=1;
						if(!VPP){output_buffer[0] = PIN_STATE_12V;break;}
						if(VPP_RST){output_buffer[0] = PIN_STATE_0V;break;}
						if(VPP_RUN){output_buffer[0] = PIN_STATE_5V;break;}
						output_buffer[0] = PIN_STATE_FLOAT;
						break;
					case SUBCMD_PIN_VPP_VOLTAGE:
						ReadAdc(output_buffer);
						counter=2;
						break;
					default:
						output_buffer[0]=3;
						counter=1;
						break;
				}
				break;
			case CMD_SET_PIN_STATUS:
				switch(input_buffer[1])
				{
					case SUBCMD_PIN_PGC:
						switch(input_buffer[2])
						{
							case PIN_STATE_0V:
								TRISPGC = 0;
								PGC = 0;
								TRISPGC_LOW = 1;
								PGC_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_3_3V:
								TRISPGC = 0;
								PGC = 1;
								TRISPGC_LOW = 0;
								PGC_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_5V:
								TRISPGC = 0;
								PGC = 1;
								TRISPGC_LOW = 1;
								PGC_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							default:
								output_buffer[0]=3;
								break;
						}
						break;
					case SUBCMD_PIN_PGD:
						switch(input_buffer[2])
						{
							case PIN_STATE_0V:
								TRISPGD = 0;
								PGD = 0;
								TRISPGD_LOW = 1;
								PGD_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_3_3V:
								TRISPGD = 0;
								PGD = 1;
								TRISPGD_LOW = 0;
								PGD_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_5V:
								TRISPGD = 0;
								PGD = 1;
								TRISPGD_LOW = 1;
								PGD_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_INPUT:
								TRISPGD_LOW = 1;
								TRISPGD = 1;
								output_buffer[0]=1;//ok
								break;
							default:
								output_buffer[0]=3;
								break;
						}
						break;
					case SUBCMD_PIN_VDD:
						switch(input_buffer[2])
						{
							case PIN_STATE_5V:
								VDD = 0;
								output_buffer[0]=1;
								break;
							case PIN_STATE_FLOAT:
								VDD = 1;
								output_buffer[0]=1;
								break;
							default:
								output_buffer[0]=3;
								break;
						}
						break;
					case SUBCMD_PIN_VPP:
						switch(input_buffer[2])
						{
							case PIN_STATE_0V:
								VPP = 1;
								VPP_RST = 1;
								VPP_RUN = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_5V:
								VPP = 1;
								VPP_RST = 0;
								VPP_RUN = 1;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_12V:
								VPP = 0;
								VPP_RST = 0;
								VPP_RUN = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_FLOAT:
								VPP = 1;
								VPP_RST = 0;
								VPP_RUN = 0;
								output_buffer[0]=1;//ok
								break;
							default:
								output_buffer[0]=3;
								break;
						}
						break;
					default:
						output_buffer[0]=3;
				}
				counter=1;
				break;
		}
	}
	if(counter != 0)
	{
		if(!mUSBGenTxIsBusy())
		USBGenWrite((byte*)&output_buffer,counter);
		counter=0;
	}
}//end ProcessIO
コード例 #12
0
ファイル: ata_cmd.c プロジェクト: JackYangzg/sage
void set_feature()
{
	BYTE tmp;
	tmp = sata.FIS_seccnt;
	switch(sata.FIS_feature)
	{
	    case enable_write_cache:
		{       
			    g_enable_write_cache = 1;
				tmp = read_code(0x00aa+identify_data_addr);
		        tmp = tmp | 0x20;
			    enable_code_program;
                write_code(0x00aa+identify_data_addr,tmp);  //enable
                disable_code_program;
				break;
		}
		
		case disable_write_cache:
	    {       
				g_enable_write_cache = 0;
				tmp = read_code(0x00aa+identify_data_addr);//and  need  a  flag  here  to  disable  buf_cmd?
		        tmp = tmp & 0xdf;
				enable_code_program;
				write_code(0x00aa+identify_data_addr,tmp);  //disable
			    disable_code_program;
				break;
		}
		
		case mode_transfer:
		{
			if(tmp & mode_ultra_dma) //ultra dma mode
			{
				tmp = tmp & 0x07;
				tmp = 0x01 << tmp;
				enable_code_program;
                write_code(0x00B1+identify_data_addr,tmp);
				write_code(0x007F+identify_data_addr,0x00);
				disable_code_program;
			}
			else if(tmp & mode_mul_dma) //mulitword dma mode
			{
			    tmp = tmp & 0x07;
				tmp = 0x01 << tmp;
				enable_code_program;
                write_code(0x007F+identify_data_addr,tmp);
				write_code(0x00B1+identify_data_addr,0x00);
				disable_code_program;
			}
			else if((tmp & 0xf8)==0)  //default pio mode ;; todo: I don't konw what iordy is ,	so do nothing with it		
		    {
                /*
				enable_code_program;
				write_code(0x0080+identify_data_addr,0x01);//default pio mode is mode 1
				disable_code_program;
				*/

			}
			else if(tmp & mode_pio_tran)// since PIO mode set may disturb host to send PIO read/write only , we close it
			{
			    /*
                         tmp = tmp & 0x07;
				tmp = 0x01 << tmp;
				tmp1= tmp;
				tmp = tmp - 1;
				tmp += tmp1;
				enable_code_program;
                          write_code(0x0080+identify_data_addr,tmp);
				disable_code_program;
				*/
			}
			break;
		}

	    case enable_adv_power_manage:
		{       
				tmp = read_code(0x00ac+identify_data_addr);
		        tmp = tmp | 0x08;
			    enable_code_program;
                write_code(0x00ac+identify_data_addr,tmp);  //enable
                disable_code_program;
				break;
		}

		case disable_adv_power_manage:
		{		
				tmp = read_code(0x00ac+identify_data_addr);
				tmp = tmp & 0xf7;
				enable_code_program;
				write_code(0x00ac+identify_data_addr,tmp);	//enable
				disable_code_program;
				break;
		}

		case enable_power_up_standby:
		{		
				tmp = read_code(0x00ac+identify_data_addr);
				tmp = tmp | 0x20;
				enable_code_program;
				write_code(0x00ac+identify_data_addr,tmp);	//enable
				disable_code_program;
				break;
		}

		case disable_power_up_standby:
		{		
				tmp = read_code(0x00ac+identify_data_addr);
				tmp = tmp & 0xdf;
				enable_code_program;
				write_code(0x00ac+identify_data_addr,tmp);	//enable
				disable_code_program;
				break;
		}

		case enable_rw_verify:
		{		
				tmp = read_code(0x00f0+identify_data_addr);
				tmp = tmp | 0x02;
				enable_code_program;
				write_code(0x00f0+identify_data_addr,tmp);	//enable
				disable_code_program;
				break;
		}

        case disable_rw_verify:
		{		
				tmp = read_code(0x00f0+identify_data_addr);
				tmp = tmp & 0xfd;
				enable_code_program;
				write_code(0x00f0+identify_data_addr,tmp);	//enable
				disable_code_program;
				break;
		}

		case enable_look_ahead:
		{		
				tmp = read_code(0x00aa+identify_data_addr);
				tmp = tmp | 0x40;
				enable_code_program;
				write_code(0x00aa+identify_data_addr,tmp);	//enable
				disable_code_program;
				break;
		}

        case disable_look_ahead:
		{		
				tmp = read_code(0x00aa+identify_data_addr);
				tmp = tmp & 0xbf;
				enable_code_program;
				write_code(0x00aa+identify_data_addr,tmp);	//enable
				disable_code_program;
				break;
		}

		case enable_auto_acoustic_manage:
		{		
				tmp = read_code(0x00ad+identify_data_addr);
				tmp = tmp | 0x02;
				enable_code_program;
				write_code(0x00ad+identify_data_addr,tmp);	//enable
				disable_code_program;
				break;
		}

        case disable_auto_acoustic_manage:
		{		
				tmp = read_code(0x00ad+identify_data_addr);
				tmp = tmp & 0xfd;
				enable_code_program;
				write_code(0x00ad+identify_data_addr,tmp);	//enable
				disable_code_program;
				break;
		}

		case enable_revert_pow_default:
		{		
				break;
		}		

        case disable_revert_pow_default:
		{		
				break;
		}

		case disable_sata_feature:
		{
			    break;
		}
		default :
		{
			    tx_fis_34(status_bad,error_abort,int_set);
				return;
		}		
	}
	tx_fis_34(status_good,error_no,int_set);
}
コード例 #13
0
ファイル: thinnx.c プロジェクト: BackupTheBerlios/freenx-svn
int
main (int argc, char **argv)
{
  gchar *confdir;

  gchar *host = g_strdup ("localhost");
  gchar *port = g_strdup ("22");
  gchar *sshkey = NULL;

  gchar *user = NULL;
  gchar *password = NULL;

  gchar *session = g_strdup ("thinnx");
  gchar *type = g_strdup ("unix-gnome");
  gchar *cookie = NULL;

  gboolean use_ssl = 0;

  gchar *link = g_strdup ("adsl");
  gchar *kbdtype = g_strdup ("pc104/us");

  gchar *geometry = g_strdup ("fullscreen");
  gchar *screeninfo = NULL;

  gchar *session_id = NULL;
  gchar *session_display = NULL;
  gchar *pcookie = NULL;
  
  gchar **nxssh_argv = (gchar**) g_malloc (sizeof(gchar*) * 9);

  gchar *restore_id = NULL;

  pid_t pid;

  int parent_pipe[2];	/* For talking to the parent */
  int child_pipe[2];	/* For talking to the child */

  gint in = 0, out = 0;

  gtk_init (&argc, &argv);

  homedir = g_get_home_dir ();
  confdir = g_strdup_printf ("%s/.nx/", homedir);
  sshkey = g_strdup_printf ("%s/.ssh/id_dsa", homedir);

  {
    struct stat info;
    
    if (stat (confdir, &info) == -1)
      {
      if (mkdir (confdir, 0777) == -1)
	g_critical ("Could not create directory %s: %s\n", 
		    confdir, strerror (errno));
      }
  }    

  {
#if GTK_MAJOR_VERSION == 2
    GdkScreen *screen;

    screen = gdk_screen_get_default ();
    
    screeninfo = g_strdup_printf ("%dx%dx%d+render", 
				  gdk_screen_get_width (screen),
				  gdk_screen_get_height (screen),
				  gdk_visual_get_best_depth ());
#else
    screeninfo = g_strdup_printf ("%dx%dx%d+render",
				  gdk_screen_width (),
				  gdk_screen_height (),
				  gdk_visual_get_best_depth ());
#endif
  }

  { /* get X authentication cookie information */
    FILE *xauth_output;
    gchar xauth[256] = {0};

    gchar *tmp = NULL;
    gchar **tmpv = NULL;
    gchar *display = NULL;

    /* avoid problems with "network" DISPLAY's */
    display = g_strdup (getenv ("DISPLAY"));
    tmpv = g_strsplit (display, ":", 3);
    g_free (display);
  
    display = g_strdup_printf (":%s", tmpv[1]);
    g_strfreev (tmpv);

    /* get the authorization token */
    tmp = g_strdup_printf (XAUTHBINDIR"/xauth list %s | "
			   "grep 'MIT-MAGIC-COOKIE-1' | "
			   "cut -d ' ' -f 5",
			   display);

    if ((xauth_output = popen (tmp, "r")) == NULL)
      {
	g_critical ("Failed to obtain xauth key: %s", strerror(errno));
	exit (1);
      }

    fread (xauth, sizeof(char), 256, xauth_output);
    xauth[strlen(xauth) - 1] = '\0';
    pclose (xauth_output);
    g_free (tmp);

    if (!strcmp (xauth, ""))
      {
	message_dialog ("Não foi possível obter um cookie de autenticação\n"
			"do servidor X. Impossível continuar.");
	exit (1);
      }

    cookie = g_strdup (xauth);
  }


  { /* read configuration file */
    FILE *fconf;
    gint fconf_fd;
    gchar **tmp, *key, *value;
    struct stat info;
    
    if (stat (CONFFILE, &info) == -1)
      {
	g_warning ("WARNING: Could not stat %s: %s.\n", 
		   CONFFILE, strerror (errno));
      }

    fconf = fopen (CONFFILE, "r");
    if (fconf == NULL)
      {
	g_critical ("Could not open %s: %s.\n", 
		    CONFFILE, strerror (errno));
      }
    else
      {
	fconf_fd = fileno (fconf);

	while (!feof (fconf))
	  {

	    buffer = read_line (fconf_fd);
	    if (!buffer)
	      break;

	    /* remove comments */
	    tmp = g_strsplit (buffer, "#", 2);
	    g_free (buffer);

	    buffer = g_strdup (tmp[0]);
	    g_strfreev (tmp);

	    /* check if we still have a key/value pair */
	    tmp = g_strsplit (buffer, "=", 2);
	    g_free (buffer);
	    if (tmp[1] == NULL || tmp[0] == NULL)
	      {
		g_strfreev (tmp);
		continue;
	      }

	    key = tmp[0];
	    value = tmp[1];

	    g_strstrip (key);
	    g_strstrip (value);

	    if (!strcmp ("host", key))
	      {
		g_free (host);
		host = g_strdup (value);
	      }
	    else if (!strcmp ("port", key))
	      {
		g_free (port);
		port = g_strdup (value);
	      }
	    else if (!strcmp ("sshkey", key))
	      {
		g_free (sshkey);
		sshkey = g_strdup (value);
	      }
	    else if (!strcmp ("session", key))
	      {
		g_free (session);
		session = g_strdup (value);
	      }
	    else if (!strcmp ("ssl", key))
	      {
		if (!strcmp (value, "yes"))
		    use_ssl = 1;
	      }
	    else if (!strcmp ("type", key))
	      {
		g_free (type);
		type = g_strdup (value);
	      }
	    else if (!strcmp ("link", key))
	      {
		g_free (link);
		link = g_strdup (value);
	      }
	    else if (!strcmp ("kbdtype", key))
	      {
		g_free (kbdtype);
		kbdtype = g_strdup (value);
	      }
	    else if (!strcmp ("geometry", key))
	      {
		g_free (geometry);
		geometry = g_strdup (value);
	      }
	    else
	      g_warning ("Unknown option in %s: %s=%s\n", 
			 CONFFILE, key, value);

	    g_strfreev (tmp);
	  }
	fclose (fconf);
      }
  }

  /* grab auth information from the user before anything else */
  input_dialog (&user, &password);

  if (!strcmp (user, "root"))
    {
      message_dialog ("O usuário root não pode entrar por aqui!");
      exit (1);
    }

  pipe (parent_pipe);
  pipe (child_pipe);

  pid = fork ();
  if (pid == -1)
    {
      g_critical ("Could not fork!\n");
      exit (1);
    }
  else if (pid == 0)
    {
      close (child_pipe[1]);
      dup2 (child_pipe[0], STDIN_FILENO);
      dup2 (parent_pipe[1], STDOUT_FILENO);

      nxssh_argv[0] = g_strdup (BINDIR"/nxssh");
      nxssh_argv[1] = g_strdup ("-nx");
      nxssh_argv[2] = g_strdup_printf ("-p%s", port);
      nxssh_argv[3] = g_strdup ("-i");
      nxssh_argv[4] = g_strdup (sshkey);
      nxssh_argv[5] = g_strdup_printf ("nx@%s", host);
      nxssh_argv[6] = g_strdup ("-2");
      nxssh_argv[7] = g_strdup ("-S");
      nxssh_argv[8] = NULL;

      execv (nxssh_argv[0], nxssh_argv);
    }
  else
    {
      close(parent_pipe[1]);

      out = parent_pipe[0];
      in = child_pipe[1];

      /* Handle initial hand-shaking */
      {
	gboolean ssh_authed = FALSE;

	while (!ssh_authed)
	  {
	    buffer = read_code (out);
	    if (!strcmp (buffer, "NX> 205"))
	      {
		flush_buffer (buffer);
		drop_line (out);
		drop_line (out);
		drop_chars (out, 56);
		write_line (in, "yes");
		drop_line (out);
		drop_line (out);

		/* buffer != NULL? but why?! */
		buffer = NULL;
	      }
	    else if (!strcmp (buffer, "NX> 208"))
	      { 
		/* OK, authenticating... */
	      }
	    else if (!strcmp (buffer, "NX> 203") || 
		     (!strcmp (buffer, "NX> 285")) ||
		     (!strcmp (buffer, "NX> 200")) ||
		     (!strcmp (buffer, "NX> 202")))
	      {
		/* ignored stderr */
	      }
	    else if (!strncmp (buffer, "nxssh", 5))
	      {
		gchar *msg;

		flush_buffer (buffer);
		buffer = read_line (out);
		msg = get_info_after_colon (buffer);
		g_free (buffer);

		if (!strcmp (msg, "Name or service not known"))
		  message_dialog ("Não foi possível resolver o nome do servidor.");
		else if (!strcmp (msg, "Connection refused"))
		  message_dialog ("A conexão foi recusada!\n"
				  "Verifique a porta.");
		else if (!strcmp (msg, "Connection timed out"))
		  message_dialog ("Tempo limite da conexão expirou!\n"
				  "Verifique servidor e porta.");

		flush_buffer (msg);
		fprintf (stderr, "\n");
		exit (1);
	      }
	    else if (!strcmp (buffer, "NX> 204"))
	      {
		message_dialog ("Falha na autenticação inicial!\n"
				"Confira a chave privada.");
		g_critical ("Failed to authenticate to SSH using the public key!\n");
		exit (1);
	      }
	    else if (!strcmp (buffer, "HELLO N"))
	      {
		/* OK, time to say HELLO! */
		ssh_authed = TRUE;
	      }
	    else
	      protocol_error ("problems waiting for HELLO");

	    flush_buffer (buffer);

	    buffer = read_line (out);
	    flush_buffer (buffer);
	  }
      }

      /* Handle HELLO */
      buffer = read_code (out);
      if (!strcmp (buffer, "NX> 105"))
	{
	  flush_buffer (buffer);
	  drop_chars (out, 1);
	  write_line (in, "HELLO NXCLIENT - Version 1.4.0");
	  drop_line (out);
	}
      else
	protocol_error ("problems during HELLO");

      /* Handle Login */
      buffer = read_code (out);
      if (!strcmp (buffer, "NX> 134"))
	{
	  flush_buffer (buffer);
	  buffer = read_line (out);
	  flush_buffer (buffer);
	}
      else
	protocol_error ("HELLO failed?");

      buffer = read_code (out);
      if (!strcmp (buffer, "NX> 105"))
	{
	  flush_buffer (buffer);
	  drop_chars (out, 1);
	  write_line (in, "login");
	  drop_line (out);
	}
      else
	protocol_error ("No login? How come!");

      buffer = read_code (out);
      if (!strcmp (buffer, "NX> 101"))
	{
	  flush_buffer (buffer);
	  drop_chars (out, 7);
	  write_line (in, user);
	  drop_line (out);
	}
      else
	protocol_error ("who took my login prompt away?");

      buffer = read_code (out);
      if (!strcmp (buffer, "NX> 102"))
	{
	  flush_buffer (buffer);
	  drop_chars (out, 11);
	  write_line (in, password);
	  drop_line (out);
	}
      else
	protocol_error ("where is my password prompt?");

      buffer = read_code (out);
      if (!strcmp (buffer, "NX> 103"))
	{
	  flush_buffer (buffer);
	  drop_line (out);
	}
      else
	{
	  flush_buffer (buffer);
	  message_dialog ("Login ou senha incorretos!");
	  exit (1);
	}

      buffer = read_code (out);
      if (!strcmp (buffer, "NX> 105"))
	{
	  gchar *m;

	  flush_buffer (buffer);
	  drop_chars (out, 1);

	  m = g_strdup_printf ("list %s", user);
	  write_line (in, m);
	  g_free (m);

	  drop_lines (out, 5);

	  while (1)
	    {
	      buffer = read_code (out);
	      if (!strcmp (buffer, "NX> 105"))
		{
		  flush_buffer (buffer);
		  drop_chars (out, 1);
		  break;
		}

	      flush_buffer (buffer);
	      buffer = read_line (out);
	      restore_id = get_restore_id (buffer);
	    }
	}
      else
	protocol_error ("session startup, buddy, I don't want problems!");
      

      {
	gchar *cmdline;
	
	if (!restore_id)
	  cmdline = g_strdup_printf ("startsession --session=\"%s\" --type=\"%s\" --cache=\"8M\" --images=\"32M\" --cookie=\"%s\" --link=\"%s\" --kbtype=\"%s\" --nodelay=\"1\" --backingstore=\"never\" --geometry=\"%s\" --media=\"0\" --agent_server=\"\" --agent_user=\"\" --agent_password=\"\" --screeninfo=\"%s\" --encryption=\"%d\"", session, type, cookie, link, kbdtype, geometry, screeninfo, use_ssl);
	else
	  cmdline = g_strdup_printf ("restoresession --session=\"%s\" --type=\"%s\" --cache=\"8M\" --images=\"32M\" --cookie=\"%s\" --link=\"%s\" --kbtype=\"%s\" --nodelay=\"1\" --backingstore=\"never\" --geometry=\"%s\" --media=\"0\" --agent_server=\"\" --agent_user=\"\" --agent_password=\"\" --screeninfo=\"%s\" --encryption=\"%d\" --id=\"%s\"", session, type, cookie, link, kbdtype, geometry, screeninfo, use_ssl, restore_id);
	
	write_line (in, cmdline);
	g_free (cmdline);
	cmdline = NULL;
	
	drop_lines (out, 4);
      }

      session_id = get_session_info (out, "NX> 700");
      session_display = get_session_info (out, "NX> 705");
      drop_line (out); /* 703 (session type) */
      pcookie = get_session_info (out, "NX> 701");
      drop_line (out); /* 702 proxy ip */
      drop_line (out); /* 706 agent cookie */
      drop_line (out); /* 704 session cache */
      {
	gchar *tmp = get_session_info (out, "NX> 707"); /* 707 ssl tunneling */
	
	use_ssl = atoi (tmp);
	g_free (tmp);
      }
      drop_line (out); /* 710 session status: running */
      drop_line (out); /* 1002 commit */
      drop_line (out); /* 1006 session status: running */

      read_code (out);
      drop_chars (out, 1);

      /* now prepare to run nxproxy */
      {
	FILE *options;
		
	gchar *dirname;
	gchar *fname;
	gchar *cmdline;
		
	dirname = g_strdup_printf ("%s/.nx/S-%s", homedir, session_id);
	fname = g_strdup_printf ("%s/options", dirname);
		
	g_print ("Dir: %s\nFname: %s\n", dirname, fname);
		
	if (mkdir (dirname, 0777) == -1)
	  {
	    /* BOMB or handle 'directory already exists' */
	  }
	g_free (dirname);
		
	if (use_ssl)
	  buffer = g_strdup_printf ("cookie=%s,root=%s/.nx,session=%s,id=%s,listen=%d:%s", pcookie, homedir, session, session_id, 8008, session_display);
	else
	  buffer = g_strdup_printf ("cookie=%s,root=%s/.nx,session=%s,id=%s,connect=%s:%s", pcookie, homedir, session, session_id, host, session_display);
		
	options = fopen (fname, "w");
	fwrite (buffer, sizeof(char), strlen (buffer), options);
	fclose (options);
		
	g_free (buffer);
		
	cmdline = g_strdup_printf (BINDIR"/nxproxy -S options=%s:%s", fname, session_display);
	system (cmdline);
	g_free (cmdline);
		
	g_free (fname);
      }
    }

  write_line (in, "bye");
  drop_line (out);

  if (use_ssl)
    write_line (in, "switch");

  drop_line (out);
  drop_line (out);
  drop_line (out);

  return 0;
}
コード例 #14
0
ファイル: llink.cpp プロジェクト: AmziLS/apls
void Linker::read_linked_segs(FILE * f, aUINT16 atom_table_length, 
                              FILE * pFtarg, int filei)
{                             //  reads the linked segments for one PROCEDURE 
  aINT32      proc_code_length;
  aUINT16      clause_code_length;
  CODE       buf[6];
  aUINT16     last_clause, first_clause;
  aINT32      start_of_proc, end_of_proc;  // changed from long
  aINT16     zero = 0;
  char       op;   
  
  start_of_proc = ftell(pFtarg);
  
  /* build the procedure prefix segment
     
     proc_code_length
     name
     arity

     */
  read_l_atoms(f, atom_table_length, filei);    // Read the local atom table 
  
  if (!read_uint16(&clause_code_length, f))      // code length 
    aborteof(aS("linked segment length"));
#ifdef BUG_LINK
  fprintf(lout, "clause_length = %u, local_atom_table_length = %u\n", clause_code_length, atom_table_length);
#endif
  //  ucFWRITE(&zero, sizeof(aINT16), 1, pFtarg);      // reserve this 
  // ucFWRITE(&zero, sizeof(intC), 1, pFtarg);      // reserve this  ray
  ucFWRITE(&zero, sizeof(aINT32), 1, pFtarg);      // no ray, should be int32, intC might be 64
  
  if (!read_uint16(&last_clause, f))             // last clause marker 
    aborteof(aS("linked segment clause marker"));
  
  read_atom(f, pFtarg);                         // functor 
  
  if (0 == fread(buf, sizeof(aINT16), 1, f))     // arity 
    aborteof(aS("linked segment arity"));
  ucFWRITE(buf, 2, 1, pFtarg);
  
  proc_code_length = clause_code_length - 2;     // size of first clause 
  /* 
     There is no last clause marker in the created prefix segment 
     so subtract this off
     */
   first_clause = 1;
   while (1)
   {                                            // We are now at the code

#ifdef BUG_LINK
      fprintf(lout, "\nNext clause");
#endif
      if (first_clause)
      {
         first_clause = 0;
         fread(&op, sizeof(aBYTE), 1, f);       // see if  switch is active
         if (op == Ono_switch)
         {
#ifdef xBUG_LINK
            fprintf(lout, "\nno switch");
#endif
            fseek(f, 6L, SEEK_CUR);            // skip the remaining labels
            clause_code_length -= 7;
            proc_code_length -= 7;
              
            fread(&op, sizeof(aBYTE), 1, f);   // now look at try_me_else
            if (op == Ono_try)
            {
#ifdef xBUG_LINK
               fprintf(lout, "\nno try_me_else");
#endif
               clause_code_length -= 5;
               proc_code_length -= 5;
               fseek(f, 4L, SEEK_CUR);         // skip label and NTV
            }
            else
               fseek(f, -1L, SEEK_CUR);          // get back to the try_me
         }
         else
            fseek(f, -1L, SEEK_CUR);              // get back to first op code
      }
      
      read_code(f, pFtarg, PLM_CLHEAD_L, clause_code_length, (aBYTE*) buf);
      if (last_clause)                            // was last clause 
         break;
      
      if (!read_uint16(&atom_table_length, f))
         aborteof(aS("linked atom table length"));
      read_l_atoms(f, atom_table_length, filei);
      
      if (!read_uint16(&clause_code_length, f))    
         aborteof(aS("linked clause length"));
#ifdef BUG_LINK
  fprintf(lout, "clause_length = %d\n", clause_code_length);
#endif

      /* We don't include junk in prefix as part of length 
         after the first clause (we only have ONE name, arity etc) */
      
      proc_code_length += clause_code_length - PLM_CLHEAD_L;
      
      if (!read_uint16(&last_clause, f))
        aborteof(aS("linked last clause"));
      
      fseek(f, 4L, SEEK_CUR);                 // skip Name, ARITY 
    }
#ifdef BUG_LINK
  fprintf(lout, "\n  ----- end of predicate ----- \n");
#endif
                         // seek back to fill in proc_size & proc length 
  end_of_proc = ftell(pFtarg);
  fseek(pFtarg, start_of_proc, SEEK_SET);
#ifdef BUG_LINK
  fprintf(lout, "proc_length = %d\n", proc_code_length);
#endif
  write_int32(proc_code_length, pFtarg);
  fseek(pFtarg, end_of_proc, SEEK_SET);

}
コード例 #15
0
ファイル: data.c プロジェクト: dramenti/semblance
void read_file() {
    read_data();
    read_code();
}
コード例 #16
0
ファイル: upp.c プロジェクト: ArtTech86/the-bus-pirate
void ProcessIO(void)
{
	char oldPGDtris;
	char PIN;
	static byte counter=0;
	int nBytes;
	unsigned long address;
	unsigned char i;
	
	input_buffer[0]=UART1RX(); //USBGenRead((byte*)input_buffer,64);
//	if(nBytes>0)
//	{
		switch(input_buffer[0])
		{
			case CMD_ERASE:
				setLeds(LEDS_ON | LEDS_WR);
				getBytes(1,1);//get more data, #bytes, where to insert in input buffer array
				output_buffer[0]=bulk_erase(picfamily,pictype,input_buffer[1]);
				counter=1;
				setLeds(LEDS_ON);
				break;
			case CMD_READ_ID:
				setLeds(LEDS_ON | LEDS_RD);
				switch(picfamily)
				{
					case DSPIC30:
						read_code(picfamily,pictype,0xFF0000,(unsigned char*)output_buffer,2,3);
						break;
					case PIC18:
						read_code(picfamily,pictype,0x3FFFFE,(unsigned char*)output_buffer,2,3);  //devid is at location 0x3ffffe   for PIC18 devices
						break;
					case PIC16:
						set_vdd_vpp(picfamily, pictype, 0);
						read_code(picfamily,pictype,0x2006,(unsigned char*)output_buffer,2,3);  //devid is at location 0x2006  for PIC16 devices
						break;
				}
				counter=2;
				setLeds(LEDS_ON);
				break;
			case CMD_WRITE_CODE:
				setLeds(LEDS_ON | LEDS_WR);
				address=((unsigned long)input_buffer[2])<<16|
						((unsigned long)input_buffer[3])<<8|
						((unsigned long)input_buffer[4]);
				output_buffer[0]=write_code(picfamily,pictype,address, (unsigned char*)(input_buffer+6),input_buffer[1],input_buffer[5]);
				counter=1;
				setLeds(LEDS_ON);
				break;
			case CMD_READ_CODE:
				setLeds(LEDS_ON | LEDS_RD);
				address=((unsigned long)input_buffer[2])<<16|
						((unsigned long)input_buffer[3])<<8|
						((unsigned long)input_buffer[4]);
				read_code(picfamily,pictype,address,(unsigned char*)output_buffer,input_buffer[1],input_buffer[5]);
				counter=input_buffer[1];
				setLeds(LEDS_ON);
				break;
			case CMD_WRITE_DATA:
				setLeds(LEDS_ON | LEDS_WR);
				address=((unsigned long)input_buffer[2])<<16|
						((unsigned long)input_buffer[3])<<8|
						((unsigned long)input_buffer[4]);
				output_buffer[0]=write_data(picfamily,pictype,address, (unsigned char*)(input_buffer+6),input_buffer[1],input_buffer[5]); 
				counter=1;
				setLeds(LEDS_ON);
				break;
			case CMD_READ_DATA:
				setLeds(LEDS_ON | LEDS_RD);
				address=((unsigned long)input_buffer[2])<<16|
						((unsigned long)input_buffer[3])<<8|
						((unsigned long)input_buffer[4]);
				read_data(picfamily,pictype,address,(unsigned char*)output_buffer,input_buffer[1],input_buffer[5]); 
				counter=input_buffer[1];
				setLeds(LEDS_ON);
				break;
			case CMD_WRITE_CONFIG:
				setLeds(LEDS_ON | LEDS_WR);
				address=((unsigned long)input_buffer[2])<<16|
						((unsigned long)input_buffer[3])<<8|
						((unsigned long)input_buffer[4]);
				output_buffer[0]=write_config_bits(picfamily, pictype, address, (unsigned char*)(input_buffer+6),input_buffer[1],input_buffer[5]);
				counter=1;
				setLeds(LEDS_ON);
				break;
			case CMD_SET_PICTYPE:
				output_buffer[0]=set_pictype(input_buffer+1);
				//output_buffer[0]=1; //Ok
				counter=1;
				setLeds(LEDS_ON);
				break;
			case CMD_FIRMWARE_VERSION:
				for(counter=0; counter<18; counter++)output_buffer[counter]=upp_version[counter];
				counter=18;
				setLeds(LEDS_ON);
				break;
			case CMD_DEBUG:
				setLeds(LEDS_ON | LEDS_WR | LEDS_RD);
				switch(input_buffer[1])
				{
					case 0:
						set_vdd_vpp(dsP30F, DSPIC30, 1);
						output_buffer[0]=1;
						counter=1;	
						break;
					case 1:
						set_vdd_vpp(dsP30F, DSPIC30, 0);
						output_buffer[0]=1;
						counter=1;	
						break;
					case 2:
						dspic_send_24_bits(((unsigned long)input_buffer[2])|
								((unsigned long)input_buffer[3])<<8|
								((unsigned long)input_buffer[4])<<16);
						output_buffer[0]=1;
						counter=1;
						break;
					case 3:
						nBytes =  dspic_read_16_bits();
						output_buffer[0]=(unsigned char)nBytes;
						output_buffer[1]=(unsigned char)(nBytes>>8);
						counter=2;
						break;
						
				}
				break;
			case CMD_GET_PIN_STATUS:
				switch(input_buffer[1])
				{
					case SUBCMD_PIN_PGC:
						if((!TRISPGC_LOW)&&(!PGC_LOW)) //3.3V levels
						{
							if(PGC) output_buffer[0] = PIN_STATE_3_3V;
							else output_buffer[0] = PIN_STATE_0V;
						}
						else	//5V levels
						{
							if(PGC) output_buffer[0] = PIN_STATE_5V;
							else output_buffer[0] = PIN_STATE_0V;
						}
						counter=1;
						break;
					case SUBCMD_PIN_PGD:
						if(TRISPGD)//PGD is input
						{
							if(PGD_READ) output_buffer[0] = PIN_STATE_5V;
							else output_buffer[0] = PIN_STATE_0V;
						}
						else
						{							
							if((!TRISPGD_LOW)&&(!PGD_LOW)) //3.3V levels
							{
								if(PGD) output_buffer[0] = PIN_STATE_3_3V;
								else output_buffer[0] = PIN_STATE_0V;
							}
							else	//5V levels
							{
								if(PGD) output_buffer[0] = PIN_STATE_5V;
								else output_buffer[0] = PIN_STATE_0V;
							}
						}
						counter=1;
						break;
					case SUBCMD_PIN_VDD:
						//if(VDD) output_buffer[0] = PIN_STATE_FLOAT;
						//else output_buffer[0] = PIN_STATE_5V;
						output_buffer[0] = PIN_STATE_5V;
						counter = 1;
						break;
					case SUBCMD_PIN_VPP:
						counter=1;
						if(!VPP){output_buffer[0] = PIN_STATE_12V;break;}
						if(VPP_RST){output_buffer[0] = PIN_STATE_0V;break;}
						if(VPP_RUN){output_buffer[0] = PIN_STATE_5V;break;}
						output_buffer[0] = PIN_STATE_FLOAT;
						break;
					case SUBCMD_PIN_VPP_VOLTAGE:
						ReadAdc(output_buffer);
						counter=2;
						break;
					default:
						output_buffer[0]=3;
						counter=1;
						break;
				}
				break;
			case CMD_SET_PIN_STATUS:
				switch(input_buffer[1])
				{
					case SUBCMD_PIN_PGC:
						switch(input_buffer[2])
						{
							case PIN_STATE_0V:
								TRISPGC = 0;
								PGC = 0;
								TRISPGC_LOW = 1;
								PGC_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_3_3V:
								TRISPGC = 0;
								PGC = 1;
								TRISPGC_LOW = 0;
								PGC_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_5V:
								TRISPGC = 0;
								PGC = 1;
								TRISPGC_LOW = 1;
								PGC_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							default:
								output_buffer[0]=3;
								break;
						}
						break;
					case SUBCMD_PIN_PGD:
						switch(input_buffer[2])
						{
							case PIN_STATE_0V:
								TRISPGD = 0;
								PGD = 0;
								TRISPGD_LOW = 1;
								PGD_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_3_3V:
								TRISPGD = 0;
								PGD = 1;
								TRISPGD_LOW = 0;
								PGD_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_5V:
								TRISPGD = 0;
								PGD = 1;
								TRISPGD_LOW = 1;
								PGD_LOW = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_INPUT:
								TRISPGD_LOW = 1;
								TRISPGD = 1;
								output_buffer[0]=1;//ok
								break;
							default:
								output_buffer[0]=3;
								break;
						}
						break;
					case SUBCMD_PIN_VDD:
						switch(input_buffer[2])
						{
							case PIN_STATE_5V:
								//VDD = 0;
								output_buffer[0]=1;
								break;
							case PIN_STATE_FLOAT:
								//VDD = 1;
								output_buffer[0]=1;
								break;
							default:
								output_buffer[0]=3;
								break;
						}
						break;
					case SUBCMD_PIN_VPP:
						switch(input_buffer[2])
						{
							case PIN_STATE_0V:
								VPP = 1;
								VPP_RST = 1;
								VPP_RUN = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_5V:
								VPP = 1;
								VPP_RST = 0;
								VPP_RUN = 1;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_12V:
								VPP = 0;
								VPP_RST = 0;
								VPP_RUN = 0;
								output_buffer[0]=1;//ok
								break;
							case PIN_STATE_FLOAT:
								VPP = 1;
								VPP_RST = 0;
								VPP_RUN = 0;
								output_buffer[0]=1;//ok
								break;
							default:
								output_buffer[0]=3;
								break;
						}
						break;
					default:
						output_buffer[0]=3;
				}
				counter=1;
				break;
		}
	//} //if nBytes>0
	if(counter != 0)
	{
		//if(!mUSBGenTxIsBusy())
		//USBGenWrite((byte*)&output_buffer,counter);
		for(i=0; i<counter; i++) UART1TX(output_buffer[i]);
		counter=0;
	}
}//end ProcessIO
コード例 #17
0
ファイル: ata_cmd.c プロジェクト: JackYangzg/sage
void intial_data_partition()
{
    u8 ii;
	g_tmp_addr = identify_data_addr+0xad;//28bits or 48bits
	if((read_code(g_tmp_addr)&(0x04))==0x04) g_tmp_addr = identify_data_addr+0xc8;
	else  g_tmp_addr = identify_data_addr+0x78;//word 60-61
	for(ii=0;ii<4;ii++)
	{
	    sum.No[3-ii]= read_code(g_tmp_addr);
        g_tmp_addr ++;
	} 

	sata.SUP_LBA0 = 0x00;
    sata.SUP_LBA1 = 0x00;
    sata.SUP_LBA2 = 0x00;
    sata.SUP_LBA3 = 0x00;
    sata.SUP_LBA4 = 0x00;
    sata.SUP_LBA5 = 0x00;

    send_trim_cmd(sum);

		g_tmp_addr = identify_data_addr+0xad;//28bits or 48bits
	if((read_code(g_tmp_addr)&(0x04))==0x04) g_tmp_addr = identify_data_addr+0xc8;
	else 
		g_tmp_addr = identify_data_addr+0x78;//word 60-61
	for(ii=0;ii<4;ii++)
	{
	    sum.No[3-ii]= read_code(g_tmp_addr);
        g_tmp_addr ++;
	} 
    
	
	SFR_ext_sram_addr = 0x0000;	
	SFR_ext_sram_cntl = 0x10;
	while(SFR_ext_sram_addr<0x8000)SFR_ext_sram_data = 0x77;
	
	trim_addr_offset.No[3] = BLOCK_SIZE_L;
    trim_addr_offset.No[2] = BLOCK_SIZE_H;
	trim_addr_offset.No[1] = 0x00;
	trim_addr_offset.No[0] = 0x00;
	trim_addr_offset.Number =trim_addr_offset.Number<<3;
	sum.Number -= trim_addr_offset.Number;
	g_sec_cnt.word = trim_addr_offset.Word[1];
	myprintf("sec:%x %x",g_sec_cnt.word);
		myprintf("\nnum:%x %x %x %x",sum.No[3],sum.No[2],sum.No[1],sum.No[0]);
	reset_engine();
	sata.SUP_LBA0 = sum.No[3];
    sata.SUP_LBA1 = sum.No[2];
    sata.SUP_LBA2 = sum.No[1];
    sata.SUP_LBA3 = sum.No[0];
    sata.SUP_LBA4 = 0x00;
    sata.SUP_LBA5 = 0x00;
	sata.CHP_cmd = CHP_CMD_WRITE;
	SFR_dma_base = 0x0000;

    if((g_sec_cnt.byte.l != 0x00)||(g_sec_cnt.byte.h != 0x00))//sata.ncq_cntl = sata.ncq_cntl | ncq_cntl_set_dma_cnt_high;
    SFR_dma_max_num = g_sec_cnt.word;
	else 
	{
	    SFR_dma_max_num = 0x0000;
	    sata.ncq_cntl = sata.ncq_cntl | ncq_cntl_set_dma_cnt_high;
	    trim_addr_offset.Word[0] -= 0x01;
	}
    SFR_dma_cntl = SFR_dma_cntl_run;
	while(!dma_done);

	while(trim_addr_offset.Word[0]>0)
	{
	    SFR_dma_max_num = 0x0000;
	    sata.ncq_cntl = sata.ncq_cntl | ncq_cntl_set_dma_cnt_high;
		dma_cont = 1;
		while(!dma_done);
	}

	
    clear_dma_run;    
	
	SFR_ext_sram_cntl = 0x00; 
	flush_delay();
	return;
}