📄 besys.c
字号:
/****************************************************************************PARAMETERS:addr - Emulator memory address to readval - Value to storeREMARKS:Writes a long value to emulator memory. We have three distinct memoryregions that are handled differently, which this function handles.****************************************************************************/void X86API BE_wrl( u32 addr, u32 val){DB( if (DEBUG_MEM()) printf("%#08x 4 <- %#x\n", addr, val);) if (addr < M.mem_size - 3) { WRITE32(M.mem_base + addr , val); } else if (addr >= 0xC0000 && addr <= _BE_env.biosmem_limit) { WRITE32(_BE_env.biosmem_base + addr - 0xC0000 , val); } else if (addr >= 0xA0000 && addr < 0xC0000) { WRITE32(_BE_env.busmem_base + addr - 0xA0000 , val); } else if (addr >= 0xf0000 && addr < SYS_SIZE) { WRITE32(_BE_env.sysmem_base + addr - 0xf0000 , val); }else { printf("mem_write: address %#x out of range!\n", addr); HALT_SYS(); }}#ifdef DEBUG_EMU_VGA#define DEBUG_IO() (M.x86.debug & DEBUG_IO_TRACE_F)void check_io(int port,int read,int val){ if(port==0x40||port==0x43) return; //if(port>0x3ff) return;/* static int printed[1024]; static int count=0; int i; for (i=0;i<count;i++) if (printed[i]==port) return; printed[count] = port; count++; if (count>=1024) count=1023;*/ if(port!=0xcf8&&port!=0xcfc&&port!=0x3da&&port!=0x3ba&&port!=61) printf("%4X:%4X %s io port %x, val %x\n",M.x86.R_CS,M.x86.R_IP,read?"write":"read",port,val);}#else#define check_io(port,type,val) #endifu8 X86API BE_inb(int port){ u8 val;#ifdef PLAY_SAFE if (port < 0 || port > 0x10000) { printf("Invalid ioport %x\n",port); return 0xff; }#endif#if !defined(_PC) && !defined(_PC_PCI) if (!pciCfg1in(port,(u32 *)&val,1))#endif val = linux_inb(port);#ifdef DEBUG_EMU_VGA if (DEBUG_IO());#endif// printf("inb.%04X -> %02X\n", (ushort)port, val); check_io(port,0,val); return val;}u16 X86API BE_inw(int port){ u16 val;#ifdef PLAY_SAFE if (port < 0 || port > 0x10000) { printf("Invalid ioport %x\n",port); return 0xffff; }#endif#if !defined(_PC) && !defined(_PC_PCI) if (!pciCfg1in(port,(u32 *)&val,2))#endif#if 0 if (port == 0x5c) { /* Emulate a PC98's timer */ long sec,usec; (void)getsecs(&sec,&usec); val = (u16)(usec / 3 ); }else#endif val = linux_inw(port);#ifdef DEBUG_EMU_VGA if (DEBUG_IO());#endif// printf("inw.%04X -> %04X\n", (ushort)port, val); check_io(port,0,val); return val;}u32 X86API BE_inl(int port){ u32 val; #ifdef PLAY_SAFE if (port < 0 || port > 0x10000) { printf("Invalid ioport %x\n",port); return 0xffffffff; }#endif#if !defined(_PC) && !defined(_PC_PCI) if (!pciCfg1in(port,&val,4))#endif val = linux_inl(port);#ifdef DEBUG_EMU_VGA if (DEBUG_IO());#endif// printf("inl.%04X -> %08X\n", (ushort)port, val); check_io(port,0,val); return val;}void X86API BE_outb(int port, u8 val){#ifdef DEBUG_EMU_VGA if (DEBUG_IO());#endif#ifdef PLAY_SAFE if (port < 0 || port > 0x10000) { printf("Invalid ioport %x\n",port); return; }#endif#if !defined(_PC) && !defined(_PC_PCI) if (!pciCfg1out(port,val,1))#endif //if (port == 0x20 || port == 0x21 || port==0xa0 || port == 0xa1) return; linux_outb(val,port); check_io(port,1,val);//printf("outb.%04X <- %02X\n",(ushort)port, val);}void X86API BE_outw(int port, u16 val){#ifdef DEBUG_EMU_VGA if (DEBUG_IO());#endif#ifdef PLAY_SAFE if (port < 0 || port > 0x10000) { printf("Invalid ioport %x\n",port); return; }#endif#if !defined(_PC) && !defined(_PC_PCI) if (!pciCfg1out(port,val,2))#endif linux_outw(val,port); check_io(port,1,val); //printf("outw.%04X <- %04X\n", (ushort)port, val);}void X86API BE_outl(int port, u32 val){#ifdef DEBUG_EMU_VGA if (DEBUG_IO());#endif#if !defined(_PC) && !defined(_PC_PCI) if (!pciCfg1out(port,val,4))#endif#ifdef PLAY_SAFE if (port < 0 || port > 0x10000) { printf("Invalid ioport %x\n",port); return; }#endif linux_outl(val,port); check_io(port,1,val); //printf("outl.%04X <- %08X\n", (ushort)port, val);}#if !defined(_PC) && !defined(_PC_PCI)static u32 PciCfg1Addr = 0;#define BUS(Cfg1Addr) ((Cfg1Addr & 0xff0000) >> 16)#define DEVFN(Cfg1Addr) ((Cfg1Addr & 0xff00) >> 8)#define OFFSET(Cfg1Addr) (Cfg1Addr & 0xff)void pcibios_read_config_dword(int bus,int devfn,int offset,int * val){ *val=_pci_conf_read(_pci_make_tag(bus,((devfn>>3)&0x1f),(devfn&0x7)),offset);}void pcibios_read_config_byte(int bus,int devfn,int offset,int * val){ *val=_pci_conf_readn(_pci_make_tag(bus,((devfn>>3)&0x1f),(devfn&0x7)),offset,1);}void pcibios_read_config_word(int bus,int devfn,int offset,int * val){ *val=_pci_conf_readn(_pci_make_tag(bus,((devfn>>3)&0x1f),(devfn&0x7)),offset,2);}void pcibios_write_config_dword(int bus,int devfn,int offset,int val){ _pci_conf_write(_pci_make_tag(bus,((devfn>>3)&0x1f),(devfn&0x7)),offset,val);}void pcibios_write_config_byte(int bus,int devfn,int offset,int val){ _pci_conf_writen(_pci_make_tag(bus,((devfn>>3)&0x1f),(devfn&0x7)),offset,val,1);}void pcibios_write_config_word(int bus,int devfn,int offset,int val){ _pci_conf_writen(_pci_make_tag(bus,((devfn>>3)&0x1f),(devfn&0x7)),offset,val,2);}static intpciCfg1in(u16 addr, u32 *val,int type){ if (addr == 0xCF8) { *val = PciCfg1Addr; return 1; } if (addr == 0xCFC) { if(type==0){ pcibios_read_config_byte(BUS(PciCfg1Addr),DEVFN(PciCfg1Addr),OFFSET(PciCfg1Addr),(u8*)val); }else if(type==1){ pcibios_read_config_word(BUS(PciCfg1Addr),DEVFN(PciCfg1Addr),OFFSET(PciCfg1Addr),(u16*)val); }else if(type==2){ pcibios_read_config_dword(BUS(PciCfg1Addr),DEVFN(PciCfg1Addr),OFFSET(PciCfg1Addr),(u32*)val); }else{ printf("wrong type for pci config op\n"); } return 1; } return 0;}static intpciCfg1out(u16 addr, u32 val,int type){ if (addr == 0xCF8) { PciCfg1Addr = val; return 1; } if (addr == 0xCFC) { if(type==0){ pcibios_write_config_byte(BUS(PciCfg1Addr),DEVFN(PciCfg1Addr),OFFSET(PciCfg1Addr),val); }else if(type==1){ pcibios_write_config_word(BUS(PciCfg1Addr),DEVFN(PciCfg1Addr),OFFSET(PciCfg1Addr),val); }else if(type==2){ pcibios_write_config_dword(BUS(PciCfg1Addr),DEVFN(PciCfg1Addr),OFFSET(PciCfg1Addr),val); }else{ printf("wrong type for pci config op\n"); } return 1; } return 0;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -