Re: Display instruction address in instrument

Max <[email protected]> Sat, 26 Nov 2016 09:32:39 +0100
Newsgroups gmane.comp.emulators.bochs.devel
Message-ID <[email protected]>
Hello,

Thank you for your answer.

I wrote an ugly workaround, which only work in this case (mono cpu, boot
code).

I added a static bx_address to save eip (local_eip) in my instrument.cc.

I changed the BEFORE_EXECUTION ans AFTER_EXECUTION to this:
#define BX_INSTR_BEFORE_EXECUTION(cpu_id, i, eip)
bx_instr_before_execution(cpu_id, i, eip)
#define BX_INSTR_AFTER_EXECUTION(cpu_id, i, eip)
bx_instr_after_execution(cpu_id, i, eip)

I save eip in BEFORE_EXECUTION, (because of the i->ilen() increase
between BEFORE and AFTER) and use it in the AFTER_EXECUTION.

I can get the address with:
opaddr = BX_CPU(cpu)->get_laddr32(BX_SEG_REG_CS, local_eip);

Then I have the display I need:
1c794 cmp al, 0x00

I hope it describe better that I asked, and the question is still open,
to do it in a better way.

I can resume it with:
How to get the eip value in the instrument part ?

Thanks&Regards,
Max

On 25. 11. 16 19:48, Stanislav wrote:
> Hi,
> 
> I don't understand your question.
> Are you interested in instruction CS:EIP as well ?
> You could simply access CPU class from any of the function and grab the
> value of any register at any moment.
> For example the BEFORE_EXECUTION callback simply asks CPU about CS.D_B and
> CS.L:
> 
>   i->is32 = BX_CPU(cpu)->sregs[BX_SEG_REG_CS].cache.u.segment.d_b;
>   i->is64 = BX_CPU(cpu)->long64_mode(); 
> 
> Similarly you can get any value of any register, even EAX if you want. 
> 
> Stanislav
> 
> -----Original Message-----
> From: Max [mailto:[email protected]] 
> Sent: Wednesday, November 23, 2016 5:53 PM
> To: [email protected]
> Subject: [Bochs-developers] Display instruction address in instrument
> 
> Good day,
> 
> I'm new to Bochs and C++, that's why it's probably an easy question, sorry,
> but I already spend few hours on the source code, without success.
> 
> I'm trying to adapt the function:
>  void bx_print_instruction(unsigned cpu, const instruction_t *i) defined in:
>  instrument/example0/instrument.cc
> to display the memory address too, but I can't make it.
> 
> I tried to find the right attribut/method but didn't find.
> I tried to pass EIP, but as the code runs in real mode (mbr), the CS part is
> missing.
> There's probably an easier way to do it than adding parameters to:
> BX_INSTR_BEFORE_EXECUTION
> BX_INSTR_AFTER_EXECUTION
> 
> Any hint ?
> 
> Regards,
> Max
> 
> ----------------------------------------------------------------------------
> --
> _______________________________________________
> bochs-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bochs-developers
> 
> 


------------------------------------------------------------------------------