📄 sys.c
字号:
Long value read from emulator memory.REMARKS:Reads a long value from the emulator memory.****************************************************************************/u32 X86API rdl( u32 addr){ u32 val = 0; if (addr > M.mem_size - 4) { DB(printk("mem_read: address %#lx out of range!\n", addr);) HALT_SYS(); }#ifdef __BIG_ENDIAN__ if (addr & 0x3) { val = (*(u8*)(M.mem_base + addr + 0) | (*(u8*)(M.mem_base + addr + 1) << 8) | (*(u8*)(M.mem_base + addr + 2) << 16) | (*(u8*)(M.mem_base + addr + 3) << 24)); } else#endif#ifdef __alpha__ val = ldl_u((u32*)(M.mem_base + addr));#elif defined (__ia64__) val = uldl((u32*)(M.mem_base + addr));#else val = *(u32*)(M.mem_base + addr);#endifDB( if (DEBUG_MEM_TRACE()) printk("%#08x 4 -> %#x\n", addr, val);) return val;}/****************************************************************************PARAMETERS:addr - Emulator memory address to readval - Value to storeREMARKS:Writes a byte value to emulator memory.****************************************************************************/void X86API wrb( u32 addr, u8 val){DB( if (DEBUG_MEM_TRACE()) printk("%#08x 1 <- %#x\n", addr, val);) if (addr > M.mem_size - 1) { DB(printk("mem_write: address %#lx out of range!\n", addr);) HALT_SYS(); } *(u8*)(M.mem_base + addr) = val;}/****************************************************************************PARAMETERS:addr - Emulator memory address to readval - Value to storeREMARKS:Writes a word value to emulator memory.****************************************************************************/void X86API wrw( u32 addr, u16 val){DB( if (DEBUG_MEM_TRACE()) printk("%#08x 2 <- %#x\n", addr, val);) if (addr > M.mem_size - 2) { DB(printk("mem_write: address %#lx out of range!\n", addr);) HALT_SYS(); }#ifdef __BIG_ENDIAN__ if (addr & 0x1) { *(u8*)(M.mem_base + addr + 0) = (val >> 0) & 0xff; *(u8*)(M.mem_base + addr + 1) = (val >> 8) & 0xff; } else#endif#ifdef __alpha__ stw_u(val,(u16*)(M.mem_base + addr));#elif defined (__ia64__) ustw(val,(u16*)(M.mem_base + addr));#else *(u16*)(M.mem_base + addr) = val;#endif}/****************************************************************************PARAMETERS:addr - Emulator memory address to readval - Value to storeREMARKS:Writes a long value to emulator memory.****************************************************************************/void X86API wrl( u32 addr, u32 val){DB( if (DEBUG_MEM_TRACE()) printk("%#08x 4 <- %#x\n", addr, val);) if (addr > M.mem_size - 4) { DB(printk("mem_write: address %#lx out of range!\n", addr);) HALT_SYS(); }#ifdef __BIG_ENDIAN__ if (addr & 0x1) { *(u8*)(M.mem_base + addr + 0) = (val >> 0) & 0xff; *(u8*)(M.mem_base + addr + 1) = (val >> 8) & 0xff; *(u8*)(M.mem_base + addr + 2) = (val >> 16) & 0xff; *(u8*)(M.mem_base + addr + 3) = (val >> 24) & 0xff; } else#endif#ifdef __alpha__ stl_u(val,(u32*)(M.mem_base + addr));#elif defined (__ia64__) ustl(val,(u32*)(M.mem_base + addr));#else *(u32*)(M.mem_base + addr) = val;#endif}/****************************************************************************PARAMETERS:addr - PIO address to readRETURN:0REMARKS:Default PIO byte read function. Doesn't perform real inb.****************************************************************************/static u8 X86API p_inb( X86EMU_pioAddr addr){DB( if (DEBUG_IO_TRACE()) printk("inb %#04x \n", addr);) return 0;}/****************************************************************************PARAMETERS:addr - PIO address to readRETURN:0REMARKS:Default PIO word read function. Doesn't perform real inw.****************************************************************************/static u16 X86API p_inw( X86EMU_pioAddr addr){DB( if (DEBUG_IO_TRACE()) printk("inw %#04x \n", addr);) return 0;}/****************************************************************************PARAMETERS:addr - PIO address to readRETURN:0REMARKS:Default PIO long read function. Doesn't perform real inl.****************************************************************************/static u32 X86API p_inl( X86EMU_pioAddr addr){DB( if (DEBUG_IO_TRACE()) printk("inl %#04x \n", addr);) return 0;}/****************************************************************************PARAMETERS:addr - PIO address to writeval - Value to storeREMARKS:Default PIO byte write function. Doesn't perform real outb.****************************************************************************/static void X86API p_outb( X86EMU_pioAddr addr, u8 val){DB( if (DEBUG_IO_TRACE()) printk("outb %#02x -> %#04x \n", val, addr);) return;}/****************************************************************************PARAMETERS:addr - PIO address to writeval - Value to storeREMARKS:Default PIO word write function. Doesn't perform real outw.****************************************************************************/static void X86API p_outw( X86EMU_pioAddr addr, u16 val){DB( if (DEBUG_IO_TRACE()) printk("outw %#04x -> %#04x \n", val, addr);) return;}/****************************************************************************PARAMETERS:addr - PIO address to writeval - Value to storeREMARKS:Default PIO ;ong write function. Doesn't perform real outl.****************************************************************************/static void X86API p_outl( X86EMU_pioAddr addr, u32 val){DB( if (DEBUG_IO_TRACE()) printk("outl %#08x -> %#04x \n", val, addr);) return;}/*------------------------- Global Variables ------------------------------*/u8 (X86APIP sys_rdb)(u32 addr) = rdb;u16 (X86APIP sys_rdw)(u32 addr) = rdw;u32 (X86APIP sys_rdl)(u32 addr) = rdl;void (X86APIP sys_wrb)(u32 addr,u8 val) = wrb;void (X86APIP sys_wrw)(u32 addr,u16 val) = wrw;void (X86APIP sys_wrl)(u32 addr,u32 val) = wrl;u8 (X86APIP sys_inb)(X86EMU_pioAddr addr) = p_inb;u16 (X86APIP sys_inw)(X86EMU_pioAddr addr) = p_inw;u32 (X86APIP sys_inl)(X86EMU_pioAddr addr) = p_inl;void (X86APIP sys_outb)(X86EMU_pioAddr addr, u8 val) = p_outb;void (X86APIP sys_outw)(X86EMU_pioAddr addr, u16 val) = p_outw;void (X86APIP sys_outl)(X86EMU_pioAddr addr, u32 val) = p_outl;/*----------------------------- Setup -------------------------------------*//****************************************************************************PARAMETERS:funcs - New memory function pointers to make activeREMARKS:This function is used to set the pointers to functions which accessmemory space, allowing the user application to override these functionsand hook them out as necessary for their application.****************************************************************************/void X86EMU_setupMemFuncs( X86EMU_memFuncs *funcs){ sys_rdb = funcs->rdb; sys_rdw = funcs->rdw; sys_rdl = funcs->rdl; sys_wrb = funcs->wrb; sys_wrw = funcs->wrw; sys_wrl = funcs->wrl;}/****************************************************************************PARAMETERS:funcs - New programmed I/O function pointers to make activeREMARKS:This function is used to set the pointers to functions which accessI/O space, allowing the user application to override these functionsand hook them out as necessary for their application.****************************************************************************/void X86EMU_setupPioFuncs( X86EMU_pioFuncs *funcs){ sys_inb = funcs->inb; sys_inw = funcs->inw; sys_inl = funcs->inl; sys_outb = funcs->outb; sys_outw = funcs->outw; sys_outl = funcs->outl;}/****************************************************************************PARAMETERS:funcs - New interrupt vector table to make activeREMARKS:This function is used to set the pointers to functions which handleinterrupt processing in the emulator, allowing the user application tohook interrupts as necessary for their application. Any interrupts thatare not hooked by the user application, and reflected and handled internallyin the emulator via the interrupt vector table. This allows the applicationto get control when the code being emulated executes specific softwareinterrupts.****************************************************************************/void X86EMU_setupIntrFuncs( X86EMU_intrFuncs funcs[]){ int i; for (i=0; i < 256; i++) _X86EMU_intrTab[i] = NULL; if (funcs) { for (i = 0; i < 256; i++) _X86EMU_intrTab[i] = funcs[i]; }}/****************************************************************************PARAMETERS:int - New software interrupt to prepare forREMARKS:This function is used to set up the emulator state to exceute a softwareinterrupt. This can be used by the user application code to allow aninterrupt to be hooked, examined and then reflected back to the emulatorso that the code in the emulator will continue processing the softwareinterrupt as per normal. This essentially allows system code to activelyhook and handle certain software interrupts as necessary.****************************************************************************/void X86EMU_prepareForInt( int num){ push_word((u16)M.x86.R_FLG); CLEAR_FLAG(F_IF); CLEAR_FLAG(F_TF); push_word(M.x86.R_CS); M.x86.R_CS = mem_access_word(num * 4 + 2); push_word(M.x86.R_IP); M.x86.R_IP = mem_access_word(num * 4); M.x86.intr = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -