--- np2/i386c/ia32/resolve.c 2003/12/08 00:55:31 1.1 +++ np2/i386c/ia32/resolve.c 2004/02/20 16:09:04 1.6 @@ -1,4 +1,4 @@ -/* $Id: resolve.c,v 1.1 2003/12/08 00:55:31 yui Exp $ */ +/* $Id: resolve.c,v 1.6 2004/02/20 16:09:04 monaka Exp $ */ /* * Copyright (c) 2002-2003 NONAKA Kimihiro @@ -32,24 +32,27 @@ #include "ia32.mcr" -static DWORD (*calc_ea_dst_tbl[0x100])(void); -static DWORD (*calc_ea32_dst_tbl[0x100])(void); +UINT32 (*calc_ea_dst_tbl[0x100])(void); +UINT32 (*calc_ea32_dst_tbl[0x100])(void); - -DWORD -calc_ea_dst(DWORD op) +#if defined(DEBUG) || !defined(IA32_INLINE_CALC_EA) +UINT32 +calc_ea_dst(UINT32 op) { + __ASSERT(op < 0x100); + if (!CPU_INST_AS32) return ((*calc_ea_dst_tbl[op])() & 0xffff); return (*calc_ea32_dst_tbl[op])(); } +#endif /* IA32_INLINE_CALC_EA */ /* * common */ -DWORD +UINT32 ea_nop(void) { @@ -65,7 +68,7 @@ ea_nop(void) /* * ea_dest */ -static DWORD +static UINT32 ea_bx_si(void) { @@ -73,27 +76,27 @@ ea_bx_si(void) return (CPU_BX + CPU_SI); } -static DWORD +static UINT32 ea_bx_si_disp8(void) { - SDWORD adrs; + UINT32 adrs; - GET_PCBYTESD(adrs); + GET_PCBYTES(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return (adrs + CPU_BX + CPU_SI); } -static DWORD +static UINT32 ea_bx_si_disp16(void) { - DWORD adrs; + UINT32 adrs; GET_PCWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return (adrs + CPU_BX + CPU_SI); } -static DWORD +static UINT32 ea_bx_di(void) { @@ -101,27 +104,27 @@ ea_bx_di(void) return (CPU_BX + CPU_DI); } -static DWORD +static UINT32 ea_bx_di_disp8(void) { - SDWORD adrs; + UINT32 adrs; - GET_PCBYTESD(adrs); + GET_PCBYTES(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return (adrs + CPU_BX + CPU_DI); } -static DWORD +static UINT32 ea_bx_di_disp16(void) { - DWORD adrs; + UINT32 adrs; GET_PCWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return (adrs + CPU_BX + CPU_DI); } -static DWORD +static UINT32 ea_bp_si(void) { @@ -129,27 +132,27 @@ ea_bp_si(void) return (CPU_BP + CPU_SI); } -static DWORD +static UINT32 ea_bp_si_disp8(void) { - SDWORD adrs; + UINT32 adrs; - GET_PCBYTESD(adrs); + GET_PCBYTES(adrs); CPU_INST_SEGREG_INDEX = SS_FIX; return (adrs + CPU_BP + CPU_SI); } -static DWORD +static UINT32 ea_bp_si_disp16(void) { - DWORD adrs; + UINT32 adrs; GET_PCWORD(adrs); CPU_INST_SEGREG_INDEX = SS_FIX; return (adrs + CPU_BP + CPU_SI); } -static DWORD +static UINT32 ea_bp_di(void) { @@ -157,27 +160,27 @@ ea_bp_di(void) return (CPU_BP + CPU_DI); } -static DWORD +static UINT32 ea_bp_di_disp8(void) { - SDWORD adrs; + UINT32 adrs; - GET_PCBYTESD(adrs); + GET_PCBYTES(adrs); CPU_INST_SEGREG_INDEX = SS_FIX; return (adrs + CPU_BP + CPU_DI); } -static DWORD +static UINT32 ea_bp_di_disp16(void) { - DWORD adrs; + UINT32 adrs; GET_PCWORD(adrs); CPU_INST_SEGREG_INDEX = SS_FIX; return (adrs + CPU_BP + CPU_DI); } -static DWORD +static UINT32 ea_si(void) { @@ -185,27 +188,27 @@ ea_si(void) return CPU_SI; } -static DWORD +static UINT32 ea_si_disp8(void) { - SDWORD adrs; + UINT32 adrs; - GET_PCBYTESD(adrs); + GET_PCBYTES(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return (adrs + CPU_SI); } -static DWORD +static UINT32 ea_si_disp16(void) { - DWORD adrs; + UINT32 adrs; GET_PCWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return (adrs + CPU_SI); } -static DWORD +static UINT32 ea_di(void) { @@ -213,57 +216,57 @@ ea_di(void) return CPU_DI; } -static DWORD +static UINT32 ea_di_disp8(void) { - SDWORD adrs; + UINT32 adrs; - GET_PCBYTESD(adrs); + GET_PCBYTES(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return (adrs + CPU_DI); } -static DWORD +static UINT32 ea_di_disp16(void) { - DWORD adrs; + UINT32 adrs; GET_PCWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return (adrs + CPU_DI); } -static DWORD +static UINT32 ea_disp16(void) { - DWORD adrs; + UINT32 adrs; GET_PCWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs; } -static DWORD +static UINT32 ea_bp_disp8(void) { - SDWORD adrs; + UINT32 adrs; - GET_PCBYTESD(adrs); + GET_PCBYTES(adrs); CPU_INST_SEGREG_INDEX = SS_FIX; return (adrs + CPU_BP); } -static DWORD +static UINT32 ea_bp_disp16(void) { - DWORD adrs; + UINT32 adrs; GET_PCWORD(adrs); CPU_INST_SEGREG_INDEX = SS_FIX; return (adrs + CPU_BP); } -static DWORD +static UINT32 ea_bx(void) { @@ -271,27 +274,27 @@ ea_bx(void) return CPU_BX; } -static DWORD +static UINT32 ea_bx_disp8(void) { - SDWORD adrs; + UINT32 adrs; - GET_PCBYTESD(adrs); + GET_PCBYTES(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return (adrs + CPU_BX); } -static DWORD +static UINT32 ea_bx_disp16(void) { - DWORD adrs; + UINT32 adrs; GET_PCWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return (adrs + CPU_BX); } -static DWORD (*c_ea_dst_tbl[])(void) = { +static UINT32 (*c_ea_dst_tbl[])(void) = { ea_bx_si, ea_bx_di, ea_bp_si, ea_bp_di, ea_si, ea_di, @@ -313,7 +316,7 @@ static DWORD (*c_ea_dst_tbl[])(void) = { /* * ea_dest 32 */ -static DWORD +static UINT32 ea32_eax(void) { @@ -321,7 +324,7 @@ ea32_eax(void) return CPU_EAX; } -static DWORD +static UINT32 ea32_ecx(void) { @@ -329,7 +332,7 @@ ea32_ecx(void) return CPU_ECX; } -static DWORD +static UINT32 ea32_edx(void) { @@ -337,7 +340,7 @@ ea32_edx(void) return CPU_EDX; } -static DWORD +static UINT32 ea32_ebx(void) { @@ -345,18 +348,18 @@ ea32_ebx(void) return CPU_EBX; } -static DWORD +static UINT32 ea32_sib(void) { - DWORD op, dst; - DWORD base, idx, scale; + UINT32 dst; + UINT32 op; + UINT32 base, idx, scale; GET_PCBYTE(op); - dst = 0; /* compiler happy */ - base = op & 7; idx = (op >> 3) & 7; scale = (op >> 6) & 3; + switch (base) { case 0: case 1: case 2: case 3: case 6: case 7: CPU_INST_SEGREG_INDEX = DS_FIX; @@ -372,23 +375,28 @@ ea32_sib(void) CPU_INST_SEGREG_INDEX = DS_FIX; GET_PCDWORD(dst); break; + + default: + dst = 0; /* compiler happy */ + ia32_panic("ea32_sib: invalid base = %d", base); + break; } if (idx != 4) dst += CPU_REGS_DWORD(idx) << scale; return dst; } -static DWORD +static UINT32 ea32_disp32(void) { - DWORD adrs; + UINT32 adrs; GET_PCDWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs; } -static DWORD +static UINT32 ea32_esi(void) { @@ -396,7 +404,7 @@ ea32_esi(void) return CPU_ESI; } -static DWORD +static UINT32 ea32_edi(void) { @@ -404,59 +412,60 @@ ea32_edi(void) return CPU_EDI; } -static DWORD +static UINT32 ea32_eax_disp8(void) { - SDWORD adrs; + SINT32 adrs; GET_PCBYTESD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_EAX; } -static DWORD +static UINT32 ea32_ecx_disp8(void) { - SDWORD adrs; + SINT32 adrs; GET_PCBYTESD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_ECX; } -static DWORD +static UINT32 ea32_edx_disp8(void) { - SDWORD adrs; + SINT32 adrs; GET_PCBYTESD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_EDX; } -static DWORD +static UINT32 ea32_ebx_disp8(void) { - SDWORD adrs; + SINT32 adrs; GET_PCBYTESD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_EBX; } -static DWORD +static UINT32 ea32_sib_disp8(void) { - SDWORD adrs; - DWORD op; - DWORD base, idx, scale; + SINT32 adrs; + UINT32 op; + UINT32 base, idx, scale; GET_PCBYTE(op); - GET_PCBYTESD(adrs); - base = op & 7; idx = (op >> 3) & 7; scale = (op >> 6) & 3; + + GET_PCBYTESD(adrs); + switch (base) { case 0: case 1: case 2: case 3: case 6: case 7: CPU_INST_SEGREG_INDEX = DS_FIX; @@ -471,89 +480,90 @@ ea32_sib_disp8(void) return CPU_REGS_DWORD(base) + adrs; } -static DWORD +static UINT32 ea32_ebp_disp8(void) { - SDWORD adrs; + SINT32 adrs; GET_PCBYTESD(adrs); CPU_INST_SEGREG_INDEX = SS_FIX; return adrs + CPU_EBP; } -static DWORD +static UINT32 ea32_esi_disp8(void) { - SDWORD adrs; + SINT32 adrs; GET_PCBYTESD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_ESI; } -static DWORD +static UINT32 ea32_edi_disp8(void) { - SDWORD adrs; + SINT32 adrs; GET_PCBYTESD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_EDI; } -static DWORD +static UINT32 ea32_eax_disp32(void) { - DWORD adrs; + UINT32 adrs; GET_PCDWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_EAX; } -static DWORD +static UINT32 ea32_ecx_disp32(void) { - DWORD adrs; + UINT32 adrs; GET_PCDWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_ECX; } -static DWORD +static UINT32 ea32_edx_disp32(void) { - DWORD adrs; + UINT32 adrs; GET_PCDWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_EDX; } -static DWORD +static UINT32 ea32_ebx_disp32(void) { - DWORD adrs; + UINT32 adrs; GET_PCDWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_EBX; } -static DWORD +static UINT32 ea32_sib_disp32(void) { - DWORD adrs; - DWORD op; - DWORD base, idx, scale; + UINT32 adrs; + UINT32 op; + UINT32 base, idx, scale; GET_PCBYTE(op); - GET_PCDWORD(adrs); - base = op & 7; idx = (op >> 3) & 7; scale = (op >> 6) & 3; + + GET_PCDWORD(adrs); + switch (base) { case 0: case 1: case 2: case 3: case 6: case 7: CPU_INST_SEGREG_INDEX = DS_FIX; @@ -568,37 +578,37 @@ ea32_sib_disp32(void) return CPU_REGS_DWORD(base) + adrs; } -static DWORD +static UINT32 ea32_ebp_disp32(void) { - DWORD adrs; + UINT32 adrs; GET_PCDWORD(adrs); CPU_INST_SEGREG_INDEX = SS_FIX; return adrs + CPU_EBP; } -static DWORD +static UINT32 ea32_esi_disp32(void) { - DWORD adrs; + UINT32 adrs; GET_PCDWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_ESI; } -static DWORD +static UINT32 ea32_edi_disp32(void) { - DWORD adrs; + UINT32 adrs; GET_PCDWORD(adrs); CPU_INST_SEGREG_INDEX = DS_FIX; return adrs + CPU_EDI; } -static DWORD (*c_ea32_dst_tbl[])(void) = { +static UINT32 (*c_ea32_dst_tbl[])(void) = { ea32_eax, ea32_ecx, ea32_edx, ea32_ebx, ea32_sib, ea32_disp32,