--- np2/i386c/memory.c 2005/03/18 06:49:17 1.34 +++ np2/i386c/memory.c 2012/01/23 10:23:54 1.37 @@ -173,7 +173,7 @@ static const VACCTBL vacctbl[0x10] = { {memegc_rd8, memegc_wr8, memegc_rd16, memegc_wr16}}; -void MEMCALL i286_memorymap(UINT type) { +void MEMCALL memm_arch(UINT type) { const MMAPTBL *mm; @@ -194,7 +194,7 @@ const MMAPTBL *mm; memfn0.wr16[0xf8000 >> 15] = mm->bwr16; } -void MEMCALL i286_vram_dispatch(UINT func) { +void MEMCALL memm_vram(UINT func) { const VACCTBL *vacc; @@ -317,7 +317,7 @@ static const MEMFNF memfnf = { // ---- -REG8 MEMCALL i286_memoryread(UINT32 address) { +REG8 MEMCALL memp_read8(UINT32 address) { if (address < I286_MEMREADMAX) { return(mem[address]); @@ -353,7 +353,7 @@ REG8 MEMCALL i286_memoryread(UINT32 addr } } -REG16 MEMCALL i286_memoryread_w(UINT32 address) { +REG16 MEMCALL memp_read16(UINT32 address) { REG16 ret; @@ -390,13 +390,13 @@ REG16 MEMCALL i286_memoryread_w(UINT32 a } } else { - ret = i286_memoryread(address + 0); - ret += (REG16)(i286_memoryread(address + 1) << 8); + ret = memp_read8(address + 0); + ret += (REG16)(memp_read8(address + 1) << 8); return(ret); } } -UINT32 MEMCALL i286_memoryread_d(UINT32 address) { +UINT32 MEMCALL memp_read32(UINT32 address) { UINT32 pos; UINT32 ret; @@ -411,18 +411,18 @@ UINT32 MEMCALL i286_memoryread_d(UINT32 } } if (!(address & 1)) { - ret = i286_memoryread_w(address + 0); - ret += (UINT32)i286_memoryread_w(address + 2) << 16; + ret = memp_read16(address + 0); + ret += (UINT32)memp_read16(address + 2) << 16; } else { - ret = i286_memoryread(address + 0); - ret += (UINT32)i286_memoryread_w(address + 1) << 8; - ret += (UINT32)i286_memoryread(address + 3) << 24; + ret = memp_read8(address + 0); + ret += (UINT32)memp_read16(address + 1) << 8; + ret += (UINT32)memp_read8(address + 3) << 24; } return(ret); } -void MEMCALL i286_memorywrite(UINT32 address, REG8 value) { +void MEMCALL memp_write8(UINT32 address, REG8 value) { if (address < I286_MEMWRITEMAX) { mem[address] = (UINT8)value; @@ -456,7 +456,7 @@ void MEMCALL i286_memorywrite(UINT32 add } } -void MEMCALL i286_memorywrite_w(UINT32 address, REG16 value) { +void MEMCALL memp_write16(UINT32 address, REG16 value) { if (address < (I286_MEMWRITEMAX - 1)) { STOREINTELWORD(mem + address, value); @@ -489,12 +489,12 @@ void MEMCALL i286_memorywrite_w(UINT32 a } } else { - i286_memorywrite(address + 0, (UINT8)value); - i286_memorywrite(address + 1, (UINT8)(value >> 8)); + memp_write8(address + 0, (UINT8)value); + memp_write8(address + 1, (UINT8)(value >> 8)); } } -void MEMCALL i286_memorywrite_d(UINT32 address, UINT32 value) { +void MEMCALL memp_write32(UINT32 address, UINT32 value) { UINT32 pos; @@ -510,18 +510,18 @@ void MEMCALL i286_memorywrite_d(UINT32 a } } if (!(address & 1)) { - i286_memorywrite_w(address + 0, (UINT16)value); - i286_memorywrite_w(address + 2, (UINT16)(value >> 16)); + memp_write16(address + 0, (UINT16)value); + memp_write16(address + 2, (UINT16)(value >> 16)); } else { - i286_memorywrite(address + 0, (UINT8)value); - i286_memorywrite_w(address + 1, (UINT16)(value >> 8)); - i286_memorywrite(address + 3, (UINT8)(value >> 24)); + memp_write8(address + 0, (UINT8)value); + memp_write16(address + 1, (UINT16)(value >> 8)); + memp_write8(address + 3, (UINT8)(value >> 24)); } } -void MEMCALL memp_read(UINT32 address, void *dat, UINT leng) { +void MEMCALL memp_reads(UINT32 address, void *dat, UINT leng) { UINT8 *out = (UINT8 *)dat; UINT diff; @@ -546,13 +546,13 @@ void MEMCALL memp_read(UINT32 address, v /* slow memory access */ while (leng-- > 0) { - *out++ = i286_memoryread(address++); + *out++ = memp_read8(address++); } } -void MEMCALL memp_write(UINT32 address, const void *dat, UINT leng) { +void MEMCALL memp_writes(UINT32 address, const void *dat, UINT leng) { - const UINT8 *out = (UINT8 *)dat; + const UINT8 *out = dat; UINT diff; /* fast memory access */ @@ -575,182 +575,176 @@ void MEMCALL memp_write(UINT32 address, /* slow memory access */ while (leng-- > 0) { - i286_memorywrite(address++, *out++); + memp_write8(address++, *out++); } } // ---- Logical Space (BIOS) -static UINT32 physicaladdr(UINT32 addr, BOOL wr) { +void MEMCALL meml_reads(UINT32 address, void *dat, UINT leng) { - UINT32 a; - UINT32 pde; - UINT32 pte; - - a = CPU_STAT_PDE_BASE + ((addr >> 20) & 0xffc); - pde = i286_memoryread_d(a); - if (!(pde & CPU_PDE_PRESENT)) { - goto retdummy; + if (!CPU_STAT_PM) { + memp_reads(address, dat, leng); } - if (!(pde & CPU_PDE_ACCESS)) { - i286_memorywrite(a, (UINT8)(pde | CPU_PDE_ACCESS)); + else if (CPU_STAT_VM86) { + cpu_memory_access_la_region(address, leng, + CPU_PAGE_READ_DATA | CPU_PAGE_USER_MODE, dat); } - a = (pde & CPU_PDE_BASEADDR_MASK) + ((addr >> 10) & 0xffc); - pte = cpu_memoryread_d(a); - if (!(pte & CPU_PTE_PRESENT)) { - goto retdummy; + else { + ia32_panic("%s: call from BIOS, but protected mode", __func__); } - if (!(pte & CPU_PTE_ACCESS)) { - i286_memorywrite(a, (UINT8)(pte | CPU_PTE_ACCESS)); +} + +void MEMCALL meml_writes(UINT32 address, const void *dat, UINT leng) { + + if (!CPU_STAT_PM) { + memp_writes(address, dat, leng); } - if ((wr) && (!(pte & CPU_PTE_DIRTY))) { - i286_memorywrite(a, (UINT8)(pte | CPU_PTE_DIRTY)); + else if (CPU_STAT_VM86) { + cpu_memory_access_la_region(address, leng, + CPU_PAGE_WRITE_DATA | CPU_PAGE_USER_MODE, (UINT8 *)dat); + } + else { + ia32_panic("%s: call from BIOS, but protected mode", __func__); } - addr = (pte & CPU_PTE_BASEADDR_MASK) + (addr & 0x00000fff); - return(addr); - -retdummy: - return(0x01000000); // てきとーにメモリが存在しない場所 } -REG8 MEMCALL meml_read8(UINT seg, UINT off) { +REG8 MEMCALL memr_read8(UINT seg, UINT off) { UINT32 addr; addr = (seg << 4) + LOW16(off); - if (CPU_STAT_PAGING) { - addr = physicaladdr(addr, FALSE); + if (!CPU_STAT_PM) { + return(memp_read8(addr)); + } + else if (CPU_STAT_VM86) { + return(cpu_linear_memory_read_b(addr, + CPU_PAGE_READ_DATA | CPU_PAGE_USER_MODE)); + } + else { + ia32_panic("%s: call from BIOS, but protected mode", __func__); + return(0xff); } - return(i286_memoryread(addr)); } -REG16 MEMCALL meml_read16(UINT seg, UINT off) { +REG16 MEMCALL memr_read16(UINT seg, UINT off) { UINT32 addr; addr = (seg << 4) + LOW16(off); - if (!CPU_STAT_PAGING) { - return(i286_memoryread_w(addr)); + if (!CPU_STAT_PM) { + return(memp_read16(addr)); + } + else if (CPU_STAT_VM86) { + return(cpu_linear_memory_read_w(addr, + CPU_PAGE_READ_DATA | CPU_PAGE_USER_MODE)); } - else if ((addr + 1) & 0xfff) { - return(i286_memoryread_w(physicaladdr(addr, FALSE))); + else { + ia32_panic("%s: call from BIOS, but protected mode", __func__); + return(0xffff); } - return(meml_read8(seg, off) + (meml_read8(seg, off + 1) << 8)); } -void MEMCALL meml_write8(UINT seg, UINT off, REG8 dat) { +void MEMCALL memr_write8(UINT seg, UINT off, REG8 dat) { UINT32 addr; addr = (seg << 4) + LOW16(off); - if (CPU_STAT_PAGING) { - addr = physicaladdr(addr, TRUE); + if (!CPU_STAT_PM) { + memp_write8(addr, dat); + } + else if (CPU_STAT_VM86) { + cpu_linear_memory_write_b(addr, dat, + CPU_PAGE_WRITE_DATA | CPU_PAGE_USER_MODE); + } + else { + ia32_panic("%s: call from BIOS, but protected mode", __func__); } - i286_memorywrite(addr, dat); } -void MEMCALL meml_write16(UINT seg, UINT off, REG16 dat) { +void MEMCALL memr_write16(UINT seg, UINT off, REG16 dat) { UINT32 addr; addr = (seg << 4) + LOW16(off); - if (!CPU_STAT_PAGING) { - i286_memorywrite_w(addr, dat); + if (!CPU_STAT_PM) { + memp_write16(addr, dat); } - else if ((addr + 1) & 0xfff) { - i286_memorywrite_w(physicaladdr(addr, TRUE), dat); + else if (CPU_STAT_VM86) { + cpu_linear_memory_write_w(addr, dat, + CPU_PAGE_WRITE_DATA | CPU_PAGE_USER_MODE); } else { - meml_write8(seg, off, (REG8)dat); - meml_write8(seg, off + 1, (REG8)(dat >> 8)); + ia32_panic("%s: call from BIOS, but protected mode", __func__); } } -void MEMCALL meml_readstr(UINT seg, UINT off, void *dat, UINT leng) { +void MEMCALL memr_reads(UINT seg, UINT off, void *dat, UINT leng) { + UINT8 *in = dat; UINT32 addr; UINT rem; UINT size; + if (CPU_STAT_PM && !CPU_STAT_VM86) { + ia32_panic("%s: call from BIOS, but protected mode", __func__); + return; + } + while(leng) { off = LOW16(off); addr = (seg << 4) + off; rem = 0x10000 - off; size = min(leng, rem); - if (CPU_STAT_PAGING) { - rem = 0x1000 - (addr & 0xfff); + if (!CPU_STAT_PM) { + memp_reads(addr, in, size); + } + else { + /* VM86 */ + rem = CPU_PAGE_SIZE - (addr & CPU_PAGE_MASK); size = min(size, rem); - addr = physicaladdr(addr, FALSE); + cpu_memory_access_la_region(addr, size, + CPU_PAGE_READ_DATA | CPU_PAGE_USER_MODE, in); } - memp_read(addr, dat, size); off += size; - dat = ((UINT8 *)dat) + size; + in += size; leng -= size; } } -void MEMCALL meml_writestr(UINT seg, UINT off, const void *dat, UINT leng) { +void MEMCALL memr_writes(UINT seg, UINT off, const void *dat, UINT leng) { - UINT32 addr; - UINT rem; - UINT size; + const UINT8 *out = dat; + UINT32 addr; + UINT rem; + UINT size; + + if (CPU_STAT_PM && !CPU_STAT_VM86) { + ia32_panic("%s: call from BIOS, but protected mode", __func__); + return; + } while(leng) { off = LOW16(off); addr = (seg << 4) + off; rem = 0x10000 - off; size = min(leng, rem); - if (CPU_STAT_PAGING) { + if (!CPU_STAT_PM) { + memp_writes(addr, out, size); + } + else { + /* VM86 */ rem = 0x1000 - (addr & 0xfff); size = min(size, rem); - addr = physicaladdr(addr, TRUE); + cpu_memory_access_la_region(addr, size, + CPU_PAGE_WRITE_DATA | CPU_PAGE_USER_MODE, (UINT8 *)out); } - memp_write(addr, dat, size); off += size; - dat = ((UINT8 *)dat) + size; + out += size; leng -= size; } } -void MEMCALL meml_read(UINT32 address, void *dat, UINT leng) { - - UINT size; - - if (!CPU_STAT_PAGING) { - memp_read(address, dat, leng); - } - else { - while(leng) { - size = 0x1000 - (address & 0xfff); - size = min(size, leng); - memp_read(physicaladdr(address, FALSE), dat, size); - address += size; - dat = ((UINT8 *)dat) + size; - leng -= size; - } - } -} - -void MEMCALL meml_write(UINT32 address, const void *dat, UINT leng) { - - UINT size; - - if (!CPU_STAT_PAGING) { - memp_write(address, dat, leng); - } - else { - while(leng) { - size = 0x1000 - (address & 0xfff); - size = min(size, leng); - memp_write(physicaladdr(address, TRUE), dat, size); - address += size; - dat = ((UINT8 *)dat) + size; - leng -= size; - } - } -} - #endif -