static void usb_send_desc(setup_t *sp) { // initialize with: // * len = requested length // * dsc = configuration descriptor // * wTotalLength = wTotalLength field of configuration descriptor uint8_t len = HTOUS(sp->asdescreq.len); usbdescr_t *dsc = (usbdescr_t*) &(usbdev.usbdesc[((usbdescr_t*) usbdev.usbdesc)->bLength]); uint16_t wTotalLength = HTOUS(*(uint16_t*) dsc->buf); size_t i; switch(sp->asdescreq.val) { case DEVICE_DESCRIPTOR: PUTS("dev_desc\n"); dsc = (usbdescr_t*) usbdev.usbdesc; len = dsc->bLength; break; case CONFIGURATION_DESCRIPTOR: PUTS("conf_desc\n"); len = MIN(len, wTotalLength); break; case STRING_DESCRIPTOR: PUTS("str_desc\n"); dsc = (usbdescr_t*) &dsc->buf[wTotalLength-sizeof(usbdescr_t)]; /* at the first string now */ for(i=0; i<sp->asdescreq.idx && dsc->bDescriptorType==STRING_DESCRIPTOR; i++) dsc = (usbdescr_t*) &dsc->buf[dsc->bLength-sizeof(usbdescr_t)]; len = dsc->bLength; break; default: PUTS("unknown setup request\n"); STALLEP0(); } { uint8_t wlen = MIN(64, len), *pt = (uint8_t*) dsc; reg_t st = {0x00}; do { wlen = MIN(64, len); /* wait until asserted */ do { rreg(EPIRQ, &st); } while( !st.EPIRQ.IN0BAVIRQ ); /* writing to EP0, also clrs irq */ wregn(EP0FIFO, pt, wlen, false); wregn(EP0BC, &wlen, sizeof(uint8_t), len<64); len -= wlen; pt += wlen; } while(len>0); } }
void CFanmotorDlg::OnBnClickedButtonRtest() { // TODO: Add your control notification handler code here int datr = 0; //CFanmotorDlg* pParent = (CFanmotorDlg*)m_pParent; // read reg datr = rreg(0x81);//MSB is R/W bit!!!!!!!!!!!! // display data m_EDIT_Rtest.Format(_T("%x"), datr); UpdateData(FALSE); }
int CFanmotorDlg::dataread_anybits(int addr,int ind,int length) { int datr,datr_section; CString datstring,dat_section; datr = rreg(addr); if (!success){goto end;}; datstring = int2bin(datr); for(int i=0;i<length;i++){ dat_section += datstring[ind + i]; } datr_section = bin2intwl(dat_section,length); return datr_section; end:; }
void CFanmotorDlg::dataupdate_anybits(int addr, int ind, CString datbits,int length) { int temp,datupdated; CString datbintemp; temp = rreg(addr); if (!success){goto end;}; datbintemp = int2bin(temp); for(int i = 0;i<length;i++){ datbintemp.SetAt(ind+i,datbits[i]); } datupdated = bin2int(datbintemp); wreg(addr,datupdated); if (!success){goto end;}; end:; }
int regexpApp::main (void) { string tstr; regexpression re ("^[[:digit:]]{4}[[:alpha:]]{2}"); if (! re.eval ("3038XX")) { ferr.printf ("fail1\n"); return 1; } if (re.eval ("173YA")) { ferr.printf ("fail2\n"); return 1; } if (re.eval ("This is a test")) { ferr.printf ("fail3\n"); return 1; } tstr = "This is a dumb test"; tstr = strutil::regexp (tstr, "s/dumb/cool/"); if (tstr != "This is a cool test") { ferr.printf ("fail4\n"); } regexpression rreg ("^([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$"); if (! rreg.eval ("317")) ferr.printf ("002\n"); for (int i=0; i<1000; ++i) { string c = "^([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$"; regexpression reg (c); if (! reg.eval ("317.90.90.188")) { ferr.printf ("123\n"); } } return 0; }
static void get_status(setup_t *sp) { uint8_t len = sizeof(sp->asstatresp); reg_t st = {0x00}; switch(sp->reqtype.recp) { case TO_DEVICE: sp->asstatresp = (usbdev.status.rwu_enabled)<<9 | (usbdev.status.self_powered)<<8; break; case TO_ENDPOINT: /* XXX: for endpoint the stall status should be returned */ case TO_INTERFACE: sp->asstatresp = 0x0000; break; default: STALLEP0(); } do { rreg(EPIRQ, &st); } while( !st.EPIRQ.IN0BAVIRQ ); wregn(EP0FIFO, (uint8_t*) &sp->asstatresp, len, false); wregn(EP0BC, &len, sizeof(len), true); }
void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, int reason, bool gate_valid, uint8_t gate, uint64_t gate_type) { uint64_t rip = rreg(cpu->hvf_fd, HV_X86_RIP); if (!gate_valid || (gate_type != VMCS_INTR_T_HWEXCEPTION && gate_type != VMCS_INTR_T_HWINTR && gate_type != VMCS_INTR_T_NMI)) { int ins_len = rvmcs(cpu->hvf_fd, VMCS_EXIT_INSTRUCTION_LENGTH); macvm_set_rip(cpu, rip + ins_len); return; } load_regs(cpu); struct x86_segment_descriptor curr_tss_desc, next_tss_desc; int ret; x68_segment_selector old_tss_sel = vmx_read_segment_selector(cpu, R_TR); uint64_t old_tss_base = vmx_read_segment_base(cpu, R_TR); uint32_t desc_limit; struct x86_call_gate task_gate_desc; struct vmx_segment vmx_seg; X86CPU *x86_cpu = X86_CPU(cpu); CPUX86State *env = &x86_cpu->env; x86_read_segment_descriptor(cpu, &next_tss_desc, tss_sel); x86_read_segment_descriptor(cpu, &curr_tss_desc, old_tss_sel); if (reason == TSR_IDT_GATE && gate_valid) { int dpl; ret = x86_read_call_gate(cpu, &task_gate_desc, gate); dpl = task_gate_desc.dpl; x68_segment_selector cs = vmx_read_segment_selector(cpu, R_CS); if (tss_sel.rpl > dpl || cs.rpl > dpl) ;//DPRINTF("emulate_gp"); } desc_limit = x86_segment_limit(&next_tss_desc); if (!next_tss_desc.p || ((desc_limit < 0x67 && (next_tss_desc.type & 8)) || desc_limit < 0x2b)) { VM_PANIC("emulate_ts"); } if (reason == TSR_IRET || reason == TSR_JMP) { curr_tss_desc.type &= ~(1 << 1); /* clear busy flag */ x86_write_segment_descriptor(cpu, &curr_tss_desc, old_tss_sel); } if (reason == TSR_IRET) EFLAGS(env) &= ~RFLAGS_NT; if (reason != TSR_CALL && reason != TSR_IDT_GATE) old_tss_sel.sel = 0xffff; if (reason != TSR_IRET) { next_tss_desc.type |= (1 << 1); /* set busy flag */ x86_write_segment_descriptor(cpu, &next_tss_desc, tss_sel); } if (next_tss_desc.type & 8) ret = task_switch_32(cpu, tss_sel, old_tss_sel, old_tss_base, &next_tss_desc); else //ret = task_switch_16(cpu, tss_sel, old_tss_sel, old_tss_base, &next_tss_desc); VM_PANIC("task_switch_16"); macvm_set_cr0(cpu->hvf_fd, rvmcs(cpu->hvf_fd, VMCS_GUEST_CR0) | CR0_TS); x86_segment_descriptor_to_vmx(cpu, tss_sel, &next_tss_desc, &vmx_seg); vmx_write_segment_descriptor(cpu, &vmx_seg, R_TR); store_regs(cpu); hv_vcpu_invalidate_tlb(cpu->hvf_fd); hv_vcpu_flush(cpu->hvf_fd); }
static bool std_req(setup_t *sp) { switch(sp->req) { case SR_SET_ADDRESS: PUTS("set_addr\n"); rregn(FNADDR, NULL, 0, true); break; case SR_GET_DESCRIPTOR: PUTS("get_desc: "); usb_send_desc(sp); break; case SR_SET_FEATURE: /* this either sets that RWU is to be enabled or to halt an EP, * which is mandatory for bulk and interrupt EPs */ PUTS("set_feature\n"); break; case SR_CLEAR_FEATURE: /* clear one of the features which have been set by SET_FEATURE */ PUTS("clear_feature\n"); break; case SR_GET_STATUS: PUTS("get_status\n"); get_status(sp); break; case SR_SET_INTERFACE: /* this is used to set alternative interfaces. For example when * the CDC device will be put up */ PUTS("setif"); ACK(); break; case SR_GET_INTERFACE: PUTS("getif"); /* always report the same alternative: 1 */ { uint8_t i = 0x01; reg_t st = {0x00}; do { rreg(EPIRQ, &st); } while( !st.EPIRQ.IN0BAVIRQ ); wregn(EP0FIFO, &i, sizeof(uint8_t), false); i=sizeof(uint8_t); wregn(EP0BC, &i, i, true); } break; case SR_SET_CONFIGURATION: PUTS("set_conf\n"); usbdev.status.configuration = sp->asconfreq.conf; ACK(); return true; break; case SR_GET_CONFIGURATION: PUTS("get_conf\n"); { uint8_t len = sizeof(usbdev.status.configuration); reg_t st = {0x00}; do { rreg(EPIRQ, &st); } while( !st.EPIRQ.IN0BAVIRQ ); wregn(EP0FIFO, &usbdev.status.configuration, len, false); wregn(EP0BC, &len, sizeof(len), true); } break; default: PUTS("unknown std_req()"); STALLEP0(); } return false; }