void PrintContext(CONTEXT* context) { while (context) { printf("{"); PAIR* list = context->list; while (list) { printf("%s: ", list->identifier); VALUE value = list->value; if (value.type == VAL_PRIMITIVE) printf("%i", value.data.primitive); else if (value.type == VAL_STRING) printf("%s", value.data.string); else if (value.type == VAL_REFERENCE) { printf("["); PrintContext(value.data.reference); printf("]"); } else if (value.type == VAL_FUNCTION) printf("f()"); else printf("nil"); printf(", "); list = list->next; } context = context->parent; printf("}"); if (context) printf("\n"); } }
void StdoutConsumer::Consume(const Log::Entry& entry) { PrintHeader(entry); PrintMessage(std::cout, entry, true); PrintContext(entry); PrintNewLine(std::cout, true); }
void CDebugger::DumpCrash(DWORD dwThreadId, DWORD dwProcessId, DWORD_PTR dwAddress) { PrintContext(dwThreadId); PrintDisAsm(dwProcessId, dwAddress); PrintCallStack(dwThreadId, dwProcessId); m_pCrash->Send(); m_pCrash->PrintLog(); }
VOID ShowContext(VOID * ip, VOID * handle, ADDRINT gax) { CONTEXT ctxt; // Capture the context. This must be done first before some floating point // registers have been overwritten PIN_MakeContext(handle, &ctxt); static bool first = false; if (first) { cout << "ip: " << ip << endl; PrintContext(&ctxt); cout << endl; } #if defined(TARGET_IA32) || defined(TARGET_IA32E) ASSERTX(gax == ctxt._gax); #endif }
IOReturn CLASS::AddressDevice(uint32_t deviceSlot, uint16_t maxPacketSize, bool wantSAR, uint8_t speed, int32_t highSpeedHubSlot, int32_t highSpeedPort) { ringStruct* pRing; ContextStruct *pContext, *pHubContext; uint32_t routeString; int32_t retFromCMD; uint16_t currentPortOnHub, currentHubAddress, addr; TRBStruct localTrb = { 0 }; pRing = GetRing(deviceSlot, 1, 0U); if (pRing->isInactive()) return kIOReturnInternalError; currentPortOnHub = _deviceZero.PortOnHub; currentHubAddress = _deviceZero.HubAddress; routeString = 0U; for (int32_t depth = 0; depth < 5; ++depth) { if (currentHubAddress == _hub3Address || currentHubAddress == _hub2Address) break; if (currentPortOnHub > kMaxExternalHubPorts) currentPortOnHub = kMaxExternalHubPorts; routeString = (routeString << 4) + currentPortOnHub; addr = currentHubAddress; currentHubAddress = _addressMapper.HubAddress[addr]; currentPortOnHub = _addressMapper.PortOnHub[addr]; } if (currentHubAddress != _hub3Address && currentHubAddress != _hub2Address) { IOLog("%s: Root hub port not found in topology: hub: %u, rootHubSS: %u rootHubHS: %u\n", __FUNCTION__, currentHubAddress, _hub3Address, _hub2Address); return kIOReturnInternalError; } if (!currentPortOnHub || currentPortOnHub > _rootHubNumPorts) { IOLog("%s: Root hub port number invalid: %u\n", __FUNCTION__, currentPortOnHub); return kIOReturnInternalError; } GetInputContext(); pContext = GetInputContextPtr(); pContext->_ic.dwInCtx1 = XHCI_INCTX_1_ADD_MASK(1U) | XHCI_INCTX_1_ADD_MASK(0U); pContext = GetInputContextPtr(1); pContext->_s.dwSctx1 |= XHCI_SCTX_1_RH_PORT_SET(static_cast<uint32_t>(currentPortOnHub)); pContext->_s.dwSctx0 = XHCI_SCTX_0_CTX_NUM_SET(1U); #if 0 uint32_t portSpeed = Read32Reg(&_pXHCIOperationalRegisters->prs[currentPortOnHub - 1U].PortSC); if (m_invalid_regspace) return kIOReturnNoDevice; portSpeed = XHCI_PS_SPEED_GET(portSpeed); if (portSpeed >= XDEV_SS) { SetSlCtxSpeed(pContext, portSpeed); maxPacketSize = 512U; goto skip_low_full; } #else if ((currentHubAddress == _hub3Address) && (speed < kUSBDeviceSpeedSuper || maxPacketSize != 512U)) IOLog("%s: Inconsistent device speed %u (maxPacketSize %u) for topology rooted in SuperSpeed hub\n", __FUNCTION__, speed, maxPacketSize); #endif switch (speed) { case kUSBDeviceSpeedLow: SetSlCtxSpeed(pContext, XDEV_LS); break; case kUSBDeviceSpeedFull: default: SetSlCtxSpeed(pContext, XDEV_FS); break; case kUSBDeviceSpeedHigh: SetSlCtxSpeed(pContext, XDEV_HS); goto skip_low_full; case kUSBDeviceSpeedSuper: SetSlCtxSpeed(pContext, XDEV_SS); goto skip_low_full; } /* * Note: Only for Low or Full Speed devices */ if (highSpeedHubSlot) { pContext->_s.dwSctx2 |= XHCI_SCTX_2_TT_PORT_NUM_SET(highSpeedPort); pContext->_s.dwSctx2 |= XHCI_SCTX_2_TT_HUB_SID_SET(highSpeedHubSlot); pHubContext = GetSlotContext(highSpeedHubSlot); if (pHubContext && XHCI_SCTX_0_MTT_GET(pHubContext->_s.dwSctx0)) pContext->_s.dwSctx0 |= XHCI_SCTX_0_MTT_SET(1U); else pContext->_s.dwSctx0 &= ~XHCI_SCTX_0_MTT_SET(1U); } skip_low_full: #if kMaxActiveInterrupters > 1 pContext->_s.dwSctx2 |= XHCI_SCTX_2_IRQ_TARGET_SET(1U); #endif pContext->_s.dwSctx0 |= XHCI_SCTX_0_ROUTE_SET(routeString); pContext = GetInputContextPtr(2); pContext->_e.dwEpCtx1 |= XHCI_EPCTX_1_EPTYPE_SET(CTRL_EP); pContext->_e.dwEpCtx1 |= XHCI_EPCTX_1_MAXP_SIZE_SET(static_cast<uint32_t>(maxPacketSize)); pContext->_e.qwEpCtx2 |= (pRing->physAddr + pRing->dequeueIndex * sizeof *pRing->ptr) & XHCI_EPCTX_2_TR_DQ_PTR_MASK; if (pRing->cycleState) pContext->_e.qwEpCtx2 |= XHCI_EPCTX_2_DCS_SET(1U); else pContext->_e.qwEpCtx2 &= ~static_cast<uint64_t>(XHCI_EPCTX_2_DCS_SET(1U)); pContext->_e.dwEpCtx1 |= XHCI_EPCTX_1_CERR_SET(3U); pContext->_e.dwEpCtx4 |= XHCI_EPCTX_4_AVG_TRB_LEN_SET(8U); SetTRBAddr64(&localTrb, _inputContext.physAddr); localTrb.d |= XHCI_TRB_3_SLOT_SET(deviceSlot); if (!wantSAR) localTrb.d |= XHCI_TRB_3_BSR_BIT; retFromCMD = WaitForCMD(&localTrb, XHCI_TRB_TYPE_ADDRESS_DEVICE, 0); ReleaseInputContext(); if (retFromCMD == -1) return kIOReturnInternalError; else if (retFromCMD > -1000) return kIOReturnSuccess; else if (retFromCMD == -1000 - XHCI_TRB_ERROR_PARAMETER) { #if 0 PrintContext(GetInputContextPtr()); PrintContext(GetInputContextPtr(1)); PrintContext(GetInputContextPtr(2)); #endif } return TranslateXHCIStatus(-1000 - retFromCMD, deviceSlot, false); }
IOReturn CLASS::UIMCreateControlEndpoint(UInt8 functionNumber, UInt8 endpointNumber, UInt16 maxPacketSize, UInt8 speed, USBDeviceAddress highSpeedHub, int highSpeedPort) { TRBStruct localTrb = { 0U }; IOReturn rc; ContextStruct* pContext; ringStruct* pRing; int32_t retFromCMD; uint16_t packetSize; uint8_t slot; if (functionNumber == _hub3Address || functionNumber == _hub2Address) return kIOReturnSuccess; packetSize = maxPacketSize != 9U ? maxPacketSize : 512U; if (!functionNumber) { if (_numEndpoints >= _maxNumEndpoints) return kIOUSBEndpointCountExceeded; retFromCMD = WaitForCMD(&localTrb, XHCI_TRB_TYPE_ENABLE_SLOT, 0); if (retFromCMD == -1 || retFromCMD <= -1000) return retFromCMD == (-1000 - XHCI_TRB_ERROR_NO_SLOTS) ? kIOUSBDeviceCountExceeded : kIOReturnInternalError; slot = static_cast<uint8_t>(retFromCMD); #if 0 /* * Note: Added Mavericks */ if (_vendorID == kVendorIntel && _IntelSlotWorkaround && slot == _numSlots) { _IntelSlotWorkaround = false; retFromCMD = CleanupControlEndpoint(slot, true); _IntelSWSlot = slot; if (retFromCMD == -1 || retFromCMD <= -1000) return kIOReturnInternalError; ClearTRB(&localTrb, true); retFromCMD = WaitForCMD(&localTrb, XHCI_TRB_TYPE_ENABLE_SLOT, 0); if (retFromCMD == -1 || retFromCMD <= -1000) return retFromCMD == (-1000 - XHCI_TRB_ERROR_NO_SLOTS) ? kIOUSBDeviceCountExceeded : kIOReturnInternalError; slot = static_cast<uint8_t>(retFromCMD); if (slot == _numSlots) ExecuteGetPortBandwidthWorkaround(); } _IntelSlotWorkaround = false; #endif if (!slot || slot > _numSlots) { /* * Sanity check. Bail out, 'cause UIMDeleteEndpoint * won't handle invalid slot # well. */ CleanupControlEndpoint(slot, true); IOLog("%s: xHC assigned invalid slot number %u\n", __FUNCTION__, slot); return kIOUSBDeviceCountExceeded; } pRing = CreateRing(slot, 1, 0U); if (!pRing || pRing->md) { CleanupControlEndpoint(slot, true); return kIOReturnInternalError; } _addressMapper.Slot[0] = slot; _addressMapper.Active[0] = true; rc = AllocRing(pRing, 1); if (rc != kIOReturnSuccess) { CleanupControlEndpoint(slot, false); return kIOReturnNoMemory; } rc = MakeBuffer(kIOMemoryPhysicallyContiguous | kIODirectionInOut, GetDeviceContextSize(), -PAGE_SIZE, &SlotPtr(slot)->md, reinterpret_cast<void**>(&SlotPtr(slot)->ctx), &SlotPtr(slot)->physAddr); if (rc != kIOReturnSuccess) { CleanupControlEndpoint(slot, false); return kIOReturnNoMemory; } if (!pRing->asyncEndpoint) { pRing->epType = CTRL_EP; pRing->asyncEndpoint = XHCIAsyncEndpoint::withParameters(this, pRing, packetSize, 0U, 0U); if (!pRing->asyncEndpoint) { CleanupControlEndpoint(slot, false); return kIOReturnNoMemory; } static_cast<void>(__sync_fetch_and_add(&_numEndpoints, 1)); } SetDCBAAAddr64(&_dcbaa.ptr[slot], ConstSlotPtr(slot)->physAddr); return AddressDevice(slot, packetSize, false, speed, GetSlotID(highSpeedHub), highSpeedPort); } if (endpointNumber) return kIOReturnInternalError; slot = GetSlotID(functionNumber); if (!slot) return kIOReturnInternalError; pContext = GetSlotContext(slot, 1); if (!pContext) return kIOReturnInternalError; if (XHCI_EPCTX_1_MAXP_SIZE_GET(pContext->_e.dwEpCtx1) == packetSize) return kIOReturnSuccess; GetInputContext(); pContext = GetInputContextPtr(); pContext->_ic.dwInCtx1 = XHCI_INCTX_1_ADD_MASK(1U); pContext = GetInputContextPtr(2); pContext->_e.dwEpCtx1 = XHCI_EPCTX_1_MAXP_SIZE_SET(static_cast<uint32_t>(packetSize)); SetTRBAddr64(&localTrb, _inputContext.physAddr); localTrb.d = XHCI_TRB_3_SLOT_SET(static_cast<uint32_t>(slot)); retFromCMD = WaitForCMD(&localTrb, XHCI_TRB_TYPE_EVALUATE_CTX, 0); ReleaseInputContext(); if (retFromCMD == -1) return kIOReturnInternalError; if (retFromCMD > -1000) return kIOReturnSuccess; if (retFromCMD == -1000 - XHCI_TRB_ERROR_PARAMETER) { #if 0 PrintContext(GetInputContextPtr()); PrintContext(GetInputContextPtr(2)); #endif } return kIOReturnInternalError; }
VOID IntelRegistersp( IN HANDLE CurrentProcess, IN HANDLE CurrentThread, IN LPSTR ArgumentString ) /*++ Routine Description: This routine dumps out the 16 bit register set from the vdmtib Arguments: CurrentProcess -- Supplies a handle to the current process CurrentThread -- Supplies a handle to the current thread ArgumentString -- Supplies a pointer to the commands argument string Return Value: None. Notes: This routine assumes that the pointers to the ntsd routines have already been set up. --*/ { BOOL Status; ULONG Address, BytesRead; CONTEXT IntelRegisters; UNREFERENCED_PARAMETER(CurrentThread); // // Get the address of the VdmTib // if (sscanf(ArgumentString, "%lx", &Address) < 0) { Address = (*GetExpression)( "ntvdm!VdmTib" ); } if (!Address) { (*Print)("Error geting VdmTib address\n"); return; } // // Read the 16 bit context // Status = ReadProcessMem( CurrentProcess, &(((PVDM_TIB)Address)->VdmContext), &IntelRegisters, sizeof(CONTEXT), &BytesRead ); if ((!Status) || (BytesRead != sizeof(CONTEXT))) { GetLastError(); (*Print)("Could not get VdmContext\n"); } else { PrintContext(&IntelRegisters); } }