--- np2/i286x/i286x.cpp 2003/10/17 07:17:20 1.2 +++ np2/i286x/i286x.cpp 2004/01/25 07:53:08 1.17 @@ -1,11 +1,10 @@ #include "compiler.h" -#include "i286.h" +#include "cpucore.h" #include "i286x.h" #include "i286xadr.h" #include "i286xs.h" #include "i286xrep.h" #include "i286xcts.h" -#include "memory.h" #include "pccore.h" #include "iocore.h" #include "i286x.mcr" @@ -15,7 +14,7 @@ #include "dmap.h" - I286REG i286reg; + I286CORE i286core; const BYTE iflags[256] = { // Z_FLAG, S_FLAG, P_FLAG 0x44, 0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x00, @@ -52,29 +51,94 @@ const BYTE iflags[256] = { // Z_FLAG 0x80, 0x84, 0x84, 0x80, 0x84, 0x80, 0x80, 0x84}; -void i286_reset(void) { +void i286x_initialize(void) { - i286xadr_init(); // 毎回通すのはどうか… - v30init(); // 毎回通すのはどうか… - ZeroMemory(&i286reg, sizeof(i286reg)); - I286_CS = 0x1fc0; - CS_BASE = 0x1fc00; + i286xadr_init(); + v30xinit(); } +void i286x_deinitialize(void) { -LABEL void i286_resetprefetch(void) { + if (CPU_EXTMEM) { + _MFREE(CPU_EXTMEM); + CPU_EXTMEM = NULL; + CPU_EXTMEMSIZE = 0; + } +} + +static void i286x_initreg(void) { + + I286_CS = 0xf000; + CS_BASE = 0xf0000; + I286_IP = 0xfff0; + i286core.s.adrsmask = 0xfffff; + i286x_resetprefetch(); +} + +void i286x_reset(void) { + + ZeroMemory(&i286core.s, sizeof(i286core.s)); + i286x_initreg(); +} + +void i286x_shut(void) { + + ZeroMemory(&i286core.s, offsetof(I286STAT, cpu_type)); + i286x_initreg(); +} + +void i286x_setextsize(UINT32 size) { + + if (CPU_EXTMEMSIZE != size) { + if (CPU_EXTMEM) { + _MFREE(CPU_EXTMEM); + CPU_EXTMEM = NULL; + } + if (size) { + CPU_EXTMEM = (BYTE *)_MALLOC(size + 16, "EXTMEM"); + if (CPU_EXTMEM == NULL) { + size = 0; + } + } + CPU_EXTMEMSIZE = size; + } + i286core.e.ems[0] = mem + 0xc0000; + i286core.e.ems[1] = mem + 0xc4000; + i286core.e.ems[2] = mem + 0xc8000; + i286core.e.ems[3] = mem + 0xcc000; +} + +void i286x_setemm(UINT frame, UINT32 addr) { + + BYTE *ptr; + + frame &= 3; + if (addr < USE_HIMEM) { + ptr = mem + addr; + } + else if ((addr - 0x100000 + 0x4000) <= CPU_EXTMEMSIZE) { + ptr = CPU_EXTMEM + (addr - 0x100000); + } + else { + ptr = mem + 0xc0000 + (frame << 14); + } + i286core.e.ems[frame] = ptr; +} + + +LABEL void i286x_resetprefetch(void) { __asm { pushad movzx esi, I286_IP RESET_XPREFETCH - mov dword ptr (i286reg.prefetchque), ebx + mov dword ptr (i286core.s.prefetchque), ebx popad ret } } -LABEL void __fastcall i286_interrupt(BYTE vect) { +LABEL void __fastcall i286x_interrupt(BYTE vect) { __asm { pushad @@ -84,7 +148,7 @@ LABEL void __fastcall i286_interrupt(BYT sub bx, 2 // hlt.. - cmp byte ptr (i286reg.prefetchque), 0f4h // hlt + cmp byte ptr (i286core.s.prefetchque), 0f4h // hlt jne short nonhlt inc I286_IP nonhlt: mov edi, SS_BASE @@ -116,7 +180,7 @@ nonhlt: mov edi, SS_BASE shl eax, 4 // make segreg mov CS_BASE, eax RESET_XPREFETCH - mov dword ptr (i286reg.prefetchque), ebx + mov dword ptr (i286core.s.prefetchque), ebx popad ret @@ -163,12 +227,36 @@ LABEL void __fastcall i286x_localint(voi } +// プロテクトモードのセレクタ(in ax / ret eax) +LABEL void __fastcall i286x_selector(void) { + + __asm { + mov ecx, dword ptr (I286_GDTR.base) + test eax, 4 + je short ixsl_1 + mov ecx, dword ptr (I286_LDTRC.base) +ixsl_1: and eax, not 7 + and ecx, 0ffffffh + lea ecx, [ecx + eax + 2] + call i286_memoryread_w + push eax + add ecx, 2 + call i286_memoryread + pop ecx + and eax, 0ffh + movzx ecx, cx + shl eax, 16 + add eax, ecx + ret + } +} + -LABEL void i286(void) { +LABEL void i286x(void) { __asm { pushad - mov ebx, dword ptr (i286reg.prefetchque) + mov ebx, dword ptr (i286core.s.prefetchque) movzx esi, I286_IP cmp I286_TRAP, 0 @@ -178,9 +266,9 @@ LABEL void i286(void) { i286_mnlp: movzx eax, bl call i286op[eax*4] - cmp nevent.remainclock, 0 + cmp I286_REMCLOCK, 0 jg i286_mnlp - mov dword ptr (i286reg.prefetchque), ebx + mov dword ptr (i286core.s.prefetchque), ebx mov I286_IP, si popad ret @@ -189,9 +277,9 @@ i286_mnlp: movzx eax, bl i286_dma_mnlp: movzx eax, bl call i286op[eax*4] call dmap_i286 - cmp nevent.remainclock, 0 + cmp I286_REMCLOCK, 0 jg i286_dma_mnlp - mov dword ptr (i286reg.prefetchque), ebx + mov dword ptr (i286core.s.prefetchque), ebx mov I286_IP, si popad ret @@ -203,7 +291,7 @@ i286_trapping: movzx eax, bl je i286notrap mov ecx, 1 call i286x_localint -i286notrap: mov dword ptr (i286reg.prefetchque), ebx +i286notrap: mov dword ptr (i286core.s.prefetchque), ebx mov I286_IP, si popad ret @@ -212,11 +300,11 @@ i286notrap: mov dword ptr (i286reg.pre -LABEL void i286_step(void) { +LABEL void i286x_step(void) { __asm { pushad - mov ebx, dword ptr (i286reg.prefetchque) + mov ebx, dword ptr (i286core.s.prefetchque) movzx esi, I286_IP movzx eax, bl @@ -227,7 +315,7 @@ LABEL void i286_step(void) { mov ecx, 1 call i286x_localint nexts: - mov dword ptr (i286reg.prefetchque), ebx + mov dword ptr (i286core.s.prefetchque), ebx mov I286_IP, si call dmap_i286 @@ -242,7 +330,7 @@ nexts: LABEL void removeprefix(void) { __asm { - mov i286reg.prefix, 0 + mov i286core.s.prefix, 0 mov eax, DS_BASE mov DS_FIX, eax mov eax, SS_BASE @@ -359,11 +447,16 @@ I286 pop_es(void) { // 07: pop es __asm { I286CLOCK(5) REGPOP(I286_ES) - and eax, 00ffffh + movzx eax, ax + test I286_MSW, MSW_PE + jne short pop_es_pe shl eax, 4 // make segreg - mov ES_BASE, eax +pop_es_base: mov ES_BASE, eax GET_NEXTPRE1 ret + +pop_es_pe: push offset pop_es_base + jmp i286x_selector } } @@ -567,18 +660,25 @@ I286 pop_ss(void) { // 17: pop ss __asm { I286CLOCK(5) REGPOP(I286_SS) - and eax, 00ffffh + movzx eax, ax + test I286_MSW, MSW_PE + jne short pop_ss_pe shl eax, 4 // make segreg - mov SS_BASE, eax +pop_ss_base: mov SS_BASE, eax mov SS_FIX, eax - cmp i286reg.prefix, 0 // 00/06/24 - je noprefix - call removeprefix - pop eax + cmp i286core.s.prefix, 0 // 00/06/24 + jne prefix_exist noprefix: movzx ebp, bh GET_NEXTPRE1 jmp i286op[ebp*4] + +pop_ss_pe: push offset pop_ss_base + jmp i286x_selector + +prefix_exist: pop eax // eax<-offset removeprefix + call eax + jmp noprefix } } @@ -689,12 +789,17 @@ I286 pop_ds(void) { // 1F: pop ds __asm { I286CLOCK(5) REGPOP(I286_DS) - and eax, 00ffffh + movzx eax, ax + test I286_MSW, MSW_PE + jne short pop_ds_pe shl eax, 4 // make segreg - mov DS_BASE, eax +pop_ds_base: mov DS_BASE, eax mov DS_FIX, eax GET_NEXTPRE1 ret + +pop_ds_pe: push offset pop_ds_base + jmp i286x_selector } } @@ -1671,13 +1776,8 @@ I286 _insb(void) { // 6C: insb __asm { GET_NEXTPRE1 I286CLOCK(5) -#if 1 movzx ecx, I286_DX call iocore_inp8 -#else - mov cx, I286_DX - call i286_in -#endif mov dl, al movzx ecx, I286_ES shl ecx, 4 @@ -1718,13 +1818,8 @@ I286 _outsb(void) { // 6E: outsb mov dl, al STRING_DIR add I286_SI, ax -#if 1 movzx ecx, I286_DX jmp iocore_out8 -#else - mov cx, I286_DX - jmp i286_out -#endif } } @@ -2395,24 +2490,25 @@ I286 mov_seg_ea(void) { // 8E: mov GET_NEXTPRE2 mov ax, word ptr I286_REG[edi*2] jmp segset - align 16 + align 4 src_memory: I286CLOCK(5) call p_ea_dst[eax*4] call i286_memoryread_w segset: mov word ptr I286_SEGREG[ebp], ax - and eax, 0000ffffh + movzx eax, ax + test I286_MSW, MSW_PE + jne short mov_seg_pe shl eax, 4 // make segreg - mov SEG_BASE[ebp*2], eax +mov_seg_base: mov SEG_BASE[ebp*2], eax sub ebp, 2*2 - jc segsetr + jc short segsetr mov SS_FIX[ebp*2], eax - je setss + je short setss segsetr:ret - align 16 - setss: cmp i286reg.prefix, 0 // 00/05/13 + setss: cmp i286core.s.prefix, 0 // 00/05/13 je noprefix pop eax call eax // eax<-offset removeprefix @@ -2420,9 +2516,10 @@ I286 mov_seg_ea(void) { // 8E: mov movzx eax, bl jmp i286op[eax*4] - align 16 - fixcs: - INT_NUM(6) +mov_seg_pe: push offset mov_seg_base + jmp i286x_selector + + fixcs: INT_NUM(6) } } @@ -2660,7 +2757,22 @@ I286 _popf(void) { // 9D: popf and ah, 3 cmp ah, 3 sete I286_TRAP - I286IRQCHECKTERM + + je irqcheck // fast_intr + test ah, 2 + je nextop + cmp pic.ext_irq, 0 + jne nextop + mov al, pic.pi[0].imr + mov ah, pic.pi[1].imr + not ax + test al, pic.pi[0].irr + jne irqcheck + test ah, pic.pi[1].irr + jne irqcheck +nextop: ret + +irqcheck: I286IRQCHECKTERM } } @@ -3273,7 +3385,7 @@ I286 les_r16_ea(void) { // C4: les shl eax, 4 // make segreg mov ES_BASE, eax ret - align 16 + align 4 src_register: INT_NUM(6) } @@ -3534,15 +3646,13 @@ I286 int_data8(void) { // CD: int I286 _into(void) { // CE: into __asm { + I286CLOCK(4) test I286_FLAG, O_FLAG jne intovf - I286CLOCK(4) GET_NEXTPRE1 ret - align 16 - intovf: - I286CLOCK(24) - INT_NUM(4) + + intovf: INT_NUM(4) } } @@ -3574,7 +3684,23 @@ I286 _iret(void) { // CF: iret cmp ah, 3 sete I286_TRAP RESET_XPREFETCH - I286IRQCHECKTERM + + cmp I286_TRAP, 0 // fast_intr + jne irqcheck + test I286_FLAG, I_FLAG + je nextop + cmp pic.ext_irq, 0 + jne nextop + mov al, pic.pi[0].imr + mov ah, pic.pi[1].imr + not ax + test al, pic.pi[0].irr + jne irqcheck + test ah, pic.pi[1].irr + jne irqcheck +nextop: ret + +irqcheck: I286IRQCHECKTERM } } @@ -3743,9 +3869,8 @@ nzflagsed: xor al, ah or I286_FLAGL, al GET_NEXTPRE2 ret - align 16 - div0: - INT_NUM(0) + + div0: INT_NUM(0) } } @@ -3889,15 +4014,11 @@ I286 in_al_data8(void) { // E4: in I286CLOCK(5) lea eax, [esi + 2] add eax, CS_BASE - mov i286reg.inport, eax + mov I286_INPADRS, eax movzx ecx, bh -#if 1 call iocore_inp8 -#else - call i286_in -#endif mov I286_AL, al - mov i286reg.inport, 0 + mov I286_INPADRS, 0 GET_NEXTPRE2 ret } @@ -3926,12 +4047,8 @@ I286 out_data8_al(void) { // E6: ou GET_NEXTPRE2 pop ecx mov dl, I286_AL -#if 1 jmp iocore_out8 -#else - jmp i286_out -#endif - } + } } I286 out_data8_ax(void) { // E7: out DATA8, ax @@ -4006,13 +4123,8 @@ I286 in_al_dx(void) { // EC: in al __asm { I286CLOCK(5) -#if 1 movzx ecx, I286_DX call iocore_inp8 -#else - mov cx, I286_DX - call i286_in -#endif mov I286_AL, al GET_NEXTPRE1 ret @@ -4036,15 +4148,9 @@ I286 out_dx_al(void) { // EE: out __asm { GET_NEXTPRE1 I286CLOCK(3) -#if 1 movzx ecx, I286_DX mov dl, I286_AL jmp iocore_out8 -#else - mov cx, I286_DX - mov dl, I286_AL - jmp i286_out -#endif } } @@ -4084,7 +4190,7 @@ I286 _repe(void) { // F3: repe I286 _hlt(void) { // F4: hlt __asm { - mov nevent.remainclock, -1 + mov I286_REMCLOCK, -1 ret } } @@ -4157,14 +4263,28 @@ I286 _sti(void) { // FB: sti __asm { GET_NEXTPRE1 I286CLOCK(2) - or I286_FLAG, I_FLAG + cmp i286core.s.prefix, 0 // ver0.26 00/10/08 + jne prefix_exist // 前方分岐ジャンプなので。 + noprefix: + movzx ebp, bl + bts I286_FLAG, 9 + jne jmp_nextop test I286_FLAG, T_FLAG setne I286_TRAP - cmp i286reg.prefix, 0 // ver0.26 00/10/08 - jne prefix_exist // 前方分岐ジャンプなので。 -noprefix: movzx eax, bl - call i286op[eax*4] + jne nextopandexit // fast_intr + cmp pic.ext_irq, 0 + jne jmp_nextop + mov al, pic.pi[0].imr + mov ah, pic.pi[1].imr + not ax + test al, pic.pi[0].irr + jne nextopandexit + test ah, pic.pi[1].irr + jne nextopandexit +jmp_nextop: jmp i286op[ebp*4] + +nextopandexit: call i286op[ebp*4] I286IRQCHECKTERM prefix_exist: pop eax // eax<-offset removeprefix