Commit 1190935d98ec8a8e2e2438858bee8bd5e49ee324
1 parent
bfbc9133
precise self modifying code test
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@742 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
23 additions
and
1 deletions
tests/test-i386.c
... | ... | @@ -1580,8 +1580,23 @@ uint8_t code[] = { |
1580 | 1580 | 0xc3, /* ret */ |
1581 | 1581 | }; |
1582 | 1582 | |
1583 | -typedef int FuncType(void); | |
1583 | +asm("smc_code2:\n" | |
1584 | + "movl 4(%esp), %eax\n" | |
1585 | + "movl %eax, smc_patch_addr2 + 1\n" | |
1586 | + "nop\n" | |
1587 | + "nop\n" | |
1588 | + "nop\n" | |
1589 | + "nop\n" | |
1590 | + "nop\n" | |
1591 | + "nop\n" | |
1592 | + "nop\n" | |
1593 | + "nop\n" | |
1594 | + "smc_patch_addr2:\n" | |
1595 | + "movl $1, %eax\n" | |
1596 | + "ret\n"); | |
1584 | 1597 | |
1598 | +typedef int FuncType(void); | |
1599 | +extern int smc_code2(int); | |
1585 | 1600 | void test_self_modifying_code(void) |
1586 | 1601 | { |
1587 | 1602 | int i; |
... | ... | @@ -1592,6 +1607,13 @@ void test_self_modifying_code(void) |
1592 | 1607 | code[1] = i; |
1593 | 1608 | printf("func%d = 0x%x\n", i, ((FuncType *)code)()); |
1594 | 1609 | } |
1610 | + | |
1611 | + /* more difficult test : the modified code is just after the | |
1612 | + modifying instruction. It is forbidden in Intel specs, but it | |
1613 | + is used by old DOS programs */ | |
1614 | + for(i = 2; i <= 4; i++) { | |
1615 | + printf("smc_code2(%d) = %d\n", i, smc_code2(i)); | |
1616 | + } | |
1595 | 1617 | } |
1596 | 1618 | |
1597 | 1619 | static void *call_end __init_call = NULL; | ... | ... |