//#include "compiler.h"
+
#if 1
#undef TRACEOUT
#define USE_TRACEOUT_VS
#include "i386hax/haxfunc.h"
#include "i386hax/haxcore.h"
#endif
+#include "./cpumem.h"
DEVICE *device_cpu = NULL;
DEVICE *device_mem = NULL;
UINT32 __exception_pc;
UINT64 __exception_code;
// ----
-REG8 MEMCALL memp_read8(UINT32 address) {
-
- address = address & CPU_ADRSMASK;
- int wait = 0;
- REG8 val;
- val = device_mem->read_data8w(address, &wait);
- i386_memory_wait += wait;
- return val;
-}
-
-REG16 MEMCALL memp_read16(UINT32 address) {
-
- address = address & CPU_ADRSMASK;
- int wait = 0;
- REG16 val;
- val = device_mem->read_data16w(address, &wait);
- i386_memory_wait += wait;
- return val;
-// return device_mem->read_data16(address);
-}
-
-UINT32 MEMCALL memp_read32(UINT32 address) {
- address = address & CPU_ADRSMASK;
- int wait = 0;
- UINT32 val;
- val = device_mem->read_data32w(address, &wait);
- i386_memory_wait += wait;
- return val;
-// return device_mem->read_data32(address);
-}
-
-// ----
-REG8 MEMCALL memp_read8_codefetch(UINT32 address) {
-
- address = address & CPU_ADRSMASK;
- int wait = 0;
- REG8 val;
- if(device_debugger != NULL) {
- codefetch_address = address & CPU_ADRSMASK;
- val = device_mem->read_data8w(codefetch_address, &wait);
- } else {
- val = device_mem->read_data8w(address, &wait);
- }
- i386_memory_wait += wait;
- return val;
-// return device_mem->read_data8(address);
-}
-
-REG16 MEMCALL memp_read16_codefetch(UINT32 address) {
-
- address = address & CPU_ADRSMASK;
- int wait = 0;
- REG16 val;
- if(device_debugger != NULL) {
- codefetch_address = address & CPU_ADRSMASK;
- val = device_mem->read_data16w(codefetch_address, &wait);
- } else {
- val = device_mem->read_data16w(address, &wait);
- }
- i386_memory_wait += wait;
- return val;
-// return device_mem->read_data16(address);
-}
-
-UINT32 MEMCALL memp_read32_codefetch(UINT32 address) {
-
- address = address & CPU_ADRSMASK;
- int wait = 0;
- UINT32 val;
- if(device_debugger != NULL) {
- codefetch_address = address & CPU_ADRSMASK;
- val = device_mem->read_data32w(codefetch_address, &wait);
- } else {
- val = device_mem->read_data32w(address, &wait);
- }
- i386_memory_wait += wait;
- return val;
-// return device_mem->read_data32(address);
-}
-
-// ----
-REG8 MEMCALL memp_read8_paging(UINT32 address) {
-
- return memp_read8_codefetch(address);
-}
-REG16 MEMCALL memp_read16_paging(UINT32 address) {
-
- return memp_read16_codefetch(address);
-}
-
-UINT32 MEMCALL memp_read32_paging(UINT32 address) {
-
- return memp_read32_codefetch(address);
-}
-
-void MEMCALL memp_write8(UINT32 address, REG8 value) {
-
- address = address & CPU_ADRSMASK;
- int wait = 0;
- device_mem->write_data8w(address, value, &wait);
- i386_memory_wait += wait;
-}
-
-void MEMCALL memp_write16(UINT32 address, REG16 value) {
-
- address = address & CPU_ADRSMASK;
- int wait = 0;
- device_mem->write_data16w(address, value, &wait);
- i386_memory_wait += wait;
-// device_mem->write_data16(address, value);
-}
-
-void MEMCALL memp_write32(UINT32 address, UINT32 value) {
-
- address = address & CPU_ADRSMASK;
- int wait = 0;
- device_mem->write_data32w(address, value, &wait);
- i386_memory_wait += wait;
-// device_mem->write_data32(address, value);
-}
-
-void MEMCALL memp_write8_paging(UINT32 address, REG8 value) {
-
- address = address & CPU_ADRSMASK;
- int wait = 0;
- device_mem->write_data8w(address, value, &wait);
- i386_memory_wait += wait;
-// device_mem->write_data8(address, value);
-}
-
-void MEMCALL memp_write16_paging(UINT32 address, REG16 value) {
-
- address = address & CPU_ADRSMASK;
- int wait = 0;
- device_mem->write_data16w(address, value, &wait);
- i386_memory_wait += wait;
-// device_mem->write_data16(address, value);
-}
-
-void MEMCALL memp_write32_paging(UINT32 address, UINT32 value) {
-
- address = address & CPU_ADRSMASK;
-// device_mem->write_data32(address, value);
- int wait = 0;
- device_mem->write_data32w(address, value, &wait);
- i386_memory_wait += wait;
-}
-
-
-void MEMCALL memp_reads(UINT32 address, void *dat, UINT leng) {
-
- UINT8 *out = (UINT8 *)dat;
-
- //address = address & CPU_ADRSMASK;
-
- /* slow memory access */
- while (leng-- > 0) {
- *out++ = memp_read8(address++);
- }
-}
-
-void MEMCALL memp_writes(UINT32 address, const void *dat, UINT leng) {
-
- const UINT8 *out = (UINT8 *)dat;
-
- //address = address & CPU_ADRSMASK;
-
- /* slow memory access */
- while (leng-- > 0) {
- memp_write8(address++, *out++);
- }
-}
-
// ---- Logical Space (BIOS)
-
-static UINT32 MEMCALL physicaladdr(UINT32 addr, BOOL wr) {
+#if 1
+static inline UINT32 MEMCALL physicaladdr(UINT32 addr, BOOL wr) {
UINT32 a;
UINT32 pde;
}
}
-void IOOUTCALL iocore_out8(UINT port, REG8 dat)
-{
- int wait = 0;
- device_io->write_io8w(port, dat, &wait);
- i386_memory_wait += wait;
-}
-
-REG8 IOINPCALL iocore_inp8(UINT port)
-{
- int wait = 0;
- REG8 val = device_io->read_io8w(port, &wait);
- i386_memory_wait += wait;
- return val;
-}
-
-void IOOUTCALL iocore_out16(UINT port, REG16 dat)
-{
- int wait = 0;
- device_io->write_io16w(port, dat, &wait);
- i386_memory_wait += wait;
-// device_io->write_io16(port, dat);
-}
-
-REG16 IOINPCALL iocore_inp16(UINT port)
-{
- int wait = 0;
- REG16 val = device_io->read_io16w(port, &wait);
- i386_memory_wait += wait;
- return val;
-// return device_io->read_io16(port);
-}
-
-void IOOUTCALL iocore_out32(UINT port, UINT32 dat)
-{
- int wait = 0;
- device_io->write_io32w(port, dat, &wait);
- i386_memory_wait += wait;
-// device_io->write_io32(port, dat);
-}
-
-UINT32 IOINPCALL iocore_inp32(UINT port)
-{
- int wait = 0;
- UINT32 val = device_io->read_io32w(port, &wait);
- i386_memory_wait += wait;
- return val;
-// return device_io->read_io32(port);
-}
-
-void dmax86(void)
-{
-//#ifdef SINGLE_MODE_DMA
- if(device_dma != NULL) device_dma->do_dma();
-//#endif
-}
-
+#endif
#endif
#ifndef NP2_I386C_CPUMEM_H__
#define NP2_I386C_CPUMEM_H__
+#include "cpucore.h"
+#if defined(SUPPORT_IA32_HAXM)
+#include "i386hax/haxfunc.h"
+#include "i386hax/haxcore.h"
+#endif
#ifdef NP2_MEMORY_ASM // \83A\83Z\83\93\83u\83\89\94Å\82Í \95K\82¸fastcall\82Å
#undef MEMCALL
//#ifdef __cplusplus
//extern "C" {
//#endif
+#include "../../common.h"
+#include "../device.h"
-REG8 MEMCALL memp_read8(UINT32 address);
-REG16 MEMCALL memp_read16(UINT32 address);
-UINT32 MEMCALL memp_read32(UINT32 address);
-void MEMCALL memp_write8(UINT32 address, REG8 value);
-void MEMCALL memp_write16(UINT32 address, REG16 value);
-void MEMCALL memp_write32(UINT32 address, UINT32 value);
-void MEMCALL memp_reads(UINT32 address, void *dat, UINT leng);
-void MEMCALL memp_writes(UINT32 address, const void *dat, UINT leng);
-REG8 MEMCALL memp_read8_codefetch(UINT32 address);
-REG16 MEMCALL memp_read16_codefetch(UINT32 address);
-UINT32 MEMCALL memp_read32_codefetch(UINT32 address);
-REG8 MEMCALL memp_read8_paging(UINT32 address);
-REG16 MEMCALL memp_read16_paging(UINT32 address);
-UINT32 MEMCALL memp_read32_paging(UINT32 address);
-void MEMCALL memp_write8_paging(UINT32 address, REG8 value);
-void MEMCALL memp_write16_paging(UINT32 address, REG16 value);
-void MEMCALL memp_write32_paging(UINT32 address, UINT32 value);
+extern DEVICE *device_cpu;
+extern DEVICE *device_mem;
+extern DEVICE *device_io;
+//#ifdef I386_PSEUDO_BIOS
+extern DEVICE *device_bios;
+//#endif
+//#ifdef SINGLE_MODE_DMA
+extern DEVICE *device_dma;
+//#endif
+extern SINT64 i386_memory_wait;
+extern DEBUGGER *device_debugger;
+extern UINT32 codefetch_address;
+extern SINT32 __exception_set;
+extern UINT32 __exception_pc;
+extern UINT64 __exception_code;
+
+inline REG8 MEMCALL memp_read8(UINT32 address);
+inline REG16 MEMCALL memp_read16(UINT32 address);
+inline UINT32 MEMCALL memp_read32(UINT32 address);
+inline void MEMCALL memp_write8(UINT32 address, REG8 value);
+inline void MEMCALL memp_write16(UINT32 address, REG16 value);
+inline void MEMCALL memp_write32(UINT32 address, UINT32 value);
+inline void MEMCALL memp_reads(UINT32 address, void *dat, UINT leng);
+inline void MEMCALL memp_writes(UINT32 address, const void *dat, UINT leng);
+inline REG8 MEMCALL memp_read8_codefetch(UINT32 address);
+inline REG16 MEMCALL memp_read16_codefetch(UINT32 address);
+inline UINT32 MEMCALL memp_read32_codefetch(UINT32 address);
+inline REG8 MEMCALL memp_read8_paging(UINT32 address);
+inline REG16 MEMCALL memp_read16_paging(UINT32 address);
+inline UINT32 MEMCALL memp_read32_paging(UINT32 address);
+inline void MEMCALL memp_write8_paging(UINT32 address, REG8 value);
+inline void MEMCALL memp_write16_paging(UINT32 address, REG16 value);
+inline void MEMCALL memp_write32_paging(UINT32 address, UINT32 value);
REG8 MEMCALL meml_read8(UINT32 address);
REG16 MEMCALL meml_read16(UINT32 address);
void MEMCALL memr_reads(UINT seg, UINT off, void *dat, UINT leng);
void MEMCALL memr_writes(UINT seg, UINT off, const void *dat, UINT leng);
-void IOOUTCALL iocore_out8(UINT port, REG8 dat);
-REG8 IOINPCALL iocore_inp8(UINT port);
+inline void IOOUTCALL iocore_out8(UINT port, REG8 dat);
+inline REG8 IOINPCALL iocore_inp8(UINT port);
-void IOOUTCALL iocore_out16(UINT port, REG16 dat);
-REG16 IOINPCALL iocore_inp16(UINT port);
+inline void IOOUTCALL iocore_out16(UINT port, REG16 dat);
+inline REG16 IOINPCALL iocore_inp16(UINT port);
-void IOOUTCALL iocore_out32(UINT port, UINT32 dat);
-UINT32 IOINPCALL iocore_inp32(UINT port);
+inline void IOOUTCALL iocore_out32(UINT port, UINT32 dat);
+inline UINT32 IOINPCALL iocore_inp32(UINT port);
-void dmax86(void);
+inline void dmax86(void);
//#ifdef __cplusplus
//}
#define MEMR_WRITES(seg, off, dat, leng) \
memr_writes((seg), (off), (dat), (leng))
+inline REG8 MEMCALL memp_read8(UINT32 address) {
+
+ address = address & CPU_ADRSMASK;
+ int wait = 0;
+ REG8 val;
+ val = device_mem->read_data8w(address, &wait);
+ i386_memory_wait += wait;
+ return val;
+}
+
+inline REG16 MEMCALL memp_read16(UINT32 address) {
+
+ address = address & CPU_ADRSMASK;
+ int wait = 0;
+ REG16 val;
+ val = device_mem->read_data16w(address, &wait);
+ i386_memory_wait += wait;
+ return val;
+// return device_mem->read_data16(address);
+}
+
+inline UINT32 MEMCALL memp_read32(UINT32 address) {
+ address = address & CPU_ADRSMASK;
+ int wait = 0;
+ UINT32 val;
+ val = device_mem->read_data32w(address, &wait);
+ i386_memory_wait += wait;
+ return val;
+// return device_mem->read_data32(address);
+}
+
+// ----
+inline REG8 MEMCALL memp_read8_codefetch(UINT32 address) {
+
+ address = address & CPU_ADRSMASK;
+ int wait = 0;
+ REG8 val;
+ if(device_debugger != NULL) {
+ codefetch_address = address & CPU_ADRSMASK;
+ val = device_mem->read_data8w(codefetch_address, &wait);
+ } else {
+ val = device_mem->read_data8w(address, &wait);
+ }
+ i386_memory_wait += wait;
+ return val;
+// return device_mem->read_data8(address);
+}
+
+inline REG16 MEMCALL memp_read16_codefetch(UINT32 address) {
+
+ address = address & CPU_ADRSMASK;
+ int wait = 0;
+ REG16 val;
+ if(device_debugger != NULL) {
+ codefetch_address = address & CPU_ADRSMASK;
+ val = device_mem->read_data16w(codefetch_address, &wait);
+ } else {
+ val = device_mem->read_data16w(address, &wait);
+ }
+ i386_memory_wait += wait;
+ return val;
+// return device_mem->read_data16(address);
+}
+
+inline UINT32 MEMCALL memp_read32_codefetch(UINT32 address) {
+
+ address = address & CPU_ADRSMASK;
+ int wait = 0;
+ UINT32 val;
+ if(device_debugger != NULL) {
+ codefetch_address = address & CPU_ADRSMASK;
+ val = device_mem->read_data32w(codefetch_address, &wait);
+ } else {
+ val = device_mem->read_data32w(address, &wait);
+ }
+ i386_memory_wait += wait;
+ return val;
+// return device_mem->read_data32(address);
+}
+
+// ----
+inline REG8 MEMCALL memp_read8_paging(UINT32 address) {
+
+ return memp_read8_codefetch(address);
+}
+inline REG16 MEMCALL memp_read16_paging(UINT32 address) {
+
+ return memp_read16_codefetch(address);
+}
+
+inline UINT32 MEMCALL memp_read32_paging(UINT32 address) {
+
+ return memp_read32_codefetch(address);
+}
+
+inline void MEMCALL memp_write8(UINT32 address, REG8 value) {
+
+ address = address & CPU_ADRSMASK;
+ int wait = 0;
+ device_mem->write_data8w(address, value, &wait);
+ i386_memory_wait += wait;
+}
+
+inline void MEMCALL memp_write16(UINT32 address, REG16 value) {
+
+ address = address & CPU_ADRSMASK;
+ int wait = 0;
+ device_mem->write_data16w(address, value, &wait);
+ i386_memory_wait += wait;
+// device_mem->write_data16(address, value);
+}
+
+inline void MEMCALL memp_write32(UINT32 address, UINT32 value) {
+
+ address = address & CPU_ADRSMASK;
+ int wait = 0;
+ device_mem->write_data32w(address, value, &wait);
+ i386_memory_wait += wait;
+// device_mem->write_data32(address, value);
+}
+
+inline void MEMCALL memp_write8_paging(UINT32 address, REG8 value) {
+
+ address = address & CPU_ADRSMASK;
+ int wait = 0;
+ device_mem->write_data8w(address, value, &wait);
+ i386_memory_wait += wait;
+// device_mem->write_data8(address, value);
+}
+
+inline void MEMCALL memp_write16_paging(UINT32 address, REG16 value) {
+
+ address = address & CPU_ADRSMASK;
+ int wait = 0;
+ device_mem->write_data16w(address, value, &wait);
+ i386_memory_wait += wait;
+// device_mem->write_data16(address, value);
+}
+
+inline void MEMCALL memp_write32_paging(UINT32 address, UINT32 value) {
+
+ address = address & CPU_ADRSMASK;
+// device_mem->write_data32(address, value);
+ int wait = 0;
+ device_mem->write_data32w(address, value, &wait);
+ i386_memory_wait += wait;
+}
+
+
+inline void MEMCALL memp_reads(UINT32 address, void *dat, UINT leng) {
+
+ UINT8 *out = (UINT8 *)dat;
+
+ //address = address & CPU_ADRSMASK;
+
+ /* slow memory access */
+ while (leng-- > 0) {
+ *out++ = memp_read8(address++);
+ }
+}
+
+inline void MEMCALL memp_writes(UINT32 address, const void *dat, UINT leng) {
+
+ const UINT8 *out = (UINT8 *)dat;
+
+ //address = address & CPU_ADRSMASK;
+
+ /* slow memory access */
+ while (leng-- > 0) {
+ memp_write8(address++, *out++);
+ }
+}
+
+inline void dmax86(void)
+{
+//#ifdef SINGLE_MODE_DMA
+ if(device_dma != NULL) device_dma->do_dma();
+//#endif
+}
+
+inline void IOOUTCALL iocore_out8(UINT port, REG8 dat)
+{
+ int wait = 0;
+ device_io->write_io8w(port, dat, &wait);
+ i386_memory_wait += wait;
+}
+
+inline REG8 IOINPCALL iocore_inp8(UINT port)
+{
+ int wait = 0;
+ REG8 val = device_io->read_io8w(port, &wait);
+ i386_memory_wait += wait;
+ return val;
+}
+
+inline void IOOUTCALL iocore_out16(UINT port, REG16 dat)
+{
+ int wait = 0;
+ device_io->write_io16w(port, dat, &wait);
+ i386_memory_wait += wait;
+// device_io->write_io16(port, dat);
+}
+
+inline REG16 IOINPCALL iocore_inp16(UINT port)
+{
+ int wait = 0;
+ REG16 val = device_io->read_io16w(port, &wait);
+ i386_memory_wait += wait;
+ return val;
+// return device_io->read_io16(port);
+}
+
+inline void IOOUTCALL iocore_out32(UINT port, UINT32 dat)
+{
+ int wait = 0;
+ device_io->write_io32w(port, dat, &wait);
+ i386_memory_wait += wait;
+// device_io->write_io32(port, dat);
+}
+
+inline UINT32 IOINPCALL iocore_inp32(UINT port)
+{
+ int wait = 0;
+ UINT32 val = device_io->read_io32w(port, &wait);
+ i386_memory_wait += wait;
+ return val;
+// return device_io->read_io32(port);
+}
+
#endif /* !NP2_I386C_CPUMEM_H__ */
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-//#include "compiler.h"
#include "cpu.h"
#include "../cpumem.h"
}
-/*
- * code fetch
- */
-UINT8 MEMCALL
-cpu_codefetch(UINT32 offset)
-{
- const int ucrw = CPU_PAGE_READ_CODE | CPU_STAT_USER_MODE;
- descriptor_t *sdp;
- UINT32 addr;
-
- sdp = &CPU_CS_DESC;
- addr = sdp->u.seg.segbase + offset;
-
- if (!CPU_STAT_PM)
- return cpu_memoryread_codefetch(addr);
- if (offset <= sdp->u.seg.limit)
- return cpu_lmemoryread_codefetch(addr, ucrw);
-
- EXCEPTION(GP_EXCEPTION, 0);
- return 0; /* compiler happy */
-}
-
-UINT16 MEMCALL
-cpu_codefetch_w(UINT32 offset)
-{
- const int ucrw = CPU_PAGE_READ_CODE | CPU_STAT_USER_MODE;
- descriptor_t *sdp;
- UINT32 addr;
-
- sdp = &CPU_CS_DESC;
- addr = sdp->u.seg.segbase + offset;
-
- if (!CPU_STAT_PM)
- return cpu_memoryread_w_codefetch(addr);
- if (offset <= sdp->u.seg.limit - 1)
- return cpu_lmemoryread_w_codefetch(addr, ucrw);
-
- EXCEPTION(GP_EXCEPTION, 0);
- return 0; /* compiler happy */
-}
-
-UINT32 MEMCALL
-cpu_codefetch_d(UINT32 offset)
-{
- const int ucrw = CPU_PAGE_READ_CODE | CPU_STAT_USER_MODE;
- descriptor_t *sdp;
- UINT32 addr;
-
- sdp = &CPU_CS_DESC;
- addr = sdp->u.seg.segbase + offset;
-
- if (!CPU_STAT_PM)
- return cpu_memoryread_d_codefetch(addr);
-
- if (offset <= sdp->u.seg.limit - 3)
- return cpu_lmemoryread_d_codefetch(addr, ucrw);
-
- EXCEPTION(GP_EXCEPTION, 0);
- return 0; /* compiler happy */
-}
/*
* additional physical address memory access functions
err:
EXCEPTION(exc, 0);
}
+
+/*
+ * code fetch
+ */
+UINT8 MEMCALL
+cpu_codefetch(UINT32 offset)
+{
+ const int ucrw = CPU_PAGE_READ_CODE | CPU_STAT_USER_MODE;
+ descriptor_t *sdp;
+ UINT32 addr;
+
+ sdp = &CPU_CS_DESC;
+ addr = sdp->u.seg.segbase + offset;
+
+ if (!CPU_STAT_PM)
+ return cpu_memoryread_codefetch(addr);
+ if (offset <= sdp->u.seg.limit)
+ return cpu_lmemoryread_codefetch(addr, ucrw);
+
+ EXCEPTION(GP_EXCEPTION, 0);
+ return 0; /* compiler happy */
+}
+
+UINT16 MEMCALL
+cpu_codefetch_w(UINT32 offset)
+{
+ const int ucrw = CPU_PAGE_READ_CODE | CPU_STAT_USER_MODE;
+ descriptor_t *sdp;
+ UINT32 addr;
+
+ sdp = &CPU_CS_DESC;
+ addr = sdp->u.seg.segbase + offset;
+
+ if (!CPU_STAT_PM)
+ return cpu_memoryread_w_codefetch(addr);
+ if (offset <= sdp->u.seg.limit - 1)
+ return cpu_lmemoryread_w_codefetch(addr, ucrw);
+
+ EXCEPTION(GP_EXCEPTION, 0);
+ return 0; /* compiler happy */
+}
+
+UINT32 MEMCALL
+cpu_codefetch_d(UINT32 offset)
+{
+ const int ucrw = CPU_PAGE_READ_CODE | CPU_STAT_USER_MODE;
+ descriptor_t *sdp;
+ UINT32 addr;
+
+ sdp = &CPU_CS_DESC;
+ addr = sdp->u.seg.segbase + offset;
+
+ if (!CPU_STAT_PM)
+ return cpu_memoryread_d_codefetch(addr);
+
+ if (offset <= sdp->u.seg.limit - 3)
+ return cpu_lmemoryread_d_codefetch(addr, ucrw);
+
+ EXCEPTION(GP_EXCEPTION, 0);
+ return 0; /* compiler happy */
+}