t_stat i8259_raiseint(I8259* chip,int level) { int32 bit, isr, myprio; TRACE_PRINT1(DBG_PIC_II,"Request INT level=%d",level); if (chip->state != 5) return SCPE_OK; /* not yet initialized, ignore interrupts */ bit = 1<<level; if (chip->imr & bit) return SCPE_OK; /* inhibited */ chip->isr = (chip->isr | bit) & 0xff; /* request this interrupt level */ /* bit7=prio7 => bitN = prioN bit7=prio6 => bitN = prioN-1 ... bit7=prio0 => bitN = prioN-7 */ isr = (chip->isr<<8) | chip->isr; /* simple rotation */ isr = isr << (7-level); /* shift level bit into bit 15 */ myprio = chip->prio - 7 + level; if (myprio < 0) myprio += 8; if (!(isr & priomask[myprio])) { /* higher interrupt is pending */ if (chip->autoint) { TRACE_PRINT1(DBG_PIC_IO,"Raise AUTOINT level=%d",chip->intlevel); return m68k_raise_autoint(chip->intlevel); } else { TRACE_PRINT2(DBG_PIC_IO,"Raise VECTORINT level=%d vector=%x",chip->intlevel,chip->intvector); return m68k_raise_vectorint(chip->intlevel,chip->intvector); } } return SCPE_OK; }
int getIntDevID(TCHAR strDevID[]) //DevID is in form like: "ROOT\\NET\\0008" { TRACE_ENTER(); int iDevID = -1; int iMatched = _stscanf_s(strDevID, _T("ROOT\\NET\\%04d"), &iDevID); TRACE_PRINT2("_stscanf_s: iMatched = %d, iDevID = %d.", iMatched, iDevID); if (iMatched != 1) iDevID = -1; TRACE_EXIT(); return iDevID; }
BOOL EraseLoopbackRecord() { TRACE_ENTER(); BOOL rv = TRUE; #ifndef NPF_NPCAP_RUN_IN_WINPCAP_MODE HKEY hKey; DWORD type; char buffer[BUFSIZE]; DWORD size = sizeof(buffer); DWORD dwWinPcapMode = 0; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, NPCAP_SERVICE_REG_KEY_NAME _T("\\Parameters"), 0, KEY_READ, &hKey) == ERROR_SUCCESS) { if (RegQueryValueExA(hKey, "WinPcapCompatible", 0, &type, (LPBYTE)buffer, &size) == ERROR_SUCCESS && type == REG_DWORD) { dwWinPcapMode = *((DWORD *) buffer); } else { TRACE_PRINT1("RegQueryValueExA(WinPcapCompatible) failed or not REG_DWORD: %#x\n", GetLastError()); dwWinPcapMode = 0; } RegCloseKey(hKey); } else { TRACE_PRINT2("%s\\Parameters) failed: %#x\n", NPCAP_SERVICE_REG_KEY_NAME, GetLastError()); dwWinPcapMode = 0; } if (dwWinPcapMode != 0 && !DeleteValueFromRegistry(_T("SYSTEM\\CurrentControlSet\\Services\\npf\\Parameters"), NPCAP_REG_LOOPBACK_VALUE_NAME)) { rv = FALSE; } #endif /* ifndef NPF_NPCAP_RUN_IN_WINPCAP_MODE */ if (!DeleteValueFromRegistry(NPCAP_REG_KEY_NAME, NPCAP_REG_LOOPBACK_VALUE_NAME)) { rv = FALSE; } if (!DeleteValueFromRegistry(NPCAP_SERVICE_REG_KEY_NAME _T("\\Parameters"), NPCAP_REG_LOOPBACK_VALUE_NAME)) { rv = FALSE; } TRACE_EXIT(); return rv; }
t_stat i8259_read(I8259* chip,int addr, uint32* value) { int i, bit, num; if (addr) { *value = chip->imr; } else { switch (chip->rmode) { case 0: TRACE_PRINT2(DBG_PIC_RD,"Read IRR addr=%d data=0x%x",addr,chip->irr); *value = chip->irr; break; case 1: TRACE_PRINT2(DBG_PIC_RD,"Read ISR addr=%d data=0x%x",addr,chip->irr); *value = chip->isr; break; case 2: case 3: TRACE_PRINT2(DBG_PIC_RD,"Read POLL addr=%d data=0x%x",addr,chip->irr); num = chip->prio; bit = 1 << chip->prio; for (i=0; i<8; i++,num--) { if (chip->isr & bit) { *value = 0x80 | (num & 7); TRACE_PRINT2(DBG_PIC_RD,"Read POLL addr=%d data=0x%x",addr,*value); return SCPE_OK; } bit >>= 1; if (bit==0) { bit = 0x80; num = 7; } } chip->rmode &= ~2; } } #if 0 TRACE_PRINT2(DBG_PIC_RD,"Read addr=%d data=0x%x",addr,*value); #endif return SCPE_OK; }
BOOL AddFlagToRegistry_Service(tstring strDeviceName) { TRACE_ENTER(); BOOL rv = TRUE; #ifndef NPF_NPCAP_RUN_IN_WINPCAP_MODE /* If this is *not* the WinPcap-API compatible build, then it's the native * build, which is responsible for installing and recording the loopback * interface so that both drivers can access it. */ HKEY hKey; DWORD type; char buffer[BUFSIZE]; DWORD size = sizeof(buffer); DWORD dwWinPcapMode = 0; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, NPCAP_SERVICE_REG_KEY_NAME _T("\\Parameters"), 0, KEY_READ, &hKey) == ERROR_SUCCESS) { if (RegQueryValueExA(hKey, "WinPcapCompatible", 0, &type, (LPBYTE)buffer, &size) == ERROR_SUCCESS && type == REG_DWORD) { dwWinPcapMode = *((DWORD *) buffer); } else { TRACE_PRINT1("RegQueryValueExA(WinPcapCompatible) failed or not REG_DWORD: %#x\n", GetLastError()); dwWinPcapMode = 0; } RegCloseKey(hKey); } else { TRACE_PRINT2("%s\\Parameters) failed: %#x\n", NPCAP_SERVICE_REG_KEY_NAME, GetLastError()); dwWinPcapMode = 0; } if (dwWinPcapMode != 0) { rv = WriteStrToRegistry(_T("SYSTEM\\CurrentControlSet\\Services\\npf\\Parameters"), NPCAP_REG_LOOPBACK_VALUE_NAME, tstring(_T("\\Device\\") + strDeviceName).c_str(), KEY_WRITE); } #endif /* ifndef NPF_NPCAP_RUN_IN_WINPCAP_MODE */ rv = WriteStrToRegistry(NPCAP_SERVICE_REG_KEY_NAME _T("\\Parameters"), NPCAP_REG_LOOPBACK_VALUE_NAME, tstring(_T("\\Device\\") + strDeviceName).c_str(), KEY_WRITE) && rv; TRACE_EXIT(); return rv; }
t_stat i8259_write(I8259* chip,int addr,uint32 value) { int i, bit; #if 0 TRACE_PRINT2(DBG_PIC_WR,"WR addr=%d data=0x%x",addr,value); #endif if (addr==1) { switch (chip->state) { default: case 0: /* after reset */ sim_printf("PIC: write addr=1 without initialization\n"); return SCPE_IOERR; case 1: /* expect ICW2 */ TRACE_PRINT2(DBG_PIC_WR,"WR ICW2: addr=%d data=0x%x",addr,value); chip->icw2 = value; if (chip->icw1 & I8259_ICW1_SNGL) { chip->state = (chip->icw1 & I8259_ICW1_IC4) ? 4 : 5; } else { /* attempt to program cascade mode */ sim_printf("PIC: attempt to program chip for cascade mode - not wired for this!\n"); chip->state = 0; return SCPE_IOERR; } break; case 4: /* expect ICW4 */ TRACE_PRINT2(DBG_PIC_WR,"WR ICW4 addr=%d data=0x%x",addr,value); chip->icw4 = value; if (chip->icw4 & I8259_ICW4_AEOI) { sim_printf("PIC: attempt to program chip for AEOI mode - not wired for this!\n"); return SCPE_IOERR; } if (chip->icw4 & I8259_ICW4_BUF) { sim_printf("PIC: attempt to program chip for buffered mode - not wired for this!\n"); return SCPE_IOERR; } if (chip->icw4 & I8259_ICW4_SFNM) { sim_printf("PIC: attempt to program chip for spc nested mode - not wired for this!\n"); return SCPE_IOERR; } chip->state = 5; break; case 5: /* ready to accept interrupt requests and ocw commands */ /* ocw1 */ TRACE_PRINT2(DBG_PIC_WR,"WR IMR addr=%d data=0x%x",addr,value); chip->imr = value; break; } } else { if (value & I8259_ICW1) { /* state initialization sequence */ TRACE_PRINT2(DBG_PIC_WR,"WR ICW1 addr=%d data=0x%x",addr,value); chip->icw1 = value; chip->state = 1; chip->rmode = 0; chip->prio = 7; if ((chip->icw1 & I8259_ICW1_IC4)==0) chip->icw4 = 0; return SCPE_OK; } else { /* ocw2 and ocw3 */ if (value & I8259_OCW3) { /* ocw3 */ TRACE_PRINT2(DBG_PIC_WR,"WR OCW3 addr=%d data=0x%x",addr,value); if (value & I8259_OCW3_ESMM) { sim_printf("PIC: ESMM not yet supported\n"); return STOP_IMPL; } if (value & I8259_OCW3_POLL) { chip->rmode |= 2; return SCPE_OK; } if (value & I8259_OCW3_RR) chip->rmode = (value & I8259_OCW3_RIS) ? 1 /*isr*/ : 0; /* irr */ } else { /* ocw2 */ TRACE_PRINT2(DBG_PIC_WR,"WR OCW2 addr=%d data=0x%x",addr,value); switch (value & I8259_OCW2_MODE) { case 0xa0: /* rotate on nospecific eoi */ case 0x20: /* nonspecific eoi */ bit = 1 << (7 - chip->prio); for (i=0; i<7; i++) { if (chip->isr & bit) break; bit = bit << 1; if (bit==0x100) bit = 1; } chip->isr &= ~bit; break; if ((value & I8259_OCW2_MODE) == 0xa0) { chip->prio = 7 - i + chip->prio; if (chip->prio>7) chip->prio -= 8; } break; case 0xe0: /* rotate on specific eoi */ chip->prio = 7 - (value & 7) + chip->prio; if (chip->prio>7) chip->prio -= 8; /*fallthru*/ case 0x60: /* specific eoi */ bit = 1 << (value & 7); chip->isr = chip->isr & ~bit & 0xff; break; case 0x80: /* rotate in autoeoi (set) */ case 0x00: /* rotate in autoeoi (clear) */ sim_printf("PIC: AEOI not supported\n"); return SCPE_IOERR; case 0xc0: /* set prio */ chip->prio = value & 7; return SCPE_OK; case 0x40: /* nop */ break; default: return SCPE_IERR; } } } } return SCPE_OK; }
BOOL EnumerateComponents(CComPtr<INetCfg>& pINetCfg, const GUID* pguidClass) { TRACE_ENTER(); /* cout << "\n\nEnumerating " << GUID2Str(pguidClass) << " class:\n" << endl;*/ // IEnumNetCfgComponent provides methods that enumerate the INetCfgComponent interfaces // for network components of a particular type installed on the operating system. // Types of network components include network cards, protocols, services, and clients. CComPtr<IEnumNetCfgComponent> pIEnumNetCfgComponent; // get enumeration containing network components of the provided class (GUID) HRESULT hr = pINetCfg->EnumComponents(pguidClass, &pIEnumNetCfgComponent); if(!SUCCEEDED(hr)) { TRACE_PRINT1("INetCfg::EnumComponents: error, errCode = 0x%08x.", hr); throw 1; } // INetCfgComponent interface provides methods that control and retrieve // information about a network component. CComPtr<INetCfgComponent> pINetCfgComponent; unsigned int nIndex = 1; BOOL bFound = FALSE; BOOL bFailed = FALSE; // retrieve the next specified number of INetCfgComponent interfaces in the enumeration sequence. while(pIEnumNetCfgComponent->Next(1, &pINetCfgComponent, 0) == S_OK) { /* cout << GUID2Desc(pguidClass) << " "<< nIndex++ << ":\n";*/ // LPWSTR pszDisplayName = NULL; // pINetCfgComponent->GetDisplayName(&pszDisplayName); // wcout << L"\tDisplay name: " << wstring(pszDisplayName) << L'\n'; // CoTaskMemFree(pszDisplayName); LPWSTR pszBindName = NULL; pINetCfgComponent->GetBindName(&pszBindName); // wcout << L"\tBind name: " << wstring(pszBindName) << L'\n'; // DWORD dwCharacteristics = 0; // pINetCfgComponent->GetCharacteristics(&dwCharacteristics); // cout << "\tCharacteristics: " << dwCharacteristics << '\n'; // // GUID guid; // pINetCfgComponent->GetClassGuid(&guid); // cout << "\tClass GUID: " << guid.Data1 << '-' << guid.Data2 << '-' // << guid.Data3 << '-' << (unsigned int) guid.Data4 << '\n'; // // ULONG ulDeviceStatus = 0; // pINetCfgComponent->GetDeviceStatus(&ulDeviceStatus); // cout << "\tDevice Status: " << ulDeviceStatus << '\n'; // // LPWSTR pszHelpText = NULL; // pINetCfgComponent->GetHelpText(&pszHelpText); // wcout << L"\tHelp Text: " << wstring(pszHelpText) << L'\n'; // CoTaskMemFree(pszHelpText); // // LPWSTR pszID = NULL; // pINetCfgComponent->GetId(&pszID); // wcout << L"\tID: " << wstring(pszID) << L'\n'; // CoTaskMemFree(pszID); // // pINetCfgComponent->GetInstanceGuid(&guid); // cout << "\tInstance GUID: " << guid.Data1 << '-' << guid.Data2 << '-' // << guid.Data3 << '-' << (unsigned int) guid.Data4 << '\n'; LPWSTR pszPndDevNodeId = NULL; hr = pINetCfgComponent->GetPnpDevNodeId(&pszPndDevNodeId); if (!SUCCEEDED(hr)) { TRACE_PRINT1("GetPnpDevNodeId failed: %#x", hr); TRACE_EXIT(); return FALSE; } // wcout << L"\tPNP Device Node ID: " << wstring(pszPndDevNodeId) << L'\n'; int iDevID = getIntDevID(pszPndDevNodeId); TRACE_PRINT4("INetCfgComponent::GetPnpDevNodeId: executing, pszPndDevNodeId = %s, iDevID = %d, g_NpcapAdapterID = %d, pszBindName = %ws.", pszPndDevNodeId, iDevID, g_NpcapAdapterID, pszBindName); if (g_NpcapAdapterID == iDevID) { bFound = TRUE; TRACE_PRINT2("INetCfgComponent::SetDisplayName: executing, g_NpcapAdapterID = iDevID = %d, pszBindName = %ws.", g_NpcapAdapterID, pszBindName); hr = pINetCfgComponent->SetDisplayName(NPCAP_LOOPBACK_ADAPTER_NAME); if (hr != S_OK) { TRACE_PRINT1("INetCfgComponent::SetDisplayName: error, errCode = 0x%08x.", hr); bFailed = TRUE; } if (!AddFlagToRegistry(pszBindName)) { TRACE_PRINT1("AddFlagToRegistry: error, pszBindName = %ws.", pszBindName); bFailed = TRUE; } if (!AddFlagToRegistry_Service(pszBindName)) { TRACE_PRINT1("AddFlagToRegistry_Service: error, pszBindName = %ws.", pszBindName); bFailed = TRUE; } if (!RenameLoopbackNetwork(pszBindName)) { TRACE_PRINT1("RenameLoopbackNetwork: error, pszBindName = %ws.", pszBindName); bFailed = TRUE; } } CoTaskMemFree(pszBindName); CoTaskMemFree(pszPndDevNodeId); pINetCfgComponent.Release(); if (bFound) { TRACE_EXIT(); return !bFailed; } } TRACE_EXIT(); return FALSE; }