| version 1.3, 2003/10/19 14:56:15 | version 1.12, 2003/12/25 19:58:24 | 
| Line 1 | Line 1 | 
 | #include        "compiler.h" | #include        "compiler.h" | 
| #include        "i286.h" | #include        "cpucore.h" | 
 | #include        "i286x.h" | #include        "i286x.h" | 
 | #include        "i286xadr.h" | #include        "i286xadr.h" | 
 | #include        "i286xs.h" | #include        "i286xs.h" | 
 | #include        "i286xrep.h" | #include        "i286xrep.h" | 
 | #include        "i286xcts.h" | #include        "i286xcts.h" | 
 | #include        "memory.h" |  | 
 | #include        "pccore.h" | #include        "pccore.h" | 
 | #include        "iocore.h" | #include        "iocore.h" | 
 | #include        "i286x.mcr" | #include        "i286x.mcr" | 
| Line 15 | Line 14 | 
 | #include        "dmap.h" | #include        "dmap.h" | 
 |  |  | 
 |  |  | 
| I286REG i286reg; | I286CORE        i286core; | 
 |  |  | 
 | const BYTE iflags[256] = {                                      // Z_FLAG, S_FLAG, P_FLAG | const BYTE iflags[256] = {                                      // Z_FLAG, S_FLAG, P_FLAG | 
 | 0x44, 0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x00, | 0x44, 0x00, 0x00, 0x04, 0x00, 0x04, 0x04, 0x00, | 
| Line 52  const BYTE iflags[256] = {     // Z_FLAG | Line 51  const BYTE iflags[256] = {     // Z_FLAG | 
 | 0x80, 0x84, 0x84, 0x80, 0x84, 0x80, 0x80, 0x84}; | 0x80, 0x84, 0x84, 0x80, 0x84, 0x80, 0x80, 0x84}; | 
 |  |  | 
 |  |  | 
| void i286_reset(void) { | void i286x_initialize(void) { | 
 |  |  | 
| i286xadr_init();                                                        // 毎回通すのはどうか… | i286xadr_init(); | 
| v30init();                                                                      // 毎回通すのはどうか… | v30xinit(); | 
| ZeroMemory(&i286reg, sizeof(i286reg)); |  | 
| I286_CS = 0x1fc0; |  | 
| CS_BASE = 0x1fc00; |  | 
 | } | } | 
 |  |  | 
 |  | void i286x_reset(void) { | 
 |  |  | 
| LABEL void i286_resetprefetch(void) { | ZeroMemory(&i286core.s, sizeof(i286core.s)); | 
|  | I286_CS = 0xffff; | 
|  | CS_BASE = 0xffff0; | 
|  | i286core.s.adrsmask = 0xfffff; | 
|  | } | 
|  |  | 
|  | void i286x_shut(void) { | 
|  |  | 
|  | I286_MSW = 0; | 
|  | I286_CS = 0xffff; | 
|  | CS_BASE = 0xffff0; | 
|  | I286_IP = 0; | 
|  | I286_ADRSMASK = 0xfffff; | 
|  | i286x_resetprefetch(); | 
|  | } | 
|  |  | 
|  |  | 
|  | LABEL void i286x_resetprefetch(void) { | 
 |  |  | 
 | __asm { | __asm { | 
 | pushad | pushad | 
 | movzx   esi, I286_IP | movzx   esi, I286_IP | 
 | RESET_XPREFETCH | RESET_XPREFETCH | 
| mov             dword ptr (i286reg.prefetchque), ebx | mov             dword ptr (i286core.s.prefetchque), ebx | 
 | popad | popad | 
 | ret | ret | 
 | } | } | 
 | } | } | 
 |  |  | 
| LABEL void __fastcall i286_interrupt(BYTE vect) { | LABEL void __fastcall i286x_interrupt(BYTE vect) { | 
 |  |  | 
 | __asm { | __asm { | 
 | pushad | pushad | 
| Line 84  LABEL void __fastcall i286_interrupt(BYT | Line 98  LABEL void __fastcall i286_interrupt(BYT | 
 | sub             bx, 2 | sub             bx, 2 | 
 |  |  | 
 | // hlt.. | // hlt.. | 
| cmp             byte ptr (i286reg.prefetchque), 0f4h            // hlt | cmp             byte ptr (i286core.s.prefetchque), 0f4h         // hlt | 
 | jne             short nonhlt | jne             short nonhlt | 
 | inc             I286_IP | inc             I286_IP | 
 | nonhlt:                 mov             edi, SS_BASE | nonhlt:                 mov             edi, SS_BASE | 
| Line 116  nonhlt:   mov  edi, SS_BASE | Line 130  nonhlt:   mov  edi, SS_BASE | 
 | shl             eax, 4                                  // make segreg | shl             eax, 4                                  // make segreg | 
 | mov             CS_BASE, eax | mov             CS_BASE, eax | 
 | RESET_XPREFETCH | RESET_XPREFETCH | 
| mov             dword ptr (i286reg.prefetchque), ebx | mov             dword ptr (i286core.s.prefetchque), ebx | 
 |  |  | 
 | popad | popad | 
 | ret | ret | 
| Line 164  LABEL void __fastcall i286x_localint(voi | Line 178  LABEL void __fastcall i286x_localint(voi | 
 |  |  | 
 |  |  | 
 |  |  | 
| LABEL void i286(void) { | LABEL void i286x(void) { | 
 |  |  | 
 | __asm { | __asm { | 
 | pushad | pushad | 
| mov             ebx, dword ptr (i286reg.prefetchque) | mov             ebx, dword ptr (i286core.s.prefetchque) | 
 | movzx   esi, I286_IP | movzx   esi, I286_IP | 
 |  |  | 
 | cmp             I286_TRAP, 0 | cmp             I286_TRAP, 0 | 
| Line 180  i286_mnlp:  movzx eax, bl | Line 194  i286_mnlp:  movzx eax, bl | 
 | call    i286op[eax*4] | call    i286op[eax*4] | 
 | cmp             I286_REMCLOCK, 0 | cmp             I286_REMCLOCK, 0 | 
 | jg              i286_mnlp | jg              i286_mnlp | 
| mov             dword ptr (i286reg.prefetchque), ebx | mov             dword ptr (i286core.s.prefetchque), ebx | 
 | mov             I286_IP, si | mov             I286_IP, si | 
 | popad | popad | 
 | ret | ret | 
| Line 191  i286_dma_mnlp: movzx eax, bl | Line 205  i286_dma_mnlp: movzx eax, bl | 
 | call    dmap_i286 | call    dmap_i286 | 
 | cmp             I286_REMCLOCK, 0 | cmp             I286_REMCLOCK, 0 | 
 | jg              i286_dma_mnlp | jg              i286_dma_mnlp | 
| mov             dword ptr (i286reg.prefetchque), ebx | mov             dword ptr (i286core.s.prefetchque), ebx | 
 | mov             I286_IP, si | mov             I286_IP, si | 
 | popad | popad | 
 | ret | ret | 
| Line 203  i286_trapping: movzx eax, bl | Line 217  i286_trapping: movzx eax, bl | 
 | je              i286notrap | je              i286notrap | 
 | mov             ecx, 1 | mov             ecx, 1 | 
 | call    i286x_localint | call    i286x_localint | 
| i286notrap:             mov             dword ptr (i286reg.prefetchque), ebx | i286notrap:             mov             dword ptr (i286core.s.prefetchque), ebx | 
 | mov             I286_IP, si | mov             I286_IP, si | 
 | popad | popad | 
 | ret | ret | 
| Line 212  i286notrap:  mov  dword ptr (i286reg.pre | Line 226  i286notrap:  mov  dword ptr (i286reg.pre | 
 |  |  | 
 |  |  | 
 |  |  | 
| LABEL void i286_step(void) { | LABEL void i286x_step(void) { | 
 |  |  | 
 | __asm { | __asm { | 
 | pushad | pushad | 
| mov             ebx, dword ptr (i286reg.prefetchque) | mov             ebx, dword ptr (i286core.s.prefetchque) | 
 | movzx   esi, I286_IP | movzx   esi, I286_IP | 
 |  |  | 
 | movzx   eax, bl | movzx   eax, bl | 
| Line 227  LABEL void i286_step(void) { | Line 241  LABEL void i286_step(void) { | 
 | mov             ecx, 1 | mov             ecx, 1 | 
 | call    i286x_localint | call    i286x_localint | 
 | nexts: | nexts: | 
| mov             dword ptr (i286reg.prefetchque), ebx | mov             dword ptr (i286core.s.prefetchque), ebx | 
 | mov             I286_IP, si | mov             I286_IP, si | 
 |  |  | 
 | call    dmap_i286 | call    dmap_i286 | 
| Line 242  nexts: | Line 256  nexts: | 
 | LABEL void removeprefix(void) { | LABEL void removeprefix(void) { | 
 |  |  | 
 | __asm { | __asm { | 
| mov             i286reg.prefix, 0 | mov             i286core.s.prefix, 0 | 
 | mov             eax, DS_BASE | mov             eax, DS_BASE | 
 | mov             DS_FIX, eax | mov             DS_FIX, eax | 
 | mov             eax, SS_BASE | mov             eax, SS_BASE | 
| Line 571  I286 pop_ss(void) {        // 17: pop ss | Line 585  I286 pop_ss(void) {        // 17: pop ss | 
 | shl             eax, 4                                  // make segreg | shl             eax, 4                                  // make segreg | 
 | mov             SS_BASE, eax | mov             SS_BASE, eax | 
 | mov             SS_FIX, eax | mov             SS_FIX, eax | 
| cmp             i286reg.prefix, 0               // 00/06/24 | cmp             i286core.s.prefix, 0            // 00/06/24 | 
| je              noprefix | jne             prefix_exist | 
| call    removeprefix |  | 
| pop             eax |  | 
 | noprefix: | noprefix: | 
 | movzx   ebp, bh | movzx   ebp, bh | 
 | GET_NEXTPRE1 | GET_NEXTPRE1 | 
 | jmp             i286op[ebp*4] | jmp             i286op[ebp*4] | 
 |  |  | 
 |  | prefix_exist:   pop             eax                                             // eax<-offset removeprefix | 
 |  | call    eax | 
 |  | jmp             noprefix | 
 | } | } | 
 | } | } | 
 |  |  | 
| Line 2412  I286 mov_seg_ea(void) {       // 8E: mov | Line 2428  I286 mov_seg_ea(void) {       // 8E: mov | 
 | segsetr:ret | segsetr:ret | 
 |  |  | 
 | align   16 | align   16 | 
| setss:  cmp             i286reg.prefix, 0               // 00/05/13 | setss:  cmp             i286core.s.prefix, 0    // 00/05/13 | 
 | je              noprefix | je              noprefix | 
 | pop             eax | pop             eax | 
 | call    eax                                             // eax<-offset removeprefix | call    eax                                             // eax<-offset removeprefix | 
| Line 2660  I286 _popf(void) {        // 9D: popf | Line 2676  I286 _popf(void) {        // 9D: popf | 
 | and             ah, 3 | and             ah, 3 | 
 | cmp             ah, 3 | cmp             ah, 3 | 
 | sete    I286_TRAP | 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 | 
 | } | } | 
 | } | } | 
 |  |  | 
| Line 3574  I286 _iret(void) {        // CF: iret | Line 3605  I286 _iret(void) {        // CF: iret | 
 | cmp             ah, 3 | cmp             ah, 3 | 
 | sete    I286_TRAP | sete    I286_TRAP | 
 | RESET_XPREFETCH | 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 | 
 | } | } | 
 | } | } | 
 |  |  | 
| Line 3889  I286 in_al_data8(void) {      // E4: in | Line 3936  I286 in_al_data8(void) {      // E4: in | 
 | I286CLOCK(5) | I286CLOCK(5) | 
 | lea             eax, [esi + 2] | lea             eax, [esi + 2] | 
 | add             eax, CS_BASE | add             eax, CS_BASE | 
| mov             i286reg.inport, eax | mov             i286core.s.inport, eax | 
 | movzx   ecx, bh | movzx   ecx, bh | 
 | #if 1 | #if 1 | 
 | call    iocore_inp8 | call    iocore_inp8 | 
| Line 3897  I286 in_al_data8(void) {      // E4: in | Line 3944  I286 in_al_data8(void) {      // E4: in | 
 | call    i286_in | call    i286_in | 
 | #endif | #endif | 
 | mov             I286_AL, al | mov             I286_AL, al | 
| mov             i286reg.inport, 0 | mov             i286core.s.inport, 0 | 
 | GET_NEXTPRE2 | GET_NEXTPRE2 | 
 | ret | ret | 
 | } | } | 
| Line 4157  I286 _sti(void) {        // FB: sti | Line 4204  I286 _sti(void) {        // FB: sti | 
 | __asm { | __asm { | 
 | GET_NEXTPRE1 | GET_NEXTPRE1 | 
 | I286CLOCK(2) | 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 | test    I286_FLAG, T_FLAG | 
 | setne   I286_TRAP | setne   I286_TRAP | 
 |  |  | 
| cmp             i286reg.prefix, 0               // ver0.26 00/10/08 | jne             nextopandexit                   // fast_intr | 
| jne             prefix_exist                    // 前方分岐ジャンプなので。 | cmp             pic.ext_irq, 0 | 
| noprefix:               movzx   eax, bl | jne             jmp_nextop | 
| call    i286op[eax*4] | 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 | I286IRQCHECKTERM | 
 |  |  | 
 | prefix_exist:   pop             eax                                             // eax<-offset removeprefix | prefix_exist:   pop             eax                                             // eax<-offset removeprefix |