Changeset 1639
- Timestamp:
- 06/29/08 14:36:13 (2 months ago)
- Files:
-
- libemu/trunk/include/emu/emu_cpu_data.h (modified) (2 diffs)
- libemu/trunk/include/emu/emu_cpu_stack.h (modified) (2 diffs)
- libemu/trunk/include/emu/emu_memory.h (modified) (2 diffs)
- libemu/trunk/src/emu_cpu.c (modified) (1 diff)
- libemu/trunk/src/emu_memory.c (modified) (7 diffs)
- libemu/trunk/src/functions/adc.c (modified) (3 diffs)
- libemu/trunk/src/functions/cmp.c (modified) (1 diff)
- libemu/trunk/src/functions/imul.c (modified) (2 diffs)
- libemu/trunk/src/functions/mov.c (modified) (2 diffs)
- libemu/trunk/src/functions/push.c (modified) (1 diff)
- libemu/trunk/src/functions/ret.c (modified) (1 diff)
- libemu/trunk/testsuite/instrtest.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libemu/trunk/include/emu/emu_cpu_data.h
r1437 r1639 126 126 127 127 #if !defined(INSTR_CALC) 128 #if BYTE_ORDER == BIG_ENDIAN 129 #define INSTR_CALC(bits, a, b, c, operation) \ 130 UINT(bits) operand_a; \ 131 UINT(bits) operand_b; \ 132 bcopy(&(a), &operand_a, bits/8); \ 133 bcopy(&(b), &operand_b, bits/8); \ 134 UINT(bits) operation_result = operand_a operation operand_b; \ 135 bcopy(&operation_result, &(c), bits/8); 136 #else // ENDIAN 128 137 #define INSTR_CALC(bits, a, b, c, operation) \ 129 138 UINT(bits) operand_a = a; \ … … 131 140 UINT(bits) operation_result = operand_a operation operand_b; \ 132 141 c = operation_result; 142 #endif // ENDIAN 133 143 #endif // INSTR_CALC 134 144 libemu/trunk/include/emu/emu_cpu_stack.h
r1317 r1639 31 31 #define PUSH_DWORD(cpu, arg) \ 32 32 { \ 33 uint32_t pushme = arg; \ 33 uint32_t pushme; \ 34 bcopy(&(arg), &pushme, 4); \ 34 35 if (cpu->reg[esp] < 4) \ 35 36 { \ … … 50 51 #define PUSH_WORD(cpu, arg) \ 51 52 { \ 52 uint16_t pushme = arg; \ 53 uint16_t pushme; \ 54 bcopy(&(arg), &pushme, 2); \ 53 55 if (cpu->reg[esp] < 2) \ 54 56 { \ libemu/trunk/include/emu/emu_memory.h
r1317 r1639 88 88 89 89 #define MEM_WORD_WRITE(cpu_p, addr, data) \ 90 { int32_t ret = emu_memory_write_word((cpu_p)->mem, addr, data); \ 90 { uint16_t val; \ 91 bcopy(&(data), &val, 2); \ 92 int32_t ret = emu_memory_write_word((cpu_p)->mem, addr, val); \ 91 93 if( ret != 0 ) \ 92 94 return ret; } … … 98 100 99 101 #define MEM_DWORD_WRITE(cpu_p, addr, data) \ 100 { int32_t ret = emu_memory_write_dword((cpu_p)->mem, addr, data); \ 102 { uint32_t val; \ 103 bcopy(&(data), &val, 4); \ 104 int32_t ret = emu_memory_write_dword((cpu_p)->mem, addr, val); \ 101 105 if( ret != 0 ) \ 102 106 return ret; } libemu/trunk/src/emu_cpu.c
r1437 r1639 846 846 { 847 847 /* fnstenv volume 1, page 230 */ 848 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x00, 0); 849 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x04, 0); 850 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x08, 0); 848 static int null = 0; 849 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x00, null); 850 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x04, null); 851 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x08, null); 851 852 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x0c, c->last_fpu_instr[1]); 852 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x10, 0);853 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x14, 0);854 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x18, 0);853 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x10, null); 854 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x14, null); 855 MEM_DWORD_WRITE(c, c->instr.fpu.ea + 0x18, null); 855 856 856 857 TRACK_NEED_FPU(c->instr, TRACK_FPU_LAST_INSTRUCTION); libemu/trunk/src/emu_memory.c
r1317 r1639 276 276 int32_t emu_memory_read_word(struct emu_memory *m, uint32_t addr, uint16_t *word) 277 277 { 278 #if BYTE_ORDER == BIG_ENDIAN 279 uint16_t val; 280 int32_t retval = emu_memory_read_block(m, addr, &val, 2); 281 val = ((val & 0xff00) >> 8) | 282 ((val & 0x00ff) << 8); 283 bcopy(&val,word,2); 284 return retval; 285 #else 278 286 return emu_memory_read_block(m, addr, word, 2); 287 #endif 279 288 } 280 289 281 290 int32_t emu_memory_read_dword(struct emu_memory *m, uint32_t addr, uint32_t *dword) 282 291 { 292 #if BYTE_ORDER == BIG_ENDIAN 293 uint32_t val; 294 int32_t retval = emu_memory_read_block(m, addr, &val, 4); 295 val = ((val & (0xff000000)) >> 24) | 296 ((val & (0x00ff0000)) >> 8) | 297 ((val & (0x0000ff00)) << 8) | 298 ((val & (0x000000ff)) << 24); 299 memcpy(dword, &val, 4); 300 return retval; 301 #else 283 302 return emu_memory_read_block(m, addr, dword, 4); 303 #endif 284 304 } 285 305 … … 300 320 if (OFFSET(addr) + len <= PAGE_SIZE) 301 321 { 302 memcpy(dest, address, len);322 bcopy(address, dest, len); 303 323 return 0; 304 324 } … … 306 326 { 307 327 uint32_t cb = PAGE_SIZE - OFFSET(addr); 308 memcpy(dest, address, cb);328 bcopy(address, dest, cb); 309 329 return emu_memory_read_block(m, oaddr + cb, dest + cb, len - cb); 310 330 } … … 369 389 return 0; 370 390 391 #if BYTE_ORDER == BIG_ENDIAN 392 uint16_t val; 393 bcopy(&word, &val, 2); 394 val = ((val & 0xff00) >> 8) | 395 ((val & 0x00ff) << 8); 396 return emu_memory_write_block(m, addr, &val, 2); 397 #else 371 398 return emu_memory_write_block(m, addr, &word, 2); 399 #endif 372 400 } 373 401 … … 377 405 return 0; 378 406 407 #if BYTE_ORDER == BIG_ENDIAN 408 uint32_t val; 409 bcopy(&dword, &val, 4); 410 val = ((val & (0xff000000)) >> 24) | 411 ((val & (0x00ff0000)) >> 8) | 412 ((val & (0x0000ff00)) << 8) | 413 ((val & (0x000000ff)) << 24); 414 return emu_memory_write_block(m, addr, &val, 4); 415 #else 379 416 return emu_memory_write_block(m, addr, &dword, 4); 417 #endif 380 418 } 381 419 … … 400 438 if (OFFSET(addr) + len <= PAGE_SIZE) 401 439 { 402 memcpy(address, src, len);440 bcopy(src, address, len); 403 441 return 0; 404 442 } … … 406 444 { 407 445 uint32_t cb = PAGE_SIZE - OFFSET(addr); 408 memcpy(address, src, cb);446 bcopy(src, address, cb); 409 447 return emu_memory_write_block(m, oaddr + cb, src + cb, len - cb); 410 448 } libemu/trunk/src/functions/adc.c
r1317 r1639 29 29 #include <stdio.h> 30 30 31 32 #if BYTE_ORDER == BIG_ENDIAN 33 #define INSTR_CALC(bits, a, b, c, operation, cpu) \ 34 UINT(bits) operand_a; \ 35 UINT(bits) operand_b; \ 36 bcopy(&(a), &operand_a, bits/8); \ 37 bcopy(&(b), &operand_b, bits/8); \ 38 UINT(bits) operation_result = operand_a operation operand_b operation ((cpu->eflags & (1 << f_cf))?1:0); \ 39 bcopy(&operation_result, &(c), bits/8); 40 #else // ENDIAN 31 41 #define INSTR_CALC(bits, a, b, c, operation, cpu) \ 32 42 UINT(bits) operand_a = a; \ … … 34 44 UINT(bits) operation_result = operand_a operation operand_b operation ((cpu->eflags & (1 << f_cf))?1:0); \ 35 45 c = operation_result; 46 #endif // ENDIAN 47 36 48 37 49 #define INSTR_SET_FLAG_OF(cpu, operand,bits) \ … … 546 558 * ADC r/m16,imm8 547 559 */ 548 int16_t sexd = (int8_t)*i->imm 16;560 int16_t sexd = (int8_t)*i->imm8; 549 561 INSTR_CALC_AND_SET_FLAGS(16, 550 562 c, libemu/trunk/src/functions/cmp.c
r1317 r1639 28 28 #include <stdint.h> 29 29 30 #if BYTE_ORDER == BIG_ENDIAN 31 #define INSTR_CALC(bits, a, b, operation) \ 32 UINT(bits) operand_a; \ 33 UINT(bits) operand_b; \ 34 bcopy(&(a), &operand_a, bits/8); \ 35 bcopy(&(b), &operand_b, bits/8); \ 36 UINT(bits) operation_result = operand_a operation operand_b; 37 #else // ENDIAN 30 38 #define INSTR_CALC(bits, a, b, operation) \ 31 39 UINT(bits) operand_a = a; \ 32 40 UINT(bits) operand_b = b; \ 33 UINT(bits) operation_result = operand_a operation operand_b; \ 41 UINT(bits) operation_result = operand_a operation operand_b; 42 #endif // ENDIAN 34 43 35 44 libemu/trunk/src/functions/imul.c
r1317 r1639 68 68 * IMUL r16,r/m16,imm16 69 69 */ 70 70 #if BYTE_ORDER == BIG_ENDIAN 71 int16_t sexd; 72 bcopy(i->imm16, &sexd, 2); 73 #else 71 74 int16_t sexd = (int16_t)*i->imm16; 72 75 #endif 73 76 uint16_t m16; 74 77 MEM_WORD_READ(c, i->modrm.ea, &m16); … … 125 128 * IMUL r16,r/m16,imm16 126 129 */ 130 #if BYTE_ORDER == BIG_ENDIAN 131 int16_t sexd; 132 bcopy(i->imm16, &sexd, 2); 133 #else 127 134 int16_t sexd = (int16_t)*i->imm16; 135 #endif 136 128 137 129 138 INSTR_CALC(16, libemu/trunk/src/functions/mov.c
r1317 r1639 270 270 * MOV r16,imm16 271 271 */ 272 272 #if BYTE_ORDER == BIG_ENDIAN 273 bcopy(i->imm16, c->reg16[i->opc & 7], 2); 274 #else 273 275 *c->reg16[i->opc & 7] = *i->imm16; 276 #endif 277 278 274 279 } 275 280 else … … 328 333 else 329 334 { 335 #if BYTE_ORDER == BIG_ENDIAN 336 bcopy(i->imm16, c->reg16[i->modrm.rm], 2); 337 #else 330 338 *c->reg16[i->modrm.rm] = *i->imm16; 331 } 339 #endif 340 } 332 341 } 333 342 else libemu/trunk/src/functions/push.c
r1328 r1639 150 150 * PUSH imm8 151 151 */ 152 if (i->prefixes & PREFIX_OPSIZE) 153 { 154 PUSH_WORD(c, (uint16_t)((int8_t)*i->imm8)); 155 } 156 else 157 { 158 PUSH_DWORD(c, (uint32_t)((int8_t)*i->imm8)); 152 if ( i->prefixes & PREFIX_OPSIZE ) 153 { 154 uint16_t word = (uint16_t)((int8_t)*i->imm8); 155 PUSH_WORD(c, word); 156 } 157 else 158 { 159 uint32_t dword = (uint32_t)((int8_t)*i->imm8); 160 PUSH_DWORD(c, dword); 159 161 } 160 162 libemu/trunk/src/functions/ret.c
r1317 r1639 41 41 */ 42 42 POP_DWORD(c, &c->eip); 43 43 44 #if BYTE_ORDER == BIG_ENDIAN 45 uint16_t val; 46 bcopy(i->imm16, &val, 2); 47 c->reg[esp] += val; 48 #else 44 49 c->reg[esp] += *i->imm16; 45 50 #endif 46 51 return 0; 47 52 } libemu/trunk/testsuite/instrtest.c
r1552 r1639 436 436 { 437 437 .instr = "or ecx,[ebx+eax*4+0xdeadbeef]", 438 // .code = "\x03\x8c\x83\xef\xbe\xad\xde",439 //.codesize = 7,438 .code = "\x0b\x8c\x83\xef\xbe\xad\xde", 439 .codesize = 7, 440 440 .in_state.reg = {0x2,0x1,0,0x1,0,0,0,0}, 441 441 .in_state.mem_state = {0xdeadbef8, 0x44443333}, … … 458 458 { 459 459 .instr = "or ax,0x1111", 460 // .code = "\x66\x05\x11\x11",461 //.codesize = 4,460 .code = "\x66\x0d\x11\x11", 461 .codesize = 4, 462 462 .in_state.reg = {0x22222222,0,0,0,0,0,0,0}, 463 463 .in_state.mem_state = {0, 0}, … … 468 468 { 469 469 .instr = "or eax,0x11111111", 470 // .code = "\x05\x11\x11\x11\x11",471 //.codesize = 5,470 .code = "\x0d\x11\x11\x11\x11", 471 .codesize = 5, 472 472 .in_state.reg = {0x22222222,0,0,0,0,0,0,0}, 473 473 .in_state.mem_state = {0, 0}, … … 634 634 { 635 635 .instr = "adc ecx,[ebx+eax*4+0xdeadbeef]", 636 // .code = "\x03\x8c\x83\xef\xbe\xad\xde",637 //.codesize = 7,636 .code = "\x13\x8c\x83\xef\xbe\xad\xde", 637 .codesize = 7, 638 638 .in_state.reg = {0x2,0x1,0,0x1,0,0,0,0}, 639 639 .in_state.mem_state = {0xdeadbef8, 0x44443333}, … … 655 655 { 656 656 .instr = "adc ax,0x1111", 657 // .code = "\x66\x05\x11\x11",658 //.codesize = 4,657 .code = "\x66\x15\x11\x11", 658 .codesize = 4, 659 659 .in_state.reg = {0x22222222,0,0,0,0,0,0,0}, 660 660 .in_state.mem_state = {0, 0}, … … 665 665 { 666 666 .instr = "adc eax,0x11111111", 667 // .code = "\x05\x11\x11\x11\x11",668 //.codesize = 5,667 .code = "\x15\x11\x11\x11\x11", 668 .codesize = 5, 669 669 .in_state.reg = {0x22222222,0,0,0,0,0,0,0}, 670 670 .in_state.mem_state = {0, 0}, … … 694 694 }, 695 695 { 696 .instr = "jmp +16", 696 697 .code = "\xeb\x10", /* jmp +16*/ 697 698 .codesize = 2, … … 699 700 }, 700 701 { 702 .instr = "jmp -1", 701 703 .code = "\xeb\xff", /* jmp -1 */ 702 704 .codesize = 2, … … 704 706 }, 705 707 { 708 .instr = "jmp +0x01000000", 706 709 .code = "\xe9\x00\x00\x00\x01", /* jmp +0x01000000 */ 707 710 .codesize = 5, … … 719 722 { 720 723 .instr = "mov ax, 0xffff", 724 .code = "\x66\xb8\xff\xff", 725 .codesize = 4, 721 726 .out_state.reg = {0xffff,0,0,0,0,0,0,0}, 722 727 }, 723 728 { 724 729 .instr = "mov eax, 0xffffffff", 730 .code = "\xb8\xff\xff\xff\xff", 731 .codesize = 5, 725 732 .out_state.reg = {0xffffffff,0,0,0,0,0,0,0}, 726 733 }, … … 734 741 { 735 742 .instr = "xor dword [eax+0x1000], 0x11111111", 743 .code = "\x81\xb0\x00\x10\x00\x00\x11\x11\x11\x11", 744 .codesize = 10, 736 745 .in_state.mem_state = {0x2000, 0x22222222}, 737 746 .in_state.reg = {0x1000,0,0,0,0,0,0,0}, … … 742 751 { 743 752 .instr = "mov eax, [ebp+ecx*4-0x100]", 753 .code = "\x8b\x84\x8d\x00\xff\xff\xff", 754 .codesize = 7, 744 755 .in_state.mem_state = {0x140, 0x22222222}, 745 756 .in_state.reg = {0x1000,0x10,0,0,0,0x200,0,0}, … … 749 760 { 750 761 .instr = "mov eax, [ebp+ecx*4-0x10000000]", 762 .code = "\x8b\x84\x8d\x00\x00\x00\xf0", 763 .codesize = 7, 751 764 .in_state.mem_state = {0x14000000, 0x22222222}, 752 765 .in_state.reg = {0x1000,0x1000000,0,0,0,0x20000000,0,0},
