krb5_error_code KRB5_LIB_FUNCTION krb5_ret_int32(krb5_storage *sp, int32_t *value) { krb5_error_code ret = krb5_ret_int(sp, value, 4); if(ret) return ret; if(BYTEORDER_IS_HOST(sp)) *value = htonl(*value); else if(BYTEORDER_IS_LE(sp)) *value = bswap32(*value); return 0; }
static uint32_t pci_unin_main_config_readl (void *opaque, target_phys_addr_t addr) { UNINState *s = opaque; uint32_t val; val = s->config_reg; #ifdef TARGET_WORDS_BIGENDIAN val = bswap32(val); #endif UNIN_DPRINTF("config_readl addr " TARGET_FMT_plx " val %x\n", addr, val); return val; }
static void F32IEncode( void *outp, const uint8_t *inp, unsigned samples ) { const float *in = (const float *)inp; uint8_t *out = outp; for( size_t i = 0; i < samples; i++ ) { union { float f; uint32_t u; char b[4]; } s; s.f = *(in++); s.u = bswap32( s.u ); memcpy( out, s.b, 4 ); out += 4; } }
static void at91_bswap_buf(struct at91_mci_softc *sc, void * dptr, void * sptr, uint32_t memsize) { uint32_t * dst = (uint32_t *)dptr; uint32_t * src = (uint32_t *)sptr; uint32_t i; /* * If the hardware doesn't need byte-swapping, let bcopy() do the * work. Use bounce buffer even if we don't need byteswap, since * buffer may straddle a page boundry, and we don't handle * multi-segment transfers in hardware. Seen from 'bsdlabel -w' which * uses raw geom access to the volume. Greg Ansley (gja (at) * ansley.com) */ if (!(sc->sc_cap & CAP_NEEDS_BYTESWAP)) { memcpy(dptr, sptr, memsize); return; } /* * Nice performance boost for slightly unrolling this loop. * (But very little extra boost for further unrolling it.) */ for (i = 0; i < memsize; i += 16) { *dst++ = bswap32(*src++); *dst++ = bswap32(*src++); *dst++ = bswap32(*src++); *dst++ = bswap32(*src++); } /* Mop up the last 1-3 words, if any. */ for (i = 0; i < (memsize & 0x0F); i += 4) { *dst++ = bswap32(*src++); } }
static uint32_t empb_bsr4_swap(bus_space_handle_t handle, bus_size_t offset) { uint32_t *p; uint32_t x; bus_addr_t wp; wp = empb_switch_window(empb_sc, handle); p = (uint32_t*) ((empb_sc->pci_mem_win_t->base) + (handle - wp) + offset); x = *p; return bswap32(x); }
uint16_t dkcksum_target(struct disklabel *lp) { uint16_t npartitions; if (lp->d_magic == DISKMAGIC) npartitions = lp->d_npartitions; else if (bswap32(lp->d_magic) == DISKMAGIC) npartitions = bswap16(lp->d_npartitions); else npartitions = 0; if (npartitions > maxpartitions) npartitions = 0; return dkcksum_sized(lp, npartitions); }
void _KEY1::applyKeycode(u8 modulo) { encrypt(&keyCode[1]); encrypt(&keyCode[0]); u32 scratch[2] = {0}; for (u32 i = 0; i <= 0x44; i += 4) // xor with reversed byte-order (bswap) keyBuf[DWNUM(i)] ^= bswap32(keyCode[DWNUM(i % modulo)]); for (u32 i = 0; i <= 0x1040; i += 8) { encrypt(scratch); // encrypt S (64bit) by keybuf keyBuf[DWNUM(i)] = scratch[1]; // write S to keybuf (first upper 32bit) keyBuf[DWNUM(i+4)] = scratch[0]; // write S to keybuf (then lower 32bit) } }
static void empb_bswm4_swap(bus_space_handle_t handle, bus_size_t offset, const u_int32_t *pointer, bus_size_t count) { volatile uint32_t *p; bus_addr_t wp; wp = empb_switch_window(empb_sc, handle); p = (volatile uint32_t *) ((empb_sc->pci_mem_win_t->base) + (handle - wp) + offset); while (count > 0) { *p = bswap32(*pointer++); amiga_bus_reorder_protect(); --count; } }
static void process(lzma_check_state *check) { #ifdef WORDS_BIGENDIAN transform(check->state.sha256.state, check->buffer.u32); #else uint32_t data[16]; size_t i; for (i = 0; i < 16; ++i) data[i] = bswap32(check->buffer.u32[i]); transform(check->state.sha256.state, data); #endif return; }
/* ACPI 1.0b: 15.2.3.6.4.1 EISAID Macro - Convert EISA ID String To Integer */ Aml *aml_eisaid(const char *str) { Aml *var = aml_alloc(); uint32_t id; g_assert(strlen(str) == 7); id = (str[0] - 0x40) << 26 | (str[1] - 0x40) << 21 | (str[2] - 0x40) << 16 | Hex2Digit(str[3]) << 12 | Hex2Digit(str[4]) << 8 | Hex2Digit(str[5]) << 4 | Hex2Digit(str[6]); build_append_byte(var->buf, 0x0C); /* DWordPrefix */ build_append_int_noprefix(var->buf, bswap32(id), sizeof(id)); return var; }
struct atsc_ett_section *atsc_ett_section_codec(struct atsc_section_psip *psip) { uint8_t * buf = (uint8_t *) psip; size_t pos = sizeof(struct atsc_section_psip); size_t len = section_ext_length(&(psip->ext_head)); if (len < sizeof(struct atsc_ett_section)) return NULL; bswap32(buf + pos); pos += 4; if (atsc_text_validate(buf + pos, section_ext_length(&psip->ext_head) - sizeof(struct atsc_ett_section))) return NULL; return (struct atsc_ett_section *) psip; }
void MsgDialog :: swap(uint8_t* aBuf) const { ASSERT(aBuf != nullptr); MsgInfo* info = (MsgInfo*)aBuf; if (info->Action == ACTION_TASKID) { info->TaskId = bswap32(info->TaskId); } else { info->PosX = bswap16(info->PosX); info->PosY = bswap16(info->PosY); } info->Data = bswap16(info->Data); }
void fw_cfg_setup(void) { int i, n; fw_cfg_select(FW_CFG_ID); version = fw_cfg_readl_le(); fw_cfg_select(FW_CFG_FILE_DIR); n = fw_cfg_readl_be(); filecnt = n; files = malloc_fseg(sizeof(files[0]) * n); fw_cfg_read(files, sizeof(files[0]) * n); for (i = 0; i < n; i++) { struct fw_cfg_file *f = &files[i]; f->size = bswap32(f->size); f->select = bswap16(f->select); } }
static inline void endian_fix32(uint32_t * tofix, size_t count) { /* bFLT is always big endian */ /* endianness test */ union { uint16_t int_val; uint8_t char_val[2]; } endian; endian.int_val = 1; if (endian.char_val[0]) { /* we are little endian, do a byteswap */ size_t i; for (i=0; i<count; i++) { tofix[i] = bswap32(tofix[i]); } } }
struct atsc_stt_section *atsc_stt_section_codec(struct atsc_section_psip *psip) { uint8_t *buf = (uint8_t *) psip; size_t pos = sizeof(struct atsc_section_psip); size_t len = section_ext_length(&(psip->ext_head)); if (len < sizeof(struct atsc_stt_section)) return NULL; bswap32(buf + pos); pos += 5; bswap16(buf + pos); pos += 2; if (verify_descriptors(buf + pos, len - sizeof(struct atsc_stt_section))) return NULL; return (struct atsc_stt_section *) psip; }
bool MediaEngine::stepVideo(int videoPixelMode) { // if video engine is broken, force to add timestamp m_videopts += 3003; #ifdef USE_FFMPEG updateSwsFormat(videoPixelMode); // TODO: Technically we could set this to frameWidth instead of m_desWidth for better perf. // Update the linesize for the new format too. We started with the largest size, so it should fit. m_pFrameRGB->linesize[0] = getPixelFormatBytes(videoPixelMode) * m_desWidth; AVFormatContext *pFormatCtx = (AVFormatContext*)m_pFormatCtx; AVCodecContext *pCodecCtx = (AVCodecContext*)m_pCodecCtx; AVFrame *pFrame = (AVFrame*)m_pFrame; AVFrame *pFrameRGB = (AVFrame*)m_pFrameRGB; if ((!m_pFrame)||(!m_pFrameRGB)) return false; AVPacket packet; int frameFinished; bool bGetFrame = false; while(av_read_frame(pFormatCtx, &packet)>=0) { if(packet.stream_index == m_videoStream) { // Decode video frame avcodec_decode_video2(pCodecCtx, m_pFrame, &frameFinished, &packet); sws_scale(m_sws_ctx, m_pFrame->data, m_pFrame->linesize, 0, pCodecCtx->height, m_pFrameRGB->data, m_pFrameRGB->linesize); if(frameFinished) { int firstTimeStamp = bswap32(*(int*)(m_pdata + 86)); m_videopts = pFrame->pkt_dts + pFrame->pkt_duration - firstTimeStamp; bGetFrame = true; } } av_free_packet(&packet); if (bGetFrame) break; } if (!bGetFrame && m_readSize >= m_streamSize) m_isVideoEnd = true; return bGetFrame; #else return true; #endif // USE_FFMPEG }
static uint32_t pci_cfg_read_32bit(uint32_t addr) { uint32_t temp = 0; uint32_t *p = (uint32_t *)xlr_pci_config_base + addr / sizeof(uint32_t); uint64_t cerr_cpu_log = 0; disable_and_clear_cache_error(); temp = bswap32(*p); /* Read cache err log */ cerr_cpu_log = read_xlr_ctrl_register(CPU_BLOCKID_LSU, LSU_CERRLOG_REGID); if (cerr_cpu_log) { /* Device don't exist. */ temp = ~0x0; } clear_and_enable_cache_error(); return (temp); }
void setup_openpic_ipi(void) { uint32_t x; ipiops.ppc_send_ipi = openpic_send_ipi; ipiops.ppc_establish_ipi = openpic_establish_ipi; ipiops.ppc_ipi_vector = IPI_VECTOR; /* Some (broken) openpic's byteswap on read, but not write. */ openpic_write(OPENPIC_IPI_VECTOR(0), OPENPIC_IMASK); x = openpic_read(OPENPIC_IPI_VECTOR(0)); if (x != OPENPIC_IMASK) x = bswap32(openpic_read(OPENPIC_IPI_VECTOR(1))); else x = openpic_read(OPENPIC_IPI_VECTOR(1)); x &= ~(OPENPIC_IMASK | OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK); x |= (15 << OPENPIC_PRIORITY_SHIFT) | ipiops.ppc_ipi_vector; openpic_write(OPENPIC_IPI_VECTOR(1), x); }
int MediaEngine::addStreamData(u8* buffer, int addSize) { int size = addSize; if (size > 0 && m_pdata) { if (!m_pdata->push(buffer, size)) size = 0; if (m_demux) { m_demux->addStreamData(buffer, addSize); m_demux->demux(m_audioStream); } #ifdef USE_FFMPEG if (!m_pFormatCtx) { m_pdata->get_front(m_mpegheader, sizeof(m_mpegheader)); int mpegoffset = bswap32(*(int*)(m_mpegheader + 8)); m_pdata->pop_front(0, mpegoffset); openContext(); } #endif // USE_FFMPEG } return size; }
/* * This swaps endian for a hammer2_msg_hdr. Note that the extended * header is not adjusted, just the core header. */ void hammer2_bswap_head(hammer2_msg_hdr_t *head) { head->magic = bswap16(head->magic); head->reserved02 = bswap16(head->reserved02); head->salt = bswap32(head->salt); head->msgid = bswap64(head->msgid); head->source = bswap64(head->source); head->target = bswap64(head->target); head->cmd = bswap32(head->cmd); head->aux_crc = bswap32(head->aux_crc); head->aux_bytes = bswap32(head->aux_bytes); head->error = bswap32(head->error); head->aux_descr = bswap64(head->aux_descr); head->reserved38= bswap32(head->reserved38); head->hdr_crc = bswap32(head->hdr_crc); }
int MediaEngine::addStreamData(u8* buffer, int addSize) { int size = addSize; if (size > 0 && m_pdata) { if (!m_pdata->push(buffer, size)) size = 0; if (m_demux) { m_demux->addStreamData(buffer, addSize); } #ifdef USE_FFMPEG if (!m_pFormatCtx && m_pdata->getQueueSize() >= 2048) { m_pdata->get_front(m_mpegheader, sizeof(m_mpegheader)); int mpegoffset = bswap32(*(int*)(m_mpegheader + 8)); m_pdata->pop_front(0, mpegoffset); openContext(); } #endif // USE_FFMPEG // We added data, so... not the end anymore? m_isVideoEnd = false; } return size; }
/* * This needs hacking and fixery. It is currently broke and hangs. * Debugging it will be tricky; there seems to be no way to enable * a target abort which would cause a nice target abort. * Look at linux again? */ static u_int32_t siba_pcib_read_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, int bytes) { struct siba_pcib_softc *sc = device_get_softc(dev); bus_addr_t cfgaddr; uint32_t cfgtag; uint32_t val; /* XXX anything higher than slot 2 currently seems to hang the bus. * not sure why this is; look at linux again */ if (bus != 0 || slot > 2) { printf("%s: bad b/s/f %d/%d/%d\n", __func__, bus, slot, func); return 0xffffffff; // XXX } device_printf(dev, "requested %d bytes from b/s/f %d/%d/%d reg %d\n", bytes, bus, slot, func, reg); /* * The configuration tag on the broadcom is weird. */ SBPCI_WRITE_4(sc, SIBA_PCICORE_SBTOPCI1, 2); /* XXX again??? */ cfgtag = ((1 << slot) << 16) | (func << 8); cfgaddr = SBPCI_CFGBASE | cfgtag | (reg & ~3); /* cfg space i/o is always 32 bits on this bridge */ printf("reading 4 bytes from %08x\n", cfgaddr); val = *(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(cfgaddr); /* XXX MIPS */ val = bswap32(val); /* XXX seems to be needed for now */ /* swizzle and return what was asked for */ val &= 0xffffffff >> ((4 - bytes) * 8); return (val); }
Psmf::Psmf(u32 data) { headerOffset = data; magic = Memory::Read_U32(data); version = Memory::Read_U32(data + 4); streamOffset = bswap32(Memory::Read_U32(data + 8)); streamSize = bswap32(Memory::Read_U32(data + 12)); streamDataTotalSize = bswap32(Memory::Read_U32(data + 0x50)); presentationStartTime = bswap32(Memory::Read_U32(data + PSMF_FIRST_TIMESTAMP_OFFSET)); presentationEndTime = bswap32(Memory::Read_U32(data + PSMF_LAST_TIMESTAMP_OFFSET)); streamDataNextBlockSize = bswap32(Memory::Read_U32(data + 0x6A)); streamDataNextInnerBlockSize = bswap32(Memory::Read_U32(data + 0x7C)); numStreams = bswap16(Memory::Read_U16(data + 0x80)); currentStreamNum = -1; currentAudioStreamNum = -1; currentVideoStreamNum = -1; for (int i = 0; i < numStreams; i++) { PsmfStream *stream = 0; u32 currentStreamAddr = data + 0x82 + i * 16; int streamId = Memory::Read_U8(currentStreamAddr); if ((streamId & PSMF_VIDEO_STREAM_ID) == PSMF_VIDEO_STREAM_ID) { stream = new PsmfStream(PSMF_AVC_STREAM, 0); stream->readMPEGVideoStreamParams(currentStreamAddr, this); currentVideoStreamNum++; } else if ((streamId & PSMF_AUDIO_STREAM_ID) == PSMF_AUDIO_STREAM_ID) { stream = new PsmfStream(PSMF_ATRAC_STREAM, 1); stream->readPrivateAudioStreamParams(currentStreamAddr, this); currentAudioStreamNum++; } if (stream) { currentStreamNum++; streamMap[currentStreamNum] = stream; } } }
static inline uint32_t SWAPU32(uint32_t x) { return bswap32(x); }
static inline int32_t SWAPS32(int32_t x) { return bswap32(x); }
void AnalyzeMpeg(u32 buffer_addr, MpegContext *ctx) { ctx->mpegStreamAddr = buffer_addr; ctx->mpegMagic = Memory::Read_U32(buffer_addr); ctx->mpegRawVersion = Memory::Read_U32(buffer_addr + PSMF_STREAM_VERSION_OFFSET); switch (ctx->mpegRawVersion) { case PSMF_VERSION_0012: ctx->mpegVersion = MPEG_VERSION_0012; break; case PSMF_VERSION_0013: ctx->mpegVersion = MPEG_VERSION_0013; break; case PSMF_VERSION_0014: ctx->mpegVersion = MPEG_VERSION_0014; break; case PSMF_VERSION_0015: ctx->mpegVersion = MPEG_VERSION_0015; break; default: ctx->mpegVersion = -1; break; } ctx->mpegOffset = bswap32(Memory::Read_U32(buffer_addr + PSMF_STREAM_OFFSET_OFFSET)); ctx->mpegStreamSize = bswap32(Memory::Read_U32(buffer_addr + PSMF_STREAM_SIZE_OFFSET)); ctx->mpegFirstTimestamp = getMpegTimeStamp(Memory::GetPointer(buffer_addr + PSMF_FIRST_TIMESTAMP_OFFSET)); ctx->mpegLastTimestamp = getMpegTimeStamp(Memory::GetPointer(buffer_addr + PSMF_LAST_TIMESTAMP_OFFSET)); ctx->mpegFirstDate = convertTimestampToDate(ctx->mpegFirstTimestamp); ctx->mpegLastDate = convertTimestampToDate(ctx->mpegLastTimestamp); ctx->avc.avcDetailFrameWidth = (Memory::Read_U8(buffer_addr + 142) * 0x10); ctx->avc.avcDetailFrameHeight = (Memory::Read_U8(buffer_addr + 143) * 0x10); ctx->avc.avcDecodeResult = MPEG_AVC_DECODE_SUCCESS; ctx->avc.avcFrameStatus = 0; ctx->videoFrameCount = 0; ctx->audioFrameCount = 0; ctx->endOfAudioReached = false; ctx->endOfVideoReached = false; if (ctx->mpegMagic != PSMF_MAGIC || ctx->mpegVersion < 0 || (ctx->mpegOffset & 2047) != 0 || ctx->mpegOffset == 0) { // mpeg header is invalid! return; } if (ctx->mediaengine && (ctx->mpegStreamSize > 0) && !ctx->isAnalyzed) { // init mediaEngine SceMpegRingBuffer ringbuffer = {0}; if(ctx->mpegRingbufferAddr != 0){ Memory::ReadStruct(ctx->mpegRingbufferAddr, &ringbuffer); }; ctx->mediaengine->loadStream(Memory::GetPointer(buffer_addr), ctx->mpegOffset, ringbuffer.packets * ringbuffer.packetSize); ctx->mediaengine->setVideoDim(); } // When used with scePsmf, some applications attempt to use sceMpegQueryStreamOffset // and sceMpegQueryStreamSize, which forces a packet overwrite in the Media Engine and in // the MPEG ringbuffer. // Mark the current MPEG as analyzed to filter this, and restore it at sceMpegFinish. ctx->isAnalyzed = true; INFO_LOG(ME, "Stream offset: %d, Stream size: 0x%X", ctx->mpegOffset, ctx->mpegStreamSize); INFO_LOG(ME, "First timestamp: %lld, Last timestamp: %lld", ctx->mpegFirstTimestamp, ctx->mpegLastTimestamp); }
/* * Scan each entry in a directory block. */ int dirscan(struct inodesc *idesc) { struct direct *dp; struct bufarea *bp; int dsize, n; long blksiz; #if DIRBLKSIZ > APPLEUFS_DIRBLKSIZ char dbuf[DIRBLKSIZ]; #else char dbuf[APPLEUFS_DIRBLKSIZ]; #endif if (idesc->id_type != DATA) errexit("wrong type to dirscan %d", idesc->id_type); if (idesc->id_entryno == 0 && (idesc->id_filesize & (dirblksiz - 1)) != 0) idesc->id_filesize = roundup(idesc->id_filesize, dirblksiz); blksiz = idesc->id_numfrags * sblock->fs_fsize; if (chkrange(idesc->id_blkno, idesc->id_numfrags)) { idesc->id_filesize -= blksiz; return (SKIP); } /* * If we are are swapping byte order in directory entries, just swap * this block and return. */ if (do_dirswap) { int off; bp = getdirblk(idesc->id_blkno, blksiz); for (off = 0; off < blksiz; off += iswap16(dp->d_reclen)) { dp = (struct direct *)(bp->b_un.b_buf + off); dp->d_ino = bswap32(dp->d_ino); dp->d_reclen = bswap16(dp->d_reclen); if (!newinofmt) { u_int8_t tmp = dp->d_namlen; dp->d_namlen = dp->d_type; dp->d_type = tmp; } if (dp->d_reclen == 0) break; } dirty(bp); idesc->id_filesize -= blksiz; return (idesc->id_filesize > 0 ? KEEPON : STOP); } idesc->id_loc = 0; for (dp = fsck_readdir(idesc); dp != NULL; dp = fsck_readdir(idesc)) { dsize = iswap16(dp->d_reclen); if (dsize > sizeof dbuf) dsize = sizeof dbuf; memmove(dbuf, dp, (size_t)dsize); # if (BYTE_ORDER == LITTLE_ENDIAN) if (!newinofmt && !needswap) { # else if (!newinofmt && needswap) { # endif struct direct *tdp = (struct direct *)dbuf; u_char tmp; tmp = tdp->d_namlen; tdp->d_namlen = tdp->d_type; tdp->d_type = tmp; } idesc->id_dirp = (struct direct *)dbuf; if ((n = (*idesc->id_func)(idesc)) & ALTERED) { # if (BYTE_ORDER == LITTLE_ENDIAN) if (!newinofmt && !doinglevel2 && !needswap) { # else if (!newinofmt && !doinglevel2 && needswap) { # endif struct direct *tdp; u_char tmp; tdp = (struct direct *)dbuf; tmp = tdp->d_namlen; tdp->d_namlen = tdp->d_type; tdp->d_type = tmp; } bp = getdirblk(idesc->id_blkno, blksiz); memmove(bp->b_un.b_buf + idesc->id_loc - dsize, dbuf, (size_t)dsize); dirty(bp); sbdirty(); } if (n & STOP) return (n); } return (idesc->id_filesize > 0 ? KEEPON : STOP); } /* * get next entry in a directory. */ static struct direct * fsck_readdir(struct inodesc *idesc) { struct direct *dp, *ndp; struct bufarea *bp; long size, blksiz, fix, dploc; blksiz = idesc->id_numfrags * sblock->fs_fsize; bp = getdirblk(idesc->id_blkno, blksiz); if (idesc->id_loc % dirblksiz == 0 && idesc->id_filesize > 0 && idesc->id_loc < blksiz) { dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc); if (dircheck(idesc, dp)) goto dpok; if (idesc->id_fix == IGNORE) return (0); fix = dofix(idesc, "DIRECTORY CORRUPTED"); bp = getdirblk(idesc->id_blkno, blksiz); dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc); dp->d_reclen = iswap16(dirblksiz); dp->d_ino = 0; dp->d_type = 0; dp->d_namlen = 0; dp->d_name[0] = '\0'; if (fix) dirty(bp); else markclean = 0; idesc->id_loc += dirblksiz; idesc->id_filesize -= dirblksiz; return (dp); } dpok: if (idesc->id_filesize <= 0 || idesc->id_loc >= blksiz) return NULL; dploc = idesc->id_loc; dp = (struct direct *)(bp->b_un.b_buf + dploc); idesc->id_loc += iswap16(dp->d_reclen); idesc->id_filesize -= iswap16(dp->d_reclen); if ((idesc->id_loc % dirblksiz) == 0) return (dp); ndp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc); if (idesc->id_loc < blksiz && idesc->id_filesize > 0 && dircheck(idesc, ndp) == 0) { size = dirblksiz - (idesc->id_loc % dirblksiz); idesc->id_loc += size; idesc->id_filesize -= size; if (idesc->id_fix == IGNORE) return (0); fix = dofix(idesc, "DIRECTORY CORRUPTED"); bp = getdirblk(idesc->id_blkno, blksiz); dp = (struct direct *)(bp->b_un.b_buf + dploc); dp->d_reclen = iswap16(iswap16(dp->d_reclen) + size); if (fix) dirty(bp); else markclean = 0; } return (dp); } /* * Verify that a directory entry is valid. * This is a superset of the checks made in the kernel. */ static int dircheck(struct inodesc *idesc, struct direct *dp) { int size; char *cp; u_char namlen, type; int spaceleft; spaceleft = dirblksiz - (idesc->id_loc % dirblksiz); if (iswap32(dp->d_ino) >= maxino || dp->d_reclen == 0 || iswap16(dp->d_reclen) > spaceleft || (iswap16(dp->d_reclen) & 0x3) != 0) return (0); if (dp->d_ino == 0) return (1); size = DIRSIZ(!newinofmt, dp, needswap); # if (BYTE_ORDER == LITTLE_ENDIAN) if (!newinofmt && !needswap) { # else if (!newinofmt && needswap) { # endif type = dp->d_namlen; namlen = dp->d_type; } else { namlen = dp->d_namlen; type = dp->d_type; } if (iswap16(dp->d_reclen) < size || idesc->id_filesize < size || /* namlen > MAXNAMLEN || */ type > 15) return (0); for (cp = dp->d_name, size = 0; size < namlen; size++) if (*cp == '\0' || (*cp++ == '/')) return (0); if (*cp != '\0') return (0); return (1); } void direrror(ino_t ino, const char *errmesg) { fileerror(ino, ino, errmesg); } void fileerror(ino_t cwd, ino_t ino, const char *errmesg) { union dinode *dp; char pathbuf[MAXPATHLEN + 1]; uint16_t mode; pwarn("%s ", errmesg); pinode(ino); printf("\n"); getpathname(pathbuf, sizeof(pathbuf), cwd, ino); if (ino < ROOTINO || ino > maxino) { pfatal("NAME=%s\n", pathbuf); return; } dp = ginode(ino); if (ftypeok(dp)) { mode = DIP(dp, mode); pfatal("%s=%s\n", (iswap16(mode) & IFMT) == IFDIR ? "DIR" : "FILE", pathbuf); } else pfatal("NAME=%s\n", pathbuf); } void adjust(struct inodesc *idesc, int lcnt) { union dinode *dp; int16_t nlink; int saveresolved; dp = ginode(idesc->id_number); nlink = iswap16(DIP(dp, nlink)); if (nlink == lcnt) { /* * If we have not hit any unresolved problems, are running * in preen mode, and are on a file system using soft updates, * then just toss any partially allocated files. */ if (resolved && preen && usedsoftdep) { clri(idesc, "UNREF", 1); return; } else { /* * The file system can be marked clean even if * a file is not linked up, but is cleared. * Hence, resolved should not be cleared when * linkup is answered no, but clri is answered yes. */ saveresolved = resolved; if (linkup(idesc->id_number, (ino_t)0, NULL) == 0) { resolved = saveresolved; clri(idesc, "UNREF", 0); return; } /* * Account for the new reference created by linkup(). */ dp = ginode(idesc->id_number); lcnt--; } } if (lcnt != 0) { pwarn("LINK COUNT %s", (lfdir == idesc->id_number) ? lfname : ((iswap16(DIP(dp, mode)) & IFMT) == IFDIR ? "DIR" : "FILE")); pinode(idesc->id_number); printf(" COUNT %d SHOULD BE %d", nlink, nlink - lcnt); if (preen || usedsoftdep) { if (lcnt < 0) { printf("\n"); pfatal("LINK COUNT INCREASING"); } if (preen) printf(" (ADJUSTED)\n"); } if (preen || reply("ADJUST") == 1) { DIP_SET(dp, nlink, iswap16(nlink - lcnt)); inodirty(); } else markclean = 0; } } static int mkentry(struct inodesc *idesc) { struct direct *dirp = idesc->id_dirp; struct direct newent; int newlen, oldlen; newent.d_namlen = strlen(idesc->id_name); newlen = DIRSIZ(0, &newent, 0); if (dirp->d_ino != 0) oldlen = DIRSIZ(0, dirp, 0); else oldlen = 0; if (iswap16(dirp->d_reclen) - oldlen < newlen) return (KEEPON); newent.d_reclen = iswap16(iswap16(dirp->d_reclen) - oldlen); dirp->d_reclen = iswap16(oldlen); dirp = (struct direct *)(((char *)dirp) + oldlen); /* ino to be entered is in id_parent */ dirp->d_ino = iswap32(idesc->id_parent); dirp->d_reclen = newent.d_reclen; if (newinofmt) dirp->d_type = inoinfo(idesc->id_parent)->ino_type; else dirp->d_type = 0; dirp->d_namlen = newent.d_namlen; memmove(dirp->d_name, idesc->id_name, (size_t)newent.d_namlen + 1); # if (BYTE_ORDER == LITTLE_ENDIAN) /* * If the entry was split, dirscan() will only reverse the byte * order of the original entry, and not the new one, before * writing it back out. So, we reverse the byte order here if * necessary. */ if (oldlen != 0 && !newinofmt && !doinglevel2 && !needswap) { # else if (oldlen != 0 && !newinofmt && !doinglevel2 && needswap) { # endif u_char tmp; tmp = dirp->d_namlen; dirp->d_namlen = dirp->d_type; dirp->d_type = tmp; } return (ALTERED|STOP); } static int chgino(struct inodesc *idesc) { struct direct *dirp = idesc->id_dirp; if (memcmp(dirp->d_name, idesc->id_name, (int)dirp->d_namlen + 1)) return (KEEPON); dirp->d_ino = iswap32(idesc->id_parent); if (newinofmt) dirp->d_type = inoinfo(idesc->id_parent)->ino_type; else dirp->d_type = 0; return (ALTERED|STOP); } int linkup(ino_t orphan, ino_t parentdir, char *name) { union dinode *dp; int lostdir; ino_t oldlfdir; struct inodesc idesc; char tempname[BUFSIZ]; int16_t nlink; uint16_t mode; memset(&idesc, 0, sizeof(struct inodesc)); dp = ginode(orphan); mode = iswap16(DIP(dp, mode)); nlink = iswap16(DIP(dp, nlink)); lostdir = (mode & IFMT) == IFDIR; pwarn("UNREF %s ", lostdir ? "DIR" : "FILE"); pinode(orphan); if (preen && DIP(dp, size) == 0) return (0); if (preen) printf(" (RECONNECTED)\n"); else if (reply("RECONNECT") == 0) { markclean = 0; return (0); } if (parentdir != 0) inoinfo(parentdir)->ino_linkcnt++; if (lfdir == 0) { dp = ginode(ROOTINO); idesc.id_name = lfname; idesc.id_type = DATA; idesc.id_func = findino; idesc.id_number = ROOTINO; if ((ckinode(dp, &idesc) & FOUND) != 0) { lfdir = idesc.id_parent; } else { pwarn("NO lost+found DIRECTORY"); if (preen || reply("CREATE")) { lfdir = allocdir(ROOTINO, (ino_t)0, lfmode); if (lfdir != 0) { if (makeentry(ROOTINO, lfdir, lfname) != 0) { numdirs++; if (preen) printf(" (CREATED)\n"); } else { freedir(lfdir, ROOTINO); lfdir = 0; if (preen) printf("\n"); } } if (lfdir != 0) { reparent(lfdir, ROOTINO); } } } if (lfdir == 0) { pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); markclean = 0; return (0); } } dp = ginode(lfdir); mode = DIP(dp, mode); mode = iswap16(mode); if ((mode & IFMT) != IFDIR) { pfatal("lost+found IS NOT A DIRECTORY"); if (reply("REALLOCATE") == 0) { markclean = 0; return (0); } oldlfdir = lfdir; lfdir = allocdir(ROOTINO, (ino_t)0, lfmode); if (lfdir == 0) { pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); markclean = 0; return (0); } if ((changeino(ROOTINO, lfname, lfdir) & ALTERED) == 0) { pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); markclean = 0; return (0); } inodirty(); reparent(lfdir, ROOTINO); idesc.id_type = ADDR; idesc.id_func = pass4check; idesc.id_number = oldlfdir; adjust(&idesc, inoinfo(oldlfdir)->ino_linkcnt + 1); inoinfo(oldlfdir)->ino_linkcnt = 0; dp = ginode(lfdir); } if (inoinfo(lfdir)->ino_state != DFOUND) { pfatal("SORRY. NO lost+found DIRECTORY\n\n"); markclean = 0; return (0); } (void)lftempname(tempname, orphan); if (makeentry(lfdir, orphan, (name ? name : tempname)) == 0) { pfatal("SORRY. NO SPACE IN lost+found DIRECTORY"); printf("\n\n"); markclean = 0; return (0); } inoinfo(orphan)->ino_linkcnt--; if (lostdir) { if ((changeino(orphan, "..", lfdir) & ALTERED) == 0 && parentdir != (ino_t)-1) (void)makeentry(orphan, lfdir, ".."); dp = ginode(lfdir); nlink = DIP(dp, nlink); DIP_SET(dp, nlink, iswap16(iswap16(nlink) + 1)); inodirty(); inoinfo(lfdir)->ino_linkcnt++; reparent(orphan, lfdir); pwarn("DIR I=%llu CONNECTED. ", (unsigned long long)orphan); if (parentdir != (ino_t)-1) printf("PARENT WAS I=%llu\n", (unsigned long long)parentdir); if (preen == 0) printf("\n"); } return (1); } /* * fix an entry in a directory. */ int changeino(ino_t dir, const char *name, ino_t newnum) { struct inodesc idesc; memset(&idesc, 0, sizeof(struct inodesc)); idesc.id_type = DATA; idesc.id_func = chgino; idesc.id_number = dir; idesc.id_fix = DONTKNOW; idesc.id_name = name; idesc.id_parent = newnum; /* new value for name */ return (ckinode(ginode(dir), &idesc)); } /* * make an entry in a directory */ int makeentry(ino_t parent, ino_t ino, const char *name) { union dinode *dp; struct inodesc idesc; char pathbuf[MAXPATHLEN + 1]; if (parent < ROOTINO || parent >= maxino || ino < ROOTINO || ino >= maxino) return (0); memset(&idesc, 0, sizeof(struct inodesc)); idesc.id_type = DATA; idesc.id_func = mkentry; idesc.id_number = parent; idesc.id_parent = ino; /* this is the inode to enter */ idesc.id_fix = DONTKNOW; idesc.id_name = name; dp = ginode(parent); if (iswap64(DIP(dp, size)) % dirblksiz) { DIP_SET(dp, size, iswap64(roundup(iswap64(DIP(dp, size)), dirblksiz))); inodirty(); } if ((ckinode(dp, &idesc) & ALTERED) != 0) return (1); getpathname(pathbuf, sizeof(pathbuf), parent, parent); dp = ginode(parent); if (expanddir(dp, pathbuf) == 0) return (0); return (ckinode(dp, &idesc) & ALTERED); } /* * Attempt to expand the size of a directory */ static int expanddir(union dinode *dp, char *name) { daddr_t lastbn, newblk, dirblk; struct bufarea *bp; char *cp; #if DIRBLKSIZ > APPLEUFS_DIRBLKSIZ char firstblk[DIRBLKSIZ]; #else char firstblk[APPLEUFS_DIRBLKSIZ]; #endif struct ufs1_dinode *dp1 = NULL; struct ufs2_dinode *dp2 = NULL; if (is_ufs2) dp2 = &dp->dp2; else dp1 = &dp->dp1; lastbn = lblkno(sblock, iswap64(DIP(dp, size))); if (lastbn >= NDADDR - 1 || DIP(dp, db[lastbn]) == 0 || DIP(dp, size) == 0) return (0); if ((newblk = allocblk(sblock->fs_frag)) == 0) return (0); if (is_ufs2) { dp2->di_db[lastbn + 1] = dp2->di_db[lastbn]; dp2->di_db[lastbn] = iswap64(newblk); dp2->di_size = iswap64(iswap64(dp2->di_size)+sblock->fs_bsize); dp2->di_blocks = iswap64(iswap64(dp2->di_blocks) + btodb(sblock->fs_bsize)); dirblk = iswap64(dp2->di_db[lastbn + 1]); } else { dp1->di_db[lastbn + 1] = dp1->di_db[lastbn]; dp1->di_db[lastbn] = iswap32((int32_t)newblk); dp1->di_size = iswap64(iswap64(dp1->di_size)+sblock->fs_bsize); dp1->di_blocks = iswap32(iswap32(dp1->di_blocks) + btodb(sblock->fs_bsize)); dirblk = iswap32(dp1->di_db[lastbn + 1]); } bp = getdirblk(dirblk, sblksize(sblock, DIP(dp, size), lastbn + 1)); if (bp->b_errs) goto bad; memmove(firstblk, bp->b_un.b_buf, dirblksiz); bp = getdirblk(newblk, sblock->fs_bsize); if (bp->b_errs) goto bad; memmove(bp->b_un.b_buf, firstblk, dirblksiz); emptydir.dot_reclen = iswap16(dirblksiz); for (cp = &bp->b_un.b_buf[dirblksiz]; cp < &bp->b_un.b_buf[sblock->fs_bsize]; cp += dirblksiz) memmove(cp, &emptydir, sizeof emptydir); dirty(bp); bp = getdirblk(dirblk, sblksize(sblock, DIP(dp, size), lastbn + 1)); if (bp->b_errs) goto bad; memmove(bp->b_un.b_buf, &emptydir, sizeof emptydir); pwarn("NO SPACE LEFT IN %s", name); if (preen) printf(" (EXPANDED)\n"); else if (reply("EXPAND") == 0) goto bad; dirty(bp); inodirty(); return (1); bad: if (is_ufs2) { dp2->di_db[lastbn] = dp2->di_db[lastbn + 1]; dp2->di_db[lastbn + 1] = 0; dp2->di_size = iswap64(iswap64(dp2->di_size)-sblock->fs_bsize); dp2->di_blocks = iswap64(iswap64(dp2->di_blocks) - btodb(sblock->fs_bsize)); } else { dp1->di_db[lastbn] = dp1->di_db[lastbn + 1]; dp1->di_db[lastbn + 1] = 0; dp1->di_size = iswap64(iswap64(dp1->di_size)-sblock->fs_bsize); dp1->di_blocks = iswap32(iswap32(dp1->di_blocks) - btodb(sblock->fs_bsize)); } freeblk(newblk, sblock->fs_frag); markclean = 0; return (0); } /* * allocate a new directory */ ino_t allocdir(ino_t parent, ino_t request, int mode) { ino_t ino; char *cp; union dinode *dp; struct bufarea *bp; struct inoinfo *inp; struct dirtemplate *dirp; daddr_t dirblk; ino = allocino(request, IFDIR|mode); if (ino < ROOTINO) return 0; dirhead.dot_reclen = iswap16(12); dirhead.dotdot_reclen = iswap16(dirblksiz - 12); odirhead.dot_reclen = iswap16(12); odirhead.dotdot_reclen = iswap16(dirblksiz - 12); odirhead.dot_namlen = iswap16(1); odirhead.dotdot_namlen = iswap16(2); if (newinofmt) dirp = &dirhead; else dirp = (struct dirtemplate *)&odirhead; dirp->dot_ino = iswap32(ino); dirp->dotdot_ino = iswap32(parent); dp = ginode(ino); dirblk = is_ufs2 ? iswap64(dp->dp2.di_db[0]) : iswap32(dp->dp1.di_db[0]); bp = getdirblk(dirblk, sblock->fs_fsize); if (bp->b_errs) { freeino(ino); return (0); } memmove(bp->b_un.b_buf, dirp, sizeof(struct dirtemplate)); emptydir.dot_reclen = iswap16(dirblksiz); for (cp = &bp->b_un.b_buf[dirblksiz]; cp < &bp->b_un.b_buf[sblock->fs_fsize]; cp += dirblksiz) memmove(cp, &emptydir, sizeof emptydir); dirty(bp); DIP_SET(dp, nlink, iswap16(2)); inodirty(); if (ino == ROOTINO) { inoinfo(ino)->ino_linkcnt = iswap16(DIP(dp, nlink)); cacheino(dp, ino); return(ino); } if (inoinfo(parent)->ino_state != DSTATE && inoinfo(parent)->ino_state != DFOUND) { freeino(ino); return (0); } cacheino(dp, ino); inp = getinoinfo(ino); inp->i_parent = parent; inp->i_dotdot = parent; inoinfo(ino)->ino_state = inoinfo(parent)->ino_state; if (inoinfo(ino)->ino_state == DSTATE) { inoinfo(ino)->ino_linkcnt = iswap16(DIP(dp, nlink)); inoinfo(parent)->ino_linkcnt++; } dp = ginode(parent); DIP_SET(dp, nlink, iswap16(iswap16(DIP(dp, nlink)) + 1)); inodirty(); return (ino); }
ssize_t atsc_table_eit_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, struct atsc_table_eit **table) { const uint8_t *p = buf, *endbuf = buf + buflen; struct atsc_table_eit *eit; struct atsc_table_eit_event **head; size_t size; int i = 0; size = offsetof(struct atsc_table_eit, event); if (p + size > endbuf) { dvb_logerr("%s: short read %zd/%zd bytes", __func__, endbuf - p, size); return -1; } if (buf[0] != ATSC_TABLE_EIT) { dvb_logerr("%s: invalid marker 0x%02x, sould be 0x%02x", __func__, buf[0], ATSC_TABLE_EIT); return -2; } if (!*table) { *table = calloc(sizeof(struct atsc_table_eit), 1); if (!*table) { dvb_logerr("%s: out of memory", __func__); return -3; } } eit = *table; memcpy(eit, p, size); p += size; dvb_table_header_init(&eit->header); /* find end of curent list */ head = &eit->event; while (*head != NULL) head = &(*head)->next; while (i++ < eit->events && p < endbuf) { struct atsc_table_eit_event *event; union atsc_table_eit_desc_length dl; size = offsetof(struct atsc_table_eit_event, descriptor); if (p + size > endbuf) { dvb_logerr("%s: short read %zd/%zd bytes", __func__, endbuf - p, size); return -4; } event = (struct atsc_table_eit_event *) malloc(sizeof(struct atsc_table_eit_event)); if (!event) { dvb_logerr("%s: out of memory", __func__); return -5; } memcpy(event, p, size); p += size; bswap16(event->bitfield); bswap32(event->start_time); bswap32(event->bitfield2); event->descriptor = NULL; event->next = NULL; atsc_time(event->start_time, &event->start); event->source_id = eit->header.id; *head = event; head = &(*head)->next; size = event->title_length - 1; if (p + size > endbuf) { dvb_logerr("%s: short read %zd/%zd bytes", __func__, endbuf - p, size); return -6; } /* TODO: parse title */ p += size; /* get the descriptors for each program */ size = sizeof(union atsc_table_eit_desc_length); if (p + size > endbuf) { dvb_logerr("%s: short read %zd/%zd bytes", __func__, endbuf - p, size); return -7; } memcpy(&dl, p, size); p += size; bswap16(dl.bitfield); size = dl.desc_length; if (p + size > endbuf) { dvb_logerr("%s: short read %zd/%zd bytes", __func__, endbuf - p, size); return -8; } if (dvb_desc_parse(parms, p, size, &event->descriptor) != 0 ) { return -9; } p += size; } return p - buf; }
/* Interpret pseudo code in tb. */ tcg_target_ulong tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr) { long tcg_temps[CPU_TEMP_BUF_NLONGS]; uintptr_t sp_value = (uintptr_t)(tcg_temps + CPU_TEMP_BUF_NLONGS); tcg_target_ulong next_tb = 0; tci_reg[TCG_AREG0] = (tcg_target_ulong)env; tci_reg[TCG_REG_CALL_STACK] = sp_value; assert(tb_ptr); for (;;) { TCGOpcode opc = tb_ptr[0]; #if !defined(NDEBUG) uint8_t op_size = tb_ptr[1]; uint8_t *old_code_ptr = tb_ptr; #endif tcg_target_ulong t0; tcg_target_ulong t1; tcg_target_ulong t2; tcg_target_ulong label; TCGCond condition; target_ulong taddr; #ifndef CONFIG_SOFTMMU tcg_target_ulong host_addr; #endif uint8_t tmp8; uint16_t tmp16; uint32_t tmp32; uint64_t tmp64; #if TCG_TARGET_REG_BITS == 32 uint64_t v64; #endif #if defined(GETPC) tci_tb_ptr = (uintptr_t)tb_ptr; #endif /* Skip opcode and size entry. */ tb_ptr += 2; switch (opc) { case INDEX_op_end: case INDEX_op_nop: break; case INDEX_op_nop1: case INDEX_op_nop2: case INDEX_op_nop3: case INDEX_op_nopn: case INDEX_op_discard: TODO(); break; case INDEX_op_set_label: TODO(); break; case INDEX_op_call: t0 = tci_read_ri(&tb_ptr); #if TCG_TARGET_REG_BITS == 32 tmp64 = ((helper_function)t0)(tci_read_reg(TCG_REG_R0), tci_read_reg(TCG_REG_R1), tci_read_reg(TCG_REG_R2), tci_read_reg(TCG_REG_R3), tci_read_reg(TCG_REG_R5), tci_read_reg(TCG_REG_R6), tci_read_reg(TCG_REG_R7), tci_read_reg(TCG_REG_R8), tci_read_reg(TCG_REG_R9), tci_read_reg(TCG_REG_R10)); tci_write_reg(TCG_REG_R0, tmp64); tci_write_reg(TCG_REG_R1, tmp64 >> 32); #else tmp64 = ((helper_function)t0)(tci_read_reg(TCG_REG_R0), tci_read_reg(TCG_REG_R1), tci_read_reg(TCG_REG_R2), tci_read_reg(TCG_REG_R3), tci_read_reg(TCG_REG_R5)); tci_write_reg(TCG_REG_R0, tmp64); #endif break; case INDEX_op_br: label = tci_read_label(&tb_ptr); assert(tb_ptr == old_code_ptr + op_size); tb_ptr = (uint8_t *)label; continue; case INDEX_op_setcond_i32: t0 = *tb_ptr++; t1 = tci_read_r32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); condition = *tb_ptr++; tci_write_reg32(t0, tci_compare32(t1, t2, condition)); break; #if TCG_TARGET_REG_BITS == 32 case INDEX_op_setcond2_i32: t0 = *tb_ptr++; tmp64 = tci_read_r64(&tb_ptr); v64 = tci_read_ri64(&tb_ptr); condition = *tb_ptr++; tci_write_reg32(t0, tci_compare64(tmp64, v64, condition)); break; #elif TCG_TARGET_REG_BITS == 64 case INDEX_op_setcond_i64: t0 = *tb_ptr++; t1 = tci_read_r64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); condition = *tb_ptr++; tci_write_reg64(t0, tci_compare64(t1, t2, condition)); break; #endif case INDEX_op_mov_i32: t0 = *tb_ptr++; t1 = tci_read_r32(&tb_ptr); tci_write_reg32(t0, t1); break; case INDEX_op_movi_i32: t0 = *tb_ptr++; t1 = tci_read_i32(&tb_ptr); tci_write_reg32(t0, t1); break; /* Load/store operations (32 bit). */ case INDEX_op_ld8u_i32: t0 = *tb_ptr++; t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); tci_write_reg8(t0, *(uint8_t *)(t1 + t2)); break; case INDEX_op_ld8s_i32: case INDEX_op_ld16u_i32: TODO(); break; case INDEX_op_ld16s_i32: TODO(); break; case INDEX_op_ld_i32: t0 = *tb_ptr++; t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); tci_write_reg32(t0, *(uint32_t *)(t1 + t2)); break; case INDEX_op_st8_i32: t0 = tci_read_r8(&tb_ptr); t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); *(uint8_t *)(t1 + t2) = t0; break; case INDEX_op_st16_i32: t0 = tci_read_r16(&tb_ptr); t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); *(uint16_t *)(t1 + t2) = t0; break; case INDEX_op_st_i32: t0 = tci_read_r32(&tb_ptr); t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); assert(t1 != sp_value || (int32_t)t2 < 0); *(uint32_t *)(t1 + t2) = t0; break; /* Arithmetic operations (32 bit). */ case INDEX_op_add_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, t1 + t2); break; case INDEX_op_sub_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, t1 - t2); break; case INDEX_op_mul_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, t1 * t2); break; #if TCG_TARGET_HAS_div_i32 case INDEX_op_div_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, (int32_t)t1 / (int32_t)t2); break; case INDEX_op_divu_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, t1 / t2); break; case INDEX_op_rem_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, (int32_t)t1 % (int32_t)t2); break; case INDEX_op_remu_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, t1 % t2); break; #elif TCG_TARGET_HAS_div2_i32 case INDEX_op_div2_i32: case INDEX_op_divu2_i32: TODO(); break; #endif case INDEX_op_and_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, t1 & t2); break; case INDEX_op_or_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, t1 | t2); break; case INDEX_op_xor_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, t1 ^ t2); break; /* Shift/rotate operations (32 bit). */ case INDEX_op_shl_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, t1 << t2); break; case INDEX_op_shr_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, t1 >> t2); break; case INDEX_op_sar_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, ((int32_t)t1 >> t2)); break; #if TCG_TARGET_HAS_rot_i32 case INDEX_op_rotl_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, rol32(t1, t2)); break; case INDEX_op_rotr_i32: t0 = *tb_ptr++; t1 = tci_read_ri32(&tb_ptr); t2 = tci_read_ri32(&tb_ptr); tci_write_reg32(t0, ror32(t1, t2)); break; #endif #if TCG_TARGET_HAS_deposit_i32 case INDEX_op_deposit_i32: t0 = *tb_ptr++; t1 = tci_read_r32(&tb_ptr); t2 = tci_read_r32(&tb_ptr); tmp16 = *tb_ptr++; tmp8 = *tb_ptr++; tmp32 = (((1 << tmp8) - 1) << tmp16); tci_write_reg32(t0, (t1 & ~tmp32) | ((t2 << tmp16) & tmp32)); break; #endif case INDEX_op_brcond_i32: t0 = tci_read_r32(&tb_ptr); t1 = tci_read_ri32(&tb_ptr); condition = *tb_ptr++; label = tci_read_label(&tb_ptr); if (tci_compare32(t0, t1, condition)) { assert(tb_ptr == old_code_ptr + op_size); tb_ptr = (uint8_t *)label; continue; } break; #if TCG_TARGET_REG_BITS == 32 case INDEX_op_add2_i32: t0 = *tb_ptr++; t1 = *tb_ptr++; tmp64 = tci_read_r64(&tb_ptr); tmp64 += tci_read_r64(&tb_ptr); tci_write_reg64(t1, t0, tmp64); break; case INDEX_op_sub2_i32: t0 = *tb_ptr++; t1 = *tb_ptr++; tmp64 = tci_read_r64(&tb_ptr); tmp64 -= tci_read_r64(&tb_ptr); tci_write_reg64(t1, t0, tmp64); break; case INDEX_op_brcond2_i32: tmp64 = tci_read_r64(&tb_ptr); v64 = tci_read_ri64(&tb_ptr); condition = *tb_ptr++; label = tci_read_label(&tb_ptr); if (tci_compare64(tmp64, v64, condition)) { assert(tb_ptr == old_code_ptr + op_size); tb_ptr = (uint8_t *)label; continue; } break; case INDEX_op_mulu2_i32: t0 = *tb_ptr++; t1 = *tb_ptr++; t2 = tci_read_r32(&tb_ptr); tmp64 = tci_read_r32(&tb_ptr); tci_write_reg64(t1, t0, t2 * tmp64); break; #endif /* TCG_TARGET_REG_BITS == 32 */ #if TCG_TARGET_HAS_ext8s_i32 case INDEX_op_ext8s_i32: t0 = *tb_ptr++; t1 = tci_read_r8s(&tb_ptr); tci_write_reg32(t0, t1); break; #endif #if TCG_TARGET_HAS_ext16s_i32 case INDEX_op_ext16s_i32: t0 = *tb_ptr++; t1 = tci_read_r16s(&tb_ptr); tci_write_reg32(t0, t1); break; #endif #if TCG_TARGET_HAS_ext8u_i32 case INDEX_op_ext8u_i32: t0 = *tb_ptr++; t1 = tci_read_r8(&tb_ptr); tci_write_reg32(t0, t1); break; #endif #if TCG_TARGET_HAS_ext16u_i32 case INDEX_op_ext16u_i32: t0 = *tb_ptr++; t1 = tci_read_r16(&tb_ptr); tci_write_reg32(t0, t1); break; #endif #if TCG_TARGET_HAS_bswap16_i32 case INDEX_op_bswap16_i32: t0 = *tb_ptr++; t1 = tci_read_r16(&tb_ptr); tci_write_reg32(t0, bswap16(t1)); break; #endif #if TCG_TARGET_HAS_bswap32_i32 case INDEX_op_bswap32_i32: t0 = *tb_ptr++; t1 = tci_read_r32(&tb_ptr); tci_write_reg32(t0, bswap32(t1)); break; #endif #if TCG_TARGET_HAS_not_i32 case INDEX_op_not_i32: t0 = *tb_ptr++; t1 = tci_read_r32(&tb_ptr); tci_write_reg32(t0, ~t1); break; #endif #if TCG_TARGET_HAS_neg_i32 case INDEX_op_neg_i32: t0 = *tb_ptr++; t1 = tci_read_r32(&tb_ptr); tci_write_reg32(t0, -t1); break; #endif #if TCG_TARGET_REG_BITS == 64 case INDEX_op_mov_i64: t0 = *tb_ptr++; t1 = tci_read_r64(&tb_ptr); tci_write_reg64(t0, t1); break; case INDEX_op_movi_i64: t0 = *tb_ptr++; t1 = tci_read_i64(&tb_ptr); tci_write_reg64(t0, t1); break; /* Load/store operations (64 bit). */ case INDEX_op_ld8u_i64: t0 = *tb_ptr++; t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); tci_write_reg8(t0, *(uint8_t *)(t1 + t2)); break; case INDEX_op_ld8s_i64: case INDEX_op_ld16u_i64: case INDEX_op_ld16s_i64: TODO(); break; case INDEX_op_ld32u_i64: t0 = *tb_ptr++; t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); tci_write_reg32(t0, *(uint32_t *)(t1 + t2)); break; case INDEX_op_ld32s_i64: t0 = *tb_ptr++; t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); tci_write_reg32s(t0, *(int32_t *)(t1 + t2)); break; case INDEX_op_ld_i64: t0 = *tb_ptr++; t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); tci_write_reg64(t0, *(uint64_t *)(t1 + t2)); break; case INDEX_op_st8_i64: t0 = tci_read_r8(&tb_ptr); t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); *(uint8_t *)(t1 + t2) = t0; break; case INDEX_op_st16_i64: t0 = tci_read_r16(&tb_ptr); t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); *(uint16_t *)(t1 + t2) = t0; break; case INDEX_op_st32_i64: t0 = tci_read_r32(&tb_ptr); t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); *(uint32_t *)(t1 + t2) = t0; break; case INDEX_op_st_i64: t0 = tci_read_r64(&tb_ptr); t1 = tci_read_r(&tb_ptr); t2 = tci_read_s32(&tb_ptr); assert(t1 != sp_value || (int32_t)t2 < 0); *(uint64_t *)(t1 + t2) = t0; break; /* Arithmetic operations (64 bit). */ case INDEX_op_add_i64: t0 = *tb_ptr++; t1 = tci_read_ri64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); tci_write_reg64(t0, t1 + t2); break; case INDEX_op_sub_i64: t0 = *tb_ptr++; t1 = tci_read_ri64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); tci_write_reg64(t0, t1 - t2); break; case INDEX_op_mul_i64: t0 = *tb_ptr++; t1 = tci_read_ri64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); tci_write_reg64(t0, t1 * t2); break; #if TCG_TARGET_HAS_div_i64 case INDEX_op_div_i64: case INDEX_op_divu_i64: case INDEX_op_rem_i64: case INDEX_op_remu_i64: TODO(); break; #elif TCG_TARGET_HAS_div2_i64 case INDEX_op_div2_i64: case INDEX_op_divu2_i64: TODO(); break; #endif case INDEX_op_and_i64: t0 = *tb_ptr++; t1 = tci_read_ri64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); tci_write_reg64(t0, t1 & t2); break; case INDEX_op_or_i64: t0 = *tb_ptr++; t1 = tci_read_ri64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); tci_write_reg64(t0, t1 | t2); break; case INDEX_op_xor_i64: t0 = *tb_ptr++; t1 = tci_read_ri64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); tci_write_reg64(t0, t1 ^ t2); break; /* Shift/rotate operations (64 bit). */ case INDEX_op_shl_i64: t0 = *tb_ptr++; t1 = tci_read_ri64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); tci_write_reg64(t0, t1 << t2); break; case INDEX_op_shr_i64: t0 = *tb_ptr++; t1 = tci_read_ri64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); tci_write_reg64(t0, t1 >> t2); break; case INDEX_op_sar_i64: t0 = *tb_ptr++; t1 = tci_read_ri64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); tci_write_reg64(t0, ((int64_t)t1 >> t2)); break; #if TCG_TARGET_HAS_rot_i64 case INDEX_op_rotl_i64: t0 = *tb_ptr++; t1 = tci_read_ri64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); tci_write_reg64(t0, rol64(t1, t2)); break; case INDEX_op_rotr_i64: t0 = *tb_ptr++; t1 = tci_read_ri64(&tb_ptr); t2 = tci_read_ri64(&tb_ptr); tci_write_reg64(t0, ror64(t1, t2)); break; #endif #if TCG_TARGET_HAS_deposit_i64 case INDEX_op_deposit_i64: t0 = *tb_ptr++; t1 = tci_read_r64(&tb_ptr); t2 = tci_read_r64(&tb_ptr); tmp16 = *tb_ptr++; tmp8 = *tb_ptr++; tmp64 = (((1ULL << tmp8) - 1) << tmp16); tci_write_reg64(t0, (t1 & ~tmp64) | ((t2 << tmp16) & tmp64)); break; #endif case INDEX_op_brcond_i64: t0 = tci_read_r64(&tb_ptr); t1 = tci_read_ri64(&tb_ptr); condition = *tb_ptr++; label = tci_read_label(&tb_ptr); if (tci_compare64(t0, t1, condition)) { assert(tb_ptr == old_code_ptr + op_size); tb_ptr = (uint8_t *)label; continue; } break; #if TCG_TARGET_HAS_ext8u_i64 case INDEX_op_ext8u_i64: t0 = *tb_ptr++; t1 = tci_read_r8(&tb_ptr); tci_write_reg64(t0, t1); break; #endif #if TCG_TARGET_HAS_ext8s_i64 case INDEX_op_ext8s_i64: t0 = *tb_ptr++; t1 = tci_read_r8s(&tb_ptr); tci_write_reg64(t0, t1); break; #endif #if TCG_TARGET_HAS_ext16s_i64 case INDEX_op_ext16s_i64: t0 = *tb_ptr++; t1 = tci_read_r16s(&tb_ptr); tci_write_reg64(t0, t1); break; #endif #if TCG_TARGET_HAS_ext16u_i64 case INDEX_op_ext16u_i64: t0 = *tb_ptr++; t1 = tci_read_r16(&tb_ptr); tci_write_reg64(t0, t1); break; #endif #if TCG_TARGET_HAS_ext32s_i64 case INDEX_op_ext32s_i64: t0 = *tb_ptr++; t1 = tci_read_r32s(&tb_ptr); tci_write_reg64(t0, t1); break; #endif #if TCG_TARGET_HAS_ext32u_i64 case INDEX_op_ext32u_i64: t0 = *tb_ptr++; t1 = tci_read_r32(&tb_ptr); tci_write_reg64(t0, t1); break; #endif #if TCG_TARGET_HAS_bswap16_i64 case INDEX_op_bswap16_i64: TODO(); t0 = *tb_ptr++; t1 = tci_read_r16(&tb_ptr); tci_write_reg64(t0, bswap16(t1)); break; #endif #if TCG_TARGET_HAS_bswap32_i64 case INDEX_op_bswap32_i64: t0 = *tb_ptr++; t1 = tci_read_r32(&tb_ptr); tci_write_reg64(t0, bswap32(t1)); break; #endif #if TCG_TARGET_HAS_bswap64_i64 case INDEX_op_bswap64_i64: t0 = *tb_ptr++; t1 = tci_read_r64(&tb_ptr); tci_write_reg64(t0, bswap64(t1)); break; #endif #if TCG_TARGET_HAS_not_i64 case INDEX_op_not_i64: t0 = *tb_ptr++; t1 = tci_read_r64(&tb_ptr); tci_write_reg64(t0, ~t1); break; #endif #if TCG_TARGET_HAS_neg_i64 case INDEX_op_neg_i64: t0 = *tb_ptr++; t1 = tci_read_r64(&tb_ptr); tci_write_reg64(t0, -t1); break; #endif #endif /* TCG_TARGET_REG_BITS == 64 */ /* QEMU specific operations. */ #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS case INDEX_op_debug_insn_start: TODO(); break; #else case INDEX_op_debug_insn_start: TODO(); break; #endif case INDEX_op_exit_tb: next_tb = *(uint64_t *)tb_ptr; goto exit; break; case INDEX_op_goto_tb: t0 = tci_read_i32(&tb_ptr); assert(tb_ptr == old_code_ptr + op_size); tb_ptr += (int32_t)t0; continue; case INDEX_op_qemu_ld8u: t0 = *tb_ptr++; taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU tmp8 = helper_ldb_mmu(env, taddr, tci_read_i(&tb_ptr)); #else host_addr = (tcg_target_ulong)taddr; tmp8 = *(uint8_t *)(host_addr + GUEST_BASE); #endif tci_write_reg8(t0, tmp8); break; case INDEX_op_qemu_ld8s: t0 = *tb_ptr++; taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU tmp8 = helper_ldb_mmu(env, taddr, tci_read_i(&tb_ptr)); #else host_addr = (tcg_target_ulong)taddr; tmp8 = *(uint8_t *)(host_addr + GUEST_BASE); #endif tci_write_reg8s(t0, tmp8); break; case INDEX_op_qemu_ld16u: t0 = *tb_ptr++; taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU tmp16 = helper_ldw_mmu(env, taddr, tci_read_i(&tb_ptr)); #else host_addr = (tcg_target_ulong)taddr; tmp16 = tswap16(*(uint16_t *)(host_addr + GUEST_BASE)); #endif tci_write_reg16(t0, tmp16); break; case INDEX_op_qemu_ld16s: t0 = *tb_ptr++; taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU tmp16 = helper_ldw_mmu(env, taddr, tci_read_i(&tb_ptr)); #else host_addr = (tcg_target_ulong)taddr; tmp16 = tswap16(*(uint16_t *)(host_addr + GUEST_BASE)); #endif tci_write_reg16s(t0, tmp16); break; #if TCG_TARGET_REG_BITS == 64 case INDEX_op_qemu_ld32u: t0 = *tb_ptr++; taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU tmp32 = helper_ldl_mmu(env, taddr, tci_read_i(&tb_ptr)); #else host_addr = (tcg_target_ulong)taddr; tmp32 = tswap32(*(uint32_t *)(host_addr + GUEST_BASE)); #endif tci_write_reg32(t0, tmp32); break; case INDEX_op_qemu_ld32s: t0 = *tb_ptr++; taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU tmp32 = helper_ldl_mmu(env, taddr, tci_read_i(&tb_ptr)); #else host_addr = (tcg_target_ulong)taddr; tmp32 = tswap32(*(uint32_t *)(host_addr + GUEST_BASE)); #endif tci_write_reg32s(t0, tmp32); break; #endif /* TCG_TARGET_REG_BITS == 64 */ case INDEX_op_qemu_ld32: t0 = *tb_ptr++; taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU tmp32 = helper_ldl_mmu(env, taddr, tci_read_i(&tb_ptr)); #else host_addr = (tcg_target_ulong)taddr; tmp32 = tswap32(*(uint32_t *)(host_addr + GUEST_BASE)); #endif tci_write_reg32(t0, tmp32); break; case INDEX_op_qemu_ld64: t0 = *tb_ptr++; #if TCG_TARGET_REG_BITS == 32 t1 = *tb_ptr++; #endif taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU tmp64 = helper_ldq_mmu(env, taddr, tci_read_i(&tb_ptr)); #else host_addr = (tcg_target_ulong)taddr; tmp64 = tswap64(*(uint64_t *)(host_addr + GUEST_BASE)); #endif tci_write_reg(t0, tmp64); #if TCG_TARGET_REG_BITS == 32 tci_write_reg(t1, tmp64 >> 32); #endif break; case INDEX_op_qemu_st8: t0 = tci_read_r8(&tb_ptr); taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU t2 = tci_read_i(&tb_ptr); helper_stb_mmu(env, taddr, t0, t2); #else host_addr = (tcg_target_ulong)taddr; *(uint8_t *)(host_addr + GUEST_BASE) = t0; #endif break; case INDEX_op_qemu_st16: t0 = tci_read_r16(&tb_ptr); taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU t2 = tci_read_i(&tb_ptr); helper_stw_mmu(env, taddr, t0, t2); #else host_addr = (tcg_target_ulong)taddr; *(uint16_t *)(host_addr + GUEST_BASE) = tswap16(t0); #endif break; case INDEX_op_qemu_st32: t0 = tci_read_r32(&tb_ptr); taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU t2 = tci_read_i(&tb_ptr); helper_stl_mmu(env, taddr, t0, t2); #else host_addr = (tcg_target_ulong)taddr; *(uint32_t *)(host_addr + GUEST_BASE) = tswap32(t0); #endif break; case INDEX_op_qemu_st64: tmp64 = tci_read_r64(&tb_ptr); taddr = tci_read_ulong(&tb_ptr); #ifdef CONFIG_SOFTMMU t2 = tci_read_i(&tb_ptr); helper_stq_mmu(env, taddr, tmp64, t2); #else host_addr = (tcg_target_ulong)taddr; *(uint64_t *)(host_addr + GUEST_BASE) = tswap64(tmp64); #endif break; default: TODO(); break; } assert(tb_ptr == old_code_ptr + op_size); } exit: return next_tb; }
/* * Management process * start mgmt <cpuid> <nic> <ip address/mask> <default-gw> */ int mgmt_main(int argc, char *argv[]) { /* Search network device for management */ struct netdev_list *list; struct netdev *netdev; char *nic; char *ipaddr; char *gw; int m; int ret; u32 ipa; int ipm; u32 gwa; /* Check the argument first */ if ( argc < 4 ) { kprintf("Invalid argument: %s <nic> <ip address/mask> <default-gw>\r\n", argv[0]); return -1; } nic = argv[1]; ipaddr = argv[2]; gw = argv[3]; /* Obtain the specified netdev */ netdev = NULL; list = netdev_head; while ( NULL != list ) { if ( 0 == kstrcmp(nic, list->netdev->name) ) { netdev = list->netdev; break; } list = list->next; } if ( NULL == netdev ) { kprintf("netdev %s cannot be found\r\n", nic); return -1; } ret = str2v4addr(ipaddr, &ipa, &ipm); if ( ret < 0 || ipm < 0 ) { /* Wrint IP address */ kprintf("%s is wrong IP address format\r\n", ipaddr); return -1; } ret = str2v4addr(gw, &gwa, &m); if ( ret < 0 || m >= 0 ) { /* Wrint gateway address */ kprintf("%s is wrong gateway address format\r\n", gw); return -1; } /* Network */ int i; int n; u8 *pkt; struct net_port port; struct net_port_host hport; arch_busy_usleep(1000); pkt = alloca(gnet.sys_mtu); /* Port */ kmemcpy(hport.macaddr, netdev->macaddr, 6); hport.ip4addr.nr = 1; hport.ip4addr.addrs = kmalloc(sizeof(u32) * 1); if ( NULL == hport.ip4addr.addrs ){ return -1; } hport.ip4addr.addrs[0] = bswap32(ipa); hport.arp.sz = 4096; hport.arp.entries = kmalloc(sizeof(struct net_arp_entry) * hport.arp.sz); for ( i = 0; i < hport.arp.sz; i++ ) { hport.arp.entries[i].state = -1; } hport.ip6addr.nr = 0; hport.port = &port; port.netdev = netdev; port.next.data = (void *)&hport; port.next.func = net_sc_rx_port_host; hport.tx.func = NULL; hport.tx.data = (void *)&port; /* Routing table */ hport.rib4.nr = 0; hport.rib4.entries = NULL; net_rib4_add(&hport.rib4, bswap32(ipa & (0xffffffffULL<<(32-ipm))), ipm, 0); net_rib4_add(&hport.rib4, 0, 0, bswap32(gwa)); u64 tsc0 = rdtsc(); u64 tsc1; for ( ;; ) { n = port.netdev->recvpkt(pkt, gnet.sys_mtu, port.netdev); if ( n <= 0 ) { continue; } port.next.func(&gnet, pkt, n, port.next.data); /* Trigger for TCP transmission */ tsc1 = rdtsc(); if ( tsc1 - tsc0 > 3000 * 1000 * 100 /* ~100ms FIXME */ ) { net_tcp_trigger(&gnet); tsc0 = tsc1; } } return 0; }