📄 besys.c
字号:
case 0x3C7: _BE_env.emu3C7 = (int) val *3; break; case 0x3C8: _BE_env.emu3C8 = (int) val *3; break; case 0x3C9: if (_BE_env.emu3C8 < PAL_C) _BE_env.emu3C9[_BE_env.emu3C8++] = val; break; case 0x3CE: _BE_env.emu3CE = val; break; case 0x3CF: if (_BE_env.emu3CE < GRA_C) _BE_env.emu3CF[_BE_env.emu3CE] = val; break; case 0x3D4: if (_BE_env.emu3C2 & 0x1) _BE_env.emu3D4 = val; break; case 0x3D5: if ((_BE_env.emu3C2 & 0x1) && (_BE_env.emu3D4 < CRT_C)) _BE_env.emu3D5[_BE_env.emu3D4] = val; break; }}/****************************************************************************PARAMETERS:regOffset - Offset into register space for non-DWORD accessesvalue - Value to write to register for PCI_WRITE_* operationsfunc - Function to perform (PCIAccessRegFlags)RETURNS:Value read from configuration register for PCI_READ_* operationsREMARKS:Accesses a PCI configuration space register by decoding the value currentlystored in the _BE_env.configAddress variable and passing it through to theportable PCI_accessReg function.****************************************************************************/static u32 BE_accessReg(int regOffset, u32 value, int func){#ifdef __KERNEL__ int function, device, bus; u8 val8; u16 val16; u32 val32; /* Decode the configuration register values for the register we wish to * access */ regOffset += (_BE_env.configAddress & 0xFF); function = (_BE_env.configAddress >> 8) & 0x7; device = (_BE_env.configAddress >> 11) & 0x1F; bus = (_BE_env.configAddress >> 16) & 0xFF; /* Ignore accesses to all devices other than the one we're POSTing */ if ((function == _BE_env.vgaInfo.function) && (device == _BE_env.vgaInfo.device) && (bus == _BE_env.vgaInfo.bus)) { switch (func) { case REG_READ_BYTE: pci_read_config_byte(_BE_env.vgaInfo.pcidev, regOffset, &val8); return val8; case REG_READ_WORD: pci_read_config_word(_BE_env.vgaInfo.pcidev, regOffset, &val16); return val16; case REG_READ_DWORD: pci_read_config_dword(_BE_env.vgaInfo.pcidev, regOffset, &val32); return val32; case REG_WRITE_BYTE: pci_write_config_byte(_BE_env.vgaInfo.pcidev, regOffset, value); return 0; case REG_WRITE_WORD: pci_write_config_word(_BE_env.vgaInfo.pcidev, regOffset, value); return 0; case REG_WRITE_DWORD: pci_write_config_dword(_BE_env.vgaInfo.pcidev, regOffset, value); return 0; } } return 0;#else PCIDeviceInfo pciInfo; pciInfo.mech1 = 1; pciInfo.slot.i = 0; pciInfo.slot.p.Function = (_BE_env.configAddress >> 8) & 0x7; pciInfo.slot.p.Device = (_BE_env.configAddress >> 11) & 0x1F; pciInfo.slot.p.Bus = (_BE_env.configAddress >> 16) & 0xFF; pciInfo.slot.p.Enable = 1; /* Ignore accesses to all devices other than the one we're POSTing */ if ((pciInfo.slot.p.Function == _BE_env.vgaInfo.pciInfo->slot.p.Function) && (pciInfo.slot.p.Device == _BE_env.vgaInfo.pciInfo->slot.p.Device) && (pciInfo.slot.p.Bus == _BE_env.vgaInfo.pciInfo->slot.p.Bus)) return PCI_accessReg((_BE_env.configAddress & 0xFF) + regOffset, value, func, &pciInfo); return 0;#endif}/****************************************************************************PARAMETERS:port - Port to read fromtype - Type of access to performREMARKS:Performs an emulated read from one of the PCI configuration space registers.We emulate this using our PCI_accessReg function which will access the PCIconfiguration space registers in a portable fashion.****************************************************************************/static u32 PCI_inp(int port, int type){ switch (type) { case REG_READ_BYTE: if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port && port <= 0xCFF) return BE_accessReg(port - 0xCFC, 0, REG_READ_BYTE); break; case REG_READ_WORD: if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port && port <= 0xCFF) return BE_accessReg(port - 0xCFC, 0, REG_READ_WORD); break; case REG_READ_DWORD: if (port == 0xCF8) return _BE_env.configAddress; else if ((_BE_env.configAddress & 0x80000000) && port == 0xCFC) return BE_accessReg(0, 0, REG_READ_DWORD); break; } return 0;}/****************************************************************************PARAMETERS:port - Port to write totype - Type of access to performREMARKS:Performs an emulated write to one of the PCI control registers.****************************************************************************/static void PCI_outp(int port, u32 val, int type){ switch (type) { case REG_WRITE_BYTE: if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port && port <= 0xCFF) BE_accessReg(port - 0xCFC, val, REG_WRITE_BYTE); break; case REG_WRITE_WORD: if ((_BE_env.configAddress & 0x80000000) && 0xCFC <= port && port <= 0xCFF) BE_accessReg(port - 0xCFC, val, REG_WRITE_WORD); break; case REG_WRITE_DWORD: if (port == 0xCF8) { _BE_env.configAddress = val & 0x80FFFFFC; } else if ((_BE_env.configAddress & 0x80000000) && port == 0xCFC) BE_accessReg(0, val, REG_WRITE_DWORD); break; }}#endif/****************************************************************************PARAMETERS:port - Port to write toRETURNS:Value read from the I/O portREMARKS:Performs an emulated 8-bit read from an I/O port. We handle special casesthat we need to emulate in here, and fall through to reflecting the writethrough to the real hardware if we don't need to special case it.****************************************************************************/u8 X86API BE_inb(X86EMU_pioAddr port){ u8 val = 0;#if defined(DEBUG) || !defined(__i386__) if (IS_VGA_PORT(port)){ /*seems reading port 0x3c3 return the high 16 bit of io port*/ if(port == 0x3c3) val = LOG_inpb(port); else val = VGA_inpb(port); } else if (IS_TIMER_PORT(port)) DB(printf("Can not interept TIMER port now!\n");) else if (IS_SPKR_PORT(port)) DB(printf("Can not interept SPEAKER port now!\n");) else if (IS_CMOS_PORT(port)) DB(printf("Can not interept CMOS port now!\n");) else if (IS_PCI_PORT(port)) val = PCI_inp(port, REG_READ_BYTE); else if (port < 0x100) { DB(printf("WARN: INVALID inb.%04X -> %02X\n", (u16) port, val);) val = LOG_inpb(port); } else#endif val = LOG_inpb(port); return val;}/****************************************************************************PARAMETERS:port - Port to write toRETURNS:Value read from the I/O portREMARKS:Performs an emulated 16-bit read from an I/O port. We handle special casesthat we need to emulate in here, and fall through to reflecting the writethrough to the real hardware if we don't need to special case it.****************************************************************************/u16 X86API BE_inw(X86EMU_pioAddr port){ u16 val = 0;#if defined(DEBUG) || !defined(__i386__) if (IS_PCI_PORT(port)) val = PCI_inp(port, REG_READ_WORD); else if (port < 0x100) { DB(printf("WARN: Maybe INVALID inw.%04X -> %04X\n", (u16) port, val);) val = LOG_inpw(port); } else#endif val = LOG_inpw(port); return val;}/****************************************************************************PARAMETERS:port - Port to write toRETURNS:Value read from the I/O portREMARKS:Performs an emulated 32-bit read from an I/O port. We handle special casesthat we need to emulate in here, and fall through to reflecting the writethrough to the real hardware if we don't need to special case it.****************************************************************************/u32 X86API BE_inl(X86EMU_pioAddr port){ u32 val = 0;#if defined(DEBUG) || !defined(__i386__) if (IS_PCI_PORT(port)) val = PCI_inp(port, REG_READ_DWORD); else if (port < 0x100) { val = LOG_inpd(port); } else#endif val = LOG_inpd(port); return val;}/****************************************************************************PARAMETERS:port - Port to write toval - Value to write to portREMARKS:Performs an emulated 8-bit write to an I/O port. We handle special casesthat we need to emulate in here, and fall through to reflecting the writethrough to the real hardware if we don't need to special case it.****************************************************************************/void X86API BE_outb(X86EMU_pioAddr port, u8 val){#if defined(DEBUG) || !defined(__i386__) if (IS_VGA_PORT(port)) VGA_outpb(port, val); else if (IS_TIMER_PORT(port)) DB(printf("Can not interept TIMER port now!\n");) else if (IS_SPKR_PORT(port)) DB(printf("Can not interept SPEAKER port now!\n");) else if (IS_CMOS_PORT(port)) DB(printf("Can not interept CMOS port now!\n");) else if (IS_PCI_PORT(port)) PCI_outp(port, val, REG_WRITE_BYTE); else if (port < 0x100) { DB(printf("WARN:Maybe INVALID outb.%04X <- %02X\n", (u16) port, val);) LOG_outpb(port, val); } else#endif LOG_outpb(port, val);}/****************************************************************************PARAMETERS:port - Port to write toval - Value to write to portREMARKS:Performs an emulated 16-bit write to an I/O port. We handle special casesthat we need to emulate in here, and fall through to reflecting the writethrough to the real hardware if we don't need to special case it.****************************************************************************/void X86API BE_outw(X86EMU_pioAddr port, u16 val){#if defined(DEBUG) || !defined(__i386__) if (IS_VGA_PORT(port)) { VGA_outpb(port, val); VGA_outpb(port + 1, val >> 8); } else if (IS_PCI_PORT(port)) PCI_outp(port, val, REG_WRITE_WORD); else if (port < 0x100) { DB(printf("WARN: MAybe INVALID outw.%04X <- %04X\n", (u16) port, val);) LOG_outpw(port, val); } else#endif LOG_outpw(port, val);}/****************************************************************************PARAMETERS:port - Port to write toval - Value to write to portREMARKS:Performs an emulated 32-bit write to an I/O port. We handle special casesthat we need to emulate in here, and fall through to reflecting the writethrough to the real hardware if we don't need to special case it.****************************************************************************/void X86API BE_outl(X86EMU_pioAddr port, u32 val){#if defined(DEBUG) || !defined(__i386__) if (IS_PCI_PORT(port)) PCI_outp(port, val, REG_WRITE_DWORD); else if (port < 0x100) { DB(printf("WARN: INVALID outl.%04X <- %08X\n", (u16) port,val);) LOG_outpd(port, val); } else#endif LOG_outpd(port, val);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -