--- np2/i286c/i286c_mn.c 2003/12/25 19:26:55 1.26 +++ np2/i286c/i286c_mn.c 2005/03/05 06:02:29 1.39 @@ -5,6 +5,9 @@ #include "iocore.h" #include "bios.h" #include "i286c.mcr" +#if defined(ENABLE_TRAP) +#include "inttrap.h" +#endif #define MAX_PREFIX 8 @@ -22,22 +25,6 @@ I286_REMCLOCK = (c); \ } -// ---- select... - -static UINT32 segselect(UINT sel) { - - I286DTR *dtr; - UINT32 addr; - UINT32 ret; - - dtr = (sel & 4)?&I286_IDTR:&I286_GDTR; - addr = (dtr->base24 << 16) + dtr->base + (sel & (~7)); - ret = i286_memoryread_w(addr+2); - ret += i286_memoryread(addr+4) << 16; - TRACEOUT(("PE - select %.4x %.8x", sel, ret)); - return(ret); -} - // ---- @@ -48,7 +35,7 @@ I286FN _reserved(void) { I286FN _add_ea_r8(void) { // 00: add EA, REG8 - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -73,7 +60,7 @@ I286FN _add_ea_r8(void) { // 00: ad } dst = *out; ADDBYTE(res, dst, src); - *out = (BYTE)res; + *out = (UINT8)res; } I286FN _add_ea_r16(void) { // 01: add EA, REG16 @@ -108,7 +95,7 @@ I286FN _add_ea_r16(void) { // 01: a I286FN _add_r8_ea(void) { // 02: add REG8, EA - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -117,7 +104,7 @@ I286FN _add_r8_ea(void) { // 02: ad PREPART_REG8_EA(op, src, out, 2, 7); dst = *out; ADDBYTE(res, dst, src); - *out = (BYTE)res; + *out = (UINT8)res; } I286FN _add_r16_ea(void) { // 03: add REG16, EA @@ -142,7 +129,7 @@ I286FN _add_al_data8(void) { // 04: I286_WORKCLOCK(3); GET_PCBYTE(src); ADDBYTE(res, I286_AL, src); - I286_AL = (BYTE)res; + I286_AL = (UINT8)res; } I286FN _add_ax_data16(void) { // 05: add ax, DATA16 @@ -167,18 +154,12 @@ I286FN _pop_es(void) { // 07: pop REGPOP(tmp, 5) I286_ES = tmp; - if (!(I286_MSW & 1)) { - ES_BASE = tmp << 4; - NEXT_OPCODE - } - else { - ES_BASE = segselect(tmp); - } + ES_BASE = SEGSELECT(tmp); } I286FN _or_ea_r8(void) { // 08: or EA, REG8 - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -202,7 +183,7 @@ I286FN _or_ea_r8(void) { // 08: or } dst = *out; ORBYTE(dst, src); - *out = (BYTE)dst; + *out = (UINT8)dst; } I286FN _or_ea_r16(void) { // 09: or EA, REG16 @@ -236,7 +217,7 @@ I286FN _or_ea_r16(void) { // 09: o I286FN _or_r8_ea(void) { // 0a: or REG8, EA - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -244,7 +225,7 @@ I286FN _or_r8_ea(void) { // 0a: or PREPART_REG8_EA(op, src, out, 2, 7); dst = *out; ORBYTE(dst, src); - *out = (BYTE)dst; + *out = (UINT8)dst; } I286FN _or_r16_ea(void) { // 0b: or REG16, EA @@ -269,7 +250,7 @@ I286FN _or_al_data8(void) { // 0c: GET_PCBYTE(src); dst = I286_AL; ORBYTE(dst, src); - I286_AL = (BYTE)dst; + I286_AL = (UINT8)dst; } I286FN _or_ax_data16(void) { // 0d: or ax, DATA16 @@ -291,7 +272,7 @@ I286FN _push_cs(void) { // 0e: pus I286FN _adc_ea_r8(void) { // 10: adc EA, REG8 - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -316,7 +297,7 @@ I286FN _adc_ea_r8(void) { // 10: ad } dst = *out; ADCBYTE(res, dst, src); - *out = (BYTE)res; + *out = (UINT8)res; } I286FN _adc_ea_r16(void) { // 11: adc EA, REG16 @@ -351,7 +332,7 @@ I286FN _adc_ea_r16(void) { // 11: a I286FN _adc_r8_ea(void) { // 12: adc REG8, EA - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -360,7 +341,7 @@ I286FN _adc_r8_ea(void) { // 12: ad PREPART_REG8_EA(op, src, out, 2, 7); dst = *out; ADCBYTE(res, dst, src); - *out = (BYTE)res; + *out = (UINT8)res; } I286FN _adc_r16_ea(void) { // 13: adc REG16, EA @@ -385,7 +366,7 @@ I286FN _adc_al_data8(void) { // 14: I286_WORKCLOCK(3); GET_PCBYTE(src); ADCBYTE(res, I286_AL, src); - I286_AL = (BYTE)res; + I286_AL = (UINT8)res; } I286FN _adc_ax_data16(void) { // 15: adc ax, DATA16 @@ -407,26 +388,17 @@ I286FN _push_ss(void) { // 16: pus I286FN _pop_ss(void) { // 17: pop ss UINT tmp; - UINT32 base; REGPOP(tmp, 5) I286_SS = tmp; - if (!(I286_MSW & 1)) { - SS_BASE = tmp << 4; - SS_FIX = tmp << 4; - NEXT_OPCODE - } - else { - base = segselect(tmp); - SS_BASE = base; - SS_FIX = base; - NEXT_OPCODE - } + SS_BASE = SEGSELECT(tmp); + SS_FIX = SS_BASE; + NEXT_OPCODE } I286FN _sbb_ea_r8(void) { // 18: sbb EA, REG8 - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -451,7 +423,7 @@ I286FN _sbb_ea_r8(void) { // 18: sb } dst = *out; SBBBYTE(res, dst, src); - *out = (BYTE)res; + *out = (UINT8)res; } I286FN _sbb_ea_r16(void) { // 19: sbb EA, REG16 @@ -486,7 +458,7 @@ I286FN _sbb_ea_r16(void) { // 19: s I286FN _sbb_r8_ea(void) { // 1a: sbb REG8, EA - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -495,7 +467,7 @@ I286FN _sbb_r8_ea(void) { // 1a: sb PREPART_REG8_EA(op, src, out, 2, 7); dst = *out; SBBBYTE(res, dst, src); - *out = (BYTE)res; + *out = (UINT8)res; } I286FN _sbb_r16_ea(void) { // 1b: sbb REG16, EA @@ -520,7 +492,7 @@ I286FN _sbb_al_data8(void) { // 1c: I286_WORKCLOCK(3); GET_PCBYTE(src); SBBBYTE(res, I286_AL, src); - I286_AL = (BYTE)res; + I286_AL = (UINT8)res; } I286FN _sbb_ax_data16(void) { // 1d: adc ax, DATA16 @@ -542,26 +514,16 @@ I286FN _push_ds(void) { // 1e: pus I286FN _pop_ds(void) { // 1f: pop ds UINT tmp; - UINT32 base; REGPOP(tmp, 5) I286_DS = tmp; - if (!(I286_MSW & 1)) { - DS_BASE = tmp << 4; - DS_FIX = tmp << 4; - NEXT_OPCODE - } - else { - base = segselect(tmp); - DS_BASE = base; - DS_FIX = base; - NEXT_OPCODE - } + DS_BASE = SEGSELECT(tmp); + DS_FIX = DS_BASE; } I286FN _and_ea_r8(void) { // 20: and EA, REG8 - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -585,7 +547,7 @@ I286FN _and_ea_r8(void) { // 20: an } dst = *out; ANDBYTE(dst, src); - *out = (BYTE)dst; + *out = (UINT8)dst; } I286FN _and_ea_r16(void) { // 21: and EA, REG16 @@ -619,7 +581,7 @@ I286FN _and_ea_r16(void) { // 21: a I286FN _and_r8_ea(void) { // 22: and REG8, EA - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -627,7 +589,7 @@ I286FN _and_r8_ea(void) { // 22: an PREPART_REG8_EA(op, src, out, 2, 7); dst = *out; ANDBYTE(dst, src); - *out = (BYTE)dst; + *out = (UINT8)dst; } I286FN _and_r16_ea(void) { // 23: and REG16, EA @@ -652,7 +614,7 @@ I286FN _and_al_data8(void) { // 24: GET_PCBYTE(src); dst = I286_AL; ANDBYTE(dst, src); - I286_AL = (BYTE)dst; + I286_AL = (UINT8)dst; } I286FN _and_ax_data16(void) { // 25: and ax, DATA16 @@ -692,7 +654,7 @@ I286FN _daa(void) { // 27: daa ((I286_AL >= 0x1a) && (I286_FLAGL & C_FLAG)))); if ((I286_FLAGL & A_FLAG) || ((I286_AL & 0x0f) > 9)) { I286_FLAGL |= A_FLAG; - I286_FLAGL |= (BYTE)((I286_AL + 6) >> 8); + I286_FLAGL |= (UINT8)((I286_AL + 6) >> 8); I286_AL += 6; } if ((I286_FLAGL & C_FLAG) || (I286_AL > 0x9f)) { @@ -705,7 +667,7 @@ I286FN _daa(void) { // 27: daa I286FN _sub_ea_r8(void) { // 28: sub EA, REG8 - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -730,7 +692,7 @@ I286FN _sub_ea_r8(void) { // 28: su } dst = *out; SUBBYTE(res, dst, src); - *out = (BYTE)res; + *out = (UINT8)res; } I286FN _sub_ea_r16(void) { // 29: sub EA, REG16 @@ -765,7 +727,7 @@ I286FN _sub_ea_r16(void) { // 29: s I286FN _sub_r8_ea(void) { // 2a: sub REG8, EA - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -774,7 +736,7 @@ I286FN _sub_r8_ea(void) { // 2a: su PREPART_REG8_EA(op, src, out, 2, 7); dst = *out; SUBBYTE(res, dst, src); - *out = (BYTE)res; + *out = (UINT8)res; } I286FN _sub_r16_ea(void) { // 2b: sub REG16, EA @@ -799,7 +761,7 @@ I286FN _sub_al_data8(void) { // 2c: I286_WORKCLOCK(3); GET_PCBYTE(src); SUBBYTE(res, I286_AL, src); - I286_AL = (BYTE)res; + I286_AL = (UINT8)res; } I286FN _sub_ax_data16(void) { // 2d: sub ax, DATA16 @@ -848,7 +810,7 @@ I286FN _das(void) { // 2f: das I286FN _xor_ea_r8(void) { // 30: xor EA, REG8 - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -872,7 +834,7 @@ I286FN _xor_ea_r8(void) { // 30: xo } dst = *out; XORBYTE(dst, src); - *out = (BYTE)dst; + *out = (UINT8)dst; } I286FN _xor_ea_r16(void) { // 31: xor EA, REG16 @@ -906,7 +868,7 @@ I286FN _xor_ea_r16(void) { // 31: x I286FN _xor_r8_ea(void) { // 32: xor REG8, EA - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -914,7 +876,7 @@ I286FN _xor_r8_ea(void) { // 32: xo PREPART_REG8_EA(op, src, out, 2, 7); dst = *out; XORBYTE(dst, src); - *out = (BYTE)dst; + *out = (UINT8)dst; } I286FN _xor_r16_ea(void) { // 33: or REG16, EA @@ -939,7 +901,7 @@ I286FN _xor_al_data8(void) { // 34: GET_PCBYTE(src); dst = I286_AL; XORBYTE(dst, src); - I286_AL = (BYTE)dst; + I286_AL = (UINT8)dst; } I286FN _xor_ax_data16(void) { // 35: or ax, DATA16 @@ -1027,7 +989,7 @@ I286FN _cmp_ea_r16(void) { // 39: c I286FN _cmp_r8_ea(void) { // 3a: cmp REG8, EA - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT dst; @@ -1264,7 +1226,7 @@ I286FN _arpl(void) { // 63: arpl GET_PCBYTE(op) tmp = ((op < 0xc0)?1:0); - I286_IP += (BYTE)tmp; + I286_IP += (UINT8)tmp; I286_WORKCLOCK(tmp + 10); INT_NUM(6, I286_IP); } @@ -1340,7 +1302,7 @@ I286FN _outsb(void) { // 6E: outsb I286_WORKCLOCK(3); dat = i286_memoryread(I286_SI + DS_FIX); I286_SI += STRING_DIR; - iocore_out8(I286_DX, (BYTE)dat); + iocore_out8(I286_DX, (UINT8)dat); } I286FN _outsw(void) { // 6F: outsw @@ -1440,7 +1402,7 @@ I286FN _jnle_short(void) { // 7F: jg I286FN _calc_ea8_i8(void) { // 80: op EA8, DATA8 // 82: op EA8, DATA8 - BYTE *out; + UINT8 *out; UINT op; UINT32 madr; @@ -1515,7 +1477,7 @@ I286FN _calc_ea16_i8(void) { // 83: o I286FN _test_ea_r8(void) { // 84: test EA, REG8 - BYTE *out; + UINT8 *out; UINT op; UINT src; UINT tmp; @@ -1569,8 +1531,8 @@ I286FN _test_ea_r16(void) { // 85: t I286FN _xchg_ea_r8(void) { // 86: xchg EA, REG8 - BYTE *out; - BYTE *src; + UINT8 *out; + UINT8 *src; UINT op; UINT32 madr; @@ -1583,7 +1545,7 @@ I286FN _xchg_ea_r8(void) { // 86: xc I286_WORKCLOCK(5); madr = CALC_EA(op); if (madr >= I286_MEMWRITEMAX) { - BYTE tmp = i286_memoryread(madr); + UINT8 tmp = i286_memoryread(madr); i286_memorywrite(madr, *src); *src = tmp; return; @@ -1621,7 +1583,7 @@ I286FN _xchg_ea_r16(void) { // 87: x I286FN _mov_ea_r8(void) { // 88: mov EA, REG8 - BYTE src; + UINT8 src; UINT op; UINT32 madr; @@ -1655,8 +1617,8 @@ I286FN _mov_ea_r16(void) { // 89: mo I286FN _mov_r8_ea(void) { // 8A: mov REG8, EA - BYTE *out; - BYTE src; + UINT8 *out; + UINT8 src; UINT op; PREPART_REG8_EA(op, src, out, 2, 5); @@ -1721,13 +1683,7 @@ I286FN _mov_seg_ea(void) { // 8E: mo I286_WORKCLOCK(5); tmp = i286_memoryread_w(CALC_EA(op)); } - if (!(I286_MSW & 1)) { - base = tmp << 4; - } - else { - base = segselect(tmp); - } - + base = SEGSELECT(tmp); switch(op & 0x18) { case 0x00: // es I286_ES = (UINT16)tmp; @@ -1851,7 +1807,7 @@ I286FN _call_far(void) { // 9A: call REGPUSH0(I286_CS) GET_PCWORD(newip) GET_PCWORD(I286_CS) - CS_BASE = I286_CS << 4; + CS_BASE = SEGSELECT(I286_CS); REGPUSH0(I286_IP) I286_IP = newip; } @@ -1934,7 +1890,7 @@ I286FN _mov_m16_ax(void) { // A3: mo I286FN _movsb(void) { // A4: movsb - BYTE tmp; + UINT8 tmp; I286_WORKCLOCK(5); tmp = i286_memoryread(I286_SI + DS_FIX); @@ -2077,10 +2033,10 @@ I286FN _mov_di_imm(void) MOVIMM16(I286_D I286FN _shift_ea8_data8(void) { // C0: shift EA8, DATA8 - BYTE *out; + UINT8 *out; UINT op; UINT32 madr; - BYTE cl; + UINT8 cl; GET_PCBYTE(op) if (op >= 0xc0) { @@ -2108,7 +2064,7 @@ I286FN _shift_ea16_data8(void) { // C1 UINT16 *out; UINT op; UINT32 madr; - BYTE cl; + UINT8 cl; GET_PCBYTE(op) if (op >= 0xc0) { @@ -2159,7 +2115,7 @@ I286FN _les_r16_ea(void) { // C4: le ad = GET_EA(op, &seg); *(REG16_B53(op)) = i286_memoryread_w(seg + ad); I286_ES = i286_memoryread_w(seg + LOW16(ad + 2)); - ES_BASE = I286_ES << 4; + ES_BASE = SEGSELECT(I286_ES); } else { INT_NUM(6, I286_IP - 2); @@ -2178,7 +2134,7 @@ I286FN _lds_r16_ea(void) { // C5: ld ad = GET_EA(op, &seg); *(REG16_B53(op)) = i286_memoryread_w(seg + ad); I286_DS = i286_memoryread_w(seg + LOW16(ad + 2)); - DS_BASE = I286_DS << 4; + DS_BASE = SEGSELECT(I286_DS); DS_FIX = DS_BASE; } else { @@ -2197,7 +2153,7 @@ I286FN _mov_ea8_data8(void) { // C6: } else { // 03/11/23 UINT32 ad; - BYTE val; + UINT8 val; I286_WORKCLOCK(3); ad = CALC_EA(op); GET_PCBYTE(val) @@ -2227,7 +2183,7 @@ I286FN _mov_ea16_data16(void) { // C7 I286FN _enter(void) { // C8: enter DATA16, DATA8 UINT16 dimsize; - BYTE level; + UINT8 level; GET_PCWORD(dimsize) GET_PCBYTE(level) @@ -2289,7 +2245,7 @@ I286FN _ret_far_data16(void) { // CA: REGPOP0(I286_IP) REGPOP0(I286_CS) I286_SP += ad; - CS_BASE = I286_CS << 4; + CS_BASE = SEGSELECT(I286_CS); } I286FN _ret_far(void) { // CB: ret far @@ -2297,7 +2253,7 @@ I286FN _ret_far(void) { // CB: ret I286_WORKCLOCK(15); REGPOP0(I286_IP) REGPOP0(I286_CS) - CS_BASE = I286_CS << 4; + CS_BASE = SEGSELECT(I286_CS); } I286FN _int_03(void) { // CC: int 3 @@ -2312,6 +2268,9 @@ I286FN _int_data8(void) { // CD: int I286_WORKCLOCK(3); GET_PCBYTE(vect) +#if defined(ENABLE_TRAP) + softinttrap(CPU_CS, CPU_IP - 2, vect); +#endif INT_NUM(vect, I286_IP); } @@ -2327,7 +2286,6 @@ I286FN _iret(void) { // CF: iret UINT flag; - extirq_pop(); REGPOP0(I286_IP) REGPOP0(I286_CS) REGPOP0(flag) @@ -2335,6 +2293,7 @@ I286FN _iret(void) { // CF: iret I286_FLAG = flag & (0xfff ^ O_FLAG); I286_TRAP = ((flag & 0x300) == 0x300); CS_BASE = I286_CS << 4; +// CS_BASE = SEGSELECT(I286_CS); I286_WORKCLOCK(31); #if defined(INTR_FAST) if ((I286_TRAP) || ((flag & I_FLAG) && (PICEXISTINTR))) { @@ -2347,7 +2306,7 @@ I286FN _iret(void) { // CF: iret I286FN _shift_ea8_1(void) { // D0: shift EA8, 1 - BYTE *out; + UINT8 *out; UINT op; UINT32 madr; @@ -2393,7 +2352,7 @@ I286FN _shift_ea16_1(void) { // D1: sh I286FN _shift_ea8_cl(void) { // D2: shift EA8, cl - BYTE *out; + UINT8 *out; UINT op; UINT32 madr; REG8 cl; @@ -2449,8 +2408,8 @@ I286FN _shift_ea16_cl(void) { // D3: s I286FN _aam(void) { // D4: AAM - BYTE al; - BYTE div; + UINT8 al; + UINT8 div; I286_WORKCLOCK(16); GET_PCBYTE(div); @@ -2469,11 +2428,11 @@ I286FN _aam(void) { // D4: AAM I286FN _aad(void) { // D5: AAD - BYTE mul; + UINT8 mul; I286_WORKCLOCK(14); GET_PCBYTE(mul); - I286_AL += (BYTE)(I286_AH * mul); + I286_AL += (UINT8)(I286_AH * mul); I286_AH = 0; I286_FLAGL &= ~(S_FLAG | Z_FLAG | P_FLAG); I286_FLAGL |= BYTESZPF(I286_AL); @@ -2588,8 +2547,8 @@ I286FN _jmp_far(void) { // EA: jmp I286_WORKCLOCK(11); GET_PCWORD(ad); GET_PCWORD(I286_CS); - CS_BASE = I286_CS << 4; I286_IP = ad; + CS_BASE = SEGSELECT(I286_CS); } I286FN _jmp_short(void) { // EB: jmp short