void MImHwKeyboardTrackerPrivate::tryEvdevDevice(const char *device) { QFile *qfile = new QFile(this); unsigned char evbits[BITS2BYTES(EV_MAX)]; int fd; qfile->setFileName(device); if (!qfile->open(QIODevice::ReadOnly | QIODevice::Unbuffered)) { delete qfile; return; } fd = qfile->handle(); if (fd == -1) { delete qfile; return; } if (ioctl(fd, EVIOCGBIT(0, EV_MAX), evbits) < 0) { delete qfile; return; } // Check that this input device has switches if (!TEST_BIT(EV_SW, evbits)) { delete qfile; return; } unsigned char swbit[BITS2BYTES(EV_MAX)]; if (ioctl(fd, EVIOCGBIT(EV_SW, SW_CNT), swbit) < 0) { delete qfile; return; } // Check that there is a tablet mode switch here if (!TEST_BIT(SW_TABLET_MODE, swbit)) { delete qfile; return; } // Found an appropriate device - start monitoring it QSocketNotifier *sn = new QSocketNotifier(fd, QSocketNotifier::Read, qfile); sn->setEnabled(true); QObject::connect(sn, SIGNAL(activated(int)), this, SLOT(evdevEvent())); evdevFile = qfile; present = true; // Initialise initial tablet mode state unsigned long state[BITS2BYTES(SW_MAX)]; if (ioctl(fd, EVIOCGSW(SW_MAX), state) < 0) return; evdevTabletMode = TEST_BIT(SW_TABLET_MODE, state); }
static void ebc_anal_jmp(RAnalOp *op, ut64 addr, const ut8 *buf) { op->fail = addr + 6; op->jump = (ut64)*(int32_t*)(buf + 2); if (TEST_BIT(buf[1], 4)) op->jump += addr + 6; if (buf[1] & 0x7) { op->type = R_ANAL_OP_TYPE_UJMP; } else { if (TEST_BIT(buf[1], 7)) { op->type = R_ANAL_OP_TYPE_CJMP; } else { op->type = R_ANAL_OP_TYPE_JMP; } } }
static void cfg_blocks_add (basic_block bb) { gcc_assert (bb != ENTRY_BLOCK_PTR && bb != EXIT_BLOCK_PTR); gcc_assert (!TEST_BIT (bb_in_list, bb->index)); if (cfg_blocks_empty_p ()) { cfg_blocks_tail = cfg_blocks_head = 0; cfg_blocks_num = 1; } else { cfg_blocks_num++; if (cfg_blocks_num > VARRAY_SIZE (cfg_blocks)) { /* We have to grow the array now. Adjust to queue to occupy the full space of the original array. */ cfg_blocks_tail = VARRAY_SIZE (cfg_blocks); cfg_blocks_head = 0; VARRAY_GROW (cfg_blocks, 2 * VARRAY_SIZE (cfg_blocks)); } else cfg_blocks_tail = (cfg_blocks_tail + 1) % VARRAY_SIZE (cfg_blocks); } VARRAY_BB (cfg_blocks, cfg_blocks_tail) = bb; SET_BIT (bb_in_list, bb->index); }
edge cached_make_edge (sbitmap edge_cache, basic_block src, basic_block dst, int flags) { if (edge_cache == NULL || src == ENTRY_BLOCK_PTR || dst == EXIT_BLOCK_PTR) return make_edge (src, dst, flags); /* Does the requested edge already exist? */ if (! TEST_BIT (edge_cache, dst->index)) { /* The edge does not exist. Create one and update the cache. */ SET_BIT (edge_cache, dst->index); return unchecked_make_edge (src, dst, flags); } /* At this point, we know that the requested edge exists. Adjust flags if necessary. */ if (flags) { edge e = find_edge (src, dst); e->flags |= flags; } return NULL; }
void chunkArchive::do_tagging(enum atoms TAG) { if (!TEST_BIT(status_bits, bTAG)) return; CLEAR_BIT(status_bits, bTAG); writeBlock((const char *) &TAG, 1); }
ssize_t iio_device_get_sample_size_mask(const struct iio_device *dev, const uint32_t *mask, size_t words) { ssize_t size = 0; unsigned int i; if (words != (dev->nb_channels + 31) / 32) return -EINVAL; for (i = 0; i < dev->nb_channels; i++) { const struct iio_channel *chn = dev->channels[i]; unsigned int length = chn->format.length / 8; if (chn->index < 0) break; if (!TEST_BIT(mask, chn->index)) continue; if (size % length) size += 2 * length - (size % length); else size += length; } return size; }
char *mem_pool::mem_pool_impl::alloc_page(int &index) { assert(inited == 1); if(free_pages == 0) { return 0; /* there are no pages to allocate */ } /* * find a free page index from bitmap */ int page_index; for(;; ++current_page) { if(current_page == total_pages) { current_page = 0; } if(TEST_BIT(page_bitmap, current_page) == 0) { /* found */ page_index = current_page++; break; } } index = page_index; --free_pages; SET_BIT(page_bitmap, index); return index_to_page(index); }
int open_dev(const char *path) { if((dev_fd = open(path, O_RDWR)) == -1) { if((dev_fd = open(path, O_RDONLY)) == -1) { perror("failed to open device"); return -1; } fprintf(stderr, "opened device read-only, LEDs won't work\n"); } if(ioctl(dev_fd, EVIOCGNAME(sizeof(dev_name)), dev_name) == -1) { perror("EVIOCGNAME ioctl failed\n"); strcpy(dev_name, "unknown"); } if(ioctl(dev_fd, EVIOCGBIT(0, sizeof(evtype_mask)), evtype_mask) == -1) { perror("EVIOCGBIT ioctl failed\n"); close(dev_fd); dev_fd = -1; return -1; } if(!TEST_BIT(EV_REL, evtype_mask)) { fprintf(stderr, "Wrong device, no relative events reported!\n"); close(dev_fd); dev_fd = -1; return -1; } if(cfg.led) { set_led(1); } return 0; }
void * iio_buffer_first(const struct iio_buffer *buffer, const struct iio_channel *chn) { size_t len; unsigned int i; uintptr_t ptr = (uintptr_t) buffer->buffer; if (!iio_channel_is_enabled(chn)) return iio_buffer_end(buffer); for (i = 0; i < buffer->dev->nb_channels; i++) { struct iio_channel *cur = buffer->dev->channels[i]; len = cur->format.length / 8; /* NOTE: dev->channels are ordered by index */ if (cur->index < 0 || cur->index == chn->index) break; /* Test if the buffer has samples for this channel */ if (!TEST_BIT(buffer->mask, cur->index)) continue; if (ptr % len) ptr += len - (ptr % len); ptr += len; } len = chn->format.length / 8; if (ptr % len) ptr += len - (ptr % len); return (void *) ptr; }
static bool fill_joystick_buttons(ALLEGRO_JOYSTICK_LINUX *joy, int fd) { unsigned long key_bits[NLONGS(KEY_CNT)] = {0}; int b; int i; if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)), key_bits) < 0) return false; b = 0; for (i = LJOY_BTN_RANGE_START; i < LJOY_BTN_RANGE_END; i++) { if (TEST_BIT(i, key_bits) && is_joystick_button(i)) { joy->button_mapping[b].ev_code = i; ALLEGRO_DEBUG("Input event code %d maps to button %d\n", i, b); joy->parent.info.button[b].name = al_malloc(32); snprintf((char *)joy->parent.info.button[b].name, 32, "B%d", b+1); b++; if (b == _AL_MAX_JOYSTICK_BUTTONS) break; } } joy->parent.info.num_buttons = b; /* Clear the rest. */ for (; b < _AL_MAX_JOYSTICK_BUTTONS; b++) { joy->button_mapping[b].ev_code = -1; } return true; }
/*! * @brief Function to control reset operations * * @param halObj Pointer to the HAL object * @param cmd Reset control command * @param arg Arguments specific to the reset control command * * @sa */ Int DM8168VIDEOM3_halResetCtrl(Ptr halObj, Processor_ResetCtrlCmd cmd, Ptr args) { Int status = PROCESSOR_SUCCESS; DM8168VIDEOM3_HalObject * halObject = NULL; GT_3trace(curTrace, GT_ENTER, "DM8168VIDEOM3_halResetCtrl", halObj, cmd, args); GT_assert(curTrace, (halObj != NULL)); GT_assert(curTrace, (cmd < Processor_ResetCtrlCmd_EndValue)); halObject = (DM8168VIDEOM3_HalObject *) halObj ; switch (cmd) { case Processor_ResetCtrlCmd_Reset: { /*Put ONLY Ducati M3_0 to Reset*/ SET_BIT (REG((halObject->prcmBase) + RM_DEFAULT_RSTCTRL), 0x2); /* clear the status bit only if it is set*/ if(TEST_BIT(REG((halObject->prcmBase) + RM_DEFAULT_RSTST) , 0x2)) { REG((halObject->prcmBase) + RM_DEFAULT_RSTST) = 0x4; } } break; case Processor_ResetCtrlCmd_Release: { /*Bring ONLY Ducati M3_0 out of Reset*/ CLEAR_BIT (REG((halObject->prcmBase) + RM_DEFAULT_RSTCTRL), 0x2); /*Check for Ducati M3_0 out of Reset*/ while((((REG(halObject->prcmBase + RM_DEFAULT_RSTST)&0x04))!=0x04) && (((REG(halObject->prcmBase + RM_DEFAULT_RSTST)&0x14))!=0x14) && (((REG(halObject->prcmBase + RM_DEFAULT_RSTST)&0x1C))!=0x1C)) ; /*Check Module is in Functional Mode */ while(((REG(halObject->prcmBase + CM_DEFAULT_DUCATI_CLKCTRL)&0x30000)>>16)!=0) ; } break; case Processor_ResetCtrlCmd_PeripheralUp: { /* Nothing to be done to bringup the peripherals for this device. */ } break; default: { /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */ status = PROCESSOR_E_INVALIDARG; GT_setFailureReason (curTrace, GT_4CLASS, "DM8168VIDEOM3_halResetCtrl", status, "Unsupported reset ctrl cmd specified"); } break; } GT_1trace(curTrace, GT_LEAVE, "DM8168VIDEOM3_halResetCtrl",status); /*! @retval PROCESSOR_SUCCESS Operation successful */ return status; }
int expandList1_ (char ***tolist, int num, int *bitmMaps, char **keys) { int ii, jj, isSet; char **temp; if (num <= 0) return 0; if ((temp = (char **) calloc (num, sizeof (char *))) == NULL) { lserrno = LSE_MALLOC; return (-1); } for (ii = 0, jj = 0; ii < num; ii++) { TEST_BIT (ii, bitmMaps, isSet); if (isSet == 1) { temp[jj++] = keys[ii]; } } if (jj > 0) { *tolist = temp; } else { FREEUP (temp); *tolist = NULL; } return (jj); }
void Vga::draw() { if(SDL_MUSTLOCK(screen)) { SDL_LockSurface(screen); } for(int y = 0; y < VGA_HEIGHT; ++y) { for(int x = 0; x < VGA_WIDTH; x += (sizeof(ensitlm::data_t) * CHAR_BIT)) { ensitlm::data_t d; initiator.read(address + ((x + (y * VGA_LINE)) / CHAR_BIT), d); for(unsigned int bit = 0; bit < (sizeof(ensitlm::data_t) * CHAR_BIT); ++bit) { Uint16 *bufp = (Uint16 *) screen->pixels + x + (y * screen->pitch / 2) + ((sizeof(ensitlm::data_t) * CHAR_BIT) - 1 - bit); if(TEST_BIT(d, bit)) { *bufp = white; } else { *bufp = black; } } } } if(SDL_MUSTLOCK(screen)) { SDL_UnlockSurface(screen); } SDL_Flip(screen); }
// Expand #1: // wait if other threads already have token. return if this thread is the first. int tree_simple_begin_expand(TreeBlock* parent, BlockOffset parent_offset, TreeBlock **child) { BlockBits expansion_before = __atomic_fetch_or( &parent->expansion, BIT(parent_offset), __ATOMIC_ACQ_REL); if (!TEST_BIT(expansion_before, parent_offset)) { *child = NULL; return EXPAND_STATUS_FIRST; // we've got to do it } ChildInfo* cinfo = &parent->children[parent_offset]; TreeBlock* c; // Wait if no one has done it yet. if ((c = __atomic_load_n(&cinfo->child, __ATOMIC_ACQUIRE)) == NULL) { // We've got to wait. for (;;) { EventCountKey key = event_count_prepare(&cinfo->event_count); if ((c = __atomic_load_n(&cinfo->child, __ATOMIC_ACQUIRE)) != NULL) { event_count_cancel(&cinfo->event_count); break; } event_count_wait(&cinfo->event_count, key); } } *child = c; return EXPAND_STATUS_DONE; }
ssize_t iio_buffer_foreach_sample(struct iio_buffer *buffer, ssize_t (*callback)(const struct iio_channel *, void *, size_t, void *), void *d) { uintptr_t ptr = (uintptr_t) buffer->buffer, end = ptr + buffer->data_length; const struct iio_device *dev = buffer->dev; ssize_t processed = 0; if (buffer->sample_size <= 0) return -EINVAL; if (buffer->data_length < buffer->dev_sample_size) return 0; while (end - ptr >= (size_t) buffer->sample_size) { unsigned int i; for (i = 0; i < dev->nb_channels; i++) { const struct iio_channel *chn = dev->channels[i]; unsigned int length = chn->format.length / 8; if (chn->index < 0) break; /* Test if the buffer has samples for this channel */ if (!TEST_BIT(buffer->mask, chn->index)) continue; if (ptr % length) ptr += length - (ptr % length); /* Test if the client wants samples from this channel */ if (TEST_BIT(dev->mask, chn->index)) { ssize_t ret = callback(chn, (void *) ptr, length, d); if (ret < 0) return ret; else processed += ret; } ptr += length; } } return processed; }
static bool reachable_at_most_once (basic_block va_arg_bb, basic_block va_start_bb) { VEC (edge, heap) *stack = NULL; edge e; edge_iterator ei; sbitmap visited; bool ret; if (va_arg_bb == va_start_bb) return true; if (! dominated_by_p (CDI_DOMINATORS, va_arg_bb, va_start_bb)) return false; visited = sbitmap_alloc (last_basic_block); sbitmap_zero (visited); ret = true; FOR_EACH_EDGE (e, ei, va_arg_bb->preds) VEC_safe_push (edge, heap, stack, e); while (! VEC_empty (edge, stack)) { basic_block src; e = VEC_pop (edge, stack); src = e->src; if (e->flags & EDGE_COMPLEX) { ret = false; break; } if (src == va_start_bb) continue; /* va_arg_bb can be executed more times than va_start_bb. */ if (src == va_arg_bb) { ret = false; break; } gcc_assert (src != ENTRY_BLOCK_PTR); if (! TEST_BIT (visited, src->index)) { SET_BIT (visited, src->index); FOR_EACH_EDGE (e, ei, src->preds) VEC_safe_push (edge, heap, stack, e); } } VEC_free (edge, heap, stack); sbitmap_free (visited); return ret; }
int get_pixel(uint32_t base_addr, int x, int y) { uint32_t addr = base_addr + ALIGN( (x / CHAR_BIT) + (y * (VGA_LINE / CHAR_BIT)) ); int bit = 31 - x % (sizeof(uint32_t) * CHAR_BIT); uint32_t data = read_mem(addr); return (TEST_BIT(data, bit) != 0); }
unsigned char cnn_data_wait_until_evaluated_bit(CNNData* data, unsigned char bit) { unsigned char v = __atomic_load_n(&data->evaluated, __ATOMIC_ACQUIRE); if (!TEST_BIT(v, bit)) { EventCount* ev = &data->event_counts[bit]; for (;;) { EventCountKey ek = event_count_prepare(ev); v = __atomic_load_n(&data->evaluated, __ATOMIC_ACQUIRE); if (TEST_BIT(v, bit)) { event_count_cancel(ev); break; } event_count_wait(ev, ek); } } return v; }
void chunkArchive::ignore() { VALIDF; if (TEST_BIT(status_bits, bCHUNK)) { F->seek(current_chunk_end); CLEAR_BIT(status_bits, bCHUNK); } }
static void page_fault_handler(const struct cpu_state* regs) { uint32_t address = 0; asm("mov %%cr2, %0":"=r"(address)); bool user = TEST_BIT(regs->error_code, 2); bool rw = TEST_BIT(regs->error_code, 1); bool present = TEST_BIT(regs->error_code, 0); printk( PRINTK_ERROR "Page fault at 0x%8lX in %s mode when %s because %s\n", address, user ? "user" : "kernel", rw ? "writing" : "reading", present ? "there was an invalid write" : "the page was not marked present" ); if (!(user)) { panic("bug: kernel triggered page fault"); } }
static void ebc_anal_call(RAnalOp *op, ut64 addr, const ut8 *buf) { int32_t addr_call; op->fail = addr + 6; if ((buf[1] & 0x7) == 0 && TEST_BIT(buf[0], 6) == 0 && TEST_BIT(buf[0], 7)) { addr_call = *(int32_t*)(buf + 2); if (TEST_BIT(buf[1], 4)) { op->jump = (addr + 6 + addr_call); } else { op->jump = addr_call; } op->type = R_ANAL_OP_TYPE_CALL; } else { op->type = R_ANAL_OP_TYPE_UCALL; } }
void mem_pool::mem_pool_impl::free_page(int index) { assert(index > 0 && index < total_pages); /* page 0 is used to META DATA */ if(TEST_BIT(page_bitmap, index) == 0) { /* has already released */ return; } CLEAR_BIT(page_bitmap, index); ++free_pages; }
void chunkArchive::newChunk(unsigned short id) { if (TEST_BIT(status_bits, bCHUNK)) closeChunk(); current_chunk_id = id; writeShort(id); writeLong(0); current_chunk_start = F->pos(); SET_BIT(status_bits, bCHUNK); }
int handle_ioregs_write ( unsigned short addr, char value ) { switch ( addr ) { case JOYP: P14_select_direction_keys = TEST_BIT(value, 4); P15_select_button_keys = TEST_BIT(value, 5); break; case SB: serial_transfer_data = value; break; case SC: serial_shift_clock = TEST_BIT(value, 0); // serial_clock_speed = TEST_BIT(value, 1); // GBC only serial_transfer_start_flag = TEST_BIT(value, 7); break; case DIV: div_reg = 0; break; case TIMA: timer_counter = value & 0xff; break; case TMA: timer_modulo = value; break; case TAC: timer_enabled = TEST_BIT(value, 2); timer_input_clock_select = value & 0x2; timer_counter = 0; break; case NR10: if ( TEST_BIT(audio_enabled, 7) ) { channel1_number_of_sweep_shift = value & 0x7; channel1_sweep_increase_decrease = TEST_BIT(value, 3); channel1_sweep_time = (value & 0x70) >> 4; } break; case NR11: if ( TEST_BIT(audio_enabled, 7) ) { channel1_sound_length_data = value & 0x3f; channel1_wave_pattern_duty = (value & 0xc0) >> 6; }
void tunQueryDevice (int fd, TunDeviceInfo info) { int i; memset (info, 0, sizeof (TunDeviceInfo)); ioctl (fd, EVIOCGBIT (0, EV_MAX), info [0]); for (i = 0; i < EV_MAX; i++) if (TEST_BIT (i, info [0])) ioctl (fd, EVIOCGBIT (i, KEY_MAX), info [i]); }
static void ebc_anal_jmp8(RAnalOp *op, ut64 addr, const ut8 *buf) { int jmpadr = (int8_t)buf[1]; op->jump = addr + 2 + (jmpadr * 2); op->addr = addr; op->fail = addr + 2; if (TEST_BIT(buf[0], 7)) { op->type = R_ANAL_OP_TYPE_CJMP; } else { op->type = R_ANAL_OP_TYPE_JMP; } }
bool SC_LID::isEventCodeSupported(int evtType, int evtCode) { if (evtType != m_lastEventType) { m_lastEventType = evtType; memset(m_eventCodeCaps, 0, sizeof(m_eventCodeCaps)); if (ioctl(m_fd, EVIOCGBIT(evtType, KEY_MAX), m_eventCodeCaps) == -1) { post("LID failed to check event code (error %s)\n", strerror(errno)); return false; } } return TEST_BIT(m_eventCodeCaps, evtCode); }