// ---------------------------------------------------------------------------------------------------- UInt32 PlatformInterfaceI2S_Mapped::getPeakLevel ( UInt32 channelTarget ) { UInt32 result; switch ( channelTarget ) { case kStreamFrontLeft: result = OSReadLittleInt32 ( mI2SBaseAddress, kI2SPeakLevelIn0Offset ); break; case kStreamFrontRight: result = OSReadLittleInt32 ( mI2SBaseAddress, kI2SPeakLevelIn1Offset ); break; default: result = 0; break; } return result; }
IOReturn AppleI386AGP::commitAGPMemory( IOAGPDevice * master, IOMemoryDescriptor * memory, IOByteCount agpOffset, IOOptionBits options ) { IOPCIAddressSpace target = getBridgeSpace(); IOReturn err = kIOReturnSuccess; UInt32 offset = 0, tmp, agpCtrl; IOPhysicalAddress physAddr; IOByteCount len; // ok = agpRange->allocate( memory->getLength(), &agpOffset ); agpCtrl = configRead32(target, kiAGPCTRL); agpCtrl &= ~(1 << 7); configWrite32( target, kiAGPCTRL, agpCtrl ); // b7 gtlb ena if(memory) { assert( agpOffset < systemLength ); agpOffset /= (page_size / 4); while( (physAddr = memory->getPhysicalSegment( offset, &len ))) { offset += len; len = (len + 0xfff) & ~0xfff; while( len > 0) { OSWriteLittleInt32( gartArray, agpOffset, ((physAddr & ~0xfff) | 1)); agpOffset += 4; physAddr += page_size; len -= page_size; } } // Read back from last entry written to flush entry to main memory. tmp = OSReadLittleInt32(gartArray, agpOffset-4); #if 1 // Deal with stupid Pentium 4 8-deeps store queue crap. for(offset = 0; offset < 64*16; offset += 64) { tmp = OSReadLittleInt32(gartArray, offset); OSWriteLittleInt32(gartArray, offset, tmp); } #endif } agpCtrl = configRead32(target, kiAGPCTRL); agpCtrl |= (1 << 7); configWrite32( target, kiAGPCTRL, agpCtrl ); // b7 gtlb ena return( err ); }
void computeMD5HashStringForContext(CGContextRef bitmapContext, char hashString[33]) { ASSERT(CGBitmapContextGetBitsPerPixel(bitmapContext) == 32); // ImageDiff assumes 32 bit RGBA, we must as well. size_t pixelsHigh = CGBitmapContextGetHeight(bitmapContext); size_t pixelsWide = CGBitmapContextGetWidth(bitmapContext); size_t bytesPerRow = CGBitmapContextGetBytesPerRow(bitmapContext); // We need to swap the bytes to ensure consistent hashes independently of endianness MD5 md5; unsigned char* bitmapData = static_cast<unsigned char*>(CGBitmapContextGetData(bitmapContext)); #if PLATFORM(MAC) if ((CGBitmapContextGetBitmapInfo(bitmapContext) & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Big) { for (unsigned row = 0; row < pixelsHigh; row++) { Vector<uint8_t> buffer(4 * pixelsWide); for (unsigned column = 0; column < pixelsWide; column++) buffer[column] = OSReadLittleInt32(bitmapData, 4 * column); md5.addBytes(buffer); bitmapData += bytesPerRow; } } else #endif { for (unsigned row = 0; row < pixelsHigh; row++) { md5.addBytes(bitmapData, 4 * pixelsWide); bitmapData += bytesPerRow; } } Vector<uint8_t, 16> hash; md5.checksum(hash); hashString[0] = '\0'; for (int i = 0; i < 16; i++) snprintf(hashString, 33, "%s%02x", hashString, hash[i]); }
/* * Find a resident attribute of a given type. Returns a pointer to the * attribute data, and its size in bytes. */ static int ntfs_find_attr( char *buf, u_int32_t attrType, void **attrData, size_t *attrSize) { struct filerec *filerec; struct attr *attr; u_int16_t offset; filerec = (struct filerec *) buf; offset = OSReadLittleInt16(&filerec->fr_attroff,0); attr = (struct attr *) (buf + offset); /*ее Should we also check offset < buffer size? */ while (attr->a_hdr.a_type != 0xFFFFFFFF) /* same for big/little endian */ { if (OSReadLittleInt32(&attr->a_hdr.a_type,0) == attrType) { if (attr->a_hdr.a_flag != 0) { //verbose("NTFS: attriubte 0x%X is non-resident\n", attrType); return 1; } *attrSize = OSReadLittleInt16(&attr->a_r.a_datalen,0); *attrData = buf + offset + OSReadLittleInt16(&attr->a_r.a_dataoff,0); return 0; /* found it! */ } /* Skip to the next attribute */ offset += OSReadLittleInt32(&attr->a_hdr.reclen,0); attr = (struct attr *) (buf + offset); } return 1; /* No matching attrType found */ }
/* * Process per-sector "fixups" that NTFS uses to detect corruption of * multi-sector data structures, like MFT records. */ static int ntfs_fixup( char *buf, size_t len, u_int32_t magic, u_int32_t bytesPerSector) { struct fixuphdr *fhp = (struct fixuphdr *) buf; int i; u_int16_t fixup; u_int16_t *fxp; u_int16_t *cfxp; u_int32_t fixup_magic; u_int16_t fixup_count; u_int16_t fixup_offset; fixup_magic = OSReadLittleInt32(&fhp->fh_magic,0); if (fixup_magic != magic) { error("ntfs_fixup: magic doesn't match: %08x != %08x\n", fixup_magic, magic); return (ERROR); } fixup_count = OSReadLittleInt16(&fhp->fh_fnum,0); if ((fixup_count - 1) * bytesPerSector != len) { error("ntfs_fixup: " \ "bad fixups number: %d for %ld bytes block\n", fixup_count, (long)len); /* XXX printf kludge */ return (ERROR); } fixup_offset = OSReadLittleInt16(&fhp->fh_foff,0); if (fixup_offset >= len) { error("ntfs_fixup: invalid offset: %x", fixup_offset); return (ERROR); } fxp = (u_int16_t *) (buf + fixup_offset); cfxp = (u_int16_t *) (buf + bytesPerSector - 2); fixup = *fxp++; for (i = 1; i < fixup_count; i++, fxp++) { if (*cfxp != fixup) { error("ntfs_fixup: fixup %d doesn't match\n", i); return (ERROR); } *cfxp = *fxp; cfxp = (u_int16_t *)(((caddr_t)cfxp) + bytesPerSector); } return (0); }
void CLASS::serviceTxInterrupt( void ) { TxDesc * descPtr; UInt32 headIndex = fTxHeadIndex; UInt32 busyCount = TX_RING_BUSY(headIndex, fTxTailIndex); UInt32 doneCount = 0; UInt32 txStatus; while (doneCount < busyCount) { descPtr = &fTxDescBase[ headIndex ]; assert(descPtr->descLast); assert(descPtr->descCount); // Examine ownership bit in the last descriptor for this chain. txStatus = OSReadLittleInt32(&descPtr->descLast->cmdStatus, 0); if (txStatus & kDescOwn) break; // transmit not done yet if (txStatus & kDescTxAbnormalMask) { recordTxDescriptorErrors(txStatus); } if (descPtr->packet) { freePacket(descPtr->packet, kDelayFree); descPtr->packet = 0; } // Skip to the start of the next transmit slot. headIndex = descPtr->nextIndex; doneCount += descPtr->descCount; } if (doneCount) { fTxHeadIndex = headIndex; fTransmitQueue->service(); releaseFreePackets(); DEBUG_LOG("TX ISR: retired %lu\n", doneCount); } }
static uint64_t ReadMMIO(uint64_t phys, uint8_t length){ uint64_t value = 0; //uint32_t *ioaddr; IOMemoryDescriptor* io_desc; IOMemoryMap* io_map; uint64_t page_offset = phys & PAGE_MASK; log_addr((uint64_t) page_offset, 64, "page_offset"); xlate_pa_va(phys, &io_desc, &io_map); if(io_map) { log_addr(io_map->getVirtualAddress(), 64, "io_map->getVirtualAddress"); switch (length) { case 1: value = *(volatile uint8_t *)((uintptr_t)(io_map->getVirtualAddress()) + page_offset); break; case 2: value = OSReadLittleInt16((void *)io_map->getVirtualAddress(), page_offset); break; case 4: value = OSReadLittleInt32((void *)io_map->getVirtualAddress(), page_offset); break; case 8: value = OSReadLittleInt64((void *)io_map->getVirtualAddress(), page_offset); default: pmem_error("ReadMMIO Incorrect read length"); break; } // DEBUG //ioaddr = (uint32_t *) (io_map->getVirtualAddress() + page_offset); //log_addr((uint64_t)ioaddr, 64, "ioaddr"); } unxlate_pa_va(&io_desc, &io_map); return value; }
/* * Parse/validate a security buffer. Verifies that supplied offset/length don't go * past end of avaialble data. Returns ptr to actual data and its length. Returns * NTLM_ERR_PARSE_ERR on bogus values. */ OSStatus ntlmParseSecBuffer( const unsigned char *cp, /* start of security buffer */ const unsigned char *bufStart, /* start of whole msg buffer */ unsigned bufLen, /* # of valid bytes starting at bufStart */ const unsigned char **data, /* RETURNED, start of actual data */ uint16_t *dataLen) /* RETURNED, length of actual data */ { assert(cp >= bufStart); uint16_t secBufLen = OSReadLittleInt16(cp, 0); /* skip length we just parsed plus alloc size, which we don't use */ cp += 4; uint32_t offset = OSReadLittleInt32(cp, 0); if((offset + secBufLen) > bufLen) { dprintf("ntlmParseSecBuffer: buf overflow\n"); return NTLM_ERR_PARSE_ERR; } *data = bufStart + offset; *dataLen = secBufLen; return errSecSuccess; }
void FreeBSDGetDescription(CICell ih, char *str, long strMaxLen) { char * buf=malloc(FreeBSDProbeSize); str[0]=0; if (!buf) return; Seek(ih, 0); Read(ih, (long)buf, FreeBSDProbeSize); if (!FreeBSDProbe (buf)) { free (buf); return; } if (OSReadLittleInt32 (buf+0x44c,0)<1) { free (buf); return; } str[strMaxLen]=0; strncpy (str, buf+0x478, MIN (strMaxLen, 32)); free (buf); }
void EX2GetDescription(CICell ih, char *str, long strMaxLen) { char * buf=malloc (EX2ProbeSize); str[0]=0; if (!buf) return; Seek(ih, 0); Read(ih, (long)buf, EX2ProbeSize); if (!EX2Probe (buf)) { free (buf); return; } if (OSReadLittleInt32 (buf+0x44c,0)<1) { free (buf); return; } str[strMaxLen]=0; strncpy (str, buf+0x478, min (strMaxLen, 16)); free (buf); }
bool OpenBSDProbe (const void *buf) { return (OSReadLittleInt32(buf+0x200,0)==0x82564557); }
/** * at_probe - Device Initialization Routine * @pdev: PCI device information struct * @ent: entry in at_pci_tbl * * Returns 0 on success, negative on failure * * at_probe initializes an adapter identified by a pci_dev structure. * The OS initialization, configuring of the adapter private structure, * and a hardware reset occur. **/ bool AtherosL1Ethernet::atProbe() { u16 vendorId, deviceId; at_adapter *adapter=&adapter_; IOPCIDevice *pdev = adapter_.pdev; pdev->setBusMasterEnable(true); pdev->setMemoryEnable(true); pdev->setIOEnable(true); vendorId = pdev->configRead16(kIOPCIConfigVendorID); deviceId = pdev->configRead16(kIOPCIConfigDeviceID); DbgPrint("Vendor ID %x, device ID %x\n", vendorId, deviceId); DbgPrint("MMR0 address %x\n", (u32)pdev->configRead32(kIOPCIConfigBaseAddress0)); pdev->enablePCIPowerManagement(); hw_addr_ = pdev->mapDeviceMemoryWithRegister(kIOPCIConfigBaseAddress0); if (hw_addr_ == NULL) { ErrPrint("Couldn't map io regs\n"); return false; } DbgPrint("Memory mapped at bus address %x, virtual address %x, length %d\n", (u32)hw_addr_->getPhysicalAddress(), (u32)hw_addr_->getVirtualAddress(), (u32)hw_addr_->getLength()); hw_addr_->retain(); adapter->hw.mmr_base = reinterpret_cast<char *>(hw_addr_->getVirtualAddress()); DbgPrint("REG_VPD_CAP = %x\n", OSReadLittleInt32(adapter->hw.mmr_base, REG_VPD_CAP)); DbgPrint("REG_PCIE_CAP_LIST = %x\n", OSReadLittleInt32(adapter->hw.mmr_base, REG_PCIE_CAP_LIST)); DbgPrint("REG_MASTER_CTRL = %x\n", OSReadLittleInt32(adapter->hw.mmr_base, REG_MASTER_CTRL)); at_setup_pcicmd(pdev); /* get user settings */ at_check_options(adapter); /* setup the private structure */ if(at_sw_init(adapter)) { ErrPrint("Couldn't init software\n"); return false; } /* Init GPHY as early as possible due to power saving issue */ at_phy_init(&adapter->hw); /* reset the controller to * put the device in a known good starting state */ if (at_reset_hw(&adapter->hw)) { ErrPrint("Couldn't reset hardware\n"); return false; //TO-DO: Uncomment } /* copy the MAC address out of the EEPROM */ at_read_mac_addr(&adapter->hw); return true; }
unsigned int readl(void *addr) { return OSReadLittleInt32((volatile void*)addr, 0); }
// Generic INLINEd methods to access to registers: // =============================================== UInt32 AudioI2SControl::ReadWordLittleEndian(void *address, UInt32 offset ) { return OSReadLittleInt32(address, offset); }
// ---------------------------------------------------------------------------------------------------- UInt32 PlatformInterfaceI2S_Mapped::getFrameCount () { return OSReadLittleInt32(mI2SBaseAddress, kI2SFrameCountOffset); }
// ---------------------------------------------------------------------------------------------------- UInt32 PlatformInterfaceI2S_Mapped::getDataWordSizes() { UInt32 result = OSReadLittleInt32(mI2SBaseAddress, kI2SDataWordSizesOffset); return result; }
/* Find BeFS signature */ bool BeFSProbe (const void *buf) { return (OSReadLittleInt32(buf+0x220,0)==SUPER_BLOCK_MAGIC1); }
void CLASS::serviceRxInterrupt(void) { mbuf_t pkt; UInt32 rxStatus; UInt32 rxLength; UInt32 rxIndex = fRxHeadIndex; RxDesc * descPtr = &fRxDescBase[ rxIndex ]; bool pktReplaced; rxStatus = OSReadLittleInt32(&descPtr->cmdStatus, 0); while (rxStatus & kDescOwn) { DEBUG_LOG("RX Status = %lx @ index %lu\n", rxStatus, rxIndex); // Total packet length, including the 4-byte FCS? rxLength = (rxStatus & kDescBufferSizeMask); // Packet must be contained within a single descriptor, // and must be a good packet. if (((rxStatus & (kDescMore | kDescPacketOK)) == kDescPacketOK) && (rxLength <= kIOEthernetMaxPacketSize + 4)) { pkt = replaceOrCopyPacket( &descPtr->packet, rxLength, &pktReplaced); if (pkt) { if (pktReplaced) { // New packet added to ring, update descriptor // with new physical address. OSWriteLittleInt32(&descPtr->bufferPtr, 0, MBUF_PADDR(descPtr->packet)); assert(descPtr->bufferPtr != 0); } fNetif->inputPacket( pkt, rxLength, IONetworkInterface::kInputOptionQueuePacket ); NET_STAT(inputPackets, 1); } else /* !pkt (mbuf shortage) */ { NET_STAT(inputErrors, 1); ETH_STAT(dot3RxExtraEntry.resourceErrors, 1); DEBUG_LOG("RX RESOURCE ERROR\n"); } } else { recordRxDescriptorErrors(rxStatus); } // Update the current descriptor and make it owned by NIC. rxStatus = kDescInterrupt | kDescIncludeCRC | (kRxMaxBufferSize & kDescBufferSizeMask); OSWriteLittleInt32(&descPtr->cmdStatus, 0, rxStatus); // Advance to next descriptor. rxIndex = (rxIndex + 1) & (kRxDescCount - 1); descPtr = &fRxDescBase[rxIndex]; rxStatus = OSReadLittleInt32(&descPtr->cmdStatus, 0); } fRxHeadIndex = rxIndex; // Push up all packets received in the loop above in one shot. fNetif->flushInputQueue(); }
// ---------------------------------------------------------------------------------------------------- UInt32 PlatformInterfaceI2S_Mapped::getI2SIOM_PeakLevelIn1 () { UInt32 result = OSReadLittleInt32(mI2SBaseAddress, kI2SPeakLevelIn1Offset); return result; }
// ---------------------------------------------------------------------------------------------------- UInt32 PlatformInterfaceI2S_Mapped::getI2SIOM_FrameMatch () { UInt32 result = OSReadLittleInt32(mI2SBaseAddress, kI2SFrameMatchOffset); return result; }
// ---------------------------------------------------------------------------------------------------- UInt32 PlatformInterfaceI2S_Mapped::getI2SIOM_CodecMsgIn () { UInt32 result = OSReadLittleInt32(mI2SBaseAddress, kI2SCodecMsgInOffset); return result; }
bool FreeBSDProbe (const void *buf) { return (OSReadLittleInt32(buf+0xA55C,0)==0x19540119); }
// ---------------------------------------------------------------------------------------------------- UInt32 PlatformInterfaceI2S_Mapped::getSerialFormatRegister () { UInt32 result = OSReadLittleInt32(mI2SBaseAddress, kI2SSerialFormatOffset); return result; }
// ---------------------------------------------------------------------------------------------------- UInt32 PlatformInterfaceI2S_Mapped::getI2SIOMIntControl () { UInt32 result = OSReadLittleInt32(mI2SBaseAddress, kI2SIntCtlOffset); return result; }