|
|
| version 1.7, 2003/12/08 00:55:31 | version 1.17, 2004/01/25 07:53:08 |
|---|---|
| Line 5 | Line 5 |
| #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 58 void i286x_initialize(void) { | Line 57 void i286x_initialize(void) { |
| v30xinit(); | v30xinit(); |
| } | } |
| void i286x_deinitialize(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) { | void i286x_reset(void) { |
| ZeroMemory(&i286core.s, sizeof(i286core.s)); | ZeroMemory(&i286core.s, sizeof(i286core.s)); |
| I286_CS = 0x1fc0; | i286x_initreg(); |
| CS_BASE = 0x1fc00; | } |
| i286core.s.adrsmask = 0xfffff; | |
| 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; | |
| } | } |
| Line 168 LABEL void __fastcall i286x_localint(voi | Line 227 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 i286x(void) { | LABEL void i286x(void) { |
| Line 364 I286 pop_es(void) { // 07: pop es | Line 447 I286 pop_es(void) { // 07: pop es |
| __asm { | __asm { |
| I286CLOCK(5) | I286CLOCK(5) |
| REGPOP(I286_ES) | REGPOP(I286_ES) |
| and eax, 00ffffh | movzx eax, ax |
| test I286_MSW, MSW_PE | |
| jne short pop_es_pe | |
| shl eax, 4 // make segreg | shl eax, 4 // make segreg |
| mov ES_BASE, eax | pop_es_base: mov ES_BASE, eax |
| GET_NEXTPRE1 | GET_NEXTPRE1 |
| ret | ret |
| pop_es_pe: push offset pop_es_base | |
| jmp i286x_selector | |
| } | } |
| } | } |
| Line 572 I286 pop_ss(void) { // 17: pop ss | Line 660 I286 pop_ss(void) { // 17: pop ss |
| __asm { | __asm { |
| I286CLOCK(5) | I286CLOCK(5) |
| REGPOP(I286_SS) | REGPOP(I286_SS) |
| and eax, 00ffffh | movzx eax, ax |
| test I286_MSW, MSW_PE | |
| jne short pop_ss_pe | |
| shl eax, 4 // make segreg | shl eax, 4 // make segreg |
| mov SS_BASE, eax | pop_ss_base: mov SS_BASE, eax |
| mov SS_FIX, eax | mov SS_FIX, eax |
| cmp i286core.s.prefix, 0 // 00/06/24 | cmp i286core.s.prefix, 0 // 00/06/24 |
| jne prefix_exist | jne prefix_exist |
| Line 583 I286 pop_ss(void) { // 17: pop ss | Line 673 I286 pop_ss(void) { // 17: pop ss |
| GET_NEXTPRE1 | GET_NEXTPRE1 |
| jmp i286op[ebp*4] | jmp i286op[ebp*4] |
| pop_ss_pe: push offset pop_ss_base | |
| jmp i286x_selector | |
| prefix_exist: pop eax // eax<-offset removeprefix | prefix_exist: pop eax // eax<-offset removeprefix |
| call eax | call eax |
| jmp noprefix | jmp noprefix |
| Line 696 I286 pop_ds(void) { // 1F: pop ds | Line 789 I286 pop_ds(void) { // 1F: pop ds |
| __asm { | __asm { |
| I286CLOCK(5) | I286CLOCK(5) |
| REGPOP(I286_DS) | REGPOP(I286_DS) |
| and eax, 00ffffh | movzx eax, ax |
| test I286_MSW, MSW_PE | |
| jne short pop_ds_pe | |
| shl eax, 4 // make segreg | shl eax, 4 // make segreg |
| mov DS_BASE, eax | pop_ds_base: mov DS_BASE, eax |
| mov DS_FIX, eax | mov DS_FIX, eax |
| GET_NEXTPRE1 | GET_NEXTPRE1 |
| ret | ret |
| pop_ds_pe: push offset pop_ds_base | |
| jmp i286x_selector | |
| } | } |
| } | } |
| Line 1678 I286 _insb(void) { // 6C: insb | Line 1776 I286 _insb(void) { // 6C: insb |
| __asm { | __asm { |
| GET_NEXTPRE1 | GET_NEXTPRE1 |
| I286CLOCK(5) | I286CLOCK(5) |
| #if 1 | |
| movzx ecx, I286_DX | movzx ecx, I286_DX |
| call iocore_inp8 | call iocore_inp8 |
| #else | |
| mov cx, I286_DX | |
| call i286_in | |
| #endif | |
| mov dl, al | mov dl, al |
| movzx ecx, I286_ES | movzx ecx, I286_ES |
| shl ecx, 4 | shl ecx, 4 |
| Line 1725 I286 _outsb(void) { // 6E: outsb | Line 1818 I286 _outsb(void) { // 6E: outsb |
| mov dl, al | mov dl, al |
| STRING_DIR | STRING_DIR |
| add I286_SI, ax | add I286_SI, ax |
| #if 1 | |
| movzx ecx, I286_DX | movzx ecx, I286_DX |
| jmp iocore_out8 | jmp iocore_out8 |
| #else | |
| mov cx, I286_DX | |
| jmp i286_out | |
| #endif | |
| } | } |
| } | } |
| Line 2402 I286 mov_seg_ea(void) { // 8E: mov | Line 2490 I286 mov_seg_ea(void) { // 8E: mov |
| GET_NEXTPRE2 | GET_NEXTPRE2 |
| mov ax, word ptr I286_REG[edi*2] | mov ax, word ptr I286_REG[edi*2] |
| jmp segset | jmp segset |
| align 16 | align 4 |
| src_memory: | src_memory: |
| I286CLOCK(5) | I286CLOCK(5) |
| call p_ea_dst[eax*4] | call p_ea_dst[eax*4] |
| call i286_memoryread_w | call i286_memoryread_w |
| segset: | segset: |
| mov word ptr I286_SEGREG[ebp], ax | 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 | shl eax, 4 // make segreg |
| mov SEG_BASE[ebp*2], eax | mov_seg_base: mov SEG_BASE[ebp*2], eax |
| sub ebp, 2*2 | sub ebp, 2*2 |
| jc segsetr | jc short segsetr |
| mov SS_FIX[ebp*2], eax | mov SS_FIX[ebp*2], eax |
| je setss | je short setss |
| segsetr:ret | segsetr:ret |
| align 16 | |
| setss: cmp i286core.s.prefix, 0 // 00/05/13 | setss: cmp i286core.s.prefix, 0 // 00/05/13 |
| je noprefix | je noprefix |
| pop eax | pop eax |
| Line 2427 I286 mov_seg_ea(void) { // 8E: mov | Line 2516 I286 mov_seg_ea(void) { // 8E: mov |
| movzx eax, bl | movzx eax, bl |
| jmp i286op[eax*4] | jmp i286op[eax*4] |
| align 16 | mov_seg_pe: push offset mov_seg_base |
| fixcs: | jmp i286x_selector |
| INT_NUM(6) | |
| fixcs: INT_NUM(6) | |
| } | } |
| } | } |
| Line 2668 I286 _popf(void) { // 9D: popf | Line 2758 I286 _popf(void) { // 9D: popf |
| cmp ah, 3 | cmp ah, 3 |
| sete I286_TRAP | sete I286_TRAP |
| test ah, 2 // fast_intr | je irqcheck // fast_intr |
| test ah, 2 | |
| je nextop | je nextop |
| cmp pic.ext_irq, 0 | cmp pic.ext_irq, 0 |
| jne nextop | jne nextop |
| Line 2677 I286 _popf(void) { // 9D: popf | Line 2768 I286 _popf(void) { // 9D: popf |
| not ax | not ax |
| test al, pic.pi[0].irr | test al, pic.pi[0].irr |
| jne irqcheck | jne irqcheck |
| test al, pic.pi[1].irr | test ah, pic.pi[1].irr |
| jne irqcheck | jne irqcheck |
| nextop: ret | nextop: ret |
| Line 3294 I286 les_r16_ea(void) { // C4: les | Line 3385 I286 les_r16_ea(void) { // C4: les |
| shl eax, 4 // make segreg | shl eax, 4 // make segreg |
| mov ES_BASE, eax | mov ES_BASE, eax |
| ret | ret |
| align 16 | align 4 |
| src_register: | src_register: |
| INT_NUM(6) | INT_NUM(6) |
| } | } |
| Line 3555 I286 int_data8(void) { // CD: int | Line 3646 I286 int_data8(void) { // CD: int |
| I286 _into(void) { // CE: into | I286 _into(void) { // CE: into |
| __asm { | __asm { |
| I286CLOCK(4) | |
| test I286_FLAG, O_FLAG | test I286_FLAG, O_FLAG |
| jne intovf | jne intovf |
| I286CLOCK(4) | |
| GET_NEXTPRE1 | GET_NEXTPRE1 |
| ret | ret |
| align 16 | |
| intovf: | intovf: INT_NUM(4) |
| I286CLOCK(24) | |
| INT_NUM(4) | |
| } | } |
| } | } |
| Line 3596 I286 _iret(void) { // CF: iret | Line 3685 I286 _iret(void) { // CF: iret |
| sete I286_TRAP | sete I286_TRAP |
| RESET_XPREFETCH | RESET_XPREFETCH |
| test I286_FLAG, I_FLAG // fast_intr | cmp I286_TRAP, 0 // fast_intr |
| jne irqcheck | |
| test I286_FLAG, I_FLAG | |
| je nextop | je nextop |
| cmp pic.ext_irq, 0 | cmp pic.ext_irq, 0 |
| jne nextop | jne nextop |
| Line 3605 I286 _iret(void) { // CF: iret | Line 3696 I286 _iret(void) { // CF: iret |
| not ax | not ax |
| test al, pic.pi[0].irr | test al, pic.pi[0].irr |
| jne irqcheck | jne irqcheck |
| test al, pic.pi[1].irr | test ah, pic.pi[1].irr |
| jne irqcheck | jne irqcheck |
| nextop: ret | nextop: ret |
| Line 3778 nzflagsed: xor al, ah | Line 3869 nzflagsed: xor al, ah |
| or I286_FLAGL, al | or I286_FLAGL, al |
| GET_NEXTPRE2 | GET_NEXTPRE2 |
| ret | ret |
| align 16 | |
| div0: | div0: INT_NUM(0) |
| INT_NUM(0) | |
| } | } |
| } | } |
| Line 3924 I286 in_al_data8(void) { // E4: in | Line 4014 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 i286core.s.inport, eax | mov I286_INPADRS, eax |
| movzx ecx, bh | movzx ecx, bh |
| #if 1 | |
| call iocore_inp8 | call iocore_inp8 |
| #else | |
| call i286_in | |
| #endif | |
| mov I286_AL, al | mov I286_AL, al |
| mov i286core.s.inport, 0 | mov I286_INPADRS, 0 |
| GET_NEXTPRE2 | GET_NEXTPRE2 |
| ret | ret |
| } | } |
| Line 3961 I286 out_data8_al(void) { // E6: ou | Line 4047 I286 out_data8_al(void) { // E6: ou |
| GET_NEXTPRE2 | GET_NEXTPRE2 |
| pop ecx | pop ecx |
| mov dl, I286_AL | mov dl, I286_AL |
| #if 1 | |
| jmp iocore_out8 | jmp iocore_out8 |
| #else | } |
| jmp i286_out | |
| #endif | |
| } | |
| } | } |
| I286 out_data8_ax(void) { // E7: out DATA8, ax | I286 out_data8_ax(void) { // E7: out DATA8, ax |
| Line 4041 I286 in_al_dx(void) { // EC: in al | Line 4123 I286 in_al_dx(void) { // EC: in al |
| __asm { | __asm { |
| I286CLOCK(5) | I286CLOCK(5) |
| #if 1 | |
| movzx ecx, I286_DX | movzx ecx, I286_DX |
| call iocore_inp8 | call iocore_inp8 |
| #else | |
| mov cx, I286_DX | |
| call i286_in | |
| #endif | |
| mov I286_AL, al | mov I286_AL, al |
| GET_NEXTPRE1 | GET_NEXTPRE1 |
| ret | ret |
| Line 4071 I286 out_dx_al(void) { // EE: out | Line 4148 I286 out_dx_al(void) { // EE: out |
| __asm { | __asm { |
| GET_NEXTPRE1 | GET_NEXTPRE1 |
| I286CLOCK(3) | I286CLOCK(3) |
| #if 1 | |
| movzx ecx, I286_DX | movzx ecx, I286_DX |
| mov dl, I286_AL | mov dl, I286_AL |
| jmp iocore_out8 | jmp iocore_out8 |
| #else | |
| mov cx, I286_DX | |
| mov dl, I286_AL | |
| jmp i286_out | |
| #endif | |
| } | } |
| } | } |
| Line 4201 I286 _sti(void) { // FB: sti | Line 4272 I286 _sti(void) { // FB: sti |
| test I286_FLAG, T_FLAG | test I286_FLAG, T_FLAG |
| setne I286_TRAP | setne I286_TRAP |
| cmp pic.ext_irq, 0 // fast_intr | jne nextopandexit // fast_intr |
| cmp pic.ext_irq, 0 | |
| jne jmp_nextop | jne jmp_nextop |
| mov al, pic.pi[0].imr | mov al, pic.pi[0].imr |
| mov ah, pic.pi[1].imr | mov ah, pic.pi[1].imr |
| not ax | not ax |
| test al, pic.pi[0].irr | test al, pic.pi[0].irr |
| jne nextopandexit | jne nextopandexit |
| test al, pic.pi[1].irr | test ah, pic.pi[1].irr |
| jne nextopandexit | jne nextopandexit |
| jmp_nextop: jmp i286op[ebp*4] | jmp_nextop: jmp i286op[ebp*4] |