Commit 727d01d4f6846708f0f32dcf9b086a2fba15bd8c
1 parent
ae228531
return code size
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@162 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
14 additions
and
8 deletions
translate-i386.c
| @@ -32,10 +32,6 @@ | @@ -32,10 +32,6 @@ | ||
| 32 | #define IN_OP_I386 | 32 | #define IN_OP_I386 |
| 33 | #include "cpu-i386.h" | 33 | #include "cpu-i386.h" |
| 34 | 34 | ||
| 35 | -#ifndef offsetof | ||
| 36 | -#define offsetof(type, field) ((size_t) &((type *)0)->field) | ||
| 37 | -#endif | ||
| 38 | - | ||
| 39 | /* XXX: move that elsewhere */ | 35 | /* XXX: move that elsewhere */ |
| 40 | static uint16_t *gen_opc_ptr; | 36 | static uint16_t *gen_opc_ptr; |
| 41 | static uint32_t *gen_opparam_ptr; | 37 | static uint32_t *gen_opparam_ptr; |
| @@ -3721,10 +3717,19 @@ static uint16_t gen_opc_buf[OPC_BUF_SIZE]; | @@ -3721,10 +3717,19 @@ static uint16_t gen_opc_buf[OPC_BUF_SIZE]; | ||
| 3721 | static uint32_t gen_opparam_buf[OPPARAM_BUF_SIZE]; | 3717 | static uint32_t gen_opparam_buf[OPPARAM_BUF_SIZE]; |
| 3722 | 3718 | ||
| 3723 | /* return non zero if the very first instruction is invalid so that | 3719 | /* return non zero if the very first instruction is invalid so that |
| 3724 | - the virtual CPU can trigger an exception. */ | 3720 | + the virtual CPU can trigger an exception. |
| 3721 | + | ||
| 3722 | + '*code_size_ptr' contains the target code size including the | ||
| 3723 | + instruction which triggered an exception, except in case of invalid | ||
| 3724 | + illegal opcode. It must never exceed one target page. | ||
| 3725 | + | ||
| 3726 | + '*gen_code_size_ptr' contains the size of the generated code (host | ||
| 3727 | + code). | ||
| 3728 | +*/ | ||
| 3725 | int cpu_x86_gen_code(uint8_t *gen_code_buf, int max_code_size, | 3729 | int cpu_x86_gen_code(uint8_t *gen_code_buf, int max_code_size, |
| 3726 | int *gen_code_size_ptr, | 3730 | int *gen_code_size_ptr, |
| 3727 | - uint8_t *pc_start, uint8_t *cs_base, int flags) | 3731 | + uint8_t *pc_start, uint8_t *cs_base, int flags, |
| 3732 | + int *code_size_ptr) | ||
| 3728 | { | 3733 | { |
| 3729 | DisasContext dc1, *dc = &dc1; | 3734 | DisasContext dc1, *dc = &dc1; |
| 3730 | uint8_t *pc_ptr; | 3735 | uint8_t *pc_ptr; |
| @@ -3767,7 +3772,8 @@ int cpu_x86_gen_code(uint8_t *gen_code_buf, int max_code_size, | @@ -3767,7 +3772,8 @@ int cpu_x86_gen_code(uint8_t *gen_code_buf, int max_code_size, | ||
| 3767 | generate an exception */ | 3772 | generate an exception */ |
| 3768 | if (dc->tf) | 3773 | if (dc->tf) |
| 3769 | break; | 3774 | break; |
| 3770 | - } while (!dc->is_jmp && gen_opc_ptr < gen_opc_end); | 3775 | + } while (!dc->is_jmp && gen_opc_ptr < gen_opc_end && |
| 3776 | + (pc_ptr - pc_start) < (TARGET_PAGE_SIZE - 32)); | ||
| 3771 | /* we must store the eflags state if it is not already done */ | 3777 | /* we must store the eflags state if it is not already done */ |
| 3772 | if (dc->cc_op != CC_OP_DYNAMIC) | 3778 | if (dc->cc_op != CC_OP_DYNAMIC) |
| 3773 | gen_op_set_cc_op(dc->cc_op); | 3779 | gen_op_set_cc_op(dc->cc_op); |
| @@ -3810,7 +3816,7 @@ int cpu_x86_gen_code(uint8_t *gen_code_buf, int max_code_size, | @@ -3810,7 +3816,7 @@ int cpu_x86_gen_code(uint8_t *gen_code_buf, int max_code_size, | ||
| 3810 | gen_code_size = dyngen_code(gen_code_buf, gen_opc_buf, gen_opparam_buf); | 3816 | gen_code_size = dyngen_code(gen_code_buf, gen_opc_buf, gen_opparam_buf); |
| 3811 | flush_icache_range((unsigned long)gen_code_buf, (unsigned long)(gen_code_buf + gen_code_size)); | 3817 | flush_icache_range((unsigned long)gen_code_buf, (unsigned long)(gen_code_buf + gen_code_size)); |
| 3812 | *gen_code_size_ptr = gen_code_size; | 3818 | *gen_code_size_ptr = gen_code_size; |
| 3813 | - | 3819 | + *code_size_ptr = pc_ptr - pc_start; |
| 3814 | #ifdef DEBUG_DISAS | 3820 | #ifdef DEBUG_DISAS |
| 3815 | if (loglevel) { | 3821 | if (loglevel) { |
| 3816 | fprintf(logfile, "OUT: [size=%d]\n", *gen_code_size_ptr); | 3822 | fprintf(logfile, "OUT: [size=%d]\n", *gen_code_size_ptr); |